aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-07-02 15:45:47 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-07-02 15:45:47 +0200
commiteba708d93c4f5e8d8c95db54e0fa3856d9117ef8 (patch)
treeefe05a8a71c081dce76ce3661ae918ab64b446d2
parent9f21df049144d3f4244b24e789c9820ca631379e (diff)
sysmobts: Store the netmask as suffixsysmocom/old-stable
If one uses ip(8) one can configure the ip using the form of A.B.C.D/N. Store N as uint8_t and parse it using strtok_r to get the otional /N. Change-Id: I45f884e1a980511fdb3a09425408262420870e0b
-rw-r--r--src/osmo-bts-sysmo/misc/sysmobts_eeprom.h11
-rw-r--r--src/osmo-bts-sysmo/misc/sysmobts_util.c42
2 files changed, 38 insertions, 15 deletions
diff --git a/src/osmo-bts-sysmo/misc/sysmobts_eeprom.h b/src/osmo-bts-sysmo/misc/sysmobts_eeprom.h
index 97344f3..c7bbcb1 100644
--- a/src/osmo-bts-sysmo/misc/sysmobts_eeprom.h
+++ b/src/osmo-bts-sysmo/misc/sysmobts_eeprom.h
@@ -6,9 +6,9 @@
struct sysmobts_net_cfg {
uint8_t mode; /* 0 */
uint32_t ip; /* 1 - 4 */
- uint32_t mask; /* 5 - 8 */
- uint32_t gw; /* 9 - 12 */
- uint32_t dns; /* 13 - 16 */
+ uint32_t gw; /* 5 - 8 */
+ uint32_t dns; /* 9 - 12 */
+ uint8_t mask; /* 13 */
} __attribute__((packed));
struct sysmobts_eeprom { /* offset */
@@ -25,8 +25,9 @@ struct sysmobts_eeprom { /* offset */
uint8_t trx_nr; /* 36 */
uint8_t boot_state[48]; /* 37-84 */
uint8_t _pad1[18]; /* 85-102 */
- struct sysmobts_net_cfg net_cfg;/* 103-119 */
- uint8_t crc; /* 120 */
+ struct sysmobts_net_cfg net_cfg;/* 103-116 */
+ uint8_t crc; /* 117 */
+ uint8_t _pad2[3]; /* 118-120 */
uint8_t gpg_key[128]; /* 121-249 */
} __attribute__((packed));
diff --git a/src/osmo-bts-sysmo/misc/sysmobts_util.c b/src/osmo-bts-sysmo/misc/sysmobts_util.c
index c9930d8..0e4d58a 100644
--- a/src/osmo-bts-sysmo/misc/sysmobts_util.c
+++ b/src/osmo-bts-sysmo/misc/sysmobts_util.c
@@ -44,8 +44,9 @@ static char *write_arg;
static int void_warranty;
-static struct in_addr net_ip = { 0, }, net_dns = { 0, }, net_gw = { 0, }, net_mask = { 0, };
+static struct in_addr net_ip = { 0, }, net_dns = { 0, }, net_gw = { 0, };
static uint8_t net_mode = 0;
+static uint8_t net_mask = 0;
static void print_help()
{
@@ -53,7 +54,7 @@ static void print_help()
printf("sysmobts-util [--void-warranty -r | -w value] param_name\n");
printf("sysmobts-util --net-read\n");
- printf("sysmobts-util --net-write --mode INT --ip IP_STR --gw IP_STR --dns IP_STR --net-mask IP_STR\n");
+ printf("sysmobts-util --net-write --mode INT --ip IP_STR/mask --gw IP_STR --dns IP_STR\n");
printf("Possible param names:\n");
for (; par->str != NULL; par += 1) {
@@ -63,6 +64,29 @@ static void print_help()
}
}
+/*
+ * Parse 8.8.8.8 and 8.8.8.8/24 like ip addresses and netmask
+ */
+static int parse_ip_mask(const char *ip_str, struct in_addr *out_ip, uint8_t *out_mask)
+{
+ char *lasts = NULL;
+ char *ip;
+ char *mask = NULL;
+
+ char *str = talloc_strdup(NULL, ip_str);
+ ip = strtok_r(str, "/", &lasts);
+ mask = strtok_r(NULL, "/", &lasts);
+
+ inet_aton(ip, out_ip);
+ if (mask)
+ *out_mask = atoi(mask);
+ else
+ *out_mask = 0;
+
+ talloc_free(str);
+ return 0;
+}
+
static int parse_options(int argc, char **argv)
{
while (1) {
@@ -75,7 +99,6 @@ static int parse_options(int argc, char **argv)
{ "ip", 1, 0, 241 },
{ "gw", 1, 0, 242 },
{ "dns", 1, 0, 243 },
- { "net-mask", 1, 0, 244 },
{ "mode", 1, 0, 245 },
{ "net-read", 0, 0, 246 },
{ "net-write", 0, 0, 247 },
@@ -111,8 +134,6 @@ static int parse_options(int argc, char **argv)
case 245:
net_mode = atoi(optarg);
break;
- case 244:
- inet_aton(optarg, &net_mask);
break;
case 243:
inet_aton(optarg, &net_dns);
@@ -121,7 +142,7 @@ static int parse_options(int argc, char **argv)
inet_aton(optarg, &net_gw);
break;
case 241:
- inet_aton(optarg, &net_ip);
+ parse_ip_mask(optarg, &net_ip, &net_mask);
break;
default:
printf("Unknown option %d/%c\n", c, c);
@@ -145,12 +166,13 @@ static void dump_net_cfg(struct sysmobts_net_cfg *net_cfg)
printf("IP=dhcp\n");
printf("DNS=\n");
printf("GATEWAY=\n");
- printf("NETMASK=\n");
} else {
- printf("IP=%s\n", make_addr(net_cfg->ip));
+ if (net_cfg->mask == 0)
+ printf("IP=%s\n", make_addr(net_cfg->ip));
+ else
+ printf("IP=%s/%d\n", make_addr(net_cfg->ip), net_cfg->mask);
printf("GATEWAY=%s\n", make_addr(net_cfg->gw));
printf("DNS=%s\n", make_addr(net_cfg->dns));
- printf("NETMASK=%s\n", make_addr(net_cfg->mask));
}
}
@@ -172,7 +194,7 @@ static int handle_net(void)
memset(&net_cfg, 0, sizeof(net_cfg));
net_cfg.mode = net_mode;
net_cfg.ip = htonl(net_ip.s_addr);
- net_cfg.mask = htonl(net_mask.s_addr);
+ net_cfg.mask = net_mask;
net_cfg.gw = htonl(net_gw.s_addr);
net_cfg.dns = htonl(net_dns.s_addr);
printf("Going to write\n");