Commit ab1a2a52 authored by Paolo Abeni's avatar Paolo Abeni
Browse files

Merge branch 'ipv4-fix-incorrect-tos-in-route-get-reply'

Ido Schimmel says:

====================
ipv4: Fix incorrect TOS in route get reply

Two small fixes for incorrect TOS in route get reply. See more details
in the commit messages.

No regressions in FIB tests:

 # ./fib_tests.sh
 [...]
 Tests passed: 218
 Tests failed:   0
====================

Link: https://patch.msgid.link/20240715142354.3697987-1-idosch@nvidia.com


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parents 120f1c85 f036e682
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -173,6 +173,7 @@ struct fib_result {
	unsigned char		type;
	unsigned char		scope;
	u32			tclassid;
	dscp_t			dscp;
	struct fib_nh_common	*nhc;
	struct fib_info		*fi;
	struct fib_table	*table;
+1 −0
Original line number Diff line number Diff line
@@ -1629,6 +1629,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
			res->nhc = nhc;
			res->type = fa->fa_type;
			res->scope = fi->fib_scope;
			res->dscp = fa->fa_dscp;
			res->fi = fi;
			res->table = tb;
			res->fa_head = &n->leaf;
+8 −8
Original line number Diff line number Diff line
@@ -2867,9 +2867,9 @@ EXPORT_SYMBOL_GPL(ip_route_output_flow);

/* called with rcu_read_lock held */
static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
			struct rtable *rt, u32 table_id, struct flowi4 *fl4,
			struct sk_buff *skb, u32 portid, u32 seq,
			unsigned int flags)
			struct rtable *rt, u32 table_id, dscp_t dscp,
			struct flowi4 *fl4, struct sk_buff *skb, u32 portid,
			u32 seq, unsigned int flags)
{
	struct rtmsg *r;
	struct nlmsghdr *nlh;
@@ -2885,7 +2885,7 @@ static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
	r->rtm_family	 = AF_INET;
	r->rtm_dst_len	= 32;
	r->rtm_src_len	= 0;
	r->rtm_tos	= fl4 ? fl4->flowi4_tos : 0;
	r->rtm_tos	= inet_dscp_to_dsfield(dscp);
	r->rtm_table	= table_id < 256 ? table_id : RT_TABLE_COMPAT;
	if (nla_put_u32(skb, RTA_TABLE, table_id))
		goto nla_put_failure;
@@ -3035,7 +3035,7 @@ static int fnhe_dump_bucket(struct net *net, struct sk_buff *skb,
				goto next;

			err = rt_fill_info(net, fnhe->fnhe_daddr, 0, rt,
					   table_id, NULL, skb,
					   table_id, 0, NULL, skb,
					   NETLINK_CB(cb->skb).portid,
					   cb->nlh->nlmsg_seq, flags);
			if (err)
@@ -3331,7 +3331,7 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
		fri.tb_id = table_id;
		fri.dst = res.prefix;
		fri.dst_len = res.prefixlen;
		fri.dscp = inet_dsfield_to_dscp(fl4.flowi4_tos);
		fri.dscp = res.dscp;
		fri.type = rt->rt_type;
		fri.offload = 0;
		fri.trap = 0;
@@ -3358,8 +3358,8 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
		err = fib_dump_info(skb, NETLINK_CB(in_skb).portid,
				    nlh->nlmsg_seq, RTM_NEWROUTE, &fri, 0);
	} else {
		err = rt_fill_info(net, dst, src, rt, table_id, &fl4, skb,
				   NETLINK_CB(in_skb).portid,
		err = rt_fill_info(net, dst, src, rt, table_id, res.dscp, &fl4,
				   skb, NETLINK_CB(in_skb).portid,
				   nlh->nlmsg_seq, 0);
	}
	if (err < 0)
+12 −12
Original line number Diff line number Diff line
@@ -1737,53 +1737,53 @@ ipv4_rt_dsfield()

	# DSCP 0x10 should match the specific route, no matter the ECN bits
	$IP route get fibmatch 172.16.102.1 dsfield 0x10 | \
		grep -q "via 172.16.103.2"
		grep -q "172.16.102.0/24 tos 0x10 via 172.16.103.2"
	log_test $? 0 "IPv4 route with DSCP and ECN:Not-ECT"

	$IP route get fibmatch 172.16.102.1 dsfield 0x11 | \
		grep -q "via 172.16.103.2"
		grep -q "172.16.102.0/24 tos 0x10 via 172.16.103.2"
	log_test $? 0 "IPv4 route with DSCP and ECN:ECT(1)"

	$IP route get fibmatch 172.16.102.1 dsfield 0x12 | \
		grep -q "via 172.16.103.2"
		grep -q "172.16.102.0/24 tos 0x10 via 172.16.103.2"
	log_test $? 0 "IPv4 route with DSCP and ECN:ECT(0)"

	$IP route get fibmatch 172.16.102.1 dsfield 0x13 | \
		grep -q "via 172.16.103.2"
		grep -q "172.16.102.0/24 tos 0x10 via 172.16.103.2"
	log_test $? 0 "IPv4 route with DSCP and ECN:CE"

	# Unknown DSCP should match the generic route, no matter the ECN bits
	$IP route get fibmatch 172.16.102.1 dsfield 0x14 | \
		grep -q "via 172.16.101.2"
		grep -q "172.16.102.0/24 via 172.16.101.2"
	log_test $? 0 "IPv4 route with unknown DSCP and ECN:Not-ECT"

	$IP route get fibmatch 172.16.102.1 dsfield 0x15 | \
		grep -q "via 172.16.101.2"
		grep -q "172.16.102.0/24 via 172.16.101.2"
	log_test $? 0 "IPv4 route with unknown DSCP and ECN:ECT(1)"

	$IP route get fibmatch 172.16.102.1 dsfield 0x16 | \
		grep -q "via 172.16.101.2"
		grep -q "172.16.102.0/24 via 172.16.101.2"
	log_test $? 0 "IPv4 route with unknown DSCP and ECN:ECT(0)"

	$IP route get fibmatch 172.16.102.1 dsfield 0x17 | \
		grep -q "via 172.16.101.2"
		grep -q "172.16.102.0/24 via 172.16.101.2"
	log_test $? 0 "IPv4 route with unknown DSCP and ECN:CE"

	# Null DSCP should match the generic route, no matter the ECN bits
	$IP route get fibmatch 172.16.102.1 dsfield 0x00 | \
		grep -q "via 172.16.101.2"
		grep -q "172.16.102.0/24 via 172.16.101.2"
	log_test $? 0 "IPv4 route with no DSCP and ECN:Not-ECT"

	$IP route get fibmatch 172.16.102.1 dsfield 0x01 | \
		grep -q "via 172.16.101.2"
		grep -q "172.16.102.0/24 via 172.16.101.2"
	log_test $? 0 "IPv4 route with no DSCP and ECN:ECT(1)"

	$IP route get fibmatch 172.16.102.1 dsfield 0x02 | \
		grep -q "via 172.16.101.2"
		grep -q "172.16.102.0/24 via 172.16.101.2"
	log_test $? 0 "IPv4 route with no DSCP and ECN:ECT(0)"

	$IP route get fibmatch 172.16.102.1 dsfield 0x03 | \
		grep -q "via 172.16.101.2"
		grep -q "172.16.102.0/24 via 172.16.101.2"
	log_test $? 0 "IPv4 route with no DSCP and ECN:CE"
}