@@ -2217,9 +2217,10 @@ static struct net_device *ip_rt_get_dev(struct net *net,
22172217 * called with rcu_read_lock()
22182218 */
22192219
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 )
22232224{
22242225 enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED ;
22252226 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,
22492250 fl4 .flowi4_tun_key .tun_id = 0 ;
22502251 skb_dst_drop (skb );
22512252
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 ;
22532255 goto martian_source ;
2256+ }
22542257
22552258 res -> fi = NULL ;
22562259 res -> table = NULL ;
@@ -2260,21 +2263,29 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
22602263 /* Accept zero addresses only to limited broadcast;
22612264 * I even do not know to fix it or not. Waiting for complains :-)
22622265 */
2263- if (ipv4_is_zeronet (saddr ))
2266+ if (ipv4_is_zeronet (saddr )) {
2267+ reason = SKB_DROP_REASON_IP_INVALID_SOURCE ;
22642268 goto martian_source ;
2269+ }
22652270
2266- if (ipv4_is_zeronet (daddr ))
2271+ if (ipv4_is_zeronet (daddr )) {
2272+ reason = SKB_DROP_REASON_IP_INVALID_DEST ;
22672273 goto martian_destination ;
2274+ }
22682275
22692276 /* Following code try to avoid calling IN_DEV_NET_ROUTE_LOCALNET(),
22702277 * and call it once if daddr or/and saddr are loopback addresses
22712278 */
22722279 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 ;
22742282 goto martian_destination ;
2283+ }
22752284 } 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 ;
22772287 goto martian_source ;
2288+ }
22782289 }
22792290
22802291 /*
@@ -2329,19 +2340,26 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
23292340 err = - EHOSTUNREACH ;
23302341 goto no_route ;
23312342 }
2332- if (res -> type != RTN_UNICAST )
2343+ if (res -> type != RTN_UNICAST ) {
2344+ reason = SKB_DROP_REASON_IP_INVALID_DEST ;
23332345 goto martian_destination ;
2346+ }
23342347
23352348make_route :
23362349 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 ;
23382355
23392356brd_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+ }
23422361
23432362 if (!ipv4_is_zeronet (saddr )) {
2344- err = - EINVAL ;
23452363 reason = fib_validate_source_reason (skb , saddr , 0 , dscp , 0 ,
23462364 dev , in_dev , & itag );
23472365 if (reason )
@@ -2362,7 +2380,7 @@ out: return err;
23622380 rth = rcu_dereference (nhc -> nhc_rth_input );
23632381 if (rt_cache_valid (rth )) {
23642382 skb_dst_set_noref (skb , & rth -> dst );
2365- err = 0 ;
2383+ reason = SKB_NOT_DROPPED_YET ;
23662384 goto out ;
23672385 }
23682386 }
@@ -2399,7 +2417,7 @@ out: return err;
23992417 rt_add_uncached_list (rth );
24002418 }
24012419 skb_dst_set (skb , & rth -> dst );
2402- err = 0 ;
2420+ reason = SKB_NOT_DROPPED_YET ;
24032421 goto out ;
24042422
24052423no_route :
@@ -2420,12 +2438,8 @@ out: return err;
24202438 & daddr , & saddr , dev -> name );
24212439#endif
24222440
2423- e_inval :
2424- err = - EINVAL ;
2425- goto out ;
2426-
24272441e_nobufs :
2428- err = - ENOBUFS ;
2442+ reason = SKB_DROP_REASON_NOMEM ;
24292443 goto out ;
24302444
24312445martian_source :
@@ -2482,7 +2496,7 @@ static int ip_route_input_rcu(struct sk_buff *skb, __be32 daddr, __be32 saddr,
24822496 return reason ? - EINVAL : 0 ;
24832497 }
24842498
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 ;
24862500}
24872501
24882502int ip_route_input_noref (struct sk_buff * skb , __be32 daddr , __be32 saddr ,
0 commit comments