Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/networking/ifupdown.c

    r3232 r3621  
    4545
    4646#include "libbb.h"
     47#include "common_bufsiz.h"
    4748/* After libbb.h, since it needs sys/types.h on some systems */
    4849#include <sys/utsname.h>
     
    130131    char *shell;
    131132} 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)
    134135
    135136
     
    290291                     * unlike ifconfig, ip doesnt want <class>
    291292                     * (usually "ether" keyword). Skip it. */
    292                     if (strncmp(command, "hwaddress", 9) == 0) {
     293                    if (is_prefixed_with(command, "hwaddress")) {
    293294                        varvalue = skip_whitespace(skip_non_whitespace(varvalue));
    294295                    }
     
    299300                    /* Sigh...  Add a special case for 'ip' to convert from
    300301                     * dotted quad to bit count style netmasks.  */
    301                     if (strncmp(command, "bnmask", 6) == 0) {
     302                    if (is_prefixed_with(command, "bnmask")) {
    302303                        unsigned res;
    303304                        varvalue = get_var("netmask", 7, ifd);
     
    395396    result = execute("ip addr add %address%/%netmask% dev %iface%[[ label %label%]]", ifd, exec);
    396397    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);
    399400# else
    400401    result = execute("ifconfig %iface%[[ media %media%]][[ hw %hwaddress%]][[ mtu %mtu%]] up", ifd, exec);
     
    422423    result += execute("ip link set %iface% up", ifd, exec);
    423424    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);
    425427    return ((result == 4) ? 4 : 0);
    426428}
     
    483485            "dev %iface%[[ peer %pointopoint%]][[ label %label%]]", ifd, exec);
    484486    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);
    486488    return ((result == 3) ? 3 : 0);
    487489# else
     
    535537    },
    536538    { "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%]]"
    538540                "[[ -s %script%]][[ %udhcpc_opts%]]",
    539541        "kill `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null",
     
    556558#  endif
    557559    for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) {
    558         if (exists_execable(ext_dhcp_clients[i].name))
     560        if (executable_exists(ext_dhcp_clients[i].name))
    559561            return execute(ext_dhcp_clients[i].startcmd, ifd, exec);
    560562    }
     
    575577#  endif
    576578    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%]]",
    578580            ifd, exec);
    579581}
     
    593595
    594596    for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) {
    595         if (exists_execable(ext_dhcp_clients[i].name)) {
     597        if (executable_exists(ext_dhcp_clients[i].name)) {
    596598            result = execute(ext_dhcp_clients[i].stopcmd, ifd, exec);
    597599            if (result)
     
    686688#endif  /* FEATURE_IFUPDOWN_IPV4 */
    687689
     690static int FAST_FUNC link_up_down(struct interface_defn_t *ifd UNUSED_PARAM, execfn *exec UNUSED_PARAM)
     691{
     692    return 1;
     693}
     694
     695static const struct method_t link_methods[] = {
     696    { "none", link_up_down, link_up_down }
     697};
     698
     699static const struct address_family_t addr_link = {
     700    "link", ARRAY_SIZE(link_methods), link_methods
     701};
    688702
    689703/* Returns pointer to the next word, or NULL.
     
    744758}
    745759
    746 static struct interfaces_file_t *read_interfaces(const char *filename)
     760static struct interfaces_file_t *read_interfaces(const char *filename, struct interfaces_file_t *defn)
    747761{
    748762    /* Let's try to be compatible.
     
    759773     * A "\" character at the very end of the line indicates the next line
    760774     * 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.
    761779     */
    762780#if ENABLE_FEATURE_IFUPDOWN_MAPPING
     
    764782#endif
    765783    struct interface_defn_t *currif = NULL;
    766     struct interfaces_file_t *defn;
    767784    FILE *f;
    768785    char *buf;
     
    771788    enum { NONE, IFACE, MAPPING } currently_processing = NONE;
    772789
    773     defn = xzalloc(sizeof(*defn));
     790    if (!defn)
     791        defn = xzalloc(sizeof(*defn));
     792
     793    debug_noise("reading %s file:\n", filename);
    774794    f = xfopen_for_read(filename);
    775795
     
    826846                &addr_inet6,
    827847#endif
     848                &addr_link,
    828849                NULL
    829850            };
     
    831852            char *address_family_name;
    832853            char *method_name;
    833             llist_t *iface_list;
    834854
    835855            currif = xzalloc(sizeof(*currif));
     
    856876            if (!currif->method)
    857877                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;
    859892            for (iface_list = defn->ifaces; iface_list; iface_list = iface_list->link) {
    860893                struct interface_defn_t *tmp = (struct interface_defn_t *) iface_list->data;
     
    865898                }
    866899            }
     900#endif
    867901            llist_add_to_end(&(defn->ifaces), (char*)currif);
    868902
     
    882916            }
    883917            currently_processing = NONE;
     918        } else if (strcmp(first_word, "source") == 0) {
     919            read_interfaces(next_word(&rest_of_line), defn);
    884920        } else {
    885921            switch (currently_processing) {
     
    935971    }
    936972    fclose(f);
     973    debug_noise("\ndone reading %s\n\n", filename);
    937974
    938975    return defn;
     
    11381175static llist_t *find_iface_state(llist_t *state_list, const char *iface)
    11391176{
    1140     unsigned iface_len = strlen(iface);
    11411177    llist_t *search = state_list;
    11421178
    11431179    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 == '='
    11461183        ) {
    11471184            return search;
     
    12001237    }
    12011238
    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);
    12051240
    12061241    /* Create a list of interfaces to work on */
     
    12201255        bool okay = 0;
    12211256        int cmds_ret;
     1257        bool curr_failure = 0;
    12221258
    12231259        iface = xstrdup(target_list->data);
     
    12851321                cmds_ret = cmds(currif);
    12861322                if (cmds_ret == -1) {
    1287                     bb_error_msg("don't seem to have all the variables for %s/%s",
     1323                    bb_error_msg("don't have all variables for %s/%s",
    12881324                            liface, currif->address_family->name);
    1289                     any_failures = 1;
     1325                    any_failures = curr_failure = 1;
    12901326                } else if (cmds_ret == 0) {
    1291                     any_failures = 1;
     1327                    any_failures = curr_failure = 1;
    12921328                }
    12931329
     
    13101346            llist_t *iface_state = find_iface_state(state_list, iface);
    13111347
    1312             if (cmds == iface_up && !any_failures) {
     1348            if (cmds == iface_up && !curr_failure) {
    13131349                char *newiface = xasprintf("%s=%s", iface, liface);
    13141350                if (!iface_state) {
Note: See TracChangeset for help on using the changeset viewer.