nameif: add matching by phy_address=NUM; extend help text
function old new delta nameif_main 618 686 +68 packed_usage 28095 28149 +54 prepend_new_eth_table 295 338 +43 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 165/0) Total: 165 bytes Signed-off-by: Phil Sutter <phil.sutter@viprinet.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
2adc0e6d8b
commit
293a8f250d
@ -2546,20 +2546,6 @@ INSERT
|
||||
"ras3 reset retension rewind rewoffline seek setblk setdensity\n" \
|
||||
"setpart tell unload unlock weof wset" \
|
||||
|
||||
#define nameif_trivial_usage \
|
||||
"[-s] [-c FILE] [{IFNAME MACADDR}]"
|
||||
#define nameif_full_usage "\n\n" \
|
||||
"Rename network interface while it in the down state\n" \
|
||||
"\nOptions:" \
|
||||
"\n -c FILE Use configuration file (default: /etc/mactab)" \
|
||||
"\n -s Use syslog (LOCAL0 facility)" \
|
||||
"\n IFNAME MACADDR new_interface_name interface_mac_address" \
|
||||
|
||||
#define nameif_example_usage \
|
||||
"$ nameif -s dmz0 00:A0:C9:8C:F6:3F\n" \
|
||||
" or\n" \
|
||||
"$ nameif -c /etc/my_mactab_file\n" \
|
||||
|
||||
#define nohup_trivial_usage \
|
||||
"PROG ARGS"
|
||||
#define nohup_full_usage "\n\n" \
|
||||
|
@ -612,35 +612,6 @@ config FEATURE_IPCALC_LONG_OPTIONS
|
||||
help
|
||||
Support long options for the ipcalc applet.
|
||||
|
||||
config NAMEIF
|
||||
bool "nameif"
|
||||
default y
|
||||
select PLATFORM_LINUX
|
||||
select FEATURE_SYSLOG
|
||||
help
|
||||
nameif is used to rename network interface by its MAC address.
|
||||
Renamed interfaces MUST be in the down state.
|
||||
It is possible to use a file (default: /etc/mactab)
|
||||
with list of new interface names and MACs.
|
||||
Maximum interface name length: IFNAMSIZ = 16
|
||||
File fields are separated by space or tab.
|
||||
File format:
|
||||
# Comment
|
||||
new_interface_name XX:XX:XX:XX:XX:XX
|
||||
|
||||
config FEATURE_NAMEIF_EXTENDED
|
||||
bool "Extended nameif"
|
||||
default y
|
||||
depends on NAMEIF
|
||||
help
|
||||
This extends the nameif syntax to support the bus_info and driver
|
||||
checks. The syntax is compatible to the normal nameif.
|
||||
File format:
|
||||
new_interface_name driver=asix bus=usb-0000:00:08.2-3
|
||||
new_interface_name bus=usb-0000:00:08.2-3 00:80:C8:38:91:B5
|
||||
new_interface_name mac=00:80:C8:38:91:B5
|
||||
new_interface_name 00:80:C8:38:91:B5
|
||||
|
||||
config NETSTAT
|
||||
bool "netstat"
|
||||
default y
|
||||
|
@ -10,6 +10,66 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config NAMEIF
|
||||
//config: bool "nameif"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: select FEATURE_SYSLOG
|
||||
//config: help
|
||||
//config: nameif is used to rename network interface by its MAC address.
|
||||
//config: Renamed interfaces MUST be in the down state.
|
||||
//config: It is possible to use a file (default: /etc/mactab)
|
||||
//config: with list of new interface names and MACs.
|
||||
//config: Maximum interface name length: IFNAMSIZ = 16
|
||||
//config: File fields are separated by space or tab.
|
||||
//config: File format:
|
||||
//config: # Comment
|
||||
//config: new_interface_name XX:XX:XX:XX:XX:XX
|
||||
//config:
|
||||
//config:config FEATURE_NAMEIF_EXTENDED
|
||||
//config: bool "Extended nameif"
|
||||
//config: default y
|
||||
//config: depends on NAMEIF
|
||||
//config: help
|
||||
//config: This extends the nameif syntax to support the bus_info, driver,
|
||||
//config: phyaddr selectors. The syntax is compatible to the normal nameif.
|
||||
//config: File format:
|
||||
//config: new_interface_name driver=asix bus=usb-0000:00:08.2-3
|
||||
//config: new_interface_name bus=usb-0000:00:08.2-3 00:80:C8:38:91:B5
|
||||
//config: new_interface_name phy_address=2 00:80:C8:38:91:B5
|
||||
//config: new_interface_name mac=00:80:C8:38:91:B5
|
||||
//config: new_interface_name 00:80:C8:38:91:B5
|
||||
|
||||
//usage:#define nameif_trivial_usage
|
||||
//usage: IF_NOT_FEATURE_NAMEIF_EXTENDED(
|
||||
//usage: "[-s] [-c FILE] [IFNAME HWADDR]..."
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_NAMEIF_EXTENDED(
|
||||
//usage: "[-s] [-c FILE] [IFNAME SELECTOR]..."
|
||||
//usage: )
|
||||
//usage:#define nameif_full_usage "\n\n"
|
||||
//usage: "Rename network interface while it in the down state."
|
||||
//usage: IF_NOT_FEATURE_NAMEIF_EXTENDED(
|
||||
//usage: "\nThe device with address HWADDR is renamed to IFACE."
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_NAMEIF_EXTENDED(
|
||||
//usage: "\nThe device matched by SELECTOR is renamed to IFACE."
|
||||
//usage: "\nSELECTOR can be a combination of:"
|
||||
//usage: "\n driver=STRING"
|
||||
//usage: "\n bus=STRING"
|
||||
//usage: "\n phy_address=NUM"
|
||||
//usage: "\n [mac=]XX:XX:XX:XX:XX:XX"
|
||||
//usage: )
|
||||
//usage: "\n"
|
||||
//usage: "\nOptions:"
|
||||
//usage: "\n -c FILE Configuration file (default: /etc/mactab)"
|
||||
//usage: "\n -s Log to syslog"
|
||||
//usage:
|
||||
//usage:#define nameif_example_usage
|
||||
//usage: "$ nameif -s dmz0 00:A0:C9:8C:F6:3F\n"
|
||||
//usage: " or\n"
|
||||
//usage: "$ nameif -c /etc/my_mactab_file\n"
|
||||
|
||||
#include "libbb.h"
|
||||
#include <syslog.h>
|
||||
#include <net/if.h>
|
||||
@ -38,6 +98,7 @@ typedef struct ethtable_s {
|
||||
#if ENABLE_FEATURE_NAMEIF_EXTENDED
|
||||
char *bus_info;
|
||||
char *driver;
|
||||
int32_t phy_address;
|
||||
#endif
|
||||
} ethtable_t;
|
||||
|
||||
@ -59,6 +120,25 @@ struct ethtool_drvinfo {
|
||||
uint32_t eedump_len; /* Size of data from ETHTOOL_GEEPROM (bytes) */
|
||||
uint32_t regdump_len; /* Size of data from ETHTOOL_GREGS (bytes) */
|
||||
};
|
||||
|
||||
struct ethtool_cmd {
|
||||
__u32 cmd;
|
||||
__u32 supported; /* Features this interface supports */
|
||||
__u32 advertising; /* Features this interface advertises */
|
||||
__u16 speed; /* The forced speed, 10Mb, 100Mb, gigabit */
|
||||
__u8 duplex; /* Duplex, half or full */
|
||||
__u8 port; /* Which connector port */
|
||||
__u8 phy_address;
|
||||
__u8 transceiver; /* Which transceiver to use */
|
||||
__u8 autoneg; /* Enable or disable autonegotiation */
|
||||
__u32 maxtxpkt; /* Tx pkts before generating tx int */
|
||||
__u32 maxrxpkt; /* Rx pkts before generating rx int */
|
||||
__u16 speed_hi;
|
||||
__u16 reserved2;
|
||||
__u32 reserved[3];
|
||||
};
|
||||
|
||||
#define ETHTOOL_GSET 0x00000001 /* Get settings. */
|
||||
#define ETHTOOL_GDRVINFO 0x00000003 /* Get driver info. */
|
||||
#endif
|
||||
|
||||
@ -74,6 +154,7 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector)
|
||||
#endif
|
||||
selector = skip_whitespace(selector);
|
||||
#if ENABLE_FEATURE_NAMEIF_EXTENDED
|
||||
ch->phy_address = -1;
|
||||
if (*selector == '\0')
|
||||
break;
|
||||
/* Search for the end .... */
|
||||
@ -87,6 +168,9 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector)
|
||||
} else if (strncmp(selector, "driver=", 7) == 0) {
|
||||
ch->driver = xstrdup(selector + 7);
|
||||
found_selector++;
|
||||
} else if (strncmp(selector, "phyaddr=", 8) == 0) {
|
||||
ch->phy_address = xatoi_positive(selector + 8);
|
||||
found_selector++;
|
||||
} else {
|
||||
#endif
|
||||
lmac = xmalloc(ETH_ALEN);
|
||||
@ -171,6 +255,7 @@ int nameif_main(int argc UNUSED_PARAM, char **argv)
|
||||
struct ifreq ifr;
|
||||
#if ENABLE_FEATURE_NAMEIF_EXTENDED
|
||||
struct ethtool_drvinfo drvinfo;
|
||||
struct ethtool_cmd eth_settings;
|
||||
#endif
|
||||
if (parser->lineno <= 2)
|
||||
continue; /* Skip the first two lines */
|
||||
@ -180,8 +265,14 @@ int nameif_main(int argc UNUSED_PARAM, char **argv)
|
||||
strncpy_IFNAMSIZ(ifr.ifr_name, token[0]);
|
||||
|
||||
#if ENABLE_FEATURE_NAMEIF_EXTENDED
|
||||
/* Check for phy address */
|
||||
memset(ð_settings, 0, sizeof(eth_settings));
|
||||
eth_settings.cmd = ETHTOOL_GSET;
|
||||
ifr.ifr_data = (caddr_t) ð_settings;
|
||||
ioctl(ctl_sk, SIOCETHTOOL, &ifr);
|
||||
|
||||
/* Check for driver etc. */
|
||||
memset(&drvinfo, 0, sizeof(struct ethtool_drvinfo));
|
||||
memset(&drvinfo, 0, sizeof(drvinfo));
|
||||
drvinfo.cmd = ETHTOOL_GDRVINFO;
|
||||
ifr.ifr_data = (caddr_t) &drvinfo;
|
||||
/* Get driver and businfo first, so we have it in drvinfo */
|
||||
@ -196,6 +287,8 @@ int nameif_main(int argc UNUSED_PARAM, char **argv)
|
||||
continue;
|
||||
if (ch->driver && strcmp(ch->driver, drvinfo.driver) != 0)
|
||||
continue;
|
||||
if (ch->phy_address != -1 && ch->phy_address != eth_settings.phy_address)
|
||||
continue;
|
||||
#endif
|
||||
if (ch->mac && memcmp(ch->mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN) != 0)
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user