diff options
author | Phil Sutter <phil.sutter@viprinet.com> | 2011-03-06 19:42:51 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-03-06 19:42:51 +0100 |
commit | 293a8f250d35157aced813695e1975078a521d19 (patch) | |
tree | 4a99690e5464e1ea832cfca2907fe0732ba1b4fa | |
parent | 2adc0e6d8b146991063309238569a703af6bda8f (diff) | |
download | busybox-w32-293a8f250d35157aced813695e1975078a521d19.tar.gz busybox-w32-293a8f250d35157aced813695e1975078a521d19.tar.bz2 busybox-w32-293a8f250d35157aced813695e1975078a521d19.zip |
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>
-rw-r--r-- | include/usage.src.h | 14 | ||||
-rw-r--r-- | networking/Config.src | 29 | ||||
-rw-r--r-- | networking/nameif.c | 95 |
3 files changed, 94 insertions, 44 deletions
diff --git a/include/usage.src.h b/include/usage.src.h index c2575b561..df770c454 100644 --- a/include/usage.src.h +++ b/include/usage.src.h | |||
@@ -2546,20 +2546,6 @@ INSERT | |||
2546 | "ras3 reset retension rewind rewoffline seek setblk setdensity\n" \ | 2546 | "ras3 reset retension rewind rewoffline seek setblk setdensity\n" \ |
2547 | "setpart tell unload unlock weof wset" \ | 2547 | "setpart tell unload unlock weof wset" \ |
2548 | 2548 | ||
2549 | #define nameif_trivial_usage \ | ||
2550 | "[-s] [-c FILE] [{IFNAME MACADDR}]" | ||
2551 | #define nameif_full_usage "\n\n" \ | ||
2552 | "Rename network interface while it in the down state\n" \ | ||
2553 | "\nOptions:" \ | ||
2554 | "\n -c FILE Use configuration file (default: /etc/mactab)" \ | ||
2555 | "\n -s Use syslog (LOCAL0 facility)" \ | ||
2556 | "\n IFNAME MACADDR new_interface_name interface_mac_address" \ | ||
2557 | |||
2558 | #define nameif_example_usage \ | ||
2559 | "$ nameif -s dmz0 00:A0:C9:8C:F6:3F\n" \ | ||
2560 | " or\n" \ | ||
2561 | "$ nameif -c /etc/my_mactab_file\n" \ | ||
2562 | |||
2563 | #define nohup_trivial_usage \ | 2549 | #define nohup_trivial_usage \ |
2564 | "PROG ARGS" | 2550 | "PROG ARGS" |
2565 | #define nohup_full_usage "\n\n" \ | 2551 | #define nohup_full_usage "\n\n" \ |
diff --git a/networking/Config.src b/networking/Config.src index 06930f4a6..8aeba0ef9 100644 --- a/networking/Config.src +++ b/networking/Config.src | |||
@@ -612,35 +612,6 @@ config FEATURE_IPCALC_LONG_OPTIONS | |||
612 | help | 612 | help |
613 | Support long options for the ipcalc applet. | 613 | Support long options for the ipcalc applet. |
614 | 614 | ||
615 | config NAMEIF | ||
616 | bool "nameif" | ||
617 | default y | ||
618 | select PLATFORM_LINUX | ||
619 | select FEATURE_SYSLOG | ||
620 | help | ||
621 | nameif is used to rename network interface by its MAC address. | ||
622 | Renamed interfaces MUST be in the down state. | ||
623 | It is possible to use a file (default: /etc/mactab) | ||
624 | with list of new interface names and MACs. | ||
625 | Maximum interface name length: IFNAMSIZ = 16 | ||
626 | File fields are separated by space or tab. | ||
627 | File format: | ||
628 | # Comment | ||
629 | new_interface_name XX:XX:XX:XX:XX:XX | ||
630 | |||
631 | config FEATURE_NAMEIF_EXTENDED | ||
632 | bool "Extended nameif" | ||
633 | default y | ||
634 | depends on NAMEIF | ||
635 | help | ||
636 | This extends the nameif syntax to support the bus_info and driver | ||
637 | checks. The syntax is compatible to the normal nameif. | ||
638 | File format: | ||
639 | new_interface_name driver=asix bus=usb-0000:00:08.2-3 | ||
640 | new_interface_name bus=usb-0000:00:08.2-3 00:80:C8:38:91:B5 | ||
641 | new_interface_name mac=00:80:C8:38:91:B5 | ||
642 | new_interface_name 00:80:C8:38:91:B5 | ||
643 | |||
644 | config NETSTAT | 615 | config NETSTAT |
645 | bool "netstat" | 616 | bool "netstat" |
646 | default y | 617 | default y |
diff --git a/networking/nameif.c b/networking/nameif.c index e9bff8b11..78719edac 100644 --- a/networking/nameif.c +++ b/networking/nameif.c | |||
@@ -10,6 +10,66 @@ | |||
10 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | 10 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
11 | */ | 11 | */ |
12 | 12 | ||
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: "\nOptions:" | ||
65 | //usage: "\n -c FILE Configuration file (default: /etc/mactab)" | ||
66 | //usage: "\n -s Log to syslog" | ||
67 | //usage: | ||
68 | //usage:#define nameif_example_usage | ||
69 | //usage: "$ nameif -s dmz0 00:A0:C9:8C:F6:3F\n" | ||
70 | //usage: " or\n" | ||
71 | //usage: "$ nameif -c /etc/my_mactab_file\n" | ||
72 | |||
13 | #include "libbb.h" | 73 | #include "libbb.h" |
14 | #include <syslog.h> | 74 | #include <syslog.h> |
15 | #include <net/if.h> | 75 | #include <net/if.h> |
@@ -38,6 +98,7 @@ typedef struct ethtable_s { | |||
38 | #if ENABLE_FEATURE_NAMEIF_EXTENDED | 98 | #if ENABLE_FEATURE_NAMEIF_EXTENDED |
39 | char *bus_info; | 99 | char *bus_info; |
40 | char *driver; | 100 | char *driver; |
101 | int32_t phy_address; | ||
41 | #endif | 102 | #endif |
42 | } ethtable_t; | 103 | } ethtable_t; |
43 | 104 | ||
@@ -59,6 +120,25 @@ struct ethtool_drvinfo { | |||
59 | uint32_t eedump_len; /* Size of data from ETHTOOL_GEEPROM (bytes) */ | 120 | uint32_t eedump_len; /* Size of data from ETHTOOL_GEEPROM (bytes) */ |
60 | uint32_t regdump_len; /* Size of data from ETHTOOL_GREGS (bytes) */ | 121 | uint32_t regdump_len; /* Size of data from ETHTOOL_GREGS (bytes) */ |
61 | }; | 122 | }; |
123 | |||
124 | struct ethtool_cmd { | ||
125 | __u32 cmd; | ||
126 | __u32 supported; /* Features this interface supports */ | ||
127 | __u32 advertising; /* Features this interface advertises */ | ||
128 | __u16 speed; /* The forced speed, 10Mb, 100Mb, gigabit */ | ||
129 | __u8 duplex; /* Duplex, half or full */ | ||
130 | __u8 port; /* Which connector port */ | ||
131 | __u8 phy_address; | ||
132 | __u8 transceiver; /* Which transceiver to use */ | ||
133 | __u8 autoneg; /* Enable or disable autonegotiation */ | ||
134 | __u32 maxtxpkt; /* Tx pkts before generating tx int */ | ||
135 | __u32 maxrxpkt; /* Rx pkts before generating rx int */ | ||
136 | __u16 speed_hi; | ||
137 | __u16 reserved2; | ||
138 | __u32 reserved[3]; | ||
139 | }; | ||
140 | |||
141 | #define ETHTOOL_GSET 0x00000001 /* Get settings. */ | ||
62 | #define ETHTOOL_GDRVINFO 0x00000003 /* Get driver info. */ | 142 | #define ETHTOOL_GDRVINFO 0x00000003 /* Get driver info. */ |
63 | #endif | 143 | #endif |
64 | 144 | ||
@@ -74,6 +154,7 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector) | |||
74 | #endif | 154 | #endif |
75 | selector = skip_whitespace(selector); | 155 | selector = skip_whitespace(selector); |
76 | #if ENABLE_FEATURE_NAMEIF_EXTENDED | 156 | #if ENABLE_FEATURE_NAMEIF_EXTENDED |
157 | ch->phy_address = -1; | ||
77 | if (*selector == '\0') | 158 | if (*selector == '\0') |
78 | break; | 159 | break; |
79 | /* Search for the end .... */ | 160 | /* Search for the end .... */ |
@@ -87,6 +168,9 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector) | |||
87 | } else if (strncmp(selector, "driver=", 7) == 0) { | 168 | } else if (strncmp(selector, "driver=", 7) == 0) { |
88 | ch->driver = xstrdup(selector + 7); | 169 | ch->driver = xstrdup(selector + 7); |
89 | found_selector++; | 170 | found_selector++; |
171 | } else if (strncmp(selector, "phyaddr=", 8) == 0) { | ||
172 | ch->phy_address = xatoi_positive(selector + 8); | ||
173 | found_selector++; | ||
90 | } else { | 174 | } else { |
91 | #endif | 175 | #endif |
92 | lmac = xmalloc(ETH_ALEN); | 176 | lmac = xmalloc(ETH_ALEN); |
@@ -171,6 +255,7 @@ int nameif_main(int argc UNUSED_PARAM, char **argv) | |||
171 | struct ifreq ifr; | 255 | struct ifreq ifr; |
172 | #if ENABLE_FEATURE_NAMEIF_EXTENDED | 256 | #if ENABLE_FEATURE_NAMEIF_EXTENDED |
173 | struct ethtool_drvinfo drvinfo; | 257 | struct ethtool_drvinfo drvinfo; |
258 | struct ethtool_cmd eth_settings; | ||
174 | #endif | 259 | #endif |
175 | if (parser->lineno <= 2) | 260 | if (parser->lineno <= 2) |
176 | continue; /* Skip the first two lines */ | 261 | continue; /* Skip the first two lines */ |
@@ -180,8 +265,14 @@ int nameif_main(int argc UNUSED_PARAM, char **argv) | |||
180 | strncpy_IFNAMSIZ(ifr.ifr_name, token[0]); | 265 | strncpy_IFNAMSIZ(ifr.ifr_name, token[0]); |
181 | 266 | ||
182 | #if ENABLE_FEATURE_NAMEIF_EXTENDED | 267 | #if ENABLE_FEATURE_NAMEIF_EXTENDED |
268 | /* Check for phy address */ | ||
269 | memset(ð_settings, 0, sizeof(eth_settings)); | ||
270 | eth_settings.cmd = ETHTOOL_GSET; | ||
271 | ifr.ifr_data = (caddr_t) ð_settings; | ||
272 | ioctl(ctl_sk, SIOCETHTOOL, &ifr); | ||
273 | |||
183 | /* Check for driver etc. */ | 274 | /* Check for driver etc. */ |
184 | memset(&drvinfo, 0, sizeof(struct ethtool_drvinfo)); | 275 | memset(&drvinfo, 0, sizeof(drvinfo)); |
185 | drvinfo.cmd = ETHTOOL_GDRVINFO; | 276 | drvinfo.cmd = ETHTOOL_GDRVINFO; |
186 | ifr.ifr_data = (caddr_t) &drvinfo; | 277 | ifr.ifr_data = (caddr_t) &drvinfo; |
187 | /* Get driver and businfo first, so we have it in drvinfo */ | 278 | /* Get driver and businfo first, so we have it in drvinfo */ |
@@ -196,6 +287,8 @@ int nameif_main(int argc UNUSED_PARAM, char **argv) | |||
196 | continue; | 287 | continue; |
197 | if (ch->driver && strcmp(ch->driver, drvinfo.driver) != 0) | 288 | if (ch->driver && strcmp(ch->driver, drvinfo.driver) != 0) |
198 | continue; | 289 | continue; |
290 | if (ch->phy_address != -1 && ch->phy_address != eth_settings.phy_address) | ||
291 | continue; | ||
199 | #endif | 292 | #endif |
200 | if (ch->mac && memcmp(ch->mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN) != 0) | 293 | if (ch->mac && memcmp(ch->mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN) != 0) |
201 | continue; | 294 | continue; |