Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

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

    r2725 r3232  
    2626 */
    2727
     28//usage:#define route_trivial_usage
     29//usage:       "[{add|del|delete}]"
     30//usage:#define route_full_usage "\n\n"
     31//usage:       "Edit kernel routing tables\n"
     32//usage:     "\n    -n  Don't resolve names"
     33//usage:     "\n    -e  Display other/more information"
     34//usage:     "\n    -A inet" IF_FEATURE_IPV6("{6}") "   Select address family"
     35
    2836#include <net/route.h>
    2937#include <net/if.h>
     
    154162static NOINLINE void INET_setroute(int action, char **args)
    155163{
    156     struct rtentry rt;
     164    /* char buffer instead of bona-fide struct avoids aliasing warning */
     165    char rt_buf[sizeof(struct rtentry)];
     166    struct rtentry *const rt = (void *)rt_buf;
     167
    157168    const char *netmask = NULL;
    158169    int skfd, isnet, xflag;
     
    167178
    168179    /* Clean out the RTREQ structure. */
    169     memset(&rt, 0, sizeof(rt));
     180    memset(rt, 0, sizeof(*rt));
    170181
    171182    {
     
    179190
    180191            prefix_len = xatoul_range(prefix+1, 0, 32);
    181             mask_in_addr(rt) = htonl( ~(0xffffffffUL >> prefix_len));
     192            mask_in_addr(*rt) = htonl( ~(0xffffffffUL >> prefix_len));
    182193            *prefix = '\0';
    183194#if HAVE_NEW_ADDRT
    184             rt.rt_genmask.sa_family = AF_INET;
     195            rt->rt_genmask.sa_family = AF_INET;
    185196#endif
    186197        } else {
     
    189200        }
    190201        /* Prefer hostname lookup is -host flag (xflag==1) was given. */
    191         isnet = INET_resolve(target, (struct sockaddr_in *) &rt.rt_dst,
     202        isnet = INET_resolve(target, (struct sockaddr_in *) &rt->rt_dst,
    192203                             (xflag & HOST_FLAG));
    193204        if (isnet < 0) {
     
    205216
    206217    /* Fill in the other fields. */
    207     rt.rt_flags = ((isnet) ? RTF_UP : (RTF_UP | RTF_HOST));
     218    rt->rt_flags = ((isnet) ? RTF_UP : (RTF_UP | RTF_HOST));
    208219
    209220    while (*args) {
     
    212223
    213224        if (k & KW_IPVx_FLAG_ONLY) {
    214             rt.rt_flags |= flags_ipvx[k & 3];
     225            rt->rt_flags |= flags_ipvx[k & 3];
    215226            continue;
    216227        }
     
    218229#if HAVE_NEW_ADDRT
    219230        if (k == KW_IPVx_METRIC) {
    220             rt.rt_metric = xatoul(args_m1) + 1;
     231            rt->rt_metric = xatoul(args_m1) + 1;
    221232            continue;
    222233        }
     
    226237            struct sockaddr mask;
    227238
    228             if (mask_in_addr(rt)) {
     239            if (mask_in_addr(*rt)) {
    229240                bb_show_usage();
    230241            }
     
    235246                bb_error_msg_and_die("resolving %s", netmask);
    236247            }
    237             rt.rt_genmask = full_mask(mask);
     248            rt->rt_genmask = full_mask(mask);
    238249            continue;
    239250        }
    240251
    241252        if (k == KW_IPVx_GATEWAY) {
    242             if (rt.rt_flags & RTF_GATEWAY) {
     253            if (rt->rt_flags & RTF_GATEWAY) {
    243254                bb_show_usage();
    244255            }
    245256
    246257            isnet = INET_resolve(args_m1,
    247                                  (struct sockaddr_in *) &rt.rt_gateway, 1);
    248             rt.rt_flags |= RTF_GATEWAY;
     258                        (struct sockaddr_in *) &rt->rt_gateway, 1);
     259            rt->rt_flags |= RTF_GATEWAY;
    249260
    250261            if (isnet) {
     
    258269
    259270        if (k == KW_IPVx_MSS) { /* Check valid MSS bounds. */
    260             rt.rt_flags |= RTF_MSS;
    261             rt.rt_mss = xatoul_range(args_m1, 64, 32768);
     271            rt->rt_flags |= RTF_MSS;
     272            rt->rt_mss = xatoul_range(args_m1, 64, 32768);
    262273            continue;
    263274        }
    264275
    265276        if (k == KW_IPVx_WINDOW) {  /* Check valid window bounds. */
    266             rt.rt_flags |= RTF_WINDOW;
    267             rt.rt_window = xatoul_range(args_m1, 128, INT_MAX);
     277            rt->rt_flags |= RTF_WINDOW;
     278            rt->rt_window = xatoul_range(args_m1, 128, INT_MAX);
    268279            continue;
    269280        }
     
    271282#ifdef RTF_IRTT
    272283        if (k == KW_IPVx_IRTT) {
    273             rt.rt_flags |= RTF_IRTT;
    274             rt.rt_irtt = xatoul(args_m1);
    275             rt.rt_irtt *= (sysconf(_SC_CLK_TCK) / 100); /* FIXME */
     284            rt->rt_flags |= RTF_IRTT;
     285            rt->rt_irtt = xatoul(args_m1);
     286            rt->rt_irtt *= (sysconf(_SC_CLK_TCK) / 100);    /* FIXME */
    276287#if 0                   /* FIXME: do we need to check anything of this? */
    277             if (rt.rt_irtt < 1 || rt.rt_irtt > (120 * HZ)) {
     288            if (rt->rt_irtt < 1 || rt->rt_irtt > (120 * HZ)) {
    278289                bb_error_msg_and_die("bad irtt");
    279290            }
     
    285296        /* Device is special in that it can be the last arg specified
    286297         * and doesn't requre the dev/device keyword in that case. */
    287         if (!rt.rt_dev && ((k == KW_IPVx_DEVICE) || (!k && !*++args))) {
     298        if (!rt->rt_dev && ((k == KW_IPVx_DEVICE) || (!k && !*++args))) {
    288299            /* Don't use args_m1 here since args may have changed! */
    289             rt.rt_dev = args[-1];
     300            rt->rt_dev = args[-1];
    290301            continue;
    291302        }
     
    296307
    297308#ifdef RTF_REJECT
    298     if ((rt.rt_flags & RTF_REJECT) && !rt.rt_dev) {
    299         rt.rt_dev = (char*)"lo";
     309    if ((rt->rt_flags & RTF_REJECT) && !rt->rt_dev) {
     310        rt->rt_dev = (char*)"lo";
    300311    }
    301312#endif
    302313
    303314    /* sanity checks.. */
    304     if (mask_in_addr(rt)) {
    305         uint32_t mask = mask_in_addr(rt);
     315    if (mask_in_addr(*rt)) {
     316        uint32_t mask = mask_in_addr(*rt);
    306317
    307318        mask = ~ntohl(mask);
    308         if ((rt.rt_flags & RTF_HOST) && mask != 0xffffffff) {
     319        if ((rt->rt_flags & RTF_HOST) && mask != 0xffffffff) {
    309320            bb_error_msg_and_die("netmask %.8x and host route conflict",
    310321                                 (unsigned int) mask);
     
    313324            bb_error_msg_and_die("bogus netmask %s", netmask);
    314325        }
    315         mask = ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr;
    316         if (mask & ~(uint32_t)mask_in_addr(rt)) {
     326        mask = ((struct sockaddr_in *) &rt->rt_dst)->sin_addr.s_addr;
     327        if (mask & ~(uint32_t)mask_in_addr(*rt)) {
    317328            bb_error_msg_and_die("netmask and route address conflict");
    318329        }
     
    320331
    321332    /* Fill out netmask if still unset */
    322     if ((action == RTACTION_ADD) && (rt.rt_flags & RTF_HOST)) {
    323         mask_in_addr(rt) = 0xffffffff;
     333    if ((action == RTACTION_ADD) && (rt->rt_flags & RTF_HOST)) {
     334        mask_in_addr(*rt) = 0xffffffff;
    324335    }
    325336
     
    328339
    329340    if (action == RTACTION_ADD)
    330         xioctl(skfd, SIOCADDRT, &rt);
     341        xioctl(skfd, SIOCADDRT, rt);
    331342    else
    332         xioctl(skfd, SIOCDELRT, &rt);
     343        xioctl(skfd, SIOCDELRT, rt);
    333344
    334345    if (ENABLE_FEATURE_CLEAN_UP) close(skfd);
     
    399410            }
    400411            memcpy(&rt.rtmsg_gateway, sa6.sin6_addr.s6_addr,
    401                    sizeof(struct in6_addr));
     412                    sizeof(struct in6_addr));
    402413            rt.rtmsg_flags |= RTF_GATEWAY;
    403414            continue;
     
    425436        memset(&ifr, 0, sizeof(ifr));
    426437        strncpy_IFNAMSIZ(ifr.ifr_name, devname);
    427         xioctl(skfd, SIOGIFINDEX, &ifr);
     438        xioctl(skfd, SIOCGIFINDEX, &ifr);
    428439        rt.rtmsg_ifindex = ifr.ifr_ifindex;
    429440    }
     
    488499
    489500    printf("Kernel IP routing table\n"
    490            "Destination     Gateway         Genmask         Flags %s Iface\n",
     501        "Destination     Gateway         Genmask         Flags %s Iface\n",
    491502            netstatfmt ? "  MSS Window  irtt" : "Metric Ref    Use");
    492503
    493504    if (fscanf(fp, "%*[^\n]\n") < 0) { /* Skip the first line. */
    494         goto ERROR;        /* Empty or missing line, or read error. */
     505        goto ERROR;                /* Empty or missing line, or read error. */
    495506    }
    496507    while (1) {
    497508        int r;
    498509        r = fscanf(fp, "%63s%lx%lx%X%d%d%d%lx%d%d%d\n",
    499                    devname, &d, &g, &flgs, &ref, &use, &metric, &m,
    500                    &mtu, &win, &ir);
     510                devname, &d, &g, &flgs, &ref, &use, &metric, &m,
     511                &mtu, &win, &ir);
    501512        if (r != 11) {
    502513            if ((r < 0) && feof(fp)) { /* EOF with no (nonspace) chars read. */
     
    535546        }
    536547    }
     548    fclose(fp);
    537549}
    538550
     
    556568
    557569    printf("Kernel IPv6 routing table\n%-44s%-40s"
    558               "Flags Metric Ref    Use Iface\n",
    559               "Destination", "Next Hop");
     570            "Flags Metric Ref    Use Iface\n",
     571            "Destination", "Next Hop");
    560572
    561573    while (1) {
     
    602614
    603615        r = 0;
    604         do {
     616        while (1) {
    605617            inet_pton(AF_INET6, addr6x + r,
    606618                      (struct sockaddr *) &snaddr6.sin6_addr);
    607619            snaddr6.sin6_family = AF_INET6;
    608620            naddr6 = INET6_rresolve((struct sockaddr_in6 *) &snaddr6,
    609                            0x0fff /* Apparently, upstream never resolves. */
    610                            );
     621                        0x0fff /* Apparently, upstream never resolves. */
     622                        );
    611623
    612624            if (!r) {           /* 1st pass */
     
    621633                break;
    622634            }
    623         } while (1);
    624     }
     635        }
     636    }
     637    fclose(fp);
    625638}
    626639
Note: See TracChangeset for help on using the changeset viewer.