Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/networking/ifupdown.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/networking/ifupdown.c
r2725 r3232 18 18 */ 19 19 20 //usage:#define ifup_trivial_usage 21 //usage: "[-an"IF_FEATURE_IFUPDOWN_MAPPING("m")"vf] [-i FILE] IFACE..." 22 //usage:#define ifup_full_usage "\n\n" 23 //usage: " -a De/configure all interfaces automatically" 24 //usage: "\n -i FILE Use FILE for interface definitions" 25 //usage: "\n -n Print out what would happen, but don't do it" 26 //usage: IF_FEATURE_IFUPDOWN_MAPPING( 27 //usage: "\n (note: doesn't disable mappings)" 28 //usage: "\n -m Don't run any mappings" 29 //usage: ) 30 //usage: "\n -v Print out what would happen before doing it" 31 //usage: "\n -f Force de/configuration" 32 //usage: 33 //usage:#define ifdown_trivial_usage 34 //usage: "[-an"IF_FEATURE_IFUPDOWN_MAPPING("m")"vf] [-i FILE] IFACE..." 35 //usage:#define ifdown_full_usage "\n\n" 36 //usage: " -a De/configure all interfaces automatically" 37 //usage: "\n -i FILE Use FILE for interface definitions" 38 //usage: "\n -n Print out what would happen, but don't do it" 39 //usage: IF_FEATURE_IFUPDOWN_MAPPING( 40 //usage: "\n (note: doesn't disable mappings)" 41 //usage: "\n -m Don't run any mappings" 42 //usage: ) 43 //usage: "\n -v Print out what would happen before doing it" 44 //usage: "\n -f Force de/configuration" 45 20 46 #include "libbb.h" 21 47 /* After libbb.h, since it needs sys/types.h on some systems */ … … 24 50 25 51 #define MAX_OPT_DEPTH 10 26 #define EUNBALBRACK 1000127 #define EUNDEFVAR 1000228 #define EUNBALPER 1000029 52 30 53 #if ENABLE_FEATURE_IFUPDOWN_MAPPING … … 62 85 char *script; 63 86 64 int max_mappings;65 87 int n_mappings; 66 88 char **mapping; … … 77 99 78 100 char *iface; 79 int max_options;80 101 int n_options; 81 102 struct variable_t *option; … … 107 128 char **my_environ; 108 129 const char *startup_PATH; 130 char *shell; 109 131 } FIX_ALIASING; 110 132 #define G (*(struct globals*)&bb_common_bufsiz1) 111 133 #define INIT_G() do { } while (0) 134 135 136 static const char keywords_up_down[] ALIGN1 = 137 "up\0" 138 "down\0" 139 "pre-up\0" 140 "post-down\0" 141 ; 112 142 113 143 … … 201 231 { 202 232 size_t old_pos[MAX_OPT_DEPTH] = { 0 }; 203 int okay[MAX_OPT_DEPTH] = { 1 };233 smallint okay[MAX_OPT_DEPTH] = { 1 }; 204 234 int opt_depth = 1; 205 235 char *result = NULL; … … 212 242 break; 213 243 case '\\': 214 if (command[1]) { 215 addstr(&result, command + 1, 1); 216 command += 2; 217 } else { 218 addstr(&result, command, 1); 244 if (command[1]) 219 245 command++; 220 } 246 addstr(&result, command, 1); 247 command++; 221 248 break; 222 249 case '[': … … 227 254 command += 2; 228 255 } else { 229 addstr(&result, "[", 1);256 addstr(&result, command, 1); 230 257 command++; 231 258 } … … 239 266 command += 2; 240 267 } else { 241 addstr(&result, "]", 1);268 addstr(&result, command, 1); 242 269 command++; 243 270 } … … 251 278 nextpercent = strchr(command, '%'); 252 279 if (!nextpercent) { 253 errno = EUNBALPER;280 /* Unterminated %var% */ 254 281 free(result); 255 282 return NULL; … … 296 323 297 324 if (opt_depth > 1) { 298 errno = EUNBALBRACK;325 /* Unbalanced bracket */ 299 326 free(result); 300 327 return NULL; … … 302 329 303 330 if (!okay[0]) { 304 errno = EUNDEFVAR;331 /* Undefined variable and we aren't in a bracket */ 305 332 free(result); 306 333 return NULL; … … 369 396 result += execute("ip link set[[ mtu %mtu%]][[ addr %hwaddress%]] %iface% up", ifd, exec); 370 397 /* Was: "[[ ip ....%gateway% ]]". Removed extra spaces w/o checking */ 371 result += execute("[[ip route add ::/0 via %gateway%]] ", ifd, exec);398 result += execute("[[ip route add ::/0 via %gateway%]][[ prio %metric%]]", ifd, exec); 372 399 # else 373 400 result = execute("ifconfig %iface%[[ media %media%]][[ hw %hwaddress%]][[ mtu %mtu%]] up", ifd, exec); 374 401 result += execute("ifconfig %iface% add %address%/%netmask%", ifd, exec); 375 result += execute("[[route -A inet6 add ::/0 gw %gateway% ]]", ifd, exec);402 result += execute("[[route -A inet6 add ::/0 gw %gateway%[[ metric %metric%]]]]", ifd, exec); 376 403 # endif 377 404 return ((result == 3) ? 3 : 0); … … 456 483 "dev %iface%[[ peer %pointopoint%]][[ label %label%]]", ifd, exec); 457 484 result += execute("ip link set[[ mtu %mtu%]][[ addr %hwaddress%]] %iface% up", ifd, exec); 458 result += execute("[[ip route add default via %gateway% dev %iface% ]]", ifd, exec);485 result += execute("[[ip route add default via %gateway% dev %iface%[[ prio %metric%]]]]", ifd, exec); 459 486 return ((result == 3) ? 3 : 0); 460 487 # else … … 466 493 "[[ broadcast %broadcast%]][[ pointopoint %pointopoint%]] ", 467 494 ifd, exec); 468 result += execute("[[route add default gw %gateway% %iface%]]", ifd, exec);495 result += execute("[[route add default gw %gateway%[[ metric %metric%]] %iface%]]", ifd, exec); 469 496 return ((result == 3) ? 3 : 0); 470 497 # endif … … 777 804 currmap->match[currmap->n_matches++] = xstrdup(first_word); 778 805 } 779 /*currmap->max_mappings = 0; - done by xzalloc */780 806 /*currmap->n_mappings = 0;*/ 781 807 /*currmap->mapping = NULL;*/ … … 862 888 bb_error_msg_and_die("option with empty value \"%s\"", buf); 863 889 864 if (strcmp(first_word, "up") != 0 865 && strcmp(first_word, "down") != 0 866 && strcmp(first_word, "pre-up") != 0 867 && strcmp(first_word, "post-down") != 0 868 ) { 890 if (strcmp(first_word, "post-up") == 0) 891 first_word += 5; /* "up" */ 892 else if (strcmp(first_word, "pre-down") == 0) 893 first_word += 4; /* "down" */ 894 895 /* If not one of "up", "down",... words... */ 896 if (index_in_strings(keywords_up_down, first_word) < 0) { 869 897 int i; 870 898 for (i = 0; i < currif->n_options; i++) { … … 873 901 } 874 902 } 875 if (currif->n_options >= currif->max_options) {876 currif->max_options += 10;877 currif->option = xrealloc(currif->option,878 sizeof(*currif->option) * currif->max_options);879 }880 903 debug_noise("\t%s=%s\n", first_word, rest_of_line); 904 currif->option = xrealloc_vector(currif->option, 4, currif->n_options); 881 905 currif->option[currif->n_options].name = xstrdup(first_word); 882 906 currif->option[currif->n_options].value = xstrdup(rest_of_line); … … 890 914 currmap->script = xstrdup(next_word(&rest_of_line)); 891 915 } else if (strcmp(first_word, "map") == 0) { 892 if (currmap->n_mappings >= currmap->max_mappings) { 893 currmap->max_mappings = currmap->max_mappings * 2 + 1; 894 currmap->mapping = xrealloc(currmap->mapping, 895 sizeof(char *) * currmap->max_mappings); 896 } 916 currmap->mapping = xrealloc_vector(currmap->mapping, 2, currmap->n_mappings); 897 917 currmap->mapping[currmap->n_mappings] = xstrdup(next_word(&rest_of_line)); 898 918 currmap->n_mappings++; … … 941 961 } 942 962 943 static void set_environ(struct interface_defn_t *iface, const char *mode )963 static void set_environ(struct interface_defn_t *iface, const char *mode, const char *opt) 944 964 { 945 965 int i; … … 954 974 955 975 /* note: last element will stay NULL: */ 956 G.my_environ = xzalloc(sizeof(char *) * (iface->n_options + 6));976 G.my_environ = xzalloc(sizeof(char *) * (iface->n_options + 7)); 957 977 pp = G.my_environ; 958 978 959 979 for (i = 0; i < iface->n_options; i++) { 960 if (strcmp(iface->option[i].name, "up") == 0 961 || strcmp(iface->option[i].name, "down") == 0 962 || strcmp(iface->option[i].name, "pre-up") == 0 963 || strcmp(iface->option[i].name, "post-down") == 0 964 ) { 980 if (index_in_strings(keywords_up_down, iface->option[i].name) >= 0) { 965 981 continue; 966 982 } … … 972 988 *pp++ = setlocalenv("%s=%s", "METHOD", iface->method->name); 973 989 *pp++ = setlocalenv("%s=%s", "MODE", mode); 990 *pp++ = setlocalenv("%s=%s", "PHASE", opt); 974 991 if (G.startup_PATH) 975 992 *pp++ = setlocalenv("%s=%s", "PATH", G.startup_PATH); … … 987 1004 fflush_all(); 988 1005 child = vfork(); 989 switch (child) { 990 case -1: /* failure */ 1006 if (child < 0) /* failure */ 991 1007 return 0; 992 case 0:/* child */993 execle( DEFAULT_SHELL, DEFAULT_SHELL, "-c", str, (char *) NULL, G.my_environ);1008 if (child == 0) { /* child */ 1009 execle(G.shell, G.shell, "-c", str, (char *) NULL, G.my_environ); 994 1010 _exit(127); 995 1011 } … … 1027 1043 { 1028 1044 if (!iface->method->up(iface, check)) return -1; 1029 set_environ(iface, "start" );1045 set_environ(iface, "start", "pre-up"); 1030 1046 if (!execute_all(iface, "pre-up")) return 0; 1031 1047 if (!iface->method->up(iface, doit)) return 0; 1048 set_environ(iface, "start", "post-up"); 1032 1049 if (!execute_all(iface, "up")) return 0; 1033 1050 return 1; … … 1036 1053 static int iface_down(struct interface_defn_t *iface) 1037 1054 { 1038 if (!iface->method->down(iface, check)) return -1;1039 set_environ(iface, "stop" );1055 if (!iface->method->down(iface, check)) return -1; 1056 set_environ(iface, "stop", "pre-down"); 1040 1057 if (!execute_all(iface, "down")) return 0; 1041 1058 if (!iface->method->down(iface, doit)) return 0; 1059 set_environ(iface, "stop", "post-down"); 1042 1060 if (!execute_all(iface, "post-down")) return 0; 1043 1061 return 1; … … 1166 1184 1167 1185 G.startup_PATH = getenv("PATH"); 1186 G.shell = xstrdup(get_shell_name()); 1168 1187 1169 1188 cmds = iface_down; … … 1221 1240 if (iface_state) { 1222 1241 bb_error_msg("interface %s already configured", iface); 1223 continue;1242 goto next; 1224 1243 } 1225 1244 } else { … … 1227 1246 if (!iface_state) { 1228 1247 bb_error_msg("interface %s not configured", iface); 1229 continue;1248 goto next; 1230 1249 } 1231 1250 } … … 1291 1310 llist_t *iface_state = find_iface_state(state_list, iface); 1292 1311 1293 if (cmds == iface_up ) {1294 char * constnewiface = xasprintf("%s=%s", iface, liface);1295 if ( iface_state == NULL) {1312 if (cmds == iface_up && !any_failures) { 1313 char *newiface = xasprintf("%s=%s", iface, liface); 1314 if (!iface_state) { 1296 1315 llist_add_to_end(&state_list, newiface); 1297 1316 } else { … … 1317 1336 llist_free(state_list, free); 1318 1337 } 1338 next: 1339 free(iface); 1340 free(liface); 1319 1341 } 1320 1342
Note:
See TracChangeset
for help on using the changeset viewer.