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/libiproute/ipaddress.c

    r3232 r3621  
    1414
    1515#include "ip_common.h"  /* #include "libbb.h" is inside */
     16#include "common_bufsiz.h"
    1617#include "rt_names.h"
    1718#include "utils.h"
     
    4041typedef struct filter_t filter_t;
    4142
    42 #define G_filter (*(filter_t*)&bb_common_bufsiz1)
    43 
     43#define G_filter (*(filter_t*)bb_common_bufsiz1)
     44#define INIT_G() do { setup_common_bufsiz(); } while (0)
    4445
    4546static void print_link_flags(unsigned flags, unsigned mdown)
     
    138139        unsigned m_flag = 0;
    139140        if (tb[IFLA_LINK]) {
    140             SPRINT_BUF(b1);
    141141            int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]);
    142142            if (iflink == 0)
    143143                printf("@NONE: ");
    144144            else {
    145                 printf("@%s: ", ll_idx_n2a(iflink, b1));
     145                printf("@%s: ", ll_index_to_name(iflink));
    146146                m_flag = ll_index_to_flags(iflink);
    147147                m_flag = !(m_flag & IFF_UP);
     
    159159#ifdef IFLA_MASTER
    160160    if (tb[IFLA_MASTER]) {
    161         SPRINT_BUF(b1);
    162         printf("master %s ", ll_idx_n2a(*(int*)RTA_DATA(tb[IFLA_MASTER]), b1));
     161        printf("master %s ", ll_index_to_name(*(int*)RTA_DATA(tb[IFLA_MASTER])));
    163162    }
    164163#endif
     
    217216    struct ifaddrmsg *ifa = NLMSG_DATA(n);
    218217    int len = n->nlmsg_len;
    219     struct rtattr * rta_tb[IFA_MAX+1];
    220     char abuf[256];
    221     SPRINT_BUF(b1);
     218    struct rtattr *rta_tb[IFA_MAX+1];
    222219
    223220    if (n->nlmsg_type != RTM_NEWADDR && n->nlmsg_type != RTM_DELADDR)
     
    251248            label = RTA_DATA(rta_tb[IFA_LABEL]);
    252249        else
    253             label = ll_idx_n2a(ifa->ifa_index, b1);
     250            label = ll_index_to_name(ifa->ifa_index);
    254251        if (fnmatch(G_filter.label, label, 0) != 0)
    255252            return 0;
     
    295292
    296293    if (rta_tb[IFA_LOCAL]) {
    297         fputs(rt_addr_n2a(ifa->ifa_family,
    298                           RTA_DATA(rta_tb[IFA_LOCAL]),
    299                           abuf, sizeof(abuf)), stdout);
     294        fputs(rt_addr_n2a(ifa->ifa_family, RTA_DATA(rta_tb[IFA_LOCAL])),
     295            stdout
     296        );
    300297
    301298        if (rta_tb[IFA_ADDRESS] == NULL
     
    305302        } else {
    306303            printf(" peer %s/%d ",
    307                 rt_addr_n2a(ifa->ifa_family,
    308                         RTA_DATA(rta_tb[IFA_ADDRESS]),
    309                         abuf, sizeof(abuf)),
    310                 ifa->ifa_prefixlen);
     304                rt_addr_n2a(ifa->ifa_family, RTA_DATA(rta_tb[IFA_ADDRESS])),
     305                ifa->ifa_prefixlen
     306            );
    311307        }
    312308    }
     
    315311        printf("brd %s ",
    316312            rt_addr_n2a(ifa->ifa_family,
    317                     RTA_DATA(rta_tb[IFA_BROADCAST]),
    318                     abuf, sizeof(abuf))
     313                RTA_DATA(rta_tb[IFA_BROADCAST]))
    319314        );
    320315    }
     
    322317        printf("any %s ",
    323318            rt_addr_n2a(ifa->ifa_family,
    324                     RTA_DATA(rta_tb[IFA_ANYCAST]),
    325                     abuf, sizeof(abuf))
     319                RTA_DATA(rta_tb[IFA_ANYCAST]))
    326320        );
    327321    }
    328     printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1));
     322    printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope));
    329323    if (ifa->ifa_flags & IFA_F_SECONDARY) {
    330324        ifa->ifa_flags &= ~IFA_F_SECONDARY;
     
    459453            if (rtnl_rtscope_a2n(&scope, *argv)) {
    460454                if (strcmp(*argv, "all") != 0) {
    461                     invarg(*argv, "scope");
     455                    invarg_1_to_2(*argv, "scope");
    462456                }
    463457                scope = RT_SCOPE_NOWHERE;
     
    557551                    }
    558552                    if (G_filter.label) {
    559                         SPRINT_BUF(b1);
    560553                        const char *label;
    561554                        if (tb[IFA_LABEL])
    562555                            label = RTA_DATA(tb[IFA_LABEL]);
    563556                        else
    564                             label = ll_idx_n2a(ifa->ifa_index, b1);
     557                            label = ll_index_to_name(ifa->ifa_index);
    565558                        if (fnmatch(G_filter.label, label, 0) != 0)
    566559                            continue;
     
    599592
    600593/* Return value becomes exitcode. It's okay to not return at all */
    601 static int ipaddr_modify(int cmd, char **argv)
     594static int ipaddr_modify(int cmd, int flags, char **argv)
    602595{
    603596    static const char option[] ALIGN1 =
     
    623616
    624617    req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
    625     req.n.nlmsg_flags = NLM_F_REQUEST;
     618    req.n.nlmsg_flags = NLM_F_REQUEST | flags;
    626619    req.n.nlmsg_type = cmd;
    627620    req.ifa.ifa_family = preferred_family;
    628621
    629622    while (*argv) {
    630         const smalluint arg = index_in_strings(option, *argv);
     623        unsigned arg = index_in_strings(option, *argv);
     624        /* if search fails, "local" is assumed */
     625        if ((int)arg >= 0)
     626            NEXT_ARG();
     627
    631628        if (arg <= 1) { /* peer, remote */
    632             NEXT_ARG();
    633 
    634629            if (peer_len) {
    635630                duparg("peer", *argv);
     
    644639        } else if (arg <= 3) { /* broadcast, brd */
    645640            inet_prefix addr;
    646             NEXT_ARG();
    647641            if (brd_len) {
    648642                duparg("broadcast", *argv);
     
    661655        } else if (arg == 4) { /* anycast */
    662656            inet_prefix addr;
    663             NEXT_ARG();
    664657            if (any_len) {
    665658                duparg("anycast", *argv);
     
    673666        } else if (arg == 5) { /* scope */
    674667            uint32_t scope = 0;
    675             NEXT_ARG();
    676668            if (rtnl_rtscope_a2n(&scope, *argv)) {
    677                 invarg(*argv, "scope");
     669                invarg_1_to_2(*argv, "scope");
    678670            }
    679671            req.ifa.ifa_scope = scope;
    680672            scoped = 1;
    681673        } else if (arg == 6) { /* dev */
    682             NEXT_ARG();
    683674            d = *argv;
    684675        } else if (arg == 7) { /* label */
    685             NEXT_ARG();
    686676            l = *argv;
    687677            addattr_l(&req.n, sizeof(req), IFA_LABEL, l, strlen(l) + 1);
    688678        } else {
    689             if (arg == 8) /* local */
    690                 NEXT_ARG();
     679            /* local (specified or assumed) */
    691680            if (local_len) {
    692681                duparg2("local", *argv);
     
    706695        bb_error_msg_and_die("need \"dev IFACE\"");
    707696    }
    708     if (l && strncmp(d, l, strlen(d)) != 0) {
     697    if (l && !is_prefixed_with(l, d)) {
    709698        bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s)", d, l);
    710699    }
     
    725714        brd = peer;
    726715        if (brd.bitlen <= 30) {
    727             for (i=31; i>=brd.bitlen; i--) {
     716            for (i = 31; i >= brd.bitlen; i--) {
    728717                if (brd_len == -1)
    729718                    brd.data[0] |= htonl(1<<(31-i));
     
    754743{
    755744    static const char commands[] ALIGN1 =
    756         "add\0""delete\0""list\0""show\0""lst\0""flush\0";
    757     smalluint cmd = 2;
     745        /* 0    1         2      3          4         5       6       7      8 */
     746        "add\0""change\0""chg\0""replace\0""delete\0""list\0""show\0""lst\0""flush\0";
     747    int cmd = 2;
     748
     749    INIT_G();
     750
    758751    if (*argv) {
    759752        cmd = index_in_substrings(commands, *argv);
    760         if (cmd > 5)
    761             bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
     753        if (cmd < 0)
     754            invarg_1_to_2(*argv, applet_name);
    762755        argv++;
    763         if (cmd <= 1)
    764             return ipaddr_modify((cmd == 0) ? RTM_NEWADDR : RTM_DELADDR, argv);
    765     }
    766     /* 2 == list, 3 == show, 4 == lst */
    767     return ipaddr_list_or_flush(argv, cmd == 5);
    768 }
     756        if (cmd <= 4) {
     757            return ipaddr_modify(
     758                /*cmd:*/ cmd == 4 ? RTM_DELADDR : RTM_NEWADDR,
     759                /*flags:*/
     760                    cmd == 0 ? NLM_F_CREATE|NLM_F_EXCL : /* add */
     761                    cmd == 1 || cmd == 2 ? NLM_F_REPLACE : /* change */
     762                    cmd == 3 ? NLM_F_CREATE|NLM_F_REPLACE : /* replace */
     763                    0 /* delete */
     764            , argv);
     765        }
     766    }
     767    return ipaddr_list_or_flush(argv, cmd == 8);
     768}
Note: See TracChangeset for help on using the changeset viewer.