lwtunnel: add ip and ip6 options setting and dumping
Subsystems (3)
cover lwtunnel: add ip and ip6 options setting and dumping
With this patchset, users can configure options by ip route encap for geneve, vxlan and ersapn lwtunnel, like:
# ip r a 1.1.1.0/24 encap ip id 1 geneve class 0 type 0 \
data "1212121234567890" dst 10.1.0.2 dev geneve1 # ip r a 1.1.1.0/24 encap ip id 1 vxlan gbp 456 \
dst 10.1.0.2 dev erspan1 # ip r a 1.1.1.0/24 encap ip id 1 erspan ver 1 idx 123 \
dst 10.1.0.2 dev erspan1iproute side patch is attached on the reply of this mail.
Thank Simon for good advice.
Xin Long (5):
lwtunnel: add options process for arp request
lwtunnel: add options process for cmp_encap
lwtunnel: add options setting and dumping for geneve
lwtunnel: add options setting and dumping for vxlan
lwtunnel: add options setting and dumping for erspan
include/uapi/linux/lwtunnel.h | 41 +++++ net/ipv4/ip_tunnel_core.c | 382 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 402 insertions(+), 21 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/5 lwtunnel: add options process for arp request
Without options copied to the dst tun_info in iptunnel_metadata_reply() called by arp_process for handling arp_request, the generated arp_reply packet may be dropped or sent out with wrong options for some tunnels like erspan and vxlan, and the traffic will break.
--- net/ipv4/ip_tunnel_core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/ipv4/ip_tunnel_core.c +4 -3
@@ -126,15 +126,14 @@ struct metadata_dst *iptunnel_metadata_reply(struct metadata_dst *md,if (!md || md->type !=METADATA_IP_TUNNEL || md->u.tun_info.mode &IP_TUNNEL_INFO_TX ) -return NULL ; - res =metadata_dst_alloc (0 ,METADATA_IP_TUNNEL , flags); + src = &md->u.tun_info; + res =metadata_dst_alloc (src->options_len,METADATA_IP_TUNNEL , flags);if (!res)return NULL ; dst = &res->u.tun_info; - src = &md->u.tun_info; dst->key.tun_id = src->key.tun_id;if (src->mode &IP_TUNNEL_INFO_IPV6 ) memcpy(&dst->key.u.ipv6.dst, &src->key.u.ipv6.src,
@@ -143,6 +142,8 @@ struct metadata_dst *iptunnel_metadata_reply(struct metadata_dst *md, dst->key.u.ipv4.dst = src->key.u.ipv4.src; dst->key.tun_flags = src->key.tun_flags; dst->mode = src->mode |IP_TUNNEL_INFO_TX ; +ip_tunnel_info_opts_set (dst,ip_tunnel_info_opts (src), + src->options_len,0 );return res; }
Signature · 1 line
2.1.0
PATCH 2/5 lwtunnel: add options process for cmp_encap
When comparing two tun_info, dst_cache member should have been skipped, as dst_cache is a per cpu pointer and they are always different values even in two tun_info with the same keys.
So this patch is to skip dst_cache member and compare the key, mode and options_len only. For the future opts setting support, also to compare options.
--- net/ipv4/ip_tunnel_core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
net/ipv4/ip_tunnel_core.c +8 -2
@@ -315,8 +315,14 @@ static int ip_tun_encap_nlsize(struct lwtunnel_state *lwtstate)static int ip_tun_cmp_encap (struct lwtunnel_state *a,struct lwtunnel_state *b) { -return memcmp (lwt_tun_info (a),lwt_tun_info (b), -sizeof (struct ip_tunnel_info )); +struct ip_tunnel_info *info_a =lwt_tun_info (a); +struct ip_tunnel_info *info_b =lwt_tun_info (b); + +return memcmp (info_a, info_b,sizeof (info_a->key)) || + info_a->mode != info_b->mode || + info_a->options_len != info_b->options_len || +memcmp (ip_tunnel_info_opts (info_a), +ip_tunnel_info_opts (info_b), info_a->options_len); }static const struct lwtunnel_encap_ops ip_tun_lwt_ops = {
Signature · 1 line
2.1.0
PATCH 3/5 lwtunnel: add options setting and dumping for geneve
To add options setting and dumping, .build_state(), .fill_encap() and .get_encap_size() in ip_tun_lwt_ops needs to be extended:
ip_tun_build_state():
ip_tun_parse_opts():
ip_tun_parse_opts_geneve()
ip_tun_fill_encap_info():
ip_tun_fill_encap_opts():
ip_tun_fill_encap_opts_geneve()
ip_tun_encap_nlsize()
ip_tun_opts_nlsize():
if (tun_flags & TUNNEL_GENEVE_OPT)
ip_tun_parse_opts(), ip_tun_fill_encap_opts() and ip_tun_opts_nlsize() processes LWTUNNEL_IP_OPTS.
ip_tun_parse_opts_geneve(), ip_tun_fill_encap_opts_geneve() and if (tun_flags & TUNNEL_GENEVE_OPT) processes LWTUNNEL_IP_OPTS_GENEVE.
--- include/uapi/linux/lwtunnel.h | 20 ++++ net/ipv4/ip_tunnel_core.c | 212 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 216 insertions(+), 16 deletions(-)
include/uapi/linux/lwtunnel.h +20 -0
@@ -27,6 +27,7 @@ enum lwtunnel_ip_t {LWTUNNEL_IP_TOS ,LWTUNNEL_IP_FLAGS ,LWTUNNEL_IP_PAD , +LWTUNNEL_IP_OPTS , __LWTUNNEL_IP_MAX, };
@@ -41,12 +42,31 @@ enum lwtunnel_ip6_t {LWTUNNEL_IP6_TC ,LWTUNNEL_IP6_FLAGS ,LWTUNNEL_IP6_PAD , +LWTUNNEL_IP6_OPTS , __LWTUNNEL_IP6_MAX, };#define LWTUNNEL_IP6_MAX (__LWTUNNEL_IP6_MAX - 1)enum { +LWTUNNEL_IP_OPTS_UNSPEC , +LWTUNNEL_IP_OPTS_GENEVE , + __LWTUNNEL_IP_OPTS_MAX, +}; + +#define LWTUNNEL_IP_OPTS_MAX (__LWTUNNEL_IP_OPTS_MAX - 1) + +enum { +LWTUNNEL_IP_OPT_GENEVE_UNSPEC , +LWTUNNEL_IP_OPT_GENEVE_CLASS , +LWTUNNEL_IP_OPT_GENEVE_TYPE , +LWTUNNEL_IP_OPT_GENEVE_DATA , + __LWTUNNEL_IP_OPT_GENEVE_MAX, +}; + +#define LWTUNNEL_IP_OPT_GENEVE_MAX (__LWTUNNEL_IP_OPT_GENEVE_MAX - 1) + +enum {LWT_BPF_PROG_UNSPEC ,LWT_BPF_PROG_FD , LWT_BPF_PROG_NAME,
net/ipv4/ip_tunnel_core.c +196 -16
314 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH 4/5 lwtunnel: add options setting and dumping for vxlan
Based on the code framework built on the last patch, to support setting and dumping for vxlan, we only need to add ip_tun_parse_opts_vxlan() for .build_state and ip_tun_fill_encap_opts_vxlan() for .fill_encap and if (tun_flags & TUNNEL_VXLAN_OPT) for .get_encap_size.
--- include/uapi/linux/lwtunnel.h | 9 ++++++ net/ipv4/ip_tunnel_core.c | 67 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 2 deletions(-)
include/uapi/linux/lwtunnel.h +9 -0
@@ -51,6 +51,7 @@ enum lwtunnel_ip6_t {enum {LWTUNNEL_IP_OPTS_UNSPEC ,LWTUNNEL_IP_OPTS_GENEVE , +LWTUNNEL_IP_OPTS_VXLAN , __LWTUNNEL_IP_OPTS_MAX, };
@@ -67,6 +68,14 @@ enum {#define LWTUNNEL_IP_OPT_GENEVE_MAX (__LWTUNNEL_IP_OPT_GENEVE_MAX - 1)enum { +LWTUNNEL_IP_OPT_VXLAN_UNSPEC , +LWTUNNEL_IP_OPT_VXLAN_GBP , + __LWTUNNEL_IP_OPT_VXLAN_MAX, +}; + +#define LWTUNNEL_IP_OPT_VXLAN_MAX (__LWTUNNEL_IP_OPT_VXLAN_MAX - 1) + +enum {LWT_BPF_PROG_UNSPEC ,LWT_BPF_PROG_FD ,LWT_BPF_PROG_NAME ,
net/ipv4/ip_tunnel_core.c +65 -2
127 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH 5/5 lwtunnel: add options setting and dumping for erspan
Based on the code framework built on the last patch, to support setting and dumping for vxlan, we only need to add ip_tun_parse_opts_erspan() for .build_state and ip_tun_fill_encap_opts_erspan() for .fill_encap and if (tun_flags & TUNNEL_ERSPAN_OPT) for .get_encap_size.
--- include/uapi/linux/lwtunnel.h | 12 ++++++ net/ipv4/ip_tunnel_core.c | 94 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 104 insertions(+), 2 deletions(-)
include/uapi/linux/lwtunnel.h +12 -0
@@ -52,6 +52,7 @@ enum {LWTUNNEL_IP_OPTS_UNSPEC ,LWTUNNEL_IP_OPTS_GENEVE ,LWTUNNEL_IP_OPTS_VXLAN , +LWTUNNEL_IP_OPTS_ERSPAN , __LWTUNNEL_IP_OPTS_MAX, };
@@ -76,6 +77,17 @@ enum {#define LWTUNNEL_IP_OPT_VXLAN_MAX (__LWTUNNEL_IP_OPT_VXLAN_MAX - 1)enum { +LWTUNNEL_IP_OPT_ERSPAN_UNSPEC , +LWTUNNEL_IP_OPT_ERSPAN_VER , +LWTUNNEL_IP_OPT_ERSPAN_INDEX , +LWTUNNEL_IP_OPT_ERSPAN_DIR , +LWTUNNEL_IP_OPT_ERSPAN_HWID , + __LWTUNNEL_IP_OPT_ERSPAN_MAX, +}; + +#define LWTUNNEL_IP_OPT_ERSPAN_MAX (__LWTUNNEL_IP_OPT_ERSPAN_MAX - 1) + +enum {LWT_BPF_PROG_UNSPEC ,LWT_BPF_PROG_FD ,LWT_BPF_PROG_NAME ,
net/ipv4/ip_tunnel_core.c +92 -2
154 lines not on this page · raw message
Signature · 1 line
2.1.0
Quoted 24 lines · Xin Long
With this patchset, users can configure options by ip route encap for geneve, vxlan and ersapn lwtunnel, like:
# ip r a 1.1.1.0/24 encap ip id 1 geneve class 0 type 0 \ data "1212121234567890" dst 10.1.0.2 dev geneve1# ip r a 1.1.1.0/24 encap ip id 1 vxlan gbp 456 \ dst 10.1.0.2 dev erspan1# ip r a 1.1.1.0/24 encap ip id 1 erspan ver 1 idx 123 \ dst 10.1.0.2 dev erspan1iproute side patch is attached on the reply of this mail.
Thank Simon for good advice.
Xin Long (5):
lwtunnel: add options process for arp request
lwtunnel: add options process forcmp_encap
lwtunnel: add options setting and dumping for geneve
lwtunnel: add options setting and dumping for vxlan
lwtunnel: add options setting and dumping for erspan
Quoted 7 lines
include/uapi/linux/lwtunnel.h | 41 +++++ net/ipv4/ip_tunnel_core.c | 382 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 402 insertions(+), 21 deletions(-)--
2.1.0
From 6be78778a9046bdc7430eec6908d06c61ea39ea1 Mon Sep 17 00:00:00 2001
From: Xin Long <[email protected]>
Date: Tue, 5 Nov 2019 23:42:51 -0500
Subject: [PATCH] iproute_lwtunnel: add support options for geneve/vxlan/erspan
metadata
1. example for geneve:
ip net d a; ip net d b; ip net a a; ip net a b
ip -n a l a eth0 type veth peer name eth0 netns b
ip -n a l s eth0 up; ip -n b link set eth0 up
ip -n a a a 10.1.0.1/24 dev eth0; ip -n b a a 10.1.0.2/24 dev eth0
ip -n b l a erspan1 type geneve id 1 remote 10.1.0.1 ttl 64
ip -n b a a 1.1.1.1/24 dev erspan1; ip -n b l s erspan1 up
ip -n b r a 2.1.1.0/24 dev erspan1
ip -n a l a erspan1 type geneve external
ip -n a a a 2.1.1.1/24 dev erspan1; ip -n a l s erspan1 up
ip -n a r a 1.1.1.0/24 encap ip id 1 geneve class 0 type 0 data "1212121234567890" dst 10.1.0.2 dev erspan1 ip -n a r s; ip net exec a ping 1.1.1.1 -c 1
2. example for vxlan:
ip net d a; ip net d b; ip net a a; ip net a b
ip -n a l a eth0 type veth peer name eth0b netns b
ip -n a l s eth0 up; ip -n b link set eth0b up
ip -n a a a 10.1.0.1/24 dev eth0; ip -n b a a 10.1.0.2/24 dev eth0b
ip -n b l a erspan1 type vxlan id 1 local 10.1.0.2 remote 10.1.0.1 dev eth0b ttl 64 gbp ip -n b a a 1.1.1.1/24 dev erspan1; ip -n b l s erspan1 up
ip -n b r a 2.1.1.0/24 dev erspan1
ip -n a l a erspan1 type vxlan local 10.1.0.1 dev eth0 ttl 64 gbp external ip -n a a a 2.1.1.1/24 dev erspan1; ip -n a l s erspan1 up
ip -n a r a 1.1.1.0/24 encap ip id 1 vxlan gbp 456 dst 10.1.0.2 dev erspan1 ip -n a r s; ip net exec a ping 1.1.1.1 -c 1
3. example for erspan:
ip net d a; ip net d b; ip net a a; ip net a b
ip -n a l a eth0 type veth peer name eth0 netns b
ip -n a l s eth0 up; ip -n b link set eth0 up
ip -n a a a 10.1.0.1/24 dev eth0; ip -n b a a 10.1.0.2/24 dev eth0
ip -n b l a erspan1 type erspan key 1 seq erspan 123 local 10.1.0.2 remote 10.1.0.1 ip -n b a a 1.1.1.1/24 dev erspan1; ip -n b l s erspan1 up
ip -n b r a 2.1.1.0/24 dev erspan1
ip -n a l a erspan1 type erspan key 1 seq local 10.1.0.1 external
ip -n a a a 2.1.1.1/24 dev erspan1; ip -n a l s erspan1 up
ip -n a r a 1.1.1.0/24 encap ip id 1 erspan ver 1 idx 123 dst 10.1.0.2 dev erspan1 ip -n a r s; ip net exec a ping 1.1.1.1 -c 1
--- include/uapi/linux/lwtunnel.h | 41 ++++ ip/iproute_lwtunnel.c | 355 +++++++++++++++++++++++++++++++++- 2 files changed, 390 insertions(+), 6 deletions(-)
include/uapi/linux/lwtunnel.h +41 -0
@@ -27,6 +27,7 @@ enum lwtunnel_ip_t {LWTUNNEL_IP_TOS ,LWTUNNEL_IP_FLAGS ,LWTUNNEL_IP_PAD , +LWTUNNEL_IP_OPTS , __LWTUNNEL_IP_MAX, };
@@ -41,6 +42,7 @@ enum lwtunnel_ip6_t {LWTUNNEL_IP6_TC ,LWTUNNEL_IP6_FLAGS ,LWTUNNEL_IP6_PAD , +LWTUNNEL_IP6_OPTS , __LWTUNNEL_IP6_MAX, };
@@ -68,4 +70,43 @@ enum {#define LWT_BPF_MAX_HEADROOM 256 +enum { +LWTUNNEL_IP_OPTS_UNSPEC , +LWTUNNEL_IP_OPTS_GENEVE , +LWTUNNEL_IP_OPTS_VXLAN , +LWTUNNEL_IP_OPTS_ERSPAN , + __LWTUNNEL_IP_OPTS_MAX, +}; + +#define LWTUNNEL_IP_OPTS_MAX (__LWTUNNEL_IP_OPTS_MAX - 1) + +enum { +LWTUNNEL_IP_OPT_GENEVE_UNSPEC , +LWTUNNEL_IP_OPT_GENEVE_CLASS , +LWTUNNEL_IP_OPT_GENEVE_TYPE , +LWTUNNEL_IP_OPT_GENEVE_DATA , + __LWTUNNEL_IP_OPT_GENEVE_MAX, +}; + +#define LWTUNNEL_IP_OPT_GENEVE_MAX (__LWTUNNEL_IP_OPT_GENEVE_MAX - 1) + +enum { +LWTUNNEL_IP_OPT_VXLAN_UNSPEC , +LWTUNNEL_IP_OPT_VXLAN_GBP , + __LWTUNNEL_IP_OPT_VXLAN_MAX, +}; + +#define LWTUNNEL_IP_OPT_VXLAN_MAX (__LWTUNNEL_IP_OPT_VXLAN_MAX - 1) + +enum { +LWTUNNEL_IP_OPT_ERSPAN_UNSPEC , +LWTUNNEL_IP_OPT_ERSPAN_VER , +LWTUNNEL_IP_OPT_ERSPAN_INDEX , +LWTUNNEL_IP_OPT_ERSPAN_DIR , +LWTUNNEL_IP_OPT_ERSPAN_HWID , + __LWTUNNEL_IP_OPT_ERSPAN_MAX, +}; + +#define LWTUNNEL_IP_OPT_ERSPAN_MAX (__LWTUNNEL_IP_OPT_ERSPAN_MAX - 1) +#endif /* _LWTUNNEL_H_ */
ip/iproute_lwtunnel.c +349 -6
413 lines not on this page · raw message
Signature · 1 line
2.18.1
David Miller
maintainerFrom: Xin Long <[email protected]>
Date: Wed, 6 Nov 2019 17:01:02 +0800
Quoted 9 lines
With this patchset, users can configure options by ip route encap for geneve, vxlan and ersapn lwtunnel, like:
# ip r a 1.1.1.0/24 encap ip id 1 geneve class 0 type 0 \ data "1212121234567890" dst 10.1.0.2 dev geneve1# ip r a 1.1.1.0/24 encap ip id 1 vxlan gbp 456 \ dst 10.1.0.2 dev erspan1
Quoted 6 lines
# ip r a 1.1.1.0/24 encap ip id 1 erspan ver 1 idx 123 \ dst 10.1.0.2 dev erspan1iproute side patch is attached on the reply of this mail.
Thank Simon for good advice.
Series applied, looks good.
Can you comment about how this code is using the deprecated nla parsers for new options?
Thank you.
Quoted 16 lines · David Miller
From: Xin Long <[email protected]>
Date: Wed, 6 Nov 2019 17:01:02 +0800Quoted 12 lines
With this patchset, users can configure options by ip route encap for geneve, vxlan and ersapn lwtunnel, like:
# ip r a 1.1.1.0/24 encap ip id 1 geneve class 0 type 0 \ data "1212121234567890" dst 10.1.0.2 dev geneve1# ip r a 1.1.1.0/24 encap ip id 1 vxlan gbp 456 \ dst 10.1.0.2 dev erspan1# ip r a 1.1.1.0/24 encap ip id 1 erspan ver 1 idx 123 \ dst 10.1.0.2 dev erspan1
Quoted 8 lines
Quoted 3 lines
iproute side patch is attached on the reply of this mail.
Thank Simon for good advice.
Series applied, looks good.
Can you comment about how this code is using the deprecated nla parsers for new options?
I didn't think too much, just used what it's using in cls_flower.c and act_tunnel_key.c to parse GENEVE options.
Now think about it again, nla_parse_nested() should always be used on new options, should I post a fix for it? since no code to access this from userspace yet.
Quoted 3 lines · Xin Long
Now think about it again,
nla_parse_nested()should always be used on new options, should I post a fix for it? since no code to access this from userspace yet.
please do. All new options should use strict parsing from the beginning. And you should be able to set LWTUNNEL_IP_OPT_GENEVE_UNSPEC to .strict_start_type = LWTUNNEL_IP_OPT_GENEVE_UNSPEC + 1 in the policy so that new command using new option on an old kernel throws an error.
Quoted 10 lines · David Ahern
Quoted 3 lines · Xin Long
Now think about it again,
nla_parse_nested()should always be used on new options, should I post a fix for it? since no code to access this from userspace yet.please do. All new options should use strict parsing from the beginning. And you should be able to set
LWTUNNEL_IP_OPT_GENEVE_UNSPECto .strict_start_type =LWTUNNEL_IP_OPT_GENEVE_UNSPEC+ 1 in the policy so that new command using new option on an old kernel throws an error.
I'm not sure if strict_start_type is needed when using nla_parse_nested().
.strict_start_type seems only checked in validate_nla():
if (strict_start_type && type >= strict_start_type)
validate |= NL_VALIDATE_STRICT; <------ [1]But in the path of:
nla_parse_nested() ->
__nla_parse() ->
__nla_validate_parse() ->
validate_nla()The param 'validate' is always NL_VALIDATE_STRICT, no matter Code [1] is triggered or not. or am I missing something here?
Quoted 18 lines · Xin Long
Quoted 10 lines · David Ahern
Quoted 3 lines · Xin Long
Now think about it again,
nla_parse_nested()should always be used on new options, should I post a fix for it? since no code to access this from userspace yet.please do. All new options should use strict parsing from the beginning. And you should be able to set
LWTUNNEL_IP_OPT_GENEVE_UNSPECto .strict_start_type =LWTUNNEL_IP_OPT_GENEVE_UNSPEC+ 1 in the policy so that new command using new option on an old kernel throws an error.I'm not sure if
strict_start_typeis needed when usingnla_parse_nested()..strict_start_type seems only checked in
validate_nla():if (strict_start_type && type >= strict_start_type) validate |= NL_VALIDATE_STRICT; <------ [1]
Quoted 9 lines
But in the path of:
nla_parse_nested()->__nla_parse() -> __nla_validate_parse() -> validate_nla()The param 'validate' is always
NL_VALIDATE_STRICT, no matter Code [1] is triggered or not. or am I missing something here?
ok, I missed that.
David Miller
maintainerFrom: Xin Long <[email protected]>
Date: Thu, 7 Nov 2019 18:50:15 +0800
Quoted 3 lines
Now think about it again,
nla_parse_nested()should always be used on new options, should I post a fix for it? since no code to access this from userspace yet.
If that is true, yes you should.