: Support multiple VTIs with the same src+dst pair
Subsystems (4)
cover : Support multiple VTIs with the same src+dst pair
When using IPsec tunnel mode, VTIs provide many benefits compared to direct configuration of xfrm policies / states. However, one limitation is that there can only be one VTI between a given pair of IP addresses. This does not allow configuring multiple IPsec tunnels to the same security gateway. This is required by some deployments, for example I-WLAN [3GPP TS 24.327].
This patchset introduces a new VTI_KEYED flag that allows configuration of multiple VTIs between the same IP address pairs. The output path is the same as current VTI behaviour, where a routing lookup selects a VTI interface, and the VTI's okey specifies the mark to use in the XFRM lookup. The input and ICMP error paths instead work by first looking up an SA with a loose match that ignores the mark. That mark is then used to find the tunnel by ikey.
This approach is simple and requires few userspace changes, but it has one limitation in that ICMP errors received in response to VTI-emitted packets can only be processed if the VTI's ikey and okey are the same. This limitation could be lifted by introducing another XFRM mark, similar to XFRMA_OUTPUT_MARK, but used for input.
RFC 1/4 met: xfrm: Add an xfrm lookup that ignores the mark.
The xfrm inbound and ICMP error paths can match inbound XFRM states that have a mark, but only if the skb mark is already correctly set to match the state mark. This typically requires iptables rules (potentially even per SA iptables rules), which impose configuration complexity.
In some cases, it may be useful to match such an SA anyway. An example is when processing an ICMP error to an ESP packet that we previously sent. In this case, the only information available to match the SA are the IP addresses and the outbound SPI. Therefore, if the output SA has a mark, the lookup will fail and the ICMP packet cannot be processed unless the packet is somehow already marked.
--- include/net/xfrm.h | 4 ++++ net/xfrm/xfrm_state.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)
include/net/xfrm.h +4 -0
@@ -1550,6 +1550,10 @@ struct xfrm_state *xfrm_state_lookup_byaddr(struct net *net, u32 mark,const xfrm_address_t *saddr, u8 proto, unsigned short family); +struct xfrm_state *xfrm_state_lookup_loose (struct net *net,u32 mark, +const xfrm_address_t *daddr, +__be32 spi,u8 proto, +unsigned short family);#ifdef CONFIG_XFRM_SUB_POLICY int xfrm_tmpl_sort (struct xfrm_tmpl **dst,struct xfrm_tmpl **src,int n,unsigned short family,struct net *net);
net/xfrm/xfrm_state.c +32 -0
@@ -839,6 +839,38 @@ static struct xfrm_state *__xfrm_state_lookup(struct net *net, u32 mark,return NULL ; } +struct xfrm_state *xfrm_state_lookup_loose (struct net *net,u32 mark, +const xfrm_address_t *daddr, +__be32 spi,u8 proto, +unsigned short family) +{ +unsigned int h =xfrm_spi_hash (net, daddr, spi, proto, family); +struct xfrm_state *x, *cand =NULL ; + +rcu_read_lock (); +hlist_for_each_entry_rcu (x, net->xfrm.state_byspi + h, byspi) { +if (x->props.family != family || + x->id.spi != spi || + x->id.proto != proto || + !xfrm_addr_equal (&x->id.daddr, daddr, family)) +continue ; + +if (((mark & x->mark.m) == x->mark.v) && +xfrm_state_hold_rcu (x)) { +if (cand) +xfrm_state_put (cand); +rcu_read_unlock (); +return x; + } + +if (!cand &&xfrm_state_hold_rcu (x)) + cand = x; + } + +rcu_read_unlock (); +return cand; +} + static struct xfrm_state *__xfrm_state_lookup_byaddr(struct net *net, u32 mark, const xfrm_address_t *daddr, const xfrm_address_t *saddr,
Signature · 1 line
2.15.1.504.g5279b80103-goog
RFC 2/4 net: xfrm: find VTI interfaces from xfrm_input
In reply to Lorenzo ColittiCurrently, the VTI input path works by first looking up the VTI by its IP addresses, then setting the tunnel pointer in the XFRM_TUNNEL_SKB_CB, and then having xfrm_input override the mark with the mark in the tunnel.
This patch changes the order so that the tunnel is found by a callback from xfrm_input. Each tunnel type (currently only ip_vti and ip6_vti) implements a lookup function pointer that finds the tunnel and sets it in the CB, and also does a state lookup.
This has the advantage that much more information is available to the tunnel lookup function, including the looked-up XFRM state. This will be used in a future change to allow finding the tunnel not just from the IP addresses, but also from the xfrm lookup.
The lookup function pointer occupies the same space in the XFRM_TUNNEL_SKB_CB as the IPv4/IPv6 tunnel pointer. The semantics of the field are:
- When not running a handler that uses tunnels: always null.
- At the beginning of xfrm_input: lookup function pointer.
- After xfrm_input calls the lookup function: tunnel if found, else null.
--- include/net/xfrm.h | 2 ++ net/ipv4/ip_vti.c | 43 ++++++++++++++++++++++++++++++++++++---- net/ipv6/ip6_vti.c | 53 +++++++++++++++++++++++++++++++++++++++++++++----- net/ipv6/xfrm6_input.c | 1 - net/xfrm/xfrm_input.c | 34 +++++++++++++++++++------------- 5 files changed, 109 insertions(+), 24 deletions(-)
include/net/xfrm.h +2 -0
@@ -653,6 +653,8 @@ struct xfrm_tunnel_skb_cb { } header;union { +int (*lookup)(struct sk_buff *skb,int nexthdr,__be32 spi, +__be32 seq,struct xfrm_state **x);struct ip_tunnel *ip4;struct ip6_tnl *ip6; } tunnel;
net/ipv4/ip_vti.c +39 -4
72 lines not on this page · raw message
net/ipv6/ip6_vti.c +48 -5
89 lines not on this page · raw message
net/ipv6/xfrm6_input.c +0 -1
@@ -25,7 +25,6 @@ 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) { -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,0 );
net/xfrm/xfrm_input.c +20 -14
@@ -267,18 +267,6 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) family =XFRM_SPI_SKB_CB (skb)->family; -/* if tunnel is present override skb->mark value with tunnel i_key */ -switch (family) { -case AF_INET : -if (XFRM_TUNNEL_SKB_CB (skb)->tunnel.ip4) - mark =be32_to_cpu (XFRM_TUNNEL_SKB_CB (skb)->tunnel.ip4->parms.i_key); -break ; -case AF_INET6 : -if (XFRM_TUNNEL_SKB_CB (skb)->tunnel.ip6) - mark =be32_to_cpu (XFRM_TUNNEL_SKB_CB (skb)->tunnel.ip6->parms.i_key); -break ; - } - err =secpath_set (skb);if (err) {XFRM_INC_STATS (net,LINUX_MIB_XFRMINERROR );
@@ -293,14 +281,29 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) daddr = (xfrm_address_t *)(skb_network_header (skb) +XFRM_SPI_SKB_CB (skb)->daddroff); + +if (XFRM_TUNNEL_SKB_CB (skb)->tunnel.lookup) { + err =XFRM_TUNNEL_SKB_CB (skb)->tunnel.lookup (skb, nexthdr, + spi, seq, &x); +if (err) { +XFRM_TUNNEL_SKB_CB (skb)->tunnel.lookup =NULL ; +return err; + } + } + do { if (skb->sp->len == XFRM_MAX_DEPTH) { XFRM_INC_STATS(net, LINUX_MIB_XFRMINBUFFERERROR); + if (x) + xfrm_state_put(x); goto drop; } - x = xfrm_state_lookup(net, mark, daddr, spi, nexthdr, family); - if (x == NULL) { + if (!x) + x = xfrm_state_lookup(net, mark, daddr, spi, nexthdr, + family); + + if (!x) { XFRM_INC_STATS(net, LINUX_MIB_XFRMINNOSTATES); xfrm_audit_state_notfound(skb, family, spi, seq); goto drop;
@@ -420,6 +423,9 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)XFRM_INC_STATS (net,LINUX_MIB_XFRMINHDRERROR ); goto drop; } + +if (!err) + x =NULL ; }while (!err); err =xfrm_rcv_cb (skb, family, x->type->proto,0 );
Signature · 1 line
2.15.1.504.g5279b80103-goog
RFC 3/4 net: xfrm: support multiple VTI tunnels
In reply to Lorenzo ColittiThis commit allows the creation of multiple VTI tunnels with the same src+dst pair, via a new VTI_KEYED flag. This makes it possible to maintain multiple IPsec tunnels to the same security gateway, with the tunnels distinguished by SPI.
The new semantics are as follows:
- The output path is the same as existing VTIs. A routing lookup matches a VTI interface. The VTI uses its o_key to as the mark to select an XFRM state. The state transforms the packet.
- Input works as follows:
1. Attempt to match a regular VTI by IP addresses only. If that succeeds, use the i_key as the mark to look up the xfrm state.
2. If the match failed, do an XFRM state lookup that ignores the mark. If that finds an state, then use the state match's mark to find the tunnel by its i_key.
- ICMP errors are similar to input, except the search is for the outbound XFRM state, because the only data that is available is the outbound SPI. Thus, ICMP errors are only processed if the ikey is the same as the same as the okey. AFAICS this is consistent with GRE tunnels, but not with existing VTI behaviour.
Tested: https://android-review.googlesource.com/571524
--- include/uapi/linux/if_tunnel.h | 3 ++ net/ipv4/ip_vti.c | 75 +++++++++++++++++++++++-------- net/ipv6/ip6_vti.c | 100 +++++++++++++++++++++++++++++++---------- 3 files changed, 136 insertions(+), 42 deletions(-)
include/uapi/linux/if_tunnel.h +3 -0
@@ -147,6 +147,8 @@ enum {/* VTI-mode i_flags */ #define VTI_ISVTI ((__force __be16)0x0001) +#define VTI_KEYED ((__force __be16)0x0002) +#define VTI_IFLAG_MASK ((__force __be16)0x0003)enum {IFLA_VTI_UNSPEC ,
@@ -156,6 +158,7 @@ enum {IFLA_VTI_LOCAL ,IFLA_VTI_REMOTE ,IFLA_VTI_FWMARK , +IFLA_VTI_IFLAGS , __IFLA_VTI_MAX, };
net/ipv4/ip_vti.c +57 -18
141 lines not on this page · raw message
net/ipv6/ip6_vti.c +76 -24
223 lines not on this page · raw message
Signature · 1 line
2.15.1.504.g5279b80103-goog
RFC 4/4 net: xfrm: don't pass tunnel objects to xfrm6_rcv_spi.
In reply to Lorenzo ColittiThis change removes the tunnel parameter from xfrm6_rcv_spi and deletes xfrm6_rcv_tnl. These were only used by the VTI code and are now unused.
--- include/net/xfrm.h | 4 +--- net/ipv4/ip_vti.c | 4 ++-- net/ipv6/ip6_vti.c | 2 +- net/ipv6/xfrm6_input.c | 13 +++---------- net/ipv6/xfrm6_tunnel.c | 2 +- 5 files changed, 8 insertions(+), 17 deletions(-)
include/net/xfrm.h +1 -3
@@ -1638,10 +1638,8 @@ int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler, unsigned short family);void xfrm4_local_error (struct sk_buff *skb,u32 mtu);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_spi (struct sk_buff *skb,int nexthdr,__be32 spi);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);int xfrm6_input_addr (struct sk_buff *skb,xfrm_address_t *daddr,xfrm_address_t *saddr,u8 proto);
net/ipv4/ip_vti.c +2 -2
@@ -384,12 +384,12 @@ static int vti4_err(struct sk_buff *skb, u32 info)static __be16 vti_flags_to_tnl_flags (__be16 i_flags) { -return VTI_ISVTI | ((i_flags &VTI_KEYED ) ?GRE_KEY :0 ); +return VTI_ISVTI | ((i_flags &VTI_KEYED ) ?TUNNEL_KEY :0 ); }static __be16 tnl_flags_to_vti_flags (__be16 i_flags) { -return VTI_ISVTI | ((i_flags &GRE_KEY ) ?VTI_KEYED :0 ); +return VTI_ISVTI | ((i_flags &TUNNEL_KEY ) ?VTI_KEYED :0 ); } static int
net/ipv6/ip6_vti.c +1 -1
@@ -391,7 +391,7 @@ static int vti6_rcv(struct sk_buff *skb)int nexthdr =skb_network_header (skb)[IP6CB (skb)->nhoff];XFRM_TUNNEL_SKB_CB (skb)->tunnel.lookup = vti6_lookup; -return xfrm6_rcv_spi (skb, nexthdr,0 ,NULL ); +return xfrm6_rcv_spi (skb, nexthdr,0 ); }static int vti6_rcv_cb (struct sk_buff *skb,int err)
net/ipv6/xfrm6_input.c +3 -10
@@ -22,8 +22,7 @@ int xfrm6_extract_input(struct xfrm_state *x, struct sk_buff *skb)return xfrm6_extract_header (skb); } -int xfrm6_rcv_spi (struct sk_buff *skb,int nexthdr,__be32 spi, -struct ip6_tnl *t) +int xfrm6_rcv_spi (struct sk_buff *skb,int nexthdr,__be32 spi) {XFRM_SPI_SKB_CB (skb)->family =AF_INET6 ;XFRM_SPI_SKB_CB (skb)->daddroff = offsetof(struct ipv6hdr , daddr);
@@ -59,16 +58,10 @@ int xfrm6_transport_finish(struct sk_buff *skb, int async)return -1 ; } -int xfrm6_rcv_tnl (struct sk_buff *skb,struct ip6_tnl *t) -{ -return xfrm6_rcv_spi (skb,skb_network_header (skb)[IP6CB (skb)->nhoff], -0 , t); -} -EXPORT_SYMBOL (xfrm6_rcv_tnl); -int xfrm6_rcv (struct sk_buff *skb) { -return xfrm6_rcv_tnl (skb,NULL ); +return xfrm6_rcv_spi (skb,skb_network_header (skb)[IP6CB (skb)->nhoff], +0 ); }EXPORT_SYMBOL (xfrm6_rcv); int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
net/ipv6/xfrm6_tunnel.c +1 -1
@@ -236,7 +236,7 @@ static int xfrm6_tunnel_rcv(struct sk_buff *skb)__be32 spi; spi =xfrm6_tunnel_spi_lookup (net, (const xfrm_address_t *)&iph->saddr); -return xfrm6_rcv_spi (skb,IPPROTO_IPV6 , spi,NULL ); +return xfrm6_rcv_spi (skb,IPPROTO_IPV6 , spi); } static int xfrm6_tunnel_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
Signature · 1 line
2.15.1.504.g5279b80103-goog
David Miller
maintainerRe: [RFC ipsec-next 3/4] net: xfrm: support multiple VTI tunnels
In reply to Lorenzo ColittiFrom: Lorenzo Colitti <[email protected]>
Date: Tue, 19 Dec 2017 01:16:55 +0900
Quoted 6 lines
- ICMP errors are similar to input, except the search is for the outbound XFRM state, because the only data that is available is the outbound SPI. Thus, ICMP errors are only processed if the ikey is the same as the same as the okey. AFAICS this is consistent with GRE tunnels, but not with existing VTI behaviour.
I think you will need to sort out the VTI ICMP behavior difference with what exists now.
Re: [RFC ipsec-next 3/4] net: xfrm: support multiple VTI tunnels
Quoted 9 lines · David Miller
Quoted 6 lines
- ICMP errors are similar to input, except the search is for the outbound XFRM state, because the only data that is available is the outbound SPI. Thus, ICMP errors are only processed if the ikey is the same as the same as the okey. AFAICS this is consistent with GRE tunnels, but not with existing VTI behaviour.
I think you will need to sort out the VTI ICMP behavior difference with what exists now.
Thanks for the feedback. I've sent out a new series that addresses this.
I had to make some minor changes to the common ip tunnel lookup functions to make it work, because currently, a tunnel can only be looked up by i_key. https://patchwork.ozlabs.org/patch/851558/ .