diff options
author | Jonas Gorski <jonas.gorski@bisdn.de> | 2024-05-13 12:00:39 (GMT) |
---|---|---|
committer | Jonas Gorski <jonas.gorski@bisdn.de> | 2024-05-14 09:50:57 (GMT) |
commit | 8cf29d7b4a8f4dadcc68932edc23e05f5d0fee89 (patch) | |
tree | 270e51baaf57f26cf47824d1910bae469f55fb23 | |
parent | 7cc72d19f84698a194bee843af66be9be6179baa (diff) | |
download | libnl-8cf29d7b4a8f4dadcc68932edc23e05f5d0fee89.zip libnl-8cf29d7b4a8f4dadcc68932edc23e05f5d0fee89.tar.gz libnl-8cf29d7b4a8f4dadcc68932edc23e05f5d0fee89.tar.bz2 |
nexthop: add a identical helper function
Not all attributes of a nexthop are id attributes, e.g. the flags will
contain state (LINKDOWN, DEAD) of the attached link about which the
kernel will not send route updates.
Likewise, the weight may not exist when processing an ECMP IPv6 route
update which only contains a single nexthop.
Since rtnl_nexthop isn't a first class cache object, we cannot use
nl_object_identical(), so add a separate identical helper function which
compares only fixed attributes.
Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
-rw-r--r-- | include/netlink/route/nexthop.h | 3 | ||||
-rw-r--r-- | lib/route/nexthop.c | 17 | ||||
-rw-r--r-- | libnl-route-3.sym | 1 |
3 files changed, 21 insertions, 0 deletions
diff --git a/include/netlink/route/nexthop.h b/include/netlink/route/nexthop.h index c4a2604..1beb9fa 100644 --- a/include/netlink/route/nexthop.h +++ b/include/netlink/route/nexthop.h @@ -30,6 +30,9 @@ extern int rtnl_route_nh_compare(struct rtnl_nexthop *, struct rtnl_nexthop *, uint32_t, int); +extern int rtnl_route_nh_identical(struct rtnl_nexthop *, + struct rtnl_nexthop *); + extern void rtnl_route_nh_dump(struct rtnl_nexthop *, struct nl_dump_params *); diff --git a/lib/route/nexthop.c b/lib/route/nexthop.c index 962f2ba..7e0df61 100644 --- a/lib/route/nexthop.c +++ b/lib/route/nexthop.c @@ -136,6 +136,23 @@ int rtnl_route_nh_compare(struct rtnl_nexthop *a, struct rtnl_nexthop *b, return diff; } +/** + * Check if the fixed attributes of two nexthops are identical, and may + * only differ in flags or weight. + * + * @arg a a nexthop + * @arg b another nexthop + * + * @return true if both nexthop have equal attributes, otherwise false. + */ +int rtnl_route_nh_identical(struct rtnl_nexthop *a, struct rtnl_nexthop *b) +{ + return !rtnl_route_nh_compare(a, b, + NH_ATTR_IFINDEX | NH_ATTR_REALMS | + NH_ATTR_GATEWAY | NH_ATTR_NEWDST | + NH_ATTR_VIA | NH_ATTR_ENCAP, 0); +} + static void nh_dump_line(struct rtnl_nexthop *nh, struct nl_dump_params *dp) { struct nl_cache *link_cache; diff --git a/libnl-route-3.sym b/libnl-route-3.sym index c941884..aca02e9 100644 --- a/libnl-route-3.sym +++ b/libnl-route-3.sym @@ -1328,4 +1328,5 @@ global: rtnl_link_bridge_set_port_vlan_map_range; rtnl_link_bridge_set_port_vlan_pvid; rtnl_link_bridge_unset_port_vlan_map_range; + rtnl_route_nh_identical; } libnl_3_9; |