aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shevchenko <andy.shevchenko@gmail.com>2013-06-04 12:46:26 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-06-05 15:00:27 -0400
commit4cd5773a2ae6facdde3f563087a4cc50f00d9530 (patch)
treef473e0a20e69f056394d3b268bfb4256cedff4ed
parent143e9c76c487957de89808cf2a3c828518ad131b (diff)
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>
-rw-r--r--drivers/misc/Kconfig1
-rw-r--r--drivers/net/netconsole.c1
-rw-r--r--include/linux/if_ether.h1
-rw-r--r--include/linux/kernel.h2
-rw-r--r--lib/Kconfig3
-rw-r--r--lib/Makefile2
-rw-r--r--lib/net_utils.c26
-rw-r--r--net/Kconfig1
-rw-r--r--net/core/netpoll.c1
-rw-r--r--net/core/utils.c22
10 files changed, 37 insertions, 23 deletions
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index c002d8660e30..80889d5f95f5 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -480,6 +480,7 @@ config BMP085_SPI
480 480
481config PCH_PHUB 481config PCH_PHUB
482 tristate "Intel EG20T PCH/LAPIS Semicon IOH(ML7213/ML7223/ML7831) PHUB" 482 tristate "Intel EG20T PCH/LAPIS Semicon IOH(ML7213/ML7223/ML7831) PHUB"
483 select GENERIC_NET_UTILS
483 depends on PCI 484 depends on PCI
484 help 485 help
485 This driver is for PCH(Platform controller Hub) PHUB(Packet Hub) of 486 This driver is for PCH(Platform controller Hub) PHUB(Packet Hub) of
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 59ac143dec25..4f777ed9b089 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -40,6 +40,7 @@
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/console.h> 41#include <linux/console.h>
42#include <linux/moduleparam.h> 42#include <linux/moduleparam.h>
43#include <linux/kernel.h>
43#include <linux/string.h> 44#include <linux/string.h>
44#include <linux/netpoll.h> 45#include <linux/netpoll.h>
45#include <linux/inet.h> 46#include <linux/inet.h>
diff --git a/include/linux/if_ether.h b/include/linux/if_ether.h
index 12b4d55a02af..d5569734f672 100644
--- a/include/linux/if_ether.h
+++ b/include/linux/if_ether.h
@@ -30,7 +30,6 @@ static inline struct ethhdr *eth_hdr(const struct sk_buff *skb)
30 30
31int eth_header_parse(const struct sk_buff *skb, unsigned char *haddr); 31int eth_header_parse(const struct sk_buff *skb, unsigned char *haddr);
32 32
33int mac_pton(const char *s, u8 *mac);
34extern ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len); 33extern ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len);
35 34
36#endif /* _LINUX_IF_ETHER_H */ 35#endif /* _LINUX_IF_ETHER_H */
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index e9ef6d6b51d5..3afb969441d1 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -450,6 +450,8 @@ static inline char * __deprecated pack_hex_byte(char *buf, u8 byte)
450extern int hex_to_bin(char ch); 450extern int hex_to_bin(char ch);
451extern int __must_check hex2bin(u8 *dst, const char *src, size_t count); 451extern int __must_check hex2bin(u8 *dst, const char *src, size_t count);
452 452
453int mac_pton(const char *s, u8 *mac);
454
453/* 455/*
454 * General tracing related utility functions - trace_printk(), 456 * General tracing related utility functions - trace_printk(),
455 * tracing_on/tracing_off and tracing_start()/tracing_stop 457 * tracing_on/tracing_off and tracing_start()/tracing_stop
diff --git a/lib/Kconfig b/lib/Kconfig
index fe01d418b09a..d246a3bbd6ef 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -22,6 +22,9 @@ config GENERIC_STRNCPY_FROM_USER
22config GENERIC_STRNLEN_USER 22config GENERIC_STRNLEN_USER
23 bool 23 bool
24 24
25config GENERIC_NET_UTILS
26 bool
27
25config GENERIC_FIND_FIRST_BIT 28config GENERIC_FIND_FIRST_BIT
26 bool 29 bool
27 30
diff --git a/lib/Makefile b/lib/Makefile
index c55a037a354e..22f0f4e8a9e1 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -137,6 +137,8 @@ obj-$(CONFIG_DDR) += jedec_ddr_data.o
137obj-$(CONFIG_GENERIC_STRNCPY_FROM_USER) += strncpy_from_user.o 137obj-$(CONFIG_GENERIC_STRNCPY_FROM_USER) += strncpy_from_user.o
138obj-$(CONFIG_GENERIC_STRNLEN_USER) += strnlen_user.o 138obj-$(CONFIG_GENERIC_STRNLEN_USER) += strnlen_user.o
139 139
140obj-$(CONFIG_GENERIC_NET_UTILS) += net_utils.o
141
140obj-$(CONFIG_STMP_DEVICE) += stmp_device.o 142obj-$(CONFIG_STMP_DEVICE) += stmp_device.o
141 143
142libfdt_files = fdt.o fdt_ro.o fdt_wip.o fdt_rw.o fdt_sw.o fdt_strerror.o 144libfdt_files = fdt.o fdt_ro.o fdt_wip.o fdt_rw.o fdt_sw.o fdt_strerror.o
diff --git a/lib/net_utils.c b/lib/net_utils.c
new file mode 100644
index 000000000000..2e3c52c8d050
--- /dev/null
+++ b/lib/net_utils.c
@@ -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
6int 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}
26EXPORT_SYMBOL(mac_pton);
diff --git a/net/Kconfig b/net/Kconfig
index 2ddc9046868e..6dfe1c636a80 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -5,6 +5,7 @@
5menuconfig NET 5menuconfig NET
6 bool "Networking support" 6 bool "Networking support"
7 select NLATTR 7 select NLATTR
8 select GENERIC_NET_UTILS
8 ---help--- 9 ---help---
9 Unless you really know what you are doing, you should say Y here. 10 Unless you really know what you are doing, you should say Y here.
10 The reason is that some programs need kernel networking support even 11 The reason is that some programs need kernel networking support even
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index cec074be8c43..35a9f0804b6f 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -12,6 +12,7 @@
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 13
14#include <linux/moduleparam.h> 14#include <linux/moduleparam.h>
15#include <linux/kernel.h>
15#include <linux/netdevice.h> 16#include <linux/netdevice.h>
16#include <linux/etherdevice.h> 17#include <linux/etherdevice.h>
17#include <linux/string.h> 18#include <linux/string.h>
diff --git a/net/core/utils.c b/net/core/utils.c
index 3c7f5b51b979..aa88e23fc87a 100644
--- a/net/core/utils.c
+++ b/net/core/utils.c
@@ -338,25 +338,3 @@ void inet_proto_csum_replace16(__sum16 *sum, struct sk_buff *skb,
338 csum_unfold(*sum))); 338 csum_unfold(*sum)));
339} 339}
340EXPORT_SYMBOL(inet_proto_csum_replace16); 340EXPORT_SYMBOL(inet_proto_csum_replace16);
341
342int 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}
362EXPORT_SYMBOL(mac_pton);