ipv4: Convert ip_mc_validate_source() to dscp_t.
authorGuillaume Nault <gnault@redhat.com>
Mon, 7 Oct 2024 18:24:54 +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_mc_validate_source(), instead of a plain
u8, to prevent accidental setting of ECN bits in ->flowi4_tos.

Callers of ip_mc_validate_source() to consider are:

  * ip_route_input_mc() which already has a dscp_t variable to pass as
    parameter. We just need to remove the inet_dscp_to_dsfield()
    conversion.

  * udp_v4_early_demux() which gets the DSCP directly from the IPv4
    header and can simply use the ip4h_dscp() helper.

Also, stop including net/inet_dscp.h in udp.c as we don't use any of
its declarations anymore.

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/c91b2cca04718b7ee6cf5b9c1d5b40507d65a8d4.1728302212.git.gnault@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/route.h
net/ipv4/route.c
net/ipv4/udp.c

index c219c0fecdcf8f5d3b337eec635ca2356110b321..586e59f7ed8af1de74061cf81b301a86e5038435 100644 (file)
@@ -198,8 +198,9 @@ static inline struct rtable *ip_route_output_gre(struct net *net, struct flowi4
        fl4->fl4_gre_key = gre_key;
        return ip_route_output_key(net, fl4);
 }
+
 int ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr,
-                         u8 tos, struct net_device *dev,
+                         dscp_t dscp, struct net_device *dev,
                          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);
index 527121be1ba2cd8cbc80ad64f36734ea4dd243fa..1efb65e647c14354c49bffb92aa0b8ab39d761a4 100644 (file)
@@ -1666,7 +1666,7 @@ EXPORT_SYMBOL(rt_dst_clone);
 
 /* called in rcu_read_lock() section */
 int ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr,
-                         u8 tos, struct net_device *dev,
+                         dscp_t dscp, struct net_device *dev,
                          struct in_device *in_dev, u32 *itag)
 {
        int err;
@@ -1687,7 +1687,8 @@ int ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr,
                    ip_hdr(skb)->protocol != IPPROTO_IGMP)
                        return -EINVAL;
        } else {
-               err = fib_validate_source(skb, saddr, 0, tos, 0, dev,
+               err = fib_validate_source(skb, saddr, 0,
+                                         inet_dscp_to_dsfield(dscp), 0, dev,
                                          in_dev, itag);
                if (err < 0)
                        return err;
@@ -1705,8 +1706,7 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
        u32 itag = 0;
        int err;
 
-       err = ip_mc_validate_source(skb, daddr, saddr,
-                                   inet_dscp_to_dsfield(dscp), dev, in_dev,
+       err = ip_mc_validate_source(skb, daddr, saddr, dscp, dev, in_dev,
                                    &itag);
        if (err)
                return err;
index 8accbf4cb2956a7334e2b455de55404a56e016ba..4b74a25d0b6e2d38401df489e7bbfc4e269519c4 100644 (file)
 #include <net/net_namespace.h>
 #include <net/icmp.h>
 #include <net/inet_hashtables.h>
+#include <net/ip.h>
 #include <net/ip_tunnels.h>
 #include <net/route.h>
 #include <net/checksum.h>
 #include <net/addrconf.h>
 #include <net/udp_tunnel.h>
 #include <net/gro.h>
-#include <net/inet_dscp.h>
 #if IS_ENABLED(CONFIG_IPV6)
 #include <net/ipv6_stubs.h>
 #endif
@@ -2619,7 +2619,7 @@ int udp_v4_early_demux(struct sk_buff *skb)
                if (!inet_sk(sk)->inet_daddr && in_dev)
                        return ip_mc_validate_source(skb, iph->daddr,
                                                     iph->saddr,
-                                                    iph->tos & INET_DSCP_MASK,
+                                                    ip4h_dscp(iph),
                                                     skb->dev, in_dev, &itag);
        }
        return 0;