diff options
author | Philippe Guibert <philippe.guibert@6wind.com> | 2022-11-18 13:49:53 +0100 |
---|---|---|
committer | Philippe Guibert <philippe.guibert@6wind.com> | 2023-02-10 10:27:23 +0100 |
commit | e84c7c12f224f27ae430f2929a9fd121b133c2b3 (patch) | |
tree | 4957646b5b93635e3b9cab8281f591cda750a89d | |
parent | bgpd: aspath list format binds on as-notation format (diff) | |
download | frr-e84c7c12f224f27ae430f2929a9fd121b133c2b3.tar.xz frr-e84c7c12f224f27ae430f2929a9fd121b133c2b3.zip |
bgpd: modify bgp as number output
A json AS number API is created in order to output a
given AS number. In order to keep backward compatibility,
if the as-notation uses a number, then the json is encoded
as an integer, otherwise the encoding will be a string.
For what is not relevant to running-configuration, the
as-notation mode is the one used for the BGP instance.
Also, the vty completion gets the configured 'as_pretty'
string value, when an user wants to get the available
BGP instances.
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
-rw-r--r-- | bgpd/bgp_evpn_vty.c | 6 | ||||
-rw-r--r-- | bgpd/bgp_route.c | 20 | ||||
-rw-r--r-- | bgpd/bgp_vty.c | 7 | ||||
-rw-r--r-- | bgpd/bgpd.c | 4 | ||||
-rw-r--r-- | lib/asn.c | 14 | ||||
-rw-r--r-- | lib/asn.h | 2 |
6 files changed, 41 insertions, 12 deletions
diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index 6b63c6e3a..067ad525c 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -1345,9 +1345,9 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd, json, "defaultLocPrf", bgp->default_local_pref); - json_object_int_add( - json, "localAS", - bgp->as); + asn_asn2json(json, "localAS", + bgp->as, + bgp->asnotation); } else { if (option == SHOW_DISPLAY_TAGS) vty_out(vty, diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 32de9e302..9d9422b36 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -11190,17 +11190,26 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, vty_out(vty, "{\n"); *json_header_depth = 2; } - vty_out(vty, " \"vrfId\": %d,\n \"vrfName\": \"%s\",\n \"tableVersion\": %" PRId64 ",\n \"routerId\": \"%pI4\",\n \"defaultLocPrf\": %u,\n" - " \"localAS\": %u,\n \"routes\": { ", + " \"localAS\": ", bgp->vrf_id == VRF_UNKNOWN ? -1 : (int)bgp->vrf_id, bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ? VRF_DEFAULT_NAME : bgp->name, table->version, &bgp->router_id, - bgp->default_local_pref, bgp->as); + bgp->default_local_pref); + if ((bgp->asnotation == ASNOTATION_PLAIN) || + ((bgp->asnotation == ASNOTATION_DOT) && + (bgp->as < UINT16_MAX))) + vty_out(vty, "%u", bgp->as); + else { + vty_out(vty, "\""); + vty_out(vty, ASN_FORMAT(bgp->asnotation), &bgp->as); + vty_out(vty, "\""); + } + vty_out(vty, ",\n \"routes\": { "); if (rd) { vty_out(vty, " \"routeDistinguishers\" : {"); ++*json_header_depth; @@ -11474,7 +11483,10 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, vty_out(vty, "\n"); vty_out(vty, "Default local pref %u, ", bgp->default_local_pref); - vty_out(vty, "local AS %u\n", bgp->as); + vty_out(vty, "local AS "); + vty_out(vty, ASN_FORMAT(bgp->asnotation), + &bgp->as); + vty_out(vty, "\n"); if (!detail_routes) { vty_out(vty, BGP_SHOW_SCODE_HEADER); vty_out(vty, BGP_SHOW_NCODE_HEADER); diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index a1fda80ad..29fc22655 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -11161,7 +11161,8 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, json_object_string_addf(json, "routerId", "%pI4", &bgp->router_id); - json_object_int_add(json, "as", bgp->as); + asn_asn2json(json, "as", bgp->as, + bgp->asnotation); json_object_int_add(json, "vrfId", vrf_id_ui); json_object_string_add( json, "vrfName", @@ -16003,8 +16004,8 @@ static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group, group->name, conf->as); } else if (conf->as_type == AS_INTERNAL) { if (json) - json_object_int_add(json_peer_group, "remoteAs", - group->bgp->as); + asn_asn2json(json, "remoteAs", group->bgp->as, + group->bgp->asnotation); else vty_out(vty, "\nBGP peer-group %s, remote AS %s\n", group->name, group->bgp->as_pretty); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 6b8c17da8..5da156ba6 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -8030,7 +8030,7 @@ static void bgp_instasn_autocomplete(vector comps, struct cmd_token *token) { struct listnode *next, *next2; struct bgp *bgp, *bgp2; - char buf[11]; + char buf[ASN_STRING_MAX_SIZE]; for (ALL_LIST_ELEMENTS_RO(bm->bgp, next, bgp)) { /* deduplicate */ @@ -8043,7 +8043,7 @@ static void bgp_instasn_autocomplete(vector comps, struct cmd_token *token) if (bgp2 != bgp) continue; - snprintf(buf, sizeof(buf), "%u", bgp->as); + snprintf(buf, sizeof(buf), "%s", bgp->as_pretty); vector_set(comps, XSTRDUP(MTYPE_COMPLETION, buf)); } } @@ -183,6 +183,20 @@ const char *asn_mode2str(enum asnotation_mode asnotation) "Unrecognized AS notation mode"); } +void asn_asn2json(json_object *json, const char *attr, + as_t asn, enum asnotation_mode asnotation) +{ + static char as_str[ASN_STRING_MAX_SIZE]; + + if ((asnotation == ASNOTATION_PLAIN) || + ((asnotation == ASNOTATION_DOT) && asn < UINT16_MAX)) + json_object_int_add(json, attr, asn); + else { + asn_asn2asdot(asn, as_str, sizeof(as_str)); + json_object_string_add(json, attr, as_str); + } +} + void asn_asn2json_array(json_object *jseg_list, as_t asn, enum asnotation_mode asnotation) { @@ -51,6 +51,8 @@ extern bool asn_str2asn_notation(const char *asstring, as_t *asn, extern const char *asn_mode2str(enum asnotation_mode asnotation); void asn_asn2json_array(json_object *jseg_list, as_t asn, enum asnotation_mode asnotation); +void asn_asn2json(json_object *jseg_list, const char *attr, + as_t asn, enum asnotation_mode asnotation); /* display AS in appropriate format */ #ifdef _FRR_ATTRIBUTE_PRINTFRR #pragma FRR printfrr_ext "%pASP" (as_t *) |