Skip to content

Commit 73a4b31

Browse files
qsndavem330
authored andcommitted
macsec: fix secy->n_rx_sc accounting
secy->n_rx_sc is supposed to be the number of _active_ rxsc's within a secy. This is then used by macsec_send_sci to help decide if we should add the SCI to the header or not. This logic is currently broken when we create a new RXSC and turn it off at creation, as create_rx_sc always sets ->active to true (and immediately uses that to increment n_rx_sc), and only later macsec_add_rxsc sets rx_sc->active. Fixes: c09440f ("macsec: introduce IEEE 802.1AE driver") Signed-off-by: Sabrina Dubroca <[email protected]> Reviewed-by: Antoine Tenart <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 93a3094 commit 73a4b31

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/net/macsec.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,8 @@ static struct macsec_rx_sc *del_rx_sc(struct macsec_secy *secy, sci_t sci)
14131413
return NULL;
14141414
}
14151415

1416-
static struct macsec_rx_sc *create_rx_sc(struct net_device *dev, sci_t sci)
1416+
static struct macsec_rx_sc *create_rx_sc(struct net_device *dev, sci_t sci,
1417+
bool active)
14171418
{
14181419
struct macsec_rx_sc *rx_sc;
14191420
struct macsec_dev *macsec;
@@ -1437,7 +1438,7 @@ static struct macsec_rx_sc *create_rx_sc(struct net_device *dev, sci_t sci)
14371438
}
14381439

14391440
rx_sc->sci = sci;
1440-
rx_sc->active = true;
1441+
rx_sc->active = active;
14411442
refcount_set(&rx_sc->refcnt, 1);
14421443

14431444
secy = &macsec_priv(dev)->secy;
@@ -1876,6 +1877,7 @@ static int macsec_add_rxsc(struct sk_buff *skb, struct genl_info *info)
18761877
struct macsec_rx_sc *rx_sc;
18771878
struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX + 1];
18781879
struct macsec_secy *secy;
1880+
bool active = true;
18791881
int ret;
18801882

18811883
if (!attrs[MACSEC_ATTR_IFINDEX])
@@ -1897,15 +1899,15 @@ static int macsec_add_rxsc(struct sk_buff *skb, struct genl_info *info)
18971899
secy = &macsec_priv(dev)->secy;
18981900
sci = nla_get_sci(tb_rxsc[MACSEC_RXSC_ATTR_SCI]);
18991901

1900-
rx_sc = create_rx_sc(dev, sci);
1902+
if (tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE])
1903+
active = nla_get_u8(tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE]);
1904+
1905+
rx_sc = create_rx_sc(dev, sci, active);
19011906
if (IS_ERR(rx_sc)) {
19021907
rtnl_unlock();
19031908
return PTR_ERR(rx_sc);
19041909
}
19051910

1906-
if (tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE])
1907-
rx_sc->active = !!nla_get_u8(tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE]);
1908-
19091911
if (macsec_is_offloaded(netdev_priv(dev))) {
19101912
const struct macsec_ops *ops;
19111913
struct macsec_context ctx;

0 commit comments

Comments
 (0)