Skip to content

Commit 43d0035

Browse files
committed
Merge branch 'unmask-dscp-bits'
Ido Schimmel says: ==================== Unmask upper DSCP bits - part 2 tl;dr - This patchset continues 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. Part 1 was merged in commit ("Merge branch 'unmask-upper-dscp-bits-part-1'"). 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 continues to unmask the upper DSCP bits, but this time in the output route path. Patches #1-#3 unmask the upper DSCP bits in the various places that invoke the core output route lookup functions directly. Patches #4-#6 do the same in three helpers that are widely used in the output path to initialize the TOS field in the IPv4 flow key. The rest of the patches continue to unmask these bits in call sites that invoke the following wrappers around the core lookup functions: Patch #7 - __ip_route_output_key() Patches #8-#12 - ip_route_output_flow() The next patchset will handle the callers of ip_route_output_ports() and ip_route_output_key(). 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. Changes since v1 [1]: * Remove IPTOS_RT_MASK in patch #7 instead of in patch #6 [1] https://lore.kernel.org/netdev/[email protected]/ ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents cff69f7 + 5003340 commit 43d0035

File tree

10 files changed

+25
-16
lines changed

10 files changed

+25
-16
lines changed

drivers/net/ipvlan/ipvlan_core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
/* Copyright (c) 2014 Mahesh Bandewar <[email protected]>
33
*/
44

5+
#include <net/inet_dscp.h>
6+
57
#include "ipvlan.h"
68

79
static u32 ipvlan_jhash_secret __read_mostly;
@@ -420,7 +422,7 @@ static noinline_for_stack int ipvlan_process_v4_outbound(struct sk_buff *skb)
420422
int err, ret = NET_XMIT_DROP;
421423
struct flowi4 fl4 = {
422424
.flowi4_oif = dev->ifindex,
423-
.flowi4_tos = RT_TOS(ip4h->tos),
425+
.flowi4_tos = ip4h->tos & INET_DSCP_MASK,
424426
.flowi4_flags = FLOWI_FLAG_ANYSRC,
425427
.flowi4_mark = skb->mark,
426428
.daddr = ip4h->daddr,

drivers/net/vrf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <net/sch_generic.h>
3838
#include <net/netns/generic.h>
3939
#include <net/netfilter/nf_conntrack.h>
40+
#include <net/inet_dscp.h>
4041

4142
#define DRV_NAME "vrf"
4243
#define DRV_VERSION "1.1"
@@ -520,7 +521,7 @@ static netdev_tx_t vrf_process_v4_outbound(struct sk_buff *skb,
520521
/* needed to match OIF rule */
521522
fl4.flowi4_l3mdev = vrf_dev->ifindex;
522523
fl4.flowi4_iif = LOOPBACK_IFINDEX;
523-
fl4.flowi4_tos = RT_TOS(ip4h->tos);
524+
fl4.flowi4_tos = ip4h->tos & INET_DSCP_MASK;
524525
fl4.flowi4_flags = FLOWI_FLAG_ANYSRC;
525526
fl4.flowi4_proto = ip4h->protocol;
526527
fl4.daddr = ip4h->daddr;

include/net/ip.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <net/flow_dissector.h>
3434
#include <net/netns/hash.h>
3535
#include <net/lwtunnel.h>
36+
#include <net/inet_dscp.h>
3637

3738
#define IPV4_MAX_PMTU 65535U /* RFC 2675, Section 5.1 */
3839
#define IPV4_MIN_MTU 68 /* RFC 791 */
@@ -258,7 +259,9 @@ static inline u8 ip_sendmsg_scope(const struct inet_sock *inet,
258259

259260
static inline __u8 get_rttos(struct ipcm_cookie* ipc, struct inet_sock *inet)
260261
{
261-
return (ipc->tos != -1) ? RT_TOS(ipc->tos) : RT_TOS(READ_ONCE(inet->tos));
262+
u8 dsfield = ipc->tos != -1 ? ipc->tos : READ_ONCE(inet->tos);
263+
264+
return dsfield & INET_DSCP_MASK;
262265
}
263266

264267
/* datagram.c */

include/net/route.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <net/ip_fib.h>
2828
#include <net/arp.h>
2929
#include <net/ndisc.h>
30+
#include <net/inet_dscp.h>
3031
#include <linux/in_route.h>
3132
#include <linux/rtnetlink.h>
3233
#include <linux/rcupdate.h>
@@ -45,7 +46,7 @@ static inline __u8 ip_sock_rt_scope(const struct sock *sk)
4546

4647
static inline __u8 ip_sock_rt_tos(const struct sock *sk)
4748
{
48-
return RT_TOS(READ_ONCE(inet_sk(sk)->tos));
49+
return READ_ONCE(inet_sk(sk)->tos) & INET_DSCP_MASK;
4950
}
5051

5152
struct ip_tunnel_info;
@@ -265,8 +266,6 @@ static inline void ip_rt_put(struct rtable *rt)
265266
dst_release(&rt->dst);
266267
}
267268

268-
#define IPTOS_RT_MASK (IPTOS_TOS_MASK & ~3)
269-
270269
extern const __u8 ip_tos2prio[16];
271270

272271
static inline char rt_tos2priority(u8 tos)

net/core/filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2372,7 +2372,7 @@ static int __bpf_redirect_neigh_v4(struct sk_buff *skb, struct net_device *dev,
23722372
struct flowi4 fl4 = {
23732373
.flowi4_flags = FLOWI_FLAG_ANYSRC,
23742374
.flowi4_mark = skb->mark,
2375-
.flowi4_tos = RT_TOS(ip4h->tos),
2375+
.flowi4_tos = ip4h->tos & INET_DSCP_MASK,
23762376
.flowi4_oif = dev->ifindex,
23772377
.flowi4_proto = ip4h->protocol,
23782378
.daddr = ip4h->daddr,

net/ipv4/icmp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
#include <net/ip_fib.h>
9494
#include <net/l3mdev.h>
9595
#include <net/addrconf.h>
96+
#include <net/inet_dscp.h>
9697
#define CREATE_TRACE_POINTS
9798
#include <trace/events/icmp.h>
9899

@@ -497,7 +498,7 @@ static struct rtable *icmp_route_lookup(struct net *net,
497498
fl4->saddr = saddr;
498499
fl4->flowi4_mark = mark;
499500
fl4->flowi4_uid = sock_net_uid(net, NULL);
500-
fl4->flowi4_tos = RT_TOS(tos);
501+
fl4->flowi4_tos = tos & INET_DSCP_MASK;
501502
fl4->flowi4_proto = IPPROTO_ICMP;
502503
fl4->fl4_icmp_type = type;
503504
fl4->fl4_icmp_code = code;

net/ipv4/ip_output.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#include <net/inetpeer.h>
7878
#include <net/inet_ecn.h>
7979
#include <net/lwtunnel.h>
80+
#include <net/inet_dscp.h>
8081
#include <linux/bpf-cgroup.h>
8182
#include <linux/igmp.h>
8283
#include <linux/netfilter_ipv4.h>
@@ -1621,7 +1622,7 @@ void ip_send_unicast_reply(struct sock *sk, struct sk_buff *skb,
16211622

16221623
flowi4_init_output(&fl4, oif,
16231624
IP4_REPLY_MARK(net, skb->mark) ?: sk->sk_mark,
1624-
RT_TOS(arg->tos),
1625+
arg->tos & INET_DSCP_MASK,
16251626
RT_SCOPE_UNIVERSE, ip_hdr(skb)->protocol,
16261627
ip_reply_arg_flowi_flags(arg),
16271628
daddr, saddr,

net/ipv4/route.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ static void __build_flow_key(const struct net *net, struct flowi4 *fl4,
512512
sk->sk_protocol;
513513
}
514514

515-
flowi4_init_output(fl4, oif, mark, tos & IPTOS_RT_MASK, scope,
515+
flowi4_init_output(fl4, oif, mark, tos & INET_DSCP_MASK, scope,
516516
prot, flow_flags, iph->daddr, iph->saddr, 0, 0,
517517
sock_net_uid(net, sk));
518518
}
@@ -541,7 +541,7 @@ static void build_sk_flow_key(struct flowi4 *fl4, const struct sock *sk)
541541
if (inet_opt && inet_opt->opt.srr)
542542
daddr = inet_opt->opt.faddr;
543543
flowi4_init_output(fl4, sk->sk_bound_dev_if, READ_ONCE(sk->sk_mark),
544-
ip_sock_rt_tos(sk) & IPTOS_RT_MASK,
544+
ip_sock_rt_tos(sk),
545545
ip_sock_rt_scope(sk),
546546
inet_test_bit(HDRINCL, sk) ?
547547
IPPROTO_RAW : sk->sk_protocol,
@@ -2618,7 +2618,7 @@ struct rtable *ip_route_output_key_hash(struct net *net, struct flowi4 *fl4,
26182618
struct rtable *rth;
26192619

26202620
fl4->flowi4_iif = LOOPBACK_IFINDEX;
2621-
fl4->flowi4_tos &= IPTOS_RT_MASK;
2621+
fl4->flowi4_tos &= INET_DSCP_MASK;
26222622

26232623
rcu_read_lock();
26242624
rth = ip_route_output_key_hash_rcu(net, fl4, &res, skb);
@@ -3261,7 +3261,7 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
32613261

32623262
fl4.daddr = dst;
32633263
fl4.saddr = src;
3264-
fl4.flowi4_tos = rtm->rtm_tos & IPTOS_RT_MASK;
3264+
fl4.flowi4_tos = rtm->rtm_tos & INET_DSCP_MASK;
32653265
fl4.flowi4_oif = tb[RTA_OIF] ? nla_get_u32(tb[RTA_OIF]) : 0;
32663266
fl4.flowi4_mark = mark;
32673267
fl4.flowi4_uid = uid;

net/ipv6/sit.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include <net/dsfield.h>
5252
#include <net/net_namespace.h>
5353
#include <net/netns/generic.h>
54+
#include <net/inet_dscp.h>
5455

5556
/*
5657
This version of net/ipv6/sit.c is cloned of net/ipv4/ip_gre.c
@@ -935,8 +936,8 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
935936
}
936937

937938
flowi4_init_output(&fl4, tunnel->parms.link, tunnel->fwmark,
938-
RT_TOS(tos), RT_SCOPE_UNIVERSE, IPPROTO_IPV6,
939-
0, dst, tiph->saddr, 0, 0,
939+
tos & INET_DSCP_MASK, RT_SCOPE_UNIVERSE,
940+
IPPROTO_IPV6, 0, dst, tiph->saddr, 0, 0,
940941
sock_net_uid(tunnel->net, NULL));
941942

942943
rt = dst_cache_get_ip4(&tunnel->dst_cache, &fl4.saddr);

net/xfrm/xfrm_policy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#ifdef CONFIG_XFRM_ESPINTCP
4646
#include <net/espintcp.h>
4747
#endif
48+
#include <net/inet_dscp.h>
4849

4950
#include "xfrm_hash.h"
5051

@@ -2561,7 +2562,7 @@ xfrm_tmpl_resolve(struct xfrm_policy **pols, int npols, const struct flowi *fl,
25612562
static int xfrm_get_tos(const struct flowi *fl, int family)
25622563
{
25632564
if (family == AF_INET)
2564-
return IPTOS_RT_MASK & fl->u.ip4.flowi4_tos;
2565+
return fl->u.ip4.flowi4_tos & INET_DSCP_MASK;
25652566

25662567
return 0;
25672568
}

0 commit comments

Comments
 (0)