aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/ifupdown.c55
1 files changed, 37 insertions, 18 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 8170e80b3..818bec2d6 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -388,8 +388,8 @@ static int loopback_up6(struct interface_defn_t *ifd, execfn *exec)
388{ 388{
389#ifdef CONFIG_FEATURE_IFUPDOWN_IP 389#ifdef CONFIG_FEATURE_IFUPDOWN_IP
390 int result; 390 int result;
391 result = execute("ip link set %iface% up", ifd, exec); 391 result =execute("ip addr add ::1 dev %iface% label %label%", ifd, exec);
392 result +=execute("ip addr add ::1 dev %iface% label %label%", ifd, exec); 392 result += execute("ip link set %iface% up", ifd, exec);
393 return( result); 393 return( result);
394#else 394#else
395 return( execute("ifconfig %iface% add ::1", ifd, exec)); 395 return( execute("ifconfig %iface% add ::1", ifd, exec));
@@ -409,8 +409,8 @@ static int static_up6(struct interface_defn_t *ifd, execfn *exec)
409{ 409{
410 int result; 410 int result;
411#ifdef CONFIG_FEATURE_IFUPDOWN_IP 411#ifdef CONFIG_FEATURE_IFUPDOWN_IP
412 result = execute("ip link set %iface% up", ifd, exec); 412 result = execute("ip addr add %address%/%netmask% dev %iface% label %label%", ifd, exec);
413 result += execute("ip addr add %address%/%netmask% dev %iface% label %label%", ifd, exec); 413 result += execute("ip link set %iface% up", ifd, exec);
414 result += execute("[[ ip route add ::/0 via %gateway% ]]", ifd, exec); 414 result += execute("[[ ip route add ::/0 via %gateway% ]]", ifd, exec);
415#else 415#else
416 result = execute("ifconfig %iface% [[media %media%]] [[hw %hwaddress%]] [[mtu %mtu%]] up", ifd, exec); 416 result = execute("ifconfig %iface% [[media %media%]] [[hw %hwaddress%]] [[mtu %mtu%]] up", ifd, exec);
@@ -435,8 +435,8 @@ static int v4tunnel_up(struct interface_defn_t *ifd, execfn *exec)
435 int result; 435 int result;
436 result = execute("ip tunnel add %iface% mode sit remote " 436 result = execute("ip tunnel add %iface% mode sit remote "
437 "%endpoint% [[local %local%]] [[ttl %ttl%]]", ifd, exec); 437 "%endpoint% [[local %local%]] [[ttl %ttl%]]", ifd, exec);
438 result += execute("ip link set %iface% up", ifd, exec);
439 result += execute("ip addr add %address%/%netmask% dev %iface% label %label%", ifd, exec); 438 result += execute("ip addr add %address%/%netmask% dev %iface% label %label%", ifd, exec);
439 result += execute("ip link set %iface% up", ifd, exec);
440 result += execute("[[ ip route add ::/0 via %gateway% ]]", ifd, exec); 440 result += execute("[[ ip route add ::/0 via %gateway% ]]", ifd, exec);
441 return( result); 441 return( result);
442} 442}
@@ -467,8 +467,8 @@ static int loopback_up(struct interface_defn_t *ifd, execfn *exec)
467{ 467{
468#ifdef CONFIG_FEATURE_IFUPDOWN_IP 468#ifdef CONFIG_FEATURE_IFUPDOWN_IP
469 int result; 469 int result;
470 result = execute("ip link set %iface% up", ifd, exec); 470 result = execute("ip addr add 127.0.0.1/8 dev %iface% label %label%", ifd, exec);
471 result += execute("ip addr add 127.0.0.1/8 dev %iface% label %label%", ifd, exec); 471 result += execute("ip link set %iface% up", ifd, exec);
472 return(result); 472 return(result);
473#else 473#else
474 return( execute("ifconfig %iface% 127.0.0.1 up", ifd, exec)); 474 return( execute("ifconfig %iface% 127.0.0.1 up", ifd, exec));
@@ -491,9 +491,9 @@ static int static_up(struct interface_defn_t *ifd, execfn *exec)
491{ 491{
492 int result; 492 int result;
493#ifdef CONFIG_FEATURE_IFUPDOWN_IP 493#ifdef CONFIG_FEATURE_IFUPDOWN_IP
494 result = execute("ip link set %iface% up", ifd, exec); 494 result = execute("ip addr add %address%/%bnmask% [[broadcast %broadcast%]] "
495 result += execute("ip addr add %address%/%bnmask% [[broadcast %broadcast%]] "
496 "dev %iface% label %label%", ifd, exec); 495 "dev %iface% label %label%", ifd, exec);
496 result += execute("ip link set %iface% up", ifd, exec);
497 result += execute("[[ ip route add default via %gateway% dev %iface% ]]", ifd, exec); 497 result += execute("[[ ip route add default via %gateway% dev %iface% ]]", ifd, exec);
498#else 498#else
499 result = execute("ifconfig %iface% %address% netmask %netmask% " 499 result = execute("ifconfig %iface% %address% netmask %netmask% "
@@ -1116,38 +1116,57 @@ static int popen2(FILE **in, FILE **out, char *command, ...)
1116 /* unreached */ 1116 /* unreached */
1117} 1117}
1118 1118
1119static char * run_mapping(char *physical, char *logical, int len, struct mapping_defn_t * map) 1119static char * run_mapping(char *physical, struct mapping_defn_t * map)
1120{ 1120{
1121 FILE *in, *out; 1121 FILE *in, *out;
1122 int i, status; 1122 int i, status;
1123 pid_t pid; 1123 pid_t pid;
1124 1124
1125 char *new_logical = NULL; 1125 char *logical = bb_xstrdup(physical);
1126 1126
1127 /* Run the mapping script. */
1127 pid = popen2(&in, &out, map->script, physical, NULL); 1128 pid = popen2(&in, &out, map->script, physical, NULL);
1128 if (pid == 0) { 1129
1129 return 0; 1130 /* popen2() returns 0 on failure. */
1130 } 1131 if (pid == 0)
1132 return logical;
1133
1134 /* Write mappings to stdin of mapping script. */
1131 for (i = 0; i < map->n_mappings; i++) { 1135 for (i = 0; i < map->n_mappings; i++) {
1132 fprintf(in, "%s\n", map->mapping[i]); 1136 fprintf(in, "%s\n", map->mapping[i]);
1133 } 1137 }
1134 fclose(in); 1138 fclose(in);
1135 waitpid(pid, &status, 0); 1139 waitpid(pid, &status, 0);
1140
1136 if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { 1141 if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
1137 new_logical = (char *)xmalloc(MAX_INTERFACE_LENGTH); 1142 /* If the mapping script exited successfully, try to
1143 * grab a line of output and use that as the name of the
1144 * logical interface. */
1145 char *new_logical = (char *)xmalloc(MAX_INTERFACE_LENGTH);
1138 1146
1139 if (fgets(new_logical, MAX_INTERFACE_LENGTH, out)) { 1147 if (fgets(new_logical, MAX_INTERFACE_LENGTH, out)) {
1148 /* If we are able to read a line of output from the script,
1149 * remove any trailing whitespace and use this value
1150 * as the name of the logical interface. */
1140 char *pch = new_logical + bb_strlen(new_logical) - 1; 1151 char *pch = new_logical + bb_strlen(new_logical) - 1;
1141 1152
1142 while (pch >= new_logical && isspace(*pch)) 1153 while (pch >= new_logical && isspace(*pch))
1143 *(pch--) = '\0'; 1154 *(pch--) = '\0';
1155
1156 free(logical);
1157 logical = new_logical;
1158 } else {
1159 /* If we are UNABLE to read a line of output, discard are
1160 * freshly allocated memory. */
1161 free(new_logical);
1144 } 1162 }
1145 } 1163 }
1164
1146 fclose(out); 1165 fclose(out);
1147 1166
1148 return new_logical ? new_logical : logical; 1167 return logical;
1149} 1168}
1150#endif /* CONFIG_FEATURE_IFUPDOWN_IPV6 */ 1169#endif /* CONFIG_FEATURE_IFUPDOWN_MAPPING */
1151 1170
1152static llist_t *find_iface_state(llist_t *state_list, const char *iface) 1171static llist_t *find_iface_state(llist_t *state_list, const char *iface)
1153{ 1172{
@@ -1335,7 +1354,7 @@ extern int ifupdown_main(int argc, char **argv)
1335 if (verbose) { 1354 if (verbose) {
1336 printf("Running mapping script %s on %s\n", currmap->script, liface); 1355 printf("Running mapping script %s on %s\n", currmap->script, liface);
1337 } 1356 }
1338 liface = run_mapping(iface, liface, sizeof(liface), currmap); 1357 liface = run_mapping(iface, currmap);
1339 break; 1358 break;
1340 } 1359 }
1341 } 1360 }