Skip to content

Commit 308453a

Browse files
Mike Manningdavem330
authored andcommitted
vlan: Propagate MAC address to VLANs
The MAC address of the physical interface is only copied to the VLAN when it is first created, resulting in an inconsistency after MAC address changes of only newly created VLANs having an up-to-date MAC. The VLANs should continue inheriting the MAC address of the physical interface until the VLAN MAC address is explicitly set to any value. This allows IPv6 EUI64 addresses for the VLAN to reflect any changes to the MAC of the physical interface and thus for DAD to behave as expected. Signed-off-by: Mike Manning <mmanning@brocade.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f2633d2 commit 308453a

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

‎net/8021q/vlan.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ static void vlan_sync_address(struct net_device *dev,
290290
if (ether_addr_equal(vlan->real_dev_addr, dev->dev_addr))
291291
return;
292292

293+
/* vlan continues to inherit address of lower device */
294+
if (vlan_dev_inherit_address(vlandev, dev))
295+
goto out;
296+
293297
/* vlan address was different from the old address and is equal to
294298
* the new address */
295299
if (!ether_addr_equal(vlandev->dev_addr, vlan->real_dev_addr) &&
@@ -302,6 +306,7 @@ static void vlan_sync_address(struct net_device *dev,
302306
!ether_addr_equal(vlandev->dev_addr, dev->dev_addr))
303307
dev_uc_add(dev, vlandev->dev_addr);
304308

309+
out:
305310
ether_addr_copy(vlan->real_dev_addr, dev->dev_addr);
306311
}
307312

‎net/8021q/vlan.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ int vlan_check_real_dev(struct net_device *real_dev,
109109
void vlan_setup(struct net_device *dev);
110110
int register_vlan_dev(struct net_device *dev);
111111
void unregister_vlan_dev(struct net_device *dev, struct list_head *head);
112+
bool vlan_dev_inherit_address(struct net_device *dev,
113+
struct net_device *real_dev);
112114

113115
static inline u32 vlan_get_ingress_priority(struct net_device *dev,
114116
u16 vlan_tci)

‎net/8021q/vlan_dev.c‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,17 @@ void vlan_dev_get_realdev_name(const struct net_device *dev, char *result)
245245
strncpy(result, vlan_dev_priv(dev)->real_dev->name, 23);
246246
}
247247

248+
bool vlan_dev_inherit_address(struct net_device *dev,
249+
struct net_device *real_dev)
250+
{
251+
if (dev->addr_assign_type != NET_ADDR_STOLEN)
252+
return false;
253+
254+
ether_addr_copy(dev->dev_addr, real_dev->dev_addr);
255+
call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
256+
return true;
257+
}
258+
248259
static int vlan_dev_open(struct net_device *dev)
249260
{
250261
struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
@@ -255,7 +266,8 @@ static int vlan_dev_open(struct net_device *dev)
255266
!(vlan->flags & VLAN_FLAG_LOOSE_BINDING))
256267
return -ENETDOWN;
257268

258-
if (!ether_addr_equal(dev->dev_addr, real_dev->dev_addr)) {
269+
if (!ether_addr_equal(dev->dev_addr, real_dev->dev_addr) &&
270+
!vlan_dev_inherit_address(dev, real_dev)) {
259271
err = dev_uc_add(real_dev, dev->dev_addr);
260272
if (err < 0)
261273
goto out;
@@ -560,8 +572,10 @@ static int vlan_dev_init(struct net_device *dev)
560572
/* ipv6 shared card related stuff */
561573
dev->dev_id = real_dev->dev_id;
562574

563-
if (is_zero_ether_addr(dev->dev_addr))
564-
eth_hw_addr_inherit(dev, real_dev);
575+
if (is_zero_ether_addr(dev->dev_addr)) {
576+
ether_addr_copy(dev->dev_addr, real_dev->dev_addr);
577+
dev->addr_assign_type = NET_ADDR_STOLEN;
578+
}
565579
if (is_zero_ether_addr(dev->broadcast))
566580
memcpy(dev->broadcast, real_dev->broadcast, dev->addr_len);
567581

0 commit comments

Comments
 (0)