Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/networking/libiproute/iprule.c

    r1765 r2725  
    11/* vi: set sw=4 ts=4: */
    22/*
    3  * iprule.c     "ip rule".
     3 * This program is free software; you can redistribute it and/or
     4 * modify it under the terms of the GNU General Public License
     5 * as published by the Free Software Foundation; either version
     6 * 2 of the License, or (at your option) any later version.
    47 *
    5  *      This program is free software; you can redistribute it and/or
    6  *      modify it under the terms of the GNU General Public License
    7  *      as published by the Free Software Foundation; either version
    8  *      2 of the License, or (at your option) any later version.
    9  *
    10  * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
    11  *
     8 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
    129 *
    1310 * Changes:
    1411 *
    15  * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
    16  * initially integrated into busybox by Bernhard Fischer
     12 * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
     13 * initially integrated into busybox by Bernhard Reutner-Fischer
    1714 */
    1815
    19 #include <syslog.h>
    20 //#include <sys/socket.h>
    2116#include <netinet/in.h>
    2217#include <netinet/ip.h>
     
    4338*/
    4439
    45 static int print_rule(struct sockaddr_nl *who ATTRIBUTE_UNUSED,
    46                     struct nlmsghdr *n, void *arg)
    47 {
    48     FILE *fp = (FILE*)arg;
     40static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
     41                    struct nlmsghdr *n, void *arg UNUSED_PARAM)
     42{
    4943    struct rtmsg *r = NLMSG_DATA(n);
    5044    int len = n->nlmsg_len;
     
    7367        host_len = 80;
    7468*/
    75     if (tb[RTA_PRIORITY])
    76         fprintf(fp, "%u:\t", *(unsigned*)RTA_DATA(tb[RTA_PRIORITY]));
    77     else
    78         fprintf(fp, "0:\t");
    79 
    80     fprintf(fp, "from ");
     69    printf("%u:\t", tb[RTA_PRIORITY] ?
     70                    *(unsigned*)RTA_DATA(tb[RTA_PRIORITY])
     71                    : 0);
     72    printf("from ");
    8173    if (tb[RTA_SRC]) {
    8274        if (r->rtm_src_len != host_len) {
    83             fprintf(fp, "%s/%u", rt_addr_n2a(r->rtm_family,
    84                              RTA_PAYLOAD(tb[RTA_SRC]),
     75            printf("%s/%u", rt_addr_n2a(r->rtm_family,
    8576                             RTA_DATA(tb[RTA_SRC]),
    8677                             abuf, sizeof(abuf)),
     
    8879                );
    8980        } else {
    90             fprintf(fp, "%s", format_host(r->rtm_family,
     81            fputs(format_host(r->rtm_family,
    9182                               RTA_PAYLOAD(tb[RTA_SRC]),
    9283                               RTA_DATA(tb[RTA_SRC]),
    93                                abuf, sizeof(abuf))
    94                 );
     84                               abuf, sizeof(abuf)), stdout);
    9585        }
    9686    } else if (r->rtm_src_len) {
    97         fprintf(fp, "0/%d", r->rtm_src_len);
     87        printf("0/%d", r->rtm_src_len);
    9888    } else {
    99         fprintf(fp, "all");
    100     }
    101     fprintf(fp, " ");
     89        printf("all");
     90    }
     91    bb_putchar(' ');
    10292
    10393    if (tb[RTA_DST]) {
    10494        if (r->rtm_dst_len != host_len) {
    105             fprintf(fp, "to %s/%u ", rt_addr_n2a(r->rtm_family,
    106                              RTA_PAYLOAD(tb[RTA_DST]),
     95            printf("to %s/%u ", rt_addr_n2a(r->rtm_family,
    10796                             RTA_DATA(tb[RTA_DST]),
    10897                             abuf, sizeof(abuf)),
     
    11099                );
    111100        } else {
    112             fprintf(fp, "to %s ", format_host(r->rtm_family,
     101            printf("to %s ", format_host(r->rtm_family,
    113102                               RTA_PAYLOAD(tb[RTA_DST]),
    114103                               RTA_DATA(tb[RTA_DST]),
     
    116105        }
    117106    } else if (r->rtm_dst_len) {
    118         fprintf(fp, "to 0/%d ", r->rtm_dst_len);
     107        printf("to 0/%d ", r->rtm_dst_len);
    119108    }
    120109
    121110    if (r->rtm_tos) {
    122         fprintf(fp, "tos %s ", rtnl_dsfield_n2a(r->rtm_tos, b1, sizeof(b1)));
     111        printf("tos %s ", rtnl_dsfield_n2a(r->rtm_tos, b1));
    123112    }
    124113    if (tb[RTA_PROTOINFO]) {
    125         fprintf(fp, "fwmark %#x ", *(uint32_t*)RTA_DATA(tb[RTA_PROTOINFO]));
     114        printf("fwmark %#x ", *(uint32_t*)RTA_DATA(tb[RTA_PROTOINFO]));
    126115    }
    127116
    128117    if (tb[RTA_IIF]) {
    129         fprintf(fp, "iif %s ", (char*)RTA_DATA(tb[RTA_IIF]));
     118        printf("iif %s ", (char*)RTA_DATA(tb[RTA_IIF]));
    130119    }
    131120
    132121    if (r->rtm_table)
    133         fprintf(fp, "lookup %s ", rtnl_rttable_n2a(r->rtm_table, b1, sizeof(b1)));
     122        printf("lookup %s ", rtnl_rttable_n2a(r->rtm_table, b1));
    134123
    135124    if (tb[RTA_FLOW]) {
     
    138127        to &= 0xFFFF;
    139128        if (from) {
    140             fprintf(fp, "realms %s/",
    141                 rtnl_rtrealm_n2a(from, b1, sizeof(b1)));
     129            printf("realms %s/",
     130                rtnl_rtrealm_n2a(from, b1));
    142131        }
    143         fprintf(fp, "%s ",
    144             rtnl_rtrealm_n2a(to, b1, sizeof(b1)));
     132        printf("%s ",
     133            rtnl_rtrealm_n2a(to, b1));
    145134    }
    146135
    147136    if (r->rtm_type == RTN_NAT) {
    148137        if (tb[RTA_GATEWAY]) {
    149             fprintf(fp, "map-to %s ",
     138            printf("map-to %s ",
    150139                format_host(r->rtm_family,
    151140                        RTA_PAYLOAD(tb[RTA_GATEWAY]),
     
    153142                        abuf, sizeof(abuf)));
    154143        } else
    155             fprintf(fp, "masquerade");
     144            printf("masquerade");
    156145    } else if (r->rtm_type != RTN_UNICAST)
    157         fprintf(fp, "%s", rtnl_rtntype_n2a(r->rtm_type, b1, sizeof(b1)));
    158 
    159     fputc('\n', fp);
    160     fflush(fp);
     146        fputs(rtnl_rtntype_n2a(r->rtm_type, b1), stdout);
     147
     148    bb_putchar('\n');
     149    /*fflush_all();*/
    161150    return 0;
    162151}
    163152
    164153/* Return value becomes exitcode. It's okay to not return at all */
    165 static int iprule_list(int argc, char **argv)
     154static int iprule_list(char **argv)
    166155{
    167156    struct rtnl_handle rth;
     
    171160        af = AF_INET;
    172161
    173     if (argc > 0) {
     162    if (*argv) {
    174163        //bb_error_msg("\"rule show\" needs no arguments");
    175         bb_warn_ignoring_args(argc);
     164        bb_warn_ignoring_args(*argv);
    176165        return -1;
    177166    }
     
    180169
    181170    xrtnl_wilddump_request(&rth, af, RTM_GETRULE);
    182     xrtnl_dump_filter(&rth, print_rule, stdout);
     171    xrtnl_dump_filter(&rth, print_rule, NULL);
    183172
    184173    return 0;
     
    186175
    187176/* Return value becomes exitcode. It's okay to not return at all */
    188 static int iprule_modify(int cmd, int argc, char **argv)
     177static int iprule_modify(int cmd, char **argv)
    189178{
    190179    static const char keywords[] ALIGN1 =
     
    200189    struct rtnl_handle rth;
    201190    struct {
    202         struct nlmsghdr n;
    203         struct rtmsg    r;
    204         char        buf[1024];
     191        struct nlmsghdr n;
     192        struct rtmsg    r;
     193        char            buf[1024];
    205194    } req;
    206195    smalluint key;
     
    222211    }
    223212
    224     while (argc > 0) {
     213    while (*argv) {
    225214        key = index_in_substrings(keywords, *argv) + 1;
    226215        if (key == 0) /* no match found in keywords array, bail out. */
     
    240229        } else if (key == ARG_preference ||
    241230               key == ARG_order ||
    242                key == ARG_priority) {
     231               key == ARG_priority
     232        ) {
    243233            uint32_t pref;
    244234            NEXT_ARG();
    245             if (get_u32(&pref, *argv, 0))
    246                 invarg(*argv, "preference");
     235            pref = get_u32(*argv, "preference");
    247236            addattr32(&req.n, sizeof(req), RTA_PRIORITY, pref);
    248237        } else if (key == ARG_tos) {
     
    255244            uint32_t fwmark;
    256245            NEXT_ARG();
    257             if (get_u32(&fwmark, *argv, 0))
    258                 invarg(*argv, "fwmark");
     246            fwmark = get_u32(*argv, "fwmark");
    259247            addattr32(&req.n, sizeof(req), RTA_PROTOINFO, fwmark);
    260248        } else if (key == ARG_realms) {
     
    265253            addattr32(&req.n, sizeof(req), RTA_FLOW, realm);
    266254        } else if (key == ARG_table ||
    267                key == ARG_lookup) {
     255               key == ARG_lookup
     256        ) {
    268257            uint32_t tid;
    269258            NEXT_ARG();
     
    273262            table_ok = 1;
    274263        } else if (key == ARG_dev ||
    275                key == ARG_iif) {
     264               key == ARG_iif
     265        ) {
    276266            NEXT_ARG();
    277267            addattr_l(&req.n, sizeof(req), RTA_IIF, *argv, strlen(*argv)+1);
    278268        } else if (key == ARG_nat ||
    279                key == ARG_map_to) {
     269               key == ARG_map_to
     270        ) {
    280271            NEXT_ARG();
    281272            addattr32(&req.n, sizeof(req), RTA_GATEWAY, get_addr32(*argv));
     
    293284            req.r.rtm_type = type;
    294285        }
    295         argc--;
    296286        argv++;
    297287    }
     
    312302
    313303/* Return value becomes exitcode. It's okay to not return at all */
    314 int do_iprule(int argc, char **argv)
     304int FAST_FUNC do_iprule(char **argv)
    315305{
    316306    static const char ip_rule_commands[] ALIGN1 =
    317307        "add\0""delete\0""list\0""show\0";
    318     int cmd = 2; /* list */
    319 
    320     if (argc < 1)
    321         return iprule_list(0, NULL);
    322     if (*argv)
    323         cmd = index_in_substrings(ip_rule_commands, *argv);
    324 
    325     switch (cmd) {
    326         case 0: /* add */
    327             cmd = RTM_NEWRULE;
    328             break;
    329         case 1: /* delete */
    330             cmd = RTM_DELRULE;
    331             break;
    332         case 2: /* list */
    333         case 3: /* show */
    334             return iprule_list(argc-1, argv+1);
    335             break;
    336         default:
    337             bb_error_msg_and_die("unknown command %s", *argv);
    338     }
    339     return iprule_modify(cmd, argc-1, argv+1);
    340 }
     308    if (*argv) {
     309        smalluint cmd = index_in_substrings(ip_rule_commands, *argv);
     310        if (cmd > 3)
     311            bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
     312        argv++;
     313        if (cmd < 2)
     314            return iprule_modify((cmd == 0) ? RTM_NEWRULE : RTM_DELRULE, argv);
     315    }
     316    return iprule_list(argv);
     317}
Note: See TracChangeset for help on using the changeset viewer.