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/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
Note: See TracChangeset for help on using the changeset viewer.