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

    r2725 r3232  
    1111 */
    1212
     13//config:config NAMEIF
     14//config:   bool "nameif"
     15//config:   default y
     16//config:   select PLATFORM_LINUX
     17//config:   select FEATURE_SYSLOG
     18//config:   help
     19//config:     nameif is used to rename network interface by its MAC address.
     20//config:     Renamed interfaces MUST be in the down state.
     21//config:     It is possible to use a file (default: /etc/mactab)
     22//config:     with list of new interface names and MACs.
     23//config:     Maximum interface name length: IFNAMSIZ = 16
     24//config:     File fields are separated by space or tab.
     25//config:     File format:
     26//config:     # Comment
     27//config:     new_interface_name    XX:XX:XX:XX:XX:XX
     28//config:
     29//config:config FEATURE_NAMEIF_EXTENDED
     30//config:   bool "Extended nameif"
     31//config:   default y
     32//config:   depends on NAMEIF
     33//config:   help
     34//config:     This extends the nameif syntax to support the bus_info, driver,
     35//config:     phyaddr selectors. The syntax is compatible to the normal nameif.
     36//config:     File format:
     37//config:       new_interface_name  driver=asix bus=usb-0000:00:08.2-3
     38//config:       new_interface_name  bus=usb-0000:00:08.2-3 00:80:C8:38:91:B5
     39//config:       new_interface_name  phy_address=2 00:80:C8:38:91:B5
     40//config:       new_interface_name  mac=00:80:C8:38:91:B5
     41//config:       new_interface_name  00:80:C8:38:91:B5
     42
     43//usage:#define nameif_trivial_usage
     44//usage:    IF_NOT_FEATURE_NAMEIF_EXTENDED(
     45//usage:        "[-s] [-c FILE] [IFNAME HWADDR]..."
     46//usage:    )
     47//usage:    IF_FEATURE_NAMEIF_EXTENDED(
     48//usage:        "[-s] [-c FILE] [IFNAME SELECTOR]..."
     49//usage:    )
     50//usage:#define nameif_full_usage "\n\n"
     51//usage:    "Rename network interface while it in the down state."
     52//usage:    IF_NOT_FEATURE_NAMEIF_EXTENDED(
     53//usage:     "\nThe device with address HWADDR is renamed to IFACE."
     54//usage:    )
     55//usage:    IF_FEATURE_NAMEIF_EXTENDED(
     56//usage:     "\nThe device matched by SELECTOR is renamed to IFACE."
     57//usage:     "\nSELECTOR can be a combination of:"
     58//usage:     "\n    driver=STRING"
     59//usage:     "\n    bus=STRING"
     60//usage:     "\n    phy_address=NUM"
     61//usage:     "\n    [mac=]XX:XX:XX:XX:XX:XX"
     62//usage:    )
     63//usage:     "\n"
     64//usage:     "\n    -c FILE Configuration file (default: /etc/mactab)"
     65//usage:     "\n    -s  Log to syslog"
     66//usage:
     67//usage:#define nameif_example_usage
     68//usage:       "$ nameif -s dmz0 00:A0:C9:8C:F6:3F\n"
     69//usage:       " or\n"
     70//usage:       "$ nameif -c /etc/my_mactab_file\n"
     71
    1372#include "libbb.h"
    1473#include <syslog.h>
     
    3998    char *bus_info;
    4099    char *driver;
     100    int32_t phy_address;
    41101#endif
    42102} ethtable_t;
     
    60120    uint32_t regdump_len;  /* Size of data from ETHTOOL_GREGS (bytes) */
    61121};
     122
     123struct ethtool_cmd {
     124    uint32_t   cmd;
     125    uint32_t   supported;      /* Features this interface supports */
     126    uint32_t   advertising;    /* Features this interface advertises */
     127    uint16_t   speed;          /* The forced speed, 10Mb, 100Mb, gigabit */
     128    uint8_t    duplex;         /* Duplex, half or full */
     129    uint8_t    port;           /* Which connector port */
     130    uint8_t    phy_address;
     131    uint8_t    transceiver;    /* Which transceiver to use */
     132    uint8_t    autoneg;        /* Enable or disable autonegotiation */
     133    uint32_t   maxtxpkt;       /* Tx pkts before generating tx int */
     134    uint32_t   maxrxpkt;       /* Rx pkts before generating rx int */
     135    uint16_t   speed_hi;
     136    uint16_t   reserved2;
     137    uint32_t   reserved[3];
     138};
     139
     140#define ETHTOOL_GSET      0x00000001 /* Get settings. */
    62141#define ETHTOOL_GDRVINFO  0x00000003 /* Get driver info. */
    63142#endif
     
    75154        selector = skip_whitespace(selector);
    76155#if ENABLE_FEATURE_NAMEIF_EXTENDED
     156        ch->phy_address = -1;
    77157        if (*selector == '\0')
    78158            break;
     
    88168            ch->driver = xstrdup(selector + 7);
    89169            found_selector++;
     170        } else if (strncmp(selector, "phyaddr=", 8) == 0) {
     171            ch->phy_address = xatoi_positive(selector + 8);
     172            found_selector++;
    90173        } else {
    91174#endif
     
    134217
    135218int nameif_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    136 int nameif_main(int argc, char **argv)
     219int nameif_main(int argc UNUSED_PARAM, char **argv)
    137220{
    138221    ethtable_t *clist = NULL;
     
    149232        logmode |= LOGMODE_SYSLOG;
    150233    }
    151     argc -= optind;
    152234    argv += optind;
    153235
    154     if (argc & 1)
    155         bb_show_usage();
    156 
    157     if (argc) {
    158         while (*argv) {
    159             char *ifname = xstrdup(*argv++);
    160             prepend_new_eth_table(&clist, ifname, *argv++);
    161         }
     236    if (argv[0]) {
     237        do {
     238            if (!argv[1])
     239                bb_show_usage();
     240            prepend_new_eth_table(&clist, argv[0], argv[1]);
     241            argv += 2;
     242        } while (*argv);
    162243    } else {
    163244        parser = config_open(fname);
     
    174255#if  ENABLE_FEATURE_NAMEIF_EXTENDED
    175256        struct ethtool_drvinfo drvinfo;
    176 #endif
    177         if (parser->lineno < 2)
     257        struct ethtool_cmd eth_settings;
     258#endif
     259        if (parser->lineno <= 2)
    178260            continue; /* Skip the first two lines */
    179261
     
    183265
    184266#if ENABLE_FEATURE_NAMEIF_EXTENDED
     267        /* Check for phy address */
     268        memset(&eth_settings, 0, sizeof(eth_settings));
     269        eth_settings.cmd = ETHTOOL_GSET;
     270        ifr.ifr_data = (caddr_t) &eth_settings;
     271        ioctl(ctl_sk, SIOCETHTOOL, &ifr);
     272
    185273        /* Check for driver etc. */
    186         memset(&drvinfo, 0, sizeof(struct ethtool_drvinfo));
     274        memset(&drvinfo, 0, sizeof(drvinfo));
    187275        drvinfo.cmd = ETHTOOL_GDRVINFO;
    188276        ifr.ifr_data = (caddr_t) &drvinfo;
     
    198286                continue;
    199287            if (ch->driver && strcmp(ch->driver, drvinfo.driver) != 0)
     288                continue;
     289            if (ch->phy_address != -1 && ch->phy_address != eth_settings.phy_address)
    200290                continue;
    201291#endif
Note: See TracChangeset for help on using the changeset viewer.