thom311 / libnl

Netlink Library Suite
GNU Lesser General Public License v2.1
419 stars 311 forks source link

route: expose nexthop id attribute #386

Closed KanjiMonster closed 3 months ago

KanjiMonster commented 3 months ago

Routes may reference a nexthop (group) via the new nexthop API by its ID, so add accessors for setting and getting it.

Referencing a nexthop is mutually exclusive to specifiying nexthops in the route, so make sure we do not do that when creating netlink messages (which may exist both, since netlink messages from the kernel contain both unless 'nexthop_compat_mode' is disabled).

$ ip -6 r
2001:db8:3::/64 nhid 20 metric 1024 pref medium
    nexthop via 2001:db8:1::2 dev v0 weight 1
    nexthop via 2001:db8:2::2 dev v1 weight 1

Before:

$ nl-route-list
inet6 2001:db8:3::/64 table main type unicast via 2001:db8:1::2 dev v0 via 2001:db8:2::2 dev v1

After:

$ nl-route-list
inet6 2001:db8:3::/64 table main type unicast nhid 20 via 2001:db8:1::2 dev v0 via 2001:db8:2::2 dev v1
KanjiMonster commented 3 months ago

I didn't try to link the nexthop and route caches for now, to keep the changes simple.

thom311 commented 3 months ago

There is still a if (r->ce_mask & ROUTE_ATTR_NHID && r->rt_nhid != 0). It should only check the flags (granted, the conditions are true always at the same time).

Rest lgtm.

KanjiMonster commented 3 months ago

There is still a if (r->ce_mask & ROUTE_ATTR_NHID && r->rt_nhid != 0). It should only check the flags (granted, the conditions are true always at the same time).

Rest lgtm.

Oops, fixed.

thom311 commented 3 months ago

merged as 3e0806317b5116bca7a097a0cb9b7a9cbebc465a

Thank you!!