Skip to content

Commit ab1a2a5

Browse files
author
Paolo Abeni
committed
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/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents 120f1c8 + f036e68 commit ab1a2a5

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

include/net/ip_fib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ struct fib_result {
173173
unsigned char type;
174174
unsigned char scope;
175175
u32 tclassid;
176+
dscp_t dscp;
176177
struct fib_nh_common *nhc;
177178
struct fib_info *fi;
178179
struct fib_table *table;

net/ipv4/fib_trie.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
16291629
res->nhc = nhc;
16301630
res->type = fa->fa_type;
16311631
res->scope = fi->fib_scope;
1632+
res->dscp = fa->fa_dscp;
16321633
res->fi = fi;
16331634
res->table = tb;
16341635
res->fa_head = &n->leaf;

net/ipv4/route.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2867,9 +2867,9 @@ EXPORT_SYMBOL_GPL(ip_route_output_flow);
28672867

28682868
/* called with rcu_read_lock held */
28692869
static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
2870-
struct rtable *rt, u32 table_id, struct flowi4 *fl4,
2871-
struct sk_buff *skb, u32 portid, u32 seq,
2872-
unsigned int flags)
2870+
struct rtable *rt, u32 table_id, dscp_t dscp,
2871+
struct flowi4 *fl4, struct sk_buff *skb, u32 portid,
2872+
u32 seq, unsigned int flags)
28732873
{
28742874
struct rtmsg *r;
28752875
struct nlmsghdr *nlh;
@@ -2885,7 +2885,7 @@ static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
28852885
r->rtm_family = AF_INET;
28862886
r->rtm_dst_len = 32;
28872887
r->rtm_src_len = 0;
2888-
r->rtm_tos = fl4 ? fl4->flowi4_tos : 0;
2888+
r->rtm_tos = inet_dscp_to_dsfield(dscp);
28892889
r->rtm_table = table_id < 256 ? table_id : RT_TABLE_COMPAT;
28902890
if (nla_put_u32(skb, RTA_TABLE, table_id))
28912891
goto nla_put_failure;
@@ -3035,7 +3035,7 @@ static int fnhe_dump_bucket(struct net *net, struct sk_buff *skb,
30353035
goto next;
30363036

30373037
err = rt_fill_info(net, fnhe->fnhe_daddr, 0, rt,
3038-
table_id, NULL, skb,
3038+
table_id, 0, NULL, skb,
30393039
NETLINK_CB(cb->skb).portid,
30403040
cb->nlh->nlmsg_seq, flags);
30413041
if (err)
@@ -3331,7 +3331,7 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
33313331
fri.tb_id = table_id;
33323332
fri.dst = res.prefix;
33333333
fri.dst_len = res.prefixlen;
3334-
fri.dscp = inet_dsfield_to_dscp(fl4.flowi4_tos);
3334+
fri.dscp = res.dscp;
33353335
fri.type = rt->rt_type;
33363336
fri.offload = 0;
33373337
fri.trap = 0;
@@ -3358,8 +3358,8 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
33583358
err = fib_dump_info(skb, NETLINK_CB(in_skb).portid,
33593359
nlh->nlmsg_seq, RTM_NEWROUTE, &fri, 0);
33603360
} else {
3361-
err = rt_fill_info(net, dst, src, rt, table_id, &fl4, skb,
3362-
NETLINK_CB(in_skb).portid,
3361+
err = rt_fill_info(net, dst, src, rt, table_id, res.dscp, &fl4,
3362+
skb, NETLINK_CB(in_skb).portid,
33633363
nlh->nlmsg_seq, 0);
33643364
}
33653365
if (err < 0)

tools/testing/selftests/net/fib_tests.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,53 +1737,53 @@ ipv4_rt_dsfield()
17371737

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

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

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)