Commit e289fd28 authored by dingtianhong's avatar dingtianhong Committed by David S. Miller

macvlan: fix the problem when mac address changes for passthru mode

The macvlan dev should always have the same mac address like lowerdev
when in the passthru mode, change the mac address alone will break the
work mechanism, so when the lowerdev or macvlan mac address changes,
we should propagate the changes to another dev.

v1->v2: Allow macvlan dev to change mac address for passthru mode and propagate to
	lowerdev.

v2->v3: Don't set the mac address to the lower dev's unicast address for
	passthru mode when mac address changes.
Signed-off-by: default avatarDing Tianhong <dingtianhong@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d7ec8584
...@@ -494,35 +494,49 @@ static int macvlan_stop(struct net_device *dev) ...@@ -494,35 +494,49 @@ static int macvlan_stop(struct net_device *dev)
return 0; return 0;
} }
static int macvlan_set_mac_address(struct net_device *dev, void *p) static int macvlan_sync_address(struct net_device *dev, unsigned char *addr)
{ {
struct macvlan_dev *vlan = netdev_priv(dev); struct macvlan_dev *vlan = netdev_priv(dev);
struct net_device *lowerdev = vlan->lowerdev; struct net_device *lowerdev = vlan->lowerdev;
struct sockaddr *addr = p;
int err; int err;
if (!is_valid_ether_addr(addr->sa_data))
return -EADDRNOTAVAIL;
if (!(dev->flags & IFF_UP)) { if (!(dev->flags & IFF_UP)) {
/* Just copy in the new address */ /* Just copy in the new address */
memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); ether_addr_copy(dev->dev_addr, addr);
} else { } else {
/* Rehash and update the device filters */ /* Rehash and update the device filters */
if (macvlan_addr_busy(vlan->port, addr->sa_data)) if (macvlan_addr_busy(vlan->port, addr))
return -EBUSY; return -EBUSY;
err = dev_uc_add(lowerdev, addr->sa_data); if (!vlan->port->passthru) {
if (err) err = dev_uc_add(lowerdev, addr);
return err; if (err)
return err;
dev_uc_del(lowerdev, dev->dev_addr); dev_uc_del(lowerdev, dev->dev_addr);
}
macvlan_hash_change_addr(vlan, addr->sa_data); macvlan_hash_change_addr(vlan, addr);
} }
return 0; return 0;
} }
static int macvlan_set_mac_address(struct net_device *dev, void *p)
{
struct macvlan_dev *vlan = netdev_priv(dev);
struct sockaddr *addr = p;
if (!is_valid_ether_addr(addr->sa_data))
return -EADDRNOTAVAIL;
if (vlan->mode == MACVLAN_MODE_PASSTHRU) {
dev_set_mac_address(vlan->lowerdev, addr);
return 0;
}
return macvlan_sync_address(dev, addr->sa_data);
}
static void macvlan_change_rx_flags(struct net_device *dev, int change) static void macvlan_change_rx_flags(struct net_device *dev, int change)
{ {
struct macvlan_dev *vlan = netdev_priv(dev); struct macvlan_dev *vlan = netdev_priv(dev);
...@@ -1105,6 +1119,18 @@ static int macvlan_device_event(struct notifier_block *unused, ...@@ -1105,6 +1119,18 @@ static int macvlan_device_event(struct notifier_block *unused,
continue; continue;
dev_set_mtu(vlan->dev, dev->mtu); dev_set_mtu(vlan->dev, dev->mtu);
} }
break;
case NETDEV_CHANGEADDR:
if (!port->passthru)
return NOTIFY_DONE;
vlan = list_first_entry_or_null(&port->vlans,
struct macvlan_dev,
list);
if (macvlan_sync_address(vlan->dev, dev->dev_addr))
return NOTIFY_BAD;
break; break;
case NETDEV_UNREGISTER: case NETDEV_UNREGISTER:
/* twiddle thumbs on netns device moves */ /* twiddle thumbs on netns device moves */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment