Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/networking/ifupdown.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/networking/ifupdown.c
r3232 r3621 45 45 46 46 #include "libbb.h" 47 #include "common_bufsiz.h" 47 48 /* After libbb.h, since it needs sys/types.h on some systems */ 48 49 #include <sys/utsname.h> … … 130 131 char *shell; 131 132 } FIX_ALIASING; 132 #define G (*(struct globals*) &bb_common_bufsiz1)133 #define INIT_G() do { } while (0)133 #define G (*(struct globals*)bb_common_bufsiz1) 134 #define INIT_G() do { setup_common_bufsiz(); } while (0) 134 135 135 136 … … 290 291 * unlike ifconfig, ip doesnt want <class> 291 292 * (usually "ether" keyword). Skip it. */ 292 if ( strncmp(command, "hwaddress", 9) == 0) {293 if (is_prefixed_with(command, "hwaddress")) { 293 294 varvalue = skip_whitespace(skip_non_whitespace(varvalue)); 294 295 } … … 299 300 /* Sigh... Add a special case for 'ip' to convert from 300 301 * dotted quad to bit count style netmasks. */ 301 if ( strncmp(command, "bnmask", 6) == 0) {302 if (is_prefixed_with(command, "bnmask")) { 302 303 unsigned res; 303 304 varvalue = get_var("netmask", 7, ifd); … … 395 396 result = execute("ip addr add %address%/%netmask% dev %iface%[[ label %label%]]", ifd, exec); 396 397 result += execute("ip link set[[ mtu %mtu%]][[ addr %hwaddress%]] %iface% up", ifd, exec); 397 /* Was: "[[ ip ....%gateway% ]]". Removed extra spaces w/o checking*/398 result += execute("[[ip route add ::/0 via %gateway% ]][[ prio%metric%]]", ifd, exec);398 /* Reportedly, IPv6 needs "dev %iface%", but IPv4 does not: */ 399 result += execute("[[ip route add ::/0 via %gateway% dev %iface%]][[ metric %metric%]]", ifd, exec); 399 400 # else 400 401 result = execute("ifconfig %iface%[[ media %media%]][[ hw %hwaddress%]][[ mtu %mtu%]] up", ifd, exec); … … 422 423 result += execute("ip link set %iface% up", ifd, exec); 423 424 result += execute("ip addr add %address%/%netmask% dev %iface%", ifd, exec); 424 result += execute("[[ip route add ::/0 via %gateway%]]", ifd, exec); 425 /* Reportedly, IPv6 needs "dev %iface%", but IPv4 does not: */ 426 result += execute("[[ip route add ::/0 via %gateway% dev %iface%]]", ifd, exec); 425 427 return ((result == 4) ? 4 : 0); 426 428 } … … 483 485 "dev %iface%[[ peer %pointopoint%]][[ label %label%]]", ifd, exec); 484 486 result += execute("ip link set[[ mtu %mtu%]][[ addr %hwaddress%]] %iface% up", ifd, exec); 485 result += execute("[[ip route add default via %gateway% dev %iface%[[ prio%metric%]]]]", ifd, exec);487 result += execute("[[ip route add default via %gateway% dev %iface%[[ metric %metric%]]]]", ifd, exec); 486 488 return ((result == 3) ? 3 : 0); 487 489 # else … … 535 537 }, 536 538 { "udhcpc", 537 "udhcpc " UDHCPC_CMD_OPTIONS " -p /var/run/udhcpc.%iface%.pid -i %iface%[[ - H%hostname%]][[ -c %client%]]"539 "udhcpc " UDHCPC_CMD_OPTIONS " -p /var/run/udhcpc.%iface%.pid -i %iface%[[ -x hostname:%hostname%]][[ -c %client%]]" 538 540 "[[ -s %script%]][[ %udhcpc_opts%]]", 539 541 "kill `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", … … 556 558 # endif 557 559 for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) { 558 if (ex ists_execable(ext_dhcp_clients[i].name))560 if (executable_exists(ext_dhcp_clients[i].name)) 559 561 return execute(ext_dhcp_clients[i].startcmd, ifd, exec); 560 562 } … … 575 577 # endif 576 578 return execute("udhcpc " UDHCPC_CMD_OPTIONS " -p /var/run/udhcpc.%iface%.pid " 577 "-i %iface%[[ - H%hostname%]][[ -c %client%]][[ -s %script%]][[ %udhcpc_opts%]]",579 "-i %iface%[[ -x hostname:%hostname%]][[ -c %client%]][[ -s %script%]][[ %udhcpc_opts%]]", 578 580 ifd, exec); 579 581 } … … 593 595 594 596 for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) { 595 if (ex ists_execable(ext_dhcp_clients[i].name)) {597 if (executable_exists(ext_dhcp_clients[i].name)) { 596 598 result = execute(ext_dhcp_clients[i].stopcmd, ifd, exec); 597 599 if (result) … … 686 688 #endif /* FEATURE_IFUPDOWN_IPV4 */ 687 689 690 static int FAST_FUNC link_up_down(struct interface_defn_t *ifd UNUSED_PARAM, execfn *exec UNUSED_PARAM) 691 { 692 return 1; 693 } 694 695 static const struct method_t link_methods[] = { 696 { "none", link_up_down, link_up_down } 697 }; 698 699 static const struct address_family_t addr_link = { 700 "link", ARRAY_SIZE(link_methods), link_methods 701 }; 688 702 689 703 /* Returns pointer to the next word, or NULL. … … 744 758 } 745 759 746 static struct interfaces_file_t *read_interfaces(const char *filename )760 static struct interfaces_file_t *read_interfaces(const char *filename, struct interfaces_file_t *defn) 747 761 { 748 762 /* Let's try to be compatible. … … 759 773 * A "\" character at the very end of the line indicates the next line 760 774 * should be treated as a continuation of the current one. 775 * 776 * Lines beginning with "source" are used to include stanzas from 777 * other files, so configuration can be split into many files. 778 * The word "source" is followed by the path of file to be sourced. 761 779 */ 762 780 #if ENABLE_FEATURE_IFUPDOWN_MAPPING … … 764 782 #endif 765 783 struct interface_defn_t *currif = NULL; 766 struct interfaces_file_t *defn;767 784 FILE *f; 768 785 char *buf; … … 771 788 enum { NONE, IFACE, MAPPING } currently_processing = NONE; 772 789 773 defn = xzalloc(sizeof(*defn)); 790 if (!defn) 791 defn = xzalloc(sizeof(*defn)); 792 793 debug_noise("reading %s file:\n", filename); 774 794 f = xfopen_for_read(filename); 775 795 … … 826 846 &addr_inet6, 827 847 #endif 848 &addr_link, 828 849 NULL 829 850 }; … … 831 852 char *address_family_name; 832 853 char *method_name; 833 llist_t *iface_list;834 854 835 855 currif = xzalloc(sizeof(*currif)); … … 856 876 if (!currif->method) 857 877 bb_error_msg_and_die("unknown method \"%s\"", method_name); 858 878 #if 0 879 // Allegedly, Debian allows a duplicate definition: 880 // iface eth0 inet static 881 // address 192.168.0.15 882 // netmask 255.255.0.0 883 // gateway 192.168.0.1 884 // 885 // iface eth0 inet static 886 // address 10.0.0.1 887 // netmask 255.255.255.0 888 // 889 // This adds *two* addresses to eth0 (probably requires use of "ip", not "ifconfig" 890 // 891 llist_t *iface_list; 859 892 for (iface_list = defn->ifaces; iface_list; iface_list = iface_list->link) { 860 893 struct interface_defn_t *tmp = (struct interface_defn_t *) iface_list->data; … … 865 898 } 866 899 } 900 #endif 867 901 llist_add_to_end(&(defn->ifaces), (char*)currif); 868 902 … … 882 916 } 883 917 currently_processing = NONE; 918 } else if (strcmp(first_word, "source") == 0) { 919 read_interfaces(next_word(&rest_of_line), defn); 884 920 } else { 885 921 switch (currently_processing) { … … 935 971 } 936 972 fclose(f); 973 debug_noise("\ndone reading %s\n\n", filename); 937 974 938 975 return defn; … … 1138 1175 static llist_t *find_iface_state(llist_t *state_list, const char *iface) 1139 1176 { 1140 unsigned iface_len = strlen(iface);1141 1177 llist_t *search = state_list; 1142 1178 1143 1179 while (search) { 1144 if ((strncmp(search->data, iface, iface_len) == 0) 1145 && (search->data[iface_len] == '=') 1180 char *after_iface = is_prefixed_with(search->data, iface); 1181 if (after_iface 1182 && *after_iface == '=' 1146 1183 ) { 1147 1184 return search; … … 1200 1237 } 1201 1238 1202 debug_noise("reading %s file:\n", interfaces); 1203 defn = read_interfaces(interfaces); 1204 debug_noise("\ndone reading %s\n\n", interfaces); 1239 defn = read_interfaces(interfaces, NULL); 1205 1240 1206 1241 /* Create a list of interfaces to work on */ … … 1220 1255 bool okay = 0; 1221 1256 int cmds_ret; 1257 bool curr_failure = 0; 1222 1258 1223 1259 iface = xstrdup(target_list->data); … … 1285 1321 cmds_ret = cmds(currif); 1286 1322 if (cmds_ret == -1) { 1287 bb_error_msg("don't seem to have all thevariables for %s/%s",1323 bb_error_msg("don't have all variables for %s/%s", 1288 1324 liface, currif->address_family->name); 1289 any_failures = 1;1325 any_failures = curr_failure = 1; 1290 1326 } else if (cmds_ret == 0) { 1291 any_failures = 1;1327 any_failures = curr_failure = 1; 1292 1328 } 1293 1329 … … 1310 1346 llist_t *iface_state = find_iface_state(state_list, iface); 1311 1347 1312 if (cmds == iface_up && ! any_failures) {1348 if (cmds == iface_up && !curr_failure) { 1313 1349 char *newiface = xasprintf("%s=%s", iface, liface); 1314 1350 if (!iface_state) {
Note:
See TracChangeset
for help on using the changeset viewer.