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/vconfig.c

    r2725 r3232  
    99
    1010/* BB_AUDIT SUSv3 N/A */
     11
     12//usage:#define vconfig_trivial_usage
     13//usage:       "COMMAND [OPTIONS]"
     14//usage:#define vconfig_full_usage "\n\n"
     15//usage:       "Create and remove virtual ethernet devices\n"
     16//usage:     "\n    add     IFACE VLAN_ID"
     17//usage:     "\n    rem     VLAN_NAME"
     18//usage:     "\n    set_flag    IFACE 0|1 VLAN_QOS"
     19//usage:     "\n    set_egress_map  VLAN_NAME SKB_PRIO VLAN_QOS"
     20//usage:     "\n    set_ingress_map VLAN_NAME SKB_PRIO VLAN_QOS"
     21//usage:     "\n    set_name_type   NAME_TYPE"
    1122
    1223#include "libbb.h"
     
    5667static const char *xfind_str(const char *table, const char *str)
    5768{
    58     while (strcasecmp(str, table+1) != 0) {
     69    while (strcasecmp(str, table + 1) != 0) {
     70        if (!table[0])
     71            bb_show_usage();
    5972        table += table[0];
    60         if (!*table) {
    61             bb_show_usage();
    62         }
    6373    }
    6474    return table - 1;
     
    6777static const char cmds[] ALIGN1 = {
    6878    4, ADD_VLAN_CMD, 7,
    69     'a', 'd', 'd', 0,
     79    'a','d','d',0,
    7080    3, DEL_VLAN_CMD, 7,
    71     'r', 'e', 'm', 0,
     81    'r','e','m',0,
    7282    3, SET_VLAN_NAME_TYPE_CMD, 17,
    73     's', 'e', 't', '_',
    74     'n', 'a', 'm', 'e', '_',
    75     't', 'y', 'p', 'e', 0,
     83    's','e','t','_','n','a','m','e','_','t','y','p','e',0,
    7684    5, SET_VLAN_FLAG_CMD, 12,
    77     's', 'e', 't', '_',
    78     'f', 'l', 'a', 'g', 0,
     85    's','e','t','_','f','l','a','g',0,
    7986    5, SET_VLAN_EGRESS_PRIORITY_CMD, 18,
    80     's', 'e', 't', '_',
    81     'e', 'g', 'r', 'e', 's', 's', '_',
    82     'm', 'a', 'p', 0,
    83     5, SET_VLAN_INGRESS_PRIORITY_CMD, 16,
    84     's', 'e', 't', '_',
    85     'i', 'n', 'g', 'r', 'e', 's', 's', '_',
    86     'm', 'a', 'p', 0,
     87    's','e','t','_','e','g','r','e','s','s','_','m','a','p',0,
     88    5, SET_VLAN_INGRESS_PRIORITY_CMD, 0,
     89    's','e','t','_','i','n','g','r','e','s','s','_','m','a','p',0,
    8790};
    8891
    8992static const char name_types[] ALIGN1 = {
    9093    VLAN_NAME_TYPE_PLUS_VID, 16,
    91     'V', 'L', 'A', 'N',
    92     '_', 'P', 'L', 'U', 'S', '_', 'V', 'I', 'D',
    93     0,
     94    'V','L','A','N','_','P','L','U','S','_','V','I','D',0,
    9495    VLAN_NAME_TYPE_PLUS_VID_NO_PAD, 22,
    95     'V', 'L', 'A', 'N',
    96     '_', 'P', 'L', 'U', 'S', '_', 'V', 'I', 'D',
    97     '_', 'N', 'O', '_', 'P', 'A', 'D', 0,
     96    'V','L','A','N','_','P','L','U','S','_','V','I','D','_','N','O','_','P','A','D',0,
    9897    VLAN_NAME_TYPE_RAW_PLUS_VID, 15,
    99     'D', 'E', 'V',
    100     '_', 'P', 'L', 'U', 'S', '_', 'V', 'I', 'D',
    101     0,
    102     VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD, 20,
    103     'D', 'E', 'V',
    104     '_', 'P', 'L', 'U', 'S', '_', 'V', 'I', 'D',
    105     '_', 'N', 'O', '_', 'P', 'A', 'D', 0,
     98    'D','E','V','_','P','L','U','S','_','V','I','D',0,
     99    VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD, 0,
     100    'D','E','V','_','P','L','U','S','_','V','I','D','_','N','O','_','P','A','D',0,
    106101};
    107 
    108 static const char conf_file_name[] ALIGN1 = "/proc/net/vlan/config";
    109102
    110103int vconfig_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     
    115108    int fd;
    116109
    117     if (argc < 3) {
    118         bb_show_usage();
    119     }
    120 
    121     /* Don't bother closing the filedes.  It will be closed on cleanup. */
    122     /* Will die if 802.1q is not present */
    123     xopen(conf_file_name, O_RDONLY);
    124 
    125110    memset(&ifr, 0, sizeof(ifr));
    126111
    127112    ++argv;
    128     p = xfind_str(cmds+2, *argv);
     113    if (!argv[0])
     114        bb_show_usage();
     115    p = xfind_str(cmds + 2, argv[0]);
    129116    ifr.cmd = *p;
    130     if (argc != p[-1]) {
     117    if (argc != p[-1])
    131118        bb_show_usage();
    132     }
    133119
    134     if (ifr.cmd == SET_VLAN_NAME_TYPE_CMD) { /* set_name_type */
    135         ifr.u.name_type = *xfind_str(name_types+1, argv[1]);
     120    if (ifr.cmd == SET_VLAN_NAME_TYPE_CMD) {
     121        /* set_name_type */
     122        ifr.u.name_type = *xfind_str(name_types + 1, argv[1]);
    136123    } else {
    137124        strncpy_IFNAMSIZ(ifr.device1, argv[1]);
     
    142129         * (unsigned) int members of a unions.  But because of the range checking,
    143130         * doing so wouldn't save that much space and would also make maintainence
    144          * more of a pain. */
    145         if (ifr.cmd == SET_VLAN_FLAG_CMD) { /* set_flag */
    146             ifr.u.flag = xatoul_range(p, 0, 1);
     131         * more of a pain.
     132         */
     133        if (ifr.cmd == SET_VLAN_FLAG_CMD) {
     134            /* set_flag */
     135            ifr.u.flag = xatou_range(p, 0, 1);
    147136            /* DM: in order to set reorder header, qos must be set */
    148             ifr.vlan_qos = xatoul_range(argv[3], 0, 7);
    149         } else if (ifr.cmd == ADD_VLAN_CMD) { /* add */
    150             ifr.u.VID = xatoul_range(p, 0, VLAN_GROUP_ARRAY_LEN-1);
    151         } else if (ifr.cmd != DEL_VLAN_CMD) { /* set_{egress|ingress}_map */
     137            ifr.vlan_qos = xatou_range(argv[3], 0, 7);
     138        } else if (ifr.cmd == ADD_VLAN_CMD) {
     139            /* add */
     140            ifr.u.VID = xatou_range(p, 0, VLAN_GROUP_ARRAY_LEN - 1);
     141        } else if (ifr.cmd != DEL_VLAN_CMD) {
     142            /* set_{egress|ingress}_map */
    152143            ifr.u.skb_priority = xatou(p);
    153             ifr.vlan_qos = xatoul_range(argv[3], 0, 7);
     144            ifr.vlan_qos = xatou_range(argv[3], 0, 7);
    154145        }
    155146    }
     
    157148    fd = xsocket(AF_INET, SOCK_STREAM, 0);
    158149    ioctl_or_perror_and_die(fd, SIOCSIFVLAN, &ifr,
    159                         "ioctl error for %s", *argv);
     150                        "ioctl error for %s", argv[0]);
    160151
    161152    return 0;
Note: See TracChangeset for help on using the changeset viewer.