Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
Location:
branches/3.2/mindi-busybox/networking/libiproute
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/networking/libiproute/ipaddress.c

    r2725 r3232  
    163163    }
    164164#endif
     165/* IFLA_OPERSTATE was added to kernel with the same commit as IFF_DORMANT */
     166#ifdef IFF_DORMANT
    165167    if (tb[IFLA_OPERSTATE]) {
    166168        static const char operstate_labels[] ALIGN1 =
     
    170172                    *(uint8_t *)RTA_DATA(tb[IFLA_OPERSTATE])));
    171173    }
     174#endif
    172175    if (G_filter.showqueue)
    173176        print_queuelen((char*)RTA_DATA(tb[IFLA_IFNAME]));
     
    312315        printf("brd %s ",
    313316            rt_addr_n2a(ifa->ifa_family,
    314                     RTA_DATA(rta_tb[IFA_BROADCAST]),
    315                     abuf, sizeof(abuf)));
     317                    RTA_DATA(rta_tb[IFA_BROADCAST]),
     318                    abuf, sizeof(abuf))
     319        );
    316320    }
    317321    if (rta_tb[IFA_ANYCAST]) {
    318322        printf("any %s ",
    319323            rt_addr_n2a(ifa->ifa_family,
    320                     RTA_DATA(rta_tb[IFA_ANYCAST]),
    321                     abuf, sizeof(abuf)));
     324                    RTA_DATA(rta_tb[IFA_ANYCAST]),
     325                    abuf, sizeof(abuf))
     326        );
    322327    }
    323328    printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1));
  • branches/3.2/mindi-busybox/networking/libiproute/iplink.c

    r2725 r3232  
    88#include <net/if_packet.h>
    99#include <netpacket/packet.h>
    10 #include <net/ethernet.h>
     10#include <netinet/if_ether.h>
    1111
    1212#include "ip_common.h"  /* #include "libbb.h" is inside */
  • branches/3.2/mindi-busybox/networking/libiproute/iproute.c

    r2725 r3232  
    3232    //int typemask; - unused
    3333    //int tos, tosmask; - unused
    34     int iif, iifmask;
    35     int oif, oifmask;
     34    int iif;
     35    int oif;
    3636    //int realm, realmmask; - unused
    3737    //inet_prefix rprefsrc; - read-only
     
    8383    struct rtmsg *r = NLMSG_DATA(n);
    8484    int len = n->nlmsg_len;
    85     struct rtattr * tb[RTA_MAX+1];
     85    struct rtattr *tb[RTA_MAX+1];
    8686    char abuf[256];
    8787    inet_prefix dst;
     
    160160
    161161    memset(tb, 0, sizeof(tb));
     162    memset(&src, 0, sizeof(src));
     163    memset(&dst, 0, sizeof(dst));
    162164    parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
     165
     166    if (tb[RTA_SRC]) {
     167        src.bitlen = r->rtm_src_len;
     168        src.bytelen = (r->rtm_family == AF_INET6 ? 16 : 4);
     169        memcpy(src.data, RTA_DATA(tb[RTA_SRC]), src.bytelen);
     170    }
     171    if (tb[RTA_DST]) {
     172        dst.bitlen = r->rtm_dst_len;
     173        dst.bytelen = (r->rtm_family == AF_INET6 ? 16 : 4);
     174        memcpy(dst.data, RTA_DATA(tb[RTA_DST]), dst.bytelen);
     175    }
    163176
    164177    if (G_filter.rdst.family
     
    183196        return 0;
    184197    }
    185     if (G_filter.flushb
    186      && r->rtm_family == AF_INET6
    187      && r->rtm_dst_len == 0
    188      && r->rtm_type == RTN_UNREACHABLE
    189      && tb[RTA_PRIORITY]
    190      && *(int*)RTA_DATA(tb[RTA_PRIORITY]) == -1
    191     ) {
    192         return 0;
     198    if (G_filter.oif != 0) {
     199        if (!tb[RTA_OIF])
     200            return 0;
     201        if (G_filter.oif != *(int*)RTA_DATA(tb[RTA_OIF]))
     202            return 0;
    193203    }
    194204
    195205    if (G_filter.flushb) {
    196206        struct nlmsghdr *fn;
     207
     208        /* We are creating route flush commands */
     209
     210        if (r->rtm_family == AF_INET6
     211         && r->rtm_dst_len == 0
     212         && r->rtm_type == RTN_UNREACHABLE
     213         && tb[RTA_PRIORITY]
     214         && *(int*)RTA_DATA(tb[RTA_PRIORITY]) == -1
     215        ) {
     216            return 0;
     217        }
     218
    197219        if (NLMSG_ALIGN(G_filter.flushp) + n->nlmsg_len > G_filter.flushe) {
    198220            if (flush_update())
    199221                bb_error_msg_and_die("flush");
    200222        }
    201         fn = (struct nlmsghdr*)(G_filter.flushb + NLMSG_ALIGN(G_filter.flushp));
     223        fn = (void*)(G_filter.flushb + NLMSG_ALIGN(G_filter.flushp));
    202224        memcpy(fn, n, n->nlmsg_len);
    203225        fn->nlmsg_type = RTM_DELROUTE;
     
    208230        return 0;
    209231    }
     232
     233    /* We are printing routes */
    210234
    211235    if (n->nlmsg_type == RTM_DELROUTE) {
     
    258282                    abuf, sizeof(abuf)));
    259283    }
    260     if (tb[RTA_OIF] && G_filter.oifmask != -1) {
     284    if (tb[RTA_OIF]) {
    261285        printf("dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF])));
    262286    }
     287
     288    /* Todo: parse & show "proto kernel", "scope link" here */
    263289
    264290    if (tb[RTA_PREFSRC] && /*G_filter.rprefsrc.bitlen - always 0*/ 0 != host_len) {
     
    293319        }
    294320    }
    295     if (tb[RTA_IIF] && G_filter.iifmask != -1) {
     321    if (tb[RTA_IIF] && G_filter.iif == 0) {
    296322        printf(" iif %s", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_IIF])));
    297323    }
     
    414440            }
    415441            if ((**argv < '0' || **argv > '9')
    416              && rtnl_rtntype_a2n(&type, *argv) == 0) {
     442             && rtnl_rtntype_a2n(&type, *argv) == 0
     443            ) {
    417444                NEXT_ARG();
    418445                req.r.rtm_type = type;
     
    663690            idx = xll_name_to_index(id);
    664691            G_filter.iif = idx;
    665             G_filter.iifmask = -1;
    666692        }
    667693        if (od) {
    668694            idx = xll_name_to_index(od);
    669695            G_filter.oif = idx;
    670             G_filter.oifmask = -1;
    671696        }
    672697    }
  • branches/3.2/mindi-busybox/networking/libiproute/iprule.c

    r2725 r3232  
    7474        if (r->rtm_src_len != host_len) {
    7575            printf("%s/%u", rt_addr_n2a(r->rtm_family,
    76                              RTA_DATA(tb[RTA_SRC]),
    77                              abuf, sizeof(abuf)),
     76                            RTA_DATA(tb[RTA_SRC]),
     77                            abuf, sizeof(abuf)),
    7878                r->rtm_src_len
    79                 );
     79            );
    8080        } else {
    8181            fputs(format_host(r->rtm_family,
    82                                RTA_PAYLOAD(tb[RTA_SRC]),
    83                                RTA_DATA(tb[RTA_SRC]),
    84                                abuf, sizeof(abuf)), stdout);
     82                        RTA_PAYLOAD(tb[RTA_SRC]),
     83                        RTA_DATA(tb[RTA_SRC]),
     84                        abuf, sizeof(abuf)),
     85                stdout
     86            );
    8587        }
    8688    } else if (r->rtm_src_len) {
  • branches/3.2/mindi-busybox/networking/libiproute/iptunnel.c

    r2725 r3232  
    439439        if (p->iph.tos & ~1)
    440440            printf("%c%s ", p->iph.tos & 1 ? '/' : ' ',
    441                    rtnl_dsfield_n2a(p->iph.tos & ~1, b1));
     441                rtnl_dsfield_n2a(p->iph.tos & ~1, b1));
    442442    }
    443443    if (!(p->iph.frag_off & htons(IP_DF)))
  • branches/3.2/mindi-busybox/networking/libiproute/libnetlink.c

    r2725 r3232  
    5656}
    5757
     58//TODO: pass rth->fd instead of full rth?
    5859int FAST_FUNC rtnl_send(struct rtnl_handle *rth, char *buf, int len)
    5960{
     
    393394            tb[rta->rta_type] = rta;
    394395        }
    395         rta = RTA_NEXT(rta,len);
     396        rta = RTA_NEXT(rta, len);
    396397    }
    397398    if (len) {
  • branches/3.2/mindi-busybox/networking/libiproute/ll_proto.c

    r2725 r3232  
    1313#include "utils.h"
    1414
    15 #if defined(__GLIBC__) && __GLIBC__ >=2 && __GLIBC_MINOR__ >= 1
    16 #include <net/ethernet.h>
    17 #else
    18 #include <linux/if_ether.h>
    19 #endif
     15#include <netinet/if_ether.h>
    2016
    21 #if !ENABLE_WERROR
    22 #warning de-bloat
    23 #endif
    24 /* Before re-enabling this, please (1) conditionalize exotic protocols
    25  * on CONFIG_something, and (2) decouple strings and numbers
    26  * (use llproto_ids[] = n,n,n..; and llproto_names[] = "loop\0" "pup\0" ...;)
    27  */
     17/* Please conditionalize exotic protocols on CONFIG_something */
    2818
    29 #define __PF(f,n) { ETH_P_##f, #n },
    30 static struct {
    31     int id;
    32     const char *name;
    33 } llproto_names[] = {
     19static const uint16_t llproto_ids[] = {
     20#define __PF(f,n) ETH_P_##f,
    3421__PF(LOOP,loop)
    3522__PF(PUP,pup)
     
    9178#endif
    9279
    93 { 0x8100, "802.1Q" },
    94 { ETH_P_IP, "ipv4" },
     800x8100,
     81ETH_P_IP
    9582};
     83#undef __PF
     84
     85/* Keep declarations above and below in sync! */
     86
     87static const char llproto_names[] =
     88#define __PF(f,n) #n "\0"
     89__PF(LOOP,loop)
     90__PF(PUP,pup)
     91#ifdef ETH_P_PUPAT
     92__PF(PUPAT,pupat)
     93#endif
     94__PF(IP,ip)
     95__PF(X25,x25)
     96__PF(ARP,arp)
     97__PF(BPQ,bpq)
     98#ifdef ETH_P_IEEEPUP
     99__PF(IEEEPUP,ieeepup)
     100#endif
     101#ifdef ETH_P_IEEEPUPAT
     102__PF(IEEEPUPAT,ieeepupat)
     103#endif
     104__PF(DEC,dec)
     105__PF(DNA_DL,dna_dl)
     106__PF(DNA_RC,dna_rc)
     107__PF(DNA_RT,dna_rt)
     108__PF(LAT,lat)
     109__PF(DIAG,diag)
     110__PF(CUST,cust)
     111__PF(SCA,sca)
     112__PF(RARP,rarp)
     113__PF(ATALK,atalk)
     114__PF(AARP,aarp)
     115__PF(IPX,ipx)
     116__PF(IPV6,ipv6)
     117#ifdef ETH_P_PPP_DISC
     118__PF(PPP_DISC,ppp_disc)
     119#endif
     120#ifdef ETH_P_PPP_SES
     121__PF(PPP_SES,ppp_ses)
     122#endif
     123#ifdef ETH_P_ATMMPOA
     124__PF(ATMMPOA,atmmpoa)
     125#endif
     126#ifdef ETH_P_ATMFATE
     127__PF(ATMFATE,atmfate)
     128#endif
     129
     130__PF(802_3,802_3)
     131__PF(AX25,ax25)
     132__PF(ALL,all)
     133__PF(802_2,802_2)
     134__PF(SNAP,snap)
     135__PF(DDCMP,ddcmp)
     136__PF(WAN_PPP,wan_ppp)
     137__PF(PPP_MP,ppp_mp)
     138__PF(LOCALTALK,localtalk)
     139__PF(PPPTALK,ppptalk)
     140__PF(TR_802_2,tr_802_2)
     141__PF(MOBITEX,mobitex)
     142__PF(CONTROL,control)
     143__PF(IRDA,irda)
     144#ifdef ETH_P_ECONET
     145__PF(ECONET,econet)
     146#endif
     147
     148"802.1Q" "\0"
     149"ipv4" "\0"
     150;
    96151#undef __PF
    97152
     
    101156    unsigned i;
    102157    id = ntohs(id);
    103     for (i = 0; i < ARRAY_SIZE(llproto_names); i++) {
    104          if (llproto_names[i].id == id)
    105             return llproto_names[i].name;
     158    for (i = 0; i < ARRAY_SIZE(llproto_ids); i++) {
     159        if (llproto_ids[i] == id)
     160            return nth_string(llproto_names, i);
    106161    }
    107     snprintf(buf, len, "[%d]", id);
     162    snprintf(buf, len, "[%u]", id);
    108163    return buf;
    109164}
     
    112167{
    113168    unsigned i;
    114     for (i = 0; i < ARRAY_SIZE(llproto_names); i++) {
    115          if (strcasecmp(llproto_names[i].name, buf) == 0) {
    116              i = llproto_names[i].id;
    117              goto good;
    118          }
     169    const char *name = llproto_names;
     170    for (i = 0; i < ARRAY_SIZE(llproto_ids); i++) {
     171        if (strcasecmp(name, buf) == 0) {
     172            i = llproto_ids[i];
     173            goto good;
     174        }
     175        name += strlen(name) + 1;
    119176    }
     177    errno = 0;
    120178    i = bb_strtou(buf, NULL, 0);
    121179    if (errno || i > 0xffff)
  • branches/3.2/mindi-busybox/networking/libiproute/ll_types.c

    r2725 r3232  
    88 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
    99 */
     10#include <sys/socket.h> /* linux/if_arp.h needs it on some systems */
    1011#include <arpa/inet.h>
    1112#include <linux/if_arp.h>
  • branches/3.2/mindi-busybox/networking/libiproute/utils.c

    r2725 r3232  
    8484    }
    8585
    86     addr->family = AF_INET;
    8786    if (family != AF_UNSPEC && family != AF_INET)
    8887        return -1;
     88
     89    /* Try to parse it as IPv4 */
     90    addr->family = AF_INET;
     91#if 0 /* Doesn't handle e.g. "10.10", for example, "ip r l root 10.10/16" */
    8992    if (inet_pton(AF_INET, name, addr->data) <= 0)
    9093        return -1;
     94#else
     95    {
     96        unsigned i = 0;
     97        unsigned n = 0;
     98        const char *cp = name - 1;
     99        while (*++cp) {
     100            if ((unsigned char)(*cp - '0') <= 9) {
     101                n = 10 * n + (unsigned char)(*cp - '0');
     102                if (n >= 256)
     103                    return -1;
     104                ((uint8_t*)addr->data)[i] = n;
     105                continue;
     106            }
     107            if (*cp == '.' && ++i <= 3) {
     108                n = 0;
     109                continue;
     110            }
     111            return -1;
     112        }
     113    }
     114#endif
    91115    addr->bytelen = 4;
    92116    addr->bitlen = -1;
     117
    93118    return 0;
    94119}
    95120
    96 static int get_prefix_1(inet_prefix *dst, char *arg, int family)
    97 {
    98     int err;
    99     unsigned plen;
     121static void get_prefix_1(inet_prefix *dst, char *arg, int family)
     122{
    100123    char *slash;
    101124
     
    109132        /*dst->bytelen = 0; - done by memset */
    110133        /*dst->bitlen = 0;*/
    111         return 0;
     134        return;
    112135    }
    113136
     
    115138    if (slash)
    116139        *slash = '\0';
    117     err = get_addr_1(dst, arg, family);
    118     if (err == 0) {
     140
     141    if (get_addr_1(dst, arg, family) == 0) {
    119142        dst->bitlen = (dst->family == AF_INET6) ? 128 : 32;
    120143        if (slash) {
     144            unsigned plen;
    121145            inet_prefix netmask_pfx;
    122146
     
    124148            plen = bb_strtou(slash + 1, NULL, 0);
    125149            if ((errno || plen > dst->bitlen)
    126              && (get_addr_1(&netmask_pfx, slash + 1, family)))
    127                 err = -1;
    128             else if (netmask_pfx.family == AF_INET) {
     150             && get_addr_1(&netmask_pfx, slash + 1, family) != 0
     151            ) {
     152                goto bad;
     153            }
     154            if (netmask_pfx.family == AF_INET) {
    129155                /* fill in prefix length of dotted quad */
    130156                uint32_t mask = ntohl(netmask_pfx.data[0]);
     
    132158
    133159                /* a valid netmask must be 2^n - 1 */
    134                 if (!(host & (host + 1))) {
    135                     for (plen = 0; mask; mask <<= 1)
    136                         ++plen;
    137                     if (plen <= dst->bitlen) {
    138                         dst->bitlen = plen;
    139                         /* dst->flags |= PREFIXLEN_SPECIFIED; */
    140                     } else
    141                         err = -1;
    142                 } else
    143                     err = -1;
    144             } else {
    145                 /* plain prefix */
    146                 dst->bitlen = plen;
    147             }
    148         }
    149     }
     160                if (host & (host + 1))
     161                    goto bad;
     162
     163                for (plen = 0; mask; mask <<= 1)
     164                    ++plen;
     165                if (plen > dst->bitlen)
     166                    goto bad;
     167                /* dst->flags |= PREFIXLEN_SPECIFIED; */
     168            }
     169            dst->bitlen = plen;
     170        }
     171    }
     172
    150173    if (slash)
    151174        *slash = '/';
    152     return err;
     175    return;
     176 bad:
     177    bb_error_msg_and_die("an %s %s is expected rather than \"%s\"", "inet", "prefix", arg);
    153178}
    154179
     
    164189}
    165190
    166 int get_prefix(inet_prefix *dst, char *arg, int family)
     191void get_prefix(inet_prefix *dst, char *arg, int family)
    167192{
    168193    if (family == AF_PACKET) {
    169194        bb_error_msg_and_die("\"%s\" may be inet %s, but it is not allowed in this context", arg, "prefix");
    170195    }
    171     if (get_prefix_1(dst, arg, family)) {
    172         bb_error_msg_and_die("an %s %s is expected rather than \"%s\"", "inet", "prefix", arg);
    173     }
    174     return 0;
     196    get_prefix_1(dst, arg, family);
    175197}
    176198
     
    205227}
    206228
    207 int inet_addr_match(inet_prefix *a, inet_prefix *b, int bits)
    208 {
    209     uint32_t *a1 = a->data;
    210     uint32_t *a2 = b->data;
     229int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits)
     230{
     231    const uint32_t *a1 = a->data;
     232    const uint32_t *a2 = b->data;
    211233    int words = bits >> 5;
    212234
  • branches/3.2/mindi-busybox/networking/libiproute/utils.h

    r2725 r3232  
    5959extern uint32_t get_addr32(char *name);
    6060extern int get_addr_1(inet_prefix *dst, char *arg, int family);
    61 /*extern int get_prefix_1(inet_prefix *dst, char *arg, int family);*/
     61/*extern void get_prefix_1(inet_prefix *dst, char *arg, int family);*/
    6262extern int get_addr(inet_prefix *dst, char *arg, int family);
    63 extern int get_prefix(inet_prefix *dst, char *arg, int family);
     63extern void get_prefix(inet_prefix *dst, char *arg, int family);
    6464
    6565extern unsigned get_unsigned(char *arg, const char *errmsg);
     
    7878void duparg(const char *, const char *) NORETURN;
    7979void duparg2(const char *, const char *) NORETURN;
    80 int inet_addr_match(inet_prefix *a, inet_prefix *b, int bits);
     80int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits);
    8181
    8282const char *dnet_ntop(int af, const void *addr, char *str, size_t len);
Note: See TracChangeset for help on using the changeset viewer.