diff --git a/include/netlink/route/nexthop.h b/include/netlink/route/nexthop.h index c4a2604a..1beb9fa9 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 962f2bab..7e0df613 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 c9418841..aca02e9b 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;