diff options
Diffstat (limited to 'net/ipv6')
-rw-r--r-- | net/ipv6/xfrm6_input.c | 7 | ||||
-rw-r--r-- | net/ipv6/xfrm6_mode_beet.c | 36 | ||||
-rw-r--r-- | net/ipv6/xfrm6_mode_tunnel.c | 31 | ||||
-rw-r--r-- | net/ipv6/xfrm6_output.c | 1 | ||||
-rw-r--r-- | net/ipv6/xfrm6_state.c | 5 |
5 files changed, 44 insertions, 36 deletions
diff --git a/net/ipv6/xfrm6_input.c b/net/ipv6/xfrm6_input.c index 515783707e86..c458d0a2e684 100644 --- a/net/ipv6/xfrm6_input.c +++ b/net/ipv6/xfrm6_input.c | |||
@@ -16,6 +16,11 @@ | |||
16 | #include <net/ipv6.h> | 16 | #include <net/ipv6.h> |
17 | #include <net/xfrm.h> | 17 | #include <net/xfrm.h> |
18 | 18 | ||
19 | int xfrm6_extract_input(struct xfrm_state *x, struct sk_buff *skb) | ||
20 | { | ||
21 | return xfrm6_extract_header(skb); | ||
22 | } | ||
23 | |||
19 | int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi) | 24 | int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi) |
20 | { | 25 | { |
21 | int err; | 26 | int err; |
@@ -68,7 +73,7 @@ int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi) | |||
68 | 73 | ||
69 | xfrm_vec[xfrm_nr++] = x; | 74 | xfrm_vec[xfrm_nr++] = x; |
70 | 75 | ||
71 | if (x->outer_mode->input(x, skb)) | 76 | if (x->inner_mode->input(x, skb)) |
72 | goto drop; | 77 | goto drop; |
73 | 78 | ||
74 | if (x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) { | 79 | if (x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) { |
diff --git a/net/ipv6/xfrm6_mode_beet.c b/net/ipv6/xfrm6_mode_beet.c index 4988ed9c76c6..0527d11c1ae3 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, |
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 | ||
28 | static 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 | ||
105 | static struct xfrm_mode xfrm6_tunnel_mode = { | 91 | static 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, |
diff --git a/net/ipv6/xfrm6_output.c b/net/ipv6/xfrm6_output.c index bc2e80e3b0b1..c45050cfe72b 100644 --- a/net/ipv6/xfrm6_output.c +++ b/net/ipv6/xfrm6_output.c | |||
@@ -53,6 +53,7 @@ int xfrm6_extract_output(struct xfrm_state *x, struct sk_buff *skb) | |||
53 | if (err) | 53 | if (err) |
54 | return err; | 54 | return err; |
55 | 55 | ||
56 | IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr); | ||
56 | return xfrm6_extract_header(skb); | 57 | return xfrm6_extract_header(skb); |
57 | } | 58 | } |
58 | 59 | ||
diff --git a/net/ipv6/xfrm6_state.c b/net/ipv6/xfrm6_state.c index 98b05f472322..90fef0a4726f 100644 --- a/net/ipv6/xfrm6_state.c +++ b/net/ipv6/xfrm6_state.c | |||
@@ -177,7 +177,8 @@ int xfrm6_extract_header(struct sk_buff *skb) | |||
177 | XFRM_MODE_SKB_CB(skb)->frag_off = htons(IP_DF); | 177 | XFRM_MODE_SKB_CB(skb)->frag_off = htons(IP_DF); |
178 | XFRM_MODE_SKB_CB(skb)->tos = ipv6_get_dsfield(iph); | 178 | XFRM_MODE_SKB_CB(skb)->tos = ipv6_get_dsfield(iph); |
179 | XFRM_MODE_SKB_CB(skb)->ttl = iph->hop_limit; | 179 | XFRM_MODE_SKB_CB(skb)->ttl = iph->hop_limit; |
180 | XFRM_MODE_SKB_CB(skb)->protocol = iph->nexthdr; | 180 | XFRM_MODE_SKB_CB(skb)->protocol = |
181 | skb_network_header(skb)[IP6CB(skb)->nhoff]; | ||
181 | memcpy(XFRM_MODE_SKB_CB(skb)->flow_lbl, iph->flow_lbl, | 182 | memcpy(XFRM_MODE_SKB_CB(skb)->flow_lbl, iph->flow_lbl, |
182 | sizeof(XFRM_MODE_SKB_CB(skb)->flow_lbl)); | 183 | sizeof(XFRM_MODE_SKB_CB(skb)->flow_lbl)); |
183 | 184 | ||
@@ -187,11 +188,13 @@ int xfrm6_extract_header(struct sk_buff *skb) | |||
187 | static struct xfrm_state_afinfo xfrm6_state_afinfo = { | 188 | static struct xfrm_state_afinfo xfrm6_state_afinfo = { |
188 | .family = AF_INET6, | 189 | .family = AF_INET6, |
189 | .proto = IPPROTO_IPV6, | 190 | .proto = IPPROTO_IPV6, |
191 | .eth_proto = htons(ETH_P_IPV6), | ||
190 | .owner = THIS_MODULE, | 192 | .owner = THIS_MODULE, |
191 | .init_tempsel = __xfrm6_init_tempsel, | 193 | .init_tempsel = __xfrm6_init_tempsel, |
192 | .tmpl_sort = __xfrm6_tmpl_sort, | 194 | .tmpl_sort = __xfrm6_tmpl_sort, |
193 | .state_sort = __xfrm6_state_sort, | 195 | .state_sort = __xfrm6_state_sort, |
194 | .output = xfrm6_output, | 196 | .output = xfrm6_output, |
197 | .extract_input = xfrm6_extract_input, | ||
195 | .extract_output = xfrm6_extract_output, | 198 | .extract_output = xfrm6_extract_output, |
196 | }; | 199 | }; |
197 | 200 | ||