Commit 885b8b4d authored by Stefano Brivio's avatar Stefano Brivio Committed by David S. Miller

ipv4: Fix off-by-one in route dump counter without netlink strict checking

In commit ee28906f ("ipv4: Dump route exceptions if requested") I
added a counter of per-node dumped routes (including actual routes and
exceptions), analogous to the existing counter for dumped nodes. Dumping
exceptions means we need to also keep track of how many routes are dumped
for each node: this would be just one route per node, without exceptions.

When netlink strict checking is not enabled, we dump both routes and
exceptions at the same time: the RTM_F_CLONED flag is not used as a
filter. In this case, the per-node counter 'i_fa' is incremented by one
to track the single dumped route, then also incremented by one for each
exception dumped, and then stored as netlink callback argument as skip
counter, 's_fa', to be used when a partial dump operation restarts.

The per-node counter needs to be increased by one also when we skip a
route (exception) due to a previous non-zero skip counter, because it
needs to match the existing skip counter, if we are dumping both routes
and exceptions. I missed this, and only incremented the counter, for
regular routes, if the previous skip counter was zero. This means that,
in case of a mixed dump, partial dump operations after the first one
will start with a mismatching skip counter value, one less than expected.

This means in turn that the first exception for a given node is skipped
every time a partial dump operation restarts, if netlink strict checking
is not enabled (iproute < 5.0).

It turns out I didn't repeat the test in its final version, commit
de755a85 ("selftests: pmtu: Introduce list_flush_ipv4_exception test
case"), which also counts the number of route exceptions returned, with
iproute2 versions < 5.0 -- I was instead using the equivalent of the IPv6
test as it was before commit b964641e ("selftests: pmtu: Make
list_flush_ipv6_exception test more demanding").

Always increment the per-node counter by one if we previously dumped
a regular route, so that it matches the current skip counter.

Fixes: ee28906f ("ipv4: Dump route exceptions if requested")
Signed-off-by: default avatarStefano Brivio <sbrivio@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cce581a0
...@@ -2126,14 +2126,20 @@ static int fn_trie_dump_leaf(struct key_vector *l, struct fib_table *tb, ...@@ -2126,14 +2126,20 @@ static int fn_trie_dump_leaf(struct key_vector *l, struct fib_table *tb,
goto next; goto next;
} }
if (filter->dump_routes && !s_fa) { if (filter->dump_routes) {
err = fib_dump_info(skb, NETLINK_CB(cb->skb).portid, if (!s_fa) {
cb->nlh->nlmsg_seq, RTM_NEWROUTE, err = fib_dump_info(skb,
tb->tb_id, fa->fa_type, NETLINK_CB(cb->skb).portid,
xkey, KEYLENGTH - fa->fa_slen, cb->nlh->nlmsg_seq,
fa->fa_tos, fi, flags); RTM_NEWROUTE,
if (err < 0) tb->tb_id, fa->fa_type,
goto stop; xkey,
KEYLENGTH - fa->fa_slen,
fa->fa_tos, fi, flags);
if (err < 0)
goto stop;
}
i_fa++; i_fa++;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment