Skip to content

Commit 4cd5773

Browse files
andy-shevgregkh
authored andcommitted
net: core: move mac_pton() to lib/net_utils.c
Since we have at least one user of this function outside of CONFIG_NET scope, we have to provide this function independently. The proposed solution is to move it under lib/net_utils.c with corresponding configuration variable and select wherever it is needed. Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reported-by: Arnd Bergmann <arnd@arndb.de> Acked-by: David S. Miller <davem@davemloft.net> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 143e9c7 commit 4cd5773

10 files changed

Lines changed: 37 additions & 23 deletions

File tree

‎drivers/misc/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ config BMP085_SPI
480480

481481
config PCH_PHUB
482482
tristate "Intel EG20T PCH/LAPIS Semicon IOH(ML7213/ML7223/ML7831) PHUB"
483+
select GENERIC_NET_UTILS
483484
depends on PCI
484485
help
485486
This driver is for PCH(Platform controller Hub) PHUB(Packet Hub) of

‎drivers/net/netconsole.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <linux/slab.h>
4141
#include <linux/console.h>
4242
#include <linux/moduleparam.h>
43+
#include <linux/kernel.h>
4344
#include <linux/string.h>
4445
#include <linux/netpoll.h>
4546
#include <linux/inet.h>

‎include/linux/if_ether.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ static inline struct ethhdr *eth_hdr(const struct sk_buff *skb)
3030

3131
int eth_header_parse(const struct sk_buff *skb, unsigned char *haddr);
3232

33-
int mac_pton(const char *s, u8 *mac);
3433
extern ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len);
3534

3635
#endif /* _LINUX_IF_ETHER_H */

‎include/linux/kernel.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@ static inline char * __deprecated pack_hex_byte(char *buf, u8 byte)
450450
extern int hex_to_bin(char ch);
451451
extern int __must_check hex2bin(u8 *dst, const char *src, size_t count);
452452

453+
int mac_pton(const char *s, u8 *mac);
454+
453455
/*
454456
* General tracing related utility functions - trace_printk(),
455457
* tracing_on/tracing_off and tracing_start()/tracing_stop

‎lib/Kconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ config GENERIC_STRNCPY_FROM_USER
2222
config GENERIC_STRNLEN_USER
2323
bool
2424

25+
config GENERIC_NET_UTILS
26+
bool
27+
2528
config GENERIC_FIND_FIRST_BIT
2629
bool
2730

‎lib/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ obj-$(CONFIG_DDR) += jedec_ddr_data.o
137137
obj-$(CONFIG_GENERIC_STRNCPY_FROM_USER) += strncpy_from_user.o
138138
obj-$(CONFIG_GENERIC_STRNLEN_USER) += strnlen_user.o
139139

140+
obj-$(CONFIG_GENERIC_NET_UTILS) += net_utils.o
141+
140142
obj-$(CONFIG_STMP_DEVICE) += stmp_device.o
141143

142144
libfdt_files = fdt.o fdt_ro.o fdt_wip.o fdt_rw.o fdt_sw.o fdt_strerror.o

‎lib/net_utils.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <linux/string.h>
2+
#include <linux/if_ether.h>
3+
#include <linux/ctype.h>
4+
#include <linux/kernel.h>
5+
6+
int mac_pton(const char *s, u8 *mac)
7+
{
8+
int i;
9+
10+
/* XX:XX:XX:XX:XX:XX */
11+
if (strlen(s) < 3 * ETH_ALEN - 1)
12+
return 0;
13+
14+
/* Don't dirty result unless string is valid MAC. */
15+
for (i = 0; i < ETH_ALEN; i++) {
16+
if (!isxdigit(s[i * 3]) || !isxdigit(s[i * 3 + 1]))
17+
return 0;
18+
if (i != ETH_ALEN - 1 && s[i * 3 + 2] != ':')
19+
return 0;
20+
}
21+
for (i = 0; i < ETH_ALEN; i++) {
22+
mac[i] = (hex_to_bin(s[i * 3]) << 4) | hex_to_bin(s[i * 3 + 1]);
23+
}
24+
return 1;
25+
}
26+
EXPORT_SYMBOL(mac_pton);

‎net/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
menuconfig NET
66
bool "Networking support"
77
select NLATTR
8+
select GENERIC_NET_UTILS
89
---help---
910
Unless you really know what you are doing, you should say Y here.
1011
The reason is that some programs need kernel networking support even

‎net/core/netpoll.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1313

1414
#include <linux/moduleparam.h>
15+
#include <linux/kernel.h>
1516
#include <linux/netdevice.h>
1617
#include <linux/etherdevice.h>
1718
#include <linux/string.h>

‎net/core/utils.c‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -338,25 +338,3 @@ void inet_proto_csum_replace16(__sum16 *sum, struct sk_buff *skb,
338338
csum_unfold(*sum)));
339339
}
340340
EXPORT_SYMBOL(inet_proto_csum_replace16);
341-
342-
int mac_pton(const char *s, u8 *mac)
343-
{
344-
int i;
345-
346-
/* XX:XX:XX:XX:XX:XX */
347-
if (strlen(s) < 3 * ETH_ALEN - 1)
348-
return 0;
349-
350-
/* Don't dirty result unless string is valid MAC. */
351-
for (i = 0; i < ETH_ALEN; i++) {
352-
if (!isxdigit(s[i * 3]) || !isxdigit(s[i * 3 + 1]))
353-
return 0;
354-
if (i != ETH_ALEN - 1 && s[i * 3 + 2] != ':')
355-
return 0;
356-
}
357-
for (i = 0; i < ETH_ALEN; i++) {
358-
mac[i] = (hex_to_bin(s[i * 3]) << 4) | hex_to_bin(s[i * 3 + 1]);
359-
}
360-
return 1;
361-
}
362-
EXPORT_SYMBOL(mac_pton);

0 commit comments

Comments
 (0)