]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: ip: make ip_route_use_hint() return drop reasons
authorMenglong Dong <menglong8.dong@gmail.com>
Thu, 7 Nov 2024 12:56:01 +0000 (20:56 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 12 Nov 2024 10:24:51 +0000 (11:24 +0100)
In this commit, we make ip_route_use_hint() return drop reasons. The
drop reasons that we return are similar to what we do in
ip_route_input_slow(), and no drop reasons are added in this commit.

Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
include/net/route.h
net/ipv4/ip_input.c
net/ipv4/route.c

index fb3433dc9c7231b555afb2d140832cecde67334b..84cb1e04f5cd9c2a9d35a53ee2081042b5b8a8d0 100644 (file)
@@ -206,9 +206,10 @@ ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr,
 enum skb_drop_reason
 ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr,
                     dscp_t dscp, struct net_device *dev);
-int ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
-                     dscp_t dscp, struct net_device *dev,
-                     const struct sk_buff *hint);
+enum skb_drop_reason
+ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
+                 dscp_t dscp, struct net_device *dev,
+                 const struct sk_buff *hint);
 
 static inline enum skb_drop_reason
 ip_route_input(struct sk_buff *skb, __be32 dst, __be32 src, dscp_t dscp,
index 513eb0c6435a9910ea2933bb7c1d66db2f34be98..f0a4dda246abc9431b9abc059d64d2b5fb062f7c 100644 (file)
@@ -322,15 +322,14 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk,
        int err, drop_reason;
        struct rtable *rt;
 
-       drop_reason = SKB_DROP_REASON_NOT_SPECIFIED;
-
        if (ip_can_use_hint(skb, iph, hint)) {
-               err = ip_route_use_hint(skb, iph->daddr, iph->saddr,
-                                       ip4h_dscp(iph), dev, hint);
-               if (unlikely(err))
+               drop_reason = ip_route_use_hint(skb, iph->daddr, iph->saddr,
+                                               ip4h_dscp(iph), dev, hint);
+               if (unlikely(drop_reason))
                        goto drop_error;
        }
 
+       drop_reason = SKB_DROP_REASON_NOT_SPECIFIED;
        if (READ_ONCE(net->ipv4.sysctl_ip_early_demux) &&
            !skb_dst(skb) &&
            !skb->sk &&
index 2697a6c884163833d2539b8d628a33cb9920adf2..e5603e84b20d1af6aba887746fcca3ee4080dad4 100644 (file)
@@ -2154,28 +2154,34 @@ ip_mkroute_input(struct sk_buff *skb, struct fib_result *res,
  * assuming daddr is valid and the destination is not a local broadcast one.
  * Uses the provided hint instead of performing a route lookup.
  */
-int ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
-                     dscp_t dscp, struct net_device *dev,
-                     const struct sk_buff *hint)
+enum skb_drop_reason
+ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
+                 dscp_t dscp, struct net_device *dev,
+                 const struct sk_buff *hint)
 {
+       enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
        struct in_device *in_dev = __in_dev_get_rcu(dev);
        struct rtable *rt = skb_rtable(hint);
        struct net *net = dev_net(dev);
-       enum skb_drop_reason reason;
-       int err = -EINVAL;
        u32 tag = 0;
 
        if (!in_dev)
-               return -EINVAL;
+               return reason;
 
-       if (ipv4_is_multicast(saddr) || ipv4_is_lbcast(saddr))
+       if (ipv4_is_multicast(saddr) || ipv4_is_lbcast(saddr)) {
+               reason = SKB_DROP_REASON_IP_INVALID_SOURCE;
                goto martian_source;
+       }
 
-       if (ipv4_is_zeronet(saddr))
+       if (ipv4_is_zeronet(saddr)) {
+               reason = SKB_DROP_REASON_IP_INVALID_SOURCE;
                goto martian_source;
+       }
 
-       if (ipv4_is_loopback(saddr) && !IN_DEV_NET_ROUTE_LOCALNET(in_dev, net))
+       if (ipv4_is_loopback(saddr) && !IN_DEV_NET_ROUTE_LOCALNET(in_dev, net)) {
+               reason = SKB_DROP_REASON_IP_LOCALNET;
                goto martian_source;
+       }
 
        if (rt->rt_type != RTN_LOCAL)
                goto skip_validate_source;
@@ -2187,11 +2193,11 @@ int ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
 
 skip_validate_source:
        skb_dst_copy(skb, hint);
-       return 0;
+       return SKB_NOT_DROPPED_YET;
 
 martian_source:
        ip_handle_martian_source(dev, in_dev, skb, daddr, saddr);
-       return err;
+       return reason;
 }
 
 /* get device for dst_alloc with local routes */