Skip to content

Commit 9b90783

Browse files
committed
zebra: Store received NHG from upper level protocol
Upper level protocols are sending down a list of nexthops that a temporary nhg was created to hold it. After route resolution is done, this NHG is thrown away. Let's keep this received NHG as a pointer off the RE. Follow the `installedNexthopGroupId` pattern for display purposes at this point in time. Signed-off-by: Donald Sharp <[email protected]>
1 parent a96dc3b commit 9b90783

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

zebra/rib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ struct route_entry {
8585
*/
8686
struct nhg_hash_entry *nhe;
8787

88+
struct nhg_hash_entry *nhe_received;
89+
8890
/*
8991
* Nexthop group hash entry IDs.
9092
* Since the nhe_id is used as a temporary holder

zebra/zebra_rib.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,12 @@ static void route_entry_attach_ref(struct route_entry *re,
474474
zebra_nhg_increment_ref(new);
475475
}
476476

477+
static void route_entry_update_original_nhe(struct route_entry *re, struct nhg_hash_entry *nhe)
478+
{
479+
re->nhe_received = nhe;
480+
zebra_nhg_increment_ref(nhe);
481+
}
482+
477483
/* Replace (if 'new_nhghe') or clear (if that's NULL) an re's nhe. */
478484
int route_entry_update_nhe(struct route_entry *re,
479485
struct nhg_hash_entry *new_nhghe)
@@ -503,6 +509,14 @@ int route_entry_update_nhe(struct route_entry *re,
503509
/* Detach / deref previous nhg */
504510

505511
if (old_nhg) {
512+
if (re->nhe_received == old_nhg) {
513+
zebra_nhg_decrement_ref(old_nhg);
514+
}
515+
if (new_nhghe)
516+
zebra_nhg_increment_ref(new_nhghe);
517+
518+
re->nhe_received = new_nhghe;
519+
506520
/*
507521
* Return true if we are deleting the previous NHE
508522
* Note: we dont check the return value of the function anywhere
@@ -2703,6 +2717,11 @@ static void rib_re_nhg_free(struct route_entry *re)
27032717
nexthops_free(re->nhe->nhg.nexthop);
27042718

27052719
nexthops_free(re->fib_ng.nexthop);
2720+
2721+
if (re->nhe_received) {
2722+
zebra_nhg_decrement_ref(re->nhe_received);
2723+
re->nhe_received = NULL;
2724+
}
27062725
}
27072726

27082727
struct zebra_early_route {
@@ -2813,6 +2832,7 @@ static void process_subq_early_route_add(struct zebra_early_route *ere)
28132832
* if old_id != new_id.
28142833
*/
28152834
route_entry_update_nhe(re, nhe);
2835+
route_entry_update_original_nhe(re, nhe);
28162836

28172837
/* Make it sure prefixlen is applied to the prefix. */
28182838
apply_mask(&ere->p);

zebra/zebra_vty.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,10 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn,
477477
vty_out(vty,
478478
" Installed Nexthop Group ID: %u\n",
479479
re->nhe_installed_id);
480+
481+
if (re->nhe_received)
482+
vty_out(vty, " Received Nexthop Group ID: %u\n",
483+
re->nhe_received->id);
480484
}
481485

482486
for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) {
@@ -589,6 +593,9 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
589593
json_object_int_add(json_route,
590594
"installedNexthopGroupId",
591595
re->nhe_installed_id);
596+
if (re->nhe_received)
597+
json_object_int_add(json_route, "receivedNexthopGroupId",
598+
re->nhe_received->id);
592599

593600
json_object_string_add(json_route, "uptime", up_str);
594601

0 commit comments

Comments
 (0)