summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2024-05-14 16:17:08 +0200
committerThomas Haller <thaller@redhat.com>2024-05-14 16:17:08 +0200
commit6db85366264c9c83e0d53995bfb68e0150184cb4 (patch)
treeea9a64220f9335a21b5cf03afd8094f16da50f9c
parent7cc72d19f84698a194bee843af66be9be6179baa (diff)
parent861fb8090c4bd670890b310b9761edfd1d12d916 (diff)
downloadlibnl-upstream-main.tar.gz
route: merge branch 'bisdn:jogo_route_nh_cmp'upstream-main
https://github.com/thom311/libnl/pull/384
-rw-r--r--include/netlink/route/nexthop.h3
-rw-r--r--lib/route/nexthop.c17
-rw-r--r--lib/route/route_obj.c16
-rw-r--r--libnl-route-3.sym1
4 files changed, 25 insertions, 12 deletions
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/lib/route/route_obj.c b/lib/route/route_obj.c
index aba1a1bb..0a0c06d6 100644
--- a/lib/route/route_obj.c
+++ b/lib/route/route_obj.c
@@ -449,7 +449,7 @@ static uint64_t route_compare(struct nl_object *_a, struct nl_object *_b,
found = 0;
nl_list_for_each_entry(nh_b, &b->rt_nexthops,
rtnh_list) {
- if (!rtnl_route_nh_compare(nh_a, nh_b, ~0, 0)) {
+ if (rtnl_route_nh_identical(nh_a, nh_b)) {
found = 1;
break;
}
@@ -464,7 +464,7 @@ static uint64_t route_compare(struct nl_object *_a, struct nl_object *_b,
found = 0;
nl_list_for_each_entry(nh_a, &a->rt_nexthops,
rtnh_list) {
- if (!rtnl_route_nh_compare(nh_a, nh_b, ~0, 0)) {
+ if (rtnl_route_nh_identical(nh_a, nh_b)) {
found = 1;
break;
}
@@ -538,7 +538,7 @@ static int route_update(struct nl_object *old_obj, struct nl_object *new_obj)
* Do not add the nexthop to old route if it was already added before
*/
nl_list_for_each_entry(old_nh, &old_route->rt_nexthops, rtnh_list) {
- if (!rtnl_route_nh_compare(old_nh, new_nh, ~0, 0)) {
+ if (rtnl_route_nh_identical(old_nh, new_nh)) {
return 0;
}
}
@@ -574,15 +574,7 @@ static int route_update(struct nl_object *old_obj, struct nl_object *new_obj)
*/
nl_list_for_each_entry(old_nh, &old_route->rt_nexthops,
rtnh_list) {
- /*
- * Since the new route has only one nexthop, it's not
- * an ECMP route and the nexthop won't have a weight.
- * Similarily, the nexthop might have been marked as
- * DEAD in its flags if it was deleted.
- * Therefore ignore NH_ATTR_FLAGS (= 0x1) and
- * NH_ATTR_WEIGHT (= 0x2) while comparing nexthops.
- */
- if (!rtnl_route_nh_compare(old_nh, new_nh, ~0x3, 0)) {
+ if (rtnl_route_nh_identical(old_nh, new_nh)) {
rtnl_route_remove_nexthop(old_route, old_nh);
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;