diff options
Diffstat (limited to 'zebra/zebra_nhg.c')
| -rw-r--r-- | zebra/zebra_nhg.c | 164 |
1 files changed, 93 insertions, 71 deletions
diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index cf09902d52..500f4b0f1b 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -324,8 +324,8 @@ static int zebra_nhg_insert_id(struct nhg_hash_entry *nhe) if (hash_lookup(zrouter.nhgs_id, nhe)) { flog_err( EC_ZEBRA_NHG_TABLE_INSERT_FAILED, - "Failed inserting NHG id=%u into the ID hash table, entry already exists", - nhe->id); + "Failed inserting NHG %pNG into the ID hash table, entry already exists", + nhe); return -1; } @@ -358,10 +358,9 @@ zebra_nhg_connect_depends(struct nhg_hash_entry *nhe, if (!zebra_nhg_depends_is_empty(nhe)) { frr_each(nhg_connected_tree, &nhe->nhg_depends, rb_node_dep) { if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: nhe %p (%u), dep %p (%u)", - __func__, nhe, nhe->id, - rb_node_dep->nhe, - rb_node_dep->nhe->id); + zlog_debug("%s: nhe %p (%pNG), dep %p (%pNG)", + __func__, nhe, nhe, rb_node_dep->nhe, + rb_node_dep->nhe); zebra_nhg_dependents_add(rb_node_dep->nhe, nhe); } @@ -470,9 +469,9 @@ static void *zebra_nhg_hash_alloc(void *arg) else { if (IS_ZEBRA_DEBUG_NHG) zlog_debug( - "Failed to lookup an interface with ifindex=%d in vrf=%u for NHE id=%u", + "Failed to lookup an interface with ifindex=%d in vrf=%u for NHE %pNG", nhe->nhg.nexthop->ifindex, - nhe->nhg.nexthop->vrf_id, nhe->id); + nhe->nhg.nexthop->vrf_id, nhe); } } @@ -706,9 +705,7 @@ static bool zebra_nhe_find(struct nhg_hash_entry **nhe, /* return value */ (*nhe) = hash_lookup(zrouter.nhgs, lookup); if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: lookup => %p (%u)", - __func__, (*nhe), - (*nhe) ? (*nhe)->id : 0); + zlog_debug("%s: lookup => %p (%pNG)", __func__, *nhe, *nhe); /* If we found an existing object, we're done */ if (*nhe) @@ -745,8 +742,8 @@ static bool zebra_nhe_find(struct nhg_hash_entry **nhe, /* return value */ *nhe = newnhe; if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: => created %p (%u)", __func__, newnhe, - newnhe->id); + zlog_debug("%s: => created %p (%pNG)", __func__, newnhe, + newnhe); /* Only hash/lookup the depends if the first lookup * fails to find something. This should hopefully save a @@ -928,8 +925,7 @@ static struct nhg_hash_entry *zebra_nhg_find_nexthop(uint32_t id, zebra_nhg_find(&nhe, id, &nhg, NULL, vrf_id, afi, type, from_dplane); if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: nh %pNHv => %p (%u)", - __func__, nh, nhe, nhe ? nhe->id : 0); + zlog_debug("%s: nh %pNHv => %p (%pNG)", __func__, nh, nhe, nhe); return nhe; } @@ -1096,7 +1092,7 @@ static void zebra_nhg_release_all_deps(struct nhg_hash_entry *nhe) static void zebra_nhg_release(struct nhg_hash_entry *nhe) { if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: nhe %p (%u)", __func__, nhe, nhe->id); + zlog_debug("%s: nhe %p (%pNG)", __func__, nhe, nhe); zebra_nhg_release_all_deps(nhe); @@ -1135,8 +1131,8 @@ static void zebra_nhg_handle_kernel_state_change(struct nhg_hash_entry *nhe, if (nhe->refcnt) { flog_err( EC_ZEBRA_NHG_SYNC, - "Kernel %s a nexthop group with ID (%u) that we are still using for a route, sending it back down", - (is_delete ? "deleted" : "updated"), nhe->id); + "Kernel %s a nexthop group with ID (%pNG) that we are still using for a route, sending it back down", + (is_delete ? "deleted" : "updated"), nhe); UNSET_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED); zebra_nhg_install_kernel(nhe); @@ -1199,7 +1195,7 @@ static int nhg_ctx_process_new(struct nhg_ctx *ctx) } if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: nhe %p (%u) is new", __func__, nhe, nhe->id); + zlog_debug("%s: nhe %p (%pNG) is new", __func__, nhe, nhe); /* * If daemon nhg from the kernel, add a refcnt here to indicate the @@ -1389,8 +1385,7 @@ static struct nhg_hash_entry *depends_find_singleton(const struct nexthop *nh, nexthop_del_srv6_seg6(&lookup); if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: nh %pNHv => %p (%u)", - __func__, nh, nhe, nhe ? nhe->id : 0); + zlog_debug("%s: nh %pNHv => %p (%pNG)", __func__, nh, nhe, nhe); return nhe; } @@ -1413,10 +1408,10 @@ static struct nhg_hash_entry *depends_find(const struct nexthop *nh, afi_t afi, if (IS_ZEBRA_DEBUG_NHG_DETAIL) { - zlog_debug("%s: nh %pNHv %s => %p (%u)", __func__, nh, + zlog_debug("%s: nh %pNHv %s => %p (%pNG)", __func__, nh, CHECK_FLAG(nh->flags, NEXTHOP_FLAG_RECURSIVE) ? "(R)" : "", - nhe, nhe ? nhe->id : 0); + nhe, nhe); } done: @@ -1495,8 +1490,7 @@ struct nhg_hash_entry *zebra_nhg_rib_find(uint32_t id, zebra_nhg_find(&nhe, id, nhg, NULL, vrf_id, rt_afi, type, false); if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: => nhe %p (%u)", - __func__, nhe, nhe ? nhe->id : 0); + zlog_debug("%s: => nhe %p (%pNG)", __func__, nhe, nhe); return nhe; } @@ -1514,13 +1508,12 @@ zebra_nhg_rib_find_nhe(struct nhg_hash_entry *rt_nhe, afi_t rt_afi) } if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: rt_nhe %p (%u)", __func__, rt_nhe, rt_nhe->id); + zlog_debug("%s: rt_nhe %p (%pNG)", __func__, rt_nhe, rt_nhe); zebra_nhe_find(&nhe, rt_nhe, NULL, rt_afi, false); if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: => nhe %p (%u)", - __func__, nhe, nhe ? nhe->id : 0); + zlog_debug("%s: => nhe %p (%pNG)", __func__, nhe, nhe); return nhe; } @@ -1604,16 +1597,16 @@ void zebra_nhg_free(struct nhg_hash_entry *nhe) if (IS_ZEBRA_DEBUG_NHG_DETAIL) { /* Group or singleton? */ if (nhe->nhg.nexthop && nhe->nhg.nexthop->next) - zlog_debug("%s: nhe %p (%u), refcnt %d", - __func__, nhe, nhe->id, nhe->refcnt); + zlog_debug("%s: nhe %p (%pNG), refcnt %d", __func__, + nhe, nhe, nhe->refcnt); else - zlog_debug("%s: nhe %p (%u), refcnt %d, NH %pNHv", - __func__, nhe, nhe->id, nhe->refcnt, + zlog_debug("%s: nhe %p (%pNG), refcnt %d, NH %pNHv", + __func__, nhe, nhe, nhe->refcnt, nhe->nhg.nexthop); } if (nhe->refcnt) - zlog_debug("nhe_id=%u hash refcnt=%d", nhe->id, nhe->refcnt); + zlog_debug("nhe_id=%pNG hash refcnt=%d", nhe, nhe->refcnt); zebra_nhg_free_members(nhe); @@ -1629,9 +1622,8 @@ void zebra_nhg_hash_free(void *p) void zebra_nhg_decrement_ref(struct nhg_hash_entry *nhe) { if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: nhe %p (%u) %d => %d", - __func__, nhe, nhe->id, nhe->refcnt, - nhe->refcnt - 1); + zlog_debug("%s: nhe %p (%pNG) %d => %d", __func__, nhe, nhe, + nhe->refcnt, nhe->refcnt - 1); nhe->refcnt--; @@ -1645,9 +1637,8 @@ void zebra_nhg_decrement_ref(struct nhg_hash_entry *nhe) void zebra_nhg_increment_ref(struct nhg_hash_entry *nhe) { if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: nhe %p (%u) %d => %d", - __func__, nhe, nhe->id, nhe->refcnt, - nhe->refcnt + 1); + zlog_debug("%s: nhe %p (%pNG) %d => %d", __func__, nhe, nhe, + nhe->refcnt, nhe->refcnt + 1); nhe->refcnt++; @@ -2287,9 +2278,9 @@ static int nexthop_active(struct nexthop *nexthop, struct nhg_hash_entry *nhe, } if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: CONNECT match %p (%u), newhop %pNHv", - __func__, match, - match->nhe->id, newhop); + zlog_debug( + "%s: CONNECT match %p (%pNG), newhop %pNHv", + __func__, match, match->nhe, newhop); return 1; } else if (CHECK_FLAG(flags, ZEBRA_FLAG_ALLOW_RECURSION)) { @@ -2302,9 +2293,9 @@ static int nexthop_active(struct nexthop *nexthop, struct nhg_hash_entry *nhe, /* Only useful if installed */ if (!CHECK_FLAG(match->status, ROUTE_ENTRY_INSTALLED)) { if (IS_ZEBRA_DEBUG_RIB_DETAILED) - zlog_debug("%s: match %p (%u) not installed", - __func__, match, - match->nhe->id); + zlog_debug( + "%s: match %p (%pNG) not installed", + __func__, match, match->nhe); goto done_with_match; } @@ -2319,9 +2310,10 @@ static int nexthop_active(struct nexthop *nexthop, struct nhg_hash_entry *nhe, continue; if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: RECURSIVE match %p (%u), newhop %pNHv", - __func__, match, - match->nhe->id, newhop); + zlog_debug( + "%s: RECURSIVE match %p (%pNG), newhop %pNHv", + __func__, match, match->nhe, + newhop); SET_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE); @@ -2355,9 +2347,10 @@ static int nexthop_active(struct nexthop *nexthop, struct nhg_hash_entry *nhe, continue; if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: RECURSIVE match backup %p (%u), newhop %pNHv", - __func__, match, - match->nhe->id, newhop); + zlog_debug( + "%s: RECURSIVE match backup %p (%pNG), newhop %pNHv", + __func__, match, match->nhe, + newhop); SET_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE); @@ -2702,9 +2695,8 @@ int nexthop_active_update(struct route_node *rn, struct route_entry *re) curr_nhe = zebra_nhe_copy(re->nhe, re->nhe->id); if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: re %p nhe %p (%u), curr_nhe %p", - __func__, re, re->nhe, re->nhe->id, - curr_nhe); + zlog_debug("%s: re %p nhe %p (%pNG), curr_nhe %p", __func__, re, + re->nhe, re->nhe, curr_nhe); /* Clear the existing id, if any: this will avoid any confusion * if the id exists, and will also force the creation @@ -2742,9 +2734,10 @@ backups_done: new_nhe = zebra_nhg_rib_find_nhe(curr_nhe, rt_afi); if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: re %p CHANGED: nhe %p (%u) => new_nhe %p (%u)", - __func__, re, re->nhe, - re->nhe->id, new_nhe, new_nhe->id); + zlog_debug( + "%s: re %p CHANGED: nhe %p (%pNG) => new_nhe %p (%pNG)", + __func__, re, re->nhe, re->nhe, new_nhe, + new_nhe); route_entry_update_nhe(re, new_nhe); } @@ -2803,8 +2796,8 @@ static uint8_t zebra_nhg_nhe2grp_internal(struct nh_grp *grp, if (!depend) { flog_err( EC_ZEBRA_NHG_FIB_UPDATE, - "Failed to recursively resolve Nexthop Hash Entry in the group id=%u", - nhe->id); + "Failed to recursively resolve Nexthop Hash Entry in the group id=%pNG", + nhe); continue; } } @@ -2909,8 +2902,8 @@ void zebra_nhg_install_kernel(struct nhg_hash_entry *nhe) case ZEBRA_DPLANE_REQUEST_FAILURE: flog_err( EC_ZEBRA_DP_INSTALL_FAIL, - "Failed to install Nexthop ID (%u) into the kernel", - nhe->id); + "Failed to install Nexthop ID (%pNG) into the kernel", + nhe); break; case ZEBRA_DPLANE_REQUEST_SUCCESS: SET_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED); @@ -2932,8 +2925,8 @@ void zebra_nhg_uninstall_kernel(struct nhg_hash_entry *nhe) case ZEBRA_DPLANE_REQUEST_FAILURE: flog_err( EC_ZEBRA_DP_DELETE_FAIL, - "Failed to uninstall Nexthop ID (%u) from the kernel", - nhe->id); + "Failed to uninstall Nexthop ID (%pNG) from the kernel", + nhe); break; case ZEBRA_DPLANE_REQUEST_SUCCESS: UNSET_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED); @@ -3006,8 +2999,8 @@ void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx) !PROTO_OWNED(nhe))) flog_err( EC_ZEBRA_DP_INSTALL_FAIL, - "Failed to install Nexthop ID (%u) into the kernel", - nhe->id); + "Failed to install Nexthop (%pNG) into the kernel", + nhe); } break; @@ -3358,14 +3351,14 @@ struct nhg_hash_entry *zebra_nhg_proto_del(uint32_t id, int type) if (nhe->refcnt > 1) { if (IS_ZEBRA_DEBUG_NHG) zlog_debug( - "%s: id %u, still being used by routes refcnt %u", - __func__, nhe->id, nhe->refcnt); + "%s: %pNG, still being used by routes refcnt %u", + __func__, nhe, nhe->refcnt); return nhe; } if (IS_ZEBRA_DEBUG_NHG_DETAIL) - zlog_debug("%s: deleted nhe %p (%u), vrf %d, type %s", __func__, - nhe, nhe->id, nhe->vrf_id, + zlog_debug("%s: deleted nhe %p (%pNG), vrf %d, type %s", + __func__, nhe, nhe, nhe->vrf_id, zebra_route_string(nhe->type)); return nhe; @@ -3388,8 +3381,8 @@ static void zebra_nhg_score_proto_entry(struct hash_bucket *bucket, void *arg) if (nhe->type == iter->type && PROTO_OWNED(nhe)) { if (IS_ZEBRA_DEBUG_NHG_DETAIL) zlog_debug( - "%s: found nhe %p (%u), vrf %d, type %s after client disconnect", - __func__, nhe, nhe->id, nhe->vrf_id, + "%s: found nhe %p (%pNG), vrf %d, type %s after client disconnect", + __func__, nhe, nhe, nhe->vrf_id, zebra_route_string(nhe->type)); /* Add to removal list */ @@ -3425,3 +3418,32 @@ unsigned long zebra_nhg_score_proto(int type) return count; } + +printfrr_ext_autoreg_p("NG", printfrr_nhghe); +static ssize_t printfrr_nhghe(struct fbuf *buf, struct printfrr_eargs *ea, + const void *ptr) +{ + const struct nhg_hash_entry *nhe = ptr; + const struct nhg_connected *dep; + ssize_t ret = 0; + + if (!nhe) + return bputs(buf, "[NULL]"); + + ret += bprintfrr(buf, "%u[", nhe->id); + if (nhe->ifp) + ret += printfrr_nhs(buf, nhe->nhg.nexthop); + else { + int count = zebra_nhg_depends_count(nhe); + + frr_each (nhg_connected_tree_const, &nhe->nhg_depends, dep) { + ret += bprintfrr(buf, "%u", dep->nhe->id); + if (count > 1) + ret += bputs(buf, "/"); + count--; + } + } + + ret += bputs(buf, "]"); + return ret; +} |
