Skip to content

Commit

Permalink
nexthop: add a identical helper function
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
KanjiMonster committed May 14, 2024
1 parent 7cc72d1 commit 8cf29d7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 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
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 8cf29d7

Please sign in to comment.