Skip to content

Commit

Permalink
zebra: apply the suggestion from frrbot
Browse files Browse the repository at this point in the history
Signed-off-by: Yamato Sugawara <yamato.sugawara@linecorp.com>
  • Loading branch information
Drumato committed Nov 3, 2021
1 parent ae1ac7f commit 0601e68
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -9213,14 +9213,10 @@ DEFPY (no_bgp_srv6_locator,
return CMD_SUCCESS;
}

DEFPY (show_bgp_srv6,
show_bgp_srv6_cmd,
"show bgp segment-routing srv6 [json]",
SHOW_STR
BGP_STR
"BGP Segment Routing\n"
"BGP Segment Routing SRv6\n"
JSON_STR)
DEFPY(show_bgp_srv6, show_bgp_srv6_cmd, "show bgp segment-routing srv6 [json]",
SHOW_STR BGP_STR
"BGP Segment Routing\n"
"BGP Segment Routing SRv6\n" JSON_STR)
{
struct bgp *bgp;
struct listnode *node;
Expand Down Expand Up @@ -9251,13 +9247,15 @@ DEFPY (show_bgp_srv6,
json_chunks = json_object_new_array();
json_functions = json_object_new_array();
json_bgps = json_object_new_array();
json_object_string_add(json, "locatorName", bgp->srv6_locator_name);
json_object_string_add(json, "locatorName",
bgp->srv6_locator_name);
json_object_object_add(json, "locatorChunks", json_chunks);
json_object_object_add(json, "functions", json_functions);
json_object_object_add(json, "bgps", json_bgps);

/* collect all chunk to json array*/
for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node,
chunk)) {
prefix2str(chunk, buf, sizeof(buf));
json_array_string_add(json_chunks, buf);
}
Expand All @@ -9268,23 +9266,27 @@ DEFPY (show_bgp_srv6,
json_object_array_add(json_functions, json_function);
inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
json_object_string_add(json_function, "Sid", buf);
json_object_string_add(json_function, "locator",
func->locator_name);
json_object_string_add(json_function, "locator",
func->locator_name);
}

/* collect all bgp instance to json array*/
for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
json_bgp = json_object_new_object();
json_object_array_add(json_bgps, json_bgp);
json_object_string_add(json_bgp, "name",
bgp->name ? bgp->name : "default");
bgp->name ? bgp->name
: "default");

json_vpn_policy = json_object_new_object();
json_vpn_policy_ip = json_object_new_object();
json_vpn_policy_ip6 = json_object_new_object();
json_object_object_add(json_bgp, "vpnPolicy", json_vpn_policy);
json_object_object_add(json_vpn_policy, "ip", json_vpn_policy_ip);
json_object_object_add(json_vpn_policy, "ip6", json_vpn_policy_ip6);
json_object_object_add(json_bgp, "vpnPolicy",
json_vpn_policy);
json_object_object_add(json_vpn_policy, "ip",
json_vpn_policy_ip);
json_object_object_add(json_vpn_policy, "ip6",
json_vpn_policy_ip6);

tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
Expand All @@ -9294,20 +9296,24 @@ DEFPY (show_bgp_srv6,
if (tovpn6_sid)
inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
sizeof(buf_tovpn6_sid));

json_object_string_add(json_vpn_policy_ip, "toVpnSid",
tovpn4_sid ? buf_tovpn4_sid : "none");
tovpn4_sid ? buf_tovpn4_sid
: "none");
json_object_string_add(json_vpn_policy_ip6, "toVpnSid",
tovpn6_sid ? buf_tovpn6_sid : "none");
tovpn6_sid ? buf_tovpn6_sid
: "none");
}

vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
vty_out(vty, "%s\n",
json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
} else {
vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
vty_out(vty, "locator_chunks:\n");
for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node,
chunk)) {
prefix2str(chunk, buf, sizeof(buf));
vty_out(vty, "- %s\n", buf);
}
Expand Down

0 comments on commit 0601e68

Please sign in to comment.