adding existing ipv6 network route returns ENOMEM instead of EEXIST if loopback route also exists

From: Guy Yur <guyyur_at_gmail.com>
Date: Sun, 22 Nov 2020 00:48:16 +0200
Hi,

When adding a route with a netmask, add_route() in route_ctl.c
adds the route with destination address masked.
If the add failed (for example, the route exists) it calls
lookup_prefix() with the original unmasked destination.

In a scenario where a loopback route was added followed
by the network route being added, if the network route
is added again and the network route destination is the
same as the loopback route, lookup_prefix() will match on
the loopback route, not finding the network route and
add_route() will return ENOMEM instead of EEXIST.
Adding the route with just the network part returns EEXIST as expected.

Example:
# route -6 add -host fd53::1111 -prefixlen 128 ::1
# route -6 add -net fd53::1111 -prefixlen 64 ::1
# route -6 add -net fd53::1111 -prefixlen 64 ::1
route: writing to routing socket: Cannot allocate memory
add net fd53::1111: gateway ::1 fib 0: Cannot allocate memory
# route -6 add -net fd53:: -prefixlen 64 ::1
add net fd53::: gateway ::1 fib 0: route already in table

I was testing https://reviews.freebsd.org/D15406
changes applied to r367863.
The changes call rtinit to add prefix route when
interface address is added/updated and uses the
interface address as the destination.
rtinit returned ENOMEM instead of EEXIST
causing dhcpcd to printCannot allocate memory.

route commands above showing the problem were run
in r367863 without D15406 changesas well.

Thanks,
Guy Yur
Received on Sat Nov 21 2020 - 21:48:21 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:25 UTC