@@ -122,125 +122,6 @@ static int ipgre_tunnel_init(struct net_device *dev);
122
122
static int ipgre_net_id __read_mostly ;
123
123
static int gre_tap_net_id __read_mostly ;
124
124
125
- static int ip_gre_calc_hlen (__be16 o_flags )
126
- {
127
- int addend = 4 ;
128
-
129
- if (o_flags & TUNNEL_CSUM )
130
- addend += 4 ;
131
- if (o_flags & TUNNEL_KEY )
132
- addend += 4 ;
133
- if (o_flags & TUNNEL_SEQ )
134
- addend += 4 ;
135
- return addend ;
136
- }
137
-
138
- static __be16 gre_flags_to_tnl_flags (__be16 flags )
139
- {
140
- __be16 tflags = 0 ;
141
-
142
- if (flags & GRE_CSUM )
143
- tflags |= TUNNEL_CSUM ;
144
- if (flags & GRE_ROUTING )
145
- tflags |= TUNNEL_ROUTING ;
146
- if (flags & GRE_KEY )
147
- tflags |= TUNNEL_KEY ;
148
- if (flags & GRE_SEQ )
149
- tflags |= TUNNEL_SEQ ;
150
- if (flags & GRE_STRICT )
151
- tflags |= TUNNEL_STRICT ;
152
- if (flags & GRE_REC )
153
- tflags |= TUNNEL_REC ;
154
- if (flags & GRE_VERSION )
155
- tflags |= TUNNEL_VERSION ;
156
-
157
- return tflags ;
158
- }
159
-
160
- static __be16 tnl_flags_to_gre_flags (__be16 tflags )
161
- {
162
- __be16 flags = 0 ;
163
-
164
- if (tflags & TUNNEL_CSUM )
165
- flags |= GRE_CSUM ;
166
- if (tflags & TUNNEL_ROUTING )
167
- flags |= GRE_ROUTING ;
168
- if (tflags & TUNNEL_KEY )
169
- flags |= GRE_KEY ;
170
- if (tflags & TUNNEL_SEQ )
171
- flags |= GRE_SEQ ;
172
- if (tflags & TUNNEL_STRICT )
173
- flags |= GRE_STRICT ;
174
- if (tflags & TUNNEL_REC )
175
- flags |= GRE_REC ;
176
- if (tflags & TUNNEL_VERSION )
177
- flags |= GRE_VERSION ;
178
-
179
- return flags ;
180
- }
181
-
182
- static int parse_gre_header (struct sk_buff * skb , struct tnl_ptk_info * tpi ,
183
- bool * csum_err )
184
- {
185
- const struct gre_base_hdr * greh ;
186
- __be32 * options ;
187
- int hdr_len ;
188
-
189
- if (unlikely (!pskb_may_pull (skb , sizeof (struct gre_base_hdr ))))
190
- return - EINVAL ;
191
-
192
- greh = (struct gre_base_hdr * )skb_transport_header (skb );
193
- if (unlikely (greh -> flags & (GRE_VERSION | GRE_ROUTING )))
194
- return - EINVAL ;
195
-
196
- tpi -> flags = gre_flags_to_tnl_flags (greh -> flags );
197
- hdr_len = ip_gre_calc_hlen (tpi -> flags );
198
-
199
- if (!pskb_may_pull (skb , hdr_len ))
200
- return - EINVAL ;
201
-
202
- greh = (struct gre_base_hdr * )skb_transport_header (skb );
203
- tpi -> proto = greh -> protocol ;
204
-
205
- options = (__be32 * )(greh + 1 );
206
- if (greh -> flags & GRE_CSUM ) {
207
- if (skb_checksum_simple_validate (skb )) {
208
- * csum_err = true;
209
- return - EINVAL ;
210
- }
211
-
212
- skb_checksum_try_convert (skb , IPPROTO_GRE , 0 ,
213
- null_compute_pseudo );
214
- options ++ ;
215
- }
216
-
217
- if (greh -> flags & GRE_KEY ) {
218
- tpi -> key = * options ;
219
- options ++ ;
220
- } else {
221
- tpi -> key = 0 ;
222
- }
223
- if (unlikely (greh -> flags & GRE_SEQ )) {
224
- tpi -> seq = * options ;
225
- options ++ ;
226
- } else {
227
- tpi -> seq = 0 ;
228
- }
229
- /* WCCP version 1 and 2 protocol decoding.
230
- * - Change protocol to IP
231
- * - When dealing with WCCPv2, Skip extra 4 bytes in GRE header
232
- */
233
- if (greh -> flags == 0 && tpi -> proto == htons (ETH_P_WCCP )) {
234
- tpi -> proto = htons (ETH_P_IP );
235
- if ((* (u8 * )options & 0xF0 ) != 0x40 ) {
236
- hdr_len += 4 ;
237
- if (!pskb_may_pull (skb , hdr_len ))
238
- return - EINVAL ;
239
- }
240
- }
241
- return iptunnel_pull_header (skb , hdr_len , tpi -> proto , false);
242
- }
243
-
244
125
static void ipgre_err (struct sk_buff * skb , u32 info ,
245
126
const struct tnl_ptk_info * tpi )
246
127
{
@@ -340,12 +221,16 @@ static void gre_err(struct sk_buff *skb, u32 info)
340
221
const int code = icmp_hdr (skb )-> code ;
341
222
struct tnl_ptk_info tpi ;
342
223
bool csum_err = false;
224
+ int hdr_len ;
343
225
344
- if (parse_gre_header (skb , & tpi , & csum_err )) {
226
+ if (gre_parse_header (skb , & tpi , & csum_err , & hdr_len )) {
345
227
if (!csum_err ) /* ignore csum errors. */
346
228
return ;
347
229
}
348
230
231
+ if (iptunnel_pull_header (skb , hdr_len , tpi .proto , false))
232
+ return ;
233
+
349
234
if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED ) {
350
235
ipv4_update_pmtu (skb , dev_net (skb -> dev ), info ,
351
236
skb -> dev -> ifindex , 0 , IPPROTO_GRE , 0 );
@@ -419,6 +304,7 @@ static int gre_rcv(struct sk_buff *skb)
419
304
{
420
305
struct tnl_ptk_info tpi ;
421
306
bool csum_err = false;
307
+ int hdr_len ;
422
308
423
309
#ifdef CONFIG_NET_IPGRE_BROADCAST
424
310
if (ipv4_is_multicast (ip_hdr (skb )-> daddr )) {
@@ -428,7 +314,10 @@ static int gre_rcv(struct sk_buff *skb)
428
314
}
429
315
#endif
430
316
431
- if (parse_gre_header (skb , & tpi , & csum_err ) < 0 )
317
+ if (gre_parse_header (skb , & tpi , & csum_err , & hdr_len ) < 0 )
318
+ goto drop ;
319
+
320
+ if (iptunnel_pull_header (skb , hdr_len , tpi .proto , false))
432
321
goto drop ;
433
322
434
323
if (ipgre_rcv (skb , & tpi ) == PACKET_RCVD )
@@ -460,7 +349,7 @@ static void build_header(struct sk_buff *skb, int hdr_len, __be16 flags,
460
349
461
350
skb_reset_transport_header (skb );
462
351
greh = (struct gre_base_hdr * )skb -> data ;
463
- greh -> flags = tnl_flags_to_gre_flags (flags );
352
+ greh -> flags = gre_tnl_flags_to_gre_flags (flags );
464
353
greh -> protocol = proto ;
465
354
466
355
if (flags & (TUNNEL_KEY | TUNNEL_CSUM | TUNNEL_SEQ )) {
@@ -552,7 +441,7 @@ static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev)
552
441
fl .saddr );
553
442
}
554
443
555
- tunnel_hlen = ip_gre_calc_hlen (key -> tun_flags );
444
+ tunnel_hlen = gre_calc_hlen (key -> tun_flags );
556
445
557
446
min_headroom = LL_RESERVED_SPACE (rt -> dst .dev ) + rt -> dst .header_len
558
447
+ tunnel_hlen + sizeof (struct iphdr );
@@ -694,8 +583,8 @@ static int ipgre_tunnel_ioctl(struct net_device *dev,
694
583
if (err )
695
584
return err ;
696
585
697
- p .i_flags = tnl_flags_to_gre_flags (p .i_flags );
698
- p .o_flags = tnl_flags_to_gre_flags (p .o_flags );
586
+ p .i_flags = gre_tnl_flags_to_gre_flags (p .i_flags );
587
+ p .o_flags = gre_tnl_flags_to_gre_flags (p .o_flags );
699
588
700
589
if (copy_to_user (ifr -> ifr_ifru .ifru_data , & p , sizeof (p )))
701
590
return - EFAULT ;
@@ -739,7 +628,7 @@ static int ipgre_header(struct sk_buff *skb, struct net_device *dev,
739
628
740
629
iph = (struct iphdr * )skb_push (skb , t -> hlen + sizeof (* iph ));
741
630
greh = (struct gre_base_hdr * )(iph + 1 );
742
- greh -> flags = tnl_flags_to_gre_flags (t -> parms .o_flags );
631
+ greh -> flags = gre_tnl_flags_to_gre_flags (t -> parms .o_flags );
743
632
greh -> protocol = htons (type );
744
633
745
634
memcpy (iph , & t -> parms .iph , sizeof (struct iphdr ));
@@ -840,7 +729,7 @@ static void __gre_tunnel_init(struct net_device *dev)
840
729
int t_hlen ;
841
730
842
731
tunnel = netdev_priv (dev );
843
- tunnel -> tun_hlen = ip_gre_calc_hlen (tunnel -> parms .o_flags );
732
+ tunnel -> tun_hlen = gre_calc_hlen (tunnel -> parms .o_flags );
844
733
tunnel -> parms .iph .protocol = IPPROTO_GRE ;
845
734
846
735
tunnel -> hlen = tunnel -> tun_hlen + tunnel -> encap_hlen ;
@@ -1155,8 +1044,10 @@ static int ipgre_fill_info(struct sk_buff *skb, const struct net_device *dev)
1155
1044
struct ip_tunnel_parm * p = & t -> parms ;
1156
1045
1157
1046
if (nla_put_u32 (skb , IFLA_GRE_LINK , p -> link ) ||
1158
- nla_put_be16 (skb , IFLA_GRE_IFLAGS , tnl_flags_to_gre_flags (p -> i_flags )) ||
1159
- nla_put_be16 (skb , IFLA_GRE_OFLAGS , tnl_flags_to_gre_flags (p -> o_flags )) ||
1047
+ nla_put_be16 (skb , IFLA_GRE_IFLAGS ,
1048
+ gre_tnl_flags_to_gre_flags (p -> i_flags )) ||
1049
+ nla_put_be16 (skb , IFLA_GRE_OFLAGS ,
1050
+ gre_tnl_flags_to_gre_flags (p -> o_flags )) ||
1160
1051
nla_put_be32 (skb , IFLA_GRE_IKEY , p -> i_key ) ||
1161
1052
nla_put_be32 (skb , IFLA_GRE_OKEY , p -> o_key ) ||
1162
1053
nla_put_in_addr (skb , IFLA_GRE_LOCAL , p -> iph .saddr ) ||
0 commit comments