net: introduce and use IFF_LIFE_ADDR_CHANGE
Subsystems (5)
cover net: introduce and use IFF_LIFE_ADDR_CHANGE
three drivers updated, but this can be used in many others.
Jiri Pirko (4):
net: introduce new priv_flag indicating iface capable of change mac
when running
virtio_net: use IFF_LIFE_ADDR_CHANGE priv_flag
team: use IFF_LIFE_ADDR_CHANGE priv_flag
dummy: use IFF_LIFE_ADDR_CHANGE priv_flag
drivers/net/dummy.c | 15 ++------------- drivers/net/team/team.c | 9 +++++---- drivers/net/virtio_net.c | 11 +++++------ include/linux/if.h | 2 ++ net/ethernet/eth.c | 2 +- 5 files changed, 15 insertions(+), 24 deletions(-)
Signature · 1 line
1.7.10.4
PATCH 1/4 net: introduce new priv_flag indicating iface capable of change mac when running
Introduce IFF_LIFE_ADDR_CHANGE priv_flag and use it to disable netif_running() check in eth_mac_addr()
--- include/linux/if.h | 2 ++ net/ethernet/eth.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
include/linux/if.h +2 -0
@@ -81,6 +81,8 @@#define IFF_UNICAST_FLT 0x20000/* Supports unicast filtering */ #define IFF_TEAM_PORT 0x40000/* device used as team port */ #define IFF_SUPP_NOFCS 0x80000/* device supports sending custom FCS */ +#define IFF_LIFE_ADDR_CHANGE 0x100000/* device supports hardware address +* change when it's running */ #define IF_GET_IFACE 0x0001/* for querying only */
net/ethernet/eth.c +1 -1
@@ -283,7 +283,7 @@ int eth_mac_addr(struct net_device *dev, void *p) {struct sockaddr *addr = p; -if (netif_running (dev)) +if (!(dev->priv_flags &IFF_LIFE_ADDR_CHANGE ) &&netif_running (dev))return -EBUSY ;if (!is_valid_ether_addr (addr->sa_data))return -EADDRNOTAVAIL ;
Signature · 1 line
1.7.10.4
Re: [patch net-next 1/4] net: introduce new priv_flag indicating iface capable of change mac when running
Quoted 27 lines · Jiri Pirko
Introduce
IFF_LIFE_ADDR_CHANGEpriv_flagand use it to disablenetif_running()check ineth_mac_addr()Signed-off-by Jiri Pirko <[email protected]>--- include/linux/if.h | 2 ++ net/ethernet/eth.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)include/linux/if.h +2
-0@@ -81,6 +81,8 @@#define IFF_UNICAST_FLT 0x20000/* Supports unicast filtering */ #define IFF_TEAM_PORT 0x40000/* device used as team port */ #define IFF_SUPP_NOFCS 0x80000/* device supports sending custom FCS */ +#define IFF_LIFE_ADDR_CHANGE 0x100000/* device supports hardware address +* change when it's running */ #define IF_GET_IFACE 0x0001/* for querying only */ net/ethernet/eth.c +0
-0
net/ethernet/eth.c int eth_mac_addr(struct net_device *dev, void *p) · line 289
Quoted 8 lines
net/ethernet/eth.c +1
-1@@ -283,7 +283,7 @@ int eth_mac_addr(struct net_device *dev, void *p) {struct sockaddr *addr = p; -if (netif_running (dev)) +if (!(dev->priv_flags &IFF_LIFE_ADDR_CHANGE ) &&netif_running (dev))return -EBUSY ;if (!is_valid_ether_addr (addr->sa_data))return -EADDRNOTAVAIL ;
Since the memcpy() is not atomic, there is a small window where a reader could get a half-changed mac address. I guess its a detail.
Michael S. Tsirkin
maintainerRe: [patch net-next 1/4] net: introduce new priv_flag indicating iface capable of change mac when running
Quoted 31 lines · Eric Dumazet
Quoted 30 lines · Jiri Pirko
Introduce
IFF_LIFE_ADDR_CHANGEpriv_flagand use it to disablenetif_running()check ineth_mac_addr()Signed-off-by Jiri Pirko <[email protected]>--- include/linux/if.h | 2 ++ net/ethernet/eth.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)include/linux/if.h +2
-0@@ -81,6 +81,8 @@#define IFF_UNICAST_FLT 0x20000/* Supports unicast filtering */ #define IFF_TEAM_PORT 0x40000/* device used as team port */ #define IFF_SUPP_NOFCS 0x80000/* device supports sending custom FCS */ +#define IFF_LIFE_ADDR_CHANGE 0x100000/* device supports hardware address +* change when it's running */ #define IF_GET_IFACE 0x0001/* for querying only */ net/ethernet/eth.c +0
-0@@ -283,7 +283,7 @@ int eth_mac_addr(struct net_device *dev, void *p) {struct sockaddr *addr = p;
Quoted 9 lines
net/ethernet/eth.c int eth_mac_addr(struct net_device *dev, void *p) · line 289
Quoted 5 lines
net/ethernet/eth.c +1
-1-if (netif_running (dev)) +if (!(dev->priv_flags &IFF_LIFE_ADDR_CHANGE ) &&netif_running (dev))return -EBUSY ;if (!is_valid_ether_addr (addr->sa_data))return -EADDRNOTAVAIL ;Since the
memcpy()is not atomic, there is a small window where a reader could get a half-changed mac address. I guess its a detail.
At least for virtio nothing changes - we had this bug forever. How'd you fix this?
Signature · 1 line
MST
Re: [patch net-next 1/4] net: introduce new priv_flag indicating iface capable of change mac when running
In reply to Jiri PirkoQuoted 14 lines · Jiri Pirko
Introduce
IFF_LIFE_ADDR_CHANGEpriv_flagand use it to disablenetif_running()check ineth_mac_addr()Signed-off-by Jiri Pirko <[email protected]>--- include/linux/if.h | 2 ++ net/ethernet/eth.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)include/linux/if.h +0
-0
include/linux/if.h line 85
Quoted 5 lines
include/linux/if.h +2
-0@@ -81,6 +81,8 @@#define IFF_UNICAST_FLT 0x20000/* Supports unicast filtering */ #define IFF_TEAM_PORT 0x40000/* device used as team port */ #define IFF_SUPP_NOFCS 0x80000/* device supports sending custom FCS */ +#define IFF_LIFE_ADDR_CHANGE 0x100000/* device supports hardware address +* change when it's running */
[...]
Any device that has IFF_UNICAST_FLT can update the unicast MAC filter while it's running; doesn't that go hand-in-hand with being able to handle changes to the primary MAC address? Is the new flag really necessary at all?
Ben.
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [patch net-next 1/4] net: introduce new priv_flag indicating iface capable of change mac when running
Quoted 22 lines · Fri, Jun 29, 2012 at 12:17:34AM CEST, [email protected] wrote:
Quoted 19 lines · Jiri Pirko
Introduce
IFF_LIFE_ADDR_CHANGEpriv_flagand use it to disablenetif_running()check ineth_mac_addr()Signed-off-by Jiri Pirko <[email protected]>--- include/linux/if.h | 2 ++ net/ethernet/eth.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)include/linux/if.h +2
-0@@ -81,6 +81,8 @@#define IFF_UNICAST_FLT 0x20000/* Supports unicast filtering */ #define IFF_TEAM_PORT 0x40000/* device used as team port */ #define IFF_SUPP_NOFCS 0x80000/* device supports sending custom FCS */ +#define IFF_LIFE_ADDR_CHANGE 0x100000/* device supports hardware address +* change when it's running */ [...]
Quoted 4 lines
Any device that has
IFF_UNICAST_FLTcan update the unicast MAC filter while it's running; doesn't that go hand-in-hand with being able to handle changes to the primary MAC address? Is the new flag really necessary at all?
Hmm, this makes sense. But, can you guarantee that all devices behave like this?
Also, there are many devices that does not support unicast filtering and yet they support updating mac adress while running.
Jirka
Quoted 8 lines
Ben.
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
PATCH 2/4 virtio_net: use IFF_LIFE_ADDR_CHANGE priv_flag
In reply to Jiri Pirko--- drivers/net/virtio_net.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/net/virtio_net.c +5 -6
@@ -679,12 +679,11 @@ static int virtnet_set_mac_address(struct net_device *dev, void *p) {struct virtnet_info *vi =netdev_priv (dev);struct virtio_device *vdev = vi->vdev; -struct sockaddr *addr = p; +int ret; -if (!is_valid_ether_addr (addr->sa_data)) -return -EADDRNOTAVAIL ; -memcpy (dev->dev_addr, addr->sa_data,ETH_ALEN ); - dev->addr_assign_type &= ~NET_ADDR_RANDOM ; + ret =eth_mac_addr (dev, p); +if (ret) +return ret;if (virtio_has_feature (vdev,VIRTIO_NET_F_MAC )) vdev->config->set(vdev, offsetof(struct virtio_net_config, mac),
@@ -1063,7 +1062,7 @@ static int virtnet_probe(struct virtio_device *vdev)return -ENOMEM ;/* Set up network device as normal. */ - dev->priv_flags |=IFF_UNICAST_FLT ; + dev->priv_flags |=IFF_UNICAST_FLT |IFF_LIFE_ADDR_CHANGE ; dev->netdev_ops = &virtnet_netdev; dev->features =NETIF_F_HIGHDMA ;
Signature · 1 line
1.7.10.4
Re: [patch net-next 2/4] virtio_net: use IFF_LIFE_ADDR_CHANGE priv_flag
Quoted 1 line · Jiri Pirko
Signed-off-by Jiri Pirko <[email protected]>
FWIW
Quoted 36 lines
--- drivers/net/virtio_net.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/net/virtio_net.c +5
-6@@ -679,12 +679,11 @@ static int virtnet_set_mac_address(struct net_device *dev, void *p) {struct virtnet_info *vi =netdev_priv (dev);struct virtio_device *vdev = vi->vdev; -struct sockaddr *addr = p; +int ret; -if (!is_valid_ether_addr (addr->sa_data)) -return -EADDRNOTAVAIL ; -memcpy (dev->dev_addr, addr->sa_data,ETH_ALEN ); - dev->addr_assign_type &= ~NET_ADDR_RANDOM ; + ret =eth_mac_addr (dev, p); +if (ret) +return ret;if (virtio_has_feature (vdev,VIRTIO_NET_F_MAC )) vdev->config->set(vdev, offsetof(struct virtio_net_config, mac),@@ -1063,7 +1062,7 @@ static int virtnet_probe(struct virtio_device *vdev)return -ENOMEM ;/* Set up network device as normal. */ - dev->priv_flags |=IFF_UNICAST_FLT ; + dev->priv_flags |=IFF_UNICAST_FLT |IFF_LIFE_ADDR_CHANGE ; dev->netdev_ops = &virtnet_netdev; dev->features =NETIF_F_HIGHDMA ;Signature · 1 line
1.7.10.4
PATCH 3/4 team: use IFF_LIFE_ADDR_CHANGE priv_flag
In reply to Jiri Pirko--- drivers/net/team/team.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/team/team.c +5 -4
@@ -1188,10 +1188,11 @@ static int team_set_mac_address(struct net_device *dev, void *p) {struct team *team =netdev_priv (dev);struct team_port *port; -struct sockaddr *addr = p; +int err; - dev->addr_assign_type &= ~NET_ADDR_RANDOM ; -memcpy (dev->dev_addr, addr->sa_data,ETH_ALEN ); + err =eth_mac_addr (dev, p); +if (err) +return err;rcu_read_lock ();list_for_each_entry_rcu (port, &team->port_list, list)if (team->ops.port_change_mac)
@@ -1393,7 +1394,7 @@ static void team_setup(struct net_device *dev)* bring us to promisc mode in case a unicast addr is added. * Let this up to underlay drivers. */ - dev->priv_flags |=IFF_UNICAST_FLT ; + dev->priv_flags |=IFF_UNICAST_FLT |IFF_LIFE_ADDR_CHANGE ; dev->features |=NETIF_F_LLTX ; dev->features |=NETIF_F_GRO ;
Signature · 1 line
1.7.10.4
PATCH 4/4 dummy: use IFF_LIFE_ADDR_CHANGE priv_flag
In reply to Jiri Pirko--- drivers/net/dummy.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)
drivers/net/dummy.c +2 -13
@@ -40,18 +40,6 @@static int numdummies =1 ; -static int dummy_set_address (struct net_device *dev,void *p) -{ -struct sockaddr *sa = p; - -if (!is_valid_ether_addr (sa->sa_data)) -return -EADDRNOTAVAIL ; - - dev->addr_assign_type &= ~NET_ADDR_RANDOM ; -memcpy (dev->dev_addr, sa->sa_data,ETH_ALEN ); -return 0 ; -} -/* fake multicast ability */ static void set_multicast_list (struct net_device *dev) {
@@ -118,7 +106,7 @@ static const struct net_device_ops dummy_netdev_ops = { .ndo_start_xmit = dummy_xmit, .ndo_validate_addr = eth_validate_addr, .ndo_set_rx_mode = set_multicast_list, - .ndo_set_mac_address = dummy_set_address, + .ndo_set_mac_address = eth_mac_addr, .ndo_get_stats64 = dummy_get_stats64, };
@@ -134,6 +122,7 @@ static void dummy_setup(struct net_device *dev) dev->tx_queue_len =0 ; dev->flags |=IFF_NOARP ; dev->flags &= ~IFF_MULTICAST ; + dev->priv_flags |=IFF_LIFE_ADDR_CHANGE ; dev->features |=NETIF_F_SG |NETIF_F_FRAGLIST |NETIF_F_TSO ; dev->features |=NETIF_F_HW_CSUM |NETIF_F_HIGHDMA |NETIF_F_LLTX ;eth_hw_addr_random (dev);
Signature · 1 line
1.7.10.4
PATCH 4/4 dummy: use IFF_LIFE_ADDR_CHANGE priv_flag
In reply to Jiri Pirko--- drivers/net/dummy.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)
drivers/net/dummy.c +2 -13
@@ -40,18 +40,6 @@static int numdummies =1 ; -static int dummy_set_address (struct net_device *dev,void *p) -{ -struct sockaddr *sa = p; - -if (!is_valid_ether_addr (sa->sa_data)) -return -EADDRNOTAVAIL ; - - dev->addr_assign_type &= ~NET_ADDR_RANDOM ; -memcpy (dev->dev_addr, sa->sa_data,ETH_ALEN ); -return 0 ; -} -/* fake multicast ability */ static void set_multicast_list (struct net_device *dev) {
@@ -118,7 +106,7 @@ static const struct net_device_ops dummy_netdev_ops = { .ndo_start_xmit = dummy_xmit, .ndo_validate_addr = eth_validate_addr, .ndo_set_rx_mode = set_multicast_list, - .ndo_set_mac_address = dummy_set_address, + .ndo_set_mac_address = eth_mac_addr, .ndo_get_stats64 = dummy_get_stats64, };
@@ -134,6 +122,7 @@ static void dummy_setup(struct net_device *dev) dev->tx_queue_len =0 ; dev->flags |=IFF_NOARP ; dev->flags &= ~IFF_MULTICAST ; + dev->priv_flags |=IFF_LIFE_ADDR_CHANGE ; dev->features |=NETIF_F_SG |NETIF_F_FRAGLIST |NETIF_F_TSO ; dev->features |=NETIF_F_HW_CSUM |NETIF_F_HIGHDMA |NETIF_F_LLTX ;eth_hw_addr_random (dev);
Signature · 1 line
1.7.10.4
Quoted 8 lines · Jiri Pirko
three drivers updated, but this can be used in many others.
Jiri Pirko (4):
net: introduce newpriv_flagindicating iface capable of change mac
when running
virtio_net: useIFF_LIFE_ADDR_CHANGEpriv_flag
team: useIFF_LIFE_ADDR_CHANGEpriv_flag
dummy: useIFF_LIFE_ADDR_CHANGEpriv_flag
I think you must mean LIVE and not LIFE...
Thanks,
Richard
Quoted 15 lines
drivers/net/dummy.c | 15 ++------------- drivers/net/team/team.c | 9 +++++---- drivers/net/virtio_net.c | 11 +++++------ include/linux/if.h | 2 ++ net/ethernet/eth.c | 2 +- 5 files changed, 15 insertions(+), 24 deletions(-)Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Jiri Pirko
three drivers updated, but this can be used in many others.
Jiri Pirko (4):
net: introduce newpriv_flagindicating iface capable of change mac
when running
virtio_net: useIFF_LIFE_ADDR_CHANGEpriv_flag
team: useIFF_LIFE_ADDR_CHANGEpriv_flag
dummy: useIFF_LIFE_ADDR_CHANGEpriv_flag
I think you must mean LIVE and not LIFE...
Thanks,
Richard
Quoted 15 lines
drivers/net/dummy.c | 15 ++------------- drivers/net/team/team.c | 9 +++++---- drivers/net/virtio_net.c | 11 +++++------ include/linux/if.h | 2 ++ net/ethernet/eth.c | 2 +- 5 files changed, 15 insertions(+), 24 deletions(-)Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines · Thu, Jun 28, 2012 at 05:15:07PM CEST, [email protected] wrote:
Quoted 8 lines · Jiri Pirko
three drivers updated, but this can be used in many others.
Jiri Pirko (4):
net: introduce newpriv_flagindicating iface capable of change mac
when running
virtio_net: useIFF_LIFE_ADDR_CHANGEpriv_flag
team: useIFF_LIFE_ADDR_CHANGEpriv_flag
dummy: useIFF_LIFE_ADDR_CHANGEpriv_flagI think you must mean LIVE and not LIFE...
Good point. I will change it and repost, but I will give it some time so people can express themselves.
Thanks!
Jirka
Quoted 20 lines
Thanks,
RichardQuoted 15 lines
drivers/net/dummy.c | 15 ++------------- drivers/net/team/team.c | 9 +++++---- drivers/net/virtio_net.c | 11 +++++------ include/linux/if.h | 2 ++ net/ethernet/eth.c | 2 +- 5 files changed, 15 insertions(+), 24 deletions(-)Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html