Skip to content

Commit

Permalink
zebra: remove proto nhid from system, when NHG_DEL is sent
Browse files Browse the repository at this point in the history
When suppressing a nexthop group, the proto nhid is still present
in the system:
> ubuntu2204(config)# nexthop-group LL
> 2023/12/04 21:23:44 SHARP: [Q5NBA-GN1BG] NHG ID assigned: 179687510
> ubuntu2204(config-nh-group)# nexthop 192.0.2.43 loop1
> ubuntu2204(config-nh-group)# no  nexthop 192.0.2.43 loop1
> 2023/12/04 21:23:56 ZEBRA: [RY75W-058E9] zebra_nhg_proto_del: deleted nhe 0x55edc18eb870 (179687510[260]), vrf 0, type sharp
> 2023/12/04 21:23:56 ZEBRA: [WDEB1-93HCZ] zebra_nhg_decrement_ref: nhe 0x55edc18eb870 (179687510[260]) 1 => 0
> 2023/12/04 21:23:56 SHARP: [H3QKG-WH8ZV] Removed nhg 179687510
> ubuntu2204(config-nh-group)#
> ubuntu2204(config-nh-group)# exi
> ubuntu2204(config)# <Ctrl-D>
> # ip nexthop ls
> id 179687510 group 260 proto 194
> id 260 via 192.0.2.43 dev loop1 scope link proto 194

There is no need to keep nexthop group from protocol levels if there
are no references to that nexthop group. Fix this by forcing the system
removal only if it is a protocol nhid.

Fixes: 35729f3 ("zebra: Add a timer to nexthop group deletion")

Signed-off-by: Philippe Guibert <[email protected]>
  • Loading branch information
pguibert6WIND committed Dec 5, 2023
1 parent 3f4c682 commit 859b0dc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
36 changes: 36 additions & 0 deletions tests/topotests/all_protocol_startup/test_all_protocol_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,20 @@ def verify_nexthop_group(nhg_id, recursive=False, ecmp=0):
"Nexthop Group ID=%d not marked Installed" % nhg_id
)

def verify_nexthop_group_on_system(nhg_id, present):
# Verify nhgid presence on the system
net = get_topogen().net
output = net["r1"].cmd("ip nexthop show id %s" % nhg_id)
match = re.search(r"id %s" % nhg_id, output)
if present:
assert match is not None, (
"Nexthop Group ID=%d should be present on the system, but is not" % nhg_id
)
else:
assert match is None, (
"Nexthop Group ID=%d should not be present on the system, but is not" % nhg_id
)


def verify_route_nexthop_group(route_str, recursive=False, ecmp=0):
# Verify route and that zebra created NHGs for and they are valid/installed
Expand Down Expand Up @@ -613,6 +627,28 @@ def test_nexthop_groups():
% nhg_id
)

## nexthop suppression

net["r1"].cmd(
'vtysh -c "c t" -c "nexthop-group suppress" -c "nexthop 192.168.0.165 r1-eth0"'
)
net["r1"].cmd(
'vtysh -c "sharp install routes 7.7.7.1 nexthop-group suppress 1"'
)
verify_route_nexthop_group("7.7.7.1/32")
nhg_id = route_get_nhg_id("7.7.7.1/32")
verify_nexthop_group_on_system(nhg_id, True)
net["r1"].cmd(
'vtysh -c "sharp remove routes 7.7.7.1 1"'
)
net["r1"].cmd(
'vtysh -c "c t" -c "nexthop-group suppress" -c "no nexthop 192.168.0.165 r1-eth0"'
)
net["r1"].cmd(
'vtysh -c "c t" -c "no nexthop-group suppress"'
)
verify_nexthop_group_on_system(nhg_id, False)

## Remove all NHG routes

net["r1"].cmd('vtysh -c "sharp remove routes 2.2.2.1 1"')
Expand Down
3 changes: 2 additions & 1 deletion zebra/zebra_nhg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,8 @@ void zebra_nhg_decrement_ref(struct nhg_hash_entry *nhe)

nhe->refcnt--;

if (!zebra_router_in_shutdown() && nhe->refcnt <= 0 &&
if (!PROTO_OWNED(nhe) && !zebra_router_in_shutdown() &&
nhe->refcnt <= 0 &&
CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED) &&
!CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_KEEP_AROUND)) {
nhe->refcnt = 1;
Expand Down

0 comments on commit 859b0dc

Please sign in to comment.