ipv4: Convert ip_route_use_hint() to dscp_t.
authorGuillaume Nault <gnault@redhat.com>
Mon, 7 Oct 2024 18:24:29 +0000 (20:24 +0200)
committerJakub Kicinski <kuba@kernel.org>
Thu, 10 Oct 2024 00:31:40 +0000 (17:31 -0700)
Pass a dscp_t variable to ip_route_use_hint(), instead of a plain u8,
to prevent accidental setting of ECN bits in ->flowi4_tos.

Only ip_rcv_finish_core() actually calls ip_route_use_hint(). Use the
ip4h_dscp() helper to get the DSCP from the IPv4 header.

While there, modify the declaration of ip_route_use_hint() in
include/net/route.h so that it matches the prototype of its
implementation in net/ipv4/route.c.

Signed-off-by: Guillaume Nault <gnault@redhat.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Tested-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Link: https://patch.msgid.link/c40994fdf804db7a363d04fdee01bf48dddda676.1728302212.git.gnault@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/route.h
net/ipv4/ip_input.c
net/ipv4/route.c

index 5e4374d66927d7b871e082fe2f01055f18950daa..c219c0fecdcf8f5d3b337eec635ca2356110b321 100644 (file)
@@ -203,8 +203,8 @@ int ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr,
                          struct in_device *in_dev, u32 *itag);
 int 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 dst, __be32 src,
-                     u8 tos, struct net_device *devin,
+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);
 
 static inline int ip_route_input(struct sk_buff *skb, __be32 dst, __be32 src,
index c0a2490eb7c1b0b21cfce3d7f6a7799b1eb4c7fb..89bb63da6852164e498bb391a0ebcdac590612b0 100644 (file)
@@ -325,8 +325,8 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk,
        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, iph->tos,
-                                       dev, hint);
+               err = ip_route_use_hint(skb, iph->daddr, iph->saddr,
+                                       ip4h_dscp(iph), dev, hint);
                if (unlikely(err))
                        goto drop_error;
        }
index 6e1cd0065b871122e959ccceee8f4e994bee260b..ac03916cfcde164d35a4c25e3e61b33e9fa9d8d4 100644 (file)
@@ -2136,7 +2136,7 @@ static int ip_mkroute_input(struct sk_buff *skb,
  * Uses the provided hint instead of performing a route lookup.
  */
 int ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
-                     u8 tos, struct net_device *dev,
+                     dscp_t dscp, struct net_device *dev,
                      const struct sk_buff *hint)
 {
        struct in_device *in_dev = __in_dev_get_rcu(dev);
@@ -2160,8 +2160,8 @@ int ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
        if (rt->rt_type != RTN_LOCAL)
                goto skip_validate_source;
 
-       tos &= INET_DSCP_MASK;
-       err = fib_validate_source(skb, saddr, daddr, tos, 0, dev, in_dev, &tag);
+       err = fib_validate_source(skb, saddr, daddr, inet_dscp_to_dsfield(dscp),
+                                 0, dev, in_dev, &tag);
        if (err < 0)
                goto martian_source;