]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
doc: extend documentation of SRv6 locator
[mirror_frr.git] / bgpd / bgp_vty.c
CommitLineData
718e3744 1/* BGP VTY interface.
896014f4
DL
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 20
21#include <zebra.h>
22
23#include "command.h"
afec25d9 24#include "lib/json.h"
4ab46701 25#include "lib/sockopt.h"
5cb5f4d0 26#include "lib_errors.h"
ec0ab544 27#include "lib/zclient.h"
6f4eacf3 28#include "lib/printfrr.h"
718e3744 29#include "prefix.h"
30#include "plist.h"
31#include "buffer.h"
32#include "linklist.h"
33#include "stream.h"
34#include "thread.h"
35#include "log.h"
3b8b1855 36#include "memory.h"
1c0d8808 37#include "lib_vty.h"
4bf6a362 38#include "hash.h"
3f9c7369 39#include "queue.h"
039f3a34 40#include "filter.h"
5d5ba018 41#include "frrstr.h"
718e3744 42
43#include "bgpd/bgpd.h"
48ecf8f5 44#include "bgpd/bgp_attr_evpn.h"
4bf6a362 45#include "bgpd/bgp_advertise.h"
718e3744 46#include "bgpd/bgp_attr.h"
47#include "bgpd/bgp_aspath.h"
48#include "bgpd/bgp_community.h"
ed0e57e3 49#include "bgpd/bgp_community_alias.h"
4bf6a362 50#include "bgpd/bgp_ecommunity.h"
57d187bc 51#include "bgpd/bgp_lcommunity.h"
4bf6a362 52#include "bgpd/bgp_damp.h"
718e3744 53#include "bgpd/bgp_debug.h"
14454c9f 54#include "bgpd/bgp_errors.h"
e0701b79 55#include "bgpd/bgp_fsm.h"
4cd690ae 56#include "bgpd/bgp_nht.h"
4bf6a362 57#include "bgpd/bgp_nexthop.h"
4122b697 58#include "bgpd/bgp_network.h"
718e3744 59#include "bgpd/bgp_open.h"
4bf6a362 60#include "bgpd/bgp_regex.h"
718e3744 61#include "bgpd/bgp_route.h"
c016b6c7 62#include "bgpd/bgp_mplsvpn.h"
718e3744 63#include "bgpd/bgp_zebra.h"
fee0f4c6 64#include "bgpd/bgp_table.h"
94f2b392 65#include "bgpd/bgp_vty.h"
165b5fff 66#include "bgpd/bgp_mpath.h"
cb1faec9 67#include "bgpd/bgp_packet.h"
3f9c7369 68#include "bgpd/bgp_updgrp.h"
c43ed2e4 69#include "bgpd/bgp_bfd.h"
555e09d4 70#include "bgpd/bgp_io.h"
94c2f693 71#include "bgpd/bgp_evpn.h"
dd65f45e 72#include "bgpd/bgp_evpn_vty.h"
b5e140c8 73#include "bgpd/bgp_evpn_mh.h"
dcc68b5e 74#include "bgpd/bgp_addpath.h"
48ecf8f5 75#include "bgpd/bgp_mac.h"
dd65f45e 76#include "bgpd/bgp_flowspec.h"
389e4f92 77#include "bgpd/bgp_conditional_adv.h"
49e5a4a0 78#ifdef ENABLE_BGP_VNC
dd65f45e
DL
79#include "bgpd/rfapi/bgp_rfapi_cfg.h"
80#endif
70cd87ca
MK
81#include "bgpd/bgp_orr.h"
82
dd65f45e 83
5d5393b9 84FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
62282e83
DS
85 {
86 .val_bool = false,
87 .match_profile = "traditional",
88 .match_version = "< 7.4",
89 },
90 { .val_bool = true },
67b0f40c 91);
5d5393b9 92FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
4c1458b5
DL
93 { .val_bool = true, .match_profile = "datacenter", },
94 { .val_bool = false },
67b0f40c 95);
aef999a2
DA
96FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
97 { .val_bool = true, .match_profile = "datacenter", },
98 { .val_bool = false },
67b0f40c 99);
5d5393b9 100FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
4c1458b5
DL
101 { .val_bool = true, .match_profile = "datacenter", },
102 { .val_bool = false },
67b0f40c 103);
5d5393b9 104FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
4c1458b5
DL
105 { .val_bool = true, .match_profile = "datacenter", },
106 { .val_bool = false },
67b0f40c 107);
5d5393b9
DL
108FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
109 { .val_ulong = 10, .match_profile = "datacenter", },
110 { .val_ulong = 120 },
67b0f40c 111);
5d5393b9
DL
112FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
113 { .val_ulong = 9, .match_profile = "datacenter", },
114 { .val_ulong = 180 },
67b0f40c 115);
5d5393b9
DL
116FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
117 { .val_ulong = 3, .match_profile = "datacenter", },
118 { .val_ulong = 60 },
67b0f40c 119);
1d3fdccf
DA
120FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
121 { .val_bool = false, .match_profile = "datacenter", },
122 { .val_bool = false, .match_version = "< 7.4", },
123 { .val_bool = true },
67b0f40c 124);
2adac256
DA
125FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
126 { .val_bool = false, .match_version = "< 7.6", },
127 { .val_bool = true },
67b0f40c 128);
f2ca5c5b
DA
129FRR_CFG_DEFAULT_BOOL(BGP_GRACEFUL_NOTIFICATION,
130 { .val_bool = false, .match_version = "< 8.3", },
131 { .val_bool = true },
132);
1ae314be
DA
133FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET,
134 { .val_bool = false, .match_version = "< 8.3", },
135 { .val_bool = true },
136);
5d5393b9 137
dd65f45e
DL
138DEFINE_HOOK(bgp_inst_config_write,
139 (struct bgp *bgp, struct vty *vty),
8451921b
DL
140 (bgp, vty));
141DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
1ca2fd11 142DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
718e3744 143
d62a17ae 144static struct peer_group *listen_range_exists(struct bgp *bgp,
145 struct prefix *range, int exact);
146
055679e9 147/* Show BGP peer's information. */
148enum show_type {
149 show_all,
150 show_peer,
151 show_ipv4_all,
152 show_ipv6_all,
153 show_ipv4_peer,
154 show_ipv6_peer
155};
156
36235319
QY
157static struct peer_group *listen_range_exists(struct bgp *bgp,
158 struct prefix *range, int exact);
2986cac2 159
36235319
QY
160static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
161 struct bgp *bgp,
162 bool use_json,
163 json_object *json);
2986cac2 164
36235319
QY
165static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
166 enum show_type type,
167 const char *ip_str,
168 afi_t afi, bool use_json);
2986cac2 169
d62a17ae 170static enum node_type bgp_node_type(afi_t afi, safi_t safi)
171{
172 switch (afi) {
173 case AFI_IP:
174 switch (safi) {
175 case SAFI_UNICAST:
176 return BGP_IPV4_NODE;
d62a17ae 177 case SAFI_MULTICAST:
178 return BGP_IPV4M_NODE;
d62a17ae 179 case SAFI_LABELED_UNICAST:
180 return BGP_IPV4L_NODE;
d62a17ae 181 case SAFI_MPLS_VPN:
182 return BGP_VPNV4_NODE;
7c40bf39 183 case SAFI_FLOWSPEC:
184 return BGP_FLOWSPECV4_NODE;
5c525538
RW
185 default:
186 /* not expected */
187 return BGP_IPV4_NODE;
d62a17ae 188 }
d62a17ae 189 case AFI_IP6:
190 switch (safi) {
191 case SAFI_UNICAST:
192 return BGP_IPV6_NODE;
d62a17ae 193 case SAFI_MULTICAST:
194 return BGP_IPV6M_NODE;
d62a17ae 195 case SAFI_LABELED_UNICAST:
196 return BGP_IPV6L_NODE;
d62a17ae 197 case SAFI_MPLS_VPN:
198 return BGP_VPNV6_NODE;
7c40bf39 199 case SAFI_FLOWSPEC:
200 return BGP_FLOWSPECV6_NODE;
5c525538
RW
201 default:
202 /* not expected */
203 return BGP_IPV4_NODE;
d62a17ae 204 }
d62a17ae 205 case AFI_L2VPN:
206 return BGP_EVPN_NODE;
b26f891d 207 case AFI_UNSPEC:
d62a17ae 208 case AFI_MAX:
209 // We should never be here but to clarify the switch statement..
210 return BGP_IPV4_NODE;
d62a17ae 211 }
212
213 // Impossible to happen
214 return BGP_IPV4_NODE;
f51bae9c 215}
20eb8864 216
5cb5f4d0
DD
217static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
218{
7d0d37de
DS
219 if (afi == AFI_IP) {
220 if (safi == SAFI_UNICAST)
221 return "IPv4 Unicast";
222 if (safi == SAFI_MULTICAST)
223 return "IPv4 Multicast";
224 if (safi == SAFI_LABELED_UNICAST)
225 return "IPv4 Labeled Unicast";
226 if (safi == SAFI_MPLS_VPN)
227 return "IPv4 VPN";
228 if (safi == SAFI_ENCAP)
229 return "IPv4 Encap";
230 if (safi == SAFI_FLOWSPEC)
231 return "IPv4 Flowspec";
232 } else if (afi == AFI_IP6) {
233 if (safi == SAFI_UNICAST)
234 return "IPv6 Unicast";
235 if (safi == SAFI_MULTICAST)
236 return "IPv6 Multicast";
237 if (safi == SAFI_LABELED_UNICAST)
238 return "IPv6 Labeled Unicast";
239 if (safi == SAFI_MPLS_VPN)
240 return "IPv6 VPN";
241 if (safi == SAFI_ENCAP)
242 return "IPv6 Encap";
243 if (safi == SAFI_FLOWSPEC)
244 return "IPv6 Flowspec";
245 } else if (afi == AFI_L2VPN) {
246 if (safi == SAFI_EVPN)
247 return "L2VPN EVPN";
248 }
249
250 return "Unknown";
5cb5f4d0
DD
251}
252
253/*
254 * Please note that we have intentionally camelCased
255 * the return strings here. So if you want
256 * to use this function, please ensure you
257 * are doing this within json output
258 */
259static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
260{
7d0d37de
DS
261 if (afi == AFI_IP) {
262 if (safi == SAFI_UNICAST)
263 return "ipv4Unicast";
264 if (safi == SAFI_MULTICAST)
265 return "ipv4Multicast";
266 if (safi == SAFI_LABELED_UNICAST)
267 return "ipv4LabeledUnicast";
268 if (safi == SAFI_MPLS_VPN)
269 return "ipv4Vpn";
270 if (safi == SAFI_ENCAP)
271 return "ipv4Encap";
272 if (safi == SAFI_FLOWSPEC)
273 return "ipv4Flowspec";
274 } else if (afi == AFI_IP6) {
275 if (safi == SAFI_UNICAST)
276 return "ipv6Unicast";
277 if (safi == SAFI_MULTICAST)
278 return "ipv6Multicast";
279 if (safi == SAFI_LABELED_UNICAST)
280 return "ipv6LabeledUnicast";
281 if (safi == SAFI_MPLS_VPN)
282 return "ipv6Vpn";
283 if (safi == SAFI_ENCAP)
284 return "ipv6Encap";
285 if (safi == SAFI_FLOWSPEC)
286 return "ipv6Flowspec";
287 } else if (afi == AFI_L2VPN) {
288 if (safi == SAFI_EVPN)
289 return "l2VpnEvpn";
290 }
291
292 return "Unknown";
5cb5f4d0
DD
293}
294
0249b8b6
HS
295/* unset srv6 locator */
296static int bgp_srv6_locator_unset(struct bgp *bgp)
297{
298 int ret;
299 struct listnode *node, *nnode;
bee2e7d0 300 struct srv6_locator_chunk *chunk, *tovpn_sid_locator;
0249b8b6
HS
301 struct bgp_srv6_function *func;
302 struct bgp *bgp_vrf;
0249b8b6
HS
303
304 /* release chunk notification via ZAPI */
305 ret = bgp_zebra_srv6_manager_release_locator_chunk(
306 bgp->srv6_locator_name);
307 if (ret < 0)
308 return -1;
309
310 /* refresh chunks */
03852f67 311 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
0249b8b6 312 listnode_delete(bgp->srv6_locator_chunks, chunk);
03852f67
CS
313 srv6_locator_chunk_free(chunk);
314 }
0249b8b6
HS
315
316 /* refresh functions */
bda15542 317 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
0249b8b6 318 listnode_delete(bgp->srv6_functions, func);
bda15542
CS
319 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
320 }
0249b8b6
HS
321
322 /* refresh tovpn_sid */
323 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
324 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
325 continue;
326
327 /* refresh vpnv4 tovpn_sid */
944909f4
CS
328 XFREE(MTYPE_BGP_SRV6_SID,
329 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
0249b8b6
HS
330
331 /* refresh vpnv6 tovpn_sid */
944909f4
CS
332 XFREE(MTYPE_BGP_SRV6_SID,
333 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
527588aa
CS
334
335 /* refresh per-vrf tovpn_sid */
336 XFREE(MTYPE_BGP_SRV6_SID, bgp_vrf->tovpn_sid);
0249b8b6
HS
337 }
338
339 /* update vpn bgp processes */
340 vpn_leak_postchange_all();
341
f8e9c702
CS
342 /* refresh tovpn_sid_locator */
343 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
344 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
345 continue;
346
347 /* refresh vpnv4 tovpn_sid_locator */
bee2e7d0
RS
348 tovpn_sid_locator =
349 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator;
350 if (tovpn_sid_locator) {
351 srv6_locator_chunk_free(tovpn_sid_locator);
352 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator = NULL;
353 }
f8e9c702
CS
354
355 /* refresh vpnv6 tovpn_sid_locator */
bee2e7d0
RS
356 tovpn_sid_locator =
357 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator;
358 if (tovpn_sid_locator) {
359 srv6_locator_chunk_free(tovpn_sid_locator);
360 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator = NULL;
361 }
527588aa
CS
362
363 /* refresh per-vrf tovpn_sid_locator */
364 srv6_locator_chunk_free(bgp_vrf->tovpn_sid_locator);
f8e9c702
CS
365 }
366
0249b8b6
HS
367 /* clear locator name */
368 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
369
370 return 0;
371}
372
718e3744 373/* Utility function to get address family from current node. */
d62a17ae 374afi_t bgp_node_afi(struct vty *vty)
375{
376 afi_t afi;
377 switch (vty->node) {
378 case BGP_IPV6_NODE:
379 case BGP_IPV6M_NODE:
380 case BGP_IPV6L_NODE:
381 case BGP_VPNV6_NODE:
7c40bf39 382 case BGP_FLOWSPECV6_NODE:
d62a17ae 383 afi = AFI_IP6;
384 break;
385 case BGP_EVPN_NODE:
386 afi = AFI_L2VPN;
387 break;
388 default:
389 afi = AFI_IP;
390 break;
391 }
392 return afi;
718e3744 393}
394
395/* Utility function to get subsequent address family from current
396 node. */
d62a17ae 397safi_t bgp_node_safi(struct vty *vty)
398{
399 safi_t safi;
400 switch (vty->node) {
401 case BGP_VPNV4_NODE:
402 case BGP_VPNV6_NODE:
403 safi = SAFI_MPLS_VPN;
404 break;
405 case BGP_IPV4M_NODE:
406 case BGP_IPV6M_NODE:
407 safi = SAFI_MULTICAST;
408 break;
409 case BGP_EVPN_NODE:
410 safi = SAFI_EVPN;
411 break;
412 case BGP_IPV4L_NODE:
413 case BGP_IPV6L_NODE:
414 safi = SAFI_LABELED_UNICAST;
415 break;
7c40bf39 416 case BGP_FLOWSPECV4_NODE:
417 case BGP_FLOWSPECV6_NODE:
418 safi = SAFI_FLOWSPEC;
419 break;
d62a17ae 420 default:
421 safi = SAFI_UNICAST;
422 break;
423 }
424 return safi;
718e3744 425}
426
55f91488
QY
427/**
428 * Converts an AFI in string form to afi_t
429 *
430 * @param afi string, one of
431 * - "ipv4"
432 * - "ipv6"
81cf0de5 433 * - "l2vpn"
55f91488
QY
434 * @return the corresponding afi_t
435 */
d62a17ae 436afi_t bgp_vty_afi_from_str(const char *afi_str)
437{
438 afi_t afi = AFI_MAX; /* unknown */
439 if (strmatch(afi_str, "ipv4"))
440 afi = AFI_IP;
441 else if (strmatch(afi_str, "ipv6"))
442 afi = AFI_IP6;
81cf0de5
CS
443 else if (strmatch(afi_str, "l2vpn"))
444 afi = AFI_L2VPN;
d62a17ae 445 return afi;
446}
447
448int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
449 afi_t *afi)
450{
451 int ret = 0;
452 if (argv_find(argv, argc, "ipv4", index)) {
453 ret = 1;
454 if (afi)
455 *afi = AFI_IP;
456 } else if (argv_find(argv, argc, "ipv6", index)) {
457 ret = 1;
458 if (afi)
459 *afi = AFI_IP6;
8688b3e7
DS
460 } else if (argv_find(argv, argc, "l2vpn", index)) {
461 ret = 1;
462 if (afi)
463 *afi = AFI_L2VPN;
d62a17ae 464 }
465 return ret;
46f296b4
LB
466}
467
375a2e67 468/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 469safi_t bgp_vty_safi_from_str(const char *safi_str)
470{
471 safi_t safi = SAFI_MAX; /* unknown */
472 if (strmatch(safi_str, "multicast"))
473 safi = SAFI_MULTICAST;
474 else if (strmatch(safi_str, "unicast"))
475 safi = SAFI_UNICAST;
476 else if (strmatch(safi_str, "vpn"))
477 safi = SAFI_MPLS_VPN;
81cf0de5
CS
478 else if (strmatch(safi_str, "evpn"))
479 safi = SAFI_EVPN;
d62a17ae 480 else if (strmatch(safi_str, "labeled-unicast"))
481 safi = SAFI_LABELED_UNICAST;
7c40bf39 482 else if (strmatch(safi_str, "flowspec"))
483 safi = SAFI_FLOWSPEC;
d62a17ae 484 return safi;
485}
486
487int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
488 safi_t *safi)
489{
490 int ret = 0;
491 if (argv_find(argv, argc, "unicast", index)) {
492 ret = 1;
493 if (safi)
494 *safi = SAFI_UNICAST;
495 } else if (argv_find(argv, argc, "multicast", index)) {
496 ret = 1;
497 if (safi)
498 *safi = SAFI_MULTICAST;
499 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
500 ret = 1;
501 if (safi)
502 *safi = SAFI_LABELED_UNICAST;
503 } else if (argv_find(argv, argc, "vpn", index)) {
504 ret = 1;
505 if (safi)
506 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
507 } else if (argv_find(argv, argc, "evpn", index)) {
508 ret = 1;
509 if (safi)
510 *safi = SAFI_EVPN;
7c40bf39 511 } else if (argv_find(argv, argc, "flowspec", index)) {
512 ret = 1;
513 if (safi)
514 *safi = SAFI_FLOWSPEC;
d62a17ae 515 }
516 return ret;
46f296b4
LB
517}
518
b16bcbba
TA
519/*
520 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
521 *
522 * afi
523 * address-family identifier
524 *
525 * safi
526 * subsequent address-family identifier
527 *
528 * Returns:
529 * default_af string corresponding to the supplied afi/safi pair.
530 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
531 * return -1.
532 */
533static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
534{
535 switch (afi) {
536 case AFI_IP:
537 switch (safi) {
538 case SAFI_UNICAST:
539 return "ipv4-unicast";
540 case SAFI_MULTICAST:
541 return "ipv4-multicast";
542 case SAFI_MPLS_VPN:
543 return "ipv4-vpn";
544 case SAFI_ENCAP:
545 return "ipv4-encap";
546 case SAFI_LABELED_UNICAST:
547 return "ipv4-labeled-unicast";
548 case SAFI_FLOWSPEC:
549 return "ipv4-flowspec";
550 default:
551 return "unknown-afi/safi";
552 }
553 break;
554 case AFI_IP6:
555 switch (safi) {
556 case SAFI_UNICAST:
557 return "ipv6-unicast";
558 case SAFI_MULTICAST:
559 return "ipv6-multicast";
560 case SAFI_MPLS_VPN:
561 return "ipv6-vpn";
562 case SAFI_ENCAP:
563 return "ipv6-encap";
564 case SAFI_LABELED_UNICAST:
565 return "ipv6-labeled-unicast";
566 case SAFI_FLOWSPEC:
567 return "ipv6-flowspec";
568 default:
569 return "unknown-afi/safi";
570 }
571 break;
572 case AFI_L2VPN:
573 switch (safi) {
574 case SAFI_EVPN:
575 return "l2vpn-evpn";
576 default:
577 return "unknown-afi/safi";
578 }
579 case AFI_UNSPEC:
580 case AFI_MAX:
581 return "unknown-afi/safi";
582 }
583 /* all AFIs are accounted for above, so this shouldn't happen */
584 return "unknown-afi/safi";
585}
586
5d5393b9
DL
587int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
588 enum bgp_instance_type inst_type)
589{
590 int ret = bgp_get(bgp, as, name, inst_type);
591
592 if (ret == BGP_CREATED) {
593 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
d43114f3 594 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
5d5393b9
DL
595
596 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 597 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 598 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 599 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
600 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
601 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 602 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 603 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 604 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 605 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
606 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
607 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2adac256
DA
608 if (DFLT_BGP_SUPPRESS_DUPLICATES)
609 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
f2ca5c5b
DA
610 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
611 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
1ae314be
DA
612 if (DFLT_BGP_HARD_ADMIN_RESET)
613 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
5d5393b9
DL
614
615 ret = BGP_SUCCESS;
616 }
617 return ret;
618}
619
7eeee51e 620/*
f212a857 621 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 622 *
f212a857
DS
623 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
624 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
625 * to appropriate values for the calling function. This is to allow the
626 * calling function to make decisions appropriate for the show command
627 * that is being parsed.
628 *
629 * The show commands are generally of the form:
d62a17ae 630 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
631 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
632 *
633 * Since we use argv_find if the show command in particular doesn't have:
634 * [ip]
18c57037 635 * [<view|vrf> VIEWVRFNAME]
375a2e67 636 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
637 * The command parsing should still be ok.
638 *
639 * vty -> The vty for the command so we can output some useful data in
640 * the event of a parse error in the vrf.
641 * argv -> The command tokens
642 * argc -> How many command tokens we have
d62a17ae 643 * idx -> The current place in the command, generally should be 0 for this
644 * function
7eeee51e
DS
645 * afi -> The parsed afi if it was included in the show command, returned here
646 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 647 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 648 * use_json -> json is configured or not
7eeee51e
DS
649 *
650 * The function returns the correct location in the parse tree for the
651 * last token found.
0e37c258
DS
652 *
653 * Returns 0 for failure to parse correctly, else the idx position of where
654 * it found the last token.
7eeee51e 655 */
d62a17ae 656int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
657 struct cmd_token **argv, int argc,
658 int *idx, afi_t *afi, safi_t *safi,
9f049418 659 struct bgp **bgp, bool use_json)
d62a17ae 660{
661 char *vrf_name = NULL;
662
663 assert(afi);
664 assert(safi);
665 assert(bgp);
666
667 if (argv_find(argv, argc, "ip", idx))
668 *afi = AFI_IP;
669
9a8bdf1c 670 if (argv_find(argv, argc, "view", idx))
d62a17ae 671 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
672 else if (argv_find(argv, argc, "vrf", idx)) {
673 vrf_name = argv[*idx + 1]->arg;
674 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
675 vrf_name = NULL;
676 }
677 if (vrf_name) {
d62a17ae 678 if (strmatch(vrf_name, "all"))
679 *bgp = NULL;
680 else {
681 *bgp = bgp_lookup_by_name(vrf_name);
682 if (!*bgp) {
52e5b8c4
SP
683 if (use_json) {
684 json_object *json = NULL;
685 json = json_object_new_object();
686 json_object_string_add(
687 json, "warning",
688 "View/Vrf is unknown");
75eeda93 689 vty_json(vty, json);
52e5b8c4 690 }
ca61fd25
DS
691 else
692 vty_out(vty, "View/Vrf %s is unknown\n",
693 vrf_name);
d62a17ae 694 *idx = 0;
695 return 0;
696 }
697 }
698 } else {
699 *bgp = bgp_get_default();
700 if (!*bgp) {
52e5b8c4
SP
701 if (use_json) {
702 json_object *json = NULL;
703 json = json_object_new_object();
704 json_object_string_add(
705 json, "warning",
706 "Default BGP instance not found");
75eeda93 707 vty_json(vty, json);
52e5b8c4 708 }
ca61fd25
DS
709 else
710 vty_out(vty,
711 "Default BGP instance not found\n");
d62a17ae 712 *idx = 0;
713 return 0;
714 }
715 }
716
717 if (argv_find_and_parse_afi(argv, argc, idx, afi))
718 argv_find_and_parse_safi(argv, argc, idx, safi);
719
720 *idx += 1;
721 return *idx;
722}
723
28c6e247 724static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 725{
726 struct interface *ifp = NULL;
4122b697
DA
727 struct listnode *node;
728 struct bgp_listener *listener;
729 union sockunion all_su;
d62a17ae 730
4122b697 731 if (su->sa.sa_family == AF_INET) {
3d2a2725 732 (void)str2sockunion("0.0.0.0", &all_su);
d62a17ae 733 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
4122b697 734 } else if (su->sa.sa_family == AF_INET6) {
3d2a2725 735 (void)str2sockunion("::", &all_su);
d62a17ae 736 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
737 su->sin6.sin6_scope_id,
738 bgp->vrf_id);
4122b697 739 }
d62a17ae 740
4122b697
DA
741 if (ifp) {
742 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
743 if (sockunion_family(su) !=
744 sockunion_family(&listener->su))
745 continue;
746
747 /* If 0.0.0.0/:: is a listener, then treat as self and
748 * reject.
749 */
750 if (!sockunion_cmp(&listener->su, su) ||
751 !sockunion_cmp(&listener->su, &all_su))
752 return true;
753 }
754 }
d62a17ae 755
3dc339cd 756 return false;
718e3744 757}
758
28c6e247
IR
759/* Utility function for looking up peer from VTY. */
760/* This is used only for configuration, so disallow if attempted on
761 * a dynamic neighbor.
762 */
763static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
764{
765 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
766 int ret;
767 union sockunion su;
768 struct peer *peer;
769
770 if (!bgp) {
771 return NULL;
772 }
773
774 ret = str2sockunion(ip_str, &su);
775 if (ret < 0) {
776 peer = peer_lookup_by_conf_if(bgp, ip_str);
777 if (!peer) {
778 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
779 == NULL) {
780 vty_out(vty,
781 "%% Malformed address or name: %s\n",
782 ip_str);
783 return NULL;
784 }
785 }
786 } else {
787 peer = peer_lookup(bgp, &su);
788 if (!peer) {
789 vty_out(vty,
790 "%% Specify remote-as or peer-group commands first\n");
791 return NULL;
792 }
793 if (peer_dynamic_neighbor(peer)) {
794 vty_out(vty,
795 "%% Operation not allowed on a dynamic neighbor\n");
796 return NULL;
797 }
798 }
799 return peer;
800}
801
718e3744 802/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
803/* This is used only for configuration, so disallow if attempted on
804 * a dynamic neighbor.
805 */
d62a17ae 806struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
807{
808 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
809 int ret;
810 union sockunion su;
811 struct peer *peer = NULL;
812 struct peer_group *group = NULL;
813
814 if (!bgp) {
815 return NULL;
816 }
817
818 ret = str2sockunion(peer_str, &su);
819 if (ret == 0) {
820 /* IP address, locate peer. */
821 peer = peer_lookup(bgp, &su);
822 } else {
823 /* Not IP, could match either peer configured on interface or a
824 * group. */
825 peer = peer_lookup_by_conf_if(bgp, peer_str);
826 if (!peer)
827 group = peer_group_lookup(bgp, peer_str);
828 }
829
830 if (peer) {
831 if (peer_dynamic_neighbor(peer)) {
832 vty_out(vty,
833 "%% Operation not allowed on a dynamic neighbor\n");
834 return NULL;
835 }
836
837 return peer;
838 }
839
840 if (group)
841 return group->conf;
842
843 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
844
845 return NULL;
846}
847
4b7e23e9 848int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
d62a17ae 849{
850 const char *str = NULL;
851
852 switch (ret) {
4b7e23e9
DS
853 case BGP_SUCCESS:
854 case BGP_CREATED:
855 case BGP_GR_NO_OPERATION:
856 break;
d62a17ae 857 case BGP_ERR_INVALID_VALUE:
858 str = "Invalid value";
859 break;
860 case BGP_ERR_INVALID_FLAG:
861 str = "Invalid flag";
862 break;
863 case BGP_ERR_PEER_GROUP_SHUTDOWN:
864 str = "Peer-group has been shutdown. Activate the peer-group first";
865 break;
866 case BGP_ERR_PEER_FLAG_CONFLICT:
867 str = "Can't set override-capability and strict-capability-match at the same time";
868 break;
869 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
870 str = "Specify remote-as or peer-group remote AS first";
871 break;
872 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
873 str = "Cannot change the peer-group. Deconfigure first";
874 break;
875 case BGP_ERR_PEER_GROUP_MISMATCH:
876 str = "Peer is not a member of this peer-group";
877 break;
878 case BGP_ERR_PEER_FILTER_CONFLICT:
879 str = "Prefix/distribute list can not co-exist";
880 break;
881 case BGP_ERR_NOT_INTERNAL_PEER:
882 str = "Invalid command. Not an internal neighbor";
883 break;
884 case BGP_ERR_REMOVE_PRIVATE_AS:
885 str = "remove-private-AS cannot be configured for IBGP peers";
886 break;
d62a17ae 887 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
888 str = "Cannot have local-as same as BGP AS number";
889 break;
890 case BGP_ERR_TCPSIG_FAILED:
891 str = "Error while applying TCP-Sig to session(s)";
892 break;
893 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
894 str = "ebgp-multihop and ttl-security cannot be configured together";
895 break;
896 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
897 str = "ttl-security only allowed for EBGP peers";
898 break;
899 case BGP_ERR_AS_OVERRIDE:
900 str = "as-override cannot be configured for IBGP peers";
901 break;
902 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
903 str = "Invalid limit for number of dynamic neighbors";
904 break;
905 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
906 str = "Dynamic neighbor listen range already exists";
907 break;
908 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
909 str = "Operation not allowed on a dynamic neighbor";
910 break;
911 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
912 str = "Operation not allowed on a directly connected neighbor";
913 break;
914 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 915 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
055679e9 916 break;
917 case BGP_ERR_GR_INVALID_CMD:
918 str = "The Graceful Restart command used is not valid at this moment.";
919 break;
920 case BGP_ERR_GR_OPERATION_FAILED:
921 str = "The Graceful Restart Operation failed due to an err.";
922 break;
6dcea6fe
DS
923 case BGP_ERR_PEER_GROUP_MEMBER:
924 str = "Peer-group member cannot override remote-as of peer-group.";
925 break;
926 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
927 str = "Peer-group members must be all internal or all external.";
928 break;
4b7e23e9
DS
929 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
930 str = "Range specified cannot be deleted because it is not part of current config.";
931 break;
932 case BGP_ERR_INSTANCE_MISMATCH:
933 str = "Instance specified does not match the current instance.";
934 break;
935 case BGP_ERR_NO_INTERFACE_CONFIG:
936 str = "Interface specified is not being used for interface based peer.";
937 break;
938 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
939 str = "No configuration already specified for soft reconfiguration.";
940 break;
941 case BGP_ERR_AS_MISMATCH:
942 str = "BGP is already running.";
943 break;
944 case BGP_ERR_AF_UNCONFIGURED:
945 str = "AFI/SAFI specified is not currently configured.";
946 break;
4b7e23e9
DS
947 case BGP_ERR_INVALID_AS:
948 str = "Confederation AS specified is the same AS as our AS.";
949 break;
d864dd9e
EB
950 case BGP_ERR_INVALID_ROLE_NAME:
951 str = "Invalid role name";
952 break;
953 case BGP_ERR_INVALID_INTERNAL_ROLE:
8f2d6021 954 str = "External roles can be set only on eBGP session";
d864dd9e 955 break;
70cd87ca 956 case BGP_ERR_PEER_ORR_CONFIGURED:
d6b27611 957 str = "Deconfigure optimal-route-reflection on this peer first";
70cd87ca 958 break;
d62a17ae 959 }
960 if (str) {
961 vty_out(vty, "%% %s\n", str);
962 return CMD_WARNING_CONFIG_FAILED;
963 }
964 return CMD_SUCCESS;
718e3744 965}
966
7aafcaca 967/* BGP clear sort. */
d62a17ae 968enum clear_sort {
969 clear_all,
970 clear_peer,
971 clear_group,
972 clear_external,
973 clear_as
7aafcaca
DS
974};
975
1ca2fd11
IR
976static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
977 safi_t safi, int error)
d62a17ae 978{
979 switch (error) {
980 case BGP_ERR_AF_UNCONFIGURED:
a486300b
PG
981 if (vty)
982 vty_out(vty,
983 "%% BGP: Enable %s address family for the neighbor %s\n",
984 get_afi_safi_str(afi, safi, false), peer->host);
985 else
986 zlog_warn(
1af6e82b 987 "%% BGP: Enable %s address family for the neighbor %s",
a486300b 988 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 989 break;
990 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
a486300b
PG
991 if (vty)
992 vty_out(vty,
993 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
994 peer->host);
995 else
996 zlog_warn(
1af6e82b 997 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
a486300b 998 peer->host);
d62a17ae 999 break;
1000 default:
1001 break;
1002 }
7aafcaca
DS
1003}
1004
dc912615 1005static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 1006 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
1007{
1008 int ret = 0;
2adac256 1009 struct peer_af *paf;
dc912615
DS
1010
1011 /* if afi/.safi not specified, spin thru all of them */
1012 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1013 afi_t tmp_afi;
1014 safi_t tmp_safi;
0e5cdd59
DS
1015 enum bgp_af_index index;
1016
1017 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1018 paf = peer->peer_af_array[index];
1019 if (!paf)
1020 continue;
dc912615 1021
2adac256
DA
1022 if (paf && paf->subgroup)
1023 SET_FLAG(paf->subgroup->sflags,
1024 SUBGRP_STATUS_FORCE_UPDATES);
1025
0e5cdd59
DS
1026 tmp_afi = paf->afi;
1027 tmp_safi = paf->safi;
dc912615
DS
1028 if (!peer->afc[tmp_afi][tmp_safi])
1029 continue;
1030
1031 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1032 ret = peer_clear(peer, nnode);
dc912615
DS
1033 else
1034 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1035 stype);
1036 }
1037 /* if afi specified and safi not, spin thru safis on this afi */
1038 } else if (safi == SAFI_UNSPEC) {
1039 safi_t tmp_safi;
1040
1041 for (tmp_safi = SAFI_UNICAST;
1042 tmp_safi < SAFI_MAX; tmp_safi++) {
1043 if (!peer->afc[afi][tmp_safi])
1044 continue;
1045
2adac256
DA
1046 paf = peer_af_find(peer, afi, tmp_safi);
1047 if (paf && paf->subgroup)
1048 SET_FLAG(paf->subgroup->sflags,
1049 SUBGRP_STATUS_FORCE_UPDATES);
1050
dc912615 1051 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1052 ret = peer_clear(peer, nnode);
dc912615
DS
1053 else
1054 ret = peer_clear_soft(peer, afi,
1055 tmp_safi, stype);
1056 }
1057 /* both afi/safi specified, let the caller know if not defined */
1058 } else {
1059 if (!peer->afc[afi][safi])
1060 return 1;
1061
2adac256
DA
1062 paf = peer_af_find(peer, afi, safi);
1063 if (paf && paf->subgroup)
1064 SET_FLAG(paf->subgroup->sflags,
1065 SUBGRP_STATUS_FORCE_UPDATES);
1066
dc912615 1067 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1068 ret = peer_clear(peer, nnode);
dc912615
DS
1069 else
1070 ret = peer_clear_soft(peer, afi, safi, stype);
1071 }
1072
1073 return ret;
1074}
1075
7aafcaca 1076/* `clear ip bgp' functions. */
1ca2fd11 1077static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 1078 enum clear_sort sort, enum bgp_clear_type stype,
1ca2fd11 1079 const char *arg)
d62a17ae 1080{
dc912615 1081 int ret = 0;
3ae8bfa5 1082 bool found = false;
d62a17ae 1083 struct peer *peer;
dc95985f 1084
1085 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 1086
1087 /* Clear all neighbors. */
1088 /*
1089 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
1090 * nodes on the BGP instance as that may get freed if it is a
1091 * doppelganger
d62a17ae 1092 */
1093 if (sort == clear_all) {
1094 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 1095
1096 bgp_peer_gr_flags_update(peer);
1097
36235319 1098 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 1099 gr_router_detected = true;
1100
c368171c 1101 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 1102 stype);
d62a17ae 1103
1104 if (ret < 0)
1ca2fd11 1105 bgp_clear_vty_error(vty, peer, afi, safi, ret);
dc95985f 1106 }
1107
36235319
QY
1108 if (gr_router_detected
1109 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1110 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1111 } else if (!gr_router_detected
1112 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1113 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 1114 }
d62a17ae 1115
1116 /* This is to apply read-only mode on this clear. */
1117 if (stype == BGP_CLEAR_SOFT_NONE)
1118 bgp->update_delay_over = 0;
1119
1120 return CMD_SUCCESS;
7aafcaca
DS
1121 }
1122
3ae8bfa5 1123 /* Clear specified neighbor. */
d62a17ae 1124 if (sort == clear_peer) {
1125 union sockunion su;
d62a17ae 1126
1127 /* Make sockunion for lookup. */
1128 ret = str2sockunion(arg, &su);
1129 if (ret < 0) {
1130 peer = peer_lookup_by_conf_if(bgp, arg);
1131 if (!peer) {
1132 peer = peer_lookup_by_hostname(bgp, arg);
1133 if (!peer) {
1ca2fd11
IR
1134 vty_out(vty,
1135 "Malformed address or name: %s\n",
d62a17ae 1136 arg);
1137 return CMD_WARNING;
1138 }
1139 }
1140 } else {
1141 peer = peer_lookup(bgp, &su);
1142 if (!peer) {
1ca2fd11 1143 vty_out(vty,
664b6f18 1144 "%% BGP: Unknown neighbor - \"%s\"\n",
1ca2fd11 1145 arg);
d62a17ae 1146 return CMD_WARNING;
1147 }
1148 }
7aafcaca 1149
dc95985f 1150 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1151 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1152
dc912615
DS
1153 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1154
1155 /* if afi/safi not defined for this peer, let caller know */
1156 if (ret == 1)
3ae8bfa5 1157 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1158
d62a17ae 1159 if (ret < 0)
1ca2fd11 1160 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 1161
d62a17ae 1162 return CMD_SUCCESS;
7aafcaca 1163 }
7aafcaca 1164
3ae8bfa5 1165 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1166 if (sort == clear_group) {
1167 struct peer_group *group;
7aafcaca 1168
d62a17ae 1169 group = peer_group_lookup(bgp, arg);
1170 if (!group) {
664b6f18 1171 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
d62a17ae 1172 return CMD_WARNING;
1173 }
1174
1175 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1176 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1177
d62a17ae 1178 if (ret < 0)
1ca2fd11 1179 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1180 else
1181 found = true;
d62a17ae 1182 }
3ae8bfa5
PM
1183
1184 if (!found)
1ca2fd11 1185 vty_out(vty,
664b6f18 1186 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 1187 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1188
d62a17ae 1189 return CMD_SUCCESS;
7aafcaca 1190 }
7aafcaca 1191
3ae8bfa5 1192 /* Clear all external (eBGP) neighbors. */
d62a17ae 1193 if (sort == clear_external) {
1194 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1195 if (peer->sort == BGP_PEER_IBGP)
1196 continue;
7aafcaca 1197
dc95985f 1198 bgp_peer_gr_flags_update(peer);
1199
36235319 1200 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1201 gr_router_detected = true;
dc95985f 1202
c368171c 1203 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1204
d62a17ae 1205 if (ret < 0)
1ca2fd11 1206 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1207 else
1208 found = true;
d62a17ae 1209 }
3ae8bfa5 1210
36235319
QY
1211 if (gr_router_detected
1212 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1213 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1214 } else if (!gr_router_detected
1215 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1216 bgp_zebra_send_capabilities(bgp, true);
1217 }
1218
3ae8bfa5 1219 if (!found)
1ca2fd11 1220 vty_out(vty,
664b6f18 1221 "%% BGP: No external %s peer is configured\n",
1ca2fd11 1222 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1223
d62a17ae 1224 return CMD_SUCCESS;
1225 }
1226
3ae8bfa5 1227 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1228 if (sort == clear_as) {
3ae8bfa5 1229 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1230
1231 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1232 if (peer->as != as)
1233 continue;
1234
dc95985f 1235 bgp_peer_gr_flags_update(peer);
1236
36235319 1237 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1238 gr_router_detected = true;
dc95985f 1239
c368171c 1240 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1241
1242 if (ret < 0)
1ca2fd11 1243 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1244 else
1245 found = true;
d62a17ae 1246 }
3ae8bfa5 1247
36235319
QY
1248 if (gr_router_detected
1249 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1250 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1251 } else if (!gr_router_detected
1252 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1253 bgp_zebra_send_capabilities(bgp, true);
1254 }
1255
3ae8bfa5 1256 if (!found)
1ca2fd11 1257 vty_out(vty,
664b6f18 1258 "%% BGP: No %s peer is configured with AS %s\n",
1ca2fd11 1259 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1260
d62a17ae 1261 return CMD_SUCCESS;
1262 }
1263
1264 return CMD_SUCCESS;
1265}
1266
1ca2fd11
IR
1267static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1268 safi_t safi, enum clear_sort sort,
1269 enum bgp_clear_type stype, const char *arg)
d62a17ae 1270{
1271 struct bgp *bgp;
1272
1273 /* BGP structure lookup. */
1274 if (name) {
1275 bgp = bgp_lookup_by_name(name);
1276 if (bgp == NULL) {
1ca2fd11 1277 vty_out(vty, "Can't find BGP instance %s\n", name);
d62a17ae 1278 return CMD_WARNING;
1279 }
1280 } else {
1281 bgp = bgp_get_default();
1282 if (bgp == NULL) {
1ca2fd11 1283 vty_out(vty, "No BGP process is configured\n");
d62a17ae 1284 return CMD_WARNING;
1285 }
1286 }
1287
1ca2fd11 1288 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
1289}
1290
1291/* clear soft inbound */
1ca2fd11 1292static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 1293{
99b3ebd3
NS
1294 afi_t afi;
1295 safi_t safi;
1296
1ca2fd11
IR
1297 FOREACH_AFI_SAFI (afi, safi)
1298 bgp_clear_vty(vty, name, afi, safi, clear_all,
1299 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
1300}
1301
1302/* clear soft outbound */
1ca2fd11 1303static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 1304{
99b3ebd3
NS
1305 afi_t afi;
1306 safi_t safi;
1307
1ca2fd11
IR
1308 FOREACH_AFI_SAFI (afi, safi)
1309 bgp_clear_vty(vty, name, afi, safi, clear_all,
1310 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
1311}
1312
1313
a486300b
PG
1314void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1315{
1316 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1317}
1318
f787d7a0 1319#ifndef VTYSH_EXTRACT_PL
2e4c2296 1320#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1321#endif
1322
8029b216
AK
1323DEFUN_HIDDEN (bgp_local_mac,
1324 bgp_local_mac_cmd,
093e3f23 1325 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1326 BGP_STR
1327 "Local MAC config\n"
1328 "VxLAN Network Identifier\n"
1329 "VNI number\n"
1330 "local mac\n"
1331 "mac address\n"
1332 "mac-mobility sequence\n"
1333 "seq number\n")
1334{
1335 int rv;
1336 vni_t vni;
1337 struct ethaddr mac;
1338 struct ipaddr ip;
1339 uint32_t seq;
1340 struct bgp *bgp;
1341
1342 vni = strtoul(argv[3]->arg, NULL, 10);
1343 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1344 vty_out(vty, "%% Malformed MAC address\n");
1345 return CMD_WARNING;
1346 }
1347 memset(&ip, 0, sizeof(ip));
1348 seq = strtoul(argv[7]->arg, NULL, 10);
1349
1350 bgp = bgp_get_default();
1351 if (!bgp) {
1352 vty_out(vty, "Default BGP instance is not there\n");
1353 return CMD_WARNING;
1354 }
1355
b5e140c8
AK
1356 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1357 zero_esi);
8029b216
AK
1358 if (rv < 0) {
1359 vty_out(vty, "Internal error\n");
1360 return CMD_WARNING;
1361 }
1362
1363 return CMD_SUCCESS;
1364}
1365
1366DEFUN_HIDDEN (no_bgp_local_mac,
1367 no_bgp_local_mac_cmd,
093e3f23 1368 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1369 NO_STR
1370 BGP_STR
1371 "Local MAC config\n"
1372 "VxLAN Network Identifier\n"
1373 "VNI number\n"
1374 "local mac\n"
1375 "mac address\n")
1376{
1377 int rv;
1378 vni_t vni;
1379 struct ethaddr mac;
1380 struct ipaddr ip;
1381 struct bgp *bgp;
1382
1383 vni = strtoul(argv[4]->arg, NULL, 10);
1384 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1385 vty_out(vty, "%% Malformed MAC address\n");
1386 return CMD_WARNING;
1387 }
1388 memset(&ip, 0, sizeof(ip));
1389
1390 bgp = bgp_get_default();
1391 if (!bgp) {
1392 vty_out(vty, "Default BGP instance is not there\n");
1393 return CMD_WARNING;
1394 }
1395
ec0ab544 1396 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1397 if (rv < 0) {
1398 vty_out(vty, "Internal error\n");
1399 return CMD_WARNING;
1400 }
1401
1402 return CMD_SUCCESS;
1403}
1404
718e3744 1405DEFUN (no_synchronization,
1406 no_synchronization_cmd,
1407 "no synchronization",
1408 NO_STR
1409 "Perform IGP synchronization\n")
1410{
d62a17ae 1411 return CMD_SUCCESS;
718e3744 1412}
1413
1414DEFUN (no_auto_summary,
1415 no_auto_summary_cmd,
1416 "no auto-summary",
1417 NO_STR
1418 "Enable automatic network number summarization\n")
1419{
d62a17ae 1420 return CMD_SUCCESS;
718e3744 1421}
3d515fd9 1422
718e3744 1423/* "router bgp" commands. */
1ca2fd11
IR
1424DEFUN_NOSH (router_bgp,
1425 router_bgp_cmd,
1426 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1427 ROUTER_STR
1428 BGP_STR
1429 AS_STR
1430 BGP_INSTANCE_HELP_STR)
718e3744 1431{
d62a17ae 1432 int idx_asn = 2;
1433 int idx_view_vrf = 3;
1434 int idx_vrf = 4;
1ca2fd11
IR
1435 int is_new_bgp = 0;
1436 int ret;
d62a17ae 1437 as_t as;
1438 struct bgp *bgp;
1439 const char *name = NULL;
1440 enum bgp_instance_type inst_type;
1441
1442 // "router bgp" without an ASN
1443 if (argc == 2) {
1444 // Pending: Make VRF option available for ASN less config
1abef40f 1445 bgp = bgp_get_default();
d62a17ae 1446
1abef40f 1447 if (bgp == NULL) {
d62a17ae 1448 vty_out(vty, "%% No BGP process is configured\n");
1449 return CMD_WARNING_CONFIG_FAILED;
1450 }
1451
1452 if (listcount(bm->bgp) > 1) {
996c9314 1453 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1454 return CMD_WARNING_CONFIG_FAILED;
1455 }
1456 }
1457
1458 // "router bgp X"
1459 else {
ff8a8a7a 1460 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1ca2fd11 1461
cc413e2a
DA
1462 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1463 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1464 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1465
d62a17ae 1466 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1467 if (argc > 3) {
1468 name = argv[idx_vrf]->arg;
1469
9a8bdf1c
PG
1470 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1471 if (strmatch(name, VRF_DEFAULT_NAME))
1472 name = NULL;
1473 else
1474 inst_type = BGP_INSTANCE_TYPE_VRF;
1ca2fd11 1475 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1476 inst_type = BGP_INSTANCE_TYPE_VIEW;
d62a17ae 1477 }
1478
1ca2fd11
IR
1479 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1480 is_new_bgp = (bgp_lookup(as, name) == NULL);
3bd70bf8 1481
1ca2fd11
IR
1482 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1483 switch (ret) {
1484 case BGP_ERR_AS_MISMATCH:
1485 vty_out(vty, "BGP is already running; AS is %u\n", as);
1486 return CMD_WARNING_CONFIG_FAILED;
1487 case BGP_ERR_INSTANCE_MISMATCH:
1488 vty_out(vty,
1489 "BGP instance name and AS number mismatch\n");
1490 vty_out(vty,
1491 "BGP instance is already running; AS is %u\n",
1492 as);
1493 return CMD_WARNING_CONFIG_FAILED;
ff8a8a7a 1494 }
1ca2fd11
IR
1495
1496 /*
1497 * If we just instantiated the default instance, complete
1498 * any pending VRF-VPN leaking that was configured via
1499 * earlier "router bgp X vrf FOO" blocks.
1500 */
1501 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1502 vpn_leak_postchange_all();
1503
1504 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1505 bgp_vpn_leak_export(bgp);
1506 /* Pending: handle when user tries to change a view to vrf n vv.
1507 */
d62a17ae 1508 }
1509
1ca2fd11
IR
1510 /* unset the auto created flag as the user config is now present */
1511 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1512 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1513
1514 return CMD_SUCCESS;
718e3744 1515}
1516
718e3744 1517/* "no router bgp" commands. */
1ca2fd11
IR
1518DEFUN (no_router_bgp,
1519 no_router_bgp_cmd,
1520 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1521 NO_STR
1522 ROUTER_STR
1523 BGP_STR
1524 AS_STR
1525 BGP_INSTANCE_HELP_STR)
718e3744 1526{
4fd9919e 1527 int idx_asn = 3;
d62a17ae 1528 int idx_vrf = 5;
1ca2fd11 1529 as_t as;
4fd9919e 1530 struct bgp *bgp;
d62a17ae 1531 const char *name = NULL;
718e3744 1532
d62a17ae 1533 // "no router bgp" without an ASN
1534 if (argc == 3) {
1535 // Pending: Make VRF option available for ASN less config
8382083a 1536 bgp = bgp_get_default();
718e3744 1537
8382083a 1538 if (bgp == NULL) {
d62a17ae 1539 vty_out(vty, "%% No BGP process is configured\n");
1540 return CMD_WARNING_CONFIG_FAILED;
1541 }
7fb21a9f 1542
d62a17ae 1543 if (listcount(bm->bgp) > 1) {
996c9314 1544 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1545 return CMD_WARNING_CONFIG_FAILED;
1546 }
4fd9919e 1547
4fd9919e 1548 if (bgp->l3vni) {
be125e6f 1549 vty_out(vty, "%% Please unconfigure l3vni %u\n",
4fd9919e
IR
1550 bgp->l3vni);
1551 return CMD_WARNING_CONFIG_FAILED;
1552 }
d62a17ae 1553 } else {
4fd9919e
IR
1554 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1555
1ca42c8d 1556 if (argc > 4) {
d62a17ae 1557 name = argv[idx_vrf]->arg;
1ca42c8d
IR
1558 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1559 && strmatch(name, VRF_DEFAULT_NAME))
1560 name = NULL;
1561 }
7fb21a9f 1562
4fd9919e
IR
1563 /* Lookup bgp structure. */
1564 bgp = bgp_lookup(as, name);
1565 if (!bgp) {
1566 vty_out(vty, "%% Can't find BGP instance\n");
1567 return CMD_WARNING_CONFIG_FAILED;
1568 }
1569
1570 if (bgp->l3vni) {
1571 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1572 bgp->l3vni);
1573 return CMD_WARNING_CONFIG_FAILED;
1574 }
1575
1576 /* Cannot delete default instance if vrf instances exist */
1577 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1578 struct listnode *node;
1579 struct bgp *tmp_bgp;
1580
1581 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1582 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1583 continue;
1584 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1585 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1586 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1587 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1588 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1589 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1590 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1591 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1592 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1593 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1594 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1595 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1596 (bgp == bgp_get_evpn() &&
1597 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1598 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1599 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1600 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1601 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1602 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1603 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1604 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
f33bf7c0 1605 (hashcount(tmp_bgp->vnihash))) {
4fd9919e
IR
1606 vty_out(vty,
1607 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1608 return CMD_WARNING_CONFIG_FAILED;
1609 }
1610 }
1611 }
d62a17ae 1612 }
718e3744 1613
1ca2fd11 1614 bgp_delete(bgp);
718e3744 1615
1ca2fd11 1616 return CMD_SUCCESS;
718e3744 1617}
1618
425bd64b
PS
1619/* bgp session-dscp */
1620
1621DEFPY (bgp_session_dscp,
1622 bgp_session_dscp_cmd,
1623 "bgp session-dscp (0-63)$dscp",
1624 BGP_STR
1625 "Override default (C6) bgp TCP session DSCP value\n"
1626 "Manually configured dscp parameter\n")
1627{
1628 bm->tcp_dscp = dscp << 2;
1629
1630 return CMD_SUCCESS;
1631}
1632
1633DEFPY (no_bgp_session_dscp,
1634 no_bgp_session_dscp_cmd,
1635 "no bgp session-dscp [(0-63)]",
1636 NO_STR
1637 BGP_STR
1638 "Override default (C6) bgp TCP session DSCP value\n"
1639 "Manually configured dscp parameter\n")
1640{
1641 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1642
1643 return CMD_SUCCESS;
1644}
718e3744 1645
ff8a8a7a
CS
1646/* BGP router-id. */
1647
1ca2fd11
IR
1648DEFPY (bgp_router_id,
1649 bgp_router_id_cmd,
1650 "bgp router-id A.B.C.D",
1651 BGP_STR
1652 "Override configured router identifier\n"
1653 "Manually configured router identifier\n")
718e3744 1654{
1ca2fd11
IR
1655 VTY_DECLVAR_CONTEXT(bgp, bgp);
1656 bgp_router_id_static_set(bgp, router_id);
1657 return CMD_SUCCESS;
ff8a8a7a 1658}
718e3744 1659
1ca2fd11
IR
1660DEFPY (no_bgp_router_id,
1661 no_bgp_router_id_cmd,
1662 "no bgp router-id [A.B.C.D]",
1663 NO_STR
1664 BGP_STR
1665 "Override configured router identifier\n"
1666 "Manually configured router identifier\n")
ff8a8a7a 1667{
1ca2fd11 1668 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1669
1ca2fd11
IR
1670 if (router_id_str) {
1671 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1672 vty_out(vty, "%% BGP router-id doesn't match\n");
1673 return CMD_WARNING_CONFIG_FAILED;
1674 }
1675 }
718e3744 1676
1ca2fd11
IR
1677 router_id.s_addr = 0;
1678 bgp_router_id_static_set(bgp, router_id);
1679
1680 return CMD_SUCCESS;
ff8a8a7a 1681}
6b0655a2 1682
ed0e57e3 1683DEFPY(bgp_community_alias, bgp_community_alias_cmd,
b4ad2fae 1684 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
ed0e57e3
DA
1685 NO_STR BGP_STR
1686 "Add community specific parameters\n"
1687 "Create an alias for a community\n"
1688 "Community (AA:BB or AA:BB:CC)\n"
1689 "Alias name\n")
1690{
8cfa1e78 1691 struct community_alias ca = {};
ed0e57e3
DA
1692 struct community_alias *lookup_community;
1693 struct community_alias *lookup_alias;
d13d137a
DA
1694 struct community *comm;
1695 struct lcommunity *lcomm;
1696 uint8_t invalid = 0;
ed0e57e3 1697
d13d137a
DA
1698 comm = community_str2com(community);
1699 if (!comm)
1700 invalid++;
1701 community_free(&comm);
1702
1703 lcomm = lcommunity_str2com(community);
1704 if (!lcomm)
1705 invalid++;
1706 lcommunity_free(&lcomm);
1707
1708 if (invalid > 1) {
ed0e57e3
DA
1709 vty_out(vty, "Invalid community format\n");
1710 return CMD_WARNING;
1711 }
1712
8cfa1e78
DA
1713 strlcpy(ca.community, community, sizeof(ca.community));
1714 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
ed0e57e3 1715
8cfa1e78
DA
1716 lookup_community = bgp_ca_community_lookup(&ca);
1717 lookup_alias = bgp_ca_alias_lookup(&ca);
ed0e57e3
DA
1718
1719 if (no) {
8cfa1e78
DA
1720 bgp_ca_alias_delete(&ca);
1721 bgp_ca_community_delete(&ca);
ed0e57e3
DA
1722 } else {
1723 if (lookup_alias) {
1724 /* Lookup if community hash table has an item
1725 * with the same alias name.
1726 */
8cfa1e78
DA
1727 strlcpy(ca.community, lookup_alias->community,
1728 sizeof(ca.community));
1729 if (bgp_ca_community_lookup(&ca)) {
ed0e57e3
DA
1730 vty_out(vty,
1731 "community (%s) already has this alias (%s)\n",
1732 lookup_alias->community,
1733 lookup_alias->alias);
1734 return CMD_WARNING;
1735 }
8cfa1e78 1736 bgp_ca_alias_delete(&ca);
ed0e57e3
DA
1737 }
1738
8cfa1e78
DA
1739 if (lookup_community) {
1740 /* Lookup if alias hash table has an item
1741 * with the same community.
1742 */
1743 strlcpy(ca.alias, lookup_community->alias,
1744 sizeof(ca.alias));
1745 if (bgp_ca_alias_lookup(&ca)) {
1746 vty_out(vty,
1747 "alias (%s) already has this community (%s)\n",
1748 lookup_community->alias,
1749 lookup_community->community);
1750 return CMD_WARNING;
1751 }
1752 bgp_ca_community_delete(&ca);
1753 }
ed0e57e3 1754
8cfa1e78
DA
1755 bgp_ca_alias_insert(&ca);
1756 bgp_ca_community_insert(&ca);
ed0e57e3
DA
1757 }
1758
1759 return CMD_SUCCESS;
1760}
1761
9acb67cb
DS
1762DEFPY (bgp_global_suppress_fib_pending,
1763 bgp_global_suppress_fib_pending_cmd,
1764 "[no] bgp suppress-fib-pending",
1765 NO_STR
1766 BGP_STR
1767 "Advertise only routes that are programmed in kernel to peers globally\n")
1768{
1769 bm_wait_for_fib_set(!no);
1770
1771 return CMD_SUCCESS;
1772}
1773
c208c586
S
1774DEFPY (bgp_suppress_fib_pending,
1775 bgp_suppress_fib_pending_cmd,
1776 "[no] bgp suppress-fib-pending",
1777 NO_STR
1778 BGP_STR
1779 "Advertise only routes that are programmed in kernel to peers\n")
1780{
1781 VTY_DECLVAR_CONTEXT(bgp, bgp);
1782
1783 bgp_suppress_fib_pending_set(bgp, !no);
1784 return CMD_SUCCESS;
1785}
1786
1787
718e3744 1788/* BGP Cluster ID. */
1ca2fd11
IR
1789DEFUN (bgp_cluster_id,
1790 bgp_cluster_id_cmd,
1791 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1792 BGP_STR
1793 "Configure Route-Reflector Cluster-id\n"
1794 "Route-Reflector Cluster-id in IP address format\n"
1795 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1796{
1ca2fd11 1797 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1798 int idx_ipv4 = 2;
1ca2fd11
IR
1799 int ret;
1800 struct in_addr cluster;
1801
1802 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1803 if (!ret) {
1804 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1805 return CMD_WARNING_CONFIG_FAILED;
1806 }
718e3744 1807
1ca2fd11
IR
1808 bgp_cluster_id_set(bgp, &cluster);
1809 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1810
1ca2fd11 1811 return CMD_SUCCESS;
718e3744 1812}
1813
1ca2fd11
IR
1814DEFUN (no_bgp_cluster_id,
1815 no_bgp_cluster_id_cmd,
1816 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1817 NO_STR
1818 BGP_STR
1819 "Configure Route-Reflector Cluster-id\n"
1820 "Route-Reflector Cluster-id in IP address format\n"
1821 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1822{
1ca2fd11
IR
1823 VTY_DECLVAR_CONTEXT(bgp, bgp);
1824 bgp_cluster_id_unset(bgp);
1825 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1826
1ca2fd11 1827 return CMD_SUCCESS;
718e3744 1828}
1829
c163f297
DS
1830DEFPY (bgp_norib,
1831 bgp_norib_cmd,
1832 "bgp no-rib",
1833 BGP_STR
1834 "Disable BGP route installation to RIB (Zebra)\n")
1835{
1836 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1837 vty_out(vty,
1838 "%% No-RIB option is already set, nothing to do here.\n");
1839 return CMD_SUCCESS;
1840 }
1841
1842 bgp_option_norib_set_runtime();
1843
1844 return CMD_SUCCESS;
1845}
1846
1847DEFPY (no_bgp_norib,
1848 no_bgp_norib_cmd,
1849 "no bgp no-rib",
1850 NO_STR
1851 BGP_STR
1852 "Disable BGP route installation to RIB (Zebra)\n")
1853{
1854 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1855 vty_out(vty,
1856 "%% No-RIB option is not set, nothing to do here.\n");
1857 return CMD_SUCCESS;
1858 }
1859
1860 bgp_option_norib_unset_runtime();
1861
1862 return CMD_SUCCESS;
1863}
1864
e46723a5
DS
1865DEFPY (no_bgp_send_extra_data,
1866 no_bgp_send_extra_data_cmd,
1867 "[no] bgp send-extra-data zebra",
1868 NO_STR
1869 BGP_STR
1870 "Extra data to Zebra for display/use\n"
1871 "To zebra\n")
1872{
ec0acb80
DA
1873 if (no)
1874 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1875 else
1876 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1877
1878 return CMD_SUCCESS;
1879}
1880
1ca2fd11
IR
1881DEFUN (bgp_confederation_identifier,
1882 bgp_confederation_identifier_cmd,
1883 "bgp confederation identifier (1-4294967295)",
e9273987 1884 BGP_STR
1ca2fd11
IR
1885 "AS confederation parameters\n"
1886 "AS number\n"
1887 "Set routing domain confederation AS\n")
718e3744 1888{
1ca2fd11 1889 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1890 int idx_number = 3;
1ca2fd11 1891 as_t as;
718e3744 1892
1ca2fd11 1893 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1894
1ca2fd11 1895 bgp_confederation_id_set(bgp, as);
718e3744 1896
1ca2fd11 1897 return CMD_SUCCESS;
718e3744 1898}
1899
1ca2fd11
IR
1900DEFUN (no_bgp_confederation_identifier,
1901 no_bgp_confederation_identifier_cmd,
1902 "no bgp confederation identifier [(1-4294967295)]",
1903 NO_STR
e9273987 1904 BGP_STR
1ca2fd11
IR
1905 "AS confederation parameters\n"
1906 "AS number\n"
1907 "Set routing domain confederation AS\n")
ff8a8a7a 1908{
1ca2fd11
IR
1909 VTY_DECLVAR_CONTEXT(bgp, bgp);
1910 bgp_confederation_id_unset(bgp);
1911
1912 return CMD_SUCCESS;
ff8a8a7a
CS
1913}
1914
1ca2fd11
IR
1915DEFUN (bgp_confederation_peers,
1916 bgp_confederation_peers_cmd,
1917 "bgp confederation peers (1-4294967295)...",
e9273987 1918 BGP_STR
1ca2fd11
IR
1919 "AS confederation parameters\n"
1920 "Peer ASs in BGP confederation\n"
1921 AS_STR)
718e3744 1922{
1ca2fd11 1923 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1924 int idx_asn = 3;
1ca2fd11 1925 as_t as;
d62a17ae 1926 int i;
718e3744 1927
1ca2fd11
IR
1928 for (i = idx_asn; i < argc; i++) {
1929 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1930
1ca2fd11
IR
1931 if (bgp->as == as) {
1932 vty_out(vty,
1933 "%% Local member-AS not allowed in confed peer list\n");
1934 continue;
1935 }
1936
1937 bgp_confederation_peers_add(bgp, as);
1938 }
1939 return CMD_SUCCESS;
718e3744 1940}
1941
1ca2fd11
IR
1942DEFUN (no_bgp_confederation_peers,
1943 no_bgp_confederation_peers_cmd,
1944 "no bgp confederation peers (1-4294967295)...",
1945 NO_STR
e9273987 1946 BGP_STR
1ca2fd11
IR
1947 "AS confederation parameters\n"
1948 "Peer ASs in BGP confederation\n"
1949 AS_STR)
718e3744 1950{
1ca2fd11 1951 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1952 int idx_asn = 4;
1ca2fd11 1953 as_t as;
d62a17ae 1954 int i;
718e3744 1955
1ca2fd11
IR
1956 for (i = idx_asn; i < argc; i++) {
1957 as = strtoul(argv[i]->arg, NULL, 10);
ff8a8a7a 1958
1ca2fd11
IR
1959 bgp_confederation_peers_remove(bgp, as);
1960 }
1961 return CMD_SUCCESS;
718e3744 1962}
6b0655a2 1963
5e242b0d
DS
1964/**
1965 * Central routine for maximum-paths configuration.
1966 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1967 * @set: 1 for setting values, 0 for removing the max-paths config.
1968 */
585f1adc
IR
1969static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1970 const char *mpaths, uint16_t options,
1971 int set)
d62a17ae 1972{
585f1adc
IR
1973 VTY_DECLVAR_CONTEXT(bgp, bgp);
1974 uint16_t maxpaths = 0;
d62a17ae 1975 int ret;
585f1adc
IR
1976 afi_t afi;
1977 safi_t safi;
1978
1979 afi = bgp_node_afi(vty);
1980 safi = bgp_node_safi(vty);
d62a17ae 1981
1982 if (set) {
585f1adc 1983 maxpaths = strtol(mpaths, NULL, 10);
d62a17ae 1984 if (maxpaths > multipath_num) {
585f1adc 1985 vty_out(vty,
d62a17ae 1986 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1987 maxpaths, multipath_num);
1988 return CMD_WARNING_CONFIG_FAILED;
1989 }
1990 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1991 options);
1992 } else
1993 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1994
1995 if (ret < 0) {
585f1adc 1996 vty_out(vty,
d62a17ae 1997 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1998 (set == 1) ? "" : "un",
1999 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
2000 maxpaths, afi, safi);
2001 return CMD_WARNING_CONFIG_FAILED;
2002 }
2003
2004 bgp_recalculate_all_bestpaths(bgp);
2005
2006 return CMD_SUCCESS;
165b5fff
JB
2007}
2008
1ca2fd11
IR
2009DEFUN (bgp_maxmed_admin,
2010 bgp_maxmed_admin_cmd,
2011 "bgp max-med administrative ",
2012 BGP_STR
2013 "Advertise routes with max-med\n"
2014 "Administratively applied, for an indefinite period\n")
abc920f8 2015{
1ca2fd11 2016 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 2017
1ca2fd11
IR
2018 bgp->v_maxmed_admin = 1;
2019 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
ff8a8a7a 2020
1ca2fd11 2021 bgp_maxmed_update(bgp);
abc920f8 2022
1ca2fd11 2023 return CMD_SUCCESS;
ff8a8a7a
CS
2024}
2025
1ca2fd11
IR
2026DEFUN (bgp_maxmed_admin_medv,
2027 bgp_maxmed_admin_medv_cmd,
2028 "bgp max-med administrative (0-4294967295)",
2029 BGP_STR
2030 "Advertise routes with max-med\n"
2031 "Administratively applied, for an indefinite period\n"
2032 "Max MED value to be used\n")
abc920f8 2033{
1ca2fd11 2034 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2035 int idx_number = 3;
abc920f8 2036
1ca2fd11
IR
2037 bgp->v_maxmed_admin = 1;
2038 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 2039
1ca2fd11 2040 bgp_maxmed_update(bgp);
abc920f8 2041
1ca2fd11 2042 return CMD_SUCCESS;
abc920f8
DS
2043}
2044
1ca2fd11
IR
2045DEFUN (no_bgp_maxmed_admin,
2046 no_bgp_maxmed_admin_cmd,
2047 "no bgp max-med administrative [(0-4294967295)]",
2048 NO_STR
2049 BGP_STR
2050 "Advertise routes with max-med\n"
2051 "Administratively applied, for an indefinite period\n"
2052 "Max MED value to be used\n")
abc920f8 2053{
1ca2fd11
IR
2054 VTY_DECLVAR_CONTEXT(bgp, bgp);
2055 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2056 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2057 bgp_maxmed_update(bgp);
ff8a8a7a 2058
1ca2fd11 2059 return CMD_SUCCESS;
abc920f8
DS
2060}
2061
1ca2fd11
IR
2062DEFUN (bgp_maxmed_onstartup,
2063 bgp_maxmed_onstartup_cmd,
2064 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2065 BGP_STR
2066 "Advertise routes with max-med\n"
2067 "Effective on a startup\n"
2068 "Time (seconds) period for max-med\n"
2069 "Max MED value to be used\n")
abc920f8 2070{
1ca2fd11 2071 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2072 int idx = 0;
4668a151 2073
9b01d289
DA
2074 if (argv_find(argv, argc, "(5-86400)", &idx))
2075 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 2076 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1ca2fd11 2077 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 2078 else
1ca2fd11 2079 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 2080
1ca2fd11
IR
2081 bgp_maxmed_update(bgp);
2082
2083 return CMD_SUCCESS;
abc920f8
DS
2084}
2085
1ca2fd11
IR
2086DEFUN (no_bgp_maxmed_onstartup,
2087 no_bgp_maxmed_onstartup_cmd,
2088 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2089 NO_STR
2090 BGP_STR
2091 "Advertise routes with max-med\n"
2092 "Effective on a startup\n"
2093 "Time (seconds) period for max-med\n"
2094 "Max MED value to be used\n")
abc920f8 2095{
1ca2fd11
IR
2096 VTY_DECLVAR_CONTEXT(bgp, bgp);
2097
2098 /* Cancel max-med onstartup if its on */
2099 if (bgp->t_maxmed_onstartup) {
c3aaa89a 2100 THREAD_OFF(bgp->t_maxmed_onstartup);
1ca2fd11
IR
2101 bgp->maxmed_onstartup_over = 1;
2102 }
abc920f8 2103
1ca2fd11
IR
2104 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2105 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 2106
1ca2fd11
IR
2107 bgp_maxmed_update(bgp);
2108
2109 return CMD_SUCCESS;
abc920f8
DS
2110}
2111
d70583f7
D
2112static int bgp_global_update_delay_config_vty(struct vty *vty,
2113 uint16_t update_delay,
2114 uint16_t establish_wait)
2115{
2116 struct listnode *node, *nnode;
2117 struct bgp *bgp;
2118 bool vrf_cfg = false;
2119
2120 /*
2121 * See if update-delay is set per-vrf and warn user to delete it
2122 * Note that we only need to check this if this is the first time
2123 * setting the global config.
2124 */
2125 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2126 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2127 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2128 vty_out(vty,
2129 "%% update-delay configuration found in vrf %s\n",
2130 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2131 ? VRF_DEFAULT_NAME
2132 : bgp->name);
2133 vrf_cfg = true;
2134 }
2135 }
2136 }
2137
2138 if (vrf_cfg) {
2139 vty_out(vty,
2140 "%%Failed: global update-delay config not permitted\n");
2141 return CMD_WARNING;
2142 }
2143
2144 if (!establish_wait) { /* update-delay <delay> */
2145 bm->v_update_delay = update_delay;
2146 bm->v_establish_wait = bm->v_update_delay;
2147 } else {
2148 /* update-delay <delay> <establish-wait> */
2149 if (update_delay < establish_wait) {
2150 vty_out(vty,
2151 "%%Failed: update-delay less than the establish-wait!\n");
2152 return CMD_WARNING_CONFIG_FAILED;
2153 }
2154
2155 bm->v_update_delay = update_delay;
2156 bm->v_establish_wait = establish_wait;
2157 }
2158
2159 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2160 bgp->v_update_delay = bm->v_update_delay;
2161 bgp->v_establish_wait = bm->v_establish_wait;
2162 }
2163
2164 return CMD_SUCCESS;
2165}
2166
2167static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2168{
2169 struct listnode *node, *nnode;
2170 struct bgp *bgp;
2171
2172 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2173 bm->v_establish_wait = bm->v_update_delay;
2174
2175 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2176 bgp->v_update_delay = bm->v_update_delay;
2177 bgp->v_establish_wait = bm->v_establish_wait;
2178 }
2179
2180 return CMD_SUCCESS;
2181}
2182
2183static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2184 uint16_t establish_wait)
f188f2c4 2185{
d62a17ae 2186 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2187
d70583f7
D
2188 /* if configured globally, per-instance config is not allowed */
2189 if (bm->v_update_delay) {
2190 vty_out(vty,
2191 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2192 return CMD_WARNING_CONFIG_FAILED;
2193 }
2194
f188f2c4 2195
d70583f7 2196 if (!establish_wait) /* update-delay <delay> */
d62a17ae 2197 {
2198 bgp->v_update_delay = update_delay;
2199 bgp->v_establish_wait = bgp->v_update_delay;
2200 return CMD_SUCCESS;
2201 }
f188f2c4 2202
d62a17ae 2203 /* update-delay <delay> <establish-wait> */
d62a17ae 2204 if (update_delay < establish_wait) {
2205 vty_out(vty,
2206 "%%Failed: update-delay less than the establish-wait!\n");
2207 return CMD_WARNING_CONFIG_FAILED;
2208 }
f188f2c4 2209
d62a17ae 2210 bgp->v_update_delay = update_delay;
2211 bgp->v_establish_wait = establish_wait;
f188f2c4 2212
d62a17ae 2213 return CMD_SUCCESS;
f188f2c4
DS
2214}
2215
d62a17ae 2216static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2217{
d62a17ae 2218 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2219
d70583f7
D
2220 /* If configured globally, cannot remove from one bgp instance */
2221 if (bm->v_update_delay) {
2222 vty_out(vty,
2223 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2224 return CMD_WARNING_CONFIG_FAILED;
2225 }
d62a17ae 2226 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2227 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2228
d62a17ae 2229 return CMD_SUCCESS;
f188f2c4
DS
2230}
2231
2b791107 2232void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2233{
d70583f7
D
2234 /* If configured globally, no need to display per-instance value */
2235 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2236 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2237 if (bgp->v_update_delay != bgp->v_establish_wait)
2238 vty_out(vty, " %d", bgp->v_establish_wait);
2239 vty_out(vty, "\n");
2240 }
f188f2c4
DS
2241}
2242
d70583f7
D
2243/* Global update-delay configuration */
2244DEFPY (bgp_global_update_delay,
2245 bgp_global_update_delay_cmd,
2246 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2247 BGP_STR
2248 "Force initial delay for best-path and updates for all bgp instances\n"
2249 "Max delay in seconds\n"
2250 "Establish wait in seconds\n")
2251{
2252 return bgp_global_update_delay_config_vty(vty, delay, wait);
2253}
f188f2c4 2254
d70583f7
D
2255/* Global update-delay deconfiguration */
2256DEFPY (no_bgp_global_update_delay,
2257 no_bgp_global_update_delay_cmd,
2258 "no bgp update-delay [(0-3600) [(1-3600)]]",
2259 NO_STR
2260 BGP_STR
f188f2c4 2261 "Force initial delay for best-path and updates\n"
d70583f7
D
2262 "Max delay in seconds\n"
2263 "Establish wait in seconds\n")
f188f2c4 2264{
d70583f7 2265 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2266}
2267
d70583f7
D
2268/* Update-delay configuration */
2269
2270DEFPY (bgp_update_delay,
2271 bgp_update_delay_cmd,
2272 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2273 "Force initial delay for best-path and updates\n"
d70583f7
D
2274 "Max delay in seconds\n"
2275 "Establish wait in seconds\n")
f188f2c4 2276{
d70583f7 2277 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2278}
2279
2280/* Update-delay deconfiguration */
d70583f7 2281DEFPY (no_bgp_update_delay,
f188f2c4 2282 no_bgp_update_delay_cmd,
838758ac
DW
2283 "no update-delay [(0-3600) [(1-3600)]]",
2284 NO_STR
f188f2c4 2285 "Force initial delay for best-path and updates\n"
d70583f7
D
2286 "Max delay in seconds\n"
2287 "Establish wait in seconds\n")
f188f2c4 2288{
d62a17ae 2289 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2290}
2291
5e242b0d 2292
1ca2fd11
IR
2293static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2294 bool set)
cb1faec9 2295{
1ca2fd11
IR
2296 VTY_DECLVAR_CONTEXT(bgp, bgp);
2297
8fa7732f
QY
2298 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2299 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2300
2301 return CMD_SUCCESS;
2302}
2303
1ca2fd11
IR
2304static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2305 bool set)
555e09d4 2306{
1ca2fd11
IR
2307 VTY_DECLVAR_CONTEXT(bgp, bgp);
2308
8fa7732f
QY
2309 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2310 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2311
d62a17ae 2312 return CMD_SUCCESS;
cb1faec9
DS
2313}
2314
2b791107 2315void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2316{
555e09d4
QY
2317 uint32_t quanta =
2318 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2319 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2320 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2321}
2322
555e09d4
QY
2323void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2324{
2325 uint32_t quanta =
2326 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2327 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2328 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2329}
cb1faec9 2330
8fa7732f
QY
2331/* Packet quanta configuration
2332 *
2333 * XXX: The value set here controls the size of a stack buffer in the IO
2334 * thread. When changing these limits be careful to prevent stack overflow.
2335 *
2336 * Furthermore, the maximums used here should correspond to
2337 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2338 */
1ca2fd11
IR
2339DEFPY (bgp_wpkt_quanta,
2340 bgp_wpkt_quanta_cmd,
2341 "[no] write-quanta (1-64)$quanta",
2342 NO_STR
2343 "How many packets to write to peer socket per run\n"
2344 "Number of packets\n")
2345{
2346 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2347}
cb1faec9 2348
1ca2fd11
IR
2349DEFPY (bgp_rpkt_quanta,
2350 bgp_rpkt_quanta_cmd,
2351 "[no] read-quanta (1-10)$quanta",
2352 NO_STR
2353 "How many packets to read from peer socket per I/O cycle\n"
2354 "Number of packets\n")
2355{
2356 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
2357}
2358
2b791107 2359void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2360{
37a333fe 2361 if (!bgp->heuristic_coalesce)
d62a17ae 2362 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2363}
2364
d1adb448
PG
2365/* BGP TCP keepalive */
2366static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2367{
2368 if (bgp->tcp_keepalive_idle) {
2369 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2370 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2371 bgp->tcp_keepalive_probes);
2372 }
2373}
4668a151 2374
1ca2fd11
IR
2375DEFUN (bgp_coalesce_time,
2376 bgp_coalesce_time_cmd,
2377 "coalesce-time (0-4294967295)",
2378 "Subgroup coalesce timer\n"
2379 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2380{
1ca2fd11 2381 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 2382
1ca2fd11 2383 int idx = 0;
9b01d289 2384
1ca2fd11 2385 bgp->heuristic_coalesce = false;
9b01d289
DA
2386
2387 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2388 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2389
1ca2fd11 2390 return CMD_SUCCESS;
3f9c7369
DS
2391}
2392
1ca2fd11
IR
2393DEFUN (no_bgp_coalesce_time,
2394 no_bgp_coalesce_time_cmd,
2395 "no coalesce-time (0-4294967295)",
2396 NO_STR
2397 "Subgroup coalesce timer\n"
2398 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2399{
1ca2fd11 2400 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 2401
1ca2fd11
IR
2402 bgp->heuristic_coalesce = true;
2403 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2404 return CMD_SUCCESS;
3f9c7369
DS
2405}
2406
5e242b0d 2407/* Maximum-paths configuration */
585f1adc
IR
2408DEFUN (bgp_maxpaths,
2409 bgp_maxpaths_cmd,
2410 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2411 "Forward packets over multiple paths\n"
2412 "Number of paths\n")
5e242b0d 2413{
d62a17ae 2414 int idx_number = 1;
585f1adc
IR
2415 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2416 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
2417}
2418
d62a17ae 2419ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2420 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2421 "Forward packets over multiple paths\n"
2422 "Number of paths\n")
596c17ba 2423
585f1adc
IR
2424DEFUN (bgp_maxpaths_ibgp,
2425 bgp_maxpaths_ibgp_cmd,
2426 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2427 "Forward packets over multiple paths\n"
2428 "iBGP-multipath\n"
2429 "Number of paths\n")
165b5fff 2430{
d62a17ae 2431 int idx_number = 2;
585f1adc
IR
2432 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2433 argv[idx_number]->arg, 0, 1);
5e242b0d 2434}
165b5fff 2435
d62a17ae 2436ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2437 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2438 "Forward packets over multiple paths\n"
2439 "iBGP-multipath\n"
2440 "Number of paths\n")
596c17ba 2441
585f1adc
IR
2442DEFUN (bgp_maxpaths_ibgp_cluster,
2443 bgp_maxpaths_ibgp_cluster_cmd,
2444 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2445 "Forward packets over multiple paths\n"
2446 "iBGP-multipath\n"
2447 "Number of paths\n"
2448 "Match the cluster length\n")
5e242b0d 2449{
d62a17ae 2450 int idx_number = 2;
aa53c036
DS
2451 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2452 argv[idx_number]->arg, true, 1);
165b5fff
JB
2453}
2454
d62a17ae 2455ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2456 "maximum-paths ibgp " CMD_RANGE_STR(
2457 1, MULTIPATH_NUM) " equal-cluster-length",
2458 "Forward packets over multiple paths\n"
2459 "iBGP-multipath\n"
2460 "Number of paths\n"
2461 "Match the cluster length\n")
596c17ba 2462
585f1adc
IR
2463DEFUN (no_bgp_maxpaths,
2464 no_bgp_maxpaths_cmd,
2465 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2466 NO_STR
2467 "Forward packets over multiple paths\n"
2468 "Number of paths\n")
165b5fff 2469{
585f1adc 2470 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
2471}
2472
d62a17ae 2473ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2474 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2475 "Forward packets over multiple paths\n"
2476 "Number of paths\n")
596c17ba 2477
585f1adc
IR
2478DEFUN (no_bgp_maxpaths_ibgp,
2479 no_bgp_maxpaths_ibgp_cmd,
2480 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2481 NO_STR
2482 "Forward packets over multiple paths\n"
2483 "iBGP-multipath\n"
2484 "Number of paths\n"
2485 "Match the cluster length\n")
165b5fff 2486{
585f1adc 2487 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
2488}
2489
d62a17ae 2490ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2491 "no maximum-paths ibgp [" CMD_RANGE_STR(
2492 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2493 NO_STR
2494 "Forward packets over multiple paths\n"
2495 "iBGP-multipath\n"
2496 "Number of paths\n"
2497 "Match the cluster length\n")
596c17ba 2498
dd65f45e
DL
2499static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2500 afi_t afi, safi_t safi)
165b5fff 2501{
00908b7a 2502 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2503 vty_out(vty, " maximum-paths %d\n",
2504 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2505 }
165b5fff 2506
00908b7a 2507 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2508 vty_out(vty, " maximum-paths ibgp %d",
2509 bgp->maxpaths[afi][safi].maxpaths_ibgp);
aa53c036 2510 if (bgp->maxpaths[afi][safi].same_clusterlen)
d62a17ae 2511 vty_out(vty, " equal-cluster-length");
2512 vty_out(vty, "\n");
2513 }
165b5fff 2514}
6b0655a2 2515
718e3744 2516/* BGP timers. */
2517
1ca2fd11
IR
2518DEFUN (bgp_timers,
2519 bgp_timers_cmd,
2520 "timers bgp (0-65535) (0-65535)",
2521 "Adjust routing timers\n"
2522 "BGP timers\n"
2523 "Keepalive interval\n"
2524 "Holdtime\n")
718e3744 2525{
1ca2fd11 2526 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2527 int idx_number = 2;
2528 int idx_number_2 = 3;
1ca2fd11
IR
2529 unsigned long keepalive = 0;
2530 unsigned long holdtime = 0;
718e3744 2531
1ca2fd11
IR
2532 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2533 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 2534
1ca2fd11
IR
2535 /* Holdtime value check. */
2536 if (holdtime < 3 && holdtime != 0) {
2537 vty_out(vty,
2538 "%% hold time value must be either 0 or greater than 3\n");
2539 return CMD_WARNING_CONFIG_FAILED;
2540 }
718e3744 2541
1ca2fd11
IR
2542 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2543 BGP_DEFAULT_DELAYOPEN);
718e3744 2544
1ca2fd11 2545 return CMD_SUCCESS;
718e3744 2546}
2547
1ca2fd11
IR
2548DEFUN (no_bgp_timers,
2549 no_bgp_timers_cmd,
2550 "no timers bgp [(0-65535) (0-65535)]",
2551 NO_STR
2552 "Adjust routing timers\n"
2553 "BGP timers\n"
2554 "Keepalive interval\n"
2555 "Holdtime\n")
718e3744 2556{
1ca2fd11
IR
2557 VTY_DECLVAR_CONTEXT(bgp, bgp);
2558 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2559 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
ff8a8a7a 2560
1ca2fd11 2561 return CMD_SUCCESS;
718e3744 2562}
2563
b042667a
TI
2564/* BGP minimum holdtime. */
2565
2566DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2567 "bgp minimum-holdtime (1-65535)",
2568 "BGP specific commands\n"
2569 "BGP minimum holdtime\n"
2570 "Seconds\n")
2571{
2572 VTY_DECLVAR_CONTEXT(bgp, bgp);
2573 int idx_number = 2;
2574 unsigned long min_holdtime;
2575
2576 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2577
2578 bgp->default_min_holdtime = min_holdtime;
2579
2580 return CMD_SUCCESS;
2581}
2582
2583DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2584 "no bgp minimum-holdtime [(1-65535)]",
2585 NO_STR
2586 "BGP specific commands\n"
2587 "BGP minimum holdtime\n"
2588 "Seconds\n")
2589{
2590 VTY_DECLVAR_CONTEXT(bgp, bgp);
2591
2592 bgp->default_min_holdtime = 0;
2593
2594 return CMD_SUCCESS;
2595}
ff8a8a7a 2596
d1adb448
PG
2597DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2598 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2599 BGP_STR
2600 "TCP keepalive parameters\n"
2601 "TCP keepalive idle time (seconds)\n"
2602 "TCP keepalive interval (seconds)\n"
2603 "TCP keepalive maximum probes\n")
2604{
2605 VTY_DECLVAR_CONTEXT(bgp, bgp);
2606
2607 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2608 (uint16_t)probes);
2609
2610 return CMD_SUCCESS;
2611}
2612
2613DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2614 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2615 NO_STR
2616 BGP_STR
2617 "TCP keepalive parameters\n"
2618 "TCP keepalive idle time (seconds)\n"
2619 "TCP keepalive interval (seconds)\n"
2620 "TCP keepalive maximum probes\n")
2621{
2622 VTY_DECLVAR_CONTEXT(bgp, bgp);
2623
2624 bgp_tcp_keepalive_unset(bgp);
2625
2626 return CMD_SUCCESS;
2627}
2628
1ca2fd11
IR
2629DEFUN (bgp_client_to_client_reflection,
2630 bgp_client_to_client_reflection_cmd,
2631 "bgp client-to-client reflection",
e9273987 2632 BGP_STR
1ca2fd11
IR
2633 "Configure client to client route reflection\n"
2634 "reflection of routes allowed\n")
718e3744 2635{
1ca2fd11
IR
2636 VTY_DECLVAR_CONTEXT(bgp, bgp);
2637 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2638 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2639
1ca2fd11 2640 return CMD_SUCCESS;
718e3744 2641}
2642
1ca2fd11
IR
2643DEFUN (no_bgp_client_to_client_reflection,
2644 no_bgp_client_to_client_reflection_cmd,
2645 "no bgp client-to-client reflection",
2646 NO_STR
e9273987 2647 BGP_STR
1ca2fd11
IR
2648 "Configure client to client route reflection\n"
2649 "reflection of routes allowed\n")
718e3744 2650{
1ca2fd11
IR
2651 VTY_DECLVAR_CONTEXT(bgp, bgp);
2652 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2653 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2654
1ca2fd11 2655 return CMD_SUCCESS;
718e3744 2656}
2657
2658/* "bgp always-compare-med" configuration. */
1ca2fd11
IR
2659DEFUN (bgp_always_compare_med,
2660 bgp_always_compare_med_cmd,
2661 "bgp always-compare-med",
e9273987 2662 BGP_STR
1ca2fd11 2663 "Allow comparing MED from different neighbors\n")
718e3744 2664{
1ca2fd11
IR
2665 VTY_DECLVAR_CONTEXT(bgp, bgp);
2666 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2667 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2668
1ca2fd11 2669 return CMD_SUCCESS;
718e3744 2670}
2671
1ca2fd11
IR
2672DEFUN (no_bgp_always_compare_med,
2673 no_bgp_always_compare_med_cmd,
2674 "no bgp always-compare-med",
2675 NO_STR
e9273987 2676 BGP_STR
1ca2fd11 2677 "Allow comparing MED from different neighbors\n")
718e3744 2678{
1ca2fd11
IR
2679 VTY_DECLVAR_CONTEXT(bgp, bgp);
2680 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2681 bgp_recalculate_all_bestpaths(bgp);
6b0655a2 2682
1ca2fd11 2683 return CMD_SUCCESS;
2adac256
DA
2684}
2685
2adac256 2686
1ca2fd11
IR
2687DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2688 "bgp ebgp-requires-policy",
e9273987 2689 BGP_STR
1ca2fd11 2690 "Require in and out policy for eBGP peers (RFC8212)\n")
2adac256 2691{
1ca2fd11
IR
2692 VTY_DECLVAR_CONTEXT(bgp, bgp);
2693 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2694 return CMD_SUCCESS;
2adac256
DA
2695}
2696
1ca2fd11
IR
2697DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2698 "no bgp ebgp-requires-policy",
2699 NO_STR
e9273987 2700 BGP_STR
1ca2fd11 2701 "Require in and out policy for eBGP peers (RFC8212)\n")
ff8a8a7a 2702{
1ca2fd11
IR
2703 VTY_DECLVAR_CONTEXT(bgp, bgp);
2704 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2705 return CMD_SUCCESS;
ff8a8a7a 2706}
9dac9fc8 2707
1ca2fd11
IR
2708DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2709 "bgp suppress-duplicates",
e9273987 2710 BGP_STR
1ca2fd11 2711 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2712{
1ca2fd11
IR
2713 VTY_DECLVAR_CONTEXT(bgp, bgp);
2714 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2715 return CMD_SUCCESS;
9dac9fc8
DA
2716}
2717
1ca2fd11
IR
2718DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2719 "no bgp suppress-duplicates",
2720 NO_STR
e9273987 2721 BGP_STR
1ca2fd11 2722 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2723{
1ca2fd11
IR
2724 VTY_DECLVAR_CONTEXT(bgp, bgp);
2725 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2726 return CMD_SUCCESS;
9dac9fc8
DA
2727}
2728
fb29348a
DA
2729DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2730 "bgp reject-as-sets",
e9273987 2731 BGP_STR
fb29348a
DA
2732 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2733{
2734 VTY_DECLVAR_CONTEXT(bgp, bgp);
2735 struct listnode *node, *nnode;
2736 struct peer *peer;
2737
7f972cd8 2738 bgp->reject_as_sets = true;
fb29348a
DA
2739
2740 /* Reset existing BGP sessions to reject routes
2741 * with aspath containing AS_SET or AS_CONFED_SET.
2742 */
2743 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2744 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2745 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2746 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2747 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2748 }
2749 }
2750
2751 return CMD_SUCCESS;
2752}
2753
2754DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2755 "no bgp reject-as-sets",
2756 NO_STR
e9273987 2757 BGP_STR
fb29348a
DA
2758 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2759{
2760 VTY_DECLVAR_CONTEXT(bgp, bgp);
2761 struct listnode *node, *nnode;
2762 struct peer *peer;
2763
7f972cd8 2764 bgp->reject_as_sets = false;
fb29348a
DA
2765
2766 /* Reset existing BGP sessions to reject routes
2767 * with aspath containing AS_SET or AS_CONFED_SET.
2768 */
2769 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2770 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2771 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2772 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2773 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2774 }
2775 }
2776
2777 return CMD_SUCCESS;
2778}
9dac9fc8 2779
718e3744 2780/* "bgp deterministic-med" configuration. */
1ca2fd11 2781DEFUN (bgp_deterministic_med,
718e3744 2782 bgp_deterministic_med_cmd,
2783 "bgp deterministic-med",
e9273987 2784 BGP_STR
718e3744 2785 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2786{
1ca2fd11
IR
2787 VTY_DECLVAR_CONTEXT(bgp, bgp);
2788
2789 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2790 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2791 bgp_recalculate_all_bestpaths(bgp);
2792 }
7aafcaca 2793
1ca2fd11 2794 return CMD_SUCCESS;
718e3744 2795}
2796
1ca2fd11 2797DEFUN (no_bgp_deterministic_med,
718e3744 2798 no_bgp_deterministic_med_cmd,
2799 "no bgp deterministic-med",
2800 NO_STR
e9273987 2801 BGP_STR
718e3744 2802 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2803{
1ca2fd11
IR
2804 VTY_DECLVAR_CONTEXT(bgp, bgp);
2805 int bestpath_per_as_used;
2806 afi_t afi;
2807 safi_t safi;
2808 struct peer *peer;
2809 struct listnode *node, *nnode;
2810
2811 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2812 bestpath_per_as_used = 0;
2813
2814 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2815 FOREACH_AFI_SAFI (afi, safi)
2816 if (bgp_addpath_dmed_required(
2817 peer->addpath_type[afi][safi])) {
2818 bestpath_per_as_used = 1;
2819 break;
2820 }
2821
2822 if (bestpath_per_as_used)
2823 break;
2824 }
2825
2826 if (bestpath_per_as_used) {
2827 vty_out(vty,
2828 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2829 return CMD_WARNING_CONFIG_FAILED;
2830 } else {
2831 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2832 bgp_recalculate_all_bestpaths(bgp);
2833 }
2834 }
d62a17ae 2835
1ca2fd11 2836 return CMD_SUCCESS;
718e3744 2837}
538621f2 2838
055679e9 2839/* "bgp graceful-restart mode" configuration. */
538621f2 2840DEFUN (bgp_graceful_restart,
2ba1fe69 2841 bgp_graceful_restart_cmd,
2842 "bgp graceful-restart",
e9273987 2843 BGP_STR
2ba1fe69 2844 GR_CMD
055679e9 2845 )
538621f2 2846{
055679e9 2847 int ret = BGP_GR_FAILURE;
2848
2849 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2850 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2851
d62a17ae 2852 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2853
2854 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2855
36235319
QY
2856 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2857 ret);
5cce3f05 2858
055679e9 2859 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2860 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2861 vty_out(vty,
2862 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2863 return bgp_vty_return(vty, ret);
538621f2 2864}
2865
2866DEFUN (no_bgp_graceful_restart,
2ba1fe69 2867 no_bgp_graceful_restart_cmd,
2868 "no bgp graceful-restart",
2869 NO_STR
e9273987 2870 BGP_STR
2ba1fe69 2871 NO_GR_CMD
055679e9 2872 )
538621f2 2873{
d62a17ae 2874 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2875
2876 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2877 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2878
2879 int ret = BGP_GR_FAILURE;
2880
2881 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2882
36235319
QY
2883 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2884 ret);
5cce3f05 2885
055679e9 2886 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2887 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2888 vty_out(vty,
2889 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2890
2891 return bgp_vty_return(vty, ret);
538621f2 2892}
2893
93406d87 2894DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2895 bgp_graceful_restart_stalepath_time_cmd,
2896 "bgp graceful-restart stalepath-time (1-4095)",
e9273987 2897 BGP_STR
2ba1fe69 2898 "Graceful restart capability parameters\n"
2899 "Set the max time to hold onto restarting peer's stale paths\n"
2900 "Delay value (seconds)\n")
93406d87 2901{
d62a17ae 2902 VTY_DECLVAR_CONTEXT(bgp, bgp);
2903 int idx_number = 3;
d7c0a89a 2904 uint32_t stalepath;
93406d87 2905
d62a17ae 2906 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2907 bgp->stalepath_time = stalepath;
2908 return CMD_SUCCESS;
93406d87 2909}
2910
eb6f1b41 2911DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2912 bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2913 "bgp graceful-restart restart-time (0-4095)",
e9273987 2914 BGP_STR
2ba1fe69 2915 "Graceful restart capability parameters\n"
2916 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2917 "Delay value (seconds)\n")
eb6f1b41 2918{
d62a17ae 2919 VTY_DECLVAR_CONTEXT(bgp, bgp);
2920 int idx_number = 3;
d7c0a89a 2921 uint32_t restart;
eb6f1b41 2922
d62a17ae 2923 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2924 bgp->restart_time = restart;
2925 return CMD_SUCCESS;
eb6f1b41
PG
2926}
2927
cfd47646 2928DEFUN (bgp_graceful_restart_select_defer_time,
2929 bgp_graceful_restart_select_defer_time_cmd,
2930 "bgp graceful-restart select-defer-time (0-3600)",
e9273987 2931 BGP_STR
cfd47646 2932 "Graceful restart capability parameters\n"
2933 "Set the time to defer the BGP route selection after restart\n"
2934 "Delay value (seconds, 0 - disable)\n")
2935{
2936 VTY_DECLVAR_CONTEXT(bgp, bgp);
2937 int idx_number = 3;
2938 uint32_t defer_time;
2939
2940 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2941 bgp->select_defer_time = defer_time;
2942 if (defer_time == 0)
892fedb6 2943 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2944 else
892fedb6 2945 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2946
2947 return CMD_SUCCESS;
2948}
2949
93406d87 2950DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2951 no_bgp_graceful_restart_stalepath_time_cmd,
2952 "no bgp graceful-restart stalepath-time [(1-4095)]",
2953 NO_STR
e9273987 2954 BGP_STR
2ba1fe69 2955 "Graceful restart capability parameters\n"
2956 "Set the max time to hold onto restarting peer's stale paths\n"
2957 "Delay value (seconds)\n")
93406d87 2958{
d62a17ae 2959 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2960
d62a17ae 2961 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2962 return CMD_SUCCESS;
93406d87 2963}
2964
eb6f1b41 2965DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2966 no_bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2967 "no bgp graceful-restart restart-time [(0-4095)]",
2ba1fe69 2968 NO_STR
e9273987 2969 BGP_STR
2ba1fe69 2970 "Graceful restart capability parameters\n"
2971 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2972 "Delay value (seconds)\n")
eb6f1b41 2973{
d62a17ae 2974 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2975
d62a17ae 2976 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2977 return CMD_SUCCESS;
eb6f1b41
PG
2978}
2979
cfd47646 2980DEFUN (no_bgp_graceful_restart_select_defer_time,
2981 no_bgp_graceful_restart_select_defer_time_cmd,
2982 "no bgp graceful-restart select-defer-time [(0-3600)]",
2983 NO_STR
e9273987 2984 BGP_STR
cfd47646 2985 "Graceful restart capability parameters\n"
2986 "Set the time to defer the BGP route selection after restart\n"
2987 "Delay value (seconds)\n")
2988{
2989 VTY_DECLVAR_CONTEXT(bgp, bgp);
2990
2991 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2992 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2993
2994 return CMD_SUCCESS;
2995}
2996
43fc21b3 2997DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2998 bgp_graceful_restart_preserve_fw_cmd,
2999 "bgp graceful-restart preserve-fw-state",
e9273987 3000 BGP_STR
2ba1fe69 3001 "Graceful restart capability parameters\n"
3002 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 3003{
d62a17ae 3004 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3005 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 3006 return CMD_SUCCESS;
43fc21b3
JC
3007}
3008
3009DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 3010 no_bgp_graceful_restart_preserve_fw_cmd,
3011 "no bgp graceful-restart preserve-fw-state",
3012 NO_STR
e9273987 3013 BGP_STR
2ba1fe69 3014 "Graceful restart capability parameters\n"
3015 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 3016{
d62a17ae 3017 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3018 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 3019 return CMD_SUCCESS;
43fc21b3
JC
3020}
3021
f2ca5c5b
DA
3022DEFPY (bgp_graceful_restart_notification,
3023 bgp_graceful_restart_notification_cmd,
3024 "[no$no] bgp graceful-restart notification",
3025 NO_STR
3026 BGP_STR
3027 "Graceful restart capability parameters\n"
3028 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3029{
3030 VTY_DECLVAR_CONTEXT(bgp, bgp);
3031
3032 if (no)
3033 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3034 else
3035 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3036
3037 return CMD_SUCCESS;
3038}
3039
1ae314be
DA
3040DEFPY (bgp_administrative_reset,
3041 bgp_administrative_reset_cmd,
3042 "[no$no] bgp hard-administrative-reset",
3043 NO_STR
3044 BGP_STR
3045 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3046{
3047 VTY_DECLVAR_CONTEXT(bgp, bgp);
3048
3049 if (no)
3050 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3051 else
3052 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3053
3054 return CMD_SUCCESS;
3055}
3056
055679e9 3057DEFUN (bgp_graceful_restart_disable,
2ba1fe69 3058 bgp_graceful_restart_disable_cmd,
3059 "bgp graceful-restart-disable",
e9273987 3060 BGP_STR
2ba1fe69 3061 GR_DISABLE)
055679e9 3062{
3063 int ret = BGP_GR_FAILURE;
3064
3065 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3066 zlog_debug(
2ba1fe69 3067 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 3068
055679e9 3069 VTY_DECLVAR_CONTEXT(bgp, bgp);
3070
3071 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3072
dc95985f 3073 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3074 bgp->peer, ret);
5cce3f05 3075
055679e9 3076 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3077 zlog_debug(
2ba1fe69 3078 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 3079 vty_out(vty,
3080 "Graceful restart configuration changed, reset all peers to take effect\n");
3081
055679e9 3082 return bgp_vty_return(vty, ret);
3083}
3084
3085DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 3086 no_bgp_graceful_restart_disable_cmd,
3087 "no bgp graceful-restart-disable",
3088 NO_STR
e9273987 3089 BGP_STR
2ba1fe69 3090 NO_GR_DISABLE
055679e9 3091 )
3092{
3093 VTY_DECLVAR_CONTEXT(bgp, bgp);
3094
3095 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3096 zlog_debug(
2ba1fe69 3097 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 3098
3099 int ret = BGP_GR_FAILURE;
3100
3101 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3102
36235319
QY
3103 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3104 ret);
5cce3f05 3105
055679e9 3106 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3107 zlog_debug(
2ba1fe69 3108 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 3109 vty_out(vty,
3110 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 3111
3112 return bgp_vty_return(vty, ret);
3113}
3114
3115DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 3116 bgp_neighbor_graceful_restart_set_cmd,
3117 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3118 NEIGHBOR_STR
3119 NEIGHBOR_ADDR_STR2
3120 GR_NEIGHBOR_CMD
055679e9 3121 )
3122{
3123 int idx_peer = 1;
3124 struct peer *peer;
3125 int ret = BGP_GR_FAILURE;
3126
dc95985f 3127 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3128
055679e9 3129 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3130 zlog_debug(
2ba1fe69 3131 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 3132
055679e9 3133 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3134 if (!peer)
3135 return CMD_WARNING_CONFIG_FAILED;
3136
3137 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3138
dc95985f 3139 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3140 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3141
3142 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3143 zlog_debug(
2ba1fe69 3144 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3145 vty_out(vty,
3146 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3147
3148 return bgp_vty_return(vty, ret);
3149}
3150
3151DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 3152 no_bgp_neighbor_graceful_restart_set_cmd,
3153 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3154 NO_STR
3155 NEIGHBOR_STR
3156 NEIGHBOR_ADDR_STR2
3157 NO_GR_NEIGHBOR_CMD
055679e9 3158 )
3159{
3160 int idx_peer = 2;
3161 int ret = BGP_GR_FAILURE;
3162 struct peer *peer;
3163
dc95985f 3164 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3165
055679e9 3166 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3167 if (!peer)
3168 return CMD_WARNING_CONFIG_FAILED;
3169
3170 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3171 zlog_debug(
2ba1fe69 3172 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 3173
3174 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3175
dc95985f 3176 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3177 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3178
3179 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3180 zlog_debug(
2ba1fe69 3181 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3182 vty_out(vty,
3183 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3184
3185 return bgp_vty_return(vty, ret);
3186}
3187
3188DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 3189 bgp_neighbor_graceful_restart_helper_set_cmd,
3190 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3191 NEIGHBOR_STR
3192 NEIGHBOR_ADDR_STR2
3193 GR_NEIGHBOR_HELPER_CMD
055679e9 3194 )
3195{
3196 int idx_peer = 1;
3197 struct peer *peer;
3198 int ret = BGP_GR_FAILURE;
3199
dc95985f 3200 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3201
055679e9 3202 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3203 zlog_debug(
2ba1fe69 3204 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 3205
055679e9 3206 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3207
055679e9 3208 if (!peer)
3209 return CMD_WARNING_CONFIG_FAILED;
3210
3211
3212 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 3213
dc95985f 3214 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3215 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 3216
055679e9 3217 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3218 zlog_debug(
2ba1fe69 3219 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3220 vty_out(vty,
3221 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3222
3223 return bgp_vty_return(vty, ret);
3224}
3225
3226DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3227 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3228 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3229 NO_STR
3230 NEIGHBOR_STR
3231 NEIGHBOR_ADDR_STR2
3232 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3233 )
3234{
3235 int idx_peer = 2;
3236 int ret = BGP_GR_FAILURE;
3237 struct peer *peer;
3238
dc95985f 3239 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3240
055679e9 3241 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3242 if (!peer)
3243 return CMD_WARNING_CONFIG_FAILED;
3244
3245 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3246 zlog_debug(
2ba1fe69 3247 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3248
36235319 3249 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3250
dc95985f 3251 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3252 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3253
3254 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3255 zlog_debug(
2ba1fe69 3256 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3257 vty_out(vty,
3258 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3259
3260 return bgp_vty_return(vty, ret);
3261}
3262
3263DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3264 bgp_neighbor_graceful_restart_disable_set_cmd,
3265 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3266 NEIGHBOR_STR
3267 NEIGHBOR_ADDR_STR2
3268 GR_NEIGHBOR_DISABLE_CMD
055679e9 3269 )
3270{
3271 int idx_peer = 1;
3272 struct peer *peer;
3273 int ret = BGP_GR_FAILURE;
3274
dc95985f 3275 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3276
055679e9 3277 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3278 zlog_debug(
2ba1fe69 3279 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3280
3281 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3282 if (!peer)
3283 return CMD_WARNING_CONFIG_FAILED;
3284
36235319 3285 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3286
3287 if (peer->bgp->t_startup)
3288 bgp_peer_gr_flags_update(peer);
3289
dc95985f 3290 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3291 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3292
055679e9 3293 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3294 zlog_debug(
2ba1fe69 3295 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3296 vty_out(vty,
3297 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3298
3299 return bgp_vty_return(vty, ret);
3300}
3301
3302DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3303 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3304 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3305 NO_STR
3306 NEIGHBOR_STR
3307 NEIGHBOR_ADDR_STR2
3308 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3309 )
3310{
3311 int idx_peer = 2;
3312 int ret = BGP_GR_FAILURE;
3313 struct peer *peer;
3314
dc95985f 3315 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3316
055679e9 3317 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3318 if (!peer)
3319 return CMD_WARNING_CONFIG_FAILED;
3320
3321 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3322 zlog_debug(
2ba1fe69 3323 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3324
3325 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3326
dc95985f 3327 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3328 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3329
3330 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3331 zlog_debug(
2ba1fe69 3332 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3333 vty_out(vty,
3334 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3335
3336 return bgp_vty_return(vty, ret);
3337}
3338
d6e3c15b 3339DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3340 bgp_graceful_restart_disable_eor_cmd,
3341 "bgp graceful-restart disable-eor",
e9273987 3342 BGP_STR
d6e3c15b 3343 "Graceful restart configuration parameters\n"
3344 "Disable EOR Check\n")
3345{
3346 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3347 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3348
d6e3c15b 3349 return CMD_SUCCESS;
3350}
3351
3352DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3353 no_bgp_graceful_restart_disable_eor_cmd,
3354 "no bgp graceful-restart disable-eor",
3355 NO_STR
e9273987 3356 BGP_STR
d6e3c15b 3357 "Graceful restart configuration parameters\n"
3358 "Disable EOR Check\n")
3359{
3360 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3361 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3362
3363 return CMD_SUCCESS;
3364}
3365
3366DEFUN (bgp_graceful_restart_rib_stale_time,
3367 bgp_graceful_restart_rib_stale_time_cmd,
3368 "bgp graceful-restart rib-stale-time (1-3600)",
e9273987 3369 BGP_STR
dc95985f 3370 "Graceful restart configuration parameters\n"
3371 "Specify the stale route removal timer in rib\n"
3372 "Delay value (seconds)\n")
3373{
3374 VTY_DECLVAR_CONTEXT(bgp, bgp);
3375 int idx_number = 3;
3376 uint32_t stale_time;
3377
3378 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3379 bgp->rib_stale_time = stale_time;
3380 /* Send the stale timer update message to RIB */
3381 if (bgp_zebra_stale_timer_update(bgp))
3382 return CMD_WARNING;
3383
3384 return CMD_SUCCESS;
3385}
3386
3387DEFUN (no_bgp_graceful_restart_rib_stale_time,
3388 no_bgp_graceful_restart_rib_stale_time_cmd,
3389 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3390 NO_STR
e9273987 3391 BGP_STR
dc95985f 3392 "Graceful restart configuration parameters\n"
3393 "Specify the stale route removal timer in rib\n"
3394 "Delay value (seconds)\n")
3395{
3396 VTY_DECLVAR_CONTEXT(bgp, bgp);
3397
3398 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3399 /* Send the stale timer update message to RIB */
3400 if (bgp_zebra_stale_timer_update(bgp))
3401 return CMD_WARNING;
3402
d6e3c15b 3403 return CMD_SUCCESS;
3404}
3405
8606be87 3406DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
7f8a9a24
DA
3407 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3408 BGP_STR
8606be87
DA
3409 "Enable Long-lived Graceful Restart\n"
3410 "Specifies maximum time to wait before purging long-lived stale routes\n"
3411 "Stale time value (seconds)\n")
3412{
3413 VTY_DECLVAR_CONTEXT(bgp, bgp);
3414
3415 uint32_t llgr_stale_time;
3416
3417 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3418 bgp->llgr_stale_time = llgr_stale_time;
3419
3420 return CMD_SUCCESS;
3421}
3422
3423DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
7f8a9a24 3424 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
8606be87
DA
3425 NO_STR BGP_STR
3426 "Enable Long-lived Graceful Restart\n"
3427 "Specifies maximum time to wait before purging long-lived stale routes\n"
3428 "Stale time value (seconds)\n")
3429{
3430 VTY_DECLVAR_CONTEXT(bgp, bgp);
3431
3432 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3433
3434 return CMD_SUCCESS;
3435}
3436
1ca2fd11
IR
3437static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3438 struct bgp *bgp)
05bd726c 3439{
3440 bgp_static_redo_import_check(bgp);
3441 bgp_redistribute_redo(bgp);
1ca2fd11
IR
3442 bgp_clear_star_soft_out(vty, bgp->name);
3443 bgp_clear_star_soft_in(vty, bgp->name);
05bd726c 3444}
3445
3446static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3447{
3448 struct listnode *node, *nnode;
3449 struct bgp *bgp;
3450 bool vrf_cfg = false;
3451
3452 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3453 return CMD_SUCCESS;
3454
3455 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3456 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3457 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3458 vty_out(vty,
3459 "%% graceful-shutdown configuration found in vrf %s\n",
3460 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3461 VRF_DEFAULT_NAME : bgp->name);
3462 vrf_cfg = true;
3463 }
3464 }
3465
3466 if (vrf_cfg) {
3467 vty_out(vty,
3468 "%%Failed: global graceful-shutdown not permitted\n");
3469 return CMD_WARNING;
3470 }
3471
3472 /* Set flag globally */
3473 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3474
3475 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3476 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3477 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3478
3479 return CMD_SUCCESS;
3480}
3481
3482static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3483{
3484 struct listnode *node, *nnode;
3485 struct bgp *bgp;
3486
3487 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3488 return CMD_SUCCESS;
3489
3490 /* Unset flag globally */
3491 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3492
3493 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3494 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3495 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3496
3497 return CMD_SUCCESS;
3498}
3499
7f323236
DW
3500/* "bgp graceful-shutdown" configuration */
3501DEFUN (bgp_graceful_shutdown,
3502 bgp_graceful_shutdown_cmd,
3503 "bgp graceful-shutdown",
3504 BGP_STR
3505 "Graceful shutdown parameters\n")
3506{
05bd726c 3507 if (vty->node == CONFIG_NODE)
3508 return bgp_global_graceful_shutdown_config_vty(vty);
3509
1ca2fd11 3510 VTY_DECLVAR_CONTEXT(bgp, bgp);
7f323236 3511
1ca2fd11
IR
3512 /* if configured globally, per-instance config is not allowed */
3513 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3514 vty_out(vty,
3515 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3516 return CMD_WARNING_CONFIG_FAILED;
3517 }
3518
3519 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3520 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3521 bgp_initiate_graceful_shut_unshut(vty, bgp);
3522 }
3523
3524 return CMD_SUCCESS;
7f323236
DW
3525}
3526
1ca2fd11 3527DEFUN (no_bgp_graceful_shutdown,
7f323236
DW
3528 no_bgp_graceful_shutdown_cmd,
3529 "no bgp graceful-shutdown",
3530 NO_STR
3531 BGP_STR
3532 "Graceful shutdown parameters\n")
3533{
05bd726c 3534 if (vty->node == CONFIG_NODE)
3535 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3536
1ca2fd11 3537 VTY_DECLVAR_CONTEXT(bgp, bgp);
05bd726c 3538
1ca2fd11
IR
3539 /* If configured globally, cannot remove from one bgp instance */
3540 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3541 vty_out(vty,
3542 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3543 return CMD_WARNING_CONFIG_FAILED;
3544 }
7f323236 3545
1ca2fd11
IR
3546 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3547 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3548 bgp_initiate_graceful_shut_unshut(vty, bgp);
3549 }
3550
3551 return CMD_SUCCESS;
7f323236
DW
3552}
3553
718e3744 3554/* "bgp fast-external-failover" configuration. */
1ca2fd11 3555DEFUN (bgp_fast_external_failover,
718e3744 3556 bgp_fast_external_failover_cmd,
3557 "bgp fast-external-failover",
3558 BGP_STR
3559 "Immediately reset session if a link to a directly connected external peer goes down\n")
3560{
1ca2fd11
IR
3561 VTY_DECLVAR_CONTEXT(bgp, bgp);
3562 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3563 return CMD_SUCCESS;
718e3744 3564}
3565
1ca2fd11 3566DEFUN (no_bgp_fast_external_failover,
718e3744 3567 no_bgp_fast_external_failover_cmd,
3568 "no bgp fast-external-failover",
3569 NO_STR
3570 BGP_STR
3571 "Immediately reset session if a link to a directly connected external peer goes down\n")
3572{
1ca2fd11
IR
3573 VTY_DECLVAR_CONTEXT(bgp, bgp);
3574 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3575 return CMD_SUCCESS;
718e3744 3576}
6b0655a2 3577
718e3744 3578/* "bgp bestpath compare-routerid" configuration. */
1ca2fd11
IR
3579DEFUN (bgp_bestpath_compare_router_id,
3580 bgp_bestpath_compare_router_id_cmd,
3581 "bgp bestpath compare-routerid",
e9273987 3582 BGP_STR
1ca2fd11
IR
3583 "Change the default bestpath selection\n"
3584 "Compare router-id for identical EBGP paths\n")
718e3744 3585{
1ca2fd11
IR
3586 VTY_DECLVAR_CONTEXT(bgp, bgp);
3587 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3588 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3589
1ca2fd11 3590 return CMD_SUCCESS;
718e3744 3591}
3592
1ca2fd11
IR
3593DEFUN (no_bgp_bestpath_compare_router_id,
3594 no_bgp_bestpath_compare_router_id_cmd,
3595 "no bgp bestpath compare-routerid",
3596 NO_STR
e9273987 3597 BGP_STR
1ca2fd11
IR
3598 "Change the default bestpath selection\n"
3599 "Compare router-id for identical EBGP paths\n")
718e3744 3600{
1ca2fd11
IR
3601 VTY_DECLVAR_CONTEXT(bgp, bgp);
3602 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3603 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3604
1ca2fd11 3605 return CMD_SUCCESS;
718e3744 3606}
6b0655a2 3607
718e3744 3608/* "bgp bestpath as-path ignore" configuration. */
1ca2fd11
IR
3609DEFUN (bgp_bestpath_aspath_ignore,
3610 bgp_bestpath_aspath_ignore_cmd,
3611 "bgp bestpath as-path ignore",
e9273987 3612 BGP_STR
1ca2fd11
IR
3613 "Change the default bestpath selection\n"
3614 "AS-path attribute\n"
3615 "Ignore as-path length in selecting a route\n")
718e3744 3616{
1ca2fd11
IR
3617 VTY_DECLVAR_CONTEXT(bgp, bgp);
3618 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3619 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3620
1ca2fd11 3621 return CMD_SUCCESS;
718e3744 3622}
3623
1ca2fd11
IR
3624DEFUN (no_bgp_bestpath_aspath_ignore,
3625 no_bgp_bestpath_aspath_ignore_cmd,
3626 "no bgp bestpath as-path ignore",
3627 NO_STR
e9273987 3628 BGP_STR
1ca2fd11
IR
3629 "Change the default bestpath selection\n"
3630 "AS-path attribute\n"
3631 "Ignore as-path length in selecting a route\n")
718e3744 3632{
1ca2fd11
IR
3633 VTY_DECLVAR_CONTEXT(bgp, bgp);
3634 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3635 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3636
1ca2fd11 3637 return CMD_SUCCESS;
718e3744 3638}
6b0655a2 3639
6811845b 3640/* "bgp bestpath as-path confed" configuration. */
1ca2fd11 3641DEFUN (bgp_bestpath_aspath_confed,
6811845b 3642 bgp_bestpath_aspath_confed_cmd,
3643 "bgp bestpath as-path confed",
e9273987 3644 BGP_STR
6811845b 3645 "Change the default bestpath selection\n"
3646 "AS-path attribute\n"
3647 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3648{
1ca2fd11
IR
3649 VTY_DECLVAR_CONTEXT(bgp, bgp);
3650 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3651 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3652
1ca2fd11 3653 return CMD_SUCCESS;
6811845b 3654}
3655
1ca2fd11 3656DEFUN (no_bgp_bestpath_aspath_confed,
6811845b 3657 no_bgp_bestpath_aspath_confed_cmd,
3658 "no bgp bestpath as-path confed",
3659 NO_STR
e9273987 3660 BGP_STR
6811845b 3661 "Change the default bestpath selection\n"
3662 "AS-path attribute\n"
3663 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3664{
1ca2fd11
IR
3665 VTY_DECLVAR_CONTEXT(bgp, bgp);
3666 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3667 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3668
1ca2fd11 3669 return CMD_SUCCESS;
6811845b 3670}
6b0655a2 3671
2fdd455c 3672/* "bgp bestpath as-path multipath-relax" configuration. */
1ca2fd11 3673DEFUN (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3674 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3675 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
e9273987 3676 BGP_STR
16fc1eec
DS
3677 "Change the default bestpath selection\n"
3678 "AS-path attribute\n"
3679 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3680 "Generate an AS_SET\n"
16fc1eec
DS
3681 "Do not generate an AS_SET\n")
3682{
1ca2fd11 3683 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3684 int idx = 0;
1ca2fd11 3685 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 3686
1ca2fd11
IR
3687 /* no-as-set is now the default behavior so we can silently
3688 * ignore it */
d62a17ae 3689 if (argv_find(argv, argc, "as-set", &idx))
1ca2fd11 3690 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 3691 else
1ca2fd11 3692 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
7aafcaca 3693
1ca2fd11
IR
3694 bgp_recalculate_all_bestpaths(bgp);
3695
3696 return CMD_SUCCESS;
16fc1eec
DS
3697}
3698
1ca2fd11 3699DEFUN (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3700 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3701 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec 3702 NO_STR
e9273987 3703 BGP_STR
16fc1eec
DS
3704 "Change the default bestpath selection\n"
3705 "AS-path attribute\n"
3706 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3707 "Generate an AS_SET\n"
16fc1eec
DS
3708 "Do not generate an AS_SET\n")
3709{
1ca2fd11
IR
3710 VTY_DECLVAR_CONTEXT(bgp, bgp);
3711 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3712 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3713 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3714
1ca2fd11 3715 return CMD_SUCCESS;
2fdd455c 3716}
6b0655a2 3717
ee88563a
JM
3718/* "bgp bestpath peer-type multipath-relax" configuration. */
3719DEFUN(bgp_bestpath_peer_type_multipath_relax,
3720 bgp_bestpath_peer_type_multipath_relax_cmd,
3721 "bgp bestpath peer-type multipath-relax",
3722 BGP_STR
3723 "Change the default bestpath selection\n"
3724 "Peer type\n"
3725 "Allow load sharing across routes learned from different peer types\n")
3726{
3727 VTY_DECLVAR_CONTEXT(bgp, bgp);
3728 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3729 bgp_recalculate_all_bestpaths(bgp);
3730
3731 return CMD_SUCCESS;
3732}
3733
3734DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3735 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3736 "no bgp bestpath peer-type multipath-relax",
3737 NO_STR BGP_STR
3738 "Change the default bestpath selection\n"
3739 "Peer type\n"
3740 "Allow load sharing across routes learned from different peer types\n")
3741{
3742 VTY_DECLVAR_CONTEXT(bgp, bgp);
3743 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3744 bgp_recalculate_all_bestpaths(bgp);
3745
3746 return CMD_SUCCESS;
3747}
3748
848973c7 3749/* "bgp log-neighbor-changes" configuration. */
1ca2fd11
IR
3750DEFUN (bgp_log_neighbor_changes,
3751 bgp_log_neighbor_changes_cmd,
3752 "bgp log-neighbor-changes",
e9273987 3753 BGP_STR
1ca2fd11 3754 "Log neighbor up/down and reset reason\n")
848973c7 3755{
1ca2fd11
IR
3756 VTY_DECLVAR_CONTEXT(bgp, bgp);
3757 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3758 return CMD_SUCCESS;
848973c7 3759}
3760
1ca2fd11
IR
3761DEFUN (no_bgp_log_neighbor_changes,
3762 no_bgp_log_neighbor_changes_cmd,
3763 "no bgp log-neighbor-changes",
3764 NO_STR
e9273987 3765 BGP_STR
1ca2fd11 3766 "Log neighbor up/down and reset reason\n")
848973c7 3767{
1ca2fd11
IR
3768 VTY_DECLVAR_CONTEXT(bgp, bgp);
3769 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3770 return CMD_SUCCESS;
848973c7 3771}
6b0655a2 3772
718e3744 3773/* "bgp bestpath med" configuration. */
1ca2fd11 3774DEFUN (bgp_bestpath_med,
718e3744 3775 bgp_bestpath_med_cmd,
2d8c1a4d 3776 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
e9273987 3777 BGP_STR
718e3744 3778 "Change the default bestpath selection\n"
3779 "MED attribute\n"
3780 "Compare MED among confederation paths\n"
838758ac
DW
3781 "Treat missing MED as the least preferred one\n"
3782 "Treat missing MED as the least preferred one\n"
3783 "Compare MED among confederation paths\n")
718e3744 3784{
1ca2fd11 3785 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3786
1ca2fd11 3787 int idx = 0;
d62a17ae 3788 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3789 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3790 idx = 0;
3791 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11 3792 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 3793
1ca2fd11 3794 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3795
1ca2fd11 3796 return CMD_SUCCESS;
718e3744 3797}
3798
1ca2fd11 3799DEFUN (no_bgp_bestpath_med,
718e3744 3800 no_bgp_bestpath_med_cmd,
2d8c1a4d 3801 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3802 NO_STR
e9273987 3803 BGP_STR
718e3744 3804 "Change the default bestpath selection\n"
3805 "MED attribute\n"
3806 "Compare MED among confederation paths\n"
3a2d747c
QY
3807 "Treat missing MED as the least preferred one\n"
3808 "Treat missing MED as the least preferred one\n"
3809 "Compare MED among confederation paths\n")
718e3744 3810{
1ca2fd11 3811 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3812
1ca2fd11 3813 int idx = 0;
d62a17ae 3814 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3815 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3816 idx = 0;
3817 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11
IR
3818 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3819
3820 bgp_recalculate_all_bestpaths(bgp);
718e3744 3821
1ca2fd11 3822 return CMD_SUCCESS;
718e3744 3823}
3824
f7e1c681 3825/* "bgp bestpath bandwidth" configuration. */
3826DEFPY (bgp_bestpath_bw,
3827 bgp_bestpath_bw_cmd,
ad36d216 3828 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
e9273987 3829 BGP_STR
f7e1c681 3830 "Change the default bestpath selection\n"
3831 "Link Bandwidth attribute\n"
3832 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3833 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3834 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3835{
3836 VTY_DECLVAR_CONTEXT(bgp, bgp);
3837 afi_t afi;
3838 safi_t safi;
3839
ad36d216
DS
3840 if (!bw_cfg) {
3841 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3842 return CMD_ERR_INCOMPLETE;
f7e1c681 3843 }
ad36d216
DS
3844 if (!strcmp(bw_cfg, "ignore"))
3845 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3846 else if (!strcmp(bw_cfg, "skip-missing"))
3847 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3848 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3849 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3850 else
3851 return CMD_ERR_NO_MATCH;
f7e1c681 3852
3853 /* This config is used in route install, so redo that. */
3854 FOREACH_AFI_SAFI (afi, safi) {
3855 if (!bgp_fibupd_safi(safi))
3856 continue;
3857 bgp_zebra_announce_table(bgp, afi, safi);
3858 }
3859
3860 return CMD_SUCCESS;
3861}
3862
ad36d216
DS
3863DEFPY (no_bgp_bestpath_bw,
3864 no_bgp_bestpath_bw_cmd,
3865 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3866 NO_STR
e9273987 3867 BGP_STR
ad36d216
DS
3868 "Change the default bestpath selection\n"
3869 "Link Bandwidth attribute\n"
3870 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3871 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3872 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3873{
3874 VTY_DECLVAR_CONTEXT(bgp, bgp);
3875 afi_t afi;
3876 safi_t safi;
3877
3878 bgp->lb_handling = BGP_LINK_BW_ECMP;
3879
3880 /* This config is used in route install, so redo that. */
3881 FOREACH_AFI_SAFI (afi, safi) {
3882 if (!bgp_fibupd_safi(safi))
3883 continue;
3884 bgp_zebra_announce_table(bgp, afi, safi);
3885 }
3886 return CMD_SUCCESS;
3887}
3888
b16bcbba 3889DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
38d11af5
TA
3890 "[no] bgp default <ipv4-unicast|"
3891 "ipv4-multicast|"
3892 "ipv4-vpn|"
3893 "ipv4-labeled-unicast|"
3894 "ipv4-flowspec|"
3895 "ipv6-unicast|"
3896 "ipv6-multicast|"
3897 "ipv6-vpn|"
3898 "ipv6-labeled-unicast|"
3899 "ipv6-flowspec|"
3900 "l2vpn-evpn>$afi_safi",
b16bcbba 3901 NO_STR
e9273987 3902 BGP_STR
e84c59af 3903 "Configure BGP defaults\n"
b16bcbba 3904 "Activate ipv4-unicast for a peer by default\n"
38d11af5
TA
3905 "Activate ipv4-multicast for a peer by default\n"
3906 "Activate ipv4-vpn for a peer by default\n"
3907 "Activate ipv4-labeled-unicast for a peer by default\n"
3908 "Activate ipv4-flowspec for a peer by default\n"
3909 "Activate ipv6-unicast for a peer by default\n"
3910 "Activate ipv6-multicast for a peer by default\n"
3911 "Activate ipv6-vpn for a peer by default\n"
3912 "Activate ipv6-labeled-unicast for a peer by default\n"
3913 "Activate ipv6-flowspec for a peer by default\n"
3914 "Activate l2vpn-evpn for a peer by default\n")
e84c59af
DA
3915{
3916 VTY_DECLVAR_CONTEXT(bgp, bgp);
b16bcbba
TA
3917 char afi_safi_str[strlen(afi_safi) + 1];
3918 char *afi_safi_str_tok;
e84c59af 3919
b16bcbba
TA
3920 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3921 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3922 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3923 afi_t afi = bgp_vty_afi_from_str(afi_str);
38d11af5 3924 safi_t safi;
e84c59af 3925
d880a643
DS
3926 /*
3927 * Impossible situation but making coverity happy
3928 */
3929 assert(afi != AFI_MAX);
3930
38d11af5
TA
3931 if (strmatch(safi_str, "labeled"))
3932 safi = bgp_vty_safi_from_str("labeled-unicast");
3933 else
3934 safi = bgp_vty_safi_from_str(safi_str);
b16bcbba 3935
f609bcd6 3936 assert(safi != SAFI_MAX);
b16bcbba
TA
3937 if (no)
3938 bgp->default_af[afi][safi] = false;
38d11af5
TA
3939 else {
3940 if ((safi == SAFI_LABELED_UNICAST
3941 && bgp->default_af[afi][SAFI_UNICAST])
3942 || (safi == SAFI_UNICAST
3943 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3944 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3945 else
3946 bgp->default_af[afi][safi] = true;
3947 }
718e3744 3948
d62a17ae 3949 return CMD_SUCCESS;
718e3744 3950}
6b0655a2 3951
04b6bdc0 3952/* Display hostname in certain command outputs */
1ca2fd11 3953DEFUN (bgp_default_show_hostname,
04b6bdc0
DW
3954 bgp_default_show_hostname_cmd,
3955 "bgp default show-hostname",
e9273987 3956 BGP_STR
04b6bdc0 3957 "Configure BGP defaults\n"
0437e105 3958 "Show hostname in certain command outputs\n")
04b6bdc0 3959{
1ca2fd11
IR
3960 VTY_DECLVAR_CONTEXT(bgp, bgp);
3961 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3962 return CMD_SUCCESS;
ff8a8a7a
CS
3963}
3964
1ca2fd11
IR
3965DEFUN (no_bgp_default_show_hostname,
3966 no_bgp_default_show_hostname_cmd,
3967 "no bgp default show-hostname",
3968 NO_STR
e9273987 3969 BGP_STR
1ca2fd11
IR
3970 "Configure BGP defaults\n"
3971 "Show hostname in certain command outputs\n")
ff8a8a7a 3972{
1ca2fd11
IR
3973 VTY_DECLVAR_CONTEXT(bgp, bgp);
3974 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3975 return CMD_SUCCESS;
04b6bdc0
DW
3976}
3977
aef999a2 3978/* Display hostname in certain command outputs */
1d80f243
IR
3979DEFUN (bgp_default_show_nexthop_hostname,
3980 bgp_default_show_nexthop_hostname_cmd,
3981 "bgp default show-nexthop-hostname",
e9273987 3982 BGP_STR
1d80f243
IR
3983 "Configure BGP defaults\n"
3984 "Show hostname for nexthop in certain command outputs\n")
aef999a2 3985{
1ca2fd11
IR
3986 VTY_DECLVAR_CONTEXT(bgp, bgp);
3987 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3988 return CMD_SUCCESS;
aef999a2
DA
3989}
3990
3991DEFUN (no_bgp_default_show_nexthop_hostname,
3992 no_bgp_default_show_nexthop_hostname_cmd,
3993 "no bgp default show-nexthop-hostname",
3994 NO_STR
e9273987 3995 BGP_STR
aef999a2
DA
3996 "Configure BGP defaults\n"
3997 "Show hostname for nexthop in certain command outputs\n")
3998{
1ca2fd11
IR
3999 VTY_DECLVAR_CONTEXT(bgp, bgp);
4000 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4001 return CMD_SUCCESS;
aef999a2
DA
4002}
4003
8233ef81 4004/* "bgp network import-check" configuration. */
1ca2fd11
IR
4005DEFUN (bgp_network_import_check,
4006 bgp_network_import_check_cmd,
4007 "bgp network import-check",
e9273987 4008 BGP_STR
1ca2fd11
IR
4009 "BGP network command\n"
4010 "Check BGP network route exists in IGP\n")
718e3744 4011{
1ca2fd11
IR
4012 VTY_DECLVAR_CONTEXT(bgp, bgp);
4013 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4014 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4015 bgp_static_redo_import_check(bgp);
4016 }
078430f6 4017
1ca2fd11 4018 return CMD_SUCCESS;
718e3744 4019}
4020
d62a17ae 4021ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4022 "bgp network import-check exact",
e9273987 4023 BGP_STR
d62a17ae 4024 "BGP network command\n"
4025 "Check BGP network route exists in IGP\n"
4026 "Match route precisely\n")
8233ef81 4027
1ca2fd11
IR
4028DEFUN (no_bgp_network_import_check,
4029 no_bgp_network_import_check_cmd,
4030 "no bgp network import-check",
4031 NO_STR
e9273987 4032 BGP_STR
1ca2fd11
IR
4033 "BGP network command\n"
4034 "Check BGP network route exists in IGP\n")
718e3744 4035{
1ca2fd11
IR
4036 VTY_DECLVAR_CONTEXT(bgp, bgp);
4037 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4038 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4039 bgp_static_redo_import_check(bgp);
4040 }
6b0655a2 4041
1ca2fd11 4042 return CMD_SUCCESS;
ff8a8a7a 4043}
718e3744 4044
1ca2fd11
IR
4045DEFUN (bgp_default_local_preference,
4046 bgp_default_local_preference_cmd,
4047 "bgp default local-preference (0-4294967295)",
e9273987 4048 BGP_STR
1ca2fd11
IR
4049 "Configure BGP defaults\n"
4050 "local preference (higher=more preferred)\n"
4051 "Configure default local preference value\n")
ff8a8a7a 4052{
1ca2fd11 4053 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 4054 int idx_number = 3;
1ca2fd11 4055 uint32_t local_pref;
718e3744 4056
1ca2fd11 4057 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 4058
1ca2fd11
IR
4059 bgp_default_local_preference_set(bgp, local_pref);
4060 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 4061
1ca2fd11 4062 return CMD_SUCCESS;
718e3744 4063}
4064
1ca2fd11
IR
4065DEFUN (no_bgp_default_local_preference,
4066 no_bgp_default_local_preference_cmd,
4067 "no bgp default local-preference [(0-4294967295)]",
4068 NO_STR
e9273987 4069 BGP_STR
1ca2fd11
IR
4070 "Configure BGP defaults\n"
4071 "local preference (higher=more preferred)\n"
4072 "Configure default local preference value\n")
ff8a8a7a 4073{
1ca2fd11
IR
4074 VTY_DECLVAR_CONTEXT(bgp, bgp);
4075 bgp_default_local_preference_unset(bgp);
4076 bgp_clear_star_soft_in(vty, bgp->name);
4077
4078 return CMD_SUCCESS;
ff8a8a7a 4079}
6b0655a2 4080
ff8a8a7a 4081
1ca2fd11
IR
4082DEFUN (bgp_default_subgroup_pkt_queue_max,
4083 bgp_default_subgroup_pkt_queue_max_cmd,
4084 "bgp default subgroup-pkt-queue-max (20-100)",
e9273987 4085 BGP_STR
1ca2fd11
IR
4086 "Configure BGP defaults\n"
4087 "subgroup-pkt-queue-max\n"
4088 "Configure subgroup packet queue max\n")
8bd9d948 4089{
1ca2fd11 4090 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4091 int idx_number = 3;
1ca2fd11 4092 uint32_t max_size;
3f9c7369 4093
1ca2fd11 4094 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 4095
1ca2fd11 4096 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
ff8a8a7a 4097
1ca2fd11 4098 return CMD_SUCCESS;
8bd9d948
DS
4099}
4100
1ca2fd11
IR
4101DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4102 no_bgp_default_subgroup_pkt_queue_max_cmd,
4103 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4104 NO_STR
e9273987 4105 BGP_STR
1ca2fd11
IR
4106 "Configure BGP defaults\n"
4107 "subgroup-pkt-queue-max\n"
4108 "Configure subgroup packet queue max\n")
ff8a8a7a 4109{
1ca2fd11
IR
4110 VTY_DECLVAR_CONTEXT(bgp, bgp);
4111 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4112 return CMD_SUCCESS;
ff8a8a7a 4113}
813d4307 4114
8bd9d948 4115
1ca2fd11
IR
4116DEFUN (bgp_rr_allow_outbound_policy,
4117 bgp_rr_allow_outbound_policy_cmd,
4118 "bgp route-reflector allow-outbound-policy",
e9273987 4119 BGP_STR
1ca2fd11
IR
4120 "Allow modifications made by out route-map\n"
4121 "on ibgp neighbors\n")
ff8a8a7a 4122{
1ca2fd11 4123 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 4124
1ca2fd11
IR
4125 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4126 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4127 update_group_announce_rrclients(bgp);
4128 bgp_clear_star_soft_out(vty, bgp->name);
4129 }
8bd9d948 4130
1ca2fd11
IR
4131 return CMD_SUCCESS;
4132}
ff8a8a7a 4133
1ca2fd11
IR
4134DEFUN (no_bgp_rr_allow_outbound_policy,
4135 no_bgp_rr_allow_outbound_policy_cmd,
4136 "no bgp route-reflector allow-outbound-policy",
4137 NO_STR
e9273987 4138 BGP_STR
1ca2fd11
IR
4139 "Allow modifications made by out route-map\n"
4140 "on ibgp neighbors\n")
8bd9d948 4141{
1ca2fd11 4142 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 4143
1ca2fd11
IR
4144 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4145 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4146 update_group_announce_rrclients(bgp);
4147 bgp_clear_star_soft_out(vty, bgp->name);
d62a17ae 4148 }
8bd9d948 4149
1ca2fd11 4150 return CMD_SUCCESS;
8bd9d948
DS
4151}
4152
1ca2fd11
IR
4153DEFUN (bgp_listen_limit,
4154 bgp_listen_limit_cmd,
4155 "bgp listen limit (1-65535)",
e9273987 4156 BGP_STR
1ca2fd11
IR
4157 "BGP Dynamic Neighbors listen commands\n"
4158 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4159 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4160{
1ca2fd11 4161 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4162 int idx_number = 3;
1ca2fd11
IR
4163 int listen_limit;
4164
4165 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 4166
1ca2fd11 4167 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 4168
1ca2fd11 4169 return CMD_SUCCESS;
f14e6fdb
DS
4170}
4171
1ca2fd11
IR
4172DEFUN (no_bgp_listen_limit,
4173 no_bgp_listen_limit_cmd,
4174 "no bgp listen limit [(1-65535)]",
4175 NO_STR
e9273987 4176 BGP_STR
1ca2fd11
IR
4177 "BGP Dynamic Neighbors listen commands\n"
4178 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4179 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4180{
1ca2fd11
IR
4181 VTY_DECLVAR_CONTEXT(bgp, bgp);
4182 bgp_listen_limit_unset(bgp);
4183 return CMD_SUCCESS;
f14e6fdb
DS
4184}
4185
4186
20eb8864 4187/*
4188 * Check if this listen range is already configured. Check for exact
4189 * match or overlap based on input.
4190 */
d62a17ae 4191static struct peer_group *listen_range_exists(struct bgp *bgp,
4192 struct prefix *range, int exact)
4193{
4194 struct listnode *node, *nnode;
4195 struct listnode *node1, *nnode1;
4196 struct peer_group *group;
4197 struct prefix *lr;
4198 afi_t afi;
4199 int match;
4200
4201 afi = family2afi(range->family);
4202 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4203 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4204 lr)) {
4205 if (exact)
4206 match = prefix_same(range, lr);
4207 else
4208 match = (prefix_match(range, lr)
4209 || prefix_match(lr, range));
4210 if (match)
4211 return group;
4212 }
4213 }
4214
4215 return NULL;
20eb8864 4216}
4217
f14e6fdb
DS
4218DEFUN (bgp_listen_range,
4219 bgp_listen_range_cmd,
d7b9898c 4220 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
e9273987 4221 BGP_STR
d7fa34c1
QY
4222 "Configure BGP dynamic neighbors listen range\n"
4223 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
4224 NEIGHBOR_ADDR_STR
4225 "Member of the peer-group\n"
4226 "Peer-group name\n")
f14e6fdb 4227{
d62a17ae 4228 VTY_DECLVAR_CONTEXT(bgp, bgp);
4229 struct prefix range;
4230 struct peer_group *group, *existing_group;
4231 afi_t afi;
4232 int ret;
4233 int idx = 0;
4234
4235 argv_find(argv, argc, "A.B.C.D/M", &idx);
4236 argv_find(argv, argc, "X:X::X:X/M", &idx);
4237 char *prefix = argv[idx]->arg;
d7b9898c 4238 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4239 char *peergroup = argv[idx]->arg;
4240
4241 /* Convert IP prefix string to struct prefix. */
4242 ret = str2prefix(prefix, &range);
4243 if (!ret) {
4244 vty_out(vty, "%% Malformed listen range\n");
4245 return CMD_WARNING_CONFIG_FAILED;
4246 }
4247
4248 afi = family2afi(range.family);
4249
4250 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4251 vty_out(vty,
4252 "%% Malformed listen range (link-local address)\n");
4253 return CMD_WARNING_CONFIG_FAILED;
4254 }
4255
4256 apply_mask(&range);
4257
4258 /* Check if same listen range is already configured. */
4259 existing_group = listen_range_exists(bgp, &range, 1);
4260 if (existing_group) {
4261 if (strcmp(existing_group->name, peergroup) == 0)
4262 return CMD_SUCCESS;
4263 else {
4264 vty_out(vty,
4265 "%% Same listen range is attached to peer-group %s\n",
4266 existing_group->name);
4267 return CMD_WARNING_CONFIG_FAILED;
4268 }
4269 }
4270
4271 /* Check if an overlapping listen range exists. */
4272 if (listen_range_exists(bgp, &range, 0)) {
4273 vty_out(vty,
4274 "%% Listen range overlaps with existing listen range\n");
4275 return CMD_WARNING_CONFIG_FAILED;
4276 }
4277
4278 group = peer_group_lookup(bgp, peergroup);
4279 if (!group) {
4280 vty_out(vty, "%% Configure the peer-group first\n");
4281 return CMD_WARNING_CONFIG_FAILED;
4282 }
4283
4284 ret = peer_group_listen_range_add(group, &range);
4285 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4286}
4287
4288DEFUN (no_bgp_listen_range,
4289 no_bgp_listen_range_cmd,
d7b9898c 4290 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4291 NO_STR
e9273987 4292 BGP_STR
d7fa34c1
QY
4293 "Unconfigure BGP dynamic neighbors listen range\n"
4294 "Unconfigure BGP dynamic neighbors listen range\n"
4295 NEIGHBOR_ADDR_STR
4296 "Member of the peer-group\n"
4297 "Peer-group name\n")
f14e6fdb 4298{
d62a17ae 4299 VTY_DECLVAR_CONTEXT(bgp, bgp);
4300 struct prefix range;
4301 struct peer_group *group;
4302 afi_t afi;
4303 int ret;
4304 int idx = 0;
4305
4306 argv_find(argv, argc, "A.B.C.D/M", &idx);
4307 argv_find(argv, argc, "X:X::X:X/M", &idx);
4308 char *prefix = argv[idx]->arg;
21d88a71 4309 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4310 char *peergroup = argv[idx]->arg;
4311
4312 /* Convert IP prefix string to struct prefix. */
4313 ret = str2prefix(prefix, &range);
4314 if (!ret) {
4315 vty_out(vty, "%% Malformed listen range\n");
4316 return CMD_WARNING_CONFIG_FAILED;
4317 }
4318
4319 afi = family2afi(range.family);
4320
4321 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4322 vty_out(vty,
4323 "%% Malformed listen range (link-local address)\n");
4324 return CMD_WARNING_CONFIG_FAILED;
4325 }
4326
4327 apply_mask(&range);
4328
4329 group = peer_group_lookup(bgp, peergroup);
4330 if (!group) {
4331 vty_out(vty, "%% Peer-group does not exist\n");
4332 return CMD_WARNING_CONFIG_FAILED;
4333 }
4334
4335 ret = peer_group_listen_range_del(group, &range);
4336 return bgp_vty_return(vty, ret);
4337}
4338
2b791107 4339void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4340{
4341 struct peer_group *group;
4342 struct listnode *node, *nnode, *rnode, *nrnode;
4343 struct prefix *range;
4344 afi_t afi;
d62a17ae 4345
4346 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4347 vty_out(vty, " bgp listen limit %d\n",
4348 bgp->dynamic_neighbors_limit);
4349
4350 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4351 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4352 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4353 nrnode, range)) {
d62a17ae 4354 vty_out(vty,
2dbe669b
DA
4355 " bgp listen range %pFX peer-group %s\n",
4356 range, group->name);
d62a17ae 4357 }
4358 }
4359 }
f14e6fdb
DS
4360}
4361
4362
1ca2fd11
IR
4363DEFUN (bgp_disable_connected_route_check,
4364 bgp_disable_connected_route_check_cmd,
4365 "bgp disable-ebgp-connected-route-check",
e9273987 4366 BGP_STR
1ca2fd11 4367 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4368{
1ca2fd11
IR
4369 VTY_DECLVAR_CONTEXT(bgp, bgp);
4370 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4371 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 4372
1ca2fd11 4373 return CMD_SUCCESS;
907f92c8
DS
4374}
4375
1ca2fd11
IR
4376DEFUN (no_bgp_disable_connected_route_check,
4377 no_bgp_disable_connected_route_check_cmd,
4378 "no bgp disable-ebgp-connected-route-check",
4379 NO_STR
e9273987 4380 BGP_STR
1ca2fd11 4381 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4382{
1ca2fd11
IR
4383 VTY_DECLVAR_CONTEXT(bgp, bgp);
4384 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4385 bgp_clear_star_soft_in(vty, bgp->name);
d62a17ae 4386
1ca2fd11 4387 return CMD_SUCCESS;
d62a17ae 4388}
4389
4390
28c6e247
IR
4391static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4392 const char *as_str)
4393{
4394 VTY_DECLVAR_CONTEXT(bgp, bgp);
4395 int ret;
4396 as_t as;
4397 int as_type = AS_SPECIFIED;
4398 union sockunion su;
4399
4400 if (as_str[0] == 'i') {
4401 as = 0;
4402 as_type = AS_INTERNAL;
4403 } else if (as_str[0] == 'e') {
4404 as = 0;
4405 as_type = AS_EXTERNAL;
4406 } else {
4407 /* Get AS number. */
4408 as = strtoul(as_str, NULL, 10);
4409 }
4410
4411 /* If peer is peer group or interface peer, call proper function. */
4412 ret = str2sockunion(peer_str, &su);
4413 if (ret < 0) {
4414 struct peer *peer;
4415
4416 /* Check if existing interface peer */
4417 peer = peer_lookup_by_conf_if(bgp, peer_str);
4418
4419 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4420
4421 /* if not interface peer, check peer-group settings */
4422 if (ret < 0 && !peer) {
4423 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4424 if (ret < 0) {
4425 vty_out(vty,
4426 "%% Create the peer-group or interface first\n");
4427 return CMD_WARNING_CONFIG_FAILED;
4428 }
4429 return CMD_SUCCESS;
4430 }
4431 } else {
4432 if (peer_address_self_check(bgp, &su)) {
4433 vty_out(vty,
4434 "%% Can not configure the local system as neighbor\n");
4435 return CMD_WARNING_CONFIG_FAILED;
4436 }
4437 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4438 }
4439
28c6e247
IR
4440 return bgp_vty_return(vty, ret);
4441}
4442
1ca2fd11
IR
4443DEFUN (bgp_default_shutdown,
4444 bgp_default_shutdown_cmd,
4445 "[no] bgp default shutdown",
4446 NO_STR
4447 BGP_STR
4448 "Configure BGP defaults\n"
4449 "Apply administrative shutdown to newly configured peers\n")
ff8a8a7a 4450{
1ca2fd11
IR
4451 VTY_DECLVAR_CONTEXT(bgp, bgp);
4452 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4453 return CMD_SUCCESS;
f26845f9
QY
4454}
4455
736b68f3
DS
4456DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4457 BGP_STR
9ddf4b81 4458 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4459 "Add a shutdown message (RFC 8203)\n"
4460 "Shutdown message\n")
9cf59432 4461{
736b68f3 4462 char *msgstr = NULL;
8389c83a 4463
9cf59432
DS
4464 VTY_DECLVAR_CONTEXT(bgp, bgp);
4465
8389c83a 4466 if (argc > 3)
f80e35b6 4467 msgstr = argv_concat(argv, argc, 3);
8389c83a 4468
b776f48c
DA
4469 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4470 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4471 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4472 return CMD_WARNING_CONFIG_FAILED;
4473 }
4474
8389c83a
DS
4475 bgp_shutdown_enable(bgp, msgstr);
4476 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4477
4478 return CMD_SUCCESS;
4479}
4480
736b68f3 4481DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4482 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4483{
4484 VTY_DECLVAR_CONTEXT(bgp, bgp);
4485
4486 bgp_shutdown_enable(bgp, NULL);
4487
4488 return CMD_SUCCESS;
4489}
8389c83a 4490
736b68f3 4491DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4492 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4493{
4494 VTY_DECLVAR_CONTEXT(bgp, bgp);
4495
4496 bgp_shutdown_disable(bgp);
4497
4498 return CMD_SUCCESS;
4499}
4500
9ddf4b81 4501ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4502 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4503 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4504 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4505
28c6e247
IR
4506DEFUN (neighbor_remote_as,
4507 neighbor_remote_as_cmd,
4508 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4509 NEIGHBOR_STR
4510 NEIGHBOR_ADDR_STR2
4511 "Specify a BGP neighbor\n"
4512 AS_STR
4513 "Internal BGP peer\n"
4514 "External BGP peer\n")
718e3744 4515{
d62a17ae 4516 int idx_peer = 1;
4517 int idx_remote_as = 3;
28c6e247
IR
4518 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4519 argv[idx_remote_as]->arg);
d62a17ae 4520}
8666265e
DS
4521
4522DEFPY (bgp_allow_martian,
4523 bgp_allow_martian_cmd,
4524 "[no]$no bgp allow-martian-nexthop",
4525 NO_STR
4526 BGP_STR
4527 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4528{
4529 VTY_DECLVAR_CONTEXT(bgp, bgp);
4530
4531 if (no)
4532 bgp->allow_martian = false;
4533 else
4534 bgp->allow_martian = true;
4535
4536 return CMD_SUCCESS;
4537}
4538
f852eb98
PG
4539/* Enable fast convergence of bgp sessions. If this is enabled, bgp
4540 * sessions do not wait for hold timer expiry to bring down the sessions
4541 * when nexthop becomes unreachable
4542 */
4543DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4544 BGP_STR "Fast convergence for bgp sessions\n")
4545{
4546 VTY_DECLVAR_CONTEXT(bgp, bgp);
4547 bgp->fast_convergence = true;
4548
4549 return CMD_SUCCESS;
4550}
4551
4552DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4553 "no bgp fast-convergence",
4554 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4555{
4556 VTY_DECLVAR_CONTEXT(bgp, bgp);
4557 bgp->fast_convergence = false;
4558
4559 return CMD_SUCCESS;
4560}
d62a17ae 4561
28c6e247
IR
4562static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4563 int v6only,
4564 const char *peer_group_name,
4565 const char *as_str)
d62a17ae 4566{
28c6e247
IR
4567 VTY_DECLVAR_CONTEXT(bgp, bgp);
4568 as_t as = 0;
4569 int as_type = AS_UNSPECIFIED;
d62a17ae 4570 struct peer *peer;
4571 struct peer_group *group;
4572 int ret = 0;
d62a17ae 4573
4574 group = peer_group_lookup(bgp, conf_if);
4575
4576 if (group) {
28c6e247
IR
4577 vty_out(vty, "%% Name conflict with peer-group \n");
4578 return CMD_WARNING_CONFIG_FAILED;
4579 }
4580
4581 if (as_str) {
4582 if (as_str[0] == 'i') {
4583 as_type = AS_INTERNAL;
4584 } else if (as_str[0] == 'e') {
4585 as_type = AS_EXTERNAL;
4586 } else {
4587 /* Get AS number. */
4588 as = strtoul(as_str, NULL, 10);
4589 as_type = AS_SPECIFIED;
4590 }
d62a17ae 4591 }
4592
4593 peer = peer_lookup_by_conf_if(bgp, conf_if);
4594 if (peer) {
28c6e247 4595 if (as_str)
e84c59af 4596 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
d62a17ae 4597 } else {
e84c59af
DA
4598 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4599 NULL);
d62a17ae 4600
4601 if (!peer) {
28c6e247
IR
4602 vty_out(vty, "%% BGP failed to create peer\n");
4603 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4604 }
4605
4606 if (v6only)
527de3dc 4607 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4608
4609 /* Request zebra to initiate IPv6 RAs on this interface. We do
4610 * this
4611 * any unnumbered peer in order to not worry about run-time
4612 * transitions
4613 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4614 * address
4615 * gets deleted later etc.)
4616 */
4617 if (peer->ifp)
4618 bgp_zebra_initiate_radv(bgp, peer);
4619 }
4620
4621 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4622 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4623 if (v6only)
527de3dc 4624 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4625 else
527de3dc 4626 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4627
4628 /* v6only flag changed. Reset bgp seesion */
4629 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4630 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4631 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4632 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4633 } else
4634 bgp_session_reset(peer);
4635 }
4636
9fb964de
PM
4637 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4638 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4639 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4640 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4641 }
d62a17ae 4642
4643 if (peer_group_name) {
4644 group = peer_group_lookup(bgp, peer_group_name);
4645 if (!group) {
28c6e247
IR
4646 vty_out(vty, "%% Configure the peer-group first\n");
4647 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4648 }
4649
8395c1f8 4650 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4651 }
4652
28c6e247 4653 return bgp_vty_return(vty, ret);
a80beece
DS
4654}
4655
28c6e247
IR
4656DEFUN (neighbor_interface_config,
4657 neighbor_interface_config_cmd,
4658 "neighbor WORD interface [peer-group PGNAME]",
4659 NEIGHBOR_STR
4660 "Interface name or neighbor tag\n"
4661 "Enable BGP on interface\n"
4662 "Member of the peer-group\n"
4663 "Peer-group name\n")
4c48cf63 4664{
d62a17ae 4665 int idx_word = 1;
4666 int idx_peer_group_word = 4;
f4b8ec07 4667
d62a17ae 4668 if (argc > idx_peer_group_word)
28c6e247
IR
4669 return peer_conf_interface_get(
4670 vty, argv[idx_word]->arg, 0,
4671 argv[idx_peer_group_word]->arg, NULL);
4672 else
4673 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4674 NULL, NULL);
4c48cf63
DW
4675}
4676
28c6e247
IR
4677DEFUN (neighbor_interface_config_v6only,
4678 neighbor_interface_config_v6only_cmd,
4679 "neighbor WORD interface v6only [peer-group PGNAME]",
4680 NEIGHBOR_STR
4681 "Interface name or neighbor tag\n"
4682 "Enable BGP on interface\n"
4683 "Enable BGP with v6 link-local only\n"
4684 "Member of the peer-group\n"
4685 "Peer-group name\n")
4c48cf63 4686{
d62a17ae 4687 int idx_word = 1;
4688 int idx_peer_group_word = 5;
31500417 4689
d62a17ae 4690 if (argc > idx_peer_group_word)
28c6e247
IR
4691 return peer_conf_interface_get(
4692 vty, argv[idx_word]->arg, 1,
4693 argv[idx_peer_group_word]->arg, NULL);
31500417 4694
28c6e247 4695 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4c48cf63
DW
4696}
4697
a80beece 4698
28c6e247
IR
4699DEFUN (neighbor_interface_config_remote_as,
4700 neighbor_interface_config_remote_as_cmd,
4701 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4702 NEIGHBOR_STR
4703 "Interface name or neighbor tag\n"
4704 "Enable BGP on interface\n"
4705 "Specify a BGP neighbor\n"
4706 AS_STR
4707 "Internal BGP peer\n"
4708 "External BGP peer\n")
b3a39dc5 4709{
d62a17ae 4710 int idx_word = 1;
4711 int idx_remote_as = 4;
28c6e247
IR
4712 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4713 argv[idx_remote_as]->arg);
b3a39dc5
DD
4714}
4715
28c6e247
IR
4716DEFUN (neighbor_interface_v6only_config_remote_as,
4717 neighbor_interface_v6only_config_remote_as_cmd,
4718 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4719 NEIGHBOR_STR
4720 "Interface name or neighbor tag\n"
4721 "Enable BGP with v6 link-local only\n"
4722 "Enable BGP on interface\n"
4723 "Specify a BGP neighbor\n"
4724 AS_STR
4725 "Internal BGP peer\n"
4726 "External BGP peer\n")
b3a39dc5 4727{
d62a17ae 4728 int idx_word = 1;
4729 int idx_remote_as = 5;
28c6e247
IR
4730 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4731 argv[idx_remote_as]->arg);
b3a39dc5
DD
4732}
4733
28c6e247
IR
4734DEFUN (neighbor_peer_group,
4735 neighbor_peer_group_cmd,
4736 "neighbor WORD peer-group",
4737 NEIGHBOR_STR
4738 "Interface name or neighbor tag\n"
4739 "Configure peer-group\n")
718e3744 4740{
28c6e247 4741 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4742 int idx_word = 1;
28c6e247
IR
4743 struct peer *peer;
4744 struct peer_group *group;
718e3744 4745
28c6e247
IR
4746 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4747 if (peer) {
4748 vty_out(vty, "%% Name conflict with interface: \n");
4749 return CMD_WARNING_CONFIG_FAILED;
4750 }
718e3744 4751
28c6e247
IR
4752 group = peer_group_get(bgp, argv[idx_word]->arg);
4753 if (!group) {
4754 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4755 return CMD_WARNING_CONFIG_FAILED;
4756 }
718e3744 4757
28c6e247 4758 return CMD_SUCCESS;
718e3744 4759}
4760
1d80f243
IR
4761DEFUN (no_neighbor,
4762 no_neighbor_cmd,
4763 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4764 NO_STR
4765 NEIGHBOR_STR
4766 NEIGHBOR_ADDR_STR2
4767 "Specify a BGP neighbor\n"
4768 AS_STR
4769 "Internal BGP peer\n"
4770 "External BGP peer\n")
718e3744 4771{
28c6e247 4772 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4773 int idx_peer = 2;
28c6e247 4774 int ret;
d62a17ae 4775 union sockunion su;
28c6e247
IR
4776 struct peer_group *group;
4777 struct peer *peer;
4778 struct peer *other;
d62a17ae 4779
28c6e247
IR
4780 ret = str2sockunion(argv[idx_peer]->arg, &su);
4781 if (ret < 0) {
4782 /* look up for neighbor by interface name config. */
4783 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4784 if (peer) {
4785 /* Request zebra to terminate IPv6 RAs on this
4786 * interface. */
4787 if (peer->ifp)
4788 bgp_zebra_terminate_radv(peer->bgp, peer);
4789 peer_notify_unconfig(peer);
4790 peer_delete(peer);
4791 return CMD_SUCCESS;
d62a17ae 4792 }
28c6e247
IR
4793
4794 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4795 if (group) {
4796 peer_group_notify_unconfig(group);
4797 peer_group_delete(group);
4e2786df 4798 } else {
28c6e247 4799 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4800 return CMD_WARNING_CONFIG_FAILED;
4801 }
28c6e247
IR
4802 } else {
4803 peer = peer_lookup(bgp, &su);
4804 if (peer) {
4805 if (peer_dynamic_neighbor(peer)) {
4806 vty_out(vty,
4807 "%% Operation not allowed on a dynamic neighbor\n");
4808 return CMD_WARNING_CONFIG_FAILED;
4809 }
d62a17ae 4810
28c6e247 4811 other = peer->doppelganger;
f4b8ec07 4812
28c6e247
IR
4813 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4814 bgp_zebra_terminate_radv(peer->bgp, peer);
f4b8ec07 4815
28c6e247
IR
4816 peer_notify_unconfig(peer);
4817 peer_delete(peer);
4818 if (other && other->status != Deleted) {
4819 peer_notify_unconfig(other);
4820 peer_delete(other);
4821 }
4822 }
4823 }
4824
4825 return CMD_SUCCESS;
a80beece
DS
4826}
4827
28c6e247
IR
4828DEFUN (no_neighbor_interface_config,
4829 no_neighbor_interface_config_cmd,
4830 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4831 NO_STR
4832 NEIGHBOR_STR
4833 "Interface name\n"
4834 "Configure BGP on interface\n"
4835 "Enable BGP with v6 link-local only\n"
4836 "Member of the peer-group\n"
4837 "Peer-group name\n"
4838 "Specify a BGP neighbor\n"
4839 AS_STR
4840 "Internal BGP peer\n"
4841 "External BGP peer\n")
718e3744 4842{
28c6e247 4843 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4844 int idx_word = 2;
28c6e247 4845 struct peer *peer;
718e3744 4846
28c6e247
IR
4847 /* look up for neighbor by interface name config. */
4848 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4849 if (peer) {
4850 /* Request zebra to terminate IPv6 RAs on this interface. */
4851 if (peer->ifp)
4852 bgp_zebra_terminate_radv(peer->bgp, peer);
4853 peer_notify_unconfig(peer);
4854 peer_delete(peer);
4855 } else {
4856 vty_out(vty, "%% Create the bgp interface first\n");
4857 return CMD_WARNING_CONFIG_FAILED;
4858 }
4859 return CMD_SUCCESS;
718e3744 4860}
4861
28c6e247
IR
4862DEFUN (no_neighbor_peer_group,
4863 no_neighbor_peer_group_cmd,
4864 "no neighbor WORD peer-group",
4865 NO_STR
4866 NEIGHBOR_STR
4867 "Neighbor tag\n"
4868 "Configure peer-group\n")
718e3744 4869{
28c6e247
IR
4870 VTY_DECLVAR_CONTEXT(bgp, bgp);
4871 int idx_word = 2;
4872 struct peer_group *group;
f4b8ec07 4873
28c6e247
IR
4874 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4875 if (group) {
4876 peer_group_notify_unconfig(group);
4877 peer_group_delete(group);
f4b8ec07 4878 } else {
28c6e247 4879 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4880 return CMD_WARNING_CONFIG_FAILED;
4881 }
28c6e247
IR
4882 return CMD_SUCCESS;
4883}
f4b8ec07 4884
28c6e247
IR
4885DEFUN (no_neighbor_interface_peer_group_remote_as,
4886 no_neighbor_interface_peer_group_remote_as_cmd,
4887 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4888 NO_STR
4889 NEIGHBOR_STR
4890 "Interface name or neighbor tag\n"
4891 "Specify a BGP neighbor\n"
4892 AS_STR
4893 "Internal BGP peer\n"
4894 "External BGP peer\n")
4895{
4896 VTY_DECLVAR_CONTEXT(bgp, bgp);
4897 int idx_word = 2;
4898 struct peer_group *group;
4899 struct peer *peer;
f4b8ec07 4900
28c6e247
IR
4901 /* look up for neighbor by interface name config. */
4902 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4903 if (peer) {
4904 peer_as_change(peer, 0, AS_UNSPECIFIED);
4905 return CMD_SUCCESS;
4906 }
f4b8ec07 4907
28c6e247
IR
4908 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4909 if (group)
4910 peer_group_remote_as_delete(group);
4911 else {
4912 vty_out(vty, "%% Create the peer-group or interface first\n");
4913 return CMD_WARNING_CONFIG_FAILED;
4914 }
4915 return CMD_SUCCESS;
718e3744 4916}
6b0655a2 4917
28c6e247
IR
4918DEFUN (neighbor_local_as,
4919 neighbor_local_as_cmd,
4920 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4921 NEIGHBOR_STR
4922 NEIGHBOR_ADDR_STR2
4923 "Specify a local-as number\n"
4924 "AS number used as local AS\n")
718e3744 4925{
d62a17ae 4926 int idx_peer = 1;
4927 int idx_number = 3;
28c6e247
IR
4928 struct peer *peer;
4929 int ret;
4930 as_t as;
718e3744 4931
28c6e247
IR
4932 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4933 if (!peer)
d62a17ae 4934 return CMD_WARNING_CONFIG_FAILED;
718e3744 4935
28c6e247
IR
4936 as = strtoul(argv[idx_number]->arg, NULL, 10);
4937 ret = peer_local_as_set(peer, as, 0, 0);
4938 return bgp_vty_return(vty, ret);
718e3744 4939}
4940
28c6e247
IR
4941DEFUN (neighbor_local_as_no_prepend,
4942 neighbor_local_as_no_prepend_cmd,
4943 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4944 NEIGHBOR_STR
4945 NEIGHBOR_ADDR_STR2
4946 "Specify a local-as number\n"
4947 "AS number used as local AS\n"
4948 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4949{
d62a17ae 4950 int idx_peer = 1;
4951 int idx_number = 3;
28c6e247
IR
4952 struct peer *peer;
4953 int ret;
4954 as_t as;
718e3744 4955
28c6e247
IR
4956 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4957 if (!peer)
d62a17ae 4958 return CMD_WARNING_CONFIG_FAILED;
718e3744 4959
28c6e247
IR
4960 as = strtoul(argv[idx_number]->arg, NULL, 10);
4961 ret = peer_local_as_set(peer, as, 1, 0);
4962 return bgp_vty_return(vty, ret);
718e3744 4963}
4964
28c6e247
IR
4965DEFUN (neighbor_local_as_no_prepend_replace_as,
4966 neighbor_local_as_no_prepend_replace_as_cmd,
4967 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4968 NEIGHBOR_STR
4969 NEIGHBOR_ADDR_STR2
4970 "Specify a local-as number\n"
4971 "AS number used as local AS\n"
4972 "Do not prepend local-as to updates from ebgp peers\n"
4973 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4974{
d62a17ae 4975 int idx_peer = 1;
4976 int idx_number = 3;
28c6e247
IR
4977 struct peer *peer;
4978 int ret;
4979 as_t as;
9d3f9705 4980
28c6e247
IR
4981 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4982 if (!peer)
d62a17ae 4983 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4984
28c6e247
IR
4985 as = strtoul(argv[idx_number]->arg, NULL, 10);
4986 ret = peer_local_as_set(peer, as, 1, 1);
4987 return bgp_vty_return(vty, ret);
9d3f9705
AC
4988}
4989
28c6e247
IR
4990DEFUN (no_neighbor_local_as,
4991 no_neighbor_local_as_cmd,
4992 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4993 NO_STR
4994 NEIGHBOR_STR
4995 NEIGHBOR_ADDR_STR2
4996 "Specify a local-as number\n"
4997 "AS number used as local AS\n"
4998 "Do not prepend local-as to updates from ebgp peers\n"
4999 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 5000{
d62a17ae 5001 int idx_peer = 2;
28c6e247
IR
5002 struct peer *peer;
5003 int ret;
718e3744 5004
28c6e247
IR
5005 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5006 if (!peer)
d62a17ae 5007 return CMD_WARNING_CONFIG_FAILED;
718e3744 5008
28c6e247
IR
5009 ret = peer_local_as_unset(peer);
5010 return bgp_vty_return(vty, ret);
718e3744 5011}
5012
718e3744 5013
3f9c7369
DS
5014DEFUN (neighbor_solo,
5015 neighbor_solo_cmd,
9ccf14f7 5016 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
5017 NEIGHBOR_STR
5018 NEIGHBOR_ADDR_STR2
5019 "Solo peer - part of its own update group\n")
5020{
d62a17ae 5021 int idx_peer = 1;
5022 struct peer *peer;
5023 int ret;
3f9c7369 5024
d62a17ae 5025 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5026 if (!peer)
5027 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 5028
d62a17ae 5029 ret = update_group_adjust_soloness(peer, 1);
5030 return bgp_vty_return(vty, ret);
3f9c7369
DS
5031}
5032
5033DEFUN (no_neighbor_solo,
5034 no_neighbor_solo_cmd,
9ccf14f7 5035 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
5036 NO_STR
5037 NEIGHBOR_STR
5038 NEIGHBOR_ADDR_STR2
5039 "Solo peer - part of its own update group\n")
5040{
d62a17ae 5041 int idx_peer = 2;
5042 struct peer *peer;
5043 int ret;
3f9c7369 5044
d62a17ae 5045 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5046 if (!peer)
5047 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 5048
d62a17ae 5049 ret = update_group_adjust_soloness(peer, 0);
5050 return bgp_vty_return(vty, ret);
3f9c7369
DS
5051}
5052
28c6e247
IR
5053DEFUN (neighbor_password,
5054 neighbor_password_cmd,
5055 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5056 NEIGHBOR_STR
5057 NEIGHBOR_ADDR_STR2
5058 "Set a password\n"
5059 "The password\n")
0df7c91f 5060{
d62a17ae 5061 int idx_peer = 1;
5062 int idx_line = 3;
28c6e247
IR
5063 struct peer *peer;
5064 int ret;
0df7c91f 5065
28c6e247
IR
5066 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5067 if (!peer)
d62a17ae 5068 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 5069
28c6e247
IR
5070 ret = peer_password_set(peer, argv[idx_line]->arg);
5071 return bgp_vty_return(vty, ret);
0df7c91f
PJ
5072}
5073
28c6e247
IR
5074DEFUN (no_neighbor_password,
5075 no_neighbor_password_cmd,
5076 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5077 NO_STR
5078 NEIGHBOR_STR
5079 NEIGHBOR_ADDR_STR2
5080 "Set a password\n"
5081 "The password\n")
0df7c91f 5082{
d62a17ae 5083 int idx_peer = 2;
28c6e247
IR
5084 struct peer *peer;
5085 int ret;
0df7c91f 5086
28c6e247
IR
5087 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5088 if (!peer)
d62a17ae 5089 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 5090
28c6e247
IR
5091 ret = peer_password_unset(peer);
5092 return bgp_vty_return(vty, ret);
0df7c91f 5093}
6b0655a2 5094
28c6e247
IR
5095DEFUN (neighbor_activate,
5096 neighbor_activate_cmd,
5097 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5098 NEIGHBOR_STR
5099 NEIGHBOR_ADDR_STR2
5100 "Enable the Address Family for this Neighbor\n")
718e3744 5101{
d62a17ae 5102 int idx_peer = 1;
28c6e247
IR
5103 int ret;
5104 struct peer *peer;
56ceae84 5105
28c6e247
IR
5106 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5107 if (!peer)
d62a17ae 5108 return CMD_WARNING_CONFIG_FAILED;
718e3744 5109
28c6e247
IR
5110 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5111 return bgp_vty_return(vty, ret);
718e3744 5112}
5113
d62a17ae 5114ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5115 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5116 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5117 "Enable the Address Family for this Neighbor\n")
596c17ba 5118
28c6e247
IR
5119DEFUN (no_neighbor_activate,
5120 no_neighbor_activate_cmd,
5121 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5122 NO_STR
5123 NEIGHBOR_STR
5124 NEIGHBOR_ADDR_STR2
5125 "Enable the Address Family for this Neighbor\n")
718e3744 5126{
d62a17ae 5127 int idx_peer = 2;
28c6e247
IR
5128 int ret;
5129 struct peer *peer;
f4b8ec07 5130
28c6e247
IR
5131 /* Lookup peer. */
5132 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5133 if (!peer)
d62a17ae 5134 return CMD_WARNING_CONFIG_FAILED;
718e3744 5135
28c6e247
IR
5136 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5137 return bgp_vty_return(vty, ret);
718e3744 5138}
6b0655a2 5139
d62a17ae 5140ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5141 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5142 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5143 "Enable the Address Family for this Neighbor\n")
596c17ba 5144
28c6e247
IR
5145DEFUN (neighbor_set_peer_group,
5146 neighbor_set_peer_group_cmd,
5147 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5148 NEIGHBOR_STR
5149 NEIGHBOR_ADDR_STR2
5150 "Member of the peer-group\n"
5151 "Peer-group name\n")
718e3744 5152{
28c6e247 5153 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5154 int idx_peer = 1;
5155 int idx_word = 3;
28c6e247
IR
5156 int ret;
5157 as_t as;
5158 union sockunion su;
5159 struct peer *peer;
5160 struct peer_group *group;
5161
5162 ret = str2sockunion(argv[idx_peer]->arg, &su);
5163 if (ret < 0) {
5164 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5165 if (!peer) {
5166 vty_out(vty, "%% Malformed address or name: %s\n",
5167 argv[idx_peer]->arg);
5168 return CMD_WARNING_CONFIG_FAILED;
5169 }
5170 } else {
5171 if (peer_address_self_check(bgp, &su)) {
5172 vty_out(vty,
5173 "%% Can not configure the local system as neighbor\n");
5174 return CMD_WARNING_CONFIG_FAILED;
5175 }
2a059a54 5176
28c6e247
IR
5177 /* Disallow for dynamic neighbor. */
5178 peer = peer_lookup(bgp, &su);
5179 if (peer && peer_dynamic_neighbor(peer)) {
5180 vty_out(vty,
5181 "%% Operation not allowed on a dynamic neighbor\n");
5182 return CMD_WARNING_CONFIG_FAILED;
5183 }
5184 }
5185
5186 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5187 if (!group) {
5188 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 5189 return CMD_WARNING_CONFIG_FAILED;
28c6e247 5190 }
d62a17ae 5191
28c6e247 5192 ret = peer_group_bind(bgp, &su, peer, group, &as);
2a059a54 5193
28c6e247 5194 return bgp_vty_return(vty, ret);
d62a17ae 5195}
5196
5197ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 5198 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5199 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5200 "Member of the peer-group\n"
5201 "Peer-group name\n")
596c17ba 5202
28c6e247
IR
5203DEFUN (no_neighbor_set_peer_group,
5204 no_neighbor_set_peer_group_cmd,
5205 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5206 NO_STR
5207 NEIGHBOR_STR
5208 NEIGHBOR_ADDR_STR2
5209 "Member of the peer-group\n"
5210 "Peer-group name\n")
718e3744 5211{
28c6e247 5212 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5213 int idx_peer = 2;
28c6e247
IR
5214 int idx_word = 4;
5215 int ret;
5216 struct peer *peer;
5217 struct peer_group *group;
d62a17ae 5218
28c6e247
IR
5219 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5220 if (!peer)
d62a17ae 5221 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 5222
28c6e247
IR
5223 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5224 if (!group) {
5225 vty_out(vty, "%% Configure the peer-group first\n");
5226 return CMD_WARNING_CONFIG_FAILED;
5227 }
718e3744 5228
28c6e247
IR
5229 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5230 bgp_zebra_terminate_radv(peer->bgp, peer);
5231
5232 peer_notify_unconfig(peer);
5233 ret = peer_delete(peer);
5234
5235 return bgp_vty_return(vty, ret);
718e3744 5236}
6b0655a2 5237
d62a17ae 5238ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
71cc0c88 5239 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5240 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5241 "Member of the peer-group\n"
5242 "Peer-group name\n")
596c17ba 5243
d62a17ae 5244static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
83194f39 5245 uint64_t flag, int set)
718e3744 5246{
d62a17ae 5247 int ret;
5248 struct peer *peer;
718e3744 5249
d62a17ae 5250 peer = peer_and_group_lookup_vty(vty, ip_str);
5251 if (!peer)
5252 return CMD_WARNING_CONFIG_FAILED;
718e3744 5253
7ebe625c
QY
5254 /*
5255 * If 'neighbor <interface>', then this is for directly connected peers,
5256 * we should not accept disable-connected-check.
5257 */
5258 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5259 vty_out(vty,
3efd0893 5260 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
5261 ip_str);
5262 return CMD_WARNING_CONFIG_FAILED;
5263 }
5264
d62a17ae 5265 if (!set && flag == PEER_FLAG_SHUTDOWN)
5266 peer_tx_shutdown_message_unset(peer);
ae9b0e11 5267
d62a17ae 5268 if (set)
5269 ret = peer_flag_set(peer, flag);
5270 else
5271 ret = peer_flag_unset(peer, flag);
718e3744 5272
d62a17ae 5273 return bgp_vty_return(vty, ret);
718e3744 5274}
5275
83194f39 5276static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
718e3744 5277{
d62a17ae 5278 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 5279}
5280
d62a17ae 5281static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
83194f39 5282 uint64_t flag)
718e3744 5283{
d62a17ae 5284 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 5285}
5286
5287/* neighbor passive. */
28c6e247
IR
5288DEFUN (neighbor_passive,
5289 neighbor_passive_cmd,
5290 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5291 NEIGHBOR_STR
5292 NEIGHBOR_ADDR_STR2
5293 "Don't send open messages to this neighbor\n")
718e3744 5294{
d62a17ae 5295 int idx_peer = 1;
28c6e247 5296 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5297}
5298
28c6e247
IR
5299DEFUN (no_neighbor_passive,
5300 no_neighbor_passive_cmd,
5301 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5302 NO_STR
5303 NEIGHBOR_STR
5304 NEIGHBOR_ADDR_STR2
5305 "Don't send open messages to this neighbor\n")
718e3744 5306{
d62a17ae 5307 int idx_peer = 2;
28c6e247 5308 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5309}
6b0655a2 5310
718e3744 5311/* neighbor shutdown. */
28c6e247
IR
5312DEFUN (neighbor_shutdown_msg,
5313 neighbor_shutdown_msg_cmd,
5314 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5315 NEIGHBOR_STR
5316 NEIGHBOR_ADDR_STR2
5317 "Administratively shut down this neighbor\n"
5318 "Add a shutdown message (RFC 8203)\n"
5319 "Shutdown message\n")
718e3744 5320{
d62a17ae 5321 int idx_peer = 1;
73d70fa6 5322
d62a17ae 5323 if (argc >= 5) {
28c6e247
IR
5324 struct peer *peer =
5325 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
d62a17ae 5326 char *message;
73d70fa6 5327
28c6e247
IR
5328 if (!peer)
5329 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5330 message = argv_concat(argv, argc, 4);
28c6e247
IR
5331 peer_tx_shutdown_message_set(peer, message);
5332 XFREE(MTYPE_TMP, message);
d62a17ae 5333 }
73d70fa6 5334
28c6e247 5335 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 5336}
5337
1d80f243 5338ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5339 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5340 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5341 "Administratively shut down this neighbor\n")
73d70fa6 5342
28c6e247
IR
5343DEFUN (no_neighbor_shutdown_msg,
5344 no_neighbor_shutdown_msg_cmd,
5345 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5346 NO_STR
5347 NEIGHBOR_STR
5348 NEIGHBOR_ADDR_STR2
5349 "Administratively shut down this neighbor\n"
5350 "Remove a shutdown message (RFC 8203)\n"
5351 "Shutdown message\n")
718e3744 5352{
d62a17ae 5353 int idx_peer = 2;
73d70fa6 5354
28c6e247
IR
5355 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5356 PEER_FLAG_SHUTDOWN);
718e3744 5357}
6b0655a2 5358
1d80f243 5359ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5360 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5361 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5362 "Administratively shut down this neighbor\n")
73d70fa6 5363
8336c896
DA
5364DEFUN(neighbor_shutdown_rtt,
5365 neighbor_shutdown_rtt_cmd,
5366 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5367 NEIGHBOR_STR
5368 NEIGHBOR_ADDR_STR2
5369 "Administratively shut down this neighbor\n"
5370 "Shutdown if round-trip-time is higher than expected\n"
5371 "Round-trip-time in milliseconds\n"
5372 "Specify the number of keepalives before shutdown\n"
5373 "The number of keepalives with higher RTT to shutdown\n")
5374{
5375 int idx_peer = 1;
5376 int idx_rtt = 4;
5377 int idx_count = 0;
5378 struct peer *peer;
5379
5380 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5381
5382 if (!peer)
5383 return CMD_WARNING_CONFIG_FAILED;
5384
5385 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5386
5387 if (argv_find(argv, argc, "count", &idx_count))
5388 peer->rtt_keepalive_conf =
5389 strtol(argv[idx_count + 1]->arg, NULL, 10);
5390
5391 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5392 PEER_FLAG_RTT_SHUTDOWN);
5393}
5394
5395DEFUN(no_neighbor_shutdown_rtt,
5396 no_neighbor_shutdown_rtt_cmd,
5397 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5398 NO_STR
5399 NEIGHBOR_STR
5400 NEIGHBOR_ADDR_STR2
5401 "Administratively shut down this neighbor\n"
5402 "Shutdown if round-trip-time is higher than expected\n"
5403 "Round-trip-time in milliseconds\n"
5404 "Specify the number of keepalives before shutdown\n"
5405 "The number of keepalives with higher RTT to shutdown\n")
5406{
5407 int idx_peer = 2;
5408 struct peer *peer;
5409
5410 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5411
5412 if (!peer)
5413 return CMD_WARNING_CONFIG_FAILED;
5414
5415 peer->rtt_expected = 0;
5416 peer->rtt_keepalive_conf = 1;
5417
5418 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5419 PEER_FLAG_RTT_SHUTDOWN);
5420}
5421
718e3744 5422/* neighbor capability dynamic. */
28c6e247
IR
5423DEFUN (neighbor_capability_dynamic,
5424 neighbor_capability_dynamic_cmd,
5425 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5426 NEIGHBOR_STR
5427 NEIGHBOR_ADDR_STR2
5428 "Advertise capability to the peer\n"
5429 "Advertise dynamic capability to this neighbor\n")
718e3744 5430{
d62a17ae 5431 int idx_peer = 1;
28c6e247
IR
5432 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5433 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5434}
5435
28c6e247
IR
5436DEFUN (no_neighbor_capability_dynamic,
5437 no_neighbor_capability_dynamic_cmd,
5438 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5439 NO_STR
5440 NEIGHBOR_STR
5441 NEIGHBOR_ADDR_STR2
5442 "Advertise capability to the peer\n"
5443 "Advertise dynamic capability to this neighbor\n")
718e3744 5444{
d62a17ae 5445 int idx_peer = 2;
28c6e247
IR
5446 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5447 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5448}
6b0655a2 5449
718e3744 5450/* neighbor dont-capability-negotiate */
5451DEFUN (neighbor_dont_capability_negotiate,
5452 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5453 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5454 NEIGHBOR_STR
5455 NEIGHBOR_ADDR_STR2
5456 "Do not perform capability negotiation\n")
5457{
d62a17ae 5458 int idx_peer = 1;
5459 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5460 PEER_FLAG_DONT_CAPABILITY);
718e3744 5461}
5462
5463DEFUN (no_neighbor_dont_capability_negotiate,
5464 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5465 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5466 NO_STR
5467 NEIGHBOR_STR
5468 NEIGHBOR_ADDR_STR2
5469 "Do not perform capability negotiation\n")
5470{
28c6e247
IR
5471 int idx_peer = 2;
5472 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5473 PEER_FLAG_DONT_CAPABILITY);
f4b8ec07
CS
5474}
5475
28c6e247
IR
5476/* neighbor capability extended next hop encoding */
5477DEFUN (neighbor_capability_enhe,
5478 neighbor_capability_enhe_cmd,
5479 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5480 NEIGHBOR_STR
5481 NEIGHBOR_ADDR_STR2
5482 "Advertise capability to the peer\n"
5483 "Advertise extended next-hop capability to the peer\n")
f4b8ec07 5484{
28c6e247 5485 int idx_peer = 1;
c4786405
DS
5486 struct peer *peer;
5487
5488 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5489 if (peer && peer->conf_if)
5490 return CMD_SUCCESS;
5491
28c6e247
IR
5492 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5493 PEER_FLAG_CAPABILITY_ENHE);
5494}
f4b8ec07 5495
28c6e247
IR
5496DEFUN (no_neighbor_capability_enhe,
5497 no_neighbor_capability_enhe_cmd,
5498 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5499 NO_STR
5500 NEIGHBOR_STR
5501 NEIGHBOR_ADDR_STR2
5502 "Advertise capability to the peer\n"
5503 "Advertise extended next-hop capability to the peer\n")
5504{
5505 int idx_peer = 2;
c4786405
DS
5506 struct peer *peer;
5507
5508 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5509 if (peer && peer->conf_if) {
5510 vty_out(vty,
5511 "Peer %s cannot have capability extended-nexthop turned off\n",
5512 argv[idx_peer]->arg);
5513 return CMD_WARNING_CONFIG_FAILED;
5514 }
5515
28c6e247
IR
5516 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5517 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5518}
5519
d62a17ae 5520static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5521 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5522 int set)
718e3744 5523{
d62a17ae 5524 int ret;
5525 struct peer *peer;
718e3744 5526
d62a17ae 5527 peer = peer_and_group_lookup_vty(vty, peer_str);
5528 if (!peer)
5529 return CMD_WARNING_CONFIG_FAILED;
718e3744 5530
d62a17ae 5531 if (set)
5532 ret = peer_af_flag_set(peer, afi, safi, flag);
5533 else
5534 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5535
d62a17ae 5536 return bgp_vty_return(vty, ret);
718e3744 5537}
5538
d62a17ae 5539static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5540 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5541{
d62a17ae 5542 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5543}
5544
d62a17ae 5545static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5546 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5547{
d62a17ae 5548 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5549}
6b0655a2 5550
718e3744 5551/* neighbor capability orf prefix-list. */
5552DEFUN (neighbor_capability_orf_prefix,
5553 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5554 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5555 NEIGHBOR_STR
5556 NEIGHBOR_ADDR_STR2
5557 "Advertise capability to the peer\n"
5558 "Advertise ORF capability to the peer\n"
5559 "Advertise prefixlist ORF capability to this neighbor\n"
5560 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5561 "Capability to RECEIVE the ORF from this neighbor\n"
5562 "Capability to SEND the ORF to this neighbor\n")
5563{
d62a17ae 5564 int idx_send_recv = 5;
db45f64d
DS
5565 char *peer_str = argv[1]->arg;
5566 struct peer *peer;
5567 afi_t afi = bgp_node_afi(vty);
5568 safi_t safi = bgp_node_safi(vty);
d62a17ae 5569
db45f64d
DS
5570 peer = peer_and_group_lookup_vty(vty, peer_str);
5571 if (!peer)
d62a17ae 5572 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5573
db45f64d
DS
5574 if (strmatch(argv[idx_send_recv]->text, "send"))
5575 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5576 PEER_FLAG_ORF_PREFIX_SM);
5577
5578 if (strmatch(argv[idx_send_recv]->text, "receive"))
5579 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5580 PEER_FLAG_ORF_PREFIX_RM);
5581
5582 if (strmatch(argv[idx_send_recv]->text, "both"))
5583 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5584 PEER_FLAG_ORF_PREFIX_SM)
5585 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5586 PEER_FLAG_ORF_PREFIX_RM);
5587
5588 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5589}
5590
5591ALIAS_HIDDEN(
5592 neighbor_capability_orf_prefix,
5593 neighbor_capability_orf_prefix_hidden_cmd,
5594 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5595 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5596 "Advertise capability to the peer\n"
5597 "Advertise ORF capability to the peer\n"
5598 "Advertise prefixlist ORF capability to this neighbor\n"
5599 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5600 "Capability to RECEIVE the ORF from this neighbor\n"
5601 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5602
718e3744 5603DEFUN (no_neighbor_capability_orf_prefix,
5604 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5605 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5606 NO_STR
5607 NEIGHBOR_STR
5608 NEIGHBOR_ADDR_STR2
5609 "Advertise capability to the peer\n"
5610 "Advertise ORF capability to the peer\n"
5611 "Advertise prefixlist ORF capability to this neighbor\n"
5612 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5613 "Capability to RECEIVE the ORF from this neighbor\n"
5614 "Capability to SEND the ORF to this neighbor\n")
5615{
d62a17ae 5616 int idx_send_recv = 6;
db45f64d
DS
5617 char *peer_str = argv[2]->arg;
5618 struct peer *peer;
5619 afi_t afi = bgp_node_afi(vty);
5620 safi_t safi = bgp_node_safi(vty);
d62a17ae 5621
db45f64d
DS
5622 peer = peer_and_group_lookup_vty(vty, peer_str);
5623 if (!peer)
d62a17ae 5624 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5625
db45f64d
DS
5626 if (strmatch(argv[idx_send_recv]->text, "send"))
5627 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5628 PEER_FLAG_ORF_PREFIX_SM);
5629
5630 if (strmatch(argv[idx_send_recv]->text, "receive"))
5631 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5632 PEER_FLAG_ORF_PREFIX_RM);
5633
5634 if (strmatch(argv[idx_send_recv]->text, "both"))
5635 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5636 PEER_FLAG_ORF_PREFIX_SM)
5637 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5638 PEER_FLAG_ORF_PREFIX_RM);
5639
5640 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5641}
5642
5643ALIAS_HIDDEN(
5644 no_neighbor_capability_orf_prefix,
5645 no_neighbor_capability_orf_prefix_hidden_cmd,
5646 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5647 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5648 "Advertise capability to the peer\n"
5649 "Advertise ORF capability to the peer\n"
5650 "Advertise prefixlist ORF capability to this neighbor\n"
5651 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5652 "Capability to RECEIVE the ORF from this neighbor\n"
5653 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5654
718e3744 5655/* neighbor next-hop-self. */
28c6e247
IR
5656DEFUN (neighbor_nexthop_self,
5657 neighbor_nexthop_self_cmd,
5658 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5659 NEIGHBOR_STR
5660 NEIGHBOR_ADDR_STR2
5661 "Disable the next hop calculation for this neighbor\n")
718e3744 5662{
d62a17ae 5663 int idx_peer = 1;
28c6e247
IR
5664 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5665 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 5666}
9e7a53c1 5667
d62a17ae 5668ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5669 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5670 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5671 "Disable the next hop calculation for this neighbor\n")
596c17ba 5672
f4b8ec07 5673/* neighbor next-hop-self. */
28c6e247
IR
5674DEFUN (neighbor_nexthop_self_force,
5675 neighbor_nexthop_self_force_cmd,
5676 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5677 NEIGHBOR_STR
5678 NEIGHBOR_ADDR_STR2
5679 "Disable the next hop calculation for this neighbor\n"
5680 "Set the next hop to self for reflected routes\n")
f4b8ec07
CS
5681{
5682 int idx_peer = 1;
28c6e247
IR
5683 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5684 bgp_node_safi(vty),
5685 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 5686}
5687
d62a17ae 5688ALIAS_HIDDEN(neighbor_nexthop_self_force,
5689 neighbor_nexthop_self_force_hidden_cmd,
5690 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5691 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5692 "Disable the next hop calculation for this neighbor\n"
5693 "Set the next hop to self for reflected routes\n")
596c17ba 5694
1bc4e531
DA
5695ALIAS_HIDDEN(neighbor_nexthop_self_force,
5696 neighbor_nexthop_self_all_hidden_cmd,
5697 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5698 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5699 "Disable the next hop calculation for this neighbor\n"
5700 "Set the next hop to self for reflected routes\n")
5701
28c6e247
IR
5702DEFUN (no_neighbor_nexthop_self,
5703 no_neighbor_nexthop_self_cmd,
5704 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5705 NO_STR
5706 NEIGHBOR_STR
5707 NEIGHBOR_ADDR_STR2
5708 "Disable the next hop calculation for this neighbor\n")
718e3744 5709{
d62a17ae 5710 int idx_peer = 2;
28c6e247
IR
5711 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5712 bgp_node_afi(vty), bgp_node_safi(vty),
5713 PEER_FLAG_NEXTHOP_SELF);
718e3744 5714}
6b0655a2 5715
d62a17ae 5716ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5717 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5718 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5719 "Disable the next hop calculation for this neighbor\n")
596c17ba 5720
28c6e247
IR
5721DEFUN (no_neighbor_nexthop_self_force,
5722 no_neighbor_nexthop_self_force_cmd,
5723 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5724 NO_STR
5725 NEIGHBOR_STR
5726 NEIGHBOR_ADDR_STR2
5727 "Disable the next hop calculation for this neighbor\n"
5728 "Set the next hop to self for reflected routes\n")
88b8ed8d 5729{
d62a17ae 5730 int idx_peer = 2;
28c6e247
IR
5731 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5732 bgp_node_afi(vty), bgp_node_safi(vty),
5733 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5734}
a538debe 5735
d62a17ae 5736ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5737 no_neighbor_nexthop_self_force_hidden_cmd,
5738 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5739 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5740 "Disable the next hop calculation for this neighbor\n"
5741 "Set the next hop to self for reflected routes\n")
596c17ba 5742
1bc4e531
DA
5743ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5744 no_neighbor_nexthop_self_all_hidden_cmd,
5745 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5746 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5747 "Disable the next hop calculation for this neighbor\n"
5748 "Set the next hop to self for reflected routes\n")
5749
c7122e14 5750/* neighbor as-override */
28c6e247
IR
5751DEFUN (neighbor_as_override,
5752 neighbor_as_override_cmd,
5753 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5754 NEIGHBOR_STR
5755 NEIGHBOR_ADDR_STR2
5756 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5757{
d62a17ae 5758 int idx_peer = 1;
28c6e247
IR
5759 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5760 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5761}
5762
d62a17ae 5763ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5764 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5765 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5766 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5767
28c6e247
IR
5768DEFUN (no_neighbor_as_override,
5769 no_neighbor_as_override_cmd,
5770 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5771 NO_STR
5772 NEIGHBOR_STR
5773 NEIGHBOR_ADDR_STR2
5774 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5775{
d62a17ae 5776 int idx_peer = 2;
28c6e247
IR
5777 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5778 bgp_node_afi(vty), bgp_node_safi(vty),
5779 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5780}
5781
d62a17ae 5782ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5783 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5784 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5785 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5786
718e3744 5787/* neighbor remove-private-AS. */
28c6e247
IR
5788DEFUN (neighbor_remove_private_as,
5789 neighbor_remove_private_as_cmd,
5790 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5791 NEIGHBOR_STR
5792 NEIGHBOR_ADDR_STR2
5793 "Remove private ASNs in outbound updates\n")
718e3744 5794{
d62a17ae 5795 int idx_peer = 1;
28c6e247
IR
5796 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5797 bgp_node_safi(vty),
5798 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5799}
5800
d62a17ae 5801ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5802 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5803 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5804 "Remove private ASNs in outbound updates\n")
596c17ba 5805
28c6e247
IR
5806DEFUN (neighbor_remove_private_as_all,
5807 neighbor_remove_private_as_all_cmd,
5808 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5809 NEIGHBOR_STR
5810 NEIGHBOR_ADDR_STR2
5811 "Remove private ASNs in outbound updates\n"
5812 "Apply to all AS numbers\n")
5000f21c 5813{
d62a17ae 5814 int idx_peer = 1;
28c6e247
IR
5815 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5816 bgp_node_safi(vty),
5817 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
5818}
5819
d62a17ae 5820ALIAS_HIDDEN(neighbor_remove_private_as_all,
5821 neighbor_remove_private_as_all_hidden_cmd,
5822 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5823 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5824 "Remove private ASNs in outbound updates\n"
a0dfca37 5825 "Apply to all AS numbers\n")
596c17ba 5826
28c6e247
IR
5827DEFUN (neighbor_remove_private_as_replace_as,
5828 neighbor_remove_private_as_replace_as_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5830 NEIGHBOR_STR
5831 NEIGHBOR_ADDR_STR2
5832 "Remove private ASNs in outbound updates\n"
5833 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5834{
d62a17ae 5835 int idx_peer = 1;
28c6e247
IR
5836 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5837 bgp_node_safi(vty),
5838 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
5839}
5840
d62a17ae 5841ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5842 neighbor_remove_private_as_replace_as_hidden_cmd,
5843 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5844 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5845 "Remove private ASNs in outbound updates\n"
5846 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5847
28c6e247
IR
5848DEFUN (neighbor_remove_private_as_all_replace_as,
5849 neighbor_remove_private_as_all_replace_as_cmd,
5850 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5851 NEIGHBOR_STR
5852 NEIGHBOR_ADDR_STR2
5853 "Remove private ASNs in outbound updates\n"
5854 "Apply to all AS numbers\n"
5855 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5856{
d62a17ae 5857 int idx_peer = 1;
28c6e247
IR
5858 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5859 bgp_node_safi(vty),
5860 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
5861}
5862
d62a17ae 5863ALIAS_HIDDEN(
5864 neighbor_remove_private_as_all_replace_as,
5865 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5866 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5867 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5868 "Remove private ASNs in outbound updates\n"
5869 "Apply to all AS numbers\n"
5870 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5871
28c6e247
IR
5872DEFUN (no_neighbor_remove_private_as,
5873 no_neighbor_remove_private_as_cmd,
5874 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5875 NO_STR
5876 NEIGHBOR_STR
5877 NEIGHBOR_ADDR_STR2
5878 "Remove private ASNs in outbound updates\n")
718e3744 5879{
d62a17ae 5880 int idx_peer = 2;
28c6e247
IR
5881 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5882 bgp_node_afi(vty), bgp_node_safi(vty),
5883 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5884}
6b0655a2 5885
d62a17ae 5886ALIAS_HIDDEN(no_neighbor_remove_private_as,
5887 no_neighbor_remove_private_as_hidden_cmd,
5888 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5889 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5890 "Remove private ASNs in outbound updates\n")
596c17ba 5891
28c6e247
IR
5892DEFUN (no_neighbor_remove_private_as_all,
5893 no_neighbor_remove_private_as_all_cmd,
5894 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5895 NO_STR
5896 NEIGHBOR_STR
5897 NEIGHBOR_ADDR_STR2
5898 "Remove private ASNs in outbound updates\n"
5899 "Apply to all AS numbers\n")
88b8ed8d 5900{
d62a17ae 5901 int idx_peer = 2;
28c6e247
IR
5902 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5903 bgp_node_afi(vty), bgp_node_safi(vty),
5904 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 5905}
5000f21c 5906
d62a17ae 5907ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5908 no_neighbor_remove_private_as_all_hidden_cmd,
5909 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5910 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5911 "Remove private ASNs in outbound updates\n"
5912 "Apply to all AS numbers\n")
596c17ba 5913
28c6e247
IR
5914DEFUN (no_neighbor_remove_private_as_replace_as,
5915 no_neighbor_remove_private_as_replace_as_cmd,
5916 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5917 NO_STR
5918 NEIGHBOR_STR
5919 NEIGHBOR_ADDR_STR2
5920 "Remove private ASNs in outbound updates\n"
5921 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5922{
d62a17ae 5923 int idx_peer = 2;
28c6e247
IR
5924 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5925 bgp_node_afi(vty), bgp_node_safi(vty),
5926 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 5927}
5000f21c 5928
d62a17ae 5929ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5930 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5931 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5932 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5933 "Remove private ASNs in outbound updates\n"
5934 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5935
28c6e247
IR
5936DEFUN (no_neighbor_remove_private_as_all_replace_as,
5937 no_neighbor_remove_private_as_all_replace_as_cmd,
5938 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5939 NO_STR
5940 NEIGHBOR_STR
5941 NEIGHBOR_ADDR_STR2
5942 "Remove private ASNs in outbound updates\n"
5943 "Apply to all AS numbers\n"
5944 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5945{
d62a17ae 5946 int idx_peer = 2;
28c6e247
IR
5947 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5948 bgp_node_afi(vty), bgp_node_safi(vty),
5949 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 5950}
5000f21c 5951
d62a17ae 5952ALIAS_HIDDEN(
5953 no_neighbor_remove_private_as_all_replace_as,
5954 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5955 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5956 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5957 "Remove private ASNs in outbound updates\n"
5958 "Apply to all AS numbers\n"
5959 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5960
5000f21c 5961
718e3744 5962/* neighbor send-community. */
28c6e247
IR
5963DEFUN (neighbor_send_community,
5964 neighbor_send_community_cmd,
5965 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5966 NEIGHBOR_STR
5967 NEIGHBOR_ADDR_STR2
5968 "Send Community attribute to this neighbor\n")
718e3744 5969{
d62a17ae 5970 int idx_peer = 1;
27c05d4d 5971
f63d4054
IR
5972 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5973 bgp_node_safi(vty),
5974 PEER_FLAG_SEND_COMMUNITY);
718e3744 5975}
5976
d62a17ae 5977ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5978 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5979 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5980 "Send Community attribute to this neighbor\n")
596c17ba 5981
28c6e247
IR
5982DEFUN (no_neighbor_send_community,
5983 no_neighbor_send_community_cmd,
5984 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5985 NO_STR
5986 NEIGHBOR_STR
5987 NEIGHBOR_ADDR_STR2
5988 "Send Community attribute to this neighbor\n")
718e3744 5989{
d62a17ae 5990 int idx_peer = 2;
27c05d4d 5991
f63d4054
IR
5992 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5993 bgp_node_afi(vty), bgp_node_safi(vty),
5994 PEER_FLAG_SEND_COMMUNITY);
718e3744 5995}
6b0655a2 5996
d62a17ae 5997ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5998 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5999 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6000 "Send Community attribute to this neighbor\n")
596c17ba 6001
718e3744 6002/* neighbor send-community extended. */
28c6e247
IR
6003DEFUN (neighbor_send_community_type,
6004 neighbor_send_community_type_cmd,
6005 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6006 NEIGHBOR_STR
6007 NEIGHBOR_ADDR_STR2
6008 "Send Community attribute to this neighbor\n"
6009 "Send Standard and Extended Community attributes\n"
6010 "Send Standard, Large and Extended Community attributes\n"
6011 "Send Extended Community attributes\n"
6012 "Send Standard Community attributes\n"
6013 "Send Large Community attributes\n")
718e3744 6014{
27c05d4d 6015 const char *type = argv[argc - 1]->text;
db45f64d 6016 char *peer_str = argv[1]->arg;
28c6e247 6017 struct peer *peer;
db45f64d 6018 afi_t afi = bgp_node_afi(vty);
28c6e247 6019 safi_t safi = bgp_node_safi(vty);
f4b8ec07 6020
28c6e247
IR
6021 peer = peer_and_group_lookup_vty(vty, peer_str);
6022 if (!peer)
6023 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07 6024
28c6e247
IR
6025 if (strmatch(type, "standard"))
6026 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6027 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 6028
28c6e247
IR
6029 if (strmatch(type, "extended"))
6030 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6031 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6032
28c6e247
IR
6033 if (strmatch(type, "large"))
6034 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6035 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07 6036
28c6e247
IR
6037 if (strmatch(type, "both")) {
6038 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6039 PEER_FLAG_SEND_COMMUNITY)
6040 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6041 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6042 }
28c6e247
IR
6043 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6044 PEER_FLAG_SEND_COMMUNITY)
6045 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6046 PEER_FLAG_SEND_EXT_COMMUNITY)
6047 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6048 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 6049}
6050
6051ALIAS_HIDDEN(
6052 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6053 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6054 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6055 "Send Community attribute to this neighbor\n"
6056 "Send Standard and Extended Community attributes\n"
6057 "Send Standard, Large and Extended Community attributes\n"
6058 "Send Extended Community attributes\n"
6059 "Send Standard Community attributes\n"
6060 "Send Large Community attributes\n")
596c17ba 6061
28c6e247
IR
6062DEFUN (no_neighbor_send_community_type,
6063 no_neighbor_send_community_type_cmd,
6064 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6065 NO_STR
6066 NEIGHBOR_STR
6067 NEIGHBOR_ADDR_STR2
6068 "Send Community attribute to this neighbor\n"
6069 "Send Standard and Extended Community attributes\n"
6070 "Send Standard, Large and Extended Community attributes\n"
6071 "Send Extended Community attributes\n"
6072 "Send Standard Community attributes\n"
6073 "Send Large Community attributes\n")
718e3744 6074{
d62a17ae 6075 const char *type = argv[argc - 1]->text;
db45f64d 6076 char *peer_str = argv[2]->arg;
28c6e247 6077 struct peer *peer;
db45f64d
DS
6078 afi_t afi = bgp_node_afi(vty);
6079 safi_t safi = bgp_node_safi(vty);
6080
28c6e247
IR
6081 peer = peer_and_group_lookup_vty(vty, peer_str);
6082 if (!peer)
f4b8ec07
CS
6083 return CMD_WARNING_CONFIG_FAILED;
6084
28c6e247
IR
6085 if (strmatch(type, "standard"))
6086 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6087 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 6088
28c6e247
IR
6089 if (strmatch(type, "extended"))
6090 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6091 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6092
28c6e247
IR
6093 if (strmatch(type, "large"))
6094 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6095 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07
CS
6096
6097 if (strmatch(type, "both")) {
db45f64d 6098
28c6e247
IR
6099 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6100 PEER_FLAG_SEND_COMMUNITY)
6101 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6102 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
6103 }
6104
28c6e247
IR
6105 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6106 PEER_FLAG_SEND_COMMUNITY)
6107 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6108 PEER_FLAG_SEND_EXT_COMMUNITY)
6109 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6110 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 6111}
6112
6113ALIAS_HIDDEN(
6114 no_neighbor_send_community_type,
6115 no_neighbor_send_community_type_hidden_cmd,
6116 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6117 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6118 "Send Community attribute to this neighbor\n"
6119 "Send Standard and Extended Community attributes\n"
6120 "Send Standard, Large and Extended Community attributes\n"
6121 "Send Extended Community attributes\n"
6122 "Send Standard Community attributes\n"
6123 "Send Large Community attributes\n")
596c17ba 6124
718e3744 6125/* neighbor soft-reconfig. */
28c6e247
IR
6126DEFUN (neighbor_soft_reconfiguration,
6127 neighbor_soft_reconfiguration_cmd,
6128 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6129 NEIGHBOR_STR
6130 NEIGHBOR_ADDR_STR2
6131 "Per neighbor soft reconfiguration\n"
6132 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6133{
d62a17ae 6134 int idx_peer = 1;
28c6e247
IR
6135 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6136 bgp_node_safi(vty),
6137 PEER_FLAG_SOFT_RECONFIG);
718e3744 6138}
6139
d62a17ae 6140ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6141 neighbor_soft_reconfiguration_hidden_cmd,
6142 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6143 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6144 "Per neighbor soft reconfiguration\n"
6145 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6146
28c6e247
IR
6147DEFUN (no_neighbor_soft_reconfiguration,
6148 no_neighbor_soft_reconfiguration_cmd,
6149 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6150 NO_STR
6151 NEIGHBOR_STR
6152 NEIGHBOR_ADDR_STR2
6153 "Per neighbor soft reconfiguration\n"
6154 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6155{
d62a17ae 6156 int idx_peer = 2;
28c6e247
IR
6157 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6158 bgp_node_afi(vty), bgp_node_safi(vty),
6159 PEER_FLAG_SOFT_RECONFIG);
718e3744 6160}
6b0655a2 6161
d62a17ae 6162ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6163 no_neighbor_soft_reconfiguration_hidden_cmd,
6164 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6165 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6166 "Per neighbor soft reconfiguration\n"
6167 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6168
28c6e247
IR
6169DEFUN (neighbor_route_reflector_client,
6170 neighbor_route_reflector_client_cmd,
6171 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6172 NEIGHBOR_STR
6173 NEIGHBOR_ADDR_STR2
6174 "Configure a neighbor as Route Reflector client\n")
718e3744 6175{
d62a17ae 6176 int idx_peer = 1;
28c6e247 6177 struct peer *peer;
718e3744 6178
6179
28c6e247
IR
6180 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6181 if (!peer)
d62a17ae 6182 return CMD_WARNING_CONFIG_FAILED;
718e3744 6183
28c6e247
IR
6184 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6185 bgp_node_safi(vty),
6186 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 6187}
6188
d62a17ae 6189ALIAS_HIDDEN(neighbor_route_reflector_client,
6190 neighbor_route_reflector_client_hidden_cmd,
6191 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6192 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6193 "Configure a neighbor as Route Reflector client\n")
596c17ba 6194
28c6e247
IR
6195DEFUN (no_neighbor_route_reflector_client,
6196 no_neighbor_route_reflector_client_cmd,
6197 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6198 NO_STR
6199 NEIGHBOR_STR
6200 NEIGHBOR_ADDR_STR2
6201 "Configure a neighbor as Route Reflector client\n")
718e3744 6202{
d62a17ae 6203 int idx_peer = 2;
28c6e247
IR
6204 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6205 bgp_node_afi(vty), bgp_node_safi(vty),
6206 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 6207}
6b0655a2 6208
d62a17ae 6209ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6210 no_neighbor_route_reflector_client_hidden_cmd,
6211 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6212 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6213 "Configure a neighbor as Route Reflector client\n")
596c17ba 6214
70cd87ca
MK
6215/* optimal-route-reflection Root Routers configuration */
6216DEFPY (optimal_route_reflection,
6217 optimal_route_reflection_cmd,
6218 "[no$no] optimal-route-reflection WORD$orr_group [<A.B.C.D|X:X::X:X>$primary [<A.B.C.D|X:X::X:X>$secondary [<A.B.C.D|X:X::X:X>$tertiary]]]",
6219 NO_STR
6220 "Create ORR group and assign root router(s)\n"
6221 "ORR Group name\n"
6222 "Primary Root address\n"
6223 "Primary Root IPv6 address\n"
6224 "Secondary Root address\n"
6225 "Secondary Root IPv6 address\n"
6226 "Tertiary Root address\n"
6227 "Tertiary Root IPv6 address\n")
6228{
6229 if (!no && !primary) {
6230 vty_out(vty, "%% Specify Primary Root address\n");
6231 return CMD_WARNING_CONFIG_FAILED;
6232 }
6233 return bgp_afi_safi_orr_group_set_vty(
6234 vty, bgp_node_afi(vty), bgp_node_safi(vty), orr_group,
80f6ea8b 6235 primary_str, secondary_str, tertiary_str, !!no);
70cd87ca
MK
6236}
6237
6238/* neighbor optimal-route-reflection group*/
6239DEFPY (neighbor_optimal_route_reflection,
6240 neighbor_optimal_route_reflection_cmd,
6241 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor optimal-route-reflection WORD$orr_group",
6242 NO_STR
6243 NEIGHBOR_STR
6244 NEIGHBOR_ADDR_STR2
6245 "Apply ORR group configuration to the neighbor\n"
6246 "ORR group name\n")
6247{
6248 return peer_orr_group_set_vty(vty, neighbor, bgp_node_afi(vty),
80f6ea8b 6249 bgp_node_safi(vty), orr_group, !!no);
70cd87ca
MK
6250}
6251
718e3744 6252/* neighbor route-server-client. */
28c6e247
IR
6253DEFUN (neighbor_route_server_client,
6254 neighbor_route_server_client_cmd,
6255 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6256 NEIGHBOR_STR
6257 NEIGHBOR_ADDR_STR2
6258 "Configure a neighbor as Route Server client\n")
718e3744 6259{
d62a17ae 6260 int idx_peer = 1;
28c6e247 6261 struct peer *peer;
f4b8ec07 6262
28c6e247
IR
6263 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6264 if (!peer)
d62a17ae 6265 return CMD_WARNING_CONFIG_FAILED;
28c6e247
IR
6266 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6267 bgp_node_safi(vty),
6268 PEER_FLAG_RSERVER_CLIENT);
718e3744 6269}
6270
d62a17ae 6271ALIAS_HIDDEN(neighbor_route_server_client,
6272 neighbor_route_server_client_hidden_cmd,
6273 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6274 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6275 "Configure a neighbor as Route Server client\n")
596c17ba 6276
28c6e247
IR
6277DEFUN (no_neighbor_route_server_client,
6278 no_neighbor_route_server_client_cmd,
6279 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6280 NO_STR
6281 NEIGHBOR_STR
6282 NEIGHBOR_ADDR_STR2
6283 "Configure a neighbor as Route Server client\n")
fee0f4c6 6284{
d62a17ae 6285 int idx_peer = 2;
28c6e247
IR
6286 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6287 bgp_node_afi(vty), bgp_node_safi(vty),
6288 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 6289}
6b0655a2 6290
d62a17ae 6291ALIAS_HIDDEN(no_neighbor_route_server_client,
6292 no_neighbor_route_server_client_hidden_cmd,
6293 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6294 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6295 "Configure a neighbor as Route Server client\n")
596c17ba 6296
fee0f4c6 6297DEFUN (neighbor_nexthop_local_unchanged,
6298 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6299 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6300 NEIGHBOR_STR
6301 NEIGHBOR_ADDR_STR2
6302 "Configure treatment of outgoing link-local nexthop attribute\n"
6303 "Leave link-local nexthop unchanged for this peer\n")
6304{
d62a17ae 6305 int idx_peer = 1;
6306 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6307 bgp_node_safi(vty),
6308 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6309}
6b0655a2 6310
fee0f4c6 6311DEFUN (no_neighbor_nexthop_local_unchanged,
6312 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6313 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6314 NO_STR
6315 NEIGHBOR_STR
6316 NEIGHBOR_ADDR_STR2
6317 "Configure treatment of outgoing link-local-nexthop attribute\n"
6318 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6319{
d62a17ae 6320 int idx_peer = 2;
6321 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6322 bgp_node_afi(vty), bgp_node_safi(vty),
6323 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6324}
6b0655a2 6325
28c6e247
IR
6326DEFUN (neighbor_attr_unchanged,
6327 neighbor_attr_unchanged_cmd,
6328 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6329 NEIGHBOR_STR
6330 NEIGHBOR_ADDR_STR2
6331 "BGP attribute is propagated unchanged to this neighbor\n"
6332 "As-path attribute\n"
6333 "Nexthop attribute\n"
6334 "Med attribute\n")
718e3744 6335{
d62a17ae 6336 int idx = 0;
8eeb0335 6337 char *peer_str = argv[1]->arg;
28c6e247 6338 struct peer *peer;
db45f64d
DS
6339 bool aspath = false;
6340 bool nexthop = false;
6341 bool med = false;
8eeb0335
DW
6342 afi_t afi = bgp_node_afi(vty);
6343 safi_t safi = bgp_node_safi(vty);
28c6e247 6344 int ret = 0;
f4b8ec07 6345
28c6e247
IR
6346 peer = peer_and_group_lookup_vty(vty, peer_str);
6347 if (!peer)
8eeb0335 6348 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6349
6350 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6351 aspath = true;
6352
d62a17ae 6353 idx = 0;
6354 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6355 nexthop = true;
6356
d62a17ae 6357 idx = 0;
6358 if (argv_find(argv, argc, "med", &idx))
db45f64d 6359 med = true;
d62a17ae 6360
8eeb0335 6361 /* no flags means all of them! */
db45f64d 6362 if (!aspath && !nexthop && !med) {
28c6e247
IR
6363 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6364 PEER_FLAG_AS_PATH_UNCHANGED);
6365 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6366 PEER_FLAG_NEXTHOP_UNCHANGED);
6367 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6368 PEER_FLAG_MED_UNCHANGED);
8eeb0335 6369 } else {
28c6e247
IR
6370 if (!aspath) {
6371 if (peer_af_flag_check(peer, afi, safi,
6372 PEER_FLAG_AS_PATH_UNCHANGED)) {
6373 ret |= peer_af_flag_unset_vty(
6374 vty, peer_str, afi, safi,
6375 PEER_FLAG_AS_PATH_UNCHANGED);
6376 }
6377 } else
6378 ret |= peer_af_flag_set_vty(
6379 vty, peer_str, afi, safi,
6380 PEER_FLAG_AS_PATH_UNCHANGED);
6381
6382 if (!nexthop) {
6383 if (peer_af_flag_check(peer, afi, safi,
6384 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6385 ret |= peer_af_flag_unset_vty(
6386 vty, peer_str, afi, safi,
6387 PEER_FLAG_NEXTHOP_UNCHANGED);
6388 }
6389 } else
6390 ret |= peer_af_flag_set_vty(
6391 vty, peer_str, afi, safi,
6392 PEER_FLAG_NEXTHOP_UNCHANGED);
6393
6394 if (!med) {
6395 if (peer_af_flag_check(peer, afi, safi,
6396 PEER_FLAG_MED_UNCHANGED)) {
6397 ret |= peer_af_flag_unset_vty(
6398 vty, peer_str, afi, safi,
6399 PEER_FLAG_MED_UNCHANGED);
6400 }
6401 } else
6402 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6403 PEER_FLAG_MED_UNCHANGED);
d62a17ae 6404 }
6405
28c6e247 6406 return ret;
d62a17ae 6407}
6408
6409ALIAS_HIDDEN(
6410 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6411 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6412 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6413 "BGP attribute is propagated unchanged to this neighbor\n"
6414 "As-path attribute\n"
6415 "Nexthop attribute\n"
6416 "Med attribute\n")
596c17ba 6417
28c6e247
IR
6418DEFUN (no_neighbor_attr_unchanged,
6419 no_neighbor_attr_unchanged_cmd,
6420 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6421 NO_STR
6422 NEIGHBOR_STR
6423 NEIGHBOR_ADDR_STR2
6424 "BGP attribute is propagated unchanged to this neighbor\n"
6425 "As-path attribute\n"
6426 "Nexthop attribute\n"
6427 "Med attribute\n")
718e3744 6428{
d62a17ae 6429 int idx = 0;
db45f64d 6430 char *peer_str = argv[2]->arg;
28c6e247 6431 struct peer *peer;
db45f64d
DS
6432 bool aspath = false;
6433 bool nexthop = false;
6434 bool med = false;
6435 afi_t afi = bgp_node_afi(vty);
6436 safi_t safi = bgp_node_safi(vty);
28c6e247 6437 int ret = 0;
f4b8ec07 6438
28c6e247
IR
6439 peer = peer_and_group_lookup_vty(vty, peer_str);
6440 if (!peer)
db45f64d 6441 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6442
6443 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6444 aspath = true;
6445
d62a17ae 6446 idx = 0;
6447 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6448 nexthop = true;
6449
d62a17ae 6450 idx = 0;
6451 if (argv_find(argv, argc, "med", &idx))
db45f64d 6452 med = true;
d62a17ae 6453
28c6e247
IR
6454 if (!aspath && !nexthop && !med) // no flags means all of them!
6455 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6456 PEER_FLAG_AS_PATH_UNCHANGED)
6457 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6458 PEER_FLAG_NEXTHOP_UNCHANGED)
6459 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6460 PEER_FLAG_MED_UNCHANGED);
db45f64d
DS
6461
6462 if (aspath)
28c6e247
IR
6463 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6464 PEER_FLAG_AS_PATH_UNCHANGED);
db45f64d
DS
6465
6466 if (nexthop)
28c6e247
IR
6467 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6468 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 6469
db45f64d 6470 if (med)
28c6e247
IR
6471 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6472 PEER_FLAG_MED_UNCHANGED);
db45f64d 6473
28c6e247 6474 return ret;
d62a17ae 6475}
6476
6477ALIAS_HIDDEN(
6478 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6479 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6480 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6481 "BGP attribute is propagated unchanged to this neighbor\n"
6482 "As-path attribute\n"
6483 "Nexthop attribute\n"
6484 "Med attribute\n")
718e3744 6485
28c6e247
IR
6486/* EBGP multihop configuration. */
6487static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6488 const char *ttl_str)
718e3744 6489{
28c6e247
IR
6490 struct peer *peer;
6491 unsigned int ttl;
718e3744 6492
28c6e247
IR
6493 peer = peer_and_group_lookup_vty(vty, ip_str);
6494 if (!peer)
d62a17ae 6495 return CMD_WARNING_CONFIG_FAILED;
718e3744 6496
28c6e247
IR
6497 if (peer->conf_if)
6498 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6499
6500 if (!ttl_str)
6501 ttl = MAXTTL;
6502 else
6503 ttl = strtoul(ttl_str, NULL, 10);
718e3744 6504
28c6e247 6505 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 6506}
6507
28c6e247 6508static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6509{
28c6e247 6510 struct peer *peer;
718e3744 6511
28c6e247
IR
6512 peer = peer_and_group_lookup_vty(vty, ip_str);
6513 if (!peer)
d62a17ae 6514 return CMD_WARNING_CONFIG_FAILED;
718e3744 6515
28c6e247 6516 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 6517}
6518
28c6e247
IR
6519/* neighbor ebgp-multihop. */
6520DEFUN (neighbor_ebgp_multihop,
6521 neighbor_ebgp_multihop_cmd,
6522 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6523 NEIGHBOR_STR
6524 NEIGHBOR_ADDR_STR2
6525 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6526{
28c6e247
IR
6527 int idx_peer = 1;
6528 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6529}
f4b8ec07 6530
28c6e247
IR
6531DEFUN (neighbor_ebgp_multihop_ttl,
6532 neighbor_ebgp_multihop_ttl_cmd,
6533 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6534 NEIGHBOR_STR
6535 NEIGHBOR_ADDR_STR2
6536 "Allow EBGP neighbors not on directly connected networks\n"
6537 "maximum hop count\n")
6538{
6539 int idx_peer = 1;
6540 int idx_number = 3;
6541 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6542 argv[idx_number]->arg);
6543}
f4b8ec07 6544
28c6e247
IR
6545DEFUN (no_neighbor_ebgp_multihop,
6546 no_neighbor_ebgp_multihop_cmd,
6547 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6548 NO_STR
6549 NEIGHBOR_STR
6550 NEIGHBOR_ADDR_STR2
6551 "Allow EBGP neighbors not on directly connected networks\n"
6552 "maximum hop count\n")
6553{
6554 int idx_peer = 2;
6555 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6556}
6557
d864dd9e
EB
6558static uint8_t get_role_by_name(const char *role_str)
6559{
6560 if (strncmp(role_str, "peer", 2) == 0)
6561 return ROLE_PEER;
6562 if (strncmp(role_str, "provider", 2) == 0)
6563 return ROLE_PROVIDER;
6564 if (strncmp(role_str, "customer", 2) == 0)
6565 return ROLE_CUSTOMER;
6566 if (strncmp(role_str, "rs-server", 4) == 0)
6567 return ROLE_RS_SERVER;
6568 if (strncmp(role_str, "rs-client", 4) == 0)
6569 return ROLE_RS_CLIENT;
8f2d6021 6570 return ROLE_UNDEFINED;
d864dd9e
EB
6571}
6572
6573static int peer_role_set_vty(struct vty *vty, const char *ip_str,
8f2d6021 6574 const char *role_str, bool strict_mode)
d864dd9e
EB
6575{
6576 struct peer *peer;
6577
7dddd1f7 6578 peer = peer_and_group_lookup_vty(vty, ip_str);
d864dd9e
EB
6579 if (!peer)
6580 return CMD_WARNING_CONFIG_FAILED;
6581 uint8_t role = get_role_by_name(role_str);
6582
8f2d6021 6583 if (role == ROLE_UNDEFINED)
d864dd9e
EB
6584 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6585 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6586}
6587
6588static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6589{
6590 struct peer *peer;
6591
7dddd1f7 6592 peer = peer_and_group_lookup_vty(vty, ip_str);
d864dd9e
EB
6593 if (!peer)
6594 return CMD_WARNING_CONFIG_FAILED;
6595 return bgp_vty_return(vty, peer_role_unset(peer));
6596}
6597
8f2d6021 6598DEFPY(neighbor_role,
d864dd9e
EB
6599 neighbor_role_cmd,
6600 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6601 NEIGHBOR_STR
6602 NEIGHBOR_ADDR_STR2
6603 "Set session role\n"
6604 ROLE_STR)
6605{
6606 int idx_peer = 1;
6607 int idx_role = 3;
6608
6609 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
8f2d6021 6610 false);
d864dd9e
EB
6611}
6612
8f2d6021 6613DEFPY(neighbor_role_strict,
d864dd9e
EB
6614 neighbor_role_strict_cmd,
6615 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6616 NEIGHBOR_STR
6617 NEIGHBOR_ADDR_STR2
6618 "Set session role\n"
6619 ROLE_STR
6620 "Use additional restriction on peer\n")
6621{
6622 int idx_peer = 1;
6623 int idx_role = 3;
6624
6625 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
8f2d6021 6626 true);
d864dd9e
EB
6627}
6628
8f2d6021 6629DEFPY(no_neighbor_role,
d864dd9e
EB
6630 no_neighbor_role_cmd,
6631 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6632 NO_STR
6633 NEIGHBOR_STR
6634 NEIGHBOR_ADDR_STR2
8f2d6021 6635 "Set session role\n"
d864dd9e 6636 ROLE_STR
8f2d6021 6637 "Use additional restriction on peer\n")
d864dd9e
EB
6638{
6639 int idx_peer = 2;
6640
6641 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6642}
6b0655a2 6643
6ffd2079 6644/* disable-connected-check */
28c6e247
IR
6645DEFUN (neighbor_disable_connected_check,
6646 neighbor_disable_connected_check_cmd,
6647 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6648 NEIGHBOR_STR
6649 NEIGHBOR_ADDR_STR2
6650 "one-hop away EBGP peer using loopback address\n"
6651 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6652{
d62a17ae 6653 int idx_peer = 1;
28c6e247
IR
6654 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6655 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6656}
6657
28c6e247
IR
6658DEFUN (no_neighbor_disable_connected_check,
6659 no_neighbor_disable_connected_check_cmd,
6660 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6661 NO_STR
6662 NEIGHBOR_STR
6663 NEIGHBOR_ADDR_STR2
6664 "one-hop away EBGP peer using loopback address\n"
6665 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6666{
d62a17ae 6667 int idx_peer = 2;
28c6e247
IR
6668 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6669 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6670}
6671
7ab294ea
DA
6672/* disable-link-bw-encoding-ieee */
6673DEFUN(neighbor_disable_link_bw_encoding_ieee,
6674 neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6675 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6676 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6677 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6678{
6679 int idx_peer = 1;
6680
6681 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6682 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6683}
6684
7ab294ea
DA
6685DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6686 no_neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6687 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6688 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6689 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6690{
6691 int idx_peer = 2;
6692
6693 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6694 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6695}
6696
d08c0c80
DA
6697/* extended-optional-parameters */
6698DEFUN(neighbor_extended_optional_parameters,
6699 neighbor_extended_optional_parameters_cmd,
6700 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6701 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6702 "Force the extended optional parameters format for OPEN messages\n")
6703{
6704 int idx_peer = 1;
6705
6706 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6707 PEER_FLAG_EXTENDED_OPT_PARAMS);
6708}
6709
6710DEFUN(no_neighbor_extended_optional_parameters,
6711 no_neighbor_extended_optional_parameters_cmd,
6712 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6713 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6714 "Force the extended optional parameters format for OPEN messages\n")
6715{
6716 int idx_peer = 2;
6717
6718 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6719 PEER_FLAG_EXTENDED_OPT_PARAMS);
6720}
47cbc09b
PM
6721
6722/* enforce-first-as */
28c6e247
IR
6723DEFUN (neighbor_enforce_first_as,
6724 neighbor_enforce_first_as_cmd,
6725 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6726 NEIGHBOR_STR
6727 NEIGHBOR_ADDR_STR2
6728 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6729{
6730 int idx_peer = 1;
f4b8ec07 6731
28c6e247
IR
6732 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6733 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6734}
6735
28c6e247
IR
6736DEFUN (no_neighbor_enforce_first_as,
6737 no_neighbor_enforce_first_as_cmd,
6738 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6739 NO_STR
6740 NEIGHBOR_STR
6741 NEIGHBOR_ADDR_STR2
6742 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6743{
6744 int idx_peer = 2;
f4b8ec07 6745
28c6e247
IR
6746 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6747 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6748}
6749
6750
28c6e247
IR
6751DEFUN (neighbor_description,
6752 neighbor_description_cmd,
6753 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6754 NEIGHBOR_STR
6755 NEIGHBOR_ADDR_STR2
6756 "Neighbor specific description\n"
6757 "Up to 80 characters describing this neighbor\n")
718e3744 6758{
d62a17ae 6759 int idx_peer = 1;
6760 int idx_line = 3;
28c6e247 6761 struct peer *peer;
d62a17ae 6762 char *str;
718e3744 6763
28c6e247
IR
6764 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6765 if (!peer)
d62a17ae 6766 return CMD_WARNING_CONFIG_FAILED;
718e3744 6767
d62a17ae 6768 str = argv_concat(argv, argc, idx_line);
718e3744 6769
28c6e247 6770 peer_description_set(peer, str);
718e3744 6771
d62a17ae 6772 XFREE(MTYPE_TMP, str);
718e3744 6773
28c6e247 6774 return CMD_SUCCESS;
718e3744 6775}
6776
28c6e247
IR
6777DEFUN (no_neighbor_description,
6778 no_neighbor_description_cmd,
6779 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6780 NO_STR
6781 NEIGHBOR_STR
6782 NEIGHBOR_ADDR_STR2
6783 "Neighbor specific description\n")
718e3744 6784{
d62a17ae 6785 int idx_peer = 2;
28c6e247 6786 struct peer *peer;
f4b8ec07 6787
28c6e247
IR
6788 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6789 if (!peer)
d62a17ae 6790 return CMD_WARNING_CONFIG_FAILED;
718e3744 6791
28c6e247 6792 peer_description_unset(peer);
718e3744 6793
28c6e247 6794 return CMD_SUCCESS;
718e3744 6795}
6796
1d80f243 6797ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
6798 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6799 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6800 "Neighbor specific description\n"
6801 "Up to 80 characters describing this neighbor\n")
6b0655a2 6802
28c6e247
IR
6803/* Neighbor update-source. */
6804static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6805 const char *source_str)
6806{
6807 struct peer *peer;
6808 struct prefix p;
6809 union sockunion su;
6810
6811 peer = peer_and_group_lookup_vty(vty, peer_str);
6812 if (!peer)
6813 return CMD_WARNING_CONFIG_FAILED;
6814
6815 if (peer->conf_if)
6816 return CMD_WARNING;
6817
6818 if (source_str) {
6819 if (str2sockunion(source_str, &su) == 0)
6820 peer_update_source_addr_set(peer, &su);
6821 else {
6822 if (str2prefix(source_str, &p)) {
6823 vty_out(vty,
6824 "%% Invalid update-source, remove prefix length \n");
6825 return CMD_WARNING_CONFIG_FAILED;
6826 } else
6827 peer_update_source_if_set(peer, source_str);
6828 }
6829 } else
6830 peer_update_source_unset(peer);
6831
6832 return CMD_SUCCESS;
6833}
6834
d62a17ae 6835#define BGP_UPDATE_SOURCE_HELP_STR \
6836 "IPv4 address\n" \
6837 "IPv6 address\n" \
6838 "Interface name (requires zebra to be running)\n"
369688c0 6839
28c6e247
IR
6840DEFUN (neighbor_update_source,
6841 neighbor_update_source_cmd,
6842 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6843 NEIGHBOR_STR
6844 NEIGHBOR_ADDR_STR2
6845 "Source of routing updates\n"
6846 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6847{
d62a17ae 6848 int idx_peer = 1;
6849 int idx_peer_2 = 3;
28c6e247 6850 return peer_update_source_vty(vty, argv[idx_peer]->arg,
d62a17ae 6851 argv[idx_peer_2]->arg);
718e3744 6852}
6853
28c6e247
IR
6854DEFUN (no_neighbor_update_source,
6855 no_neighbor_update_source_cmd,
6856 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6857 NO_STR
6858 NEIGHBOR_STR
6859 NEIGHBOR_ADDR_STR2
6860 "Source of routing updates\n"
6861 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6862{
d62a17ae 6863 int idx_peer = 2;
28c6e247 6864 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6865}
6b0655a2 6866
d62a17ae 6867static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6868 afi_t afi, safi_t safi,
6869 const char *rmap, int set)
718e3744 6870{
d62a17ae 6871 int ret;
6872 struct peer *peer;
80912664 6873 struct route_map *route_map = NULL;
718e3744 6874
d62a17ae 6875 peer = peer_and_group_lookup_vty(vty, peer_str);
6876 if (!peer)
6877 return CMD_WARNING_CONFIG_FAILED;
718e3744 6878
1de27621 6879 if (set) {
80912664
DS
6880 if (rmap)
6881 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
6882 ret = peer_default_originate_set(peer, afi, safi,
6883 rmap, route_map);
6884 } else
d62a17ae 6885 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 6886
d62a17ae 6887 return bgp_vty_return(vty, ret);
718e3744 6888}
6889
6890/* neighbor default-originate. */
6891DEFUN (neighbor_default_originate,
6892 neighbor_default_originate_cmd,
9ccf14f7 6893 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 6894 NEIGHBOR_STR
6895 NEIGHBOR_ADDR_STR2
6896 "Originate default route to this neighbor\n")
6897{
d62a17ae 6898 int idx_peer = 1;
6899 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6900 bgp_node_afi(vty),
6901 bgp_node_safi(vty), NULL, 1);
718e3744 6902}
6903
d62a17ae 6904ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6905 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6906 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6907 "Originate default route to this neighbor\n")
596c17ba 6908
718e3744 6909DEFUN (neighbor_default_originate_rmap,
6910 neighbor_default_originate_rmap_cmd,
70dd370f 6911 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
718e3744 6912 NEIGHBOR_STR
6913 NEIGHBOR_ADDR_STR2
6914 "Originate default route to this neighbor\n"
6915 "Route-map to specify criteria to originate default\n"
6916 "route-map name\n")
6917{
d62a17ae 6918 int idx_peer = 1;
6919 int idx_word = 4;
6920 return peer_default_originate_set_vty(
6921 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6922 argv[idx_word]->arg, 1);
718e3744 6923}
6924
d62a17ae 6925ALIAS_HIDDEN(
6926 neighbor_default_originate_rmap,
6927 neighbor_default_originate_rmap_hidden_cmd,
70dd370f 6928 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
d62a17ae 6929 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6930 "Originate default route to this neighbor\n"
6931 "Route-map to specify criteria to originate default\n"
6932 "route-map name\n")
596c17ba 6933
718e3744 6934DEFUN (no_neighbor_default_originate,
6935 no_neighbor_default_originate_cmd,
70dd370f 6936 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
718e3744 6937 NO_STR
6938 NEIGHBOR_STR
6939 NEIGHBOR_ADDR_STR2
a636c635
DW
6940 "Originate default route to this neighbor\n"
6941 "Route-map to specify criteria to originate default\n"
6942 "route-map name\n")
718e3744 6943{
d62a17ae 6944 int idx_peer = 2;
6945 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6946 bgp_node_afi(vty),
6947 bgp_node_safi(vty), NULL, 0);
718e3744 6948}
6949
d62a17ae 6950ALIAS_HIDDEN(
6951 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
70dd370f 6952 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
d62a17ae 6953 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6954 "Originate default route to this neighbor\n"
6955 "Route-map to specify criteria to originate default\n"
6956 "route-map name\n")
596c17ba 6957
6b0655a2 6958
28c6e247
IR
6959/* Set neighbor's BGP port. */
6960static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6961 const char *port_str)
718e3744 6962{
28c6e247
IR
6963 struct peer *peer;
6964 uint16_t port;
6965 struct servent *sp;
6966
a3aecc99 6967 peer = peer_and_group_lookup_vty(vty, ip_str);
28c6e247
IR
6968 if (!peer)
6969 return CMD_WARNING_CONFIG_FAILED;
6970
6971 if (!port_str) {
6972 sp = getservbyname("bgp", "tcp");
6973 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6974 } else {
6975 port = strtoul(port_str, NULL, 10);
6976 }
718e3744 6977
28c6e247 6978 peer_port_set(peer, port);
718e3744 6979
28c6e247
IR
6980 return CMD_SUCCESS;
6981}
f4b8ec07 6982
28c6e247
IR
6983/* Set specified peer's BGP port. */
6984DEFUN (neighbor_port,
6985 neighbor_port_cmd,
a3aecc99 6986 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
28c6e247 6987 NEIGHBOR_STR
a3aecc99 6988 NEIGHBOR_ADDR_STR2
28c6e247
IR
6989 "Neighbor's BGP port\n"
6990 "TCP port number\n")
6991{
6992 int idx_ip = 1;
6993 int idx_number = 3;
6994 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6995 argv[idx_number]->arg);
f4b8ec07 6996}
6b0655a2 6997
28c6e247
IR
6998DEFUN (no_neighbor_port,
6999 no_neighbor_port_cmd,
a3aecc99 7000 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
28c6e247
IR
7001 NO_STR
7002 NEIGHBOR_STR
a3aecc99 7003 NEIGHBOR_ADDR_STR2
28c6e247
IR
7004 "Neighbor's BGP port\n"
7005 "TCP port number\n")
718e3744 7006{
f4b8ec07 7007 int idx_ip = 2;
28c6e247
IR
7008 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
7009}
7010
7011
7012/* neighbor weight. */
7013static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7014 safi_t safi, const char *weight_str)
7015{
7016 int ret;
7017 struct peer *peer;
7018 unsigned long weight;
718e3744 7019
28c6e247
IR
7020 peer = peer_and_group_lookup_vty(vty, ip_str);
7021 if (!peer)
7022 return CMD_WARNING_CONFIG_FAILED;
718e3744 7023
28c6e247 7024 weight = strtoul(weight_str, NULL, 10);
718e3744 7025
28c6e247
IR
7026 ret = peer_weight_set(peer, afi, safi, weight);
7027 return bgp_vty_return(vty, ret);
718e3744 7028}
7029
28c6e247
IR
7030static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7031 safi_t safi)
718e3744 7032{
28c6e247
IR
7033 int ret;
7034 struct peer *peer;
f4b8ec07 7035
28c6e247
IR
7036 peer = peer_and_group_lookup_vty(vty, ip_str);
7037 if (!peer)
d62a17ae 7038 return CMD_WARNING_CONFIG_FAILED;
718e3744 7039
28c6e247
IR
7040 ret = peer_weight_unset(peer, afi, safi);
7041 return bgp_vty_return(vty, ret);
7042}
f4b8ec07 7043
28c6e247
IR
7044DEFUN (neighbor_weight,
7045 neighbor_weight_cmd,
7046 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7047 NEIGHBOR_STR
7048 NEIGHBOR_ADDR_STR2
7049 "Set default weight for routes from this neighbor\n"
7050 "default weight\n")
7051{
7052 int idx_peer = 1;
7053 int idx_number = 3;
7054 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7055 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 7056}
7057
d62a17ae 7058ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7059 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7060 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7061 "Set default weight for routes from this neighbor\n"
7062 "default weight\n")
596c17ba 7063
28c6e247
IR
7064DEFUN (no_neighbor_weight,
7065 no_neighbor_weight_cmd,
7066 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7067 NO_STR
7068 NEIGHBOR_STR
7069 NEIGHBOR_ADDR_STR2
7070 "Set default weight for routes from this neighbor\n"
7071 "default weight\n")
718e3744 7072{
d62a17ae 7073 int idx_peer = 2;
28c6e247
IR
7074 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7075 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 7076}
7077
d62a17ae 7078ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7079 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7080 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7081 "Set default weight for routes from this neighbor\n"
7082 "default weight\n")
596c17ba 7083
6b0655a2 7084
718e3744 7085/* Override capability negotiation. */
c36bc05f
IR
7086DEFUN (neighbor_override_capability,
7087 neighbor_override_capability_cmd,
7088 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7089 NEIGHBOR_STR
7090 NEIGHBOR_ADDR_STR2
7091 "Override capability negotiation result\n")
718e3744 7092{
d62a17ae 7093 int idx_peer = 1;
c36bc05f
IR
7094 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7095 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 7096}
7097
c36bc05f
IR
7098DEFUN (no_neighbor_override_capability,
7099 no_neighbor_override_capability_cmd,
7100 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7101 NO_STR
7102 NEIGHBOR_STR
7103 NEIGHBOR_ADDR_STR2
7104 "Override capability negotiation result\n")
718e3744 7105{
d62a17ae 7106 int idx_peer = 2;
c36bc05f
IR
7107 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7108 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 7109}
6b0655a2 7110
c36bc05f
IR
7111DEFUN (neighbor_strict_capability,
7112 neighbor_strict_capability_cmd,
7113 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7114 NEIGHBOR_STR
7115 NEIGHBOR_ADDR_STR2
7116 "Strict capability negotiation match\n")
718e3744 7117{
9fb964de
PM
7118 int idx_peer = 1;
7119
c36bc05f
IR
7120 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7121 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 7122}
7123
c36bc05f
IR
7124DEFUN (no_neighbor_strict_capability,
7125 no_neighbor_strict_capability_cmd,
7126 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7127 NO_STR
7128 NEIGHBOR_STR
7129 NEIGHBOR_ADDR_STR2
7130 "Strict capability negotiation match\n")
718e3744 7131{
9fb964de 7132 int idx_peer = 2;
8611c7f3 7133
c36bc05f
IR
7134 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7135 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 7136}
6b0655a2 7137
28c6e247
IR
7138static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7139 const char *keep_str, const char *hold_str)
718e3744 7140{
28c6e247
IR
7141 int ret;
7142 struct peer *peer;
7143 uint32_t keepalive;
7144 uint32_t holdtime;
718e3744 7145
28c6e247
IR
7146 peer = peer_and_group_lookup_vty(vty, ip_str);
7147 if (!peer)
d62a17ae 7148 return CMD_WARNING_CONFIG_FAILED;
718e3744 7149
28c6e247
IR
7150 keepalive = strtoul(keep_str, NULL, 10);
7151 holdtime = strtoul(hold_str, NULL, 10);
718e3744 7152
28c6e247 7153 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 7154
28c6e247 7155 return bgp_vty_return(vty, ret);
718e3744 7156}
6b0655a2 7157
28c6e247 7158static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 7159{
28c6e247
IR
7160 int ret;
7161 struct peer *peer;
718e3744 7162
28c6e247
IR
7163 peer = peer_and_group_lookup_vty(vty, ip_str);
7164 if (!peer)
d62a17ae 7165 return CMD_WARNING_CONFIG_FAILED;
718e3744 7166
28c6e247 7167 ret = peer_timers_unset(peer);
718e3744 7168
28c6e247 7169 return bgp_vty_return(vty, ret);
718e3744 7170}
6b0655a2 7171
28c6e247
IR
7172DEFUN (neighbor_timers,
7173 neighbor_timers_cmd,
7174 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7175 NEIGHBOR_STR
7176 NEIGHBOR_ADDR_STR2
7177 "BGP per neighbor timers\n"
7178 "Keepalive interval\n"
7179 "Holdtime\n")
718e3744 7180{
f4b8ec07 7181 int idx_peer = 1;
28c6e247
IR
7182 int idx_number = 3;
7183 int idx_number_2 = 4;
7184 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7185 argv[idx_number]->arg,
7186 argv[idx_number_2]->arg);
7187}
7188
7189DEFUN (no_neighbor_timers,
7190 no_neighbor_timers_cmd,
7191 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7192 NO_STR
7193 NEIGHBOR_STR
7194 NEIGHBOR_ADDR_STR2
7195 "BGP per neighbor timers\n"
7196 "Keepalive interval\n"
7197 "Holdtime\n")
7198{
7199 int idx_peer = 2;
7200 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7201}
7202
7203
7204static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7205 const char *time_str)
7206{
7207 int ret;
7208 struct peer *peer;
7209 uint32_t connect;
718e3744 7210
28c6e247
IR
7211 peer = peer_and_group_lookup_vty(vty, ip_str);
7212 if (!peer)
d62a17ae 7213 return CMD_WARNING_CONFIG_FAILED;
718e3744 7214
28c6e247
IR
7215 connect = strtoul(time_str, NULL, 10);
7216
7217 ret = peer_timers_connect_set(peer, connect);
718e3744 7218
28c6e247 7219 return bgp_vty_return(vty, ret);
718e3744 7220}
7221
28c6e247 7222static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 7223{
28c6e247
IR
7224 int ret;
7225 struct peer *peer;
718e3744 7226
28c6e247
IR
7227 peer = peer_and_group_lookup_vty(vty, ip_str);
7228 if (!peer)
d62a17ae 7229 return CMD_WARNING_CONFIG_FAILED;
718e3744 7230
28c6e247
IR
7231 ret = peer_timers_connect_unset(peer);
7232
7233 return bgp_vty_return(vty, ret);
7234}
7235
7236DEFUN (neighbor_timers_connect,
7237 neighbor_timers_connect_cmd,
7238 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7239 NEIGHBOR_STR
7240 NEIGHBOR_ADDR_STR2
7241 "BGP per neighbor timers\n"
7242 "BGP connect timer\n"
7243 "Connect timer\n")
7244{
7245 int idx_peer = 1;
7246 int idx_number = 4;
7247 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7248 argv[idx_number]->arg);
7249}
718e3744 7250
28c6e247
IR
7251DEFUN (no_neighbor_timers_connect,
7252 no_neighbor_timers_connect_cmd,
7253 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7254 NO_STR
7255 NEIGHBOR_STR
7256 NEIGHBOR_ADDR_STR2
7257 "BGP per neighbor timers\n"
7258 "BGP connect timer\n"
7259 "Connect timer\n")
7260{
7261 int idx_peer = 2;
7262 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 7263}
7264
d43114f3
DS
7265DEFPY (neighbor_timers_delayopen,
7266 neighbor_timers_delayopen_cmd,
7267 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7268 NEIGHBOR_STR
7269 NEIGHBOR_ADDR_STR2
7270 "BGP per neighbor timers\n"
7271 "RFC 4271 DelayOpenTimer\n"
7272 "DelayOpenTime timer interval\n")
7273{
7274 struct peer *peer;
7275
7276 peer = peer_and_group_lookup_vty(vty, neighbor);
7277 if (!peer)
7278 return CMD_WARNING_CONFIG_FAILED;
7279
7280 if (!interval) {
7281 if (peer_timers_delayopen_unset(peer))
7282 return CMD_WARNING_CONFIG_FAILED;
7283 } else {
7284 if (peer_timers_delayopen_set(peer, interval))
7285 return CMD_WARNING_CONFIG_FAILED;
7286 }
7287
7288 return CMD_SUCCESS;
7289}
7290
7291DEFPY (no_neighbor_timers_delayopen,
7292 no_neighbor_timers_delayopen_cmd,
7293 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7294 NO_STR
7295 NEIGHBOR_STR
7296 NEIGHBOR_ADDR_STR2
7297 "BGP per neighbor timers\n"
7298 "RFC 4271 DelayOpenTimer\n"
7299 "DelayOpenTime timer interval\n")
7300{
7301 struct peer *peer;
7302
7303 peer = peer_and_group_lookup_vty(vty, neighbor);
7304 if (!peer)
7305 return CMD_WARNING_CONFIG_FAILED;
7306
7307 if (peer_timers_delayopen_unset(peer))
7308 return CMD_WARNING_CONFIG_FAILED;
7309
7310 return CMD_SUCCESS;
7311}
7312
28c6e247
IR
7313static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7314 const char *time_str, int set)
718e3744 7315{
28c6e247
IR
7316 int ret;
7317 struct peer *peer;
7318 uint32_t routeadv = 0;
718e3744 7319
28c6e247
IR
7320 peer = peer_and_group_lookup_vty(vty, ip_str);
7321 if (!peer)
d62a17ae 7322 return CMD_WARNING_CONFIG_FAILED;
718e3744 7323
28c6e247
IR
7324 if (time_str)
7325 routeadv = strtoul(time_str, NULL, 10);
7326
7327 if (set)
7328 ret = peer_advertise_interval_set(peer, routeadv);
7329 else
7330 ret = peer_advertise_interval_unset(peer);
718e3744 7331
28c6e247 7332 return bgp_vty_return(vty, ret);
718e3744 7333}
7334
28c6e247
IR
7335DEFUN (neighbor_advertise_interval,
7336 neighbor_advertise_interval_cmd,
7337 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7338 NEIGHBOR_STR
7339 NEIGHBOR_ADDR_STR2
7340 "Minimum interval between sending BGP routing updates\n"
7341 "time in seconds\n")
718e3744 7342{
28c6e247
IR
7343 int idx_peer = 1;
7344 int idx_number = 3;
7345 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7346 argv[idx_number]->arg, 1);
7347}
f4b8ec07 7348
28c6e247
IR
7349DEFUN (no_neighbor_advertise_interval,
7350 no_neighbor_advertise_interval_cmd,
7351 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7352 NO_STR
7353 NEIGHBOR_STR
7354 NEIGHBOR_ADDR_STR2
7355 "Minimum interval between sending BGP routing updates\n"
7356 "time in seconds\n")
7357{
7358 int idx_peer = 2;
7359 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 7360}
7361
6b0655a2 7362
518f0eb1
DS
7363/* Time to wait before processing route-map updates */
7364DEFUN (bgp_set_route_map_delay_timer,
7365 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7366 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7367 SET_STR
7368 "BGP route-map delay timer\n"
7369 "Time in secs to wait before processing route-map changes\n"
f414725f 7370 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7371{
d62a17ae 7372 int idx_number = 3;
d7c0a89a 7373 uint32_t rmap_delay_timer;
d62a17ae 7374
7375 if (argv[idx_number]->arg) {
7376 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7377 bm->rmap_update_timer = rmap_delay_timer;
7378
7379 /* if the dynamic update handling is being disabled, and a timer
7380 * is
7381 * running, stop the timer and act as if the timer has already
7382 * fired.
7383 */
7384 if (!rmap_delay_timer && bm->t_rmap_update) {
fa5806c3 7385 THREAD_OFF(bm->t_rmap_update);
d62a17ae 7386 thread_execute(bm->master, bgp_route_map_update_timer,
7387 NULL, 0);
7388 }
7389 return CMD_SUCCESS;
7390 } else {
7391 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7392 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7393 }
518f0eb1
DS
7394}
7395
7396DEFUN (no_bgp_set_route_map_delay_timer,
7397 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7398 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7399 NO_STR
3a2d747c 7400 BGP_STR
518f0eb1 7401 "Default BGP route-map delay timer\n"
8334fd5a
DW
7402 "Reset to default time to wait for processing route-map changes\n"
7403 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7404{
518f0eb1 7405
d62a17ae 7406 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7407
d62a17ae 7408 return CMD_SUCCESS;
518f0eb1
DS
7409}
7410
28c6e247
IR
7411/* neighbor interface */
7412static int peer_interface_vty(struct vty *vty, const char *ip_str,
7413 const char *str)
718e3744 7414{
28c6e247 7415 struct peer *peer;
718e3744 7416
28c6e247
IR
7417 peer = peer_lookup_vty(vty, ip_str);
7418 if (!peer || peer->conf_if) {
7419 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7420 return CMD_WARNING_CONFIG_FAILED;
7421 }
718e3744 7422
28c6e247
IR
7423 if (str)
7424 peer_interface_set(peer, str);
7425 else
7426 peer_interface_unset(peer);
718e3744 7427
28c6e247 7428 return CMD_SUCCESS;
718e3744 7429}
7430
28c6e247
IR
7431DEFUN (neighbor_interface,
7432 neighbor_interface_cmd,
7433 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7434 NEIGHBOR_STR
7435 NEIGHBOR_ADDR_STR
7436 "Interface\n"
7437 "Interface name\n")
718e3744 7438{
28c6e247
IR
7439 int idx_ip = 1;
7440 int idx_word = 3;
294d8425 7441
28c6e247
IR
7442 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7443}
f4b8ec07 7444
28c6e247
IR
7445DEFUN (no_neighbor_interface,
7446 no_neighbor_interface_cmd,
294d8425 7447 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
28c6e247
IR
7448 NO_STR
7449 NEIGHBOR_STR
294d8425 7450 NEIGHBOR_ADDR_STR
28c6e247
IR
7451 "Interface\n"
7452 "Interface name\n")
7453{
7454 int idx_peer = 2;
294d8425 7455
28c6e247 7456 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 7457}
6b0655a2 7458
718e3744 7459DEFUN (neighbor_distribute_list,
7460 neighbor_distribute_list_cmd,
c60dec36 7461 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7462 NEIGHBOR_STR
7463 NEIGHBOR_ADDR_STR2
7464 "Filter updates to/from this neighbor\n"
718e3744 7465 "IP Access-list name\n"
7466 "Filter incoming updates\n"
7467 "Filter outgoing updates\n")
7468{
d62a17ae 7469 int idx_peer = 1;
7470 int idx_acl = 3;
7471 int direct, ret;
7472 struct peer *peer;
a8206004 7473
d62a17ae 7474 const char *pstr = argv[idx_peer]->arg;
7475 const char *acl = argv[idx_acl]->arg;
7476 const char *inout = argv[argc - 1]->text;
a8206004 7477
d62a17ae 7478 peer = peer_and_group_lookup_vty(vty, pstr);
7479 if (!peer)
7480 return CMD_WARNING_CONFIG_FAILED;
a8206004 7481
d62a17ae 7482 /* Check filter direction. */
7483 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7484 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7485 direct, acl);
a8206004 7486
d62a17ae 7487 return bgp_vty_return(vty, ret);
718e3744 7488}
7489
d62a17ae 7490ALIAS_HIDDEN(
7491 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
c60dec36 7492 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7493 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7494 "Filter updates to/from this neighbor\n"
d62a17ae 7495 "IP Access-list name\n"
7496 "Filter incoming updates\n"
7497 "Filter outgoing updates\n")
596c17ba 7498
718e3744 7499DEFUN (no_neighbor_distribute_list,
7500 no_neighbor_distribute_list_cmd,
c60dec36 7501 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7502 NO_STR
7503 NEIGHBOR_STR
7504 NEIGHBOR_ADDR_STR2
7505 "Filter updates to/from this neighbor\n"
718e3744 7506 "IP Access-list name\n"
7507 "Filter incoming updates\n"
7508 "Filter outgoing updates\n")
7509{
d62a17ae 7510 int idx_peer = 2;
7511 int direct, ret;
7512 struct peer *peer;
a8206004 7513
d62a17ae 7514 const char *pstr = argv[idx_peer]->arg;
7515 const char *inout = argv[argc - 1]->text;
a8206004 7516
d62a17ae 7517 peer = peer_and_group_lookup_vty(vty, pstr);
7518 if (!peer)
7519 return CMD_WARNING_CONFIG_FAILED;
a8206004 7520
d62a17ae 7521 /* Check filter direction. */
7522 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7523 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7524 direct);
a8206004 7525
d62a17ae 7526 return bgp_vty_return(vty, ret);
718e3744 7527}
6b0655a2 7528
d62a17ae 7529ALIAS_HIDDEN(
7530 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
c60dec36 7531 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7532 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7533 "Filter updates to/from this neighbor\n"
d62a17ae 7534 "IP Access-list name\n"
7535 "Filter incoming updates\n"
7536 "Filter outgoing updates\n")
596c17ba 7537
718e3744 7538/* Set prefix list to the peer. */
642ef664
IR
7539static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7540 afi_t afi, safi_t safi,
7541 const char *name_str,
7542 const char *direct_str)
718e3744 7543{
642ef664
IR
7544 int ret;
7545 int direct = FILTER_IN;
7546 struct peer *peer;
718e3744 7547
642ef664
IR
7548 peer = peer_and_group_lookup_vty(vty, ip_str);
7549 if (!peer)
d62a17ae 7550 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7551
642ef664
IR
7552 /* Check filter direction. */
7553 if (strncmp(direct_str, "i", 1) == 0)
7554 direct = FILTER_IN;
7555 else if (strncmp(direct_str, "o", 1) == 0)
7556 direct = FILTER_OUT;
718e3744 7557
642ef664 7558 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 7559
642ef664
IR
7560 return bgp_vty_return(vty, ret);
7561}
7562
7563static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7564 afi_t afi, safi_t safi,
7565 const char *direct_str)
7566{
7567 int ret;
7568 struct peer *peer;
7569 int direct = FILTER_IN;
7570
7571 peer = peer_and_group_lookup_vty(vty, ip_str);
7572 if (!peer)
7573 return CMD_WARNING_CONFIG_FAILED;
7574
7575 /* Check filter direction. */
7576 if (strncmp(direct_str, "i", 1) == 0)
7577 direct = FILTER_IN;
7578 else if (strncmp(direct_str, "o", 1) == 0)
7579 direct = FILTER_OUT;
7580
7581 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7582
7583 return bgp_vty_return(vty, ret);
7584}
7585
7586DEFUN (neighbor_prefix_list,
7587 neighbor_prefix_list_cmd,
7588 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7589 NEIGHBOR_STR
7590 NEIGHBOR_ADDR_STR2
7591 "Filter updates to/from this neighbor\n"
7592 "Name of a prefix list\n"
7593 "Filter incoming updates\n"
7594 "Filter outgoing updates\n")
7595{
7596 int idx_peer = 1;
7597 int idx_word = 3;
7598 int idx_in_out = 4;
7599 return peer_prefix_list_set_vty(
7600 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7601 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7602}
7603
d62a17ae 7604ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7605 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7606 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7607 "Filter updates to/from this neighbor\n"
7608 "Name of a prefix list\n"
7609 "Filter incoming updates\n"
7610 "Filter outgoing updates\n")
596c17ba 7611
642ef664
IR
7612DEFUN (no_neighbor_prefix_list,
7613 no_neighbor_prefix_list_cmd,
7614 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7615 NO_STR
7616 NEIGHBOR_STR
7617 NEIGHBOR_ADDR_STR2
7618 "Filter updates to/from this neighbor\n"
7619 "Name of a prefix list\n"
7620 "Filter incoming updates\n"
7621 "Filter outgoing updates\n")
7622{
7623 int idx_peer = 2;
7624 int idx_in_out = 5;
7625 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7626 bgp_node_afi(vty), bgp_node_safi(vty),
7627 argv[idx_in_out]->arg);
7628}
7629
7630ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7631 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7632 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7633 "Filter updates to/from this neighbor\n"
7634 "Name of a prefix list\n"
7635 "Filter incoming updates\n"
7636 "Filter outgoing updates\n")
7637
d62a17ae 7638static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7639 safi_t safi, const char *name_str,
7640 const char *direct_str)
718e3744 7641{
d62a17ae 7642 int ret;
7643 struct peer *peer;
7644 int direct = FILTER_IN;
718e3744 7645
d62a17ae 7646 peer = peer_and_group_lookup_vty(vty, ip_str);
7647 if (!peer)
7648 return CMD_WARNING_CONFIG_FAILED;
718e3744 7649
d62a17ae 7650 /* Check filter direction. */
7651 if (strncmp(direct_str, "i", 1) == 0)
7652 direct = FILTER_IN;
7653 else if (strncmp(direct_str, "o", 1) == 0)
7654 direct = FILTER_OUT;
718e3744 7655
d62a17ae 7656 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7657
d62a17ae 7658 return bgp_vty_return(vty, ret);
718e3744 7659}
7660
d62a17ae 7661static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7662 safi_t safi, const char *direct_str)
718e3744 7663{
d62a17ae 7664 int ret;
7665 struct peer *peer;
7666 int direct = FILTER_IN;
718e3744 7667
d62a17ae 7668 peer = peer_and_group_lookup_vty(vty, ip_str);
7669 if (!peer)
7670 return CMD_WARNING_CONFIG_FAILED;
718e3744 7671
d62a17ae 7672 /* Check filter direction. */
7673 if (strncmp(direct_str, "i", 1) == 0)
7674 direct = FILTER_IN;
7675 else if (strncmp(direct_str, "o", 1) == 0)
7676 direct = FILTER_OUT;
718e3744 7677
d62a17ae 7678 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7679
d62a17ae 7680 return bgp_vty_return(vty, ret);
718e3744 7681}
7682
7683DEFUN (neighbor_filter_list,
7684 neighbor_filter_list_cmd,
de71d43e 7685 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7686 NEIGHBOR_STR
7687 NEIGHBOR_ADDR_STR2
7688 "Establish BGP filters\n"
7689 "AS path access-list name\n"
7690 "Filter incoming routes\n"
7691 "Filter outgoing routes\n")
7692{
d62a17ae 7693 int idx_peer = 1;
7694 int idx_word = 3;
7695 int idx_in_out = 4;
7696 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7697 bgp_node_safi(vty), argv[idx_word]->arg,
7698 argv[idx_in_out]->arg);
718e3744 7699}
7700
d62a17ae 7701ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
de71d43e 7702 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7703 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7704 "Establish BGP filters\n"
7705 "AS path access-list name\n"
7706 "Filter incoming routes\n"
7707 "Filter outgoing routes\n")
596c17ba 7708
718e3744 7709DEFUN (no_neighbor_filter_list,
7710 no_neighbor_filter_list_cmd,
de71d43e 7711 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7712 NO_STR
7713 NEIGHBOR_STR
7714 NEIGHBOR_ADDR_STR2
7715 "Establish BGP filters\n"
7716 "AS path access-list name\n"
7717 "Filter incoming routes\n"
7718 "Filter outgoing routes\n")
7719{
d62a17ae 7720 int idx_peer = 2;
7721 int idx_in_out = 5;
7722 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7723 bgp_node_afi(vty), bgp_node_safi(vty),
7724 argv[idx_in_out]->arg);
718e3744 7725}
6b0655a2 7726
d62a17ae 7727ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
de71d43e 7728 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7729 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7730 "Establish BGP filters\n"
7731 "AS path access-list name\n"
7732 "Filter incoming routes\n"
7733 "Filter outgoing routes\n")
596c17ba 7734
7f7940e6
MK
7735/* Set advertise-map to the peer. */
7736static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7737 afi_t afi, safi_t safi,
cf2ad4d8
MK
7738 const char *advertise_str,
7739 const char *condition_str, bool condition,
7740 bool set)
7f7940e6
MK
7741{
7742 int ret = CMD_WARNING_CONFIG_FAILED;
7743 struct peer *peer;
7744 struct route_map *advertise_map;
7745 struct route_map *condition_map;
7746
7747 peer = peer_and_group_lookup_vty(vty, ip_str);
7748 if (!peer)
7749 return ret;
7750
7751 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7752 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7753
cf2ad4d8
MK
7754 if (set)
7755 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7756 advertise_map, condition_str,
7757 condition_map, condition);
7758 else
7759 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7760 advertise_map, condition_str,
7761 condition_map, condition);
7f7940e6
MK
7762
7763 return bgp_vty_return(vty, ret);
7764}
7765
389e4f92
QY
7766DEFPY (bgp_condadv_period,
7767 bgp_condadv_period_cmd,
7768 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7769 NO_STR
7770 BGP_STR
7771 "Conditional advertisement settings\n"
7772 "Set period to rescan BGP table to check if condition is met\n"
7773 "Period between BGP table scans, in seconds; default 60\n")
7774{
7775 VTY_DECLVAR_CONTEXT(bgp, bgp);
7776
7777 bgp->condition_check_period =
7778 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7779
7780 return CMD_SUCCESS;
7781}
7782
cf2ad4d8 7783DEFPY (neighbor_advertise_map,
7f7940e6 7784 neighbor_advertise_map_cmd,
3ccddc25 7785 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map RMAP_NAME$advertise_str <exist-map|non-exist-map>$exist RMAP_NAME$condition_str",
cf2ad4d8 7786 NO_STR
7f7940e6
MK
7787 NEIGHBOR_STR
7788 NEIGHBOR_ADDR_STR2
7789 "Route-map to conditionally advertise routes\n"
7790 "Name of advertise map\n"
7791 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7792 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7793 "Name of the exist or non exist map\n")
7f7940e6 7794{
7f7940e6
MK
7795 bool condition = CONDITION_EXIST;
7796
52b84062 7797 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7798 condition = CONDITION_NON_EXIST;
7799
52b84062
MK
7800 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7801 bgp_node_safi(vty), advertise_str,
7802 condition_str, condition, !no);
7f7940e6
MK
7803}
7804
7805ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
3ccddc25 7806 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map RMAP_NAME$advertise_str <exist-map|non-exist-map>$exist RMAP_NAME$condition_str",
7f7940e6
MK
7807 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7808 "Route-map to conditionally advertise routes\n"
7809 "Name of advertise map\n"
7810 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7811 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7812 "Name of the exist or non exist map\n")
7f7940e6 7813
718e3744 7814/* Set route-map to the peer. */
0ea8d871
IR
7815static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7816 afi_t afi, safi_t safi, const char *name_str,
7817 const char *direct_str)
718e3744 7818{
0ea8d871
IR
7819 int ret;
7820 struct peer *peer;
7821 int direct = RMAP_IN;
7822 struct route_map *route_map;
718e3744 7823
0ea8d871
IR
7824 peer = peer_and_group_lookup_vty(vty, ip_str);
7825 if (!peer)
d62a17ae 7826 return CMD_WARNING_CONFIG_FAILED;
718e3744 7827
0ea8d871
IR
7828 /* Check filter direction. */
7829 if (strncmp(direct_str, "in", 2) == 0)
7830 direct = RMAP_IN;
7831 else if (strncmp(direct_str, "o", 1) == 0)
7832 direct = RMAP_OUT;
718e3744 7833
0ea8d871
IR
7834 route_map = route_map_lookup_warn_noexist(vty, name_str);
7835 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7836
0ea8d871
IR
7837 return bgp_vty_return(vty, ret);
7838}
7839
7840static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7841 afi_t afi, safi_t safi,
7842 const char *direct_str)
7843{
7844 int ret;
7845 struct peer *peer;
7846 int direct = RMAP_IN;
7847
7848 peer = peer_and_group_lookup_vty(vty, ip_str);
7849 if (!peer)
7850 return CMD_WARNING_CONFIG_FAILED;
7851
7852 /* Check filter direction. */
7853 if (strncmp(direct_str, "in", 2) == 0)
7854 direct = RMAP_IN;
7855 else if (strncmp(direct_str, "o", 1) == 0)
7856 direct = RMAP_OUT;
7857
7858 ret = peer_route_map_unset(peer, afi, safi, direct);
7859
7860 return bgp_vty_return(vty, ret);
7861}
7862
7863DEFUN (neighbor_route_map,
7864 neighbor_route_map_cmd,
70dd370f 7865 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
0ea8d871
IR
7866 NEIGHBOR_STR
7867 NEIGHBOR_ADDR_STR2
7868 "Apply route map to neighbor\n"
7869 "Name of route map\n"
7870 "Apply map to incoming routes\n"
7871 "Apply map to outbound routes\n")
7872{
7873 int idx_peer = 1;
7874 int idx_word = 3;
7875 int idx_in_out = 4;
7876 return peer_route_map_set_vty(
7877 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7878 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7879}
7880
d6d7ed37 7881ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
70dd370f 7882 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
d6d7ed37
IR
7883 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7884 "Apply route map to neighbor\n"
7885 "Name of route map\n"
7886 "Apply map to incoming routes\n"
7887 "Apply map to outbound routes\n")
7888
0ea8d871
IR
7889DEFUN (no_neighbor_route_map,
7890 no_neighbor_route_map_cmd,
70dd370f 7891 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
0ea8d871
IR
7892 NO_STR
7893 NEIGHBOR_STR
7894 NEIGHBOR_ADDR_STR2
7895 "Apply route map to neighbor\n"
7896 "Name of route map\n"
7897 "Apply map to incoming routes\n"
7898 "Apply map to outbound routes\n")
7899{
7900 int idx_peer = 2;
7901 int idx_in_out = 5;
7902 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7903 bgp_node_afi(vty), bgp_node_safi(vty),
7904 argv[idx_in_out]->arg);
7905}
7906
7907ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
70dd370f 7908 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
d6d7ed37
IR
7909 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7910 "Apply route map to neighbor\n"
7911 "Name of route map\n"
7912 "Apply map to incoming routes\n"
7913 "Apply map to outbound routes\n")
7914
718e3744 7915/* Set unsuppress-map to the peer. */
d62a17ae 7916static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7917 afi_t afi, safi_t safi,
7918 const char *name_str)
718e3744 7919{
d62a17ae 7920 int ret;
7921 struct peer *peer;
1de27621 7922 struct route_map *route_map;
718e3744 7923
d62a17ae 7924 peer = peer_and_group_lookup_vty(vty, ip_str);
7925 if (!peer)
7926 return CMD_WARNING_CONFIG_FAILED;
718e3744 7927
1de27621
DA
7928 route_map = route_map_lookup_warn_noexist(vty, name_str);
7929 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 7930
d62a17ae 7931 return bgp_vty_return(vty, ret);
718e3744 7932}
7933
7934/* Unset route-map from the peer. */
d62a17ae 7935static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7936 afi_t afi, safi_t safi)
718e3744 7937{
d62a17ae 7938 int ret;
7939 struct peer *peer;
718e3744 7940
d62a17ae 7941 peer = peer_and_group_lookup_vty(vty, ip_str);
7942 if (!peer)
7943 return CMD_WARNING_CONFIG_FAILED;
718e3744 7944
d62a17ae 7945 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 7946
d62a17ae 7947 return bgp_vty_return(vty, ret);
718e3744 7948}
7949
7950DEFUN (neighbor_unsuppress_map,
7951 neighbor_unsuppress_map_cmd,
9ccf14f7 7952 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7953 NEIGHBOR_STR
7954 NEIGHBOR_ADDR_STR2
7955 "Route-map to selectively unsuppress suppressed routes\n"
7956 "Name of route map\n")
7957{
d62a17ae 7958 int idx_peer = 1;
7959 int idx_word = 3;
7960 return peer_unsuppress_map_set_vty(
7961 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7962 argv[idx_word]->arg);
718e3744 7963}
7964
d62a17ae 7965ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7966 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7967 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7968 "Route-map to selectively unsuppress suppressed routes\n"
7969 "Name of route map\n")
596c17ba 7970
718e3744 7971DEFUN (no_neighbor_unsuppress_map,
7972 no_neighbor_unsuppress_map_cmd,
9ccf14f7 7973 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7974 NO_STR
7975 NEIGHBOR_STR
7976 NEIGHBOR_ADDR_STR2
7977 "Route-map to selectively unsuppress suppressed routes\n"
7978 "Name of route map\n")
7979{
d62a17ae 7980 int idx_peer = 2;
7981 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7982 bgp_node_afi(vty),
7983 bgp_node_safi(vty));
718e3744 7984}
6b0655a2 7985
d62a17ae 7986ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7987 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7988 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7989 "Route-map to selectively unsuppress suppressed routes\n"
7990 "Name of route map\n")
596c17ba 7991
7e62b792
IR
7992static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7993 afi_t afi, safi_t safi,
7994 const char *num_str,
7995 const char *threshold_str, int warning,
7996 const char *restart_str,
7997 const char *force_str)
7998{
7999 int ret;
8000 struct peer *peer;
8001 uint32_t max;
8002 uint8_t threshold;
8003 uint16_t restart;
8004
8005 peer = peer_and_group_lookup_vty(vty, ip_str);
8006 if (!peer)
8007 return CMD_WARNING_CONFIG_FAILED;
8008
8009 max = strtoul(num_str, NULL, 10);
8010 if (threshold_str)
8011 threshold = atoi(threshold_str);
8012 else
8013 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
8014
8015 if (restart_str)
8016 restart = atoi(restart_str);
8017 else
8018 restart = 0;
8019
8020 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
8021 restart, force_str ? true : false);
8022
8023 return bgp_vty_return(vty, ret);
8024}
8025
8026static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
8027 afi_t afi, safi_t safi)
8028{
8029 int ret;
8030 struct peer *peer;
8031
8032 peer = peer_and_group_lookup_vty(vty, ip_str);
8033 if (!peer)
8034 return CMD_WARNING_CONFIG_FAILED;
8035
8036 ret = peer_maximum_prefix_unset(peer, afi, safi);
8037
8038 return bgp_vty_return(vty, ret);
8039}
8040
fde246e8 8041/* Maximum number of prefix to be sent to the neighbor. */
1d80f243
IR
8042DEFUN(neighbor_maximum_prefix_out,
8043 neighbor_maximum_prefix_out_cmd,
8044 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8045 NEIGHBOR_STR
8046 NEIGHBOR_ADDR_STR2
8047 "Maximum number of prefixes to be sent to this peer\n"
8048 "Maximum no. of prefix limit\n")
fde246e8 8049{
80444d30 8050 int ret;
fde246e8
DA
8051 int idx_peer = 1;
8052 int idx_number = 3;
7e62b792
IR
8053 struct peer *peer;
8054 uint32_t max;
fde246e8
DA
8055 afi_t afi = bgp_node_afi(vty);
8056 safi_t safi = bgp_node_safi(vty);
8057
7e62b792
IR
8058 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8059 if (!peer)
fde246e8
DA
8060 return CMD_WARNING_CONFIG_FAILED;
8061
7e62b792 8062 max = strtoul(argv[idx_number]->arg, NULL, 10);
fde246e8 8063
80444d30 8064 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
fde246e8 8065
80444d30 8066 return bgp_vty_return(vty, ret);
fde246e8
DA
8067}
8068
1d80f243
IR
8069DEFUN(no_neighbor_maximum_prefix_out,
8070 no_neighbor_maximum_prefix_out_cmd,
bc03c622 8071 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
1d80f243
IR
8072 NO_STR
8073 NEIGHBOR_STR
8074 NEIGHBOR_ADDR_STR2
bc03c622
LS
8075 "Maximum number of prefixes to be sent to this peer\n"
8076 "Maximum no. of prefix limit\n")
fde246e8 8077{
80444d30 8078 int ret;
fde246e8 8079 int idx_peer = 2;
7e62b792 8080 struct peer *peer;
fde246e8
DA
8081 afi_t afi = bgp_node_afi(vty);
8082 safi_t safi = bgp_node_safi(vty);
8083
7e62b792
IR
8084 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8085 if (!peer)
fde246e8
DA
8086 return CMD_WARNING_CONFIG_FAILED;
8087
80444d30 8088 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
fde246e8 8089
80444d30 8090 return bgp_vty_return(vty, ret);
fde246e8
DA
8091}
8092
9cbd06e0
DA
8093/* Maximum number of prefix configuration. Prefix count is different
8094 for each peer configuration. So this configuration can be set for
718e3744 8095 each peer configuration. */
1d80f243
IR
8096DEFUN (neighbor_maximum_prefix,
8097 neighbor_maximum_prefix_cmd,
8098 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8099 NEIGHBOR_STR
8100 NEIGHBOR_ADDR_STR2
8101 "Maximum number of prefix accept from this peer\n"
8102 "maximum no. of prefix limit\n"
8103 "Force checking all received routes not only accepted\n")
718e3744 8104{
d62a17ae 8105 int idx_peer = 1;
8106 int idx_number = 3;
9cbd06e0 8107 int idx_force = 0;
7e62b792 8108 char *force = NULL;
9cbd06e0
DA
8109
8110 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8111 force = argv[idx_force]->arg;
9cbd06e0 8112
7e62b792
IR
8113 return peer_maximum_prefix_set_vty(
8114 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8115 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 8116}
8117
d62a17ae 8118ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8119 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 8120 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8121 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
8122 "maximum no. of prefix limit\n"
8123 "Force checking all received routes not only accepted\n")
596c17ba 8124
1d80f243
IR
8125DEFUN (neighbor_maximum_prefix_threshold,
8126 neighbor_maximum_prefix_threshold_cmd,
8127 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8128 NEIGHBOR_STR
8129 NEIGHBOR_ADDR_STR2
8130 "Maximum number of prefix accept from this peer\n"
8131 "maximum no. of prefix limit\n"
8132 "Threshold value (%) at which to generate a warning msg\n"
8133 "Force checking all received routes not only accepted\n")
e0701b79 8134{
d62a17ae 8135 int idx_peer = 1;
8136 int idx_number = 3;
8137 int idx_number_2 = 4;
9cbd06e0 8138 int idx_force = 0;
7e62b792 8139 char *force = NULL;
9cbd06e0
DA
8140
8141 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8142 force = argv[idx_force]->arg;
9cbd06e0 8143
7e62b792
IR
8144 return peer_maximum_prefix_set_vty(
8145 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8146 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 8147}
e0701b79 8148
d62a17ae 8149ALIAS_HIDDEN(
8150 neighbor_maximum_prefix_threshold,
8151 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 8152 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 8153 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8154 "Maximum number of prefix accept from this peer\n"
8155 "maximum no. of prefix limit\n"
9cbd06e0
DA
8156 "Threshold value (%) at which to generate a warning msg\n"
8157 "Force checking all received routes not only accepted\n")
596c17ba 8158
1d80f243
IR
8159DEFUN (neighbor_maximum_prefix_warning,
8160 neighbor_maximum_prefix_warning_cmd,
8161 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8162 NEIGHBOR_STR
8163 NEIGHBOR_ADDR_STR2
8164 "Maximum number of prefix accept from this peer\n"
8165 "maximum no. of prefix limit\n"
8166 "Only give warning message when limit is exceeded\n"
8167 "Force checking all received routes not only accepted\n")
718e3744 8168{
d62a17ae 8169 int idx_peer = 1;
8170 int idx_number = 3;
9cbd06e0 8171 int idx_force = 0;
7e62b792 8172 char *force = NULL;
9cbd06e0
DA
8173
8174 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8175 force = argv[idx_force]->arg;
9cbd06e0 8176
7e62b792
IR
8177 return peer_maximum_prefix_set_vty(
8178 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8179 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 8180}
8181
d62a17ae 8182ALIAS_HIDDEN(
8183 neighbor_maximum_prefix_warning,
8184 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 8185 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 8186 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8187 "Maximum number of prefix accept from this peer\n"
8188 "maximum no. of prefix limit\n"
9cbd06e0
DA
8189 "Only give warning message when limit is exceeded\n"
8190 "Force checking all received routes not only accepted\n")
596c17ba 8191
1d80f243
IR
8192DEFUN (neighbor_maximum_prefix_threshold_warning,
8193 neighbor_maximum_prefix_threshold_warning_cmd,
8194 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8195 NEIGHBOR_STR
8196 NEIGHBOR_ADDR_STR2
8197 "Maximum number of prefix accept from this peer\n"
8198 "maximum no. of prefix limit\n"
8199 "Threshold value (%) at which to generate a warning msg\n"
8200 "Only give warning message when limit is exceeded\n"
8201 "Force checking all received routes not only accepted\n")
e0701b79 8202{
d62a17ae 8203 int idx_peer = 1;
8204 int idx_number = 3;
8205 int idx_number_2 = 4;
9cbd06e0 8206 int idx_force = 0;
7e62b792 8207 char *force = NULL;
9cbd06e0
DA
8208
8209 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8210 force = argv[idx_force]->arg;
9cbd06e0 8211
7e62b792
IR
8212 return peer_maximum_prefix_set_vty(
8213 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8214 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 8215}
8216
d62a17ae 8217ALIAS_HIDDEN(
8218 neighbor_maximum_prefix_threshold_warning,
8219 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 8220 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 8221 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8222 "Maximum number of prefix accept from this peer\n"
8223 "maximum no. of prefix limit\n"
8224 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
8225 "Only give warning message when limit is exceeded\n"
8226 "Force checking all received routes not only accepted\n")
596c17ba 8227
1d80f243
IR
8228DEFUN (neighbor_maximum_prefix_restart,
8229 neighbor_maximum_prefix_restart_cmd,
8230 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8231 NEIGHBOR_STR
8232 NEIGHBOR_ADDR_STR2
8233 "Maximum number of prefix accept from this peer\n"
8234 "maximum no. of prefix limit\n"
8235 "Restart bgp connection after limit is exceeded\n"
8236 "Restart interval in minutes\n"
8237 "Force checking all received routes not only accepted\n")
0a486e5f 8238{
d62a17ae 8239 int idx_peer = 1;
8240 int idx_number = 3;
8241 int idx_number_2 = 5;
9cbd06e0 8242 int idx_force = 0;
7e62b792 8243 char *force = NULL;
9cbd06e0
DA
8244
8245 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8246 force = argv[idx_force]->arg;
9cbd06e0 8247
7e62b792
IR
8248 return peer_maximum_prefix_set_vty(
8249 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8250 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 8251}
8252
d62a17ae 8253ALIAS_HIDDEN(
8254 neighbor_maximum_prefix_restart,
8255 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 8256 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 8257 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8258 "Maximum number of prefix accept from this peer\n"
8259 "maximum no. of prefix limit\n"
8260 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8261 "Restart interval in minutes\n"
8262 "Force checking all received routes not only accepted\n")
596c17ba 8263
1d80f243
IR
8264DEFUN (neighbor_maximum_prefix_threshold_restart,
8265 neighbor_maximum_prefix_threshold_restart_cmd,
8266 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8267 NEIGHBOR_STR
8268 NEIGHBOR_ADDR_STR2
8269 "Maximum number of prefixes to accept from this peer\n"
8270 "maximum no. of prefix limit\n"
8271 "Threshold value (%) at which to generate a warning msg\n"
8272 "Restart bgp connection after limit is exceeded\n"
8273 "Restart interval in minutes\n"
8274 "Force checking all received routes not only accepted\n")
0a486e5f 8275{
d62a17ae 8276 int idx_peer = 1;
8277 int idx_number = 3;
8278 int idx_number_2 = 4;
8279 int idx_number_3 = 6;
9cbd06e0 8280 int idx_force = 0;
7e62b792 8281 char *force = NULL;
9cbd06e0
DA
8282
8283 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8284 force = argv[idx_force]->arg;
9cbd06e0 8285
7e62b792
IR
8286 return peer_maximum_prefix_set_vty(
8287 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8288 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8289 argv[idx_number_3]->arg, force);
d62a17ae 8290}
8291
8292ALIAS_HIDDEN(
8293 neighbor_maximum_prefix_threshold_restart,
8294 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 8295 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 8296 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8297 "Maximum number of prefixes to accept from this peer\n"
8298 "maximum no. of prefix limit\n"
8299 "Threshold value (%) at which to generate a warning msg\n"
8300 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8301 "Restart interval in minutes\n"
8302 "Force checking all received routes not only accepted\n")
596c17ba 8303
1d80f243
IR
8304DEFUN (no_neighbor_maximum_prefix,
8305 no_neighbor_maximum_prefix_cmd,
8306 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8307 NO_STR
8308 NEIGHBOR_STR
8309 NEIGHBOR_ADDR_STR2
8310 "Maximum number of prefixes to accept from this peer\n"
8311 "maximum no. of prefix limit\n"
8312 "Threshold value (%) at which to generate a warning msg\n"
8313 "Restart bgp connection after limit is exceeded\n"
8314 "Restart interval in minutes\n"
8315 "Only give warning message when limit is exceeded\n"
8316 "Force checking all received routes not only accepted\n")
718e3744 8317{
d62a17ae 8318 int idx_peer = 2;
7e62b792
IR
8319 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8320 bgp_node_afi(vty),
8321 bgp_node_safi(vty));
718e3744 8322}
e52702f2 8323
d62a17ae 8324ALIAS_HIDDEN(
8325 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8326 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 8327 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8328 "Maximum number of prefixes to accept from this peer\n"
8329 "maximum no. of prefix limit\n"
8330 "Threshold value (%) at which to generate a warning msg\n"
8331 "Restart bgp connection after limit is exceeded\n"
8332 "Restart interval in minutes\n"
9cbd06e0
DA
8333 "Only give warning message when limit is exceeded\n"
8334 "Force checking all received routes not only accepted\n")
596c17ba 8335
46dbf9d0
DA
8336/* "neighbor accept-own" */
8337DEFPY (neighbor_accept_own,
8338 neighbor_accept_own_cmd,
8339 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor accept-own",
8340 NO_STR
8341 NEIGHBOR_STR
8342 NEIGHBOR_ADDR_STR2
8343 "Enable handling of self-originated VPN routes containing ACCEPT_OWN community\n")
8344{
8345 struct peer *peer;
8346 afi_t afi = bgp_node_afi(vty);
8347 safi_t safi = bgp_node_safi(vty);
8348 int ret;
8349
8350 peer = peer_and_group_lookup_vty(vty, neighbor);
8351 if (!peer)
8352 return CMD_WARNING_CONFIG_FAILED;
8353
8354 if (no)
8355 ret = peer_af_flag_unset(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8356 else
8357 ret = peer_af_flag_set(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8358
8359 return bgp_vty_return(vty, ret);
8360}
8361
01da2d26
DA
8362/* "neighbor soo" */
8363DEFPY (neighbor_soo,
8364 neighbor_soo_cmd,
8365 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8366 NEIGHBOR_STR
8367 NEIGHBOR_ADDR_STR2
8368 "Set the Site-of-Origin (SoO) extended community\n"
8369 "VPN extended community\n")
8370{
8371 struct peer *peer;
8372 afi_t afi = bgp_node_afi(vty);
8373 safi_t safi = bgp_node_safi(vty);
8374 struct ecommunity *ecomm_soo;
8375
8376 peer = peer_and_group_lookup_vty(vty, neighbor);
8377 if (!peer)
8378 return CMD_WARNING_CONFIG_FAILED;
8379
8380 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8381 if (!ecomm_soo) {
8382 vty_out(vty, "%% Malformed SoO extended community\n");
8383 return CMD_WARNING;
8384 }
8385 ecommunity_str(ecomm_soo);
8386
8387 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8388 ecommunity_free(&peer->soo[afi][safi]);
8389 peer->soo[afi][safi] = ecomm_soo;
8390 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8391 }
8392
8393 return bgp_vty_return(vty,
8394 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8395}
8396
8397DEFPY (no_neighbor_soo,
8398 no_neighbor_soo_cmd,
8399 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8400 NO_STR
8401 NEIGHBOR_STR
8402 NEIGHBOR_ADDR_STR2
8403 "Set the Site-of-Origin (SoO) extended community\n"
8404 "VPN extended community\n")
8405{
8406 struct peer *peer;
8407 afi_t afi = bgp_node_afi(vty);
8408 safi_t safi = bgp_node_safi(vty);
8409
8410 peer = peer_and_group_lookup_vty(vty, neighbor);
8411 if (!peer)
8412 return CMD_WARNING_CONFIG_FAILED;
8413
8414 ecommunity_free(&peer->soo[afi][safi]);
8415
8416 return bgp_vty_return(
8417 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8418}
718e3744 8419
718e3744 8420/* "neighbor allowas-in" */
8421DEFUN (neighbor_allowas_in,
8422 neighbor_allowas_in_cmd,
fd8503f5 8423 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8424 NEIGHBOR_STR
8425 NEIGHBOR_ADDR_STR2
31500417 8426 "Accept as-path with my AS present in it\n"
f79f7a7b 8427 "Number of occurrences of AS number\n"
fd8503f5 8428 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8429{
d62a17ae 8430 int idx_peer = 1;
8431 int idx_number_origin = 3;
8432 int ret;
8433 int origin = 0;
8434 struct peer *peer;
8435 int allow_num = 0;
8436
8437 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8438 if (!peer)
8439 return CMD_WARNING_CONFIG_FAILED;
8440
8441 if (argc <= idx_number_origin)
8442 allow_num = 3;
8443 else {
8444 if (argv[idx_number_origin]->type == WORD_TKN)
8445 origin = 1;
8446 else
8447 allow_num = atoi(argv[idx_number_origin]->arg);
8448 }
8449
8450 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8451 allow_num, origin);
8452
8453 return bgp_vty_return(vty, ret);
8454}
8455
8456ALIAS_HIDDEN(
8457 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8458 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8459 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8460 "Accept as-path with my AS present in it\n"
f79f7a7b 8461 "Number of occurrences of AS number\n"
d62a17ae 8462 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8463
718e3744 8464DEFUN (no_neighbor_allowas_in,
8465 no_neighbor_allowas_in_cmd,
fd8503f5 8466 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8467 NO_STR
8468 NEIGHBOR_STR
8469 NEIGHBOR_ADDR_STR2
8334fd5a 8470 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8471 "Number of occurrences of AS number\n"
fd8503f5 8472 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8473{
d62a17ae 8474 int idx_peer = 2;
8475 int ret;
8476 struct peer *peer;
718e3744 8477
d62a17ae 8478 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8479 if (!peer)
8480 return CMD_WARNING_CONFIG_FAILED;
718e3744 8481
d62a17ae 8482 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8483 bgp_node_safi(vty));
718e3744 8484
d62a17ae 8485 return bgp_vty_return(vty, ret);
718e3744 8486}
6b0655a2 8487
d62a17ae 8488ALIAS_HIDDEN(
8489 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8490 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8491 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8492 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8493 "Number of occurrences of AS number\n"
d62a17ae 8494 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8495
28c6e247
IR
8496DEFUN (neighbor_ttl_security,
8497 neighbor_ttl_security_cmd,
8498 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8499 NEIGHBOR_STR
8500 NEIGHBOR_ADDR_STR2
8501 "BGP ttl-security parameters\n"
8502 "Specify the maximum number of hops to the BGP peer\n"
8503 "Number of hops to BGP peer\n")
fa411a21 8504{
d62a17ae 8505 int idx_peer = 1;
8506 int idx_number = 4;
28c6e247
IR
8507 struct peer *peer;
8508 int gtsm_hops;
d62a17ae 8509
28c6e247
IR
8510 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8511 if (!peer)
d62a17ae 8512 return CMD_WARNING_CONFIG_FAILED;
8513
28c6e247
IR
8514 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8515
8516 /*
8517 * If 'neighbor swpX', then this is for directly connected peers,
8518 * we should not accept a ttl-security hops value greater than 1.
8519 */
8520 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8521 vty_out(vty,
8522 "%s is directly connected peer, hops cannot exceed 1\n",
8523 argv[idx_peer]->arg);
8524 return CMD_WARNING_CONFIG_FAILED;
8525 }
7ebe625c 8526
28c6e247 8527 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
8528}
8529
1d80f243
IR
8530DEFUN (no_neighbor_ttl_security,
8531 no_neighbor_ttl_security_cmd,
8532 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8533 NO_STR
8534 NEIGHBOR_STR
8535 NEIGHBOR_ADDR_STR2
8536 "BGP ttl-security parameters\n"
8537 "Specify the maximum number of hops to the BGP peer\n"
8538 "Number of hops to BGP peer\n")
fa411a21 8539{
d62a17ae 8540 int idx_peer = 2;
28c6e247 8541 struct peer *peer;
fa411a21 8542
28c6e247
IR
8543 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8544 if (!peer)
d62a17ae 8545 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8546
28c6e247 8547 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 8548}
6b0655a2 8549
7c0e4312
DA
8550/* disable-addpath-rx */
8551DEFUN(neighbor_disable_addpath_rx,
8552 neighbor_disable_addpath_rx_cmd,
8553 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8554 NEIGHBOR_STR
8555 NEIGHBOR_ADDR_STR2
8556 "Do not accept additional paths\n")
8557{
8558 char *peer_str = argv[1]->arg;
8559 struct peer *peer;
8560 afi_t afi = bgp_node_afi(vty);
8561 safi_t safi = bgp_node_safi(vty);
8562
8563 peer = peer_and_group_lookup_vty(vty, peer_str);
8564 if (!peer)
8565 return CMD_WARNING_CONFIG_FAILED;
8566
8567 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8568 PEER_FLAG_DISABLE_ADDPATH_RX);
8569}
8570
8571DEFUN(no_neighbor_disable_addpath_rx,
8572 no_neighbor_disable_addpath_rx_cmd,
8573 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8574 NO_STR
8575 NEIGHBOR_STR
8576 NEIGHBOR_ADDR_STR2
8577 "Do not accept additional paths\n")
8578{
8579 char *peer_str = argv[2]->arg;
8580 struct peer *peer;
8581 afi_t afi = bgp_node_afi(vty);
8582 safi_t safi = bgp_node_safi(vty);
8583
8584 peer = peer_and_group_lookup_vty(vty, peer_str);
8585 if (!peer)
8586 return CMD_WARNING_CONFIG_FAILED;
8587
8588 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8589 PEER_FLAG_DISABLE_ADDPATH_RX);
8590}
8591
adbac85e
DW
8592DEFUN (neighbor_addpath_tx_all_paths,
8593 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8594 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8595 NEIGHBOR_STR
8596 NEIGHBOR_ADDR_STR2
8597 "Use addpath to advertise all paths to a neighbor\n")
8598{
d62a17ae 8599 int idx_peer = 1;
8600 struct peer *peer;
adbac85e 8601
d62a17ae 8602 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8603 if (!peer)
8604 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8605
dcc68b5e
MS
8606 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8607 BGP_ADDPATH_ALL);
8608 return CMD_SUCCESS;
adbac85e
DW
8609}
8610
d62a17ae 8611ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8612 neighbor_addpath_tx_all_paths_hidden_cmd,
8613 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8614 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8615 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8616
adbac85e
DW
8617DEFUN (no_neighbor_addpath_tx_all_paths,
8618 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8619 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8620 NO_STR
8621 NEIGHBOR_STR
8622 NEIGHBOR_ADDR_STR2
8623 "Use addpath to advertise all paths to a neighbor\n")
8624{
d62a17ae 8625 int idx_peer = 2;
dcc68b5e
MS
8626 struct peer *peer;
8627
8628 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8629 if (!peer)
8630 return CMD_WARNING_CONFIG_FAILED;
8631
8632 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8633 != BGP_ADDPATH_ALL) {
8634 vty_out(vty,
8635 "%% Peer not currently configured to transmit all paths.");
8636 return CMD_WARNING_CONFIG_FAILED;
8637 }
8638
8639 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8640 BGP_ADDPATH_NONE);
8641
8642 return CMD_SUCCESS;
adbac85e
DW
8643}
8644
d62a17ae 8645ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8646 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8647 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8648 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8649 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8650
06370dac
DW
8651DEFUN (neighbor_addpath_tx_bestpath_per_as,
8652 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8653 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8654 NEIGHBOR_STR
8655 NEIGHBOR_ADDR_STR2
8656 "Use addpath to advertise the bestpath per each neighboring AS\n")
8657{
d62a17ae 8658 int idx_peer = 1;
8659 struct peer *peer;
06370dac 8660
d62a17ae 8661 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8662 if (!peer)
8663 return CMD_WARNING_CONFIG_FAILED;
06370dac 8664
dcc68b5e
MS
8665 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8666 BGP_ADDPATH_BEST_PER_AS);
8667
8668 return CMD_SUCCESS;
06370dac
DW
8669}
8670
d62a17ae 8671ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8672 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8673 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8674 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8675 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8676
06370dac
DW
8677DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8678 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8679 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8680 NO_STR
8681 NEIGHBOR_STR
8682 NEIGHBOR_ADDR_STR2
8683 "Use addpath to advertise the bestpath per each neighboring AS\n")
8684{
d62a17ae 8685 int idx_peer = 2;
dcc68b5e
MS
8686 struct peer *peer;
8687
8688 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8689 if (!peer)
8690 return CMD_WARNING_CONFIG_FAILED;
8691
8692 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8693 != BGP_ADDPATH_BEST_PER_AS) {
8694 vty_out(vty,
8695 "%% Peer not currently configured to transmit all best path per as.");
8696 return CMD_WARNING_CONFIG_FAILED;
8697 }
8698
8699 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8700 BGP_ADDPATH_NONE);
8701
8702 return CMD_SUCCESS;
06370dac
DW
8703}
8704
d62a17ae 8705ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8706 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8707 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8708 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8709 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8710
2b31007c
RZ
8711DEFPY(
8712 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8713 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8714 NEIGHBOR_STR
8715 NEIGHBOR_ADDR_STR2
8716 "Detect AS loops before sending to neighbor\n")
8717{
8718 struct peer *peer;
8719
8720 peer = peer_and_group_lookup_vty(vty, neighbor);
8721 if (!peer)
8722 return CMD_WARNING_CONFIG_FAILED;
8723
8724 peer->as_path_loop_detection = true;
8725
8726 return CMD_SUCCESS;
8727}
8728
8729DEFPY(
8730 no_neighbor_aspath_loop_detection,
8731 no_neighbor_aspath_loop_detection_cmd,
8732 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8733 NO_STR
8734 NEIGHBOR_STR
8735 NEIGHBOR_ADDR_STR2
8736 "Detect AS loops before sending to neighbor\n")
8737{
8738 struct peer *peer;
8739
8740 peer = peer_and_group_lookup_vty(vty, neighbor);
8741 if (!peer)
8742 return CMD_WARNING_CONFIG_FAILED;
8743
8744 peer->as_path_loop_detection = false;
8745
8746 return CMD_SUCCESS;
8747}
8748
b9c7bc5a 8749static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8750 struct ecommunity **list, bool is_rt6)
ddb5b488 8751{
b9c7bc5a
PZ
8752 struct ecommunity *ecom = NULL;
8753 struct ecommunity *ecomadd;
ddb5b488 8754
b9c7bc5a 8755 for (; argc; --argc, ++argv) {
9a659715
PG
8756 if (is_rt6)
8757 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8758 ECOMMUNITY_ROUTE_TARGET,
8759 0);
8760 else
8761 ecomadd = ecommunity_str2com(argv[0]->arg,
8762 ECOMMUNITY_ROUTE_TARGET,
8763 0);
b9c7bc5a
PZ
8764 if (!ecomadd) {
8765 vty_out(vty, "Malformed community-list value\n");
8766 if (ecom)
8767 ecommunity_free(&ecom);
8768 return CMD_WARNING_CONFIG_FAILED;
8769 }
ddb5b488 8770
b9c7bc5a
PZ
8771 if (ecom) {
8772 ecommunity_merge(ecom, ecomadd);
8773 ecommunity_free(&ecomadd);
8774 } else {
8775 ecom = ecomadd;
8776 }
8777 }
8778
8779 if (*list) {
8780 ecommunity_free(&*list);
ddb5b488 8781 }
b9c7bc5a
PZ
8782 *list = ecom;
8783
8784 return CMD_SUCCESS;
ddb5b488
PZ
8785}
8786
0ca70ba5
DS
8787/*
8788 * v2vimport is true if we are handling a `import vrf ...` command
8789 */
8790static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8791{
0ca70ba5
DS
8792 afi_t afi;
8793
ddb5b488 8794 switch (vty->node) {
b9c7bc5a 8795 case BGP_IPV4_NODE:
0ca70ba5
DS
8796 afi = AFI_IP;
8797 break;
b9c7bc5a 8798 case BGP_IPV6_NODE:
0ca70ba5
DS
8799 afi = AFI_IP6;
8800 break;
ddb5b488
PZ
8801 default:
8802 vty_out(vty,
b9c7bc5a 8803 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 8804 return AFI_MAX;
ddb5b488 8805 }
69b07479 8806
0ca70ba5
DS
8807 if (!v2vimport) {
8808 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8809 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8810 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8811 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8812 vty_out(vty,
8813 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8814 return AFI_MAX;
8815 }
8816 } else {
8817 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8818 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8819 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8820 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8821 vty_out(vty,
8822 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8823 return AFI_MAX;
8824 }
8825 }
8826 return afi;
ddb5b488
PZ
8827}
8828
585f1adc
IR
8829DEFPY (af_rd_vpn_export,
8830 af_rd_vpn_export_cmd,
8831 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8832 NO_STR
8833 "Specify route distinguisher\n"
8834 "Between current address-family and vpn\n"
8835 "For routes leaked from current address-family to vpn\n"
8836 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 8837{
585f1adc
IR
8838 VTY_DECLVAR_CONTEXT(bgp, bgp);
8839 struct prefix_rd prd;
8840 int ret;
ddb5b488 8841 afi_t afi;
b9c7bc5a 8842 int idx = 0;
585f1adc 8843 bool yes = true;
b9c7bc5a 8844
585f1adc
IR
8845 if (argv_find(argv, argc, "no", &idx))
8846 yes = false;
ddb5b488 8847
585f1adc
IR
8848 if (yes) {
8849 ret = str2prefix_rd(rd_str, &prd);
8850 if (!ret) {
8851 vty_out(vty, "%% Malformed rd\n");
8852 return CMD_WARNING_CONFIG_FAILED;
8853 }
8854 }
ddb5b488 8855
585f1adc
IR
8856 afi = vpn_policy_getafi(vty, bgp, false);
8857 if (afi == AFI_MAX)
8858 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8859
585f1adc
IR
8860 /*
8861 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8862 */
8863 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8864 bgp_get_default(), bgp);
ddb5b488 8865
585f1adc
IR
8866 if (yes) {
8867 bgp->vpn_policy[afi].tovpn_rd = prd;
8868 SET_FLAG(bgp->vpn_policy[afi].flags,
8869 BGP_VPN_POLICY_TOVPN_RD_SET);
8870 } else {
8871 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8872 BGP_VPN_POLICY_TOVPN_RD_SET);
8873 }
69b07479 8874
585f1adc
IR
8875 /* post-change: re-export vpn routes */
8876 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8877 bgp_get_default(), bgp);
8878
8879 return CMD_SUCCESS;
ddb5b488
PZ
8880}
8881
b9c7bc5a
PZ
8882ALIAS (af_rd_vpn_export,
8883 af_no_rd_vpn_export_cmd,
8884 "no rd vpn export",
ddb5b488 8885 NO_STR
b9c7bc5a
PZ
8886 "Specify route distinguisher\n"
8887 "Between current address-family and vpn\n"
8888 "For routes leaked from current address-family to vpn\n")
ddb5b488 8889
b9c7bc5a
PZ
8890DEFPY (af_label_vpn_export,
8891 af_label_vpn_export_cmd,
e70e9f8e 8892 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 8893 NO_STR
ddb5b488 8894 "label value for VRF\n"
b9c7bc5a
PZ
8895 "Between current address-family and vpn\n"
8896 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
8897 "Label Value <0-1048575>\n"
8898 "Automatically assign a label\n")
ddb5b488
PZ
8899{
8900 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8901 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 8902 afi_t afi;
b9c7bc5a 8903 int idx = 0;
c6423c31 8904 bool yes = true;
b9c7bc5a
PZ
8905
8906 if (argv_find(argv, argc, "no", &idx))
c6423c31 8907 yes = false;
ddb5b488 8908
21a16cc2
PZ
8909 /* If "no ...", squash trailing parameter */
8910 if (!yes)
8911 label_auto = NULL;
8912
e70e9f8e
PZ
8913 if (yes) {
8914 if (!label_auto)
8915 label = label_val; /* parser should force unsigned */
8916 }
ddb5b488 8917
0ca70ba5 8918 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8919 if (afi == AFI_MAX)
8920 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 8921
e70e9f8e 8922
69b07479
DS
8923 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8924 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8925 /* no change */
8926 return CMD_SUCCESS;
e70e9f8e 8927
69b07479
DS
8928 /*
8929 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8930 */
8931 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8932 bgp_get_default(), bgp);
8933
8934 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8935 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8936
8937 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8938
8939 /*
8940 * label has previously been automatically
8941 * assigned by labelpool: release it
8942 *
8943 * NB if tovpn_label == MPLS_LABEL_NONE it
8944 * means the automatic assignment is in flight
8945 * and therefore the labelpool callback must
8946 * detect that the auto label is not needed.
8947 */
8948
8949 bgp_lp_release(LP_TYPE_VRF,
8950 &bgp->vpn_policy[afi],
8951 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 8952 }
69b07479
DS
8953 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8954 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8955 }
ddb5b488 8956
69b07479
DS
8957 bgp->vpn_policy[afi].tovpn_label = label;
8958 if (label_auto) {
8959 SET_FLAG(bgp->vpn_policy[afi].flags,
8960 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8961 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8962 vpn_leak_label_callback);
ddb5b488
PZ
8963 }
8964
69b07479
DS
8965 /* post-change: re-export vpn routes */
8966 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8967 bgp_get_default(), bgp);
8968
0d020cd6 8969 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
8970 return CMD_SUCCESS;
8971}
8972
b72c9e14
HS
8973DEFPY (af_sid_vpn_export,
8974 af_sid_vpn_export_cmd,
46279a11 8975 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
b72c9e14
HS
8976 NO_STR
8977 "sid value for VRF\n"
8978 "Between current address-family and vpn\n"
8979 "For routes leaked from current address-family to vpn\n"
8980 "Sid allocation index\n"
8981 "Automatically assign a label\n")
8982{
8983 VTY_DECLVAR_CONTEXT(bgp, bgp);
8984 afi_t afi;
8985 int debug = 0;
8986 int idx = 0;
8987 bool yes = true;
8988
8989 if (argv_find(argv, argc, "no", &idx))
8990 yes = false;
8991 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8992 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8993
8994 afi = vpn_policy_getafi(vty, bgp, false);
8995 if (afi == AFI_MAX)
8996 return CMD_WARNING_CONFIG_FAILED;
8997
8998 if (!yes) {
8999 /* implement me */
4d4c404b 9000 vty_out(vty, "It's not implemented\n");
b72c9e14
HS
9001 return CMD_WARNING_CONFIG_FAILED;
9002 }
9003
527588aa
CS
9004 if (bgp->tovpn_sid_index != 0 ||
9005 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
9006 vty_out(vty,
9007 "per-vrf sid and per-af sid are mutually exclusive\n"
9008 "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9009 return CMD_WARNING_CONFIG_FAILED;
9010 }
9011
b72c9e14
HS
9012 /* skip when it's already configured */
9013 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9014 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9015 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9016 return CMD_SUCCESS;
9017
7de4c885
HS
9018 /*
9019 * mode change between sid_idx and sid_auto isn't supported.
9020 * user must negate sid vpn export when they want to change the mode
9021 */
b72c9e14
HS
9022 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9023 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9024 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9025 vty_out(vty, "it's already configured as %s.\n",
9026 sid_auto ? "auto-mode" : "idx-mode");
9027 return CMD_WARNING_CONFIG_FAILED;
9028 }
9029
9030 /* pre-change */
9031 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9032 bgp_get_default(), bgp);
9033
9034 if (sid_auto) {
9035 /* SID allocation auto-mode */
9036 if (debug)
9037 zlog_debug("%s: auto sid alloc.", __func__);
9038 SET_FLAG(bgp->vpn_policy[afi].flags,
9039 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9040 } else {
9041 /* SID allocation index-mode */
9042 if (debug)
9043 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9044 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9045 }
9046
9047 /* post-change */
9048 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9049 bgp_get_default(), bgp);
9050 return CMD_SUCCESS;
9051}
9052
527588aa
CS
9053DEFPY (bgp_sid_vpn_export,
9054 bgp_sid_vpn_export_cmd,
9055 "[no] sid vpn per-vrf export <(1-255)$sid_idx|auto$sid_auto>",
9056 NO_STR
9057 "sid value for VRF\n"
9058 "Between current vrf and vpn\n"
9059 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9060 "For routes leaked from current vrf to vpn\n"
9061 "Sid allocation index\n"
9062 "Automatically assign a label\n")
9063{
9064 VTY_DECLVAR_CONTEXT(bgp, bgp);
9065 int debug;
9066
9067 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9068 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9069
9070 if (no) {
9071 /* implement me */
9072 vty_out(vty, "It's not implemented\n");
9073 return CMD_WARNING_CONFIG_FAILED;
9074 }
9075
9076 if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9077 CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9078 BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9079 bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9080 CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9081 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9082 vty_out(vty,
9083 "per-vrf sid and per-af sid are mutually exclusive\n"
9084 "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9085 return CMD_WARNING_CONFIG_FAILED;
9086 }
9087
9088 /* skip when it's already configured */
9089 if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9090 (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9091 return CMD_SUCCESS;
9092
9093 /*
9094 * mode change between sid_idx and sid_auto isn't supported.
9095 * user must negate sid vpn export when they want to change the mode
9096 */
9097 if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9098 (sid_idx != 0 &&
9099 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9100 vty_out(vty, "it's already configured as %s.\n",
9101 sid_auto ? "auto-mode" : "idx-mode");
9102 return CMD_WARNING_CONFIG_FAILED;
9103 }
9104
9105 /* pre-change */
9106 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9107 bgp);
9108 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9109 bgp);
9110
9111 if (sid_auto) {
9112 /* SID allocation auto-mode */
9113 if (debug)
9114 zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9115 SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9116 } else {
9117 /* SID allocation index-mode */
9118 if (debug)
9119 zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9120 sid_idx);
9121 bgp->tovpn_sid_index = sid_idx;
9122 }
9123
9124 /* post-change */
9125 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9126 bgp);
9127 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9128 bgp_get_default(), bgp);
9129
9130 return CMD_SUCCESS;
9131}
9132
b9c7bc5a
PZ
9133ALIAS (af_label_vpn_export,
9134 af_no_label_vpn_export_cmd,
9135 "no label vpn export",
9136 NO_STR
9137 "label value for VRF\n"
9138 "Between current address-family and vpn\n"
9139 "For routes leaked from current address-family to vpn\n")
ddb5b488 9140
585f1adc 9141DEFPY (af_nexthop_vpn_export,
b9c7bc5a 9142 af_nexthop_vpn_export_cmd,
8c85ca28 9143 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 9144 NO_STR
ddb5b488 9145 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
9146 "Between current address-family and vpn\n"
9147 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9148 "IPv4 prefix\n"
9149 "IPv6 prefix\n")
9150{
585f1adc 9151 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 9152 afi_t afi;
ddb5b488
PZ
9153 struct prefix p;
9154
8c85ca28
QY
9155 if (!no) {
9156 if (!nexthop_su) {
9157 vty_out(vty, "%% Nexthop required\n");
9158 return CMD_WARNING_CONFIG_FAILED;
9159 }
8c85ca28 9160 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
9161 return CMD_WARNING_CONFIG_FAILED;
9162 }
ddb5b488 9163
585f1adc
IR
9164 afi = vpn_policy_getafi(vty, bgp, false);
9165 if (afi == AFI_MAX)
9166 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9167
585f1adc
IR
9168 /*
9169 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9170 */
9171 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9172 bgp_get_default(), bgp);
ddb5b488 9173
585f1adc
IR
9174 if (!no) {
9175 bgp->vpn_policy[afi].tovpn_nexthop = p;
9176 SET_FLAG(bgp->vpn_policy[afi].flags,
9177 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9178 } else {
9179 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9180 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9181 }
69b07479 9182
585f1adc
IR
9183 /* post-change: re-export vpn routes */
9184 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9185 bgp_get_default(), bgp);
37a87b8f 9186
585f1adc 9187 return CMD_SUCCESS;
ddb5b488
PZ
9188}
9189
b9c7bc5a 9190static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 9191{
b9c7bc5a
PZ
9192 if (!strcmp(dstr, "import")) {
9193 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9194 } else if (!strcmp(dstr, "export")) {
9195 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9196 } else if (!strcmp(dstr, "both")) {
9197 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9198 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9199 } else {
9200 vty_out(vty, "%% direction parse error\n");
9201 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9202 }
ddb5b488
PZ
9203 return CMD_SUCCESS;
9204}
9205
b9c7bc5a
PZ
9206DEFPY (af_rt_vpn_imexport,
9207 af_rt_vpn_imexport_cmd,
9208 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9209 NO_STR
9210 "Specify route target list\n"
ddb5b488 9211 "Specify route target list\n"
b9c7bc5a
PZ
9212 "Between current address-family and vpn\n"
9213 "For routes leaked from vpn to current address-family: match any\n"
9214 "For routes leaked from current address-family to vpn: set\n"
9215 "both import: match any and export: set\n"
ddb5b488
PZ
9216 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9217{
9218 VTY_DECLVAR_CONTEXT(bgp, bgp);
9219 int ret;
9220 struct ecommunity *ecom = NULL;
9221 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 9222 enum vpn_policy_direction dir;
ddb5b488
PZ
9223 afi_t afi;
9224 int idx = 0;
c6423c31 9225 bool yes = true;
ddb5b488 9226
b9c7bc5a 9227 if (argv_find(argv, argc, "no", &idx))
c6423c31 9228 yes = false;
b9c7bc5a 9229
0ca70ba5 9230 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9231 if (afi == AFI_MAX)
9232 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9233
b9c7bc5a 9234 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
9235 if (ret != CMD_SUCCESS)
9236 return ret;
9237
b9c7bc5a
PZ
9238 if (yes) {
9239 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9240 vty_out(vty, "%% Missing RTLIST\n");
9241 return CMD_WARNING_CONFIG_FAILED;
9242 }
c6423c31 9243 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
9244 if (ret != CMD_SUCCESS) {
9245 return ret;
9246 }
ddb5b488
PZ
9247 }
9248
69b07479
DS
9249 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9250 if (!dodir[dir])
ddb5b488 9251 continue;
ddb5b488 9252
69b07479 9253 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9254
69b07479
DS
9255 if (yes) {
9256 if (bgp->vpn_policy[afi].rtlist[dir])
9257 ecommunity_free(
9258 &bgp->vpn_policy[afi].rtlist[dir]);
9259 bgp->vpn_policy[afi].rtlist[dir] =
9260 ecommunity_dup(ecom);
9261 } else {
9262 if (bgp->vpn_policy[afi].rtlist[dir])
9263 ecommunity_free(
9264 &bgp->vpn_policy[afi].rtlist[dir]);
9265 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 9266 }
69b07479
DS
9267
9268 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9269 }
69b07479 9270
d555f3e9
PZ
9271 if (ecom)
9272 ecommunity_free(&ecom);
ddb5b488
PZ
9273
9274 return CMD_SUCCESS;
9275}
9276
b9c7bc5a
PZ
9277ALIAS (af_rt_vpn_imexport,
9278 af_no_rt_vpn_imexport_cmd,
9279 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
9280 NO_STR
9281 "Specify route target list\n"
b9c7bc5a
PZ
9282 "Specify route target list\n"
9283 "Between current address-family and vpn\n"
9284 "For routes leaked from vpn to current address-family\n"
9285 "For routes leaked from current address-family to vpn\n"
9286 "both import and export\n")
9287
585f1adc 9288DEFPY (af_route_map_vpn_imexport,
b9c7bc5a
PZ
9289 af_route_map_vpn_imexport_cmd,
9290/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9291 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9292 NO_STR
ddb5b488 9293 "Specify route map\n"
b9c7bc5a
PZ
9294 "Between current address-family and vpn\n"
9295 "For routes leaked from vpn to current address-family\n"
9296 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9297 "name of route-map\n")
9298{
585f1adc
IR
9299 VTY_DECLVAR_CONTEXT(bgp, bgp);
9300 int ret;
9301 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 9302 enum vpn_policy_direction dir;
ddb5b488 9303 afi_t afi;
ddb5b488 9304 int idx = 0;
585f1adc 9305 bool yes = true;
ddb5b488 9306
585f1adc
IR
9307 if (argv_find(argv, argc, "no", &idx))
9308 yes = false;
ddb5b488 9309
585f1adc
IR
9310 afi = vpn_policy_getafi(vty, bgp, false);
9311 if (afi == AFI_MAX)
9312 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9313
585f1adc
IR
9314 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9315 if (ret != CMD_SUCCESS)
9316 return ret;
ddb5b488 9317
585f1adc
IR
9318 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9319 if (!dodir[dir])
9320 continue;
69b07479 9321
585f1adc
IR
9322 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9323
9324 if (yes) {
9325 if (bgp->vpn_policy[afi].rmap_name[dir])
9326 XFREE(MTYPE_ROUTE_MAP_NAME,
9327 bgp->vpn_policy[afi].rmap_name[dir]);
9328 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9329 MTYPE_ROUTE_MAP_NAME, rmap_str);
9330 bgp->vpn_policy[afi].rmap[dir] =
9331 route_map_lookup_warn_noexist(vty, rmap_str);
9332 if (!bgp->vpn_policy[afi].rmap[dir])
9333 return CMD_SUCCESS;
9334 } else {
9335 if (bgp->vpn_policy[afi].rmap_name[dir])
9336 XFREE(MTYPE_ROUTE_MAP_NAME,
9337 bgp->vpn_policy[afi].rmap_name[dir]);
9338 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9339 bgp->vpn_policy[afi].rmap[dir] = NULL;
9340 }
9341
9342 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9343 }
ddb5b488 9344
585f1adc 9345 return CMD_SUCCESS;
ddb5b488
PZ
9346}
9347
b9c7bc5a
PZ
9348ALIAS (af_route_map_vpn_imexport,
9349 af_no_route_map_vpn_imexport_cmd,
9350 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
9351 NO_STR
9352 "Specify route map\n"
b9c7bc5a
PZ
9353 "Between current address-family and vpn\n"
9354 "For routes leaked from vpn to current address-family\n"
9355 "For routes leaked from current address-family to vpn\n")
9356
bb4f6190 9357DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 9358 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
9359 "Import routes from another VRF\n"
9360 "Vrf routes being filtered\n"
9361 "Specify route map\n"
9362 "name of route-map\n")
9363{
9364 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 9365 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
bb4f6190 9366 afi_t afi;
bb4f6190
DS
9367 struct bgp *bgp_default;
9368
0ca70ba5 9369 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
9370 if (afi == AFI_MAX)
9371 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
9372
9373 bgp_default = bgp_get_default();
9374 if (!bgp_default) {
9375 int32_t ret;
9376 as_t as = bgp->as;
9377
9378 /* Auto-create assuming the same AS */
5d5393b9
DL
9379 ret = bgp_get_vty(&bgp_default, &as, NULL,
9380 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
9381
9382 if (ret) {
9383 vty_out(vty,
9384 "VRF default is not configured as a bgp instance\n");
9385 return CMD_WARNING;
9386 }
9387 }
9388
69b07479 9389 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 9390
ae6a6fb4
DS
9391 if (bgp->vpn_policy[afi].rmap_name[dir])
9392 XFREE(MTYPE_ROUTE_MAP_NAME,
9393 bgp->vpn_policy[afi].rmap_name[dir]);
9394 bgp->vpn_policy[afi].rmap_name[dir] =
9395 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9396 bgp->vpn_policy[afi].rmap[dir] =
9397 route_map_lookup_warn_noexist(vty, rmap_str);
9398 if (!bgp->vpn_policy[afi].rmap[dir])
9399 return CMD_SUCCESS;
9400
9401 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9402 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 9403
69b07479
DS
9404 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9405
bb4f6190
DS
9406 return CMD_SUCCESS;
9407}
9408
ae6a6fb4
DS
9409DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9410 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
9411 NO_STR
9412 "Import routes from another VRF\n"
9413 "Vrf routes being filtered\n"
ae6a6fb4
DS
9414 "Specify route map\n"
9415 "name of route-map\n")
9416{
9417 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 9418 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
ae6a6fb4
DS
9419 afi_t afi;
9420
9421 afi = vpn_policy_getafi(vty, bgp, true);
9422 if (afi == AFI_MAX)
9423 return CMD_WARNING_CONFIG_FAILED;
9424
9425 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9426
9427 if (bgp->vpn_policy[afi].rmap_name[dir])
9428 XFREE(MTYPE_ROUTE_MAP_NAME,
9429 bgp->vpn_policy[afi].rmap_name[dir]);
9430 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9431 bgp->vpn_policy[afi].rmap[dir] = NULL;
9432
9433 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9434 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9435 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9436
9437 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9438
9439 return CMD_SUCCESS;
9440}
bb4f6190 9441
585f1adc
IR
9442DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9443 "[no] import vrf VIEWVRFNAME$import_name",
9444 NO_STR
9445 "Import routes from another VRF\n"
9446 "VRF to import from\n"
9447 "The name of the VRF\n")
12a844a5 9448{
585f1adc
IR
9449 VTY_DECLVAR_CONTEXT(bgp, bgp);
9450 struct listnode *node;
9451 struct bgp *vrf_bgp, *bgp_default;
9452 int32_t ret = 0;
9453 as_t as = bgp->as;
9454 bool remove = false;
9455 int32_t idx = 0;
9456 char *vname;
9457 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
9458 safi_t safi;
9459 afi_t afi;
9460
867f0cca 9461 if (import_name == NULL) {
9462 vty_out(vty, "%% Missing import name\n");
9463 return CMD_WARNING;
9464 }
9465
ae6a6fb4
DS
9466 if (strcmp(import_name, "route-map") == 0) {
9467 vty_out(vty, "%% Must include route-map name\n");
9468 return CMD_WARNING;
9469 }
9470
585f1adc
IR
9471 if (argv_find(argv, argc, "no", &idx))
9472 remove = true;
9473
9474 afi = vpn_policy_getafi(vty, bgp, true);
9475 if (afi == AFI_MAX)
9476 return CMD_WARNING_CONFIG_FAILED;
9477
12a844a5
DS
9478 safi = bgp_node_safi(vty);
9479
585f1adc
IR
9480 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9481 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9482 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9483 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9484 remove ? "unimport" : "import", import_name);
9485 return CMD_WARNING;
9486 }
25679caa 9487
585f1adc
IR
9488 bgp_default = bgp_get_default();
9489 if (!bgp_default) {
9490 /* Auto-create assuming the same AS */
9491 ret = bgp_get_vty(&bgp_default, &as, NULL,
9492 BGP_INSTANCE_TYPE_DEFAULT);
12a844a5 9493
585f1adc
IR
9494 if (ret) {
9495 vty_out(vty,
9496 "VRF default is not configured as a bgp instance\n");
9497 return CMD_WARNING;
9498 }
9499 }
12a844a5 9500
585f1adc
IR
9501 vrf_bgp = bgp_lookup_by_name(import_name);
9502 if (!vrf_bgp) {
9503 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9504 vrf_bgp = bgp_default;
9505 else
9506 /* Auto-create assuming the same AS */
9507 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9508
9509 if (ret) {
9510 vty_out(vty,
9511 "VRF %s is not configured as a bgp instance\n",
9512 import_name);
9513 return CMD_WARNING;
9514 }
9515 }
9516
9517 if (remove) {
9518 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9519 } else {
9520 /* Already importing from "import_vrf"? */
9521 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9522 vname)) {
9523 if (strcmp(vname, import_name) == 0)
9524 return CMD_WARNING;
9525 }
9526
9527 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9528 }
9529
9530 return CMD_SUCCESS;
12a844a5
DS
9531}
9532
b9c7bc5a 9533/* This command is valid only in a bgp vrf instance or the default instance */
585f1adc 9534DEFPY (bgp_imexport_vpn,
b9c7bc5a
PZ
9535 bgp_imexport_vpn_cmd,
9536 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9537 NO_STR
9538 "Import routes to this address-family\n"
9539 "Export routes from this address-family\n"
9540 "to/from default instance VPN RIB\n")
ddb5b488 9541{
585f1adc
IR
9542 VTY_DECLVAR_CONTEXT(bgp, bgp);
9543 int previous_state;
37a87b8f 9544 afi_t afi;
585f1adc
IR
9545 safi_t safi;
9546 int idx = 0;
9547 bool yes = true;
9548 int flag;
9c2fd3fe 9549 enum vpn_policy_direction dir;
585f1adc
IR
9550
9551 if (argv_find(argv, argc, "no", &idx))
9552 yes = false;
9553
9554 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9555 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9556
9557 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9558 return CMD_WARNING_CONFIG_FAILED;
9559 }
ddb5b488 9560
b9c7bc5a
PZ
9561 afi = bgp_node_afi(vty);
9562 safi = bgp_node_safi(vty);
585f1adc
IR
9563 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9564 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9565 return CMD_WARNING_CONFIG_FAILED;
9566 }
ddb5b488 9567
b9c7bc5a 9568 if (!strcmp(direction_str, "import")) {
585f1adc
IR
9569 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9570 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b9c7bc5a 9571 } else if (!strcmp(direction_str, "export")) {
585f1adc
IR
9572 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9573 dir = BGP_VPN_POLICY_DIR_TOVPN;
b9c7bc5a
PZ
9574 } else {
9575 vty_out(vty, "%% unknown direction %s\n", direction_str);
9576 return CMD_WARNING_CONFIG_FAILED;
9577 }
9578
585f1adc 9579 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 9580
585f1adc
IR
9581 if (yes) {
9582 SET_FLAG(bgp->af_flags[afi][safi], flag);
9583 if (!previous_state) {
9584 /* trigger export current vrf */
9585 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9586 }
9587 } else {
9588 if (previous_state) {
9589 /* trigger un-export current vrf */
9590 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9591 }
9592 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9593 }
37a87b8f 9594
1ca2fd11
IR
9595 hook_call(bgp_snmp_init_stats, bgp);
9596
585f1adc 9597 return CMD_SUCCESS;
ddb5b488
PZ
9598}
9599
301ad80a
PG
9600DEFPY (af_routetarget_import,
9601 af_routetarget_import_cmd,
9a659715 9602 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9603 NO_STR
9604 "Specify route target list\n"
9605 "Specify route target list\n"
9a659715
PG
9606 "Specify route target list\n"
9607 "Specify route target list\n"
301ad80a
PG
9608 "Flow-spec redirect type route target\n"
9609 "Import routes to this address-family\n"
9a659715 9610 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9611{
9612 VTY_DECLVAR_CONTEXT(bgp, bgp);
9613 int ret;
9614 struct ecommunity *ecom = NULL;
301ad80a 9615 afi_t afi;
9a659715 9616 int idx = 0, idx_unused = 0;
c6423c31
PG
9617 bool yes = true;
9618 bool rt6 = false;
301ad80a
PG
9619
9620 if (argv_find(argv, argc, "no", &idx))
c6423c31 9621 yes = false;
301ad80a 9622
9a659715
PG
9623 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9624 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9625 rt6 = true;
301ad80a 9626
0ca70ba5 9627 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9628 if (afi == AFI_MAX)
9629 return CMD_WARNING_CONFIG_FAILED;
9630
9a659715
PG
9631 if (rt6 && afi != AFI_IP6)
9632 return CMD_WARNING_CONFIG_FAILED;
9633
301ad80a
PG
9634 if (yes) {
9635 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9636 vty_out(vty, "%% Missing RTLIST\n");
9637 return CMD_WARNING_CONFIG_FAILED;
9638 }
9a659715 9639 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9640 if (ret != CMD_SUCCESS)
9641 return ret;
9642 }
69b07479
DS
9643
9644 if (yes) {
9645 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9646 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9647 .import_redirect_rtlist);
69b07479
DS
9648 bgp->vpn_policy[afi].import_redirect_rtlist =
9649 ecommunity_dup(ecom);
9650 } else {
9651 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9652 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9653 .import_redirect_rtlist);
69b07479 9654 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9655 }
69b07479 9656
301ad80a
PG
9657 if (ecom)
9658 ecommunity_free(&ecom);
9659
9660 return CMD_SUCCESS;
9661}
9662
505e5056 9663DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9664 address_family_ipv4_safi_cmd,
9665 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9666 "Enter Address Family command mode\n"
00e6edb9 9667 BGP_AF_STR
7c40bf39 9668 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9669{
f51bae9c 9670
d62a17ae 9671 if (argc == 3) {
585f1adc
IR
9672 VTY_DECLVAR_CONTEXT(bgp, bgp);
9673 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9674 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9675 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9676 && safi != SAFI_EVPN) {
31947174
MK
9677 vty_out(vty,
9678 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9679 return CMD_WARNING_CONFIG_FAILED;
9680 }
585f1adc
IR
9681 vty->node = bgp_node_type(AFI_IP, safi);
9682 } else
9683 vty->node = BGP_IPV4_NODE;
718e3744 9684
d62a17ae 9685 return CMD_SUCCESS;
718e3744 9686}
9687
505e5056 9688DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9689 address_family_ipv6_safi_cmd,
9690 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9691 "Enter Address Family command mode\n"
00e6edb9 9692 BGP_AF_STR
7c40bf39 9693 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9694{
d62a17ae 9695 if (argc == 3) {
585f1adc
IR
9696 VTY_DECLVAR_CONTEXT(bgp, bgp);
9697 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9698 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9699 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9700 && safi != SAFI_EVPN) {
31947174
MK
9701 vty_out(vty,
9702 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9703 return CMD_WARNING_CONFIG_FAILED;
9704 }
585f1adc
IR
9705 vty->node = bgp_node_type(AFI_IP6, safi);
9706 } else
9707 vty->node = BGP_IPV6_NODE;
25ffbdc1 9708
d62a17ae 9709 return CMD_SUCCESS;
25ffbdc1 9710}
718e3744 9711
d6902373 9712#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9713DEFUN_NOSH (address_family_vpnv4,
718e3744 9714 address_family_vpnv4_cmd,
8334fd5a 9715 "address-family vpnv4 [unicast]",
718e3744 9716 "Enter Address Family command mode\n"
00e6edb9
DA
9717 BGP_AF_STR
9718 BGP_AF_MODIFIER_STR)
718e3744 9719{
d62a17ae 9720 vty->node = BGP_VPNV4_NODE;
9721 return CMD_SUCCESS;
718e3744 9722}
9723
505e5056 9724DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9725 address_family_vpnv6_cmd,
8334fd5a 9726 "address-family vpnv6 [unicast]",
8ecd3266 9727 "Enter Address Family command mode\n"
00e6edb9
DA
9728 BGP_AF_STR
9729 BGP_AF_MODIFIER_STR)
8ecd3266 9730{
d62a17ae 9731 vty->node = BGP_VPNV6_NODE;
9732 return CMD_SUCCESS;
8ecd3266 9733}
64e4a6c5 9734#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9735
505e5056 9736DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9737 address_family_evpn_cmd,
7111c1a0 9738 "address-family l2vpn evpn",
4e0b7b6d 9739 "Enter Address Family command mode\n"
00e6edb9
DA
9740 BGP_AF_STR
9741 BGP_AF_MODIFIER_STR)
4e0b7b6d 9742{
2131d5cf 9743 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9744 vty->node = BGP_EVPN_NODE;
9745 return CMD_SUCCESS;
4e0b7b6d
PG
9746}
9747
bfaab44d
HS
9748DEFUN_NOSH (bgp_segment_routing_srv6,
9749 bgp_segment_routing_srv6_cmd,
9750 "segment-routing srv6",
9751 "Segment-Routing configuration\n"
9752 "Segment-Routing SRv6 configuration\n")
9753{
9754 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 9755 bgp->srv6_enabled = true;
bfaab44d
HS
9756 vty->node = BGP_SRV6_NODE;
9757 return CMD_SUCCESS;
9758}
9759
0249b8b6
HS
9760DEFUN (no_bgp_segment_routing_srv6,
9761 no_bgp_segment_routing_srv6_cmd,
9762 "no segment-routing srv6",
9763 NO_STR
9764 "Segment-Routing configuration\n"
9765 "Segment-Routing SRv6 configuration\n")
9766{
9767 VTY_DECLVAR_CONTEXT(bgp, bgp);
9768
9769 if (strlen(bgp->srv6_locator_name) > 0)
9770 if (bgp_srv6_locator_unset(bgp) < 0)
9771 return CMD_WARNING_CONFIG_FAILED;
9772
9773 bgp->srv6_enabled = false;
9774 return CMD_SUCCESS;
9775}
9776
a0281b2e
HS
9777DEFPY (bgp_srv6_locator,
9778 bgp_srv6_locator_cmd,
9779 "locator NAME$name",
9780 "Specify SRv6 locator\n"
9781 "Specify SRv6 locator\n")
9782{
9783 VTY_DECLVAR_CONTEXT(bgp, bgp);
7de4c885 9784 int ret;
a0281b2e
HS
9785
9786 if (strlen(bgp->srv6_locator_name) > 0
9787 && strcmp(name, bgp->srv6_locator_name) != 0) {
9788 vty_out(vty, "srv6 locator is already configured\n");
9789 return CMD_WARNING_CONFIG_FAILED;
7de4c885
HS
9790 }
9791
9792 snprintf(bgp->srv6_locator_name,
9793 sizeof(bgp->srv6_locator_name), "%s", name);
a0281b2e 9794
7de4c885 9795 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
a0281b2e
HS
9796 if (ret < 0)
9797 return CMD_WARNING_CONFIG_FAILED;
9798
9799 return CMD_SUCCESS;
9800}
9801
0249b8b6
HS
9802DEFPY (no_bgp_srv6_locator,
9803 no_bgp_srv6_locator_cmd,
9804 "no locator NAME$name",
9805 NO_STR
9806 "Specify SRv6 locator\n"
9807 "Specify SRv6 locator\n")
9808{
9809 VTY_DECLVAR_CONTEXT(bgp, bgp);
9810
9811 /* when locator isn't configured, do nothing */
9812 if (strlen(bgp->srv6_locator_name) < 1)
9813 return CMD_SUCCESS;
9814
9815 /* name validation */
9816 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9817 vty_out(vty, "%% No srv6 locator is configured\n");
9818 return CMD_WARNING_CONFIG_FAILED;
9819 }
9820
9821 /* unset locator */
9822 if (bgp_srv6_locator_unset(bgp) < 0)
9823 return CMD_WARNING_CONFIG_FAILED;
9824
9825 return CMD_SUCCESS;
9826}
9827
ea372e81
HS
9828DEFPY (show_bgp_srv6,
9829 show_bgp_srv6_cmd,
9830 "show bgp segment-routing srv6",
9831 SHOW_STR
9832 BGP_STR
9833 "BGP Segment Routing\n"
9834 "BGP Segment Routing SRv6\n")
9835{
9836 struct bgp *bgp;
9837 struct listnode *node;
1c21a234 9838 struct srv6_locator_chunk *chunk;
ea372e81 9839 struct bgp_srv6_function *func;
ea372e81 9840 char buf[256];
ea372e81
HS
9841
9842 bgp = bgp_get_default();
96db4340 9843 if (!bgp)
ea372e81
HS
9844 return CMD_SUCCESS;
9845
9846 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9847 vty_out(vty, "locator_chunks:\n");
dccef127 9848 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
511211bf 9849 vty_out(vty, "- %pFX\n", &chunk->prefix);
dccef127
CS
9850 vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
9851 vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
9852 vty_out(vty, " func-length: %d\n",
9853 chunk->function_bits_length);
9854 vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
9855 }
ea372e81
HS
9856
9857 vty_out(vty, "functions:\n");
9858 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9859 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9860 vty_out(vty, "- sid: %s\n", buf);
9861 vty_out(vty, " locator: %s\n", func->locator_name);
9862 }
9863
9864 vty_out(vty, "bgps:\n");
9865 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9866 vty_out(vty, "- name: %s\n",
9867 bgp->name ? bgp->name : "default");
9868
1830895a
CS
9869 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
9870 bgp->vpn_policy[AFI_IP].tovpn_sid);
9871 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
9872 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9f5d4430 9873 vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
ea372e81
HS
9874 }
9875
9876 return CMD_SUCCESS;
9877}
9878
505e5056 9879DEFUN_NOSH (exit_address_family,
718e3744 9880 exit_address_family_cmd,
9881 "exit-address-family",
9882 "Exit from Address Family configuration mode\n")
9883{
d62a17ae 9884 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9885 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9886 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9887 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9888 || vty->node == BGP_EVPN_NODE
9889 || vty->node == BGP_FLOWSPECV4_NODE
9890 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9891 vty->node = BGP_NODE;
9892 return CMD_SUCCESS;
718e3744 9893}
6b0655a2 9894
8ad7271d 9895/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9896static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9897 const char *ip_str, afi_t afi, safi_t safi,
9898 struct prefix_rd *prd)
9899{
9900 int ret;
9901 struct prefix match;
9bcb3eef
DS
9902 struct bgp_dest *dest;
9903 struct bgp_dest *rm;
d62a17ae 9904 struct bgp *bgp;
9905 struct bgp_table *table;
9906 struct bgp_table *rib;
9907
9908 /* BGP structure lookup. */
9909 if (view_name) {
9910 bgp = bgp_lookup_by_name(view_name);
9911 if (bgp == NULL) {
9912 vty_out(vty, "%% Can't find BGP instance %s\n",
9913 view_name);
9914 return CMD_WARNING;
9915 }
9916 } else {
9917 bgp = bgp_get_default();
9918 if (bgp == NULL) {
9919 vty_out(vty, "%% No BGP process is configured\n");
9920 return CMD_WARNING;
9921 }
9922 }
9923
9924 /* Check IP address argument. */
9925 ret = str2prefix(ip_str, &match);
9926 if (!ret) {
9927 vty_out(vty, "%% address is malformed\n");
9928 return CMD_WARNING;
9929 }
9930
9931 match.family = afi2family(afi);
9932 rib = bgp->rib[afi][safi];
9933
9934 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9935 for (dest = bgp_table_top(rib); dest;
9936 dest = bgp_route_next(dest)) {
9937 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9938
9bcb3eef 9939 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9940 continue;
9941
9bcb3eef 9942 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9943 if (table == NULL)
9944 continue;
9945
4953391b
DA
9946 rm = bgp_node_match(table, &match);
9947 if (rm != NULL) {
b54892e0 9948 const struct prefix *rm_p =
9bcb3eef 9949 bgp_dest_get_prefix(rm);
b54892e0
DS
9950
9951 if (rm_p->prefixlen == match.prefixlen) {
9952 SET_FLAG(rm->flags,
9953 BGP_NODE_USER_CLEAR);
9954 bgp_process(bgp, rm, afi, safi);
d62a17ae 9955 }
9bcb3eef 9956 bgp_dest_unlock_node(rm);
d62a17ae 9957 }
9958 }
9959 } else {
4953391b
DA
9960 dest = bgp_node_match(rib, &match);
9961 if (dest != NULL) {
9bcb3eef 9962 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9963
9bcb3eef
DS
9964 if (dest_p->prefixlen == match.prefixlen) {
9965 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9966 bgp_process(bgp, dest, afi, safi);
d62a17ae 9967 }
9bcb3eef 9968 bgp_dest_unlock_node(dest);
d62a17ae 9969 }
9970 }
9971
9972 return CMD_SUCCESS;
8ad7271d
DS
9973}
9974
b09b5ae0 9975/* one clear bgp command to rule them all */
718e3744 9976DEFUN (clear_ip_bgp_all,
9977 clear_ip_bgp_all_cmd,
3cb14f26 9978 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D$neighbor|X:X::X:X$neighbor|WORD$neighbor|(1-4294967295)|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out|message-stats>]",
718e3744 9979 CLEAR_STR
9980 IP_STR
9981 BGP_STR
838758ac 9982 BGP_INSTANCE_HELP_STR
510afcd6 9983 BGP_AFI_HELP_STR
00e6edb9 9984 BGP_AF_STR
510afcd6 9985 BGP_SAFI_WITH_LABEL_HELP_STR
00e6edb9 9986 BGP_AF_MODIFIER_STR
b09b5ae0 9987 "Clear all peers\n"
453c92f6 9988 "BGP IPv4 neighbor to clear\n"
a80beece 9989 "BGP IPv6 neighbor to clear\n"
838758ac 9990 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9991 "Clear peers with the AS number\n"
9992 "Clear all external peers\n"
718e3744 9993 "Clear all members of peer-group\n"
b09b5ae0 9994 "BGP peer-group name\n"
b09b5ae0
DW
9995 BGP_SOFT_STR
9996 BGP_SOFT_IN_STR
b09b5ae0
DW
9997 BGP_SOFT_OUT_STR
9998 BGP_SOFT_IN_STR
9999 "Push out prefix-list ORF and do inbound soft reconfig\n"
3cb14f26
DS
10000 BGP_SOFT_OUT_STR
10001 "Reset message statistics\n")
718e3744 10002{
d62a17ae 10003 char *vrf = NULL;
10004
dc912615
DS
10005 afi_t afi = AFI_UNSPEC;
10006 safi_t safi = SAFI_UNSPEC;
d62a17ae 10007 enum clear_sort clr_sort = clear_peer;
10008 enum bgp_clear_type clr_type;
10009 char *clr_arg = NULL;
10010
10011 int idx = 0;
10012
10013 /* clear [ip] bgp */
10014 if (argv_find(argv, argc, "ip", &idx))
10015 afi = AFI_IP;
10016
9a8bdf1c
PG
10017 /* [<vrf> VIEWVRFNAME] */
10018 if (argv_find(argv, argc, "vrf", &idx)) {
10019 vrf = argv[idx + 1]->arg;
10020 idx += 2;
10021 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10022 vrf = NULL;
10023 } else if (argv_find(argv, argc, "view", &idx)) {
10024 /* [<view> VIEWVRFNAME] */
d62a17ae 10025 vrf = argv[idx + 1]->arg;
10026 idx += 2;
10027 }
d62a17ae 10028 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10029 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10030 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10031
d7b9898c 10032 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 10033 if (argv_find(argv, argc, "*", &idx)) {
10034 clr_sort = clear_all;
10035 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10036 clr_sort = clear_peer;
10037 clr_arg = argv[idx]->arg;
10038 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10039 clr_sort = clear_peer;
10040 clr_arg = argv[idx]->arg;
10041 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10042 clr_sort = clear_group;
10043 idx++;
10044 clr_arg = argv[idx]->arg;
d7b9898c 10045 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 10046 clr_sort = clear_peer;
10047 clr_arg = argv[idx]->arg;
8fa7d444
DS
10048 } else if (argv_find(argv, argc, "WORD", &idx)) {
10049 clr_sort = clear_peer;
10050 clr_arg = argv[idx]->arg;
d62a17ae 10051 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10052 clr_sort = clear_as;
10053 clr_arg = argv[idx]->arg;
10054 } else if (argv_find(argv, argc, "external", &idx)) {
10055 clr_sort = clear_external;
10056 }
10057
3cb14f26 10058 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
d62a17ae 10059 if (argv_find(argv, argc, "soft", &idx)) {
10060 if (argv_find(argv, argc, "in", &idx)
10061 || argv_find(argv, argc, "out", &idx))
10062 clr_type = strmatch(argv[idx]->text, "in")
10063 ? BGP_CLEAR_SOFT_IN
10064 : BGP_CLEAR_SOFT_OUT;
10065 else
10066 clr_type = BGP_CLEAR_SOFT_BOTH;
10067 } else if (argv_find(argv, argc, "in", &idx)) {
10068 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10069 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10070 : BGP_CLEAR_SOFT_IN;
10071 } else if (argv_find(argv, argc, "out", &idx)) {
10072 clr_type = BGP_CLEAR_SOFT_OUT;
3cb14f26
DS
10073 } else if (argv_find(argv, argc, "message-stats", &idx)) {
10074 clr_type = BGP_CLEAR_MESSAGE_STATS;
d62a17ae 10075 } else
10076 clr_type = BGP_CLEAR_SOFT_NONE;
10077
1ca2fd11 10078 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 10079}
01080f7c 10080
8ad7271d
DS
10081DEFUN (clear_ip_bgp_prefix,
10082 clear_ip_bgp_prefix_cmd,
18c57037 10083 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
10084 CLEAR_STR
10085 IP_STR
10086 BGP_STR
838758ac 10087 BGP_INSTANCE_HELP_STR
8ad7271d 10088 "Clear bestpath and re-advertise\n"
0c7b1b01 10089 "IPv4 prefix\n")
8ad7271d 10090{
d62a17ae 10091 char *vrf = NULL;
10092 char *prefix = NULL;
8ad7271d 10093
d62a17ae 10094 int idx = 0;
01080f7c 10095
d62a17ae 10096 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
10097 if (argv_find(argv, argc, "vrf", &idx)) {
10098 vrf = argv[idx + 1]->arg;
10099 idx += 2;
10100 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10101 vrf = NULL;
10102 } else if (argv_find(argv, argc, "view", &idx)) {
10103 /* [<view> VIEWVRFNAME] */
10104 vrf = argv[idx + 1]->arg;
10105 idx += 2;
10106 }
0c7b1b01 10107
d62a17ae 10108 prefix = argv[argc - 1]->arg;
8ad7271d 10109
d62a17ae 10110 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 10111}
8ad7271d 10112
b09b5ae0
DW
10113DEFUN (clear_bgp_ipv6_safi_prefix,
10114 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 10115 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10116 CLEAR_STR
3a2d747c 10117 IP_STR
718e3744 10118 BGP_STR
00e6edb9 10119 BGP_AF_STR
46f296b4 10120 BGP_SAFI_HELP_STR
b09b5ae0 10121 "Clear bestpath and re-advertise\n"
0c7b1b01 10122 "IPv6 prefix\n")
718e3744 10123{
9b475e76
PG
10124 int idx_safi = 0;
10125 int idx_ipv6_prefix = 0;
10126 safi_t safi = SAFI_UNICAST;
10127 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10128 argv[idx_ipv6_prefix]->arg : NULL;
10129
10130 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 10131 return bgp_clear_prefix(
9b475e76
PG
10132 vty, NULL, prefix, AFI_IP6,
10133 safi, NULL);
838758ac 10134}
01080f7c 10135
b09b5ae0
DW
10136DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10137 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 10138 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10139 CLEAR_STR
3a2d747c 10140 IP_STR
718e3744 10141 BGP_STR
838758ac 10142 BGP_INSTANCE_HELP_STR
00e6edb9 10143 BGP_AF_STR
46f296b4 10144 BGP_SAFI_HELP_STR
b09b5ae0 10145 "Clear bestpath and re-advertise\n"
0c7b1b01 10146 "IPv6 prefix\n")
718e3744 10147{
9b475e76 10148 int idx_safi = 0;
9a8bdf1c 10149 int idx_vrfview = 0;
9b475e76
PG
10150 int idx_ipv6_prefix = 0;
10151 safi_t safi = SAFI_UNICAST;
10152 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10153 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 10154 char *vrfview = NULL;
9b475e76 10155
9a8bdf1c
PG
10156 /* [<view|vrf> VIEWVRFNAME] */
10157 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10158 vrfview = argv[idx_vrfview + 1]->arg;
10159 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10160 vrfview = NULL;
10161 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10162 /* [<view> VIEWVRFNAME] */
10163 vrfview = argv[idx_vrfview + 1]->arg;
10164 }
9b475e76
PG
10165 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10166
d62a17ae 10167 return bgp_clear_prefix(
9b475e76
PG
10168 vty, vrfview, prefix,
10169 AFI_IP6, safi, NULL);
718e3744 10170}
10171
b09b5ae0
DW
10172DEFUN (show_bgp_views,
10173 show_bgp_views_cmd,
d6e3c605 10174 "show [ip] bgp views",
b09b5ae0 10175 SHOW_STR
d6e3c605 10176 IP_STR
01080f7c 10177 BGP_STR
b09b5ae0 10178 "Show the defined BGP views\n")
01080f7c 10179{
d62a17ae 10180 struct list *inst = bm->bgp;
10181 struct listnode *node;
10182 struct bgp *bgp;
01080f7c 10183
d62a17ae 10184 vty_out(vty, "Defined BGP views:\n");
10185 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10186 /* Skip VRFs. */
10187 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10188 continue;
10189 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10190 bgp->as);
10191 }
e52702f2 10192
d62a17ae 10193 return CMD_SUCCESS;
e0081f70
ML
10194}
10195
8386ac43 10196DEFUN (show_bgp_vrfs,
10197 show_bgp_vrfs_cmd,
d6e3c605 10198 "show [ip] bgp vrfs [json]",
8386ac43 10199 SHOW_STR
d6e3c605 10200 IP_STR
8386ac43 10201 BGP_STR
10202 "Show BGP VRFs\n"
9973d184 10203 JSON_STR)
8386ac43 10204{
fe1dc5a3 10205 char buf[ETHER_ADDR_STRLEN];
d62a17ae 10206 struct list *inst = bm->bgp;
10207 struct listnode *node;
10208 struct bgp *bgp;
9f049418 10209 bool uj = use_json(argc, argv);
d62a17ae 10210 json_object *json = NULL;
10211 json_object *json_vrfs = NULL;
10212 int count = 0;
d62a17ae 10213
d62a17ae 10214 if (uj) {
10215 json = json_object_new_object();
10216 json_vrfs = json_object_new_object();
10217 }
10218
10219 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10220 const char *name, *type;
10221 struct peer *peer;
7fe96307 10222 struct listnode *node2, *nnode2;
d62a17ae 10223 int peers_cfg, peers_estb;
10224 json_object *json_vrf = NULL;
d62a17ae 10225
10226 /* Skip Views. */
10227 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10228 continue;
10229
10230 count++;
efb4077a 10231 if (!uj && count == 1) {
fe1dc5a3 10232 vty_out(vty,
efb4077a 10233 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 10234 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
10235 "#PeersEstb", "Name");
10236 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10237 "L3-VNI", "RouterMAC", "Interface");
10238 }
d62a17ae 10239
10240 peers_cfg = peers_estb = 0;
10241 if (uj)
10242 json_vrf = json_object_new_object();
10243
10244
7fe96307 10245 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 10246 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10247 continue;
10248 peers_cfg++;
feb17238 10249 if (peer_established(peer))
d62a17ae 10250 peers_estb++;
10251 }
10252
10253 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 10254 name = VRF_DEFAULT_NAME;
d62a17ae 10255 type = "DFLT";
10256 } else {
10257 name = bgp->name;
10258 type = "VRF";
10259 }
10260
a8bf7d9c 10261
d62a17ae 10262 if (uj) {
a4d82a8a
PZ
10263 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10264 ? -1
10265 : (int64_t)bgp->vrf_id;
23d0a753
DA
10266 char buf[BUFSIZ] = {0};
10267
d62a17ae 10268 json_object_string_add(json_vrf, "type", type);
10269 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
c949c771
DA
10270 json_object_string_addf(json_vrf, "routerId", "%pI4",
10271 &bgp->router_id);
d62a17ae 10272 json_object_int_add(json_vrf, "numConfiguredPeers",
10273 peers_cfg);
10274 json_object_int_add(json_vrf, "numEstablishedPeers",
10275 peers_estb);
10276
fe1dc5a3 10277 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
10278 json_object_string_add(
10279 json_vrf, "rmac",
10280 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
10281 json_object_string_add(json_vrf, "interface",
10282 ifindex2ifname(bgp->l3vni_svi_ifindex,
10283 bgp->vrf_id));
d62a17ae 10284 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 10285 } else {
23d0a753 10286 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
10287 type,
10288 bgp->vrf_id == VRF_UNKNOWN ? -1
10289 : (int)bgp->vrf_id,
23d0a753 10290 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
10291 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10292 bgp->l3vni,
10293 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10294 ifindex2ifname(bgp->l3vni_svi_ifindex,
10295 bgp->vrf_id));
10296 }
d62a17ae 10297 }
10298
10299 if (uj) {
10300 json_object_object_add(json, "vrfs", json_vrfs);
10301
10302 json_object_int_add(json, "totalVrfs", count);
10303
75eeda93 10304 vty_json(vty, json);
d62a17ae 10305 } else {
10306 if (count)
10307 vty_out(vty,
10308 "\nTotal number of VRFs (including default): %d\n",
10309 count);
10310 }
10311
10312 return CMD_SUCCESS;
8386ac43 10313}
10314
48ecf8f5
DS
10315DEFUN (show_bgp_mac_hash,
10316 show_bgp_mac_hash_cmd,
10317 "show bgp mac hash",
10318 SHOW_STR
10319 BGP_STR
10320 "Mac Address\n"
10321 "Mac Address database\n")
10322{
10323 bgp_mac_dump_table(vty);
10324
10325 return CMD_SUCCESS;
10326}
acf71666 10327
e3b78da8 10328static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 10329{
0291c246 10330 struct vty *vty = (struct vty *)args;
e3b78da8 10331 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 10332
23d0a753 10333 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
10334}
10335
10336static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10337{
10338 vty_out(vty, "self nexthop database:\n");
af97a18b 10339 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
10340
10341 vty_out(vty, "Tunnel-ip database:\n");
10342 hash_iterate(bgp->tip_hash,
e3b78da8 10343 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
10344 vty);
10345}
10346
15c81ca4
DS
10347DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10348 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10349 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
10350 "martian next-hops\n"
10351 "martian next-hop database\n")
acf71666 10352{
0291c246 10353 struct bgp *bgp = NULL;
15c81ca4 10354 int idx = 0;
9a8bdf1c
PG
10355 char *name = NULL;
10356
10357 /* [<vrf> VIEWVRFNAME] */
10358 if (argv_find(argv, argc, "vrf", &idx)) {
10359 name = argv[idx + 1]->arg;
10360 if (name && strmatch(name, VRF_DEFAULT_NAME))
10361 name = NULL;
10362 } else if (argv_find(argv, argc, "view", &idx))
10363 /* [<view> VIEWVRFNAME] */
10364 name = argv[idx + 1]->arg;
10365 if (name)
10366 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
10367 else
10368 bgp = bgp_get_default();
acf71666 10369
acf71666
MK
10370 if (!bgp) {
10371 vty_out(vty, "%% No BGP process is configured\n");
10372 return CMD_WARNING;
10373 }
10374 bgp_show_martian_nexthops(vty, bgp);
10375
10376 return CMD_SUCCESS;
10377}
10378
f412b39a 10379DEFUN (show_bgp_memory,
4bf6a362 10380 show_bgp_memory_cmd,
7fa12b13 10381 "show [ip] bgp memory",
4bf6a362 10382 SHOW_STR
3a2d747c 10383 IP_STR
4bf6a362
PJ
10384 BGP_STR
10385 "Global BGP memory statistics\n")
10386{
d62a17ae 10387 char memstrbuf[MTYPE_MEMSTR_LEN];
10388 unsigned long count;
10389
10390 /* RIB related usage stats */
10391 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10392 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10393 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 10394 count * sizeof(struct bgp_dest)));
d62a17ae 10395
10396 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10397 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10398 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 10399 count * sizeof(struct bgp_path_info)));
d62a17ae 10400 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10401 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10402 count,
4b7e6066
DS
10403 mtype_memstr(
10404 memstrbuf, sizeof(memstrbuf),
10405 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 10406
10407 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10408 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10409 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10410 count * sizeof(struct bgp_static)));
10411
10412 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10413 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10414 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10415 count * sizeof(struct bpacket)));
10416
10417 /* Adj-In/Out */
10418 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10419 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10420 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10421 count * sizeof(struct bgp_adj_in)));
10422 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10423 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10424 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10425 count * sizeof(struct bgp_adj_out)));
10426
10427 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10428 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10429 count,
10430 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10431 count * sizeof(struct bgp_nexthop_cache)));
10432
10433 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10434 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10435 count,
10436 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10437 count * sizeof(struct bgp_damp_info)));
10438
10439 /* Attributes */
10440 count = attr_count();
10441 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10442 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10443 count * sizeof(struct attr)));
10444
10445 if ((count = attr_unknown_count()))
10446 vty_out(vty, "%ld unknown attributes\n", count);
10447
10448 /* AS_PATH attributes */
10449 count = aspath_count();
10450 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10451 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10452 count * sizeof(struct aspath)));
10453
10454 count = mtype_stats_alloc(MTYPE_AS_SEG);
10455 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10456 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10457 count * sizeof(struct assegment)));
10458
10459 /* Other attributes */
10460 if ((count = community_count()))
10461 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10462 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10463 count * sizeof(struct community)));
d62a17ae 10464 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
145f7619
DA
10465 vty_out(vty,
10466 "%ld BGP ext-community entries, using %s of memory\n",
10467 count,
10468 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10469 count * sizeof(struct ecommunity)));
d62a17ae 10470 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10471 vty_out(vty,
10472 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10473 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10474 count * sizeof(struct lcommunity)));
d62a17ae 10475
10476 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10477 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10478 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10479 count * sizeof(struct cluster_list)));
10480
10481 /* Peer related usage */
10482 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10483 vty_out(vty, "%ld peers, using %s of memory\n", count,
10484 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10485 count * sizeof(struct peer)));
10486
10487 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10488 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10489 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10490 count * sizeof(struct peer_group)));
10491
10492 /* Other */
d62a17ae 10493 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10494 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10495 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10496 count * sizeof(regex_t)));
d62a17ae 10497 return CMD_SUCCESS;
4bf6a362 10498}
fee0f4c6 10499
57a9c8a8
DS
10500static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10501{
10502 json_object *bestpath = json_object_new_object();
10503
892fedb6 10504 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10505 json_object_string_add(bestpath, "asPath", "ignore");
10506
892fedb6 10507 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10508 json_object_string_add(bestpath, "asPath", "confed");
10509
892fedb6
DA
10510 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10511 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10512 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10513 "as-set");
10514 else
a4d82a8a 10515 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10516 "true");
10517 } else
a4d82a8a 10518 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10519
ee88563a
JM
10520 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10521 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10522
892fedb6 10523 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10524 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10525 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10526 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10527 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10528 json_object_string_add(bestpath, "med", "confed");
892fedb6 10529 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10530 json_object_string_add(bestpath, "med",
10531 "missing-as-worst");
10532 else
10533 json_object_string_add(bestpath, "med", "true");
10534 }
10535
10536 json_object_object_add(json, "bestPath", bestpath);
10537}
10538
3577f1c5
DD
10539/* Print the error code/subcode for why the peer is down */
10540static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10541 json_object *json_peer, bool use_json)
10542{
10543 const char *code_str;
10544 const char *subcode_str;
10545
10546 if (use_json) {
10547 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10548 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10549 char errorcodesubcode_hexstr[5];
10550 char errorcodesubcode_str[256];
10551
10552 code_str = bgp_notify_code_str(peer->notify.code);
10553 subcode_str = bgp_notify_subcode_str(
10554 peer->notify.code,
10555 peer->notify.subcode);
10556
772270f3
QY
10557 snprintf(errorcodesubcode_hexstr,
10558 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10559 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10560 json_object_string_add(json_peer,
10561 "lastErrorCodeSubcode",
10562 errorcodesubcode_hexstr);
10563 snprintf(errorcodesubcode_str, 255, "%s%s",
10564 code_str, subcode_str);
10565 json_object_string_add(json_peer,
10566 "lastNotificationReason",
10567 errorcodesubcode_str);
eea685b6
DA
10568 json_object_boolean_add(json_peer,
10569 "lastNotificationHardReset",
10570 peer->notify.hard_reset);
3577f1c5
DD
10571 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10572 && peer->notify.code == BGP_NOTIFY_CEASE
10573 && (peer->notify.subcode
10574 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10575 || peer->notify.subcode
10576 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10577 && peer->notify.length) {
10578 char msgbuf[1024];
10579 const char *msg_str;
10580
10581 msg_str = bgp_notify_admin_message(
10582 msgbuf, sizeof(msgbuf),
10583 (uint8_t *)peer->notify.data,
10584 peer->notify.length);
10585 if (msg_str)
10586 json_object_string_add(
10587 json_peer,
10588 "lastShutdownDescription",
10589 msg_str);
10590 }
10591
c258527b 10592 }
3577f1c5
DD
10593 json_object_string_add(json_peer, "lastResetDueTo",
10594 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10595 json_object_int_add(json_peer, "lastResetCode",
10596 peer->last_reset);
3577f1c5
DD
10597 } else {
10598 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10599 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10600 code_str = bgp_notify_code_str(peer->notify.code);
10601 subcode_str =
10602 bgp_notify_subcode_str(peer->notify.code,
10603 peer->notify.subcode);
eea685b6 10604 vty_out(vty, " Notification %s (%s%s%s)\n",
3577f1c5 10605 peer->last_reset == PEER_DOWN_NOTIFY_SEND
eea685b6
DA
10606 ? "sent"
10607 : "received",
10608 code_str, subcode_str,
10609 peer->notify.hard_reset
10610 ? bgp_notify_subcode_str(
10611 BGP_NOTIFY_CEASE,
10612 BGP_NOTIFY_CEASE_HARD_RESET)
10613 : "");
3577f1c5 10614 } else {
e91c24c8 10615 vty_out(vty, " %s\n",
3577f1c5
DD
10616 peer_down_str[(int)peer->last_reset]);
10617 }
10618 }
10619}
10620
10621static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10622 safi_t safi)
10623{
feb17238 10624 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
3577f1c5
DD
10625}
10626
10627static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10628 struct peer *peer, json_object *json_peer,
10629 int max_neighbor_width, bool use_json)
10630{
10631 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10632 int len;
10633
10634 if (use_json) {
10635 if (peer_dynamic_neighbor(peer))
10636 json_object_boolean_true_add(json_peer,
10637 "dynamicPeer");
10638 if (peer->hostname)
10639 json_object_string_add(json_peer, "hostname",
10640 peer->hostname);
10641
10642 if (peer->domainname)
10643 json_object_string_add(json_peer, "domainname",
10644 peer->domainname);
10645 json_object_int_add(json_peer, "connectionsEstablished",
10646 peer->established);
10647 json_object_int_add(json_peer, "connectionsDropped",
10648 peer->dropped);
10649 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10650 use_json, json_peer);
feb17238 10651 if (peer_established(peer))
3577f1c5
DD
10652 json_object_string_add(json_peer, "lastResetDueTo",
10653 "AFI/SAFI Not Negotiated");
10654 else
10655 bgp_show_peer_reset(NULL, peer, json_peer, true);
10656 } else {
10657 dn_flag[1] = '\0';
10658 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10659 if (peer->hostname
892fedb6 10660 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10661 len = vty_out(vty, "%s%s(%s)", dn_flag,
10662 peer->hostname, peer->host);
10663 else
10664 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10665
10666 /* pad the neighbor column with spaces */
10667 if (len < max_neighbor_width)
10668 vty_out(vty, "%*s", max_neighbor_width - len,
10669 " ");
e91c24c8 10670 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10671 peer->dropped,
10672 peer_uptime(peer->uptime, timebuf,
10673 BGP_UPTIME_LEN, 0, NULL));
feb17238 10674 if (peer_established(peer))
3577f1c5
DD
10675 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10676 else
10677 bgp_show_peer_reset(vty, peer, NULL,
10678 false);
10679 }
10680}
c258527b 10681
565e9ddd 10682/* Strip peer's description to the given size. */
cb75bb31
DA
10683static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10684{
10685 static char stripped[BUFSIZ];
64541ffa
FD
10686 uint32_t i = 0;
10687 uint32_t last_space = 0;
cb75bb31 10688
64541ffa
FD
10689 while (i < size) {
10690 if (*(desc + i) == 0) {
10691 stripped[i] = '\0';
10692 return stripped;
10693 }
10694 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10695 last_space = i;
10696 stripped[i] = *(desc + i);
10697 i++;
10698 }
10699
10700 if (last_space > size)
10701 stripped[size + 1] = '\0';
10702 else
10703 stripped[last_space] = '\0';
cb75bb31
DA
10704
10705 return stripped;
10706}
3577f1c5 10707
8c1d4cd5
LS
10708/* Determine whether var peer should be filtered out of the summary. */
10709static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10710 struct peer *fpeer, int as_type,
10711 as_t as)
10712{
10713
10714 /* filter neighbor XXXX */
10715 if (fpeer && fpeer != peer)
10716 return true;
10717
10718 /* filter remote-as (internal|external) */
10719 if (as_type != AS_UNSPECIFIED) {
10720 if (peer->as_type == AS_SPECIFIED) {
10721 if (as_type == AS_INTERNAL) {
10722 if (peer->as != peer->local_as)
10723 return true;
10724 } else if (peer->as == peer->local_as)
10725 return true;
10726 } else if (as_type != peer->as_type)
10727 return true;
10728 } else if (as && as != peer->as) /* filter remote-as XXX */
10729 return true;
10730
10731 return false;
10732}
10733
565e9ddd
DA
10734/* Show BGP peer's summary information.
10735 *
10736 * Peer's description is stripped according to if `wide` option is given
10737 * or not.
10738 *
10739 * When adding new columns to `show bgp summary` output, please make
10740 * sure `Desc` is the lastest column to show because it can contain
10741 * whitespaces and the whole output will be tricky.
10742 */
d62a17ae 10743static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 10744 struct peer *fpeer, int as_type, as_t as,
96c81f66 10745 uint16_t show_flags)
d62a17ae 10746{
10747 struct peer *peer;
10748 struct listnode *node, *nnode;
10749 unsigned int count = 0, dn_count = 0;
10750 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10751 char neighbor_buf[VTY_BUFSIZ];
10752 int neighbor_col_default_width = 16;
3577f1c5 10753 int len, failed_count = 0;
ce1944f0 10754 unsigned int filtered_count = 0;
d62a17ae 10755 int max_neighbor_width = 0;
10756 int pfx_rcd_safi;
3c13337d 10757 json_object *json = NULL;
d62a17ae 10758 json_object *json_peer = NULL;
10759 json_object *json_peers = NULL;
50e05855 10760 struct peer_af *paf;
d3ada366 10761 struct bgp_filter *filter;
85eeb029
DA
10762 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10763 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10764 bool show_established =
10765 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10766 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
96c81f66 10767 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
d62a17ae 10768
10769 /* labeled-unicast routes are installed in the unicast table so in order
10770 * to
10771 * display the correct PfxRcd value we must look at SAFI_UNICAST
10772 */
3577f1c5 10773
d62a17ae 10774 if (safi == SAFI_LABELED_UNICAST)
10775 pfx_rcd_safi = SAFI_UNICAST;
10776 else
10777 pfx_rcd_safi = safi;
10778
10779 if (use_json) {
3c13337d 10780 json = json_object_new_object();
d62a17ae 10781 json_peers = json_object_new_object();
3577f1c5 10782 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10783 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10784 as_type, as)) {
ce1944f0 10785 filtered_count++;
8c1d4cd5
LS
10786 count++;
10787 continue;
10788 }
10789
3577f1c5
DD
10790 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10791 continue;
10792
10793 if (peer->afc[afi][safi]) {
10794 /* See if we have at least a single failed peer */
10795 if (bgp_has_peer_failed(peer, afi, safi))
10796 failed_count++;
10797 count++;
10798 }
10799 if (peer_dynamic_neighbor(peer))
10800 dn_count++;
10801 }
c258527b 10802
d62a17ae 10803 } else {
10804 /* Loop over all neighbors that will be displayed to determine
10805 * how many
10806 * characters are needed for the Neighbor column
10807 */
10808 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10809 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10810 as_type, as)) {
ce1944f0 10811 filtered_count++;
8c1d4cd5
LS
10812 count++;
10813 continue;
10814 }
10815
d62a17ae 10816 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10817 continue;
10818
10819 if (peer->afc[afi][safi]) {
10820 memset(dn_flag, '\0', sizeof(dn_flag));
10821 if (peer_dynamic_neighbor(peer))
10822 dn_flag[0] = '*';
10823
10824 if (peer->hostname
892fedb6
DA
10825 && CHECK_FLAG(bgp->flags,
10826 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10827 snprintf(neighbor_buf,
10828 sizeof(neighbor_buf),
10829 "%s%s(%s) ", dn_flag,
10830 peer->hostname, peer->host);
d62a17ae 10831 else
772270f3
QY
10832 snprintf(neighbor_buf,
10833 sizeof(neighbor_buf), "%s%s ",
10834 dn_flag, peer->host);
d62a17ae 10835
10836 len = strlen(neighbor_buf);
10837
10838 if (len > max_neighbor_width)
10839 max_neighbor_width = len;
c258527b 10840
3577f1c5
DD
10841 /* See if we have at least a single failed peer */
10842 if (bgp_has_peer_failed(peer, afi, safi))
10843 failed_count++;
10844 count++;
d62a17ae 10845 }
10846 }
f933309e 10847
d62a17ae 10848 /* Originally we displayed the Neighbor column as 16
10849 * characters wide so make that the default
10850 */
10851 if (max_neighbor_width < neighbor_col_default_width)
10852 max_neighbor_width = neighbor_col_default_width;
10853 }
f933309e 10854
3577f1c5
DD
10855 if (show_failed && !failed_count) {
10856 if (use_json) {
10857 json_object_int_add(json, "failedPeersCount", 0);
10858 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10859 json_object_int_add(json, "totalPeers", count);
3577f1c5 10860
75eeda93 10861 vty_json(vty, json);
3577f1c5
DD
10862 } else {
10863 vty_out(vty, "%% No failed BGP neighbors found\n");
3577f1c5
DD
10864 }
10865 return CMD_SUCCESS;
10866 }
c258527b 10867
3577f1c5 10868 count = 0; /* Reset the value as its used again */
ce1944f0 10869 filtered_count = 0;
800867d8 10870 dn_count = 0;
d62a17ae 10871 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10872 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10873 continue;
10874
ea47320b
DL
10875 if (!peer->afc[afi][safi])
10876 continue;
d62a17ae 10877
ea47320b
DL
10878 if (!count) {
10879 unsigned long ents;
10880 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10881 int64_t vrf_id_ui;
d62a17ae 10882
a4d82a8a
PZ
10883 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10884 ? -1
10885 : (int64_t)bgp->vrf_id;
ea47320b
DL
10886
10887 /* Usage summary and header */
10888 if (use_json) {
c949c771
DA
10889 json_object_string_addf(json, "routerId",
10890 "%pI4",
10891 &bgp->router_id);
60466a63
QY
10892 json_object_int_add(json, "as", bgp->as);
10893 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10894 json_object_string_add(
10895 json, "vrfName",
10896 (bgp->inst_type
10897 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10898 ? VRF_DEFAULT_NAME
ea47320b
DL
10899 : bgp->name);
10900 } else {
10901 vty_out(vty,
23d0a753
DA
10902 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10903 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10904 bgp->vrf_id == VRF_UNKNOWN
10905 ? -1
10906 : (int)bgp->vrf_id);
ea47320b
DL
10907 vty_out(vty, "\n");
10908 }
d62a17ae 10909
ea47320b 10910 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10911 if (use_json) {
ea47320b 10912 json_object_int_add(
60466a63 10913 json, "updateDelayLimit",
ea47320b 10914 bgp->v_update_delay);
d62a17ae 10915
ea47320b
DL
10916 if (bgp->v_update_delay
10917 != bgp->v_establish_wait)
d62a17ae 10918 json_object_int_add(
10919 json,
ea47320b
DL
10920 "updateDelayEstablishWait",
10921 bgp->v_establish_wait);
d62a17ae 10922
60466a63 10923 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10924 json_object_string_add(
10925 json,
10926 "updateDelayFirstNeighbor",
10927 bgp->update_delay_begin_time);
10928 json_object_boolean_true_add(
10929 json,
10930 "updateDelayInProgress");
10931 } else {
10932 if (bgp->update_delay_over) {
d62a17ae 10933 json_object_string_add(
10934 json,
10935 "updateDelayFirstNeighbor",
10936 bgp->update_delay_begin_time);
ea47320b 10937 json_object_string_add(
d62a17ae 10938 json,
ea47320b
DL
10939 "updateDelayBestpathResumed",
10940 bgp->update_delay_end_time);
10941 json_object_string_add(
d62a17ae 10942 json,
ea47320b
DL
10943 "updateDelayZebraUpdateResume",
10944 bgp->update_delay_zebra_resume_time);
10945 json_object_string_add(
10946 json,
10947 "updateDelayPeerUpdateResume",
10948 bgp->update_delay_peers_resume_time);
d62a17ae 10949 }
ea47320b
DL
10950 }
10951 } else {
10952 vty_out(vty,
10953 "Read-only mode update-delay limit: %d seconds\n",
10954 bgp->v_update_delay);
10955 if (bgp->v_update_delay
10956 != bgp->v_establish_wait)
d62a17ae 10957 vty_out(vty,
ea47320b
DL
10958 " Establish wait: %d seconds\n",
10959 bgp->v_establish_wait);
d62a17ae 10960
60466a63 10961 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10962 vty_out(vty,
10963 " First neighbor established: %s\n",
10964 bgp->update_delay_begin_time);
10965 vty_out(vty,
10966 " Delay in progress\n");
10967 } else {
10968 if (bgp->update_delay_over) {
d62a17ae 10969 vty_out(vty,
10970 " First neighbor established: %s\n",
10971 bgp->update_delay_begin_time);
10972 vty_out(vty,
ea47320b
DL
10973 " Best-paths resumed: %s\n",
10974 bgp->update_delay_end_time);
10975 vty_out(vty,
10976 " zebra update resumed: %s\n",
10977 bgp->update_delay_zebra_resume_time);
10978 vty_out(vty,
10979 " peers update resumed: %s\n",
10980 bgp->update_delay_peers_resume_time);
d62a17ae 10981 }
10982 }
10983 }
ea47320b 10984 }
d62a17ae 10985
ea47320b
DL
10986 if (use_json) {
10987 if (bgp_maxmed_onstartup_configured(bgp)
10988 && bgp->maxmed_active)
10989 json_object_boolean_true_add(
60466a63 10990 json, "maxMedOnStartup");
ea47320b
DL
10991 if (bgp->v_maxmed_admin)
10992 json_object_boolean_true_add(
60466a63 10993 json, "maxMedAdministrative");
d62a17ae 10994
ea47320b
DL
10995 json_object_int_add(
10996 json, "tableVersion",
60466a63 10997 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 10998
60466a63
QY
10999 ents = bgp_table_count(bgp->rib[afi][safi]);
11000 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
11001 json_object_int_add(
11002 json, "ribMemory",
9bcb3eef 11003 ents * sizeof(struct bgp_dest));
d62a17ae 11004
210ec2a0 11005 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
11006 json_object_int_add(json, "peerCount", ents);
11007 json_object_int_add(json, "peerMemory",
11008 ents * sizeof(struct peer));
d62a17ae 11009
ea47320b
DL
11010 if ((ents = listcount(bgp->group))) {
11011 json_object_int_add(
60466a63 11012 json, "peerGroupCount", ents);
ea47320b
DL
11013 json_object_int_add(
11014 json, "peerGroupMemory",
996c9314
LB
11015 ents * sizeof(struct
11016 peer_group));
ea47320b 11017 }
d62a17ae 11018
ea47320b
DL
11019 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11020 BGP_CONFIG_DAMPENING))
11021 json_object_boolean_true_add(
60466a63 11022 json, "dampeningEnabled");
ea47320b 11023 } else {
96c81f66
LS
11024 if (!show_terse) {
11025 if (bgp_maxmed_onstartup_configured(bgp)
11026 && bgp->maxmed_active)
11027 vty_out(vty,
11028 "Max-med on-startup active\n");
11029 if (bgp->v_maxmed_admin)
11030 vty_out(vty,
11031 "Max-med administrative active\n");
d62a17ae 11032
96c81f66
LS
11033 vty_out(vty,
11034 "BGP table version %" PRIu64
11035 "\n",
11036 bgp_table_version(
11037 bgp->rib[afi][safi]));
ea47320b 11038
96c81f66
LS
11039 ents = bgp_table_count(
11040 bgp->rib[afi][safi]);
d62a17ae 11041 vty_out(vty,
96c81f66 11042 "RIB entries %ld, using %s of memory\n",
d62a17ae 11043 ents,
11044 mtype_memstr(
11045 memstrbuf,
11046 sizeof(memstrbuf),
96c81f66
LS
11047 ents
11048 * sizeof(
11049 struct
11050 bgp_dest)));
d62a17ae 11051
96c81f66
LS
11052 /* Peer related usage */
11053 ents = bgp->af_peer_count[afi][safi];
11054 vty_out(vty,
11055 "Peers %ld, using %s of memory\n",
11056 ents,
11057 mtype_memstr(
11058 memstrbuf,
11059 sizeof(memstrbuf),
11060 ents
11061 * sizeof(
11062 struct
11063 peer)));
d62a17ae 11064
96c81f66
LS
11065 if ((ents = listcount(bgp->group)))
11066 vty_out(vty,
11067 "Peer groups %ld, using %s of memory\n",
11068 ents,
11069 mtype_memstr(
11070 memstrbuf,
11071 sizeof(memstrbuf),
11072 ents
11073 * sizeof(
11074 struct
11075 peer_group)));
11076
11077 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11078 BGP_CONFIG_DAMPENING))
11079 vty_out(vty,
11080 "Dampening enabled.\n");
11081 }
11082 if (show_failed) {
11083 vty_out(vty, "\n");
11084
11085 /* Subtract 8 here because 'Neighbor' is
11086 * 8 characters */
11087 vty_out(vty, "Neighbor");
11088 vty_out(vty, "%*s",
11089 max_neighbor_width - 8, " ");
85eeb029
DA
11090 vty_out(vty,
11091 BGP_SHOW_SUMMARY_HEADER_FAILED);
96c81f66 11092 }
d62a17ae 11093 }
ea47320b 11094 }
d62a17ae 11095
d55811cc 11096 paf = peer_af_find(peer, afi, safi);
d3ada366 11097 filter = &peer->filter[afi][safi];
db92d226 11098
ea47320b 11099 count++;
3577f1c5
DD
11100 /* Works for both failed & successful cases */
11101 if (peer_dynamic_neighbor(peer))
11102 dn_count++;
d62a17ae 11103
ea47320b 11104 if (use_json) {
3577f1c5 11105 json_peer = NULL;
8c1d4cd5 11106 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
11107 as_type, as)) {
11108 filtered_count++;
8c1d4cd5 11109 continue;
ce1944f0 11110 }
3577f1c5
DD
11111 if (show_failed &&
11112 bgp_has_peer_failed(peer, afi, safi)) {
11113 json_peer = json_object_new_object();
11114 bgp_show_failed_summary(vty, bgp, peer,
11115 json_peer, 0, use_json);
11116 } else if (!show_failed) {
10b49f14 11117 if (show_established
ce1944f0
LS
11118 && bgp_has_peer_failed(peer, afi, safi)) {
11119 filtered_count++;
10b49f14 11120 continue;
ce1944f0 11121 }
10b49f14 11122
3577f1c5
DD
11123 json_peer = json_object_new_object();
11124 if (peer_dynamic_neighbor(peer)) {
11125 json_object_boolean_true_add(json_peer,
11126 "dynamicPeer");
11127 }
d62a17ae 11128
3577f1c5
DD
11129 if (peer->hostname)
11130 json_object_string_add(json_peer, "hostname",
11131 peer->hostname);
11132
11133 if (peer->domainname)
11134 json_object_string_add(json_peer, "domainname",
11135 peer->domainname);
11136
11137 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
11138 json_object_int_add(
11139 json_peer, "localAs",
11140 peer->change_local_as
11141 ? peer->change_local_as
11142 : peer->local_as);
3577f1c5
DD
11143 json_object_int_add(json_peer, "version", 4);
11144 json_object_int_add(json_peer, "msgRcvd",
11145 PEER_TOTAL_RX(peer));
11146 json_object_int_add(json_peer, "msgSent",
11147 PEER_TOTAL_TX(peer));
11148
43aa5965
QY
11149 atomic_size_t outq_count, inq_count;
11150 outq_count = atomic_load_explicit(
11151 &peer->obuf->count,
11152 memory_order_relaxed);
11153 inq_count = atomic_load_explicit(
11154 &peer->ibuf->count,
11155 memory_order_relaxed);
11156
3577f1c5
DD
11157 json_object_int_add(json_peer, "tableVersion",
11158 peer->version[afi][safi]);
11159 json_object_int_add(json_peer, "outq",
43aa5965
QY
11160 outq_count);
11161 json_object_int_add(json_peer, "inq",
11162 inq_count);
3577f1c5
DD
11163 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11164 use_json, json_peer);
11165
3577f1c5
DD
11166 json_object_int_add(json_peer, "pfxRcd",
11167 peer->pcount[afi][pfx_rcd_safi]);
11168
3577f1c5 11169 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
11170 json_object_int_add(
11171 json_peer, "pfxSnt",
11172 (PAF_SUBGRP(paf))->scount);
11173 else
11174 json_object_int_add(json_peer, "pfxSnt",
11175 0);
0e1f8ab5
DA
11176
11177 /* BGP FSM state */
cb9196e7 11178 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
11179 || CHECK_FLAG(peer->bgp->flags,
11180 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
11181 json_object_string_add(json_peer,
11182 "state",
3577f1c5
DD
11183 "Idle (Admin)");
11184 else if (peer->afc_recv[afi][safi])
11185 json_object_string_add(
0e1f8ab5
DA
11186 json_peer, "state",
11187 lookup_msg(bgp_status_msg,
11188 peer->status, NULL));
11189 else if (CHECK_FLAG(
11190 peer->sflags,
11191 PEER_STATUS_PREFIX_OVERFLOW))
11192 json_object_string_add(json_peer,
11193 "state",
3577f1c5
DD
11194 "Idle (PfxCt)");
11195 else
11196 json_object_string_add(
0e1f8ab5
DA
11197 json_peer, "state",
11198 lookup_msg(bgp_status_msg,
11199 peer->status, NULL));
11200
11201 /* BGP peer state */
11202 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11203 || CHECK_FLAG(peer->bgp->flags,
11204 BGP_FLAG_SHUTDOWN))
11205 json_object_string_add(json_peer,
11206 "peerState",
11207 "Admin");
11208 else if (CHECK_FLAG(
11209 peer->sflags,
11210 PEER_STATUS_PREFIX_OVERFLOW))
11211 json_object_string_add(json_peer,
11212 "peerState",
11213 "PfxCt");
11214 else if (CHECK_FLAG(peer->flags,
11215 PEER_FLAG_PASSIVE))
11216 json_object_string_add(json_peer,
11217 "peerState",
11218 "Passive");
11219 else if (CHECK_FLAG(peer->sflags,
11220 PEER_STATUS_NSF_WAIT))
11221 json_object_string_add(json_peer,
11222 "peerState",
11223 "NSF passive");
11224 else if (CHECK_FLAG(
11225 peer->bgp->flags,
11226 BGP_FLAG_EBGP_REQUIRES_POLICY)
11227 && (!bgp_inbound_policy_exists(peer,
11228 filter)
11229 || !bgp_outbound_policy_exists(
11230 peer, filter)))
11231 json_object_string_add(json_peer,
11232 "peerState",
11233 "Policy");
11234 else
11235 json_object_string_add(
11236 json_peer, "peerState", "OK");
11237
200116db
DD
11238 json_object_int_add(json_peer, "connectionsEstablished",
11239 peer->established);
11240 json_object_int_add(json_peer, "connectionsDropped",
11241 peer->dropped);
aa72bd7e
PG
11242 if (peer->desc)
11243 json_object_string_add(
11244 json_peer, "desc", peer->desc);
b4e9dcba 11245 }
3577f1c5
DD
11246 /* Avoid creating empty peer dicts in JSON */
11247 if (json_peer == NULL)
11248 continue;
ea47320b
DL
11249
11250 if (peer->conf_if)
60466a63 11251 json_object_string_add(json_peer, "idType",
ea47320b
DL
11252 "interface");
11253 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
11254 json_object_string_add(json_peer, "idType",
11255 "ipv4");
ea47320b 11256 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
11257 json_object_string_add(json_peer, "idType",
11258 "ipv6");
ea47320b
DL
11259 json_object_object_add(json_peers, peer->host,
11260 json_peer);
11261 } else {
8c1d4cd5 11262 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
11263 as_type, as)) {
11264 filtered_count++;
8c1d4cd5 11265 continue;
ce1944f0 11266 }
3577f1c5
DD
11267 if (show_failed &&
11268 bgp_has_peer_failed(peer, afi, safi)) {
11269 bgp_show_failed_summary(vty, bgp, peer, NULL,
11270 max_neighbor_width,
11271 use_json);
11272 } else if (!show_failed) {
10b49f14 11273 if (show_established
ce1944f0
LS
11274 && bgp_has_peer_failed(peer, afi, safi)) {
11275 filtered_count++;
10b49f14 11276 continue;
ce1944f0 11277 }
96c81f66
LS
11278
11279 if ((count - filtered_count) == 1) {
11280 /* display headline before the first
11281 * neighbor line */
11282 vty_out(vty, "\n");
11283
11284 /* Subtract 8 here because 'Neighbor' is
11285 * 8 characters */
11286 vty_out(vty, "Neighbor");
11287 vty_out(vty, "%*s",
11288 max_neighbor_width - 8, " ");
11289 vty_out(vty,
11290 show_wide
11291 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11292 : BGP_SHOW_SUMMARY_HEADER_ALL);
11293 }
11294
3577f1c5
DD
11295 memset(dn_flag, '\0', sizeof(dn_flag));
11296 if (peer_dynamic_neighbor(peer)) {
11297 dn_flag[0] = '*';
11298 }
d62a17ae 11299
3577f1c5 11300 if (peer->hostname
892fedb6
DA
11301 && CHECK_FLAG(bgp->flags,
11302 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 11303 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
11304 peer->hostname,
11305 peer->host);
d62a17ae 11306 else
3577f1c5
DD
11307 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11308
11309 /* pad the neighbor column with spaces */
11310 if (len < max_neighbor_width)
11311 vty_out(vty, "%*s", max_neighbor_width - len,
11312 " ");
11313
43aa5965
QY
11314 atomic_size_t outq_count, inq_count;
11315 outq_count = atomic_load_explicit(
11316 &peer->obuf->count,
11317 memory_order_relaxed);
11318 inq_count = atomic_load_explicit(
11319 &peer->ibuf->count,
11320 memory_order_relaxed);
11321
85eeb029
DA
11322 if (show_wide)
11323 vty_out(vty,
11324 "4 %10u %10u %9u %9u %8" PRIu64
11325 " %4zu %4zu %8s",
11326 peer->as,
11327 peer->change_local_as
11328 ? peer->change_local_as
11329 : peer->local_as,
11330 PEER_TOTAL_RX(peer),
11331 PEER_TOTAL_TX(peer),
11332 peer->version[afi][safi],
11333 inq_count, outq_count,
11334 peer_uptime(peer->uptime,
11335 timebuf,
11336 BGP_UPTIME_LEN, 0,
11337 NULL));
11338 else
11339 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11340 " %4zu %4zu %8s",
11341 peer->as, PEER_TOTAL_RX(peer),
11342 PEER_TOTAL_TX(peer),
11343 peer->version[afi][safi],
11344 inq_count, outq_count,
11345 peer_uptime(peer->uptime,
11346 timebuf,
11347 BGP_UPTIME_LEN, 0,
11348 NULL));
3577f1c5 11349
feb17238 11350 if (peer_established(peer)) {
d3ada366
DA
11351 if (peer->afc_recv[afi][safi]) {
11352 if (CHECK_FLAG(
11353 bgp->flags,
11354 BGP_FLAG_EBGP_REQUIRES_POLICY)
11355 && !bgp_inbound_policy_exists(
11356 peer, filter))
11357 vty_out(vty, " %12s",
11358 "(Policy)");
11359 else
11360 vty_out(vty,
6cde4b45 11361 " %12u",
d3ada366
DA
11362 peer->pcount
11363 [afi]
11364 [pfx_rcd_safi]);
11365 } else {
749d0f27 11366 vty_out(vty, " NoNeg");
d3ada366 11367 }
db92d226 11368
d3ada366
DA
11369 if (paf && PAF_SUBGRP(paf)) {
11370 if (CHECK_FLAG(
11371 bgp->flags,
11372 BGP_FLAG_EBGP_REQUIRES_POLICY)
11373 && !bgp_outbound_policy_exists(
11374 peer, filter))
11375 vty_out(vty, " %8s",
11376 "(Policy)");
11377 else
11378 vty_out(vty,
6cde4b45 11379 " %8u",
d3ada366
DA
11380 (PAF_SUBGRP(
11381 paf))
11382 ->scount);
749d0f27
DA
11383 } else {
11384 vty_out(vty, " NoNeg");
d3ada366 11385 }
db92d226 11386 } else {
736b68f3
DS
11387 if (CHECK_FLAG(peer->flags,
11388 PEER_FLAG_SHUTDOWN)
11389 || CHECK_FLAG(peer->bgp->flags,
11390 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
11391 vty_out(vty, " Idle (Admin)");
11392 else if (CHECK_FLAG(
11393 peer->sflags,
11394 PEER_STATUS_PREFIX_OVERFLOW))
11395 vty_out(vty, " Idle (PfxCt)");
11396 else
11397 vty_out(vty, " %12s",
11398 lookup_msg(bgp_status_msg,
11399 peer->status, NULL));
db92d226 11400
6cde4b45 11401 vty_out(vty, " %8u", 0);
3577f1c5 11402 }
565e9ddd
DA
11403 /* Make sure `Desc` column is the lastest in
11404 * the output.
11405 */
aa72bd7e 11406 if (peer->desc)
cb75bb31
DA
11407 vty_out(vty, " %s",
11408 bgp_peer_description_stripped(
85eeb029
DA
11409 peer->desc,
11410 show_wide ? 64 : 20));
aa72bd7e
PG
11411 else
11412 vty_out(vty, " N/A");
3577f1c5 11413 vty_out(vty, "\n");
d62a17ae 11414 }
3577f1c5 11415
d62a17ae 11416 }
11417 }
f933309e 11418
d62a17ae 11419 if (use_json) {
11420 json_object_object_add(json, "peers", json_peers);
3577f1c5 11421 json_object_int_add(json, "failedPeers", failed_count);
ce1944f0
LS
11422 json_object_int_add(json, "displayedPeers",
11423 count - filtered_count);
d62a17ae 11424 json_object_int_add(json, "totalPeers", count);
11425 json_object_int_add(json, "dynamicPeers", dn_count);
11426
3577f1c5
DD
11427 if (!show_failed)
11428 bgp_show_bestpath_json(bgp, json);
57a9c8a8 11429
75eeda93 11430 vty_json(vty, json);
d62a17ae 11431 } else {
ce1944f0 11432 if (count) {
96c81f66
LS
11433 if (filtered_count == count)
11434 vty_out(vty, "\n%% No matching neighbor\n");
11435 else {
11436 if (show_failed)
11437 vty_out(vty, "\nDisplayed neighbors %d",
11438 failed_count);
11439 else if (as_type != AS_UNSPECIFIED || as
11440 || fpeer || show_established)
ce1944f0
LS
11441 vty_out(vty, "\nDisplayed neighbors %d",
11442 count - filtered_count);
96c81f66
LS
11443
11444 vty_out(vty, "\nTotal number of neighbors %d\n",
11445 count);
ce1944f0 11446 }
ce1944f0 11447 } else {
d6ceaca3 11448 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 11449 get_afi_safi_str(afi, safi, false));
d62a17ae 11450 }
b05a1c8b 11451
d6ceaca3 11452 if (dn_count) {
d62a17ae 11453 vty_out(vty, "* - dynamic neighbor\n");
11454 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11455 dn_count, bgp->dynamic_neighbors_limit);
11456 }
11457 }
1ff9a340 11458
d62a17ae 11459 return CMD_SUCCESS;
718e3744 11460}
11461
d62a17ae 11462static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5 11463 int safi, struct peer *fpeer, int as_type,
96c81f66 11464 as_t as, uint16_t show_flags)
d62a17ae 11465{
11466 int is_first = 1;
11467 int afi_wildcard = (afi == AFI_MAX);
11468 int safi_wildcard = (safi == SAFI_MAX);
11469 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 11470 bool nbr_output = false;
85eeb029 11471 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11472
11473 if (use_json && is_wildcard)
11474 vty_out(vty, "{\n");
11475 if (afi_wildcard)
11476 afi = 1; /* AFI_IP */
11477 while (afi < AFI_MAX) {
11478 if (safi_wildcard)
11479 safi = 1; /* SAFI_UNICAST */
11480 while (safi < SAFI_MAX) {
318cac96 11481 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 11482 nbr_output = true;
f86897b9 11483
d62a17ae 11484 if (is_wildcard) {
11485 /*
11486 * So limit output to those afi/safi
11487 * pairs that
11488 * actualy have something interesting in
11489 * them
11490 */
11491 if (use_json) {
d62a17ae 11492 if (!is_first)
11493 vty_out(vty, ",\n");
11494 else
11495 is_first = 0;
11496
11497 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11498 get_afi_safi_str(afi,
11499 safi,
11500 true));
d62a17ae 11501 } else {
6cac2fcc
LS
11502 vty_out(vty,
11503 "\n%s Summary (%s):\n",
5cb5f4d0
DD
11504 get_afi_safi_str(afi,
11505 safi,
6cac2fcc
LS
11506 false),
11507 bgp->name_pretty);
d62a17ae 11508 }
11509 }
8c1d4cd5
LS
11510 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11511 as_type, as, show_flags);
d62a17ae 11512 }
11513 safi++;
d62a17ae 11514 if (!safi_wildcard)
11515 safi = SAFI_MAX;
11516 }
11517 afi++;
ee851c8c 11518 if (!afi_wildcard)
d62a17ae 11519 afi = AFI_MAX;
11520 }
11521
11522 if (use_json && is_wildcard)
11523 vty_out(vty, "}\n");
ca61fd25
DS
11524 else if (!nbr_output) {
11525 if (use_json)
11526 vty_out(vty, "{}\n");
11527 else
6cac2fcc
LS
11528 vty_out(vty, "%% No BGP neighbors found in %s\n",
11529 bgp->name_pretty);
ca61fd25 11530 }
d62a17ae 11531}
11532
11533static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
11534 safi_t safi,
11535 const char *neighbor,
11536 int as_type, as_t as,
96c81f66 11537 uint16_t show_flags)
d62a17ae 11538{
11539 struct listnode *node, *nnode;
11540 struct bgp *bgp;
8c1d4cd5 11541 struct peer *fpeer = NULL;
d62a17ae 11542 int is_first = 1;
9f049418 11543 bool nbr_output = false;
85eeb029 11544 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11545
11546 if (use_json)
11547 vty_out(vty, "{\n");
11548
11549 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11550 nbr_output = true;
d62a17ae 11551 if (use_json) {
d62a17ae 11552 if (!is_first)
11553 vty_out(vty, ",\n");
11554 else
11555 is_first = 0;
11556
11557 vty_out(vty, "\"%s\":",
11558 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11559 ? VRF_DEFAULT_NAME
d62a17ae 11560 : bgp->name);
d62a17ae 11561 }
8c1d4cd5
LS
11562 if (neighbor) {
11563 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11564 use_json);
11565 if (!fpeer)
11566 continue;
11567 }
11568 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11569 as, show_flags);
d62a17ae 11570 }
11571
11572 if (use_json)
11573 vty_out(vty, "}\n");
9f049418
DS
11574 else if (!nbr_output)
11575 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11576}
11577
11578int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5 11579 safi_t safi, const char *neighbor, int as_type,
96c81f66 11580 as_t as, uint16_t show_flags)
d62a17ae 11581{
11582 struct bgp *bgp;
85eeb029 11583 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 11584 struct peer *fpeer = NULL;
d62a17ae 11585
11586 if (name) {
11587 if (strmatch(name, "all")) {
85eeb029 11588 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
11589 neighbor, as_type,
11590 as, show_flags);
d62a17ae 11591 return CMD_SUCCESS;
11592 } else {
11593 bgp = bgp_lookup_by_name(name);
11594
11595 if (!bgp) {
11596 if (use_json)
11597 vty_out(vty, "{}\n");
11598 else
11599 vty_out(vty,
ca61fd25 11600 "%% BGP instance not found\n");
d62a17ae 11601 return CMD_WARNING;
11602 }
11603
8c1d4cd5
LS
11604 if (neighbor) {
11605 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11606 use_json);
11607 if (!fpeer)
11608 return CMD_WARNING;
11609 }
11610 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11611 as_type, as, show_flags);
d62a17ae 11612 return CMD_SUCCESS;
11613 }
11614 }
11615
11616 bgp = bgp_get_default();
11617
8c1d4cd5
LS
11618 if (bgp) {
11619 if (neighbor) {
11620 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11621 use_json);
11622 if (!fpeer)
11623 return CMD_WARNING;
11624 }
11625 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11626 as, show_flags);
11627 } else {
ca61fd25
DS
11628 if (use_json)
11629 vty_out(vty, "{}\n");
11630 else
11631 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11632 return CMD_WARNING;
11633 }
d62a17ae 11634
11635 return CMD_SUCCESS;
4fb25c53
DW
11636}
11637
716b2d8a 11638/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
11639DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11640 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11641 " [" BGP_SAFI_WITH_LABEL_CMD_STR
96c81f66 11642 "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <(1-4294967295)|internal|external>>] [terse] [wide] [json$uj]",
8c1d4cd5
LS
11643 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11644 BGP_SAFI_WITH_LABEL_HELP_STR
11645 "Display the entries for all address families\n"
11646 "Summary of BGP neighbor status\n"
11647 "Show only sessions in Established state\n"
11648 "Show only sessions not in Established state\n"
11649 "Show only the specified neighbor session\n"
11650 "Neighbor to display information about\n"
11651 "Neighbor to display information about\n"
11652 "Neighbor on BGP configured interface\n"
11653 "Show only the specified remote AS sessions\n"
11654 "AS number\n"
11655 "Internal (iBGP) AS sessions\n"
11656 "External (eBGP) AS sessions\n"
96c81f66 11657 "Shorten the information on BGP instances\n"
8c1d4cd5 11658 "Increase table width for longer output\n" JSON_STR)
718e3744 11659{
d62a17ae 11660 char *vrf = NULL;
11661 afi_t afi = AFI_MAX;
11662 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
11663 as_t as = 0; /* 0 means AS filter not set */
11664 int as_type = AS_UNSPECIFIED;
96c81f66 11665 uint16_t show_flags = 0;
d62a17ae 11666
11667 int idx = 0;
11668
11669 /* show [ip] bgp */
96f3485c 11670 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11671 afi = AFI_IP;
9a8bdf1c
PG
11672 /* [<vrf> VIEWVRFNAME] */
11673 if (argv_find(argv, argc, "vrf", &idx)) {
11674 vrf = argv[idx + 1]->arg;
11675 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11676 vrf = NULL;
11677 } else if (argv_find(argv, argc, "view", &idx))
11678 /* [<view> VIEWVRFNAME] */
11679 vrf = argv[idx + 1]->arg;
d62a17ae 11680 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11681 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11682 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11683 }
11684
3577f1c5 11685 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11686 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11687
10b49f14 11688 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11689 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11690
8c1d4cd5
LS
11691 if (argv_find(argv, argc, "remote-as", &idx)) {
11692 if (argv[idx + 1]->arg[0] == 'i')
11693 as_type = AS_INTERNAL;
11694 else if (argv[idx + 1]->arg[0] == 'e')
11695 as_type = AS_EXTERNAL;
11696 else
11697 as = (as_t)atoi(argv[idx + 1]->arg);
11698 }
11699
96c81f66
LS
11700 if (argv_find(argv, argc, "terse", &idx))
11701 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11702
85eeb029
DA
11703 if (argv_find(argv, argc, "wide", &idx))
11704 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11705
11706 if (argv_find(argv, argc, "json", &idx))
11707 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11708
8c1d4cd5
LS
11709 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11710 show_flags);
d62a17ae 11711}
11712
5cb5f4d0 11713const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11714{
5cb5f4d0
DD
11715 if (for_json)
11716 return get_afi_safi_json_str(afi, safi);
d62a17ae 11717 else
5cb5f4d0 11718 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11719}
11720
d62a17ae 11721
11722static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11723 afi_t afi, safi_t safi,
d7c0a89a
QY
11724 uint16_t adv_smcap, uint16_t adv_rmcap,
11725 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11726 bool use_json, json_object *json_pref)
d62a17ae 11727{
11728 /* Send-Mode */
11729 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11730 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11731 if (use_json) {
11732 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11733 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11734 json_object_string_add(json_pref, "sendMode",
11735 "advertisedAndReceived");
11736 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11737 json_object_string_add(json_pref, "sendMode",
11738 "advertised");
11739 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11740 json_object_string_add(json_pref, "sendMode",
11741 "received");
11742 } else {
11743 vty_out(vty, " Send-mode: ");
11744 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11745 vty_out(vty, "advertised");
11746 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11747 vty_out(vty, "%sreceived",
11748 CHECK_FLAG(p->af_cap[afi][safi],
11749 adv_smcap)
11750 ? ", "
11751 : "");
11752 vty_out(vty, "\n");
11753 }
11754 }
11755
11756 /* Receive-Mode */
11757 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11758 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11759 if (use_json) {
11760 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11761 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11762 json_object_string_add(json_pref, "recvMode",
11763 "advertisedAndReceived");
11764 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11765 json_object_string_add(json_pref, "recvMode",
11766 "advertised");
11767 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11768 json_object_string_add(json_pref, "recvMode",
11769 "received");
11770 } else {
11771 vty_out(vty, " Receive-mode: ");
11772 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11773 vty_out(vty, "advertised");
11774 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11775 vty_out(vty, "%sreceived",
11776 CHECK_FLAG(p->af_cap[afi][safi],
11777 adv_rmcap)
11778 ? ", "
11779 : "");
11780 vty_out(vty, "\n");
11781 }
11782 }
11783}
11784
eea685b6
DA
11785static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11786 struct peer *p,
11787 bool use_json,
11788 json_object *json)
2986cac2 11789{
eea685b6
DA
11790 bool rbit = false;
11791 bool nbit = false;
2986cac2 11792
13909c4f
DS
11793 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11794 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
feb17238 11795 && (peer_established(p))) {
eea685b6
DA
11796 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11797 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
2986cac2 11798 }
11799
eea685b6
DA
11800 if (use_json) {
11801 json_object_boolean_add(json, "rBit", rbit);
11802 json_object_boolean_add(json, "nBit", nbit);
2986cac2 11803 } else {
eea685b6
DA
11804 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11805 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
2986cac2 11806 }
11807}
11808
13909c4f
DS
11809static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11810 struct peer *peer,
11811 bool use_json,
11812 json_object *json)
2986cac2 11813{
2bb5d39b 11814 const char *mode = "NotApplicable";
2986cac2 11815
11816 if (!use_json)
a53ca37b 11817 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11818
13909c4f 11819 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
feb17238 11820 && (peer_established(peer))) {
2986cac2 11821
13909c4f
DS
11822 if ((peer->nsf_af_count == 0)
11823 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11824
2986cac2 11825 mode = "Disable";
11826
13909c4f
DS
11827 } else if (peer->nsf_af_count == 0
11828 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11829
2986cac2 11830 mode = "Helper";
11831
13909c4f
DS
11832 } else if (peer->nsf_af_count != 0
11833 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11834
2986cac2 11835 mode = "Restart";
2986cac2 11836 }
11837 }
11838
11839 if (use_json) {
13909c4f 11840 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11841 } else
11842 vty_out(vty, mode, "\n");
11843}
11844
13909c4f
DS
11845static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11846 struct peer *p,
11847 bool use_json,
11848 json_object *json)
2986cac2 11849{
11850 const char *mode = "Invalid";
11851
11852 if (!use_json)
a53ca37b 11853 vty_out(vty, " Local GR Mode: ");
2986cac2 11854
11855 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11856 mode = "Helper";
11857 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11858 mode = "Restart";
11859 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11860 mode = "Disable";
2ba1fe69 11861 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11862 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11863 mode = "Helper*";
11864 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11865 mode = "Restart*";
11866 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11867 mode = "Disable*";
11868 else
11869 mode = "Invalid*";
2ba1fe69 11870 }
2986cac2 11871
11872 if (use_json) {
13909c4f 11873 json_object_string_add(json, "localGrMode", mode);
2986cac2 11874 } else {
11875 vty_out(vty, mode, "\n");
11876 }
11877}
11878
13909c4f
DS
11879static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11880 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11881{
2ba1fe69 11882 afi_t afi;
11883 safi_t safi;
2986cac2 11884 json_object *json_afi_safi = NULL;
11885 json_object *json_timer = NULL;
11886 json_object *json_endofrib_status = NULL;
9e3b51a7 11887 bool eor_flag = false;
2986cac2 11888
df8d723c
DA
11889 FOREACH_AFI_SAFI_NSF (afi, safi) {
11890 if (!peer->afc[afi][safi])
11891 continue;
2986cac2 11892
df8d723c
DA
11893 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11894 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11895 continue;
9e3b51a7 11896
df8d723c
DA
11897 if (use_json) {
11898 json_afi_safi = json_object_new_object();
11899 json_endofrib_status = json_object_new_object();
11900 json_timer = json_object_new_object();
11901 }
2986cac2 11902
df8d723c
DA
11903 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11904 eor_flag = true;
11905 else
11906 eor_flag = false;
2986cac2 11907
df8d723c
DA
11908 if (!use_json) {
11909 vty_out(vty, " %s:\n",
11910 get_afi_safi_str(afi, safi, false));
2986cac2 11911
df8d723c
DA
11912 vty_out(vty, " F bit: ");
11913 }
2986cac2 11914
df8d723c
DA
11915 if (peer->nsf[afi][safi] &&
11916 CHECK_FLAG(peer->af_cap[afi][safi],
11917 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11918
df8d723c
DA
11919 if (use_json) {
11920 json_object_boolean_true_add(json_afi_safi,
11921 "fBit");
11922 } else
11923 vty_out(vty, "True\n");
11924 } else {
11925 if (use_json)
11926 json_object_boolean_false_add(json_afi_safi,
11927 "fBit");
11928 else
11929 vty_out(vty, "False\n");
11930 }
2986cac2 11931
df8d723c
DA
11932 if (!use_json)
11933 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11934
df8d723c
DA
11935 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11936 PEER_STATUS_EOR_SEND)) {
11937 if (use_json) {
11938 json_object_boolean_true_add(
11939 json_endofrib_status, "endOfRibSend");
9e3b51a7 11940
df8d723c
DA
11941 PRINT_EOR_JSON(eor_flag);
11942 } else {
11943 vty_out(vty, "Yes\n");
11944 vty_out(vty,
11945 " End-of-RIB sent after update: ");
2986cac2 11946
df8d723c
DA
11947 PRINT_EOR(eor_flag);
11948 }
11949 } else {
11950 if (use_json) {
11951 json_object_boolean_false_add(
11952 json_endofrib_status, "endOfRibSend");
11953 json_object_boolean_false_add(
11954 json_endofrib_status,
11955 "endOfRibSentAfterUpdate");
13909c4f 11956 } else {
df8d723c
DA
11957 vty_out(vty, "No\n");
11958 vty_out(vty,
11959 " End-of-RIB sent after update: ");
11960 vty_out(vty, "No\n");
13909c4f 11961 }
df8d723c 11962 }
2986cac2 11963
df8d723c
DA
11964 if (!use_json)
11965 vty_out(vty, " End-of-RIB received: ");
a53ca37b 11966
df8d723c
DA
11967 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11968 PEER_STATUS_EOR_RECEIVED)) {
11969 if (use_json)
11970 json_object_boolean_true_add(
11971 json_endofrib_status, "endOfRibRecv");
11972 else
11973 vty_out(vty, "Yes\n");
11974 } else {
11975 if (use_json)
11976 json_object_boolean_false_add(
11977 json_endofrib_status, "endOfRibRecv");
11978 else
11979 vty_out(vty, "No\n");
11980 }
11981
11982 if (use_json) {
11983 json_object_int_add(json_timer, "stalePathTimer",
11984 peer->bgp->stalepath_time);
11985
11986 if (peer->t_gr_stale != NULL) {
11987 json_object_int_add(json_timer,
11988 "stalePathTimerRemaining",
11989 thread_timer_remain_second(
11990 peer->t_gr_stale));
a53ca37b
DA
11991 }
11992
df8d723c
DA
11993 /* Display Configured Selection
11994 * Deferral only when when
11995 * Gr mode is enabled.
11996 */
11997 if (CHECK_FLAG(peer->flags,
11998 PEER_FLAG_GRACEFUL_RESTART)) {
13909c4f 11999 json_object_int_add(json_timer,
df8d723c 12000 "selectionDeferralTimer",
13909c4f 12001 peer->bgp->stalepath_time);
df8d723c 12002 }
2986cac2 12003
df8d723c
DA
12004 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12005 NULL) {
2986cac2 12006
df8d723c
DA
12007 json_object_int_add(
12008 json_timer,
12009 "selectionDeferralTimerRemaining",
12010 thread_timer_remain_second(
12011 peer->bgp->gr_info[afi][safi]
12012 .t_select_deferral));
12013 }
12014 } else {
12015 vty_out(vty, " Timers:\n");
12016 vty_out(vty,
12017 " Configured Stale Path Time(sec): %u\n",
12018 peer->bgp->stalepath_time);
2986cac2 12019
df8d723c 12020 if (peer->t_gr_stale != NULL)
13909c4f 12021 vty_out(vty,
df8d723c
DA
12022 " Stale Path Remaining(sec): %ld\n",
12023 thread_timer_remain_second(
12024 peer->t_gr_stale));
12025 /* Display Configured Selection
12026 * Deferral only when when
12027 * Gr mode is enabled.
12028 */
12029 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12030 vty_out(vty,
12031 " Configured Selection Deferral Time(sec): %u\n",
12032 peer->bgp->select_defer_time);
2986cac2 12033
df8d723c
DA
12034 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12035 NULL)
12036 vty_out(vty,
12037 " Selection Deferral Time Remaining(sec): %ld\n",
12038 thread_timer_remain_second(
12039 peer->bgp->gr_info[afi][safi]
12040 .t_select_deferral));
12041 }
12042 if (use_json) {
12043 json_object_object_add(json_afi_safi, "endOfRibStatus",
12044 json_endofrib_status);
12045 json_object_object_add(json_afi_safi, "timers",
12046 json_timer);
12047 json_object_object_add(
12048 json, get_afi_safi_str(afi, safi, true),
12049 json_afi_safi);
2986cac2 12050 }
12051 }
12052}
12053
36235319
QY
12054static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12055 struct peer *p,
12056 bool use_json,
12057 json_object *json)
2986cac2 12058{
12059 if (use_json) {
12060 json_object *json_timer = NULL;
12061
12062 json_timer = json_object_new_object();
12063
13909c4f
DS
12064 json_object_int_add(json_timer, "configuredRestartTimer",
12065 p->bgp->restart_time);
2986cac2 12066
13909c4f
DS
12067 json_object_int_add(json_timer, "receivedRestartTimer",
12068 p->v_gr_restart);
2986cac2 12069
13909c4f
DS
12070 if (p->t_gr_restart != NULL)
12071 json_object_int_add(
12072 json_timer, "restartTimerRemaining",
12073 thread_timer_remain_second(p->t_gr_restart));
2986cac2 12074
12075 json_object_object_add(json, "timers", json_timer);
12076 } else {
12077
a53ca37b
DA
12078 vty_out(vty, " Timers:\n");
12079 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 12080 p->bgp->restart_time);
2986cac2 12081
a53ca37b 12082 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
12083 p->v_gr_restart);
12084 if (p->t_gr_restart != NULL)
a53ca37b 12085 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 12086 thread_timer_remain_second(p->t_gr_restart));
36235319 12087 if (p->t_gr_restart != NULL) {
a53ca37b 12088 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
12089 thread_timer_remain_second(p->t_gr_restart));
12090 }
2986cac2 12091 }
12092}
12093
12094static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 12095 bool use_json, json_object *json)
2986cac2 12096{
2986cac2 12097 char dn_flag[2] = {0};
2b7165e7
QY
12098 /* '*' + v6 address of neighbor */
12099 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 12100
2986cac2 12101 if (!p->conf_if && peer_dynamic_neighbor(p))
12102 dn_flag[0] = '*';
12103
12104 if (p->conf_if) {
12105 if (use_json)
47e12884
DA
12106 json_object_string_addf(json, "neighborAddr", "%pSU",
12107 &p->su);
2986cac2 12108 else
47e12884
DA
12109 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12110 &p->su);
2986cac2 12111 } else {
772270f3
QY
12112 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12113 p->host);
2986cac2 12114
12115 if (use_json)
36235319
QY
12116 json_object_string_add(json, "neighborAddr",
12117 neighborAddr);
2986cac2 12118 else
36235319 12119 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 12120 }
12121
12122 /* more gr info in new format */
12123 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
12124}
12125
d62a17ae 12126static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 12127 safi_t safi, bool use_json,
d62a17ae 12128 json_object *json_neigh)
12129{
0291c246
MK
12130 struct bgp_filter *filter;
12131 struct peer_af *paf;
12132 char orf_pfx_name[BUFSIZ];
12133 int orf_pfx_count;
12134 json_object *json_af = NULL;
12135 json_object *json_prefA = NULL;
12136 json_object *json_prefB = NULL;
12137 json_object *json_addr = NULL;
fa36596c 12138 json_object *json_advmap = NULL;
d62a17ae 12139
12140 if (use_json) {
12141 json_addr = json_object_new_object();
12142 json_af = json_object_new_object();
12143 filter = &p->filter[afi][safi];
12144
12145 if (peer_group_active(p))
12146 json_object_string_add(json_addr, "peerGroupMember",
12147 p->group->name);
12148
12149 paf = peer_af_find(p, afi, safi);
12150 if (paf && PAF_SUBGRP(paf)) {
12151 json_object_int_add(json_addr, "updateGroupId",
12152 PAF_UPDGRP(paf)->id);
12153 json_object_int_add(json_addr, "subGroupId",
12154 PAF_SUBGRP(paf)->id);
12155 json_object_int_add(json_addr, "packetQueueLength",
12156 bpacket_queue_virtual_length(paf));
12157 }
12158
12159 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12160 || CHECK_FLAG(p->af_cap[afi][safi],
12161 PEER_CAP_ORF_PREFIX_SM_RCV)
12162 || CHECK_FLAG(p->af_cap[afi][safi],
12163 PEER_CAP_ORF_PREFIX_RM_ADV)
12164 || CHECK_FLAG(p->af_cap[afi][safi],
12165 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12166 json_object_int_add(json_af, "orfType",
12167 ORF_TYPE_PREFIX);
12168 json_prefA = json_object_new_object();
12169 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12170 PEER_CAP_ORF_PREFIX_SM_ADV,
12171 PEER_CAP_ORF_PREFIX_RM_ADV,
12172 PEER_CAP_ORF_PREFIX_SM_RCV,
12173 PEER_CAP_ORF_PREFIX_RM_RCV,
12174 use_json, json_prefA);
12175 json_object_object_add(json_af, "orfPrefixList",
12176 json_prefA);
12177 }
12178
12179 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12180 || CHECK_FLAG(p->af_cap[afi][safi],
12181 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12182 || CHECK_FLAG(p->af_cap[afi][safi],
12183 PEER_CAP_ORF_PREFIX_RM_ADV)
12184 || CHECK_FLAG(p->af_cap[afi][safi],
12185 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12186 json_object_int_add(json_af, "orfOldType",
12187 ORF_TYPE_PREFIX_OLD);
12188 json_prefB = json_object_new_object();
12189 bgp_show_peer_afi_orf_cap(
12190 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12191 PEER_CAP_ORF_PREFIX_RM_ADV,
12192 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12193 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12194 json_prefB);
12195 json_object_object_add(json_af, "orfOldPrefixList",
12196 json_prefB);
12197 }
12198
12199 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12200 || CHECK_FLAG(p->af_cap[afi][safi],
12201 PEER_CAP_ORF_PREFIX_SM_RCV)
12202 || CHECK_FLAG(p->af_cap[afi][safi],
12203 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12204 || CHECK_FLAG(p->af_cap[afi][safi],
12205 PEER_CAP_ORF_PREFIX_RM_ADV)
12206 || CHECK_FLAG(p->af_cap[afi][safi],
12207 PEER_CAP_ORF_PREFIX_RM_RCV)
12208 || CHECK_FLAG(p->af_cap[afi][safi],
12209 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12210 json_object_object_add(json_addr, "afDependentCap",
12211 json_af);
12212 else
12213 json_object_free(json_af);
12214
772270f3
QY
12215 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12216 p->host, afi, safi);
d62a17ae 12217 orf_pfx_count = prefix_bgp_show_prefix_list(
12218 NULL, afi, orf_pfx_name, use_json);
12219
12220 if (CHECK_FLAG(p->af_sflags[afi][safi],
12221 PEER_STATUS_ORF_PREFIX_SEND)
12222 || orf_pfx_count) {
12223 if (CHECK_FLAG(p->af_sflags[afi][safi],
12224 PEER_STATUS_ORF_PREFIX_SEND))
12225 json_object_boolean_true_add(json_neigh,
12226 "orfSent");
12227 if (orf_pfx_count)
12228 json_object_int_add(json_addr, "orfRecvCounter",
12229 orf_pfx_count);
12230 }
12231 if (CHECK_FLAG(p->af_sflags[afi][safi],
12232 PEER_STATUS_ORF_WAIT_REFRESH))
12233 json_object_string_add(
12234 json_addr, "orfFirstUpdate",
12235 "deferredUntilORFOrRouteRefreshRecvd");
12236
12237 if (CHECK_FLAG(p->af_flags[afi][safi],
12238 PEER_FLAG_REFLECTOR_CLIENT))
12239 json_object_boolean_true_add(json_addr,
12240 "routeReflectorClient");
12241 if (CHECK_FLAG(p->af_flags[afi][safi],
12242 PEER_FLAG_RSERVER_CLIENT))
12243 json_object_boolean_true_add(json_addr,
12244 "routeServerClient");
12245 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12246 json_object_boolean_true_add(json_addr,
12247 "inboundSoftConfigPermit");
12248
12249 if (CHECK_FLAG(p->af_flags[afi][safi],
12250 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12251 json_object_boolean_true_add(
12252 json_addr,
12253 "privateAsNumsAllReplacedInUpdatesToNbr");
12254 else if (CHECK_FLAG(p->af_flags[afi][safi],
12255 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12256 json_object_boolean_true_add(
12257 json_addr,
12258 "privateAsNumsReplacedInUpdatesToNbr");
12259 else if (CHECK_FLAG(p->af_flags[afi][safi],
12260 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12261 json_object_boolean_true_add(
12262 json_addr,
12263 "privateAsNumsAllRemovedInUpdatesToNbr");
12264 else if (CHECK_FLAG(p->af_flags[afi][safi],
12265 PEER_FLAG_REMOVE_PRIVATE_AS))
12266 json_object_boolean_true_add(
12267 json_addr,
12268 "privateAsNumsRemovedInUpdatesToNbr");
12269
dcc68b5e
MS
12270 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12271 json_object_boolean_true_add(
12272 json_addr,
12273 bgp_addpath_names(p->addpath_type[afi][safi])
12274 ->type_json_name);
d62a17ae 12275
12276 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12277 json_object_string_add(json_addr,
12278 "overrideASNsInOutboundUpdates",
12279 "ifAspathEqualRemoteAs");
12280
12281 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12282 || CHECK_FLAG(p->af_flags[afi][safi],
12283 PEER_FLAG_FORCE_NEXTHOP_SELF))
12284 json_object_boolean_true_add(json_addr,
12285 "routerAlwaysNextHop");
12286 if (CHECK_FLAG(p->af_flags[afi][safi],
12287 PEER_FLAG_AS_PATH_UNCHANGED))
12288 json_object_boolean_true_add(
12289 json_addr, "unchangedAsPathPropogatedToNbr");
12290 if (CHECK_FLAG(p->af_flags[afi][safi],
12291 PEER_FLAG_NEXTHOP_UNCHANGED))
12292 json_object_boolean_true_add(
12293 json_addr, "unchangedNextHopPropogatedToNbr");
12294 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12295 json_object_boolean_true_add(
12296 json_addr, "unchangedMedPropogatedToNbr");
12297 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12298 || CHECK_FLAG(p->af_flags[afi][safi],
12299 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12300 if (CHECK_FLAG(p->af_flags[afi][safi],
12301 PEER_FLAG_SEND_COMMUNITY)
12302 && CHECK_FLAG(p->af_flags[afi][safi],
12303 PEER_FLAG_SEND_EXT_COMMUNITY))
12304 json_object_string_add(json_addr,
12305 "commAttriSentToNbr",
12306 "extendedAndStandard");
12307 else if (CHECK_FLAG(p->af_flags[afi][safi],
12308 PEER_FLAG_SEND_EXT_COMMUNITY))
12309 json_object_string_add(json_addr,
12310 "commAttriSentToNbr",
12311 "extended");
12312 else
12313 json_object_string_add(json_addr,
12314 "commAttriSentToNbr",
12315 "standard");
12316 }
12317 if (CHECK_FLAG(p->af_flags[afi][safi],
12318 PEER_FLAG_DEFAULT_ORIGINATE)) {
12319 if (p->default_rmap[afi][safi].name)
12320 json_object_string_add(
12321 json_addr, "defaultRouteMap",
12322 p->default_rmap[afi][safi].name);
12323
12324 if (paf && PAF_SUBGRP(paf)
12325 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12326 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12327 json_object_boolean_true_add(json_addr,
12328 "defaultSent");
12329 else
12330 json_object_boolean_true_add(json_addr,
12331 "defaultNotSent");
12332 }
12333
dff8f48d 12334 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12335 if (is_evpn_enabled())
60466a63
QY
12336 json_object_boolean_true_add(
12337 json_addr, "advertiseAllVnis");
dff8f48d
MK
12338 }
12339
d62a17ae 12340 if (filter->plist[FILTER_IN].name
12341 || filter->dlist[FILTER_IN].name
12342 || filter->aslist[FILTER_IN].name
12343 || filter->map[RMAP_IN].name)
12344 json_object_boolean_true_add(json_addr,
12345 "inboundPathPolicyConfig");
12346 if (filter->plist[FILTER_OUT].name
12347 || filter->dlist[FILTER_OUT].name
12348 || filter->aslist[FILTER_OUT].name
12349 || filter->map[RMAP_OUT].name || filter->usmap.name)
12350 json_object_boolean_true_add(
12351 json_addr, "outboundPathPolicyConfig");
12352
12353 /* prefix-list */
12354 if (filter->plist[FILTER_IN].name)
12355 json_object_string_add(json_addr,
12356 "incomingUpdatePrefixFilterList",
12357 filter->plist[FILTER_IN].name);
12358 if (filter->plist[FILTER_OUT].name)
12359 json_object_string_add(json_addr,
12360 "outgoingUpdatePrefixFilterList",
12361 filter->plist[FILTER_OUT].name);
12362
12363 /* distribute-list */
12364 if (filter->dlist[FILTER_IN].name)
12365 json_object_string_add(
12366 json_addr, "incomingUpdateNetworkFilterList",
12367 filter->dlist[FILTER_IN].name);
12368 if (filter->dlist[FILTER_OUT].name)
12369 json_object_string_add(
12370 json_addr, "outgoingUpdateNetworkFilterList",
12371 filter->dlist[FILTER_OUT].name);
12372
12373 /* filter-list. */
12374 if (filter->aslist[FILTER_IN].name)
12375 json_object_string_add(json_addr,
12376 "incomingUpdateAsPathFilterList",
12377 filter->aslist[FILTER_IN].name);
12378 if (filter->aslist[FILTER_OUT].name)
12379 json_object_string_add(json_addr,
12380 "outgoingUpdateAsPathFilterList",
12381 filter->aslist[FILTER_OUT].name);
12382
12383 /* route-map. */
12384 if (filter->map[RMAP_IN].name)
12385 json_object_string_add(
12386 json_addr, "routeMapForIncomingAdvertisements",
12387 filter->map[RMAP_IN].name);
12388 if (filter->map[RMAP_OUT].name)
12389 json_object_string_add(
12390 json_addr, "routeMapForOutgoingAdvertisements",
12391 filter->map[RMAP_OUT].name);
12392
9dac9fc8 12393 /* ebgp-requires-policy (inbound) */
1d3fdccf 12394 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12395 && !bgp_inbound_policy_exists(p, filter))
12396 json_object_string_add(
12397 json_addr, "inboundEbgpRequiresPolicy",
12398 "Inbound updates discarded due to missing policy");
12399
12400 /* ebgp-requires-policy (outbound) */
1d3fdccf 12401 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12402 && (!bgp_outbound_policy_exists(p, filter)))
12403 json_object_string_add(
12404 json_addr, "outboundEbgpRequiresPolicy",
12405 "Outbound updates discarded due to missing policy");
12406
d62a17ae 12407 /* unsuppress-map */
12408 if (filter->usmap.name)
12409 json_object_string_add(json_addr,
12410 "selectiveUnsuppressRouteMap",
12411 filter->usmap.name);
12412
fa36596c
MK
12413 /* advertise-map */
12414 if (filter->advmap.aname) {
12415 json_advmap = json_object_new_object();
12416 json_object_string_add(json_advmap, "condition",
12417 filter->advmap.condition
12418 ? "EXIST"
12419 : "NON_EXIST");
12420 json_object_string_add(json_advmap, "conditionMap",
12421 filter->advmap.cname);
12422 json_object_string_add(json_advmap, "advertiseMap",
12423 filter->advmap.aname);
ecf2b628
QY
12424 json_object_string_add(
12425 json_advmap, "advertiseStatus",
12426 filter->advmap.update_type ==
12427 UPDATE_TYPE_ADVERTISE
12428 ? "Advertise"
12429 : "Withdraw");
fa36596c
MK
12430 json_object_object_add(json_addr, "advertiseMap",
12431 json_advmap);
12432 }
12433
d62a17ae 12434 /* Receive prefix count */
12435 json_object_int_add(json_addr, "acceptedPrefixCounter",
12436 p->pcount[afi][safi]);
50e05855
AD
12437 if (paf && PAF_SUBGRP(paf))
12438 json_object_int_add(json_addr, "sentPrefixCounter",
12439 (PAF_SUBGRP(paf))->scount);
d62a17ae 12440
fde246e8
DA
12441 /* Maximum prefix */
12442 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12443 json_object_int_add(json_addr, "prefixOutAllowedMax",
12444 p->pmax_out[afi][safi]);
12445
d62a17ae 12446 /* Maximum prefix */
12447 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12448 json_object_int_add(json_addr, "prefixAllowedMax",
12449 p->pmax[afi][safi]);
12450 if (CHECK_FLAG(p->af_flags[afi][safi],
12451 PEER_FLAG_MAX_PREFIX_WARNING))
12452 json_object_boolean_true_add(
12453 json_addr, "prefixAllowedMaxWarning");
12454 json_object_int_add(json_addr,
12455 "prefixAllowedWarningThresh",
12456 p->pmax_threshold[afi][safi]);
12457 if (p->pmax_restart[afi][safi])
12458 json_object_int_add(
12459 json_addr,
12460 "prefixAllowedRestartIntervalMsecs",
12461 p->pmax_restart[afi][safi] * 60000);
12462 }
2986cac2 12463 json_object_object_add(json_neigh,
36235319 12464 get_afi_safi_str(afi, safi, true),
d62a17ae 12465 json_addr);
12466
12467 } else {
12468 filter = &p->filter[afi][safi];
12469
12470 vty_out(vty, " For address family: %s\n",
5cb5f4d0 12471 get_afi_safi_str(afi, safi, false));
d62a17ae 12472
12473 if (peer_group_active(p))
12474 vty_out(vty, " %s peer-group member\n",
12475 p->group->name);
12476
12477 paf = peer_af_find(p, afi, safi);
12478 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 12479 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 12480 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12481 vty_out(vty, " Packet Queue length %d\n",
12482 bpacket_queue_virtual_length(paf));
12483 } else {
12484 vty_out(vty, " Not part of any update group\n");
12485 }
12486 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12487 || CHECK_FLAG(p->af_cap[afi][safi],
12488 PEER_CAP_ORF_PREFIX_SM_RCV)
12489 || CHECK_FLAG(p->af_cap[afi][safi],
12490 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12491 || CHECK_FLAG(p->af_cap[afi][safi],
12492 PEER_CAP_ORF_PREFIX_RM_ADV)
12493 || CHECK_FLAG(p->af_cap[afi][safi],
12494 PEER_CAP_ORF_PREFIX_RM_RCV)
12495 || CHECK_FLAG(p->af_cap[afi][safi],
12496 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12497 vty_out(vty, " AF-dependant capabilities:\n");
12498
12499 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12500 || CHECK_FLAG(p->af_cap[afi][safi],
12501 PEER_CAP_ORF_PREFIX_SM_RCV)
12502 || CHECK_FLAG(p->af_cap[afi][safi],
12503 PEER_CAP_ORF_PREFIX_RM_ADV)
12504 || CHECK_FLAG(p->af_cap[afi][safi],
12505 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12506 vty_out(vty,
12507 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12508 ORF_TYPE_PREFIX);
12509 bgp_show_peer_afi_orf_cap(
12510 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12511 PEER_CAP_ORF_PREFIX_RM_ADV,
12512 PEER_CAP_ORF_PREFIX_SM_RCV,
12513 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12514 }
12515 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12516 || CHECK_FLAG(p->af_cap[afi][safi],
12517 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12518 || CHECK_FLAG(p->af_cap[afi][safi],
12519 PEER_CAP_ORF_PREFIX_RM_ADV)
12520 || CHECK_FLAG(p->af_cap[afi][safi],
12521 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12522 vty_out(vty,
12523 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12524 ORF_TYPE_PREFIX_OLD);
12525 bgp_show_peer_afi_orf_cap(
12526 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12527 PEER_CAP_ORF_PREFIX_RM_ADV,
12528 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12529 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12530 }
12531
772270f3
QY
12532 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12533 p->host, afi, safi);
d62a17ae 12534 orf_pfx_count = prefix_bgp_show_prefix_list(
12535 NULL, afi, orf_pfx_name, use_json);
12536
12537 if (CHECK_FLAG(p->af_sflags[afi][safi],
12538 PEER_STATUS_ORF_PREFIX_SEND)
12539 || orf_pfx_count) {
12540 vty_out(vty, " Outbound Route Filter (ORF):");
12541 if (CHECK_FLAG(p->af_sflags[afi][safi],
12542 PEER_STATUS_ORF_PREFIX_SEND))
12543 vty_out(vty, " sent;");
12544 if (orf_pfx_count)
12545 vty_out(vty, " received (%d entries)",
12546 orf_pfx_count);
12547 vty_out(vty, "\n");
12548 }
12549 if (CHECK_FLAG(p->af_sflags[afi][safi],
12550 PEER_STATUS_ORF_WAIT_REFRESH))
12551 vty_out(vty,
12552 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12553
12554 if (CHECK_FLAG(p->af_flags[afi][safi],
12555 PEER_FLAG_REFLECTOR_CLIENT))
12556 vty_out(vty, " Route-Reflector Client\n");
12557 if (CHECK_FLAG(p->af_flags[afi][safi],
12558 PEER_FLAG_RSERVER_CLIENT))
12559 vty_out(vty, " Route-Server Client\n");
70cd87ca
MK
12560
12561 if (peer_af_flag_check(p, afi, safi, PEER_FLAG_ORR_GROUP))
12562 vty_out(vty, " ORR group (configured) : %s\n",
12563 p->orr_group_name[afi][safi]);
12564
d62a17ae 12565 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12566 vty_out(vty,
12567 " Inbound soft reconfiguration allowed\n");
12568
12569 if (CHECK_FLAG(p->af_flags[afi][safi],
12570 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12571 vty_out(vty,
12572 " Private AS numbers (all) replaced in updates to this neighbor\n");
12573 else if (CHECK_FLAG(p->af_flags[afi][safi],
12574 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12575 vty_out(vty,
12576 " Private AS numbers replaced in updates to this neighbor\n");
12577 else if (CHECK_FLAG(p->af_flags[afi][safi],
12578 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12579 vty_out(vty,
12580 " Private AS numbers (all) removed in updates to this neighbor\n");
12581 else if (CHECK_FLAG(p->af_flags[afi][safi],
12582 PEER_FLAG_REMOVE_PRIVATE_AS))
12583 vty_out(vty,
12584 " Private AS numbers removed in updates to this neighbor\n");
12585
dcc68b5e
MS
12586 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12587 vty_out(vty, " %s\n",
12588 bgp_addpath_names(p->addpath_type[afi][safi])
12589 ->human_description);
d62a17ae 12590
12591 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12592 vty_out(vty,
12593 " Override ASNs in outbound updates if aspath equals remote-as\n");
12594
12595 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12596 || CHECK_FLAG(p->af_flags[afi][safi],
12597 PEER_FLAG_FORCE_NEXTHOP_SELF))
12598 vty_out(vty, " NEXT_HOP is always this router\n");
12599 if (CHECK_FLAG(p->af_flags[afi][safi],
12600 PEER_FLAG_AS_PATH_UNCHANGED))
12601 vty_out(vty,
12602 " AS_PATH is propagated unchanged to this neighbor\n");
12603 if (CHECK_FLAG(p->af_flags[afi][safi],
12604 PEER_FLAG_NEXTHOP_UNCHANGED))
12605 vty_out(vty,
12606 " NEXT_HOP is propagated unchanged to this neighbor\n");
12607 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12608 vty_out(vty,
12609 " MED is propagated unchanged to this neighbor\n");
12610 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12611 || CHECK_FLAG(p->af_flags[afi][safi],
12612 PEER_FLAG_SEND_EXT_COMMUNITY)
12613 || CHECK_FLAG(p->af_flags[afi][safi],
12614 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12615 vty_out(vty,
12616 " Community attribute sent to this neighbor");
12617 if (CHECK_FLAG(p->af_flags[afi][safi],
12618 PEER_FLAG_SEND_COMMUNITY)
12619 && CHECK_FLAG(p->af_flags[afi][safi],
12620 PEER_FLAG_SEND_EXT_COMMUNITY)
12621 && CHECK_FLAG(p->af_flags[afi][safi],
12622 PEER_FLAG_SEND_LARGE_COMMUNITY))
12623 vty_out(vty, "(all)\n");
12624 else if (CHECK_FLAG(p->af_flags[afi][safi],
12625 PEER_FLAG_SEND_LARGE_COMMUNITY))
12626 vty_out(vty, "(large)\n");
12627 else if (CHECK_FLAG(p->af_flags[afi][safi],
12628 PEER_FLAG_SEND_EXT_COMMUNITY))
12629 vty_out(vty, "(extended)\n");
12630 else
12631 vty_out(vty, "(standard)\n");
12632 }
12633 if (CHECK_FLAG(p->af_flags[afi][safi],
12634 PEER_FLAG_DEFAULT_ORIGINATE)) {
12635 vty_out(vty, " Default information originate,");
12636
12637 if (p->default_rmap[afi][safi].name)
12638 vty_out(vty, " default route-map %s%s,",
12639 p->default_rmap[afi][safi].map ? "*"
12640 : "",
12641 p->default_rmap[afi][safi].name);
12642 if (paf && PAF_SUBGRP(paf)
12643 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12644 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12645 vty_out(vty, " default sent\n");
12646 else
12647 vty_out(vty, " default not sent\n");
12648 }
12649
dff8f48d
MK
12650 /* advertise-vni-all */
12651 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12652 if (is_evpn_enabled())
dff8f48d
MK
12653 vty_out(vty, " advertise-all-vni\n");
12654 }
12655
d62a17ae 12656 if (filter->plist[FILTER_IN].name
12657 || filter->dlist[FILTER_IN].name
12658 || filter->aslist[FILTER_IN].name
12659 || filter->map[RMAP_IN].name)
12660 vty_out(vty, " Inbound path policy configured\n");
12661 if (filter->plist[FILTER_OUT].name
12662 || filter->dlist[FILTER_OUT].name
12663 || filter->aslist[FILTER_OUT].name
12664 || filter->map[RMAP_OUT].name || filter->usmap.name)
12665 vty_out(vty, " Outbound path policy configured\n");
12666
12667 /* prefix-list */
12668 if (filter->plist[FILTER_IN].name)
12669 vty_out(vty,
12670 " Incoming update prefix filter list is %s%s\n",
12671 filter->plist[FILTER_IN].plist ? "*" : "",
12672 filter->plist[FILTER_IN].name);
12673 if (filter->plist[FILTER_OUT].name)
12674 vty_out(vty,
12675 " Outgoing update prefix filter list is %s%s\n",
12676 filter->plist[FILTER_OUT].plist ? "*" : "",
12677 filter->plist[FILTER_OUT].name);
12678
12679 /* distribute-list */
12680 if (filter->dlist[FILTER_IN].name)
12681 vty_out(vty,
12682 " Incoming update network filter list is %s%s\n",
12683 filter->dlist[FILTER_IN].alist ? "*" : "",
12684 filter->dlist[FILTER_IN].name);
12685 if (filter->dlist[FILTER_OUT].name)
12686 vty_out(vty,
12687 " Outgoing update network filter list is %s%s\n",
12688 filter->dlist[FILTER_OUT].alist ? "*" : "",
12689 filter->dlist[FILTER_OUT].name);
12690
12691 /* filter-list. */
12692 if (filter->aslist[FILTER_IN].name)
12693 vty_out(vty,
12694 " Incoming update AS path filter list is %s%s\n",
12695 filter->aslist[FILTER_IN].aslist ? "*" : "",
12696 filter->aslist[FILTER_IN].name);
12697 if (filter->aslist[FILTER_OUT].name)
12698 vty_out(vty,
12699 " Outgoing update AS path filter list is %s%s\n",
12700 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12701 filter->aslist[FILTER_OUT].name);
12702
12703 /* route-map. */
12704 if (filter->map[RMAP_IN].name)
12705 vty_out(vty,
12706 " Route map for incoming advertisements is %s%s\n",
12707 filter->map[RMAP_IN].map ? "*" : "",
12708 filter->map[RMAP_IN].name);
12709 if (filter->map[RMAP_OUT].name)
12710 vty_out(vty,
12711 " Route map for outgoing advertisements is %s%s\n",
12712 filter->map[RMAP_OUT].map ? "*" : "",
12713 filter->map[RMAP_OUT].name);
12714
9dac9fc8 12715 /* ebgp-requires-policy (inbound) */
1d3fdccf 12716 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12717 && !bgp_inbound_policy_exists(p, filter))
12718 vty_out(vty,
12719 " Inbound updates discarded due to missing policy\n");
12720
12721 /* ebgp-requires-policy (outbound) */
1d3fdccf 12722 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12723 && !bgp_outbound_policy_exists(p, filter))
12724 vty_out(vty,
12725 " Outbound updates discarded due to missing policy\n");
12726
d62a17ae 12727 /* unsuppress-map */
12728 if (filter->usmap.name)
12729 vty_out(vty,
12730 " Route map for selective unsuppress is %s%s\n",
12731 filter->usmap.map ? "*" : "",
12732 filter->usmap.name);
12733
7f7940e6
MK
12734 /* advertise-map */
12735 if (filter->advmap.aname && filter->advmap.cname)
12736 vty_out(vty,
12737 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12738 filter->advmap.condition ? "EXIST"
12739 : "NON_EXIST",
12740 filter->advmap.cmap ? "*" : "",
12741 filter->advmap.cname,
12742 filter->advmap.amap ? "*" : "",
12743 filter->advmap.aname,
ecf2b628
QY
12744 filter->advmap.update_type ==
12745 UPDATE_TYPE_ADVERTISE
c385f82a
MK
12746 ? "Advertise"
12747 : "Withdraw");
7f7940e6 12748
d62a17ae 12749 /* Receive prefix count */
6cde4b45 12750 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12751 p->pcount[afi][safi]);
d62a17ae 12752
fde246e8
DA
12753 /* maximum-prefix-out */
12754 if (CHECK_FLAG(p->af_flags[afi][safi],
12755 PEER_FLAG_MAX_PREFIX_OUT))
12756 vty_out(vty,
6cde4b45 12757 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12758 p->pmax_out[afi][safi]);
12759
d62a17ae 12760 /* Maximum prefix */
12761 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12762 vty_out(vty,
6cde4b45 12763 " Maximum prefixes allowed %u%s\n",
d62a17ae 12764 p->pmax[afi][safi],
12765 CHECK_FLAG(p->af_flags[afi][safi],
12766 PEER_FLAG_MAX_PREFIX_WARNING)
12767 ? " (warning-only)"
12768 : "");
12769 vty_out(vty, " Threshold for warning message %d%%",
12770 p->pmax_threshold[afi][safi]);
12771 if (p->pmax_restart[afi][safi])
12772 vty_out(vty, ", restart interval %d min",
12773 p->pmax_restart[afi][safi]);
12774 vty_out(vty, "\n");
12775 }
12776
12777 vty_out(vty, "\n");
12778 }
12779}
12780
9f049418 12781static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12782 json_object *json)
718e3744 12783{
d62a17ae 12784 struct bgp *bgp;
47e12884 12785 char buf1[PREFIX2STR_BUFFER];
d62a17ae 12786 char timebuf[BGP_UPTIME_LEN];
12787 char dn_flag[2];
d62a17ae 12788 afi_t afi;
12789 safi_t safi;
d7c0a89a
QY
12790 uint16_t i;
12791 uint8_t *msg;
d62a17ae 12792 json_object *json_neigh = NULL;
12793 time_t epoch_tbuf;
4ab46701 12794 uint32_t sync_tcp_mss;
718e3744 12795
d62a17ae 12796 bgp = p->bgp;
12797
12798 if (use_json)
12799 json_neigh = json_object_new_object();
12800
12801 memset(dn_flag, '\0', sizeof(dn_flag));
12802 if (!p->conf_if && peer_dynamic_neighbor(p))
12803 dn_flag[0] = '*';
12804
12805 if (!use_json) {
12806 if (p->conf_if) /* Configured interface name. */
47e12884
DA
12807 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12808 &p->su);
d62a17ae 12809 else /* Configured IP address. */
12810 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12811 p->host);
12812 }
12813
12814 if (use_json) {
12815 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12816 json_object_string_add(json_neigh, "bgpNeighborAddr",
12817 "none");
12818 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
47e12884
DA
12819 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12820 "%pSU", &p->su);
d62a17ae 12821
12822 json_object_int_add(json_neigh, "remoteAs", p->as);
12823
12824 if (p->change_local_as)
12825 json_object_int_add(json_neigh, "localAs",
12826 p->change_local_as);
12827 else
12828 json_object_int_add(json_neigh, "localAs", p->local_as);
12829
12830 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12831 json_object_boolean_true_add(json_neigh,
12832 "localAsNoPrepend");
12833
12834 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12835 json_object_boolean_true_add(json_neigh,
12836 "localAsReplaceAs");
12837 } else {
12838 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12839 || (p->as_type == AS_INTERNAL))
12840 vty_out(vty, "remote AS %u, ", p->as);
12841 else
12842 vty_out(vty, "remote AS Unspecified, ");
12843 vty_out(vty, "local AS %u%s%s, ",
12844 p->change_local_as ? p->change_local_as : p->local_as,
12845 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12846 ? " no-prepend"
12847 : "",
12848 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12849 ? " replace-as"
12850 : "");
12851 }
faa16034
DS
12852 /* peer type internal or confed-internal */
12853 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12854 if (use_json) {
12855 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12856 json_object_boolean_true_add(
12857 json_neigh, "nbrConfedInternalLink");
12858 else
12859 json_object_boolean_true_add(json_neigh,
12860 "nbrInternalLink");
12861 } else {
12862 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12863 vty_out(vty, "confed-internal link\n");
12864 else
12865 vty_out(vty, "internal link\n");
12866 }
faa16034
DS
12867 /* peer type external or confed-external */
12868 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12869 if (use_json) {
12870 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12871 json_object_boolean_true_add(
12872 json_neigh, "nbrConfedExternalLink");
12873 else
12874 json_object_boolean_true_add(json_neigh,
12875 "nbrExternalLink");
12876 } else {
12877 if (bgp_confederation_peers_check(bgp, p->as))
12878 vty_out(vty, "confed-external link\n");
12879 else
12880 vty_out(vty, "external link\n");
12881 }
faa16034
DS
12882 } else {
12883 if (use_json)
12884 json_object_boolean_true_add(json_neigh,
12885 "nbrUnspecifiedLink");
12886 else
12887 vty_out(vty, "unspecified link\n");
d62a17ae 12888 }
12889
d864dd9e
EB
12890 /* Roles */
12891 if (use_json) {
12892 json_object_string_add(json_neigh, "localRole",
8f2d6021
EB
12893 bgp_get_name_by_role(p->local_role));
12894 json_object_string_add(json_neigh, "remoteRole",
12895 bgp_get_name_by_role(p->remote_role));
d864dd9e
EB
12896 } else {
12897 vty_out(vty, " Local Role: %s\n",
8f2d6021
EB
12898 bgp_get_name_by_role(p->local_role));
12899 vty_out(vty, " Remote Role: %s\n",
12900 bgp_get_name_by_role(p->remote_role));
d864dd9e
EB
12901 }
12902
12903
d62a17ae 12904 /* Description. */
12905 if (p->desc) {
12906 if (use_json)
12907 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12908 else
12909 vty_out(vty, " Description: %s\n", p->desc);
12910 }
12911
12912 if (p->hostname) {
12913 if (use_json) {
12914 if (p->hostname)
12915 json_object_string_add(json_neigh, "hostname",
12916 p->hostname);
12917
12918 if (p->domainname)
12919 json_object_string_add(json_neigh, "domainname",
12920 p->domainname);
12921 } else {
12922 if (p->domainname && (p->domainname[0] != '\0'))
12923 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12924 p->domainname);
12925 else
12926 vty_out(vty, "Hostname: %s\n", p->hostname);
12927 }
12928 }
12929
12930 /* Peer-group */
12931 if (p->group) {
12932 if (use_json) {
12933 json_object_string_add(json_neigh, "peerGroup",
12934 p->group->name);
12935
12936 if (dn_flag[0]) {
12937 struct prefix prefix, *range = NULL;
12938
0154d8ce
DS
12939 if (sockunion2hostprefix(&(p->su), &prefix))
12940 range = peer_group_lookup_dynamic_neighbor_range(
12941 p->group, &prefix);
d62a17ae 12942
12943 if (range) {
67d7e256 12944 json_object_string_addf(
d62a17ae 12945 json_neigh,
67d7e256
DA
12946 "peerSubnetRangeGroup", "%pFX",
12947 range);
d62a17ae 12948 }
12949 }
12950 } else {
12951 vty_out(vty,
12952 " Member of peer-group %s for session parameters\n",
12953 p->group->name);
12954
12955 if (dn_flag[0]) {
12956 struct prefix prefix, *range = NULL;
12957
0154d8ce
DS
12958 if (sockunion2hostprefix(&(p->su), &prefix))
12959 range = peer_group_lookup_dynamic_neighbor_range(
12960 p->group, &prefix);
d62a17ae 12961
12962 if (range) {
d62a17ae 12963 vty_out(vty,
1b78780b
DL
12964 " Belongs to the subnet range group: %pFX\n",
12965 range);
d62a17ae 12966 }
12967 }
12968 }
12969 }
12970
12971 if (use_json) {
12972 /* Administrative shutdown. */
cb9196e7
DS
12973 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12974 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12975 json_object_boolean_true_add(json_neigh,
12976 "adminShutDown");
12977
12978 /* BGP Version. */
12979 json_object_int_add(json_neigh, "bgpVersion", 4);
c949c771
DA
12980 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12981 &p->remote_id);
12982 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12983 &bgp->router_id);
d62a17ae 12984
12985 /* Confederation */
12986 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12987 && bgp_confederation_peers_check(bgp, p->as))
12988 json_object_boolean_true_add(json_neigh,
12989 "nbrCommonAdmin");
12990
12991 /* Status. */
12992 json_object_string_add(
12993 json_neigh, "bgpState",
12994 lookup_msg(bgp_status_msg, p->status, NULL));
12995
feb17238 12996 if (peer_established(p)) {
d62a17ae 12997 time_t uptime;
d62a17ae 12998
083ec940 12999 uptime = monotime(NULL);
d62a17ae 13000 uptime -= p->uptime;
d62a17ae 13001 epoch_tbuf = time(NULL) - uptime;
13002
d3c7efed
DS
13003 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13004 uptime * 1000);
d62a17ae 13005 json_object_string_add(json_neigh, "bgpTimerUpString",
13006 peer_uptime(p->uptime, timebuf,
13007 BGP_UPTIME_LEN, 0,
13008 NULL));
13009 json_object_int_add(json_neigh,
13010 "bgpTimerUpEstablishedEpoch",
13011 epoch_tbuf);
13012 }
13013
13014 else if (p->status == Active) {
13015 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13016 json_object_string_add(json_neigh, "bgpStateIs",
13017 "passive");
13018 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13019 json_object_string_add(json_neigh, "bgpStateIs",
13020 "passiveNSF");
13021 }
13022
13023 /* read timer */
13024 time_t uptime;
a2700b50 13025 struct tm tm;
d62a17ae 13026
083ec940 13027 uptime = monotime(NULL);
d62a17ae 13028 uptime -= p->readtime;
a2700b50
MS
13029 gmtime_r(&uptime, &tm);
13030
d62a17ae 13031 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
13032 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13033 + (tm.tm_hour * 3600000));
d62a17ae 13034
083ec940 13035 uptime = monotime(NULL);
d62a17ae 13036 uptime -= p->last_write;
a2700b50
MS
13037 gmtime_r(&uptime, &tm);
13038
d62a17ae 13039 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
13040 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13041 + (tm.tm_hour * 3600000));
d62a17ae 13042
083ec940 13043 uptime = monotime(NULL);
d62a17ae 13044 uptime -= p->update_time;
a2700b50
MS
13045 gmtime_r(&uptime, &tm);
13046
d62a17ae 13047 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
13048 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13049 + (tm.tm_hour * 3600000));
d62a17ae 13050
13051 /* Configured timer values. */
9b1b9623
TA
13052 json_object_int_add(json_neigh,
13053 "bgpTimerConfiguredHoldTimeMsecs",
e93d5c29
TA
13054 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13055 ? p->holdtime * 1000
13056 : bgp->default_holdtime * 1000);
13057 json_object_int_add(json_neigh,
13058 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13059 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13060 ? p->keepalive * 1000
13061 : bgp->default_keepalive * 1000);
d62a17ae 13062 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13063 p->v_holdtime * 1000);
13064 json_object_int_add(json_neigh,
13065 "bgpTimerKeepAliveIntervalMsecs",
13066 p->v_keepalive * 1000);
d43114f3
DS
13067 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13068 json_object_int_add(json_neigh,
13069 "bgpTimerDelayOpenTimeMsecs",
13070 p->v_delayopen * 1000);
13071 }
13072
4ab46701
AR
13073 /* Configured and Synced tcp-mss value for peer */
13074 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13075 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13076 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13077 p->tcp_mss);
13078 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13079 sync_tcp_mss);
13080 }
13081
d08c0c80
DA
13082 /* Extended Optional Parameters Length for BGP OPEN Message */
13083 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13084 json_object_boolean_true_add(
13085 json_neigh, "extendedOptionalParametersLength");
13086 else
13087 json_object_boolean_false_add(
13088 json_neigh, "extendedOptionalParametersLength");
6e37924b
DA
13089
13090 /* Conditional advertisements */
13091 json_object_int_add(
13092 json_neigh,
13093 "bgpTimerConfiguredConditionalAdvertisementsSec",
13094 bgp->condition_check_period);
13095 if (thread_is_scheduled(bgp->t_condition_check))
13096 json_object_int_add(
13097 json_neigh,
13098 "bgpTimerUntilConditionalAdvertisementsSec",
13099 thread_timer_remain_second(
13100 bgp->t_condition_check));
d62a17ae 13101 } else {
13102 /* Administrative shutdown. */
cb9196e7
DS
13103 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13104 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13105 vty_out(vty, " Administratively shut down\n");
13106
13107 /* BGP Version. */
13108 vty_out(vty, " BGP version 4");
0e38aeb4 13109 vty_out(vty, ", remote router ID %s",
d62a17ae 13110 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
13111 vty_out(vty, ", local router ID %s\n",
13112 inet_ntop(AF_INET, &bgp->router_id, buf1,
13113 sizeof(buf1)));
d62a17ae 13114
13115 /* Confederation */
13116 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13117 && bgp_confederation_peers_check(bgp, p->as))
13118 vty_out(vty,
13119 " Neighbor under common administration\n");
13120
13121 /* Status. */
13122 vty_out(vty, " BGP state = %s",
13123 lookup_msg(bgp_status_msg, p->status, NULL));
13124
feb17238 13125 if (peer_established(p))
d62a17ae 13126 vty_out(vty, ", up for %8s",
13127 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13128 0, NULL));
13129
13130 else if (p->status == Active) {
13131 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13132 vty_out(vty, " (passive)");
13133 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13134 vty_out(vty, " (NSF passive)");
13135 }
13136 vty_out(vty, "\n");
13137
13138 /* read timer */
13139 vty_out(vty, " Last read %s",
13140 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13141 NULL));
13142 vty_out(vty, ", Last write %s\n",
13143 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13144 NULL));
13145
13146 /* Configured timer values. */
13147 vty_out(vty,
e93d5c29 13148 " Hold time is %d seconds, keepalive interval is %d seconds\n",
d62a17ae 13149 p->v_holdtime, p->v_keepalive);
e93d5c29
TA
13150 vty_out(vty, " Configured hold time is %d seconds",
13151 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13152 ? p->holdtime
13153 : bgp->default_holdtime);
9b1b9623 13154 vty_out(vty, ", keepalive interval is %d seconds\n",
e93d5c29
TA
13155 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13156 ? p->keepalive
13157 : bgp->default_keepalive);
d43114f3
DS
13158 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13159 vty_out(vty,
13160 " Configured DelayOpenTime is %d seconds\n",
13161 p->delayopen);
4ab46701
AR
13162
13163 /* Configured and synced tcp-mss value for peer */
13164 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13165 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13166 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13167 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13168 }
d08c0c80
DA
13169
13170 /* Extended Optional Parameters Length for BGP OPEN Message */
13171 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13172 vty_out(vty,
13173 " Extended Optional Parameters Length is enabled\n");
6e37924b
DA
13174
13175 /* Conditional advertisements */
13176 vty_out(vty,
13177 " Configured conditional advertisements interval is %d seconds\n",
13178 bgp->condition_check_period);
13179 if (thread_is_scheduled(bgp->t_condition_check))
13180 vty_out(vty,
13181 " Time until conditional advertisements begin is %lu seconds\n",
13182 thread_timer_remain_second(
13183 bgp->t_condition_check));
d62a17ae 13184 }
13185 /* Capability. */
10711563
DA
13186 if (peer_established(p) &&
13187 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13188 if (use_json) {
13189 json_object *json_cap = NULL;
d62a17ae 13190
10711563 13191 json_cap = json_object_new_object();
d62a17ae 13192
10711563
DA
13193 /* AS4 */
13194 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13195 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13196 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13197 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
ef56aee4 13198 json_object_string_add(
10711563 13199 json_cap, "4byteAs",
ef56aee4 13200 "advertisedAndReceived");
10711563
DA
13201 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13202 json_object_string_add(json_cap,
13203 "4byteAs",
13204 "advertised");
13205 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13206 json_object_string_add(json_cap,
13207 "4byteAs",
13208 "received");
13209 }
ef56aee4 13210
10711563
DA
13211 /* Extended Message Support */
13212 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13213 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13214 json_object_string_add(json_cap,
13215 "extendedMessage",
13216 "advertisedAndReceived");
13217 else if (CHECK_FLAG(p->cap,
13218 PEER_CAP_EXTENDED_MESSAGE_ADV))
13219 json_object_string_add(json_cap,
13220 "extendedMessage",
13221 "advertised");
13222 else if (CHECK_FLAG(p->cap,
13223 PEER_CAP_EXTENDED_MESSAGE_RCV))
13224 json_object_string_add(json_cap,
13225 "extendedMessage",
13226 "received");
ef56aee4 13227
10711563
DA
13228 /* AddPath */
13229 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13230 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13231 json_object *json_add = NULL;
13232 const char *print_store;
d62a17ae 13233
10711563 13234 json_add = json_object_new_object();
d62a17ae 13235
10711563
DA
13236 FOREACH_AFI_SAFI (afi, safi) {
13237 json_object *json_sub = NULL;
13238 json_sub = json_object_new_object();
13239 print_store = get_afi_safi_str(
13240 afi, safi, true);
d62a17ae 13241
10711563
DA
13242 if (CHECK_FLAG(
13243 p->af_cap[afi][safi],
13244 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13245 CHECK_FLAG(
13246 p->af_cap[afi][safi],
13247 PEER_CAP_ADDPATH_AF_TX_RCV)) {
05c7a1cc
QY
13248 if (CHECK_FLAG(
13249 p->af_cap[afi]
13250 [safi],
10711563
DA
13251 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13252 CHECK_FLAG(
05c7a1cc
QY
13253 p->af_cap[afi]
13254 [safi],
10711563
DA
13255 PEER_CAP_ADDPATH_AF_TX_RCV))
13256 json_object_boolean_true_add(
13257 json_sub,
13258 "txAdvertisedAndReceived");
13259 else if (
13260 CHECK_FLAG(
13261 p->af_cap[afi]
13262 [safi],
13263 PEER_CAP_ADDPATH_AF_TX_ADV))
13264 json_object_boolean_true_add(
13265 json_sub,
13266 "txAdvertised");
13267 else if (
13268 CHECK_FLAG(
13269 p->af_cap[afi]
13270 [safi],
13271 PEER_CAP_ADDPATH_AF_TX_RCV))
13272 json_object_boolean_true_add(
13273 json_sub,
13274 "txReceived");
13275 }
d62a17ae 13276
10711563
DA
13277 if (CHECK_FLAG(
13278 p->af_cap[afi][safi],
13279 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13280 CHECK_FLAG(
13281 p->af_cap[afi][safi],
13282 PEER_CAP_ADDPATH_AF_RX_RCV)) {
05c7a1cc
QY
13283 if (CHECK_FLAG(
13284 p->af_cap[afi]
13285 [safi],
10711563
DA
13286 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13287 CHECK_FLAG(
13288 p->af_cap[afi]
13289 [safi],
13290 PEER_CAP_ADDPATH_AF_RX_RCV))
13291 json_object_boolean_true_add(
13292 json_sub,
13293 "rxAdvertisedAndReceived");
13294 else if (
13295 CHECK_FLAG(
13296 p->af_cap[afi]
13297 [safi],
13298 PEER_CAP_ADDPATH_AF_RX_ADV))
13299 json_object_boolean_true_add(
13300 json_sub,
13301 "rxAdvertised");
13302 else if (
13303 CHECK_FLAG(
13304 p->af_cap[afi]
13305 [safi],
13306 PEER_CAP_ADDPATH_AF_RX_RCV))
13307 json_object_boolean_true_add(
13308 json_sub,
13309 "rxReceived");
05c7a1cc
QY
13310 }
13311
10711563
DA
13312 if (CHECK_FLAG(
13313 p->af_cap[afi][safi],
13314 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13315 CHECK_FLAG(
13316 p->af_cap[afi][safi],
13317 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13318 CHECK_FLAG(
13319 p->af_cap[afi][safi],
13320 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13321 CHECK_FLAG(
13322 p->af_cap[afi][safi],
13323 PEER_CAP_ADDPATH_AF_RX_RCV))
13324 json_object_object_add(
13325 json_add, print_store,
13326 json_sub);
13327 else
13328 json_object_free(json_sub);
d62a17ae 13329 }
13330
10711563
DA
13331 json_object_object_add(json_cap, "addPath",
13332 json_add);
13333 }
d62a17ae 13334
10711563
DA
13335 /* Dynamic */
13336 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13337 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13338 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13339 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13340 json_object_string_add(
13341 json_cap, "dynamic",
13342 "advertisedAndReceived");
13343 else if (CHECK_FLAG(p->cap,
13344 PEER_CAP_DYNAMIC_ADV))
13345 json_object_string_add(json_cap,
13346 "dynamic",
13347 "advertised");
13348 else if (CHECK_FLAG(p->cap,
13349 PEER_CAP_DYNAMIC_RCV))
13350 json_object_string_add(json_cap,
13351 "dynamic",
13352 "received");
13353 }
d62a17ae 13354
d864dd9e
EB
13355 /* Role */
13356 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13357 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13358 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13359 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13360 json_object_string_add(
13361 json_cap, "role",
13362 "advertisedAndReceived");
13363 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13364 json_object_string_add(json_cap, "role",
13365 "advertised");
13366 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13367 json_object_string_add(json_cap, "role",
13368 "received");
13369 }
13370
10711563
DA
13371 /* Extended nexthop */
13372 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13373 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13374 json_object *json_nxt = NULL;
13375 const char *print_store;
d62a17ae 13376
d62a17ae 13377
10711563
DA
13378 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13379 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13380 json_object_string_add(
13381 json_cap, "extendedNexthop",
13382 "advertisedAndReceived");
13383 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13384 json_object_string_add(
13385 json_cap, "extendedNexthop",
13386 "advertised");
13387 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13388 json_object_string_add(
13389 json_cap, "extendedNexthop",
13390 "received");
d62a17ae 13391
10711563
DA
13392 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13393 json_nxt = json_object_new_object();
d62a17ae 13394
10711563
DA
13395 for (safi = SAFI_UNICAST;
13396 safi < SAFI_MAX; safi++) {
13397 if (CHECK_FLAG(
13398 p->af_cap[AFI_IP]
13399 [safi],
13400 PEER_CAP_ENHE_AF_RCV)) {
13401 print_store =
13402 get_afi_safi_str(
d62a17ae 13403 AFI_IP,
10711563
DA
13404 safi,
13405 true);
13406 json_object_string_add(
13407 json_nxt,
13408 print_store,
13409 "recieved"); /* misspelled for compatibility */
d62a17ae 13410 }
d62a17ae 13411 }
10711563
DA
13412 json_object_object_add(
13413 json_cap,
13414 "extendedNexthopFamililesByPeer",
13415 json_nxt);
d62a17ae 13416 }
10711563 13417 }
d62a17ae 13418
10711563
DA
13419 /* Long-lived Graceful Restart */
13420 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13421 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13422 json_object *json_llgr = NULL;
13423 const char *afi_safi_str;
8606be87 13424
10711563
DA
13425 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13426 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13427 json_object_string_add(
13428 json_cap,
13429 "longLivedGracefulRestart",
13430 "advertisedAndReceived");
13431 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13432 json_object_string_add(
13433 json_cap,
13434 "longLivedGracefulRestart",
13435 "advertised");
13436 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13437 json_object_string_add(
13438 json_cap,
13439 "longLivedGracefulRestart",
13440 "received");
8606be87 13441
10711563
DA
13442 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13443 json_llgr = json_object_new_object();
8606be87 13444
10711563
DA
13445 FOREACH_AFI_SAFI (afi, safi) {
13446 if (CHECK_FLAG(
13447 p->af_cap[afi]
13448 [safi],
13449 PEER_CAP_ENHE_AF_RCV)) {
13450 afi_safi_str =
13451 get_afi_safi_str(
8606be87
DA
13452 afi,
13453 safi,
13454 true);
10711563
DA
13455 json_object_string_add(
13456 json_llgr,
13457 afi_safi_str,
13458 "received");
8606be87 13459 }
8606be87 13460 }
10711563
DA
13461 json_object_object_add(
13462 json_cap,
13463 "longLivedGracefulRestartByPeer",
13464 json_llgr);
8606be87 13465 }
10711563 13466 }
8606be87 13467
10711563
DA
13468 /* Route Refresh */
13469 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13470 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13471 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13472 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13473 (CHECK_FLAG(p->cap,
13474 PEER_CAP_REFRESH_NEW_RCV) ||
13475 CHECK_FLAG(p->cap,
13476 PEER_CAP_REFRESH_OLD_RCV))) {
13477 if (CHECK_FLAG(
13478 p->cap,
13479 PEER_CAP_REFRESH_OLD_RCV) &&
13480 CHECK_FLAG(
13481 p->cap,
13482 PEER_CAP_REFRESH_NEW_RCV))
13483 json_object_string_add(
13484 json_cap,
13485 "routeRefresh",
13486 "advertisedAndReceivedOldNew");
13487 else {
d62a17ae 13488 if (CHECK_FLAG(
13489 p->cap,
10711563 13490 PEER_CAP_REFRESH_OLD_RCV))
d62a17ae 13491 json_object_string_add(
13492 json_cap,
13493 "routeRefresh",
10711563
DA
13494 "advertisedAndReceivedOld");
13495 else
13496 json_object_string_add(
13497 json_cap,
13498 "routeRefresh",
13499 "advertisedAndReceivedNew");
d62a17ae 13500 }
10711563
DA
13501 } else if (CHECK_FLAG(p->cap,
13502 PEER_CAP_REFRESH_ADV))
13503 json_object_string_add(json_cap,
13504 "routeRefresh",
13505 "advertised");
13506 else if (CHECK_FLAG(p->cap,
13507 PEER_CAP_REFRESH_NEW_RCV) ||
13508 CHECK_FLAG(p->cap,
13509 PEER_CAP_REFRESH_OLD_RCV))
13510 json_object_string_add(json_cap,
13511 "routeRefresh",
13512 "received");
13513 }
d62a17ae 13514
10711563
DA
13515 /* Enhanced Route Refresh */
13516 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13517 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13518 if (CHECK_FLAG(p->cap,
13519 PEER_CAP_ENHANCED_RR_ADV) &&
13520 CHECK_FLAG(p->cap,
13521 PEER_CAP_ENHANCED_RR_RCV))
d77114b7 13522 json_object_string_add(
10711563
DA
13523 json_cap,
13524 "enhancedRouteRefresh",
13525 "advertisedAndReceived");
13526 else if (CHECK_FLAG(p->cap,
13527 PEER_CAP_ENHANCED_RR_ADV))
d77114b7 13528 json_object_string_add(
10711563
DA
13529 json_cap,
13530 "enhancedRouteRefresh",
13531 "advertised");
13532 else if (CHECK_FLAG(p->cap,
9af52ccf 13533 PEER_CAP_ENHANCED_RR_RCV))
10711563
DA
13534 json_object_string_add(
13535 json_cap,
13536 "enhancedRouteRefresh",
13537 "received");
13538 }
d77114b7 13539
10711563
DA
13540 /* Multiprotocol Extensions */
13541 json_object *json_multi = NULL;
d77114b7 13542
10711563 13543 json_multi = json_object_new_object();
d77114b7 13544
10711563
DA
13545 FOREACH_AFI_SAFI (afi, safi) {
13546 if (p->afc_adv[afi][safi] ||
13547 p->afc_recv[afi][safi]) {
13548 json_object *json_exten = NULL;
13549 json_exten = json_object_new_object();
13550
13551 if (p->afc_adv[afi][safi] &&
13552 p->afc_recv[afi][safi])
13553 json_object_boolean_true_add(
13554 json_exten,
9af52ccf 13555 "advertisedAndReceived");
10711563
DA
13556 else if (p->afc_adv[afi][safi])
13557 json_object_boolean_true_add(
13558 json_exten,
9af52ccf 13559 "advertised");
10711563
DA
13560 else if (p->afc_recv[afi][safi])
13561 json_object_boolean_true_add(
13562 json_exten, "received");
9af52ccf 13563
10711563
DA
13564 json_object_object_add(
13565 json_multi,
13566 get_afi_safi_str(afi, safi,
13567 true),
13568 json_exten);
13569 }
13570 }
13571 json_object_object_add(json_cap,
13572 "multiprotocolExtensions",
13573 json_multi);
d62a17ae 13574
10711563
DA
13575 /* Hostname capabilities */
13576 json_object *json_hname = NULL;
d62a17ae 13577
10711563 13578 json_hname = json_object_new_object();
d62a17ae 13579
10711563
DA
13580 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13581 json_object_string_add(
13582 json_hname, "advHostName",
13583 bgp->peer_self->hostname
13584 ? bgp->peer_self->hostname
13585 : "n/a");
13586 json_object_string_add(
13587 json_hname, "advDomainName",
13588 bgp->peer_self->domainname
13589 ? bgp->peer_self->domainname
13590 : "n/a");
13591 }
d77114b7 13592
d77114b7 13593
10711563
DA
13594 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13595 json_object_string_add(
13596 json_hname, "rcvHostName",
13597 p->hostname ? p->hostname : "n/a");
13598 json_object_string_add(
13599 json_hname, "rcvDomainName",
13600 p->domainname ? p->domainname : "n/a");
13601 }
d77114b7 13602
10711563
DA
13603 json_object_object_add(json_cap, "hostName",
13604 json_hname);
d77114b7 13605
17be83bf 13606 /* Graceful Restart */
10711563
DA
13607 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13608 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13609 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13610 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
d77114b7 13611 json_object_string_add(
10711563
DA
13612 json_cap, "gracefulRestart",
13613 "advertisedAndReceived");
13614 else if (CHECK_FLAG(p->cap,
13615 PEER_CAP_RESTART_ADV))
d77114b7 13616 json_object_string_add(
10711563
DA
13617 json_cap,
13618 "gracefulRestartCapability",
13619 "advertised");
13620 else if (CHECK_FLAG(p->cap,
13621 PEER_CAP_RESTART_RCV))
13622 json_object_string_add(
13623 json_cap,
13624 "gracefulRestartCapability",
13625 "received");
d77114b7 13626
10711563
DA
13627 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13628 int restart_af_count = 0;
13629 json_object *json_restart = NULL;
13630 json_restart = json_object_new_object();
d62a17ae 13631
10711563
DA
13632 json_object_int_add(
13633 json_cap,
13634 "gracefulRestartRemoteTimerMsecs",
13635 p->v_gr_restart * 1000);
d62a17ae 13636
10711563 13637 FOREACH_AFI_SAFI (afi, safi) {
05c7a1cc
QY
13638 if (CHECK_FLAG(
13639 p->af_cap[afi]
13640 [safi],
10711563
DA
13641 PEER_CAP_RESTART_AF_RCV)) {
13642 json_object *json_sub =
13643 NULL;
13644 json_sub =
13645 json_object_new_object();
d62a17ae 13646
05c7a1cc
QY
13647 if (CHECK_FLAG(
13648 p->af_cap
13649 [afi]
13650 [safi],
10711563
DA
13651 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13652 json_object_boolean_true_add(
13653 json_sub,
13654 "preserved");
13655 restart_af_count++;
d62a17ae 13656 json_object_object_add(
10711563
DA
13657 json_restart,
13658 get_afi_safi_str(
13659 afi,
13660 safi,
13661 true),
13662 json_sub);
d62a17ae 13663 }
d62a17ae 13664 }
10711563
DA
13665 if (!restart_af_count) {
13666 json_object_string_add(
13667 json_cap,
13668 "addressFamiliesByPeer",
13669 "none");
13670 json_object_free(json_restart);
13671 } else
13672 json_object_object_add(
13673 json_cap,
13674 "addressFamiliesByPeer",
13675 json_restart);
d62a17ae 13676 }
10711563
DA
13677 }
13678 json_object_object_add(
13679 json_neigh, "neighborCapabilities", json_cap);
13680 } else {
13681 vty_out(vty, " Neighbor capabilities:\n");
13682
13683 /* AS4 */
13684 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13685 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13686 vty_out(vty, " 4 Byte AS:");
13687 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13688 vty_out(vty, " advertised");
13689 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13690 vty_out(vty, " %sreceived",
13691 CHECK_FLAG(p->cap,
13692 PEER_CAP_AS4_ADV)
13693 ? "and "
13694 : "");
13695 vty_out(vty, "\n");
13696 }
d62a17ae 13697
10711563
DA
13698 /* Extended Message Support */
13699 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13700 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13701 vty_out(vty, " Extended Message:");
ef56aee4 13702 if (CHECK_FLAG(p->cap,
10711563
DA
13703 PEER_CAP_EXTENDED_MESSAGE_ADV))
13704 vty_out(vty, " advertised");
13705 if (CHECK_FLAG(p->cap,
13706 PEER_CAP_EXTENDED_MESSAGE_RCV))
13707 vty_out(vty, " %sreceived",
13708 CHECK_FLAG(
13709 p->cap,
13710 PEER_CAP_EXTENDED_MESSAGE_ADV)
13711 ? "and "
13712 : "");
13713 vty_out(vty, "\n");
13714 }
d62a17ae 13715
10711563
DA
13716 /* AddPath */
13717 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13718 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13719 vty_out(vty, " AddPath:\n");
d62a17ae 13720
10711563 13721 FOREACH_AFI_SAFI (afi, safi) {
ef56aee4 13722 if (CHECK_FLAG(
10711563
DA
13723 p->af_cap[afi][safi],
13724 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13725 CHECK_FLAG(
13726 p->af_cap[afi][safi],
13727 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13728 vty_out(vty, " %s: TX ",
13729 get_afi_safi_str(
13730 afi, safi,
13731 false));
ef56aee4 13732
10711563
DA
13733 if (CHECK_FLAG(
13734 p->af_cap[afi]
13735 [safi],
13736 PEER_CAP_ADDPATH_AF_TX_ADV))
13737 vty_out(vty,
13738 "advertised");
d62a17ae 13739
05c7a1cc
QY
13740 if (CHECK_FLAG(
13741 p->af_cap[afi]
13742 [safi],
10711563 13743 PEER_CAP_ADDPATH_AF_TX_RCV))
05c7a1cc 13744 vty_out(vty,
10711563
DA
13745 "%sreceived",
13746 CHECK_FLAG(
13747 p->af_cap
13748 [afi]
13749 [safi],
13750 PEER_CAP_ADDPATH_AF_TX_ADV)
13751 ? " and "
13752 : "");
05c7a1cc 13753
10711563
DA
13754 vty_out(vty, "\n");
13755 }
d62a17ae 13756
9af52ccf 13757 if (CHECK_FLAG(
10711563
DA
13758 p->af_cap[afi][safi],
13759 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13760 CHECK_FLAG(
13761 p->af_cap[afi][safi],
13762 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13763 vty_out(vty, " %s: RX ",
5cb5f4d0 13764 get_afi_safi_str(
10711563
DA
13765 afi, safi,
13766 false));
d62a17ae 13767
05c7a1cc
QY
13768 if (CHECK_FLAG(
13769 p->af_cap[afi]
13770 [safi],
10711563 13771 PEER_CAP_ADDPATH_AF_RX_ADV))
05c7a1cc 13772 vty_out(vty,
10711563 13773 "advertised");
d62a17ae 13774
10711563
DA
13775 if (CHECK_FLAG(
13776 p->af_cap[afi]
13777 [safi],
13778 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc 13779 vty_out(vty,
10711563
DA
13780 "%sreceived",
13781 CHECK_FLAG(
13782 p->af_cap
13783 [afi]
13784 [safi],
13785 PEER_CAP_ADDPATH_AF_RX_ADV)
13786 ? " and "
05c7a1cc 13787 : "");
d62a17ae 13788
05c7a1cc 13789 vty_out(vty, "\n");
05c7a1cc 13790 }
d62a17ae 13791 }
10711563 13792 }
d62a17ae 13793
10711563
DA
13794 /* Dynamic */
13795 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13796 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13797 vty_out(vty, " Dynamic:");
13798 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13799 vty_out(vty, " advertised");
13800 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13801 vty_out(vty, " %sreceived",
13802 CHECK_FLAG(p->cap,
13803 PEER_CAP_DYNAMIC_ADV)
13804 ? "and "
13805 : "");
13806 vty_out(vty, "\n");
13807 }
d62a17ae 13808
d864dd9e
EB
13809 /* Role */
13810 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13811 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13812 vty_out(vty, " Role:");
13813 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13814 vty_out(vty, " advertised");
13815 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13816 vty_out(vty, " %sreceived",
13817 CHECK_FLAG(p->cap,
13818 PEER_CAP_ROLE_ADV)
13819 ? "and "
13820 : "");
13821 vty_out(vty, "\n");
13822 }
13823
10711563
DA
13824 /* Extended nexthop */
13825 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13826 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13827 vty_out(vty, " Extended nexthop:");
13828 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13829 vty_out(vty, " advertised");
13830 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13831 vty_out(vty, " %sreceived",
13832 CHECK_FLAG(p->cap,
13833 PEER_CAP_ENHE_ADV)
13834 ? "and "
13835 : "");
13836 vty_out(vty, "\n");
d62a17ae 13837
10711563 13838 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
57f7feb6 13839 vty_out(vty,
10711563
DA
13840 " Address families by peer:\n ");
13841 for (safi = SAFI_UNICAST;
13842 safi < SAFI_MAX; safi++)
13843 if (CHECK_FLAG(
13844 p->af_cap[AFI_IP]
13845 [safi],
13846 PEER_CAP_ENHE_AF_RCV))
13847 vty_out(vty,
13848 " %s\n",
13849 get_afi_safi_str(
13850 AFI_IP,
13851 safi,
13852 false));
d62a17ae 13853 }
10711563 13854 }
d62a17ae 13855
10711563
DA
13856 /* Long-lived Graceful Restart */
13857 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13858 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13859 vty_out(vty,
13860 " Long-lived Graceful Restart:");
13861 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13862 vty_out(vty, " advertised");
13863 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13864 vty_out(vty, " %sreceived",
13865 CHECK_FLAG(p->cap,
13866 PEER_CAP_LLGR_ADV)
13867 ? "and "
13868 : "");
13869 vty_out(vty, "\n");
8606be87 13870
10711563 13871 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
57f7feb6 13872 vty_out(vty,
10711563
DA
13873 " Address families by peer:\n");
13874 FOREACH_AFI_SAFI (afi, safi)
13875 if (CHECK_FLAG(
13876 p->af_cap[afi]
13877 [safi],
13878 PEER_CAP_LLGR_AF_RCV))
13879 vty_out(vty,
13880 " %s\n",
13881 get_afi_safi_str(
13882 afi,
13883 safi,
13884 false));
8606be87 13885 }
10711563 13886 }
8606be87 13887
10711563
DA
13888 /* Route Refresh */
13889 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13890 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13891 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13892 vty_out(vty, " Route refresh:");
13893 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13894 vty_out(vty, " advertised");
13895 if (CHECK_FLAG(p->cap,
13896 PEER_CAP_REFRESH_NEW_RCV) ||
13897 CHECK_FLAG(p->cap,
13898 PEER_CAP_REFRESH_OLD_RCV))
13899 vty_out(vty, " %sreceived(%s)",
13900 CHECK_FLAG(p->cap,
13901 PEER_CAP_REFRESH_ADV)
13902 ? "and "
13903 : "",
13904 (CHECK_FLAG(
13905 p->cap,
13906 PEER_CAP_REFRESH_OLD_RCV) &&
13907 CHECK_FLAG(
13908 p->cap,
13909 PEER_CAP_REFRESH_NEW_RCV))
13910 ? "old & new"
13911 : CHECK_FLAG(
13912 p->cap,
13913 PEER_CAP_REFRESH_OLD_RCV)
13914 ? "old"
13915 : "new");
d62a17ae 13916
d77114b7 13917 vty_out(vty, "\n");
10711563 13918 }
d62a17ae 13919
10711563
DA
13920 /* Enhanced Route Refresh */
13921 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13922 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13923 vty_out(vty, " Enhanced Route Refresh:");
13924 if (CHECK_FLAG(p->cap,
13925 PEER_CAP_ENHANCED_RR_ADV))
13926 vty_out(vty, " advertised");
13927 if (CHECK_FLAG(p->cap,
13928 PEER_CAP_ENHANCED_RR_RCV))
13929 vty_out(vty, " %sreceived",
13930 CHECK_FLAG(p->cap,
13931 PEER_CAP_REFRESH_ADV)
13932 ? "and "
13933 : "");
13934 vty_out(vty, "\n");
13935 }
13936
13937 /* Multiprotocol Extensions */
13938 FOREACH_AFI_SAFI (afi, safi)
13939 if (p->afc_adv[afi][safi] ||
13940 p->afc_recv[afi][safi]) {
13941 vty_out(vty, " Address Family %s:",
13942 get_afi_safi_str(afi, safi,
13943 false));
13944 if (p->afc_adv[afi][safi])
9af52ccf 13945 vty_out(vty, " advertised");
10711563 13946 if (p->afc_recv[afi][safi])
9af52ccf 13947 vty_out(vty, " %sreceived",
10711563 13948 p->afc_adv[afi][safi]
9af52ccf
DA
13949 ? "and "
13950 : "");
13951 vty_out(vty, "\n");
13952 }
13953
10711563
DA
13954 /* Hostname capability */
13955 vty_out(vty, " Hostname Capability:");
d62a17ae 13956
10711563
DA
13957 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13958 vty_out(vty,
13959 " advertised (name: %s,domain name: %s)",
13960 bgp->peer_self->hostname
13961 ? bgp->peer_self->hostname
13962 : "n/a",
13963 bgp->peer_self->domainname
13964 ? bgp->peer_self->domainname
13965 : "n/a");
13966 } else {
13967 vty_out(vty, " not advertised");
13968 }
d77114b7 13969
10711563
DA
13970 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13971 vty_out(vty,
13972 " received (name: %s,domain name: %s)",
13973 p->hostname ? p->hostname : "n/a",
13974 p->domainname ? p->domainname : "n/a");
13975 } else {
13976 vty_out(vty, " not received");
d62a17ae 13977 }
d62a17ae 13978
10711563 13979 vty_out(vty, "\n");
d77114b7 13980
10711563
DA
13981 /* Graceful Restart */
13982 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13983 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13984 vty_out(vty,
13985 " Graceful Restart Capability:");
13986 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13987 vty_out(vty, " advertised");
13988 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13989 vty_out(vty, " %sreceived",
13990 CHECK_FLAG(p->cap,
13991 PEER_CAP_RESTART_ADV)
13992 ? "and "
13993 : "");
d77114b7
MK
13994 vty_out(vty, "\n");
13995
10711563
DA
13996 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13997 int restart_af_count = 0;
d62a17ae 13998
10711563
DA
13999 vty_out(vty,
14000 " Remote Restart timer is %d seconds\n",
14001 p->v_gr_restart);
14002 vty_out(vty,
14003 " Address families by peer:\n ");
d62a17ae 14004
10711563
DA
14005 FOREACH_AFI_SAFI (afi, safi)
14006 if (CHECK_FLAG(
14007 p->af_cap[afi]
14008 [safi],
14009 PEER_CAP_RESTART_AF_RCV)) {
14010 vty_out(vty, "%s%s(%s)",
14011 restart_af_count
14012 ? ", "
14013 : "",
14014 get_afi_safi_str(
14015 afi,
14016 safi,
14017 false),
14018 CHECK_FLAG(
14019 p->af_cap
14020 [afi]
14021 [safi],
14022 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14023 ? "preserved"
14024 : "not preserved");
14025 restart_af_count++;
14026 }
14027 if (!restart_af_count)
14028 vty_out(vty, "none");
14029 vty_out(vty, "\n");
14030 }
17be83bf 14031 } /* Graceful Restart */
d62a17ae 14032 }
14033 }
14034
14035 /* graceful restart information */
10711563
DA
14036 json_object *json_grace = NULL;
14037 json_object *json_grace_send = NULL;
14038 json_object *json_grace_recv = NULL;
14039 int eor_send_af_count = 0;
14040 int eor_receive_af_count = 0;
d62a17ae 14041
10711563
DA
14042 if (use_json) {
14043 json_grace = json_object_new_object();
14044 json_grace_send = json_object_new_object();
14045 json_grace_recv = json_object_new_object();
14046
14047 if ((peer_established(p)) &&
14048 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14049 FOREACH_AFI_SAFI (afi, safi) {
14050 if (CHECK_FLAG(p->af_sflags[afi][safi],
14051 PEER_STATUS_EOR_SEND)) {
14052 json_object_boolean_true_add(
14053 json_grace_send,
14054 get_afi_safi_str(afi, safi,
14055 true));
14056 eor_send_af_count++;
d62a17ae 14057 }
10711563
DA
14058 }
14059 FOREACH_AFI_SAFI (afi, safi) {
14060 if (CHECK_FLAG(p->af_sflags[afi][safi],
14061 PEER_STATUS_EOR_RECEIVED)) {
14062 json_object_boolean_true_add(
14063 json_grace_recv,
14064 get_afi_safi_str(afi, safi,
14065 true));
14066 eor_receive_af_count++;
d62a17ae 14067 }
14068 }
10711563
DA
14069 }
14070 json_object_object_add(json_grace, "endOfRibSend",
14071 json_grace_send);
14072 json_object_object_add(json_grace, "endOfRibRecv",
14073 json_grace_recv);
d62a17ae 14074
d62a17ae 14075
10711563
DA
14076 if (p->t_gr_restart)
14077 json_object_int_add(
14078 json_grace, "gracefulRestartTimerMsecs",
14079 thread_timer_remain_second(p->t_gr_restart) *
14080 1000);
2986cac2 14081
10711563
DA
14082 if (p->t_gr_stale)
14083 json_object_int_add(
14084 json_grace, "gracefulStalepathTimerMsecs",
14085 thread_timer_remain_second(p->t_gr_stale) *
14086 1000);
14087 /* more gr info in new format */
14088 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
14089 json_object_object_add(json_neigh, "gracefulRestartInfo",
14090 json_grace);
14091 } else {
14092 vty_out(vty, " Graceful restart information:\n");
14093 if ((peer_established(p)) &&
14094 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14095
14096 vty_out(vty, " End-of-RIB send: ");
14097 FOREACH_AFI_SAFI (afi, safi) {
14098 if (CHECK_FLAG(p->af_sflags[afi][safi],
14099 PEER_STATUS_EOR_SEND)) {
14100 vty_out(vty, "%s%s",
14101 eor_send_af_count ? ", " : "",
14102 get_afi_safi_str(afi, safi,
14103 false));
14104 eor_send_af_count++;
d62a17ae 14105 }
10711563
DA
14106 }
14107 vty_out(vty, "\n");
14108 vty_out(vty, " End-of-RIB received: ");
14109 FOREACH_AFI_SAFI (afi, safi) {
14110 if (CHECK_FLAG(p->af_sflags[afi][safi],
14111 PEER_STATUS_EOR_RECEIVED)) {
14112 vty_out(vty, "%s%s",
14113 eor_receive_af_count ? ", "
14114 : "",
14115 get_afi_safi_str(afi, safi,
14116 false));
14117 eor_receive_af_count++;
d62a17ae 14118 }
d62a17ae 14119 }
10711563
DA
14120 vty_out(vty, "\n");
14121 }
d62a17ae 14122
10711563
DA
14123 if (p->t_gr_restart)
14124 vty_out(vty,
14125 " The remaining time of restart timer is %ld\n",
14126 thread_timer_remain_second(p->t_gr_restart));
d62a17ae 14127
10711563
DA
14128 if (p->t_gr_stale)
14129 vty_out(vty,
14130 " The remaining time of stalepath timer is %ld\n",
14131 thread_timer_remain_second(p->t_gr_stale));
2986cac2 14132
10711563
DA
14133 /* more gr info in new format */
14134 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
14135 }
2986cac2 14136
d62a17ae 14137 if (use_json) {
14138 json_object *json_stat = NULL;
14139 json_stat = json_object_new_object();
14140 /* Packet counts. */
43aa5965
QY
14141
14142 atomic_size_t outq_count, inq_count;
14143 outq_count = atomic_load_explicit(&p->obuf->count,
14144 memory_order_relaxed);
14145 inq_count = atomic_load_explicit(&p->ibuf->count,
14146 memory_order_relaxed);
14147
14148 json_object_int_add(json_stat, "depthInq",
14149 (unsigned long)inq_count);
d62a17ae 14150 json_object_int_add(json_stat, "depthOutq",
43aa5965 14151 (unsigned long)outq_count);
0112e9e0
QY
14152 json_object_int_add(json_stat, "opensSent",
14153 atomic_load_explicit(&p->open_out,
14154 memory_order_relaxed));
14155 json_object_int_add(json_stat, "opensRecv",
14156 atomic_load_explicit(&p->open_in,
14157 memory_order_relaxed));
d62a17ae 14158 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
14159 atomic_load_explicit(&p->notify_out,
14160 memory_order_relaxed));
d62a17ae 14161 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
14162 atomic_load_explicit(&p->notify_in,
14163 memory_order_relaxed));
14164 json_object_int_add(json_stat, "updatesSent",
14165 atomic_load_explicit(&p->update_out,
14166 memory_order_relaxed));
14167 json_object_int_add(json_stat, "updatesRecv",
14168 atomic_load_explicit(&p->update_in,
14169 memory_order_relaxed));
d62a17ae 14170 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
14171 atomic_load_explicit(&p->keepalive_out,
14172 memory_order_relaxed));
d62a17ae 14173 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
14174 atomic_load_explicit(&p->keepalive_in,
14175 memory_order_relaxed));
d62a17ae 14176 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
14177 atomic_load_explicit(&p->refresh_out,
14178 memory_order_relaxed));
d62a17ae 14179 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
14180 atomic_load_explicit(&p->refresh_in,
14181 memory_order_relaxed));
d62a17ae 14182 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
14183 atomic_load_explicit(&p->dynamic_cap_out,
14184 memory_order_relaxed));
d62a17ae 14185 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
14186 atomic_load_explicit(&p->dynamic_cap_in,
14187 memory_order_relaxed));
14188 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14189 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 14190 json_object_object_add(json_neigh, "messageStats", json_stat);
14191 } else {
cb93e0a2
IS
14192 atomic_size_t outq_count, inq_count, open_out, open_in,
14193 notify_out, notify_in, update_out, update_in,
14194 keepalive_out, keepalive_in, refresh_out, refresh_in,
14195 dynamic_cap_out, dynamic_cap_in;
43aa5965
QY
14196 outq_count = atomic_load_explicit(&p->obuf->count,
14197 memory_order_relaxed);
14198 inq_count = atomic_load_explicit(&p->ibuf->count,
14199 memory_order_relaxed);
cb93e0a2
IS
14200 open_out = atomic_load_explicit(&p->open_out,
14201 memory_order_relaxed);
14202 open_in =
14203 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14204 notify_out = atomic_load_explicit(&p->notify_out,
14205 memory_order_relaxed);
14206 notify_in = atomic_load_explicit(&p->notify_in,
14207 memory_order_relaxed);
14208 update_out = atomic_load_explicit(&p->update_out,
14209 memory_order_relaxed);
14210 update_in = atomic_load_explicit(&p->update_in,
14211 memory_order_relaxed);
14212 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14213 memory_order_relaxed);
14214 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14215 memory_order_relaxed);
14216 refresh_out = atomic_load_explicit(&p->refresh_out,
14217 memory_order_relaxed);
14218 refresh_in = atomic_load_explicit(&p->refresh_in,
14219 memory_order_relaxed);
14220 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14221 memory_order_relaxed);
14222 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14223 memory_order_relaxed);
43aa5965 14224
d62a17ae 14225 /* Packet counts. */
14226 vty_out(vty, " Message statistics:\n");
43aa5965
QY
14227 vty_out(vty, " Inq depth is %zu\n", inq_count);
14228 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 14229 vty_out(vty, " Sent Rcvd\n");
cb93e0a2
IS
14230 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14231 open_in);
14232 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14233 notify_in);
14234 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14235 update_in);
14236 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14237 keepalive_in);
14238 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14239 refresh_in);
14240 vty_out(vty, " Capability: %10zu %10zu\n",
14241 dynamic_cap_out, dynamic_cap_in);
14242 vty_out(vty, " Total: %10u %10u\n",
14243 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
d62a17ae 14244 }
14245
14246 if (use_json) {
14247 /* advertisement-interval */
14248 json_object_int_add(json_neigh,
14249 "minBtwnAdvertisementRunsTimerMsecs",
14250 p->v_routeadv * 1000);
14251
14252 /* Update-source. */
14253 if (p->update_if || p->update_source) {
14254 if (p->update_if)
14255 json_object_string_add(json_neigh,
14256 "updateSource",
14257 p->update_if);
14258 else if (p->update_source)
47e12884
DA
14259 json_object_string_addf(json_neigh,
14260 "updateSource", "%pSU",
14261 p->update_source);
d62a17ae 14262 }
14263 } else {
14264 /* advertisement-interval */
14265 vty_out(vty,
14266 " Minimum time between advertisement runs is %d seconds\n",
14267 p->v_routeadv);
14268
14269 /* Update-source. */
14270 if (p->update_if || p->update_source) {
14271 vty_out(vty, " Update source is ");
14272 if (p->update_if)
14273 vty_out(vty, "%s", p->update_if);
14274 else if (p->update_source)
47e12884 14275 vty_out(vty, "%pSU", p->update_source);
d62a17ae 14276 vty_out(vty, "\n");
14277 }
14278
14279 vty_out(vty, "\n");
14280 }
14281
14282 /* Address Family Information */
14283 json_object *json_hold = NULL;
14284
14285 if (use_json)
14286 json_hold = json_object_new_object();
14287
05c7a1cc
QY
14288 FOREACH_AFI_SAFI (afi, safi)
14289 if (p->afc[afi][safi])
14290 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14291 json_hold);
d62a17ae 14292
14293 if (use_json) {
14294 json_object_object_add(json_neigh, "addressFamilyInfo",
14295 json_hold);
14296 json_object_int_add(json_neigh, "connectionsEstablished",
14297 p->established);
14298 json_object_int_add(json_neigh, "connectionsDropped",
14299 p->dropped);
14300 } else
14301 vty_out(vty, " Connections established %d; dropped %d\n",
14302 p->established, p->dropped);
14303
14304 if (!p->last_reset) {
14305 if (use_json)
14306 json_object_string_add(json_neigh, "lastReset",
14307 "never");
14308 else
14309 vty_out(vty, " Last reset never\n");
14310 } else {
14311 if (use_json) {
14312 time_t uptime;
a2700b50 14313 struct tm tm;
d62a17ae 14314
083ec940 14315 uptime = monotime(NULL);
d62a17ae 14316 uptime -= p->resettime;
a2700b50
MS
14317 gmtime_r(&uptime, &tm);
14318
d62a17ae 14319 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
14320 (tm.tm_sec * 1000)
14321 + (tm.tm_min * 60000)
14322 + (tm.tm_hour * 3600000));
3577f1c5 14323 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 14324 } else {
14325 vty_out(vty, " Last reset %s, ",
14326 peer_uptime(p->resettime, timebuf,
14327 BGP_UPTIME_LEN, 0, NULL));
14328
3577f1c5 14329 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 14330 if (p->last_reset_cause_size) {
14331 msg = p->last_reset_cause;
14332 vty_out(vty,
14333 " Message received that caused BGP to send a NOTIFICATION:\n ");
14334 for (i = 1; i <= p->last_reset_cause_size;
14335 i++) {
14336 vty_out(vty, "%02X", *msg++);
14337
14338 if (i != p->last_reset_cause_size) {
14339 if (i % 16 == 0) {
14340 vty_out(vty, "\n ");
14341 } else if (i % 4 == 0) {
14342 vty_out(vty, " ");
14343 }
14344 }
14345 }
14346 vty_out(vty, "\n");
14347 }
14348 }
14349 }
14350
14351 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14352 if (use_json)
14353 json_object_boolean_true_add(json_neigh,
14354 "prefixesConfigExceedMax");
14355 else
14356 vty_out(vty,
14357 " Peer had exceeded the max. no. of prefixes configured.\n");
14358
14359 if (p->t_pmax_restart) {
14360 if (use_json) {
14361 json_object_boolean_true_add(
14362 json_neigh, "reducePrefixNumFrom");
14363 json_object_int_add(json_neigh,
14364 "restartInTimerMsec",
14365 thread_timer_remain_second(
14366 p->t_pmax_restart)
14367 * 1000);
14368 } else
14369 vty_out(vty,
14370 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
14371 p->host, thread_timer_remain_second(
14372 p->t_pmax_restart));
d62a17ae 14373 } else {
14374 if (use_json)
14375 json_object_boolean_true_add(
14376 json_neigh,
14377 "reducePrefixNumAndClearIpBgp");
14378 else
14379 vty_out(vty,
14380 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14381 p->host);
14382 }
14383 }
14384
14385 /* EBGP Multihop and GTSM */
14386 if (p->sort != BGP_PEER_IBGP) {
14387 if (use_json) {
e2521429 14388 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14389 json_object_int_add(json_neigh,
14390 "externalBgpNbrMaxHopsAway",
14391 p->gtsm_hops);
be8d1733 14392 else
d62a17ae 14393 json_object_int_add(json_neigh,
14394 "externalBgpNbrMaxHopsAway",
14395 p->ttl);
14396 } else {
e2521429 14397 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14398 vty_out(vty,
14399 " External BGP neighbor may be up to %d hops away.\n",
14400 p->gtsm_hops);
be8d1733 14401 else
d62a17ae 14402 vty_out(vty,
14403 " External BGP neighbor may be up to %d hops away.\n",
14404 p->ttl);
14405 }
14406 } else {
be8d1733
DA
14407 if (use_json) {
14408 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14409 json_object_int_add(json_neigh,
14410 "internalBgpNbrMaxHopsAway",
14411 p->gtsm_hops);
14412 else
be8d1733
DA
14413 json_object_int_add(json_neigh,
14414 "internalBgpNbrMaxHopsAway",
14415 p->ttl);
14416 } else {
14417 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14418 vty_out(vty,
14419 " Internal BGP neighbor may be up to %d hops away.\n",
14420 p->gtsm_hops);
be8d1733
DA
14421 else
14422 vty_out(vty,
14423 " Internal BGP neighbor may be up to %d hops away.\n",
14424 p->ttl);
d62a17ae 14425 }
14426 }
14427
14428 /* Local address. */
14429 if (p->su_local) {
14430 if (use_json) {
47e12884
DA
14431 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14432 p->su_local);
d62a17ae 14433 json_object_int_add(json_neigh, "portLocal",
14434 ntohs(p->su_local->sin.sin_port));
14435 } else
47e12884
DA
14436 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14437 p->su_local, ntohs(p->su_local->sin.sin_port));
1e592331
DS
14438 } else {
14439 if (use_json) {
14440 json_object_string_add(json_neigh, "hostLocal",
14441 "Unknown");
14442 json_object_int_add(json_neigh, "portLocal", -1);
14443 }
d62a17ae 14444 }
14445
14446 /* Remote address. */
14447 if (p->su_remote) {
14448 if (use_json) {
47e12884
DA
14449 json_object_string_addf(json_neigh, "hostForeign",
14450 "%pSU", p->su_remote);
d62a17ae 14451 json_object_int_add(json_neigh, "portForeign",
14452 ntohs(p->su_remote->sin.sin_port));
14453 } else
47e12884
DA
14454 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14455 p->su_remote,
d62a17ae 14456 ntohs(p->su_remote->sin.sin_port));
1e592331
DS
14457 } else {
14458 if (use_json) {
14459 json_object_string_add(json_neigh, "hostForeign",
14460 "Unknown");
14461 json_object_int_add(json_neigh, "portForeign", -1);
14462 }
d62a17ae 14463 }
14464
14465 /* Nexthop display. */
14466 if (p->su_local) {
14467 if (use_json) {
c949c771
DA
14468 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14469 &p->nexthop.v4);
14470 json_object_string_addf(json_neigh, "nexthopGlobal",
14471 "%pI6", &p->nexthop.v6_global);
14472 json_object_string_addf(json_neigh, "nexthopLocal",
14473 "%pI6", &p->nexthop.v6_local);
d62a17ae 14474 if (p->shared_network)
14475 json_object_string_add(json_neigh,
14476 "bgpConnection",
14477 "sharedNetwork");
14478 else
14479 json_object_string_add(json_neigh,
14480 "bgpConnection",
14481 "nonSharedNetwork");
14482 } else {
14483 vty_out(vty, "Nexthop: %s\n",
14484 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14485 sizeof(buf1)));
14486 vty_out(vty, "Nexthop global: %s\n",
14487 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14488 sizeof(buf1)));
14489 vty_out(vty, "Nexthop local: %s\n",
14490 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14491 sizeof(buf1)));
14492 vty_out(vty, "BGP connection: %s\n",
14493 p->shared_network ? "shared network"
14494 : "non shared network");
14495 }
14496 }
14497
14498 /* Timer information. */
14499 if (use_json) {
14500 json_object_int_add(json_neigh, "connectRetryTimer",
14501 p->v_connect);
feb17238 14502 if (peer_established(p) && p->rtt)
d62a17ae 14503 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14504 p->rtt);
14505 if (p->t_start)
14506 json_object_int_add(
14507 json_neigh, "nextStartTimerDueInMsecs",
14508 thread_timer_remain_second(p->t_start) * 1000);
14509 if (p->t_connect)
14510 json_object_int_add(
14511 json_neigh, "nextConnectTimerDueInMsecs",
14512 thread_timer_remain_second(p->t_connect)
14513 * 1000);
14514 if (p->t_routeadv) {
14515 json_object_int_add(json_neigh, "mraiInterval",
14516 p->v_routeadv);
14517 json_object_int_add(
14518 json_neigh, "mraiTimerExpireInMsecs",
14519 thread_timer_remain_second(p->t_routeadv)
14520 * 1000);
14521 }
14522 if (p->password)
14523 json_object_int_add(json_neigh, "authenticationEnabled",
14524 1);
14525
14526 if (p->t_read)
14527 json_object_string_add(json_neigh, "readThread", "on");
14528 else
14529 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
14530
14531 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 14532 json_object_string_add(json_neigh, "writeThread", "on");
14533 else
14534 json_object_string_add(json_neigh, "writeThread",
14535 "off");
14536 } else {
14537 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14538 p->v_connect);
feb17238 14539 if (peer_established(p) && p->rtt)
d62a17ae 14540 vty_out(vty, "Estimated round trip time: %d ms\n",
14541 p->rtt);
14542 if (p->t_start)
14543 vty_out(vty, "Next start timer due in %ld seconds\n",
14544 thread_timer_remain_second(p->t_start));
14545 if (p->t_connect)
14546 vty_out(vty, "Next connect timer due in %ld seconds\n",
14547 thread_timer_remain_second(p->t_connect));
14548 if (p->t_routeadv)
14549 vty_out(vty,
14550 "MRAI (interval %u) timer expires in %ld seconds\n",
14551 p->v_routeadv,
14552 thread_timer_remain_second(p->t_routeadv));
14553 if (p->password)
14554 vty_out(vty, "Peer Authentication Enabled\n");
14555
cac9e917 14556 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
14557 p->t_read ? "on" : "off",
14558 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14559 ? "on"
cac9e917 14560 : "off", p->fd);
d62a17ae 14561 }
14562
14563 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14564 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14565 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14566
14567 if (!use_json)
14568 vty_out(vty, "\n");
14569
14570 /* BFD information. */
21bfce98
RZ
14571 if (p->bfd_config)
14572 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 14573
14574 if (use_json) {
14575 if (p->conf_if) /* Configured interface name. */
14576 json_object_object_add(json, p->conf_if, json_neigh);
14577 else /* Configured IP address. */
14578 json_object_object_add(json, p->host, json_neigh);
14579 }
14580}
14581
36235319
QY
14582static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14583 enum show_type type,
14584 union sockunion *su,
14585 const char *conf_if, afi_t afi,
74a630b6 14586 bool use_json)
2986cac2 14587{
14588 struct listnode *node, *nnode;
14589 struct peer *peer;
14590 int find = 0;
14591 safi_t safi = SAFI_UNICAST;
74a630b6 14592 json_object *json = NULL;
2986cac2 14593 json_object *json_neighbor = NULL;
14594
74a630b6
NT
14595 if (use_json) {
14596 json = json_object_new_object();
14597 json_neighbor = json_object_new_object();
14598 }
14599
2986cac2 14600 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14601
14602 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14603 continue;
14604
14605 if ((peer->afc[afi][safi]) == 0)
14606 continue;
14607
2ba1fe69 14608 if (type == show_all) {
2986cac2 14609 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 14610 json_neighbor);
2986cac2 14611
74a630b6 14612 if (use_json) {
13909c4f
DS
14613 json_object_object_add(json, peer->host,
14614 json_neighbor);
74a630b6
NT
14615 json_neighbor = NULL;
14616 }
2986cac2 14617
2ba1fe69 14618 } else if (type == show_peer) {
2986cac2 14619 if (conf_if) {
14620 if ((peer->conf_if
13909c4f
DS
14621 && !strcmp(peer->conf_if, conf_if))
14622 || (peer->hostname
2986cac2 14623 && !strcmp(peer->hostname, conf_if))) {
14624 find = 1;
13909c4f
DS
14625 bgp_show_peer_gr_status(vty, peer,
14626 use_json,
14627 json_neighbor);
2986cac2 14628 }
14629 } else {
14630 if (sockunion_same(&peer->su, su)) {
14631 find = 1;
13909c4f
DS
14632 bgp_show_peer_gr_status(vty, peer,
14633 use_json,
14634 json_neighbor);
2986cac2 14635 }
14636 }
13909c4f
DS
14637 if (use_json && find)
14638 json_object_object_add(json, peer->host,
14639 json_neighbor);
2986cac2 14640 }
14641
74a630b6
NT
14642 if (find) {
14643 json_neighbor = NULL;
2986cac2 14644 break;
74a630b6 14645 }
2986cac2 14646 }
14647
14648 if (type == show_peer && !find) {
14649 if (use_json)
13909c4f 14650 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14651 else
14652 vty_out(vty, "%% No such neighbor\n");
14653 }
14654 if (use_json) {
74a630b6
NT
14655 if (json_neighbor)
14656 json_object_free(json_neighbor);
75eeda93 14657 vty_json(vty, json);
2986cac2 14658 } else {
14659 vty_out(vty, "\n");
14660 }
14661
14662 return CMD_SUCCESS;
14663}
14664
d62a17ae 14665static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14666 enum show_type type, union sockunion *su,
9f049418 14667 const char *conf_if, bool use_json,
d62a17ae 14668 json_object *json)
14669{
14670 struct listnode *node, *nnode;
14671 struct peer *peer;
14672 int find = 0;
9f049418 14673 bool nbr_output = false;
d1927ebe
AS
14674 afi_t afi = AFI_MAX;
14675 safi_t safi = SAFI_MAX;
14676
14677 if (type == show_ipv4_peer || type == show_ipv4_all) {
14678 afi = AFI_IP;
14679 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14680 afi = AFI_IP6;
14681 }
d62a17ae 14682
14683 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14684 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14685 continue;
14686
14687 switch (type) {
14688 case show_all:
14689 bgp_show_peer(vty, peer, use_json, json);
9f049418 14690 nbr_output = true;
d62a17ae 14691 break;
14692 case show_peer:
14693 if (conf_if) {
14694 if ((peer->conf_if
14695 && !strcmp(peer->conf_if, conf_if))
14696 || (peer->hostname
14697 && !strcmp(peer->hostname, conf_if))) {
14698 find = 1;
14699 bgp_show_peer(vty, peer, use_json,
14700 json);
14701 }
14702 } else {
14703 if (sockunion_same(&peer->su, su)) {
14704 find = 1;
14705 bgp_show_peer(vty, peer, use_json,
14706 json);
14707 }
14708 }
14709 break;
d1927ebe
AS
14710 case show_ipv4_peer:
14711 case show_ipv6_peer:
14712 FOREACH_SAFI (safi) {
14713 if (peer->afc[afi][safi]) {
14714 if (conf_if) {
14715 if ((peer->conf_if
14716 && !strcmp(peer->conf_if, conf_if))
14717 || (peer->hostname
14718 && !strcmp(peer->hostname, conf_if))) {
14719 find = 1;
14720 bgp_show_peer(vty, peer, use_json,
14721 json);
14722 break;
14723 }
14724 } else {
14725 if (sockunion_same(&peer->su, su)) {
14726 find = 1;
14727 bgp_show_peer(vty, peer, use_json,
14728 json);
14729 break;
14730 }
14731 }
14732 }
14733 }
14734 break;
14735 case show_ipv4_all:
14736 case show_ipv6_all:
14737 FOREACH_SAFI (safi) {
14738 if (peer->afc[afi][safi]) {
14739 bgp_show_peer(vty, peer, use_json, json);
14740 nbr_output = true;
14741 break;
14742 }
14743 }
14744 break;
d62a17ae 14745 }
14746 }
14747
d1927ebe
AS
14748 if ((type == show_peer || type == show_ipv4_peer ||
14749 type == show_ipv6_peer) && !find) {
d62a17ae 14750 if (use_json)
14751 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14752 else
88b7d255 14753 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14754 }
14755
d1927ebe
AS
14756 if (type != show_peer && type != show_ipv4_peer &&
14757 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14758 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14759
d62a17ae 14760 if (use_json) {
996c9314
LB
14761 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14762 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14763 } else {
14764 vty_out(vty, "\n");
14765 }
14766
14767 return CMD_SUCCESS;
14768}
14769
36235319
QY
14770static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14771 enum show_type type,
14772 const char *ip_str,
14773 afi_t afi, bool use_json)
2986cac2 14774{
14775
14776 int ret;
14777 struct bgp *bgp;
14778 union sockunion su;
2986cac2 14779
14780 bgp = bgp_get_default();
14781
13909c4f
DS
14782 if (!bgp)
14783 return;
2986cac2 14784
13909c4f
DS
14785 if (!use_json)
14786 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14787 NULL);
2986cac2 14788
13909c4f
DS
14789 if (ip_str) {
14790 ret = str2sockunion(ip_str, &su);
14791 if (ret < 0)
13909c4f 14792 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14793 vty, bgp, type, NULL, ip_str, afi, use_json);
14794 else
14795 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14796 NULL, afi, use_json);
13909c4f
DS
14797 } else
14798 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14799 afi, use_json);
2986cac2 14800}
14801
d62a17ae 14802static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14803 enum show_type type,
14804 const char *ip_str,
9f049418 14805 bool use_json)
d62a17ae 14806{
0291c246
MK
14807 struct listnode *node, *nnode;
14808 struct bgp *bgp;
71aedaa3 14809 union sockunion su;
0291c246 14810 json_object *json = NULL;
71aedaa3 14811 int ret, is_first = 1;
9f049418 14812 bool nbr_output = false;
d62a17ae 14813
14814 if (use_json)
14815 vty_out(vty, "{\n");
14816
14817 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14818 nbr_output = true;
d62a17ae 14819 if (use_json) {
14820 if (!(json = json_object_new_object())) {
af4c2728 14821 flog_err(
e50f7cfd 14822 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14823 "Unable to allocate memory for JSON object");
14824 vty_out(vty,
14825 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14826 return;
14827 }
14828
14829 json_object_int_add(json, "vrfId",
14830 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14831 ? -1
14832 : (int64_t)bgp->vrf_id);
d62a17ae 14833 json_object_string_add(
14834 json, "vrfName",
14835 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14836 ? VRF_DEFAULT_NAME
d62a17ae 14837 : bgp->name);
14838
14839 if (!is_first)
14840 vty_out(vty, ",\n");
14841 else
14842 is_first = 0;
14843
14844 vty_out(vty, "\"%s\":",
14845 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14846 ? VRF_DEFAULT_NAME
d62a17ae 14847 : bgp->name);
14848 } else {
14849 vty_out(vty, "\nInstance %s:\n",
14850 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14851 ? VRF_DEFAULT_NAME
d62a17ae 14852 : bgp->name);
14853 }
71aedaa3 14854
d1927ebe
AS
14855 if (type == show_peer || type == show_ipv4_peer ||
14856 type == show_ipv6_peer) {
71aedaa3
DS
14857 ret = str2sockunion(ip_str, &su);
14858 if (ret < 0)
14859 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14860 use_json, json);
14861 else
14862 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14863 use_json, json);
14864 } else {
d1927ebe 14865 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14866 use_json, json);
14867 }
b77004d6 14868 json_object_free(json);
121067e9 14869 json = NULL;
d62a17ae 14870 }
14871
3e78a6ce 14872 if (use_json)
d62a17ae 14873 vty_out(vty, "}\n");
9f049418
DS
14874 else if (!nbr_output)
14875 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14876}
14877
14878static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14879 enum show_type type, const char *ip_str,
9f049418 14880 bool use_json)
d62a17ae 14881{
14882 int ret;
14883 struct bgp *bgp;
14884 union sockunion su;
14885 json_object *json = NULL;
14886
14887 if (name) {
14888 if (strmatch(name, "all")) {
71aedaa3
DS
14889 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14890 use_json);
d62a17ae 14891 return CMD_SUCCESS;
14892 } else {
14893 bgp = bgp_lookup_by_name(name);
14894 if (!bgp) {
14895 if (use_json) {
14896 json = json_object_new_object();
75eeda93 14897 vty_json(vty, json);
d62a17ae 14898 } else
14899 vty_out(vty,
9f049418 14900 "%% BGP instance not found\n");
d62a17ae 14901
14902 return CMD_WARNING;
14903 }
14904 }
14905 } else {
14906 bgp = bgp_get_default();
14907 }
14908
14909 if (bgp) {
14910 json = json_object_new_object();
14911 if (ip_str) {
14912 ret = str2sockunion(ip_str, &su);
14913 if (ret < 0)
14914 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14915 use_json, json);
14916 else
14917 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14918 use_json, json);
14919 } else {
14920 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14921 json);
14922 }
14923 json_object_free(json);
ca61fd25
DS
14924 } else {
14925 if (use_json)
14926 vty_out(vty, "{}\n");
14927 else
14928 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14929 }
14930
14931 return CMD_SUCCESS;
4fb25c53
DW
14932}
14933
2986cac2 14934
14935
14936/* "show [ip] bgp neighbors graceful-restart" commands. */
dcab9012 14937DEFUN (show_ip_bgp_neighbors_graceful_restart,
2986cac2 14938 show_ip_bgp_neighbors_graceful_restart_cmd,
14939 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14940 SHOW_STR
14941 BGP_STR
14942 IP_STR
14943 IPV6_STR
14944 NEIGHBOR_STR
14945 "Neighbor to display information about\n"
14946 "Neighbor to display information about\n"
14947 "Neighbor on BGP configured interface\n"
14948 GR_SHOW
14949 JSON_STR)
14950{
14951 char *sh_arg = NULL;
14952 enum show_type sh_type;
14953 int idx = 0;
14954 afi_t afi = AFI_MAX;
2986cac2 14955 bool uj = use_json(argc, argv);
14956
36235319 14957 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 14958 afi = AFI_MAX;
14959
14960 idx++;
14961
14962 if (argv_find(argv, argc, "A.B.C.D", &idx)
14963 || argv_find(argv, argc, "X:X::X:X", &idx)
14964 || argv_find(argv, argc, "WORD", &idx)) {
14965 sh_type = show_peer;
14966 sh_arg = argv[idx]->arg;
14967 } else
14968 sh_type = show_all;
14969
14970 if (!argv_find(argv, argc, "graceful-restart", &idx))
14971 return CMD_SUCCESS;
14972
14973
36235319
QY
14974 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14975 afi, uj);
2986cac2 14976}
14977
716b2d8a 14978/* "show [ip] bgp neighbors" commands. */
718e3744 14979DEFUN (show_ip_bgp_neighbors,
14980 show_ip_bgp_neighbors_cmd,
24345e82 14981 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 14982 SHOW_STR
14983 IP_STR
14984 BGP_STR
f2a8972b 14985 BGP_INSTANCE_HELP_STR
00e6edb9
DA
14986 BGP_AF_STR
14987 BGP_AF_STR
718e3744 14988 "Detailed information on TCP and BGP neighbor connections\n"
14989 "Neighbor to display information about\n"
a80beece 14990 "Neighbor to display information about\n"
91d37724 14991 "Neighbor on BGP configured interface\n"
9973d184 14992 JSON_STR)
718e3744 14993{
d62a17ae 14994 char *vrf = NULL;
14995 char *sh_arg = NULL;
14996 enum show_type sh_type;
d1927ebe 14997 afi_t afi = AFI_MAX;
718e3744 14998
9f049418 14999 bool uj = use_json(argc, argv);
718e3744 15000
d62a17ae 15001 int idx = 0;
718e3744 15002
9a8bdf1c
PG
15003 /* [<vrf> VIEWVRFNAME] */
15004 if (argv_find(argv, argc, "vrf", &idx)) {
15005 vrf = argv[idx + 1]->arg;
15006 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15007 vrf = NULL;
15008 } else if (argv_find(argv, argc, "view", &idx))
15009 /* [<view> VIEWVRFNAME] */
d62a17ae 15010 vrf = argv[idx + 1]->arg;
718e3744 15011
d62a17ae 15012 idx++;
d1927ebe
AS
15013
15014 if (argv_find(argv, argc, "ipv4", &idx)) {
15015 sh_type = show_ipv4_all;
15016 afi = AFI_IP;
15017 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15018 sh_type = show_ipv6_all;
15019 afi = AFI_IP6;
15020 } else {
15021 sh_type = show_all;
15022 }
15023
d62a17ae 15024 if (argv_find(argv, argc, "A.B.C.D", &idx)
15025 || argv_find(argv, argc, "X:X::X:X", &idx)
15026 || argv_find(argv, argc, "WORD", &idx)) {
15027 sh_type = show_peer;
15028 sh_arg = argv[idx]->arg;
d1927ebe
AS
15029 }
15030
15031 if (sh_type == show_peer && afi == AFI_IP) {
15032 sh_type = show_ipv4_peer;
15033 } else if (sh_type == show_peer && afi == AFI_IP6) {
15034 sh_type = show_ipv6_peer;
15035 }
856ca177 15036
d62a17ae 15037 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 15038}
15039
716b2d8a 15040/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 15041 paths' and `show ip mbgp paths'. Those functions results are the
15042 same.*/
f412b39a 15043DEFUN (show_ip_bgp_paths,
718e3744 15044 show_ip_bgp_paths_cmd,
46f296b4 15045 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 15046 SHOW_STR
15047 IP_STR
15048 BGP_STR
46f296b4 15049 BGP_SAFI_HELP_STR
718e3744 15050 "Path information\n")
15051{
d62a17ae 15052 vty_out(vty, "Address Refcnt Path\n");
15053 aspath_print_all_vty(vty);
15054 return CMD_SUCCESS;
718e3744 15055}
15056
718e3744 15057#include "hash.h"
15058
e3b78da8 15059static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15060 struct vty *vty)
718e3744 15061{
d62a17ae 15062 struct community *com;
718e3744 15063
e3b78da8 15064 com = (struct community *)bucket->data;
3f65c5b1 15065 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
c0945b78 15066 community_str(com, false, false));
718e3744 15067}
15068
15069/* Show BGP's community internal data. */
f412b39a 15070DEFUN (show_ip_bgp_community_info,
718e3744 15071 show_ip_bgp_community_info_cmd,
bec37ba5 15072 "show [ip] bgp community-info",
718e3744 15073 SHOW_STR
15074 IP_STR
15075 BGP_STR
15076 "List all bgp community information\n")
15077{
d62a17ae 15078 vty_out(vty, "Address Refcnt Community\n");
718e3744 15079
d62a17ae 15080 hash_iterate(community_hash(),
e3b78da8 15081 (void (*)(struct hash_bucket *,
d62a17ae 15082 void *))community_show_all_iterator,
15083 vty);
718e3744 15084
d62a17ae 15085 return CMD_SUCCESS;
718e3744 15086}
15087
e3b78da8 15088static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15089 struct vty *vty)
57d187bc 15090{
d62a17ae 15091 struct lcommunity *lcom;
57d187bc 15092
e3b78da8 15093 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 15094 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
c0945b78 15095 lcommunity_str(lcom, false, false));
57d187bc
JS
15096}
15097
15098/* Show BGP's community internal data. */
15099DEFUN (show_ip_bgp_lcommunity_info,
15100 show_ip_bgp_lcommunity_info_cmd,
15101 "show ip bgp large-community-info",
15102 SHOW_STR
15103 IP_STR
15104 BGP_STR
15105 "List all bgp large-community information\n")
15106{
d62a17ae 15107 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 15108
d62a17ae 15109 hash_iterate(lcommunity_hash(),
e3b78da8 15110 (void (*)(struct hash_bucket *,
d62a17ae 15111 void *))lcommunity_show_all_iterator,
15112 vty);
57d187bc 15113
d62a17ae 15114 return CMD_SUCCESS;
57d187bc 15115}
2986cac2 15116/* Graceful Restart */
15117
15118static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
15119 struct bgp *bgp,
15120 bool use_json,
15121 json_object *json)
2986cac2 15122{
57d187bc
JS
15123
15124
2986cac2 15125 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15126
7318ae88 15127 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 15128
15129 switch (bgp_global_gr_mode) {
15130
15131 case GLOBAL_HELPER:
13909c4f 15132 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 15133 break;
15134
15135 case GLOBAL_GR:
13909c4f 15136 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 15137 break;
15138
15139 case GLOBAL_DISABLE:
13909c4f 15140 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 15141 break;
15142
15143 case GLOBAL_INVALID:
2986cac2 15144 vty_out(vty,
2ba1fe69 15145 "Global BGP GR Mode Invalid\n");
2986cac2 15146 break;
15147 }
15148 vty_out(vty, "\n");
15149}
15150
36235319
QY
15151static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15152 enum show_type type,
15153 const char *ip_str,
15154 afi_t afi, bool use_json)
2986cac2 15155{
15156 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15157 afi = AFI_IP;
15158
15159 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15160
36235319
QY
15161 bgp_show_neighbor_graceful_restart_vty(
15162 vty, type, ip_str, afi, use_json);
2986cac2 15163 afi++;
15164 }
15165 } else if (afi != AFI_MAX) {
36235319
QY
15166 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15167 use_json);
2986cac2 15168 } else {
15169 return CMD_ERR_INCOMPLETE;
15170 }
15171
15172 return CMD_SUCCESS;
15173}
15174/* Graceful Restart */
15175
f412b39a 15176DEFUN (show_ip_bgp_attr_info,
718e3744 15177 show_ip_bgp_attr_info_cmd,
bec37ba5 15178 "show [ip] bgp attribute-info",
718e3744 15179 SHOW_STR
15180 IP_STR
15181 BGP_STR
15182 "List all bgp attribute information\n")
15183{
d62a17ae 15184 attr_show_all(vty);
15185 return CMD_SUCCESS;
718e3744 15186}
6b0655a2 15187
03915806
CS
15188static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15189 afi_t afi, safi_t safi,
15190 bool use_json, json_object *json)
53089bec 15191{
15192 struct bgp *bgp;
15193 struct listnode *node;
15194 char *vname;
53089bec 15195 char *ecom_str;
9c2fd3fe 15196 enum vpn_policy_direction dir;
53089bec 15197
03915806 15198 if (json) {
b46dfd20
DS
15199 json_object *json_import_vrfs = NULL;
15200 json_object *json_export_vrfs = NULL;
15201
b46dfd20
DS
15202 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15203
53089bec 15204 if (!bgp) {
75eeda93 15205 vty_json(vty, json);
b46dfd20 15206
53089bec 15207 return CMD_WARNING;
15208 }
b46dfd20 15209
94d4c685
DS
15210 /* Provide context for the block */
15211 json_object_string_add(json, "vrf", name ? name : "default");
15212 json_object_string_add(json, "afiSafi",
5cb5f4d0 15213 get_afi_safi_str(afi, safi, true));
94d4c685 15214
b46dfd20
DS
15215 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15216 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15217 json_object_string_add(json, "importFromVrfs", "none");
15218 json_object_string_add(json, "importRts", "none");
15219 } else {
6ce24e52
DS
15220 json_import_vrfs = json_object_new_array();
15221
b46dfd20
DS
15222 for (ALL_LIST_ELEMENTS_RO(
15223 bgp->vpn_policy[afi].import_vrf,
15224 node, vname))
15225 json_object_array_add(json_import_vrfs,
15226 json_object_new_string(vname));
15227
b20875ea
CS
15228 json_object_object_add(json, "importFromVrfs",
15229 json_import_vrfs);
b46dfd20 15230 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15231 if (bgp->vpn_policy[afi].rtlist[dir]) {
15232 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15233 bgp->vpn_policy[afi].rtlist[dir],
15234 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15235 json_object_string_add(json, "importRts",
15236 ecom_str);
15237 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15238 } else
15239 json_object_string_add(json, "importRts",
15240 "none");
b46dfd20
DS
15241 }
15242
15243 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15244 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15245 json_object_string_add(json, "exportToVrfs", "none");
15246 json_object_string_add(json, "routeDistinguisher",
15247 "none");
15248 json_object_string_add(json, "exportRts", "none");
15249 } else {
6ce24e52
DS
15250 json_export_vrfs = json_object_new_array();
15251
b46dfd20
DS
15252 for (ALL_LIST_ELEMENTS_RO(
15253 bgp->vpn_policy[afi].export_vrf,
15254 node, vname))
15255 json_object_array_add(json_export_vrfs,
15256 json_object_new_string(vname));
15257 json_object_object_add(json, "exportToVrfs",
15258 json_export_vrfs);
c4f64ea9
DA
15259 json_object_string_addf(json, "routeDistinguisher",
15260 "%pRD",
15261 &bgp->vpn_policy[afi].tovpn_rd);
b46dfd20
DS
15262
15263 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15264 if (bgp->vpn_policy[afi].rtlist[dir]) {
15265 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15266 bgp->vpn_policy[afi].rtlist[dir],
15267 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15268 json_object_string_add(json, "exportRts",
15269 ecom_str);
15270 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15271 } else
15272 json_object_string_add(json, "exportRts",
15273 "none");
b46dfd20
DS
15274 }
15275
03915806 15276 if (use_json) {
75eeda93 15277 vty_json(vty, json);
03915806 15278 }
53089bec 15279 } else {
b46dfd20
DS
15280 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15281
53089bec 15282 if (!bgp) {
b46dfd20 15283 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 15284 return CMD_WARNING;
15285 }
53089bec 15286
b46dfd20
DS
15287 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15288 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15289 vty_out(vty,
15290 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 15291 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15292 else {
15293 vty_out(vty,
15294 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 15295 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15296
15297 for (ALL_LIST_ELEMENTS_RO(
15298 bgp->vpn_policy[afi].import_vrf,
15299 node, vname))
15300 vty_out(vty, " %s\n", vname);
15301
15302 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15303 ecom_str = NULL;
15304 if (bgp->vpn_policy[afi].rtlist[dir]) {
15305 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15306 bgp->vpn_policy[afi].rtlist[dir],
15307 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 15308 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 15309
b20875ea
CS
15310 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15311 } else
15312 vty_out(vty, "Import RT(s):\n");
53089bec 15313 }
53089bec 15314
b46dfd20
DS
15315 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15316 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15317 vty_out(vty,
15318 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 15319 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15320 else {
15321 vty_out(vty,
04c9077f 15322 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 15323 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15324
15325 for (ALL_LIST_ELEMENTS_RO(
15326 bgp->vpn_policy[afi].export_vrf,
15327 node, vname))
15328 vty_out(vty, " %s\n", vname);
15329
c4f64ea9
DA
15330 vty_out(vty, "RD: %pRD\n",
15331 &bgp->vpn_policy[afi].tovpn_rd);
b46dfd20
DS
15332
15333 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15334 if (bgp->vpn_policy[afi].rtlist[dir]) {
15335 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15336 bgp->vpn_policy[afi].rtlist[dir],
15337 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15338 vty_out(vty, "Export RT: %s\n", ecom_str);
15339 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15340 } else
15341 vty_out(vty, "Import RT(s):\n");
53089bec 15342 }
53089bec 15343 }
15344
15345 return CMD_SUCCESS;
15346}
15347
03915806
CS
15348static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15349 safi_t safi, bool use_json)
15350{
15351 struct listnode *node, *nnode;
15352 struct bgp *bgp;
15353 char *vrf_name = NULL;
15354 json_object *json = NULL;
15355 json_object *json_vrf = NULL;
15356 json_object *json_vrfs = NULL;
15357
15358 if (use_json) {
15359 json = json_object_new_object();
15360 json_vrfs = json_object_new_object();
15361 }
15362
15363 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15364
15365 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15366 vrf_name = bgp->name;
15367
15368 if (use_json) {
15369 json_vrf = json_object_new_object();
15370 } else {
15371 vty_out(vty, "\nInstance %s:\n",
15372 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15373 ? VRF_DEFAULT_NAME : bgp->name);
15374 }
15375 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15376 if (use_json) {
15377 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15378 json_object_object_add(json_vrfs,
15379 VRF_DEFAULT_NAME, json_vrf);
15380 else
15381 json_object_object_add(json_vrfs, vrf_name,
15382 json_vrf);
15383 }
15384 }
15385
15386 if (use_json) {
15387 json_object_object_add(json, "vrfs", json_vrfs);
75eeda93 15388 vty_json(vty, json);
03915806
CS
15389 }
15390
15391 return CMD_SUCCESS;
15392}
15393
53089bec 15394/* "show [ip] bgp route-leak" command. */
15395DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
15396 show_ip_bgp_route_leak_cmd,
15397 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
15398 SHOW_STR
15399 IP_STR
15400 BGP_STR
15401 BGP_INSTANCE_HELP_STR
15402 BGP_AFI_HELP_STR
15403 BGP_SAFI_HELP_STR
15404 "Route leaking information\n"
15405 JSON_STR)
53089bec 15406{
15407 char *vrf = NULL;
15408 afi_t afi = AFI_MAX;
15409 safi_t safi = SAFI_MAX;
15410
9f049418 15411 bool uj = use_json(argc, argv);
53089bec 15412 int idx = 0;
03915806 15413 json_object *json = NULL;
53089bec 15414
15415 /* show [ip] bgp */
15416 if (argv_find(argv, argc, "ip", &idx)) {
15417 afi = AFI_IP;
15418 safi = SAFI_UNICAST;
15419 }
15420 /* [vrf VIEWVRFNAME] */
15421 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
15422 vty_out(vty,
15423 "%% This command is not applicable to BGP views\n");
53089bec 15424 return CMD_WARNING;
15425 }
15426
9a8bdf1c
PG
15427 if (argv_find(argv, argc, "vrf", &idx)) {
15428 vrf = argv[idx + 1]->arg;
15429 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15430 vrf = NULL;
15431 }
53089bec 15432 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
c48349e3 15433 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
53089bec 15434 argv_find_and_parse_safi(argv, argc, &idx, &safi);
53089bec 15435
15436 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
15437 vty_out(vty,
15438 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 15439 return CMD_WARNING;
15440 }
15441
03915806
CS
15442 if (vrf && strmatch(vrf, "all"))
15443 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15444
15445 if (uj)
15446 json = json_object_new_object();
15447
15448 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 15449}
15450
d62a17ae 15451static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15452 safi_t safi)
f186de26 15453{
d62a17ae 15454 struct listnode *node, *nnode;
15455 struct bgp *bgp;
f186de26 15456
d62a17ae 15457 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15458 vty_out(vty, "\nInstance %s:\n",
15459 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15460 ? VRF_DEFAULT_NAME
d62a17ae 15461 : bgp->name);
15462 update_group_show(bgp, afi, safi, vty, 0);
15463 }
f186de26 15464}
15465
d62a17ae 15466static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15467 int safi, uint64_t subgrp_id)
4fb25c53 15468{
d62a17ae 15469 struct bgp *bgp;
4fb25c53 15470
d62a17ae 15471 if (name) {
15472 if (strmatch(name, "all")) {
15473 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15474 return CMD_SUCCESS;
15475 } else {
15476 bgp = bgp_lookup_by_name(name);
15477 }
15478 } else {
15479 bgp = bgp_get_default();
15480 }
4fb25c53 15481
d62a17ae 15482 if (bgp)
15483 update_group_show(bgp, afi, safi, vty, subgrp_id);
15484 return CMD_SUCCESS;
4fb25c53
DW
15485}
15486
8fe8a7f6
DS
15487DEFUN (show_ip_bgp_updgrps,
15488 show_ip_bgp_updgrps_cmd,
c1a44e43 15489 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 15490 SHOW_STR
15491 IP_STR
15492 BGP_STR
15493 BGP_INSTANCE_HELP_STR
c9e571b4 15494 BGP_AFI_HELP_STR
9bedbb1e 15495 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
15496 "Detailed info about dynamic update groups\n"
15497 "Specific subgroup to display detailed info for\n")
8386ac43 15498{
d62a17ae 15499 char *vrf = NULL;
15500 afi_t afi = AFI_IP6;
15501 safi_t safi = SAFI_UNICAST;
15502 uint64_t subgrp_id = 0;
15503
15504 int idx = 0;
15505
15506 /* show [ip] bgp */
15507 if (argv_find(argv, argc, "ip", &idx))
15508 afi = AFI_IP;
9a8bdf1c
PG
15509 /* [<vrf> VIEWVRFNAME] */
15510 if (argv_find(argv, argc, "vrf", &idx)) {
15511 vrf = argv[idx + 1]->arg;
15512 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15513 vrf = NULL;
15514 } else if (argv_find(argv, argc, "view", &idx))
15515 /* [<view> VIEWVRFNAME] */
15516 vrf = argv[idx + 1]->arg;
d62a17ae 15517 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15518 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15519 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15520 }
5bf15956 15521
d62a17ae 15522 /* get subgroup id, if provided */
15523 idx = argc - 1;
15524 if (argv[idx]->type == VARIABLE_TKN)
15525 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 15526
d62a17ae 15527 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
15528}
15529
f186de26 15530DEFUN (show_bgp_instance_all_ipv6_updgrps,
15531 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 15532 "show [ip] bgp <view|vrf> all update-groups",
f186de26 15533 SHOW_STR
716b2d8a 15534 IP_STR
f186de26 15535 BGP_STR
15536 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 15537 "Detailed info about dynamic update groups\n")
f186de26 15538{
d62a17ae 15539 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15540 return CMD_SUCCESS;
f186de26 15541}
15542
43d3f4fc
DS
15543DEFUN (show_bgp_l2vpn_evpn_updgrps,
15544 show_bgp_l2vpn_evpn_updgrps_cmd,
15545 "show [ip] bgp l2vpn evpn update-groups",
15546 SHOW_STR
15547 IP_STR
15548 BGP_STR
15549 "l2vpn address family\n"
15550 "evpn sub-address family\n"
15551 "Detailed info about dynamic update groups\n")
15552{
15553 char *vrf = NULL;
15554 uint64_t subgrp_id = 0;
15555
15556 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15557 return CMD_SUCCESS;
15558}
15559
5bf15956
DW
15560DEFUN (show_bgp_updgrps_stats,
15561 show_bgp_updgrps_stats_cmd,
716b2d8a 15562 "show [ip] bgp update-groups statistics",
3f9c7369 15563 SHOW_STR
716b2d8a 15564 IP_STR
3f9c7369 15565 BGP_STR
0c7b1b01 15566 "Detailed info about dynamic update groups\n"
3f9c7369
DS
15567 "Statistics\n")
15568{
d62a17ae 15569 struct bgp *bgp;
3f9c7369 15570
d62a17ae 15571 bgp = bgp_get_default();
15572 if (bgp)
15573 update_group_show_stats(bgp, vty);
3f9c7369 15574
d62a17ae 15575 return CMD_SUCCESS;
3f9c7369
DS
15576}
15577
8386ac43 15578DEFUN (show_bgp_instance_updgrps_stats,
15579 show_bgp_instance_updgrps_stats_cmd,
18c57037 15580 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 15581 SHOW_STR
716b2d8a 15582 IP_STR
8386ac43 15583 BGP_STR
15584 BGP_INSTANCE_HELP_STR
0c7b1b01 15585 "Detailed info about dynamic update groups\n"
8386ac43 15586 "Statistics\n")
15587{
d62a17ae 15588 int idx_word = 3;
15589 struct bgp *bgp;
8386ac43 15590
d62a17ae 15591 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15592 if (bgp)
15593 update_group_show_stats(bgp, vty);
8386ac43 15594
d62a17ae 15595 return CMD_SUCCESS;
8386ac43 15596}
15597
d62a17ae 15598static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15599 afi_t afi, safi_t safi,
15600 const char *what, uint64_t subgrp_id)
3f9c7369 15601{
d62a17ae 15602 struct bgp *bgp;
8386ac43 15603
d62a17ae 15604 if (name)
15605 bgp = bgp_lookup_by_name(name);
15606 else
15607 bgp = bgp_get_default();
8386ac43 15608
d62a17ae 15609 if (bgp) {
15610 if (!strcmp(what, "advertise-queue"))
15611 update_group_show_adj_queue(bgp, afi, safi, vty,
15612 subgrp_id);
15613 else if (!strcmp(what, "advertised-routes"))
15614 update_group_show_advertised(bgp, afi, safi, vty,
15615 subgrp_id);
15616 else if (!strcmp(what, "packet-queue"))
15617 update_group_show_packet_queue(bgp, afi, safi, vty,
15618 subgrp_id);
15619 }
3f9c7369
DS
15620}
15621
dc64bdec
QY
15622DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15623 show_ip_bgp_instance_updgrps_adj_s_cmd,
15624 "show [ip]$ip bgp [<view|vrf> VIEWVRFNAME$vrf] [<ipv4|ipv6>$afi <unicast|multicast|vpn>$safi] update-groups [SUBGROUP-ID]$sgid <advertise-queue|advertised-routes|packet-queue>$rtq",
15625 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15626 BGP_SAFI_HELP_STR
15627 "Detailed info about dynamic update groups\n"
15628 "Specific subgroup to display info for\n"
15629 "Advertisement queue\n"
15630 "Announced routes\n"
15631 "Packet queue\n")
3f9c7369 15632{
dc64bdec
QY
15633 uint64_t subgrp_id = 0;
15634 afi_t afiz;
15635 safi_t safiz;
15636 if (sgid)
15637 subgrp_id = strtoull(sgid, NULL, 10);
15638
15639 if (!ip && !afi)
15640 afiz = AFI_IP6;
15641 if (!ip && afi)
15642 afiz = bgp_vty_afi_from_str(afi);
15643 if (ip && !afi)
15644 afiz = AFI_IP;
15645 if (ip && afi) {
15646 afiz = bgp_vty_afi_from_str(afi);
15647 if (afiz != AFI_IP)
15648 vty_out(vty,
15649 "%% Cannot specify both 'ip' and 'ipv6'\n");
15650 return CMD_WARNING;
15651 }
d62a17ae 15652
dc64bdec 15653 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15654
dc64bdec 15655 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15656 return CMD_SUCCESS;
15657}
15658
6f4eacf3
DA
15659static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15660 json_object *json)
d62a17ae 15661{
15662 struct listnode *node, *nnode;
15663 struct prefix *range;
15664 struct peer *conf;
15665 struct peer *peer;
d62a17ae 15666 afi_t afi;
15667 safi_t safi;
15668 const char *peer_status;
d62a17ae 15669 int lr_count;
15670 int dynamic;
6f4eacf3
DA
15671 bool af_cfgd;
15672 json_object *json_peer_group = NULL;
15673 json_object *json_peer_group_afc = NULL;
15674 json_object *json_peer_group_members = NULL;
15675 json_object *json_peer_group_dynamic = NULL;
15676 json_object *json_peer_group_dynamic_af = NULL;
15677 json_object *json_peer_group_ranges = NULL;
d62a17ae 15678
15679 conf = group->conf;
15680
6f4eacf3
DA
15681 if (json) {
15682 json_peer_group = json_object_new_object();
15683 json_peer_group_afc = json_object_new_array();
15684 }
15685
d62a17ae 15686 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3
DA
15687 if (json)
15688 json_object_int_add(json_peer_group, "remoteAs",
15689 conf->as);
15690 else
15691 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15692 group->name, conf->as);
d62a17ae 15693 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3
DA
15694 if (json)
15695 json_object_int_add(json_peer_group, "remoteAs",
15696 group->bgp->as);
15697 else
15698 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15699 group->name, group->bgp->as);
d62a17ae 15700 } else {
6f4eacf3
DA
15701 if (!json)
15702 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 15703 }
f14e6fdb 15704
6f4eacf3
DA
15705 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15706 if (json)
15707 json_object_string_add(json_peer_group, "type",
15708 "internal");
15709 else
15710 vty_out(vty, " Peer-group type is internal\n");
15711 } else {
15712 if (json)
15713 json_object_string_add(json_peer_group, "type",
15714 "external");
15715 else
15716 vty_out(vty, " Peer-group type is external\n");
15717 }
d62a17ae 15718
15719 /* Display AFs configured. */
6f4eacf3
DA
15720 if (!json)
15721 vty_out(vty, " Configured address-families:");
15722
05c7a1cc
QY
15723 FOREACH_AFI_SAFI (afi, safi) {
15724 if (conf->afc[afi][safi]) {
6f4eacf3
DA
15725 af_cfgd = true;
15726 if (json)
15727 json_object_array_add(
15728 json_peer_group_afc,
15729 json_object_new_string(get_afi_safi_str(
15730 afi, safi, false)));
15731 else
15732 vty_out(vty, " %s;",
15733 get_afi_safi_str(afi, safi, false));
d62a17ae 15734 }
05c7a1cc 15735 }
6f4eacf3
DA
15736
15737 if (json) {
15738 json_object_object_add(json_peer_group,
15739 "addressFamiliesConfigured",
15740 json_peer_group_afc);
15741 } else {
15742 if (!af_cfgd)
15743 vty_out(vty, " none\n");
15744 else
15745 vty_out(vty, "\n");
15746 }
d62a17ae 15747
15748 /* Display listen ranges (for dynamic neighbors), if any */
15749 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 15750 lr_count = listcount(group->listen_range[afi]);
15751 if (lr_count) {
6f4eacf3
DA
15752 if (json) {
15753 if (!json_peer_group_dynamic)
15754 json_peer_group_dynamic =
15755 json_object_new_object();
15756
15757 json_peer_group_dynamic_af =
15758 json_object_new_object();
15759 json_peer_group_ranges =
15760 json_object_new_array();
15761 json_object_int_add(json_peer_group_dynamic_af,
15762 "count", lr_count);
15763 } else {
15764 vty_out(vty, " %d %s listen range(s)\n",
15765 lr_count, afi2str(afi));
15766 }
d62a17ae 15767
15768 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
15769 nnode, range)) {
15770 if (json) {
15771 char buf[BUFSIZ];
15772
15773 snprintfrr(buf, sizeof(buf), "%pFX",
15774 range);
15775
15776 json_object_array_add(
15777 json_peer_group_ranges,
15778 json_object_new_string(buf));
15779 } else {
15780 vty_out(vty, " %pFX\n", range);
15781 }
15782 }
15783
15784 if (json) {
15785 json_object_object_add(
15786 json_peer_group_dynamic_af, "ranges",
15787 json_peer_group_ranges);
15788
15789 json_object_object_add(
15790 json_peer_group_dynamic, afi2str(afi),
15791 json_peer_group_dynamic_af);
15792 }
d62a17ae 15793 }
15794 }
f14e6fdb 15795
6f4eacf3
DA
15796 if (json_peer_group_dynamic)
15797 json_object_object_add(json_peer_group, "dynamicRanges",
15798 json_peer_group_dynamic);
15799
d62a17ae 15800 /* Display group members and their status */
15801 if (listcount(group->peer)) {
6f4eacf3
DA
15802 if (json)
15803 json_peer_group_members = json_object_new_object();
15804 else
15805 vty_out(vty, " Peer-group members:\n");
d62a17ae 15806 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15807 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15808 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15809 peer_status = "Idle (Admin)";
15810 else if (CHECK_FLAG(peer->sflags,
15811 PEER_STATUS_PREFIX_OVERFLOW))
15812 peer_status = "Idle (PfxCt)";
15813 else
15814 peer_status = lookup_msg(bgp_status_msg,
15815 peer->status, NULL);
15816
15817 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
15818
15819 if (json) {
15820 json_object *json_peer_group_member =
15821 json_object_new_object();
15822
15823 json_object_string_add(json_peer_group_member,
15824 "status", peer_status);
15825
15826 if (dynamic)
15827 json_object_boolean_true_add(
15828 json_peer_group_member,
15829 "dynamic");
15830
15831 json_object_object_add(json_peer_group_members,
15832 peer->host,
15833 json_peer_group_member);
15834 } else {
15835 vty_out(vty, " %s %s %s \n", peer->host,
15836 dynamic ? "(dynamic)" : "",
15837 peer_status);
15838 }
d62a17ae 15839 }
6f4eacf3
DA
15840 if (json)
15841 json_object_object_add(json_peer_group, "members",
15842 json_peer_group_members);
d62a17ae 15843 }
f14e6fdb 15844
6f4eacf3
DA
15845 if (json)
15846 json_object_object_add(json, group->name, json_peer_group);
15847
d62a17ae 15848 return CMD_SUCCESS;
15849}
15850
ff9959b0 15851static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 15852 const char *group_name, bool uj)
d62a17ae 15853{
ff9959b0 15854 struct bgp *bgp;
d62a17ae 15855 struct listnode *node, *nnode;
15856 struct peer_group *group;
ff9959b0 15857 bool found = false;
6f4eacf3
DA
15858 json_object *json = NULL;
15859
15860 if (uj)
15861 json = json_object_new_object();
ff9959b0
QY
15862
15863 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15864
15865 if (!bgp) {
c48349e3 15866 if (uj)
75eeda93 15867 vty_json(vty, json);
c48349e3 15868 else
6f4eacf3 15869 vty_out(vty, "%% BGP instance not found\n");
6f4eacf3 15870
ff9959b0
QY
15871 return CMD_WARNING;
15872 }
d62a17ae 15873
15874 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15875 if (group_name) {
15876 if (strmatch(group->name, group_name)) {
6f4eacf3 15877 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
15878 found = true;
15879 break;
d62a17ae 15880 }
ff9959b0 15881 } else {
6f4eacf3 15882 bgp_show_one_peer_group(vty, group, json);
d62a17ae 15883 }
f14e6fdb 15884 }
f14e6fdb 15885
6f4eacf3 15886 if (group_name && !found && !uj)
d62a17ae 15887 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15888
c48349e3 15889 if (uj)
75eeda93 15890 vty_json(vty, json);
6f4eacf3 15891
d62a17ae 15892 return CMD_SUCCESS;
f14e6fdb
DS
15893}
15894
6f4eacf3
DA
15895DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15896 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15897 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15898 "Detailed information on BGP peer groups\n"
15899 "Peer group name\n" JSON_STR)
f14e6fdb 15900{
d62a17ae 15901 char *vrf, *pg;
d62a17ae 15902 int idx = 0;
6f4eacf3 15903 bool uj = use_json(argc, argv);
f14e6fdb 15904
a4d82a8a
PZ
15905 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15906 : NULL;
d62a17ae 15907 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15908
6f4eacf3 15909 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 15910}
3f9c7369 15911
d6e3c605 15912
718e3744 15913/* Redistribute VTY commands. */
15914
585f1adc
IR
15915DEFUN (bgp_redistribute_ipv4,
15916 bgp_redistribute_ipv4_cmd,
15917 "redistribute " FRR_IP_REDIST_STR_BGPD,
15918 "Redistribute information from another routing protocol\n"
15919 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 15920{
585f1adc 15921 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15922 int idx_protocol = 1;
585f1adc 15923 int type;
37a87b8f 15924
585f1adc
IR
15925 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15926 if (type < 0) {
15927 vty_out(vty, "%% Invalid route type\n");
15928 return CMD_WARNING_CONFIG_FAILED;
15929 }
7f323236 15930
585f1adc
IR
15931 bgp_redist_add(bgp, AFI_IP, type, 0);
15932 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 15933}
15934
d62a17ae 15935ALIAS_HIDDEN(
15936 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15937 "redistribute " FRR_IP_REDIST_STR_BGPD,
15938 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 15939
585f1adc
IR
15940DEFUN (bgp_redistribute_ipv4_rmap,
15941 bgp_redistribute_ipv4_rmap_cmd,
70dd370f 15942 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
585f1adc
IR
15943 "Redistribute information from another routing protocol\n"
15944 FRR_IP_REDIST_HELP_STR_BGPD
15945 "Route map reference\n"
15946 "Pointer to route-map entries\n")
718e3744 15947{
585f1adc 15948 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15949 int idx_protocol = 1;
15950 int idx_word = 3;
585f1adc
IR
15951 int type;
15952 struct bgp_redist *red;
15953 bool changed;
15954 struct route_map *route_map = route_map_lookup_warn_noexist(
15955 vty, argv[idx_word]->arg);
15956
15957 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15958 if (type < 0) {
15959 vty_out(vty, "%% Invalid route type\n");
15960 return CMD_WARNING_CONFIG_FAILED;
15961 }
37a87b8f 15962
585f1adc
IR
15963 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15964 changed =
15965 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15966 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 15967}
15968
d62a17ae 15969ALIAS_HIDDEN(
15970 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
70dd370f 15971 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
d62a17ae 15972 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15973 "Route map reference\n"
15974 "Pointer to route-map entries\n")
596c17ba 15975
585f1adc
IR
15976DEFUN (bgp_redistribute_ipv4_metric,
15977 bgp_redistribute_ipv4_metric_cmd,
15978 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15979 "Redistribute information from another routing protocol\n"
15980 FRR_IP_REDIST_HELP_STR_BGPD
15981 "Metric for redistributed routes\n"
15982 "Default metric\n")
718e3744 15983{
585f1adc 15984 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15985 int idx_protocol = 1;
15986 int idx_number = 3;
585f1adc
IR
15987 int type;
15988 uint32_t metric;
15989 struct bgp_redist *red;
15990 bool changed;
15991
15992 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15993 if (type < 0) {
15994 vty_out(vty, "%% Invalid route type\n");
15995 return CMD_WARNING_CONFIG_FAILED;
15996 }
15997 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15998
585f1adc
IR
15999 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16000 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16001 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16002}
16003
16004ALIAS_HIDDEN(
16005 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16006 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16007 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16008 "Metric for redistributed routes\n"
16009 "Default metric\n")
596c17ba 16010
585f1adc
IR
16011DEFUN (bgp_redistribute_ipv4_rmap_metric,
16012 bgp_redistribute_ipv4_rmap_metric_cmd,
70dd370f 16013 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16014 "Redistribute information from another routing protocol\n"
16015 FRR_IP_REDIST_HELP_STR_BGPD
16016 "Route map reference\n"
16017 "Pointer to route-map entries\n"
16018 "Metric for redistributed routes\n"
16019 "Default metric\n")
718e3744 16020{
585f1adc 16021 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16022 int idx_protocol = 1;
16023 int idx_word = 3;
16024 int idx_number = 5;
585f1adc
IR
16025 int type;
16026 uint32_t metric;
16027 struct bgp_redist *red;
16028 bool changed;
16029 struct route_map *route_map =
16030 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16031
16032 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16033 if (type < 0) {
16034 vty_out(vty, "%% Invalid route type\n");
16035 return CMD_WARNING_CONFIG_FAILED;
16036 }
16037 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 16038
585f1adc
IR
16039 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16040 changed =
16041 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16042 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16043 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16044}
16045
16046ALIAS_HIDDEN(
16047 bgp_redistribute_ipv4_rmap_metric,
16048 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16049 "redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16050 " route-map RMAP_NAME metric (0-4294967295)",
d62a17ae 16051 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16052 "Route map reference\n"
16053 "Pointer to route-map entries\n"
16054 "Metric for redistributed routes\n"
16055 "Default metric\n")
596c17ba 16056
585f1adc
IR
16057DEFUN (bgp_redistribute_ipv4_metric_rmap,
16058 bgp_redistribute_ipv4_metric_rmap_cmd,
70dd370f 16059 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16060 "Redistribute information from another routing protocol\n"
16061 FRR_IP_REDIST_HELP_STR_BGPD
16062 "Metric for redistributed routes\n"
16063 "Default metric\n"
16064 "Route map reference\n"
16065 "Pointer to route-map entries\n")
718e3744 16066{
585f1adc 16067 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16068 int idx_protocol = 1;
37a87b8f 16069 int idx_number = 3;
585f1adc
IR
16070 int idx_word = 5;
16071 int type;
16072 uint32_t metric;
16073 struct bgp_redist *red;
16074 bool changed;
16075 struct route_map *route_map =
16076 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16077
16078 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16079 if (type < 0) {
16080 vty_out(vty, "%% Invalid route type\n");
16081 return CMD_WARNING_CONFIG_FAILED;
16082 }
16083 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 16084
585f1adc
IR
16085 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16086 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16087 changed |=
16088 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16089 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16090}
16091
16092ALIAS_HIDDEN(
16093 bgp_redistribute_ipv4_metric_rmap,
16094 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16095 "redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16096 " metric (0-4294967295) route-map RMAP_NAME",
d62a17ae 16097 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16098 "Metric for redistributed routes\n"
16099 "Default metric\n"
16100 "Route map reference\n"
16101 "Pointer to route-map entries\n")
596c17ba 16102
585f1adc
IR
16103DEFUN (bgp_redistribute_ipv4_ospf,
16104 bgp_redistribute_ipv4_ospf_cmd,
16105 "redistribute <ospf|table> (1-65535)",
16106 "Redistribute information from another routing protocol\n"
16107 "Open Shortest Path First (OSPFv2)\n"
16108 "Non-main Kernel Routing Table\n"
16109 "Instance ID/Table ID\n")
7c8ff89e 16110{
585f1adc
IR
16111 VTY_DECLVAR_CONTEXT(bgp, bgp);
16112 int idx_ospf_table = 1;
d62a17ae 16113 int idx_number = 2;
585f1adc
IR
16114 unsigned short instance;
16115 unsigned short protocol;
7c8ff89e 16116
585f1adc 16117 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 16118
585f1adc
IR
16119 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16120 protocol = ZEBRA_ROUTE_OSPF;
16121 else
16122 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 16123
585f1adc
IR
16124 bgp_redist_add(bgp, AFI_IP, protocol, instance);
16125 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
16126}
16127
d62a17ae 16128ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16129 "redistribute <ospf|table> (1-65535)",
16130 "Redistribute information from another routing protocol\n"
16131 "Open Shortest Path First (OSPFv2)\n"
16132 "Non-main Kernel Routing Table\n"
16133 "Instance ID/Table ID\n")
596c17ba 16134
585f1adc
IR
16135DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16136 bgp_redistribute_ipv4_ospf_rmap_cmd,
70dd370f 16137 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
585f1adc
IR
16138 "Redistribute information from another routing protocol\n"
16139 "Open Shortest Path First (OSPFv2)\n"
16140 "Non-main Kernel Routing Table\n"
16141 "Instance ID/Table ID\n"
16142 "Route map reference\n"
16143 "Pointer to route-map entries\n")
7c8ff89e 16144{
585f1adc
IR
16145 VTY_DECLVAR_CONTEXT(bgp, bgp);
16146 int idx_ospf_table = 1;
d62a17ae 16147 int idx_number = 2;
16148 int idx_word = 4;
585f1adc
IR
16149 struct bgp_redist *red;
16150 unsigned short instance;
16151 int protocol;
16152 bool changed;
16153 struct route_map *route_map =
16154 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16155
16156 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16157 protocol = ZEBRA_ROUTE_OSPF;
16158 else
16159 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16160
585f1adc
IR
16161 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16162 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16163 changed =
16164 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16165 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16166}
16167
16168ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16169 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
70dd370f 16170 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
d62a17ae 16171 "Redistribute information from another routing protocol\n"
16172 "Open Shortest Path First (OSPFv2)\n"
16173 "Non-main Kernel Routing Table\n"
16174 "Instance ID/Table ID\n"
16175 "Route map reference\n"
16176 "Pointer to route-map entries\n")
596c17ba 16177
585f1adc
IR
16178DEFUN (bgp_redistribute_ipv4_ospf_metric,
16179 bgp_redistribute_ipv4_ospf_metric_cmd,
16180 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16181 "Redistribute information from another routing protocol\n"
16182 "Open Shortest Path First (OSPFv2)\n"
16183 "Non-main Kernel Routing Table\n"
16184 "Instance ID/Table ID\n"
16185 "Metric for redistributed routes\n"
16186 "Default metric\n")
7c8ff89e 16187{
585f1adc
IR
16188 VTY_DECLVAR_CONTEXT(bgp, bgp);
16189 int idx_ospf_table = 1;
d62a17ae 16190 int idx_number = 2;
16191 int idx_number_2 = 4;
585f1adc
IR
16192 uint32_t metric;
16193 struct bgp_redist *red;
16194 unsigned short instance;
16195 int protocol;
16196 bool changed;
16197
16198 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16199 protocol = ZEBRA_ROUTE_OSPF;
16200 else
16201 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16202
585f1adc
IR
16203 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16204 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16205
585f1adc
IR
16206 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16207 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16208 metric);
16209 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16210}
16211
16212ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16213 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16214 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16215 "Redistribute information from another routing protocol\n"
16216 "Open Shortest Path First (OSPFv2)\n"
16217 "Non-main Kernel Routing Table\n"
16218 "Instance ID/Table ID\n"
16219 "Metric for redistributed routes\n"
16220 "Default metric\n")
596c17ba 16221
585f1adc
IR
16222DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16223 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
70dd370f 16224 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16225 "Redistribute information from another routing protocol\n"
16226 "Open Shortest Path First (OSPFv2)\n"
16227 "Non-main Kernel Routing Table\n"
16228 "Instance ID/Table ID\n"
16229 "Route map reference\n"
16230 "Pointer to route-map entries\n"
16231 "Metric for redistributed routes\n"
16232 "Default metric\n")
7c8ff89e 16233{
585f1adc
IR
16234 VTY_DECLVAR_CONTEXT(bgp, bgp);
16235 int idx_ospf_table = 1;
d62a17ae 16236 int idx_number = 2;
16237 int idx_word = 4;
16238 int idx_number_2 = 6;
585f1adc
IR
16239 uint32_t metric;
16240 struct bgp_redist *red;
16241 unsigned short instance;
16242 int protocol;
16243 bool changed;
16244 struct route_map *route_map =
16245 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16246
16247 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16248 protocol = ZEBRA_ROUTE_OSPF;
16249 else
16250 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16251
585f1adc
IR
16252 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16253 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16254
585f1adc
IR
16255 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16256 changed =
16257 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16258 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16259 metric);
16260 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16261}
16262
16263ALIAS_HIDDEN(
16264 bgp_redistribute_ipv4_ospf_rmap_metric,
16265 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
70dd370f 16266 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
d62a17ae 16267 "Redistribute information from another routing protocol\n"
16268 "Open Shortest Path First (OSPFv2)\n"
16269 "Non-main Kernel Routing Table\n"
16270 "Instance ID/Table ID\n"
16271 "Route map reference\n"
16272 "Pointer to route-map entries\n"
16273 "Metric for redistributed routes\n"
16274 "Default metric\n")
596c17ba 16275
585f1adc
IR
16276DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16277 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
70dd370f 16278 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16279 "Redistribute information from another routing protocol\n"
16280 "Open Shortest Path First (OSPFv2)\n"
16281 "Non-main Kernel Routing Table\n"
16282 "Instance ID/Table ID\n"
16283 "Metric for redistributed routes\n"
16284 "Default metric\n"
16285 "Route map reference\n"
16286 "Pointer to route-map entries\n")
7c8ff89e 16287{
585f1adc
IR
16288 VTY_DECLVAR_CONTEXT(bgp, bgp);
16289 int idx_ospf_table = 1;
d62a17ae 16290 int idx_number = 2;
16291 int idx_number_2 = 4;
16292 int idx_word = 6;
585f1adc
IR
16293 uint32_t metric;
16294 struct bgp_redist *red;
16295 unsigned short instance;
16296 int protocol;
16297 bool changed;
16298 struct route_map *route_map =
16299 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16300
16301 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16302 protocol = ZEBRA_ROUTE_OSPF;
16303 else
16304 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16305
585f1adc
IR
16306 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16307 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16308
585f1adc
IR
16309 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16310 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16311 metric);
16312 changed |=
16313 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16314 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16315}
16316
16317ALIAS_HIDDEN(
16318 bgp_redistribute_ipv4_ospf_metric_rmap,
16319 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
70dd370f 16320 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
d62a17ae 16321 "Redistribute information from another routing protocol\n"
16322 "Open Shortest Path First (OSPFv2)\n"
16323 "Non-main Kernel Routing Table\n"
16324 "Instance ID/Table ID\n"
16325 "Metric for redistributed routes\n"
16326 "Default metric\n"
16327 "Route map reference\n"
16328 "Pointer to route-map entries\n")
596c17ba 16329
585f1adc
IR
16330DEFUN (no_bgp_redistribute_ipv4_ospf,
16331 no_bgp_redistribute_ipv4_ospf_cmd,
70dd370f 16332 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16333 NO_STR
16334 "Redistribute information from another routing protocol\n"
16335 "Open Shortest Path First (OSPFv2)\n"
16336 "Non-main Kernel Routing Table\n"
16337 "Instance ID/Table ID\n"
16338 "Metric for redistributed routes\n"
16339 "Default metric\n"
16340 "Route map reference\n"
16341 "Pointer to route-map entries\n")
7c8ff89e 16342{
585f1adc
IR
16343 VTY_DECLVAR_CONTEXT(bgp, bgp);
16344 int idx_ospf_table = 2;
d62a17ae 16345 int idx_number = 3;
585f1adc
IR
16346 unsigned short instance;
16347 int protocol;
37a87b8f 16348
585f1adc
IR
16349 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16350 protocol = ZEBRA_ROUTE_OSPF;
16351 else
16352 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16353
585f1adc
IR
16354 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16355 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
d62a17ae 16356}
16357
16358ALIAS_HIDDEN(
16359 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
70dd370f 16360 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
d62a17ae 16361 NO_STR
16362 "Redistribute information from another routing protocol\n"
16363 "Open Shortest Path First (OSPFv2)\n"
16364 "Non-main Kernel Routing Table\n"
16365 "Instance ID/Table ID\n"
16366 "Metric for redistributed routes\n"
16367 "Default metric\n"
16368 "Route map reference\n"
16369 "Pointer to route-map entries\n")
596c17ba 16370
585f1adc
IR
16371DEFUN (no_bgp_redistribute_ipv4,
16372 no_bgp_redistribute_ipv4_cmd,
70dd370f 16373 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16374 NO_STR
16375 "Redistribute information from another routing protocol\n"
16376 FRR_IP_REDIST_HELP_STR_BGPD
16377 "Metric for redistributed routes\n"
16378 "Default metric\n"
16379 "Route map reference\n"
16380 "Pointer to route-map entries\n")
718e3744 16381{
585f1adc 16382 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16383 int idx_protocol = 2;
585f1adc 16384 int type;
d62a17ae 16385
585f1adc
IR
16386 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16387 if (type < 0) {
16388 vty_out(vty, "%% Invalid route type\n");
16389 return CMD_WARNING_CONFIG_FAILED;
16390 }
16391 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
d62a17ae 16392}
16393
16394ALIAS_HIDDEN(
16395 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16396 "no redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16397 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
d62a17ae 16398 NO_STR
16399 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16400 "Metric for redistributed routes\n"
16401 "Default metric\n"
16402 "Route map reference\n"
16403 "Pointer to route-map entries\n")
596c17ba 16404
585f1adc
IR
16405DEFUN (bgp_redistribute_ipv6,
16406 bgp_redistribute_ipv6_cmd,
16407 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16408 "Redistribute information from another routing protocol\n"
16409 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 16410{
585f1adc 16411 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16412 int idx_protocol = 1;
585f1adc 16413 int type;
718e3744 16414
585f1adc
IR
16415 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16416 if (type < 0) {
16417 vty_out(vty, "%% Invalid route type\n");
16418 return CMD_WARNING_CONFIG_FAILED;
16419 }
718e3744 16420
585f1adc
IR
16421 bgp_redist_add(bgp, AFI_IP6, type, 0);
16422 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 16423}
16424
585f1adc
IR
16425DEFUN (bgp_redistribute_ipv6_rmap,
16426 bgp_redistribute_ipv6_rmap_cmd,
70dd370f 16427 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
585f1adc
IR
16428 "Redistribute information from another routing protocol\n"
16429 FRR_IP6_REDIST_HELP_STR_BGPD
16430 "Route map reference\n"
16431 "Pointer to route-map entries\n")
718e3744 16432{
585f1adc 16433 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16434 int idx_protocol = 1;
16435 int idx_word = 3;
585f1adc
IR
16436 int type;
16437 struct bgp_redist *red;
16438 bool changed;
16439 struct route_map *route_map =
16440 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16441
16442 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16443 if (type < 0) {
16444 vty_out(vty, "%% Invalid route type\n");
16445 return CMD_WARNING_CONFIG_FAILED;
16446 }
37a87b8f 16447
585f1adc
IR
16448 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16449 changed =
16450 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16451 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16452}
16453
585f1adc 16454DEFUN (bgp_redistribute_ipv6_metric,
718e3744 16455 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 16456 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 16457 "Redistribute information from another routing protocol\n"
ab0181ee 16458 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 16459 "Metric for redistributed routes\n"
16460 "Default metric\n")
16461{
585f1adc 16462 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16463 int idx_protocol = 1;
16464 int idx_number = 3;
585f1adc
IR
16465 int type;
16466 uint32_t metric;
16467 struct bgp_redist *red;
16468 bool changed;
16469
16470 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16471 if (type < 0) {
16472 vty_out(vty, "%% Invalid route type\n");
16473 return CMD_WARNING_CONFIG_FAILED;
16474 }
16475 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16476
585f1adc
IR
16477 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16478 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16479 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16480}
16481
585f1adc
IR
16482DEFUN (bgp_redistribute_ipv6_rmap_metric,
16483 bgp_redistribute_ipv6_rmap_metric_cmd,
70dd370f 16484 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16485 "Redistribute information from another routing protocol\n"
16486 FRR_IP6_REDIST_HELP_STR_BGPD
16487 "Route map reference\n"
16488 "Pointer to route-map entries\n"
16489 "Metric for redistributed routes\n"
16490 "Default metric\n")
718e3744 16491{
585f1adc 16492 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16493 int idx_protocol = 1;
16494 int idx_word = 3;
16495 int idx_number = 5;
585f1adc
IR
16496 int type;
16497 uint32_t metric;
16498 struct bgp_redist *red;
16499 bool changed;
16500 struct route_map *route_map =
16501 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16502
16503 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16504 if (type < 0) {
16505 vty_out(vty, "%% Invalid route type\n");
16506 return CMD_WARNING_CONFIG_FAILED;
16507 }
16508 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16509
585f1adc
IR
16510 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16511 changed =
16512 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16513 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16514 metric);
16515 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16516}
16517
585f1adc
IR
16518DEFUN (bgp_redistribute_ipv6_metric_rmap,
16519 bgp_redistribute_ipv6_metric_rmap_cmd,
70dd370f 16520 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16521 "Redistribute information from another routing protocol\n"
16522 FRR_IP6_REDIST_HELP_STR_BGPD
16523 "Metric for redistributed routes\n"
16524 "Default metric\n"
16525 "Route map reference\n"
16526 "Pointer to route-map entries\n")
718e3744 16527{
585f1adc 16528 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16529 int idx_protocol = 1;
37a87b8f 16530 int idx_number = 3;
585f1adc
IR
16531 int idx_word = 5;
16532 int type;
16533 uint32_t metric;
16534 struct bgp_redist *red;
16535 bool changed;
16536 struct route_map *route_map =
16537 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16538
16539 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16540 if (type < 0) {
16541 vty_out(vty, "%% Invalid route type\n");
16542 return CMD_WARNING_CONFIG_FAILED;
16543 }
16544 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16545
585f1adc
IR
16546 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16547 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16548 metric);
16549 changed |=
16550 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16551 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16552}
16553
585f1adc
IR
16554DEFUN (no_bgp_redistribute_ipv6,
16555 no_bgp_redistribute_ipv6_cmd,
70dd370f 16556 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16557 NO_STR
16558 "Redistribute information from another routing protocol\n"
16559 FRR_IP6_REDIST_HELP_STR_BGPD
16560 "Metric for redistributed routes\n"
16561 "Default metric\n"
16562 "Route map reference\n"
16563 "Pointer to route-map entries\n")
718e3744 16564{
585f1adc 16565 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16566 int idx_protocol = 2;
585f1adc 16567 int type;
37a87b8f 16568
585f1adc
IR
16569 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16570 if (type < 0) {
16571 vty_out(vty, "%% Invalid route type\n");
16572 return CMD_WARNING_CONFIG_FAILED;
16573 }
718e3744 16574
585f1adc 16575 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
d62a17ae 16576}
16577
4ab46701
AR
16578/* Neighbor update tcp-mss. */
16579static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16580 const char *tcp_mss_str)
16581{
16582 struct peer *peer;
16583 uint32_t tcp_mss_val = 0;
16584
16585 peer = peer_and_group_lookup_vty(vty, peer_str);
16586 if (!peer)
16587 return CMD_WARNING_CONFIG_FAILED;
16588
16589 if (tcp_mss_str) {
16590 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16591 peer_tcp_mss_set(peer, tcp_mss_val);
16592 } else {
16593 peer_tcp_mss_unset(peer);
16594 }
16595
16596 return CMD_SUCCESS;
16597}
16598
16599DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16600 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16601 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16602 "TCP max segment size\n"
16603 "TCP MSS value\n")
16604{
16605 int peer_index = 1;
16606 int mss_index = 3;
16607
16608 vty_out(vty,
16609 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16610 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16611 argv[mss_index]->arg);
16612}
16613
16614DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16615 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16616 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16617 "TCP max segment size\n"
16618 "TCP MSS value\n")
16619{
16620 int peer_index = 2;
16621
16622 vty_out(vty,
16623 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16624 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16625}
16626
a486300b
PG
16627DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16628 "[no$no] bgp retain route-target all",
16629 NO_STR BGP_STR
16630 "Retain BGP updates\n"
16631 "Retain BGP updates based on route-target values\n"
16632 "Retain all BGP updates\n")
16633{
16634 bool check;
16635 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16636
16637 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16638 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16639 if (check != !no) {
16640 if (!no)
16641 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16642 [bgp_node_safi(vty)],
16643 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16644 else
16645 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16646 [bgp_node_safi(vty)],
16647 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16648 /* trigger a flush to re-sync with ADJ-RIB-in */
16649 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16650 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16651 }
16652 return CMD_SUCCESS;
16653}
16654
dd65f45e
DL
16655static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16656 afi_t afi, safi_t safi)
d62a17ae 16657{
16658 int i;
16659
16660 /* Unicast redistribution only. */
16661 if (safi != SAFI_UNICAST)
2b791107 16662 return;
d62a17ae 16663
16664 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16665 /* Redistribute BGP does not make sense. */
16666 if (i != ZEBRA_ROUTE_BGP) {
16667 struct list *red_list;
16668 struct listnode *node;
16669 struct bgp_redist *red;
16670
16671 red_list = bgp->redist[afi][i];
16672 if (!red_list)
16673 continue;
16674
16675 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16676 /* "redistribute" configuration. */
16677 vty_out(vty, " redistribute %s",
16678 zebra_route_string(i));
16679 if (red->instance)
16680 vty_out(vty, " %d", red->instance);
16681 if (red->redist_metric_flag)
16682 vty_out(vty, " metric %u",
16683 red->redist_metric);
16684 if (red->rmap.name)
16685 vty_out(vty, " route-map %s",
16686 red->rmap.name);
16687 vty_out(vty, "\n");
16688 }
16689 }
16690 }
718e3744 16691}
6b0655a2 16692
dd65f45e
DL
16693/* peer-group helpers for config-write */
16694
83194f39 16695static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
dd65f45e
DL
16696{
16697 if (!peer_group_active(peer)) {
16698 if (CHECK_FLAG(peer->flags_invert, flag))
16699 return !CHECK_FLAG(peer->flags, flag);
16700 else
16701 return !!CHECK_FLAG(peer->flags, flag);
16702 }
16703
16704 return !!CHECK_FLAG(peer->flags_override, flag);
16705}
16706
16707static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
da5e1a58 16708 uint64_t flag)
dd65f45e
DL
16709{
16710 if (!peer_group_active(peer)) {
16711 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16712 return !peer_af_flag_check(peer, afi, safi, flag);
16713 else
16714 return !!peer_af_flag_check(peer, afi, safi, flag);
16715 }
16716
16717 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16718}
16719
16720static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16721 uint8_t type, int direct)
16722{
16723 struct bgp_filter *filter;
16724
16725 if (peer_group_active(peer))
16726 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16727 type);
16728
16729 filter = &peer->filter[afi][safi];
16730 switch (type) {
16731 case PEER_FT_DISTRIBUTE_LIST:
16732 return !!(filter->dlist[direct].name);
16733 case PEER_FT_FILTER_LIST:
16734 return !!(filter->aslist[direct].name);
16735 case PEER_FT_PREFIX_LIST:
16736 return !!(filter->plist[direct].name);
16737 case PEER_FT_ROUTE_MAP:
16738 return !!(filter->map[direct].name);
16739 case PEER_FT_UNSUPPRESS_MAP:
16740 return !!(filter->usmap.name);
7f7940e6
MK
16741 case PEER_FT_ADVERTISE_MAP:
16742 return !!(filter->advmap.aname
16743 && ((filter->advmap.condition == direct)
16744 && filter->advmap.cname));
dd65f45e
DL
16745 default:
16746 return false;
16747 }
16748}
16749
16750/* Return true if the addpath type is set for peer and different from
16751 * peer-group.
16752 */
3dc339cd
DA
16753static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16754 safi_t safi)
dd65f45e
DL
16755{
16756 enum bgp_addpath_strat type, g_type;
16757
16758 type = peer->addpath_type[afi][safi];
16759
16760 if (type != BGP_ADDPATH_NONE) {
16761 if (peer_group_active(peer)) {
16762 g_type = peer->group->conf->addpath_type[afi][safi];
16763
16764 if (type != g_type)
3dc339cd 16765 return true;
dd65f45e 16766 else
3dc339cd 16767 return false;
dd65f45e
DL
16768 }
16769
3dc339cd 16770 return true;
dd65f45e
DL
16771 }
16772
3dc339cd 16773 return false;
dd65f45e
DL
16774}
16775
b9c7bc5a 16776/* This is part of the address-family block (unicast only) */
dd65f45e 16777static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16778 afi_t afi)
16779{
b9c7bc5a 16780 int indent = 2;
53970de3 16781 uint32_t tovpn_sid_index = 0;
ddb5b488 16782
8a066a70 16783 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16784 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16785 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16786 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16787 bgp->vpn_policy[afi]
bb4f6190 16788 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16789 else
16790 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16791 bgp->vpn_policy[afi]
16792 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16793 }
12a844a5
DS
16794 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16795 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16796 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16797 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16798 return;
16799
e70e9f8e
PZ
16800 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16801 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16802
16803 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16804
16805 } else {
16806 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16807 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16808 bgp->vpn_policy[afi].tovpn_label);
16809 }
ddb5b488 16810 }
53970de3
RS
16811
16812 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16813 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16814 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16815 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16816 } else if (tovpn_sid_index != 0) {
16817 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16818 tovpn_sid_index);
16819 }
16820
c4f64ea9
DA
16821 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
16822 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
16823 &bgp->vpn_policy[afi].tovpn_rd);
16824
ddb5b488
PZ
16825 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16826 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16827
16828 char buf[PREFIX_STRLEN];
16829 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16830 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16831 sizeof(buf))) {
16832
b9c7bc5a
PZ
16833 vty_out(vty, "%*snexthop vpn export %s\n",
16834 indent, "", buf);
ddb5b488
PZ
16835 }
16836 }
16837 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16838 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16839 && ecommunity_cmp(
16840 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16841 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16842
16843 char *b = ecommunity_ecom2str(
16844 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16845 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16846 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16847 XFREE(MTYPE_ECOMMUNITY_STR, b);
16848 } else {
16849 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16850 char *b = ecommunity_ecom2str(
16851 bgp->vpn_policy[afi]
16852 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16853 ECOMMUNITY_FORMAT_ROUTE_MAP,
16854 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16855 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16856 XFREE(MTYPE_ECOMMUNITY_STR, b);
16857 }
16858 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16859 char *b = ecommunity_ecom2str(
16860 bgp->vpn_policy[afi]
16861 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16862 ECOMMUNITY_FORMAT_ROUTE_MAP,
16863 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16864 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16865 XFREE(MTYPE_ECOMMUNITY_STR, b);
16866 }
16867 }
bb4f6190
DS
16868
16869 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16870 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16871 bgp->vpn_policy[afi]
16872 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16873
301ad80a
PG
16874 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16875 char *b = ecommunity_ecom2str(
16876 bgp->vpn_policy[afi]
16877 .import_redirect_rtlist,
16878 ECOMMUNITY_FORMAT_ROUTE_MAP,
16879 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16880
9a659715
PG
16881 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16882 != ECOMMUNITY_SIZE)
c6423c31 16883 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16884 indent, "", b);
16885 else
16886 vty_out(vty, "%*srt redirect import %s\n",
16887 indent, "", b);
301ad80a
PG
16888 XFREE(MTYPE_ECOMMUNITY_STR, b);
16889 }
ddb5b488
PZ
16890}
16891
dd65f45e
DL
16892static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16893 afi_t afi, safi_t safi)
16894{
16895 struct bgp_filter *filter;
16896 char *addr;
16897
16898 addr = peer->host;
16899 filter = &peer->filter[afi][safi];
16900
16901 /* distribute-list. */
16902 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16903 FILTER_IN))
16904 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16905 filter->dlist[FILTER_IN].name);
16906
16907 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16908 FILTER_OUT))
16909 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16910 filter->dlist[FILTER_OUT].name);
16911
16912 /* prefix-list. */
16913 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16914 FILTER_IN))
16915 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16916 filter->plist[FILTER_IN].name);
16917
16918 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16919 FILTER_OUT))
16920 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16921 filter->plist[FILTER_OUT].name);
16922
16923 /* route-map. */
16924 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16925 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16926 filter->map[RMAP_IN].name);
16927
16928 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16929 RMAP_OUT))
16930 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16931 filter->map[RMAP_OUT].name);
16932
16933 /* unsuppress-map */
16934 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16935 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16936 filter->usmap.name);
16937
7f7940e6
MK
16938 /* advertise-map : always applied in OUT direction*/
16939 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16940 CONDITION_NON_EXIST))
16941 vty_out(vty,
16942 " neighbor %s advertise-map %s non-exist-map %s\n",
16943 addr, filter->advmap.aname, filter->advmap.cname);
16944
16945 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16946 CONDITION_EXIST))
16947 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16948 addr, filter->advmap.aname, filter->advmap.cname);
16949
dd65f45e
DL
16950 /* filter-list. */
16951 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16952 FILTER_IN))
16953 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16954 filter->aslist[FILTER_IN].name);
16955
16956 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16957 FILTER_OUT))
16958 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16959 filter->aslist[FILTER_OUT].name);
16960}
16961
16962/* BGP peer configuration display function. */
16963static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16964 struct peer *peer)
16965{
16966 struct peer *g_peer = NULL;
dd65f45e
DL
16967 char *addr;
16968 int if_pg_printed = false;
16969 int if_ras_printed = false;
16970
16971 /* Skip dynamic neighbors. */
16972 if (peer_dynamic_neighbor(peer))
16973 return;
16974
16975 if (peer->conf_if)
16976 addr = peer->conf_if;
16977 else
16978 addr = peer->host;
16979
16980 /************************************
16981 ****** Global to the neighbor ******
16982 ************************************/
16983 if (peer->conf_if) {
16984 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16985 vty_out(vty, " neighbor %s interface v6only", addr);
16986 else
16987 vty_out(vty, " neighbor %s interface", addr);
16988
16989 if (peer_group_active(peer)) {
16990 vty_out(vty, " peer-group %s", peer->group->name);
16991 if_pg_printed = true;
16992 } else if (peer->as_type == AS_SPECIFIED) {
16993 vty_out(vty, " remote-as %u", peer->as);
16994 if_ras_printed = true;
16995 } else if (peer->as_type == AS_INTERNAL) {
16996 vty_out(vty, " remote-as internal");
16997 if_ras_printed = true;
16998 } else if (peer->as_type == AS_EXTERNAL) {
16999 vty_out(vty, " remote-as external");
17000 if_ras_printed = true;
17001 }
17002
17003 vty_out(vty, "\n");
17004 }
17005
17006 /* remote-as and peer-group */
17007 /* peer is a member of a peer-group */
17008 if (peer_group_active(peer)) {
17009 g_peer = peer->group->conf;
17010
17011 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17012 if (peer->as_type == AS_SPECIFIED) {
17013 vty_out(vty, " neighbor %s remote-as %u\n",
17014 addr, peer->as);
17015 } else if (peer->as_type == AS_INTERNAL) {
17016 vty_out(vty,
17017 " neighbor %s remote-as internal\n",
17018 addr);
17019 } else if (peer->as_type == AS_EXTERNAL) {
17020 vty_out(vty,
17021 " neighbor %s remote-as external\n",
17022 addr);
17023 }
17024 }
17025
17026 /* For swpX peers we displayed the peer-group
17027 * via 'neighbor swpX interface peer-group PGNAME' */
17028 if (!if_pg_printed)
17029 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17030 peer->group->name);
17031 }
17032
17033 /* peer is NOT a member of a peer-group */
17034 else {
17035 /* peer is a peer-group, declare the peer-group */
17036 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17037 vty_out(vty, " neighbor %s peer-group\n", addr);
17038 }
17039
17040 if (!if_ras_printed) {
17041 if (peer->as_type == AS_SPECIFIED) {
17042 vty_out(vty, " neighbor %s remote-as %u\n",
17043 addr, peer->as);
17044 } else if (peer->as_type == AS_INTERNAL) {
17045 vty_out(vty,
17046 " neighbor %s remote-as internal\n",
17047 addr);
17048 } else if (peer->as_type == AS_EXTERNAL) {
17049 vty_out(vty,
17050 " neighbor %s remote-as external\n",
17051 addr);
17052 }
17053 }
17054 }
17055
17056 /* local-as */
17057 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
17058 vty_out(vty, " neighbor %s local-as %u", addr,
17059 peer->change_local_as);
17060 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17061 vty_out(vty, " no-prepend");
17062 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17063 vty_out(vty, " replace-as");
17064 vty_out(vty, "\n");
17065 }
17066
17067 /* description */
17068 if (peer->desc) {
17069 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17070 }
17071
17072 /* shutdown */
17073 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17074 if (peer->tx_shutdown_message)
17075 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17076 peer->tx_shutdown_message);
17077 else
17078 vty_out(vty, " neighbor %s shutdown\n", addr);
17079 }
17080
8336c896
DA
17081 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17082 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17083 peer->rtt_expected, peer->rtt_keepalive_conf);
17084
dd65f45e 17085 /* bfd */
21bfce98
RZ
17086 if (peer->bfd_config)
17087 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
17088
17089 /* password */
17090 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17091 vty_out(vty, " neighbor %s password %s\n", addr,
17092 peer->password);
17093
17094 /* neighbor solo */
17095 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17096 if (!peer_group_active(peer)) {
17097 vty_out(vty, " neighbor %s solo\n", addr);
17098 }
17099 }
17100
17101 /* BGP port */
17102 if (peer->port != BGP_PORT_DEFAULT) {
17103 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17104 }
17105
17106 /* Local interface name */
17107 if (peer->ifname) {
17108 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17109 }
17110
4ab46701
AR
17111 /* TCP max segment size */
17112 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17113 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17114
dd65f45e
DL
17115 /* passive */
17116 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17117 vty_out(vty, " neighbor %s passive\n", addr);
17118
17119 /* ebgp-multihop */
17120 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
17121 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17122 && peer->ttl == MAXTTL)) {
dd65f45e
DL
17123 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17124 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17125 peer->ttl);
17126 }
17127 }
17128
d864dd9e 17129 /* role */
7dddd1f7
DA
17130 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17131 peer->local_role != ROLE_UNDEFINED)
d864dd9e 17132 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
8f2d6021 17133 bgp_get_name_by_role(peer->local_role),
7dddd1f7 17134 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
d864dd9e
EB
17135 ? " strict-mode"
17136 : "");
d864dd9e 17137
dd65f45e 17138 /* ttl-security hops */
e2521429 17139 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
17140 if (!peer_group_active(peer)
17141 || g_peer->gtsm_hops != peer->gtsm_hops) {
17142 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17143 addr, peer->gtsm_hops);
17144 }
17145 }
17146
17147 /* disable-connected-check */
17148 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17149 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17150
27aa23a4
DA
17151 /* link-bw-encoding-ieee */
17152 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17153 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17154 addr);
17155
d08c0c80
DA
17156 /* extended-optional-parameters */
17157 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17158 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17159 addr);
17160
dd65f45e
DL
17161 /* enforce-first-as */
17162 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17163 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17164
17165 /* update-source */
17166 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17167 if (peer->update_source)
47e12884
DA
17168 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17169 peer->update_source);
dd65f45e
DL
17170 else if (peer->update_if)
17171 vty_out(vty, " neighbor %s update-source %s\n", addr,
17172 peer->update_if);
17173 }
17174
17175 /* advertisement-interval */
17176 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17177 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17178 peer->routeadv);
17179
17180 /* timers */
17181 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17182 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17183 peer->keepalive, peer->holdtime);
17184
17185 /* timers connect */
17186 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17187 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17188 peer->connect);
5d5393b9
DL
17189 /* need special-case handling for changed default values due to
17190 * config profile / version (because there is no "timers bgp connect"
17191 * command, we need to save this per-peer :/)
17192 */
17193 else if (!peer_group_active(peer) && !peer->connect &&
17194 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17195 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17196 peer->bgp->default_connect_retry);
dd65f45e 17197
d43114f3
DS
17198 /* timers delayopen */
17199 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17200 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17201 peer->delayopen);
17202 /* Save config even though flag is not set if default values have been
17203 * changed
17204 */
17205 else if (!peer_group_active(peer) && !peer->delayopen
17206 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17207 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17208 peer->bgp->default_delayopen);
17209
dd65f45e
DL
17210 /* capability dynamic */
17211 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17212 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17213
17214 /* capability extended-nexthop */
17215 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
8e89adc1
DS
17216 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17217 !peer->conf_if)
843770f6
DA
17218 vty_out(vty,
17219 " no neighbor %s capability extended-nexthop\n",
17220 addr);
17221 else if (!peer->conf_if)
17222 vty_out(vty,
17223 " neighbor %s capability extended-nexthop\n",
17224 addr);
dd65f45e
DL
17225 }
17226
17227 /* dont-capability-negotiation */
17228 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17229 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17230
17231 /* override-capability */
17232 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17233 vty_out(vty, " neighbor %s override-capability\n", addr);
17234
17235 /* strict-capability-match */
17236 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17237 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17238
17239 /* Sender side AS path loop detection. */
17240 if (peer->as_path_loop_detection)
17241 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17242 addr);
cfd47646 17243
17244 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17245 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 17246
17247 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17248 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 17249 vty_out(vty,
17250 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
17251 } else if (CHECK_FLAG(
17252 peer->peer_gr_new_status_flag,
17253 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 17254 vty_out(vty,
17255 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
17256 } else if (
17257 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17258 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17259 && !(CHECK_FLAG(
17260 peer->peer_gr_new_status_flag,
17261 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17262 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17263 addr);
cfd47646 17264 }
17265 }
dd65f45e
DL
17266}
17267
17268/* BGP peer configuration display function. */
17269static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17270 struct peer *peer, afi_t afi, safi_t safi)
17271{
17272 struct peer *g_peer = NULL;
17273 char *addr;
17274 bool flag_scomm, flag_secomm, flag_slcomm;
17275
17276 /* Skip dynamic neighbors. */
17277 if (peer_dynamic_neighbor(peer))
17278 return;
17279
17280 if (peer->conf_if)
17281 addr = peer->conf_if;
17282 else
17283 addr = peer->host;
17284
17285 /************************************
17286 ****** Per AF to the neighbor ******
17287 ************************************/
17288 if (peer_group_active(peer)) {
17289 g_peer = peer->group->conf;
17290
17291 /* If the peer-group is active but peer is not, print a 'no
17292 * activate' */
17293 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17294 vty_out(vty, " no neighbor %s activate\n", addr);
17295 }
17296
17297 /* If the peer-group is not active but peer is, print an
17298 'activate' */
17299 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17300 vty_out(vty, " neighbor %s activate\n", addr);
17301 }
17302 } else {
17303 if (peer->afc[afi][safi]) {
38d11af5
TA
17304 if (safi == SAFI_ENCAP)
17305 vty_out(vty, " neighbor %s activate\n", addr);
17306 else if (!bgp->default_af[afi][safi])
dd65f45e
DL
17307 vty_out(vty, " neighbor %s activate\n", addr);
17308 } else {
38d11af5
TA
17309 if (bgp->default_af[afi][safi])
17310 vty_out(vty, " no neighbor %s activate\n",
17311 addr);
dd65f45e
DL
17312 }
17313 }
17314
17315 /* addpath TX knobs */
17316 if (peergroup_af_addpath_check(peer, afi, safi)) {
17317 switch (peer->addpath_type[afi][safi]) {
17318 case BGP_ADDPATH_ALL:
17319 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17320 addr);
17321 break;
17322 case BGP_ADDPATH_BEST_PER_AS:
17323 vty_out(vty,
17324 " neighbor %s addpath-tx-bestpath-per-AS\n",
17325 addr);
17326 break;
17327 case BGP_ADDPATH_MAX:
17328 case BGP_ADDPATH_NONE:
17329 break;
17330 }
17331 }
17332
7c0e4312
DA
17333 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17334 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17335
dd65f45e
DL
17336 /* ORF capability. */
17337 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17338 || peergroup_af_flag_check(peer, afi, safi,
17339 PEER_FLAG_ORF_PREFIX_RM)) {
17340 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17341
17342 if (peergroup_af_flag_check(peer, afi, safi,
17343 PEER_FLAG_ORF_PREFIX_SM)
17344 && peergroup_af_flag_check(peer, afi, safi,
17345 PEER_FLAG_ORF_PREFIX_RM))
17346 vty_out(vty, " both");
17347 else if (peergroup_af_flag_check(peer, afi, safi,
17348 PEER_FLAG_ORF_PREFIX_SM))
17349 vty_out(vty, " send");
17350 else
17351 vty_out(vty, " receive");
17352 vty_out(vty, "\n");
17353 }
17354
dd65f45e
DL
17355 /* Route reflector client. */
17356 if (peergroup_af_flag_check(peer, afi, safi,
17357 PEER_FLAG_REFLECTOR_CLIENT)) {
17358 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17359 }
17360
17361 /* next-hop-self force */
17362 if (peergroup_af_flag_check(peer, afi, safi,
17363 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17364 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17365 }
17366
17367 /* next-hop-self */
17368 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17369 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17370 }
17371
17372 /* remove-private-AS */
17373 if (peergroup_af_flag_check(peer, afi, safi,
17374 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17375 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17376 addr);
17377 }
17378
17379 else if (peergroup_af_flag_check(peer, afi, safi,
17380 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17381 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17382 addr);
17383 }
17384
17385 else if (peergroup_af_flag_check(peer, afi, safi,
17386 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17387 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17388 }
17389
17390 else if (peergroup_af_flag_check(peer, afi, safi,
17391 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17392 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17393 }
17394
17395 /* as-override */
17396 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17397 vty_out(vty, " neighbor %s as-override\n", addr);
17398 }
17399
17400 /* send-community print. */
17401 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17402 PEER_FLAG_SEND_COMMUNITY);
17403 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17404 PEER_FLAG_SEND_EXT_COMMUNITY);
17405 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17406 PEER_FLAG_SEND_LARGE_COMMUNITY);
17407
17408 if (flag_scomm && flag_secomm && flag_slcomm) {
17409 vty_out(vty, " no neighbor %s send-community all\n", addr);
17410 } else {
17411 if (flag_scomm)
17412 vty_out(vty, " no neighbor %s send-community\n", addr);
17413 if (flag_secomm)
17414 vty_out(vty,
17415 " no neighbor %s send-community extended\n",
17416 addr);
17417
17418 if (flag_slcomm)
17419 vty_out(vty, " no neighbor %s send-community large\n",
17420 addr);
17421 }
17422
17423 /* Default information */
17424 if (peergroup_af_flag_check(peer, afi, safi,
17425 PEER_FLAG_DEFAULT_ORIGINATE)) {
17426 vty_out(vty, " neighbor %s default-originate", addr);
17427
17428 if (peer->default_rmap[afi][safi].name)
17429 vty_out(vty, " route-map %s",
17430 peer->default_rmap[afi][safi].name);
17431
17432 vty_out(vty, "\n");
17433 }
17434
17435 /* Soft reconfiguration inbound. */
17436 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17437 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17438 addr);
17439 }
17440
17441 /* maximum-prefix. */
17442 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 17443 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
17444 peer->pmax[afi][safi]);
17445
17446 if (peer->pmax_threshold[afi][safi]
17447 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17448 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17449 if (peer_af_flag_check(peer, afi, safi,
17450 PEER_FLAG_MAX_PREFIX_WARNING))
17451 vty_out(vty, " warning-only");
17452 if (peer->pmax_restart[afi][safi])
17453 vty_out(vty, " restart %u",
17454 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
17455 if (peer_af_flag_check(peer, afi, safi,
17456 PEER_FLAG_MAX_PREFIX_FORCE))
17457 vty_out(vty, " force");
dd65f45e
DL
17458
17459 vty_out(vty, "\n");
17460 }
17461
fde246e8
DA
17462 /* maximum-prefix-out */
17463 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 17464 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
17465 addr, peer->pmax_out[afi][safi]);
17466
dd65f45e
DL
17467 /* Route server client. */
17468 if (peergroup_af_flag_check(peer, afi, safi,
17469 PEER_FLAG_RSERVER_CLIENT)) {
17470 vty_out(vty, " neighbor %s route-server-client\n", addr);
17471 }
17472
17473 /* Nexthop-local unchanged. */
17474 if (peergroup_af_flag_check(peer, afi, safi,
17475 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17476 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17477 }
17478
17479 /* allowas-in <1-10> */
17480 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17481 if (peer_af_flag_check(peer, afi, safi,
17482 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17483 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17484 } else if (peer->allowas_in[afi][safi] == 3) {
17485 vty_out(vty, " neighbor %s allowas-in\n", addr);
17486 } else {
17487 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17488 peer->allowas_in[afi][safi]);
17489 }
17490 }
17491
46dbf9d0
DA
17492 /* accept-own */
17493 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
17494 vty_out(vty, " neighbor %s accept-own\n", addr);
17495
01da2d26
DA
17496 /* soo */
17497 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17498 char *soo_str = ecommunity_ecom2str(
17499 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17500
17501 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17502 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17503 }
17504
dd65f45e
DL
17505 /* weight */
17506 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17507 vty_out(vty, " neighbor %s weight %lu\n", addr,
17508 peer->weight[afi][safi]);
17509
17510 /* Filter. */
17511 bgp_config_write_filter(vty, peer, afi, safi);
17512
17513 /* atribute-unchanged. */
17514 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17515 || (safi != SAFI_EVPN
17516 && peer_af_flag_check(peer, afi, safi,
17517 PEER_FLAG_NEXTHOP_UNCHANGED))
17518 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17519
17520 if (!peer_group_active(peer)
17521 || peergroup_af_flag_check(peer, afi, safi,
17522 PEER_FLAG_AS_PATH_UNCHANGED)
17523 || peergroup_af_flag_check(peer, afi, safi,
17524 PEER_FLAG_NEXTHOP_UNCHANGED)
17525 || peergroup_af_flag_check(peer, afi, safi,
17526 PEER_FLAG_MED_UNCHANGED)) {
17527
17528 vty_out(vty,
17529 " neighbor %s attribute-unchanged%s%s%s\n",
17530 addr,
17531 peer_af_flag_check(peer, afi, safi,
17532 PEER_FLAG_AS_PATH_UNCHANGED)
17533 ? " as-path"
17534 : "",
17535 peer_af_flag_check(peer, afi, safi,
17536 PEER_FLAG_NEXTHOP_UNCHANGED)
17537 ? " next-hop"
17538 : "",
17539 peer_af_flag_check(peer, afi, safi,
17540 PEER_FLAG_MED_UNCHANGED)
17541 ? " med"
17542 : "");
17543 }
17544 }
70cd87ca
MK
17545
17546 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_ORR_GROUP))
17547 vty_out(vty, " neighbor %s optimal-route-reflection %s\n",
5fcf01c9 17548 addr, peer->orr_group_name[afi][safi]);
dd65f45e
DL
17549}
17550
a486300b
PG
17551static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17552 safi_t safi)
17553{
17554 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17555 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17556 vty_out(vty, " no bgp retain route-target all\n");
17557}
17558
dd65f45e
DL
17559/* Address family based peer configuration display. */
17560static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17561 safi_t safi)
17562{
17563 struct peer *peer;
17564 struct peer_group *group;
17565 struct listnode *node, *nnode;
17566
17567
17568 vty_frame(vty, " !\n address-family ");
17569 if (afi == AFI_IP) {
17570 if (safi == SAFI_UNICAST)
17571 vty_frame(vty, "ipv4 unicast");
17572 else if (safi == SAFI_LABELED_UNICAST)
17573 vty_frame(vty, "ipv4 labeled-unicast");
17574 else if (safi == SAFI_MULTICAST)
17575 vty_frame(vty, "ipv4 multicast");
17576 else if (safi == SAFI_MPLS_VPN)
17577 vty_frame(vty, "ipv4 vpn");
17578 else if (safi == SAFI_ENCAP)
17579 vty_frame(vty, "ipv4 encap");
17580 else if (safi == SAFI_FLOWSPEC)
17581 vty_frame(vty, "ipv4 flowspec");
17582 } else if (afi == AFI_IP6) {
17583 if (safi == SAFI_UNICAST)
17584 vty_frame(vty, "ipv6 unicast");
17585 else if (safi == SAFI_LABELED_UNICAST)
17586 vty_frame(vty, "ipv6 labeled-unicast");
17587 else if (safi == SAFI_MULTICAST)
17588 vty_frame(vty, "ipv6 multicast");
17589 else if (safi == SAFI_MPLS_VPN)
17590 vty_frame(vty, "ipv6 vpn");
17591 else if (safi == SAFI_ENCAP)
17592 vty_frame(vty, "ipv6 encap");
17593 else if (safi == SAFI_FLOWSPEC)
17594 vty_frame(vty, "ipv6 flowspec");
17595 } else if (afi == AFI_L2VPN) {
17596 if (safi == SAFI_EVPN)
17597 vty_frame(vty, "l2vpn evpn");
17598 }
17599 vty_frame(vty, "\n");
17600
17601 bgp_config_write_distance(vty, bgp, afi, safi);
17602
17603 bgp_config_write_network(vty, bgp, afi, safi);
17604
17605 bgp_config_write_redistribute(vty, bgp, afi, safi);
17606
8a4e7fe6
DA
17607 /* BGP flag dampening. */
17608 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6c75f4b3 17609 bgp_config_write_damp(vty, afi, safi);
8a4e7fe6 17610
dd65f45e
DL
17611 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17612 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17613
17614 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
17615 /* Do not display doppelganger peers */
17616 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17617 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17618 }
17619
17620 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17621 bgp_config_write_table_map(vty, bgp, afi, safi);
17622
17623 if (safi == SAFI_EVPN)
17624 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17625
17626 if (safi == SAFI_FLOWSPEC)
17627 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17628
a486300b
PG
17629 if (safi == SAFI_MPLS_VPN)
17630 bgp_vpn_config_write(vty, bgp, afi, safi);
17631
dd65f45e
DL
17632 if (safi == SAFI_UNICAST) {
17633 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17634 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17635 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17636
17637 vty_out(vty, " export vpn\n");
17638 }
17639 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17640 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17641
17642 vty_out(vty, " import vpn\n");
17643 }
17644 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17645 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17646 char *name;
17647
17648 for (ALL_LIST_ELEMENTS_RO(
17649 bgp->vpn_policy[afi].import_vrf, node,
17650 name))
17651 vty_out(vty, " import vrf %s\n", name);
17652 }
17653 }
17654
70cd87ca
MK
17655 /* Optimal Route Reflection */
17656 bgp_config_write_orr(vty, bgp, afi, safi);
17657
dd65f45e
DL
17658 vty_endframe(vty, " exit-address-family\n");
17659}
17660
17661int bgp_config_write(struct vty *vty)
17662{
17663 struct bgp *bgp;
17664 struct peer_group *group;
17665 struct peer *peer;
17666 struct listnode *node, *nnode;
17667 struct listnode *mnode, *mnnode;
b16bcbba
TA
17668 afi_t afi;
17669 safi_t safi;
dd65f45e
DL
17670
17671 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17672 vty_out(vty, "bgp route-map delay-timer %u\n",
17673 bm->rmap_update_timer);
17674
d70583f7
D
17675 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17676 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17677 if (bm->v_update_delay != bm->v_establish_wait)
17678 vty_out(vty, " %d", bm->v_establish_wait);
17679 vty_out(vty, "\n");
17680 }
17681
9acb67cb
DS
17682 if (bm->wait_for_fib)
17683 vty_out(vty, "bgp suppress-fib-pending\n");
17684
05bd726c 17685 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17686 vty_out(vty, "bgp graceful-shutdown\n");
17687
c163f297
DS
17688 /* No-RIB (Zebra) option flag configuration */
17689 if (bgp_option_check(BGP_OPT_NO_FIB))
17690 vty_out(vty, "bgp no-rib\n");
17691
870791a3
IR
17692 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17693 vty_out(vty, "bgp send-extra-data zebra\n");
e46723a5 17694
425bd64b
PS
17695 /* BGP session DSCP value */
17696 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17697 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17698
dd65f45e
DL
17699 /* BGP configuration. */
17700 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17701
17702 /* skip all auto created vrf as they dont have user config */
17703 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17704 continue;
17705
17706 /* Router bgp ASN */
17707 vty_out(vty, "router bgp %u", bgp->as);
17708
17709 if (bgp->name)
17710 vty_out(vty, " %s %s",
17711 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17712 ? "view" : "vrf", bgp->name);
17713 vty_out(vty, "\n");
17714
17715 /* BGP fast-external-failover. */
17716 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17717 vty_out(vty, " no bgp fast-external-failover\n");
17718
17719 /* BGP router ID. */
3a6290bd 17720 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17721 vty_out(vty, " bgp router-id %pI4\n",
17722 &bgp->router_id_static);
dd65f45e 17723
c208c586
S
17724 /* Suppress fib pending */
17725 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17726 vty_out(vty, " bgp suppress-fib-pending\n");
17727
dd65f45e 17728 /* BGP log-neighbor-changes. */
892fedb6 17729 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17730 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17731 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17732 CHECK_FLAG(bgp->flags,
17733 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17734 ? ""
17735 : "no ");
17736
17737 /* BGP configuration. */
892fedb6 17738 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17739 vty_out(vty, " bgp always-compare-med\n");
17740
17741 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17742 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17743 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17744 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17745 CHECK_FLAG(bgp->flags,
17746 BGP_FLAG_EBGP_REQUIRES_POLICY)
17747 ? ""
17748 : "no ");
dd65f45e
DL
17749
17750 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17751 if (bgp->reject_as_sets)
dd65f45e
DL
17752 vty_out(vty, " bgp reject-as-sets\n");
17753
2adac256
DA
17754 /* Suppress duplicate updates if the route actually not changed
17755 */
17756 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17757 != SAVE_BGP_SUPPRESS_DUPLICATES)
17758 vty_out(vty, " %sbgp suppress-duplicates\n",
17759 CHECK_FLAG(bgp->flags,
17760 BGP_FLAG_SUPPRESS_DUPLICATES)
17761 ? ""
17762 : "no ");
17763
1ae314be
DA
17764 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17765 */
17766 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17767 SAVE_BGP_HARD_ADMIN_RESET)
17768 vty_out(vty, " %sbgp hard-administrative-reset\n",
17769 CHECK_FLAG(bgp->flags,
17770 BGP_FLAG_HARD_ADMIN_RESET)
17771 ? ""
17772 : "no ");
17773
b16bcbba
TA
17774 /* BGP default <afi>-<safi> */
17775 FOREACH_AFI_SAFI (afi, safi) {
17776 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17777 if (!bgp->default_af[afi][safi])
17778 vty_out(vty, " no bgp default %s\n",
17779 get_bgp_default_af_flag(afi,
17780 safi));
17781 } else if (bgp->default_af[afi][safi])
17782 vty_out(vty, " bgp default %s\n",
17783 get_bgp_default_af_flag(afi, safi));
17784 }
e84c59af 17785
dd65f45e
DL
17786 /* BGP default local-preference. */
17787 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17788 vty_out(vty, " bgp default local-preference %u\n",
17789 bgp->default_local_pref);
17790
17791 /* BGP default show-hostname */
892fedb6 17792 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17793 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17794 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17795 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17796 ? ""
17797 : "no ");
17798
aef999a2
DA
17799 /* BGP default show-nexthop-hostname */
17800 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17801 != SAVE_BGP_SHOW_HOSTNAME)
17802 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17803 CHECK_FLAG(bgp->flags,
17804 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17805 ? ""
17806 : "no ");
17807
dd65f45e
DL
17808 /* BGP default subgroup-pkt-queue-max. */
17809 if (bgp->default_subgroup_pkt_queue_max
17810 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17811 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17812 bgp->default_subgroup_pkt_queue_max);
17813
17814 /* BGP client-to-client reflection. */
892fedb6 17815 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17816 vty_out(vty, " no bgp client-to-client reflection\n");
17817
17818 /* BGP cluster ID. */
17819 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17820 vty_out(vty, " bgp cluster-id %pI4\n",
17821 &bgp->cluster_id);
dd65f45e
DL
17822
17823 /* Disable ebgp connected nexthop check */
892fedb6 17824 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17825 vty_out(vty,
17826 " bgp disable-ebgp-connected-route-check\n");
17827
17828 /* Confederation identifier*/
17829 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17830 vty_out(vty, " bgp confederation identifier %u\n",
17831 bgp->confed_id);
17832
17833 /* Confederation peer */
17834 if (bgp->confed_peers_cnt > 0) {
17835 int i;
17836
17837 vty_out(vty, " bgp confederation peers");
17838
17839 for (i = 0; i < bgp->confed_peers_cnt; i++)
17840 vty_out(vty, " %u", bgp->confed_peers[i]);
17841
17842 vty_out(vty, "\n");
17843 }
17844
17845 /* BGP deterministic-med. */
892fedb6 17846 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 17847 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 17848 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
17849 CHECK_FLAG(bgp->flags,
17850 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
17851 ? ""
17852 : "no ");
17853
17854 /* BGP update-delay. */
17855 bgp_config_write_update_delay(vty, bgp);
17856
17857 if (bgp->v_maxmed_onstartup
17858 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17859 vty_out(vty, " bgp max-med on-startup %u",
17860 bgp->v_maxmed_onstartup);
17861 if (bgp->maxmed_onstartup_value
17862 != BGP_MAXMED_VALUE_DEFAULT)
17863 vty_out(vty, " %u",
17864 bgp->maxmed_onstartup_value);
17865 vty_out(vty, "\n");
17866 }
17867 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17868 vty_out(vty, " bgp max-med administrative");
17869 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17870 vty_out(vty, " %u", bgp->maxmed_admin_value);
17871 vty_out(vty, "\n");
17872 }
17873
17874 /* write quanta */
17875 bgp_config_write_wpkt_quanta(vty, bgp);
17876 /* read quanta */
17877 bgp_config_write_rpkt_quanta(vty, bgp);
17878
17879 /* coalesce time */
17880 bgp_config_write_coalesce_time(vty, bgp);
17881
05bd726c 17882 /* BGP per-instance graceful-shutdown */
17883 /* BGP-wide settings and per-instance settings are mutually
17884 * exclusive.
17885 */
17886 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17887 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17888 vty_out(vty, " bgp graceful-shutdown\n");
17889
8606be87
DA
17890 /* Long-lived Graceful Restart */
17891 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17892 vty_out(vty,
17893 " bgp long-lived-graceful-restart stale-time %u\n",
17894 bgp->llgr_stale_time);
17895
dd65f45e
DL
17896 /* BGP graceful-restart. */
17897 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17898 vty_out(vty,
17899 " bgp graceful-restart stalepath-time %u\n",
17900 bgp->stalepath_time);
cfd47646 17901
dd65f45e
DL
17902 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17903 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17904 bgp->restart_time);
cfd47646 17905
f2ca5c5b
DA
17906 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
17907 SAVE_BGP_GRACEFUL_NOTIFICATION)
17908 vty_out(vty, " %sbgp graceful-restart notification\n",
17909 CHECK_FLAG(bgp->flags,
17910 BGP_FLAG_GRACEFUL_NOTIFICATION)
17911 ? ""
17912 : "no ");
17913
cfd47646 17914 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17915 vty_out(vty,
17916 " bgp graceful-restart select-defer-time %u\n",
17917 bgp->select_defer_time);
17918
17919 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
17920 vty_out(vty, " bgp graceful-restart\n");
17921
cfd47646 17922 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17923 vty_out(vty, " bgp graceful-restart-disable\n");
17924
dd65f45e 17925 /* BGP graceful-restart Preserve State F bit. */
892fedb6 17926 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
17927 vty_out(vty,
17928 " bgp graceful-restart preserve-fw-state\n");
17929
d1adb448
PG
17930 /* BGP TCP keepalive */
17931 bgp_config_tcp_keepalive(vty, bgp);
17932
dc95985f 17933 /* Stale timer for RIB */
17934 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17935 vty_out(vty,
17936 " bgp graceful-restart rib-stale-time %u\n",
17937 bgp->rib_stale_time);
17938
dd65f45e 17939 /* BGP bestpath method. */
892fedb6 17940 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 17941 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 17942 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
17943 vty_out(vty, " bgp bestpath as-path confed\n");
17944
892fedb6
DA
17945 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17946 if (CHECK_FLAG(bgp->flags,
17947 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
17948 vty_out(vty,
17949 " bgp bestpath as-path multipath-relax as-set\n");
17950 } else {
17951 vty_out(vty,
17952 " bgp bestpath as-path multipath-relax\n");
17953 }
17954 }
17955
892fedb6 17956 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17957 vty_out(vty,
17958 " bgp route-reflector allow-outbound-policy\n");
17959 }
892fedb6 17960 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17961 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17962 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17963 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17964 vty_out(vty, " bgp bestpath med");
892fedb6 17965 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17966 vty_out(vty, " confed");
892fedb6
DA
17967 if (CHECK_FLAG(bgp->flags,
17968 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17969 vty_out(vty, " missing-as-worst");
17970 vty_out(vty, "\n");
17971 }
17972
ee88563a
JM
17973 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17974 vty_out(vty,
17975 " bgp bestpath peer-type multipath-relax\n");
17976
f7e1c681 17977 /* Link bandwidth handling. */
17978 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17979 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17980 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17981 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17982 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17983 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17984
dd65f45e 17985 /* BGP network import check. */
892fedb6 17986 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17987 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17988 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17989 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17990 ? ""
17991 : "no ");
17992
17993 /* BGP timers configuration. */
5d5393b9 17994 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 17995 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17996 vty_out(vty, " timers bgp %u %u\n",
17997 bgp->default_keepalive, bgp->default_holdtime);
17998
b042667a
TI
17999 /* BGP minimum holdtime configuration. */
18000 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
18001 && bgp->default_min_holdtime != 0)
18002 vty_out(vty, " bgp minimum-holdtime %u\n",
18003 bgp->default_min_holdtime);
18004
389e4f92
QY
18005 /* Conditional advertisement timer configuration */
18006 if (bgp->condition_check_period
18007 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
18008 vty_out(vty,
18009 " bgp conditional-advertisement timer %u\n",
18010 bgp->condition_check_period);
18011
dd65f45e
DL
18012 /* peer-group */
18013 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18014 bgp_config_write_peer_global(vty, bgp, group->conf);
18015 }
18016
18017 /* Normal neighbor configuration. */
18018 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18019 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18020 bgp_config_write_peer_global(vty, bgp, peer);
18021 }
18022
18023 /* listen range and limit for dynamic BGP neighbors */
18024 bgp_config_write_listen(vty, bgp);
18025
18026 /*
18027 * BGP default autoshutdown neighbors
18028 *
18029 * This must be placed after any peer and peer-group
18030 * configuration, to avoid setting all peers to shutdown after
18031 * a daemon restart, which is undesired behavior. (see #2286)
18032 */
18033 if (bgp->autoshutdown)
18034 vty_out(vty, " bgp default shutdown\n");
18035
9cf59432
DS
18036 /* BGP instance administrative shutdown */
18037 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18038 vty_out(vty, " bgp shutdown\n");
18039
8666265e
DS
18040 if (bgp->allow_martian)
18041 vty_out(vty, " bgp allow-martian-nexthop\n");
18042
f852eb98
PG
18043 if (bgp->fast_convergence)
18044 vty_out(vty, " bgp fast-convergence\n");
18045
a0281b2e
HS
18046 if (bgp->srv6_enabled) {
18047 vty_frame(vty, " !\n segment-routing srv6\n");
96db4340 18048 if (strlen(bgp->srv6_locator_name))
a0281b2e
HS
18049 vty_out(vty, " locator %s\n",
18050 bgp->srv6_locator_name);
ff7c3ee1 18051 vty_endframe(vty, " exit\n");
a0281b2e
HS
18052 }
18053
18054
dd65f45e
DL
18055 /* IPv4 unicast configuration. */
18056 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18057
18058 /* IPv4 multicast configuration. */
18059 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18060
18061 /* IPv4 labeled-unicast configuration. */
18062 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18063
18064 /* IPv4 VPN configuration. */
18065 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18066
18067 /* ENCAPv4 configuration. */
18068 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18069
18070 /* FLOWSPEC v4 configuration. */
18071 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18072
18073 /* IPv6 unicast configuration. */
18074 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18075
18076 /* IPv6 multicast configuration. */
18077 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18078
18079 /* IPv6 labeled-unicast configuration. */
18080 bgp_config_write_family(vty, bgp, AFI_IP6,
18081 SAFI_LABELED_UNICAST);
18082
18083 /* IPv6 VPN configuration. */
18084 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18085
18086 /* ENCAPv6 configuration. */
18087 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18088
18089 /* FLOWSPEC v6 configuration. */
18090 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18091
18092 /* EVPN configuration. */
18093 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18094
18095 hook_call(bgp_inst_config_write, bgp, vty);
18096
49e5a4a0 18097#ifdef ENABLE_BGP_VNC
dd65f45e
DL
18098 bgp_rfapi_cfg_write(vty, bgp);
18099#endif
18100
07679ad9 18101 vty_out(vty, "exit\n");
dd65f45e
DL
18102 vty_out(vty, "!\n");
18103 }
18104 return 0;
18105}
18106
ddb5b488 18107
718e3744 18108/* BGP node structure. */
d62a17ae 18109static struct cmd_node bgp_node = {
f4b8291f 18110 .name = "bgp",
62b346ee 18111 .node = BGP_NODE,
24389580 18112 .parent_node = CONFIG_NODE,
62b346ee 18113 .prompt = "%s(config-router)# ",
612c2c15 18114 .config_write = bgp_config_write,
718e3744 18115};
18116
d62a17ae 18117static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 18118 .name = "bgp ipv4 unicast",
62b346ee 18119 .node = BGP_IPV4_NODE,
24389580 18120 .parent_node = BGP_NODE,
62b346ee 18121 .prompt = "%s(config-router-af)# ",
dd2c81b8 18122 .no_xpath = true,
718e3744 18123};
18124
d62a17ae 18125static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 18126 .name = "bgp ipv4 multicast",
62b346ee 18127 .node = BGP_IPV4M_NODE,
24389580 18128 .parent_node = BGP_NODE,
62b346ee 18129 .prompt = "%s(config-router-af)# ",
dd2c81b8 18130 .no_xpath = true,
718e3744 18131};
18132
d62a17ae 18133static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 18134 .name = "bgp ipv4 labeled unicast",
62b346ee 18135 .node = BGP_IPV4L_NODE,
24389580 18136 .parent_node = BGP_NODE,
62b346ee 18137 .prompt = "%s(config-router-af)# ",
dd2c81b8 18138 .no_xpath = true,
f51bae9c
DS
18139};
18140
d62a17ae 18141static struct cmd_node bgp_ipv6_unicast_node = {
a17cfb3f 18142 .name = "bgp ipv6 unicast",
62b346ee 18143 .node = BGP_IPV6_NODE,
24389580 18144 .parent_node = BGP_NODE,
62b346ee 18145 .prompt = "%s(config-router-af)# ",
dd2c81b8 18146 .no_xpath = true,
718e3744 18147};
18148
d62a17ae 18149static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 18150 .name = "bgp ipv6 multicast",
62b346ee 18151 .node = BGP_IPV6M_NODE,
24389580 18152 .parent_node = BGP_NODE,
62b346ee 18153 .prompt = "%s(config-router-af)# ",
dd2c81b8 18154 .no_xpath = true,
25ffbdc1 18155};
18156
d62a17ae 18157static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 18158 .name = "bgp ipv6 labeled unicast",
62b346ee 18159 .node = BGP_IPV6L_NODE,
24389580 18160 .parent_node = BGP_NODE,
62b346ee 18161 .prompt = "%s(config-router-af)# ",
dd2c81b8 18162 .no_xpath = true,
f51bae9c
DS
18163};
18164
62b346ee 18165static struct cmd_node bgp_vpnv4_node = {
f4b8291f 18166 .name = "bgp vpnv4",
62b346ee 18167 .node = BGP_VPNV4_NODE,
24389580 18168 .parent_node = BGP_NODE,
62b346ee 18169 .prompt = "%s(config-router-af)# ",
dd2c81b8 18170 .no_xpath = true,
62b346ee 18171};
6b0655a2 18172
62b346ee 18173static struct cmd_node bgp_vpnv6_node = {
f4b8291f 18174 .name = "bgp vpnv6",
62b346ee 18175 .node = BGP_VPNV6_NODE,
24389580 18176 .parent_node = BGP_NODE,
62b346ee 18177 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 18178 .no_xpath = true,
62b346ee 18179};
8ecd3266 18180
62b346ee 18181static struct cmd_node bgp_evpn_node = {
f4b8291f 18182 .name = "bgp evpn",
62b346ee 18183 .node = BGP_EVPN_NODE,
24389580 18184 .parent_node = BGP_NODE,
62b346ee 18185 .prompt = "%s(config-router-evpn)# ",
dd2c81b8 18186 .no_xpath = true,
62b346ee 18187};
4e0b7b6d 18188
62b346ee 18189static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 18190 .name = "bgp evpn vni",
62b346ee 18191 .node = BGP_EVPN_VNI_NODE,
24389580 18192 .parent_node = BGP_EVPN_NODE,
62b346ee 18193 .prompt = "%s(config-router-af-vni)# ",
62b346ee 18194};
90e60aa7 18195
62b346ee 18196static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 18197 .name = "bgp ipv4 flowspec",
62b346ee 18198 .node = BGP_FLOWSPECV4_NODE,
24389580 18199 .parent_node = BGP_NODE,
62b346ee 18200 .prompt = "%s(config-router-af)# ",
dd2c81b8 18201 .no_xpath = true,
62b346ee 18202};
7c40bf39 18203
62b346ee 18204static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 18205 .name = "bgp ipv6 flowspec",
62b346ee 18206 .node = BGP_FLOWSPECV6_NODE,
24389580 18207 .parent_node = BGP_NODE,
62b346ee 18208 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 18209 .no_xpath = true,
62b346ee 18210};
7c40bf39 18211
bfaab44d
HS
18212static struct cmd_node bgp_srv6_node = {
18213 .name = "bgp srv6",
18214 .node = BGP_SRV6_NODE,
18215 .parent_node = BGP_NODE,
18216 .prompt = "%s(config-router-srv6)# ",
18217};
18218
d62a17ae 18219static void community_list_vty(void);
1f8ae70b 18220
8c20061f
DA
18221static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18222{
18223 struct bgp *bgp;
18224 struct peer_group *group;
18225 struct listnode *lnbgp, *lnpeer;
18226
18227 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18228 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18229 vector_set(comps,
18230 XSTRDUP(MTYPE_COMPLETION, group->name));
18231 }
18232}
18233
18234static void bgp_ac_peer(vector comps, struct cmd_token *token)
b8a815e5 18235{
d62a17ae 18236 struct bgp *bgp;
18237 struct peer *peer;
d62a17ae 18238 struct listnode *lnbgp, *lnpeer;
b8a815e5 18239
d62a17ae 18240 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18241 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18242 /* only provide suggestions on the appropriate input
18243 * token type,
18244 * they'll otherwise show up multiple times */
18245 enum cmd_token_type match_type;
18246 char *name = peer->host;
d48ed3e0 18247
d62a17ae 18248 if (peer->conf_if) {
18249 match_type = VARIABLE_TKN;
18250 name = peer->conf_if;
18251 } else if (strchr(peer->host, ':'))
18252 match_type = IPV6_TKN;
18253 else
18254 match_type = IPV4_TKN;
d48ed3e0 18255
d62a17ae 18256 if (token->type != match_type)
18257 continue;
d48ed3e0 18258
d62a17ae 18259 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18260 }
d62a17ae 18261 }
b8a815e5
DL
18262}
18263
8c20061f
DA
18264static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18265{
18266 bgp_ac_peer(comps, token);
84de1483
DA
18267
18268 if (token->type == VARIABLE_TKN)
18269 bgp_ac_peergroup(comps, token);
8c20061f
DA
18270}
18271
b8a815e5 18272static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 18273 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18274 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 18275 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 18276 {.completions = NULL}};
18277
47a306a0
DS
18278static const struct cmd_variable_handler bgp_var_peergroup[] = {
18279 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18280 {.completions = NULL} };
18281
aa24a36a
DA
18282DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18283
18284static struct thread *t_bgp_cfg;
18285
18286bool bgp_config_inprocess(void)
18287{
18288 return thread_is_scheduled(t_bgp_cfg);
18289}
18290
18291static void bgp_config_finish(struct thread *t)
18292{
18293 struct listnode *node;
18294 struct bgp *bgp;
18295
18296 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18297 hook_call(bgp_config_end, bgp);
18298}
18299
18300static void bgp_config_start(void)
18301{
18302#define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18303 THREAD_OFF(t_bgp_cfg);
18304 thread_add_timer(bm->master, bgp_config_finish, NULL,
18305 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18306}
18307
18308/* When we receive a hook the configuration is read,
18309 * we start a timer to make sure we postpone sending
18310 * EoR before route-maps are processed.
18311 * This is especially valid if using `bgp route-map delay-timer`.
18312 */
18313static void bgp_config_end(void)
18314{
18315#define BGP_POST_CONFIG_DELAY_SECONDS 1
18316 uint32_t bgp_post_config_delay =
18317 thread_is_scheduled(bm->t_rmap_update)
18318 ? thread_timer_remain_second(bm->t_rmap_update)
18319 : BGP_POST_CONFIG_DELAY_SECONDS;
18320
18321 /* If BGP config processing thread isn't running, then
18322 * we can return and rely it's properly handled.
18323 */
18324 if (!bgp_config_inprocess())
18325 return;
18326
18327 THREAD_OFF(t_bgp_cfg);
18328
18329 /* Start a new timer to make sure we don't send EoR
18330 * before route-maps are processed.
18331 */
18332 thread_add_timer(bm->master, bgp_config_finish, NULL,
18333 bgp_post_config_delay, &t_bgp_cfg);
18334}
18335
4cd690ae
PG
18336static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18337{
18338 int write = 0;
18339 struct interface *ifp;
18340 struct bgp_interface *iifp;
18341
18342 FOR_ALL_INTERFACES (vrf, ifp) {
18343 iifp = ifp->info;
18344 if (!iifp)
18345 continue;
18346
18347 if_vty_config_start(vty, ifp);
18348
18349 if (CHECK_FLAG(iifp->flags,
18350 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18351 vty_out(vty, " mpls bgp forwarding\n");
18352 write++;
18353 }
18354
18355 if_vty_config_end(vty);
18356 }
18357
18358 return write;
18359}
18360
18361/* Configuration write function for bgpd. */
18362static int config_write_interface(struct vty *vty)
18363{
18364 int write = 0;
18365 struct vrf *vrf = NULL;
18366
18367 /* Display all VRF aware OSPF interface configuration */
18368 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18369 write += config_write_interface_one(vty, vrf);
18370 }
18371
18372 return write;
18373}
18374
18375DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18376 "[no$no] mpls bgp forwarding",
18377 NO_STR MPLS_STR BGP_STR
18378 "Enable MPLS forwarding for eBGP directly connected peers\n")
18379{
18380 bool check;
18381 struct bgp_interface *iifp;
18382
18383 VTY_DECLVAR_CONTEXT(interface, ifp);
18384 iifp = ifp->info;
18385 if (!iifp) {
18386 vty_out(vty, "Interface %s not available\n", ifp->name);
18387 return CMD_WARNING_CONFIG_FAILED;
18388 }
18389 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18390 if (check != !no) {
18391 if (no)
18392 UNSET_FLAG(iifp->flags,
18393 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18394 else
18395 SET_FLAG(iifp->flags,
18396 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18397 /* trigger a nht update on eBGP sessions */
18398 if (if_is_operative(ifp))
18399 bgp_nht_ifp_up(ifp);
18400 }
18401 return CMD_SUCCESS;
18402}
18403
18404/* Initialization of BGP interface. */
18405static void bgp_vty_if_init(void)
18406{
18407 /* Install interface node. */
18408 if_cmd_init(config_write_interface);
18409
18410 /* "mpls bgp forwarding" commands. */
18411 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18412}
18413
d62a17ae 18414void bgp_vty_init(void)
18415{
18416 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 18417 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 18418
aa24a36a
DA
18419 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18420
d62a17ae 18421 /* Install bgp top node. */
612c2c15
DL
18422 install_node(&bgp_node);
18423 install_node(&bgp_ipv4_unicast_node);
18424 install_node(&bgp_ipv4_multicast_node);
18425 install_node(&bgp_ipv4_labeled_unicast_node);
18426 install_node(&bgp_ipv6_unicast_node);
18427 install_node(&bgp_ipv6_multicast_node);
18428 install_node(&bgp_ipv6_labeled_unicast_node);
18429 install_node(&bgp_vpnv4_node);
18430 install_node(&bgp_vpnv6_node);
18431 install_node(&bgp_evpn_node);
18432 install_node(&bgp_evpn_vni_node);
18433 install_node(&bgp_flowspecv4_node);
18434 install_node(&bgp_flowspecv6_node);
bfaab44d 18435 install_node(&bgp_srv6_node);
d62a17ae 18436
18437 /* Install default VTY commands to new nodes. */
18438 install_default(BGP_NODE);
18439 install_default(BGP_IPV4_NODE);
18440 install_default(BGP_IPV4M_NODE);
18441 install_default(BGP_IPV4L_NODE);
18442 install_default(BGP_IPV6_NODE);
18443 install_default(BGP_IPV6M_NODE);
18444 install_default(BGP_IPV6L_NODE);
18445 install_default(BGP_VPNV4_NODE);
18446 install_default(BGP_VPNV6_NODE);
7c40bf39 18447 install_default(BGP_FLOWSPECV4_NODE);
18448 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 18449 install_default(BGP_EVPN_NODE);
18450 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 18451 install_default(BGP_SRV6_NODE);
d62a17ae 18452
8029b216
AK
18453 /* "bgp local-mac" hidden commands. */
18454 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18455 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18456
9acb67cb
DS
18457 /* "bgp suppress-fib-pending" global */
18458 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18459
d62a17ae 18460 /* bgp route-map delay-timer commands. */
18461 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18462 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18463
8666265e
DS
18464 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18465
f852eb98
PG
18466 /* bgp fast-convergence command */
18467 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18468 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18469
d70583f7
D
18470 /* global bgp update-delay command */
18471 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18472 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18473
05bd726c 18474 /* global bgp graceful-shutdown command */
18475 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18476 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18477
d62a17ae 18478 /* Dummy commands (Currently not supported) */
18479 install_element(BGP_NODE, &no_synchronization_cmd);
18480 install_element(BGP_NODE, &no_auto_summary_cmd);
18481
18482 /* "router bgp" commands. */
18483 install_element(CONFIG_NODE, &router_bgp_cmd);
18484
18485 /* "no router bgp" commands. */
18486 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18487
425bd64b
PS
18488 /* "bgp session-dscp command */
18489 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18490 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18491
d62a17ae 18492 /* "bgp router-id" commands. */
18493 install_element(BGP_NODE, &bgp_router_id_cmd);
18494 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18495
c208c586
S
18496 /* "bgp suppress-fib-pending" command */
18497 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18498
d62a17ae 18499 /* "bgp cluster-id" commands. */
18500 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18501 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18502
c163f297
DS
18503 /* "bgp no-rib" commands. */
18504 install_element(CONFIG_NODE, &bgp_norib_cmd);
18505 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18506
e46723a5
DS
18507 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18508
d62a17ae 18509 /* "bgp confederation" commands. */
18510 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18511 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18512
18513 /* "bgp confederation peers" commands. */
18514 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18515 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18516
18517 /* bgp max-med command */
18518 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18519 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18520 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18521 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18522 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18523
d864dd9e
EB
18524 /* "neighbor role" commands. */
18525 install_element(BGP_NODE, &neighbor_role_cmd);
18526 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18527 install_element(BGP_NODE, &no_neighbor_role_cmd);
18528
d62a17ae 18529 /* bgp disable-ebgp-connected-nh-check */
18530 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18531 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18532
18533 /* bgp update-delay command */
18534 install_element(BGP_NODE, &bgp_update_delay_cmd);
18535 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 18536
18537 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 18538 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 18539
18540 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18541 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18542
18543 /* "maximum-paths" commands. */
18544 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18545 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18546 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18547 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18548 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18549 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18550 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18551 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18552 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18553 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18554 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18555 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18556 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18557 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18558 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18559
39edabac
PG
18560 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18561 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18562 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18563 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18564 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 18565 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18566 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18567 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18568 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18569 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18570
18571 /* "timers bgp" commands. */
18572 install_element(BGP_NODE, &bgp_timers_cmd);
18573 install_element(BGP_NODE, &no_bgp_timers_cmd);
18574
b042667a
TI
18575 /* "minimum-holdtime" commands. */
18576 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18577 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18578
d62a17ae 18579 /* route-map delay-timer commands - per instance for backwards compat.
18580 */
18581 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18582 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18583
18584 /* "bgp client-to-client reflection" commands */
18585 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18586 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18587
18588 /* "bgp always-compare-med" commands */
18589 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18590 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18591
9dac9fc8
DA
18592 /* bgp ebgp-requires-policy */
18593 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18594 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18595
2adac256
DA
18596 /* bgp suppress-duplicates */
18597 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18598 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18599
fb29348a
DA
18600 /* bgp reject-as-sets */
18601 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18602 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18603
d62a17ae 18604 /* "bgp deterministic-med" commands */
18605 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18606 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18607
055679e9 18608 /* "bgp graceful-restart" command */
36235319
QY
18609 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18610 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 18611
18612 /* "bgp graceful-restart-disable" command */
36235319
QY
18613 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18614 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 18615
18616 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
18617 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18618 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 18619
18620 /* "neighbor a:b:c:d graceful-restart-disable" command */
18621 install_element(BGP_NODE,
18622 &bgp_neighbor_graceful_restart_disable_set_cmd);
18623 install_element(BGP_NODE,
18624 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18625
18626 /* "neighbor a:b:c:d graceful-restart-helper" command */
18627 install_element(BGP_NODE,
18628 &bgp_neighbor_graceful_restart_helper_set_cmd);
18629 install_element(BGP_NODE,
18630 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18631
d62a17ae 18632 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18633 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18634 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18635 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 18636 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 18637 install_element(BGP_NODE,
18638 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 18639 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18640 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
f2ca5c5b 18641 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
d62a17ae 18642
d6e3c15b 18643 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18644 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 18645 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18646 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 18647
7f323236
DW
18648 /* "bgp graceful-shutdown" commands */
18649 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18650 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18651
1ae314be
DA
18652 /* "bgp hard-administrative-reset" commands */
18653 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18654
8606be87
DA
18655 /* "bgp long-lived-graceful-restart" commands */
18656 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18657 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18658
d62a17ae 18659 /* "bgp fast-external-failover" commands */
18660 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18661 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18662
d62a17ae 18663 /* "bgp bestpath compare-routerid" commands */
18664 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18665 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18666
18667 /* "bgp bestpath as-path ignore" commands */
18668 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18669 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18670
18671 /* "bgp bestpath as-path confed" commands */
18672 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18673 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18674
18675 /* "bgp bestpath as-path multipath-relax" commands */
18676 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18677 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18678
ee88563a
JM
18679 /* "bgp bestpath peer-type multipath-relax" commands */
18680 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18681 install_element(BGP_NODE,
18682 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18683
d62a17ae 18684 /* "bgp log-neighbor-changes" commands */
18685 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18686 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18687
18688 /* "bgp bestpath med" commands */
18689 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18690 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18691
f7e1c681 18692 /* "bgp bestpath bandwidth" commands */
18693 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 18694 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 18695
b16bcbba
TA
18696 /* "no bgp default <afi>-<safi>" commands. */
18697 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
e84c59af 18698
d62a17ae 18699 /* "bgp network import-check" commands. */
18700 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18701 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18702 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18703
18704 /* "bgp default local-preference" commands. */
18705 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18706 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18707
18708 /* bgp default show-hostname */
18709 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18710 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18711
aef999a2
DA
18712 /* bgp default show-nexthop-hostname */
18713 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18714 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18715
d62a17ae 18716 /* "bgp default subgroup-pkt-queue-max" commands. */
18717 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18718 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18719
18720 /* bgp ibgp-allow-policy-mods command */
18721 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18722 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18723
18724 /* "bgp listen limit" commands. */
18725 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18726 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18727
18728 /* "bgp listen range" commands. */
18729 install_element(BGP_NODE, &bgp_listen_range_cmd);
18730 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18731
8175f54a 18732 /* "bgp default shutdown" command */
f26845f9 18733 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
18734
18735 /* "bgp shutdown" commands */
18736 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 18737 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 18738 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 18739 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 18740
d62a17ae 18741 /* "neighbor remote-as" commands. */
18742 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18743 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18744 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18745 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18746 install_element(BGP_NODE,
18747 &neighbor_interface_v6only_config_remote_as_cmd);
18748 install_element(BGP_NODE, &no_neighbor_cmd);
18749 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18750
18751 /* "neighbor peer-group" commands. */
18752 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18753 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18754 install_element(BGP_NODE,
18755 &no_neighbor_interface_peer_group_remote_as_cmd);
18756
18757 /* "neighbor local-as" commands. */
18758 install_element(BGP_NODE, &neighbor_local_as_cmd);
18759 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18760 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18761 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18762
18763 /* "neighbor solo" commands. */
18764 install_element(BGP_NODE, &neighbor_solo_cmd);
18765 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18766
18767 /* "neighbor password" commands. */
18768 install_element(BGP_NODE, &neighbor_password_cmd);
18769 install_element(BGP_NODE, &no_neighbor_password_cmd);
18770
18771 /* "neighbor activate" commands. */
18772 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18773 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18774 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18775 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18776 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18777 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18778 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18779 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18780 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 18781 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18782 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 18783 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18784
18785 /* "no neighbor activate" commands. */
18786 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18787 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18788 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18789 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18790 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18791 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18792 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18793 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18794 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 18795 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18796 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 18797 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18798
18799 /* "neighbor peer-group" set commands. */
18800 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18801 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18802 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18803 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18804 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18805 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18806 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18807 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 18808 install_element(BGP_FLOWSPECV4_NODE,
18809 &neighbor_set_peer_group_hidden_cmd);
18810 install_element(BGP_FLOWSPECV6_NODE,
18811 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 18812
18813 /* "no neighbor peer-group unset" commands. */
18814 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18815 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18816 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18817 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18818 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18819 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18820 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18821 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 18822 install_element(BGP_FLOWSPECV4_NODE,
18823 &no_neighbor_set_peer_group_hidden_cmd);
18824 install_element(BGP_FLOWSPECV6_NODE,
18825 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 18826
18827 /* "neighbor softreconfiguration inbound" commands.*/
18828 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18829 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18830 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18831 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18832 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18833 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18834 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18835 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18836 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18837 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18838 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18839 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18840 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18841 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18842 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18843 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18844 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18845 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 18846 install_element(BGP_FLOWSPECV4_NODE,
18847 &neighbor_soft_reconfiguration_cmd);
18848 install_element(BGP_FLOWSPECV4_NODE,
18849 &no_neighbor_soft_reconfiguration_cmd);
18850 install_element(BGP_FLOWSPECV6_NODE,
18851 &neighbor_soft_reconfiguration_cmd);
18852 install_element(BGP_FLOWSPECV6_NODE,
18853 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
18854 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18855 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 18856
18857 /* "neighbor attribute-unchanged" commands. */
18858 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18859 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18860 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18861 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18862 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18863 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18864 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18865 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18866 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18867 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18868 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18869 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18870 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18871 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18872 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18873 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18874 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18875 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18876
18877 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18878 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18879
b8ad84d2
PG
18880 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18881 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18882 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18883 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18884
d62a17ae 18885 /* "nexthop-local unchanged" commands */
18886 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18887 install_element(BGP_IPV6_NODE,
18888 &no_neighbor_nexthop_local_unchanged_cmd);
18889
18890 /* "neighbor next-hop-self" commands. */
18891 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18892 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18893 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18894 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18895 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18896 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18897 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18898 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18899 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18900 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18901 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18902 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18903 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18904 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18905 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18906 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18907 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18908 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
18909 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18910 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 18911
18912 /* "neighbor next-hop-self force" commands. */
18913 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18914 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
18915 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18916 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18917 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18918 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18919 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18920 install_element(BGP_IPV4_NODE,
18921 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18922 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18923 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18924 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18925 install_element(BGP_IPV4M_NODE,
18926 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18927 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18928 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18929 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18930 install_element(BGP_IPV4L_NODE,
18931 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18932 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18933 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18934 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18935 install_element(BGP_IPV6_NODE,
18936 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18937 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18938 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18939 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18940 install_element(BGP_IPV6M_NODE,
18941 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18942 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18943 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18944 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18945 install_element(BGP_IPV6L_NODE,
18946 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18947 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18948 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18949 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18950 install_element(BGP_VPNV4_NODE,
18951 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18952 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18953 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18954 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18955 install_element(BGP_VPNV6_NODE,
18956 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
18957 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18958 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 18959
18960 /* "neighbor as-override" commands. */
18961 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18962 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18963 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18964 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18965 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18966 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18967 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18968 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18969 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18970 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18971 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18972 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18973 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18974 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18975 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18976 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18977 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18978 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18979
18980 /* "neighbor remove-private-AS" commands. */
18981 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18982 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18983 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18984 install_element(BGP_NODE,
18985 &no_neighbor_remove_private_as_all_hidden_cmd);
18986 install_element(BGP_NODE,
18987 &neighbor_remove_private_as_replace_as_hidden_cmd);
18988 install_element(BGP_NODE,
18989 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18990 install_element(BGP_NODE,
18991 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18992 install_element(
18993 BGP_NODE,
18994 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18995 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18996 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18997 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18998 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18999 install_element(BGP_IPV4_NODE,
19000 &neighbor_remove_private_as_replace_as_cmd);
19001 install_element(BGP_IPV4_NODE,
19002 &no_neighbor_remove_private_as_replace_as_cmd);
19003 install_element(BGP_IPV4_NODE,
19004 &neighbor_remove_private_as_all_replace_as_cmd);
19005 install_element(BGP_IPV4_NODE,
19006 &no_neighbor_remove_private_as_all_replace_as_cmd);
19007 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
19008 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
19009 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
19010 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
19011 install_element(BGP_IPV4M_NODE,
19012 &neighbor_remove_private_as_replace_as_cmd);
19013 install_element(BGP_IPV4M_NODE,
19014 &no_neighbor_remove_private_as_replace_as_cmd);
19015 install_element(BGP_IPV4M_NODE,
19016 &neighbor_remove_private_as_all_replace_as_cmd);
19017 install_element(BGP_IPV4M_NODE,
19018 &no_neighbor_remove_private_as_all_replace_as_cmd);
19019 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
19020 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
19021 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
19022 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
19023 install_element(BGP_IPV4L_NODE,
19024 &neighbor_remove_private_as_replace_as_cmd);
19025 install_element(BGP_IPV4L_NODE,
19026 &no_neighbor_remove_private_as_replace_as_cmd);
19027 install_element(BGP_IPV4L_NODE,
19028 &neighbor_remove_private_as_all_replace_as_cmd);
19029 install_element(BGP_IPV4L_NODE,
19030 &no_neighbor_remove_private_as_all_replace_as_cmd);
19031 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
19032 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
19033 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
19034 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19035 install_element(BGP_IPV6_NODE,
19036 &neighbor_remove_private_as_replace_as_cmd);
19037 install_element(BGP_IPV6_NODE,
19038 &no_neighbor_remove_private_as_replace_as_cmd);
19039 install_element(BGP_IPV6_NODE,
19040 &neighbor_remove_private_as_all_replace_as_cmd);
19041 install_element(BGP_IPV6_NODE,
19042 &no_neighbor_remove_private_as_all_replace_as_cmd);
19043 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
19044 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
19045 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
19046 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
19047 install_element(BGP_IPV6M_NODE,
19048 &neighbor_remove_private_as_replace_as_cmd);
19049 install_element(BGP_IPV6M_NODE,
19050 &no_neighbor_remove_private_as_replace_as_cmd);
19051 install_element(BGP_IPV6M_NODE,
19052 &neighbor_remove_private_as_all_replace_as_cmd);
19053 install_element(BGP_IPV6M_NODE,
19054 &no_neighbor_remove_private_as_all_replace_as_cmd);
19055 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19056 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19057 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19058 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19059 install_element(BGP_IPV6L_NODE,
19060 &neighbor_remove_private_as_replace_as_cmd);
19061 install_element(BGP_IPV6L_NODE,
19062 &no_neighbor_remove_private_as_replace_as_cmd);
19063 install_element(BGP_IPV6L_NODE,
19064 &neighbor_remove_private_as_all_replace_as_cmd);
19065 install_element(BGP_IPV6L_NODE,
19066 &no_neighbor_remove_private_as_all_replace_as_cmd);
19067 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19068 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19069 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19070 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19071 install_element(BGP_VPNV4_NODE,
19072 &neighbor_remove_private_as_replace_as_cmd);
19073 install_element(BGP_VPNV4_NODE,
19074 &no_neighbor_remove_private_as_replace_as_cmd);
19075 install_element(BGP_VPNV4_NODE,
19076 &neighbor_remove_private_as_all_replace_as_cmd);
19077 install_element(BGP_VPNV4_NODE,
19078 &no_neighbor_remove_private_as_all_replace_as_cmd);
19079 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19080 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19081 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19082 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19083 install_element(BGP_VPNV6_NODE,
19084 &neighbor_remove_private_as_replace_as_cmd);
19085 install_element(BGP_VPNV6_NODE,
19086 &no_neighbor_remove_private_as_replace_as_cmd);
19087 install_element(BGP_VPNV6_NODE,
19088 &neighbor_remove_private_as_all_replace_as_cmd);
19089 install_element(BGP_VPNV6_NODE,
19090 &no_neighbor_remove_private_as_all_replace_as_cmd);
19091
19092 /* "neighbor send-community" commands.*/
19093 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19094 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19095 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19096 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19097 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19098 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19099 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19100 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19101 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19102 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19103 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19104 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19105 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19106 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19107 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19108 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19109 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19110 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19111 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19112 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19113 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19114 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19115 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19116 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19117 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19118 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19119 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19120 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19121 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19122 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19123 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19124 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19125 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19126 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19127 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19128 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19129
19130 /* "neighbor route-reflector" commands.*/
19131 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19132 install_element(BGP_NODE,
19133 &no_neighbor_route_reflector_client_hidden_cmd);
19134 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19135 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19136 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19137 install_element(BGP_IPV4M_NODE,
19138 &no_neighbor_route_reflector_client_cmd);
19139 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19140 install_element(BGP_IPV4L_NODE,
19141 &no_neighbor_route_reflector_client_cmd);
19142 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19143 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19144 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19145 install_element(BGP_IPV6M_NODE,
19146 &no_neighbor_route_reflector_client_cmd);
19147 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19148 install_element(BGP_IPV6L_NODE,
19149 &no_neighbor_route_reflector_client_cmd);
19150 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19151 install_element(BGP_VPNV4_NODE,
19152 &no_neighbor_route_reflector_client_cmd);
19153 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19154 install_element(BGP_VPNV6_NODE,
19155 &no_neighbor_route_reflector_client_cmd);
7c40bf39 19156 install_element(BGP_FLOWSPECV4_NODE,
19157 &neighbor_route_reflector_client_cmd);
19158 install_element(BGP_FLOWSPECV4_NODE,
19159 &no_neighbor_route_reflector_client_cmd);
19160 install_element(BGP_FLOWSPECV6_NODE,
19161 &neighbor_route_reflector_client_cmd);
19162 install_element(BGP_FLOWSPECV6_NODE,
19163 &no_neighbor_route_reflector_client_cmd);
d62a17ae 19164 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19165 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19166
70cd87ca
MK
19167 /* "optimal-route-reflection" commands */
19168 install_element(BGP_IPV4_NODE, &optimal_route_reflection_cmd);
19169 install_element(BGP_IPV4M_NODE, &optimal_route_reflection_cmd);
19170 install_element(BGP_IPV4L_NODE, &optimal_route_reflection_cmd);
19171 install_element(BGP_IPV6_NODE, &optimal_route_reflection_cmd);
19172 install_element(BGP_IPV6M_NODE, &optimal_route_reflection_cmd);
19173 install_element(BGP_IPV6L_NODE, &optimal_route_reflection_cmd);
19174 install_element(BGP_VPNV4_NODE, &optimal_route_reflection_cmd);
19175 install_element(BGP_VPNV6_NODE, &optimal_route_reflection_cmd);
19176 install_element(BGP_FLOWSPECV4_NODE, &optimal_route_reflection_cmd);
19177 install_element(BGP_FLOWSPECV6_NODE, &optimal_route_reflection_cmd);
19178 install_element(BGP_EVPN_NODE, &optimal_route_reflection_cmd);
19179
19180 /* "neighbor optimal-route-reflection" commands */
19181 install_element(BGP_IPV4_NODE, &neighbor_optimal_route_reflection_cmd);
19182 install_element(BGP_IPV4M_NODE, &neighbor_optimal_route_reflection_cmd);
19183 install_element(BGP_IPV4L_NODE, &neighbor_optimal_route_reflection_cmd);
19184 install_element(BGP_IPV6_NODE, &neighbor_optimal_route_reflection_cmd);
19185 install_element(BGP_IPV6M_NODE, &neighbor_optimal_route_reflection_cmd);
19186 install_element(BGP_IPV6L_NODE, &neighbor_optimal_route_reflection_cmd);
19187 install_element(BGP_VPNV4_NODE, &neighbor_optimal_route_reflection_cmd);
19188 install_element(BGP_VPNV6_NODE, &neighbor_optimal_route_reflection_cmd);
19189 install_element(BGP_FLOWSPECV4_NODE,
19190 &neighbor_optimal_route_reflection_cmd);
19191 install_element(BGP_FLOWSPECV6_NODE,
19192 &neighbor_optimal_route_reflection_cmd);
19193 install_element(BGP_EVPN_NODE, &neighbor_optimal_route_reflection_cmd);
19194
d62a17ae 19195 /* "neighbor route-server" commands.*/
19196 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19197 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19198 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19199 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19200 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19201 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19202 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19203 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19204 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19205 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19206 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19207 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19208 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19209 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19210 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19211 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19212 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19213 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
19214 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19215 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 19216 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19217 install_element(BGP_FLOWSPECV4_NODE,
19218 &no_neighbor_route_server_client_cmd);
19219 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19220 install_element(BGP_FLOWSPECV6_NODE,
19221 &no_neighbor_route_server_client_cmd);
d62a17ae 19222
7c0e4312
DA
19223 /* "neighbor disable-addpath-rx" commands. */
19224 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19225 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19226 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19227 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19228 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19229 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19230 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19231 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19232 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19233 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19234 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19235 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19236 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19237 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19238 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19239 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19240
d62a17ae 19241 /* "neighbor addpath-tx-all-paths" commands.*/
19242 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19243 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19244 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19245 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19246 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19247 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19248 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19249 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19250 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19251 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19252 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19253 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19254 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19255 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19256 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19257 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19258 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19259 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19260
19261 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19262 install_element(BGP_NODE,
19263 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19264 install_element(BGP_NODE,
19265 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19266 install_element(BGP_IPV4_NODE,
19267 &neighbor_addpath_tx_bestpath_per_as_cmd);
19268 install_element(BGP_IPV4_NODE,
19269 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19270 install_element(BGP_IPV4M_NODE,
19271 &neighbor_addpath_tx_bestpath_per_as_cmd);
19272 install_element(BGP_IPV4M_NODE,
19273 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19274 install_element(BGP_IPV4L_NODE,
19275 &neighbor_addpath_tx_bestpath_per_as_cmd);
19276 install_element(BGP_IPV4L_NODE,
19277 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19278 install_element(BGP_IPV6_NODE,
19279 &neighbor_addpath_tx_bestpath_per_as_cmd);
19280 install_element(BGP_IPV6_NODE,
19281 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19282 install_element(BGP_IPV6M_NODE,
19283 &neighbor_addpath_tx_bestpath_per_as_cmd);
19284 install_element(BGP_IPV6M_NODE,
19285 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19286 install_element(BGP_IPV6L_NODE,
19287 &neighbor_addpath_tx_bestpath_per_as_cmd);
19288 install_element(BGP_IPV6L_NODE,
19289 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19290 install_element(BGP_VPNV4_NODE,
19291 &neighbor_addpath_tx_bestpath_per_as_cmd);
19292 install_element(BGP_VPNV4_NODE,
19293 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19294 install_element(BGP_VPNV6_NODE,
19295 &neighbor_addpath_tx_bestpath_per_as_cmd);
19296 install_element(BGP_VPNV6_NODE,
19297 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19298
2b31007c
RZ
19299 /* "neighbor sender-as-path-loop-detection" commands. */
19300 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19301 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19302
d62a17ae 19303 /* "neighbor passive" commands. */
19304 install_element(BGP_NODE, &neighbor_passive_cmd);
19305 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19306
19307
19308 /* "neighbor shutdown" commands. */
19309 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19310 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19311 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19312 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
19313 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19314 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 19315
19316 /* "neighbor capability extended-nexthop" commands.*/
19317 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19318 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19319
19320 /* "neighbor capability orf prefix-list" commands.*/
19321 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19322 install_element(BGP_NODE,
19323 &no_neighbor_capability_orf_prefix_hidden_cmd);
19324 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19325 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19326 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19327 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19328 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19329 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19330 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19331 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19332 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19333 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19334 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19335 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19336
19337 /* "neighbor capability dynamic" commands.*/
19338 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19339 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19340
19341 /* "neighbor dont-capability-negotiate" commands. */
19342 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19343 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19344
19345 /* "neighbor ebgp-multihop" commands. */
19346 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19347 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19348 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19349
19350 /* "neighbor disable-connected-check" commands. */
19351 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19352 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19353
7ab294ea
DA
19354 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19355 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19356 install_element(BGP_NODE,
19357 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
27aa23a4 19358
d08c0c80
DA
19359 /* "neighbor extended-optional-parameters" commands. */
19360 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19361 install_element(BGP_NODE,
19362 &no_neighbor_extended_optional_parameters_cmd);
19363
47cbc09b
PM
19364 /* "neighbor enforce-first-as" commands. */
19365 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19366 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19367
d62a17ae 19368 /* "neighbor description" commands. */
19369 install_element(BGP_NODE, &neighbor_description_cmd);
19370 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 19371 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 19372
19373 /* "neighbor update-source" commands. "*/
19374 install_element(BGP_NODE, &neighbor_update_source_cmd);
19375 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19376
19377 /* "neighbor default-originate" commands. */
19378 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19379 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19380 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19381 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19382 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19383 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19384 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19385 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19386 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19387 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19388 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19389 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19390 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19391 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19392 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19393 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19394 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19395 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19396 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19397 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19398 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19399
19400 /* "neighbor port" commands. */
19401 install_element(BGP_NODE, &neighbor_port_cmd);
19402 install_element(BGP_NODE, &no_neighbor_port_cmd);
19403
19404 /* "neighbor weight" commands. */
19405 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19406 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19407
19408 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19409 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19410 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19411 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19412 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19413 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19414 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19415 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19416 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19417 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19418 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19419 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19420 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19421 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19422 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19423 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19424
19425 /* "neighbor override-capability" commands. */
19426 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19427 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19428
19429 /* "neighbor strict-capability-match" commands. */
19430 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19431 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19432
19433 /* "neighbor timers" commands. */
19434 install_element(BGP_NODE, &neighbor_timers_cmd);
19435 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19436
19437 /* "neighbor timers connect" commands. */
19438 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19439 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19440
d43114f3
DS
19441 /* "neighbor timers delayopen" commands. */
19442 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19443 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19444
d62a17ae 19445 /* "neighbor advertisement-interval" commands. */
19446 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19447 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19448
19449 /* "neighbor interface" commands. */
19450 install_element(BGP_NODE, &neighbor_interface_cmd);
19451 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19452
19453 /* "neighbor distribute" commands. */
19454 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19455 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19456 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19457 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19458 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19459 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19460 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19461 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19462 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19463 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19464 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19465 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19466 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19467 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19468 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19469 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19470 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19471 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19472
19473 /* "neighbor prefix-list" commands. */
19474 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
642ef664 19475 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
d62a17ae 19476 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
642ef664 19477 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19478 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
642ef664 19479 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19480 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
642ef664 19481 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19482 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
642ef664 19483 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19484 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
642ef664 19485 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19486 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
642ef664 19487 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19488 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
642ef664 19489 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19490 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
642ef664 19491 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 19492 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
642ef664 19493 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 19494 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
642ef664 19495 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19496
19497 /* "neighbor filter-list" commands. */
19498 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19499 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19500 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19501 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19502 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19503 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19504 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19505 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19506 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19507 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19508 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19509 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19510 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19511 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19512 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19513 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19514 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19515 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 19516 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19517 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19518 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19519 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 19520
19521 /* "neighbor route-map" commands. */
d6d7ed37
IR
19522 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19523 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
d62a17ae 19524 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
0ea8d871 19525 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19526 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
0ea8d871 19527 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19528 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
0ea8d871 19529 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19530 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
0ea8d871 19531 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19532 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
0ea8d871 19533 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19534 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
0ea8d871 19535 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19536 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
0ea8d871 19537 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19538 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
0ea8d871 19539 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 19540 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
0ea8d871 19541 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
7c40bf39 19542 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
0ea8d871 19543 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549 19544 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
0ea8d871 19545 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19546
19547 /* "neighbor unsuppress-map" commands. */
19548 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19549 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19550 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19551 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19552 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19553 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19554 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19555 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19556 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19557 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19558 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19559 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19560 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19561 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19562 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19563 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19564 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19565 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19566
7f7940e6 19567 /* "neighbor advertise-map" commands. */
389e4f92 19568 install_element(BGP_NODE, &bgp_condadv_period_cmd);
7f7940e6 19569 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 19570 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19571 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19572 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19573 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19574 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19575 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19576 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19577 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19578
fde246e8
DA
19579 /* neighbor maximum-prefix-out commands. */
19580 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19581 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19582 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19583 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19584 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19585 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19586 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19587 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19588 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19589 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19590 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19591 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19592 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19593 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19594 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19595 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19596 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19597 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19598
d62a17ae 19599 /* "neighbor maximum-prefix" commands. */
19600 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19601 install_element(BGP_NODE,
19602 &neighbor_maximum_prefix_threshold_hidden_cmd);
19603 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19604 install_element(BGP_NODE,
19605 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19606 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19607 install_element(BGP_NODE,
19608 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19609 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19610 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19611 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19612 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19613 install_element(BGP_IPV4_NODE,
19614 &neighbor_maximum_prefix_threshold_warning_cmd);
19615 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19616 install_element(BGP_IPV4_NODE,
19617 &neighbor_maximum_prefix_threshold_restart_cmd);
19618 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19619 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19620 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19621 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19622 install_element(BGP_IPV4M_NODE,
19623 &neighbor_maximum_prefix_threshold_warning_cmd);
19624 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19625 install_element(BGP_IPV4M_NODE,
19626 &neighbor_maximum_prefix_threshold_restart_cmd);
19627 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19628 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19629 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19630 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19631 install_element(BGP_IPV4L_NODE,
19632 &neighbor_maximum_prefix_threshold_warning_cmd);
19633 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19634 install_element(BGP_IPV4L_NODE,
19635 &neighbor_maximum_prefix_threshold_restart_cmd);
19636 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19637 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19638 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19639 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19640 install_element(BGP_IPV6_NODE,
19641 &neighbor_maximum_prefix_threshold_warning_cmd);
19642 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19643 install_element(BGP_IPV6_NODE,
19644 &neighbor_maximum_prefix_threshold_restart_cmd);
19645 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19646 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19647 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19648 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19649 install_element(BGP_IPV6M_NODE,
19650 &neighbor_maximum_prefix_threshold_warning_cmd);
19651 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19652 install_element(BGP_IPV6M_NODE,
19653 &neighbor_maximum_prefix_threshold_restart_cmd);
19654 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19655 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19656 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19657 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19658 install_element(BGP_IPV6L_NODE,
19659 &neighbor_maximum_prefix_threshold_warning_cmd);
19660 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19661 install_element(BGP_IPV6L_NODE,
19662 &neighbor_maximum_prefix_threshold_restart_cmd);
19663 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19664 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19665 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19666 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19667 install_element(BGP_VPNV4_NODE,
19668 &neighbor_maximum_prefix_threshold_warning_cmd);
19669 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19670 install_element(BGP_VPNV4_NODE,
19671 &neighbor_maximum_prefix_threshold_restart_cmd);
19672 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19673 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19674 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19675 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19676 install_element(BGP_VPNV6_NODE,
19677 &neighbor_maximum_prefix_threshold_warning_cmd);
19678 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19679 install_element(BGP_VPNV6_NODE,
19680 &neighbor_maximum_prefix_threshold_restart_cmd);
19681 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19682
19683 /* "neighbor allowas-in" */
19684 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19685 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19686 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19687 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19688 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19689 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19690 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19691 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19692 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19693 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19694 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19695 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19696 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19697 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19698 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19699 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19700 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19701 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19702 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19703 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19704
46dbf9d0
DA
19705 /* neighbor accept-own */
19706 install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
19707 install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
19708
01da2d26
DA
19709 /* "neighbor soo" */
19710 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
19711 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
19712 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
19713 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
19714 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
19715 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
19716 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
19717 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
19718 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
19719 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
19720 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
19721 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
19722 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
19723 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
19724 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
19725 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
19726 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
19727 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
19728
d62a17ae 19729 /* address-family commands. */
19730 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19731 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 19732#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 19733 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19734 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 19735#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 19736
d62a17ae 19737 install_element(BGP_NODE, &address_family_evpn_cmd);
19738
19739 /* "exit-address-family" command. */
19740 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19741 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19742 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19743 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19744 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19745 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19746 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19747 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 19748 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19749 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 19750 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19751
a486300b
PG
19752 /* BGP retain all route-target */
19753 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
19754 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
19755
d62a17ae 19756 /* "clear ip bgp commands" */
19757 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19758
19759 /* clear ip bgp prefix */
19760 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19761 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19762 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19763
19764 /* "show [ip] bgp summary" commands. */
19765 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 19766 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 19767 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 19768 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 19769 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19770 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 19771 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19772
19773 /* "show [ip] bgp neighbors" commands. */
19774 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19775
36235319 19776 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 19777
d62a17ae 19778 /* "show [ip] bgp peer-group" commands. */
19779 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19780
19781 /* "show [ip] bgp paths" commands. */
19782 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19783
19784 /* "show [ip] bgp community" commands. */
19785 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19786
19787 /* "show ip bgp large-community" commands. */
19788 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19789 /* "show [ip] bgp attribute-info" commands. */
19790 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 19791 /* "show [ip] bgp route-leak" command */
19792 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 19793
19794 /* "redistribute" commands. */
19795 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19796 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19797 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19798 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19799 install_element(BGP_NODE,
19800 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19801 install_element(BGP_NODE,
19802 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19803 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19804 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19805 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19806 install_element(BGP_NODE,
19807 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19808 install_element(BGP_NODE,
19809 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19810 install_element(BGP_NODE,
19811 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19812 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19813 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19814 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19815 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19816 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19817 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19818 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19819 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19820 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19821 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19822 install_element(BGP_IPV4_NODE,
19823 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19824 install_element(BGP_IPV4_NODE,
19825 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19826 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19827 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19828 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19829 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19830 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19831 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19832
70dd370f 19833 /* import|export vpn [route-map RMAP_NAME] */
b9c7bc5a
PZ
19834 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19835 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 19836
12a844a5
DS
19837 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19838 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19839
d62a17ae 19840 /* ttl_security commands */
19841 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19842 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19843
d1adb448
PG
19844 /* "bgp tcp-keepalive" commands */
19845 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
19846 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
19847
d62a17ae 19848 /* "show [ip] bgp memory" commands. */
19849 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19850
acf71666
MK
19851 /* "show bgp martian next-hop" */
19852 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19853
48ecf8f5
DS
19854 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19855
d62a17ae 19856 /* "show [ip] bgp views" commands. */
19857 install_element(VIEW_NODE, &show_bgp_views_cmd);
19858
19859 /* "show [ip] bgp vrfs" commands. */
19860 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19861
19862 /* Community-list. */
19863 community_list_vty();
ddb5b488 19864
ed0e57e3
DA
19865 community_alias_vty();
19866
ddb5b488 19867 /* vpn-policy commands */
b9c7bc5a
PZ
19868 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19869 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19870 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19871 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19872 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19873 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19874 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19875 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19876 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19877 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
19878 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19879 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 19880
301ad80a
PG
19881 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19882 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19883
b9c7bc5a
PZ
19884 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19885 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19886 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19887 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
19888 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19889 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19890 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19891 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
19892 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19893 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
19894
19895 /* tcp-mss command */
19896 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19897 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
19898
19899 /* srv6 commands */
ea372e81 19900 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
bfaab44d 19901 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
0249b8b6 19902 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
a0281b2e 19903 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
0249b8b6 19904 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
b72c9e14
HS
19905 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19906 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
527588aa 19907 install_element(BGP_NODE, &bgp_sid_vpn_export_cmd);
4cd690ae
PG
19908
19909 bgp_vty_if_init();
718e3744 19910}
6b0655a2 19911
718e3744 19912#include "memory.h"
19913#include "bgp_regex.h"
19914#include "bgp_clist.h"
19915#include "bgp_ecommunity.h"
19916
19917/* VTY functions. */
19918
19919/* Direction value to string conversion. */
d62a17ae 19920static const char *community_direct_str(int direct)
19921{
19922 switch (direct) {
19923 case COMMUNITY_DENY:
19924 return "deny";
19925 case COMMUNITY_PERMIT:
19926 return "permit";
19927 default:
19928 return "unknown";
19929 }
718e3744 19930}
19931
19932/* Display error string. */
d62a17ae 19933static void community_list_perror(struct vty *vty, int ret)
19934{
19935 switch (ret) {
19936 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19937 vty_out(vty, "%% Can't find community-list\n");
19938 break;
19939 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19940 vty_out(vty, "%% Malformed community-list value\n");
19941 break;
19942 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19943 vty_out(vty,
19944 "%% Community name conflict, previously defined as standard community\n");
19945 break;
19946 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19947 vty_out(vty,
19948 "%% Community name conflict, previously defined as expanded community\n");
19949 break;
19950 }
718e3744 19951}
19952
5bf15956
DW
19953/* "community-list" keyword help string. */
19954#define COMMUNITY_LIST_STR "Add a community list entry\n"
19955
7336e101
SP
19956/*community-list standard */
19957DEFUN (community_list_standard,
19958 bgp_community_list_standard_cmd,
a2099c1d 19959 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19960 BGP_STR
718e3744 19961 COMMUNITY_LIST_STR
19962 "Community list number (standard)\n"
5bf15956 19963 "Add an standard community-list entry\n"
718e3744 19964 "Community list name\n"
2f8cc0e5
DA
19965 "Sequence number of an entry\n"
19966 "Sequence number\n"
718e3744 19967 "Specify community to reject\n"
19968 "Specify community to accept\n"
19969 COMMUNITY_VAL_STR)
19970{
d62a17ae 19971 char *cl_name_or_number = NULL;
2f8cc0e5 19972 char *seq = NULL;
d62a17ae 19973 int direct = 0;
19974 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 19975 int idx = 0;
7336e101 19976
e34627f9 19977 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19978 seq = argv[idx]->arg;
19979
19980 idx = 0;
d62a17ae 19981 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19982 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19983 cl_name_or_number = argv[idx]->arg;
19984 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19985 : COMMUNITY_DENY;
19986 argv_find(argv, argc, "AA:NN", &idx);
19987 char *str = argv_concat(argv, argc, idx);
42f914d4 19988
2f8cc0e5
DA
19989 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19990 direct, style);
42f914d4 19991
d62a17ae 19992 XFREE(MTYPE_TMP, str);
42f914d4 19993
d62a17ae 19994 if (ret < 0) {
19995 /* Display error string. */
19996 community_list_perror(vty, ret);
19997 return CMD_WARNING_CONFIG_FAILED;
19998 }
42f914d4 19999
d62a17ae 20000 return CMD_SUCCESS;
718e3744 20001}
20002
7336e101
SP
20003DEFUN (no_community_list_standard_all,
20004 no_bgp_community_list_standard_all_cmd,
a2099c1d 20005 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20006 NO_STR
20007 BGP_STR
20008 COMMUNITY_LIST_STR
20009 "Community list number (standard)\n"
20010 "Add an standard community-list entry\n"
20011 "Community list name\n"
2f8cc0e5
DA
20012 "Sequence number of an entry\n"
20013 "Sequence number\n"
7336e101
SP
20014 "Specify community to reject\n"
20015 "Specify community to accept\n"
20016 COMMUNITY_VAL_STR)
718e3744 20017{
d62a17ae 20018 char *cl_name_or_number = NULL;
174b5cb9 20019 char *str = NULL;
d62a17ae 20020 int direct = 0;
20021 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 20022 char *seq = NULL;
d62a17ae 20023 int idx = 0;
7336e101 20024
e34627f9 20025 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20026 seq = argv[idx]->arg;
20027
20028 idx = 0;
174b5cb9
DA
20029 argv_find(argv, argc, "permit", &idx);
20030 argv_find(argv, argc, "deny", &idx);
20031
20032 if (idx) {
20033 direct = argv_find(argv, argc, "permit", &idx)
20034 ? COMMUNITY_PERMIT
20035 : COMMUNITY_DENY;
20036
20037 idx = 0;
20038 argv_find(argv, argc, "AA:NN", &idx);
20039 str = argv_concat(argv, argc, idx);
20040 }
20041
20042 idx = 0;
d62a17ae 20043 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20044 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20045 cl_name_or_number = argv[idx]->arg;
42f914d4 20046
2f8cc0e5 20047 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 20048 direct, style);
42f914d4 20049
d62a17ae 20050 XFREE(MTYPE_TMP, str);
daf9ddbb 20051
d62a17ae 20052 if (ret < 0) {
20053 community_list_perror(vty, ret);
20054 return CMD_WARNING_CONFIG_FAILED;
20055 }
42f914d4 20056
d62a17ae 20057 return CMD_SUCCESS;
718e3744 20058}
7336e101 20059
174b5cb9 20060ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
a2099c1d 20061 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
174b5cb9
DA
20062 NO_STR BGP_STR COMMUNITY_LIST_STR
20063 "Community list number (standard)\n"
20064 "Add an standard community-list entry\n"
20065 "Community list name\n")
20066
7336e101
SP
20067/*community-list expanded */
20068DEFUN (community_list_expanded_all,
20069 bgp_community_list_expanded_all_cmd,
a2099c1d 20070 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20071 BGP_STR
20072 COMMUNITY_LIST_STR
718e3744 20073 "Community list number (expanded)\n"
5bf15956 20074 "Add an expanded community-list entry\n"
718e3744 20075 "Community list name\n"
2f8cc0e5
DA
20076 "Sequence number of an entry\n"
20077 "Sequence number\n"
718e3744 20078 "Specify community to reject\n"
20079 "Specify community to accept\n"
20080 COMMUNITY_VAL_STR)
20081{
d62a17ae 20082 char *cl_name_or_number = NULL;
2f8cc0e5 20083 char *seq = NULL;
d62a17ae 20084 int direct = 0;
20085 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 20086 int idx = 0;
7b9a4750 20087
e34627f9 20088 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20089 seq = argv[idx]->arg;
20090
20091 idx = 0;
20092
d62a17ae 20093 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20094 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20095 cl_name_or_number = argv[idx]->arg;
20096 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20097 : COMMUNITY_DENY;
20098 argv_find(argv, argc, "AA:NN", &idx);
20099 char *str = argv_concat(argv, argc, idx);
42f914d4 20100
2f8cc0e5
DA
20101 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20102 direct, style);
42f914d4 20103
d62a17ae 20104 XFREE(MTYPE_TMP, str);
42f914d4 20105
d62a17ae 20106 if (ret < 0) {
20107 /* Display error string. */
20108 community_list_perror(vty, ret);
20109 return CMD_WARNING_CONFIG_FAILED;
20110 }
42f914d4 20111
d62a17ae 20112 return CMD_SUCCESS;
718e3744 20113}
20114
7336e101
SP
20115DEFUN (no_community_list_expanded_all,
20116 no_bgp_community_list_expanded_all_cmd,
a2099c1d 20117 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20118 NO_STR
20119 BGP_STR
20120 COMMUNITY_LIST_STR
20121 "Community list number (expanded)\n"
20122 "Add an expanded community-list entry\n"
20123 "Community list name\n"
2f8cc0e5
DA
20124 "Sequence number of an entry\n"
20125 "Sequence number\n"
7336e101
SP
20126 "Specify community to reject\n"
20127 "Specify community to accept\n"
20128 COMMUNITY_VAL_STR)
718e3744 20129{
d62a17ae 20130 char *cl_name_or_number = NULL;
2f8cc0e5 20131 char *seq = NULL;
174b5cb9 20132 char *str = NULL;
d62a17ae 20133 int direct = 0;
20134 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 20135 int idx = 0;
174b5cb9 20136
e34627f9 20137 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20138 seq = argv[idx]->arg;
20139
20140 idx = 0;
174b5cb9
DA
20141 argv_find(argv, argc, "permit", &idx);
20142 argv_find(argv, argc, "deny", &idx);
20143
20144 if (idx) {
20145 direct = argv_find(argv, argc, "permit", &idx)
20146 ? COMMUNITY_PERMIT
20147 : COMMUNITY_DENY;
20148
20149 idx = 0;
20150 argv_find(argv, argc, "AA:NN", &idx);
20151 str = argv_concat(argv, argc, idx);
7336e101 20152 }
174b5cb9
DA
20153
20154 idx = 0;
d62a17ae 20155 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20156 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20157 cl_name_or_number = argv[idx]->arg;
42f914d4 20158
2f8cc0e5 20159 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 20160 direct, style);
42f914d4 20161
d62a17ae 20162 XFREE(MTYPE_TMP, str);
daf9ddbb 20163
d62a17ae 20164 if (ret < 0) {
20165 community_list_perror(vty, ret);
20166 return CMD_WARNING_CONFIG_FAILED;
20167 }
42f914d4 20168
d62a17ae 20169 return CMD_SUCCESS;
718e3744 20170}
20171
36d4bb44
EB
20172ALIAS(no_community_list_expanded_all,
20173 no_bgp_community_list_expanded_all_list_cmd,
a2099c1d 20174 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
36d4bb44 20175 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
20176 "Community list number (expanded)\n"
20177 "Add an expanded community-list entry\n"
20178 "Community list name\n")
20179
8d9b8ed9
PM
20180/* Return configuration string of community-list entry. */
20181static const char *community_list_config_str(struct community_entry *entry)
20182{
20183 const char *str;
20184
20185 if (entry->any)
20186 str = "";
20187 else {
20188 if (entry->style == COMMUNITY_LIST_STANDARD)
c0945b78 20189 str = community_str(entry->u.com, false, false);
8d9b8ed9 20190 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
c0945b78 20191 str = lcommunity_str(entry->u.lcom, false, false);
8d9b8ed9
PM
20192 else
20193 str = entry->config;
20194 }
20195 return str;
20196}
20197
d62a17ae 20198static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 20199{
d62a17ae 20200 struct community_entry *entry;
718e3744 20201
d62a17ae 20202 for (entry = list->head; entry; entry = entry->next) {
20203 if (entry == list->head) {
20204 if (all_digit(list->name))
20205 vty_out(vty, "Community %s list %s\n",
20206 entry->style == COMMUNITY_LIST_STANDARD
20207 ? "standard"
20208 : "(expanded) access",
20209 list->name);
20210 else
20211 vty_out(vty, "Named Community %s list %s\n",
20212 entry->style == COMMUNITY_LIST_STANDARD
20213 ? "standard"
20214 : "expanded",
20215 list->name);
20216 }
20217 if (entry->any)
20218 vty_out(vty, " %s\n",
20219 community_direct_str(entry->direct));
20220 else
20221 vty_out(vty, " %s %s\n",
20222 community_direct_str(entry->direct),
8d9b8ed9 20223 community_list_config_str(entry));
d62a17ae 20224 }
718e3744 20225}
20226
7336e101
SP
20227DEFUN (show_community_list,
20228 show_bgp_community_list_cmd,
20229 "show bgp community-list",
718e3744 20230 SHOW_STR
7336e101 20231 BGP_STR
718e3744 20232 "List community-list\n")
20233{
d62a17ae 20234 struct community_list *list;
20235 struct community_list_master *cm;
718e3744 20236
d62a17ae 20237 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20238 if (!cm)
20239 return CMD_SUCCESS;
718e3744 20240
d62a17ae 20241 for (list = cm->num.head; list; list = list->next)
20242 community_list_show(vty, list);
718e3744 20243
d62a17ae 20244 for (list = cm->str.head; list; list = list->next)
20245 community_list_show(vty, list);
718e3744 20246
d62a17ae 20247 return CMD_SUCCESS;
718e3744 20248}
20249
7336e101
SP
20250DEFUN (show_community_list_arg,
20251 show_bgp_community_list_arg_cmd,
a2099c1d 20252 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
7336e101
SP
20253 SHOW_STR
20254 BGP_STR
718e3744 20255 "List community-list\n"
20256 "Community-list number\n"
960b69b9 20257 "Community-list name\n"
20258 "Detailed information on community-list\n")
718e3744 20259{
d62a17ae 20260 int idx_comm_list = 3;
20261 struct community_list *list;
718e3744 20262
e237b0d2 20263 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20264 COMMUNITY_LIST_MASTER);
20265 if (!list) {
20266 vty_out(vty, "%% Can't find community-list\n");
20267 return CMD_WARNING;
20268 }
718e3744 20269
d62a17ae 20270 community_list_show(vty, list);
718e3744 20271
d62a17ae 20272 return CMD_SUCCESS;
718e3744 20273}
6b0655a2 20274
57d187bc
JS
20275/*
20276 * Large Community code.
20277 */
d62a17ae 20278static int lcommunity_list_set_vty(struct vty *vty, int argc,
20279 struct cmd_token **argv, int style,
20280 int reject_all_digit_name)
20281{
20282 int ret;
20283 int direct;
20284 char *str;
20285 int idx = 0;
20286 char *cl_name;
2f8cc0e5
DA
20287 char *seq = NULL;
20288
a08032fe 20289 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 20290 seq = argv[idx]->arg;
d62a17ae 20291
2f8cc0e5 20292 idx = 0;
d62a17ae 20293 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20294 : COMMUNITY_DENY;
20295
20296 /* All digit name check. */
20297 idx = 0;
a2099c1d 20298 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20299 argv_find(argv, argc, "(1-99)", &idx);
20300 argv_find(argv, argc, "(100-500)", &idx);
20301 cl_name = argv[idx]->arg;
20302 if (reject_all_digit_name && all_digit(cl_name)) {
20303 vty_out(vty, "%% Community name cannot have all digits\n");
20304 return CMD_WARNING_CONFIG_FAILED;
20305 }
20306
20307 idx = 0;
20308 argv_find(argv, argc, "AA:BB:CC", &idx);
20309 argv_find(argv, argc, "LINE", &idx);
20310 /* Concat community string argument. */
20311 if (idx)
20312 str = argv_concat(argv, argc, idx);
20313 else
20314 str = NULL;
20315
2f8cc0e5 20316 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 20317
20318 /* Free temporary community list string allocated by
20319 argv_concat(). */
0a22ddfb 20320 XFREE(MTYPE_TMP, str);
d62a17ae 20321
20322 if (ret < 0) {
20323 community_list_perror(vty, ret);
20324 return CMD_WARNING_CONFIG_FAILED;
20325 }
20326 return CMD_SUCCESS;
20327}
20328
20329static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20330 struct cmd_token **argv, int style)
20331{
20332 int ret;
20333 int direct = 0;
20334 char *str = NULL;
20335 int idx = 0;
2f8cc0e5 20336 char *seq = NULL;
d62a17ae 20337
a08032fe 20338 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 20339 seq = argv[idx]->arg;
d62a17ae 20340
2f8cc0e5 20341 idx = 0;
d62a17ae 20342 argv_find(argv, argc, "permit", &idx);
20343 argv_find(argv, argc, "deny", &idx);
20344
20345 if (idx) {
20346 /* Check the list direct. */
20347 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20348 direct = COMMUNITY_PERMIT;
20349 else
20350 direct = COMMUNITY_DENY;
20351
20352 idx = 0;
20353 argv_find(argv, argc, "LINE", &idx);
20354 argv_find(argv, argc, "AA:AA:NN", &idx);
20355 /* Concat community string argument. */
20356 str = argv_concat(argv, argc, idx);
20357 }
20358
20359 idx = 0;
20360 argv_find(argv, argc, "(1-99)", &idx);
20361 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20362 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20363
20364 /* Unset community list. */
2f8cc0e5 20365 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 20366 style);
20367
20368 /* Free temporary community list string allocated by
20369 argv_concat(). */
0a22ddfb 20370 XFREE(MTYPE_TMP, str);
d62a17ae 20371
20372 if (ret < 0) {
20373 community_list_perror(vty, ret);
20374 return CMD_WARNING_CONFIG_FAILED;
20375 }
20376
20377 return CMD_SUCCESS;
57d187bc
JS
20378}
20379
20380/* "large-community-list" keyword help string. */
20381#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20382#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20383
7336e101
SP
20384DEFUN (lcommunity_list_standard,
20385 bgp_lcommunity_list_standard_cmd,
a08032fe 20386 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
20387 BGP_STR
20388 LCOMMUNITY_LIST_STR
20389 "Large Community list number (standard)\n"
2f8cc0e5
DA
20390 "Sequence number of an entry\n"
20391 "Sequence number\n"
7336e101
SP
20392 "Specify large community to reject\n"
20393 "Specify large community to accept\n"
20394 LCOMMUNITY_VAL_STR)
52951b63 20395{
d62a17ae 20396 return lcommunity_list_set_vty(vty, argc, argv,
20397 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
20398}
20399
7336e101
SP
20400DEFUN (lcommunity_list_expanded,
20401 bgp_lcommunity_list_expanded_cmd,
a08032fe 20402 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20403 BGP_STR
20404 LCOMMUNITY_LIST_STR
20405 "Large Community list number (expanded)\n"
2f8cc0e5
DA
20406 "Sequence number of an entry\n"
20407 "Sequence number\n"
7336e101
SP
20408 "Specify large community to reject\n"
20409 "Specify large community to accept\n"
20410 "An ordered list as a regular-expression\n")
57d187bc 20411{
d62a17ae 20412 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 20413 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
20414}
20415
7336e101
SP
20416DEFUN (lcommunity_list_name_standard,
20417 bgp_lcommunity_list_name_standard_cmd,
a2099c1d 20418 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
20419 BGP_STR
20420 LCOMMUNITY_LIST_STR
20421 "Specify standard large-community-list\n"
20422 "Large Community list name\n"
2f8cc0e5
DA
20423 "Sequence number of an entry\n"
20424 "Sequence number\n"
7336e101
SP
20425 "Specify large community to reject\n"
20426 "Specify large community to accept\n"
20427 LCOMMUNITY_VAL_STR)
52951b63 20428{
d62a17ae 20429 return lcommunity_list_set_vty(vty, argc, argv,
20430 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
20431}
20432
7336e101
SP
20433DEFUN (lcommunity_list_name_expanded,
20434 bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 20435 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20436 BGP_STR
20437 LCOMMUNITY_LIST_STR
20438 "Specify expanded large-community-list\n"
20439 "Large Community list name\n"
2f8cc0e5
DA
20440 "Sequence number of an entry\n"
20441 "Sequence number\n"
7336e101
SP
20442 "Specify large community to reject\n"
20443 "Specify large community to accept\n"
20444 "An ordered list as a regular-expression\n")
57d187bc 20445{
d62a17ae 20446 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 20447 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
20448}
20449
4378f57c
DA
20450DEFUN (no_lcommunity_list_all,
20451 no_bgp_lcommunity_list_all_cmd,
a2099c1d 20452 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
7336e101
SP
20453 NO_STR
20454 BGP_STR
20455 LCOMMUNITY_LIST_STR
20456 "Large Community list number (standard)\n"
20457 "Large Community list number (expanded)\n"
20458 "Large Community list name\n")
57d187bc 20459{
7336e101
SP
20460 return lcommunity_list_unset_vty(vty, argc, argv,
20461 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20462}
20463
4378f57c
DA
20464DEFUN (no_lcommunity_list_name_standard_all,
20465 no_bgp_lcommunity_list_name_standard_all_cmd,
a2099c1d 20466 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
4378f57c
DA
20467 NO_STR
20468 BGP_STR
20469 LCOMMUNITY_LIST_STR
20470 "Specify standard large-community-list\n"
20471 "Large Community list name\n")
20472{
20473 return lcommunity_list_unset_vty(vty, argc, argv,
20474 LARGE_COMMUNITY_LIST_STANDARD);
20475}
20476
7336e101
SP
20477DEFUN (no_lcommunity_list_name_expanded_all,
20478 no_bgp_lcommunity_list_name_expanded_all_cmd,
a2099c1d 20479 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
7336e101
SP
20480 NO_STR
20481 BGP_STR
20482 LCOMMUNITY_LIST_STR
20483 "Specify expanded large-community-list\n"
20484 "Large Community list name\n")
57d187bc 20485{
d62a17ae 20486 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20487 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20488}
20489
7336e101
SP
20490DEFUN (no_lcommunity_list_standard,
20491 no_bgp_lcommunity_list_standard_cmd,
a08032fe 20492 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
20493 NO_STR
20494 BGP_STR
20495 LCOMMUNITY_LIST_STR
20496 "Large Community list number (standard)\n"
2f8cc0e5
DA
20497 "Sequence number of an entry\n"
20498 "Sequence number\n"
7336e101
SP
20499 "Specify large community to reject\n"
20500 "Specify large community to accept\n"
20501 LCOMMUNITY_VAL_STR)
57d187bc 20502{
d62a17ae 20503 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20504 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20505}
20506
7336e101
SP
20507DEFUN (no_lcommunity_list_expanded,
20508 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 20509 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20510 NO_STR
20511 BGP_STR
20512 LCOMMUNITY_LIST_STR
20513 "Large Community list number (expanded)\n"
2f8cc0e5
DA
20514 "Sequence number of an entry\n"
20515 "Sequence number\n"
7336e101
SP
20516 "Specify large community to reject\n"
20517 "Specify large community to accept\n"
20518 "An ordered list as a regular-expression\n")
57d187bc 20519{
d62a17ae 20520 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20521 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20522}
20523
7336e101
SP
20524DEFUN (no_lcommunity_list_name_standard,
20525 no_bgp_lcommunity_list_name_standard_cmd,
a2099c1d 20526 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
20527 NO_STR
20528 BGP_STR
20529 LCOMMUNITY_LIST_STR
20530 "Specify standard large-community-list\n"
20531 "Large Community list name\n"
2f8cc0e5
DA
20532 "Sequence number of an entry\n"
20533 "Sequence number\n"
7336e101
SP
20534 "Specify large community to reject\n"
20535 "Specify large community to accept\n"
20536 LCOMMUNITY_VAL_STR)
57d187bc 20537{
d62a17ae 20538 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20539 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20540}
20541
7336e101
SP
20542DEFUN (no_lcommunity_list_name_expanded,
20543 no_bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 20544 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20545 NO_STR
20546 BGP_STR
20547 LCOMMUNITY_LIST_STR
20548 "Specify expanded large-community-list\n"
20549 "Large community list name\n"
2f8cc0e5
DA
20550 "Sequence number of an entry\n"
20551 "Sequence number\n"
7336e101
SP
20552 "Specify large community to reject\n"
20553 "Specify large community to accept\n"
20554 "An ordered list as a regular-expression\n")
57d187bc 20555{
d62a17ae 20556 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20557 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20558}
20559
d62a17ae 20560static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20561{
20562 struct community_entry *entry;
20563
20564 for (entry = list->head; entry; entry = entry->next) {
20565 if (entry == list->head) {
20566 if (all_digit(list->name))
20567 vty_out(vty, "Large community %s list %s\n",
169b72c8 20568 entry->style ==
20569 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20570 ? "standard"
20571 : "(expanded) access",
20572 list->name);
20573 else
20574 vty_out(vty,
20575 "Named large community %s list %s\n",
169b72c8 20576 entry->style ==
20577 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20578 ? "standard"
20579 : "expanded",
20580 list->name);
20581 }
20582 if (entry->any)
20583 vty_out(vty, " %s\n",
20584 community_direct_str(entry->direct));
20585 else
20586 vty_out(vty, " %s %s\n",
20587 community_direct_str(entry->direct),
8d9b8ed9 20588 community_list_config_str(entry));
d62a17ae 20589 }
57d187bc
JS
20590}
20591
7336e101
SP
20592DEFUN (show_lcommunity_list,
20593 show_bgp_lcommunity_list_cmd,
20594 "show bgp large-community-list",
57d187bc 20595 SHOW_STR
7336e101 20596 BGP_STR
57d187bc
JS
20597 "List large-community list\n")
20598{
d62a17ae 20599 struct community_list *list;
20600 struct community_list_master *cm;
57d187bc 20601
d62a17ae 20602 cm = community_list_master_lookup(bgp_clist,
20603 LARGE_COMMUNITY_LIST_MASTER);
20604 if (!cm)
20605 return CMD_SUCCESS;
57d187bc 20606
d62a17ae 20607 for (list = cm->num.head; list; list = list->next)
20608 lcommunity_list_show(vty, list);
57d187bc 20609
d62a17ae 20610 for (list = cm->str.head; list; list = list->next)
20611 lcommunity_list_show(vty, list);
57d187bc 20612
d62a17ae 20613 return CMD_SUCCESS;
57d187bc
JS
20614}
20615
7336e101
SP
20616DEFUN (show_lcommunity_list_arg,
20617 show_bgp_lcommunity_list_arg_cmd,
a2099c1d 20618 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
7336e101
SP
20619 SHOW_STR
20620 BGP_STR
57d187bc 20621 "List large-community list\n"
960b69b9 20622 "Large-community-list number\n"
20623 "Large-community-list name\n"
20624 "Detailed information on large-community-list\n")
57d187bc 20625{
d62a17ae 20626 struct community_list *list;
57d187bc 20627
e237b0d2 20628 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 20629 LARGE_COMMUNITY_LIST_MASTER);
20630 if (!list) {
960b69b9 20631 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 20632 return CMD_WARNING;
20633 }
57d187bc 20634
d62a17ae 20635 lcommunity_list_show(vty, list);
57d187bc 20636
d62a17ae 20637 return CMD_SUCCESS;
57d187bc
JS
20638}
20639
718e3744 20640/* "extcommunity-list" keyword help string. */
20641#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20642#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20643
7336e101
SP
20644DEFUN (extcommunity_list_standard,
20645 bgp_extcommunity_list_standard_cmd,
a2099c1d 20646 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 20647 BGP_STR
718e3744 20648 EXTCOMMUNITY_LIST_STR
20649 "Extended Community list number (standard)\n"
718e3744 20650 "Specify standard extcommunity-list\n"
5bf15956 20651 "Community list name\n"
2f8cc0e5
DA
20652 "Sequence number of an entry\n"
20653 "Sequence number\n"
718e3744 20654 "Specify community to reject\n"
20655 "Specify community to accept\n"
20656 EXTCOMMUNITY_VAL_STR)
20657{
d62a17ae 20658 int style = EXTCOMMUNITY_LIST_STANDARD;
20659 int direct = 0;
20660 char *cl_number_or_name = NULL;
2f8cc0e5 20661 char *seq = NULL;
42f914d4 20662
d62a17ae 20663 int idx = 0;
7b9a4750 20664
d62a17ae 20665 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20666 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20667 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 20668
a08032fe 20669 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20670 seq = argv[idx]->arg;
20671
d62a17ae 20672 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20673 : COMMUNITY_DENY;
20674 argv_find(argv, argc, "AA:NN", &idx);
20675 char *str = argv_concat(argv, argc, idx);
42f914d4 20676
2f8cc0e5 20677 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 20678 direct, style);
42f914d4 20679
d62a17ae 20680 XFREE(MTYPE_TMP, str);
42f914d4 20681
d62a17ae 20682 if (ret < 0) {
20683 community_list_perror(vty, ret);
20684 return CMD_WARNING_CONFIG_FAILED;
20685 }
42f914d4 20686
d62a17ae 20687 return CMD_SUCCESS;
718e3744 20688}
20689
7336e101
SP
20690DEFUN (extcommunity_list_name_expanded,
20691 bgp_extcommunity_list_name_expanded_cmd,
a2099c1d 20692 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20693 BGP_STR
20694 EXTCOMMUNITY_LIST_STR
5bf15956 20695 "Extended Community list number (expanded)\n"
718e3744 20696 "Specify expanded extcommunity-list\n"
20697 "Extended Community list name\n"
2f8cc0e5
DA
20698 "Sequence number of an entry\n"
20699 "Sequence number\n"
718e3744 20700 "Specify community to reject\n"
20701 "Specify community to accept\n"
20702 "An ordered list as a regular-expression\n")
20703{
d62a17ae 20704 int style = EXTCOMMUNITY_LIST_EXPANDED;
20705 int direct = 0;
20706 char *cl_number_or_name = NULL;
2f8cc0e5 20707 char *seq = NULL;
d62a17ae 20708 int idx = 0;
7336e101 20709
d62a17ae 20710 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20711 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20712 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 20713
a08032fe 20714 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20715 seq = argv[idx]->arg;
20716
d62a17ae 20717 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20718 : COMMUNITY_DENY;
20719 argv_find(argv, argc, "LINE", &idx);
20720 char *str = argv_concat(argv, argc, idx);
42f914d4 20721
2f8cc0e5 20722 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 20723 direct, style);
42f914d4 20724
d62a17ae 20725 XFREE(MTYPE_TMP, str);
42f914d4 20726
d62a17ae 20727 if (ret < 0) {
20728 community_list_perror(vty, ret);
20729 return CMD_WARNING_CONFIG_FAILED;
20730 }
42f914d4 20731
d62a17ae 20732 return CMD_SUCCESS;
718e3744 20733}
20734
7336e101
SP
20735DEFUN (no_extcommunity_list_standard_all,
20736 no_bgp_extcommunity_list_standard_all_cmd,
a2099c1d 20737 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20738 NO_STR
20739 BGP_STR
20740 EXTCOMMUNITY_LIST_STR
813d4307 20741 "Extended Community list number (standard)\n"
718e3744 20742 "Specify standard extcommunity-list\n"
5bf15956 20743 "Community list name\n"
2f8cc0e5
DA
20744 "Sequence number of an entry\n"
20745 "Sequence number\n"
718e3744 20746 "Specify community to reject\n"
20747 "Specify community to accept\n"
20748 EXTCOMMUNITY_VAL_STR)
20749{
d62a17ae 20750 int style = EXTCOMMUNITY_LIST_STANDARD;
20751 int direct = 0;
20752 char *cl_number_or_name = NULL;
d4455c89 20753 char *str = NULL;
2f8cc0e5 20754 char *seq = NULL;
d62a17ae 20755 int idx = 0;
d4455c89 20756
a08032fe 20757 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20758 seq = argv[idx]->arg;
20759
20760 idx = 0;
d4455c89
DA
20761 argv_find(argv, argc, "permit", &idx);
20762 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
20763 if (idx) {
20764 direct = argv_find(argv, argc, "permit", &idx)
20765 ? COMMUNITY_PERMIT
20766 : COMMUNITY_DENY;
20767
20768 idx = 0;
20769 argv_find(argv, argc, "AA:NN", &idx);
20770 str = argv_concat(argv, argc, idx);
20771 }
20772
20773 idx = 0;
d62a17ae 20774 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20775 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20776 cl_number_or_name = argv[idx]->arg;
42f914d4 20777
d62a17ae 20778 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 20779 seq, direct, style);
42f914d4 20780
d62a17ae 20781 XFREE(MTYPE_TMP, str);
42f914d4 20782
d62a17ae 20783 if (ret < 0) {
20784 community_list_perror(vty, ret);
20785 return CMD_WARNING_CONFIG_FAILED;
20786 }
42f914d4 20787
d62a17ae 20788 return CMD_SUCCESS;
718e3744 20789}
20790
d4455c89
DA
20791ALIAS(no_extcommunity_list_standard_all,
20792 no_bgp_extcommunity_list_standard_all_list_cmd,
a2099c1d 20793 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
36d4bb44 20794 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
20795 "Extended Community list number (standard)\n"
20796 "Specify standard extcommunity-list\n"
20797 "Community list name\n")
20798
7336e101
SP
20799DEFUN (no_extcommunity_list_expanded_all,
20800 no_bgp_extcommunity_list_expanded_all_cmd,
a2099c1d 20801 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20802 NO_STR
20803 BGP_STR
20804 EXTCOMMUNITY_LIST_STR
718e3744 20805 "Extended Community list number (expanded)\n"
718e3744 20806 "Specify expanded extcommunity-list\n"
5bf15956 20807 "Extended Community list name\n"
2f8cc0e5
DA
20808 "Sequence number of an entry\n"
20809 "Sequence number\n"
718e3744 20810 "Specify community to reject\n"
20811 "Specify community to accept\n"
20812 "An ordered list as a regular-expression\n")
20813{
d62a17ae 20814 int style = EXTCOMMUNITY_LIST_EXPANDED;
20815 int direct = 0;
20816 char *cl_number_or_name = NULL;
d4455c89 20817 char *str = NULL;
2f8cc0e5 20818 char *seq = NULL;
d62a17ae 20819 int idx = 0;
d4455c89 20820
a08032fe 20821 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20822 seq = argv[idx]->arg;
20823
20824 idx = 0;
d4455c89
DA
20825 argv_find(argv, argc, "permit", &idx);
20826 argv_find(argv, argc, "deny", &idx);
20827
20828 if (idx) {
20829 direct = argv_find(argv, argc, "permit", &idx)
20830 ? COMMUNITY_PERMIT
20831 : COMMUNITY_DENY;
20832
20833 idx = 0;
20834 argv_find(argv, argc, "LINE", &idx);
20835 str = argv_concat(argv, argc, idx);
20836 }
20837
20838 idx = 0;
d62a17ae 20839 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20840 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20841 cl_number_or_name = argv[idx]->arg;
42f914d4 20842
d62a17ae 20843 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 20844 seq, direct, style);
42f914d4 20845
d62a17ae 20846 XFREE(MTYPE_TMP, str);
42f914d4 20847
d62a17ae 20848 if (ret < 0) {
20849 community_list_perror(vty, ret);
20850 return CMD_WARNING_CONFIG_FAILED;
20851 }
42f914d4 20852
d62a17ae 20853 return CMD_SUCCESS;
718e3744 20854}
20855
d4455c89
DA
20856ALIAS(no_extcommunity_list_expanded_all,
20857 no_bgp_extcommunity_list_expanded_all_list_cmd,
a2099c1d 20858 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
36d4bb44 20859 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
20860 "Extended Community list number (expanded)\n"
20861 "Specify expanded extcommunity-list\n"
20862 "Extended Community list name\n")
20863
d62a17ae 20864static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 20865{
d62a17ae 20866 struct community_entry *entry;
718e3744 20867
d62a17ae 20868 for (entry = list->head; entry; entry = entry->next) {
20869 if (entry == list->head) {
20870 if (all_digit(list->name))
20871 vty_out(vty, "Extended community %s list %s\n",
20872 entry->style == EXTCOMMUNITY_LIST_STANDARD
20873 ? "standard"
20874 : "(expanded) access",
20875 list->name);
20876 else
20877 vty_out(vty,
20878 "Named extended community %s list %s\n",
20879 entry->style == EXTCOMMUNITY_LIST_STANDARD
20880 ? "standard"
20881 : "expanded",
20882 list->name);
20883 }
20884 if (entry->any)
20885 vty_out(vty, " %s\n",
20886 community_direct_str(entry->direct));
20887 else
20888 vty_out(vty, " %s %s\n",
20889 community_direct_str(entry->direct),
8d9b8ed9 20890 community_list_config_str(entry));
d62a17ae 20891 }
718e3744 20892}
20893
7336e101
SP
20894DEFUN (show_extcommunity_list,
20895 show_bgp_extcommunity_list_cmd,
20896 "show bgp extcommunity-list",
718e3744 20897 SHOW_STR
7336e101 20898 BGP_STR
718e3744 20899 "List extended-community list\n")
20900{
d62a17ae 20901 struct community_list *list;
20902 struct community_list_master *cm;
718e3744 20903
d62a17ae 20904 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20905 if (!cm)
20906 return CMD_SUCCESS;
718e3744 20907
d62a17ae 20908 for (list = cm->num.head; list; list = list->next)
20909 extcommunity_list_show(vty, list);
718e3744 20910
d62a17ae 20911 for (list = cm->str.head; list; list = list->next)
20912 extcommunity_list_show(vty, list);
718e3744 20913
d62a17ae 20914 return CMD_SUCCESS;
718e3744 20915}
20916
7336e101
SP
20917DEFUN (show_extcommunity_list_arg,
20918 show_bgp_extcommunity_list_arg_cmd,
a2099c1d 20919 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
7336e101
SP
20920 SHOW_STR
20921 BGP_STR
718e3744 20922 "List extended-community list\n"
20923 "Extcommunity-list number\n"
960b69b9 20924 "Extcommunity-list name\n"
20925 "Detailed information on extcommunity-list\n")
718e3744 20926{
d62a17ae 20927 int idx_comm_list = 3;
20928 struct community_list *list;
718e3744 20929
e237b0d2 20930 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20931 EXTCOMMUNITY_LIST_MASTER);
20932 if (!list) {
20933 vty_out(vty, "%% Can't find extcommunity-list\n");
20934 return CMD_WARNING;
20935 }
718e3744 20936
d62a17ae 20937 extcommunity_list_show(vty, list);
718e3744 20938
d62a17ae 20939 return CMD_SUCCESS;
718e3744 20940}
6b0655a2 20941
718e3744 20942/* Display community-list and extcommunity-list configuration. */
d62a17ae 20943static int community_list_config_write(struct vty *vty)
20944{
20945 struct community_list *list;
20946 struct community_entry *entry;
20947 struct community_list_master *cm;
20948 int write = 0;
20949
20950 /* Community-list. */
20951 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20952
20953 for (list = cm->num.head; list; list = list->next)
20954 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20955 vty_out(vty,
20956 "bgp community-list %s seq %" PRId64 " %s %s\n",
20957 list->name, entry->seq,
d62a17ae 20958 community_direct_str(entry->direct),
20959 community_list_config_str(entry));
20960 write++;
20961 }
20962 for (list = cm->str.head; list; list = list->next)
20963 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20964 vty_out(vty,
20965 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 20966 entry->style == COMMUNITY_LIST_STANDARD
20967 ? "standard"
20968 : "expanded",
2f8cc0e5
DA
20969 list->name, entry->seq,
20970 community_direct_str(entry->direct),
d62a17ae 20971 community_list_config_str(entry));
20972 write++;
20973 }
20974
20975 /* Extcommunity-list. */
20976 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20977
20978 for (list = cm->num.head; list; list = list->next)
20979 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20980 vty_out(vty,
20981 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20982 list->name, entry->seq,
20983 community_direct_str(entry->direct),
d62a17ae 20984 community_list_config_str(entry));
20985 write++;
20986 }
20987 for (list = cm->str.head; list; list = list->next)
20988 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20989 vty_out(vty,
6cde4b45 20990 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 20991 entry->style == EXTCOMMUNITY_LIST_STANDARD
20992 ? "standard"
20993 : "expanded",
2f8cc0e5
DA
20994 list->name, entry->seq,
20995 community_direct_str(entry->direct),
d62a17ae 20996 community_list_config_str(entry));
20997 write++;
20998 }
20999
21000
21001 /* lcommunity-list. */
21002 cm = community_list_master_lookup(bgp_clist,
21003 LARGE_COMMUNITY_LIST_MASTER);
21004
21005 for (list = cm->num.head; list; list = list->next)
21006 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21007 vty_out(vty,
6cde4b45 21008 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
21009 list->name, entry->seq,
21010 community_direct_str(entry->direct),
d62a17ae 21011 community_list_config_str(entry));
21012 write++;
21013 }
21014 for (list = cm->str.head; list; list = list->next)
21015 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21016 vty_out(vty,
6cde4b45 21017 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 21018
d62a17ae 21019 entry->style == LARGE_COMMUNITY_LIST_STANDARD
21020 ? "standard"
21021 : "expanded",
2f8cc0e5 21022 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 21023 community_list_config_str(entry));
21024 write++;
21025 }
21026
21027 return write;
21028}
21029
612c2c15 21030static int community_list_config_write(struct vty *vty);
d62a17ae 21031static struct cmd_node community_list_node = {
f4b8291f 21032 .name = "community list",
62b346ee
DL
21033 .node = COMMUNITY_LIST_NODE,
21034 .prompt = "",
612c2c15 21035 .config_write = community_list_config_write,
718e3744 21036};
21037
d62a17ae 21038static void community_list_vty(void)
21039{
612c2c15 21040 install_node(&community_list_node);
d62a17ae 21041
21042 /* Community-list. */
7336e101
SP
21043 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
21044 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
21045 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 21046 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 21047 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 21048 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
21049 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
21050 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 21051
21052 /* Extcommunity-list. */
7336e101
SP
21053 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
21054 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
21055 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
21056 install_element(CONFIG_NODE,
21057 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 21058 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
21059 install_element(CONFIG_NODE,
21060 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
21061 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
21062 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 21063
21064 /* Large Community List */
7336e101 21065 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
21066 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
21067 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 21068 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
21069 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
21070 install_element(CONFIG_NODE,
21071 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
21072 install_element(CONFIG_NODE,
21073 &no_bgp_lcommunity_list_name_expanded_all_cmd);
21074 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
21075 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
21076 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
21077 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
21078 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
21079 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
225096bc
DA
21080
21081 bgp_community_list_command_completion_setup();
5bf15956 21082}
ed0e57e3
DA
21083
21084static struct cmd_node community_alias_node = {
21085 .name = "community alias",
21086 .node = COMMUNITY_ALIAS_NODE,
21087 .prompt = "",
21088 .config_write = bgp_community_alias_write,
21089};
21090
21091void community_alias_vty(void)
21092{
21093 install_node(&community_alias_node);
21094
21095 /* Community-list. */
21096 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
b4ad2fae
DS
21097
21098 bgp_community_alias_command_completion_setup();
ed0e57e3 21099}