Skip to content

Commit

Permalink
route: merge branch 'bisdn:jogo_route_nh_cmp'
Browse files Browse the repository at this point in the history
  • Loading branch information
thom311 committed May 14, 2024
2 parents 7cc72d1 + 861fb80 commit 6db8536
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
3 changes: 3 additions & 0 deletions include/netlink/route/nexthop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);

Expand Down
17 changes: 17 additions & 0 deletions lib/route/nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 4 additions & 12 deletions lib/route/route_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions libnl-route-3.sym
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 6db8536

Please sign in to comment.