diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2007-11-14 00:41:28 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-01-28 17:53:46 -0500 |
commit | 227620e295090629fcb2c46ad3828222ab65438d (patch) | |
tree | 534162a74628fdfa7a8201cb776a45ca07510e5b /net/ipv6/xfrm6_mode_beet.c | |
parent | 36cf9acf93e8561d9faec24849e57688a81eb9c5 (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_beet.c')
-rw-r--r-- | net/ipv6/xfrm6_mode_beet.c | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/net/ipv6/xfrm6_mode_beet.c b/net/ipv6/xfrm6_mode_beet.c index 4988ed9c76c..0527d11c1ae 100644 --- a/net/ipv6/xfrm6_mode_beet.c +++ b/net/ipv6/xfrm6_mode_beet.c | |||
@@ -19,6 +19,20 @@ | |||
19 | #include <net/ipv6.h> | 19 | #include <net/ipv6.h> |
20 | #include <net/xfrm.h> | 20 | #include <net/xfrm.h> |
21 | 21 | ||
22 | static void xfrm6_beet_make_header(struct sk_buff *skb) | ||
23 | { | ||
24 | struct ipv6hdr *iph = ipv6_hdr(skb); | ||
25 | |||
26 | iph->version = 6; | ||
27 | |||
28 | memcpy(iph->flow_lbl, XFRM_MODE_SKB_CB(skb)->flow_lbl, | ||
29 | sizeof(iph->flow_lbl)); | ||
30 | iph->nexthdr = XFRM_MODE_SKB_CB(skb)->protocol; | ||
31 | |||
32 | ipv6_change_dsfield(iph, 0, XFRM_MODE_SKB_CB(skb)->tos); | ||
33 | iph->hop_limit = XFRM_MODE_SKB_CB(skb)->ttl; | ||
34 | } | ||
35 | |||
22 | /* Add encapsulation header. | 36 | /* Add encapsulation header. |
23 | * | 37 | * |
24 | * The top IP header will be constructed per draft-nikander-esp-beet-mode-06.txt. | 38 | * The top IP header will be constructed per draft-nikander-esp-beet-mode-06.txt. |
@@ -31,16 +45,11 @@ static int xfrm6_beet_output(struct xfrm_state *x, struct sk_buff *skb) | |||
31 | skb->mac_header = skb->network_header + | 45 | skb->mac_header = skb->network_header + |
32 | offsetof(struct ipv6hdr, nexthdr); | 46 | offsetof(struct ipv6hdr, nexthdr); |
33 | skb->transport_header = skb->network_header + sizeof(*top_iph); | 47 | skb->transport_header = skb->network_header + sizeof(*top_iph); |
34 | top_iph = ipv6_hdr(skb); | ||
35 | 48 | ||
36 | top_iph->version = 6; | 49 | xfrm6_beet_make_header(skb); |
37 | 50 | ||
38 | memcpy(top_iph->flow_lbl, XFRM_MODE_SKB_CB(skb)->flow_lbl, | 51 | top_iph = ipv6_hdr(skb); |
39 | sizeof(top_iph->flow_lbl)); | ||
40 | top_iph->nexthdr = XFRM_MODE_SKB_CB(skb)->protocol; | ||
41 | 52 | ||
42 | ipv6_change_dsfield(top_iph, 0, XFRM_MODE_SKB_CB(skb)->tos); | ||
43 | top_iph->hop_limit = XFRM_MODE_SKB_CB(skb)->ttl; | ||
44 | ipv6_addr_copy(&top_iph->saddr, (struct in6_addr *)&x->props.saddr); | 53 | ipv6_addr_copy(&top_iph->saddr, (struct in6_addr *)&x->props.saddr); |
45 | ipv6_addr_copy(&top_iph->daddr, (struct in6_addr *)&x->id.daddr); | 54 | ipv6_addr_copy(&top_iph->daddr, (struct in6_addr *)&x->id.daddr); |
46 | return 0; | 55 | return 0; |
@@ -51,19 +60,21 @@ static int xfrm6_beet_input(struct xfrm_state *x, struct sk_buff *skb) | |||
51 | struct ipv6hdr *ip6h; | 60 | struct ipv6hdr *ip6h; |
52 | const unsigned char *old_mac; | 61 | const unsigned char *old_mac; |
53 | int size = sizeof(struct ipv6hdr); | 62 | int size = sizeof(struct ipv6hdr); |
54 | int err = -EINVAL; | 63 | int err; |
55 | 64 | ||
56 | if (!pskb_may_pull(skb, sizeof(struct ipv6hdr))) | 65 | err = skb_cow_head(skb, size + skb->mac_len); |
66 | if (err) | ||
57 | goto out; | 67 | goto out; |
58 | 68 | ||
59 | skb_push(skb, size); | 69 | __skb_push(skb, size); |
60 | memmove(skb->data, skb_network_header(skb), size); | ||
61 | skb_reset_network_header(skb); | 70 | skb_reset_network_header(skb); |
62 | 71 | ||
63 | old_mac = skb_mac_header(skb); | 72 | old_mac = skb_mac_header(skb); |
64 | skb_set_mac_header(skb, -skb->mac_len); | 73 | skb_set_mac_header(skb, -skb->mac_len); |
65 | memmove(skb_mac_header(skb), old_mac, skb->mac_len); | 74 | memmove(skb_mac_header(skb), old_mac, skb->mac_len); |
66 | 75 | ||
76 | xfrm6_beet_make_header(skb); | ||
77 | |||
67 | ip6h = ipv6_hdr(skb); | 78 | ip6h = ipv6_hdr(skb); |
68 | ip6h->payload_len = htons(skb->len - size); | 79 | ip6h->payload_len = htons(skb->len - size); |
69 | ipv6_addr_copy(&ip6h->daddr, (struct in6_addr *) &x->sel.daddr.a6); | 80 | ipv6_addr_copy(&ip6h->daddr, (struct in6_addr *) &x->sel.daddr.a6); |
@@ -74,7 +85,8 @@ out: | |||
74 | } | 85 | } |
75 | 86 | ||
76 | static struct xfrm_mode xfrm6_beet_mode = { | 87 | static struct xfrm_mode xfrm6_beet_mode = { |
77 | .input = xfrm6_beet_input, | 88 | .input2 = xfrm6_beet_input, |
89 | .input = xfrm_prepare_input, | ||
78 | .output2 = xfrm6_beet_output, | 90 | .output2 = xfrm6_beet_output, |
79 | .output = xfrm6_prepare_output, | 91 | .output = xfrm6_prepare_output, |
80 | .owner = THIS_MODULE, | 92 | .owner = THIS_MODULE, |