Skip to content

Commit bfba7bc

Browse files
committed
Merge branch 'unmask-dscp-part-four'
Ido Schimmel says: ==================== Unmask upper DSCP bits - part 4 (last) tl;dr - This patchset finishes 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 finishes to unmask the upper DSCP bits by adjusting all the callers of ip_route_output_key() to properly initialize the full DSCP value in the IPv4 flow 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. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 8f08854 + 8b6d13c commit bfba7bc

File tree

10 files changed

+23
-14
lines changed

10 files changed

+23
-14
lines changed

net/bridge/br_netfilter_hooks.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <net/route.h>
3737
#include <net/netfilter/br_netfilter.h>
3838
#include <net/netns/generic.h>
39+
#include <net/inet_dscp.h>
3940

4041
#include <linux/uaccess.h>
4142
#include "br_private.h"
@@ -402,7 +403,7 @@ static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_
402403
goto free_skb;
403404

404405
rt = ip_route_output(net, iph->daddr, 0,
405-
RT_TOS(iph->tos), 0,
406+
iph->tos & INET_DSCP_MASK, 0,
406407
RT_SCOPE_UNIVERSE);
407408
if (!IS_ERR(rt)) {
408409
/* - Bridged-and-DNAT'ed traffic doesn't

net/core/lwt_bpf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <net/gre.h>
1313
#include <net/ip6_route.h>
1414
#include <net/ipv6_stubs.h>
15+
#include <net/inet_dscp.h>
1516

1617
struct bpf_lwt_prog {
1718
struct bpf_prog *prog;
@@ -205,7 +206,7 @@ static int bpf_lwt_xmit_reroute(struct sk_buff *skb)
205206
fl4.flowi4_oif = oif;
206207
fl4.flowi4_mark = skb->mark;
207208
fl4.flowi4_uid = sock_net_uid(net, sk);
208-
fl4.flowi4_tos = RT_TOS(iph->tos);
209+
fl4.flowi4_tos = iph->tos & INET_DSCP_MASK;
209210
fl4.flowi4_flags = FLOWI_FLAG_ANYSRC;
210211
fl4.flowi4_proto = iph->protocol;
211212
fl4.daddr = iph->daddr;

net/ipv4/icmp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ static void icmp_reply(struct icmp_bxm *icmp_param, struct sk_buff *skb)
445445
fl4.saddr = saddr;
446446
fl4.flowi4_mark = mark;
447447
fl4.flowi4_uid = sock_net_uid(net, NULL);
448-
fl4.flowi4_tos = RT_TOS(ip_hdr(skb)->tos);
448+
fl4.flowi4_tos = ip_hdr(skb)->tos & INET_DSCP_MASK;
449449
fl4.flowi4_proto = IPPROTO_ICMP;
450450
fl4.flowi4_oif = l3mdev_master_ifindex(skb->dev);
451451
security_skb_classify_flow(skb, flowi4_to_flowi_common(&fl4));

net/ipv4/ip_gre.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <net/gre.h>
4545
#include <net/dst_metadata.h>
4646
#include <net/erspan.h>
47+
#include <net/inet_dscp.h>
4748

4849
/*
4950
Problems & solutions
@@ -930,7 +931,7 @@ static int ipgre_open(struct net_device *dev)
930931
t->parms.iph.daddr,
931932
t->parms.iph.saddr,
932933
t->parms.o_key,
933-
RT_TOS(t->parms.iph.tos),
934+
t->parms.iph.tos & INET_DSCP_MASK,
934935
t->parms.link);
935936
if (IS_ERR(rt))
936937
return -EADDRNOTAVAIL;

net/ipv4/ip_tunnel.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <net/rtnetlink.h>
4444
#include <net/udp.h>
4545
#include <net/dst_metadata.h>
46+
#include <net/inet_dscp.h>
4647

4748
#if IS_ENABLED(CONFIG_IPV6)
4849
#include <net/ipv6.h>
@@ -293,7 +294,7 @@ static int ip_tunnel_bind_dev(struct net_device *dev)
293294

294295
ip_tunnel_init_flow(&fl4, iph->protocol, iph->daddr,
295296
iph->saddr, tunnel->parms.o_key,
296-
RT_TOS(iph->tos), dev_net(dev),
297+
iph->tos & INET_DSCP_MASK, dev_net(dev),
297298
tunnel->parms.link, tunnel->fwmark, 0, 0);
298299
rt = ip_route_output_key(tunnel->net, &fl4);
299300

@@ -609,9 +610,9 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
609610
tos = ipv6_get_dsfield((const struct ipv6hdr *)inner_iph);
610611
}
611612
ip_tunnel_init_flow(&fl4, proto, key->u.ipv4.dst, key->u.ipv4.src,
612-
tunnel_id_to_key32(key->tun_id), RT_TOS(tos),
613-
dev_net(dev), 0, skb->mark, skb_get_hash(skb),
614-
key->flow_flags);
613+
tunnel_id_to_key32(key->tun_id),
614+
tos & INET_DSCP_MASK, dev_net(dev), 0, skb->mark,
615+
skb_get_hash(skb), key->flow_flags);
615616

616617
if (!tunnel_hlen)
617618
tunnel_hlen = ip_encap_hlen(&tun_info->encap);
@@ -772,7 +773,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
772773
}
773774

774775
ip_tunnel_init_flow(&fl4, protocol, dst, tnl_params->saddr,
775-
tunnel->parms.o_key, RT_TOS(tos),
776+
tunnel->parms.o_key, tos & INET_DSCP_MASK,
776777
dev_net(dev), READ_ONCE(tunnel->parms.link),
777778
tunnel->fwmark, skb_get_hash(skb), 0);
778779

net/ipv4/netfilter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <net/route.h>
1515
#include <net/xfrm.h>
1616
#include <net/ip.h>
17+
#include <net/inet_dscp.h>
1718
#include <net/netfilter/nf_queue.h>
1819

1920
/* route_me_harder function, used by iptable_nat, iptable_mangle + ip_queue */
@@ -43,7 +44,7 @@ int ip_route_me_harder(struct net *net, struct sock *sk, struct sk_buff *skb, un
4344
*/
4445
fl4.daddr = iph->daddr;
4546
fl4.saddr = saddr;
46-
fl4.flowi4_tos = RT_TOS(iph->tos);
47+
fl4.flowi4_tos = iph->tos & INET_DSCP_MASK;
4748
fl4.flowi4_oif = sk ? sk->sk_bound_dev_if : 0;
4849
fl4.flowi4_l3mdev = l3mdev_master_ifindex(dev);
4950
fl4.flowi4_mark = skb->mark;

net/ipv4/netfilter/nf_dup_ipv4.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <net/icmp.h>
1616
#include <net/ip.h>
1717
#include <net/route.h>
18+
#include <net/inet_dscp.h>
1819
#include <net/netfilter/ipv4/nf_dup_ipv4.h>
1920
#if IS_ENABLED(CONFIG_NF_CONNTRACK)
2021
#include <net/netfilter/nf_conntrack.h>
@@ -32,7 +33,7 @@ static bool nf_dup_ipv4_route(struct net *net, struct sk_buff *skb,
3233
fl4.flowi4_oif = oif;
3334

3435
fl4.daddr = gw->s_addr;
35-
fl4.flowi4_tos = RT_TOS(iph->tos);
36+
fl4.flowi4_tos = iph->tos & INET_DSCP_MASK;
3637
fl4.flowi4_scope = RT_SCOPE_UNIVERSE;
3738
fl4.flowi4_flags = FLOWI_FLAG_KNOWN_NH;
3839
rt = ip_route_output_key(net, &fl4);

net/ipv4/udp_tunnel_core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <net/dst_metadata.h>
77
#include <net/udp.h>
88
#include <net/udp_tunnel.h>
9+
#include <net/inet_dscp.h>
910

1011
int udp_sock_create4(struct net *net, struct udp_port_cfg *cfg,
1112
struct socket **sockp)
@@ -232,7 +233,7 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,
232233
fl4.saddr = key->u.ipv4.src;
233234
fl4.fl4_dport = dport;
234235
fl4.fl4_sport = sport;
235-
fl4.flowi4_tos = RT_TOS(tos);
236+
fl4.flowi4_tos = tos & INET_DSCP_MASK;
236237
fl4.flowi4_flags = key->flow_flags;
237238

238239
rt = ip_route_output_key(net, &fl4);

net/netfilter/nft_flow_offload.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/netfilter/nf_conntrack_common.h>
1010
#include <linux/netfilter/nf_tables.h>
1111
#include <net/ip.h> /* for ipv4 options. */
12+
#include <net/inet_dscp.h>
1213
#include <net/netfilter/nf_tables.h>
1314
#include <net/netfilter/nf_tables_core.h>
1415
#include <net/netfilter/nf_conntrack_core.h>
@@ -235,7 +236,7 @@ static int nft_flow_route(const struct nft_pktinfo *pkt,
235236
fl.u.ip4.saddr = ct->tuplehash[!dir].tuple.src.u3.ip;
236237
fl.u.ip4.flowi4_oif = nft_in(pkt)->ifindex;
237238
fl.u.ip4.flowi4_iif = this_dst->dev->ifindex;
238-
fl.u.ip4.flowi4_tos = RT_TOS(ip_hdr(pkt->skb)->tos);
239+
fl.u.ip4.flowi4_tos = ip_hdr(pkt->skb)->tos & INET_DSCP_MASK;
239240
fl.u.ip4.flowi4_mark = pkt->skb->mark;
240241
fl.u.ip4.flowi4_flags = FLOWI_FLAG_ANYSRC;
241242
break;

net/sctp/protocol.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <net/inet_common.h>
4545
#include <net/inet_ecn.h>
4646
#include <net/udp_tunnel.h>
47+
#include <net/inet_dscp.h>
4748

4849
#define MAX_SCTP_PORT_HASH_ENTRIES (64 * 1024)
4950

@@ -435,7 +436,7 @@ static void sctp_v4_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
435436
fl4->fl4_dport = daddr->v4.sin_port;
436437
fl4->flowi4_proto = IPPROTO_SCTP;
437438
if (asoc) {
438-
fl4->flowi4_tos = RT_TOS(tos);
439+
fl4->flowi4_tos = tos & INET_DSCP_MASK;
439440
fl4->flowi4_scope = ip_sock_rt_scope(asoc->base.sk);
440441
fl4->flowi4_oif = asoc->base.sk->sk_bound_dev_if;
441442
fl4->fl4_sport = htons(asoc->base.bind_addr.port);

0 commit comments

Comments
 (0)