bridge: Use helpers to handle MAC address
Subsystems (3)
PATCH 1/1 bridge: Use helpers to handle MAC address
Use
%pM to print MAC
mac_pton() to convert it from ASCII to binary format, and ether_addr_copy() to copy.
--- net/bridge/br_sysfs_br.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
net/bridge/br_sysfs_br.c +3 -10
@@ -272,10 +272,7 @@ static ssize_t group_addr_show(struct device *d, struct device_attribute *attr, char *buf) { struct net_bridge *br = to_bridge(d); -return sprintf (buf,"%x:%x:%x:%x:%x:%x\n" , - br->group_addr[0 ], br->group_addr[1 ], - br->group_addr[2 ], br->group_addr[3 ], - br->group_addr[4 ], br->group_addr[5 ]); +return sprintf (buf,"%pM\n" , br->group_addr); } static ssize_t group_addr_store(struct device *d,
@@ -284,14 +281,11 @@ static ssize_t group_addr_store(struct device *d, {struct net_bridge *br =to_bridge (d);u8 new_addr[6 ]; -int i;if (!ns_capable (dev_net (br->dev)->user_ns,CAP_NET_ADMIN ))return -EPERM ; -if (sscanf (buf,"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx" , - &new_addr[0 ], &new_addr[1 ], &new_addr[2 ], - &new_addr[3 ], &new_addr[4 ], &new_addr[5 ]) !=6 ) +if (!mac_pton (buf, new_addr))return -EINVAL ;if (!is_link_local_ether_addr (new_addr))
@@ -306,8 +300,7 @@ static ssize_t group_addr_store(struct device *d,return restart_syscall ();spin_lock_bh (&br->lock); -for (i =0 ; i <6 ; i++) - br->group_addr[i] = new_addr[i]; +ether_addr_copy (br->group_addr, new_addr);spin_unlock_bh (&br->lock); br->group_addr_set = true;
Signature · 1 line
2.15.1
Quoted 6 lines · On Tue, 19 Dec 2017 20:10:53 +0200 Andy Shevchenko…
Use
%pM to print MAC
mac_pton()to convert it from ASCII to binary format, andether_addr_copy()to copy.Signed-off-by Andy Shevchenko <[email protected]>
Looks good
Quoted 6 lines · Andy Shevchenko
Use
%pM to print MAC
mac_pton()to convert it from ASCII to binary format, andether_addr_copy()to copy.Signed-off-by Andy Shevchenko <[email protected]>
(same)
select GENERIC_NET_UTILS
?
Quoted 47 lines
--- net/bridge/br_sysfs_br.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)net/bridge/br_sysfs_br.c +3
-10@@ -272,10 +272,7 @@ static ssize_t group_addr_show(struct device *d, struct device_attribute *attr, char *buf) { struct net_bridge *br = to_bridge(d); -return sprintf (buf,"%x:%x:%x:%x:%x:%x\n" , - br->group_addr[0 ], br->group_addr[1 ], - br->group_addr[2 ], br->group_addr[3 ], - br->group_addr[4 ], br->group_addr[5 ]); +return sprintf (buf,"%pM\n" , br->group_addr); } static ssize_t group_addr_store(struct device *d,@@ -284,14 +281,11 @@ static ssize_t group_addr_store(struct device *d, {struct net_bridge *br =to_bridge (d);u8 new_addr[6 ]; -int i;if (!ns_capable (dev_net (br->dev)->user_ns,CAP_NET_ADMIN ))return -EPERM ; -if (sscanf (buf,"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx" , - &new_addr[0 ], &new_addr[1 ], &new_addr[2 ], - &new_addr[3 ], &new_addr[4 ], &new_addr[5 ]) !=6 ) +if (!mac_pton (buf, new_addr))return -EINVAL ;if (!is_link_local_ether_addr (new_addr))@@ -306,8 +300,7 @@ static ssize_t group_addr_store(struct device *d,return restart_syscall ();spin_lock_bh (&br->lock); -for (i =0 ; i <6 ; i++) - br->group_addr[i] = new_addr[i]; +ether_addr_copy (br->group_addr, new_addr);spin_unlock_bh (&br->lock); br->group_addr_set = true;
Signature · 1 line
~Randy
Quoted 11 lines · Randy Dunlap
Quoted 6 lines · Andy Shevchenko
Use
%pM to print MAC
mac_pton()to convert it from ASCII to binary format, andether_addr_copy()to copy.Signed-off-by Andy Shevchenko <[email protected]>(same)
selectGENERIC_NET_UTILS
?
(same)
Done by CONFIG_NET.
Quoted 54 lines
Quoted 52 lines
--- net/bridge/br_sysfs_br.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)net/bridge/br_sysfs_br.c +1
-4@@ -272,10 +272,7 @@ static ssize_t group_addr_show(struct device *d, struct device_attribute *attr, char *buf) {struct net_bridge *br =to_bridge (d); -return sprintf (buf,"%x:%x:%x:%x:%x:%x\n" , - br->group_addr[0 ], br->group_addr[1 ], - br->group_addr[2 ], br->group_addr[3 ], - br->group_addr[4 ], br->group_addr[5 ]); +return sprintf (buf,"%pM\n" , br->group_addr); }static
ssize_tgroup_addr_store(struct device *d,net/bridge/br_sysfs_br.c +1
-4@@ -284,14 +281,11 @@ static ssize_t group_addr_store(struct device *d, {struct net_bridge *br =to_bridge (d);u8 new_addr[6 ]; -int i;if (!ns_capable (dev_net (br->dev)->user_ns,CAP_NET_ADMIN ))return -EPERM ; -if (sscanf (buf,"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx" , - &new_addr[0 ], &new_addr[1 ], &new_addr[2 ], - &new_addr[3 ], &new_addr[4 ], &new_addr[5 ]) !=6 ) +if (!mac_pton (buf, new_addr))return -EINVAL ;net/bridge/br_sysfs_br.c +1
-2if (!is_link_local_ether_addr (new_addr))@@ -306,8 +300,7 @@ static ssize_t group_addr_store(struct device *d, return restart_syscall();spin_lock_bh (&br->lock); -for (i =0 ; i <6 ; i++) - br->group_addr[i] = new_addr[i]; +ether_addr_copy (br->group_addr, new_addr);spin_unlock_bh (&br->lock);
br->group_addr_set= true;
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
From: Andy Shevchenko <[email protected]>
Date: Tue, 19 Dec 2017 20:10:53 +0200
Quoted 6 lines
Use
%pM to print MAC
mac_pton()to convert it from ASCII to binary format, andether_addr_copy()to copy.Signed-off-by Andy Shevchenko <[email protected]>
Applied to net-next