xfrm: add IPv6 encapsulation support for ESP over UDP and TCP
Subsystems (5)
v2 cover xfrm: add IPv6 encapsulation support for ESP over UDP and TCP
This series adds IPv6 encapsulation of ESP over both UDP and TCP. In both cases, the code is very similar to the existing IPv4 encapsulation implementation. The core espintcp code is almost entirely version-independent.
v2: rebase on top of ipsec-next/master
Sabrina Dubroca (2):
xfrm: add support for UDPv6 encapsulation of ESP
xfrm: add IPv6 support for espintcp
include/net/ipv6_stubs.h | 5 + include/net/xfrm.h | 5 + net/ipv4/Kconfig | 1 + net/ipv4/udp.c | 10 +- net/ipv6/Kconfig | 12 ++ net/ipv6/af_inet6.c | 5 + net/ipv6/ah6.c | 1 + net/ipv6/esp6.c | 413 +++++++++++++++++++++++++++++++++++--- net/ipv6/esp6_offload.c | 7 +- net/ipv6/ip6_vti.c | 18 +- net/ipv6/ipcomp6.c | 1 + net/ipv6/xfrm6_input.c | 106 +++++++++- net/ipv6/xfrm6_protocol.c | 48 +++++ net/xfrm/Kconfig | 3 + net/xfrm/Makefile | 2 +- net/xfrm/espintcp.c | 56 +++++- net/xfrm/xfrm_interface.c | 3 + 17 files changed, 646 insertions(+), 50 deletions(-)
Signature · 1 line
2.26.1
PATCH v2 1/2 xfrm: add support for UDPv6 encapsulation of ESP
This patch adds support for encapsulation of ESP over UDPv6. The code is very similar to the IPv4 encapsulation implementation, and allows to easily add espintcp on IPv6 as a follow-up.
---
v2: rebase on top of ipsec-next/master
include/net/ipv6_stubs.h | 3 + include/net/xfrm.h | 5 + net/ipv4/udp.c | 10 +- net/ipv6/af_inet6.c | 4 + net/ipv6/ah6.c | 1 + net/ipv6/esp6.c | 225 +++++++++++++++++++++++++++++++++----- net/ipv6/esp6_offload.c | 7 +- net/ipv6/ip6_vti.c | 18 ++- net/ipv6/ipcomp6.c | 1 + net/ipv6/xfrm6_input.c | 106 +++++++++++++++++- net/ipv6/xfrm6_protocol.c | 48 ++++++++ net/xfrm/xfrm_interface.c | 3 + 12 files changed, 394 insertions(+), 37 deletions(-)
include/net/ipv6_stubs.h +3 -0
@@ -56,6 +56,9 @@ struct ipv6_stub {void (*ndisc_send_na)(struct net_device *dev,const struct in6_addr *daddr,const struct in6_addr *solicited_addr,bool router,bool solicited,bool override,bool inc_opt); +#if IS_ENABLED (CONFIG_XFRM ) +int (*xfrm6_udp_encap_rcv)(struct sock *sk,struct sk_buff *skb); +#endif struct neigh_table *nd_tbl; };extern const struct ipv6_stub *ipv6_stub__read_mostly ;
include/net/xfrm.h +5 -0
@@ -1406,6 +1406,8 @@ struct xfrm4_protocol {struct xfrm6_protocol {int (*handler)(struct sk_buff *skb); +int (*input_handler)(struct sk_buff *skb,int nexthdr,__be32 spi, +int encap_type);int (*cb_handler)(struct sk_buff *skb,int err);int (*err_handler)(struct sk_buff *skb,struct inet6_skb_parm *opt,u8 type,u8 code,int offset,__be32 info);
@@ -1590,6 +1592,8 @@ int xfrm6_extract_header(struct sk_buff *skb);int xfrm6_extract_input (struct xfrm_state *x,struct sk_buff *skb);int xfrm6_rcv_spi (struct sk_buff *skb,int nexthdr,__be32 spi,struct ip6_tnl *t); +int xfrm6_rcv_encap (struct sk_buff *skb,int nexthdr,__be32 spi, +int encap_type);int xfrm6_transport_finish (struct sk_buff *skb,int async);int xfrm6_rcv_tnl (struct sk_buff *skb,struct ip6_tnl *t);int xfrm6_rcv (struct sk_buff *skb);
@@ -1610,6 +1614,7 @@ int xfrm6_find_1stfragopt(struct xfrm_state *x, struct sk_buff *skb,#ifdef CONFIG_XFRM int xfrm4_udp_encap_rcv (struct sock *sk,struct sk_buff *skb); +int xfrm6_udp_encap_rcv (struct sock *sk,struct sk_buff *skb);int xfrm_user_policy (struct sock *sk,int optname,u8 __user *optval,int optlen);#else
net/ipv4/udp.c +9 -1
@@ -112,6 +112,9 @@#include <net/sock_reuseport.h> #include <net/addrconf.h> #include <net/udp_tunnel.h> +#if IS_ENABLED (CONFIG_IPV6 ) +#include <net/ipv6_stubs.h> +#endif struct udp_table udp_table__read_mostly ;EXPORT_SYMBOL (udp_table);
@@ -2563,7 +2566,12 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,#ifdef CONFIG_XFRM case UDP_ENCAP_ESPINUDP :case UDP_ENCAP_ESPINUDP_NON_IKE : - up->encap_rcv = xfrm4_udp_encap_rcv; +#if IS_ENABLED (CONFIG_IPV6 ) +if (sk->sk_family ==AF_INET6 ) + up->encap_rcv = ipv6_stub->xfrm6_udp_encap_rcv; + else +#endif + up->encap_rcv = xfrm4_udp_encap_rcv;#endif fallthrough;case UDP_ENCAP_L2TPINUDP :
net/ipv6/af_inet6.c +4 -0
@@ -60,6 +60,7 @@#include <net/calipso.h> #include <net/seg6.h> #include <net/rpl.h> +#include <net/xfrm.h> #include <linux/uaccess.h> #include <linux/mroute6.h>
@@ -961,6 +962,9 @@ static const struct ipv6_stub ipv6_stub_impl = { .ip6_del_rt = ip6_del_rt, .udpv6_encap_enable = udpv6_encap_enable, .ndisc_send_na = ndisc_send_na, +#if IS_ENABLED(CONFIG_XFRM) + .xfrm6_udp_encap_rcv = xfrm6_udp_encap_rcv, +#endif .nd_tbl = &nd_tbl, };
net/ipv6/ah6.c +1 -0
@@ -767,6 +767,7 @@ static const struct xfrm_type ah6_type = {static struct xfrm6_protocol ah6_protocol = { .handler = xfrm6_rcv, + .input_handler = xfrm_input, .cb_handler = ah6_rcv_cb, .err_handler = ah6_err, .priority =0 ,
net/ipv6/esp6.c +200 -25
398 lines not on this page · raw message
net/ipv6/esp6_offload.c +3 -4
@@ -271,7 +271,6 @@ static int esp6_xmit(struct xfrm_state *x, struct sk_buff *skb, netdev_featuresint alen;int blksize;struct xfrm_offload *xo; -struct ip_esp_hdr *esph;struct crypto_aead *aead;struct esp_info esp;bool hw_offload = true;
@@ -312,13 +311,13 @@ static int esp6_xmit(struct xfrm_state *x, struct sk_buff *skb, netdev_features seq = xo->seq.low; - esph =ip_esp_hdr (skb); - esph->spi = x->id.spi; + esp.esph =ip_esp_hdr (skb); + esp.esph->spi = x->id.spi;skb_push (skb, -skb_network_offset (skb));if (xo->flags &XFRM_GSO_SEGMENT ) { - esph->seq_no =htonl (seq); + esp.esph->seq_no =htonl (seq);if (!skb_is_gso (skb)) xo->seq.low++;
net/ipv6/ip6_vti.c +16 -2
@@ -296,7 +296,8 @@ static void vti6_dev_uninit(struct net_device *dev)dev_put (dev); } -static int vti6_rcv (struct sk_buff *skb) +static int vti6_input_proto (struct sk_buff *skb,int nexthdr,__be32 spi, +int encap_type) {struct ip6_tnl *t;const struct ipv6hdr *ipv6h =ipv6_hdr (skb);
@@ -323,7 +324,10 @@ static int vti6_rcv(struct sk_buff *skb)rcu_read_unlock (); -return xfrm6_rcv_tnl (skb, t); +XFRM_TUNNEL_SKB_CB (skb)->tunnel.ip6 = t; +XFRM_SPI_SKB_CB (skb)->family =AF_INET6 ; +XFRM_SPI_SKB_CB (skb)->daddroff = offsetof(struct ipv6hdr , daddr); +return xfrm_input (skb, nexthdr, spi, encap_type); }rcu_read_unlock ();return -EINVAL ;
@@ -332,6 +336,13 @@ static int vti6_rcv(struct sk_buff *skb)return 0 ; } +static int vti6_rcv (struct sk_buff *skb) +{ +int nexthdr =skb_network_header (skb)[IP6CB (skb)->nhoff]; + +return vti6_input_proto (skb, nexthdr,0 ,0 ); +} +static int vti6_rcv_cb (struct sk_buff *skb,int err) {unsigned short family;
@@ -1185,6 +1196,7 @@ static struct pernet_operations vti6_net_ops = {static struct xfrm6_protocol vti_esp6_protocol__read_mostly = { .handler = vti6_rcv, + .input_handler = vti6_input_proto, .cb_handler = vti6_rcv_cb, .err_handler = vti6_err, .priority =100 ,
@@ -1192,6 +1204,7 @@ static struct xfrm6_protocol vti_esp6_protocol __read_mostly = {static struct xfrm6_protocol vti_ah6_protocol__read_mostly = { .handler = vti6_rcv, + .input_handler = vti6_input_proto, .cb_handler = vti6_rcv_cb, .err_handler = vti6_err, .priority =100 ,
@@ -1199,6 +1212,7 @@ static struct xfrm6_protocol vti_ah6_protocol __read_mostly = {static struct xfrm6_protocol vti_ipcomp6_protocol__read_mostly = { .handler = vti6_rcv, + .input_handler = vti6_input_proto, .cb_handler = vti6_rcv_cb, .err_handler = vti6_err, .priority =100 ,
net/ipv6/ipcomp6.c +1 -0
@@ -183,6 +183,7 @@ static const struct xfrm_type ipcomp6_type = {static struct xfrm6_protocol ipcomp6_protocol = { .handler = xfrm6_rcv, + .input_handler = xfrm_input, .cb_handler = ipcomp6_rcv_cb, .err_handler = ipcomp6_err, .priority =0 ,
net/ipv6/xfrm6_input.c +101 -5
123 lines not on this page · raw message
net/ipv6/xfrm6_protocol.c +48 -0
60 lines not on this page · raw message
net/xfrm/xfrm_interface.c +3 -0
@@ -757,6 +757,7 @@ static struct pernet_operations xfrmi_net_ops = {static struct xfrm6_protocol xfrmi_esp6_protocol__read_mostly = { .handler = xfrm6_rcv, + .input_handler = xfrm_input, .cb_handler = xfrmi_rcv_cb, .err_handler = xfrmi6_err, .priority =10 ,
@@ -764,6 +765,7 @@ static struct xfrm6_protocol xfrmi_esp6_protocol __read_mostly = {static struct xfrm6_protocol xfrmi_ah6_protocol__read_mostly = { .handler = xfrm6_rcv, + .input_handler = xfrm_input, .cb_handler = xfrmi_rcv_cb, .err_handler = xfrmi6_err, .priority =10 ,
@@ -771,6 +773,7 @@ static struct xfrm6_protocol xfrmi_ah6_protocol __read_mostly = {static struct xfrm6_protocol xfrmi_ipcomp6_protocol__read_mostly = { .handler = xfrm6_rcv, + .input_handler = xfrm_input, .cb_handler = xfrmi_rcv_cb, .err_handler = xfrmi6_err, .priority =10 ,
Signature · 1 line
2.26.1
PATCH v2 2/2 xfrm: add IPv6 support for espintcp
In reply to Sabrina DubrocaThis extends espintcp to support IPv6, building on the existing code and the new UDPv6 encapsulation support. Most of the code is either reused directly (stream parser, ULP) or very similar to the IPv4 variant (net/ipv6/esp6.c changes).
The separation of config options for IPv4 and IPv6 espintcp requires a bit of Kconfig gymnastics to enable the core code.
--- include/net/ipv6_stubs.h | 2 + net/ipv4/Kconfig | 1 + net/ipv6/Kconfig | 12 +++ net/ipv6/af_inet6.c | 1 + net/ipv6/esp6.c | 188 ++++++++++++++++++++++++++++++++++++++- net/xfrm/Kconfig | 3 + net/xfrm/Makefile | 2 +- net/xfrm/espintcp.c | 56 +++++++++--- 8 files changed, 252 insertions(+), 13 deletions(-)
include/net/ipv6_stubs.h +2 -0
@@ -58,6 +58,8 @@ struct ipv6_stub { bool router, bool solicited, bool override, bool inc_opt);#if IS_ENABLED (CONFIG_XFRM )int (*xfrm6_udp_encap_rcv)(struct sock *sk,struct sk_buff *skb); +int (*xfrm6_rcv_encap)(struct sk_buff *skb,int nexthdr,__be32 spi, +int encap_type);#endif struct neigh_table *nd_tbl; };
net/ipv4/Kconfig +1 -0
@@ -384,6 +384,7 @@ config INET_ESPINTCP depends on XFRM && INET_ESP select STREAM_PARSER select NET_SOCK_MSG + select XFRM_ESPINTCP help Support for RFC 8229 encapsulation of ESP and IKE over TCP/IPv4 sockets.
net/ipv6/Kconfig +12 -0
@@ -88,6 +88,18 @@ config INET6_ESP_OFFLOAD If unsure, say N. +config INET6_ESPINTCP + bool "IPv6: ESP in TCP encapsulation (RFC 8229)" + depends on XFRM && INET6_ESP + select STREAM_PARSER + select NET_SOCK_MSG + select XFRM_ESPINTCP + help + Support for RFC 8229 encapsulation of ESP and IKE over + TCP/IPv6 sockets. + + If unsure, say N. + config INET6_IPCOMP tristate "IPv6: IPComp transformation" select INET6_XFRM_TUNNEL
net/ipv6/af_inet6.c +1 -0
@@ -964,6 +964,7 @@ static const struct ipv6_stub ipv6_stub_impl = { .ndisc_send_na = ndisc_send_na, #if IS_ENABLED(CONFIG_XFRM) .xfrm6_udp_encap_rcv = xfrm6_udp_encap_rcv, + .xfrm6_rcv_encap = xfrm6_rcv_encap, #endif .nd_tbl = &nd_tbl, };
net/ipv6/esp6.c +187 -1
239 lines not on this page · raw message
net/xfrm/Kconfig +3 -0
@@ -99,4 +99,7 @@ config NET_KEY_MIGRATE If unsure, say N. +config XFRM_ESPINTCP + bool + endif # INET
net/xfrm/Makefile +1 -1
@@ -11,4 +11,4 @@ obj-$(CONFIG_XFRM_ALGO) += xfrm_algo.o obj-$(CONFIG_XFRM_USER) += xfrm_user.o obj-$(CONFIG_XFRM_IPCOMP) += xfrm_ipcomp.o obj-$(CONFIG_XFRM_INTERFACE) += xfrm_interface.o -obj-$(CONFIG_INET_ESPINTCP) += espintcp.o +obj-$(CONFIG_XFRM_ESPINTCP) += espintcp.o
net/xfrm/espintcp.c +45 -11
101 lines not on this page · raw message
Signature · 1 line
2.26.1
Steffen Klassert
maintainerRe: [PATCH ipsec-next v2 2/2] xfrm: add IPv6 support for espintcp
Quoted 9 lines · Sabrina Dubroca
This extends espintcp to support IPv6, building on the existing code and the new UDPv6 encapsulation support. Most of the code is either reused directly (stream parser, ULP) or very similar to the IPv4 variant (
net/ipv6/esp6.cchanges).The separation of config options for IPv4 and IPv6 espintcp requires a bit of
Kconfiggymnastics to enable the core code.Signed-off-by Sabrina Dubroca <[email protected]>
This patch does not apply on top of patch 1/2:
git am -s ~/Mail/todo-ipsec-next
Applying: xfrm: add support for UDPv6 encapsulation of ESP
Applying: xfrm: add IPv6 support for espintcp
error: patch failed: net/xfrm/espintcp.c:416
error: net/xfrm/espintcp.c: patch does not apply Patch failed at 0002 xfrm: add IPv6 support for espintcp
Can you please doublecheck this?
Re: [PATCH ipsec-next v2 2/2] xfrm: add IPv6 support for espintcp
Quoted 13 lines · Steffen Klassert
Quoted 9 lines · Sabrina Dubroca
This extends espintcp to support IPv6, building on the existing code and the new UDPv6 encapsulation support. Most of the code is either reused directly (stream parser, ULP) or very similar to the IPv4 variant (
net/ipv6/esp6.cchanges).The separation of config options for IPv4 and IPv6 espintcp requires a bit of
Kconfiggymnastics to enable the core code.Signed-off-by Sabrina Dubroca <[email protected]>This patch does not apply on top of patch 1/2:
Quoted 8 lines
git am -s ~/Mail/todo-ipsec-next
Applying: xfrm: add support for UDPv6 encapsulation of ESP
Applying: xfrm: add IPv6 support for espintcp
error: patch failed:net/xfrm/espintcp.c:416
error:net/xfrm/espintcp.c: patch does not apply Patch failed at 0002 xfrm: add IPv6 support for espintcpCan you please doublecheck this?
*facepalm*
I had the sk_destruct fix in my branch when I exported those patches, so git format-patch exported a patch with slightly different offsets.
Sorry for the mess, I'll post a v3 that applies correctly on ipsec-next.
Signature · 1 line
Sabrina