Skip to content

Commit 5182a5d

Browse files
ebirgerklassert
authored andcommitted
net: allow storing xfrm interface metadata in metadata_dst
XFRM interfaces provide the association of various XFRM transformations to a netdevice using an 'if_id' identifier common to both the XFRM data structures (polcies, states) and the interface. The if_id is configured by the controlling entity (usually the IKE daemon) and can be used by the administrator to define logical relations between different connections. For example, different connections can share the if_id identifier so that they pass through the same interface, . However, currently it is not possible for connections using a different if_id to use the same interface while retaining the logical separation between them, without using additional criteria such as skb marks or different traffic selectors. When having a large number of connections, it is useful to have a the logical separation offered by the if_id identifier but use a single network interface. Similar to the way collect_md mode is used in IP tunnels. This patch attempts to enable different configuration mechanisms - such as ebpf programs, LWT encapsulations, and TC - to attach metadata to skbs which would carry the if_id. This way a single xfrm interface in collect_md mode can demux traffic based on this configuration on tx and provide this metadata on rx. The XFRM metadata is somewhat similar to ip tunnel metadata in that it has an "id", and shares similar configuration entities (bpf, tc, ...), however, it does not necessarily represent an IP tunnel or use other ip tunnel information, and also has an optional "link" property which can be used for affecting underlying routing decisions. Additional xfrm related criteria may also be added in the future. Therefore, a new metadata type is introduced, to be used in subsequent patches in the xfrm interface and configuration entities. Reviewed-by: Nikolay Aleksandrov <[email protected]> Reviewed-by: Nicolas Dichtel <[email protected]> Signed-off-by: Eyal Birger <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 0de1978 commit 5182a5d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

include/net/dst_metadata.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,26 @@
99
enum metadata_type {
1010
METADATA_IP_TUNNEL,
1111
METADATA_HW_PORT_MUX,
12+
METADATA_XFRM,
1213
};
1314

1415
struct hw_port_info {
1516
struct net_device *lower_dev;
1617
u32 port_id;
1718
};
1819

20+
struct xfrm_md_info {
21+
u32 if_id;
22+
int link;
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 xfrm_md_info xfrm_info;
2532
} u;
2633
};
2734

@@ -53,6 +60,16 @@ skb_tunnel_info(const struct sk_buff *skb)
5360
return NULL;
5461
}
5562

63+
static inline struct xfrm_md_info *skb_xfrm_md_info(const struct sk_buff *skb)
64+
{
65+
struct metadata_dst *md_dst = skb_metadata_dst(skb);
66+
67+
if (md_dst && md_dst->type == METADATA_XFRM)
68+
return &md_dst->u.xfrm_info;
69+
70+
return NULL;
71+
}
72+
5673
static inline bool skb_valid_dst(const struct sk_buff *skb)
5774
{
5875
struct dst_entry *dst = skb_dst(skb);
@@ -82,6 +99,9 @@ static inline int skb_metadata_dst_cmp(const struct sk_buff *skb_a,
8299
return memcmp(&a->u.tun_info, &b->u.tun_info,
83100
sizeof(a->u.tun_info) +
84101
a->u.tun_info.options_len);
102+
case METADATA_XFRM:
103+
return memcmp(&a->u.xfrm_info, &b->u.xfrm_info,
104+
sizeof(a->u.xfrm_info));
85105
default:
86106
return 1;
87107
}

0 commit comments

Comments
 (0)