aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/xfrm6_mode_tunnel.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-11-14 00:41:28 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 17:53:46 -0500
commit227620e295090629fcb2c46ad3828222ab65438d (patch)
tree534162a74628fdfa7a8201cb776a45ca07510e5b /net/ipv6/xfrm6_mode_tunnel.c
parent36cf9acf93e8561d9faec24849e57688a81eb9c5 (diff)
[IPSEC]: Separate inner/outer mode processing on input
With inter-family transforms the inner mode differs from the outer mode. Attempting to handle both sides from the same function means that it needs to handle both IPv4 and IPv6 which creates duplication and confusion. This patch separates the two parts on the input path so that each function deals with one family only. In particular, the functions xfrm4_extract_inut/xfrm6_extract_inut moves the pertinent fields from the IPv4/IPv6 IP headers into a neutral format stored in skb->cb. This is then used by the inner mode input functions to modify the inner IP header. In this way the input function no longer has to know about the outer address family. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/xfrm6_mode_tunnel.c')
-rw-r--r--net/ipv6/xfrm6_mode_tunnel.c31
1 files changed, 9 insertions, 22 deletions
diff --git a/net/ipv6/xfrm6_mode_tunnel.c b/net/ipv6/xfrm6_mode_tunnel.c
index d45ce5d44197..f7d0d6612650 100644
--- a/net/ipv6/xfrm6_mode_tunnel.c
+++ b/net/ipv6/xfrm6_mode_tunnel.c
@@ -25,12 +25,6 @@ static inline void ipip6_ecn_decapsulate(struct sk_buff *skb)
25 IP6_ECN_set_ce(inner_iph); 25 IP6_ECN_set_ce(inner_iph);
26} 26}
27 27
28static inline void ip6ip_ecn_decapsulate(struct sk_buff *skb)
29{
30 if (INET_ECN_is_ce(ipv6_get_dsfield(ipv6_hdr(skb))))
31 IP_ECN_set_ce(ipip_hdr(skb));
32}
33
34/* Add encapsulation header. 28/* Add encapsulation header.
35 * 29 *
36 * The top IP header will be constructed per RFC 2401. 30 * The top IP header will be constructed per RFC 2401.
@@ -68,10 +62,8 @@ static int xfrm6_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)
68{ 62{
69 int err = -EINVAL; 63 int err = -EINVAL;
70 const unsigned char *old_mac; 64 const unsigned char *old_mac;
71 const unsigned char *nh = skb_network_header(skb);
72 65
73 if (nh[IP6CB(skb)->nhoff] != IPPROTO_IPV6 && 66 if (XFRM_MODE_SKB_CB(skb)->protocol != IPPROTO_IPV6)
74 nh[IP6CB(skb)->nhoff] != IPPROTO_IPIP)
75 goto out; 67 goto out;
76 if (!pskb_may_pull(skb, sizeof(struct ipv6hdr))) 68 if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
77 goto out; 69 goto out;
@@ -80,18 +72,12 @@ static int xfrm6_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)
80 (err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC))) 72 (err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC)))
81 goto out; 73 goto out;
82 74
83 nh = skb_network_header(skb); 75 if (x->props.flags & XFRM_STATE_DECAP_DSCP)
84 if (nh[IP6CB(skb)->nhoff] == IPPROTO_IPV6) { 76 ipv6_copy_dscp(ipv6_get_dsfield(ipv6_hdr(skb)),
85 if (x->props.flags & XFRM_STATE_DECAP_DSCP) 77 ipipv6_hdr(skb));
86 ipv6_copy_dscp(ipv6_get_dsfield(ipv6_hdr(skb)), 78 if (!(x->props.flags & XFRM_STATE_NOECN))
87 ipipv6_hdr(skb)); 79 ipip6_ecn_decapsulate(skb);
88 if (!(x->props.flags & XFRM_STATE_NOECN)) 80
89 ipip6_ecn_decapsulate(skb);
90 } else {
91 if (!(x->props.flags & XFRM_STATE_NOECN))
92 ip6ip_ecn_decapsulate(skb);
93 skb->protocol = htons(ETH_P_IP);
94 }
95 old_mac = skb_mac_header(skb); 81 old_mac = skb_mac_header(skb);
96 skb_set_mac_header(skb, -skb->mac_len); 82 skb_set_mac_header(skb, -skb->mac_len);
97 memmove(skb_mac_header(skb), old_mac, skb->mac_len); 83 memmove(skb_mac_header(skb), old_mac, skb->mac_len);
@@ -103,7 +89,8 @@ out:
103} 89}
104 90
105static struct xfrm_mode xfrm6_tunnel_mode = { 91static struct xfrm_mode xfrm6_tunnel_mode = {
106 .input = xfrm6_tunnel_input, 92 .input2 = xfrm6_tunnel_input,
93 .input = xfrm_prepare_input,
107 .output2 = xfrm6_tunnel_output, 94 .output2 = xfrm6_tunnel_output,
108 .output = xfrm6_prepare_output, 95 .output = xfrm6_prepare_output,
109 .owner = THIS_MODULE, 96 .owner = THIS_MODULE,