Commit 13996378 authored by Herbert Xu's avatar Herbert Xu Committed by David S. Miller

[IPSEC]: Rename mode to outer_mode and add inner_mode

This patch adds a new field to xfrm states called inner_mode.  The existing
mode object is renamed to outer_mode.

This is the first part of an attempt to fix inter-family transforms.  As it
is we always use the outer family when determining which mode to use.  As a
result we may end up shoving IPv4 packets into netfilter6 and vice versa.

What we really want is to use the inner family for the first part of outbound
processing and the outer family for the second part.  For inbound processing
we'd use the opposite pairing.

I've also added a check to prevent silly combinations such as transport mode
with inter-family transforms.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ca68145f
...@@ -186,7 +186,8 @@ struct xfrm_state ...@@ -186,7 +186,8 @@ struct xfrm_state
/* Reference to data common to all the instances of this /* Reference to data common to all the instances of this
* transformer. */ * transformer. */
struct xfrm_type *type; struct xfrm_type *type;
struct xfrm_mode *mode; struct xfrm_mode *inner_mode;
struct xfrm_mode *outer_mode;
/* Security context */ /* Security context */
struct xfrm_sec_ctx *security; struct xfrm_sec_ctx *security;
......
...@@ -2454,7 +2454,7 @@ static int pktgen_output_ipsec(struct sk_buff *skb, struct pktgen_dev *pkt_dev) ...@@ -2454,7 +2454,7 @@ static int pktgen_output_ipsec(struct sk_buff *skb, struct pktgen_dev *pkt_dev)
spin_lock(&x->lock); spin_lock(&x->lock);
iph = ip_hdr(skb); iph = ip_hdr(skb);
err = x->mode->output(x, skb); err = x->outer_mode->output(x, skb);
if (err) if (err)
goto error; goto error;
err = x->type->output(x, skb); err = x->type->output(x, skb);
......
...@@ -91,10 +91,10 @@ int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi, ...@@ -91,10 +91,10 @@ int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
xfrm_vec[xfrm_nr++] = x; xfrm_vec[xfrm_nr++] = x;
if (x->mode->input(x, skb)) if (x->outer_mode->input(x, skb))
goto drop; goto drop;
if (x->mode->flags & XFRM_MODE_FLAG_TUNNEL) { if (x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) {
decaps = 1; decaps = 1;
break; break;
} }
......
...@@ -47,7 +47,7 @@ static inline int xfrm4_output_one(struct sk_buff *skb) ...@@ -47,7 +47,7 @@ static inline int xfrm4_output_one(struct sk_buff *skb)
struct iphdr *iph; struct iphdr *iph;
int err; int err;
if (x->mode->flags & XFRM_MODE_FLAG_TUNNEL) { if (x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) {
err = xfrm4_tunnel_check_size(skb); err = xfrm4_tunnel_check_size(skb);
if (err) if (err)
goto error_nolock; goto error_nolock;
......
...@@ -168,7 +168,7 @@ __xfrm4_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int ...@@ -168,7 +168,7 @@ __xfrm4_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
/* Copy neighbout for reachability confirmation */ /* Copy neighbout for reachability confirmation */
dst_prev->neighbour = neigh_clone(rt->u.dst.neighbour); dst_prev->neighbour = neigh_clone(rt->u.dst.neighbour);
dst_prev->input = rt->u.dst.input; dst_prev->input = rt->u.dst.input;
dst_prev->output = dst_prev->xfrm->mode->afinfo->output; dst_prev->output = dst_prev->xfrm->outer_mode->afinfo->output;
if (rt0->peer) if (rt0->peer)
atomic_inc(&rt0->peer->refcnt); atomic_inc(&rt0->peer->refcnt);
x->u.rt.peer = rt0->peer; x->u.rt.peer = rt0->peer;
......
...@@ -68,10 +68,10 @@ int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi) ...@@ -68,10 +68,10 @@ int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi)
xfrm_vec[xfrm_nr++] = x; xfrm_vec[xfrm_nr++] = x;
if (x->mode->input(x, skb)) if (x->outer_mode->input(x, skb))
goto drop; goto drop;
if (x->mode->flags & XFRM_MODE_FLAG_TUNNEL) { if (x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) {
decaps = 1; decaps = 1;
break; break;
} }
......
...@@ -50,7 +50,7 @@ static inline int xfrm6_output_one(struct sk_buff *skb) ...@@ -50,7 +50,7 @@ static inline int xfrm6_output_one(struct sk_buff *skb)
struct ipv6hdr *iph; struct ipv6hdr *iph;
int err; int err;
if (x->mode->flags & XFRM_MODE_FLAG_TUNNEL) { if (x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) {
err = xfrm6_tunnel_check_size(skb); err = xfrm6_tunnel_check_size(skb);
if (err) if (err)
goto error_nolock; goto error_nolock;
......
...@@ -230,7 +230,7 @@ __xfrm6_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int ...@@ -230,7 +230,7 @@ __xfrm6_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
/* Copy neighbour for reachability confirmation */ /* Copy neighbour for reachability confirmation */
dst_prev->neighbour = neigh_clone(rt->u.dst.neighbour); dst_prev->neighbour = neigh_clone(rt->u.dst.neighbour);
dst_prev->input = rt->u.dst.input; dst_prev->input = rt->u.dst.input;
dst_prev->output = dst_prev->xfrm->mode->afinfo->output; dst_prev->output = dst_prev->xfrm->outer_mode->afinfo->output;
/* Sheit... I remember I did this right. Apparently, /* Sheit... I remember I did this right. Apparently,
* it was magically lost, so this code needs audit */ * it was magically lost, so this code needs audit */
x->u.rt6.rt6i_flags = rt0->rt6i_flags&(RTCF_BROADCAST|RTCF_MULTICAST|RTCF_LOCAL); x->u.rt6.rt6i_flags = rt0->rt6i_flags&(RTCF_BROADCAST|RTCF_MULTICAST|RTCF_LOCAL);
......
...@@ -63,7 +63,7 @@ int xfrm_output(struct sk_buff *skb) ...@@ -63,7 +63,7 @@ int xfrm_output(struct sk_buff *skb)
xfrm_replay_notify(x, XFRM_REPLAY_UPDATE); xfrm_replay_notify(x, XFRM_REPLAY_UPDATE);
} }
err = x->mode->output(x, skb); err = x->outer_mode->output(x, skb);
if (err) if (err)
goto error; goto error;
...@@ -82,7 +82,7 @@ int xfrm_output(struct sk_buff *skb) ...@@ -82,7 +82,7 @@ int xfrm_output(struct sk_buff *skb)
} }
dst = skb->dst; dst = skb->dst;
x = dst->xfrm; x = dst->xfrm;
} while (x && !(x->mode->flags & XFRM_MODE_FLAG_TUNNEL)); } while (x && !(x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL));
err = 0; err = 0;
......
...@@ -1941,7 +1941,7 @@ int xfrm_bundle_ok(struct xfrm_policy *pol, struct xfrm_dst *first, ...@@ -1941,7 +1941,7 @@ int xfrm_bundle_ok(struct xfrm_policy *pol, struct xfrm_dst *first,
return 0; return 0;
if (strict && fl && if (strict && fl &&
!(dst->xfrm->mode->flags & XFRM_MODE_FLAG_TUNNEL) && !(dst->xfrm->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) &&
!xfrm_state_addr_flow_check(dst->xfrm, fl, family)) !xfrm_state_addr_flow_check(dst->xfrm, fl, family))
return 0; return 0;
......
...@@ -377,8 +377,10 @@ static void xfrm_state_gc_destroy(struct xfrm_state *x) ...@@ -377,8 +377,10 @@ static void xfrm_state_gc_destroy(struct xfrm_state *x)
kfree(x->calg); kfree(x->calg);
kfree(x->encap); kfree(x->encap);
kfree(x->coaddr); kfree(x->coaddr);
if (x->mode) if (x->inner_mode)
xfrm_put_mode(x->mode); xfrm_put_mode(x->inner_mode);
if (x->outer_mode)
xfrm_put_mode(x->outer_mode);
if (x->type) { if (x->type) {
x->type->destructor(x); x->type->destructor(x);
xfrm_put_type(x->type); xfrm_put_type(x->type);
...@@ -1947,6 +1949,14 @@ int xfrm_init_state(struct xfrm_state *x) ...@@ -1947,6 +1949,14 @@ int xfrm_init_state(struct xfrm_state *x)
goto error; goto error;
err = -EPROTONOSUPPORT; err = -EPROTONOSUPPORT;
x->inner_mode = xfrm_get_mode(x->props.mode, x->sel.family);
if (x->inner_mode == NULL)
goto error;
if (!(x->inner_mode->flags & XFRM_MODE_FLAG_TUNNEL) &&
family != x->sel.family)
goto error;
x->type = xfrm_get_type(x->id.proto, family); x->type = xfrm_get_type(x->id.proto, family);
if (x->type == NULL) if (x->type == NULL)
goto error; goto error;
...@@ -1955,8 +1965,8 @@ int xfrm_init_state(struct xfrm_state *x) ...@@ -1955,8 +1965,8 @@ int xfrm_init_state(struct xfrm_state *x)
if (err) if (err)
goto error; goto error;
x->mode = xfrm_get_mode(x->props.mode, family); x->outer_mode = xfrm_get_mode(x->props.mode, family);
if (x->mode == NULL) if (x->outer_mode == NULL)
goto error; goto error;
x->km.state = XFRM_STATE_VALID; x->km.state = XFRM_STATE_VALID;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment