Skip to content

Commit 0a28bfd

Browse files
Lior Nahmansondavem330
authored andcommitted
net/macsec: Add MACsec skb_metadata_dst Tx Data path support
In the current MACsec offload implementation, MACsec interfaces shares the same MAC address by default. Therefore, HW can't distinguish from which MACsec interface the traffic originated from. MACsec stack will use skb_metadata_dst to store the SCI value, which is unique per Macsec interface, skb_metadat_dst will be used by the offloading device driver to associate the SKB with the corresponding offloaded interface (SCI). Signed-off-by: Lior Nahmanson <[email protected]> Reviewed-by: Raed Salem <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent da7d8e6 commit 0a28bfd

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

drivers/net/macsec.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <net/sock.h>
1919
#include <net/gro_cells.h>
2020
#include <net/macsec.h>
21+
#include <net/dst_metadata.h>
2122
#include <linux/phy.h>
2223
#include <linux/byteorder/generic.h>
2324
#include <linux/if_arp.h>
@@ -3416,6 +3417,11 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
34163417
int ret, len;
34173418

34183419
if (macsec_is_offloaded(netdev_priv(dev))) {
3420+
struct metadata_dst *md_dst = secy->tx_sc.md_dst;
3421+
3422+
skb_dst_drop(skb);
3423+
dst_hold(&md_dst->dst);
3424+
skb_dst_set(skb, &md_dst->dst);
34193425
skb->dev = macsec->real_dev;
34203426
return dev_queue_xmit(skb);
34213427
}
@@ -3743,6 +3749,7 @@ static void macsec_free_netdev(struct net_device *dev)
37433749
{
37443750
struct macsec_dev *macsec = macsec_priv(dev);
37453751

3752+
metadata_dst_free(macsec->secy.tx_sc.md_dst);
37463753
free_percpu(macsec->stats);
37473754
free_percpu(macsec->secy.tx_sc.stats);
37483755

@@ -4015,6 +4022,13 @@ static int macsec_add_dev(struct net_device *dev, sci_t sci, u8 icv_len)
40154022
return -ENOMEM;
40164023
}
40174024

4025+
secy->tx_sc.md_dst = metadata_dst_alloc(0, METADATA_MACSEC, GFP_KERNEL);
4026+
if (!secy->tx_sc.md_dst) {
4027+
free_percpu(secy->tx_sc.stats);
4028+
free_percpu(macsec->stats);
4029+
return -ENOMEM;
4030+
}
4031+
40184032
if (sci == MACSEC_UNDEF_SCI)
40194033
sci = dev_to_sci(dev, MACSEC_PORT_ES);
40204034

@@ -4028,6 +4042,7 @@ static int macsec_add_dev(struct net_device *dev, sci_t sci, u8 icv_len)
40284042
secy->xpn = DEFAULT_XPN;
40294043

40304044
secy->sci = sci;
4045+
secy->tx_sc.md_dst->u.macsec_info.sci = sci;
40314046
secy->tx_sc.active = true;
40324047
secy->tx_sc.encoding_sa = DEFAULT_ENCODING_SA;
40334048
secy->tx_sc.encrypt = DEFAULT_ENCRYPT;

include/net/dst_metadata.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,31 @@
44

55
#include <linux/skbuff.h>
66
#include <net/ip_tunnels.h>
7+
#include <net/macsec.h>
78
#include <net/dst.h>
89

910
enum metadata_type {
1011
METADATA_IP_TUNNEL,
1112
METADATA_HW_PORT_MUX,
13+
METADATA_MACSEC,
1214
};
1315

1416
struct hw_port_info {
1517
struct net_device *lower_dev;
1618
u32 port_id;
1719
};
1820

21+
struct macsec_info {
22+
sci_t sci;
23+
};
24+
1925
struct metadata_dst {
2026
struct dst_entry dst;
2127
enum metadata_type type;
2228
union {
2329
struct ip_tunnel_info tun_info;
2430
struct hw_port_info port_info;
31+
struct macsec_info macsec_info;
2532
} u;
2633
};
2734

@@ -82,6 +89,9 @@ static inline int skb_metadata_dst_cmp(const struct sk_buff *skb_a,
8289
return memcmp(&a->u.tun_info, &b->u.tun_info,
8390
sizeof(a->u.tun_info) +
8491
a->u.tun_info.options_len);
92+
case METADATA_MACSEC:
93+
return memcmp(&a->u.macsec_info, &b->u.macsec_info,
94+
sizeof(a->u.macsec_info));
8595
default:
8696
return 1;
8797
}

include/net/macsec.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
typedef u64 __bitwise sci_t;
2020
typedef u32 __bitwise ssci_t;
2121

22+
struct metadata_dst;
23+
2224
typedef union salt {
2325
struct {
2426
u32 ssci;
@@ -182,6 +184,7 @@ struct macsec_tx_sa {
182184
* @scb: single copy broadcast flag
183185
* @sa: array of secure associations
184186
* @stats: stats for this TXSC
187+
* @md_dst: MACsec offload metadata dst
185188
*/
186189
struct macsec_tx_sc {
187190
bool active;
@@ -192,6 +195,7 @@ struct macsec_tx_sc {
192195
bool scb;
193196
struct macsec_tx_sa __rcu *sa[MACSEC_NUM_AN];
194197
struct pcpu_tx_sc_stats __percpu *stats;
198+
struct metadata_dst *md_dst;
195199
};
196200

197201
/**

0 commit comments

Comments
 (0)