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 added
1 deleted
19 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/networking/libiproute/Kbuild.src

    r2725 r3621  
    6565    rt_names.o \
    6666    utils.o
     67
     68lib-$(CONFIG_FEATURE_IP_NEIGH) += \
     69    ip_parse_common_args.o \
     70    ipneigh.o \
     71    libnetlink.o \
     72    ll_map.o \
     73    rt_names.o \
     74    utils.o
  • branches/3.3/mindi-busybox/networking/libiproute/ip_common.h

    r2725 r3621  
    2525int FAST_FUNC do_iproute(char **argv);
    2626int FAST_FUNC do_iprule(char **argv);
    27 //int FAST_FUNC do_ipneigh(char **argv);
     27int FAST_FUNC do_ipneigh(char **argv);
    2828int FAST_FUNC do_iptunnel(char **argv);
    2929int FAST_FUNC do_iplink(char **argv);
  • branches/3.3/mindi-busybox/networking/libiproute/ip_parse_common_args.c

    r2725 r3621  
    6868            arg = index_in_strings(families, *argv);
    6969            if (arg < 0)
    70                 invarg(*argv, "protocol family");
     70                invarg_1_to_2(*argv, "family");
    7171            /* now arg == 0, 1 or 2 */
    7272        } else {
  • 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}
  • branches/3.3/mindi-busybox/networking/libiproute/iplink.c

    r3232 r3621  
    22/*
    33 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
     4 *          Patrick McHardy <kaber@trash.net>
    45 *
    56 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    67 */
    78#include <net/if.h>
    8 #include <net/if_packet.h>
     9/*#include <net/if_packet.h> - not needed? */
    910#include <netpacket/packet.h>
    1011#include <netinet/if_ether.h>
    1112
     13#include <linux/if_vlan.h>
    1214#include "ip_common.h"  /* #include "libbb.h" is inside */
    1315#include "rt_names.h"
    1416#include "utils.h"
    1517
     18#undef  ETH_P_8021AD
     19#define ETH_P_8021AD            0x88A8
     20#undef  VLAN_FLAG_REORDER_HDR
     21#define VLAN_FLAG_REORDER_HDR   0x1
     22#undef  VLAN_FLAG_GVRP
     23#define VLAN_FLAG_GVRP          0x2
     24#undef  VLAN_FLAG_LOOSE_BINDING
     25#define VLAN_FLAG_LOOSE_BINDING 0x4
     26#undef  VLAN_FLAG_MVRP
     27#define VLAN_FLAG_MVRP          0x8
     28#undef  IFLA_VLAN_PROTOCOL
     29#define IFLA_VLAN_PROTOCOL      5
     30
    1631#ifndef IFLA_LINKINFO
    1732# define IFLA_LINKINFO 18
    1833# define IFLA_INFO_KIND 1
     34# define IFLA_INFO_DATA 2
     35#endif
     36
     37#ifndef IFLA_VLAN_MAX
     38# define IFLA_VLAN_ID 1
     39# define IFLA_VLAN_FLAGS 2
     40struct ifla_vlan_flags {
     41    uint32_t    flags;
     42    uint32_t    mask;
     43};
    1944#endif
    2045
    2146/* taken from linux/sockios.h */
    2247#define SIOCSIFNAME  0x8923  /* set interface name */
     48
     49#if 0
     50# define dbg(...) bb_error_msg(__VA_ARGS__)
     51#else
     52# define dbg(...) ((void)0)
     53#endif
    2354
    2455/* Exits on error */
     
    278309}
    279310
     311static void vlan_parse_opt(char **argv, struct nlmsghdr *n, unsigned int size)
     312{
     313    static const char keywords[] ALIGN1 =
     314        "id\0"
     315        "protocol\0"
     316        "reorder_hdr\0"
     317        "gvrp\0"
     318        "mvrp\0"
     319        "loose_binding\0"
     320    ;
     321    static const char protocols[] ALIGN1 =
     322        "802.1q\0"
     323        "802.1ad\0"
     324    ;
     325    static const char str_on_off[] ALIGN1 =
     326        "on\0"
     327        "off\0"
     328    ;
     329    enum {
     330        ARG_id = 0,
     331        ARG_reorder_hdr,
     332        ARG_gvrp,
     333        ARG_mvrp,
     334        ARG_loose_binding,
     335        ARG_protocol,
     336    };
     337    enum {
     338        PROTO_8021Q = 0,
     339        PROTO_8021AD,
     340    };
     341    enum {
     342        PARM_on = 0,
     343        PARM_off
     344    };
     345    int arg;
     346    uint16_t id, proto;
     347    struct ifla_vlan_flags flags = {};
     348
     349    while (*argv) {
     350        arg = index_in_substrings(keywords, *argv);
     351        if (arg < 0)
     352            invarg_1_to_2(*argv, "type vlan");
     353
     354        NEXT_ARG();
     355        if (arg == ARG_id) {
     356            id = get_u16(*argv, "id");
     357            addattr_l(n, size, IFLA_VLAN_ID, &id, sizeof(id));
     358        } else if (arg == ARG_protocol) {
     359            arg = index_in_substrings(protocols, *argv);
     360            if (arg == PROTO_8021Q)
     361                proto = ETH_P_8021Q;
     362            else if (arg == PROTO_8021AD)
     363                proto = ETH_P_8021AD;
     364            else
     365                bb_error_msg_and_die("unknown VLAN encapsulation protocol '%s'",
     366                                     *argv);
     367            addattr_l(n, size, IFLA_VLAN_PROTOCOL, &proto, sizeof(proto));
     368        } else {
     369            int param = index_in_strings(str_on_off, *argv);
     370            if (param < 0)
     371                die_must_be_on_off(nth_string(keywords, arg));
     372
     373            if (arg == ARG_reorder_hdr) {
     374                flags.mask |= VLAN_FLAG_REORDER_HDR;
     375                flags.flags &= ~VLAN_FLAG_REORDER_HDR;
     376                if (param == PARM_on)
     377                    flags.flags |= VLAN_FLAG_REORDER_HDR;
     378            } else if (arg == ARG_gvrp) {
     379                flags.mask |= VLAN_FLAG_GVRP;
     380                flags.flags &= ~VLAN_FLAG_GVRP;
     381                if (param == PARM_on)
     382                    flags.flags |= VLAN_FLAG_GVRP;
     383            } else if (arg == ARG_mvrp) {
     384                flags.mask |= VLAN_FLAG_MVRP;
     385                flags.flags &= ~VLAN_FLAG_MVRP;
     386                if (param == PARM_on)
     387                    flags.flags |= VLAN_FLAG_MVRP;
     388            } else { /*if (arg == ARG_loose_binding) */
     389                flags.mask |= VLAN_FLAG_LOOSE_BINDING;
     390                flags.flags &= ~VLAN_FLAG_LOOSE_BINDING;
     391                if (param == PARM_on)
     392                    flags.flags |= VLAN_FLAG_LOOSE_BINDING;
     393            }
     394        }
     395        argv++;
     396    }
     397
     398    if (flags.mask)
     399        addattr_l(n, size, IFLA_VLAN_FLAGS, &flags, sizeof(flags));
     400}
     401
    280402#ifndef NLMSG_TAIL
    281403#define NLMSG_TAIL(nmsg) \
     
    283405#endif
    284406/* Return value becomes exitcode. It's okay to not return at all */
    285 static int do_change(char **argv, const unsigned rtm)
     407static int do_add_or_delete(char **argv, const unsigned rtm)
    286408{
    287409    static const char keywords[] ALIGN1 =
    288         "link\0""name\0""type\0""dev\0";
     410        "link\0""name\0""type\0""dev\0""address\0";
    289411    enum {
    290412        ARG_link,
     
    292414        ARG_type,
    293415        ARG_dev,
     416        ARG_address,
    294417    };
    295418    struct rtnl_handle rth;
     
    300423    } req;
    301424    smalluint arg;
    302     char *name_str = NULL, *link_str = NULL, *type_str = NULL, *dev_str = NULL;
     425    char *name_str = NULL;
     426    char *link_str = NULL;
     427    char *type_str = NULL;
     428    char *dev_str = NULL;
     429    char *address_str = NULL;
    303430
    304431    memset(&req, 0, sizeof(req));
     
    313440    while (*argv) {
    314441        arg = index_in_substrings(keywords, *argv);
     442        if (arg == ARG_type) {
     443            NEXT_ARG();
     444            type_str = *argv++;
     445            dbg("type_str:'%s'", type_str);
     446            break;
     447        }
    315448        if (arg == ARG_link) {
    316449            NEXT_ARG();
    317450            link_str = *argv;
     451            dbg("link_str:'%s'", link_str);
    318452        } else if (arg == ARG_name) {
    319453            NEXT_ARG();
    320454            name_str = *argv;
    321         } else if (arg == ARG_type) {
    322             NEXT_ARG();
    323             type_str = *argv;
     455            dbg("name_str:'%s'", name_str);
     456        } else if (arg == ARG_address) {
     457            NEXT_ARG();
     458            address_str = *argv;
     459            dbg("address_str:'%s'", name_str);
    324460        } else {
    325461            if (arg == ARG_dev) {
     
    329465            }
    330466            dev_str = *argv;
     467            dbg("dev_str:'%s'", dev_str);
    331468        }
    332469        argv++;
     
    340477        addattr_l(&req.n, sizeof(req), IFLA_INFO_KIND, type_str,
    341478                strlen(type_str));
     479
     480        if (*argv) {
     481            struct rtattr *data = NLMSG_TAIL(&req.n);
     482            addattr_l(&req.n, sizeof(req), IFLA_INFO_DATA, NULL, 0);
     483
     484            if (strcmp(type_str, "vlan") == 0)
     485                vlan_parse_opt(argv, &req.n, sizeof(req));
     486
     487            data->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)data;
     488        }
     489
    342490        linkinfo->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)linkinfo;
    343491    }
     
    353501            addattr_l(&req.n, sizeof(req), IFLA_LINK, &idx, 4);
    354502        }
     503        if (address_str) {
     504            unsigned char abuf[32];
     505            int len = ll_addr_a2n(abuf, sizeof(abuf), address_str);
     506            dbg("address len:%d", len);
     507            if (len < 0)
     508                return -1;
     509            addattr_l(&req.n, sizeof(req), IFLA_ADDRESS, abuf, len);
     510        }
    355511    }
    356512    if (name_str) {
    357513        const size_t name_len = strlen(name_str) + 1;
    358514        if (name_len < 2 || name_len > IFNAMSIZ)
    359             invarg(name_str, "name");
     515            invarg_1_to_2(name_str, "name");
    360516        addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name_str, name_len);
    361517    }
     
    365521}
    366522
     523/* Other keywords recognized by iproute2-3.12.0: */
     524#if 0
     525        } else if (matches(*argv, "broadcast") == 0 ||
     526                strcmp(*argv, "brd") == 0) {
     527            NEXT_ARG();
     528            len = ll_addr_a2n(abuf, sizeof(abuf), *argv);
     529            if (len < 0)
     530                return -1;
     531            addattr_l(&req->n, sizeof(*req), IFLA_BROADCAST, abuf, len);
     532        } else if (matches(*argv, "txqueuelen") == 0 ||
     533                strcmp(*argv, "qlen") == 0 ||
     534                matches(*argv, "txqlen") == 0) {
     535            NEXT_ARG();
     536            if (qlen != -1)
     537                duparg("txqueuelen", *argv);
     538            if (get_integer(&qlen,  *argv, 0))
     539                invarg_1_to_2(*argv, "txqueuelen");
     540            addattr_l(&req->n, sizeof(*req), IFLA_TXQLEN, &qlen, 4);
     541        } else if (strcmp(*argv, "mtu") == 0) {
     542            NEXT_ARG();
     543            if (mtu != -1)
     544                duparg("mtu", *argv);
     545            if (get_integer(&mtu, *argv, 0))
     546                invarg_1_to_2(*argv, "mtu");
     547            addattr_l(&req->n, sizeof(*req), IFLA_MTU, &mtu, 4);
     548                } else if (strcmp(*argv, "netns") == 0) {
     549                        NEXT_ARG();
     550                        if (netns != -1)
     551                                duparg("netns", *argv);
     552            if ((netns = get_netns_fd(*argv)) >= 0)
     553                addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_FD, &netns, 4);
     554            else if (get_integer(&netns, *argv, 0) == 0)
     555                addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_PID, &netns, 4);
     556            else
     557                                invarg_1_to_2(*argv, "netns");
     558        } else if (strcmp(*argv, "multicast") == 0) {
     559            NEXT_ARG();
     560            req->i.ifi_change |= IFF_MULTICAST;
     561            if (strcmp(*argv, "on") == 0) {
     562                req->i.ifi_flags |= IFF_MULTICAST;
     563            } else if (strcmp(*argv, "off") == 0) {
     564                req->i.ifi_flags &= ~IFF_MULTICAST;
     565            } else
     566                return on_off("multicast", *argv);
     567        } else if (strcmp(*argv, "allmulticast") == 0) {
     568            NEXT_ARG();
     569            req->i.ifi_change |= IFF_ALLMULTI;
     570            if (strcmp(*argv, "on") == 0) {
     571                req->i.ifi_flags |= IFF_ALLMULTI;
     572            } else if (strcmp(*argv, "off") == 0) {
     573                req->i.ifi_flags &= ~IFF_ALLMULTI;
     574            } else
     575                return on_off("allmulticast", *argv);
     576        } else if (strcmp(*argv, "promisc") == 0) {
     577            NEXT_ARG();
     578            req->i.ifi_change |= IFF_PROMISC;
     579            if (strcmp(*argv, "on") == 0) {
     580                req->i.ifi_flags |= IFF_PROMISC;
     581            } else if (strcmp(*argv, "off") == 0) {
     582                req->i.ifi_flags &= ~IFF_PROMISC;
     583            } else
     584                return on_off("promisc", *argv);
     585        } else if (strcmp(*argv, "trailers") == 0) {
     586            NEXT_ARG();
     587            req->i.ifi_change |= IFF_NOTRAILERS;
     588            if (strcmp(*argv, "off") == 0) {
     589                req->i.ifi_flags |= IFF_NOTRAILERS;
     590            } else if (strcmp(*argv, "on") == 0) {
     591                req->i.ifi_flags &= ~IFF_NOTRAILERS;
     592            } else
     593                return on_off("trailers", *argv);
     594        } else if (strcmp(*argv, "arp") == 0) {
     595            NEXT_ARG();
     596            req->i.ifi_change |= IFF_NOARP;
     597            if (strcmp(*argv, "on") == 0) {
     598                req->i.ifi_flags &= ~IFF_NOARP;
     599            } else if (strcmp(*argv, "off") == 0) {
     600                req->i.ifi_flags |= IFF_NOARP;
     601            } else
     602                return on_off("noarp", *argv);
     603        } else if (strcmp(*argv, "vf") == 0) {
     604            struct rtattr *vflist;
     605            NEXT_ARG();
     606            if (get_integer(&vf,  *argv, 0)) {
     607                invarg_1_to_2(*argv, "vf");
     608            }
     609            vflist = addattr_nest(&req->n, sizeof(*req),
     610                          IFLA_VFINFO_LIST);
     611            len = iplink_parse_vf(vf, &argc, &argv, req);
     612            if (len < 0)
     613                return -1;
     614            addattr_nest_end(&req->n, vflist);
     615        } else if (matches(*argv, "master") == 0) {
     616            int ifindex;
     617            NEXT_ARG();
     618            ifindex = ll_name_to_index(*argv);
     619            if (!ifindex)
     620                invarg_1_to_2(*argv, "master");
     621            addattr_l(&req->n, sizeof(*req), IFLA_MASTER,
     622                  &ifindex, 4);
     623        } else if (matches(*argv, "nomaster") == 0) {
     624            int ifindex = 0;
     625            addattr_l(&req->n, sizeof(*req), IFLA_MASTER,
     626                  &ifindex, 4);
     627        } else if (matches(*argv, "dynamic") == 0) {
     628            NEXT_ARG();
     629            req->i.ifi_change |= IFF_DYNAMIC;
     630            if (strcmp(*argv, "on") == 0) {
     631                req->i.ifi_flags |= IFF_DYNAMIC;
     632            } else if (strcmp(*argv, "off") == 0) {
     633                req->i.ifi_flags &= ~IFF_DYNAMIC;
     634            } else
     635                return on_off("dynamic", *argv);
     636        } else if (matches(*argv, "alias") == 0) {
     637            NEXT_ARG();
     638            addattr_l(&req->n, sizeof(*req), IFLA_IFALIAS,
     639                  *argv, strlen(*argv));
     640            argc--; argv++;
     641            break;
     642        } else if (strcmp(*argv, "group") == 0) {
     643            NEXT_ARG();
     644            if (*group != -1)
     645                duparg("group", *argv);
     646            if (rtnl_group_a2n(group, *argv))
     647                invarg_1_to_2(*argv, "group");
     648        } else if (strcmp(*argv, "mode") == 0) {
     649            int mode;
     650            NEXT_ARG();
     651            mode = get_link_mode(*argv);
     652            if (mode < 0)
     653                invarg_1_to_2(*argv, "mode");
     654            addattr8(&req->n, sizeof(*req), IFLA_LINKMODE, mode);
     655        } else if (strcmp(*argv, "state") == 0) {
     656            int state;
     657            NEXT_ARG();
     658            state = get_operstate(*argv);
     659            if (state < 0)
     660                invarg_1_to_2(*argv, "state");
     661            addattr8(&req->n, sizeof(*req), IFLA_OPERSTATE, state);
     662        } else if (matches(*argv, "numtxqueues") == 0) {
     663            NEXT_ARG();
     664            if (numtxqueues != -1)
     665                duparg("numtxqueues", *argv);
     666            if (get_integer(&numtxqueues, *argv, 0))
     667                invarg_1_to_2(*argv, "numtxqueues");
     668            addattr_l(&req->n, sizeof(*req), IFLA_NUM_TX_QUEUES,
     669                  &numtxqueues, 4);
     670        } else if (matches(*argv, "numrxqueues") == 0) {
     671            NEXT_ARG();
     672            if (numrxqueues != -1)
     673                duparg("numrxqueues", *argv);
     674            if (get_integer(&numrxqueues, *argv, 0))
     675                invarg_1_to_2(*argv, "numrxqueues");
     676            addattr_l(&req->n, sizeof(*req), IFLA_NUM_RX_QUEUES,
     677                  &numrxqueues, 4);
     678        }
     679#endif
     680
    367681/* Return value becomes exitcode. It's okay to not return at all */
    368682int FAST_FUNC do_iplink(char **argv)
     
    371685        "add\0""delete\0""set\0""show\0""lst\0""list\0";
    372686    if (*argv) {
    373         smalluint key = index_in_substrings(keywords, *argv);
    374         if (key > 5) /* invalid argument */
    375             bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
     687        int key = index_in_substrings(keywords, *argv);
     688        if (key < 0) /* invalid argument */
     689            invarg_1_to_2(*argv, applet_name);
    376690        argv++;
    377691        if (key <= 1) /* add/delete */
    378             return do_change(argv, key ? RTM_DELLINK : RTM_NEWLINK);
    379         else if (key == 2) /* set */
     692            return do_add_or_delete(argv, key ? RTM_DELLINK : RTM_NEWLINK);
     693        if (key == 2) /* set */
    380694            return do_set(argv);
    381695    }
  • branches/3.3/mindi-busybox/networking/libiproute/iproute.c

    r3232 r3621  
    1212
    1313#include "ip_common.h"  /* #include "libbb.h" is inside */
     14#include "common_bufsiz.h"
    1415#include "rt_names.h"
    1516#include "utils.h"
     
    4445typedef struct filter_t filter_t;
    4546
    46 #define G_filter (*(filter_t*)&bb_common_bufsiz1)
     47#define G_filter (*(filter_t*)bb_common_bufsiz1)
     48#define INIT_G() do { setup_common_bufsiz(); } while (0)
    4749
    4850static int flush_update(void)
     
    5456    G_filter.flushp = 0;
    5557    return 0;
    56 }
    57 
    58 static unsigned get_hz(void)
    59 {
    60     static unsigned hz_internal;
    61     FILE *fp;
    62 
    63     if (hz_internal)
    64         return hz_internal;
    65 
    66     fp = fopen_for_read("/proc/net/psched");
    67     if (fp) {
    68         unsigned nom, denom;
    69 
    70         if (fscanf(fp, "%*08x%*08x%08x%08x", &nom, &denom) == 2)
    71             if (nom == 1000000)
    72                 hz_internal = denom;
    73         fclose(fp);
    74     }
    75     if (!hz_internal)
    76         hz_internal = sysconf(_SC_CLK_TCK);
    77     return hz_internal;
    7858}
    7959
     
    8464    int len = n->nlmsg_len;
    8565    struct rtattr *tb[RTA_MAX+1];
    86     char abuf[256];
    8766    inet_prefix dst;
    8867    inet_prefix src;
    8968    int host_len = -1;
    90     SPRINT_BUF(b1);
    9169
    9270    if (n->nlmsg_type != RTM_NEWROUTE && n->nlmsg_type != RTM_DELROUTE) {
     
    219197        if (NLMSG_ALIGN(G_filter.flushp) + n->nlmsg_len > G_filter.flushe) {
    220198            if (flush_update())
    221                 bb_error_msg_and_die("flush");
     199                xfunc_die();
    222200        }
    223201        fn = (void*)(G_filter.flushb + NLMSG_ALIGN(G_filter.flushp));
     
    237215    }
    238216    if (r->rtm_type != RTN_UNICAST /* && !G_filter.type - always 0 */) {
    239         printf("%s ", rtnl_rtntype_n2a(r->rtm_type, b1));
     217        printf("%s ", rtnl_rtntype_n2a(r->rtm_type));
    240218    }
    241219
    242220    if (tb[RTA_DST]) {
    243221        if (r->rtm_dst_len != host_len) {
    244             printf("%s/%u ", rt_addr_n2a(r->rtm_family,
    245                         RTA_DATA(tb[RTA_DST]),
    246                         abuf, sizeof(abuf)),
    247                     r->rtm_dst_len
    248                     );
     222            printf("%s/%u ",
     223                rt_addr_n2a(r->rtm_family, RTA_DATA(tb[RTA_DST])),
     224                r->rtm_dst_len
     225            );
    249226        } else {
    250227            printf("%s ", format_host(r->rtm_family,
    251228                        RTA_PAYLOAD(tb[RTA_DST]),
    252                         RTA_DATA(tb[RTA_DST]),
    253                         abuf, sizeof(abuf))
    254                     );
     229                        RTA_DATA(tb[RTA_DST]))
     230            );
    255231        }
    256232    } else if (r->rtm_dst_len) {
     
    261237    if (tb[RTA_SRC]) {
    262238        if (r->rtm_src_len != host_len) {
    263             printf("from %s/%u ", rt_addr_n2a(r->rtm_family,
    264                         RTA_DATA(tb[RTA_SRC]),
    265                         abuf, sizeof(abuf)),
    266                     r->rtm_src_len
    267                     );
     239            printf("from %s/%u ",
     240                rt_addr_n2a(r->rtm_family, RTA_DATA(tb[RTA_SRC])),
     241                r->rtm_src_len
     242            );
    268243        } else {
    269244            printf("from %s ", format_host(r->rtm_family,
    270245                        RTA_PAYLOAD(tb[RTA_SRC]),
    271                         RTA_DATA(tb[RTA_SRC]),
    272                         abuf, sizeof(abuf))
    273                     );
     246                        RTA_DATA(tb[RTA_SRC]))
     247            );
    274248        }
    275249    } else if (r->rtm_src_len) {
     
    279253        printf("via %s ", format_host(r->rtm_family,
    280254                    RTA_PAYLOAD(tb[RTA_GATEWAY]),
    281                     RTA_DATA(tb[RTA_GATEWAY]),
    282                     abuf, sizeof(abuf)));
     255                    RTA_DATA(tb[RTA_GATEWAY]))
     256        );
    283257    }
    284258    if (tb[RTA_OIF]) {
     
    293267         */
    294268        printf(" src %s ", rt_addr_n2a(r->rtm_family,
    295                     RTA_DATA(tb[RTA_PREFSRC]),
    296                     abuf, sizeof(abuf)));
     269                    RTA_DATA(tb[RTA_PREFSRC])));
    297270    }
    298271    if (tb[RTA_PRIORITY]) {
    299272        printf(" metric %d ", *(uint32_t*)RTA_DATA(tb[RTA_PRIORITY]));
    300273    }
     274    if (r->rtm_flags & RTNH_F_DEAD) {
     275        printf("dead ");
     276    }
     277    if (r->rtm_flags & RTNH_F_ONLINK) {
     278        printf("onlink ");
     279    }
     280    if (r->rtm_flags & RTNH_F_PERVASIVE) {
     281        printf("pervasive ");
     282    }
     283    if (r->rtm_flags & RTM_F_NOTIFY) {
     284        printf("notify ");
     285    }
     286
    301287    if (r->rtm_family == AF_INET6) {
    302288        struct rta_cacheinfo *ci = NULL;
     
    330316{
    331317    static const char keywords[] ALIGN1 =
    332         "src\0""via\0""mtu\0""lock\0""protocol\0"IF_FEATURE_IP_RULE("table\0")
    333         "dev\0""oif\0""to\0""metric\0";
     318        "src\0""via\0""mtu\0""lock\0""scope\0""protocol\0"IF_FEATURE_IP_RULE("table\0")
     319        "dev\0""oif\0""to\0""metric\0""onlink\0";
    334320    enum {
    335321        ARG_src,
    336322        ARG_via,
    337323        ARG_mtu, PARM_lock,
     324        ARG_scope,
    338325        ARG_protocol,
    339326IF_FEATURE_IP_RULE(ARG_table,)
     
    342329        ARG_to,
    343330        ARG_metric,
     331        ARG_onlink,
    344332    };
    345333    enum {
     
    360348    char *d = NULL;
    361349    smalluint ok = 0;
     350    smalluint scope_ok = 0;
    362351    int arg;
    363352
     
    368357    req.n.nlmsg_type = cmd;
    369358    req.r.rtm_family = preferred_family;
    370     if (RT_TABLE_MAIN) /* if it is zero, memset already did it */
     359    if (RT_TABLE_MAIN != 0) /* if it is zero, memset already did it */
    371360        req.r.rtm_table = RT_TABLE_MAIN;
    372     if (RT_SCOPE_NOWHERE)
     361    if (RT_SCOPE_NOWHERE != 0)
    373362        req.r.rtm_scope = RT_SCOPE_NOWHERE;
    374363
    375364    if (cmd != RTM_DELROUTE) {
    376         req.r.rtm_protocol = RTPROT_BOOT;
    377365        req.r.rtm_scope = RT_SCOPE_UNIVERSE;
    378         req.r.rtm_type = RTN_UNICAST;
     366        if (RTPROT_BOOT != 0)
     367            req.r.rtm_protocol = RTPROT_BOOT;
     368        if (RTN_UNICAST != 0)
     369            req.r.rtm_type = RTN_UNICAST;
    379370    }
    380371
     
    409400            mtu = get_unsigned(*argv, "mtu");
    410401            rta_addattr32(mxrta, sizeof(mxbuf), RTAX_MTU, mtu);
     402        } else if (arg == ARG_scope) {
     403            uint32_t scope;
     404            NEXT_ARG();
     405            if (rtnl_rtscope_a2n(&scope, *argv))
     406                invarg_1_to_2(*argv, "scope");
     407            req.r.rtm_scope = scope;
     408            scope_ok = 1;
    411409        } else if (arg == ARG_protocol) {
    412410            uint32_t prot;
    413411            NEXT_ARG();
    414412            if (rtnl_rtprot_a2n(&prot, *argv))
    415                 invarg(*argv, "protocol");
     413                invarg_1_to_2(*argv, "protocol");
    416414            req.r.rtm_protocol = prot;
    417415            ok |= proto_ok;
     
    421419            NEXT_ARG();
    422420            if (rtnl_rttable_a2n(&tid, *argv))
    423                 invarg(*argv, "table");
     421                invarg_1_to_2(*argv, "table");
    424422            req.r.rtm_table = tid;
    425423#endif
     
    432430            metric = get_u32(*argv, "metric");
    433431            addattr32(&req.n, sizeof(req), RTA_PRIORITY, metric);
     432        } else if (arg == ARG_onlink) {
     433            req.r.rtm_flags |= RTNH_F_ONLINK;
    434434        } else {
    435435            int type;
     
    483483    }
    484484
    485     if (req.r.rtm_type == RTN_LOCAL || req.r.rtm_type == RTN_NAT)
    486         req.r.rtm_scope = RT_SCOPE_HOST;
    487     else
    488     if (req.r.rtm_type == RTN_BROADCAST
    489      || req.r.rtm_type == RTN_MULTICAST
    490      || req.r.rtm_type == RTN_ANYCAST
    491     ) {
    492         req.r.rtm_scope = RT_SCOPE_LINK;
    493     }
    494     else if (req.r.rtm_type == RTN_UNICAST || req.r.rtm_type == RTN_UNSPEC) {
    495         if (cmd == RTM_DELROUTE)
    496             req.r.rtm_scope = RT_SCOPE_NOWHERE;
    497         else if (!(ok & gw_ok))
     485    if (!scope_ok) {
     486        if (req.r.rtm_type == RTN_LOCAL || req.r.rtm_type == RTN_NAT)
     487            req.r.rtm_scope = RT_SCOPE_HOST;
     488        else
     489        if (req.r.rtm_type == RTN_BROADCAST
     490         || req.r.rtm_type == RTN_MULTICAST
     491         || req.r.rtm_type == RTN_ANYCAST
     492        ) {
    498493            req.r.rtm_scope = RT_SCOPE_LINK;
     494        }
     495        else if (req.r.rtm_type == RTN_UNICAST || req.r.rtm_type == RTN_UNSPEC) {
     496            if (cmd == RTM_DELROUTE)
     497                req.r.rtm_scope = RT_SCOPE_NOWHERE;
     498            else if (!(ok & gw_ok))
     499                req.r.rtm_scope = RT_SCOPE_LINK;
     500        }
    499501    }
    500502
     
    605607            if (rtnl_rtprot_a2n(&prot, *argv)) {
    606608                if (index_in_strings(keywords, *argv) != KW_all)
    607                     invarg(*argv, "protocol");
     609                    invarg_1_to_2(*argv, "protocol");
    608610                prot = 0;
    609611                //G_filter.protocolmask = 0;
     
    630632                uint32_t tid;
    631633                if (rtnl_rttable_a2n(&tid, *argv))
    632                     invarg(*argv, "table");
     634                    invarg_1_to_2(*argv, "table");
    633635                G_filter.tb = tid;
    634636#else
    635                 invarg(*argv, "table");
     637                invarg_1_to_2(*argv, "table");
    636638#endif
    637639            }
     
    901903    unsigned flags = 0;
    902904    int cmd = RTM_NEWROUTE;
     905
     906    INIT_G();
    903907
    904908    if (!*argv)
     
    940944            return iproute_list_or_flush(argv+1, 1);
    941945        default:
    942             bb_error_msg_and_die("unknown command %s", *argv);
     946            invarg_1_to_2(*argv, applet_name);
    943947    }
    944948
  • branches/3.3/mindi-busybox/networking/libiproute/iprule.c

    r3232 r3621  
    4545    int host_len = -1;
    4646    struct rtattr * tb[RTA_MAX+1];
    47     char abuf[256];
    48     SPRINT_BUF(b1);
    4947
    5048    if (n->nlmsg_type != RTM_NEWRULE)
     
    7371    if (tb[RTA_SRC]) {
    7472        if (r->rtm_src_len != host_len) {
    75             printf("%s/%u", rt_addr_n2a(r->rtm_family,
    76                             RTA_DATA(tb[RTA_SRC]),
    77                             abuf, sizeof(abuf)),
     73            printf("%s/%u",
     74                rt_addr_n2a(r->rtm_family, RTA_DATA(tb[RTA_SRC])),
    7875                r->rtm_src_len
    7976            );
     
    8178            fputs(format_host(r->rtm_family,
    8279                        RTA_PAYLOAD(tb[RTA_SRC]),
    83                         RTA_DATA(tb[RTA_SRC]),
    84                         abuf, sizeof(abuf)),
     80                        RTA_DATA(tb[RTA_SRC])),
    8581                stdout
    8682            );
     
    9692        if (r->rtm_dst_len != host_len) {
    9793            printf("to %s/%u ", rt_addr_n2a(r->rtm_family,
    98                              RTA_DATA(tb[RTA_DST]),
    99                              abuf, sizeof(abuf)),
     94                             RTA_DATA(tb[RTA_DST])),
    10095                r->rtm_dst_len
    10196                );
     
    10398            printf("to %s ", format_host(r->rtm_family,
    10499                               RTA_PAYLOAD(tb[RTA_DST]),
    105                                RTA_DATA(tb[RTA_DST]),
    106                                abuf, sizeof(abuf)));
     100                               RTA_DATA(tb[RTA_DST])));
    107101        }
    108102    } else if (r->rtm_dst_len) {
     
    111105
    112106    if (r->rtm_tos) {
    113         printf("tos %s ", rtnl_dsfield_n2a(r->rtm_tos, b1));
     107        printf("tos %s ", rtnl_dsfield_n2a(r->rtm_tos));
    114108    }
    115109    if (tb[RTA_PROTOINFO]) {
     
    122116
    123117    if (r->rtm_table)
    124         printf("lookup %s ", rtnl_rttable_n2a(r->rtm_table, b1));
     118        printf("lookup %s ", rtnl_rttable_n2a(r->rtm_table));
    125119
    126120    if (tb[RTA_FLOW]) {
     
    130124        if (from) {
    131125            printf("realms %s/",
    132                 rtnl_rtrealm_n2a(from, b1));
     126                rtnl_rtrealm_n2a(from));
    133127        }
    134128        printf("%s ",
    135             rtnl_rtrealm_n2a(to, b1));
     129            rtnl_rtrealm_n2a(to));
    136130    }
    137131
     
    141135                format_host(r->rtm_family,
    142136                        RTA_PAYLOAD(tb[RTA_GATEWAY]),
    143                         RTA_DATA(tb[RTA_GATEWAY]),
    144                         abuf, sizeof(abuf)));
     137                        RTA_DATA(tb[RTA_GATEWAY]))
     138            );
    145139        } else
    146140            printf("masquerade");
    147141    } else if (r->rtm_type != RTN_UNICAST)
    148         fputs(rtnl_rtntype_n2a(r->rtm_type, b1), stdout);
     142        fputs(rtnl_rtntype_n2a(r->rtm_type), stdout);
    149143
    150144    bb_putchar('\n');
     
    216210        key = index_in_substrings(keywords, *argv) + 1;
    217211        if (key == 0) /* no match found in keywords array, bail out. */
    218             bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
     212            invarg_1_to_2(*argv, applet_name);
    219213        if (key == ARG_from) {
    220214            inet_prefix dst;
     
    241235            NEXT_ARG();
    242236            if (rtnl_dsfield_a2n(&tos, *argv))
    243                 invarg(*argv, "TOS");
     237                invarg_1_to_2(*argv, "TOS");
    244238            req.r.rtm_tos = tos;
    245239        } else if (key == ARG_fwmark) {
     
    252246            NEXT_ARG();
    253247            if (get_rt_realms(&realm, *argv))
    254                 invarg(*argv, "realms");
     248                invarg_1_to_2(*argv, "realms");
    255249            addattr32(&req.n, sizeof(req), RTA_FLOW, realm);
    256250        } else if (key == ARG_table ||
     
    260254            NEXT_ARG();
    261255            if (rtnl_rttable_a2n(&tid, *argv))
    262                 invarg(*argv, "table ID");
     256                invarg_1_to_2(*argv, "table ID");
    263257            req.r.rtm_table = tid;
    264258            table_ok = 1;
     
    283277                bb_show_usage();
    284278            if (rtnl_rtntype_a2n(&type, *argv))
    285                 invarg(*argv, "type");
     279                invarg_1_to_2(*argv, "type");
    286280            req.r.rtm_type = type;
    287281        }
     
    309303        "add\0""delete\0""list\0""show\0";
    310304    if (*argv) {
    311         smalluint cmd = index_in_substrings(ip_rule_commands, *argv);
    312         if (cmd > 3)
    313             bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
     305        int cmd = index_in_substrings(ip_rule_commands, *argv);
     306        if (cmd < 0)
     307            invarg_1_to_2(*argv, applet_name);
    314308        argv++;
    315309        if (cmd < 2)
  • branches/3.3/mindi-busybox/networking/libiproute/iptunnel.c

    r3232 r3621  
    295295                uval = get_unsigned(*argv, "TTL");
    296296                if (uval > 255)
    297                     invarg(*argv, "TTL must be <=255");
     297                    invarg_1_to_2(*argv, "TTL");
    298298                p->iph.ttl = uval;
    299299            }
     
    306306            if (key != ARG_inherit) {
    307307                if (rtnl_dsfield_a2n(&uval, *argv))
    308                     invarg(*argv, "TOS");
     308                    invarg_1_to_2(*argv, "TOS");
    309309                p->iph.tos = uval;
    310310            } else
     
    405405static void print_tunnel(struct ip_tunnel_parm *p)
    406406{
    407     char s1[256];
    408     char s2[256];
    409     char s3[64];
    410     char s4[64];
    411 
    412     format_host(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1));
    413     format_host(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2));
    414     inet_ntop(AF_INET, &p->i_key, s3, sizeof(s3));
    415     inet_ntop(AF_INET, &p->o_key, s4, sizeof(s4));
     407    char s3[INET_ADDRSTRLEN];
     408    char s4[INET_ADDRSTRLEN];
    416409
    417410    printf("%s: %s/ip  remote %s  local %s ",
    418            p->name,
    419            p->iph.protocol == IPPROTO_IPIP ? "ip" :
    420            (p->iph.protocol == IPPROTO_GRE ? "gre" :
    421         (p->iph.protocol == IPPROTO_IPV6 ? "ipv6" : "unknown")),
    422            p->iph.daddr ? s1 : "any", p->iph.saddr ? s2 : "any");
     411        p->name,
     412        p->iph.protocol == IPPROTO_IPIP ? "ip" :
     413            p->iph.protocol == IPPROTO_GRE ? "gre" :
     414            p->iph.protocol == IPPROTO_IPV6 ? "ipv6" :
     415            "unknown",
     416        p->iph.daddr ? format_host(AF_INET, 4, &p->iph.daddr) : "any",
     417        p->iph.saddr ? format_host(AF_INET, 4, &p->iph.saddr) : "any"
     418    );
    423419    if (p->link) {
    424420        char *n = do_ioctl_get_ifname(p->link);
     
    433429        printf(" ttl inherit ");
    434430    if (p->iph.tos) {
    435         SPRINT_BUF(b1);
    436431        printf(" tos");
    437432        if (p->iph.tos & 1)
     
    439434        if (p->iph.tos & ~1)
    440435            printf("%c%s ", p->iph.tos & 1 ? '/' : ' ',
    441                 rtnl_dsfield_n2a(p->iph.tos & ~1, b1));
     436                rtnl_dsfield_n2a(p->iph.tos & ~1));
    442437    }
    443438    if (!(p->iph.frag_off & htons(IP_DF)))
    444439        printf(" nopmtudisc");
    445440
     441    inet_ntop(AF_INET, &p->i_key, s3, sizeof(s3));
     442    inet_ntop(AF_INET, &p->o_key, s4, sizeof(s4));
    446443    if ((p->i_flags & GRE_KEY) && (p->o_flags & GRE_KEY) && p->o_key == p->i_key)
    447444        printf(" key %s", s3);
    448     else if ((p->i_flags | p->o_flags) & GRE_KEY) {
     445    else {
    449446        if (p->i_flags & GRE_KEY)
    450447            printf(" ikey %s ", s3);
     
    562559
    563560    if (*argv) {
    564         smalluint key = index_in_substrings(keywords, *argv);
    565         if (key > 5)
    566             bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
     561        int key = index_in_substrings(keywords, *argv);
     562        if (key < 0)
     563            invarg_1_to_2(*argv, applet_name);
    567564        argv++;
    568565        if (key == ARG_add)
  • branches/3.3/mindi-busybox/networking/libiproute/libnetlink.c

    r3232 r3621  
    7272    struct sockaddr_nl nladdr;
    7373    struct iovec iov[2] = { { &nlh, sizeof(nlh) }, { req, len } };
     74    /* Use designated initializers, struct layout is non-portable */
    7475    struct msghdr msg = {
    75         (void*)&nladdr, sizeof(nladdr),
    76         iov,  2,
    77         NULL, 0,
    78         0
     76        .msg_name = (void*)&nladdr,
     77        .msg_namelen = sizeof(nladdr),
     78        .msg_iov = iov,
     79        .msg_iovlen = 2,
     80        .msg_control = NULL,
     81        .msg_controllen = 0,
     82        .msg_flags = 0
    7983    };
    8084
     
    105109        int status;
    106110        struct nlmsghdr *h;
    107 
     111        /* Use designated initializers, struct layout is non-portable */
    108112        struct msghdr msg = {
    109             (void*)&nladdr, sizeof(nladdr),
    110             &iov, 1,
    111             NULL, 0,
    112             0
     113            .msg_name = (void*)&nladdr,
     114            .msg_namelen = sizeof(nladdr),
     115            .msg_iov = &iov,
     116            .msg_iovlen = 1,
     117            .msg_control = NULL,
     118            .msg_controllen = 0,
     119            .msg_flags = 0
    113120        };
    114121
     
    212219    struct iovec iov = { (void*)n, n->nlmsg_len };
    213220    char   *buf = xmalloc(8*1024); /* avoid big stack buffer */
     221    /* Use designated initializers, struct layout is non-portable */
    214222    struct msghdr msg = {
    215         (void*)&nladdr, sizeof(nladdr),
    216         &iov, 1,
    217         NULL, 0,
    218         0
     223        .msg_name = (void*)&nladdr,
     224        .msg_namelen = sizeof(nladdr),
     225        .msg_iov = &iov,
     226        .msg_iovlen = 1,
     227        .msg_control = NULL,
     228        .msg_controllen = 0,
     229        .msg_flags = 0
    219230    };
    220231
  • branches/3.3/mindi-busybox/networking/libiproute/ll_map.c

    r2725 r3621  
    8787}
    8888
    89 const char FAST_FUNC *ll_idx_n2a(int idx, char *buf)
     89static
     90const char FAST_FUNC *ll_idx_n2a(int idx/*, char *buf*/)
    9091{
    9192    struct idxmap *im;
     
    9697    if (im)
    9798        return im->name;
    98     snprintf(buf, 16, "if%d", idx);
    99     return buf;
     99    //snprintf(buf, 16, "if%d", idx);
     100    //return buf;
     101    return auto_string(xasprintf("if%d", idx));
    100102}
    101 
    102103
    103104const char FAST_FUNC *ll_index_to_name(int idx)
    104105{
    105     static char nbuf[16];
    106 
    107     return ll_idx_n2a(idx, nbuf);
     106    //static char nbuf[16];
     107    return ll_idx_n2a(idx/*, nbuf*/);
    108108}
    109109
     
    137137{
    138138    int ret = 0;
    139     int sock_fd;
    140139
    141140/* caching is not warranted - no users which repeatedly call it */
     
    165164        }
    166165    }
    167     /* We have not found the interface in our cache, but the kernel
    168      * may still know about it. One reason is that we may be using
    169      * module on-demand loading, which means that the kernel will
    170      * load the module and make the interface exist only when
    171      * we explicitely request it (check for dev_load() in net/core/dev.c).
    172      * I can think of other similar scenario, but they are less common...
    173      * Jean II */
    174166#endif
    175 
    176     sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
    177     if (sock_fd >= 0) {
    178         struct ifreq ifr;
    179         int tmp;
    180 
    181         strncpy_IFNAMSIZ(ifr.ifr_name, name);
    182         ifr.ifr_ifindex = -1;
    183         tmp = ioctl(sock_fd, SIOCGIFINDEX, &ifr);
    184         close(sock_fd);
    185         if (tmp >= 0)
    186             /* In theory, we should redump the interface list
    187              * to update our cache, this is left as an exercise
    188              * to the reader... Jean II */
    189             ret = ifr.ifr_ifindex;
    190     }
     167    ret = if_nametoindex(name);
    191168/* out:*/
    192169    if (ret <= 0)
  • branches/3.3/mindi-busybox/networking/libiproute/ll_map.h

    r2725 r3621  
    88int ll_init_map(struct rtnl_handle *rth) FAST_FUNC;
    99int xll_name_to_index(const char *name) FAST_FUNC;
     10//static: const char *ll_idx_n2a(int idx, char *buf) FAST_FUNC;
    1011const char *ll_index_to_name(int idx) FAST_FUNC;
    11 const char *ll_idx_n2a(int idx, char *buf) FAST_FUNC;
    1212/* int ll_index_to_type(int idx); */
    1313unsigned ll_index_to_flags(int idx) FAST_FUNC;
  • branches/3.3/mindi-busybox/networking/libiproute/ll_proto.c

    r3232 r3621  
    8585/* Keep declarations above and below in sync! */
    8686
    87 static const char llproto_names[] =
     87static const char llproto_names[] ALIGN1 =
    8888#define __PF(f,n) #n "\0"
    8989__PF(LOOP,loop)
  • branches/3.3/mindi-busybox/networking/libiproute/ll_types.c

    r3232 r3621  
    1717const char* FAST_FUNC ll_type_n2a(int type, char *buf)
    1818{
    19     static const char arphrd_name[] =
     19    static const char arphrd_name[] ALIGN1 =
    2020    /* 0,                  */ "generic" "\0"
    2121    /* ARPHRD_LOOPBACK,    */ "loopback" "\0"
     
    106106    /* Keep these arrays in sync! */
    107107
    108     static const uint16_t arphrd_type[] = {
     108    static const uint16_t arphrd_type[] ALIGN2 = {
    109109    0,                  /* "generic" "\0" */
    110110    ARPHRD_LOOPBACK,    /* "loopback" "\0" */
  • branches/3.3/mindi-busybox/networking/libiproute/rt_names.c

    r2725 r3621  
    1111#include "rt_names.h"
    1212
     13#define CONFDIR          CONFIG_FEATURE_IP_ROUTE_DIR
     14
    1315typedef struct rtnl_tab_t {
    1416    const char *cached_str;
    1517    unsigned cached_result;
    16     const char *tab[256];
     18    /* upstream version switched to a hash table and removed
     19     * id < 256 limit. For now bbox bumps this array size from 256
     20     * to 1024. If you plan to change this to a hash table,
     21     * consider merging several hash tables we have (for example,
     22     * awk has resizable one!
     23     */
     24#define RT_TABLE_MAX 1023
     25    const char *tab[RT_TABLE_MAX+1];
    1726} rtnl_tab_t;
    1827
     
    2029{
    2130    char *token[2];
    22     parser_t *parser = config_open2(file, fopen_for_read);
    23 
     31    char fullname[sizeof(CONFDIR"/rt_dsfield") + 8];
     32    parser_t *parser;
     33
     34    sprintf(fullname, CONFDIR"/rt_%s", file);
     35    parser = config_open2(fullname, fopen_for_read);
    2436    while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) {
    2537        unsigned id = bb_strtou(token[0], NULL, 0);
    26         if (id > 256) {
     38        if (id > RT_TABLE_MAX) {
    2739            bb_error_msg("database %s is corrupted at line %d",
    2840                file, parser->lineno);
     
    4355    }
    4456
    45     for (i = 0; i < 256; i++) {
     57    for (i = 0; i <= RT_TABLE_MAX; i++) {
    4658        if (tab->tab[i]
    4759         && strcmp(tab->tab[i], arg) == 0
     
    5567
    5668    i = bb_strtou(arg, NULL, base);
    57     if (i > 255)
     69    if (i > RT_TABLE_MAX)
    5870        return -1;
    5971    *id = i;
     
    8698    rtnl_rtprot_tab = xzalloc(sizeof(*rtnl_rtprot_tab));
    8799    memcpy(rtnl_rtprot_tab->tab, init_tab, sizeof(init_tab));
    88     rtnl_tab_initialize("/etc/iproute2/rt_protos", rtnl_rtprot_tab->tab);
    89 }
    90 
    91 const char* FAST_FUNC rtnl_rtprot_n2a(int id, char *buf)
    92 {
    93     if (id < 0 || id >= 256) {
    94         sprintf(buf, "%d", id);
    95         return buf;
     100    rtnl_tab_initialize("protos", rtnl_rtprot_tab->tab);
     101}
     102
     103#if 0 /* UNUSED */
     104const char* FAST_FUNC rtnl_rtprot_n2a(int id)
     105{
     106    if (id < 0 || id > RT_TABLE_MAX) {
     107        return itoa(id);
    96108    }
    97109
     
    100112    if (rtnl_rtprot_tab->tab[id])
    101113        return rtnl_rtprot_tab->tab[id];
    102     /* buf is SPRINT_BSIZE big */
    103     sprintf(buf, "%d", id);
    104     return buf;
    105 }
     114    return itoa(id);
     115}
     116#endif
    106117
    107118int FAST_FUNC rtnl_rtprot_a2n(uint32_t *id, char *arg)
     
    124135    rtnl_rtscope_tab->tab[253] = "link";
    125136    rtnl_rtscope_tab->tab[200] = "site";
    126     rtnl_tab_initialize("/etc/iproute2/rt_scopes", rtnl_rtscope_tab->tab);
    127 }
    128 
    129 const char* FAST_FUNC rtnl_rtscope_n2a(int id, char *buf)
    130 {
    131     if (id < 0 || id >= 256) {
    132         sprintf(buf, "%d", id);
    133         return buf;
     137    rtnl_tab_initialize("scopes", rtnl_rtscope_tab->tab);
     138}
     139
     140const char* FAST_FUNC rtnl_rtscope_n2a(int id)
     141{
     142    if (id < 0 || id > RT_TABLE_MAX) {
     143        return itoa(id);
    134144    }
    135145
     
    138148    if (rtnl_rtscope_tab->tab[id])
    139149        return rtnl_rtscope_tab->tab[id];
    140     /* buf is SPRINT_BSIZE big */
    141     sprintf(buf, "%d", id);
    142     return buf;
     150    return itoa(id);
    143151}
    144152
     
    157165    rtnl_rtrealm_tab = xzalloc(sizeof(*rtnl_rtrealm_tab));
    158166    rtnl_rtrealm_tab->tab[0] = "unknown";
    159     rtnl_tab_initialize("/etc/iproute2/rt_realms", rtnl_rtrealm_tab->tab);
     167    rtnl_tab_initialize("realms", rtnl_rtrealm_tab->tab);
    160168}
    161169
     
    167175
    168176#if ENABLE_FEATURE_IP_RULE
    169 const char* FAST_FUNC rtnl_rtrealm_n2a(int id, char *buf)
    170 {
    171     if (id < 0 || id >= 256) {
    172         sprintf(buf, "%d", id);
    173         return buf;
     177const char* FAST_FUNC rtnl_rtrealm_n2a(int id)
     178{
     179    if (id < 0 || id > RT_TABLE_MAX) {
     180        return itoa(id);
    174181    }
    175182
     
    178185    if (rtnl_rtrealm_tab->tab[id])
    179186        return rtnl_rtrealm_tab->tab[id];
    180     /* buf is SPRINT_BSIZE big */
    181     sprintf(buf, "%d", id);
    182     return buf;
     187    return itoa(id);
    183188}
    184189#endif
     
    192197    rtnl_rtdsfield_tab = xzalloc(sizeof(*rtnl_rtdsfield_tab));
    193198    rtnl_rtdsfield_tab->tab[0] = "0";
    194     rtnl_tab_initialize("/etc/iproute2/rt_dsfield", rtnl_rtdsfield_tab->tab);
    195 }
    196 
    197 const char* FAST_FUNC rtnl_dsfield_n2a(int id, char *buf)
    198 {
    199     if (id < 0 || id >= 256) {
    200         sprintf(buf, "%d", id);
    201         return buf;
     199    rtnl_tab_initialize("dsfield", rtnl_rtdsfield_tab->tab);
     200}
     201
     202const char* FAST_FUNC rtnl_dsfield_n2a(int id)
     203{
     204    if (id < 0 || id > RT_TABLE_MAX) {
     205        return itoa(id);
    202206    }
    203207
     
    206210    if (rtnl_rtdsfield_tab->tab[id])
    207211        return rtnl_rtdsfield_tab->tab[id];
    208     /* buf is SPRINT_BSIZE big */
    209     sprintf(buf, "0x%02x", id);
    210     return buf;
     212    return itoa(id);
    211213}
    212214
     
    223225static void rtnl_rttable_initialize(void)
    224226{
    225     if (rtnl_rtdsfield_tab) return;
     227    if (rtnl_rttable_tab)
     228        return;
     229
    226230    rtnl_rttable_tab = xzalloc(sizeof(*rtnl_rttable_tab));
    227231    rtnl_rttable_tab->tab[0] = "unspec";
     
    229233    rtnl_rttable_tab->tab[254] = "main";
    230234    rtnl_rttable_tab->tab[253] = "default";
    231     rtnl_tab_initialize("/etc/iproute2/rt_tables", rtnl_rttable_tab->tab);
    232 }
    233 
    234 const char* FAST_FUNC rtnl_rttable_n2a(int id, char *buf)
    235 {
    236     if (id < 0 || id >= 256) {
    237         sprintf(buf, "%d", id);
    238         return buf;
     235    rtnl_tab_initialize("tables", rtnl_rttable_tab->tab);
     236}
     237
     238const char* FAST_FUNC rtnl_rttable_n2a(int id)
     239{
     240    if (id < 0 || id > RT_TABLE_MAX) {
     241        return itoa(id);
    239242    }
    240243
     
    243246    if (rtnl_rttable_tab->tab[id])
    244247        return rtnl_rttable_tab->tab[id];
    245     /* buf is SPRINT_BSIZE big */
    246     sprintf(buf, "%d", id);
    247     return buf;
     248    return itoa(id);
    248249}
    249250
  • branches/3.3/mindi-busybox/networking/libiproute/rt_names.h

    r2725 r3621  
    55PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
    66
    7 /* buf is SPRINT_BSIZE big */
    8 extern const char* rtnl_rtprot_n2a(int id, char *buf) FAST_FUNC;
    9 extern const char* rtnl_rtscope_n2a(int id, char *buf) FAST_FUNC;
    10 extern const char* rtnl_rtrealm_n2a(int id, char *buf) FAST_FUNC;
    11 extern const char* rtnl_dsfield_n2a(int id, char *buf) FAST_FUNC;
    12 extern const char* rtnl_rttable_n2a(int id, char *buf) FAST_FUNC;
     7extern const char* rtnl_rtprot_n2a(int id) FAST_FUNC;
     8extern const char* rtnl_rtscope_n2a(int id) FAST_FUNC;
     9extern const char* rtnl_rtrealm_n2a(int id) FAST_FUNC;
     10extern const char* rtnl_dsfield_n2a(int id) FAST_FUNC;
     11extern const char* rtnl_rttable_n2a(int id) FAST_FUNC;
    1312extern int rtnl_rtprot_a2n(uint32_t *id, char *arg) FAST_FUNC;
    1413extern int rtnl_rtscope_a2n(uint32_t *id, char *arg) FAST_FUNC;
  • branches/3.3/mindi-busybox/networking/libiproute/rtm_map.c

    r2725 r3621  
    1313#include "utils.h"
    1414
    15 const char* FAST_FUNC rtnl_rtntype_n2a(int id, char *buf)
     15const char* FAST_FUNC rtnl_rtntype_n2a(int id)
    1616{
    1717    switch (id) {
     
    4141        return "xresolve";
    4242    default:
    43         /* buf is SPRINT_BSIZE big */
    44         sprintf(buf, "%d", id);
    45         return buf;
     43        return itoa(id);
    4644    }
    4745}
  • branches/3.3/mindi-busybox/networking/libiproute/rtm_map.h

    r2725 r3621  
    55PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
    66
    7 const char *rtnl_rtntype_n2a(int id, char *buf) FAST_FUNC;
     7const char *rtnl_rtntype_n2a(int id) FAST_FUNC;
    88int rtnl_rtntype_a2n(int *id, char *arg) FAST_FUNC;
    99
  • branches/3.3/mindi-busybox/networking/libiproute/utils.c

    r3232 r3621  
    1414#include "inet_common.h"
    1515
     16unsigned get_hz(void)
     17{
     18    static unsigned hz_internal;
     19    FILE *fp;
     20
     21    if (hz_internal)
     22        return hz_internal;
     23
     24    fp = fopen_for_read("/proc/net/psched");
     25    if (fp) {
     26        unsigned nom, denom;
     27
     28        if (fscanf(fp, "%*08x%*08x%08x%08x", &nom, &denom) == 2)
     29            if (nom == 1000000)
     30                hz_internal = denom;
     31        fclose(fp);
     32    }
     33    if (!hz_internal)
     34        hz_internal = bb_clk_tck();
     35    return hz_internal;
     36}
     37
    1638unsigned get_unsigned(char *arg, const char *errmsg)
    1739{
     
    2648        }
    2749    }
    28     invarg(arg, errmsg); /* does not return */
     50    invarg_1_to_2(arg, errmsg); /* does not return */
    2951}
    3052
     
    4163        }
    4264    }
    43     invarg(arg, errmsg); /* does not return */
     65    invarg_1_to_2(arg, errmsg); /* does not return */
    4466}
    4567
     
    5678        }
    5779    }
    58     invarg(arg, errmsg); /* does not return */
     80    invarg_1_to_2(arg, errmsg); /* does not return */
    5981}
    6082
     
    209231void incomplete_command(void)
    210232{
    211     bb_error_msg_and_die("command line is not complete, try option \"help\"");
    212 }
    213 
    214 void invarg(const char *arg, const char *opt)
    215 {
    216     bb_error_msg_and_die(bb_msg_invalid_arg, arg, opt);
     233    bb_error_msg_and_die("command line is not complete, try \"help\"");
     234}
     235
     236void invarg_1_to_2(const char *arg, const char *opt)
     237{
     238    bb_error_msg_and_die(bb_msg_invalid_arg_to, arg, opt);
    217239}
    218240
     
    255277}
    256278
    257 const char *rt_addr_n2a(int af,
    258         void *addr, char *buf, int buflen)
     279const char *rt_addr_n2a(int af, void *addr)
    259280{
    260281    switch (af) {
    261282    case AF_INET:
    262283    case AF_INET6:
    263         return inet_ntop(af, addr, buf, buflen);
     284        return inet_ntop(af, addr,
     285            auto_string(xzalloc(INET6_ADDRSTRLEN)), INET6_ADDRSTRLEN
     286        );
    264287    default:
    265288        return "???";
     
    268291
    269292#ifdef RESOLVE_HOSTNAMES
    270 const char *format_host(int af, int len, void *addr, char *buf, int buflen)
     293const char *format_host(int af, int len, void *addr)
    271294{
    272295    if (resolve_hosts) {
     
    287310            h_ent = gethostbyaddr(addr, len, af);
    288311            if (h_ent != NULL) {
    289                 safe_strncpy(buf, h_ent->h_name, buflen);
    290                 return buf;
    291             }
    292         }
    293     }
    294     return rt_addr_n2a(af, addr, buf, buflen);
     312                return auto_string(xstrdup(h_ent->h_name));
     313            }
     314        }
     315    }
     316    return rt_addr_n2a(af, addr);
    295317}
    296318#endif
  • branches/3.3/mindi-busybox/networking/libiproute/utils.h

    r3232 r3621  
    6767extern uint16_t get_u16(char *arg, const char *errmsg);
    6868
    69 extern const char *rt_addr_n2a(int af, void *addr, char *buf, int buflen);
     69extern const char *rt_addr_n2a(int af, void *addr);
    7070#ifdef RESOLVE_HOSTNAMES
    71 extern const char *format_host(int af, int len, void *addr, char *buf, int buflen);
     71extern const char *format_host(int af, int len, void *addr);
    7272#else
    73 #define format_host(af, len, addr, buf, buflen) \
    74     rt_addr_n2a(af, addr, buf, buflen)
     73#define format_host(af, len, addr) \
     74    rt_addr_n2a(af, addr)
    7575#endif
    7676
    77 void invarg(const char *, const char *) NORETURN;
     77void invarg_1_to_2(const char *, const char *) NORETURN;
    7878void duparg(const char *, const char *) NORETURN;
    7979void duparg2(const char *, const char *) NORETURN;
     
    8686int ipx_pton(int af, const char *src, void *addr);
    8787
     88unsigned get_hz(void);
     89
    8890POP_SAVED_FUNCTION_VISIBILITY
    8991
Note: See TracChangeset for help on using the changeset viewer.