diff options
Diffstat (limited to 'net/ipv6/xfrm6_mode_tunnel.c')
-rw-r--r-- | net/ipv6/xfrm6_mode_tunnel.c | 73 |
1 files changed, 25 insertions, 48 deletions
diff --git a/net/ipv6/xfrm6_mode_tunnel.c b/net/ipv6/xfrm6_mode_tunnel.c index fd84e2217274..0c742faaa30b 100644 --- a/net/ipv6/xfrm6_mode_tunnel.c +++ b/net/ipv6/xfrm6_mode_tunnel.c | |||
@@ -25,46 +25,29 @@ 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. |
37 | */ | 31 | */ |
38 | static int xfrm6_tunnel_output(struct xfrm_state *x, struct sk_buff *skb) | 32 | static int xfrm6_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb) |
39 | { | 33 | { |
40 | struct dst_entry *dst = skb->dst; | 34 | struct dst_entry *dst = skb->dst; |
41 | struct xfrm_dst *xdst = (struct xfrm_dst*)dst; | 35 | struct ipv6hdr *top_iph; |
42 | struct ipv6hdr *iph, *top_iph; | ||
43 | int dsfield; | 36 | int dsfield; |
44 | 37 | ||
45 | iph = ipv6_hdr(skb); | ||
46 | |||
47 | skb_set_network_header(skb, -x->props.header_len); | 38 | skb_set_network_header(skb, -x->props.header_len); |
48 | skb->mac_header = skb->network_header + | 39 | skb->mac_header = skb->network_header + |
49 | offsetof(struct ipv6hdr, nexthdr); | 40 | offsetof(struct ipv6hdr, nexthdr); |
50 | skb->transport_header = skb->network_header + sizeof(*iph); | 41 | skb->transport_header = skb->network_header + sizeof(*top_iph); |
51 | top_iph = ipv6_hdr(skb); | 42 | top_iph = ipv6_hdr(skb); |
52 | 43 | ||
53 | top_iph->version = 6; | 44 | top_iph->version = 6; |
54 | if (xdst->route->ops->family == AF_INET6) { | 45 | |
55 | top_iph->priority = iph->priority; | 46 | memcpy(top_iph->flow_lbl, XFRM_MODE_SKB_CB(skb)->flow_lbl, |
56 | top_iph->flow_lbl[0] = iph->flow_lbl[0]; | 47 | sizeof(top_iph->flow_lbl)); |
57 | top_iph->flow_lbl[1] = iph->flow_lbl[1]; | 48 | top_iph->nexthdr = x->inner_mode->afinfo->proto; |
58 | top_iph->flow_lbl[2] = iph->flow_lbl[2]; | 49 | |
59 | top_iph->nexthdr = IPPROTO_IPV6; | 50 | dsfield = XFRM_MODE_SKB_CB(skb)->tos; |
60 | } else { | ||
61 | top_iph->priority = 0; | ||
62 | top_iph->flow_lbl[0] = 0; | ||
63 | top_iph->flow_lbl[1] = 0; | ||
64 | top_iph->flow_lbl[2] = 0; | ||
65 | top_iph->nexthdr = IPPROTO_IPIP; | ||
66 | } | ||
67 | dsfield = ipv6_get_dsfield(top_iph); | ||
68 | dsfield = INET_ECN_encapsulate(dsfield, dsfield); | 51 | dsfield = INET_ECN_encapsulate(dsfield, dsfield); |
69 | if (x->props.flags & XFRM_STATE_NOECN) | 52 | if (x->props.flags & XFRM_STATE_NOECN) |
70 | dsfield &= ~INET_ECN_MASK; | 53 | dsfield &= ~INET_ECN_MASK; |
@@ -72,18 +55,15 @@ static int xfrm6_tunnel_output(struct xfrm_state *x, struct sk_buff *skb) | |||
72 | top_iph->hop_limit = dst_metric(dst->child, RTAX_HOPLIMIT); | 55 | top_iph->hop_limit = dst_metric(dst->child, RTAX_HOPLIMIT); |
73 | ipv6_addr_copy(&top_iph->saddr, (struct in6_addr *)&x->props.saddr); | 56 | ipv6_addr_copy(&top_iph->saddr, (struct in6_addr *)&x->props.saddr); |
74 | ipv6_addr_copy(&top_iph->daddr, (struct in6_addr *)&x->id.daddr); | 57 | ipv6_addr_copy(&top_iph->daddr, (struct in6_addr *)&x->id.daddr); |
75 | skb->protocol = htons(ETH_P_IPV6); | ||
76 | return 0; | 58 | return 0; |
77 | } | 59 | } |
78 | 60 | ||
79 | static int xfrm6_tunnel_input(struct xfrm_state *x, struct sk_buff *skb) | 61 | static int xfrm6_mode_tunnel_input(struct xfrm_state *x, struct sk_buff *skb) |
80 | { | 62 | { |
81 | int err = -EINVAL; | 63 | int err = -EINVAL; |
82 | const unsigned char *old_mac; | 64 | const unsigned char *old_mac; |
83 | const unsigned char *nh = skb_network_header(skb); | ||
84 | 65 | ||
85 | if (nh[IP6CB(skb)->nhoff] != IPPROTO_IPV6 && | 66 | if (XFRM_MODE_SKB_CB(skb)->protocol != IPPROTO_IPV6) |
86 | nh[IP6CB(skb)->nhoff] != IPPROTO_IPIP) | ||
87 | goto out; | 67 | goto out; |
88 | if (!pskb_may_pull(skb, sizeof(struct ipv6hdr))) | 68 | if (!pskb_may_pull(skb, sizeof(struct ipv6hdr))) |
89 | goto out; | 69 | goto out; |
@@ -92,17 +72,12 @@ static int xfrm6_tunnel_input(struct xfrm_state *x, struct sk_buff *skb) | |||
92 | (err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC))) | 72 | (err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC))) |
93 | goto out; | 73 | goto out; |
94 | 74 | ||
95 | nh = skb_network_header(skb); | 75 | if (x->props.flags & XFRM_STATE_DECAP_DSCP) |
96 | if (nh[IP6CB(skb)->nhoff] == IPPROTO_IPV6) { | 76 | ipv6_copy_dscp(ipv6_get_dsfield(ipv6_hdr(skb)), |
97 | if (x->props.flags & XFRM_STATE_DECAP_DSCP) | 77 | ipipv6_hdr(skb)); |
98 | ipv6_copy_dscp(ipv6_hdr(skb), ipipv6_hdr(skb)); | 78 | if (!(x->props.flags & XFRM_STATE_NOECN)) |
99 | if (!(x->props.flags & XFRM_STATE_NOECN)) | 79 | ipip6_ecn_decapsulate(skb); |
100 | ipip6_ecn_decapsulate(skb); | 80 | |
101 | } else { | ||
102 | if (!(x->props.flags & XFRM_STATE_NOECN)) | ||
103 | ip6ip_ecn_decapsulate(skb); | ||
104 | skb->protocol = htons(ETH_P_IP); | ||
105 | } | ||
106 | old_mac = skb_mac_header(skb); | 81 | old_mac = skb_mac_header(skb); |
107 | skb_set_mac_header(skb, -skb->mac_len); | 82 | skb_set_mac_header(skb, -skb->mac_len); |
108 | memmove(skb_mac_header(skb), old_mac, skb->mac_len); | 83 | memmove(skb_mac_header(skb), old_mac, skb->mac_len); |
@@ -114,19 +89,21 @@ out: | |||
114 | } | 89 | } |
115 | 90 | ||
116 | static struct xfrm_mode xfrm6_tunnel_mode = { | 91 | static struct xfrm_mode xfrm6_tunnel_mode = { |
117 | .input = xfrm6_tunnel_input, | 92 | .input2 = xfrm6_mode_tunnel_input, |
118 | .output = xfrm6_tunnel_output, | 93 | .input = xfrm_prepare_input, |
94 | .output2 = xfrm6_mode_tunnel_output, | ||
95 | .output = xfrm6_prepare_output, | ||
119 | .owner = THIS_MODULE, | 96 | .owner = THIS_MODULE, |
120 | .encap = XFRM_MODE_TUNNEL, | 97 | .encap = XFRM_MODE_TUNNEL, |
121 | .flags = XFRM_MODE_FLAG_TUNNEL, | 98 | .flags = XFRM_MODE_FLAG_TUNNEL, |
122 | }; | 99 | }; |
123 | 100 | ||
124 | static int __init xfrm6_tunnel_init(void) | 101 | static int __init xfrm6_mode_tunnel_init(void) |
125 | { | 102 | { |
126 | return xfrm_register_mode(&xfrm6_tunnel_mode, AF_INET6); | 103 | return xfrm_register_mode(&xfrm6_tunnel_mode, AF_INET6); |
127 | } | 104 | } |
128 | 105 | ||
129 | static void __exit xfrm6_tunnel_exit(void) | 106 | static void __exit xfrm6_mode_tunnel_exit(void) |
130 | { | 107 | { |
131 | int err; | 108 | int err; |
132 | 109 | ||
@@ -134,7 +111,7 @@ static void __exit xfrm6_tunnel_exit(void) | |||
134 | BUG_ON(err); | 111 | BUG_ON(err); |
135 | } | 112 | } |
136 | 113 | ||
137 | module_init(xfrm6_tunnel_init); | 114 | module_init(xfrm6_mode_tunnel_init); |
138 | module_exit(xfrm6_tunnel_exit); | 115 | module_exit(xfrm6_mode_tunnel_exit); |
139 | MODULE_LICENSE("GPL"); | 116 | MODULE_LICENSE("GPL"); |
140 | MODULE_ALIAS_XFRM_MODE(AF_INET6, XFRM_MODE_TUNNEL); | 117 | MODULE_ALIAS_XFRM_MODE(AF_INET6, XFRM_MODE_TUNNEL); |