Skip to content

Commit bfc52de

Browse files
committed
Merge branch 'unmask-upper-dscp-bits-part-1'
Ido Schimmel says: ==================== Unmask upper DSCP bits - part 1 tl;dr - This patchset starts to unmask the upper DSCP bits in the IPv4 flow key in preparation for allowing IPv4 FIB rules to match on DSCP. No functional changes are expected. The TOS field in the IPv4 flow key ('flowi4_tos') is used during FIB lookup to match against the TOS selector in FIB rules and routes. It is currently impossible for user space to configure FIB rules that match on the DSCP value as the upper DSCP bits are either masked in the various call sites that initialize the IPv4 flow key or along the path to the FIB core. In preparation for adding a DSCP selector to IPv4 and IPv6 FIB rules, we need to make sure the entire DSCP value is present in the IPv4 flow key. This patchset starts to unmask the upper DSCP bits in the various places that invoke the core FIB lookup functions directly (patches #1-#7) and in the input route path (patches #8-#12). Future patchsets will do the same in the output route path. No functional changes are expected as commit 1fa3314 ("ipv4: Centralize TOS matching") moved the masking of the upper DSCP bits to the core where 'flowi4_tos' is matched against the TOS selector. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 1cf60c6 + be8b8de commit bfc52de

File tree

8 files changed

+17
-12
lines changed

8 files changed

+17
-12
lines changed

net/core/filter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
#include <net/netkit.h>
8585
#include <linux/un.h>
8686
#include <net/xdp_sock_drv.h>
87+
#include <net/inet_dscp.h>
8788

8889
#include "dev.h"
8990

@@ -5899,7 +5900,7 @@ static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
58995900
fl4.flowi4_iif = params->ifindex;
59005901
fl4.flowi4_oif = 0;
59015902
}
5902-
fl4.flowi4_tos = params->tos & IPTOS_RT_MASK;
5903+
fl4.flowi4_tos = params->tos & INET_DSCP_MASK;
59035904
fl4.flowi4_scope = RT_SCOPE_UNIVERSE;
59045905
fl4.flowi4_flags = 0;
59055906

net/ipv4/fib_frontend.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ __be32 fib_compute_spec_dst(struct sk_buff *skb)
293293
.flowi4_iif = LOOPBACK_IFINDEX,
294294
.flowi4_l3mdev = l3mdev_master_ifindex_rcu(dev),
295295
.daddr = ip_hdr(skb)->saddr,
296-
.flowi4_tos = ip_hdr(skb)->tos & IPTOS_RT_MASK,
296+
.flowi4_tos = ip_hdr(skb)->tos & INET_DSCP_MASK,
297297
.flowi4_scope = scope,
298298
.flowi4_mark = vmark ? skb->mark : 0,
299299
};
@@ -1343,7 +1343,7 @@ static void nl_fib_lookup(struct net *net, struct fib_result_nl *frn)
13431343
struct flowi4 fl4 = {
13441344
.flowi4_mark = frn->fl_mark,
13451345
.daddr = frn->fl_addr,
1346-
.flowi4_tos = frn->fl_tos & IPTOS_RT_MASK,
1346+
.flowi4_tos = frn->fl_tos & INET_DSCP_MASK,
13471347
.flowi4_scope = frn->fl_scope,
13481348
};
13491349
struct fib_table *tb;

net/ipv4/icmp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ static struct rtable *icmp_route_lookup(struct net *net,
545545
orefdst = skb_in->_skb_refdst; /* save old refdst */
546546
skb_dst_set(skb_in, NULL);
547547
err = ip_route_input(skb_in, fl4_dec.daddr, fl4_dec.saddr,
548-
RT_TOS(tos), rt2->dst.dev);
548+
tos, rt2->dst.dev);
549549

550550
dst_release(&rt2->dst);
551551
rt2 = skb_rtable(skb_in);

net/ipv4/ipmr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include <net/fib_rules.h>
6363
#include <linux/netconf.h>
6464
#include <net/rtnh.h>
65+
#include <net/inet_dscp.h>
6566

6667
#include <linux/nospec.h>
6768

@@ -2080,7 +2081,7 @@ static struct mr_table *ipmr_rt_fib_lookup(struct net *net, struct sk_buff *skb)
20802081
struct flowi4 fl4 = {
20812082
.daddr = iph->daddr,
20822083
.saddr = iph->saddr,
2083-
.flowi4_tos = RT_TOS(iph->tos),
2084+
.flowi4_tos = iph->tos & INET_DSCP_MASK,
20842085
.flowi4_oif = (rt_is_output_route(rt) ?
20852086
skb->dev->ifindex : 0),
20862087
.flowi4_iif = (rt_is_output_route(rt) ?

net/ipv4/netfilter/ipt_rpfilter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/module.h>
99
#include <linux/skbuff.h>
1010
#include <linux/netdevice.h>
11+
#include <net/inet_dscp.h>
1112
#include <linux/ip.h>
1213
#include <net/ip.h>
1314
#include <net/ip_fib.h>
@@ -75,7 +76,7 @@ static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par)
7576
flow.daddr = iph->saddr;
7677
flow.saddr = rpfilter_get_saddr(iph->daddr);
7778
flow.flowi4_mark = info->flags & XT_RPFILTER_VALID_MARK ? skb->mark : 0;
78-
flow.flowi4_tos = iph->tos & IPTOS_RT_MASK;
79+
flow.flowi4_tos = iph->tos & INET_DSCP_MASK;
7980
flow.flowi4_scope = RT_SCOPE_UNIVERSE;
8081
flow.flowi4_l3mdev = l3mdev_master_ifindex_rcu(xt_in(par));
8182
flow.flowi4_uid = sock_net_uid(xt_net(par), NULL);

net/ipv4/netfilter/nft_fib_ipv4.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <net/netfilter/nf_tables.h>
1111
#include <net/netfilter/nft_fib.h>
1212

13+
#include <net/inet_dscp.h>
1314
#include <net/ip_fib.h>
1415
#include <net/route.h>
1516

@@ -108,7 +109,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
108109
if (priv->flags & NFTA_FIB_F_MARK)
109110
fl4.flowi4_mark = pkt->skb->mark;
110111

111-
fl4.flowi4_tos = iph->tos & IPTOS_RT_MASK;
112+
fl4.flowi4_tos = iph->tos & INET_DSCP_MASK;
112113

113114
if (priv->flags & NFTA_FIB_F_DADDR) {
114115
fl4.daddr = iph->daddr;

net/ipv4/route.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ void ip_rt_get_source(u8 *addr, struct sk_buff *skb, struct rtable *rt)
12631263
struct flowi4 fl4 = {
12641264
.daddr = iph->daddr,
12651265
.saddr = iph->saddr,
1266-
.flowi4_tos = iph->tos & IPTOS_RT_MASK,
1266+
.flowi4_tos = iph->tos & INET_DSCP_MASK,
12671267
.flowi4_oif = rt->dst.dev->ifindex,
12681268
.flowi4_iif = skb->dev->ifindex,
12691269
.flowi4_mark = skb->mark,
@@ -2160,7 +2160,7 @@ int ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
21602160
if (rt->rt_type != RTN_LOCAL)
21612161
goto skip_validate_source;
21622162

2163-
tos &= IPTOS_RT_MASK;
2163+
tos &= INET_DSCP_MASK;
21642164
err = fib_validate_source(skb, saddr, daddr, tos, 0, dev, in_dev, &tag);
21652165
if (err < 0)
21662166
goto martian_source;
@@ -2470,7 +2470,7 @@ int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr,
24702470
struct fib_result res;
24712471
int err;
24722472

2473-
tos &= IPTOS_RT_MASK;
2473+
tos &= INET_DSCP_MASK;
24742474
rcu_read_lock();
24752475
err = ip_route_input_rcu(skb, daddr, saddr, tos, dev, &res);
24762476
rcu_read_unlock();
@@ -3286,7 +3286,7 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
32863286
skb->dev = dev;
32873287
skb->mark = mark;
32883288
err = ip_route_input_rcu(skb, dst, src,
3289-
rtm->rtm_tos & IPTOS_RT_MASK, dev,
3289+
rtm->rtm_tos & INET_DSCP_MASK, dev,
32903290
&res);
32913291

32923292
rt = skb_rtable(skb);

net/ipv4/udp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
#include <net/addrconf.h>
116116
#include <net/udp_tunnel.h>
117117
#include <net/gro.h>
118+
#include <net/inet_dscp.h>
118119
#if IS_ENABLED(CONFIG_IPV6)
119120
#include <net/ipv6_stubs.h>
120121
#endif
@@ -2618,7 +2619,7 @@ int udp_v4_early_demux(struct sk_buff *skb)
26182619
if (!inet_sk(sk)->inet_daddr && in_dev)
26192620
return ip_mc_validate_source(skb, iph->daddr,
26202621
iph->saddr,
2621-
iph->tos & IPTOS_RT_MASK,
2622+
iph->tos & INET_DSCP_MASK,
26222623
skb->dev, in_dev, &itag);
26232624
}
26242625
return 0;

0 commit comments

Comments
 (0)