diff options
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, |