summaryrefslogtreecommitdiff
path: root/bgpd/bgp_vty.c
diff options
context:
space:
mode:
Diffstat (limited to 'bgpd/bgp_vty.c')
-rw-r--r--bgpd/bgp_vty.c178
1 files changed, 92 insertions, 86 deletions
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index 3725f242e1..8a63030181 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -645,10 +645,7 @@ int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
json_object_string_add(
json, "warning",
"View/Vrf is unknown");
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(json,
- JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
+ vty_json(vty, json);
}
else
vty_out(vty, "View/Vrf %s is unknown\n",
@@ -666,10 +663,7 @@ int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
json_object_string_add(
json, "warning",
"Default BGP instance not found");
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(json,
- JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
+ vty_json(vty, json);
}
else
vty_out(vty,
@@ -6308,6 +6302,30 @@ DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
}
+/* extended-optional-parameters */
+DEFUN(neighbor_extended_optional_parameters,
+ neighbor_extended_optional_parameters_cmd,
+ "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
+ NEIGHBOR_STR NEIGHBOR_ADDR_STR2
+ "Force the extended optional parameters format for OPEN messages\n")
+{
+ int idx_peer = 1;
+
+ return peer_flag_set_vty(vty, argv[idx_peer]->arg,
+ PEER_FLAG_EXTENDED_OPT_PARAMS);
+}
+
+DEFUN(no_neighbor_extended_optional_parameters,
+ no_neighbor_extended_optional_parameters_cmd,
+ "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
+ NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
+ "Force the extended optional parameters format for OPEN messages\n")
+{
+ int idx_peer = 2;
+
+ return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
+ PEER_FLAG_EXTENDED_OPT_PARAMS);
+}
/* enforce-first-as */
DEFUN (neighbor_enforce_first_as,
@@ -9690,10 +9708,8 @@ DEFUN (show_bgp_vrfs,
json_object_string_add(json_vrf, "type", type);
json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
- json_object_string_add(json_vrf, "routerId",
- inet_ntop(AF_INET,
- &bgp->router_id, buf,
- sizeof(buf)));
+ json_object_string_addf(json_vrf, "routerId", "%pI4",
+ &bgp->router_id);
json_object_int_add(json_vrf, "numConfiguredPeers",
peers_cfg);
json_object_int_add(json_vrf, "numEstablishedPeers",
@@ -9726,9 +9742,7 @@ DEFUN (show_bgp_vrfs,
json_object_int_add(json, "totalVrfs", count);
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
+ vty_json(vty, json);
} else {
if (count)
vty_out(vty,
@@ -10260,9 +10274,7 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
json_object_int_add(json, "dynamicPeers", dn_count);
json_object_int_add(json, "totalPeers", count);
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
+ vty_json(vty, json);
} else {
vty_out(vty, "%% No failed BGP neighbors found\n");
}
@@ -10290,12 +10302,9 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
/* Usage summary and header */
if (use_json) {
- char buf[BUFSIZ] = {0};
-
- json_object_string_add(
- json, "routerId",
- inet_ntop(AF_INET, &bgp->router_id, buf,
- sizeof(buf)));
+ json_object_string_addf(json, "routerId",
+ "%pI4",
+ &bgp->router_id);
json_object_int_add(json, "as", bgp->as);
json_object_int_add(json, "vrfId", vrf_id_ui);
json_object_string_add(
@@ -10834,9 +10843,7 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
if (!show_failed)
bgp_show_bestpath_json(bgp, json);
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
+ vty_json(vty, json);
} else {
if (count) {
if (filtered_count == count)
@@ -12368,10 +12375,10 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
p->group, &prefix);
if (range) {
- prefix2str(range, buf1, sizeof(buf1));
- json_object_string_add(
+ json_object_string_addf(
json_neigh,
- "peerSubnetRangeGroup", buf1);
+ "peerSubnetRangeGroup", "%pFX",
+ range);
}
}
} else {
@@ -12404,13 +12411,10 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
/* BGP Version. */
json_object_int_add(json_neigh, "bgpVersion", 4);
- json_object_string_add(
- json_neigh, "remoteRouterId",
- inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
- json_object_string_add(
- json_neigh, "localRouterId",
- inet_ntop(AF_INET, &bgp->router_id, buf1,
- sizeof(buf1)));
+ json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
+ &p->remote_id);
+ json_object_string_addf(json_neigh, "localRouterId", "%pI4",
+ &bgp->router_id);
/* Confederation */
if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
@@ -12517,6 +12521,14 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
"bgpTimerConfiguredKeepAliveIntervalMsecs",
bgp->default_keepalive);
}
+
+ /* Extended Optional Parameters Length for BGP OPEN Message */
+ if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
+ json_object_boolean_true_add(
+ json_neigh, "extendedOptionalParametersLength");
+ else
+ json_object_boolean_false_add(
+ json_neigh, "extendedOptionalParametersLength");
} else {
/* Administrative shutdown. */
if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
@@ -12589,6 +12601,11 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
}
+
+ /* Extended Optional Parameters Length for BGP OPEN Message */
+ if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
+ vty_out(vty,
+ " Extended Optional Parameters Length is enabled\n");
}
/* Capability. */
if (peer_established(p)) {
@@ -13999,18 +14016,12 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
/* Nexthop display. */
if (p->su_local) {
if (use_json) {
- json_object_string_add(json_neigh, "nexthop",
- inet_ntop(AF_INET,
- &p->nexthop.v4, buf1,
- sizeof(buf1)));
- json_object_string_add(json_neigh, "nexthopGlobal",
- inet_ntop(AF_INET6,
- &p->nexthop.v6_global,
- buf1, sizeof(buf1)));
- json_object_string_add(json_neigh, "nexthopLocal",
- inet_ntop(AF_INET6,
- &p->nexthop.v6_local,
- buf1, sizeof(buf1)));
+ json_object_string_addf(json_neigh, "nexthop", "%pI4",
+ &p->nexthop.v4);
+ json_object_string_addf(json_neigh, "nexthopGlobal",
+ "%pI6", &p->nexthop.v6_global);
+ json_object_string_addf(json_neigh, "nexthopLocal",
+ "%pI6", &p->nexthop.v6_local);
if (p->shared_network)
json_object_string_add(json_neigh,
"bgpConnection",
@@ -14192,13 +14203,9 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
vty_out(vty, "%% No such neighbor\n");
}
if (use_json) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
-
if (json_neighbor)
json_object_free(json_neighbor);
- json_object_free(json);
+ vty_json(vty, json);
} else {
vty_out(vty, "\n");
}
@@ -14438,11 +14445,7 @@ static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
if (!bgp) {
if (use_json) {
json = json_object_new_object();
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json,
- JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
+ vty_json(vty, json);
} else
vty_out(vty,
"%% BGP instance not found\n");
@@ -14751,11 +14754,7 @@ static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
if (!bgp) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json,
- JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
+ vty_json(vty, json);
return CMD_WARNING;
}
@@ -14827,10 +14826,7 @@ static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
}
if (use_json) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(json,
- JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
+ vty_json(vty, json);
}
} else {
bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
@@ -14942,9 +14938,7 @@ static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
if (use_json) {
json_object_object_add(json, "vrfs", json_vrfs);
- vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
- JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
+ vty_json(vty, json);
}
return CMD_SUCCESS;
@@ -14989,9 +14983,8 @@ DEFUN (show_ip_bgp_route_leak,
vrf = NULL;
}
/* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
- if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
+ if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
argv_find_and_parse_safi(argv, argc, &idx, &safi);
- }
if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
vty_out(vty,
@@ -15423,14 +15416,10 @@ static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
if (!bgp) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else {
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% BGP instance not found\n");
- }
return CMD_WARNING;
}
@@ -15450,12 +15439,8 @@ static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
if (group_name && !found && !uj)
vty_out(vty, "%% No such peer-group\n");
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return CMD_SUCCESS;
}
@@ -16688,6 +16673,11 @@ static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
addr);
+ /* extended-optional-parameters */
+ if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
+ vty_out(vty, " neighbor %s extended-optional-parameters\n",
+ addr);
+
/* enforce-first-as */
if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
vty_out(vty, " neighbor %s enforce-first-as\n", addr);
@@ -17593,6 +17583,7 @@ static struct cmd_node bgp_ipv4_unicast_node = {
.node = BGP_IPV4_NODE,
.parent_node = BGP_NODE,
.prompt = "%s(config-router-af)# ",
+ .no_xpath = true,
};
static struct cmd_node bgp_ipv4_multicast_node = {
@@ -17600,6 +17591,7 @@ static struct cmd_node bgp_ipv4_multicast_node = {
.node = BGP_IPV4M_NODE,
.parent_node = BGP_NODE,
.prompt = "%s(config-router-af)# ",
+ .no_xpath = true,
};
static struct cmd_node bgp_ipv4_labeled_unicast_node = {
@@ -17607,6 +17599,7 @@ static struct cmd_node bgp_ipv4_labeled_unicast_node = {
.node = BGP_IPV4L_NODE,
.parent_node = BGP_NODE,
.prompt = "%s(config-router-af)# ",
+ .no_xpath = true,
};
static struct cmd_node bgp_ipv6_unicast_node = {
@@ -17614,6 +17607,7 @@ static struct cmd_node bgp_ipv6_unicast_node = {
.node = BGP_IPV6_NODE,
.parent_node = BGP_NODE,
.prompt = "%s(config-router-af)# ",
+ .no_xpath = true,
};
static struct cmd_node bgp_ipv6_multicast_node = {
@@ -17621,6 +17615,7 @@ static struct cmd_node bgp_ipv6_multicast_node = {
.node = BGP_IPV6M_NODE,
.parent_node = BGP_NODE,
.prompt = "%s(config-router-af)# ",
+ .no_xpath = true,
};
static struct cmd_node bgp_ipv6_labeled_unicast_node = {
@@ -17628,6 +17623,7 @@ static struct cmd_node bgp_ipv6_labeled_unicast_node = {
.node = BGP_IPV6L_NODE,
.parent_node = BGP_NODE,
.prompt = "%s(config-router-af)# ",
+ .no_xpath = true,
};
static struct cmd_node bgp_vpnv4_node = {
@@ -17635,6 +17631,7 @@ static struct cmd_node bgp_vpnv4_node = {
.node = BGP_VPNV4_NODE,
.parent_node = BGP_NODE,
.prompt = "%s(config-router-af)# ",
+ .no_xpath = true,
};
static struct cmd_node bgp_vpnv6_node = {
@@ -17642,6 +17639,7 @@ static struct cmd_node bgp_vpnv6_node = {
.node = BGP_VPNV6_NODE,
.parent_node = BGP_NODE,
.prompt = "%s(config-router-af-vpnv6)# ",
+ .no_xpath = true,
};
static struct cmd_node bgp_evpn_node = {
@@ -17649,6 +17647,7 @@ static struct cmd_node bgp_evpn_node = {
.node = BGP_EVPN_NODE,
.parent_node = BGP_NODE,
.prompt = "%s(config-router-evpn)# ",
+ .no_xpath = true,
};
static struct cmd_node bgp_evpn_vni_node = {
@@ -17663,6 +17662,7 @@ static struct cmd_node bgp_flowspecv4_node = {
.node = BGP_FLOWSPECV4_NODE,
.parent_node = BGP_NODE,
.prompt = "%s(config-router-af)# ",
+ .no_xpath = true,
};
static struct cmd_node bgp_flowspecv6_node = {
@@ -17670,6 +17670,7 @@ static struct cmd_node bgp_flowspecv6_node = {
.node = BGP_FLOWSPECV6_NODE,
.parent_node = BGP_NODE,
.prompt = "%s(config-router-af-vpnv6)# ",
+ .no_xpath = true,
};
static struct cmd_node bgp_srv6_node = {
@@ -18634,6 +18635,11 @@ void bgp_vty_init(void)
install_element(BGP_NODE,
&no_neighbor_disable_link_bw_encoding_ieee_cmd);
+ /* "neighbor extended-optional-parameters" commands. */
+ install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
+ install_element(BGP_NODE,
+ &no_neighbor_extended_optional_parameters_cmd);
+
/* "neighbor enforce-first-as" commands. */
install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);