Skip to content

Commit d9816ec

Browse files
cfdez-techdavem330
authored andcommitted
macsec: MACsec SCI assignment for ES = 0
According to 802.1AE standard, when ES and SC flags in TCI are zero, used SCI should be the current active SC_RX. Current code uses the header MAC address. Without this patch, when ES flag is 0 (using a bridge or switch), header MAC will not fit the SCI and MACSec frames will be discarted. In order to test this issue, MACsec link should be stablished between two interfaces, setting SC and ES flags to zero and a port identifier different than one. For example, using ip macsec tools: ip link add link $ETH0 macsec0 type macsec port 11 send_sci off end_station off ip macsec add macsec0 tx sa 0 pn 2 on key 01 $ETH1_KEY ip macsec add macsec0 rx port 11 address $ETH1_MAC ip macsec add macsec0 rx port 11 address $ETH1_MAC sa 0 pn 2 on key 02 ip link set dev macsec0 up ip link add link $ETH1 macsec1 type macsec port 11 send_sci off end_station off ip macsec add macsec1 tx sa 0 pn 2 on key 01 $ETH0_KEY ip macsec add macsec1 rx port 11 address $ETH0_MAC ip macsec add macsec1 rx port 11 address $ETH0_MAC sa 0 pn 2 on key 02 ip link set dev macsec1 up Fixes: c09440f ("macsec: introduce IEEE 802.1AE driver") Co-developed-by: Andreu Montiel <[email protected]> Signed-off-by: Andreu Montiel <[email protected]> Signed-off-by: Carlos Fernandez <[email protected]> Reviewed-by: Subbaraya Sundeep <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f478d68 commit d9816ec

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

drivers/net/macsec.c

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,39 @@ static sci_t make_sci(const u8 *addr, __be16 port)
247247
return sci;
248248
}
249249

250-
static sci_t macsec_frame_sci(struct macsec_eth_header *hdr, bool sci_present)
250+
static sci_t macsec_active_sci(struct macsec_secy *secy)
251251
{
252-
sci_t sci;
252+
struct macsec_rx_sc *rx_sc = rcu_dereference_bh(secy->rx_sc);
253+
254+
/* Case single RX SC */
255+
if (rx_sc && !rcu_dereference_bh(rx_sc->next))
256+
return (rx_sc->active) ? rx_sc->sci : 0;
257+
/* Case no RX SC or multiple */
258+
else
259+
return 0;
260+
}
261+
262+
static sci_t macsec_frame_sci(struct macsec_eth_header *hdr, bool sci_present,
263+
struct macsec_rxh_data *rxd)
264+
{
265+
struct macsec_dev *macsec;
266+
sci_t sci = 0;
253267

254-
if (sci_present)
268+
/* SC = 1 */
269+
if (sci_present) {
255270
memcpy(&sci, hdr->secure_channel_id,
256271
sizeof(hdr->secure_channel_id));
257-
else
272+
/* SC = 0; ES = 0 */
273+
} else if ((!(hdr->tci_an & (MACSEC_TCI_ES | MACSEC_TCI_SC))) &&
274+
(list_is_singular(&rxd->secys))) {
275+
/* Only one SECY should exist on this scenario */
276+
macsec = list_first_or_null_rcu(&rxd->secys, struct macsec_dev,
277+
secys);
278+
if (macsec)
279+
return macsec_active_sci(&macsec->secy);
280+
} else {
258281
sci = make_sci(hdr->eth.h_source, MACSEC_PORT_ES);
282+
}
259283

260284
return sci;
261285
}
@@ -1109,7 +1133,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
11091133
struct macsec_rxh_data *rxd;
11101134
struct macsec_dev *macsec;
11111135
unsigned int len;
1112-
sci_t sci;
1136+
sci_t sci = 0;
11131137
u32 hdr_pn;
11141138
bool cbit;
11151139
struct pcpu_rx_sc_stats *rxsc_stats;
@@ -1156,11 +1180,14 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
11561180

11571181
macsec_skb_cb(skb)->has_sci = !!(hdr->tci_an & MACSEC_TCI_SC);
11581182
macsec_skb_cb(skb)->assoc_num = hdr->tci_an & MACSEC_AN_MASK;
1159-
sci = macsec_frame_sci(hdr, macsec_skb_cb(skb)->has_sci);
11601183

11611184
rcu_read_lock();
11621185
rxd = macsec_data_rcu(skb->dev);
11631186

1187+
sci = macsec_frame_sci(hdr, macsec_skb_cb(skb)->has_sci, rxd);
1188+
if (!sci)
1189+
goto drop_nosc;
1190+
11641191
list_for_each_entry_rcu(macsec, &rxd->secys, secys) {
11651192
struct macsec_rx_sc *sc = find_rx_sc(&macsec->secy, sci);
11661193

@@ -1283,6 +1310,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
12831310
macsec_rxsa_put(rx_sa);
12841311
drop_nosa:
12851312
macsec_rxsc_put(rx_sc);
1313+
drop_nosc:
12861314
rcu_read_unlock();
12871315
drop_direct:
12881316
kfree_skb(skb);

0 commit comments

Comments
 (0)