This commit is contained in:
Chirag Shah 2025-04-29 16:20:41 +00:00 committed by GitHub
commit 06b1c86945
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 9 deletions

View file

@ -1077,24 +1077,27 @@ void nexthop_group_json_nexthop(json_object *j, const struct nexthop *nh)
switch (nh->type) { switch (nh->type) {
case NEXTHOP_TYPE_IFINDEX: case NEXTHOP_TYPE_IFINDEX:
json_object_string_add(j, "nexthop", json_object_string_add(j, "interfaceName",
ifindex2ifname(nh->ifindex, nh->vrf_id)); ifindex2ifname(nh->ifindex, nh->vrf_id));
json_object_int_add(j, "vrfId", nh->vrf_id);
break; break;
case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV4:
json_object_string_addf(j, "nexthop", "%pI4", &nh->gate.ipv4); json_object_string_addf(j, "nexthop", "%pI4", &nh->gate.ipv4);
break; break;
case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4_IFINDEX:
json_object_string_addf(j, "nexthop", "%pI4", &nh->gate.ipv4); json_object_string_addf(j, "nexthop", "%pI4", &nh->gate.ipv4);
json_object_string_add(j, "vrfId", json_object_string_add(j, "interfaceName",
ifindex2ifname(nh->ifindex, nh->vrf_id)); ifindex2ifname(nh->ifindex, nh->vrf_id));
json_object_int_add(j, "vrfId", nh->vrf_id);
break; break;
case NEXTHOP_TYPE_IPV6: case NEXTHOP_TYPE_IPV6:
json_object_string_addf(j, "nexthop", "%pI6", &nh->gate.ipv6); json_object_string_addf(j, "nexthop", "%pI6", &nh->gate.ipv6);
break; break;
case NEXTHOP_TYPE_IPV6_IFINDEX: case NEXTHOP_TYPE_IPV6_IFINDEX:
json_object_string_addf(j, "nexthop", "%pI6", &nh->gate.ipv6); json_object_string_addf(j, "nexthop", "%pI6", &nh->gate.ipv6);
json_object_string_add(j, "vrfId", json_object_string_add(j, "interfaceName",
ifindex2ifname(nh->ifindex, nh->vrf_id)); ifindex2ifname(nh->ifindex, nh->vrf_id));
json_object_int_add(j, "vrfId", nh->vrf_id);
break; break;
case NEXTHOP_TYPE_BLACKHOLE: case NEXTHOP_TYPE_BLACKHOLE:
break; break;

View file

@ -1402,6 +1402,7 @@ struct pbr_nht_show {
struct vty *vty; struct vty *vty;
json_object *json; json_object *json;
const char *name; const char *name;
uint16_t nhg_count;
}; };
static void pbr_nht_show_nhg(struct hash_bucket *b, void *data) static void pbr_nht_show_nhg(struct hash_bucket *b, void *data)
@ -1447,7 +1448,8 @@ static void pbr_nht_json_nhg(struct hash_bucket *b, void *data)
json_object_object_add(this_group, "nexthops", group_hops); json_object_object_add(this_group, "nexthops", group_hops);
} }
json_object_array_add(j, this_group); json_object_object_addf(j, this_group, "%u", pnhgc->table_id);
pns->nhg_count++;
} }
void pbr_nht_show_nexthop_group(struct vty *vty, const char *name) void pbr_nht_show_nexthop_group(struct vty *vty, const char *name)
@ -1460,14 +1462,17 @@ void pbr_nht_show_nexthop_group(struct vty *vty, const char *name)
hash_iterate(pbr_nhg_hash, pbr_nht_show_nhg, &pns); hash_iterate(pbr_nhg_hash, pbr_nht_show_nhg, &pns);
} }
void pbr_nht_json_nexthop_group(json_object *j, const char *name) void pbr_nht_json_nexthop_group(json_object *j, const char *name,
uint16_t *pbr_nhg_count)
{ {
struct pbr_nht_show pns; struct pbr_nht_show pns;
pns.name = name; pns.name = name;
pns.json = j; pns.json = j;
pns.nhg_count = 0;
hash_iterate(pbr_nhg_hash, pbr_nht_json_nhg, &pns); hash_iterate(pbr_nhg_hash, pbr_nht_json_nhg, &pns);
*pbr_nhg_count = pns.nhg_count;
} }
void pbr_nht_init(void) void pbr_nht_init(void)

View file

@ -126,7 +126,8 @@ extern char *pbr_nht_nexthop_make_name(char *name, size_t l, uint32_t seqno,
char *buffer); char *buffer);
extern void pbr_nht_show_nexthop_group(struct vty *vty, const char *name); extern void pbr_nht_show_nexthop_group(struct vty *vty, const char *name);
extern void pbr_nht_json_nexthop_group(json_object *j, const char *name); extern void pbr_nht_json_nexthop_group(json_object *j, const char *name,
uint16_t *pbr_nhg_count);
/* /*
* When we get a callback from zebra about a nexthop changing * When we get a callback from zebra about a nexthop changing

View file

@ -1865,13 +1865,14 @@ DEFPY(show_pbr_nexthop_group,
JSON_STR) JSON_STR)
{ {
json_object *j = NULL; json_object *j = NULL;
uint16_t pbr_nhg_count = 0;
if (json) if (json)
j = json_object_new_array(); j = json_object_new_object();
if (j) { if (j) {
pbr_nht_json_nexthop_group(j, word); pbr_nht_json_nexthop_group(j, word, &pbr_nhg_count);
json_object_int_add(j, "nhgCount", pbr_nhg_count);
vty_json(vty, j); vty_json(vty, j);
} else } else
pbr_nht_show_nexthop_group(vty, word); pbr_nht_show_nexthop_group(vty, word);