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) {
case NEXTHOP_TYPE_IFINDEX:
json_object_string_add(j, "nexthop",
json_object_string_add(j, "interfaceName",
ifindex2ifname(nh->ifindex, nh->vrf_id));
json_object_int_add(j, "vrfId", nh->vrf_id);
break;
case NEXTHOP_TYPE_IPV4:
json_object_string_addf(j, "nexthop", "%pI4", &nh->gate.ipv4);
break;
case NEXTHOP_TYPE_IPV4_IFINDEX:
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));
json_object_int_add(j, "vrfId", nh->vrf_id);
break;
case NEXTHOP_TYPE_IPV6:
json_object_string_addf(j, "nexthop", "%pI6", &nh->gate.ipv6);
break;
case NEXTHOP_TYPE_IPV6_IFINDEX:
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));
json_object_int_add(j, "vrfId", nh->vrf_id);
break;
case NEXTHOP_TYPE_BLACKHOLE:
break;

View file

@ -1402,6 +1402,7 @@ struct pbr_nht_show {
struct vty *vty;
json_object *json;
const char *name;
uint16_t nhg_count;
};
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_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)
@ -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);
}
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;
pns.name = name;
pns.json = j;
pns.nhg_count = 0;
hash_iterate(pbr_nhg_hash, pbr_nht_json_nhg, &pns);
*pbr_nhg_count = pns.nhg_count;
}
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);
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

View file

@ -1865,13 +1865,14 @@ DEFPY(show_pbr_nexthop_group,
JSON_STR)
{
json_object *j = NULL;
uint16_t pbr_nhg_count = 0;
if (json)
j = json_object_new_array();
j = json_object_new_object();
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);
} else
pbr_nht_show_nexthop_group(vty, word);