aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/ifupdown.c90
-rw-r--r--networking/libiproute/ip_parse_common_args.c2
-rw-r--r--networking/libiproute/ipaddress.c2
3 files changed, 59 insertions, 35 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index f33dbc43c..fcedfd0cf 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -107,6 +107,33 @@ static char no_act = 0;
107static char verbose = 0; 107static char verbose = 0;
108static char **environ = NULL; 108static char **environ = NULL;
109 109
110#ifdef CONFIG_FEATURE_IFUPDOWN_IP
111static int count_netmask_bits(char *dotted_quad)
112{
113 unsigned int a, b, c, d;
114 unsigned int res, result;
115 /* Found a netmask... Check if it is dotted quad */
116 if (sscanf(dotted_quad, "%u.%u.%u.%u", &a, &b, &c, &d) != 4)
117 return -1;
118 res = (a & 0x55) + ((a >> 1) & 0x55);
119 res = (res & 0x33) + ((res >> 2) & 0x33);
120 result = (res & 0x0F) + ((res >> 4) & 0x0F);
121
122 res = (b & 0x55) + ((b >> 1) & 0x55);
123 res = (res & 0x33) + ((res >> 2) & 0x33);
124 result += (res & 0x0F) + ((res >> 4) & 0x0F);
125
126 res = (c & 0x55) + ((c >> 1) & 0x55);
127 res = (res & 0x33) + ((res >> 2) & 0x33);
128 result += (res & 0x0F) + ((res >> 4) & 0x0F);
129
130 res = (d & 0x55) + ((d >> 1) & 0x55);
131 res = (res & 0x33) + ((res >> 2) & 0x33);
132 result += (res & 0x0F) + ((res >> 4) & 0x0F);
133 return ((int)result);
134}
135#endif
136
110static void addstr(char **buf, size_t *len, size_t *pos, char *str, size_t str_length) 137static void addstr(char **buf, size_t *len, size_t *pos, char *str, size_t str_length)
111{ 138{
112 if (*pos + str_length >= *len) { 139 if (*pos + str_length >= *len) {
@@ -219,6 +246,21 @@ static char *parse(char *command, interface_defn_t *ifd)
219 if (varvalue) { 246 if (varvalue) {
220 addstr(&result, &len, &pos, varvalue, xstrlen(varvalue)); 247 addstr(&result, &len, &pos, varvalue, xstrlen(varvalue));
221 } else { 248 } else {
249#ifdef CONFIG_FEATURE_IFUPDOWN_IP
250 /* Sigh... Add a special case for 'ip' to convert from
251 * dotted quad to bit count style netmasks. */
252 if (strncmp(command, "bnmask", 6)==0) {
253 int res;
254 varvalue = get_var("netmask", 7, ifd);
255 if (varvalue && (res=count_netmask_bits(varvalue)) > 0) {
256 char argument[255];
257 sprintf(argument, "%d", res);
258 addstr(&result, &len, &pos, argument, xstrlen(argument));
259 command = nextpercent + 1;
260 break;
261 }
262 }
263#endif
222 okay[opt_depth - 1] = 0; 264 okay[opt_depth - 1] = 0;
223 } 265 }
224 266
@@ -428,7 +470,7 @@ static int loopback_up(interface_defn_t *ifd, execfn *exec)
428static int loopback_down(interface_defn_t *ifd, execfn *exec) 470static int loopback_down(interface_defn_t *ifd, execfn *exec)
429{ 471{
430#ifdef CONFIG_FEATURE_IFUPDOWN_IP 472#ifdef CONFIG_FEATURE_IFUPDOWN_IP
431 if (!execute("ip -f inet addr flush dev %iface%", ifd, exec)) 473 if (!execute("ip addr flush dev %iface%", ifd, exec))
432 return(0); 474 return(0);
433 if (!execute("ip link set %iface% down", ifd, exec)) 475 if (!execute("ip link set %iface% down", ifd, exec))
434 return(0); 476 return(0);
@@ -445,7 +487,7 @@ static int static_up(interface_defn_t *ifd, execfn *exec)
445#ifdef CONFIG_FEATURE_IFUPDOWN_IP 487#ifdef CONFIG_FEATURE_IFUPDOWN_IP
446 if (!execute("ip link set %iface% up", ifd, exec)) 488 if (!execute("ip link set %iface% up", ifd, exec))
447 return(0); 489 return(0);
448 if (!execute("ip addr add %address%/%netmask% dev %iface%", ifd, exec)) 490 if (!execute("ip addr add %address%/%bnmask% dev %iface%", ifd, exec))
449 return(0); 491 return(0);
450 if (!execute("[[ ip route add default via %gateway% dev %iface% ]]", ifd, exec)) 492 if (!execute("[[ ip route add default via %gateway% dev %iface% ]]", ifd, exec))
451 return(0); 493 return(0);
@@ -464,9 +506,9 @@ static int static_up(interface_defn_t *ifd, execfn *exec)
464static int static_down(interface_defn_t *ifd, execfn *exec) 506static int static_down(interface_defn_t *ifd, execfn *exec)
465{ 507{
466#ifdef CONFIG_FEATURE_IFUPDOWN_IP 508#ifdef CONFIG_FEATURE_IFUPDOWN_IP
467 if (!execute("[[ ip route del default via %gateway% dev %iface% ]]", ifd, exec)) 509 //if (!execute("[[ ip route del default via %gateway% dev %iface% ]]", ifd, exec))
468 return(0); 510 // return(0);
469 if (!execute("ip -f inet addr flush dev %iface%", ifd, exec)) 511 if (!execute("ip addr flush dev %iface%", ifd, exec))
470 return(0); 512 return(0);
471 if (!execute("ip link set %iface% down", ifd, exec)) 513 if (!execute("ip link set %iface% down", ifd, exec))
472 return(0); 514 return(0);
@@ -897,11 +939,6 @@ static interfaces_file_t *read_interfaces(char *filename)
897 return defn; 939 return defn;
898} 940}
899 941
900static int check(char *str)
901{
902 return (str != NULL);
903}
904
905static char *setlocalenv(char *format, char *name, char *value) 942static char *setlocalenv(char *format, char *name, char *value)
906{ 943{
907 char *result; 944 char *result;
@@ -1017,10 +1054,6 @@ static int execute_all(interface_defn_t *ifd, execfn *exec, const char *opt)
1017 1054
1018static int iface_up(interface_defn_t *iface) 1055static int iface_up(interface_defn_t *iface)
1019{ 1056{
1020 if (!iface->method->up(iface, check)) {
1021 return (-1);
1022 }
1023
1024 set_environ(iface, "start"); 1057 set_environ(iface, "start");
1025 if (!execute_all(iface, doit, "pre-up")) { 1058 if (!execute_all(iface, doit, "pre-up")) {
1026 return (0); 1059 return (0);
@@ -1037,9 +1070,6 @@ static int iface_up(interface_defn_t *iface)
1037 1070
1038static int iface_down(interface_defn_t *iface) 1071static int iface_down(interface_defn_t *iface)
1039{ 1072{
1040 if (!iface->method->down(iface, check)) {
1041 return (-1);
1042 }
1043 set_environ(iface, "stop"); 1073 set_environ(iface, "stop");
1044 if (!execute_all(iface, doit, "down")) { 1074 if (!execute_all(iface, doit, "down")) {
1045 return (0); 1075 return (0);
@@ -1223,20 +1253,6 @@ extern int ifupdown_main(int argc, char **argv)
1223 1253
1224 if (no_act) { 1254 if (no_act) {
1225 state_fp = fopen(statefile, "r"); 1255 state_fp = fopen(statefile, "r");
1226 } else {
1227 state_fp = xfopen(statefile, "a+");
1228 }
1229
1230 /* Read the previous state from the state file */
1231 if (state_fp != NULL) {
1232 char *start;
1233 while ((start = get_line_from_file(state_fp)) != NULL) {
1234 char *end_ptr;
1235 /* We should only need to check for a single character */
1236 end_ptr = start + strcspn(start, " \t\n");
1237 *end_ptr = '\0';
1238 state_list = llist_add_to(state_list, start);
1239 }
1240 } 1256 }
1241 1257
1242 /* Create a list of interfaces to work on */ 1258 /* Create a list of interfaces to work on */
@@ -1249,6 +1265,7 @@ extern int ifupdown_main(int argc, char **argv)
1249 target_list = llist_add_to(target_list, strdup(list->data)); 1265 target_list = llist_add_to(target_list, strdup(list->data));
1250 list = list->link; 1266 list = list->link;
1251 } 1267 }
1268 target_list = defn->autointerfaces;
1252 } 1269 }
1253 } else { 1270 } else {
1254 target_list = llist_add_to(target_list, argv[optind]); 1271 target_list = llist_add_to(target_list, argv[optind]);
@@ -1285,12 +1302,10 @@ extern int ifupdown_main(int argc, char **argv)
1285 } 1302 }
1286 } else { 1303 } else {
1287 /* ifdown */ 1304 /* ifdown */
1288 if (iface_state == NULL) { 1305 if (iface_state) {
1289 error_msg("interface %s not configured", iface); 1306 error_msg("interface %s not configured", iface);
1290 continue; 1307 continue;
1291 } 1308 }
1292 pch = strchr(iface_state->data, '=');
1293 liface = strdup(pch + 1);
1294 } 1309 }
1295 } 1310 }
1296 1311
@@ -1368,7 +1383,12 @@ extern int ifupdown_main(int argc, char **argv)
1368 } 1383 }
1369 1384
1370 /* Actually write the new state */ 1385 /* Actually write the new state */
1371 if (state_fp != NULL && !no_act) { 1386 if (!no_act) {
1387
1388 if (state_fp)
1389 fclose(state_fp);
1390 state_fp = xfopen(statefile, "a+");
1391
1372 if (ftruncate(fileno(state_fp), 0) < 0) { 1392 if (ftruncate(fileno(state_fp), 0) < 0) {
1373 error_msg_and_die("failed to truncate statefile %s: %s", statefile, strerror(errno)); 1393 error_msg_and_die("failed to truncate statefile %s: %s", statefile, strerror(errno));
1374 } 1394 }
diff --git a/networking/libiproute/ip_parse_common_args.c b/networking/libiproute/ip_parse_common_args.c
index ac9d94916..4b4355ac1 100644
--- a/networking/libiproute/ip_parse_common_args.c
+++ b/networking/libiproute/ip_parse_common_args.c
@@ -47,6 +47,8 @@ void ip_parse_common_args(int *argcp, char ***argvp)
47 if (matches(opt, "-family") == 0) { 47 if (matches(opt, "-family") == 0) {
48 argc--; 48 argc--;
49 argv++; 49 argv++;
50 if (! argv[1])
51 show_usage();
50 if (strcmp(argv[1], "inet") == 0) 52 if (strcmp(argv[1], "inet") == 0)
51 preferred_family = AF_INET; 53 preferred_family = AF_INET;
52 else if (strcmp(argv[1], "inet6") == 0) 54 else if (strcmp(argv[1], "inet6") == 0)
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c
index 88438179d..8eba90c77 100644
--- a/networking/libiproute/ipaddress.c
+++ b/networking/libiproute/ipaddress.c
@@ -524,8 +524,10 @@ extern int ipaddr_list_or_flush(int argc, char **argv, int flush)
524 exit(1); 524 exit(1);
525 } 525 }
526 if (filter.flushed == 0) { 526 if (filter.flushed == 0) {
527#if 0
527 if (round == 0) 528 if (round == 0)
528 fprintf(stderr, "Nothing to flush.\n"); 529 fprintf(stderr, "Nothing to flush.\n");
530#endif
529 fflush(stdout); 531 fflush(stdout);
530 return 0; 532 return 0;
531 } 533 }