@@ -2217,9 +2217,10 @@ static struct net_device *ip_rt_get_dev(struct net *net,
2217
2217
* called with rcu_read_lock()
2218
2218
*/
2219
2219
2220
- static int ip_route_input_slow (struct sk_buff * skb , __be32 daddr , __be32 saddr ,
2221
- dscp_t dscp , struct net_device * dev ,
2222
- struct fib_result * res )
2220
+ static enum skb_drop_reason
2221
+ ip_route_input_slow (struct sk_buff * skb , __be32 daddr , __be32 saddr ,
2222
+ dscp_t dscp , struct net_device * dev ,
2223
+ struct fib_result * res )
2223
2224
{
2224
2225
enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED ;
2225
2226
struct in_device * in_dev = __in_dev_get_rcu (dev );
@@ -2249,8 +2250,10 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
2249
2250
fl4 .flowi4_tun_key .tun_id = 0 ;
2250
2251
skb_dst_drop (skb );
2251
2252
2252
- if (ipv4_is_multicast (saddr ) || ipv4_is_lbcast (saddr ))
2253
+ if (ipv4_is_multicast (saddr ) || ipv4_is_lbcast (saddr )) {
2254
+ reason = SKB_DROP_REASON_IP_INVALID_SOURCE ;
2253
2255
goto martian_source ;
2256
+ }
2254
2257
2255
2258
res -> fi = NULL ;
2256
2259
res -> table = NULL ;
@@ -2260,21 +2263,29 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
2260
2263
/* Accept zero addresses only to limited broadcast;
2261
2264
* I even do not know to fix it or not. Waiting for complains :-)
2262
2265
*/
2263
- if (ipv4_is_zeronet (saddr ))
2266
+ if (ipv4_is_zeronet (saddr )) {
2267
+ reason = SKB_DROP_REASON_IP_INVALID_SOURCE ;
2264
2268
goto martian_source ;
2269
+ }
2265
2270
2266
- if (ipv4_is_zeronet (daddr ))
2271
+ if (ipv4_is_zeronet (daddr )) {
2272
+ reason = SKB_DROP_REASON_IP_INVALID_DEST ;
2267
2273
goto martian_destination ;
2274
+ }
2268
2275
2269
2276
/* Following code try to avoid calling IN_DEV_NET_ROUTE_LOCALNET(),
2270
2277
* and call it once if daddr or/and saddr are loopback addresses
2271
2278
*/
2272
2279
if (ipv4_is_loopback (daddr )) {
2273
- if (!IN_DEV_NET_ROUTE_LOCALNET (in_dev , net ))
2280
+ if (!IN_DEV_NET_ROUTE_LOCALNET (in_dev , net )) {
2281
+ reason = SKB_DROP_REASON_IP_LOCALNET ;
2274
2282
goto martian_destination ;
2283
+ }
2275
2284
} else if (ipv4_is_loopback (saddr )) {
2276
- if (!IN_DEV_NET_ROUTE_LOCALNET (in_dev , net ))
2285
+ if (!IN_DEV_NET_ROUTE_LOCALNET (in_dev , net )) {
2286
+ reason = SKB_DROP_REASON_IP_LOCALNET ;
2277
2287
goto martian_source ;
2288
+ }
2278
2289
}
2279
2290
2280
2291
/*
@@ -2329,19 +2340,26 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
2329
2340
err = - EHOSTUNREACH ;
2330
2341
goto no_route ;
2331
2342
}
2332
- if (res -> type != RTN_UNICAST )
2343
+ if (res -> type != RTN_UNICAST ) {
2344
+ reason = SKB_DROP_REASON_IP_INVALID_DEST ;
2333
2345
goto martian_destination ;
2346
+ }
2334
2347
2335
2348
make_route :
2336
2349
err = ip_mkroute_input (skb , res , in_dev , daddr , saddr , dscp , flkeys );
2337
- out : return err ;
2350
+ if (!err )
2351
+ reason = SKB_NOT_DROPPED_YET ;
2352
+
2353
+ out :
2354
+ return reason ;
2338
2355
2339
2356
brd_input :
2340
- if (skb -> protocol != htons (ETH_P_IP ))
2341
- goto e_inval ;
2357
+ if (skb -> protocol != htons (ETH_P_IP )) {
2358
+ reason = SKB_DROP_REASON_INVALID_PROTO ;
2359
+ goto out ;
2360
+ }
2342
2361
2343
2362
if (!ipv4_is_zeronet (saddr )) {
2344
- err = - EINVAL ;
2345
2363
reason = fib_validate_source_reason (skb , saddr , 0 , dscp , 0 ,
2346
2364
dev , in_dev , & itag );
2347
2365
if (reason )
@@ -2362,7 +2380,7 @@ out: return err;
2362
2380
rth = rcu_dereference (nhc -> nhc_rth_input );
2363
2381
if (rt_cache_valid (rth )) {
2364
2382
skb_dst_set_noref (skb , & rth -> dst );
2365
- err = 0 ;
2383
+ reason = SKB_NOT_DROPPED_YET ;
2366
2384
goto out ;
2367
2385
}
2368
2386
}
@@ -2399,7 +2417,7 @@ out: return err;
2399
2417
rt_add_uncached_list (rth );
2400
2418
}
2401
2419
skb_dst_set (skb , & rth -> dst );
2402
- err = 0 ;
2420
+ reason = SKB_NOT_DROPPED_YET ;
2403
2421
goto out ;
2404
2422
2405
2423
no_route :
@@ -2420,12 +2438,8 @@ out: return err;
2420
2438
& daddr , & saddr , dev -> name );
2421
2439
#endif
2422
2440
2423
- e_inval :
2424
- err = - EINVAL ;
2425
- goto out ;
2426
-
2427
2441
e_nobufs :
2428
- err = - ENOBUFS ;
2442
+ reason = SKB_DROP_REASON_NOMEM ;
2429
2443
goto out ;
2430
2444
2431
2445
martian_source :
@@ -2482,7 +2496,7 @@ static int ip_route_input_rcu(struct sk_buff *skb, __be32 daddr, __be32 saddr,
2482
2496
return reason ? - EINVAL : 0 ;
2483
2497
}
2484
2498
2485
- return ip_route_input_slow (skb , daddr , saddr , dscp , dev , res );
2499
+ return ip_route_input_slow (skb , daddr , saddr , dscp , dev , res ) ? - EINVAL : 0 ;
2486
2500
}
2487
2501
2488
2502
int ip_route_input_noref (struct sk_buff * skb , __be32 daddr , __be32 saddr ,
0 commit comments