net: introduce and use IFF_LIFE_ADDR_CHANGE
Subsystems (5)
v2 cover net: introduce and use IFF_LIFE_ADDR_CHANGE
three drivers updated, but this can be used in many others.
v1->v2:
%s/LIFE/LIVE
Jiri Pirko (4):
net: introduce new priv_flag indicating iface capable of change mac
when running
virtio_net: use IFF_LIVE_ADDR_CHANGE priv_flag
team: use IFF_LIVE_ADDR_CHANGE priv_flag
dummy: use IFF_LIVE_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 v2 1/4 net: introduce new priv_flag indicating iface capable of change mac when running
Introduce IFF_LIVE_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_LIVE_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_LIVE_ADDR_CHANGE ) &&netif_running (dev))return -EBUSY ;if (!is_valid_ether_addr (addr->sa_data))return -EADDRNOTAVAIL ;
Signature · 1 line
1.7.10.4
PATCH v2 2/4 virtio_net: use IFF_LIVE_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_LIVE_ADDR_CHANGE ; dev->netdev_ops = &virtnet_netdev; dev->features =NETIF_F_HIGHDMA ;
Signature · 1 line
1.7.10.4
PATCH v2 2/4 virtio_net: use IFF_LIVE_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_LIVE_ADDR_CHANGE ; dev->netdev_ops = &virtnet_netdev; dev->features =NETIF_F_HIGHDMA ;
Signature · 1 line
1.7.10.4
PATCH v2 3/4 team: use IFF_LIVE_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_LIVE_ADDR_CHANGE ; dev->features |=NETIF_F_LLTX ; dev->features |=NETIF_F_GRO ;
Signature · 1 line
1.7.10.4
PATCH v2 3/4 team: use IFF_LIVE_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_LIVE_ADDR_CHANGE ; dev->features |=NETIF_F_LLTX ; dev->features |=NETIF_F_GRO ;
Signature · 1 line
1.7.10.4
PATCH v2 4/4 dummy: use IFF_LIVE_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_LIVE_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 v2 4/4 dummy: use IFF_LIVE_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_LIVE_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
From: Jiri Pirko <[email protected]>
Date: Fri, 29 Jun 2012 17:10:04 +0200
Quoted 11 lines
three drivers updated, but this can be used in many others.
v1->v2:
%s/LIFE/LIVEJiri Pirko (4):
net: introduce newpriv_flagindicating iface capable of change mac
when running
virtio_net: useIFF_LIVE_ADDR_CHANGEpriv_flag
team: useIFF_LIVE_ADDR_CHANGEpriv_flag
dummy: useIFF_LIVE_ADDR_CHANGEpriv_flag
Applied, thanks Jiri.