Skip to content

Commit 25a00d0

Browse files
Radu Pirea (NXP OSS)davem330
authored andcommitted
net: macsec: revert the MAC address if mdo_upd_secy fails
Revert the MAC address if mdo_upd_secy fails. Offloaded MACsec device might be left in an inconsistent state. Signed-off-by: Radu Pirea (NXP OSS) <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent eb97b9b commit 25a00d0

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

drivers/net/macsec.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3589,21 +3589,19 @@ static int macsec_set_mac_address(struct net_device *dev, void *p)
35893589
struct macsec_dev *macsec = macsec_priv(dev);
35903590
struct net_device *real_dev = macsec->real_dev;
35913591
struct sockaddr *addr = p;
3592+
u8 old_addr[ETH_ALEN];
35923593
int err;
35933594

35943595
if (!is_valid_ether_addr(addr->sa_data))
35953596
return -EADDRNOTAVAIL;
35963597

3597-
if (!(dev->flags & IFF_UP))
3598-
goto out;
3599-
3600-
err = dev_uc_add(real_dev, addr->sa_data);
3601-
if (err < 0)
3602-
return err;
3603-
3604-
dev_uc_del(real_dev, dev->dev_addr);
3598+
if (dev->flags & IFF_UP) {
3599+
err = dev_uc_add(real_dev, addr->sa_data);
3600+
if (err < 0)
3601+
return err;
3602+
}
36053603

3606-
out:
3604+
ether_addr_copy(old_addr, dev->dev_addr);
36073605
eth_hw_addr_set(dev, addr->sa_data);
36083606

36093607
/* If h/w offloading is available, propagate to the device */
@@ -3612,13 +3610,29 @@ static int macsec_set_mac_address(struct net_device *dev, void *p)
36123610
struct macsec_context ctx;
36133611

36143612
ops = macsec_get_ops(macsec, &ctx);
3615-
if (ops) {
3616-
ctx.secy = &macsec->secy;
3617-
macsec_offload(ops->mdo_upd_secy, &ctx);
3613+
if (!ops) {
3614+
err = -EOPNOTSUPP;
3615+
goto restore_old_addr;
36183616
}
3617+
3618+
ctx.secy = &macsec->secy;
3619+
err = macsec_offload(ops->mdo_upd_secy, &ctx);
3620+
if (err)
3621+
goto restore_old_addr;
36193622
}
36203623

3624+
if (dev->flags & IFF_UP)
3625+
dev_uc_del(real_dev, old_addr);
3626+
36213627
return 0;
3628+
3629+
restore_old_addr:
3630+
if (dev->flags & IFF_UP)
3631+
dev_uc_del(real_dev, addr->sa_data);
3632+
3633+
eth_hw_addr_set(dev, old_addr);
3634+
3635+
return err;
36223636
}
36233637

36243638
static int macsec_change_mtu(struct net_device *dev, int new_mtu)

0 commit comments

Comments
 (0)