Merge branch 'ipv4-convert-ip_route_input_slow-and-its-callers-to-dscp_t'

Guillaume Nault says:

====================
ipv4: Convert ip_route_input_slow() and its callers to dscp_t.

Prepare ip_route_input_slow() and its call chain to future conversion
of ->flowi4_tos.

The ->flowi4_tos field of "struct flowi4" is used in many different
places, which makes it hard to convert it from __u8 to dscp_t.

In order to avoid a big patch updating all its users at once, this
patch series gradually converts some users to dscp_t. Those users now
set ->flowi4_tos from a dscp_t variable that is converted to __u8 using
inet_dscp_to_dsfield().

When all users of ->flowi4_tos will use a dscp_t variable, converting
that field to dscp_t will just be a matter of removing all the
inet_dscp_to_dsfield() conversions.

This series concentrates on ip_route_input_slow() and its direct and
indirect callers.
====================

Link: https://patch.msgid.link/cover.1727807926.git.gnault@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski 2024-10-03 16:21:23 -07:00
commit 046e64f547
13 changed files with 57 additions and 43 deletions

View File

@ -2,6 +2,8 @@
/* Copyright (c) 2014 Mahesh Bandewar <maheshb@google.com> /* Copyright (c) 2014 Mahesh Bandewar <maheshb@google.com>
*/ */
#include <net/ip.h>
#include "ipvlan.h" #include "ipvlan.h"
static unsigned int ipvlan_netid __read_mostly; static unsigned int ipvlan_netid __read_mostly;
@ -48,11 +50,11 @@ static struct sk_buff *ipvlan_l3_rcv(struct net_device *dev,
switch (proto) { switch (proto) {
case AF_INET: case AF_INET:
{ {
struct iphdr *ip4h = ip_hdr(skb); const struct iphdr *ip4h = ip_hdr(skb);
int err; int err;
err = ip_route_input_noref(skb, ip4h->daddr, ip4h->saddr, err = ip_route_input_noref(skb, ip4h->daddr, ip4h->saddr,
ip4h->tos, sdev); ip4h_dscp(ip4h), sdev);
if (unlikely(err)) if (unlikely(err))
goto out; goto out;
break; break;

View File

@ -424,6 +424,11 @@ int ip_decrease_ttl(struct iphdr *iph)
return --iph->ttl; return --iph->ttl;
} }
static inline dscp_t ip4h_dscp(const struct iphdr *ip4h)
{
return inet_dsfield_to_dscp(ip4h->tos);
}
static inline int ip_mtu_locked(const struct dst_entry *dst) static inline int ip_mtu_locked(const struct dst_entry *dst)
{ {
const struct rtable *rt = dst_rtable(dst); const struct rtable *rt = dst_rtable(dst);

View File

@ -201,19 +201,19 @@ static inline struct rtable *ip_route_output_gre(struct net *net, struct flowi4
int ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr, int ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr,
u8 tos, struct net_device *dev, u8 tos, struct net_device *dev,
struct in_device *in_dev, u32 *itag); struct in_device *in_dev, u32 *itag);
int ip_route_input_noref(struct sk_buff *skb, __be32 dst, __be32 src, int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr,
u8 tos, struct net_device *devin); dscp_t dscp, struct net_device *dev);
int ip_route_use_hint(struct sk_buff *skb, __be32 dst, __be32 src, int ip_route_use_hint(struct sk_buff *skb, __be32 dst, __be32 src,
u8 tos, struct net_device *devin, u8 tos, struct net_device *devin,
const struct sk_buff *hint); const struct sk_buff *hint);
static inline int ip_route_input(struct sk_buff *skb, __be32 dst, __be32 src, static inline int ip_route_input(struct sk_buff *skb, __be32 dst, __be32 src,
u8 tos, struct net_device *devin) dscp_t dscp, struct net_device *devin)
{ {
int err; int err;
rcu_read_lock(); rcu_read_lock();
err = ip_route_input_noref(skb, dst, src, tos, devin); err = ip_route_input_noref(skb, dst, src, dscp, devin);
if (!err) { if (!err) {
skb_dst_force(skb); skb_dst_force(skb);
if (!skb_dst(skb)) if (!skb_dst(skb))

View File

@ -369,9 +369,9 @@ br_nf_ipv4_daddr_was_changed(const struct sk_buff *skb,
*/ */
static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_buff *skb) static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
{ {
struct net_device *dev = skb->dev, *br_indev;
struct iphdr *iph = ip_hdr(skb);
struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb); struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
struct net_device *dev = skb->dev, *br_indev;
const struct iphdr *iph = ip_hdr(skb);
struct rtable *rt; struct rtable *rt;
int err; int err;
@ -389,7 +389,9 @@ static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_
} }
nf_bridge->in_prerouting = 0; nf_bridge->in_prerouting = 0;
if (br_nf_ipv4_daddr_was_changed(skb, nf_bridge)) { if (br_nf_ipv4_daddr_was_changed(skb, nf_bridge)) {
if ((err = ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev))) { err = ip_route_input(skb, iph->daddr, iph->saddr,
ip4h_dscp(iph), dev);
if (err) {
struct in_device *in_dev = __in_dev_get_rcu(dev); struct in_device *in_dev = __in_dev_get_rcu(dev);
/* If err equals -EHOSTUNREACH the error is due to a /* If err equals -EHOSTUNREACH the error is due to a

View File

@ -10,6 +10,7 @@
#include <linux/bpf.h> #include <linux/bpf.h>
#include <net/lwtunnel.h> #include <net/lwtunnel.h>
#include <net/gre.h> #include <net/gre.h>
#include <net/ip.h>
#include <net/ip6_route.h> #include <net/ip6_route.h>
#include <net/ipv6_stubs.h> #include <net/ipv6_stubs.h>
#include <net/inet_dscp.h> #include <net/inet_dscp.h>
@ -91,12 +92,12 @@ static int bpf_lwt_input_reroute(struct sk_buff *skb)
if (skb->protocol == htons(ETH_P_IP)) { if (skb->protocol == htons(ETH_P_IP)) {
struct net_device *dev = skb_dst(skb)->dev; struct net_device *dev = skb_dst(skb)->dev;
struct iphdr *iph = ip_hdr(skb); const struct iphdr *iph = ip_hdr(skb);
dev_hold(dev); dev_hold(dev);
skb_dst_drop(skb); skb_dst_drop(skb);
err = ip_route_input_noref(skb, iph->daddr, iph->saddr, err = ip_route_input_noref(skb, iph->daddr, iph->saddr,
iph->tos, dev); ip4h_dscp(iph), dev);
dev_put(dev); dev_put(dev);
} else if (skb->protocol == htons(ETH_P_IPV6)) { } else if (skb->protocol == htons(ETH_P_IPV6)) {
skb_dst_drop(skb); skb_dst_drop(skb);

View File

@ -478,13 +478,11 @@ static struct net_device *icmp_get_route_lookup_dev(struct sk_buff *skb)
return route_lookup_dev; return route_lookup_dev;
} }
static struct rtable *icmp_route_lookup(struct net *net, static struct rtable *icmp_route_lookup(struct net *net, struct flowi4 *fl4,
struct flowi4 *fl4,
struct sk_buff *skb_in, struct sk_buff *skb_in,
const struct iphdr *iph, const struct iphdr *iph, __be32 saddr,
__be32 saddr, u8 tos, u32 mark, dscp_t dscp, u32 mark, int type,
int type, int code, int code, struct icmp_bxm *param)
struct icmp_bxm *param)
{ {
struct net_device *route_lookup_dev; struct net_device *route_lookup_dev;
struct dst_entry *dst, *dst2; struct dst_entry *dst, *dst2;
@ -498,7 +496,7 @@ static struct rtable *icmp_route_lookup(struct net *net,
fl4->saddr = saddr; fl4->saddr = saddr;
fl4->flowi4_mark = mark; fl4->flowi4_mark = mark;
fl4->flowi4_uid = sock_net_uid(net, NULL); fl4->flowi4_uid = sock_net_uid(net, NULL);
fl4->flowi4_tos = tos & INET_DSCP_MASK; fl4->flowi4_tos = inet_dscp_to_dsfield(dscp);
fl4->flowi4_proto = IPPROTO_ICMP; fl4->flowi4_proto = IPPROTO_ICMP;
fl4->fl4_icmp_type = type; fl4->fl4_icmp_type = type;
fl4->fl4_icmp_code = code; fl4->fl4_icmp_code = code;
@ -547,7 +545,7 @@ static struct rtable *icmp_route_lookup(struct net *net,
orefdst = skb_in->_skb_refdst; /* save old refdst */ orefdst = skb_in->_skb_refdst; /* save old refdst */
skb_dst_set(skb_in, NULL); skb_dst_set(skb_in, NULL);
err = ip_route_input(skb_in, fl4_dec.daddr, fl4_dec.saddr, err = ip_route_input(skb_in, fl4_dec.daddr, fl4_dec.saddr,
tos, rt2->dst.dev); dscp, rt2->dst.dev);
dst_release(&rt2->dst); dst_release(&rt2->dst);
rt2 = skb_rtable(skb_in); rt2 = skb_rtable(skb_in);
@ -741,8 +739,9 @@ void __icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info,
ipc.opt = &icmp_param.replyopts.opt; ipc.opt = &icmp_param.replyopts.opt;
ipc.sockc.mark = mark; ipc.sockc.mark = mark;
rt = icmp_route_lookup(net, &fl4, skb_in, iph, saddr, tos, mark, rt = icmp_route_lookup(net, &fl4, skb_in, iph, saddr,
type, code, &icmp_param); inet_dsfield_to_dscp(tos), mark, type, code,
&icmp_param);
if (IS_ERR(rt)) if (IS_ERR(rt))
goto out_unlock; goto out_unlock;

View File

@ -175,8 +175,8 @@ static void ip_expire(struct timer_list *t)
/* skb has no dst, perform route lookup again */ /* skb has no dst, perform route lookup again */
iph = ip_hdr(head); iph = ip_hdr(head);
err = ip_route_input_noref(head, iph->daddr, iph->saddr, err = ip_route_input_noref(head, iph->daddr, iph->saddr, ip4h_dscp(iph),
iph->tos, head->dev); head->dev);
if (err) if (err)
goto out; goto out;

View File

@ -363,7 +363,7 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk,
*/ */
if (!skb_valid_dst(skb)) { if (!skb_valid_dst(skb)) {
err = ip_route_input_noref(skb, iph->daddr, iph->saddr, err = ip_route_input_noref(skb, iph->daddr, iph->saddr,
iph->tos, dev); ip4h_dscp(iph), dev);
if (unlikely(err)) if (unlikely(err))
goto drop_error; goto drop_error;
} else { } else {

View File

@ -617,7 +617,8 @@ int ip_options_rcv_srr(struct sk_buff *skb, struct net_device *dev)
orefdst = skb->_skb_refdst; orefdst = skb->_skb_refdst;
skb_dst_set(skb, NULL); skb_dst_set(skb, NULL);
err = ip_route_input(skb, nexthop, iph->saddr, iph->tos, dev); err = ip_route_input(skb, nexthop, iph->saddr, ip4h_dscp(iph),
dev);
rt2 = skb_rtable(skb); rt2 = skb_rtable(skb);
if (err || (rt2->rt_type != RTN_UNICAST && rt2->rt_type != RTN_LOCAL)) { if (err || (rt2->rt_type != RTN_UNICAST && rt2->rt_type != RTN_LOCAL)) {
skb_dst_drop(skb); skb_dst_drop(skb);

View File

@ -2201,7 +2201,7 @@ static struct net_device *ip_rt_get_dev(struct net *net,
*/ */
static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr, static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
u8 tos, struct net_device *dev, dscp_t dscp, struct net_device *dev,
struct fib_result *res) struct fib_result *res)
{ {
struct in_device *in_dev = __in_dev_get_rcu(dev); struct in_device *in_dev = __in_dev_get_rcu(dev);
@ -2266,7 +2266,7 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
fl4.flowi4_oif = 0; fl4.flowi4_oif = 0;
fl4.flowi4_iif = dev->ifindex; fl4.flowi4_iif = dev->ifindex;
fl4.flowi4_mark = skb->mark; fl4.flowi4_mark = skb->mark;
fl4.flowi4_tos = tos; fl4.flowi4_tos = inet_dscp_to_dsfield(dscp);
fl4.flowi4_scope = RT_SCOPE_UNIVERSE; fl4.flowi4_scope = RT_SCOPE_UNIVERSE;
fl4.flowi4_flags = 0; fl4.flowi4_flags = 0;
fl4.daddr = daddr; fl4.daddr = daddr;
@ -2299,8 +2299,9 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
} }
if (res->type == RTN_LOCAL) { if (res->type == RTN_LOCAL) {
err = fib_validate_source(skb, saddr, daddr, tos, err = fib_validate_source(skb, saddr, daddr,
0, dev, in_dev, &itag); inet_dscp_to_dsfield(dscp), 0, dev,
in_dev, &itag);
if (err < 0) if (err < 0)
goto martian_source; goto martian_source;
goto local_input; goto local_input;
@ -2314,7 +2315,8 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
goto martian_destination; goto martian_destination;
make_route: make_route:
err = ip_mkroute_input(skb, res, in_dev, daddr, saddr, tos, flkeys); err = ip_mkroute_input(skb, res, in_dev, daddr, saddr,
inet_dscp_to_dsfield(dscp), flkeys);
out: return err; out: return err;
brd_input: brd_input:
@ -2322,7 +2324,8 @@ out: return err;
goto e_inval; goto e_inval;
if (!ipv4_is_zeronet(saddr)) { if (!ipv4_is_zeronet(saddr)) {
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); in_dev, &itag);
if (err < 0) if (err < 0)
goto martian_source; goto martian_source;
@ -2415,7 +2418,8 @@ out: return err;
/* called with rcu_read_lock held */ /* called with rcu_read_lock held */
static int ip_route_input_rcu(struct sk_buff *skb, __be32 daddr, __be32 saddr, static int ip_route_input_rcu(struct sk_buff *skb, __be32 daddr, __be32 saddr,
u8 tos, struct net_device *dev, struct fib_result *res) dscp_t dscp, struct net_device *dev,
struct fib_result *res)
{ {
/* Multicast recognition logic is moved from route cache to here. /* Multicast recognition logic is moved from route cache to here.
* The problem was that too many Ethernet cards have broken/missing * The problem was that too many Ethernet cards have broken/missing
@ -2456,23 +2460,23 @@ static int ip_route_input_rcu(struct sk_buff *skb, __be32 daddr, __be32 saddr,
#endif #endif
) { ) {
err = ip_route_input_mc(skb, daddr, saddr, err = ip_route_input_mc(skb, daddr, saddr,
tos, dev, our); inet_dscp_to_dsfield(dscp),
dev, our);
} }
return err; return err;
} }
return ip_route_input_slow(skb, daddr, saddr, tos, dev, res); return ip_route_input_slow(skb, daddr, saddr, dscp, dev, res);
} }
int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr, int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr,
u8 tos, struct net_device *dev) dscp_t dscp, struct net_device *dev)
{ {
struct fib_result res; struct fib_result res;
int err; int err;
tos &= INET_DSCP_MASK;
rcu_read_lock(); rcu_read_lock();
err = ip_route_input_rcu(skb, daddr, saddr, tos, dev, &res); err = ip_route_input_rcu(skb, daddr, saddr, dscp, dev, &res);
rcu_read_unlock(); rcu_read_unlock();
return err; return err;
@ -3286,8 +3290,8 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
skb->dev = dev; skb->dev = dev;
skb->mark = mark; skb->mark = mark;
err = ip_route_input_rcu(skb, dst, src, err = ip_route_input_rcu(skb, dst, src,
rtm->rtm_tos & INET_DSCP_MASK, dev, inet_dsfield_to_dscp(rtm->rtm_tos),
&res); dev, &res);
rt = skb_rtable(skb); rt = skb_rtable(skb);
if (err == 0 && rt->dst.error) if (err == 0 && rt->dst.error)

View File

@ -33,7 +33,7 @@ static inline int xfrm4_rcv_encap_finish(struct net *net, struct sock *sk,
const struct iphdr *iph = ip_hdr(skb); const struct iphdr *iph = ip_hdr(skb);
if (ip_route_input_noref(skb, iph->daddr, iph->saddr, if (ip_route_input_noref(skb, iph->daddr, iph->saddr,
iph->tos, skb->dev)) ip4h_dscp(iph), skb->dev))
goto drop; goto drop;
} }

View File

@ -76,7 +76,7 @@ int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
const struct iphdr *iph = ip_hdr(skb); const struct iphdr *iph = ip_hdr(skb);
if (ip_route_input_noref(skb, iph->daddr, iph->saddr, if (ip_route_input_noref(skb, iph->daddr, iph->saddr,
iph->tos, skb->dev)) ip4h_dscp(iph), skb->dev))
goto drop; goto drop;
} }

View File

@ -630,8 +630,8 @@ ip4ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
} }
skb_dst_set(skb2, &rt->dst); skb_dst_set(skb2, &rt->dst);
} else { } else {
if (ip_route_input(skb2, eiph->daddr, eiph->saddr, eiph->tos, if (ip_route_input(skb2, eiph->daddr, eiph->saddr,
skb2->dev) || ip4h_dscp(eiph), skb2->dev) ||
skb_dst(skb2)->dev->type != ARPHRD_TUNNEL6) skb_dst(skb2)->dev->type != ARPHRD_TUNNEL6)
goto out; goto out;
} }