diff options
author | Felix Fietkau <nbd@nbd.name> | 2022-05-19 17:21:23 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@nbd.name> | 2022-05-19 17:21:24 +0200 |
commit | 507c0513d1766757d969530c51fe7d368354538d (patch) | |
tree | 21aa6169dacb0e913139a7409672f7342670078d /interface-ip.c | |
parent | 4b4849cf5e5a784aca40be55158744811b172e76 (diff) | |
download | netifd-507c0513d1766757d969530c51fe7d368354538d.tar.gz |
interface-ip: add support for excluding interfaces in host route lookup
When adding host routes needed for an interface to communicate, it may be
necessary to skip the interface itself, in case it provides a default route.
This helps with avoiding accidental loops
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'interface-ip.c')
-rw-r--r-- | interface-ip.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/interface-ip.c b/interface-ip.c index 54d5fe0..585cb6f 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -257,12 +257,19 @@ interface_ip_find_route_target(struct interface *iface, union if_addr *a, } struct interface * -interface_ip_add_target_route(union if_addr *addr, bool v6, struct interface *iface) +interface_ip_add_target_route(union if_addr *addr, bool v6, struct interface *iface, + bool exclude) { struct device_route *route, *r_next = NULL; bool defaultroute_target = false; union if_addr addr_zero; int addrsize = v6 ? sizeof(addr->in6) : sizeof(addr->in); + struct interface *exclude_iface = NULL; + + if (exclude) { + exclude_iface = iface; + iface = NULL; + } memset(&addr_zero, 0, sizeof(addr_zero)); if (memcmp(&addr_zero, addr, addrsize) == 0) @@ -278,6 +285,9 @@ interface_ip_add_target_route(union if_addr *addr, bool v6, struct interface *if interface_ip_find_route_target(iface, addr, v6, &r_next); } else { vlist_for_each_element(&interfaces, iface, node) { + if (iface == exclude_iface) + continue; + /* look for locally addressable target first */ if (interface_ip_find_addr_target(iface, addr, v6)) return iface; |