]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #13479 from ryndia/fix_leak
[mirror_frr.git] / bgpd / bgp_vty.c
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
718e3744 2/* BGP VTY interface.
896014f4 3 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
896014f4 4 */
718e3744 5
6#include <zebra.h>
7
8#include "command.h"
afec25d9 9#include "lib/json.h"
4ab46701 10#include "lib/sockopt.h"
5cb5f4d0 11#include "lib_errors.h"
ec0ab544 12#include "lib/zclient.h"
6f4eacf3 13#include "lib/printfrr.h"
718e3744 14#include "prefix.h"
15#include "plist.h"
16#include "buffer.h"
17#include "linklist.h"
18#include "stream.h"
24a58196 19#include "frrevent.h"
718e3744 20#include "log.h"
3b8b1855 21#include "memory.h"
1c0d8808 22#include "lib_vty.h"
4bf6a362 23#include "hash.h"
3f9c7369 24#include "queue.h"
039f3a34 25#include "filter.h"
5d5ba018 26#include "frrstr.h"
8079a413 27#include "asn.h"
718e3744 28
29#include "bgpd/bgpd.h"
48ecf8f5 30#include "bgpd/bgp_attr_evpn.h"
4bf6a362 31#include "bgpd/bgp_advertise.h"
718e3744 32#include "bgpd/bgp_attr.h"
33#include "bgpd/bgp_aspath.h"
34#include "bgpd/bgp_community.h"
ed0e57e3 35#include "bgpd/bgp_community_alias.h"
4bf6a362 36#include "bgpd/bgp_ecommunity.h"
57d187bc 37#include "bgpd/bgp_lcommunity.h"
4bf6a362 38#include "bgpd/bgp_damp.h"
718e3744 39#include "bgpd/bgp_debug.h"
14454c9f 40#include "bgpd/bgp_errors.h"
e0701b79 41#include "bgpd/bgp_fsm.h"
4cd690ae 42#include "bgpd/bgp_nht.h"
4bf6a362 43#include "bgpd/bgp_nexthop.h"
4122b697 44#include "bgpd/bgp_network.h"
718e3744 45#include "bgpd/bgp_open.h"
4bf6a362 46#include "bgpd/bgp_regex.h"
718e3744 47#include "bgpd/bgp_route.h"
c016b6c7 48#include "bgpd/bgp_mplsvpn.h"
718e3744 49#include "bgpd/bgp_zebra.h"
fee0f4c6 50#include "bgpd/bgp_table.h"
94f2b392 51#include "bgpd/bgp_vty.h"
165b5fff 52#include "bgpd/bgp_mpath.h"
cb1faec9 53#include "bgpd/bgp_packet.h"
3f9c7369 54#include "bgpd/bgp_updgrp.h"
c43ed2e4 55#include "bgpd/bgp_bfd.h"
555e09d4 56#include "bgpd/bgp_io.h"
94c2f693 57#include "bgpd/bgp_evpn.h"
dd65f45e 58#include "bgpd/bgp_evpn_vty.h"
b5e140c8 59#include "bgpd/bgp_evpn_mh.h"
dcc68b5e 60#include "bgpd/bgp_addpath.h"
48ecf8f5 61#include "bgpd/bgp_mac.h"
dd65f45e 62#include "bgpd/bgp_flowspec.h"
389e4f92 63#include "bgpd/bgp_conditional_adv.h"
49e5a4a0 64#ifdef ENABLE_BGP_VNC
dd65f45e
DL
65#include "bgpd/rfapi/bgp_rfapi_cfg.h"
66#endif
67
5d5393b9 68FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
62282e83
DS
69 {
70 .val_bool = false,
71 .match_profile = "traditional",
72 .match_version = "< 7.4",
73 },
74 { .val_bool = true },
67b0f40c 75);
5d5393b9 76FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
4c1458b5
DL
77 { .val_bool = true, .match_profile = "datacenter", },
78 { .val_bool = false },
67b0f40c 79);
aef999a2
DA
80FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
81 { .val_bool = true, .match_profile = "datacenter", },
82 { .val_bool = false },
67b0f40c 83);
5d5393b9 84FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
4c1458b5
DL
85 { .val_bool = true, .match_profile = "datacenter", },
86 { .val_bool = false },
67b0f40c 87);
5d5393b9 88FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
4c1458b5
DL
89 { .val_bool = true, .match_profile = "datacenter", },
90 { .val_bool = false },
67b0f40c 91);
5d5393b9
DL
92FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
93 { .val_ulong = 10, .match_profile = "datacenter", },
94 { .val_ulong = 120 },
67b0f40c 95);
5d5393b9
DL
96FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
97 { .val_ulong = 9, .match_profile = "datacenter", },
98 { .val_ulong = 180 },
67b0f40c 99);
5d5393b9
DL
100FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
101 { .val_ulong = 3, .match_profile = "datacenter", },
102 { .val_ulong = 60 },
67b0f40c 103);
1d3fdccf
DA
104FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
105 { .val_bool = false, .match_profile = "datacenter", },
106 { .val_bool = false, .match_version = "< 7.4", },
107 { .val_bool = true },
67b0f40c 108);
2adac256
DA
109FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
110 { .val_bool = false, .match_version = "< 7.6", },
111 { .val_bool = true },
67b0f40c 112);
f2ca5c5b
DA
113FRR_CFG_DEFAULT_BOOL(BGP_GRACEFUL_NOTIFICATION,
114 { .val_bool = false, .match_version = "< 8.3", },
115 { .val_bool = true },
116);
1ae314be
DA
117FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET,
118 { .val_bool = false, .match_version = "< 8.3", },
119 { .val_bool = true },
120);
5d5393b9 121
dd65f45e
DL
122DEFINE_HOOK(bgp_inst_config_write,
123 (struct bgp *bgp, struct vty *vty),
8451921b
DL
124 (bgp, vty));
125DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
1ca2fd11 126DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
718e3744 127
d62a17ae 128static struct peer_group *listen_range_exists(struct bgp *bgp,
129 struct prefix *range, int exact);
130
055679e9 131/* Show BGP peer's information. */
132enum show_type {
133 show_all,
134 show_peer,
135 show_ipv4_all,
136 show_ipv6_all,
137 show_ipv4_peer,
138 show_ipv6_peer
139};
140
36235319
QY
141static struct peer_group *listen_range_exists(struct bgp *bgp,
142 struct prefix *range, int exact);
2986cac2 143
36235319 144static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
403e64f8 145 struct bgp *bgp);
2986cac2 146
36235319
QY
147static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
148 enum show_type type,
149 const char *ip_str,
150 afi_t afi, bool use_json);
2986cac2 151
d62a17ae 152static enum node_type bgp_node_type(afi_t afi, safi_t safi)
153{
154 switch (afi) {
155 case AFI_IP:
156 switch (safi) {
157 case SAFI_UNICAST:
158 return BGP_IPV4_NODE;
d62a17ae 159 case SAFI_MULTICAST:
160 return BGP_IPV4M_NODE;
d62a17ae 161 case SAFI_LABELED_UNICAST:
162 return BGP_IPV4L_NODE;
d62a17ae 163 case SAFI_MPLS_VPN:
164 return BGP_VPNV4_NODE;
7c40bf39 165 case SAFI_FLOWSPEC:
166 return BGP_FLOWSPECV4_NODE;
58cf0823
DS
167 case SAFI_UNSPEC:
168 case SAFI_ENCAP:
169 case SAFI_EVPN:
170 case SAFI_MAX:
5c525538
RW
171 /* not expected */
172 return BGP_IPV4_NODE;
d62a17ae 173 }
58cf0823 174 break;
d62a17ae 175 case AFI_IP6:
176 switch (safi) {
177 case SAFI_UNICAST:
178 return BGP_IPV6_NODE;
d62a17ae 179 case SAFI_MULTICAST:
180 return BGP_IPV6M_NODE;
d62a17ae 181 case SAFI_LABELED_UNICAST:
182 return BGP_IPV6L_NODE;
d62a17ae 183 case SAFI_MPLS_VPN:
184 return BGP_VPNV6_NODE;
7c40bf39 185 case SAFI_FLOWSPEC:
186 return BGP_FLOWSPECV6_NODE;
58cf0823
DS
187 case SAFI_UNSPEC:
188 case SAFI_ENCAP:
189 case SAFI_EVPN:
190 case SAFI_MAX:
191 /* not expected and the return value seems wrong */
5c525538 192 return BGP_IPV4_NODE;
d62a17ae 193 }
58cf0823 194 break;
d62a17ae 195 case AFI_L2VPN:
196 return BGP_EVPN_NODE;
b26f891d 197 case AFI_UNSPEC:
d62a17ae 198 case AFI_MAX:
199 // We should never be here but to clarify the switch statement..
200 return BGP_IPV4_NODE;
d62a17ae 201 }
202
203 // Impossible to happen
204 return BGP_IPV4_NODE;
f51bae9c 205}
20eb8864 206
5cb5f4d0
DD
207static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
208{
7d0d37de
DS
209 if (afi == AFI_IP) {
210 if (safi == SAFI_UNICAST)
211 return "IPv4 Unicast";
212 if (safi == SAFI_MULTICAST)
213 return "IPv4 Multicast";
214 if (safi == SAFI_LABELED_UNICAST)
215 return "IPv4 Labeled Unicast";
216 if (safi == SAFI_MPLS_VPN)
217 return "IPv4 VPN";
218 if (safi == SAFI_ENCAP)
219 return "IPv4 Encap";
220 if (safi == SAFI_FLOWSPEC)
221 return "IPv4 Flowspec";
222 } else if (afi == AFI_IP6) {
223 if (safi == SAFI_UNICAST)
224 return "IPv6 Unicast";
225 if (safi == SAFI_MULTICAST)
226 return "IPv6 Multicast";
227 if (safi == SAFI_LABELED_UNICAST)
228 return "IPv6 Labeled Unicast";
229 if (safi == SAFI_MPLS_VPN)
230 return "IPv6 VPN";
231 if (safi == SAFI_ENCAP)
232 return "IPv6 Encap";
233 if (safi == SAFI_FLOWSPEC)
234 return "IPv6 Flowspec";
235 } else if (afi == AFI_L2VPN) {
236 if (safi == SAFI_EVPN)
237 return "L2VPN EVPN";
238 }
239
240 return "Unknown";
5cb5f4d0
DD
241}
242
243/*
244 * Please note that we have intentionally camelCased
245 * the return strings here. So if you want
246 * to use this function, please ensure you
247 * are doing this within json output
248 */
249static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
250{
7d0d37de
DS
251 if (afi == AFI_IP) {
252 if (safi == SAFI_UNICAST)
253 return "ipv4Unicast";
254 if (safi == SAFI_MULTICAST)
255 return "ipv4Multicast";
256 if (safi == SAFI_LABELED_UNICAST)
257 return "ipv4LabeledUnicast";
258 if (safi == SAFI_MPLS_VPN)
259 return "ipv4Vpn";
260 if (safi == SAFI_ENCAP)
261 return "ipv4Encap";
262 if (safi == SAFI_FLOWSPEC)
263 return "ipv4Flowspec";
264 } else if (afi == AFI_IP6) {
265 if (safi == SAFI_UNICAST)
266 return "ipv6Unicast";
267 if (safi == SAFI_MULTICAST)
268 return "ipv6Multicast";
269 if (safi == SAFI_LABELED_UNICAST)
270 return "ipv6LabeledUnicast";
271 if (safi == SAFI_MPLS_VPN)
272 return "ipv6Vpn";
273 if (safi == SAFI_ENCAP)
274 return "ipv6Encap";
275 if (safi == SAFI_FLOWSPEC)
276 return "ipv6Flowspec";
277 } else if (afi == AFI_L2VPN) {
278 if (safi == SAFI_EVPN)
279 return "l2VpnEvpn";
280 }
281
282 return "Unknown";
5cb5f4d0
DD
283}
284
0249b8b6
HS
285/* unset srv6 locator */
286static int bgp_srv6_locator_unset(struct bgp *bgp)
287{
288 int ret;
289 struct listnode *node, *nnode;
efae8c26 290 struct srv6_locator_chunk *chunk;
0249b8b6
HS
291 struct bgp_srv6_function *func;
292 struct bgp *bgp_vrf;
0249b8b6
HS
293
294 /* release chunk notification via ZAPI */
295 ret = bgp_zebra_srv6_manager_release_locator_chunk(
296 bgp->srv6_locator_name);
297 if (ret < 0)
298 return -1;
299
300 /* refresh chunks */
03852f67 301 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
0249b8b6 302 listnode_delete(bgp->srv6_locator_chunks, chunk);
69467313 303 srv6_locator_chunk_free(&chunk);
03852f67 304 }
0249b8b6
HS
305
306 /* refresh functions */
bda15542 307 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
0249b8b6 308 listnode_delete(bgp->srv6_functions, func);
bda15542
CS
309 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
310 }
0249b8b6
HS
311
312 /* refresh tovpn_sid */
313 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
314 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
315 continue;
316
317 /* refresh vpnv4 tovpn_sid */
944909f4
CS
318 XFREE(MTYPE_BGP_SRV6_SID,
319 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
0249b8b6
HS
320
321 /* refresh vpnv6 tovpn_sid */
944909f4
CS
322 XFREE(MTYPE_BGP_SRV6_SID,
323 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
527588aa
CS
324
325 /* refresh per-vrf tovpn_sid */
326 XFREE(MTYPE_BGP_SRV6_SID, bgp_vrf->tovpn_sid);
0249b8b6
HS
327 }
328
329 /* update vpn bgp processes */
330 vpn_leak_postchange_all();
331
f8e9c702
CS
332 /* refresh tovpn_sid_locator */
333 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
334 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
335 continue;
336
337 /* refresh vpnv4 tovpn_sid_locator */
efae8c26
CS
338 srv6_locator_chunk_free(
339 &bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
f8e9c702
CS
340
341 /* refresh vpnv6 tovpn_sid_locator */
efae8c26
CS
342 srv6_locator_chunk_free(
343 &bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
527588aa
CS
344
345 /* refresh per-vrf tovpn_sid_locator */
69467313 346 srv6_locator_chunk_free(&bgp_vrf->tovpn_sid_locator);
f8e9c702
CS
347 }
348
0249b8b6
HS
349 /* clear locator name */
350 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
351
352 return 0;
353}
354
718e3744 355/* Utility function to get address family from current node. */
d62a17ae 356afi_t bgp_node_afi(struct vty *vty)
357{
358 afi_t afi;
359 switch (vty->node) {
360 case BGP_IPV6_NODE:
361 case BGP_IPV6M_NODE:
362 case BGP_IPV6L_NODE:
363 case BGP_VPNV6_NODE:
7c40bf39 364 case BGP_FLOWSPECV6_NODE:
d62a17ae 365 afi = AFI_IP6;
366 break;
367 case BGP_EVPN_NODE:
368 afi = AFI_L2VPN;
369 break;
370 default:
371 afi = AFI_IP;
372 break;
373 }
374 return afi;
718e3744 375}
376
377/* Utility function to get subsequent address family from current
378 node. */
d62a17ae 379safi_t bgp_node_safi(struct vty *vty)
380{
381 safi_t safi;
382 switch (vty->node) {
383 case BGP_VPNV4_NODE:
384 case BGP_VPNV6_NODE:
385 safi = SAFI_MPLS_VPN;
386 break;
387 case BGP_IPV4M_NODE:
388 case BGP_IPV6M_NODE:
389 safi = SAFI_MULTICAST;
390 break;
391 case BGP_EVPN_NODE:
392 safi = SAFI_EVPN;
393 break;
394 case BGP_IPV4L_NODE:
395 case BGP_IPV6L_NODE:
396 safi = SAFI_LABELED_UNICAST;
397 break;
7c40bf39 398 case BGP_FLOWSPECV4_NODE:
399 case BGP_FLOWSPECV6_NODE:
400 safi = SAFI_FLOWSPEC;
401 break;
d62a17ae 402 default:
403 safi = SAFI_UNICAST;
404 break;
405 }
406 return safi;
718e3744 407}
408
55f91488
QY
409/**
410 * Converts an AFI in string form to afi_t
411 *
412 * @param afi string, one of
413 * - "ipv4"
414 * - "ipv6"
81cf0de5 415 * - "l2vpn"
55f91488
QY
416 * @return the corresponding afi_t
417 */
d62a17ae 418afi_t bgp_vty_afi_from_str(const char *afi_str)
419{
420 afi_t afi = AFI_MAX; /* unknown */
421 if (strmatch(afi_str, "ipv4"))
422 afi = AFI_IP;
423 else if (strmatch(afi_str, "ipv6"))
424 afi = AFI_IP6;
81cf0de5
CS
425 else if (strmatch(afi_str, "l2vpn"))
426 afi = AFI_L2VPN;
d62a17ae 427 return afi;
428}
429
430int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
431 afi_t *afi)
432{
433 int ret = 0;
434 if (argv_find(argv, argc, "ipv4", index)) {
435 ret = 1;
436 if (afi)
437 *afi = AFI_IP;
438 } else if (argv_find(argv, argc, "ipv6", index)) {
439 ret = 1;
440 if (afi)
441 *afi = AFI_IP6;
8688b3e7
DS
442 } else if (argv_find(argv, argc, "l2vpn", index)) {
443 ret = 1;
444 if (afi)
445 *afi = AFI_L2VPN;
d62a17ae 446 }
447 return ret;
46f296b4
LB
448}
449
375a2e67 450/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 451safi_t bgp_vty_safi_from_str(const char *safi_str)
452{
453 safi_t safi = SAFI_MAX; /* unknown */
454 if (strmatch(safi_str, "multicast"))
455 safi = SAFI_MULTICAST;
456 else if (strmatch(safi_str, "unicast"))
457 safi = SAFI_UNICAST;
458 else if (strmatch(safi_str, "vpn"))
459 safi = SAFI_MPLS_VPN;
81cf0de5
CS
460 else if (strmatch(safi_str, "evpn"))
461 safi = SAFI_EVPN;
d62a17ae 462 else if (strmatch(safi_str, "labeled-unicast"))
463 safi = SAFI_LABELED_UNICAST;
7c40bf39 464 else if (strmatch(safi_str, "flowspec"))
465 safi = SAFI_FLOWSPEC;
d62a17ae 466 return safi;
467}
468
469int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
470 safi_t *safi)
471{
472 int ret = 0;
473 if (argv_find(argv, argc, "unicast", index)) {
474 ret = 1;
475 if (safi)
476 *safi = SAFI_UNICAST;
477 } else if (argv_find(argv, argc, "multicast", index)) {
478 ret = 1;
479 if (safi)
480 *safi = SAFI_MULTICAST;
481 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
482 ret = 1;
483 if (safi)
484 *safi = SAFI_LABELED_UNICAST;
485 } else if (argv_find(argv, argc, "vpn", index)) {
486 ret = 1;
487 if (safi)
488 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
489 } else if (argv_find(argv, argc, "evpn", index)) {
490 ret = 1;
491 if (safi)
492 *safi = SAFI_EVPN;
7c40bf39 493 } else if (argv_find(argv, argc, "flowspec", index)) {
494 ret = 1;
495 if (safi)
496 *safi = SAFI_FLOWSPEC;
d62a17ae 497 }
498 return ret;
46f296b4
LB
499}
500
b16bcbba
TA
501/*
502 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
503 *
504 * afi
505 * address-family identifier
506 *
507 * safi
508 * subsequent address-family identifier
509 *
510 * Returns:
511 * default_af string corresponding to the supplied afi/safi pair.
512 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
513 * return -1.
514 */
515static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
516{
517 switch (afi) {
518 case AFI_IP:
519 switch (safi) {
520 case SAFI_UNICAST:
521 return "ipv4-unicast";
522 case SAFI_MULTICAST:
523 return "ipv4-multicast";
524 case SAFI_MPLS_VPN:
525 return "ipv4-vpn";
526 case SAFI_ENCAP:
527 return "ipv4-encap";
528 case SAFI_LABELED_UNICAST:
529 return "ipv4-labeled-unicast";
530 case SAFI_FLOWSPEC:
531 return "ipv4-flowspec";
58cf0823
DS
532 case SAFI_UNSPEC:
533 case SAFI_EVPN:
534 case SAFI_MAX:
b16bcbba
TA
535 return "unknown-afi/safi";
536 }
537 break;
538 case AFI_IP6:
539 switch (safi) {
540 case SAFI_UNICAST:
541 return "ipv6-unicast";
542 case SAFI_MULTICAST:
543 return "ipv6-multicast";
544 case SAFI_MPLS_VPN:
545 return "ipv6-vpn";
546 case SAFI_ENCAP:
547 return "ipv6-encap";
548 case SAFI_LABELED_UNICAST:
549 return "ipv6-labeled-unicast";
550 case SAFI_FLOWSPEC:
551 return "ipv6-flowspec";
58cf0823
DS
552 case SAFI_UNSPEC:
553 case SAFI_EVPN:
554 case SAFI_MAX:
b16bcbba
TA
555 return "unknown-afi/safi";
556 }
557 break;
558 case AFI_L2VPN:
559 switch (safi) {
560 case SAFI_EVPN:
561 return "l2vpn-evpn";
58cf0823
DS
562 case SAFI_UNICAST:
563 case SAFI_MULTICAST:
564 case SAFI_MPLS_VPN:
565 case SAFI_ENCAP:
566 case SAFI_LABELED_UNICAST:
567 case SAFI_FLOWSPEC:
568 case SAFI_UNSPEC:
569 case SAFI_MAX:
b16bcbba
TA
570 return "unknown-afi/safi";
571 }
58cf0823 572 break;
b16bcbba
TA
573 case AFI_UNSPEC:
574 case AFI_MAX:
575 return "unknown-afi/safi";
576 }
577 /* all AFIs are accounted for above, so this shouldn't happen */
58cf0823
DS
578
579 assert(!"Reached end of function where we did not expect to");
b16bcbba
TA
580}
581
5d5393b9 582int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
e55b0883
PG
583 enum bgp_instance_type inst_type, const char *as_pretty,
584 enum asnotation_mode asnotation)
5d5393b9 585{
e55b0883 586 int ret = bgp_get(bgp, as, name, inst_type, as_pretty, asnotation);
5d5393b9
DL
587
588 if (ret == BGP_CREATED) {
589 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
d43114f3 590 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
5d5393b9
DL
591
592 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 593 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 594 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 595 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
596 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
597 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 598 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 599 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 600 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 601 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
602 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
603 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2adac256
DA
604 if (DFLT_BGP_SUPPRESS_DUPLICATES)
605 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
f2ca5c5b
DA
606 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
607 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
1ae314be
DA
608 if (DFLT_BGP_HARD_ADMIN_RESET)
609 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
5d5393b9
DL
610
611 ret = BGP_SUCCESS;
612 }
613 return ret;
614}
615
7eeee51e 616/*
f212a857 617 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 618 *
f212a857
DS
619 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
620 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
621 * to appropriate values for the calling function. This is to allow the
622 * calling function to make decisions appropriate for the show command
623 * that is being parsed.
624 *
625 * The show commands are generally of the form:
d62a17ae 626 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
627 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
628 *
629 * Since we use argv_find if the show command in particular doesn't have:
630 * [ip]
18c57037 631 * [<view|vrf> VIEWVRFNAME]
375a2e67 632 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
633 * The command parsing should still be ok.
634 *
635 * vty -> The vty for the command so we can output some useful data in
636 * the event of a parse error in the vrf.
637 * argv -> The command tokens
638 * argc -> How many command tokens we have
d62a17ae 639 * idx -> The current place in the command, generally should be 0 for this
640 * function
7eeee51e
DS
641 * afi -> The parsed afi if it was included in the show command, returned here
642 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 643 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 644 * use_json -> json is configured or not
7eeee51e
DS
645 *
646 * The function returns the correct location in the parse tree for the
647 * last token found.
0e37c258
DS
648 *
649 * Returns 0 for failure to parse correctly, else the idx position of where
650 * it found the last token.
7eeee51e 651 */
d62a17ae 652int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
653 struct cmd_token **argv, int argc,
654 int *idx, afi_t *afi, safi_t *safi,
9f049418 655 struct bgp **bgp, bool use_json)
d62a17ae 656{
657 char *vrf_name = NULL;
658
659 assert(afi);
660 assert(safi);
661 assert(bgp);
662
663 if (argv_find(argv, argc, "ip", idx))
664 *afi = AFI_IP;
665
9a8bdf1c 666 if (argv_find(argv, argc, "view", idx))
d62a17ae 667 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
668 else if (argv_find(argv, argc, "vrf", idx)) {
669 vrf_name = argv[*idx + 1]->arg;
670 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
671 vrf_name = NULL;
672 }
673 if (vrf_name) {
d62a17ae 674 if (strmatch(vrf_name, "all"))
675 *bgp = NULL;
676 else {
677 *bgp = bgp_lookup_by_name(vrf_name);
678 if (!*bgp) {
52e5b8c4
SP
679 if (use_json) {
680 json_object *json = NULL;
681 json = json_object_new_object();
682 json_object_string_add(
683 json, "warning",
684 "View/Vrf is unknown");
75eeda93 685 vty_json(vty, json);
52e5b8c4 686 }
ca61fd25
DS
687 else
688 vty_out(vty, "View/Vrf %s is unknown\n",
689 vrf_name);
d62a17ae 690 *idx = 0;
691 return 0;
692 }
693 }
694 } else {
695 *bgp = bgp_get_default();
696 if (!*bgp) {
52e5b8c4
SP
697 if (use_json) {
698 json_object *json = NULL;
699 json = json_object_new_object();
700 json_object_string_add(
701 json, "warning",
702 "Default BGP instance not found");
75eeda93 703 vty_json(vty, json);
52e5b8c4 704 }
ca61fd25
DS
705 else
706 vty_out(vty,
707 "Default BGP instance not found\n");
d62a17ae 708 *idx = 0;
709 return 0;
710 }
711 }
712
713 if (argv_find_and_parse_afi(argv, argc, idx, afi))
714 argv_find_and_parse_safi(argv, argc, idx, safi);
715
716 *idx += 1;
717 return *idx;
718}
719
28c6e247 720static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 721{
722 struct interface *ifp = NULL;
4122b697
DA
723 struct listnode *node;
724 struct bgp_listener *listener;
725 union sockunion all_su;
d62a17ae 726
4122b697 727 if (su->sa.sa_family == AF_INET) {
3d2a2725 728 (void)str2sockunion("0.0.0.0", &all_su);
d62a17ae 729 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
4122b697 730 } else if (su->sa.sa_family == AF_INET6) {
3d2a2725 731 (void)str2sockunion("::", &all_su);
d62a17ae 732 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
733 su->sin6.sin6_scope_id,
734 bgp->vrf_id);
4122b697 735 }
d62a17ae 736
4122b697
DA
737 if (ifp) {
738 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
739 if (sockunion_family(su) !=
740 sockunion_family(&listener->su))
741 continue;
742
743 /* If 0.0.0.0/:: is a listener, then treat as self and
744 * reject.
745 */
746 if (!sockunion_cmp(&listener->su, su) ||
747 !sockunion_cmp(&listener->su, &all_su))
748 return true;
749 }
750 }
d62a17ae 751
3dc339cd 752 return false;
718e3744 753}
754
28c6e247
IR
755/* Utility function for looking up peer from VTY. */
756/* This is used only for configuration, so disallow if attempted on
757 * a dynamic neighbor.
758 */
759static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
760{
761 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
762 int ret;
763 union sockunion su;
764 struct peer *peer;
765
766 if (!bgp) {
767 return NULL;
768 }
769
770 ret = str2sockunion(ip_str, &su);
771 if (ret < 0) {
772 peer = peer_lookup_by_conf_if(bgp, ip_str);
773 if (!peer) {
774 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
775 == NULL) {
776 vty_out(vty,
777 "%% Malformed address or name: %s\n",
778 ip_str);
779 return NULL;
780 }
781 }
782 } else {
783 peer = peer_lookup(bgp, &su);
784 if (!peer) {
785 vty_out(vty,
786 "%% Specify remote-as or peer-group commands first\n");
787 return NULL;
788 }
789 if (peer_dynamic_neighbor(peer)) {
790 vty_out(vty,
791 "%% Operation not allowed on a dynamic neighbor\n");
792 return NULL;
793 }
794 }
795 return peer;
796}
797
718e3744 798/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
799/* This is used only for configuration, so disallow if attempted on
800 * a dynamic neighbor.
801 */
d62a17ae 802struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
803{
804 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
805 int ret;
806 union sockunion su;
807 struct peer *peer = NULL;
808 struct peer_group *group = NULL;
809
810 if (!bgp) {
811 return NULL;
812 }
813
814 ret = str2sockunion(peer_str, &su);
815 if (ret == 0) {
816 /* IP address, locate peer. */
817 peer = peer_lookup(bgp, &su);
818 } else {
819 /* Not IP, could match either peer configured on interface or a
820 * group. */
821 peer = peer_lookup_by_conf_if(bgp, peer_str);
822 if (!peer)
823 group = peer_group_lookup(bgp, peer_str);
824 }
825
826 if (peer) {
827 if (peer_dynamic_neighbor(peer)) {
3b56a646
DA
828 zlog_warn(
829 "%pBP: Operation not allowed on a dynamic neighbor",
830 peer);
d62a17ae 831 vty_out(vty,
832 "%% Operation not allowed on a dynamic neighbor\n");
833 return NULL;
834 }
835
836 return peer;
837 }
838
839 if (group)
840 return group->conf;
841
3b56a646
DA
842 zlog_warn("Specify remote-as or peer-group commands first before: %s",
843 vty->buf);
d62a17ae 844 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
845
846 return NULL;
847}
848
4b7e23e9 849int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
d62a17ae 850{
851 const char *str = NULL;
852
853 switch (ret) {
4b7e23e9
DS
854 case BGP_SUCCESS:
855 case BGP_CREATED:
856 case BGP_GR_NO_OPERATION:
857 break;
d62a17ae 858 case BGP_ERR_INVALID_VALUE:
859 str = "Invalid value";
860 break;
861 case BGP_ERR_INVALID_FLAG:
862 str = "Invalid flag";
863 break;
864 case BGP_ERR_PEER_GROUP_SHUTDOWN:
865 str = "Peer-group has been shutdown. Activate the peer-group first";
866 break;
867 case BGP_ERR_PEER_FLAG_CONFLICT:
868 str = "Can't set override-capability and strict-capability-match at the same time";
869 break;
870 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
871 str = "Specify remote-as or peer-group remote AS first";
872 break;
873 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
874 str = "Cannot change the peer-group. Deconfigure first";
875 break;
876 case BGP_ERR_PEER_GROUP_MISMATCH:
877 str = "Peer is not a member of this peer-group";
878 break;
879 case BGP_ERR_PEER_FILTER_CONFLICT:
880 str = "Prefix/distribute list can not co-exist";
881 break;
882 case BGP_ERR_NOT_INTERNAL_PEER:
883 str = "Invalid command. Not an internal neighbor";
884 break;
885 case BGP_ERR_REMOVE_PRIVATE_AS:
886 str = "remove-private-AS cannot be configured for IBGP peers";
887 break;
d62a17ae 888 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
889 str = "Cannot have local-as same as BGP AS number";
890 break;
891 case BGP_ERR_TCPSIG_FAILED:
892 str = "Error while applying TCP-Sig to session(s)";
893 break;
894 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
895 str = "ebgp-multihop and ttl-security cannot be configured together";
896 break;
897 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
898 str = "ttl-security only allowed for EBGP peers";
899 break;
900 case BGP_ERR_AS_OVERRIDE:
901 str = "as-override cannot be configured for IBGP peers";
902 break;
903 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
904 str = "Invalid limit for number of dynamic neighbors";
905 break;
906 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
907 str = "Dynamic neighbor listen range already exists";
908 break;
909 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
910 str = "Operation not allowed on a dynamic neighbor";
911 break;
912 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
913 str = "Operation not allowed on a directly connected neighbor";
914 break;
915 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 916 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
055679e9 917 break;
918 case BGP_ERR_GR_INVALID_CMD:
919 str = "The Graceful Restart command used is not valid at this moment.";
920 break;
921 case BGP_ERR_GR_OPERATION_FAILED:
922 str = "The Graceful Restart Operation failed due to an err.";
923 break;
6dcea6fe
DS
924 case BGP_ERR_PEER_GROUP_MEMBER:
925 str = "Peer-group member cannot override remote-as of peer-group.";
926 break;
927 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
928 str = "Peer-group members must be all internal or all external.";
929 break;
4b7e23e9
DS
930 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
931 str = "Range specified cannot be deleted because it is not part of current config.";
932 break;
933 case BGP_ERR_INSTANCE_MISMATCH:
934 str = "Instance specified does not match the current instance.";
935 break;
936 case BGP_ERR_NO_INTERFACE_CONFIG:
937 str = "Interface specified is not being used for interface based peer.";
938 break;
939 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
940 str = "No configuration already specified for soft reconfiguration.";
941 break;
942 case BGP_ERR_AS_MISMATCH:
943 str = "BGP is already running.";
944 break;
945 case BGP_ERR_AF_UNCONFIGURED:
946 str = "AFI/SAFI specified is not currently configured.";
947 break;
4b7e23e9
DS
948 case BGP_ERR_INVALID_AS:
949 str = "Confederation AS specified is the same AS as our AS.";
950 break;
d864dd9e
EB
951 case BGP_ERR_INVALID_ROLE_NAME:
952 str = "Invalid role name";
953 break;
954 case BGP_ERR_INVALID_INTERNAL_ROLE:
8f2d6021 955 str = "External roles can be set only on eBGP session";
d864dd9e 956 break;
d62a17ae 957 }
958 if (str) {
959 vty_out(vty, "%% %s\n", str);
960 return CMD_WARNING_CONFIG_FAILED;
961 }
962 return CMD_SUCCESS;
718e3744 963}
964
7aafcaca 965/* BGP clear sort. */
d62a17ae 966enum clear_sort {
967 clear_all,
968 clear_peer,
969 clear_group,
970 clear_external,
971 clear_as
7aafcaca
DS
972};
973
1ca2fd11
IR
974static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
975 safi_t safi, int error)
d62a17ae 976{
977 switch (error) {
978 case BGP_ERR_AF_UNCONFIGURED:
a486300b
PG
979 if (vty)
980 vty_out(vty,
981 "%% BGP: Enable %s address family for the neighbor %s\n",
982 get_afi_safi_str(afi, safi, false), peer->host);
983 else
984 zlog_warn(
1af6e82b 985 "%% BGP: Enable %s address family for the neighbor %s",
a486300b 986 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 987 break;
988 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
a486300b
PG
989 if (vty)
990 vty_out(vty,
991 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
992 peer->host);
993 else
994 zlog_warn(
1af6e82b 995 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
a486300b 996 peer->host);
d62a17ae 997 break;
998 default:
999 break;
1000 }
7aafcaca
DS
1001}
1002
dc912615 1003static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 1004 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
1005{
1006 int ret = 0;
2adac256 1007 struct peer_af *paf;
dc912615
DS
1008
1009 /* if afi/.safi not specified, spin thru all of them */
1010 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1011 afi_t tmp_afi;
1012 safi_t tmp_safi;
0e5cdd59
DS
1013 enum bgp_af_index index;
1014
1015 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1016 paf = peer->peer_af_array[index];
1017 if (!paf)
1018 continue;
dc912615 1019
2adac256
DA
1020 if (paf && paf->subgroup)
1021 SET_FLAG(paf->subgroup->sflags,
1022 SUBGRP_STATUS_FORCE_UPDATES);
1023
0e5cdd59
DS
1024 tmp_afi = paf->afi;
1025 tmp_safi = paf->safi;
dc912615
DS
1026 if (!peer->afc[tmp_afi][tmp_safi])
1027 continue;
1028
1029 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1030 ret = peer_clear(peer, nnode);
dc912615
DS
1031 else
1032 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1033 stype);
1034 }
1035 /* if afi specified and safi not, spin thru safis on this afi */
1036 } else if (safi == SAFI_UNSPEC) {
1037 safi_t tmp_safi;
1038
1039 for (tmp_safi = SAFI_UNICAST;
1040 tmp_safi < SAFI_MAX; tmp_safi++) {
1041 if (!peer->afc[afi][tmp_safi])
1042 continue;
1043
2adac256
DA
1044 paf = peer_af_find(peer, afi, tmp_safi);
1045 if (paf && paf->subgroup)
1046 SET_FLAG(paf->subgroup->sflags,
1047 SUBGRP_STATUS_FORCE_UPDATES);
1048
dc912615 1049 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1050 ret = peer_clear(peer, nnode);
dc912615
DS
1051 else
1052 ret = peer_clear_soft(peer, afi,
1053 tmp_safi, stype);
1054 }
1055 /* both afi/safi specified, let the caller know if not defined */
1056 } else {
1057 if (!peer->afc[afi][safi])
1058 return 1;
1059
2adac256
DA
1060 paf = peer_af_find(peer, afi, safi);
1061 if (paf && paf->subgroup)
1062 SET_FLAG(paf->subgroup->sflags,
1063 SUBGRP_STATUS_FORCE_UPDATES);
1064
dc912615 1065 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1066 ret = peer_clear(peer, nnode);
dc912615
DS
1067 else
1068 ret = peer_clear_soft(peer, afi, safi, stype);
1069 }
1070
1071 return ret;
1072}
1073
7aafcaca 1074/* `clear ip bgp' functions. */
1ca2fd11 1075static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 1076 enum clear_sort sort, enum bgp_clear_type stype,
1ca2fd11 1077 const char *arg)
d62a17ae 1078{
dc912615 1079 int ret = 0;
3ae8bfa5 1080 bool found = false;
d62a17ae 1081 struct peer *peer;
dc95985f 1082
1083 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 1084
1085 /* Clear all neighbors. */
1086 /*
1087 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
1088 * nodes on the BGP instance as that may get freed if it is a
1089 * doppelganger
d62a17ae 1090 */
1091 if (sort == clear_all) {
1092 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 1093
1094 bgp_peer_gr_flags_update(peer);
1095
36235319 1096 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 1097 gr_router_detected = true;
1098
c368171c 1099 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 1100 stype);
d62a17ae 1101
1102 if (ret < 0)
1ca2fd11 1103 bgp_clear_vty_error(vty, peer, afi, safi, ret);
dc95985f 1104 }
1105
36235319
QY
1106 if (gr_router_detected
1107 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1108 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1109 } else if (!gr_router_detected
1110 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1111 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 1112 }
d62a17ae 1113
1114 /* This is to apply read-only mode on this clear. */
1115 if (stype == BGP_CLEAR_SOFT_NONE)
1116 bgp->update_delay_over = 0;
1117
1118 return CMD_SUCCESS;
7aafcaca
DS
1119 }
1120
3ae8bfa5 1121 /* Clear specified neighbor. */
d62a17ae 1122 if (sort == clear_peer) {
1123 union sockunion su;
d62a17ae 1124
1125 /* Make sockunion for lookup. */
1126 ret = str2sockunion(arg, &su);
1127 if (ret < 0) {
1128 peer = peer_lookup_by_conf_if(bgp, arg);
1129 if (!peer) {
1130 peer = peer_lookup_by_hostname(bgp, arg);
1131 if (!peer) {
1ca2fd11
IR
1132 vty_out(vty,
1133 "Malformed address or name: %s\n",
d62a17ae 1134 arg);
1135 return CMD_WARNING;
1136 }
1137 }
1138 } else {
1139 peer = peer_lookup(bgp, &su);
1140 if (!peer) {
1ca2fd11 1141 vty_out(vty,
664b6f18 1142 "%% BGP: Unknown neighbor - \"%s\"\n",
1ca2fd11 1143 arg);
d62a17ae 1144 return CMD_WARNING;
1145 }
1146 }
7aafcaca 1147
dc95985f 1148 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1149 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1150
dc912615
DS
1151 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1152
1153 /* if afi/safi not defined for this peer, let caller know */
1154 if (ret == 1)
3ae8bfa5 1155 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1156
d62a17ae 1157 if (ret < 0)
1ca2fd11 1158 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 1159
d62a17ae 1160 return CMD_SUCCESS;
7aafcaca 1161 }
7aafcaca 1162
3ae8bfa5 1163 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1164 if (sort == clear_group) {
1165 struct peer_group *group;
7aafcaca 1166
d62a17ae 1167 group = peer_group_lookup(bgp, arg);
1168 if (!group) {
664b6f18 1169 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
d62a17ae 1170 return CMD_WARNING;
1171 }
1172
1173 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1174 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1175
d62a17ae 1176 if (ret < 0)
1ca2fd11 1177 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1178 else
1179 found = true;
d62a17ae 1180 }
3ae8bfa5
PM
1181
1182 if (!found)
1ca2fd11 1183 vty_out(vty,
664b6f18 1184 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 1185 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1186
d62a17ae 1187 return CMD_SUCCESS;
7aafcaca 1188 }
7aafcaca 1189
3ae8bfa5 1190 /* Clear all external (eBGP) neighbors. */
d62a17ae 1191 if (sort == clear_external) {
1192 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1193 if (peer->sort == BGP_PEER_IBGP)
1194 continue;
7aafcaca 1195
dc95985f 1196 bgp_peer_gr_flags_update(peer);
1197
36235319 1198 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1199 gr_router_detected = true;
dc95985f 1200
c368171c 1201 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1202
d62a17ae 1203 if (ret < 0)
1ca2fd11 1204 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1205 else
1206 found = true;
d62a17ae 1207 }
3ae8bfa5 1208
36235319
QY
1209 if (gr_router_detected
1210 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1211 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1212 } else if (!gr_router_detected
1213 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1214 bgp_zebra_send_capabilities(bgp, true);
1215 }
1216
3ae8bfa5 1217 if (!found)
1ca2fd11 1218 vty_out(vty,
664b6f18 1219 "%% BGP: No external %s peer is configured\n",
1ca2fd11 1220 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1221
d62a17ae 1222 return CMD_SUCCESS;
1223 }
1224
3ae8bfa5 1225 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1226 if (sort == clear_as) {
8079a413
PG
1227 as_t as;
1228
1229 if (!asn_str2asn(arg, &as)) {
1230 vty_out(vty, "%% BGP: No such AS %s\n", arg);
1231 return CMD_WARNING;
1232 }
d62a17ae 1233
1234 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1235 if (peer->as != as)
1236 continue;
1237
dc95985f 1238 bgp_peer_gr_flags_update(peer);
1239
36235319 1240 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1241 gr_router_detected = true;
dc95985f 1242
c368171c 1243 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1244
1245 if (ret < 0)
1ca2fd11 1246 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1247 else
1248 found = true;
d62a17ae 1249 }
3ae8bfa5 1250
36235319
QY
1251 if (gr_router_detected
1252 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1253 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1254 } else if (!gr_router_detected
1255 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1256 bgp_zebra_send_capabilities(bgp, true);
1257 }
1258
3ae8bfa5 1259 if (!found)
1ca2fd11 1260 vty_out(vty,
664b6f18 1261 "%% BGP: No %s peer is configured with AS %s\n",
1ca2fd11 1262 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1263
d62a17ae 1264 return CMD_SUCCESS;
1265 }
1266
1267 return CMD_SUCCESS;
1268}
1269
1ca2fd11
IR
1270static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1271 safi_t safi, enum clear_sort sort,
1272 enum bgp_clear_type stype, const char *arg)
d62a17ae 1273{
1274 struct bgp *bgp;
1275
1276 /* BGP structure lookup. */
1277 if (name) {
1278 bgp = bgp_lookup_by_name(name);
1279 if (bgp == NULL) {
1ca2fd11 1280 vty_out(vty, "Can't find BGP instance %s\n", name);
d62a17ae 1281 return CMD_WARNING;
1282 }
1283 } else {
1284 bgp = bgp_get_default();
1285 if (bgp == NULL) {
1ca2fd11 1286 vty_out(vty, "No BGP process is configured\n");
d62a17ae 1287 return CMD_WARNING;
1288 }
1289 }
1290
1ca2fd11 1291 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
1292}
1293
1294/* clear soft inbound */
1ca2fd11 1295static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 1296{
99b3ebd3
NS
1297 afi_t afi;
1298 safi_t safi;
1299
1ca2fd11
IR
1300 FOREACH_AFI_SAFI (afi, safi)
1301 bgp_clear_vty(vty, name, afi, safi, clear_all,
1302 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
1303}
1304
1305/* clear soft outbound */
1ca2fd11 1306static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 1307{
99b3ebd3
NS
1308 afi_t afi;
1309 safi_t safi;
1310
1ca2fd11
IR
1311 FOREACH_AFI_SAFI (afi, safi)
1312 bgp_clear_vty(vty, name, afi, safi, clear_all,
1313 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
1314}
1315
1316
a486300b
PG
1317void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1318{
1319 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1320}
1321
4f770cf1
DA
1322static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
1323 uint64_t flag, int set)
1324{
1325 int ret;
1326 struct peer *peer;
1327
1328 peer = peer_and_group_lookup_vty(vty, ip_str);
1329 if (!peer)
1330 return CMD_WARNING_CONFIG_FAILED;
1331
1332 /*
1333 * If 'neighbor <interface>', then this is for directly connected peers,
1334 * we should not accept disable-connected-check.
1335 */
1336 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
1337 vty_out(vty,
1338 "%s is directly connected peer, cannot accept disable-connected-check\n",
1339 ip_str);
1340 return CMD_WARNING_CONFIG_FAILED;
1341 }
1342
1343 if (!set && flag == PEER_FLAG_SHUTDOWN)
1344 peer_tx_shutdown_message_unset(peer);
1345
1346 if (set)
1347 ret = peer_flag_set(peer, flag);
1348 else
1349 ret = peer_flag_unset(peer, flag);
1350
1351 return bgp_vty_return(vty, ret);
1352}
1353
1354static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
1355{
1356 return peer_flag_modify_vty(vty, ip_str, flag, 1);
1357}
1358
1359static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
1360 uint64_t flag)
1361{
1362 return peer_flag_modify_vty(vty, ip_str, flag, 0);
1363}
1364
2e4c2296 1365#include "bgpd/bgp_vty_clippy.c"
f787d7a0 1366
8029b216
AK
1367DEFUN_HIDDEN (bgp_local_mac,
1368 bgp_local_mac_cmd,
093e3f23 1369 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
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 "mac-mobility sequence\n"
1377 "seq number\n")
1378{
1379 int rv;
1380 vni_t vni;
1381 struct ethaddr mac;
1382 struct ipaddr ip;
1383 uint32_t seq;
1384 struct bgp *bgp;
1385
1386 vni = strtoul(argv[3]->arg, NULL, 10);
1387 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1388 vty_out(vty, "%% Malformed MAC address\n");
1389 return CMD_WARNING;
1390 }
1391 memset(&ip, 0, sizeof(ip));
1392 seq = strtoul(argv[7]->arg, NULL, 10);
1393
1394 bgp = bgp_get_default();
1395 if (!bgp) {
1396 vty_out(vty, "Default BGP instance is not there\n");
1397 return CMD_WARNING;
1398 }
1399
b5e140c8
AK
1400 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1401 zero_esi);
8029b216
AK
1402 if (rv < 0) {
1403 vty_out(vty, "Internal error\n");
1404 return CMD_WARNING;
1405 }
1406
1407 return CMD_SUCCESS;
1408}
1409
1410DEFUN_HIDDEN (no_bgp_local_mac,
1411 no_bgp_local_mac_cmd,
093e3f23 1412 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1413 NO_STR
1414 BGP_STR
1415 "Local MAC config\n"
1416 "VxLAN Network Identifier\n"
1417 "VNI number\n"
1418 "local mac\n"
1419 "mac address\n")
1420{
1421 int rv;
1422 vni_t vni;
1423 struct ethaddr mac;
1424 struct ipaddr ip;
1425 struct bgp *bgp;
1426
1427 vni = strtoul(argv[4]->arg, NULL, 10);
1428 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1429 vty_out(vty, "%% Malformed MAC address\n");
1430 return CMD_WARNING;
1431 }
1432 memset(&ip, 0, sizeof(ip));
1433
1434 bgp = bgp_get_default();
1435 if (!bgp) {
1436 vty_out(vty, "Default BGP instance is not there\n");
1437 return CMD_WARNING;
1438 }
1439
ec0ab544 1440 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1441 if (rv < 0) {
1442 vty_out(vty, "Internal error\n");
1443 return CMD_WARNING;
1444 }
1445
1446 return CMD_SUCCESS;
1447}
1448
718e3744 1449DEFUN (no_synchronization,
1450 no_synchronization_cmd,
1451 "no synchronization",
1452 NO_STR
1453 "Perform IGP synchronization\n")
1454{
d62a17ae 1455 return CMD_SUCCESS;
718e3744 1456}
1457
1458DEFUN (no_auto_summary,
1459 no_auto_summary_cmd,
1460 "no auto-summary",
1461 NO_STR
1462 "Enable automatic network number summarization\n")
1463{
d62a17ae 1464 return CMD_SUCCESS;
718e3744 1465}
3d515fd9 1466
718e3744 1467/* "router bgp" commands. */
1ca2fd11
IR
1468DEFUN_NOSH (router_bgp,
1469 router_bgp_cmd,
e55b0883 1470 "router bgp [ASNUM$instasn [<view|vrf> VIEWVRFNAME] [as-notation <dot|dot+|plain>]]",
1ca2fd11
IR
1471 ROUTER_STR
1472 BGP_STR
1473 AS_STR
e55b0883
PG
1474 BGP_INSTANCE_HELP_STR
1475 "Force the AS notation output\n"
1476 "use 'AA.BB' format for AS 4 byte values\n"
1477 "use 'AA.BB' format for all AS values\n"
1478 "use plain format for all AS values\n")
718e3744 1479{
d62a17ae 1480 int idx_asn = 2;
1481 int idx_view_vrf = 3;
1482 int idx_vrf = 4;
1ca2fd11 1483 int is_new_bgp = 0;
e55b0883
PG
1484 int idx_asnotation = 3;
1485 int idx_asnotation_kind = 4;
1486 enum asnotation_mode asnotation = ASNOTATION_UNDEFINED;
1ca2fd11 1487 int ret;
d62a17ae 1488 as_t as;
1489 struct bgp *bgp;
1490 const char *name = NULL;
1491 enum bgp_instance_type inst_type;
1492
1493 // "router bgp" without an ASN
1494 if (argc == 2) {
1495 // Pending: Make VRF option available for ASN less config
1abef40f 1496 bgp = bgp_get_default();
d62a17ae 1497
1abef40f 1498 if (bgp == NULL) {
d62a17ae 1499 vty_out(vty, "%% No BGP process is configured\n");
1500 return CMD_WARNING_CONFIG_FAILED;
1501 }
1502
1503 if (listcount(bm->bgp) > 1) {
996c9314 1504 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1505 return CMD_WARNING_CONFIG_FAILED;
1506 }
1507 }
1508
1509 // "router bgp X"
1510 else {
8079a413
PG
1511 if (!asn_str2asn(argv[idx_asn]->arg, &as)) {
1512 vty_out(vty, "%% BGP: No such AS %s\n",
1513 argv[idx_asn]->arg);
1514 return CMD_WARNING_CONFIG_FAILED;
1515 }
1ca2fd11 1516
cc413e2a
DA
1517 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1518 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1519 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1520
d62a17ae 1521 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
d62a17ae 1522
e55b0883
PG
1523 if (argv_find(argv, argc, "VIEWVRFNAME", &idx_vrf)) {
1524 idx_view_vrf = idx_vrf - 1;
1525 if (argv[idx_view_vrf]->text) {
1526 name = argv[idx_vrf]->arg;
1527
1528 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1529 if (strmatch(name, VRF_DEFAULT_NAME))
1530 name = NULL;
1531 else
1532 inst_type =
1533 BGP_INSTANCE_TYPE_VRF;
1534 } else if (!strcmp(argv[idx_view_vrf]->text,
1535 "view"))
1536 inst_type = BGP_INSTANCE_TYPE_VIEW;
1537 }
1538 }
1539 if (argv_find(argv, argc, "as-notation", &idx_asnotation)) {
1540 idx_asnotation_kind = idx_asnotation + 1;
1541 if (strmatch(argv[idx_asnotation_kind]->text, "dot+"))
1542 asnotation = ASNOTATION_DOTPLUS;
1543 else if (strmatch(argv[idx_asnotation_kind]->text,
1544 "dot"))
1545 asnotation = ASNOTATION_DOT;
1546 else if (strmatch(argv[idx_asnotation_kind]->text,
1547 "plain"))
1548 asnotation = ASNOTATION_PLAIN;
d62a17ae 1549 }
1550
1ca2fd11
IR
1551 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1552 is_new_bgp = (bgp_lookup(as, name) == NULL);
3bd70bf8 1553
9eb11997 1554 ret = bgp_get_vty(&bgp, &as, name, inst_type,
e55b0883 1555 argv[idx_asn]->arg, asnotation);
1ca2fd11
IR
1556 switch (ret) {
1557 case BGP_ERR_AS_MISMATCH:
9eb11997
PG
1558 vty_out(vty, "BGP is already running; AS is %s\n",
1559 bgp->as_pretty);
1ca2fd11
IR
1560 return CMD_WARNING_CONFIG_FAILED;
1561 case BGP_ERR_INSTANCE_MISMATCH:
1562 vty_out(vty,
1563 "BGP instance name and AS number mismatch\n");
1564 vty_out(vty,
9eb11997
PG
1565 "BGP instance is already running; AS is %s\n",
1566 bgp->as_pretty);
1ca2fd11 1567 return CMD_WARNING_CONFIG_FAILED;
ff8a8a7a 1568 }
1ca2fd11
IR
1569
1570 /*
1571 * If we just instantiated the default instance, complete
1572 * any pending VRF-VPN leaking that was configured via
1573 * earlier "router bgp X vrf FOO" blocks.
1574 */
1575 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1576 vpn_leak_postchange_all();
1577
1578 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1579 bgp_vpn_leak_export(bgp);
1580 /* Pending: handle when user tries to change a view to vrf n vv.
1581 */
e55b0883
PG
1582 /* for pre-existing bgp instance,
1583 * - update as_pretty
1584 * - update asnotation if explicitly mentioned
1585 */
1586 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO)) {
1587 XFREE(MTYPE_BGP, bgp->as_pretty);
1588 bgp->as_pretty = XSTRDUP(MTYPE_BGP, argv[idx_asn]->arg);
1589 if (!CHECK_FLAG(bgp->config, BGP_CONFIG_ASNOTATION) &&
1590 asnotation != ASNOTATION_UNDEFINED) {
1591 SET_FLAG(bgp->config, BGP_CONFIG_ASNOTATION);
1592 bgp->asnotation = asnotation;
1593 }
1594 }
d62a17ae 1595 }
1596
1ca2fd11
IR
1597 /* unset the auto created flag as the user config is now present */
1598 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1599 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1600
1601 return CMD_SUCCESS;
718e3744 1602}
1603
718e3744 1604/* "no router bgp" commands. */
1ca2fd11
IR
1605DEFUN (no_router_bgp,
1606 no_router_bgp_cmd,
e55b0883 1607 "no router bgp [ASNUM$instasn [<view|vrf> VIEWVRFNAME] [as-notation <dot|dot+|plain>]]",
1ca2fd11
IR
1608 NO_STR
1609 ROUTER_STR
1610 BGP_STR
1611 AS_STR
e55b0883
PG
1612 BGP_INSTANCE_HELP_STR
1613 "Force the AS notation output\n"
1614 "use 'AA.BB' format for AS 4 byte values\n"
1615 "use 'AA.BB' format for all AS values\n"
1616 "use plain format for all AS values\n")
718e3744 1617{
4fd9919e 1618 int idx_asn = 3;
d62a17ae 1619 int idx_vrf = 5;
1ca2fd11 1620 as_t as;
4fd9919e 1621 struct bgp *bgp;
d62a17ae 1622 const char *name = NULL;
718e3744 1623
d62a17ae 1624 // "no router bgp" without an ASN
1625 if (argc == 3) {
1626 // Pending: Make VRF option available for ASN less config
8382083a 1627 bgp = bgp_get_default();
718e3744 1628
8382083a 1629 if (bgp == NULL) {
d62a17ae 1630 vty_out(vty, "%% No BGP process is configured\n");
1631 return CMD_WARNING_CONFIG_FAILED;
1632 }
7fb21a9f 1633
d62a17ae 1634 if (listcount(bm->bgp) > 1) {
996c9314 1635 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1636 return CMD_WARNING_CONFIG_FAILED;
1637 }
4fd9919e 1638
4fd9919e 1639 if (bgp->l3vni) {
be125e6f 1640 vty_out(vty, "%% Please unconfigure l3vni %u\n",
4fd9919e
IR
1641 bgp->l3vni);
1642 return CMD_WARNING_CONFIG_FAILED;
1643 }
d62a17ae 1644 } else {
8079a413
PG
1645 if (!asn_str2asn(argv[idx_asn]->arg, &as)) {
1646 vty_out(vty, "%% BGP: No such AS %s\n",
1647 argv[idx_asn]->arg);
1648 return CMD_WARNING_CONFIG_FAILED;
1649 }
1ca42c8d 1650 if (argc > 4) {
d62a17ae 1651 name = argv[idx_vrf]->arg;
1ca42c8d
IR
1652 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1653 && strmatch(name, VRF_DEFAULT_NAME))
1654 name = NULL;
1655 }
7fb21a9f 1656
4fd9919e
IR
1657 /* Lookup bgp structure. */
1658 bgp = bgp_lookup(as, name);
1659 if (!bgp) {
1660 vty_out(vty, "%% Can't find BGP instance\n");
1661 return CMD_WARNING_CONFIG_FAILED;
1662 }
1663
1664 if (bgp->l3vni) {
1665 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1666 bgp->l3vni);
1667 return CMD_WARNING_CONFIG_FAILED;
1668 }
1669
1670 /* Cannot delete default instance if vrf instances exist */
1671 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1672 struct listnode *node;
1673 struct bgp *tmp_bgp;
1674
1675 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1676 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1677 continue;
746e0522
DS
1678 if (CHECK_FLAG(
1679 tmp_bgp->af_flags[AFI_IP]
1680 [SAFI_UNICAST],
1681 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1682 CHECK_FLAG(
1683 tmp_bgp->af_flags[AFI_IP6]
1684 [SAFI_UNICAST],
1685 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1686 CHECK_FLAG(
1687 tmp_bgp->af_flags[AFI_IP]
1688 [SAFI_UNICAST],
1689 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1690 CHECK_FLAG(
1691 tmp_bgp->af_flags[AFI_IP6]
1692 [SAFI_UNICAST],
1693 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1694 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP]
1695 [SAFI_UNICAST],
4fd9919e 1696 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
746e0522
DS
1697 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6]
1698 [SAFI_UNICAST],
4fd9919e
IR
1699 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1700 (bgp == bgp_get_evpn() &&
746e0522
DS
1701 (CHECK_FLAG(
1702 tmp_bgp->af_flags[AFI_L2VPN]
1703 [SAFI_EVPN],
1704 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1705 CHECK_FLAG(
1706 tmp_bgp->af_flags[AFI_L2VPN]
1707 [SAFI_EVPN],
1708 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1709 CHECK_FLAG(
1710 tmp_bgp->af_flags[AFI_L2VPN]
1711 [SAFI_EVPN],
1712 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1713 CHECK_FLAG(
1714 tmp_bgp->af_flags[AFI_L2VPN]
1715 [SAFI_EVPN],
1716 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1717 (tmp_bgp->l3vni)) {
4fd9919e
IR
1718 vty_out(vty,
1719 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1720 return CMD_WARNING_CONFIG_FAILED;
1721 }
1722 }
1723 }
d62a17ae 1724 }
718e3744 1725
1ca2fd11 1726 bgp_delete(bgp);
718e3744 1727
1ca2fd11 1728 return CMD_SUCCESS;
718e3744 1729}
1730
425bd64b
PS
1731/* bgp session-dscp */
1732
1733DEFPY (bgp_session_dscp,
1734 bgp_session_dscp_cmd,
1735 "bgp session-dscp (0-63)$dscp",
1736 BGP_STR
1737 "Override default (C6) bgp TCP session DSCP value\n"
1738 "Manually configured dscp parameter\n")
1739{
1740 bm->tcp_dscp = dscp << 2;
1741
1742 return CMD_SUCCESS;
1743}
1744
1745DEFPY (no_bgp_session_dscp,
1746 no_bgp_session_dscp_cmd,
1747 "no bgp session-dscp [(0-63)]",
1748 NO_STR
1749 BGP_STR
1750 "Override default (C6) bgp TCP session DSCP value\n"
1751 "Manually configured dscp parameter\n")
1752{
1753 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1754
1755 return CMD_SUCCESS;
1756}
718e3744 1757
ff8a8a7a
CS
1758/* BGP router-id. */
1759
1ca2fd11
IR
1760DEFPY (bgp_router_id,
1761 bgp_router_id_cmd,
1762 "bgp router-id A.B.C.D",
1763 BGP_STR
1764 "Override configured router identifier\n"
1765 "Manually configured router identifier\n")
718e3744 1766{
1ca2fd11
IR
1767 VTY_DECLVAR_CONTEXT(bgp, bgp);
1768 bgp_router_id_static_set(bgp, router_id);
1769 return CMD_SUCCESS;
ff8a8a7a 1770}
718e3744 1771
1ca2fd11
IR
1772DEFPY (no_bgp_router_id,
1773 no_bgp_router_id_cmd,
1774 "no bgp router-id [A.B.C.D]",
1775 NO_STR
1776 BGP_STR
1777 "Override configured router identifier\n"
1778 "Manually configured router identifier\n")
ff8a8a7a 1779{
1ca2fd11 1780 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1781
1ca2fd11
IR
1782 if (router_id_str) {
1783 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1784 vty_out(vty, "%% BGP router-id doesn't match\n");
1785 return CMD_WARNING_CONFIG_FAILED;
1786 }
1787 }
718e3744 1788
1ca2fd11
IR
1789 router_id.s_addr = 0;
1790 bgp_router_id_static_set(bgp, router_id);
1791
1792 return CMD_SUCCESS;
ff8a8a7a 1793}
6b0655a2 1794
ed0e57e3 1795DEFPY(bgp_community_alias, bgp_community_alias_cmd,
b4ad2fae 1796 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
ed0e57e3
DA
1797 NO_STR BGP_STR
1798 "Add community specific parameters\n"
1799 "Create an alias for a community\n"
1800 "Community (AA:BB or AA:BB:CC)\n"
1801 "Alias name\n")
1802{
8cfa1e78 1803 struct community_alias ca = {};
ed0e57e3
DA
1804 struct community_alias *lookup_community;
1805 struct community_alias *lookup_alias;
d13d137a
DA
1806 struct community *comm;
1807 struct lcommunity *lcomm;
1808 uint8_t invalid = 0;
ed0e57e3 1809
d13d137a
DA
1810 comm = community_str2com(community);
1811 if (!comm)
1812 invalid++;
1813 community_free(&comm);
1814
1815 lcomm = lcommunity_str2com(community);
1816 if (!lcomm)
1817 invalid++;
1818 lcommunity_free(&lcomm);
1819
1820 if (invalid > 1) {
ed0e57e3
DA
1821 vty_out(vty, "Invalid community format\n");
1822 return CMD_WARNING;
1823 }
1824
8cfa1e78
DA
1825 strlcpy(ca.community, community, sizeof(ca.community));
1826 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
ed0e57e3 1827
8cfa1e78
DA
1828 lookup_community = bgp_ca_community_lookup(&ca);
1829 lookup_alias = bgp_ca_alias_lookup(&ca);
ed0e57e3
DA
1830
1831 if (no) {
8cfa1e78
DA
1832 bgp_ca_alias_delete(&ca);
1833 bgp_ca_community_delete(&ca);
ed0e57e3
DA
1834 } else {
1835 if (lookup_alias) {
1836 /* Lookup if community hash table has an item
1837 * with the same alias name.
1838 */
8cfa1e78
DA
1839 strlcpy(ca.community, lookup_alias->community,
1840 sizeof(ca.community));
1841 if (bgp_ca_community_lookup(&ca)) {
ed0e57e3
DA
1842 vty_out(vty,
1843 "community (%s) already has this alias (%s)\n",
1844 lookup_alias->community,
1845 lookup_alias->alias);
1846 return CMD_WARNING;
1847 }
8cfa1e78 1848 bgp_ca_alias_delete(&ca);
ed0e57e3
DA
1849 }
1850
8cfa1e78
DA
1851 if (lookup_community) {
1852 /* Lookup if alias hash table has an item
1853 * with the same community.
1854 */
1855 strlcpy(ca.alias, lookup_community->alias,
1856 sizeof(ca.alias));
1857 if (bgp_ca_alias_lookup(&ca)) {
1858 vty_out(vty,
1859 "alias (%s) already has this community (%s)\n",
1860 lookup_community->alias,
1861 lookup_community->community);
1862 return CMD_WARNING;
1863 }
1864 bgp_ca_community_delete(&ca);
1865 }
ed0e57e3 1866
8cfa1e78
DA
1867 bgp_ca_alias_insert(&ca);
1868 bgp_ca_community_insert(&ca);
ed0e57e3
DA
1869 }
1870
1871 return CMD_SUCCESS;
1872}
1873
9acb67cb
DS
1874DEFPY (bgp_global_suppress_fib_pending,
1875 bgp_global_suppress_fib_pending_cmd,
1876 "[no] bgp suppress-fib-pending",
1877 NO_STR
1878 BGP_STR
1879 "Advertise only routes that are programmed in kernel to peers globally\n")
1880{
1881 bm_wait_for_fib_set(!no);
1882
1883 return CMD_SUCCESS;
1884}
1885
c208c586
S
1886DEFPY (bgp_suppress_fib_pending,
1887 bgp_suppress_fib_pending_cmd,
1888 "[no] bgp suppress-fib-pending",
1889 NO_STR
1890 BGP_STR
1891 "Advertise only routes that are programmed in kernel to peers\n")
1892{
1893 VTY_DECLVAR_CONTEXT(bgp, bgp);
1894
1895 bgp_suppress_fib_pending_set(bgp, !no);
1896 return CMD_SUCCESS;
1897}
1898
718e3744 1899/* BGP Cluster ID. */
1ca2fd11
IR
1900DEFUN (bgp_cluster_id,
1901 bgp_cluster_id_cmd,
1902 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1903 BGP_STR
1904 "Configure Route-Reflector Cluster-id\n"
1905 "Route-Reflector Cluster-id in IP address format\n"
1906 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1907{
1ca2fd11 1908 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1909 int idx_ipv4 = 2;
1ca2fd11
IR
1910 int ret;
1911 struct in_addr cluster;
1912
1913 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1914 if (!ret) {
1915 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1916 return CMD_WARNING_CONFIG_FAILED;
1917 }
718e3744 1918
1ca2fd11
IR
1919 bgp_cluster_id_set(bgp, &cluster);
1920 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1921
1ca2fd11 1922 return CMD_SUCCESS;
718e3744 1923}
1924
1ca2fd11
IR
1925DEFUN (no_bgp_cluster_id,
1926 no_bgp_cluster_id_cmd,
1927 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1928 NO_STR
1929 BGP_STR
1930 "Configure Route-Reflector Cluster-id\n"
1931 "Route-Reflector Cluster-id in IP address format\n"
1932 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1933{
1ca2fd11
IR
1934 VTY_DECLVAR_CONTEXT(bgp, bgp);
1935 bgp_cluster_id_unset(bgp);
1936 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1937
1ca2fd11 1938 return CMD_SUCCESS;
718e3744 1939}
1940
c163f297
DS
1941DEFPY (bgp_norib,
1942 bgp_norib_cmd,
1943 "bgp no-rib",
1944 BGP_STR
1945 "Disable BGP route installation to RIB (Zebra)\n")
1946{
1947 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1948 vty_out(vty,
1949 "%% No-RIB option is already set, nothing to do here.\n");
1950 return CMD_SUCCESS;
1951 }
1952
1953 bgp_option_norib_set_runtime();
1954
1955 return CMD_SUCCESS;
1956}
1957
1958DEFPY (no_bgp_norib,
1959 no_bgp_norib_cmd,
1960 "no bgp no-rib",
1961 NO_STR
1962 BGP_STR
1963 "Disable BGP route installation to RIB (Zebra)\n")
1964{
1965 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1966 vty_out(vty,
1967 "%% No-RIB option is not set, nothing to do here.\n");
1968 return CMD_SUCCESS;
1969 }
1970
1971 bgp_option_norib_unset_runtime();
1972
1973 return CMD_SUCCESS;
1974}
1975
e46723a5
DS
1976DEFPY (no_bgp_send_extra_data,
1977 no_bgp_send_extra_data_cmd,
1978 "[no] bgp send-extra-data zebra",
1979 NO_STR
1980 BGP_STR
1981 "Extra data to Zebra for display/use\n"
1982 "To zebra\n")
1983{
ec0acb80
DA
1984 if (no)
1985 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1986 else
1987 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1988
1989 return CMD_SUCCESS;
1990}
1991
1ca2fd11
IR
1992DEFUN (bgp_confederation_identifier,
1993 bgp_confederation_identifier_cmd,
8079a413 1994 "bgp confederation identifier ASNUM",
e9273987 1995 BGP_STR
1ca2fd11 1996 "AS confederation parameters\n"
8079a413 1997 AS_STR
1ca2fd11 1998 "Set routing domain confederation AS\n")
718e3744 1999{
1ca2fd11 2000 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2001 int idx_number = 3;
1ca2fd11 2002 as_t as;
718e3744 2003
8079a413
PG
2004 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
2005 vty_out(vty, "%% BGP: No such AS %s\n", argv[idx_number]->arg);
2006 return CMD_WARNING_CONFIG_FAILED;
2007 }
718e3744 2008
7e14d0fa 2009 bgp_confederation_id_set(bgp, as, argv[idx_number]->arg);
718e3744 2010
1ca2fd11 2011 return CMD_SUCCESS;
718e3744 2012}
2013
1ca2fd11
IR
2014DEFUN (no_bgp_confederation_identifier,
2015 no_bgp_confederation_identifier_cmd,
8079a413 2016 "no bgp confederation identifier [ASNUM]",
1ca2fd11 2017 NO_STR
e9273987 2018 BGP_STR
1ca2fd11 2019 "AS confederation parameters\n"
8079a413 2020 AS_STR
1ca2fd11 2021 "Set routing domain confederation AS\n")
ff8a8a7a 2022{
1ca2fd11
IR
2023 VTY_DECLVAR_CONTEXT(bgp, bgp);
2024 bgp_confederation_id_unset(bgp);
2025
2026 return CMD_SUCCESS;
ff8a8a7a
CS
2027}
2028
1ca2fd11
IR
2029DEFUN (bgp_confederation_peers,
2030 bgp_confederation_peers_cmd,
8079a413 2031 "bgp confederation peers ASNUM...",
e9273987 2032 BGP_STR
1ca2fd11
IR
2033 "AS confederation parameters\n"
2034 "Peer ASs in BGP confederation\n"
2035 AS_STR)
718e3744 2036{
1ca2fd11 2037 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2038 int idx_asn = 3;
1ca2fd11 2039 as_t as;
d62a17ae 2040 int i;
718e3744 2041
1ca2fd11 2042 for (i = idx_asn; i < argc; i++) {
8079a413
PG
2043 if (!asn_str2asn(argv[i]->arg, &as)) {
2044 vty_out(vty, "%% Invalid confed peer AS value: %s\n",
2045 argv[i]->arg);
2046 continue;
2047 }
2048
7e14d0fa 2049 bgp_confederation_peers_add(bgp, as, argv[i]->arg);
1ca2fd11
IR
2050 }
2051 return CMD_SUCCESS;
718e3744 2052}
2053
1ca2fd11
IR
2054DEFUN (no_bgp_confederation_peers,
2055 no_bgp_confederation_peers_cmd,
8079a413 2056 "no bgp confederation peers ASNUM...",
1ca2fd11 2057 NO_STR
e9273987 2058 BGP_STR
1ca2fd11
IR
2059 "AS confederation parameters\n"
2060 "Peer ASs in BGP confederation\n"
2061 AS_STR)
718e3744 2062{
1ca2fd11 2063 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2064 int idx_asn = 4;
1ca2fd11 2065 as_t as;
d62a17ae 2066 int i;
718e3744 2067
1ca2fd11 2068 for (i = idx_asn; i < argc; i++) {
8079a413
PG
2069 if (!asn_str2asn(argv[i]->arg, &as)) {
2070 vty_out(vty, "%% Invalid confed peer AS value: %s\n",
2071 argv[i]->arg);
2072 continue;
2073 }
1ca2fd11
IR
2074 bgp_confederation_peers_remove(bgp, as);
2075 }
2076 return CMD_SUCCESS;
718e3744 2077}
6b0655a2 2078
5e242b0d
DS
2079/**
2080 * Central routine for maximum-paths configuration.
2081 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
2082 * @set: 1 for setting values, 0 for removing the max-paths config.
2083 */
585f1adc
IR
2084static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
2085 const char *mpaths, uint16_t options,
2086 int set)
d62a17ae 2087{
585f1adc
IR
2088 VTY_DECLVAR_CONTEXT(bgp, bgp);
2089 uint16_t maxpaths = 0;
d62a17ae 2090 int ret;
585f1adc
IR
2091 afi_t afi;
2092 safi_t safi;
2093
2094 afi = bgp_node_afi(vty);
2095 safi = bgp_node_safi(vty);
d62a17ae 2096
2097 if (set) {
585f1adc 2098 maxpaths = strtol(mpaths, NULL, 10);
d62a17ae 2099 if (maxpaths > multipath_num) {
585f1adc 2100 vty_out(vty,
d62a17ae 2101 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
2102 maxpaths, multipath_num);
2103 return CMD_WARNING_CONFIG_FAILED;
2104 }
2105 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
2106 options);
2107 } else
2108 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
2109
2110 if (ret < 0) {
585f1adc 2111 vty_out(vty,
d62a17ae 2112 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
2113 (set == 1) ? "" : "un",
2114 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
2115 maxpaths, afi, safi);
2116 return CMD_WARNING_CONFIG_FAILED;
2117 }
2118
2119 bgp_recalculate_all_bestpaths(bgp);
2120
2121 return CMD_SUCCESS;
165b5fff
JB
2122}
2123
1ca2fd11
IR
2124DEFUN (bgp_maxmed_admin,
2125 bgp_maxmed_admin_cmd,
2126 "bgp max-med administrative ",
2127 BGP_STR
2128 "Advertise routes with max-med\n"
2129 "Administratively applied, for an indefinite period\n")
abc920f8 2130{
1ca2fd11 2131 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 2132
1ca2fd11
IR
2133 bgp->v_maxmed_admin = 1;
2134 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
ff8a8a7a 2135
1ca2fd11 2136 bgp_maxmed_update(bgp);
abc920f8 2137
1ca2fd11 2138 return CMD_SUCCESS;
ff8a8a7a
CS
2139}
2140
1ca2fd11
IR
2141DEFUN (bgp_maxmed_admin_medv,
2142 bgp_maxmed_admin_medv_cmd,
2143 "bgp max-med administrative (0-4294967295)",
2144 BGP_STR
2145 "Advertise routes with max-med\n"
2146 "Administratively applied, for an indefinite period\n"
2147 "Max MED value to be used\n")
abc920f8 2148{
1ca2fd11 2149 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2150 int idx_number = 3;
abc920f8 2151
1ca2fd11
IR
2152 bgp->v_maxmed_admin = 1;
2153 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 2154
1ca2fd11 2155 bgp_maxmed_update(bgp);
abc920f8 2156
1ca2fd11 2157 return CMD_SUCCESS;
abc920f8
DS
2158}
2159
1ca2fd11
IR
2160DEFUN (no_bgp_maxmed_admin,
2161 no_bgp_maxmed_admin_cmd,
2162 "no bgp max-med administrative [(0-4294967295)]",
2163 NO_STR
2164 BGP_STR
2165 "Advertise routes with max-med\n"
2166 "Administratively applied, for an indefinite period\n"
2167 "Max MED value to be used\n")
abc920f8 2168{
1ca2fd11
IR
2169 VTY_DECLVAR_CONTEXT(bgp, bgp);
2170 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2171 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2172 bgp_maxmed_update(bgp);
ff8a8a7a 2173
1ca2fd11 2174 return CMD_SUCCESS;
abc920f8
DS
2175}
2176
1ca2fd11
IR
2177DEFUN (bgp_maxmed_onstartup,
2178 bgp_maxmed_onstartup_cmd,
2179 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2180 BGP_STR
2181 "Advertise routes with max-med\n"
2182 "Effective on a startup\n"
2183 "Time (seconds) period for max-med\n"
2184 "Max MED value to be used\n")
abc920f8 2185{
1ca2fd11 2186 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2187 int idx = 0;
4668a151 2188
9b01d289
DA
2189 if (argv_find(argv, argc, "(5-86400)", &idx))
2190 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 2191 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1ca2fd11 2192 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 2193 else
1ca2fd11 2194 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 2195
1ca2fd11
IR
2196 bgp_maxmed_update(bgp);
2197
2198 return CMD_SUCCESS;
abc920f8
DS
2199}
2200
1ca2fd11
IR
2201DEFUN (no_bgp_maxmed_onstartup,
2202 no_bgp_maxmed_onstartup_cmd,
2203 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2204 NO_STR
2205 BGP_STR
2206 "Advertise routes with max-med\n"
2207 "Effective on a startup\n"
2208 "Time (seconds) period for max-med\n"
2209 "Max MED value to be used\n")
abc920f8 2210{
1ca2fd11
IR
2211 VTY_DECLVAR_CONTEXT(bgp, bgp);
2212
2213 /* Cancel max-med onstartup if its on */
2214 if (bgp->t_maxmed_onstartup) {
e16d030c 2215 EVENT_OFF(bgp->t_maxmed_onstartup);
1ca2fd11
IR
2216 bgp->maxmed_onstartup_over = 1;
2217 }
abc920f8 2218
1ca2fd11
IR
2219 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2220 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 2221
1ca2fd11
IR
2222 bgp_maxmed_update(bgp);
2223
2224 return CMD_SUCCESS;
abc920f8
DS
2225}
2226
d70583f7
D
2227static int bgp_global_update_delay_config_vty(struct vty *vty,
2228 uint16_t update_delay,
2229 uint16_t establish_wait)
2230{
2231 struct listnode *node, *nnode;
2232 struct bgp *bgp;
2233 bool vrf_cfg = false;
2234
2235 /*
2236 * See if update-delay is set per-vrf and warn user to delete it
2237 * Note that we only need to check this if this is the first time
2238 * setting the global config.
2239 */
2240 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2241 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2242 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2243 vty_out(vty,
2244 "%% update-delay configuration found in vrf %s\n",
2245 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2246 ? VRF_DEFAULT_NAME
2247 : bgp->name);
2248 vrf_cfg = true;
2249 }
2250 }
2251 }
2252
2253 if (vrf_cfg) {
2254 vty_out(vty,
2255 "%%Failed: global update-delay config not permitted\n");
2256 return CMD_WARNING;
2257 }
2258
2259 if (!establish_wait) { /* update-delay <delay> */
2260 bm->v_update_delay = update_delay;
2261 bm->v_establish_wait = bm->v_update_delay;
2262 } else {
2263 /* update-delay <delay> <establish-wait> */
2264 if (update_delay < establish_wait) {
2265 vty_out(vty,
2266 "%%Failed: update-delay less than the establish-wait!\n");
2267 return CMD_WARNING_CONFIG_FAILED;
2268 }
2269
2270 bm->v_update_delay = update_delay;
2271 bm->v_establish_wait = establish_wait;
2272 }
2273
2274 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2275 bgp->v_update_delay = bm->v_update_delay;
2276 bgp->v_establish_wait = bm->v_establish_wait;
2277 }
2278
2279 return CMD_SUCCESS;
2280}
2281
2282static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2283{
2284 struct listnode *node, *nnode;
2285 struct bgp *bgp;
2286
2287 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2288 bm->v_establish_wait = bm->v_update_delay;
2289
2290 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2291 bgp->v_update_delay = bm->v_update_delay;
2292 bgp->v_establish_wait = bm->v_establish_wait;
2293 }
2294
2295 return CMD_SUCCESS;
2296}
2297
2298static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2299 uint16_t establish_wait)
f188f2c4 2300{
d62a17ae 2301 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2302
d70583f7
D
2303 /* if configured globally, per-instance config is not allowed */
2304 if (bm->v_update_delay) {
2305 vty_out(vty,
2306 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2307 return CMD_WARNING_CONFIG_FAILED;
2308 }
2309
f188f2c4 2310
d70583f7 2311 if (!establish_wait) /* update-delay <delay> */
d62a17ae 2312 {
2313 bgp->v_update_delay = update_delay;
2314 bgp->v_establish_wait = bgp->v_update_delay;
2315 return CMD_SUCCESS;
2316 }
f188f2c4 2317
d62a17ae 2318 /* update-delay <delay> <establish-wait> */
d62a17ae 2319 if (update_delay < establish_wait) {
2320 vty_out(vty,
2321 "%%Failed: update-delay less than the establish-wait!\n");
2322 return CMD_WARNING_CONFIG_FAILED;
2323 }
f188f2c4 2324
d62a17ae 2325 bgp->v_update_delay = update_delay;
2326 bgp->v_establish_wait = establish_wait;
f188f2c4 2327
d62a17ae 2328 return CMD_SUCCESS;
f188f2c4
DS
2329}
2330
d62a17ae 2331static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2332{
d62a17ae 2333 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2334
d70583f7
D
2335 /* If configured globally, cannot remove from one bgp instance */
2336 if (bm->v_update_delay) {
2337 vty_out(vty,
2338 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2339 return CMD_WARNING_CONFIG_FAILED;
2340 }
d62a17ae 2341 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2342 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2343
d62a17ae 2344 return CMD_SUCCESS;
f188f2c4
DS
2345}
2346
2b791107 2347void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2348{
d70583f7
D
2349 /* If configured globally, no need to display per-instance value */
2350 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2351 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2352 if (bgp->v_update_delay != bgp->v_establish_wait)
2353 vty_out(vty, " %d", bgp->v_establish_wait);
2354 vty_out(vty, "\n");
2355 }
f188f2c4
DS
2356}
2357
d70583f7
D
2358/* Global update-delay configuration */
2359DEFPY (bgp_global_update_delay,
2360 bgp_global_update_delay_cmd,
2361 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2362 BGP_STR
2363 "Force initial delay for best-path and updates for all bgp instances\n"
2364 "Max delay in seconds\n"
2365 "Establish wait in seconds\n")
2366{
2367 return bgp_global_update_delay_config_vty(vty, delay, wait);
2368}
f188f2c4 2369
d70583f7
D
2370/* Global update-delay deconfiguration */
2371DEFPY (no_bgp_global_update_delay,
2372 no_bgp_global_update_delay_cmd,
2373 "no bgp update-delay [(0-3600) [(1-3600)]]",
2374 NO_STR
2375 BGP_STR
f188f2c4 2376 "Force initial delay for best-path and updates\n"
d70583f7
D
2377 "Max delay in seconds\n"
2378 "Establish wait in seconds\n")
f188f2c4 2379{
d70583f7 2380 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2381}
2382
d70583f7
D
2383/* Update-delay configuration */
2384
2385DEFPY (bgp_update_delay,
2386 bgp_update_delay_cmd,
2387 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2388 "Force initial delay for best-path and updates\n"
d70583f7
D
2389 "Max delay in seconds\n"
2390 "Establish wait in seconds\n")
f188f2c4 2391{
d70583f7 2392 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2393}
2394
2395/* Update-delay deconfiguration */
d70583f7 2396DEFPY (no_bgp_update_delay,
f188f2c4 2397 no_bgp_update_delay_cmd,
838758ac
DW
2398 "no update-delay [(0-3600) [(1-3600)]]",
2399 NO_STR
f188f2c4 2400 "Force initial delay for best-path and updates\n"
d70583f7
D
2401 "Max delay in seconds\n"
2402 "Establish wait in seconds\n")
f188f2c4 2403{
d62a17ae 2404 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2405}
2406
5e242b0d 2407
1ca2fd11
IR
2408static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2409 bool set)
cb1faec9 2410{
1ca2fd11
IR
2411 VTY_DECLVAR_CONTEXT(bgp, bgp);
2412
8fa7732f
QY
2413 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2414 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2415
2416 return CMD_SUCCESS;
2417}
2418
1ca2fd11
IR
2419static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2420 bool set)
555e09d4 2421{
1ca2fd11
IR
2422 VTY_DECLVAR_CONTEXT(bgp, bgp);
2423
8fa7732f
QY
2424 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2425 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2426
d62a17ae 2427 return CMD_SUCCESS;
cb1faec9
DS
2428}
2429
2b791107 2430void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2431{
555e09d4
QY
2432 uint32_t quanta =
2433 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2434 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2435 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2436}
2437
555e09d4
QY
2438void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2439{
2440 uint32_t quanta =
2441 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2442 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2443 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2444}
cb1faec9 2445
8fa7732f
QY
2446/* Packet quanta configuration
2447 *
2448 * XXX: The value set here controls the size of a stack buffer in the IO
2449 * thread. When changing these limits be careful to prevent stack overflow.
2450 *
2451 * Furthermore, the maximums used here should correspond to
2452 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2453 */
1ca2fd11
IR
2454DEFPY (bgp_wpkt_quanta,
2455 bgp_wpkt_quanta_cmd,
2456 "[no] write-quanta (1-64)$quanta",
2457 NO_STR
2458 "How many packets to write to peer socket per run\n"
2459 "Number of packets\n")
2460{
2461 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2462}
cb1faec9 2463
1ca2fd11
IR
2464DEFPY (bgp_rpkt_quanta,
2465 bgp_rpkt_quanta_cmd,
2466 "[no] read-quanta (1-10)$quanta",
2467 NO_STR
2468 "How many packets to read from peer socket per I/O cycle\n"
2469 "Number of packets\n")
2470{
2471 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
2472}
2473
2b791107 2474void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2475{
37a333fe 2476 if (!bgp->heuristic_coalesce)
d62a17ae 2477 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2478}
2479
d1adb448
PG
2480/* BGP TCP keepalive */
2481static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2482{
2483 if (bgp->tcp_keepalive_idle) {
2484 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2485 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2486 bgp->tcp_keepalive_probes);
2487 }
2488}
4668a151 2489
1ca2fd11
IR
2490DEFUN (bgp_coalesce_time,
2491 bgp_coalesce_time_cmd,
2492 "coalesce-time (0-4294967295)",
2493 "Subgroup coalesce timer\n"
2494 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2495{
1ca2fd11 2496 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 2497
1ca2fd11 2498 int idx = 0;
9b01d289 2499
1ca2fd11 2500 bgp->heuristic_coalesce = false;
9b01d289
DA
2501
2502 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2503 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2504
1ca2fd11 2505 return CMD_SUCCESS;
3f9c7369
DS
2506}
2507
1ca2fd11
IR
2508DEFUN (no_bgp_coalesce_time,
2509 no_bgp_coalesce_time_cmd,
2510 "no coalesce-time (0-4294967295)",
2511 NO_STR
2512 "Subgroup coalesce timer\n"
2513 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2514{
1ca2fd11 2515 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 2516
1ca2fd11
IR
2517 bgp->heuristic_coalesce = true;
2518 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2519 return CMD_SUCCESS;
3f9c7369
DS
2520}
2521
5e242b0d 2522/* Maximum-paths configuration */
585f1adc
IR
2523DEFUN (bgp_maxpaths,
2524 bgp_maxpaths_cmd,
2525 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2526 "Forward packets over multiple paths\n"
2527 "Number of paths\n")
5e242b0d 2528{
d62a17ae 2529 int idx_number = 1;
585f1adc
IR
2530 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2531 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
2532}
2533
d62a17ae 2534ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2535 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2536 "Forward packets over multiple paths\n"
2537 "Number of paths\n")
596c17ba 2538
585f1adc
IR
2539DEFUN (bgp_maxpaths_ibgp,
2540 bgp_maxpaths_ibgp_cmd,
2541 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2542 "Forward packets over multiple paths\n"
2543 "iBGP-multipath\n"
2544 "Number of paths\n")
165b5fff 2545{
d62a17ae 2546 int idx_number = 2;
585f1adc
IR
2547 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2548 argv[idx_number]->arg, 0, 1);
5e242b0d 2549}
165b5fff 2550
d62a17ae 2551ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2552 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2553 "Forward packets over multiple paths\n"
2554 "iBGP-multipath\n"
2555 "Number of paths\n")
596c17ba 2556
585f1adc
IR
2557DEFUN (bgp_maxpaths_ibgp_cluster,
2558 bgp_maxpaths_ibgp_cluster_cmd,
2559 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2560 "Forward packets over multiple paths\n"
2561 "iBGP-multipath\n"
2562 "Number of paths\n"
2563 "Match the cluster length\n")
5e242b0d 2564{
d62a17ae 2565 int idx_number = 2;
aa53c036
DS
2566 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2567 argv[idx_number]->arg, true, 1);
165b5fff
JB
2568}
2569
d62a17ae 2570ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2571 "maximum-paths ibgp " CMD_RANGE_STR(
2572 1, MULTIPATH_NUM) " equal-cluster-length",
2573 "Forward packets over multiple paths\n"
2574 "iBGP-multipath\n"
2575 "Number of paths\n"
2576 "Match the cluster length\n")
596c17ba 2577
585f1adc
IR
2578DEFUN (no_bgp_maxpaths,
2579 no_bgp_maxpaths_cmd,
2580 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2581 NO_STR
2582 "Forward packets over multiple paths\n"
2583 "Number of paths\n")
165b5fff 2584{
585f1adc 2585 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
2586}
2587
d62a17ae 2588ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2589 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2590 "Forward packets over multiple paths\n"
2591 "Number of paths\n")
596c17ba 2592
585f1adc
IR
2593DEFUN (no_bgp_maxpaths_ibgp,
2594 no_bgp_maxpaths_ibgp_cmd,
2595 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2596 NO_STR
2597 "Forward packets over multiple paths\n"
2598 "iBGP-multipath\n"
2599 "Number of paths\n"
2600 "Match the cluster length\n")
165b5fff 2601{
585f1adc 2602 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
2603}
2604
d62a17ae 2605ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2606 "no maximum-paths ibgp [" CMD_RANGE_STR(
2607 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2608 NO_STR
2609 "Forward packets over multiple paths\n"
2610 "iBGP-multipath\n"
2611 "Number of paths\n"
2612 "Match the cluster length\n")
596c17ba 2613
dd65f45e
DL
2614static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2615 afi_t afi, safi_t safi)
165b5fff 2616{
00908b7a 2617 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2618 vty_out(vty, " maximum-paths %d\n",
2619 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2620 }
165b5fff 2621
00908b7a 2622 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2623 vty_out(vty, " maximum-paths ibgp %d",
2624 bgp->maxpaths[afi][safi].maxpaths_ibgp);
aa53c036 2625 if (bgp->maxpaths[afi][safi].same_clusterlen)
d62a17ae 2626 vty_out(vty, " equal-cluster-length");
2627 vty_out(vty, "\n");
2628 }
165b5fff 2629}
6b0655a2 2630
718e3744 2631/* BGP timers. */
2632
1ca2fd11
IR
2633DEFUN (bgp_timers,
2634 bgp_timers_cmd,
2635 "timers bgp (0-65535) (0-65535)",
2636 "Adjust routing timers\n"
2637 "BGP timers\n"
2638 "Keepalive interval\n"
2639 "Holdtime\n")
718e3744 2640{
1ca2fd11 2641 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2642 int idx_number = 2;
2643 int idx_number_2 = 3;
1ca2fd11
IR
2644 unsigned long keepalive = 0;
2645 unsigned long holdtime = 0;
718e3744 2646
1ca2fd11
IR
2647 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2648 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 2649
1ca2fd11
IR
2650 /* Holdtime value check. */
2651 if (holdtime < 3 && holdtime != 0) {
2652 vty_out(vty,
2653 "%% hold time value must be either 0 or greater than 3\n");
2654 return CMD_WARNING_CONFIG_FAILED;
2655 }
718e3744 2656
1ca2fd11
IR
2657 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2658 BGP_DEFAULT_DELAYOPEN);
718e3744 2659
1ca2fd11 2660 return CMD_SUCCESS;
718e3744 2661}
2662
1ca2fd11
IR
2663DEFUN (no_bgp_timers,
2664 no_bgp_timers_cmd,
2665 "no timers bgp [(0-65535) (0-65535)]",
2666 NO_STR
2667 "Adjust routing timers\n"
2668 "BGP timers\n"
2669 "Keepalive interval\n"
2670 "Holdtime\n")
718e3744 2671{
1ca2fd11
IR
2672 VTY_DECLVAR_CONTEXT(bgp, bgp);
2673 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2674 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
ff8a8a7a 2675
1ca2fd11 2676 return CMD_SUCCESS;
718e3744 2677}
2678
b042667a
TI
2679/* BGP minimum holdtime. */
2680
2681DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2682 "bgp minimum-holdtime (1-65535)",
2683 "BGP specific commands\n"
2684 "BGP minimum holdtime\n"
2685 "Seconds\n")
2686{
2687 VTY_DECLVAR_CONTEXT(bgp, bgp);
2688 int idx_number = 2;
2689 unsigned long min_holdtime;
2690
2691 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2692
2693 bgp->default_min_holdtime = min_holdtime;
2694
2695 return CMD_SUCCESS;
2696}
2697
2698DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2699 "no bgp minimum-holdtime [(1-65535)]",
2700 NO_STR
2701 "BGP specific commands\n"
2702 "BGP minimum holdtime\n"
2703 "Seconds\n")
2704{
2705 VTY_DECLVAR_CONTEXT(bgp, bgp);
2706
2707 bgp->default_min_holdtime = 0;
2708
2709 return CMD_SUCCESS;
2710}
ff8a8a7a 2711
d1adb448
PG
2712DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2713 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2714 BGP_STR
2715 "TCP keepalive parameters\n"
2716 "TCP keepalive idle time (seconds)\n"
2717 "TCP keepalive interval (seconds)\n"
2718 "TCP keepalive maximum probes\n")
2719{
2720 VTY_DECLVAR_CONTEXT(bgp, bgp);
2721
2722 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2723 (uint16_t)probes);
2724
2725 return CMD_SUCCESS;
2726}
2727
2728DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2729 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2730 NO_STR
2731 BGP_STR
2732 "TCP keepalive parameters\n"
2733 "TCP keepalive idle time (seconds)\n"
2734 "TCP keepalive interval (seconds)\n"
2735 "TCP keepalive maximum probes\n")
2736{
2737 VTY_DECLVAR_CONTEXT(bgp, bgp);
2738
2739 bgp_tcp_keepalive_unset(bgp);
2740
2741 return CMD_SUCCESS;
2742}
2743
1ca2fd11
IR
2744DEFUN (bgp_client_to_client_reflection,
2745 bgp_client_to_client_reflection_cmd,
2746 "bgp client-to-client reflection",
e9273987 2747 BGP_STR
1ca2fd11
IR
2748 "Configure client to client route reflection\n"
2749 "reflection of routes allowed\n")
718e3744 2750{
1ca2fd11
IR
2751 VTY_DECLVAR_CONTEXT(bgp, bgp);
2752 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2753 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2754
1ca2fd11 2755 return CMD_SUCCESS;
718e3744 2756}
2757
1ca2fd11
IR
2758DEFUN (no_bgp_client_to_client_reflection,
2759 no_bgp_client_to_client_reflection_cmd,
2760 "no bgp client-to-client reflection",
2761 NO_STR
e9273987 2762 BGP_STR
1ca2fd11
IR
2763 "Configure client to client route reflection\n"
2764 "reflection of routes allowed\n")
718e3744 2765{
1ca2fd11
IR
2766 VTY_DECLVAR_CONTEXT(bgp, bgp);
2767 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2768 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2769
1ca2fd11 2770 return CMD_SUCCESS;
718e3744 2771}
2772
2773/* "bgp always-compare-med" configuration. */
1ca2fd11
IR
2774DEFUN (bgp_always_compare_med,
2775 bgp_always_compare_med_cmd,
2776 "bgp always-compare-med",
e9273987 2777 BGP_STR
1ca2fd11 2778 "Allow comparing MED from different neighbors\n")
718e3744 2779{
1ca2fd11
IR
2780 VTY_DECLVAR_CONTEXT(bgp, bgp);
2781 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2782 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2783
1ca2fd11 2784 return CMD_SUCCESS;
718e3744 2785}
2786
1ca2fd11
IR
2787DEFUN (no_bgp_always_compare_med,
2788 no_bgp_always_compare_med_cmd,
2789 "no bgp always-compare-med",
2790 NO_STR
e9273987 2791 BGP_STR
1ca2fd11 2792 "Allow comparing MED from different neighbors\n")
718e3744 2793{
1ca2fd11
IR
2794 VTY_DECLVAR_CONTEXT(bgp, bgp);
2795 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2796 bgp_recalculate_all_bestpaths(bgp);
6b0655a2 2797
1ca2fd11 2798 return CMD_SUCCESS;
2adac256
DA
2799}
2800
2adac256 2801
1ca2fd11
IR
2802DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2803 "bgp ebgp-requires-policy",
e9273987 2804 BGP_STR
1ca2fd11 2805 "Require in and out policy for eBGP peers (RFC8212)\n")
2adac256 2806{
1ca2fd11
IR
2807 VTY_DECLVAR_CONTEXT(bgp, bgp);
2808 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2809 return CMD_SUCCESS;
2adac256
DA
2810}
2811
1ca2fd11
IR
2812DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2813 "no bgp ebgp-requires-policy",
2814 NO_STR
e9273987 2815 BGP_STR
1ca2fd11 2816 "Require in and out policy for eBGP peers (RFC8212)\n")
ff8a8a7a 2817{
1ca2fd11
IR
2818 VTY_DECLVAR_CONTEXT(bgp, bgp);
2819 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2820 return CMD_SUCCESS;
ff8a8a7a 2821}
9dac9fc8 2822
7ee70320 2823DEFPY(bgp_lu_uses_explicit_null, bgp_lu_uses_explicit_null_cmd,
cf1c7e30 2824 "[no] bgp labeled-unicast <explicit-null|ipv4-explicit-null|ipv6-explicit-null>$value",
7ee70320
PG
2825 NO_STR BGP_STR
2826 "BGP Labeled-unicast options\n"
cf1c7e30
PG
2827 "Use explicit-null label values for all local prefixes\n"
2828 "Use the IPv4 explicit-null label value for IPv4 local prefixes\n"
2829 "Use the IPv6 explicit-null label value for IPv6 local prefixes\n")
7ee70320
PG
2830{
2831 VTY_DECLVAR_CONTEXT(bgp, bgp);
cf1c7e30 2832 uint64_t label_mode;
7ee70320 2833
cf1c7e30
PG
2834 if (strmatch(value, "ipv4-explicit-null"))
2835 label_mode = BGP_FLAG_LU_IPV4_EXPLICIT_NULL;
2836 else if (strmatch(value, "ipv6-explicit-null"))
2837 label_mode = BGP_FLAG_LU_IPV6_EXPLICIT_NULL;
2838 else
2839 label_mode = BGP_FLAG_LU_IPV4_EXPLICIT_NULL |
2840 BGP_FLAG_LU_IPV6_EXPLICIT_NULL;
7ee70320 2841 if (no)
cf1c7e30 2842 UNSET_FLAG(bgp->flags, label_mode);
7ee70320 2843 else
cf1c7e30 2844 SET_FLAG(bgp->flags, label_mode);
7ee70320
PG
2845 return CMD_SUCCESS;
2846}
2847
1ca2fd11
IR
2848DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2849 "bgp suppress-duplicates",
e9273987 2850 BGP_STR
1ca2fd11 2851 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2852{
1ca2fd11
IR
2853 VTY_DECLVAR_CONTEXT(bgp, bgp);
2854 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2855 return CMD_SUCCESS;
9dac9fc8
DA
2856}
2857
1ca2fd11
IR
2858DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2859 "no bgp suppress-duplicates",
2860 NO_STR
e9273987 2861 BGP_STR
1ca2fd11 2862 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2863{
1ca2fd11
IR
2864 VTY_DECLVAR_CONTEXT(bgp, bgp);
2865 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2866 return CMD_SUCCESS;
9dac9fc8
DA
2867}
2868
fb29348a
DA
2869DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2870 "bgp reject-as-sets",
e9273987 2871 BGP_STR
fb29348a
DA
2872 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2873{
2874 VTY_DECLVAR_CONTEXT(bgp, bgp);
2875 struct listnode *node, *nnode;
2876 struct peer *peer;
2877
7f972cd8 2878 bgp->reject_as_sets = true;
fb29348a
DA
2879
2880 /* Reset existing BGP sessions to reject routes
2881 * with aspath containing AS_SET or AS_CONFED_SET.
2882 */
2883 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2884 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2885 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2886 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2887 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2888 }
2889 }
2890
2891 return CMD_SUCCESS;
2892}
2893
2894DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2895 "no bgp reject-as-sets",
2896 NO_STR
e9273987 2897 BGP_STR
fb29348a
DA
2898 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2899{
2900 VTY_DECLVAR_CONTEXT(bgp, bgp);
2901 struct listnode *node, *nnode;
2902 struct peer *peer;
2903
7f972cd8 2904 bgp->reject_as_sets = false;
fb29348a
DA
2905
2906 /* Reset existing BGP sessions to reject routes
2907 * with aspath containing AS_SET or AS_CONFED_SET.
2908 */
2909 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2910 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2911 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2912 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2913 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2914 }
2915 }
2916
2917 return CMD_SUCCESS;
2918}
9dac9fc8 2919
718e3744 2920/* "bgp deterministic-med" configuration. */
1ca2fd11 2921DEFUN (bgp_deterministic_med,
718e3744 2922 bgp_deterministic_med_cmd,
2923 "bgp deterministic-med",
e9273987 2924 BGP_STR
718e3744 2925 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2926{
1ca2fd11
IR
2927 VTY_DECLVAR_CONTEXT(bgp, bgp);
2928
2929 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2930 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2931 bgp_recalculate_all_bestpaths(bgp);
2932 }
7aafcaca 2933
1ca2fd11 2934 return CMD_SUCCESS;
718e3744 2935}
2936
1ca2fd11 2937DEFUN (no_bgp_deterministic_med,
718e3744 2938 no_bgp_deterministic_med_cmd,
2939 "no bgp deterministic-med",
2940 NO_STR
e9273987 2941 BGP_STR
718e3744 2942 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2943{
1ca2fd11
IR
2944 VTY_DECLVAR_CONTEXT(bgp, bgp);
2945 int bestpath_per_as_used;
2946 afi_t afi;
2947 safi_t safi;
2948 struct peer *peer;
2949 struct listnode *node, *nnode;
2950
2951 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2952 bestpath_per_as_used = 0;
2953
2954 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2955 FOREACH_AFI_SAFI (afi, safi)
2956 if (bgp_addpath_dmed_required(
2957 peer->addpath_type[afi][safi])) {
2958 bestpath_per_as_used = 1;
2959 break;
2960 }
2961
2962 if (bestpath_per_as_used)
2963 break;
2964 }
2965
2966 if (bestpath_per_as_used) {
2967 vty_out(vty,
2968 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2969 return CMD_WARNING_CONFIG_FAILED;
2970 } else {
2971 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2972 bgp_recalculate_all_bestpaths(bgp);
2973 }
2974 }
d62a17ae 2975
1ca2fd11 2976 return CMD_SUCCESS;
718e3744 2977}
538621f2 2978
055679e9 2979/* "bgp graceful-restart mode" configuration. */
538621f2 2980DEFUN (bgp_graceful_restart,
2ba1fe69 2981 bgp_graceful_restart_cmd,
2982 "bgp graceful-restart",
e9273987 2983 BGP_STR
2ba1fe69 2984 GR_CMD
055679e9 2985 )
538621f2 2986{
055679e9 2987 int ret = BGP_GR_FAILURE;
2988
2989 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2990 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2991
d62a17ae 2992 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2993
2994 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2995
36235319
QY
2996 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2997 ret);
5cce3f05 2998
055679e9 2999 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 3000 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 3001 vty_out(vty,
3002 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 3003 return bgp_vty_return(vty, ret);
538621f2 3004}
3005
3006DEFUN (no_bgp_graceful_restart,
2ba1fe69 3007 no_bgp_graceful_restart_cmd,
3008 "no bgp graceful-restart",
3009 NO_STR
e9273987 3010 BGP_STR
2ba1fe69 3011 NO_GR_CMD
055679e9 3012 )
538621f2 3013{
d62a17ae 3014 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 3015
3016 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 3017 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 3018
3019 int ret = BGP_GR_FAILURE;
3020
3021 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
3022
36235319
QY
3023 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3024 ret);
5cce3f05 3025
055679e9 3026 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 3027 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 3028 vty_out(vty,
3029 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 3030
3031 return bgp_vty_return(vty, ret);
538621f2 3032}
3033
93406d87 3034DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 3035 bgp_graceful_restart_stalepath_time_cmd,
3036 "bgp graceful-restart stalepath-time (1-4095)",
e9273987 3037 BGP_STR
2ba1fe69 3038 "Graceful restart capability parameters\n"
3039 "Set the max time to hold onto restarting peer's stale paths\n"
3040 "Delay value (seconds)\n")
93406d87 3041{
d62a17ae 3042 VTY_DECLVAR_CONTEXT(bgp, bgp);
3043 int idx_number = 3;
d7c0a89a 3044 uint32_t stalepath;
93406d87 3045
d62a17ae 3046 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
3047 bgp->stalepath_time = stalepath;
3048 return CMD_SUCCESS;
93406d87 3049}
3050
eb6f1b41 3051DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 3052 bgp_graceful_restart_restart_time_cmd,
dcbebfd3 3053 "bgp graceful-restart restart-time (0-4095)",
e9273987 3054 BGP_STR
2ba1fe69 3055 "Graceful restart capability parameters\n"
3056 "Set the time to wait to delete stale routes before a BGP open message is received\n"
3057 "Delay value (seconds)\n")
eb6f1b41 3058{
d62a17ae 3059 VTY_DECLVAR_CONTEXT(bgp, bgp);
3060 int idx_number = 3;
d7c0a89a 3061 uint32_t restart;
eb6f1b41 3062
d62a17ae 3063 restart = strtoul(argv[idx_number]->arg, NULL, 10);
3064 bgp->restart_time = restart;
3065 return CMD_SUCCESS;
eb6f1b41
PG
3066}
3067
cfd47646 3068DEFUN (bgp_graceful_restart_select_defer_time,
3069 bgp_graceful_restart_select_defer_time_cmd,
3070 "bgp graceful-restart select-defer-time (0-3600)",
e9273987 3071 BGP_STR
cfd47646 3072 "Graceful restart capability parameters\n"
3073 "Set the time to defer the BGP route selection after restart\n"
3074 "Delay value (seconds, 0 - disable)\n")
3075{
3076 VTY_DECLVAR_CONTEXT(bgp, bgp);
3077 int idx_number = 3;
3078 uint32_t defer_time;
3079
3080 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
3081 bgp->select_defer_time = defer_time;
3082 if (defer_time == 0)
892fedb6 3083 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 3084 else
892fedb6 3085 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 3086
3087 return CMD_SUCCESS;
3088}
3089
93406d87 3090DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 3091 no_bgp_graceful_restart_stalepath_time_cmd,
3092 "no bgp graceful-restart stalepath-time [(1-4095)]",
3093 NO_STR
e9273987 3094 BGP_STR
2ba1fe69 3095 "Graceful restart capability parameters\n"
3096 "Set the max time to hold onto restarting peer's stale paths\n"
3097 "Delay value (seconds)\n")
93406d87 3098{
d62a17ae 3099 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 3100
d62a17ae 3101 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
3102 return CMD_SUCCESS;
93406d87 3103}
3104
eb6f1b41 3105DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 3106 no_bgp_graceful_restart_restart_time_cmd,
dcbebfd3 3107 "no bgp graceful-restart restart-time [(0-4095)]",
2ba1fe69 3108 NO_STR
e9273987 3109 BGP_STR
2ba1fe69 3110 "Graceful restart capability parameters\n"
3111 "Set the time to wait to delete stale routes before a BGP open message is received\n"
3112 "Delay value (seconds)\n")
eb6f1b41 3113{
d62a17ae 3114 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 3115
d62a17ae 3116 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
3117 return CMD_SUCCESS;
eb6f1b41
PG
3118}
3119
cfd47646 3120DEFUN (no_bgp_graceful_restart_select_defer_time,
3121 no_bgp_graceful_restart_select_defer_time_cmd,
3122 "no bgp graceful-restart select-defer-time [(0-3600)]",
3123 NO_STR
e9273987 3124 BGP_STR
cfd47646 3125 "Graceful restart capability parameters\n"
3126 "Set the time to defer the BGP route selection after restart\n"
3127 "Delay value (seconds)\n")
3128{
3129 VTY_DECLVAR_CONTEXT(bgp, bgp);
3130
3131 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 3132 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 3133
3134 return CMD_SUCCESS;
3135}
3136
43fc21b3 3137DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 3138 bgp_graceful_restart_preserve_fw_cmd,
3139 "bgp graceful-restart preserve-fw-state",
e9273987 3140 BGP_STR
2ba1fe69 3141 "Graceful restart capability parameters\n"
3142 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 3143{
d62a17ae 3144 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3145 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 3146 return CMD_SUCCESS;
43fc21b3
JC
3147}
3148
3149DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 3150 no_bgp_graceful_restart_preserve_fw_cmd,
3151 "no bgp graceful-restart preserve-fw-state",
3152 NO_STR
e9273987 3153 BGP_STR
2ba1fe69 3154 "Graceful restart capability parameters\n"
3155 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 3156{
d62a17ae 3157 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3158 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 3159 return CMD_SUCCESS;
43fc21b3
JC
3160}
3161
f2ca5c5b
DA
3162DEFPY (bgp_graceful_restart_notification,
3163 bgp_graceful_restart_notification_cmd,
3164 "[no$no] bgp graceful-restart notification",
3165 NO_STR
3166 BGP_STR
3167 "Graceful restart capability parameters\n"
3168 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3169{
3170 VTY_DECLVAR_CONTEXT(bgp, bgp);
3171
3172 if (no)
3173 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3174 else
3175 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3176
3177 return CMD_SUCCESS;
3178}
3179
1ae314be
DA
3180DEFPY (bgp_administrative_reset,
3181 bgp_administrative_reset_cmd,
3182 "[no$no] bgp hard-administrative-reset",
3183 NO_STR
3184 BGP_STR
3185 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3186{
3187 VTY_DECLVAR_CONTEXT(bgp, bgp);
3188
3189 if (no)
3190 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3191 else
3192 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3193
3194 return CMD_SUCCESS;
3195}
3196
055679e9 3197DEFUN (bgp_graceful_restart_disable,
2ba1fe69 3198 bgp_graceful_restart_disable_cmd,
3199 "bgp graceful-restart-disable",
e9273987 3200 BGP_STR
2ba1fe69 3201 GR_DISABLE)
055679e9 3202{
3203 int ret = BGP_GR_FAILURE;
3204
3205 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3206 zlog_debug(
2ba1fe69 3207 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 3208
055679e9 3209 VTY_DECLVAR_CONTEXT(bgp, bgp);
3210
3211 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3212
dc95985f 3213 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3214 bgp->peer, ret);
5cce3f05 3215
055679e9 3216 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3217 zlog_debug(
2ba1fe69 3218 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 3219 vty_out(vty,
3220 "Graceful restart configuration changed, reset all peers to take effect\n");
3221
055679e9 3222 return bgp_vty_return(vty, ret);
3223}
3224
3225DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 3226 no_bgp_graceful_restart_disable_cmd,
3227 "no bgp graceful-restart-disable",
3228 NO_STR
e9273987 3229 BGP_STR
2ba1fe69 3230 NO_GR_DISABLE
055679e9 3231 )
3232{
3233 VTY_DECLVAR_CONTEXT(bgp, bgp);
3234
3235 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3236 zlog_debug(
2ba1fe69 3237 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 3238
3239 int ret = BGP_GR_FAILURE;
3240
3241 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3242
36235319
QY
3243 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3244 ret);
5cce3f05 3245
055679e9 3246 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3247 zlog_debug(
2ba1fe69 3248 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 3249 vty_out(vty,
3250 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 3251
3252 return bgp_vty_return(vty, ret);
3253}
3254
3255DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 3256 bgp_neighbor_graceful_restart_set_cmd,
3257 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3258 NEIGHBOR_STR
3259 NEIGHBOR_ADDR_STR2
3260 GR_NEIGHBOR_CMD
055679e9 3261 )
3262{
3263 int idx_peer = 1;
3264 struct peer *peer;
3265 int ret = BGP_GR_FAILURE;
3266
dc95985f 3267 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3268
055679e9 3269 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3270 zlog_debug(
2ba1fe69 3271 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 3272
055679e9 3273 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3274 if (!peer)
3275 return CMD_WARNING_CONFIG_FAILED;
3276
3277 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3278
dc95985f 3279 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3280 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3281
3282 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3283 zlog_debug(
2ba1fe69 3284 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3285 vty_out(vty,
3286 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3287
3288 return bgp_vty_return(vty, ret);
3289}
3290
3291DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 3292 no_bgp_neighbor_graceful_restart_set_cmd,
3293 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3294 NO_STR
3295 NEIGHBOR_STR
3296 NEIGHBOR_ADDR_STR2
3297 NO_GR_NEIGHBOR_CMD
055679e9 3298 )
3299{
3300 int idx_peer = 2;
3301 int ret = BGP_GR_FAILURE;
3302 struct peer *peer;
3303
dc95985f 3304 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3305
055679e9 3306 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3307 if (!peer)
3308 return CMD_WARNING_CONFIG_FAILED;
3309
3310 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3311 zlog_debug(
2ba1fe69 3312 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 3313
3314 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3315
dc95985f 3316 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3317 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3318
3319 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3320 zlog_debug(
2ba1fe69 3321 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3322 vty_out(vty,
3323 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3324
3325 return bgp_vty_return(vty, ret);
3326}
3327
3328DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 3329 bgp_neighbor_graceful_restart_helper_set_cmd,
3330 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3331 NEIGHBOR_STR
3332 NEIGHBOR_ADDR_STR2
3333 GR_NEIGHBOR_HELPER_CMD
055679e9 3334 )
3335{
3336 int idx_peer = 1;
3337 struct peer *peer;
3338 int ret = BGP_GR_FAILURE;
3339
dc95985f 3340 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3341
055679e9 3342 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3343 zlog_debug(
2ba1fe69 3344 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 3345
055679e9 3346 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3347
055679e9 3348 if (!peer)
3349 return CMD_WARNING_CONFIG_FAILED;
3350
3351
3352 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 3353
dc95985f 3354 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3355 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 3356
055679e9 3357 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3358 zlog_debug(
2ba1fe69 3359 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3360 vty_out(vty,
3361 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3362
3363 return bgp_vty_return(vty, ret);
3364}
3365
3366DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3367 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3368 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3369 NO_STR
3370 NEIGHBOR_STR
3371 NEIGHBOR_ADDR_STR2
3372 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3373 )
3374{
3375 int idx_peer = 2;
3376 int ret = BGP_GR_FAILURE;
3377 struct peer *peer;
3378
dc95985f 3379 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3380
055679e9 3381 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3382 if (!peer)
3383 return CMD_WARNING_CONFIG_FAILED;
3384
3385 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3386 zlog_debug(
2ba1fe69 3387 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3388
36235319 3389 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3390
dc95985f 3391 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3392 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3393
3394 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3395 zlog_debug(
2ba1fe69 3396 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3397 vty_out(vty,
3398 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3399
3400 return bgp_vty_return(vty, ret);
3401}
3402
3403DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3404 bgp_neighbor_graceful_restart_disable_set_cmd,
3405 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3406 NEIGHBOR_STR
3407 NEIGHBOR_ADDR_STR2
3408 GR_NEIGHBOR_DISABLE_CMD
055679e9 3409 )
3410{
3411 int idx_peer = 1;
3412 struct peer *peer;
3413 int ret = BGP_GR_FAILURE;
3414
dc95985f 3415 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3416
055679e9 3417 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3418 zlog_debug(
2ba1fe69 3419 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3420
3421 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3422 if (!peer)
3423 return CMD_WARNING_CONFIG_FAILED;
3424
36235319 3425 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3426
3427 if (peer->bgp->t_startup)
3428 bgp_peer_gr_flags_update(peer);
3429
dc95985f 3430 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3431 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3432
055679e9 3433 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3434 zlog_debug(
2ba1fe69 3435 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3436 vty_out(vty,
3437 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3438
3439 return bgp_vty_return(vty, ret);
3440}
3441
3442DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3443 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3444 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3445 NO_STR
3446 NEIGHBOR_STR
3447 NEIGHBOR_ADDR_STR2
3448 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3449 )
3450{
3451 int idx_peer = 2;
3452 int ret = BGP_GR_FAILURE;
3453 struct peer *peer;
3454
dc95985f 3455 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3456
055679e9 3457 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3458 if (!peer)
3459 return CMD_WARNING_CONFIG_FAILED;
3460
3461 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3462 zlog_debug(
2ba1fe69 3463 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3464
3465 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3466
dc95985f 3467 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3468 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3469
3470 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3471 zlog_debug(
2ba1fe69 3472 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3473 vty_out(vty,
3474 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3475
3476 return bgp_vty_return(vty, ret);
3477}
3478
4f770cf1
DA
3479DEFPY (neighbor_graceful_shutdown,
3480 neighbor_graceful_shutdown_cmd,
3481 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor graceful-shutdown",
3482 NO_STR
3483 NEIGHBOR_STR
3484 NEIGHBOR_ADDR_STR2
3485 "Graceful shutdown\n")
3486{
3487 afi_t afi;
3488 safi_t safi;
3489 struct peer *peer;
3490 VTY_DECLVAR_CONTEXT(bgp, bgp);
3491 int ret;
3492
3493 peer = peer_and_group_lookup_vty(vty, neighbor);
3494 if (!peer)
3495 return CMD_WARNING_CONFIG_FAILED;
3496
3497 if (no)
3498 ret = peer_flag_unset_vty(vty, neighbor,
3499 PEER_FLAG_GRACEFUL_SHUTDOWN);
3500 else
3501 ret = peer_flag_set_vty(vty, neighbor,
3502 PEER_FLAG_GRACEFUL_SHUTDOWN);
3503
3504 FOREACH_AFI_SAFI (afi, safi) {
3505 if (!peer->afc[afi][safi])
3506 continue;
3507
3508 bgp_clear(vty, bgp, afi, safi, clear_peer, BGP_CLEAR_SOFT_IN,
3509 neighbor);
3510 }
3511
3512 return ret;
3513}
3514
d6e3c15b 3515DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3516 bgp_graceful_restart_disable_eor_cmd,
3517 "bgp graceful-restart disable-eor",
e9273987 3518 BGP_STR
d6e3c15b 3519 "Graceful restart configuration parameters\n"
3520 "Disable EOR Check\n")
3521{
3522 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3523 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3524
d6e3c15b 3525 return CMD_SUCCESS;
3526}
3527
3528DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3529 no_bgp_graceful_restart_disable_eor_cmd,
3530 "no bgp graceful-restart disable-eor",
3531 NO_STR
e9273987 3532 BGP_STR
d6e3c15b 3533 "Graceful restart configuration parameters\n"
3534 "Disable EOR Check\n")
3535{
3536 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3537 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3538
3539 return CMD_SUCCESS;
3540}
3541
3542DEFUN (bgp_graceful_restart_rib_stale_time,
3543 bgp_graceful_restart_rib_stale_time_cmd,
3544 "bgp graceful-restart rib-stale-time (1-3600)",
e9273987 3545 BGP_STR
dc95985f 3546 "Graceful restart configuration parameters\n"
3547 "Specify the stale route removal timer in rib\n"
3548 "Delay value (seconds)\n")
3549{
3550 VTY_DECLVAR_CONTEXT(bgp, bgp);
3551 int idx_number = 3;
3552 uint32_t stale_time;
3553
3554 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3555 bgp->rib_stale_time = stale_time;
3556 /* Send the stale timer update message to RIB */
3557 if (bgp_zebra_stale_timer_update(bgp))
3558 return CMD_WARNING;
3559
3560 return CMD_SUCCESS;
3561}
3562
3563DEFUN (no_bgp_graceful_restart_rib_stale_time,
3564 no_bgp_graceful_restart_rib_stale_time_cmd,
3565 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3566 NO_STR
e9273987 3567 BGP_STR
dc95985f 3568 "Graceful restart configuration parameters\n"
3569 "Specify the stale route removal timer in rib\n"
3570 "Delay value (seconds)\n")
3571{
3572 VTY_DECLVAR_CONTEXT(bgp, bgp);
3573
3574 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3575 /* Send the stale timer update message to RIB */
3576 if (bgp_zebra_stale_timer_update(bgp))
3577 return CMD_WARNING;
3578
d6e3c15b 3579 return CMD_SUCCESS;
3580}
3581
8606be87 3582DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
5970204c 3583 "bgp long-lived-graceful-restart stale-time (1-16777215)",
7f8a9a24 3584 BGP_STR
8606be87
DA
3585 "Enable Long-lived Graceful Restart\n"
3586 "Specifies maximum time to wait before purging long-lived stale routes\n"
3587 "Stale time value (seconds)\n")
3588{
3589 VTY_DECLVAR_CONTEXT(bgp, bgp);
3590
3591 uint32_t llgr_stale_time;
3592
3593 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3594 bgp->llgr_stale_time = llgr_stale_time;
3595
3596 return CMD_SUCCESS;
3597}
3598
3599DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
5970204c 3600 "no bgp long-lived-graceful-restart stale-time [(1-16777215)]",
8606be87
DA
3601 NO_STR BGP_STR
3602 "Enable Long-lived Graceful Restart\n"
3603 "Specifies maximum time to wait before purging long-lived stale routes\n"
3604 "Stale time value (seconds)\n")
3605{
3606 VTY_DECLVAR_CONTEXT(bgp, bgp);
3607
3608 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3609
3610 return CMD_SUCCESS;
3611}
3612
1ca2fd11
IR
3613static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3614 struct bgp *bgp)
05bd726c 3615{
3616 bgp_static_redo_import_check(bgp);
3617 bgp_redistribute_redo(bgp);
1ca2fd11
IR
3618 bgp_clear_star_soft_out(vty, bgp->name);
3619 bgp_clear_star_soft_in(vty, bgp->name);
05bd726c 3620}
3621
3622static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3623{
3624 struct listnode *node, *nnode;
3625 struct bgp *bgp;
3626 bool vrf_cfg = false;
3627
3628 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3629 return CMD_SUCCESS;
3630
3631 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3632 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3633 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3634 vty_out(vty,
3635 "%% graceful-shutdown configuration found in vrf %s\n",
3636 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3637 VRF_DEFAULT_NAME : bgp->name);
3638 vrf_cfg = true;
3639 }
3640 }
3641
3642 if (vrf_cfg) {
3643 vty_out(vty,
3644 "%%Failed: global graceful-shutdown not permitted\n");
3645 return CMD_WARNING;
3646 }
3647
3648 /* Set flag globally */
3649 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3650
3651 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3652 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3653 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3654
3655 return CMD_SUCCESS;
3656}
3657
3658static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3659{
3660 struct listnode *node, *nnode;
3661 struct bgp *bgp;
3662
3663 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3664 return CMD_SUCCESS;
3665
3666 /* Unset flag globally */
3667 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3668
3669 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3670 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3671 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3672
3673 return CMD_SUCCESS;
3674}
3675
7f323236
DW
3676/* "bgp graceful-shutdown" configuration */
3677DEFUN (bgp_graceful_shutdown,
3678 bgp_graceful_shutdown_cmd,
3679 "bgp graceful-shutdown",
3680 BGP_STR
3681 "Graceful shutdown parameters\n")
3682{
05bd726c 3683 if (vty->node == CONFIG_NODE)
3684 return bgp_global_graceful_shutdown_config_vty(vty);
3685
1ca2fd11 3686 VTY_DECLVAR_CONTEXT(bgp, bgp);
7f323236 3687
1ca2fd11
IR
3688 /* if configured globally, per-instance config is not allowed */
3689 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3690 vty_out(vty,
3691 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3692 return CMD_WARNING_CONFIG_FAILED;
3693 }
3694
3695 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3696 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3697 bgp_initiate_graceful_shut_unshut(vty, bgp);
3698 }
3699
3700 return CMD_SUCCESS;
7f323236
DW
3701}
3702
1ca2fd11 3703DEFUN (no_bgp_graceful_shutdown,
7f323236
DW
3704 no_bgp_graceful_shutdown_cmd,
3705 "no bgp graceful-shutdown",
3706 NO_STR
3707 BGP_STR
3708 "Graceful shutdown parameters\n")
3709{
05bd726c 3710 if (vty->node == CONFIG_NODE)
3711 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3712
1ca2fd11 3713 VTY_DECLVAR_CONTEXT(bgp, bgp);
05bd726c 3714
1ca2fd11
IR
3715 /* If configured globally, cannot remove from one bgp instance */
3716 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3717 vty_out(vty,
3718 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3719 return CMD_WARNING_CONFIG_FAILED;
3720 }
7f323236 3721
1ca2fd11
IR
3722 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3723 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3724 bgp_initiate_graceful_shut_unshut(vty, bgp);
3725 }
3726
3727 return CMD_SUCCESS;
7f323236
DW
3728}
3729
718e3744 3730/* "bgp fast-external-failover" configuration. */
1ca2fd11 3731DEFUN (bgp_fast_external_failover,
718e3744 3732 bgp_fast_external_failover_cmd,
3733 "bgp fast-external-failover",
3734 BGP_STR
3735 "Immediately reset session if a link to a directly connected external peer goes down\n")
3736{
1ca2fd11
IR
3737 VTY_DECLVAR_CONTEXT(bgp, bgp);
3738 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3739 return CMD_SUCCESS;
718e3744 3740}
3741
1ca2fd11 3742DEFUN (no_bgp_fast_external_failover,
718e3744 3743 no_bgp_fast_external_failover_cmd,
3744 "no bgp fast-external-failover",
3745 NO_STR
3746 BGP_STR
3747 "Immediately reset session if a link to a directly connected external peer goes down\n")
3748{
1ca2fd11
IR
3749 VTY_DECLVAR_CONTEXT(bgp, bgp);
3750 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3751 return CMD_SUCCESS;
718e3744 3752}
6b0655a2 3753
97a52c82
DA
3754DEFPY (bgp_bestpath_aigp,
3755 bgp_bestpath_aigp_cmd,
3756 "[no$no] bgp bestpath aigp",
3757 NO_STR
3758 BGP_STR
3759 "Change the default bestpath selection\n"
3760 "Evaluate the AIGP attribute during the best path selection process\n")
3761{
3762 VTY_DECLVAR_CONTEXT(bgp, bgp);
3763
3764 if (no)
3765 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3766 else
3767 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3768
3769 bgp_recalculate_all_bestpaths(bgp);
3770
3771 return CMD_SUCCESS;
3772}
3773
718e3744 3774/* "bgp bestpath compare-routerid" configuration. */
1ca2fd11
IR
3775DEFUN (bgp_bestpath_compare_router_id,
3776 bgp_bestpath_compare_router_id_cmd,
3777 "bgp bestpath compare-routerid",
e9273987 3778 BGP_STR
1ca2fd11
IR
3779 "Change the default bestpath selection\n"
3780 "Compare router-id for identical EBGP paths\n")
718e3744 3781{
1ca2fd11
IR
3782 VTY_DECLVAR_CONTEXT(bgp, bgp);
3783 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3784 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3785
1ca2fd11 3786 return CMD_SUCCESS;
718e3744 3787}
3788
1ca2fd11
IR
3789DEFUN (no_bgp_bestpath_compare_router_id,
3790 no_bgp_bestpath_compare_router_id_cmd,
3791 "no bgp bestpath compare-routerid",
3792 NO_STR
e9273987 3793 BGP_STR
1ca2fd11
IR
3794 "Change the default bestpath selection\n"
3795 "Compare router-id for identical EBGP paths\n")
718e3744 3796{
1ca2fd11
IR
3797 VTY_DECLVAR_CONTEXT(bgp, bgp);
3798 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3799 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3800
1ca2fd11 3801 return CMD_SUCCESS;
718e3744 3802}
6b0655a2 3803
718e3744 3804/* "bgp bestpath as-path ignore" configuration. */
1ca2fd11
IR
3805DEFUN (bgp_bestpath_aspath_ignore,
3806 bgp_bestpath_aspath_ignore_cmd,
3807 "bgp bestpath as-path ignore",
e9273987 3808 BGP_STR
1ca2fd11
IR
3809 "Change the default bestpath selection\n"
3810 "AS-path attribute\n"
3811 "Ignore as-path length in selecting a route\n")
718e3744 3812{
1ca2fd11
IR
3813 VTY_DECLVAR_CONTEXT(bgp, bgp);
3814 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3815 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3816
1ca2fd11 3817 return CMD_SUCCESS;
718e3744 3818}
3819
1ca2fd11
IR
3820DEFUN (no_bgp_bestpath_aspath_ignore,
3821 no_bgp_bestpath_aspath_ignore_cmd,
3822 "no bgp bestpath as-path ignore",
3823 NO_STR
e9273987 3824 BGP_STR
1ca2fd11
IR
3825 "Change the default bestpath selection\n"
3826 "AS-path attribute\n"
3827 "Ignore as-path length in selecting a route\n")
718e3744 3828{
1ca2fd11
IR
3829 VTY_DECLVAR_CONTEXT(bgp, bgp);
3830 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3831 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3832
1ca2fd11 3833 return CMD_SUCCESS;
718e3744 3834}
6b0655a2 3835
6811845b 3836/* "bgp bestpath as-path confed" configuration. */
1ca2fd11 3837DEFUN (bgp_bestpath_aspath_confed,
6811845b 3838 bgp_bestpath_aspath_confed_cmd,
3839 "bgp bestpath as-path confed",
e9273987 3840 BGP_STR
6811845b 3841 "Change the default bestpath selection\n"
3842 "AS-path attribute\n"
3843 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3844{
1ca2fd11
IR
3845 VTY_DECLVAR_CONTEXT(bgp, bgp);
3846 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3847 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3848
1ca2fd11 3849 return CMD_SUCCESS;
6811845b 3850}
3851
1ca2fd11 3852DEFUN (no_bgp_bestpath_aspath_confed,
6811845b 3853 no_bgp_bestpath_aspath_confed_cmd,
3854 "no bgp bestpath as-path confed",
3855 NO_STR
e9273987 3856 BGP_STR
6811845b 3857 "Change the default bestpath selection\n"
3858 "AS-path attribute\n"
3859 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3860{
1ca2fd11
IR
3861 VTY_DECLVAR_CONTEXT(bgp, bgp);
3862 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3863 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3864
1ca2fd11 3865 return CMD_SUCCESS;
6811845b 3866}
6b0655a2 3867
2fdd455c 3868/* "bgp bestpath as-path multipath-relax" configuration. */
1ca2fd11 3869DEFUN (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3870 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3871 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
e9273987 3872 BGP_STR
16fc1eec
DS
3873 "Change the default bestpath selection\n"
3874 "AS-path attribute\n"
3875 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3876 "Generate an AS_SET\n"
16fc1eec
DS
3877 "Do not generate an AS_SET\n")
3878{
1ca2fd11 3879 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3880 int idx = 0;
1ca2fd11 3881 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 3882
1ca2fd11
IR
3883 /* no-as-set is now the default behavior so we can silently
3884 * ignore it */
d62a17ae 3885 if (argv_find(argv, argc, "as-set", &idx))
1ca2fd11 3886 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 3887 else
1ca2fd11 3888 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
7aafcaca 3889
1ca2fd11
IR
3890 bgp_recalculate_all_bestpaths(bgp);
3891
3892 return CMD_SUCCESS;
16fc1eec
DS
3893}
3894
1ca2fd11 3895DEFUN (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3896 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3897 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec 3898 NO_STR
e9273987 3899 BGP_STR
16fc1eec
DS
3900 "Change the default bestpath selection\n"
3901 "AS-path attribute\n"
3902 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3903 "Generate an AS_SET\n"
16fc1eec
DS
3904 "Do not generate an AS_SET\n")
3905{
1ca2fd11
IR
3906 VTY_DECLVAR_CONTEXT(bgp, bgp);
3907 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3908 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3909 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3910
1ca2fd11 3911 return CMD_SUCCESS;
2fdd455c 3912}
6b0655a2 3913
ee88563a
JM
3914/* "bgp bestpath peer-type multipath-relax" configuration. */
3915DEFUN(bgp_bestpath_peer_type_multipath_relax,
3916 bgp_bestpath_peer_type_multipath_relax_cmd,
3917 "bgp bestpath peer-type multipath-relax",
3918 BGP_STR
3919 "Change the default bestpath selection\n"
3920 "Peer type\n"
3921 "Allow load sharing across routes learned from different peer types\n")
3922{
3923 VTY_DECLVAR_CONTEXT(bgp, bgp);
3924 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3925 bgp_recalculate_all_bestpaths(bgp);
3926
3927 return CMD_SUCCESS;
3928}
3929
3930DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3931 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3932 "no bgp bestpath peer-type multipath-relax",
3933 NO_STR BGP_STR
3934 "Change the default bestpath selection\n"
3935 "Peer type\n"
3936 "Allow load sharing across routes learned from different peer types\n")
3937{
3938 VTY_DECLVAR_CONTEXT(bgp, bgp);
3939 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3940 bgp_recalculate_all_bestpaths(bgp);
3941
3942 return CMD_SUCCESS;
3943}
3944
848973c7 3945/* "bgp log-neighbor-changes" configuration. */
1ca2fd11
IR
3946DEFUN (bgp_log_neighbor_changes,
3947 bgp_log_neighbor_changes_cmd,
3948 "bgp log-neighbor-changes",
e9273987 3949 BGP_STR
1ca2fd11 3950 "Log neighbor up/down and reset reason\n")
848973c7 3951{
1ca2fd11
IR
3952 VTY_DECLVAR_CONTEXT(bgp, bgp);
3953 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3954 return CMD_SUCCESS;
848973c7 3955}
3956
1ca2fd11
IR
3957DEFUN (no_bgp_log_neighbor_changes,
3958 no_bgp_log_neighbor_changes_cmd,
3959 "no bgp log-neighbor-changes",
3960 NO_STR
e9273987 3961 BGP_STR
1ca2fd11 3962 "Log neighbor up/down and reset reason\n")
848973c7 3963{
1ca2fd11
IR
3964 VTY_DECLVAR_CONTEXT(bgp, bgp);
3965 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3966 return CMD_SUCCESS;
848973c7 3967}
6b0655a2 3968
718e3744 3969/* "bgp bestpath med" configuration. */
1ca2fd11 3970DEFUN (bgp_bestpath_med,
718e3744 3971 bgp_bestpath_med_cmd,
2d8c1a4d 3972 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
e9273987 3973 BGP_STR
718e3744 3974 "Change the default bestpath selection\n"
3975 "MED attribute\n"
3976 "Compare MED among confederation paths\n"
838758ac
DW
3977 "Treat missing MED as the least preferred one\n"
3978 "Treat missing MED as the least preferred one\n"
3979 "Compare MED among confederation paths\n")
718e3744 3980{
1ca2fd11 3981 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3982
1ca2fd11 3983 int idx = 0;
d62a17ae 3984 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3985 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3986 idx = 0;
3987 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11 3988 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 3989
1ca2fd11 3990 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3991
1ca2fd11 3992 return CMD_SUCCESS;
718e3744 3993}
3994
1ca2fd11 3995DEFUN (no_bgp_bestpath_med,
718e3744 3996 no_bgp_bestpath_med_cmd,
2d8c1a4d 3997 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3998 NO_STR
e9273987 3999 BGP_STR
718e3744 4000 "Change the default bestpath selection\n"
4001 "MED attribute\n"
4002 "Compare MED among confederation paths\n"
3a2d747c
QY
4003 "Treat missing MED as the least preferred one\n"
4004 "Treat missing MED as the least preferred one\n"
4005 "Compare MED among confederation paths\n")
718e3744 4006{
1ca2fd11 4007 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 4008
1ca2fd11 4009 int idx = 0;
d62a17ae 4010 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 4011 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 4012 idx = 0;
4013 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11
IR
4014 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
4015
4016 bgp_recalculate_all_bestpaths(bgp);
718e3744 4017
1ca2fd11 4018 return CMD_SUCCESS;
718e3744 4019}
4020
f7e1c681 4021/* "bgp bestpath bandwidth" configuration. */
4022DEFPY (bgp_bestpath_bw,
4023 bgp_bestpath_bw_cmd,
ad36d216 4024 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
e9273987 4025 BGP_STR
f7e1c681 4026 "Change the default bestpath selection\n"
4027 "Link Bandwidth attribute\n"
4028 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
4029 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
4030 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
4031{
4032 VTY_DECLVAR_CONTEXT(bgp, bgp);
4033 afi_t afi;
4034 safi_t safi;
4035
ad36d216
DS
4036 if (!bw_cfg) {
4037 vty_out(vty, "%% Bandwidth configuration must be specified\n");
4038 return CMD_ERR_INCOMPLETE;
f7e1c681 4039 }
ad36d216
DS
4040 if (!strcmp(bw_cfg, "ignore"))
4041 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
4042 else if (!strcmp(bw_cfg, "skip-missing"))
4043 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
4044 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
4045 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
4046 else
4047 return CMD_ERR_NO_MATCH;
f7e1c681 4048
4049 /* This config is used in route install, so redo that. */
4050 FOREACH_AFI_SAFI (afi, safi) {
4051 if (!bgp_fibupd_safi(safi))
4052 continue;
4053 bgp_zebra_announce_table(bgp, afi, safi);
4054 }
4055
4056 return CMD_SUCCESS;
4057}
4058
ad36d216
DS
4059DEFPY (no_bgp_bestpath_bw,
4060 no_bgp_bestpath_bw_cmd,
4061 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
4062 NO_STR
e9273987 4063 BGP_STR
ad36d216
DS
4064 "Change the default bestpath selection\n"
4065 "Link Bandwidth attribute\n"
4066 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
4067 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
4068 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
4069{
4070 VTY_DECLVAR_CONTEXT(bgp, bgp);
4071 afi_t afi;
4072 safi_t safi;
4073
4074 bgp->lb_handling = BGP_LINK_BW_ECMP;
4075
4076 /* This config is used in route install, so redo that. */
4077 FOREACH_AFI_SAFI (afi, safi) {
4078 if (!bgp_fibupd_safi(safi))
4079 continue;
4080 bgp_zebra_announce_table(bgp, afi, safi);
4081 }
4082 return CMD_SUCCESS;
4083}
4084
b16bcbba 4085DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
38d11af5
TA
4086 "[no] bgp default <ipv4-unicast|"
4087 "ipv4-multicast|"
4088 "ipv4-vpn|"
4089 "ipv4-labeled-unicast|"
4090 "ipv4-flowspec|"
4091 "ipv6-unicast|"
4092 "ipv6-multicast|"
4093 "ipv6-vpn|"
4094 "ipv6-labeled-unicast|"
4095 "ipv6-flowspec|"
4096 "l2vpn-evpn>$afi_safi",
b16bcbba 4097 NO_STR
e9273987 4098 BGP_STR
e84c59af 4099 "Configure BGP defaults\n"
b16bcbba 4100 "Activate ipv4-unicast for a peer by default\n"
38d11af5
TA
4101 "Activate ipv4-multicast for a peer by default\n"
4102 "Activate ipv4-vpn for a peer by default\n"
4103 "Activate ipv4-labeled-unicast for a peer by default\n"
4104 "Activate ipv4-flowspec for a peer by default\n"
4105 "Activate ipv6-unicast for a peer by default\n"
4106 "Activate ipv6-multicast for a peer by default\n"
4107 "Activate ipv6-vpn for a peer by default\n"
4108 "Activate ipv6-labeled-unicast for a peer by default\n"
4109 "Activate ipv6-flowspec for a peer by default\n"
4110 "Activate l2vpn-evpn for a peer by default\n")
e84c59af
DA
4111{
4112 VTY_DECLVAR_CONTEXT(bgp, bgp);
b16bcbba
TA
4113 char afi_safi_str[strlen(afi_safi) + 1];
4114 char *afi_safi_str_tok;
e84c59af 4115
b16bcbba
TA
4116 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
4117 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
4118 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
4119 afi_t afi = bgp_vty_afi_from_str(afi_str);
38d11af5 4120 safi_t safi;
e84c59af 4121
d880a643
DS
4122 /*
4123 * Impossible situation but making coverity happy
4124 */
4125 assert(afi != AFI_MAX);
4126
38d11af5
TA
4127 if (strmatch(safi_str, "labeled"))
4128 safi = bgp_vty_safi_from_str("labeled-unicast");
4129 else
4130 safi = bgp_vty_safi_from_str(safi_str);
b16bcbba 4131
f609bcd6 4132 assert(safi != SAFI_MAX);
b16bcbba
TA
4133 if (no)
4134 bgp->default_af[afi][safi] = false;
38d11af5
TA
4135 else {
4136 if ((safi == SAFI_LABELED_UNICAST
4137 && bgp->default_af[afi][SAFI_UNICAST])
4138 || (safi == SAFI_UNICAST
4139 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
4140 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
4141 else
4142 bgp->default_af[afi][safi] = true;
4143 }
718e3744 4144
d62a17ae 4145 return CMD_SUCCESS;
718e3744 4146}
6b0655a2 4147
04b6bdc0 4148/* Display hostname in certain command outputs */
1ca2fd11 4149DEFUN (bgp_default_show_hostname,
04b6bdc0
DW
4150 bgp_default_show_hostname_cmd,
4151 "bgp default show-hostname",
e9273987 4152 BGP_STR
04b6bdc0 4153 "Configure BGP defaults\n"
0437e105 4154 "Show hostname in certain command outputs\n")
04b6bdc0 4155{
1ca2fd11
IR
4156 VTY_DECLVAR_CONTEXT(bgp, bgp);
4157 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4158 return CMD_SUCCESS;
ff8a8a7a
CS
4159}
4160
1ca2fd11
IR
4161DEFUN (no_bgp_default_show_hostname,
4162 no_bgp_default_show_hostname_cmd,
4163 "no bgp default show-hostname",
4164 NO_STR
e9273987 4165 BGP_STR
1ca2fd11
IR
4166 "Configure BGP defaults\n"
4167 "Show hostname in certain command outputs\n")
ff8a8a7a 4168{
1ca2fd11
IR
4169 VTY_DECLVAR_CONTEXT(bgp, bgp);
4170 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4171 return CMD_SUCCESS;
04b6bdc0
DW
4172}
4173
aef999a2 4174/* Display hostname in certain command outputs */
1d80f243
IR
4175DEFUN (bgp_default_show_nexthop_hostname,
4176 bgp_default_show_nexthop_hostname_cmd,
4177 "bgp default show-nexthop-hostname",
e9273987 4178 BGP_STR
1d80f243
IR
4179 "Configure BGP defaults\n"
4180 "Show hostname for nexthop in certain command outputs\n")
aef999a2 4181{
1ca2fd11
IR
4182 VTY_DECLVAR_CONTEXT(bgp, bgp);
4183 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4184 return CMD_SUCCESS;
aef999a2
DA
4185}
4186
4187DEFUN (no_bgp_default_show_nexthop_hostname,
4188 no_bgp_default_show_nexthop_hostname_cmd,
4189 "no bgp default show-nexthop-hostname",
4190 NO_STR
e9273987 4191 BGP_STR
aef999a2
DA
4192 "Configure BGP defaults\n"
4193 "Show hostname for nexthop in certain command outputs\n")
4194{
1ca2fd11
IR
4195 VTY_DECLVAR_CONTEXT(bgp, bgp);
4196 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4197 return CMD_SUCCESS;
aef999a2
DA
4198}
4199
8233ef81 4200/* "bgp network import-check" configuration. */
1ca2fd11
IR
4201DEFUN (bgp_network_import_check,
4202 bgp_network_import_check_cmd,
4203 "bgp network import-check",
e9273987 4204 BGP_STR
1ca2fd11
IR
4205 "BGP network command\n"
4206 "Check BGP network route exists in IGP\n")
718e3744 4207{
1ca2fd11
IR
4208 VTY_DECLVAR_CONTEXT(bgp, bgp);
4209 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4210 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4211 bgp_static_redo_import_check(bgp);
4212 }
078430f6 4213
1ca2fd11 4214 return CMD_SUCCESS;
718e3744 4215}
4216
d62a17ae 4217ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4218 "bgp network import-check exact",
e9273987 4219 BGP_STR
d62a17ae 4220 "BGP network command\n"
4221 "Check BGP network route exists in IGP\n"
4222 "Match route precisely\n")
8233ef81 4223
1ca2fd11
IR
4224DEFUN (no_bgp_network_import_check,
4225 no_bgp_network_import_check_cmd,
4226 "no bgp network import-check",
4227 NO_STR
e9273987 4228 BGP_STR
1ca2fd11
IR
4229 "BGP network command\n"
4230 "Check BGP network route exists in IGP\n")
718e3744 4231{
1ca2fd11
IR
4232 VTY_DECLVAR_CONTEXT(bgp, bgp);
4233 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4234 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4235 bgp_static_redo_import_check(bgp);
4236 }
6b0655a2 4237
1ca2fd11 4238 return CMD_SUCCESS;
ff8a8a7a 4239}
718e3744 4240
1ca2fd11
IR
4241DEFUN (bgp_default_local_preference,
4242 bgp_default_local_preference_cmd,
4243 "bgp default local-preference (0-4294967295)",
e9273987 4244 BGP_STR
1ca2fd11
IR
4245 "Configure BGP defaults\n"
4246 "local preference (higher=more preferred)\n"
4247 "Configure default local preference value\n")
ff8a8a7a 4248{
1ca2fd11 4249 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 4250 int idx_number = 3;
1ca2fd11 4251 uint32_t local_pref;
718e3744 4252
1ca2fd11 4253 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 4254
1ca2fd11
IR
4255 bgp_default_local_preference_set(bgp, local_pref);
4256 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 4257
1ca2fd11 4258 return CMD_SUCCESS;
718e3744 4259}
4260
1ca2fd11
IR
4261DEFUN (no_bgp_default_local_preference,
4262 no_bgp_default_local_preference_cmd,
4263 "no bgp default local-preference [(0-4294967295)]",
4264 NO_STR
e9273987 4265 BGP_STR
1ca2fd11
IR
4266 "Configure BGP defaults\n"
4267 "local preference (higher=more preferred)\n"
4268 "Configure default local preference value\n")
ff8a8a7a 4269{
1ca2fd11
IR
4270 VTY_DECLVAR_CONTEXT(bgp, bgp);
4271 bgp_default_local_preference_unset(bgp);
4272 bgp_clear_star_soft_in(vty, bgp->name);
4273
4274 return CMD_SUCCESS;
ff8a8a7a 4275}
6b0655a2 4276
ff8a8a7a 4277
1ca2fd11
IR
4278DEFUN (bgp_default_subgroup_pkt_queue_max,
4279 bgp_default_subgroup_pkt_queue_max_cmd,
4280 "bgp default subgroup-pkt-queue-max (20-100)",
e9273987 4281 BGP_STR
1ca2fd11
IR
4282 "Configure BGP defaults\n"
4283 "subgroup-pkt-queue-max\n"
4284 "Configure subgroup packet queue max\n")
8bd9d948 4285{
1ca2fd11 4286 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4287 int idx_number = 3;
1ca2fd11 4288 uint32_t max_size;
3f9c7369 4289
1ca2fd11 4290 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 4291
1ca2fd11 4292 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
ff8a8a7a 4293
1ca2fd11 4294 return CMD_SUCCESS;
8bd9d948
DS
4295}
4296
1ca2fd11
IR
4297DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4298 no_bgp_default_subgroup_pkt_queue_max_cmd,
4299 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4300 NO_STR
e9273987 4301 BGP_STR
1ca2fd11
IR
4302 "Configure BGP defaults\n"
4303 "subgroup-pkt-queue-max\n"
4304 "Configure subgroup packet queue max\n")
ff8a8a7a 4305{
1ca2fd11
IR
4306 VTY_DECLVAR_CONTEXT(bgp, bgp);
4307 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4308 return CMD_SUCCESS;
ff8a8a7a 4309}
813d4307 4310
8bd9d948 4311
1ca2fd11
IR
4312DEFUN (bgp_rr_allow_outbound_policy,
4313 bgp_rr_allow_outbound_policy_cmd,
4314 "bgp route-reflector allow-outbound-policy",
e9273987 4315 BGP_STR
1ca2fd11
IR
4316 "Allow modifications made by out route-map\n"
4317 "on ibgp neighbors\n")
ff8a8a7a 4318{
1ca2fd11 4319 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 4320
1ca2fd11
IR
4321 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4322 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4323 update_group_announce_rrclients(bgp);
4324 bgp_clear_star_soft_out(vty, bgp->name);
4325 }
8bd9d948 4326
1ca2fd11
IR
4327 return CMD_SUCCESS;
4328}
ff8a8a7a 4329
1ca2fd11
IR
4330DEFUN (no_bgp_rr_allow_outbound_policy,
4331 no_bgp_rr_allow_outbound_policy_cmd,
4332 "no bgp route-reflector allow-outbound-policy",
4333 NO_STR
e9273987 4334 BGP_STR
1ca2fd11
IR
4335 "Allow modifications made by out route-map\n"
4336 "on ibgp neighbors\n")
8bd9d948 4337{
1ca2fd11 4338 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 4339
1ca2fd11
IR
4340 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4341 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4342 update_group_announce_rrclients(bgp);
4343 bgp_clear_star_soft_out(vty, bgp->name);
d62a17ae 4344 }
8bd9d948 4345
1ca2fd11 4346 return CMD_SUCCESS;
8bd9d948
DS
4347}
4348
1ca2fd11
IR
4349DEFUN (bgp_listen_limit,
4350 bgp_listen_limit_cmd,
4351 "bgp listen limit (1-65535)",
e9273987 4352 BGP_STR
1ca2fd11
IR
4353 "BGP Dynamic Neighbors listen commands\n"
4354 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4355 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4356{
1ca2fd11 4357 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4358 int idx_number = 3;
1ca2fd11
IR
4359 int listen_limit;
4360
4361 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 4362
1ca2fd11 4363 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 4364
1ca2fd11 4365 return CMD_SUCCESS;
f14e6fdb
DS
4366}
4367
1ca2fd11
IR
4368DEFUN (no_bgp_listen_limit,
4369 no_bgp_listen_limit_cmd,
4370 "no bgp listen limit [(1-65535)]",
4371 NO_STR
e9273987 4372 BGP_STR
1ca2fd11
IR
4373 "BGP Dynamic Neighbors listen commands\n"
4374 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4375 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4376{
1ca2fd11
IR
4377 VTY_DECLVAR_CONTEXT(bgp, bgp);
4378 bgp_listen_limit_unset(bgp);
4379 return CMD_SUCCESS;
f14e6fdb
DS
4380}
4381
4382
20eb8864 4383/*
4384 * Check if this listen range is already configured. Check for exact
4385 * match or overlap based on input.
4386 */
d62a17ae 4387static struct peer_group *listen_range_exists(struct bgp *bgp,
4388 struct prefix *range, int exact)
4389{
4390 struct listnode *node, *nnode;
4391 struct listnode *node1, *nnode1;
4392 struct peer_group *group;
4393 struct prefix *lr;
4394 afi_t afi;
4395 int match;
4396
4397 afi = family2afi(range->family);
4398 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4399 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4400 lr)) {
4401 if (exact)
4402 match = prefix_same(range, lr);
4403 else
4404 match = (prefix_match(range, lr)
4405 || prefix_match(lr, range));
4406 if (match)
4407 return group;
4408 }
4409 }
4410
4411 return NULL;
20eb8864 4412}
4413
f14e6fdb
DS
4414DEFUN (bgp_listen_range,
4415 bgp_listen_range_cmd,
d7b9898c 4416 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
e9273987 4417 BGP_STR
d7fa34c1
QY
4418 "Configure BGP dynamic neighbors listen range\n"
4419 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
4420 NEIGHBOR_ADDR_STR
4421 "Member of the peer-group\n"
4422 "Peer-group name\n")
f14e6fdb 4423{
d62a17ae 4424 VTY_DECLVAR_CONTEXT(bgp, bgp);
4425 struct prefix range;
4426 struct peer_group *group, *existing_group;
4427 afi_t afi;
4428 int ret;
4429 int idx = 0;
4430
4431 argv_find(argv, argc, "A.B.C.D/M", &idx);
4432 argv_find(argv, argc, "X:X::X:X/M", &idx);
4433 char *prefix = argv[idx]->arg;
d7b9898c 4434 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4435 char *peergroup = argv[idx]->arg;
4436
4437 /* Convert IP prefix string to struct prefix. */
4438 ret = str2prefix(prefix, &range);
4439 if (!ret) {
4440 vty_out(vty, "%% Malformed listen range\n");
4441 return CMD_WARNING_CONFIG_FAILED;
4442 }
4443
4444 afi = family2afi(range.family);
4445
4446 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4447 vty_out(vty,
4448 "%% Malformed listen range (link-local address)\n");
4449 return CMD_WARNING_CONFIG_FAILED;
4450 }
4451
4452 apply_mask(&range);
4453
4454 /* Check if same listen range is already configured. */
4455 existing_group = listen_range_exists(bgp, &range, 1);
4456 if (existing_group) {
4457 if (strcmp(existing_group->name, peergroup) == 0)
4458 return CMD_SUCCESS;
4459 else {
4460 vty_out(vty,
4461 "%% Same listen range is attached to peer-group %s\n",
4462 existing_group->name);
4463 return CMD_WARNING_CONFIG_FAILED;
4464 }
4465 }
4466
4467 /* Check if an overlapping listen range exists. */
4468 if (listen_range_exists(bgp, &range, 0)) {
4469 vty_out(vty,
4470 "%% Listen range overlaps with existing listen range\n");
4471 return CMD_WARNING_CONFIG_FAILED;
4472 }
4473
4474 group = peer_group_lookup(bgp, peergroup);
4475 if (!group) {
4476 vty_out(vty, "%% Configure the peer-group first\n");
4477 return CMD_WARNING_CONFIG_FAILED;
4478 }
4479
4480 ret = peer_group_listen_range_add(group, &range);
4481 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4482}
4483
4484DEFUN (no_bgp_listen_range,
4485 no_bgp_listen_range_cmd,
d7b9898c 4486 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4487 NO_STR
e9273987 4488 BGP_STR
d7fa34c1
QY
4489 "Unconfigure BGP dynamic neighbors listen range\n"
4490 "Unconfigure BGP dynamic neighbors listen range\n"
4491 NEIGHBOR_ADDR_STR
4492 "Member of the peer-group\n"
4493 "Peer-group name\n")
f14e6fdb 4494{
d62a17ae 4495 VTY_DECLVAR_CONTEXT(bgp, bgp);
4496 struct prefix range;
4497 struct peer_group *group;
4498 afi_t afi;
4499 int ret;
4500 int idx = 0;
4501
4502 argv_find(argv, argc, "A.B.C.D/M", &idx);
4503 argv_find(argv, argc, "X:X::X:X/M", &idx);
4504 char *prefix = argv[idx]->arg;
21d88a71 4505 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4506 char *peergroup = argv[idx]->arg;
4507
4508 /* Convert IP prefix string to struct prefix. */
4509 ret = str2prefix(prefix, &range);
4510 if (!ret) {
4511 vty_out(vty, "%% Malformed listen range\n");
4512 return CMD_WARNING_CONFIG_FAILED;
4513 }
4514
4515 afi = family2afi(range.family);
4516
4517 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4518 vty_out(vty,
4519 "%% Malformed listen range (link-local address)\n");
4520 return CMD_WARNING_CONFIG_FAILED;
4521 }
4522
4523 apply_mask(&range);
4524
4525 group = peer_group_lookup(bgp, peergroup);
4526 if (!group) {
4527 vty_out(vty, "%% Peer-group does not exist\n");
4528 return CMD_WARNING_CONFIG_FAILED;
4529 }
4530
4531 ret = peer_group_listen_range_del(group, &range);
4532 return bgp_vty_return(vty, ret);
4533}
4534
2b791107 4535void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4536{
4537 struct peer_group *group;
4538 struct listnode *node, *nnode, *rnode, *nrnode;
4539 struct prefix *range;
4540 afi_t afi;
d62a17ae 4541
4542 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4543 vty_out(vty, " bgp listen limit %d\n",
4544 bgp->dynamic_neighbors_limit);
4545
4546 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4547 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4548 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4549 nrnode, range)) {
d62a17ae 4550 vty_out(vty,
2dbe669b
DA
4551 " bgp listen range %pFX peer-group %s\n",
4552 range, group->name);
d62a17ae 4553 }
4554 }
4555 }
f14e6fdb
DS
4556}
4557
4558
1ca2fd11
IR
4559DEFUN (bgp_disable_connected_route_check,
4560 bgp_disable_connected_route_check_cmd,
4561 "bgp disable-ebgp-connected-route-check",
e9273987 4562 BGP_STR
1ca2fd11 4563 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4564{
1ca2fd11
IR
4565 VTY_DECLVAR_CONTEXT(bgp, bgp);
4566 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4567 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 4568
1ca2fd11 4569 return CMD_SUCCESS;
907f92c8
DS
4570}
4571
1ca2fd11
IR
4572DEFUN (no_bgp_disable_connected_route_check,
4573 no_bgp_disable_connected_route_check_cmd,
4574 "no bgp disable-ebgp-connected-route-check",
4575 NO_STR
e9273987 4576 BGP_STR
1ca2fd11 4577 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4578{
1ca2fd11
IR
4579 VTY_DECLVAR_CONTEXT(bgp, bgp);
4580 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4581 bgp_clear_star_soft_in(vty, bgp->name);
d62a17ae 4582
1ca2fd11 4583 return CMD_SUCCESS;
d62a17ae 4584}
4585
4586
28c6e247
IR
4587static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4588 const char *as_str)
4589{
4590 VTY_DECLVAR_CONTEXT(bgp, bgp);
4591 int ret;
4592 as_t as;
4593 int as_type = AS_SPECIFIED;
4594 union sockunion su;
4595
4596 if (as_str[0] == 'i') {
4597 as = 0;
4598 as_type = AS_INTERNAL;
4599 } else if (as_str[0] == 'e') {
4600 as = 0;
4601 as_type = AS_EXTERNAL;
8079a413
PG
4602 } else if (!asn_str2asn(as_str, &as))
4603 as_type = AS_UNSPECIFIED;
28c6e247 4604
8079a413
PG
4605 if (as_type == AS_UNSPECIFIED) {
4606 vty_out(vty, "%% Invalid peer AS: %s\n", as_str);
4607 return CMD_WARNING_CONFIG_FAILED;
4608 }
28c6e247
IR
4609 /* If peer is peer group or interface peer, call proper function. */
4610 ret = str2sockunion(peer_str, &su);
4611 if (ret < 0) {
4612 struct peer *peer;
4613
4614 /* Check if existing interface peer */
4615 peer = peer_lookup_by_conf_if(bgp, peer_str);
4616
de76ed8a 4617 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, as_str);
28c6e247
IR
4618
4619 /* if not interface peer, check peer-group settings */
4620 if (ret < 0 && !peer) {
de76ed8a
PG
4621 ret = peer_group_remote_as(bgp, peer_str, &as, as_type,
4622 as_str);
28c6e247
IR
4623 if (ret < 0) {
4624 vty_out(vty,
4625 "%% Create the peer-group or interface first\n");
4626 return CMD_WARNING_CONFIG_FAILED;
4627 }
4628 return CMD_SUCCESS;
4629 }
4630 } else {
4631 if (peer_address_self_check(bgp, &su)) {
4632 vty_out(vty,
4633 "%% Can not configure the local system as neighbor\n");
4634 return CMD_WARNING_CONFIG_FAILED;
4635 }
de76ed8a 4636 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, as_str);
28c6e247
IR
4637 }
4638
28c6e247
IR
4639 return bgp_vty_return(vty, ret);
4640}
4641
1ca2fd11
IR
4642DEFUN (bgp_default_shutdown,
4643 bgp_default_shutdown_cmd,
4644 "[no] bgp default shutdown",
4645 NO_STR
4646 BGP_STR
4647 "Configure BGP defaults\n"
4648 "Apply administrative shutdown to newly configured peers\n")
ff8a8a7a 4649{
1ca2fd11
IR
4650 VTY_DECLVAR_CONTEXT(bgp, bgp);
4651 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4652 return CMD_SUCCESS;
f26845f9
QY
4653}
4654
736b68f3
DS
4655DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4656 BGP_STR
9ddf4b81 4657 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4658 "Add a shutdown message (RFC 8203)\n"
4659 "Shutdown message\n")
9cf59432 4660{
736b68f3 4661 char *msgstr = NULL;
8389c83a 4662
9cf59432
DS
4663 VTY_DECLVAR_CONTEXT(bgp, bgp);
4664
8389c83a 4665 if (argc > 3)
f80e35b6 4666 msgstr = argv_concat(argv, argc, 3);
8389c83a 4667
b776f48c
DA
4668 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4669 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4670 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4671 return CMD_WARNING_CONFIG_FAILED;
4672 }
4673
8389c83a
DS
4674 bgp_shutdown_enable(bgp, msgstr);
4675 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4676
4677 return CMD_SUCCESS;
4678}
4679
736b68f3 4680DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4681 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4682{
4683 VTY_DECLVAR_CONTEXT(bgp, bgp);
4684
4685 bgp_shutdown_enable(bgp, NULL);
4686
4687 return CMD_SUCCESS;
4688}
8389c83a 4689
736b68f3 4690DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4691 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4692{
4693 VTY_DECLVAR_CONTEXT(bgp, bgp);
4694
4695 bgp_shutdown_disable(bgp);
4696
4697 return CMD_SUCCESS;
4698}
4699
9ddf4b81 4700ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4701 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4702 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4703 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4704
28c6e247
IR
4705DEFUN (neighbor_remote_as,
4706 neighbor_remote_as_cmd,
8079a413 4707 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <ASNUM|internal|external>",
28c6e247
IR
4708 NEIGHBOR_STR
4709 NEIGHBOR_ADDR_STR2
4710 "Specify a BGP neighbor\n"
4711 AS_STR
4712 "Internal BGP peer\n"
4713 "External BGP peer\n")
718e3744 4714{
d62a17ae 4715 int idx_peer = 1;
4716 int idx_remote_as = 3;
28c6e247
IR
4717 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4718 argv[idx_remote_as]->arg);
d62a17ae 4719}
8666265e
DS
4720
4721DEFPY (bgp_allow_martian,
4722 bgp_allow_martian_cmd,
4723 "[no]$no bgp allow-martian-nexthop",
4724 NO_STR
4725 BGP_STR
4726 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4727{
4728 VTY_DECLVAR_CONTEXT(bgp, bgp);
4729
4730 if (no)
4731 bgp->allow_martian = false;
4732 else
4733 bgp->allow_martian = true;
4734
4735 return CMD_SUCCESS;
4736}
4737
f852eb98
PG
4738/* Enable fast convergence of bgp sessions. If this is enabled, bgp
4739 * sessions do not wait for hold timer expiry to bring down the sessions
4740 * when nexthop becomes unreachable
4741 */
4742DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4743 BGP_STR "Fast convergence for bgp sessions\n")
4744{
4745 VTY_DECLVAR_CONTEXT(bgp, bgp);
4746 bgp->fast_convergence = true;
4747
4748 return CMD_SUCCESS;
4749}
4750
4751DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4752 "no bgp fast-convergence",
4753 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4754{
4755 VTY_DECLVAR_CONTEXT(bgp, bgp);
4756 bgp->fast_convergence = false;
4757
4758 return CMD_SUCCESS;
4759}
d62a17ae 4760
28c6e247
IR
4761static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4762 int v6only,
4763 const char *peer_group_name,
4764 const char *as_str)
d62a17ae 4765{
28c6e247
IR
4766 VTY_DECLVAR_CONTEXT(bgp, bgp);
4767 as_t as = 0;
4768 int as_type = AS_UNSPECIFIED;
d62a17ae 4769 struct peer *peer;
4770 struct peer_group *group;
4771 int ret = 0;
d62a17ae 4772
4773 group = peer_group_lookup(bgp, conf_if);
4774
4775 if (group) {
28c6e247
IR
4776 vty_out(vty, "%% Name conflict with peer-group \n");
4777 return CMD_WARNING_CONFIG_FAILED;
4778 }
4779
4780 if (as_str) {
4781 if (as_str[0] == 'i') {
4782 as_type = AS_INTERNAL;
4783 } else if (as_str[0] == 'e') {
4784 as_type = AS_EXTERNAL;
4785 } else {
4786 /* Get AS number. */
8079a413
PG
4787 if (asn_str2asn(as_str, &as))
4788 as_type = AS_SPECIFIED;
28c6e247 4789 }
d62a17ae 4790 }
4791
4792 peer = peer_lookup_by_conf_if(bgp, conf_if);
4793 if (peer) {
28c6e247 4794 if (as_str)
de76ed8a
PG
4795 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
4796 as_str);
d62a17ae 4797 } else {
e84c59af 4798 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
de76ed8a 4799 NULL, true, as_str);
d62a17ae 4800
4801 if (!peer) {
28c6e247
IR
4802 vty_out(vty, "%% BGP failed to create peer\n");
4803 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4804 }
4805
4806 if (v6only)
527de3dc 4807 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4808
4809 /* Request zebra to initiate IPv6 RAs on this interface. We do
4810 * this
4811 * any unnumbered peer in order to not worry about run-time
4812 * transitions
4813 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4814 * address
4815 * gets deleted later etc.)
4816 */
4817 if (peer->ifp)
4818 bgp_zebra_initiate_radv(bgp, peer);
4819 }
4820
4821 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4822 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4823 if (v6only)
527de3dc 4824 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4825 else
527de3dc 4826 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4827
4828 /* v6only flag changed. Reset bgp seesion */
4829 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4830 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4831 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4832 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4833 } else
4834 bgp_session_reset(peer);
4835 }
4836
9fb964de
PM
4837 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4838 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4839 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4840 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4841 }
d62a17ae 4842
4843 if (peer_group_name) {
4844 group = peer_group_lookup(bgp, peer_group_name);
4845 if (!group) {
28c6e247
IR
4846 vty_out(vty, "%% Configure the peer-group first\n");
4847 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4848 }
4849
8395c1f8 4850 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4851 }
4852
28c6e247 4853 return bgp_vty_return(vty, ret);
a80beece
DS
4854}
4855
28c6e247
IR
4856DEFUN (neighbor_interface_config,
4857 neighbor_interface_config_cmd,
4858 "neighbor WORD interface [peer-group PGNAME]",
4859 NEIGHBOR_STR
4860 "Interface name or neighbor tag\n"
4861 "Enable BGP on interface\n"
4862 "Member of the peer-group\n"
4863 "Peer-group name\n")
4c48cf63 4864{
d62a17ae 4865 int idx_word = 1;
4866 int idx_peer_group_word = 4;
f4b8ec07 4867
d62a17ae 4868 if (argc > idx_peer_group_word)
28c6e247
IR
4869 return peer_conf_interface_get(
4870 vty, argv[idx_word]->arg, 0,
4871 argv[idx_peer_group_word]->arg, NULL);
4872 else
4873 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4874 NULL, NULL);
4c48cf63
DW
4875}
4876
28c6e247
IR
4877DEFUN (neighbor_interface_config_v6only,
4878 neighbor_interface_config_v6only_cmd,
4879 "neighbor WORD interface v6only [peer-group PGNAME]",
4880 NEIGHBOR_STR
4881 "Interface name or neighbor tag\n"
4882 "Enable BGP on interface\n"
4883 "Enable BGP with v6 link-local only\n"
4884 "Member of the peer-group\n"
4885 "Peer-group name\n")
4c48cf63 4886{
d62a17ae 4887 int idx_word = 1;
4888 int idx_peer_group_word = 5;
31500417 4889
d62a17ae 4890 if (argc > idx_peer_group_word)
28c6e247
IR
4891 return peer_conf_interface_get(
4892 vty, argv[idx_word]->arg, 1,
4893 argv[idx_peer_group_word]->arg, NULL);
31500417 4894
28c6e247 4895 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4c48cf63
DW
4896}
4897
a80beece 4898
28c6e247
IR
4899DEFUN (neighbor_interface_config_remote_as,
4900 neighbor_interface_config_remote_as_cmd,
8079a413 4901 "neighbor WORD interface remote-as <ASNUM|internal|external>",
28c6e247
IR
4902 NEIGHBOR_STR
4903 "Interface name or neighbor tag\n"
4904 "Enable BGP on interface\n"
4905 "Specify a BGP neighbor\n"
4906 AS_STR
4907 "Internal BGP peer\n"
4908 "External BGP peer\n")
b3a39dc5 4909{
d62a17ae 4910 int idx_word = 1;
4911 int idx_remote_as = 4;
28c6e247
IR
4912 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4913 argv[idx_remote_as]->arg);
b3a39dc5
DD
4914}
4915
28c6e247
IR
4916DEFUN (neighbor_interface_v6only_config_remote_as,
4917 neighbor_interface_v6only_config_remote_as_cmd,
8079a413 4918 "neighbor WORD interface v6only remote-as <ASNUM|internal|external>",
28c6e247
IR
4919 NEIGHBOR_STR
4920 "Interface name or neighbor tag\n"
4921 "Enable BGP with v6 link-local only\n"
4922 "Enable BGP on interface\n"
4923 "Specify a BGP neighbor\n"
4924 AS_STR
4925 "Internal BGP peer\n"
4926 "External BGP peer\n")
b3a39dc5 4927{
d62a17ae 4928 int idx_word = 1;
4929 int idx_remote_as = 5;
28c6e247
IR
4930 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4931 argv[idx_remote_as]->arg);
b3a39dc5
DD
4932}
4933
28c6e247
IR
4934DEFUN (neighbor_peer_group,
4935 neighbor_peer_group_cmd,
4936 "neighbor WORD peer-group",
4937 NEIGHBOR_STR
4938 "Interface name or neighbor tag\n"
4939 "Configure peer-group\n")
718e3744 4940{
28c6e247 4941 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4942 int idx_word = 1;
28c6e247
IR
4943 struct peer *peer;
4944 struct peer_group *group;
718e3744 4945
28c6e247
IR
4946 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4947 if (peer) {
4948 vty_out(vty, "%% Name conflict with interface: \n");
4949 return CMD_WARNING_CONFIG_FAILED;
4950 }
718e3744 4951
28c6e247
IR
4952 group = peer_group_get(bgp, argv[idx_word]->arg);
4953 if (!group) {
4954 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4955 return CMD_WARNING_CONFIG_FAILED;
4956 }
718e3744 4957
28c6e247 4958 return CMD_SUCCESS;
718e3744 4959}
4960
1d80f243
IR
4961DEFUN (no_neighbor,
4962 no_neighbor_cmd,
4963 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4964 NO_STR
4965 NEIGHBOR_STR
4966 NEIGHBOR_ADDR_STR2
4967 "Specify a BGP neighbor\n"
4968 AS_STR
4969 "Internal BGP peer\n"
4970 "External BGP peer\n")
718e3744 4971{
28c6e247 4972 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4973 int idx_peer = 2;
28c6e247 4974 int ret;
d62a17ae 4975 union sockunion su;
28c6e247
IR
4976 struct peer_group *group;
4977 struct peer *peer;
4978 struct peer *other;
d62a17ae 4979
28c6e247
IR
4980 ret = str2sockunion(argv[idx_peer]->arg, &su);
4981 if (ret < 0) {
4982 /* look up for neighbor by interface name config. */
4983 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4984 if (peer) {
4985 /* Request zebra to terminate IPv6 RAs on this
4986 * interface. */
4987 if (peer->ifp)
4988 bgp_zebra_terminate_radv(peer->bgp, peer);
4989 peer_notify_unconfig(peer);
4990 peer_delete(peer);
4991 return CMD_SUCCESS;
d62a17ae 4992 }
28c6e247
IR
4993
4994 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4995 if (group) {
4996 peer_group_notify_unconfig(group);
4997 peer_group_delete(group);
4e2786df 4998 } else {
28c6e247 4999 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 5000 return CMD_WARNING_CONFIG_FAILED;
5001 }
28c6e247
IR
5002 } else {
5003 peer = peer_lookup(bgp, &su);
5004 if (peer) {
5005 if (peer_dynamic_neighbor(peer)) {
5006 vty_out(vty,
5007 "%% Operation not allowed on a dynamic neighbor\n");
5008 return CMD_WARNING_CONFIG_FAILED;
5009 }
d62a17ae 5010
28c6e247 5011 other = peer->doppelganger;
f4b8ec07 5012
28c6e247
IR
5013 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5014 bgp_zebra_terminate_radv(peer->bgp, peer);
f4b8ec07 5015
28c6e247
IR
5016 peer_notify_unconfig(peer);
5017 peer_delete(peer);
5018 if (other && other->status != Deleted) {
5019 peer_notify_unconfig(other);
5020 peer_delete(other);
5021 }
5022 }
5023 }
5024
5025 return CMD_SUCCESS;
a80beece
DS
5026}
5027
28c6e247
IR
5028DEFUN (no_neighbor_interface_config,
5029 no_neighbor_interface_config_cmd,
5030 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
5031 NO_STR
5032 NEIGHBOR_STR
5033 "Interface name\n"
5034 "Configure BGP on interface\n"
5035 "Enable BGP with v6 link-local only\n"
5036 "Member of the peer-group\n"
5037 "Peer-group name\n"
5038 "Specify a BGP neighbor\n"
5039 AS_STR
5040 "Internal BGP peer\n"
5041 "External BGP peer\n")
718e3744 5042{
28c6e247 5043 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5044 int idx_word = 2;
28c6e247 5045 struct peer *peer;
718e3744 5046
28c6e247
IR
5047 /* look up for neighbor by interface name config. */
5048 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
5049 if (peer) {
5050 /* Request zebra to terminate IPv6 RAs on this interface. */
5051 if (peer->ifp)
5052 bgp_zebra_terminate_radv(peer->bgp, peer);
5053 peer_notify_unconfig(peer);
5054 peer_delete(peer);
5055 } else {
5056 vty_out(vty, "%% Create the bgp interface first\n");
5057 return CMD_WARNING_CONFIG_FAILED;
5058 }
5059 return CMD_SUCCESS;
718e3744 5060}
5061
28c6e247
IR
5062DEFUN (no_neighbor_peer_group,
5063 no_neighbor_peer_group_cmd,
5064 "no neighbor WORD peer-group",
5065 NO_STR
5066 NEIGHBOR_STR
5067 "Neighbor tag\n"
5068 "Configure peer-group\n")
718e3744 5069{
28c6e247
IR
5070 VTY_DECLVAR_CONTEXT(bgp, bgp);
5071 int idx_word = 2;
5072 struct peer_group *group;
f4b8ec07 5073
28c6e247
IR
5074 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5075 if (group) {
5076 peer_group_notify_unconfig(group);
5077 peer_group_delete(group);
f4b8ec07 5078 } else {
28c6e247 5079 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 5080 return CMD_WARNING_CONFIG_FAILED;
5081 }
28c6e247
IR
5082 return CMD_SUCCESS;
5083}
f4b8ec07 5084
28c6e247
IR
5085DEFUN (no_neighbor_interface_peer_group_remote_as,
5086 no_neighbor_interface_peer_group_remote_as_cmd,
8079a413 5087 "no neighbor WORD remote-as <ASNUM|internal|external>",
28c6e247
IR
5088 NO_STR
5089 NEIGHBOR_STR
5090 "Interface name or neighbor tag\n"
5091 "Specify a BGP neighbor\n"
5092 AS_STR
5093 "Internal BGP peer\n"
5094 "External BGP peer\n")
5095{
5096 VTY_DECLVAR_CONTEXT(bgp, bgp);
5097 int idx_word = 2;
5098 struct peer_group *group;
5099 struct peer *peer;
f4b8ec07 5100
28c6e247
IR
5101 /* look up for neighbor by interface name config. */
5102 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
5103 if (peer) {
de76ed8a 5104 peer_as_change(peer, 0, AS_UNSPECIFIED, NULL);
28c6e247
IR
5105 return CMD_SUCCESS;
5106 }
f4b8ec07 5107
28c6e247
IR
5108 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5109 if (group)
5110 peer_group_remote_as_delete(group);
5111 else {
5112 vty_out(vty, "%% Create the peer-group or interface first\n");
5113 return CMD_WARNING_CONFIG_FAILED;
5114 }
5115 return CMD_SUCCESS;
718e3744 5116}
6b0655a2 5117
28c6e247
IR
5118DEFUN (neighbor_local_as,
5119 neighbor_local_as_cmd,
8079a413 5120 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM",
28c6e247
IR
5121 NEIGHBOR_STR
5122 NEIGHBOR_ADDR_STR2
5123 "Specify a local-as number\n"
8079a413 5124 "AS number expressed in dotted or plain format used as local AS\n")
718e3744 5125{
d62a17ae 5126 int idx_peer = 1;
5127 int idx_number = 3;
28c6e247
IR
5128 struct peer *peer;
5129 int ret;
5130 as_t as;
718e3744 5131
28c6e247
IR
5132 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5133 if (!peer)
d62a17ae 5134 return CMD_WARNING_CONFIG_FAILED;
718e3744 5135
8079a413
PG
5136 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
5137 vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
5138 argv[idx_number]->arg);
5139 return CMD_WARNING_CONFIG_FAILED;
5140 }
5141
de76ed8a 5142 ret = peer_local_as_set(peer, as, 0, 0, argv[idx_number]->arg);
28c6e247 5143 return bgp_vty_return(vty, ret);
718e3744 5144}
5145
28c6e247
IR
5146DEFUN (neighbor_local_as_no_prepend,
5147 neighbor_local_as_no_prepend_cmd,
8079a413 5148 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM no-prepend",
28c6e247
IR
5149 NEIGHBOR_STR
5150 NEIGHBOR_ADDR_STR2
5151 "Specify a local-as number\n"
8079a413 5152 "AS number expressed in dotted or plain format used as local AS\n"
28c6e247 5153 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 5154{
d62a17ae 5155 int idx_peer = 1;
5156 int idx_number = 3;
28c6e247
IR
5157 struct peer *peer;
5158 int ret;
5159 as_t as;
718e3744 5160
28c6e247
IR
5161 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5162 if (!peer)
d62a17ae 5163 return CMD_WARNING_CONFIG_FAILED;
718e3744 5164
8079a413
PG
5165 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
5166 vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
5167 argv[idx_number]->arg);
5168 return CMD_WARNING_CONFIG_FAILED;
5169 }
5170
de76ed8a 5171 ret = peer_local_as_set(peer, as, 1, 0, argv[idx_number]->arg);
28c6e247 5172 return bgp_vty_return(vty, ret);
718e3744 5173}
5174
28c6e247
IR
5175DEFUN (neighbor_local_as_no_prepend_replace_as,
5176 neighbor_local_as_no_prepend_replace_as_cmd,
8079a413 5177 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM no-prepend replace-as",
28c6e247
IR
5178 NEIGHBOR_STR
5179 NEIGHBOR_ADDR_STR2
5180 "Specify a local-as number\n"
8079a413 5181 "AS number expressed in dotted or plain format used as local AS\n"
28c6e247
IR
5182 "Do not prepend local-as to updates from ebgp peers\n"
5183 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 5184{
d62a17ae 5185 int idx_peer = 1;
5186 int idx_number = 3;
28c6e247
IR
5187 struct peer *peer;
5188 int ret;
5189 as_t as;
9d3f9705 5190
28c6e247
IR
5191 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5192 if (!peer)
d62a17ae 5193 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 5194
8079a413
PG
5195 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
5196 vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
5197 argv[idx_number]->arg);
5198 return CMD_WARNING_CONFIG_FAILED;
5199 }
5200
de76ed8a 5201 ret = peer_local_as_set(peer, as, 1, 1, argv[idx_number]->arg);
28c6e247 5202 return bgp_vty_return(vty, ret);
9d3f9705
AC
5203}
5204
28c6e247
IR
5205DEFUN (no_neighbor_local_as,
5206 no_neighbor_local_as_cmd,
8079a413 5207 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [ASNUM [no-prepend [replace-as]]]",
28c6e247
IR
5208 NO_STR
5209 NEIGHBOR_STR
5210 NEIGHBOR_ADDR_STR2
5211 "Specify a local-as number\n"
8079a413 5212 "AS number expressed in dotted or plain format used as local AS\n"
28c6e247
IR
5213 "Do not prepend local-as to updates from ebgp peers\n"
5214 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 5215{
d62a17ae 5216 int idx_peer = 2;
28c6e247
IR
5217 struct peer *peer;
5218 int ret;
718e3744 5219
28c6e247
IR
5220 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5221 if (!peer)
d62a17ae 5222 return CMD_WARNING_CONFIG_FAILED;
718e3744 5223
28c6e247
IR
5224 ret = peer_local_as_unset(peer);
5225 return bgp_vty_return(vty, ret);
718e3744 5226}
5227
718e3744 5228
3f9c7369
DS
5229DEFUN (neighbor_solo,
5230 neighbor_solo_cmd,
9ccf14f7 5231 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
5232 NEIGHBOR_STR
5233 NEIGHBOR_ADDR_STR2
5234 "Solo peer - part of its own update group\n")
5235{
d62a17ae 5236 int idx_peer = 1;
5237 struct peer *peer;
5238 int ret;
3f9c7369 5239
d62a17ae 5240 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5241 if (!peer)
5242 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 5243
d62a17ae 5244 ret = update_group_adjust_soloness(peer, 1);
5245 return bgp_vty_return(vty, ret);
3f9c7369
DS
5246}
5247
5248DEFUN (no_neighbor_solo,
5249 no_neighbor_solo_cmd,
9ccf14f7 5250 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
5251 NO_STR
5252 NEIGHBOR_STR
5253 NEIGHBOR_ADDR_STR2
5254 "Solo peer - part of its own update group\n")
5255{
d62a17ae 5256 int idx_peer = 2;
5257 struct peer *peer;
5258 int ret;
3f9c7369 5259
d62a17ae 5260 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5261 if (!peer)
5262 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 5263
d62a17ae 5264 ret = update_group_adjust_soloness(peer, 0);
5265 return bgp_vty_return(vty, ret);
3f9c7369
DS
5266}
5267
28c6e247
IR
5268DEFUN (neighbor_password,
5269 neighbor_password_cmd,
5270 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5271 NEIGHBOR_STR
5272 NEIGHBOR_ADDR_STR2
5273 "Set a password\n"
5274 "The password\n")
0df7c91f 5275{
d62a17ae 5276 int idx_peer = 1;
5277 int idx_line = 3;
28c6e247
IR
5278 struct peer *peer;
5279 int ret;
0df7c91f 5280
28c6e247
IR
5281 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5282 if (!peer)
d62a17ae 5283 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 5284
28c6e247
IR
5285 ret = peer_password_set(peer, argv[idx_line]->arg);
5286 return bgp_vty_return(vty, ret);
0df7c91f
PJ
5287}
5288
28c6e247
IR
5289DEFUN (no_neighbor_password,
5290 no_neighbor_password_cmd,
5291 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5292 NO_STR
5293 NEIGHBOR_STR
5294 NEIGHBOR_ADDR_STR2
5295 "Set a password\n"
5296 "The password\n")
0df7c91f 5297{
d62a17ae 5298 int idx_peer = 2;
28c6e247
IR
5299 struct peer *peer;
5300 int ret;
0df7c91f 5301
28c6e247
IR
5302 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5303 if (!peer)
d62a17ae 5304 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 5305
28c6e247
IR
5306 ret = peer_password_unset(peer);
5307 return bgp_vty_return(vty, ret);
0df7c91f 5308}
6b0655a2 5309
28c6e247
IR
5310DEFUN (neighbor_activate,
5311 neighbor_activate_cmd,
5312 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5313 NEIGHBOR_STR
5314 NEIGHBOR_ADDR_STR2
5315 "Enable the Address Family for this Neighbor\n")
718e3744 5316{
d62a17ae 5317 int idx_peer = 1;
28c6e247
IR
5318 int ret;
5319 struct peer *peer;
56ceae84 5320
28c6e247
IR
5321 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5322 if (!peer)
d62a17ae 5323 return CMD_WARNING_CONFIG_FAILED;
718e3744 5324
28c6e247
IR
5325 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5326 return bgp_vty_return(vty, ret);
718e3744 5327}
5328
d62a17ae 5329ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5330 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5331 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5332 "Enable the Address Family for this Neighbor\n")
596c17ba 5333
28c6e247
IR
5334DEFUN (no_neighbor_activate,
5335 no_neighbor_activate_cmd,
5336 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5337 NO_STR
5338 NEIGHBOR_STR
5339 NEIGHBOR_ADDR_STR2
5340 "Enable the Address Family for this Neighbor\n")
718e3744 5341{
d62a17ae 5342 int idx_peer = 2;
28c6e247
IR
5343 int ret;
5344 struct peer *peer;
f4b8ec07 5345
28c6e247
IR
5346 /* Lookup peer. */
5347 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5348 if (!peer)
d62a17ae 5349 return CMD_WARNING_CONFIG_FAILED;
718e3744 5350
28c6e247
IR
5351 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5352 return bgp_vty_return(vty, ret);
718e3744 5353}
6b0655a2 5354
d62a17ae 5355ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5356 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5357 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5358 "Enable the Address Family for this Neighbor\n")
596c17ba 5359
28c6e247
IR
5360DEFUN (neighbor_set_peer_group,
5361 neighbor_set_peer_group_cmd,
5362 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5363 NEIGHBOR_STR
5364 NEIGHBOR_ADDR_STR2
5365 "Member of the peer-group\n"
5366 "Peer-group name\n")
718e3744 5367{
28c6e247 5368 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5369 int idx_peer = 1;
5370 int idx_word = 3;
28c6e247
IR
5371 int ret;
5372 as_t as;
5373 union sockunion su;
5374 struct peer *peer;
5375 struct peer_group *group;
5376
5377 ret = str2sockunion(argv[idx_peer]->arg, &su);
5378 if (ret < 0) {
5379 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5380 if (!peer) {
5381 vty_out(vty, "%% Malformed address or name: %s\n",
5382 argv[idx_peer]->arg);
5383 return CMD_WARNING_CONFIG_FAILED;
5384 }
5385 } else {
5386 if (peer_address_self_check(bgp, &su)) {
5387 vty_out(vty,
5388 "%% Can not configure the local system as neighbor\n");
5389 return CMD_WARNING_CONFIG_FAILED;
5390 }
2a059a54 5391
28c6e247
IR
5392 /* Disallow for dynamic neighbor. */
5393 peer = peer_lookup(bgp, &su);
5394 if (peer && peer_dynamic_neighbor(peer)) {
5395 vty_out(vty,
5396 "%% Operation not allowed on a dynamic neighbor\n");
5397 return CMD_WARNING_CONFIG_FAILED;
5398 }
5399 }
5400
5401 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5402 if (!group) {
5403 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 5404 return CMD_WARNING_CONFIG_FAILED;
28c6e247 5405 }
d62a17ae 5406
28c6e247 5407 ret = peer_group_bind(bgp, &su, peer, group, &as);
2a059a54 5408
28c6e247 5409 return bgp_vty_return(vty, ret);
d62a17ae 5410}
5411
5412ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 5413 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5414 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5415 "Member of the peer-group\n"
5416 "Peer-group name\n")
596c17ba 5417
28c6e247
IR
5418DEFUN (no_neighbor_set_peer_group,
5419 no_neighbor_set_peer_group_cmd,
5420 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5421 NO_STR
5422 NEIGHBOR_STR
5423 NEIGHBOR_ADDR_STR2
5424 "Member of the peer-group\n"
5425 "Peer-group name\n")
718e3744 5426{
28c6e247 5427 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5428 int idx_peer = 2;
28c6e247
IR
5429 int idx_word = 4;
5430 int ret;
5431 struct peer *peer;
5432 struct peer_group *group;
d62a17ae 5433
28c6e247
IR
5434 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5435 if (!peer)
d62a17ae 5436 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 5437
28c6e247
IR
5438 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5439 if (!group) {
5440 vty_out(vty, "%% Configure the peer-group first\n");
5441 return CMD_WARNING_CONFIG_FAILED;
5442 }
718e3744 5443
28c6e247
IR
5444 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5445 bgp_zebra_terminate_radv(peer->bgp, peer);
5446
5447 peer_notify_unconfig(peer);
5448 ret = peer_delete(peer);
5449
5450 return bgp_vty_return(vty, ret);
718e3744 5451}
6b0655a2 5452
d62a17ae 5453ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
71cc0c88 5454 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5455 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5456 "Member of the peer-group\n"
5457 "Peer-group name\n")
596c17ba 5458
718e3744 5459/* neighbor passive. */
28c6e247
IR
5460DEFUN (neighbor_passive,
5461 neighbor_passive_cmd,
5462 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5463 NEIGHBOR_STR
5464 NEIGHBOR_ADDR_STR2
5465 "Don't send open messages to this neighbor\n")
718e3744 5466{
d62a17ae 5467 int idx_peer = 1;
28c6e247 5468 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5469}
5470
28c6e247
IR
5471DEFUN (no_neighbor_passive,
5472 no_neighbor_passive_cmd,
5473 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5474 NO_STR
5475 NEIGHBOR_STR
5476 NEIGHBOR_ADDR_STR2
5477 "Don't send open messages to this neighbor\n")
718e3744 5478{
d62a17ae 5479 int idx_peer = 2;
28c6e247 5480 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5481}
6b0655a2 5482
718e3744 5483/* neighbor shutdown. */
28c6e247
IR
5484DEFUN (neighbor_shutdown_msg,
5485 neighbor_shutdown_msg_cmd,
5486 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5487 NEIGHBOR_STR
5488 NEIGHBOR_ADDR_STR2
5489 "Administratively shut down this neighbor\n"
5490 "Add a shutdown message (RFC 8203)\n"
5491 "Shutdown message\n")
718e3744 5492{
d62a17ae 5493 int idx_peer = 1;
73d70fa6 5494
d62a17ae 5495 if (argc >= 5) {
28c6e247
IR
5496 struct peer *peer =
5497 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
d62a17ae 5498 char *message;
73d70fa6 5499
28c6e247
IR
5500 if (!peer)
5501 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5502 message = argv_concat(argv, argc, 4);
28c6e247
IR
5503 peer_tx_shutdown_message_set(peer, message);
5504 XFREE(MTYPE_TMP, message);
d62a17ae 5505 }
73d70fa6 5506
28c6e247 5507 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 5508}
5509
1d80f243 5510ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5511 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5512 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5513 "Administratively shut down this neighbor\n")
73d70fa6 5514
28c6e247
IR
5515DEFUN (no_neighbor_shutdown_msg,
5516 no_neighbor_shutdown_msg_cmd,
5517 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5518 NO_STR
5519 NEIGHBOR_STR
5520 NEIGHBOR_ADDR_STR2
5521 "Administratively shut down this neighbor\n"
5522 "Remove a shutdown message (RFC 8203)\n"
5523 "Shutdown message\n")
718e3744 5524{
d62a17ae 5525 int idx_peer = 2;
73d70fa6 5526
28c6e247
IR
5527 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5528 PEER_FLAG_SHUTDOWN);
718e3744 5529}
6b0655a2 5530
1d80f243 5531ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5532 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5533 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5534 "Administratively shut down this neighbor\n")
73d70fa6 5535
8336c896
DA
5536DEFUN(neighbor_shutdown_rtt,
5537 neighbor_shutdown_rtt_cmd,
5538 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5539 NEIGHBOR_STR
5540 NEIGHBOR_ADDR_STR2
5541 "Administratively shut down this neighbor\n"
5542 "Shutdown if round-trip-time is higher than expected\n"
5543 "Round-trip-time in milliseconds\n"
5544 "Specify the number of keepalives before shutdown\n"
5545 "The number of keepalives with higher RTT to shutdown\n")
5546{
5547 int idx_peer = 1;
5548 int idx_rtt = 4;
5549 int idx_count = 0;
5550 struct peer *peer;
5551
5552 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5553
5554 if (!peer)
5555 return CMD_WARNING_CONFIG_FAILED;
5556
5557 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5558
5559 if (argv_find(argv, argc, "count", &idx_count))
5560 peer->rtt_keepalive_conf =
5561 strtol(argv[idx_count + 1]->arg, NULL, 10);
5562
5563 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5564 PEER_FLAG_RTT_SHUTDOWN);
5565}
5566
5567DEFUN(no_neighbor_shutdown_rtt,
5568 no_neighbor_shutdown_rtt_cmd,
5569 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5570 NO_STR
5571 NEIGHBOR_STR
5572 NEIGHBOR_ADDR_STR2
5573 "Administratively shut down this neighbor\n"
5574 "Shutdown if round-trip-time is higher than expected\n"
5575 "Round-trip-time in milliseconds\n"
5576 "Specify the number of keepalives before shutdown\n"
5577 "The number of keepalives with higher RTT to shutdown\n")
5578{
5579 int idx_peer = 2;
5580 struct peer *peer;
5581
5582 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5583
5584 if (!peer)
5585 return CMD_WARNING_CONFIG_FAILED;
5586
5587 peer->rtt_expected = 0;
5588 peer->rtt_keepalive_conf = 1;
5589
5590 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5591 PEER_FLAG_RTT_SHUTDOWN);
5592}
5593
718e3744 5594/* neighbor capability dynamic. */
28c6e247
IR
5595DEFUN (neighbor_capability_dynamic,
5596 neighbor_capability_dynamic_cmd,
5597 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5598 NEIGHBOR_STR
5599 NEIGHBOR_ADDR_STR2
5600 "Advertise capability to the peer\n"
5601 "Advertise dynamic capability to this neighbor\n")
718e3744 5602{
d62a17ae 5603 int idx_peer = 1;
28c6e247
IR
5604 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5605 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5606}
5607
28c6e247
IR
5608DEFUN (no_neighbor_capability_dynamic,
5609 no_neighbor_capability_dynamic_cmd,
5610 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5611 NO_STR
5612 NEIGHBOR_STR
5613 NEIGHBOR_ADDR_STR2
5614 "Advertise capability to the peer\n"
5615 "Advertise dynamic capability to this neighbor\n")
718e3744 5616{
d62a17ae 5617 int idx_peer = 2;
28c6e247
IR
5618 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5619 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5620}
6b0655a2 5621
718e3744 5622/* neighbor dont-capability-negotiate */
5623DEFUN (neighbor_dont_capability_negotiate,
5624 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5625 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5626 NEIGHBOR_STR
5627 NEIGHBOR_ADDR_STR2
5628 "Do not perform capability negotiation\n")
5629{
d62a17ae 5630 int idx_peer = 1;
5631 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5632 PEER_FLAG_DONT_CAPABILITY);
718e3744 5633}
5634
5635DEFUN (no_neighbor_dont_capability_negotiate,
5636 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5637 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5638 NO_STR
5639 NEIGHBOR_STR
5640 NEIGHBOR_ADDR_STR2
5641 "Do not perform capability negotiation\n")
5642{
28c6e247
IR
5643 int idx_peer = 2;
5644 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5645 PEER_FLAG_DONT_CAPABILITY);
f4b8ec07
CS
5646}
5647
28c6e247
IR
5648/* neighbor capability extended next hop encoding */
5649DEFUN (neighbor_capability_enhe,
5650 neighbor_capability_enhe_cmd,
5651 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5652 NEIGHBOR_STR
5653 NEIGHBOR_ADDR_STR2
5654 "Advertise capability to the peer\n"
5655 "Advertise extended next-hop capability to the peer\n")
f4b8ec07 5656{
28c6e247 5657 int idx_peer = 1;
c4786405
DS
5658 struct peer *peer;
5659
5660 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5661 if (peer && peer->conf_if)
5662 return CMD_SUCCESS;
5663
28c6e247
IR
5664 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5665 PEER_FLAG_CAPABILITY_ENHE);
5666}
f4b8ec07 5667
28c6e247
IR
5668DEFUN (no_neighbor_capability_enhe,
5669 no_neighbor_capability_enhe_cmd,
5670 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5671 NO_STR
5672 NEIGHBOR_STR
5673 NEIGHBOR_ADDR_STR2
5674 "Advertise capability to the peer\n"
5675 "Advertise extended next-hop capability to the peer\n")
5676{
5677 int idx_peer = 2;
c4786405
DS
5678 struct peer *peer;
5679
5680 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5681 if (peer && peer->conf_if) {
5682 vty_out(vty,
5683 "Peer %s cannot have capability extended-nexthop turned off\n",
5684 argv[idx_peer]->arg);
5685 return CMD_WARNING_CONFIG_FAILED;
5686 }
5687
28c6e247
IR
5688 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5689 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5690}
5691
234f6fd4
DA
5692/* neighbor capability software-version */
5693DEFPY(neighbor_capability_software_version,
5694 neighbor_capability_software_version_cmd,
5695 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor capability software-version",
5696 NO_STR
5697 NEIGHBOR_STR
5698 NEIGHBOR_ADDR_STR2
5699 "Advertise capability to the peer\n"
5700 "Advertise Software Version capability to the peer\n")
5701{
5702 struct peer *peer;
5703
5704 peer = peer_and_group_lookup_vty(vty, neighbor);
5705 if (peer && peer->conf_if)
5706 return CMD_SUCCESS;
5707
5708 if (no)
5709 return peer_flag_unset_vty(vty, neighbor,
5710 PEER_FLAG_CAPABILITY_SOFT_VERSION);
5711 else
5712 return peer_flag_set_vty(vty, neighbor,
5713 PEER_FLAG_CAPABILITY_SOFT_VERSION);
5714}
5715
d62a17ae 5716static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d782e3ff 5717 afi_t afi, safi_t safi, uint64_t flag,
d62a17ae 5718 int set)
718e3744 5719{
d62a17ae 5720 int ret;
5721 struct peer *peer;
718e3744 5722
d62a17ae 5723 peer = peer_and_group_lookup_vty(vty, peer_str);
5724 if (!peer)
5725 return CMD_WARNING_CONFIG_FAILED;
718e3744 5726
d62a17ae 5727 if (set)
5728 ret = peer_af_flag_set(peer, afi, safi, flag);
5729 else
5730 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5731
d62a17ae 5732 return bgp_vty_return(vty, ret);
718e3744 5733}
5734
d62a17ae 5735static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d782e3ff 5736 afi_t afi, safi_t safi, uint64_t flag)
718e3744 5737{
d62a17ae 5738 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5739}
5740
d62a17ae 5741static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d782e3ff 5742 afi_t afi, safi_t safi, uint64_t flag)
718e3744 5743{
d62a17ae 5744 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5745}
6b0655a2 5746
718e3744 5747/* neighbor capability orf prefix-list. */
5748DEFUN (neighbor_capability_orf_prefix,
5749 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5750 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5751 NEIGHBOR_STR
5752 NEIGHBOR_ADDR_STR2
5753 "Advertise capability to the peer\n"
5754 "Advertise ORF capability to the peer\n"
5755 "Advertise prefixlist ORF capability to this neighbor\n"
5756 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5757 "Capability to RECEIVE the ORF from this neighbor\n"
5758 "Capability to SEND the ORF to this neighbor\n")
5759{
d62a17ae 5760 int idx_send_recv = 5;
db45f64d
DS
5761 char *peer_str = argv[1]->arg;
5762 struct peer *peer;
5763 afi_t afi = bgp_node_afi(vty);
5764 safi_t safi = bgp_node_safi(vty);
d62a17ae 5765
db45f64d
DS
5766 peer = peer_and_group_lookup_vty(vty, peer_str);
5767 if (!peer)
d62a17ae 5768 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5769
db45f64d
DS
5770 if (strmatch(argv[idx_send_recv]->text, "send"))
5771 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5772 PEER_FLAG_ORF_PREFIX_SM);
5773
5774 if (strmatch(argv[idx_send_recv]->text, "receive"))
5775 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5776 PEER_FLAG_ORF_PREFIX_RM);
5777
5778 if (strmatch(argv[idx_send_recv]->text, "both"))
5779 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5780 PEER_FLAG_ORF_PREFIX_SM)
5781 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5782 PEER_FLAG_ORF_PREFIX_RM);
5783
5784 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5785}
5786
5787ALIAS_HIDDEN(
5788 neighbor_capability_orf_prefix,
5789 neighbor_capability_orf_prefix_hidden_cmd,
5790 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5791 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5792 "Advertise capability to the peer\n"
5793 "Advertise ORF capability to the peer\n"
5794 "Advertise prefixlist ORF capability to this neighbor\n"
5795 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5796 "Capability to RECEIVE the ORF from this neighbor\n"
5797 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5798
718e3744 5799DEFUN (no_neighbor_capability_orf_prefix,
5800 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5801 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5802 NO_STR
5803 NEIGHBOR_STR
5804 NEIGHBOR_ADDR_STR2
5805 "Advertise capability to the peer\n"
5806 "Advertise ORF capability to the peer\n"
5807 "Advertise prefixlist ORF capability to this neighbor\n"
5808 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5809 "Capability to RECEIVE the ORF from this neighbor\n"
5810 "Capability to SEND the ORF to this neighbor\n")
5811{
d62a17ae 5812 int idx_send_recv = 6;
db45f64d
DS
5813 char *peer_str = argv[2]->arg;
5814 struct peer *peer;
5815 afi_t afi = bgp_node_afi(vty);
5816 safi_t safi = bgp_node_safi(vty);
d62a17ae 5817
db45f64d
DS
5818 peer = peer_and_group_lookup_vty(vty, peer_str);
5819 if (!peer)
d62a17ae 5820 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5821
db45f64d
DS
5822 if (strmatch(argv[idx_send_recv]->text, "send"))
5823 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5824 PEER_FLAG_ORF_PREFIX_SM);
5825
5826 if (strmatch(argv[idx_send_recv]->text, "receive"))
5827 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5828 PEER_FLAG_ORF_PREFIX_RM);
5829
5830 if (strmatch(argv[idx_send_recv]->text, "both"))
5831 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5832 PEER_FLAG_ORF_PREFIX_SM)
5833 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5834 PEER_FLAG_ORF_PREFIX_RM);
5835
5836 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5837}
5838
5839ALIAS_HIDDEN(
5840 no_neighbor_capability_orf_prefix,
5841 no_neighbor_capability_orf_prefix_hidden_cmd,
5842 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5843 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5844 "Advertise capability to the peer\n"
5845 "Advertise ORF capability to the peer\n"
5846 "Advertise prefixlist ORF capability to this neighbor\n"
5847 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5848 "Capability to RECEIVE the ORF from this neighbor\n"
5849 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5850
718e3744 5851/* neighbor next-hop-self. */
28c6e247
IR
5852DEFUN (neighbor_nexthop_self,
5853 neighbor_nexthop_self_cmd,
5854 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5855 NEIGHBOR_STR
5856 NEIGHBOR_ADDR_STR2
5857 "Disable the next hop calculation for this neighbor\n")
718e3744 5858{
d62a17ae 5859 int idx_peer = 1;
28c6e247
IR
5860 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5861 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 5862}
9e7a53c1 5863
d62a17ae 5864ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5865 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5866 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5867 "Disable the next hop calculation for this neighbor\n")
596c17ba 5868
f4b8ec07 5869/* neighbor next-hop-self. */
28c6e247
IR
5870DEFUN (neighbor_nexthop_self_force,
5871 neighbor_nexthop_self_force_cmd,
5872 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5873 NEIGHBOR_STR
5874 NEIGHBOR_ADDR_STR2
5875 "Disable the next hop calculation for this neighbor\n"
5876 "Set the next hop to self for reflected routes\n")
f4b8ec07
CS
5877{
5878 int idx_peer = 1;
28c6e247
IR
5879 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5880 bgp_node_safi(vty),
5881 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 5882}
5883
d62a17ae 5884ALIAS_HIDDEN(neighbor_nexthop_self_force,
5885 neighbor_nexthop_self_force_hidden_cmd,
5886 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5887 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5888 "Disable the next hop calculation for this neighbor\n"
5889 "Set the next hop to self for reflected routes\n")
596c17ba 5890
1bc4e531
DA
5891ALIAS_HIDDEN(neighbor_nexthop_self_force,
5892 neighbor_nexthop_self_all_hidden_cmd,
5893 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5894 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5895 "Disable the next hop calculation for this neighbor\n"
5896 "Set the next hop to self for reflected routes\n")
5897
28c6e247
IR
5898DEFUN (no_neighbor_nexthop_self,
5899 no_neighbor_nexthop_self_cmd,
5900 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5901 NO_STR
5902 NEIGHBOR_STR
5903 NEIGHBOR_ADDR_STR2
5904 "Disable the next hop calculation for this neighbor\n")
718e3744 5905{
d62a17ae 5906 int idx_peer = 2;
28c6e247
IR
5907 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5908 bgp_node_afi(vty), bgp_node_safi(vty),
5909 PEER_FLAG_NEXTHOP_SELF);
718e3744 5910}
6b0655a2 5911
d62a17ae 5912ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5913 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5914 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5915 "Disable the next hop calculation for this neighbor\n")
596c17ba 5916
28c6e247
IR
5917DEFUN (no_neighbor_nexthop_self_force,
5918 no_neighbor_nexthop_self_force_cmd,
5919 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5920 NO_STR
5921 NEIGHBOR_STR
5922 NEIGHBOR_ADDR_STR2
5923 "Disable the next hop calculation for this neighbor\n"
5924 "Set the next hop to self for reflected routes\n")
88b8ed8d 5925{
d62a17ae 5926 int idx_peer = 2;
28c6e247
IR
5927 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5928 bgp_node_afi(vty), bgp_node_safi(vty),
5929 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5930}
a538debe 5931
d62a17ae 5932ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5933 no_neighbor_nexthop_self_force_hidden_cmd,
5934 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5935 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5936 "Disable the next hop calculation for this neighbor\n"
5937 "Set the next hop to self for reflected routes\n")
596c17ba 5938
1bc4e531
DA
5939ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5940 no_neighbor_nexthop_self_all_hidden_cmd,
5941 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5942 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5943 "Disable the next hop calculation for this neighbor\n"
5944 "Set the next hop to self for reflected routes\n")
5945
c7122e14 5946/* neighbor as-override */
28c6e247
IR
5947DEFUN (neighbor_as_override,
5948 neighbor_as_override_cmd,
5949 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5950 NEIGHBOR_STR
5951 NEIGHBOR_ADDR_STR2
5952 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5953{
d62a17ae 5954 int idx_peer = 1;
28c6e247
IR
5955 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5956 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5957}
5958
d62a17ae 5959ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5960 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5961 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5962 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5963
28c6e247
IR
5964DEFUN (no_neighbor_as_override,
5965 no_neighbor_as_override_cmd,
5966 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5967 NO_STR
5968 NEIGHBOR_STR
5969 NEIGHBOR_ADDR_STR2
5970 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5971{
d62a17ae 5972 int idx_peer = 2;
28c6e247
IR
5973 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5974 bgp_node_afi(vty), bgp_node_safi(vty),
5975 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5976}
5977
d62a17ae 5978ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5979 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5980 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5981 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5982
718e3744 5983/* neighbor remove-private-AS. */
28c6e247
IR
5984DEFUN (neighbor_remove_private_as,
5985 neighbor_remove_private_as_cmd,
5986 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5987 NEIGHBOR_STR
5988 NEIGHBOR_ADDR_STR2
5989 "Remove private ASNs in outbound updates\n")
718e3744 5990{
d62a17ae 5991 int idx_peer = 1;
28c6e247
IR
5992 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5993 bgp_node_safi(vty),
5994 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5995}
5996
d62a17ae 5997ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5998 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5999 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6000 "Remove private ASNs in outbound updates\n")
596c17ba 6001
28c6e247
IR
6002DEFUN (neighbor_remove_private_as_all,
6003 neighbor_remove_private_as_all_cmd,
6004 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6005 NEIGHBOR_STR
6006 NEIGHBOR_ADDR_STR2
6007 "Remove private ASNs in outbound updates\n"
6008 "Apply to all AS numbers\n")
5000f21c 6009{
d62a17ae 6010 int idx_peer = 1;
28c6e247
IR
6011 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6012 bgp_node_safi(vty),
6013 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
6014}
6015
d62a17ae 6016ALIAS_HIDDEN(neighbor_remove_private_as_all,
6017 neighbor_remove_private_as_all_hidden_cmd,
6018 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6019 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6020 "Remove private ASNs in outbound updates\n"
a0dfca37 6021 "Apply to all AS numbers\n")
596c17ba 6022
28c6e247
IR
6023DEFUN (neighbor_remove_private_as_replace_as,
6024 neighbor_remove_private_as_replace_as_cmd,
6025 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6026 NEIGHBOR_STR
6027 NEIGHBOR_ADDR_STR2
6028 "Remove private ASNs in outbound updates\n"
6029 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 6030{
d62a17ae 6031 int idx_peer = 1;
28c6e247
IR
6032 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6033 bgp_node_safi(vty),
6034 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
6035}
6036
d62a17ae 6037ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
6038 neighbor_remove_private_as_replace_as_hidden_cmd,
6039 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6040 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6041 "Remove private ASNs in outbound updates\n"
6042 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6043
28c6e247
IR
6044DEFUN (neighbor_remove_private_as_all_replace_as,
6045 neighbor_remove_private_as_all_replace_as_cmd,
6046 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6047 NEIGHBOR_STR
6048 NEIGHBOR_ADDR_STR2
6049 "Remove private ASNs in outbound updates\n"
6050 "Apply to all AS numbers\n"
6051 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 6052{
d62a17ae 6053 int idx_peer = 1;
28c6e247
IR
6054 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6055 bgp_node_safi(vty),
6056 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
6057}
6058
d62a17ae 6059ALIAS_HIDDEN(
6060 neighbor_remove_private_as_all_replace_as,
6061 neighbor_remove_private_as_all_replace_as_hidden_cmd,
6062 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6063 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6064 "Remove private ASNs in outbound updates\n"
6065 "Apply to all AS numbers\n"
6066 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6067
28c6e247
IR
6068DEFUN (no_neighbor_remove_private_as,
6069 no_neighbor_remove_private_as_cmd,
6070 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6071 NO_STR
6072 NEIGHBOR_STR
6073 NEIGHBOR_ADDR_STR2
6074 "Remove private ASNs in outbound updates\n")
718e3744 6075{
d62a17ae 6076 int idx_peer = 2;
28c6e247
IR
6077 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6078 bgp_node_afi(vty), bgp_node_safi(vty),
6079 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 6080}
6b0655a2 6081
d62a17ae 6082ALIAS_HIDDEN(no_neighbor_remove_private_as,
6083 no_neighbor_remove_private_as_hidden_cmd,
6084 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6085 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6086 "Remove private ASNs in outbound updates\n")
596c17ba 6087
28c6e247
IR
6088DEFUN (no_neighbor_remove_private_as_all,
6089 no_neighbor_remove_private_as_all_cmd,
6090 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6091 NO_STR
6092 NEIGHBOR_STR
6093 NEIGHBOR_ADDR_STR2
6094 "Remove private ASNs in outbound updates\n"
6095 "Apply to all AS numbers\n")
88b8ed8d 6096{
d62a17ae 6097 int idx_peer = 2;
28c6e247
IR
6098 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6099 bgp_node_afi(vty), bgp_node_safi(vty),
6100 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 6101}
5000f21c 6102
d62a17ae 6103ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
6104 no_neighbor_remove_private_as_all_hidden_cmd,
6105 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6106 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6107 "Remove private ASNs in outbound updates\n"
6108 "Apply to all AS numbers\n")
596c17ba 6109
28c6e247
IR
6110DEFUN (no_neighbor_remove_private_as_replace_as,
6111 no_neighbor_remove_private_as_replace_as_cmd,
6112 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6113 NO_STR
6114 NEIGHBOR_STR
6115 NEIGHBOR_ADDR_STR2
6116 "Remove private ASNs in outbound updates\n"
6117 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 6118{
d62a17ae 6119 int idx_peer = 2;
28c6e247
IR
6120 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6121 bgp_node_afi(vty), bgp_node_safi(vty),
6122 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 6123}
5000f21c 6124
d62a17ae 6125ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
6126 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6127 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6128 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6129 "Remove private ASNs in outbound updates\n"
6130 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6131
28c6e247
IR
6132DEFUN (no_neighbor_remove_private_as_all_replace_as,
6133 no_neighbor_remove_private_as_all_replace_as_cmd,
6134 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6135 NO_STR
6136 NEIGHBOR_STR
6137 NEIGHBOR_ADDR_STR2
6138 "Remove private ASNs in outbound updates\n"
6139 "Apply to all AS numbers\n"
6140 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 6141{
d62a17ae 6142 int idx_peer = 2;
28c6e247
IR
6143 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6144 bgp_node_afi(vty), bgp_node_safi(vty),
6145 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 6146}
5000f21c 6147
d62a17ae 6148ALIAS_HIDDEN(
6149 no_neighbor_remove_private_as_all_replace_as,
6150 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6151 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6152 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6153 "Remove private ASNs in outbound updates\n"
6154 "Apply to all AS numbers\n"
6155 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6156
5000f21c 6157
718e3744 6158/* neighbor send-community. */
28c6e247
IR
6159DEFUN (neighbor_send_community,
6160 neighbor_send_community_cmd,
6161 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6162 NEIGHBOR_STR
6163 NEIGHBOR_ADDR_STR2
6164 "Send Community attribute to this neighbor\n")
718e3744 6165{
d62a17ae 6166 int idx_peer = 1;
27c05d4d 6167
f63d4054
IR
6168 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6169 bgp_node_safi(vty),
6170 PEER_FLAG_SEND_COMMUNITY);
718e3744 6171}
6172
d62a17ae 6173ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6174 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6175 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6176 "Send Community attribute to this neighbor\n")
596c17ba 6177
28c6e247
IR
6178DEFUN (no_neighbor_send_community,
6179 no_neighbor_send_community_cmd,
6180 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6181 NO_STR
6182 NEIGHBOR_STR
6183 NEIGHBOR_ADDR_STR2
6184 "Send Community attribute to this neighbor\n")
718e3744 6185{
d62a17ae 6186 int idx_peer = 2;
27c05d4d 6187
f63d4054
IR
6188 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6189 bgp_node_afi(vty), bgp_node_safi(vty),
6190 PEER_FLAG_SEND_COMMUNITY);
718e3744 6191}
6b0655a2 6192
d62a17ae 6193ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6194 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6195 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6196 "Send Community attribute to this neighbor\n")
596c17ba 6197
718e3744 6198/* neighbor send-community extended. */
28c6e247
IR
6199DEFUN (neighbor_send_community_type,
6200 neighbor_send_community_type_cmd,
6201 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6202 NEIGHBOR_STR
6203 NEIGHBOR_ADDR_STR2
6204 "Send Community attribute to this neighbor\n"
6205 "Send Standard and Extended Community attributes\n"
6206 "Send Standard, Large and Extended Community attributes\n"
6207 "Send Extended Community attributes\n"
6208 "Send Standard Community attributes\n"
6209 "Send Large Community attributes\n")
718e3744 6210{
27c05d4d 6211 const char *type = argv[argc - 1]->text;
db45f64d 6212 char *peer_str = argv[1]->arg;
28c6e247 6213 struct peer *peer;
db45f64d 6214 afi_t afi = bgp_node_afi(vty);
28c6e247 6215 safi_t safi = bgp_node_safi(vty);
f4b8ec07 6216
28c6e247
IR
6217 peer = peer_and_group_lookup_vty(vty, peer_str);
6218 if (!peer)
6219 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07 6220
28c6e247
IR
6221 if (strmatch(type, "standard"))
6222 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6223 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 6224
28c6e247
IR
6225 if (strmatch(type, "extended"))
6226 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6227 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6228
28c6e247
IR
6229 if (strmatch(type, "large"))
6230 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6231 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07 6232
28c6e247
IR
6233 if (strmatch(type, "both")) {
6234 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6235 PEER_FLAG_SEND_COMMUNITY)
6236 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6237 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6238 }
28c6e247
IR
6239 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6240 PEER_FLAG_SEND_COMMUNITY)
6241 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6242 PEER_FLAG_SEND_EXT_COMMUNITY)
6243 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6244 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 6245}
6246
6247ALIAS_HIDDEN(
6248 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6249 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6250 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6251 "Send Community attribute to this neighbor\n"
6252 "Send Standard and Extended Community attributes\n"
6253 "Send Standard, Large and Extended Community attributes\n"
6254 "Send Extended Community attributes\n"
6255 "Send Standard Community attributes\n"
6256 "Send Large Community attributes\n")
596c17ba 6257
28c6e247
IR
6258DEFUN (no_neighbor_send_community_type,
6259 no_neighbor_send_community_type_cmd,
6260 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6261 NO_STR
6262 NEIGHBOR_STR
6263 NEIGHBOR_ADDR_STR2
6264 "Send Community attribute to this neighbor\n"
6265 "Send Standard and Extended Community attributes\n"
6266 "Send Standard, Large and Extended Community attributes\n"
6267 "Send Extended Community attributes\n"
6268 "Send Standard Community attributes\n"
6269 "Send Large Community attributes\n")
718e3744 6270{
d62a17ae 6271 const char *type = argv[argc - 1]->text;
db45f64d 6272 char *peer_str = argv[2]->arg;
28c6e247 6273 struct peer *peer;
db45f64d
DS
6274 afi_t afi = bgp_node_afi(vty);
6275 safi_t safi = bgp_node_safi(vty);
6276
28c6e247
IR
6277 peer = peer_and_group_lookup_vty(vty, peer_str);
6278 if (!peer)
f4b8ec07
CS
6279 return CMD_WARNING_CONFIG_FAILED;
6280
28c6e247
IR
6281 if (strmatch(type, "standard"))
6282 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6283 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 6284
28c6e247
IR
6285 if (strmatch(type, "extended"))
6286 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6287 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6288
28c6e247
IR
6289 if (strmatch(type, "large"))
6290 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6291 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07
CS
6292
6293 if (strmatch(type, "both")) {
db45f64d 6294
28c6e247
IR
6295 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6296 PEER_FLAG_SEND_COMMUNITY)
6297 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6298 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
6299 }
6300
28c6e247
IR
6301 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6302 PEER_FLAG_SEND_COMMUNITY)
6303 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6304 PEER_FLAG_SEND_EXT_COMMUNITY)
6305 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6306 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 6307}
6308
6309ALIAS_HIDDEN(
6310 no_neighbor_send_community_type,
6311 no_neighbor_send_community_type_hidden_cmd,
6312 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6313 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6314 "Send Community attribute to this neighbor\n"
6315 "Send Standard and Extended Community attributes\n"
6316 "Send Standard, Large and Extended Community attributes\n"
6317 "Send Extended Community attributes\n"
6318 "Send Standard Community attributes\n"
6319 "Send Large Community attributes\n")
596c17ba 6320
718e3744 6321/* neighbor soft-reconfig. */
28c6e247
IR
6322DEFUN (neighbor_soft_reconfiguration,
6323 neighbor_soft_reconfiguration_cmd,
6324 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6325 NEIGHBOR_STR
6326 NEIGHBOR_ADDR_STR2
6327 "Per neighbor soft reconfiguration\n"
6328 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6329{
d62a17ae 6330 int idx_peer = 1;
28c6e247
IR
6331 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6332 bgp_node_safi(vty),
6333 PEER_FLAG_SOFT_RECONFIG);
718e3744 6334}
6335
d62a17ae 6336ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6337 neighbor_soft_reconfiguration_hidden_cmd,
6338 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6339 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6340 "Per neighbor soft reconfiguration\n"
6341 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6342
28c6e247
IR
6343DEFUN (no_neighbor_soft_reconfiguration,
6344 no_neighbor_soft_reconfiguration_cmd,
6345 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6346 NO_STR
6347 NEIGHBOR_STR
6348 NEIGHBOR_ADDR_STR2
6349 "Per neighbor soft reconfiguration\n"
6350 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6351{
d62a17ae 6352 int idx_peer = 2;
28c6e247
IR
6353 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6354 bgp_node_afi(vty), bgp_node_safi(vty),
6355 PEER_FLAG_SOFT_RECONFIG);
718e3744 6356}
6b0655a2 6357
d62a17ae 6358ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6359 no_neighbor_soft_reconfiguration_hidden_cmd,
6360 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6361 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6362 "Per neighbor soft reconfiguration\n"
6363 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6364
28c6e247
IR
6365DEFUN (neighbor_route_reflector_client,
6366 neighbor_route_reflector_client_cmd,
6367 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6368 NEIGHBOR_STR
6369 NEIGHBOR_ADDR_STR2
6370 "Configure a neighbor as Route Reflector client\n")
718e3744 6371{
d62a17ae 6372 int idx_peer = 1;
28c6e247 6373 struct peer *peer;
718e3744 6374
6375
28c6e247
IR
6376 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6377 if (!peer)
d62a17ae 6378 return CMD_WARNING_CONFIG_FAILED;
718e3744 6379
28c6e247
IR
6380 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6381 bgp_node_safi(vty),
6382 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 6383}
6384
d62a17ae 6385ALIAS_HIDDEN(neighbor_route_reflector_client,
6386 neighbor_route_reflector_client_hidden_cmd,
6387 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6388 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6389 "Configure a neighbor as Route Reflector client\n")
596c17ba 6390
28c6e247
IR
6391DEFUN (no_neighbor_route_reflector_client,
6392 no_neighbor_route_reflector_client_cmd,
6393 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6394 NO_STR
6395 NEIGHBOR_STR
6396 NEIGHBOR_ADDR_STR2
6397 "Configure a neighbor as Route Reflector client\n")
718e3744 6398{
d62a17ae 6399 int idx_peer = 2;
28c6e247
IR
6400 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6401 bgp_node_afi(vty), bgp_node_safi(vty),
6402 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 6403}
6b0655a2 6404
d62a17ae 6405ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6406 no_neighbor_route_reflector_client_hidden_cmd,
6407 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6408 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6409 "Configure a neighbor as Route Reflector client\n")
596c17ba 6410
718e3744 6411/* neighbor route-server-client. */
28c6e247
IR
6412DEFUN (neighbor_route_server_client,
6413 neighbor_route_server_client_cmd,
6414 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6415 NEIGHBOR_STR
6416 NEIGHBOR_ADDR_STR2
6417 "Configure a neighbor as Route Server client\n")
718e3744 6418{
d62a17ae 6419 int idx_peer = 1;
28c6e247 6420 struct peer *peer;
f4b8ec07 6421
28c6e247
IR
6422 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6423 if (!peer)
d62a17ae 6424 return CMD_WARNING_CONFIG_FAILED;
28c6e247
IR
6425 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6426 bgp_node_safi(vty),
6427 PEER_FLAG_RSERVER_CLIENT);
718e3744 6428}
6429
d62a17ae 6430ALIAS_HIDDEN(neighbor_route_server_client,
6431 neighbor_route_server_client_hidden_cmd,
6432 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6433 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6434 "Configure a neighbor as Route Server client\n")
596c17ba 6435
28c6e247
IR
6436DEFUN (no_neighbor_route_server_client,
6437 no_neighbor_route_server_client_cmd,
6438 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6439 NO_STR
6440 NEIGHBOR_STR
6441 NEIGHBOR_ADDR_STR2
6442 "Configure a neighbor as Route Server client\n")
fee0f4c6 6443{
d62a17ae 6444 int idx_peer = 2;
28c6e247
IR
6445 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6446 bgp_node_afi(vty), bgp_node_safi(vty),
6447 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 6448}
6b0655a2 6449
d62a17ae 6450ALIAS_HIDDEN(no_neighbor_route_server_client,
6451 no_neighbor_route_server_client_hidden_cmd,
6452 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6453 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6454 "Configure a neighbor as Route Server client\n")
596c17ba 6455
fee0f4c6 6456DEFUN (neighbor_nexthop_local_unchanged,
6457 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6458 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6459 NEIGHBOR_STR
6460 NEIGHBOR_ADDR_STR2
6461 "Configure treatment of outgoing link-local nexthop attribute\n"
6462 "Leave link-local nexthop unchanged for this peer\n")
6463{
d62a17ae 6464 int idx_peer = 1;
6465 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6466 bgp_node_safi(vty),
6467 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6468}
6b0655a2 6469
fee0f4c6 6470DEFUN (no_neighbor_nexthop_local_unchanged,
6471 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6472 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6473 NO_STR
6474 NEIGHBOR_STR
6475 NEIGHBOR_ADDR_STR2
6476 "Configure treatment of outgoing link-local-nexthop attribute\n"
6477 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6478{
d62a17ae 6479 int idx_peer = 2;
6480 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6481 bgp_node_afi(vty), bgp_node_safi(vty),
6482 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6483}
6b0655a2 6484
28c6e247
IR
6485DEFUN (neighbor_attr_unchanged,
6486 neighbor_attr_unchanged_cmd,
6487 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6488 NEIGHBOR_STR
6489 NEIGHBOR_ADDR_STR2
6490 "BGP attribute is propagated unchanged to this neighbor\n"
6491 "As-path attribute\n"
6492 "Nexthop attribute\n"
6493 "Med attribute\n")
718e3744 6494{
d62a17ae 6495 int idx = 0;
8eeb0335 6496 char *peer_str = argv[1]->arg;
28c6e247 6497 struct peer *peer;
db45f64d
DS
6498 bool aspath = false;
6499 bool nexthop = false;
6500 bool med = false;
8eeb0335
DW
6501 afi_t afi = bgp_node_afi(vty);
6502 safi_t safi = bgp_node_safi(vty);
28c6e247 6503 int ret = 0;
f4b8ec07 6504
28c6e247
IR
6505 peer = peer_and_group_lookup_vty(vty, peer_str);
6506 if (!peer)
8eeb0335 6507 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6508
6509 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6510 aspath = true;
6511
d62a17ae 6512 idx = 0;
6513 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6514 nexthop = true;
6515
d62a17ae 6516 idx = 0;
6517 if (argv_find(argv, argc, "med", &idx))
db45f64d 6518 med = true;
d62a17ae 6519
8eeb0335 6520 /* no flags means all of them! */
db45f64d 6521 if (!aspath && !nexthop && !med) {
28c6e247
IR
6522 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6523 PEER_FLAG_AS_PATH_UNCHANGED);
6524 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6525 PEER_FLAG_NEXTHOP_UNCHANGED);
6526 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6527 PEER_FLAG_MED_UNCHANGED);
8eeb0335 6528 } else {
28c6e247
IR
6529 if (!aspath) {
6530 if (peer_af_flag_check(peer, afi, safi,
6531 PEER_FLAG_AS_PATH_UNCHANGED)) {
6532 ret |= peer_af_flag_unset_vty(
6533 vty, peer_str, afi, safi,
6534 PEER_FLAG_AS_PATH_UNCHANGED);
6535 }
6536 } else
6537 ret |= peer_af_flag_set_vty(
6538 vty, peer_str, afi, safi,
6539 PEER_FLAG_AS_PATH_UNCHANGED);
6540
6541 if (!nexthop) {
6542 if (peer_af_flag_check(peer, afi, safi,
6543 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6544 ret |= peer_af_flag_unset_vty(
6545 vty, peer_str, afi, safi,
6546 PEER_FLAG_NEXTHOP_UNCHANGED);
6547 }
6548 } else
6549 ret |= peer_af_flag_set_vty(
6550 vty, peer_str, afi, safi,
6551 PEER_FLAG_NEXTHOP_UNCHANGED);
6552
6553 if (!med) {
6554 if (peer_af_flag_check(peer, afi, safi,
6555 PEER_FLAG_MED_UNCHANGED)) {
6556 ret |= peer_af_flag_unset_vty(
6557 vty, peer_str, afi, safi,
6558 PEER_FLAG_MED_UNCHANGED);
6559 }
6560 } else
6561 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6562 PEER_FLAG_MED_UNCHANGED);
d62a17ae 6563 }
6564
28c6e247 6565 return ret;
d62a17ae 6566}
6567
6568ALIAS_HIDDEN(
6569 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6570 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6571 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6572 "BGP attribute is propagated unchanged to this neighbor\n"
6573 "As-path attribute\n"
6574 "Nexthop attribute\n"
6575 "Med attribute\n")
596c17ba 6576
28c6e247
IR
6577DEFUN (no_neighbor_attr_unchanged,
6578 no_neighbor_attr_unchanged_cmd,
6579 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6580 NO_STR
6581 NEIGHBOR_STR
6582 NEIGHBOR_ADDR_STR2
6583 "BGP attribute is propagated unchanged to this neighbor\n"
6584 "As-path attribute\n"
6585 "Nexthop attribute\n"
6586 "Med attribute\n")
718e3744 6587{
d62a17ae 6588 int idx = 0;
db45f64d 6589 char *peer_str = argv[2]->arg;
28c6e247 6590 struct peer *peer;
db45f64d
DS
6591 bool aspath = false;
6592 bool nexthop = false;
6593 bool med = false;
6594 afi_t afi = bgp_node_afi(vty);
6595 safi_t safi = bgp_node_safi(vty);
28c6e247 6596 int ret = 0;
f4b8ec07 6597
28c6e247
IR
6598 peer = peer_and_group_lookup_vty(vty, peer_str);
6599 if (!peer)
db45f64d 6600 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6601
6602 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6603 aspath = true;
6604
d62a17ae 6605 idx = 0;
6606 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6607 nexthop = true;
6608
d62a17ae 6609 idx = 0;
6610 if (argv_find(argv, argc, "med", &idx))
db45f64d 6611 med = true;
d62a17ae 6612
28c6e247
IR
6613 if (!aspath && !nexthop && !med) // no flags means all of them!
6614 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6615 PEER_FLAG_AS_PATH_UNCHANGED)
6616 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6617 PEER_FLAG_NEXTHOP_UNCHANGED)
6618 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6619 PEER_FLAG_MED_UNCHANGED);
db45f64d
DS
6620
6621 if (aspath)
28c6e247
IR
6622 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6623 PEER_FLAG_AS_PATH_UNCHANGED);
db45f64d
DS
6624
6625 if (nexthop)
28c6e247
IR
6626 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6627 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 6628
db45f64d 6629 if (med)
28c6e247
IR
6630 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6631 PEER_FLAG_MED_UNCHANGED);
db45f64d 6632
28c6e247 6633 return ret;
d62a17ae 6634}
6635
6636ALIAS_HIDDEN(
6637 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6638 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6639 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6640 "BGP attribute is propagated unchanged to this neighbor\n"
6641 "As-path attribute\n"
6642 "Nexthop attribute\n"
6643 "Med attribute\n")
718e3744 6644
28c6e247
IR
6645/* EBGP multihop configuration. */
6646static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6647 const char *ttl_str)
718e3744 6648{
28c6e247
IR
6649 struct peer *peer;
6650 unsigned int ttl;
718e3744 6651
28c6e247
IR
6652 peer = peer_and_group_lookup_vty(vty, ip_str);
6653 if (!peer)
d62a17ae 6654 return CMD_WARNING_CONFIG_FAILED;
718e3744 6655
28c6e247
IR
6656 if (peer->conf_if)
6657 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6658
6659 if (!ttl_str)
6660 ttl = MAXTTL;
6661 else
6662 ttl = strtoul(ttl_str, NULL, 10);
718e3744 6663
28c6e247 6664 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 6665}
6666
28c6e247 6667static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6668{
28c6e247 6669 struct peer *peer;
718e3744 6670
28c6e247
IR
6671 peer = peer_and_group_lookup_vty(vty, ip_str);
6672 if (!peer)
d62a17ae 6673 return CMD_WARNING_CONFIG_FAILED;
718e3744 6674
28c6e247 6675 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 6676}
6677
28c6e247
IR
6678/* neighbor ebgp-multihop. */
6679DEFUN (neighbor_ebgp_multihop,
6680 neighbor_ebgp_multihop_cmd,
6681 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6682 NEIGHBOR_STR
6683 NEIGHBOR_ADDR_STR2
6684 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6685{
28c6e247
IR
6686 int idx_peer = 1;
6687 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6688}
f4b8ec07 6689
28c6e247
IR
6690DEFUN (neighbor_ebgp_multihop_ttl,
6691 neighbor_ebgp_multihop_ttl_cmd,
6692 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6693 NEIGHBOR_STR
6694 NEIGHBOR_ADDR_STR2
6695 "Allow EBGP neighbors not on directly connected networks\n"
6696 "maximum hop count\n")
6697{
6698 int idx_peer = 1;
6699 int idx_number = 3;
6700 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6701 argv[idx_number]->arg);
6702}
f4b8ec07 6703
28c6e247
IR
6704DEFUN (no_neighbor_ebgp_multihop,
6705 no_neighbor_ebgp_multihop_cmd,
6706 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6707 NO_STR
6708 NEIGHBOR_STR
6709 NEIGHBOR_ADDR_STR2
6710 "Allow EBGP neighbors not on directly connected networks\n"
6711 "maximum hop count\n")
6712{
6713 int idx_peer = 2;
6714 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6715}
6716
97a52c82
DA
6717DEFPY (neighbor_aigp,
6718 neighbor_aigp_cmd,
6719 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor aigp",
6720 NO_STR
6721 NEIGHBOR_STR
6722 NEIGHBOR_ADDR_STR2
6723 "Enable send and receive of the AIGP attribute per neighbor\n")
6724{
6725 struct peer *peer;
6726
6727 peer = peer_and_group_lookup_vty(vty, neighbor);
6728 if (!peer)
6729 return CMD_WARNING_CONFIG_FAILED;
6730
6731 if (no)
6732 return peer_flag_unset_vty(vty, neighbor, PEER_FLAG_AIGP);
6733 else
6734 return peer_flag_set_vty(vty, neighbor, PEER_FLAG_AIGP);
6735}
6736
d864dd9e
EB
6737static uint8_t get_role_by_name(const char *role_str)
6738{
6739 if (strncmp(role_str, "peer", 2) == 0)
6740 return ROLE_PEER;
6741 if (strncmp(role_str, "provider", 2) == 0)
6742 return ROLE_PROVIDER;
6743 if (strncmp(role_str, "customer", 2) == 0)
6744 return ROLE_CUSTOMER;
6745 if (strncmp(role_str, "rs-server", 4) == 0)
6746 return ROLE_RS_SERVER;
6747 if (strncmp(role_str, "rs-client", 4) == 0)
6748 return ROLE_RS_CLIENT;
8f2d6021 6749 return ROLE_UNDEFINED;
d864dd9e
EB
6750}
6751
6752static int peer_role_set_vty(struct vty *vty, const char *ip_str,
8f2d6021 6753 const char *role_str, bool strict_mode)
d864dd9e
EB
6754{
6755 struct peer *peer;
6756
7dddd1f7 6757 peer = peer_and_group_lookup_vty(vty, ip_str);
d864dd9e
EB
6758 if (!peer)
6759 return CMD_WARNING_CONFIG_FAILED;
6760 uint8_t role = get_role_by_name(role_str);
6761
8f2d6021 6762 if (role == ROLE_UNDEFINED)
d864dd9e
EB
6763 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6764 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6765}
6766
6767static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6768{
6769 struct peer *peer;
6770
7dddd1f7 6771 peer = peer_and_group_lookup_vty(vty, ip_str);
d864dd9e
EB
6772 if (!peer)
6773 return CMD_WARNING_CONFIG_FAILED;
6774 return bgp_vty_return(vty, peer_role_unset(peer));
6775}
6776
8f2d6021 6777DEFPY(neighbor_role,
d864dd9e
EB
6778 neighbor_role_cmd,
6779 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6780 NEIGHBOR_STR
6781 NEIGHBOR_ADDR_STR2
6782 "Set session role\n"
6783 ROLE_STR)
6784{
6785 int idx_peer = 1;
6786 int idx_role = 3;
6787
6788 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
8f2d6021 6789 false);
d864dd9e
EB
6790}
6791
8f2d6021 6792DEFPY(neighbor_role_strict,
d864dd9e
EB
6793 neighbor_role_strict_cmd,
6794 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6795 NEIGHBOR_STR
6796 NEIGHBOR_ADDR_STR2
6797 "Set session role\n"
6798 ROLE_STR
6799 "Use additional restriction on peer\n")
6800{
6801 int idx_peer = 1;
6802 int idx_role = 3;
6803
6804 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
8f2d6021 6805 true);
d864dd9e
EB
6806}
6807
8f2d6021 6808DEFPY(no_neighbor_role,
d864dd9e
EB
6809 no_neighbor_role_cmd,
6810 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6811 NO_STR
6812 NEIGHBOR_STR
6813 NEIGHBOR_ADDR_STR2
8f2d6021 6814 "Set session role\n"
d864dd9e 6815 ROLE_STR
8f2d6021 6816 "Use additional restriction on peer\n")
d864dd9e
EB
6817{
6818 int idx_peer = 2;
6819
6820 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6821}
6b0655a2 6822
6ffd2079 6823/* disable-connected-check */
28c6e247
IR
6824DEFUN (neighbor_disable_connected_check,
6825 neighbor_disable_connected_check_cmd,
6826 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6827 NEIGHBOR_STR
6828 NEIGHBOR_ADDR_STR2
6829 "one-hop away EBGP peer using loopback address\n"
6830 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6831{
d62a17ae 6832 int idx_peer = 1;
28c6e247
IR
6833 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6834 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6835}
6836
28c6e247
IR
6837DEFUN (no_neighbor_disable_connected_check,
6838 no_neighbor_disable_connected_check_cmd,
6839 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6840 NO_STR
6841 NEIGHBOR_STR
6842 NEIGHBOR_ADDR_STR2
6843 "one-hop away EBGP peer using loopback address\n"
6844 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6845{
d62a17ae 6846 int idx_peer = 2;
28c6e247
IR
6847 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6848 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6849}
6850
7ab294ea
DA
6851/* disable-link-bw-encoding-ieee */
6852DEFUN(neighbor_disable_link_bw_encoding_ieee,
6853 neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6854 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6855 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6856 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6857{
6858 int idx_peer = 1;
6859
6860 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6861 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6862}
6863
7ab294ea
DA
6864DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6865 no_neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6866 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6867 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6868 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6869{
6870 int idx_peer = 2;
6871
6872 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6873 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6874}
6875
d08c0c80
DA
6876/* extended-optional-parameters */
6877DEFUN(neighbor_extended_optional_parameters,
6878 neighbor_extended_optional_parameters_cmd,
6879 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6880 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6881 "Force the extended optional parameters format for OPEN messages\n")
6882{
6883 int idx_peer = 1;
6884
6885 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6886 PEER_FLAG_EXTENDED_OPT_PARAMS);
6887}
6888
6889DEFUN(no_neighbor_extended_optional_parameters,
6890 no_neighbor_extended_optional_parameters_cmd,
6891 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6892 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6893 "Force the extended optional parameters format for OPEN messages\n")
6894{
6895 int idx_peer = 2;
6896
6897 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6898 PEER_FLAG_EXTENDED_OPT_PARAMS);
6899}
47cbc09b
PM
6900
6901/* enforce-first-as */
28c6e247
IR
6902DEFUN (neighbor_enforce_first_as,
6903 neighbor_enforce_first_as_cmd,
6904 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6905 NEIGHBOR_STR
6906 NEIGHBOR_ADDR_STR2
6907 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6908{
6909 int idx_peer = 1;
f4b8ec07 6910
28c6e247
IR
6911 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6912 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6913}
6914
28c6e247
IR
6915DEFUN (no_neighbor_enforce_first_as,
6916 no_neighbor_enforce_first_as_cmd,
6917 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6918 NO_STR
6919 NEIGHBOR_STR
6920 NEIGHBOR_ADDR_STR2
6921 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6922{
6923 int idx_peer = 2;
f4b8ec07 6924
28c6e247
IR
6925 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6926 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6927}
6928
6929
28c6e247
IR
6930DEFUN (neighbor_description,
6931 neighbor_description_cmd,
6932 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6933 NEIGHBOR_STR
6934 NEIGHBOR_ADDR_STR2
6935 "Neighbor specific description\n"
6936 "Up to 80 characters describing this neighbor\n")
718e3744 6937{
d62a17ae 6938 int idx_peer = 1;
6939 int idx_line = 3;
28c6e247 6940 struct peer *peer;
d62a17ae 6941 char *str;
718e3744 6942
28c6e247
IR
6943 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6944 if (!peer)
d62a17ae 6945 return CMD_WARNING_CONFIG_FAILED;
718e3744 6946
d62a17ae 6947 str = argv_concat(argv, argc, idx_line);
718e3744 6948
28c6e247 6949 peer_description_set(peer, str);
718e3744 6950
d62a17ae 6951 XFREE(MTYPE_TMP, str);
718e3744 6952
28c6e247 6953 return CMD_SUCCESS;
718e3744 6954}
6955
28c6e247
IR
6956DEFUN (no_neighbor_description,
6957 no_neighbor_description_cmd,
6958 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6959 NO_STR
6960 NEIGHBOR_STR
6961 NEIGHBOR_ADDR_STR2
6962 "Neighbor specific description\n")
718e3744 6963{
d62a17ae 6964 int idx_peer = 2;
28c6e247 6965 struct peer *peer;
f4b8ec07 6966
28c6e247
IR
6967 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6968 if (!peer)
d62a17ae 6969 return CMD_WARNING_CONFIG_FAILED;
718e3744 6970
28c6e247 6971 peer_description_unset(peer);
718e3744 6972
28c6e247 6973 return CMD_SUCCESS;
718e3744 6974}
6975
1d80f243 6976ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
6977 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6978 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6979 "Neighbor specific description\n"
6980 "Up to 80 characters describing this neighbor\n")
6b0655a2 6981
28c6e247
IR
6982/* Neighbor update-source. */
6983static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6984 const char *source_str)
6985{
6986 struct peer *peer;
6987 struct prefix p;
6988 union sockunion su;
6989
6990 peer = peer_and_group_lookup_vty(vty, peer_str);
6991 if (!peer)
6992 return CMD_WARNING_CONFIG_FAILED;
6993
6994 if (peer->conf_if)
6995 return CMD_WARNING;
6996
6997 if (source_str) {
6998 if (str2sockunion(source_str, &su) == 0)
6999 peer_update_source_addr_set(peer, &su);
7000 else {
7001 if (str2prefix(source_str, &p)) {
7002 vty_out(vty,
7003 "%% Invalid update-source, remove prefix length \n");
7004 return CMD_WARNING_CONFIG_FAILED;
7005 } else
7006 peer_update_source_if_set(peer, source_str);
7007 }
7008 } else
7009 peer_update_source_unset(peer);
7010
7011 return CMD_SUCCESS;
7012}
7013
d62a17ae 7014#define BGP_UPDATE_SOURCE_HELP_STR \
7015 "IPv4 address\n" \
7016 "IPv6 address\n" \
7017 "Interface name (requires zebra to be running)\n"
369688c0 7018
28c6e247
IR
7019DEFUN (neighbor_update_source,
7020 neighbor_update_source_cmd,
7021 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
7022 NEIGHBOR_STR
7023 NEIGHBOR_ADDR_STR2
7024 "Source of routing updates\n"
7025 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 7026{
d62a17ae 7027 int idx_peer = 1;
7028 int idx_peer_2 = 3;
28c6e247 7029 return peer_update_source_vty(vty, argv[idx_peer]->arg,
d62a17ae 7030 argv[idx_peer_2]->arg);
718e3744 7031}
7032
28c6e247
IR
7033DEFUN (no_neighbor_update_source,
7034 no_neighbor_update_source_cmd,
7035 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
7036 NO_STR
7037 NEIGHBOR_STR
7038 NEIGHBOR_ADDR_STR2
7039 "Source of routing updates\n"
7040 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 7041{
d62a17ae 7042 int idx_peer = 2;
28c6e247 7043 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 7044}
6b0655a2 7045
d62a17ae 7046static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
7047 afi_t afi, safi_t safi,
7048 const char *rmap, int set)
718e3744 7049{
d62a17ae 7050 int ret;
7051 struct peer *peer;
80912664 7052 struct route_map *route_map = NULL;
718e3744 7053
d62a17ae 7054 peer = peer_and_group_lookup_vty(vty, peer_str);
7055 if (!peer)
7056 return CMD_WARNING_CONFIG_FAILED;
718e3744 7057
1de27621 7058 if (set) {
80912664
DS
7059 if (rmap)
7060 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
7061 ret = peer_default_originate_set(peer, afi, safi,
7062 rmap, route_map);
7063 } else
d62a17ae 7064 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 7065
d62a17ae 7066 return bgp_vty_return(vty, ret);
718e3744 7067}
7068
7069/* neighbor default-originate. */
7070DEFUN (neighbor_default_originate,
7071 neighbor_default_originate_cmd,
9ccf14f7 7072 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 7073 NEIGHBOR_STR
7074 NEIGHBOR_ADDR_STR2
7075 "Originate default route to this neighbor\n")
7076{
d62a17ae 7077 int idx_peer = 1;
7078 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7079 bgp_node_afi(vty),
7080 bgp_node_safi(vty), NULL, 1);
718e3744 7081}
7082
d62a17ae 7083ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7084 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7085 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7086 "Originate default route to this neighbor\n")
596c17ba 7087
718e3744 7088DEFUN (neighbor_default_originate_rmap,
7089 neighbor_default_originate_rmap_cmd,
70dd370f 7090 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
718e3744 7091 NEIGHBOR_STR
7092 NEIGHBOR_ADDR_STR2
7093 "Originate default route to this neighbor\n"
7094 "Route-map to specify criteria to originate default\n"
7095 "route-map name\n")
7096{
d62a17ae 7097 int idx_peer = 1;
7098 int idx_word = 4;
7099 return peer_default_originate_set_vty(
7100 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7101 argv[idx_word]->arg, 1);
718e3744 7102}
7103
d62a17ae 7104ALIAS_HIDDEN(
7105 neighbor_default_originate_rmap,
7106 neighbor_default_originate_rmap_hidden_cmd,
70dd370f 7107 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
d62a17ae 7108 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7109 "Originate default route to this neighbor\n"
7110 "Route-map to specify criteria to originate default\n"
7111 "route-map name\n")
596c17ba 7112
718e3744 7113DEFUN (no_neighbor_default_originate,
7114 no_neighbor_default_originate_cmd,
70dd370f 7115 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
718e3744 7116 NO_STR
7117 NEIGHBOR_STR
7118 NEIGHBOR_ADDR_STR2
a636c635
DW
7119 "Originate default route to this neighbor\n"
7120 "Route-map to specify criteria to originate default\n"
7121 "route-map name\n")
718e3744 7122{
d62a17ae 7123 int idx_peer = 2;
7124 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7125 bgp_node_afi(vty),
7126 bgp_node_safi(vty), NULL, 0);
718e3744 7127}
7128
d62a17ae 7129ALIAS_HIDDEN(
7130 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
70dd370f 7131 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
d62a17ae 7132 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7133 "Originate default route to this neighbor\n"
7134 "Route-map to specify criteria to originate default\n"
7135 "route-map name\n")
596c17ba 7136
6b0655a2 7137
28c6e247
IR
7138/* Set neighbor's BGP port. */
7139static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
7140 const char *port_str)
718e3744 7141{
28c6e247
IR
7142 struct peer *peer;
7143 uint16_t port;
7144 struct servent *sp;
7145
a3aecc99 7146 peer = peer_and_group_lookup_vty(vty, ip_str);
28c6e247
IR
7147 if (!peer)
7148 return CMD_WARNING_CONFIG_FAILED;
7149
7150 if (!port_str) {
7151 sp = getservbyname("bgp", "tcp");
7152 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
7153 } else {
7154 port = strtoul(port_str, NULL, 10);
7155 }
718e3744 7156
28c6e247 7157 peer_port_set(peer, port);
718e3744 7158
28c6e247
IR
7159 return CMD_SUCCESS;
7160}
f4b8ec07 7161
28c6e247
IR
7162/* Set specified peer's BGP port. */
7163DEFUN (neighbor_port,
7164 neighbor_port_cmd,
a3aecc99 7165 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
28c6e247 7166 NEIGHBOR_STR
a3aecc99 7167 NEIGHBOR_ADDR_STR2
28c6e247
IR
7168 "Neighbor's BGP port\n"
7169 "TCP port number\n")
7170{
7171 int idx_ip = 1;
7172 int idx_number = 3;
7173 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
7174 argv[idx_number]->arg);
f4b8ec07 7175}
6b0655a2 7176
28c6e247
IR
7177DEFUN (no_neighbor_port,
7178 no_neighbor_port_cmd,
a3aecc99 7179 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
28c6e247
IR
7180 NO_STR
7181 NEIGHBOR_STR
a3aecc99 7182 NEIGHBOR_ADDR_STR2
28c6e247
IR
7183 "Neighbor's BGP port\n"
7184 "TCP port number\n")
718e3744 7185{
f4b8ec07 7186 int idx_ip = 2;
28c6e247
IR
7187 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
7188}
7189
7190
7191/* neighbor weight. */
7192static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7193 safi_t safi, const char *weight_str)
7194{
7195 int ret;
7196 struct peer *peer;
7197 unsigned long weight;
718e3744 7198
28c6e247
IR
7199 peer = peer_and_group_lookup_vty(vty, ip_str);
7200 if (!peer)
7201 return CMD_WARNING_CONFIG_FAILED;
718e3744 7202
28c6e247 7203 weight = strtoul(weight_str, NULL, 10);
718e3744 7204
28c6e247
IR
7205 ret = peer_weight_set(peer, afi, safi, weight);
7206 return bgp_vty_return(vty, ret);
718e3744 7207}
7208
28c6e247
IR
7209static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7210 safi_t safi)
718e3744 7211{
28c6e247
IR
7212 int ret;
7213 struct peer *peer;
f4b8ec07 7214
28c6e247
IR
7215 peer = peer_and_group_lookup_vty(vty, ip_str);
7216 if (!peer)
d62a17ae 7217 return CMD_WARNING_CONFIG_FAILED;
718e3744 7218
28c6e247
IR
7219 ret = peer_weight_unset(peer, afi, safi);
7220 return bgp_vty_return(vty, ret);
7221}
f4b8ec07 7222
28c6e247
IR
7223DEFUN (neighbor_weight,
7224 neighbor_weight_cmd,
7225 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7226 NEIGHBOR_STR
7227 NEIGHBOR_ADDR_STR2
7228 "Set default weight for routes from this neighbor\n"
7229 "default weight\n")
7230{
7231 int idx_peer = 1;
7232 int idx_number = 3;
7233 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7234 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 7235}
7236
d62a17ae 7237ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7238 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7239 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7240 "Set default weight for routes from this neighbor\n"
7241 "default weight\n")
596c17ba 7242
28c6e247
IR
7243DEFUN (no_neighbor_weight,
7244 no_neighbor_weight_cmd,
7245 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7246 NO_STR
7247 NEIGHBOR_STR
7248 NEIGHBOR_ADDR_STR2
7249 "Set default weight for routes from this neighbor\n"
7250 "default weight\n")
718e3744 7251{
d62a17ae 7252 int idx_peer = 2;
28c6e247
IR
7253 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7254 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 7255}
7256
d62a17ae 7257ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7258 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7259 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7260 "Set default weight for routes from this neighbor\n"
7261 "default weight\n")
596c17ba 7262
6b0655a2 7263
718e3744 7264/* Override capability negotiation. */
c36bc05f
IR
7265DEFUN (neighbor_override_capability,
7266 neighbor_override_capability_cmd,
7267 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7268 NEIGHBOR_STR
7269 NEIGHBOR_ADDR_STR2
7270 "Override capability negotiation result\n")
718e3744 7271{
d62a17ae 7272 int idx_peer = 1;
c36bc05f
IR
7273 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7274 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 7275}
7276
c36bc05f
IR
7277DEFUN (no_neighbor_override_capability,
7278 no_neighbor_override_capability_cmd,
7279 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7280 NO_STR
7281 NEIGHBOR_STR
7282 NEIGHBOR_ADDR_STR2
7283 "Override capability negotiation result\n")
718e3744 7284{
d62a17ae 7285 int idx_peer = 2;
c36bc05f
IR
7286 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7287 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 7288}
6b0655a2 7289
c36bc05f
IR
7290DEFUN (neighbor_strict_capability,
7291 neighbor_strict_capability_cmd,
7292 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7293 NEIGHBOR_STR
7294 NEIGHBOR_ADDR_STR2
7295 "Strict capability negotiation match\n")
718e3744 7296{
9fb964de
PM
7297 int idx_peer = 1;
7298
c36bc05f
IR
7299 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7300 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 7301}
7302
c36bc05f
IR
7303DEFUN (no_neighbor_strict_capability,
7304 no_neighbor_strict_capability_cmd,
7305 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7306 NO_STR
7307 NEIGHBOR_STR
7308 NEIGHBOR_ADDR_STR2
7309 "Strict capability negotiation match\n")
718e3744 7310{
9fb964de 7311 int idx_peer = 2;
8611c7f3 7312
c36bc05f
IR
7313 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7314 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 7315}
6b0655a2 7316
28c6e247
IR
7317static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7318 const char *keep_str, const char *hold_str)
718e3744 7319{
28c6e247
IR
7320 int ret;
7321 struct peer *peer;
7322 uint32_t keepalive;
7323 uint32_t holdtime;
718e3744 7324
28c6e247
IR
7325 peer = peer_and_group_lookup_vty(vty, ip_str);
7326 if (!peer)
d62a17ae 7327 return CMD_WARNING_CONFIG_FAILED;
718e3744 7328
28c6e247
IR
7329 keepalive = strtoul(keep_str, NULL, 10);
7330 holdtime = strtoul(hold_str, NULL, 10);
718e3744 7331
28c6e247 7332 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 7333
28c6e247 7334 return bgp_vty_return(vty, ret);
718e3744 7335}
6b0655a2 7336
28c6e247 7337static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 7338{
28c6e247
IR
7339 int ret;
7340 struct peer *peer;
718e3744 7341
28c6e247
IR
7342 peer = peer_and_group_lookup_vty(vty, ip_str);
7343 if (!peer)
d62a17ae 7344 return CMD_WARNING_CONFIG_FAILED;
718e3744 7345
28c6e247 7346 ret = peer_timers_unset(peer);
718e3744 7347
28c6e247 7348 return bgp_vty_return(vty, ret);
718e3744 7349}
6b0655a2 7350
28c6e247
IR
7351DEFUN (neighbor_timers,
7352 neighbor_timers_cmd,
7353 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7354 NEIGHBOR_STR
7355 NEIGHBOR_ADDR_STR2
7356 "BGP per neighbor timers\n"
7357 "Keepalive interval\n"
7358 "Holdtime\n")
718e3744 7359{
f4b8ec07 7360 int idx_peer = 1;
28c6e247
IR
7361 int idx_number = 3;
7362 int idx_number_2 = 4;
7363 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7364 argv[idx_number]->arg,
7365 argv[idx_number_2]->arg);
7366}
7367
7368DEFUN (no_neighbor_timers,
7369 no_neighbor_timers_cmd,
7370 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7371 NO_STR
7372 NEIGHBOR_STR
7373 NEIGHBOR_ADDR_STR2
7374 "BGP per neighbor timers\n"
7375 "Keepalive interval\n"
7376 "Holdtime\n")
7377{
7378 int idx_peer = 2;
7379 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7380}
7381
7382
7383static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7384 const char *time_str)
7385{
7386 int ret;
7387 struct peer *peer;
7388 uint32_t connect;
718e3744 7389
28c6e247
IR
7390 peer = peer_and_group_lookup_vty(vty, ip_str);
7391 if (!peer)
d62a17ae 7392 return CMD_WARNING_CONFIG_FAILED;
718e3744 7393
28c6e247
IR
7394 connect = strtoul(time_str, NULL, 10);
7395
7396 ret = peer_timers_connect_set(peer, connect);
718e3744 7397
28c6e247 7398 return bgp_vty_return(vty, ret);
718e3744 7399}
7400
28c6e247 7401static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 7402{
28c6e247
IR
7403 int ret;
7404 struct peer *peer;
718e3744 7405
28c6e247
IR
7406 peer = peer_and_group_lookup_vty(vty, ip_str);
7407 if (!peer)
d62a17ae 7408 return CMD_WARNING_CONFIG_FAILED;
718e3744 7409
28c6e247
IR
7410 ret = peer_timers_connect_unset(peer);
7411
7412 return bgp_vty_return(vty, ret);
7413}
7414
7415DEFUN (neighbor_timers_connect,
7416 neighbor_timers_connect_cmd,
7417 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7418 NEIGHBOR_STR
7419 NEIGHBOR_ADDR_STR2
7420 "BGP per neighbor timers\n"
7421 "BGP connect timer\n"
7422 "Connect timer\n")
7423{
7424 int idx_peer = 1;
7425 int idx_number = 4;
7426 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7427 argv[idx_number]->arg);
7428}
718e3744 7429
28c6e247
IR
7430DEFUN (no_neighbor_timers_connect,
7431 no_neighbor_timers_connect_cmd,
7432 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7433 NO_STR
7434 NEIGHBOR_STR
7435 NEIGHBOR_ADDR_STR2
7436 "BGP per neighbor timers\n"
7437 "BGP connect timer\n"
7438 "Connect timer\n")
7439{
7440 int idx_peer = 2;
7441 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 7442}
7443
d43114f3
DS
7444DEFPY (neighbor_timers_delayopen,
7445 neighbor_timers_delayopen_cmd,
7446 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7447 NEIGHBOR_STR
7448 NEIGHBOR_ADDR_STR2
7449 "BGP per neighbor timers\n"
7450 "RFC 4271 DelayOpenTimer\n"
7451 "DelayOpenTime timer interval\n")
7452{
7453 struct peer *peer;
7454
7455 peer = peer_and_group_lookup_vty(vty, neighbor);
7456 if (!peer)
7457 return CMD_WARNING_CONFIG_FAILED;
7458
7459 if (!interval) {
7460 if (peer_timers_delayopen_unset(peer))
7461 return CMD_WARNING_CONFIG_FAILED;
7462 } else {
7463 if (peer_timers_delayopen_set(peer, interval))
7464 return CMD_WARNING_CONFIG_FAILED;
7465 }
7466
7467 return CMD_SUCCESS;
7468}
7469
7470DEFPY (no_neighbor_timers_delayopen,
7471 no_neighbor_timers_delayopen_cmd,
7472 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7473 NO_STR
7474 NEIGHBOR_STR
7475 NEIGHBOR_ADDR_STR2
7476 "BGP per neighbor timers\n"
7477 "RFC 4271 DelayOpenTimer\n"
7478 "DelayOpenTime timer interval\n")
7479{
7480 struct peer *peer;
7481
7482 peer = peer_and_group_lookup_vty(vty, neighbor);
7483 if (!peer)
7484 return CMD_WARNING_CONFIG_FAILED;
7485
7486 if (peer_timers_delayopen_unset(peer))
7487 return CMD_WARNING_CONFIG_FAILED;
7488
7489 return CMD_SUCCESS;
7490}
7491
28c6e247
IR
7492static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7493 const char *time_str, int set)
718e3744 7494{
28c6e247
IR
7495 int ret;
7496 struct peer *peer;
7497 uint32_t routeadv = 0;
718e3744 7498
28c6e247
IR
7499 peer = peer_and_group_lookup_vty(vty, ip_str);
7500 if (!peer)
d62a17ae 7501 return CMD_WARNING_CONFIG_FAILED;
718e3744 7502
28c6e247
IR
7503 if (time_str)
7504 routeadv = strtoul(time_str, NULL, 10);
7505
7506 if (set)
7507 ret = peer_advertise_interval_set(peer, routeadv);
7508 else
7509 ret = peer_advertise_interval_unset(peer);
718e3744 7510
28c6e247 7511 return bgp_vty_return(vty, ret);
718e3744 7512}
7513
28c6e247
IR
7514DEFUN (neighbor_advertise_interval,
7515 neighbor_advertise_interval_cmd,
7516 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7517 NEIGHBOR_STR
7518 NEIGHBOR_ADDR_STR2
7519 "Minimum interval between sending BGP routing updates\n"
7520 "time in seconds\n")
718e3744 7521{
28c6e247
IR
7522 int idx_peer = 1;
7523 int idx_number = 3;
7524 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7525 argv[idx_number]->arg, 1);
7526}
f4b8ec07 7527
28c6e247
IR
7528DEFUN (no_neighbor_advertise_interval,
7529 no_neighbor_advertise_interval_cmd,
7530 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7531 NO_STR
7532 NEIGHBOR_STR
7533 NEIGHBOR_ADDR_STR2
7534 "Minimum interval between sending BGP routing updates\n"
7535 "time in seconds\n")
7536{
7537 int idx_peer = 2;
7538 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 7539}
7540
6b0655a2 7541
518f0eb1
DS
7542/* Time to wait before processing route-map updates */
7543DEFUN (bgp_set_route_map_delay_timer,
7544 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7545 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7546 SET_STR
7547 "BGP route-map delay timer\n"
7548 "Time in secs to wait before processing route-map changes\n"
f414725f 7549 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7550{
d62a17ae 7551 int idx_number = 3;
d7c0a89a 7552 uint32_t rmap_delay_timer;
d62a17ae 7553
7554 if (argv[idx_number]->arg) {
7555 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7556 bm->rmap_update_timer = rmap_delay_timer;
7557
7558 /* if the dynamic update handling is being disabled, and a timer
7559 * is
7560 * running, stop the timer and act as if the timer has already
7561 * fired.
7562 */
7563 if (!rmap_delay_timer && bm->t_rmap_update) {
e16d030c 7564 EVENT_OFF(bm->t_rmap_update);
8c1186d3
DS
7565 event_execute(bm->master, bgp_route_map_update_timer,
7566 NULL, 0);
d62a17ae 7567 }
7568 return CMD_SUCCESS;
7569 } else {
7570 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7571 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7572 }
518f0eb1
DS
7573}
7574
7575DEFUN (no_bgp_set_route_map_delay_timer,
7576 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7577 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7578 NO_STR
3a2d747c 7579 BGP_STR
518f0eb1 7580 "Default BGP route-map delay timer\n"
8334fd5a
DW
7581 "Reset to default time to wait for processing route-map changes\n"
7582 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7583{
518f0eb1 7584
d62a17ae 7585 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7586
d62a17ae 7587 return CMD_SUCCESS;
518f0eb1
DS
7588}
7589
28c6e247
IR
7590/* neighbor interface */
7591static int peer_interface_vty(struct vty *vty, const char *ip_str,
7592 const char *str)
718e3744 7593{
28c6e247 7594 struct peer *peer;
718e3744 7595
28c6e247
IR
7596 peer = peer_lookup_vty(vty, ip_str);
7597 if (!peer || peer->conf_if) {
7598 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7599 return CMD_WARNING_CONFIG_FAILED;
7600 }
718e3744 7601
28c6e247
IR
7602 if (str)
7603 peer_interface_set(peer, str);
7604 else
7605 peer_interface_unset(peer);
718e3744 7606
28c6e247 7607 return CMD_SUCCESS;
718e3744 7608}
7609
28c6e247
IR
7610DEFUN (neighbor_interface,
7611 neighbor_interface_cmd,
7612 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7613 NEIGHBOR_STR
7614 NEIGHBOR_ADDR_STR
7615 "Interface\n"
7616 "Interface name\n")
718e3744 7617{
28c6e247
IR
7618 int idx_ip = 1;
7619 int idx_word = 3;
294d8425 7620
28c6e247
IR
7621 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7622}
f4b8ec07 7623
28c6e247
IR
7624DEFUN (no_neighbor_interface,
7625 no_neighbor_interface_cmd,
294d8425 7626 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
28c6e247
IR
7627 NO_STR
7628 NEIGHBOR_STR
294d8425 7629 NEIGHBOR_ADDR_STR
28c6e247
IR
7630 "Interface\n"
7631 "Interface name\n")
7632{
7633 int idx_peer = 2;
294d8425 7634
28c6e247 7635 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 7636}
6b0655a2 7637
718e3744 7638DEFUN (neighbor_distribute_list,
7639 neighbor_distribute_list_cmd,
c60dec36 7640 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7641 NEIGHBOR_STR
7642 NEIGHBOR_ADDR_STR2
7643 "Filter updates to/from this neighbor\n"
718e3744 7644 "IP Access-list name\n"
7645 "Filter incoming updates\n"
7646 "Filter outgoing updates\n")
7647{
d62a17ae 7648 int idx_peer = 1;
7649 int idx_acl = 3;
7650 int direct, ret;
7651 struct peer *peer;
a8206004 7652
d62a17ae 7653 const char *pstr = argv[idx_peer]->arg;
7654 const char *acl = argv[idx_acl]->arg;
7655 const char *inout = argv[argc - 1]->text;
a8206004 7656
d62a17ae 7657 peer = peer_and_group_lookup_vty(vty, pstr);
7658 if (!peer)
7659 return CMD_WARNING_CONFIG_FAILED;
a8206004 7660
d62a17ae 7661 /* Check filter direction. */
7662 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7663 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7664 direct, acl);
a8206004 7665
d62a17ae 7666 return bgp_vty_return(vty, ret);
718e3744 7667}
7668
d62a17ae 7669ALIAS_HIDDEN(
7670 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
c60dec36 7671 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7672 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7673 "Filter updates to/from this neighbor\n"
d62a17ae 7674 "IP Access-list name\n"
7675 "Filter incoming updates\n"
7676 "Filter outgoing updates\n")
596c17ba 7677
718e3744 7678DEFUN (no_neighbor_distribute_list,
7679 no_neighbor_distribute_list_cmd,
c60dec36 7680 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7681 NO_STR
7682 NEIGHBOR_STR
7683 NEIGHBOR_ADDR_STR2
7684 "Filter updates to/from this neighbor\n"
718e3744 7685 "IP Access-list name\n"
7686 "Filter incoming updates\n"
7687 "Filter outgoing updates\n")
7688{
d62a17ae 7689 int idx_peer = 2;
7690 int direct, ret;
7691 struct peer *peer;
a8206004 7692
d62a17ae 7693 const char *pstr = argv[idx_peer]->arg;
7694 const char *inout = argv[argc - 1]->text;
a8206004 7695
d62a17ae 7696 peer = peer_and_group_lookup_vty(vty, pstr);
7697 if (!peer)
7698 return CMD_WARNING_CONFIG_FAILED;
a8206004 7699
d62a17ae 7700 /* Check filter direction. */
7701 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7702 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7703 direct);
a8206004 7704
d62a17ae 7705 return bgp_vty_return(vty, ret);
718e3744 7706}
6b0655a2 7707
d62a17ae 7708ALIAS_HIDDEN(
7709 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
c60dec36 7710 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7711 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7712 "Filter updates to/from this neighbor\n"
d62a17ae 7713 "IP Access-list name\n"
7714 "Filter incoming updates\n"
7715 "Filter outgoing updates\n")
596c17ba 7716
718e3744 7717/* Set prefix list to the peer. */
642ef664
IR
7718static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7719 afi_t afi, safi_t safi,
7720 const char *name_str,
7721 const char *direct_str)
718e3744 7722{
642ef664
IR
7723 int ret;
7724 int direct = FILTER_IN;
7725 struct peer *peer;
718e3744 7726
642ef664
IR
7727 peer = peer_and_group_lookup_vty(vty, ip_str);
7728 if (!peer)
d62a17ae 7729 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7730
642ef664
IR
7731 /* Check filter direction. */
7732 if (strncmp(direct_str, "i", 1) == 0)
7733 direct = FILTER_IN;
7734 else if (strncmp(direct_str, "o", 1) == 0)
7735 direct = FILTER_OUT;
718e3744 7736
642ef664 7737 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 7738
642ef664
IR
7739 return bgp_vty_return(vty, ret);
7740}
7741
7742static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7743 afi_t afi, safi_t safi,
7744 const char *direct_str)
7745{
7746 int ret;
7747 struct peer *peer;
7748 int direct = FILTER_IN;
7749
7750 peer = peer_and_group_lookup_vty(vty, ip_str);
7751 if (!peer)
7752 return CMD_WARNING_CONFIG_FAILED;
7753
7754 /* Check filter direction. */
7755 if (strncmp(direct_str, "i", 1) == 0)
7756 direct = FILTER_IN;
7757 else if (strncmp(direct_str, "o", 1) == 0)
7758 direct = FILTER_OUT;
7759
7760 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7761
7762 return bgp_vty_return(vty, ret);
7763}
7764
7765DEFUN (neighbor_prefix_list,
7766 neighbor_prefix_list_cmd,
7767 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7768 NEIGHBOR_STR
7769 NEIGHBOR_ADDR_STR2
7770 "Filter updates to/from this neighbor\n"
7771 "Name of a prefix list\n"
7772 "Filter incoming updates\n"
7773 "Filter outgoing updates\n")
7774{
7775 int idx_peer = 1;
7776 int idx_word = 3;
7777 int idx_in_out = 4;
7778 return peer_prefix_list_set_vty(
7779 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7780 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7781}
7782
d62a17ae 7783ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7784 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7785 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7786 "Filter updates to/from this neighbor\n"
7787 "Name of a prefix list\n"
7788 "Filter incoming updates\n"
7789 "Filter outgoing updates\n")
596c17ba 7790
642ef664
IR
7791DEFUN (no_neighbor_prefix_list,
7792 no_neighbor_prefix_list_cmd,
7793 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7794 NO_STR
7795 NEIGHBOR_STR
7796 NEIGHBOR_ADDR_STR2
7797 "Filter updates to/from this neighbor\n"
7798 "Name of a prefix list\n"
7799 "Filter incoming updates\n"
7800 "Filter outgoing updates\n")
7801{
7802 int idx_peer = 2;
7803 int idx_in_out = 5;
7804 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7805 bgp_node_afi(vty), bgp_node_safi(vty),
7806 argv[idx_in_out]->arg);
7807}
7808
7809ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7810 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7811 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7812 "Filter updates to/from this neighbor\n"
7813 "Name of a prefix list\n"
7814 "Filter incoming updates\n"
7815 "Filter outgoing updates\n")
7816
d62a17ae 7817static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7818 safi_t safi, const char *name_str,
7819 const char *direct_str)
718e3744 7820{
d62a17ae 7821 int ret;
7822 struct peer *peer;
7823 int direct = FILTER_IN;
718e3744 7824
d62a17ae 7825 peer = peer_and_group_lookup_vty(vty, ip_str);
7826 if (!peer)
7827 return CMD_WARNING_CONFIG_FAILED;
718e3744 7828
d62a17ae 7829 /* Check filter direction. */
7830 if (strncmp(direct_str, "i", 1) == 0)
7831 direct = FILTER_IN;
7832 else if (strncmp(direct_str, "o", 1) == 0)
7833 direct = FILTER_OUT;
718e3744 7834
d62a17ae 7835 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7836
d62a17ae 7837 return bgp_vty_return(vty, ret);
718e3744 7838}
7839
d62a17ae 7840static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7841 safi_t safi, const char *direct_str)
718e3744 7842{
d62a17ae 7843 int ret;
7844 struct peer *peer;
7845 int direct = FILTER_IN;
718e3744 7846
d62a17ae 7847 peer = peer_and_group_lookup_vty(vty, ip_str);
7848 if (!peer)
7849 return CMD_WARNING_CONFIG_FAILED;
718e3744 7850
d62a17ae 7851 /* Check filter direction. */
7852 if (strncmp(direct_str, "i", 1) == 0)
7853 direct = FILTER_IN;
7854 else if (strncmp(direct_str, "o", 1) == 0)
7855 direct = FILTER_OUT;
718e3744 7856
d62a17ae 7857 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7858
d62a17ae 7859 return bgp_vty_return(vty, ret);
718e3744 7860}
7861
7862DEFUN (neighbor_filter_list,
7863 neighbor_filter_list_cmd,
de71d43e 7864 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7865 NEIGHBOR_STR
7866 NEIGHBOR_ADDR_STR2
7867 "Establish BGP filters\n"
7868 "AS path access-list name\n"
7869 "Filter incoming routes\n"
7870 "Filter outgoing routes\n")
7871{
d62a17ae 7872 int idx_peer = 1;
7873 int idx_word = 3;
7874 int idx_in_out = 4;
7875 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7876 bgp_node_safi(vty), argv[idx_word]->arg,
7877 argv[idx_in_out]->arg);
718e3744 7878}
7879
d62a17ae 7880ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
de71d43e 7881 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7882 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7883 "Establish BGP filters\n"
7884 "AS path access-list name\n"
7885 "Filter incoming routes\n"
7886 "Filter outgoing routes\n")
596c17ba 7887
718e3744 7888DEFUN (no_neighbor_filter_list,
7889 no_neighbor_filter_list_cmd,
de71d43e 7890 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7891 NO_STR
7892 NEIGHBOR_STR
7893 NEIGHBOR_ADDR_STR2
7894 "Establish BGP filters\n"
7895 "AS path access-list name\n"
7896 "Filter incoming routes\n"
7897 "Filter outgoing routes\n")
7898{
d62a17ae 7899 int idx_peer = 2;
7900 int idx_in_out = 5;
7901 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7902 bgp_node_afi(vty), bgp_node_safi(vty),
7903 argv[idx_in_out]->arg);
718e3744 7904}
6b0655a2 7905
d62a17ae 7906ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
de71d43e 7907 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7908 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7909 "Establish BGP filters\n"
7910 "AS path access-list name\n"
7911 "Filter incoming routes\n"
7912 "Filter outgoing routes\n")
596c17ba 7913
7f7940e6
MK
7914/* Set advertise-map to the peer. */
7915static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7916 afi_t afi, safi_t safi,
cf2ad4d8
MK
7917 const char *advertise_str,
7918 const char *condition_str, bool condition,
7919 bool set)
7f7940e6
MK
7920{
7921 int ret = CMD_WARNING_CONFIG_FAILED;
7922 struct peer *peer;
7923 struct route_map *advertise_map;
7924 struct route_map *condition_map;
7925
7926 peer = peer_and_group_lookup_vty(vty, ip_str);
7927 if (!peer)
7928 return ret;
7929
7930 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7931 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7932
cf2ad4d8
MK
7933 if (set)
7934 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7935 advertise_map, condition_str,
7936 condition_map, condition);
7937 else
7938 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7939 advertise_map, condition_str,
7940 condition_map, condition);
7f7940e6
MK
7941
7942 return bgp_vty_return(vty, ret);
7943}
7944
389e4f92
QY
7945DEFPY (bgp_condadv_period,
7946 bgp_condadv_period_cmd,
7947 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7948 NO_STR
7949 BGP_STR
7950 "Conditional advertisement settings\n"
7951 "Set period to rescan BGP table to check if condition is met\n"
7952 "Period between BGP table scans, in seconds; default 60\n")
7953{
7954 VTY_DECLVAR_CONTEXT(bgp, bgp);
7955
7956 bgp->condition_check_period =
7957 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7958
7959 return CMD_SUCCESS;
7960}
7961
cf2ad4d8 7962DEFPY (neighbor_advertise_map,
7f7940e6 7963 neighbor_advertise_map_cmd,
3ccddc25 7964 "[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 7965 NO_STR
7f7940e6
MK
7966 NEIGHBOR_STR
7967 NEIGHBOR_ADDR_STR2
7968 "Route-map to conditionally advertise routes\n"
7969 "Name of advertise map\n"
7970 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7971 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7972 "Name of the exist or non exist map\n")
7f7940e6 7973{
7f7940e6
MK
7974 bool condition = CONDITION_EXIST;
7975
52b84062 7976 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7977 condition = CONDITION_NON_EXIST;
7978
52b84062
MK
7979 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7980 bgp_node_safi(vty), advertise_str,
7981 condition_str, condition, !no);
7f7940e6
MK
7982}
7983
7984ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
3ccddc25 7985 "[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
7986 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7987 "Route-map to conditionally advertise routes\n"
7988 "Name of advertise map\n"
7989 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7990 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7991 "Name of the exist or non exist map\n")
7f7940e6 7992
718e3744 7993/* Set route-map to the peer. */
0ea8d871
IR
7994static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7995 afi_t afi, safi_t safi, const char *name_str,
7996 const char *direct_str)
718e3744 7997{
0ea8d871
IR
7998 int ret;
7999 struct peer *peer;
8000 int direct = RMAP_IN;
8001 struct route_map *route_map;
718e3744 8002
0ea8d871
IR
8003 peer = peer_and_group_lookup_vty(vty, ip_str);
8004 if (!peer)
d62a17ae 8005 return CMD_WARNING_CONFIG_FAILED;
718e3744 8006
0ea8d871
IR
8007 /* Check filter direction. */
8008 if (strncmp(direct_str, "in", 2) == 0)
8009 direct = RMAP_IN;
8010 else if (strncmp(direct_str, "o", 1) == 0)
8011 direct = RMAP_OUT;
718e3744 8012
0ea8d871
IR
8013 route_map = route_map_lookup_warn_noexist(vty, name_str);
8014 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 8015
0ea8d871
IR
8016 return bgp_vty_return(vty, ret);
8017}
8018
8019static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
8020 afi_t afi, safi_t safi,
8021 const char *direct_str)
8022{
8023 int ret;
8024 struct peer *peer;
8025 int direct = RMAP_IN;
8026
8027 peer = peer_and_group_lookup_vty(vty, ip_str);
8028 if (!peer)
8029 return CMD_WARNING_CONFIG_FAILED;
8030
8031 /* Check filter direction. */
8032 if (strncmp(direct_str, "in", 2) == 0)
8033 direct = RMAP_IN;
8034 else if (strncmp(direct_str, "o", 1) == 0)
8035 direct = RMAP_OUT;
8036
8037 ret = peer_route_map_unset(peer, afi, safi, direct);
8038
8039 return bgp_vty_return(vty, ret);
8040}
8041
8042DEFUN (neighbor_route_map,
8043 neighbor_route_map_cmd,
70dd370f 8044 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
0ea8d871
IR
8045 NEIGHBOR_STR
8046 NEIGHBOR_ADDR_STR2
8047 "Apply route map to neighbor\n"
8048 "Name of route map\n"
8049 "Apply map to incoming routes\n"
8050 "Apply map to outbound routes\n")
8051{
8052 int idx_peer = 1;
8053 int idx_word = 3;
8054 int idx_in_out = 4;
8055 return peer_route_map_set_vty(
8056 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8057 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 8058}
8059
d6d7ed37 8060ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
70dd370f 8061 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
d6d7ed37
IR
8062 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8063 "Apply route map to neighbor\n"
8064 "Name of route map\n"
8065 "Apply map to incoming routes\n"
8066 "Apply map to outbound routes\n")
8067
0ea8d871
IR
8068DEFUN (no_neighbor_route_map,
8069 no_neighbor_route_map_cmd,
70dd370f 8070 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
0ea8d871
IR
8071 NO_STR
8072 NEIGHBOR_STR
8073 NEIGHBOR_ADDR_STR2
8074 "Apply route map to neighbor\n"
8075 "Name of route map\n"
8076 "Apply map to incoming routes\n"
8077 "Apply map to outbound routes\n")
8078{
8079 int idx_peer = 2;
8080 int idx_in_out = 5;
8081 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
8082 bgp_node_afi(vty), bgp_node_safi(vty),
8083 argv[idx_in_out]->arg);
8084}
8085
8086ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
70dd370f 8087 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
d6d7ed37
IR
8088 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8089 "Apply route map to neighbor\n"
8090 "Name of route map\n"
8091 "Apply map to incoming routes\n"
8092 "Apply map to outbound routes\n")
8093
718e3744 8094/* Set unsuppress-map to the peer. */
d62a17ae 8095static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8096 afi_t afi, safi_t safi,
8097 const char *name_str)
718e3744 8098{
d62a17ae 8099 int ret;
8100 struct peer *peer;
1de27621 8101 struct route_map *route_map;
718e3744 8102
d62a17ae 8103 peer = peer_and_group_lookup_vty(vty, ip_str);
8104 if (!peer)
8105 return CMD_WARNING_CONFIG_FAILED;
718e3744 8106
1de27621
DA
8107 route_map = route_map_lookup_warn_noexist(vty, name_str);
8108 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 8109
d62a17ae 8110 return bgp_vty_return(vty, ret);
718e3744 8111}
8112
8113/* Unset route-map from the peer. */
d62a17ae 8114static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8115 afi_t afi, safi_t safi)
718e3744 8116{
d62a17ae 8117 int ret;
8118 struct peer *peer;
718e3744 8119
d62a17ae 8120 peer = peer_and_group_lookup_vty(vty, ip_str);
8121 if (!peer)
8122 return CMD_WARNING_CONFIG_FAILED;
718e3744 8123
d62a17ae 8124 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 8125
d62a17ae 8126 return bgp_vty_return(vty, ret);
718e3744 8127}
8128
8129DEFUN (neighbor_unsuppress_map,
8130 neighbor_unsuppress_map_cmd,
9ccf14f7 8131 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8132 NEIGHBOR_STR
8133 NEIGHBOR_ADDR_STR2
8134 "Route-map to selectively unsuppress suppressed routes\n"
8135 "Name of route map\n")
8136{
d62a17ae 8137 int idx_peer = 1;
8138 int idx_word = 3;
8139 return peer_unsuppress_map_set_vty(
8140 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8141 argv[idx_word]->arg);
718e3744 8142}
8143
d62a17ae 8144ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8145 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8146 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8147 "Route-map to selectively unsuppress suppressed routes\n"
8148 "Name of route map\n")
596c17ba 8149
718e3744 8150DEFUN (no_neighbor_unsuppress_map,
8151 no_neighbor_unsuppress_map_cmd,
9ccf14f7 8152 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8153 NO_STR
8154 NEIGHBOR_STR
8155 NEIGHBOR_ADDR_STR2
8156 "Route-map to selectively unsuppress suppressed routes\n"
8157 "Name of route map\n")
8158{
d62a17ae 8159 int idx_peer = 2;
8160 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8161 bgp_node_afi(vty),
8162 bgp_node_safi(vty));
718e3744 8163}
6b0655a2 8164
d62a17ae 8165ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8166 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8167 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8168 "Route-map to selectively unsuppress suppressed routes\n"
8169 "Name of route map\n")
596c17ba 8170
7e62b792
IR
8171static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
8172 afi_t afi, safi_t safi,
8173 const char *num_str,
8174 const char *threshold_str, int warning,
8175 const char *restart_str,
8176 const char *force_str)
8177{
8178 int ret;
8179 struct peer *peer;
8180 uint32_t max;
8181 uint8_t threshold;
8182 uint16_t restart;
8183
8184 peer = peer_and_group_lookup_vty(vty, ip_str);
8185 if (!peer)
8186 return CMD_WARNING_CONFIG_FAILED;
8187
8188 max = strtoul(num_str, NULL, 10);
8189 if (threshold_str)
8190 threshold = atoi(threshold_str);
8191 else
8192 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
8193
8194 if (restart_str)
8195 restart = atoi(restart_str);
8196 else
8197 restart = 0;
8198
8199 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
8200 restart, force_str ? true : false);
8201
8202 return bgp_vty_return(vty, ret);
8203}
8204
8205static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
8206 afi_t afi, safi_t safi)
8207{
8208 int ret;
8209 struct peer *peer;
8210
8211 peer = peer_and_group_lookup_vty(vty, ip_str);
8212 if (!peer)
8213 return CMD_WARNING_CONFIG_FAILED;
8214
8215 ret = peer_maximum_prefix_unset(peer, afi, safi);
8216
8217 return bgp_vty_return(vty, ret);
8218}
8219
fde246e8 8220/* Maximum number of prefix to be sent to the neighbor. */
1d80f243
IR
8221DEFUN(neighbor_maximum_prefix_out,
8222 neighbor_maximum_prefix_out_cmd,
8223 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8224 NEIGHBOR_STR
8225 NEIGHBOR_ADDR_STR2
8226 "Maximum number of prefixes to be sent to this peer\n"
8227 "Maximum no. of prefix limit\n")
fde246e8 8228{
80444d30 8229 int ret;
fde246e8
DA
8230 int idx_peer = 1;
8231 int idx_number = 3;
7e62b792
IR
8232 struct peer *peer;
8233 uint32_t max;
fde246e8
DA
8234 afi_t afi = bgp_node_afi(vty);
8235 safi_t safi = bgp_node_safi(vty);
8236
7e62b792
IR
8237 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8238 if (!peer)
fde246e8
DA
8239 return CMD_WARNING_CONFIG_FAILED;
8240
7e62b792 8241 max = strtoul(argv[idx_number]->arg, NULL, 10);
fde246e8 8242
80444d30 8243 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
fde246e8 8244
80444d30 8245 return bgp_vty_return(vty, ret);
fde246e8
DA
8246}
8247
1d80f243
IR
8248DEFUN(no_neighbor_maximum_prefix_out,
8249 no_neighbor_maximum_prefix_out_cmd,
bc03c622 8250 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
1d80f243
IR
8251 NO_STR
8252 NEIGHBOR_STR
8253 NEIGHBOR_ADDR_STR2
bc03c622
LS
8254 "Maximum number of prefixes to be sent to this peer\n"
8255 "Maximum no. of prefix limit\n")
fde246e8 8256{
80444d30 8257 int ret;
fde246e8 8258 int idx_peer = 2;
7e62b792 8259 struct peer *peer;
fde246e8
DA
8260 afi_t afi = bgp_node_afi(vty);
8261 safi_t safi = bgp_node_safi(vty);
8262
7e62b792
IR
8263 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8264 if (!peer)
fde246e8
DA
8265 return CMD_WARNING_CONFIG_FAILED;
8266
80444d30 8267 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
fde246e8 8268
80444d30 8269 return bgp_vty_return(vty, ret);
fde246e8
DA
8270}
8271
9cbd06e0
DA
8272/* Maximum number of prefix configuration. Prefix count is different
8273 for each peer configuration. So this configuration can be set for
718e3744 8274 each peer configuration. */
1d80f243
IR
8275DEFUN (neighbor_maximum_prefix,
8276 neighbor_maximum_prefix_cmd,
8277 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8278 NEIGHBOR_STR
8279 NEIGHBOR_ADDR_STR2
8280 "Maximum number of prefix accept from this peer\n"
8281 "maximum no. of prefix limit\n"
8282 "Force checking all received routes not only accepted\n")
718e3744 8283{
d62a17ae 8284 int idx_peer = 1;
8285 int idx_number = 3;
9cbd06e0 8286 int idx_force = 0;
7e62b792 8287 char *force = NULL;
9cbd06e0
DA
8288
8289 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8290 force = argv[idx_force]->arg;
9cbd06e0 8291
7e62b792
IR
8292 return peer_maximum_prefix_set_vty(
8293 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8294 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 8295}
8296
d62a17ae 8297ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8298 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 8299 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8300 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
8301 "maximum no. of prefix limit\n"
8302 "Force checking all received routes not only accepted\n")
596c17ba 8303
1d80f243
IR
8304DEFUN (neighbor_maximum_prefix_threshold,
8305 neighbor_maximum_prefix_threshold_cmd,
8306 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8307 NEIGHBOR_STR
8308 NEIGHBOR_ADDR_STR2
8309 "Maximum number of prefix accept from this peer\n"
8310 "maximum no. of prefix limit\n"
8311 "Threshold value (%) at which to generate a warning msg\n"
8312 "Force checking all received routes not only accepted\n")
e0701b79 8313{
d62a17ae 8314 int idx_peer = 1;
8315 int idx_number = 3;
8316 int idx_number_2 = 4;
9cbd06e0 8317 int idx_force = 0;
7e62b792 8318 char *force = NULL;
9cbd06e0
DA
8319
8320 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8321 force = argv[idx_force]->arg;
9cbd06e0 8322
7e62b792
IR
8323 return peer_maximum_prefix_set_vty(
8324 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8325 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 8326}
e0701b79 8327
d62a17ae 8328ALIAS_HIDDEN(
8329 neighbor_maximum_prefix_threshold,
8330 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 8331 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 8332 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8333 "Maximum number of prefix accept from this peer\n"
8334 "maximum no. of prefix limit\n"
9cbd06e0
DA
8335 "Threshold value (%) at which to generate a warning msg\n"
8336 "Force checking all received routes not only accepted\n")
596c17ba 8337
1d80f243
IR
8338DEFUN (neighbor_maximum_prefix_warning,
8339 neighbor_maximum_prefix_warning_cmd,
8340 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8341 NEIGHBOR_STR
8342 NEIGHBOR_ADDR_STR2
8343 "Maximum number of prefix accept from this peer\n"
8344 "maximum no. of prefix limit\n"
8345 "Only give warning message when limit is exceeded\n"
8346 "Force checking all received routes not only accepted\n")
718e3744 8347{
d62a17ae 8348 int idx_peer = 1;
8349 int idx_number = 3;
9cbd06e0 8350 int idx_force = 0;
7e62b792 8351 char *force = NULL;
9cbd06e0
DA
8352
8353 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8354 force = argv[idx_force]->arg;
9cbd06e0 8355
7e62b792
IR
8356 return peer_maximum_prefix_set_vty(
8357 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8358 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 8359}
8360
d62a17ae 8361ALIAS_HIDDEN(
8362 neighbor_maximum_prefix_warning,
8363 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 8364 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 8365 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8366 "Maximum number of prefix accept from this peer\n"
8367 "maximum no. of prefix limit\n"
9cbd06e0
DA
8368 "Only give warning message when limit is exceeded\n"
8369 "Force checking all received routes not only accepted\n")
596c17ba 8370
1d80f243
IR
8371DEFUN (neighbor_maximum_prefix_threshold_warning,
8372 neighbor_maximum_prefix_threshold_warning_cmd,
8373 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8374 NEIGHBOR_STR
8375 NEIGHBOR_ADDR_STR2
8376 "Maximum number of prefix accept from this peer\n"
8377 "maximum no. of prefix limit\n"
8378 "Threshold value (%) at which to generate a warning msg\n"
8379 "Only give warning message when limit is exceeded\n"
8380 "Force checking all received routes not only accepted\n")
e0701b79 8381{
d62a17ae 8382 int idx_peer = 1;
8383 int idx_number = 3;
8384 int idx_number_2 = 4;
9cbd06e0 8385 int idx_force = 0;
7e62b792 8386 char *force = NULL;
9cbd06e0
DA
8387
8388 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8389 force = argv[idx_force]->arg;
9cbd06e0 8390
7e62b792
IR
8391 return peer_maximum_prefix_set_vty(
8392 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8393 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 8394}
8395
d62a17ae 8396ALIAS_HIDDEN(
8397 neighbor_maximum_prefix_threshold_warning,
8398 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 8399 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 8400 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8401 "Maximum number of prefix accept from this peer\n"
8402 "maximum no. of prefix limit\n"
8403 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
8404 "Only give warning message when limit is exceeded\n"
8405 "Force checking all received routes not only accepted\n")
596c17ba 8406
1d80f243
IR
8407DEFUN (neighbor_maximum_prefix_restart,
8408 neighbor_maximum_prefix_restart_cmd,
8409 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8410 NEIGHBOR_STR
8411 NEIGHBOR_ADDR_STR2
8412 "Maximum number of prefix accept from this peer\n"
8413 "maximum no. of prefix limit\n"
8414 "Restart bgp connection after limit is exceeded\n"
8415 "Restart interval in minutes\n"
8416 "Force checking all received routes not only accepted\n")
0a486e5f 8417{
d62a17ae 8418 int idx_peer = 1;
8419 int idx_number = 3;
8420 int idx_number_2 = 5;
9cbd06e0 8421 int idx_force = 0;
7e62b792 8422 char *force = NULL;
9cbd06e0
DA
8423
8424 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8425 force = argv[idx_force]->arg;
9cbd06e0 8426
7e62b792
IR
8427 return peer_maximum_prefix_set_vty(
8428 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8429 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 8430}
8431
d62a17ae 8432ALIAS_HIDDEN(
8433 neighbor_maximum_prefix_restart,
8434 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 8435 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 8436 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8437 "Maximum number of prefix accept from this peer\n"
8438 "maximum no. of prefix limit\n"
8439 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8440 "Restart interval in minutes\n"
8441 "Force checking all received routes not only accepted\n")
596c17ba 8442
1d80f243
IR
8443DEFUN (neighbor_maximum_prefix_threshold_restart,
8444 neighbor_maximum_prefix_threshold_restart_cmd,
8445 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8446 NEIGHBOR_STR
8447 NEIGHBOR_ADDR_STR2
8448 "Maximum number of prefixes to accept from this peer\n"
8449 "maximum no. of prefix limit\n"
8450 "Threshold value (%) at which to generate a warning msg\n"
8451 "Restart bgp connection after limit is exceeded\n"
8452 "Restart interval in minutes\n"
8453 "Force checking all received routes not only accepted\n")
0a486e5f 8454{
d62a17ae 8455 int idx_peer = 1;
8456 int idx_number = 3;
8457 int idx_number_2 = 4;
8458 int idx_number_3 = 6;
9cbd06e0 8459 int idx_force = 0;
7e62b792 8460 char *force = NULL;
9cbd06e0
DA
8461
8462 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8463 force = argv[idx_force]->arg;
9cbd06e0 8464
7e62b792
IR
8465 return peer_maximum_prefix_set_vty(
8466 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8467 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8468 argv[idx_number_3]->arg, force);
d62a17ae 8469}
8470
8471ALIAS_HIDDEN(
8472 neighbor_maximum_prefix_threshold_restart,
8473 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 8474 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 8475 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8476 "Maximum number of prefixes to accept from this peer\n"
8477 "maximum no. of prefix limit\n"
8478 "Threshold value (%) at which to generate a warning msg\n"
8479 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8480 "Restart interval in minutes\n"
8481 "Force checking all received routes not only accepted\n")
596c17ba 8482
1d80f243
IR
8483DEFUN (no_neighbor_maximum_prefix,
8484 no_neighbor_maximum_prefix_cmd,
8485 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8486 NO_STR
8487 NEIGHBOR_STR
8488 NEIGHBOR_ADDR_STR2
8489 "Maximum number of prefixes to accept from this peer\n"
8490 "maximum no. of prefix limit\n"
8491 "Threshold value (%) at which to generate a warning msg\n"
8492 "Restart bgp connection after limit is exceeded\n"
8493 "Restart interval in minutes\n"
8494 "Only give warning message when limit is exceeded\n"
8495 "Force checking all received routes not only accepted\n")
718e3744 8496{
d62a17ae 8497 int idx_peer = 2;
7e62b792
IR
8498 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8499 bgp_node_afi(vty),
8500 bgp_node_safi(vty));
718e3744 8501}
e52702f2 8502
d62a17ae 8503ALIAS_HIDDEN(
8504 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8505 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 8506 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8507 "Maximum number of prefixes to accept from this peer\n"
8508 "maximum no. of prefix limit\n"
8509 "Threshold value (%) at which to generate a warning msg\n"
8510 "Restart bgp connection after limit is exceeded\n"
8511 "Restart interval in minutes\n"
9cbd06e0
DA
8512 "Only give warning message when limit is exceeded\n"
8513 "Force checking all received routes not only accepted\n")
596c17ba 8514
46dbf9d0
DA
8515/* "neighbor accept-own" */
8516DEFPY (neighbor_accept_own,
8517 neighbor_accept_own_cmd,
8518 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor accept-own",
8519 NO_STR
8520 NEIGHBOR_STR
8521 NEIGHBOR_ADDR_STR2
8522 "Enable handling of self-originated VPN routes containing ACCEPT_OWN community\n")
8523{
8524 struct peer *peer;
8525 afi_t afi = bgp_node_afi(vty);
8526 safi_t safi = bgp_node_safi(vty);
8527 int ret;
8528
8529 peer = peer_and_group_lookup_vty(vty, neighbor);
8530 if (!peer)
8531 return CMD_WARNING_CONFIG_FAILED;
8532
8533 if (no)
8534 ret = peer_af_flag_unset(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8535 else
8536 ret = peer_af_flag_set(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8537
8538 return bgp_vty_return(vty, ret);
8539}
8540
01da2d26
DA
8541/* "neighbor soo" */
8542DEFPY (neighbor_soo,
8543 neighbor_soo_cmd,
8544 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8545 NEIGHBOR_STR
8546 NEIGHBOR_ADDR_STR2
8547 "Set the Site-of-Origin (SoO) extended community\n"
8548 "VPN extended community\n")
8549{
8550 struct peer *peer;
8551 afi_t afi = bgp_node_afi(vty);
8552 safi_t safi = bgp_node_safi(vty);
8553 struct ecommunity *ecomm_soo;
8554
8555 peer = peer_and_group_lookup_vty(vty, neighbor);
8556 if (!peer)
8557 return CMD_WARNING_CONFIG_FAILED;
8558
8559 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8560 if (!ecomm_soo) {
8561 vty_out(vty, "%% Malformed SoO extended community\n");
8562 return CMD_WARNING;
8563 }
8564 ecommunity_str(ecomm_soo);
8565
8566 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8567 ecommunity_free(&peer->soo[afi][safi]);
8568 peer->soo[afi][safi] = ecomm_soo;
8569 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8570 }
8571
8572 return bgp_vty_return(vty,
8573 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8574}
8575
8576DEFPY (no_neighbor_soo,
8577 no_neighbor_soo_cmd,
8578 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8579 NO_STR
8580 NEIGHBOR_STR
8581 NEIGHBOR_ADDR_STR2
8582 "Set the Site-of-Origin (SoO) extended community\n"
8583 "VPN extended community\n")
8584{
8585 struct peer *peer;
8586 afi_t afi = bgp_node_afi(vty);
8587 safi_t safi = bgp_node_safi(vty);
8588
8589 peer = peer_and_group_lookup_vty(vty, neighbor);
8590 if (!peer)
8591 return CMD_WARNING_CONFIG_FAILED;
8592
8593 ecommunity_free(&peer->soo[afi][safi]);
8594
8595 return bgp_vty_return(
8596 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8597}
718e3744 8598
718e3744 8599/* "neighbor allowas-in" */
8600DEFUN (neighbor_allowas_in,
8601 neighbor_allowas_in_cmd,
fd8503f5 8602 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8603 NEIGHBOR_STR
8604 NEIGHBOR_ADDR_STR2
31500417 8605 "Accept as-path with my AS present in it\n"
f79f7a7b 8606 "Number of occurrences of AS number\n"
fd8503f5 8607 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8608{
d62a17ae 8609 int idx_peer = 1;
8610 int idx_number_origin = 3;
8611 int ret;
8612 int origin = 0;
8613 struct peer *peer;
8614 int allow_num = 0;
8615
8616 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8617 if (!peer)
8618 return CMD_WARNING_CONFIG_FAILED;
8619
8620 if (argc <= idx_number_origin)
8621 allow_num = 3;
8622 else {
8623 if (argv[idx_number_origin]->type == WORD_TKN)
8624 origin = 1;
8625 else
8626 allow_num = atoi(argv[idx_number_origin]->arg);
8627 }
8628
8629 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8630 allow_num, origin);
8631
8632 return bgp_vty_return(vty, ret);
8633}
8634
8635ALIAS_HIDDEN(
8636 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8637 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8638 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8639 "Accept as-path with my AS present in it\n"
f79f7a7b 8640 "Number of occurrences of AS number\n"
d62a17ae 8641 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8642
718e3744 8643DEFUN (no_neighbor_allowas_in,
8644 no_neighbor_allowas_in_cmd,
fd8503f5 8645 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8646 NO_STR
8647 NEIGHBOR_STR
8648 NEIGHBOR_ADDR_STR2
8334fd5a 8649 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8650 "Number of occurrences of AS number\n"
fd8503f5 8651 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8652{
d62a17ae 8653 int idx_peer = 2;
8654 int ret;
8655 struct peer *peer;
718e3744 8656
d62a17ae 8657 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8658 if (!peer)
8659 return CMD_WARNING_CONFIG_FAILED;
718e3744 8660
d62a17ae 8661 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8662 bgp_node_safi(vty));
718e3744 8663
d62a17ae 8664 return bgp_vty_return(vty, ret);
718e3744 8665}
6b0655a2 8666
d62a17ae 8667ALIAS_HIDDEN(
8668 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8669 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8670 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8671 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8672 "Number of occurrences of AS number\n"
d62a17ae 8673 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8674
28c6e247
IR
8675DEFUN (neighbor_ttl_security,
8676 neighbor_ttl_security_cmd,
8677 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8678 NEIGHBOR_STR
8679 NEIGHBOR_ADDR_STR2
8680 "BGP ttl-security parameters\n"
8681 "Specify the maximum number of hops to the BGP peer\n"
8682 "Number of hops to BGP peer\n")
fa411a21 8683{
d62a17ae 8684 int idx_peer = 1;
8685 int idx_number = 4;
28c6e247
IR
8686 struct peer *peer;
8687 int gtsm_hops;
d62a17ae 8688
28c6e247
IR
8689 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8690 if (!peer)
d62a17ae 8691 return CMD_WARNING_CONFIG_FAILED;
8692
28c6e247
IR
8693 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8694
8695 /*
8696 * If 'neighbor swpX', then this is for directly connected peers,
8697 * we should not accept a ttl-security hops value greater than 1.
8698 */
8699 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8700 vty_out(vty,
8701 "%s is directly connected peer, hops cannot exceed 1\n",
8702 argv[idx_peer]->arg);
8703 return CMD_WARNING_CONFIG_FAILED;
8704 }
7ebe625c 8705
28c6e247 8706 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
8707}
8708
1d80f243
IR
8709DEFUN (no_neighbor_ttl_security,
8710 no_neighbor_ttl_security_cmd,
8711 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8712 NO_STR
8713 NEIGHBOR_STR
8714 NEIGHBOR_ADDR_STR2
8715 "BGP ttl-security parameters\n"
8716 "Specify the maximum number of hops to the BGP peer\n"
8717 "Number of hops to BGP peer\n")
fa411a21 8718{
d62a17ae 8719 int idx_peer = 2;
28c6e247 8720 struct peer *peer;
fa411a21 8721
28c6e247
IR
8722 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8723 if (!peer)
d62a17ae 8724 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8725
28c6e247 8726 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 8727}
6b0655a2 8728
7c0e4312
DA
8729/* disable-addpath-rx */
8730DEFUN(neighbor_disable_addpath_rx,
8731 neighbor_disable_addpath_rx_cmd,
8732 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8733 NEIGHBOR_STR
8734 NEIGHBOR_ADDR_STR2
8735 "Do not accept additional paths\n")
8736{
8737 char *peer_str = argv[1]->arg;
8738 struct peer *peer;
8739 afi_t afi = bgp_node_afi(vty);
8740 safi_t safi = bgp_node_safi(vty);
8741
8742 peer = peer_and_group_lookup_vty(vty, peer_str);
8743 if (!peer)
8744 return CMD_WARNING_CONFIG_FAILED;
8745
8746 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8747 PEER_FLAG_DISABLE_ADDPATH_RX);
8748}
8749
8750DEFUN(no_neighbor_disable_addpath_rx,
8751 no_neighbor_disable_addpath_rx_cmd,
8752 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8753 NO_STR
8754 NEIGHBOR_STR
8755 NEIGHBOR_ADDR_STR2
8756 "Do not accept additional paths\n")
8757{
8758 char *peer_str = argv[2]->arg;
8759 struct peer *peer;
8760 afi_t afi = bgp_node_afi(vty);
8761 safi_t safi = bgp_node_safi(vty);
8762
8763 peer = peer_and_group_lookup_vty(vty, peer_str);
8764 if (!peer)
8765 return CMD_WARNING_CONFIG_FAILED;
8766
8767 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8768 PEER_FLAG_DISABLE_ADDPATH_RX);
8769}
8770
adbac85e
DW
8771DEFUN (neighbor_addpath_tx_all_paths,
8772 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8773 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8774 NEIGHBOR_STR
8775 NEIGHBOR_ADDR_STR2
8776 "Use addpath to advertise all paths to a neighbor\n")
8777{
d62a17ae 8778 int idx_peer = 1;
8779 struct peer *peer;
adbac85e 8780
d62a17ae 8781 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8782 if (!peer)
8783 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8784
dcc68b5e
MS
8785 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8786 BGP_ADDPATH_ALL);
8787 return CMD_SUCCESS;
adbac85e
DW
8788}
8789
d62a17ae 8790ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8791 neighbor_addpath_tx_all_paths_hidden_cmd,
8792 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8793 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8794 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8795
adbac85e
DW
8796DEFUN (no_neighbor_addpath_tx_all_paths,
8797 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8798 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8799 NO_STR
8800 NEIGHBOR_STR
8801 NEIGHBOR_ADDR_STR2
8802 "Use addpath to advertise all paths to a neighbor\n")
8803{
d62a17ae 8804 int idx_peer = 2;
dcc68b5e
MS
8805 struct peer *peer;
8806
8807 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8808 if (!peer)
8809 return CMD_WARNING_CONFIG_FAILED;
8810
8811 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8812 != BGP_ADDPATH_ALL) {
8813 vty_out(vty,
8814 "%% Peer not currently configured to transmit all paths.");
8815 return CMD_WARNING_CONFIG_FAILED;
8816 }
8817
8818 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8819 BGP_ADDPATH_NONE);
8820
8821 return CMD_SUCCESS;
adbac85e
DW
8822}
8823
d62a17ae 8824ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8825 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8826 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8827 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8828 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8829
06370dac
DW
8830DEFUN (neighbor_addpath_tx_bestpath_per_as,
8831 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8832 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8833 NEIGHBOR_STR
8834 NEIGHBOR_ADDR_STR2
8835 "Use addpath to advertise the bestpath per each neighboring AS\n")
8836{
d62a17ae 8837 int idx_peer = 1;
8838 struct peer *peer;
06370dac 8839
d62a17ae 8840 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8841 if (!peer)
8842 return CMD_WARNING_CONFIG_FAILED;
06370dac 8843
dcc68b5e
MS
8844 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8845 BGP_ADDPATH_BEST_PER_AS);
8846
8847 return CMD_SUCCESS;
06370dac
DW
8848}
8849
d62a17ae 8850ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8851 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8852 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8853 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8854 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8855
06370dac
DW
8856DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8857 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8858 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8859 NO_STR
8860 NEIGHBOR_STR
8861 NEIGHBOR_ADDR_STR2
8862 "Use addpath to advertise the bestpath per each neighboring AS\n")
8863{
d62a17ae 8864 int idx_peer = 2;
dcc68b5e
MS
8865 struct peer *peer;
8866
8867 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8868 if (!peer)
8869 return CMD_WARNING_CONFIG_FAILED;
8870
8871 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8872 != BGP_ADDPATH_BEST_PER_AS) {
8873 vty_out(vty,
8874 "%% Peer not currently configured to transmit all best path per as.");
8875 return CMD_WARNING_CONFIG_FAILED;
8876 }
8877
8878 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8879 BGP_ADDPATH_NONE);
8880
8881 return CMD_SUCCESS;
06370dac
DW
8882}
8883
d62a17ae 8884ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8885 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8886 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8887 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8888 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8889
2b31007c
RZ
8890DEFPY(
8891 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8892 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8893 NEIGHBOR_STR
8894 NEIGHBOR_ADDR_STR2
8895 "Detect AS loops before sending to neighbor\n")
8896{
8897 struct peer *peer;
8898
8899 peer = peer_and_group_lookup_vty(vty, neighbor);
8900 if (!peer)
8901 return CMD_WARNING_CONFIG_FAILED;
8902
8903 peer->as_path_loop_detection = true;
8904
8905 return CMD_SUCCESS;
8906}
8907
8908DEFPY(
8909 no_neighbor_aspath_loop_detection,
8910 no_neighbor_aspath_loop_detection_cmd,
8911 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8912 NO_STR
8913 NEIGHBOR_STR
8914 NEIGHBOR_ADDR_STR2
8915 "Detect AS loops before sending to neighbor\n")
8916{
8917 struct peer *peer;
8918
8919 peer = peer_and_group_lookup_vty(vty, neighbor);
8920 if (!peer)
8921 return CMD_WARNING_CONFIG_FAILED;
8922
8923 peer->as_path_loop_detection = false;
8924
8925 return CMD_SUCCESS;
8926}
8927
a5c6a9b1
DA
8928DEFPY(neighbor_path_attribute_discard,
8929 neighbor_path_attribute_discard_cmd,
8930 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard (1-255)...",
8931 NEIGHBOR_STR
8932 NEIGHBOR_ADDR_STR2
8933 "Manipulate path attributes from incoming UPDATE messages\n"
8934 "Drop specified attributes from incoming UPDATE messages\n"
8935 "Attribute number\n")
8936{
8937 struct peer *peer;
8938 int idx = 0;
14da03c5 8939 char *discard_attrs = NULL;
a5c6a9b1
DA
8940
8941 peer = peer_and_group_lookup_vty(vty, neighbor);
8942 if (!peer)
8943 return CMD_WARNING_CONFIG_FAILED;
8944
8945 argv_find(argv, argc, "(1-255)", &idx);
8946 if (idx)
8947 discard_attrs = argv_concat(argv, argc, idx);
8948
b986d7f4
DA
8949 bgp_path_attribute_discard_vty(vty, peer, discard_attrs, true);
8950
14da03c5
DA
8951 XFREE(MTYPE_TMP, discard_attrs);
8952
b986d7f4
DA
8953 return CMD_SUCCESS;
8954}
8955
8956DEFPY(no_neighbor_path_attribute_discard,
8957 no_neighbor_path_attribute_discard_cmd,
8958 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard [(1-255)]",
8959 NO_STR
8960 NEIGHBOR_STR
8961 NEIGHBOR_ADDR_STR2
8962 "Manipulate path attributes from incoming UPDATE messages\n"
8963 "Drop specified attributes from incoming UPDATE messages\n"
8964 "Attribute number\n")
8965{
8966 struct peer *peer;
8967 int idx = 0;
14da03c5 8968 char *discard_attrs = NULL;
b986d7f4
DA
8969
8970 peer = peer_and_group_lookup_vty(vty, neighbor);
8971 if (!peer)
8972 return CMD_WARNING_CONFIG_FAILED;
8973
8974 argv_find(argv, argc, "(1-255)", &idx);
8975 if (idx)
8976 discard_attrs = argv[idx]->arg;
8977
8978 bgp_path_attribute_discard_vty(vty, peer, discard_attrs, false);
a5c6a9b1 8979
14da03c5
DA
8980 XFREE(MTYPE_TMP, discard_attrs);
8981
a5c6a9b1
DA
8982 return CMD_SUCCESS;
8983}
8984
e2863b4f
DA
8985DEFPY(neighbor_path_attribute_treat_as_withdraw,
8986 neighbor_path_attribute_treat_as_withdraw_cmd,
8987 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute treat-as-withdraw (1-255)...",
8988 NEIGHBOR_STR
8989 NEIGHBOR_ADDR_STR2
8990 "Manipulate path attributes from incoming UPDATE messages\n"
8991 "Treat-as-withdraw any incoming BGP UPDATE messages that contain the specified attribute\n"
8992 "Attribute number\n")
8993{
8994 struct peer *peer;
8995 int idx = 0;
14da03c5 8996 char *withdraw_attrs = NULL;
e2863b4f
DA
8997
8998 peer = peer_and_group_lookup_vty(vty, neighbor);
8999 if (!peer)
9000 return CMD_WARNING_CONFIG_FAILED;
9001
9002 argv_find(argv, argc, "(1-255)", &idx);
9003 if (idx)
9004 withdraw_attrs = argv_concat(argv, argc, idx);
9005
9006 bgp_path_attribute_withdraw_vty(vty, peer, withdraw_attrs, true);
9007
14da03c5
DA
9008 XFREE(MTYPE_TMP, withdraw_attrs);
9009
e2863b4f
DA
9010 return CMD_SUCCESS;
9011}
9012
9013DEFPY(no_neighbor_path_attribute_treat_as_withdraw,
9014 no_neighbor_path_attribute_treat_as_withdraw_cmd,
9015 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute treat-as-withdraw (1-255)...",
9016 NO_STR
9017 NEIGHBOR_STR
9018 NEIGHBOR_ADDR_STR2
9019 "Manipulate path attributes from incoming UPDATE messages\n"
9020 "Treat-as-withdraw any incoming BGP UPDATE messages that contain the specified attribute\n"
9021 "Attribute number\n")
9022{
9023 struct peer *peer;
9024 int idx = 0;
14da03c5 9025 char *withdraw_attrs = NULL;
e2863b4f
DA
9026
9027 peer = peer_and_group_lookup_vty(vty, neighbor);
9028 if (!peer)
9029 return CMD_WARNING_CONFIG_FAILED;
9030
9031 argv_find(argv, argc, "(1-255)", &idx);
9032 if (idx)
9033 withdraw_attrs = argv_concat(argv, argc, idx);
9034
9035 bgp_path_attribute_withdraw_vty(vty, peer, withdraw_attrs, false);
9036
14da03c5
DA
9037 XFREE(MTYPE_TMP, withdraw_attrs);
9038
e2863b4f
DA
9039 return CMD_SUCCESS;
9040}
9041
b9c7bc5a 9042static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 9043 struct ecommunity **list, bool is_rt6)
ddb5b488 9044{
b9c7bc5a
PZ
9045 struct ecommunity *ecom = NULL;
9046 struct ecommunity *ecomadd;
ddb5b488 9047
b9c7bc5a 9048 for (; argc; --argc, ++argv) {
9a659715
PG
9049 if (is_rt6)
9050 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
9051 ECOMMUNITY_ROUTE_TARGET,
9052 0);
9053 else
9054 ecomadd = ecommunity_str2com(argv[0]->arg,
9055 ECOMMUNITY_ROUTE_TARGET,
9056 0);
b9c7bc5a
PZ
9057 if (!ecomadd) {
9058 vty_out(vty, "Malformed community-list value\n");
9059 if (ecom)
9060 ecommunity_free(&ecom);
9061 return CMD_WARNING_CONFIG_FAILED;
9062 }
ddb5b488 9063
b9c7bc5a
PZ
9064 if (ecom) {
9065 ecommunity_merge(ecom, ecomadd);
9066 ecommunity_free(&ecomadd);
9067 } else {
9068 ecom = ecomadd;
9069 }
9070 }
9071
9072 if (*list) {
9073 ecommunity_free(&*list);
ddb5b488 9074 }
b9c7bc5a
PZ
9075 *list = ecom;
9076
9077 return CMD_SUCCESS;
ddb5b488
PZ
9078}
9079
0ca70ba5
DS
9080/*
9081 * v2vimport is true if we are handling a `import vrf ...` command
9082 */
9083static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 9084{
0ca70ba5
DS
9085 afi_t afi;
9086
ddb5b488 9087 switch (vty->node) {
b9c7bc5a 9088 case BGP_IPV4_NODE:
0ca70ba5
DS
9089 afi = AFI_IP;
9090 break;
b9c7bc5a 9091 case BGP_IPV6_NODE:
0ca70ba5
DS
9092 afi = AFI_IP6;
9093 break;
ddb5b488
PZ
9094 default:
9095 vty_out(vty,
b9c7bc5a 9096 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 9097 return AFI_MAX;
ddb5b488 9098 }
69b07479 9099
0ca70ba5
DS
9100 if (!v2vimport) {
9101 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9102 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9103 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9104 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9105 vty_out(vty,
9106 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
9107 return AFI_MAX;
9108 }
9109 } else {
9110 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9111 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9112 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9113 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9114 vty_out(vty,
9115 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
9116 return AFI_MAX;
9117 }
9118 }
9119 return afi;
ddb5b488
PZ
9120}
9121
585f1adc
IR
9122DEFPY (af_rd_vpn_export,
9123 af_rd_vpn_export_cmd,
9124 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
9125 NO_STR
9126 "Specify route distinguisher\n"
9127 "Between current address-family and vpn\n"
9128 "For routes leaked from current address-family to vpn\n"
9129 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 9130{
585f1adc
IR
9131 VTY_DECLVAR_CONTEXT(bgp, bgp);
9132 struct prefix_rd prd;
9133 int ret;
ddb5b488 9134 afi_t afi;
b9c7bc5a 9135 int idx = 0;
585f1adc 9136 bool yes = true;
b9c7bc5a 9137
585f1adc
IR
9138 if (argv_find(argv, argc, "no", &idx))
9139 yes = false;
ddb5b488 9140
585f1adc
IR
9141 if (yes) {
9142 ret = str2prefix_rd(rd_str, &prd);
9143 if (!ret) {
9144 vty_out(vty, "%% Malformed rd\n");
9145 return CMD_WARNING_CONFIG_FAILED;
9146 }
9147 }
ddb5b488 9148
585f1adc
IR
9149 afi = vpn_policy_getafi(vty, bgp, false);
9150 if (afi == AFI_MAX)
9151 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9152
585f1adc
IR
9153 /*
9154 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9155 */
9156 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9157 bgp_get_default(), bgp);
ddb5b488 9158
585f1adc 9159 if (yes) {
fa566a94
PG
9160 bgp->vpn_policy[afi].tovpn_rd_pretty =
9161 XSTRDUP(MTYPE_BGP, rd_str);
585f1adc
IR
9162 bgp->vpn_policy[afi].tovpn_rd = prd;
9163 SET_FLAG(bgp->vpn_policy[afi].flags,
9164 BGP_VPN_POLICY_TOVPN_RD_SET);
9165 } else {
fa566a94 9166 XFREE(MTYPE_BGP, bgp->vpn_policy[afi].tovpn_rd_pretty);
585f1adc
IR
9167 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9168 BGP_VPN_POLICY_TOVPN_RD_SET);
9169 }
69b07479 9170
585f1adc
IR
9171 /* post-change: re-export vpn routes */
9172 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9173 bgp_get_default(), bgp);
9174
9175 return CMD_SUCCESS;
ddb5b488
PZ
9176}
9177
b9c7bc5a
PZ
9178ALIAS (af_rd_vpn_export,
9179 af_no_rd_vpn_export_cmd,
9180 "no rd vpn export",
ddb5b488 9181 NO_STR
b9c7bc5a
PZ
9182 "Specify route distinguisher\n"
9183 "Between current address-family and vpn\n"
9184 "For routes leaked from current address-family to vpn\n")
ddb5b488 9185
b9c7bc5a
PZ
9186DEFPY (af_label_vpn_export,
9187 af_label_vpn_export_cmd,
e70e9f8e 9188 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 9189 NO_STR
ddb5b488 9190 "label value for VRF\n"
b9c7bc5a
PZ
9191 "Between current address-family and vpn\n"
9192 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
9193 "Label Value <0-1048575>\n"
9194 "Automatically assign a label\n")
ddb5b488
PZ
9195{
9196 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 9197 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 9198 afi_t afi;
b9c7bc5a 9199 int idx = 0;
c6423c31 9200 bool yes = true;
b9c7bc5a
PZ
9201
9202 if (argv_find(argv, argc, "no", &idx))
c6423c31 9203 yes = false;
ddb5b488 9204
21a16cc2
PZ
9205 /* If "no ...", squash trailing parameter */
9206 if (!yes)
9207 label_auto = NULL;
9208
e70e9f8e
PZ
9209 if (yes) {
9210 if (!label_auto)
9211 label = label_val; /* parser should force unsigned */
9212 }
ddb5b488 9213
0ca70ba5 9214 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9215 if (afi == AFI_MAX)
9216 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 9217
e70e9f8e 9218
69b07479
DS
9219 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9220 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9221 /* no change */
9222 return CMD_SUCCESS;
e70e9f8e 9223
69b07479
DS
9224 /*
9225 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9226 */
9227 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9228 bgp_get_default(), bgp);
9229
9230 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9231 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9232
9233 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9234
9235 /*
9236 * label has previously been automatically
9237 * assigned by labelpool: release it
9238 *
9239 * NB if tovpn_label == MPLS_LABEL_NONE it
9240 * means the automatic assignment is in flight
9241 * and therefore the labelpool callback must
9242 * detect that the auto label is not needed.
9243 */
9244
9245 bgp_lp_release(LP_TYPE_VRF,
9246 &bgp->vpn_policy[afi],
9247 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 9248 }
69b07479
DS
9249 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9250 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9251 }
ddb5b488 9252
69b07479
DS
9253 bgp->vpn_policy[afi].tovpn_label = label;
9254 if (label_auto) {
9255 SET_FLAG(bgp->vpn_policy[afi].flags,
9256 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9257 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9258 vpn_leak_label_callback);
ddb5b488
PZ
9259 }
9260
69b07479
DS
9261 /* post-change: re-export vpn routes */
9262 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9263 bgp_get_default(), bgp);
9264
0d020cd6 9265 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
9266 return CMD_SUCCESS;
9267}
9268
b72c9e14
HS
9269DEFPY (af_sid_vpn_export,
9270 af_sid_vpn_export_cmd,
46279a11 9271 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
b72c9e14
HS
9272 NO_STR
9273 "sid value for VRF\n"
9274 "Between current address-family and vpn\n"
9275 "For routes leaked from current address-family to vpn\n"
9276 "Sid allocation index\n"
9277 "Automatically assign a label\n")
9278{
9279 VTY_DECLVAR_CONTEXT(bgp, bgp);
9280 afi_t afi;
9281 int debug = 0;
9282 int idx = 0;
9283 bool yes = true;
9284
9285 if (argv_find(argv, argc, "no", &idx))
9286 yes = false;
9287 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9288 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9289
9290 afi = vpn_policy_getafi(vty, bgp, false);
9291 if (afi == AFI_MAX)
9292 return CMD_WARNING_CONFIG_FAILED;
9293
9294 if (!yes) {
d7967830
DS
9295 /* when SID is not set, do nothing */
9296 if ((bgp->vpn_policy[afi].tovpn_sid_index == 0) &&
9297 !CHECK_FLAG(bgp->vpn_policy[afi].flags,
9298 BGP_VPN_POLICY_TOVPN_SID_AUTO))
9299 return CMD_SUCCESS;
9300
9301 /* pre-change */
9302 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9303 bgp_get_default(), bgp);
9304 bgp->vpn_policy[afi].tovpn_sid_index = 0;
9305 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9306 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9307
9308 /* post-change */
9309 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9310 bgp_get_default(), bgp);
9311
9312 return CMD_SUCCESS;
b72c9e14
HS
9313 }
9314
527588aa
CS
9315 if (bgp->tovpn_sid_index != 0 ||
9316 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
9317 vty_out(vty,
9318 "per-vrf sid and per-af sid are mutually exclusive\n"
9319 "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9320 return CMD_WARNING_CONFIG_FAILED;
9321 }
9322
b72c9e14
HS
9323 /* skip when it's already configured */
9324 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9325 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9326 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9327 return CMD_SUCCESS;
9328
7de4c885
HS
9329 /*
9330 * mode change between sid_idx and sid_auto isn't supported.
9331 * user must negate sid vpn export when they want to change the mode
9332 */
b72c9e14
HS
9333 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9334 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9335 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9336 vty_out(vty, "it's already configured as %s.\n",
9337 sid_auto ? "auto-mode" : "idx-mode");
9338 return CMD_WARNING_CONFIG_FAILED;
9339 }
9340
9341 /* pre-change */
9342 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9343 bgp_get_default(), bgp);
9344
9345 if (sid_auto) {
9346 /* SID allocation auto-mode */
9347 if (debug)
9348 zlog_debug("%s: auto sid alloc.", __func__);
9349 SET_FLAG(bgp->vpn_policy[afi].flags,
9350 BGP_VPN_POLICY_TOVPN_SID_AUTO);
d7967830 9351 } else if (sid_idx != 0) {
b72c9e14
HS
9352 /* SID allocation index-mode */
9353 if (debug)
9354 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9355 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9356 }
9357
9358 /* post-change */
9359 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9360 bgp_get_default(), bgp);
9361 return CMD_SUCCESS;
9362}
9363
527588aa
CS
9364DEFPY (bgp_sid_vpn_export,
9365 bgp_sid_vpn_export_cmd,
346bbb39 9366 "[no] sid vpn per-vrf export <(1-1048575)$sid_idx|auto$sid_auto>",
527588aa
CS
9367 NO_STR
9368 "sid value for VRF\n"
9369 "Between current vrf and vpn\n"
9370 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9371 "For routes leaked from current vrf to vpn\n"
9372 "Sid allocation index\n"
9373 "Automatically assign a label\n")
9374{
9375 VTY_DECLVAR_CONTEXT(bgp, bgp);
9376 int debug;
9377
9378 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9379 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9380
9381 if (no) {
e606d8ec
CS
9382 /* when per-VRF SID is not set, do nothing */
9383 if (bgp->tovpn_sid_index == 0 &&
9384 !CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))
9385 return CMD_SUCCESS;
9386
9387 sid_idx = 0;
9388 sid_auto = false;
9389 bgp->tovpn_sid_index = 0;
9390 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
527588aa
CS
9391 }
9392
9393 if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9394 CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9395 BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9396 bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9397 CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9398 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9399 vty_out(vty,
9400 "per-vrf sid and per-af sid are mutually exclusive\n"
9401 "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9402 return CMD_WARNING_CONFIG_FAILED;
9403 }
9404
9405 /* skip when it's already configured */
9406 if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9407 (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9408 return CMD_SUCCESS;
9409
9410 /*
9411 * mode change between sid_idx and sid_auto isn't supported.
9412 * user must negate sid vpn export when they want to change the mode
9413 */
9414 if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9415 (sid_idx != 0 &&
9416 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9417 vty_out(vty, "it's already configured as %s.\n",
9418 sid_auto ? "auto-mode" : "idx-mode");
9419 return CMD_WARNING_CONFIG_FAILED;
9420 }
9421
9422 /* pre-change */
9423 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9424 bgp);
9425 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9426 bgp);
9427
9428 if (sid_auto) {
9429 /* SID allocation auto-mode */
9430 if (debug)
9431 zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9432 SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
e606d8ec 9433 } else if (sid_idx != 0) {
527588aa
CS
9434 /* SID allocation index-mode */
9435 if (debug)
9436 zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9437 sid_idx);
9438 bgp->tovpn_sid_index = sid_idx;
9439 }
9440
9441 /* post-change */
9442 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9443 bgp);
9444 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9445 bgp_get_default(), bgp);
9446
9447 return CMD_SUCCESS;
9448}
9449
b9c7bc5a
PZ
9450ALIAS (af_label_vpn_export,
9451 af_no_label_vpn_export_cmd,
9452 "no label vpn export",
9453 NO_STR
9454 "label value for VRF\n"
9455 "Between current address-family and vpn\n"
9456 "For routes leaked from current address-family to vpn\n")
ddb5b488 9457
e606d8ec
CS
9458ALIAS (bgp_sid_vpn_export,
9459 no_bgp_sid_vpn_export_cmd,
9460 "no$no sid vpn per-vrf export",
9461 NO_STR
9462 "sid value for VRF\n"
9463 "Between current vrf and vpn\n"
9464 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9465 "For routes leaked from current vrf to vpn\n")
9466
585f1adc 9467DEFPY (af_nexthop_vpn_export,
b9c7bc5a 9468 af_nexthop_vpn_export_cmd,
8c85ca28 9469 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 9470 NO_STR
ddb5b488 9471 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
9472 "Between current address-family and vpn\n"
9473 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9474 "IPv4 prefix\n"
9475 "IPv6 prefix\n")
9476{
585f1adc 9477 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 9478 afi_t afi;
ddb5b488
PZ
9479 struct prefix p;
9480
8c85ca28
QY
9481 if (!no) {
9482 if (!nexthop_su) {
9483 vty_out(vty, "%% Nexthop required\n");
9484 return CMD_WARNING_CONFIG_FAILED;
9485 }
8c85ca28 9486 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
9487 return CMD_WARNING_CONFIG_FAILED;
9488 }
ddb5b488 9489
585f1adc
IR
9490 afi = vpn_policy_getafi(vty, bgp, false);
9491 if (afi == AFI_MAX)
9492 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9493
585f1adc
IR
9494 /*
9495 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9496 */
9497 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9498 bgp_get_default(), bgp);
ddb5b488 9499
585f1adc
IR
9500 if (!no) {
9501 bgp->vpn_policy[afi].tovpn_nexthop = p;
9502 SET_FLAG(bgp->vpn_policy[afi].flags,
9503 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9504 } else {
9505 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9506 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9507 }
69b07479 9508
585f1adc
IR
9509 /* post-change: re-export vpn routes */
9510 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9511 bgp_get_default(), bgp);
37a87b8f 9512
585f1adc 9513 return CMD_SUCCESS;
ddb5b488
PZ
9514}
9515
b9c7bc5a 9516static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 9517{
b9c7bc5a
PZ
9518 if (!strcmp(dstr, "import")) {
9519 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9520 } else if (!strcmp(dstr, "export")) {
9521 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9522 } else if (!strcmp(dstr, "both")) {
9523 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9524 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9525 } else {
9526 vty_out(vty, "%% direction parse error\n");
9527 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9528 }
ddb5b488
PZ
9529 return CMD_SUCCESS;
9530}
9531
b9c7bc5a
PZ
9532DEFPY (af_rt_vpn_imexport,
9533 af_rt_vpn_imexport_cmd,
9534 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9535 NO_STR
9536 "Specify route target list\n"
ddb5b488 9537 "Specify route target list\n"
b9c7bc5a
PZ
9538 "Between current address-family and vpn\n"
9539 "For routes leaked from vpn to current address-family: match any\n"
9540 "For routes leaked from current address-family to vpn: set\n"
9541 "both import: match any and export: set\n"
ddb5b488
PZ
9542 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9543{
9544 VTY_DECLVAR_CONTEXT(bgp, bgp);
9545 int ret;
9546 struct ecommunity *ecom = NULL;
9547 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 9548 enum vpn_policy_direction dir;
ddb5b488
PZ
9549 afi_t afi;
9550 int idx = 0;
c6423c31 9551 bool yes = true;
ddb5b488 9552
b9c7bc5a 9553 if (argv_find(argv, argc, "no", &idx))
c6423c31 9554 yes = false;
b9c7bc5a 9555
0ca70ba5 9556 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9557 if (afi == AFI_MAX)
9558 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9559
b9c7bc5a 9560 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
9561 if (ret != CMD_SUCCESS)
9562 return ret;
9563
b9c7bc5a
PZ
9564 if (yes) {
9565 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9566 vty_out(vty, "%% Missing RTLIST\n");
9567 return CMD_WARNING_CONFIG_FAILED;
9568 }
c6423c31 9569 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
9570 if (ret != CMD_SUCCESS) {
9571 return ret;
9572 }
ddb5b488
PZ
9573 }
9574
69b07479
DS
9575 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9576 if (!dodir[dir])
ddb5b488 9577 continue;
ddb5b488 9578
69b07479 9579 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9580
69b07479
DS
9581 if (yes) {
9582 if (bgp->vpn_policy[afi].rtlist[dir])
9583 ecommunity_free(
9584 &bgp->vpn_policy[afi].rtlist[dir]);
9585 bgp->vpn_policy[afi].rtlist[dir] =
9586 ecommunity_dup(ecom);
9587 } else {
9588 if (bgp->vpn_policy[afi].rtlist[dir])
9589 ecommunity_free(
9590 &bgp->vpn_policy[afi].rtlist[dir]);
9591 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 9592 }
69b07479
DS
9593
9594 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9595 }
69b07479 9596
d555f3e9
PZ
9597 if (ecom)
9598 ecommunity_free(&ecom);
ddb5b488
PZ
9599
9600 return CMD_SUCCESS;
9601}
9602
b9c7bc5a
PZ
9603ALIAS (af_rt_vpn_imexport,
9604 af_no_rt_vpn_imexport_cmd,
9605 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
9606 NO_STR
9607 "Specify route target list\n"
b9c7bc5a
PZ
9608 "Specify route target list\n"
9609 "Between current address-family and vpn\n"
9610 "For routes leaked from vpn to current address-family\n"
9611 "For routes leaked from current address-family to vpn\n"
9612 "both import and export\n")
9613
585f1adc 9614DEFPY (af_route_map_vpn_imexport,
b9c7bc5a
PZ
9615 af_route_map_vpn_imexport_cmd,
9616/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9617 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9618 NO_STR
ddb5b488 9619 "Specify route map\n"
b9c7bc5a
PZ
9620 "Between current address-family and vpn\n"
9621 "For routes leaked from vpn to current address-family\n"
9622 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9623 "name of route-map\n")
9624{
585f1adc
IR
9625 VTY_DECLVAR_CONTEXT(bgp, bgp);
9626 int ret;
9627 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 9628 enum vpn_policy_direction dir;
ddb5b488 9629 afi_t afi;
ddb5b488 9630 int idx = 0;
585f1adc 9631 bool yes = true;
ddb5b488 9632
585f1adc
IR
9633 if (argv_find(argv, argc, "no", &idx))
9634 yes = false;
ddb5b488 9635
585f1adc
IR
9636 afi = vpn_policy_getafi(vty, bgp, false);
9637 if (afi == AFI_MAX)
9638 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9639
585f1adc
IR
9640 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9641 if (ret != CMD_SUCCESS)
9642 return ret;
ddb5b488 9643
585f1adc
IR
9644 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9645 if (!dodir[dir])
9646 continue;
69b07479 9647
585f1adc
IR
9648 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9649
9650 if (yes) {
9651 if (bgp->vpn_policy[afi].rmap_name[dir])
9652 XFREE(MTYPE_ROUTE_MAP_NAME,
9653 bgp->vpn_policy[afi].rmap_name[dir]);
9654 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9655 MTYPE_ROUTE_MAP_NAME, rmap_str);
9656 bgp->vpn_policy[afi].rmap[dir] =
9657 route_map_lookup_warn_noexist(vty, rmap_str);
9658 if (!bgp->vpn_policy[afi].rmap[dir])
9659 return CMD_SUCCESS;
9660 } else {
9661 if (bgp->vpn_policy[afi].rmap_name[dir])
9662 XFREE(MTYPE_ROUTE_MAP_NAME,
9663 bgp->vpn_policy[afi].rmap_name[dir]);
9664 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9665 bgp->vpn_policy[afi].rmap[dir] = NULL;
9666 }
9667
9668 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9669 }
ddb5b488 9670
585f1adc 9671 return CMD_SUCCESS;
ddb5b488
PZ
9672}
9673
b9c7bc5a
PZ
9674ALIAS (af_route_map_vpn_imexport,
9675 af_no_route_map_vpn_imexport_cmd,
9676 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
9677 NO_STR
9678 "Specify route map\n"
b9c7bc5a
PZ
9679 "Between current address-family and vpn\n"
9680 "For routes leaked from vpn to current address-family\n"
9681 "For routes leaked from current address-family to vpn\n")
9682
bb4f6190 9683DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 9684 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
9685 "Import routes from another VRF\n"
9686 "Vrf routes being filtered\n"
9687 "Specify route map\n"
9688 "name of route-map\n")
9689{
9690 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 9691 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
bb4f6190 9692 afi_t afi;
bb4f6190
DS
9693 struct bgp *bgp_default;
9694
0ca70ba5 9695 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
9696 if (afi == AFI_MAX)
9697 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
9698
9699 bgp_default = bgp_get_default();
9700 if (!bgp_default) {
9701 int32_t ret;
9702 as_t as = bgp->as;
9703
9704 /* Auto-create assuming the same AS */
5d5393b9 9705 ret = bgp_get_vty(&bgp_default, &as, NULL,
e55b0883
PG
9706 BGP_INSTANCE_TYPE_DEFAULT, NULL,
9707 ASNOTATION_UNDEFINED);
bb4f6190
DS
9708
9709 if (ret) {
9710 vty_out(vty,
9711 "VRF default is not configured as a bgp instance\n");
9712 return CMD_WARNING;
9713 }
9714 }
9715
69b07479 9716 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 9717
ae6a6fb4
DS
9718 if (bgp->vpn_policy[afi].rmap_name[dir])
9719 XFREE(MTYPE_ROUTE_MAP_NAME,
9720 bgp->vpn_policy[afi].rmap_name[dir]);
9721 bgp->vpn_policy[afi].rmap_name[dir] =
9722 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9723 bgp->vpn_policy[afi].rmap[dir] =
9724 route_map_lookup_warn_noexist(vty, rmap_str);
9725 if (!bgp->vpn_policy[afi].rmap[dir])
9726 return CMD_SUCCESS;
9727
9728 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9729 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 9730
69b07479
DS
9731 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9732
bb4f6190
DS
9733 return CMD_SUCCESS;
9734}
9735
ae6a6fb4
DS
9736DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9737 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
9738 NO_STR
9739 "Import routes from another VRF\n"
9740 "Vrf routes being filtered\n"
ae6a6fb4
DS
9741 "Specify route map\n"
9742 "name of route-map\n")
9743{
9744 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 9745 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
ae6a6fb4
DS
9746 afi_t afi;
9747
9748 afi = vpn_policy_getafi(vty, bgp, true);
9749 if (afi == AFI_MAX)
9750 return CMD_WARNING_CONFIG_FAILED;
9751
9752 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9753
9754 if (bgp->vpn_policy[afi].rmap_name[dir])
9755 XFREE(MTYPE_ROUTE_MAP_NAME,
9756 bgp->vpn_policy[afi].rmap_name[dir]);
9757 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9758 bgp->vpn_policy[afi].rmap[dir] = NULL;
9759
9760 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9761 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9762 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9763
9764 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9765
9766 return CMD_SUCCESS;
9767}
bb4f6190 9768
585f1adc
IR
9769DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9770 "[no] import vrf VIEWVRFNAME$import_name",
9771 NO_STR
9772 "Import routes from another VRF\n"
9773 "VRF to import from\n"
9774 "The name of the VRF\n")
12a844a5 9775{
585f1adc
IR
9776 VTY_DECLVAR_CONTEXT(bgp, bgp);
9777 struct listnode *node;
9778 struct bgp *vrf_bgp, *bgp_default;
9779 int32_t ret = 0;
9780 as_t as = bgp->as;
9781 bool remove = false;
9782 int32_t idx = 0;
9783 char *vname;
9784 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
9785 safi_t safi;
9786 afi_t afi;
9787
867f0cca 9788 if (import_name == NULL) {
9789 vty_out(vty, "%% Missing import name\n");
9790 return CMD_WARNING;
9791 }
9792
ae6a6fb4
DS
9793 if (strcmp(import_name, "route-map") == 0) {
9794 vty_out(vty, "%% Must include route-map name\n");
9795 return CMD_WARNING;
9796 }
9797
585f1adc
IR
9798 if (argv_find(argv, argc, "no", &idx))
9799 remove = true;
9800
9801 afi = vpn_policy_getafi(vty, bgp, true);
9802 if (afi == AFI_MAX)
9803 return CMD_WARNING_CONFIG_FAILED;
9804
12a844a5
DS
9805 safi = bgp_node_safi(vty);
9806
585f1adc
IR
9807 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9808 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9809 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9810 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9811 remove ? "unimport" : "import", import_name);
9812 return CMD_WARNING;
9813 }
25679caa 9814
585f1adc
IR
9815 bgp_default = bgp_get_default();
9816 if (!bgp_default) {
9817 /* Auto-create assuming the same AS */
9818 ret = bgp_get_vty(&bgp_default, &as, NULL,
e55b0883
PG
9819 BGP_INSTANCE_TYPE_DEFAULT, NULL,
9820 ASNOTATION_UNDEFINED);
12a844a5 9821
585f1adc
IR
9822 if (ret) {
9823 vty_out(vty,
9824 "VRF default is not configured as a bgp instance\n");
9825 return CMD_WARNING;
9826 }
9827 }
12a844a5 9828
585f1adc
IR
9829 vrf_bgp = bgp_lookup_by_name(import_name);
9830 if (!vrf_bgp) {
9831 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9832 vrf_bgp = bgp_default;
9833 else
9834 /* Auto-create assuming the same AS */
e55b0883
PG
9835 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type,
9836 NULL, ASNOTATION_UNDEFINED);
585f1adc
IR
9837 if (ret) {
9838 vty_out(vty,
9839 "VRF %s is not configured as a bgp instance\n",
9840 import_name);
9841 return CMD_WARNING;
9842 }
9843 }
9844
9845 if (remove) {
9846 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9847 } else {
9848 /* Already importing from "import_vrf"? */
9849 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9850 vname)) {
9851 if (strcmp(vname, import_name) == 0)
9852 return CMD_WARNING;
9853 }
9854
9855 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9856 }
9857
9858 return CMD_SUCCESS;
12a844a5
DS
9859}
9860
b9c7bc5a 9861/* This command is valid only in a bgp vrf instance or the default instance */
585f1adc 9862DEFPY (bgp_imexport_vpn,
b9c7bc5a
PZ
9863 bgp_imexport_vpn_cmd,
9864 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9865 NO_STR
9866 "Import routes to this address-family\n"
9867 "Export routes from this address-family\n"
9868 "to/from default instance VPN RIB\n")
ddb5b488 9869{
585f1adc
IR
9870 VTY_DECLVAR_CONTEXT(bgp, bgp);
9871 int previous_state;
37a87b8f 9872 afi_t afi;
585f1adc
IR
9873 safi_t safi;
9874 int idx = 0;
9875 bool yes = true;
9876 int flag;
9c2fd3fe 9877 enum vpn_policy_direction dir;
585f1adc
IR
9878
9879 if (argv_find(argv, argc, "no", &idx))
9880 yes = false;
9881
9882 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9883 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9884
9885 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9886 return CMD_WARNING_CONFIG_FAILED;
9887 }
ddb5b488 9888
b9c7bc5a
PZ
9889 afi = bgp_node_afi(vty);
9890 safi = bgp_node_safi(vty);
585f1adc
IR
9891 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9892 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9893 return CMD_WARNING_CONFIG_FAILED;
9894 }
ddb5b488 9895
b9c7bc5a 9896 if (!strcmp(direction_str, "import")) {
585f1adc
IR
9897 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9898 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b9c7bc5a 9899 } else if (!strcmp(direction_str, "export")) {
585f1adc
IR
9900 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9901 dir = BGP_VPN_POLICY_DIR_TOVPN;
b9c7bc5a
PZ
9902 } else {
9903 vty_out(vty, "%% unknown direction %s\n", direction_str);
9904 return CMD_WARNING_CONFIG_FAILED;
9905 }
9906
585f1adc 9907 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 9908
585f1adc
IR
9909 if (yes) {
9910 SET_FLAG(bgp->af_flags[afi][safi], flag);
9911 if (!previous_state) {
9912 /* trigger export current vrf */
9913 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9914 }
9915 } else {
9916 if (previous_state) {
9917 /* trigger un-export current vrf */
9918 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9919 }
9920 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9921 }
37a87b8f 9922
1ca2fd11
IR
9923 hook_call(bgp_snmp_init_stats, bgp);
9924
585f1adc 9925 return CMD_SUCCESS;
ddb5b488
PZ
9926}
9927
301ad80a
PG
9928DEFPY (af_routetarget_import,
9929 af_routetarget_import_cmd,
9a659715 9930 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9931 NO_STR
9932 "Specify route target list\n"
9933 "Specify route target list\n"
9a659715
PG
9934 "Specify route target list\n"
9935 "Specify route target list\n"
301ad80a
PG
9936 "Flow-spec redirect type route target\n"
9937 "Import routes to this address-family\n"
9a659715 9938 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9939{
9940 VTY_DECLVAR_CONTEXT(bgp, bgp);
9941 int ret;
9942 struct ecommunity *ecom = NULL;
301ad80a 9943 afi_t afi;
9a659715 9944 int idx = 0, idx_unused = 0;
c6423c31
PG
9945 bool yes = true;
9946 bool rt6 = false;
301ad80a
PG
9947
9948 if (argv_find(argv, argc, "no", &idx))
c6423c31 9949 yes = false;
301ad80a 9950
9a659715
PG
9951 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9952 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9953 rt6 = true;
301ad80a 9954
0ca70ba5 9955 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9956 if (afi == AFI_MAX)
9957 return CMD_WARNING_CONFIG_FAILED;
9958
9a659715
PG
9959 if (rt6 && afi != AFI_IP6)
9960 return CMD_WARNING_CONFIG_FAILED;
9961
301ad80a
PG
9962 if (yes) {
9963 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9964 vty_out(vty, "%% Missing RTLIST\n");
9965 return CMD_WARNING_CONFIG_FAILED;
9966 }
9a659715 9967 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9968 if (ret != CMD_SUCCESS)
9969 return ret;
9970 }
69b07479
DS
9971
9972 if (yes) {
9973 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9974 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9975 .import_redirect_rtlist);
69b07479
DS
9976 bgp->vpn_policy[afi].import_redirect_rtlist =
9977 ecommunity_dup(ecom);
9978 } else {
9979 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9980 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9981 .import_redirect_rtlist);
69b07479 9982 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9983 }
69b07479 9984
301ad80a
PG
9985 if (ecom)
9986 ecommunity_free(&ecom);
9987
9988 return CMD_SUCCESS;
9989}
9990
505e5056 9991DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9992 address_family_ipv4_safi_cmd,
9993 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9994 "Enter Address Family command mode\n"
00e6edb9 9995 BGP_AF_STR
7c40bf39 9996 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9997{
f51bae9c 9998
d62a17ae 9999 if (argc == 3) {
585f1adc
IR
10000 VTY_DECLVAR_CONTEXT(bgp, bgp);
10001 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
10002 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 10003 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 10004 && safi != SAFI_EVPN) {
31947174
MK
10005 vty_out(vty,
10006 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
10007 return CMD_WARNING_CONFIG_FAILED;
10008 }
585f1adc
IR
10009 vty->node = bgp_node_type(AFI_IP, safi);
10010 } else
10011 vty->node = BGP_IPV4_NODE;
718e3744 10012
d62a17ae 10013 return CMD_SUCCESS;
718e3744 10014}
10015
505e5056 10016DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 10017 address_family_ipv6_safi_cmd,
10018 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
10019 "Enter Address Family command mode\n"
00e6edb9 10020 BGP_AF_STR
7c40bf39 10021 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 10022{
d62a17ae 10023 if (argc == 3) {
585f1adc
IR
10024 VTY_DECLVAR_CONTEXT(bgp, bgp);
10025 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
10026 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 10027 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 10028 && safi != SAFI_EVPN) {
31947174
MK
10029 vty_out(vty,
10030 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
10031 return CMD_WARNING_CONFIG_FAILED;
10032 }
585f1adc
IR
10033 vty->node = bgp_node_type(AFI_IP6, safi);
10034 } else
10035 vty->node = BGP_IPV6_NODE;
25ffbdc1 10036
d62a17ae 10037 return CMD_SUCCESS;
25ffbdc1 10038}
718e3744 10039
d6902373 10040#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 10041DEFUN_NOSH (address_family_vpnv4,
718e3744 10042 address_family_vpnv4_cmd,
8334fd5a 10043 "address-family vpnv4 [unicast]",
718e3744 10044 "Enter Address Family command mode\n"
00e6edb9
DA
10045 BGP_AF_STR
10046 BGP_AF_MODIFIER_STR)
718e3744 10047{
d62a17ae 10048 vty->node = BGP_VPNV4_NODE;
10049 return CMD_SUCCESS;
718e3744 10050}
10051
505e5056 10052DEFUN_NOSH (address_family_vpnv6,
8ecd3266 10053 address_family_vpnv6_cmd,
8334fd5a 10054 "address-family vpnv6 [unicast]",
8ecd3266 10055 "Enter Address Family command mode\n"
00e6edb9
DA
10056 BGP_AF_STR
10057 BGP_AF_MODIFIER_STR)
8ecd3266 10058{
d62a17ae 10059 vty->node = BGP_VPNV6_NODE;
10060 return CMD_SUCCESS;
8ecd3266 10061}
64e4a6c5 10062#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 10063
505e5056 10064DEFUN_NOSH (address_family_evpn,
4e0b7b6d 10065 address_family_evpn_cmd,
7111c1a0 10066 "address-family l2vpn evpn",
4e0b7b6d 10067 "Enter Address Family command mode\n"
00e6edb9
DA
10068 BGP_AF_STR
10069 BGP_AF_MODIFIER_STR)
4e0b7b6d 10070{
2131d5cf 10071 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 10072 vty->node = BGP_EVPN_NODE;
10073 return CMD_SUCCESS;
4e0b7b6d
PG
10074}
10075
bfaab44d
HS
10076DEFUN_NOSH (bgp_segment_routing_srv6,
10077 bgp_segment_routing_srv6_cmd,
10078 "segment-routing srv6",
10079 "Segment-Routing configuration\n"
10080 "Segment-Routing SRv6 configuration\n")
10081{
10082 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 10083 bgp->srv6_enabled = true;
bfaab44d
HS
10084 vty->node = BGP_SRV6_NODE;
10085 return CMD_SUCCESS;
10086}
10087
0249b8b6
HS
10088DEFUN (no_bgp_segment_routing_srv6,
10089 no_bgp_segment_routing_srv6_cmd,
10090 "no segment-routing srv6",
10091 NO_STR
10092 "Segment-Routing configuration\n"
10093 "Segment-Routing SRv6 configuration\n")
10094{
10095 VTY_DECLVAR_CONTEXT(bgp, bgp);
10096
10097 if (strlen(bgp->srv6_locator_name) > 0)
10098 if (bgp_srv6_locator_unset(bgp) < 0)
10099 return CMD_WARNING_CONFIG_FAILED;
10100
10101 bgp->srv6_enabled = false;
10102 return CMD_SUCCESS;
10103}
10104
a0281b2e
HS
10105DEFPY (bgp_srv6_locator,
10106 bgp_srv6_locator_cmd,
10107 "locator NAME$name",
10108 "Specify SRv6 locator\n"
10109 "Specify SRv6 locator\n")
10110{
10111 VTY_DECLVAR_CONTEXT(bgp, bgp);
7de4c885 10112 int ret;
a0281b2e
HS
10113
10114 if (strlen(bgp->srv6_locator_name) > 0
10115 && strcmp(name, bgp->srv6_locator_name) != 0) {
10116 vty_out(vty, "srv6 locator is already configured\n");
10117 return CMD_WARNING_CONFIG_FAILED;
7de4c885
HS
10118 }
10119
10120 snprintf(bgp->srv6_locator_name,
10121 sizeof(bgp->srv6_locator_name), "%s", name);
a0281b2e 10122
7de4c885 10123 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
a0281b2e
HS
10124 if (ret < 0)
10125 return CMD_WARNING_CONFIG_FAILED;
10126
10127 return CMD_SUCCESS;
10128}
10129
0249b8b6
HS
10130DEFPY (no_bgp_srv6_locator,
10131 no_bgp_srv6_locator_cmd,
10132 "no locator NAME$name",
10133 NO_STR
10134 "Specify SRv6 locator\n"
10135 "Specify SRv6 locator\n")
10136{
10137 VTY_DECLVAR_CONTEXT(bgp, bgp);
10138
10139 /* when locator isn't configured, do nothing */
10140 if (strlen(bgp->srv6_locator_name) < 1)
10141 return CMD_SUCCESS;
10142
10143 /* name validation */
10144 if (strcmp(name, bgp->srv6_locator_name) != 0) {
10145 vty_out(vty, "%% No srv6 locator is configured\n");
10146 return CMD_WARNING_CONFIG_FAILED;
10147 }
10148
10149 /* unset locator */
10150 if (bgp_srv6_locator_unset(bgp) < 0)
10151 return CMD_WARNING_CONFIG_FAILED;
10152
10153 return CMD_SUCCESS;
10154}
10155
ea372e81
HS
10156DEFPY (show_bgp_srv6,
10157 show_bgp_srv6_cmd,
10158 "show bgp segment-routing srv6",
10159 SHOW_STR
10160 BGP_STR
10161 "BGP Segment Routing\n"
10162 "BGP Segment Routing SRv6\n")
10163{
10164 struct bgp *bgp;
10165 struct listnode *node;
1c21a234 10166 struct srv6_locator_chunk *chunk;
ea372e81 10167 struct bgp_srv6_function *func;
ea372e81
HS
10168
10169 bgp = bgp_get_default();
96db4340 10170 if (!bgp)
ea372e81
HS
10171 return CMD_SUCCESS;
10172
10173 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
10174 vty_out(vty, "locator_chunks:\n");
dccef127 10175 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
511211bf 10176 vty_out(vty, "- %pFX\n", &chunk->prefix);
dccef127
CS
10177 vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
10178 vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
10179 vty_out(vty, " func-length: %d\n",
10180 chunk->function_bits_length);
10181 vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
10182 }
ea372e81
HS
10183
10184 vty_out(vty, "functions:\n");
10185 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
07380148 10186 vty_out(vty, "- sid: %pI6\n", &func->sid);
ea372e81
HS
10187 vty_out(vty, " locator: %s\n", func->locator_name);
10188 }
10189
10190 vty_out(vty, "bgps:\n");
10191 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
10192 vty_out(vty, "- name: %s\n",
10193 bgp->name ? bgp->name : "default");
10194
1830895a
CS
10195 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
10196 bgp->vpn_policy[AFI_IP].tovpn_sid);
10197 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
10198 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9f5d4430 10199 vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
ea372e81
HS
10200 }
10201
10202 return CMD_SUCCESS;
10203}
10204
505e5056 10205DEFUN_NOSH (exit_address_family,
718e3744 10206 exit_address_family_cmd,
10207 "exit-address-family",
10208 "Exit from Address Family configuration mode\n")
10209{
d62a17ae 10210 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
10211 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
10212 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
10213 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
10214 || vty->node == BGP_EVPN_NODE
10215 || vty->node == BGP_FLOWSPECV4_NODE
10216 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 10217 vty->node = BGP_NODE;
10218 return CMD_SUCCESS;
718e3744 10219}
6b0655a2 10220
8ad7271d 10221/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 10222static int bgp_clear_prefix(struct vty *vty, const char *view_name,
10223 const char *ip_str, afi_t afi, safi_t safi,
10224 struct prefix_rd *prd)
10225{
10226 int ret;
10227 struct prefix match;
9bcb3eef
DS
10228 struct bgp_dest *dest;
10229 struct bgp_dest *rm;
d62a17ae 10230 struct bgp *bgp;
10231 struct bgp_table *table;
10232 struct bgp_table *rib;
10233
10234 /* BGP structure lookup. */
10235 if (view_name) {
10236 bgp = bgp_lookup_by_name(view_name);
10237 if (bgp == NULL) {
10238 vty_out(vty, "%% Can't find BGP instance %s\n",
10239 view_name);
10240 return CMD_WARNING;
10241 }
10242 } else {
10243 bgp = bgp_get_default();
10244 if (bgp == NULL) {
10245 vty_out(vty, "%% No BGP process is configured\n");
10246 return CMD_WARNING;
10247 }
10248 }
10249
10250 /* Check IP address argument. */
10251 ret = str2prefix(ip_str, &match);
10252 if (!ret) {
10253 vty_out(vty, "%% address is malformed\n");
10254 return CMD_WARNING;
10255 }
10256
10257 match.family = afi2family(afi);
10258 rib = bgp->rib[afi][safi];
10259
10260 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
10261 for (dest = bgp_table_top(rib); dest;
10262 dest = bgp_route_next(dest)) {
10263 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 10264
9bcb3eef 10265 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 10266 continue;
10267
9bcb3eef 10268 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
10269 if (table == NULL)
10270 continue;
10271
4953391b
DA
10272 rm = bgp_node_match(table, &match);
10273 if (rm != NULL) {
b54892e0 10274 const struct prefix *rm_p =
9bcb3eef 10275 bgp_dest_get_prefix(rm);
b54892e0
DS
10276
10277 if (rm_p->prefixlen == match.prefixlen) {
10278 SET_FLAG(rm->flags,
10279 BGP_NODE_USER_CLEAR);
10280 bgp_process(bgp, rm, afi, safi);
d62a17ae 10281 }
9bcb3eef 10282 bgp_dest_unlock_node(rm);
d62a17ae 10283 }
10284 }
10285 } else {
4953391b
DA
10286 dest = bgp_node_match(rib, &match);
10287 if (dest != NULL) {
9bcb3eef 10288 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 10289
9bcb3eef
DS
10290 if (dest_p->prefixlen == match.prefixlen) {
10291 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10292 bgp_process(bgp, dest, afi, safi);
d62a17ae 10293 }
9bcb3eef 10294 bgp_dest_unlock_node(dest);
d62a17ae 10295 }
10296 }
10297
10298 return CMD_SUCCESS;
8ad7271d
DS
10299}
10300
b09b5ae0 10301/* one clear bgp command to rule them all */
718e3744 10302DEFUN (clear_ip_bgp_all,
10303 clear_ip_bgp_all_cmd,
8079a413 10304 "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|ASNUM|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out|message-stats>]",
718e3744 10305 CLEAR_STR
10306 IP_STR
10307 BGP_STR
838758ac 10308 BGP_INSTANCE_HELP_STR
510afcd6 10309 BGP_AFI_HELP_STR
00e6edb9 10310 BGP_AF_STR
510afcd6 10311 BGP_SAFI_WITH_LABEL_HELP_STR
00e6edb9 10312 BGP_AF_MODIFIER_STR
b09b5ae0 10313 "Clear all peers\n"
453c92f6 10314 "BGP IPv4 neighbor to clear\n"
a80beece 10315 "BGP IPv6 neighbor to clear\n"
838758ac 10316 "BGP neighbor on interface to clear\n"
8079a413 10317 "Clear peers with the AS number in plain or dotted format\n"
b09b5ae0 10318 "Clear all external peers\n"
718e3744 10319 "Clear all members of peer-group\n"
b09b5ae0 10320 "BGP peer-group name\n"
b09b5ae0
DW
10321 BGP_SOFT_STR
10322 BGP_SOFT_IN_STR
b09b5ae0
DW
10323 BGP_SOFT_OUT_STR
10324 BGP_SOFT_IN_STR
10325 "Push out prefix-list ORF and do inbound soft reconfig\n"
3cb14f26
DS
10326 BGP_SOFT_OUT_STR
10327 "Reset message statistics\n")
718e3744 10328{
d62a17ae 10329 char *vrf = NULL;
10330
dc912615
DS
10331 afi_t afi = AFI_UNSPEC;
10332 safi_t safi = SAFI_UNSPEC;
d62a17ae 10333 enum clear_sort clr_sort = clear_peer;
10334 enum bgp_clear_type clr_type;
10335 char *clr_arg = NULL;
10336
10337 int idx = 0;
10338
10339 /* clear [ip] bgp */
10340 if (argv_find(argv, argc, "ip", &idx))
10341 afi = AFI_IP;
10342
9a8bdf1c
PG
10343 /* [<vrf> VIEWVRFNAME] */
10344 if (argv_find(argv, argc, "vrf", &idx)) {
10345 vrf = argv[idx + 1]->arg;
10346 idx += 2;
10347 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10348 vrf = NULL;
10349 } else if (argv_find(argv, argc, "view", &idx)) {
10350 /* [<view> VIEWVRFNAME] */
d62a17ae 10351 vrf = argv[idx + 1]->arg;
10352 idx += 2;
10353 }
d62a17ae 10354 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10355 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10356 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10357
8079a413 10358 /* <*|A.B.C.D|X:X::X:X|WORD|ASNUM|external|peer-group PGNAME> */
d62a17ae 10359 if (argv_find(argv, argc, "*", &idx)) {
10360 clr_sort = clear_all;
10361 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10362 clr_sort = clear_peer;
10363 clr_arg = argv[idx]->arg;
10364 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10365 clr_sort = clear_peer;
10366 clr_arg = argv[idx]->arg;
10367 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10368 clr_sort = clear_group;
10369 idx++;
10370 clr_arg = argv[idx]->arg;
d7b9898c 10371 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 10372 clr_sort = clear_peer;
10373 clr_arg = argv[idx]->arg;
8fa7d444
DS
10374 } else if (argv_find(argv, argc, "WORD", &idx)) {
10375 clr_sort = clear_peer;
10376 clr_arg = argv[idx]->arg;
8079a413 10377 } else if (argv_find(argv, argc, "ASNUM", &idx)) {
d62a17ae 10378 clr_sort = clear_as;
10379 clr_arg = argv[idx]->arg;
10380 } else if (argv_find(argv, argc, "external", &idx)) {
10381 clr_sort = clear_external;
10382 }
10383
3cb14f26 10384 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
d62a17ae 10385 if (argv_find(argv, argc, "soft", &idx)) {
10386 if (argv_find(argv, argc, "in", &idx)
10387 || argv_find(argv, argc, "out", &idx))
10388 clr_type = strmatch(argv[idx]->text, "in")
10389 ? BGP_CLEAR_SOFT_IN
10390 : BGP_CLEAR_SOFT_OUT;
10391 else
10392 clr_type = BGP_CLEAR_SOFT_BOTH;
10393 } else if (argv_find(argv, argc, "in", &idx)) {
10394 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10395 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10396 : BGP_CLEAR_SOFT_IN;
10397 } else if (argv_find(argv, argc, "out", &idx)) {
10398 clr_type = BGP_CLEAR_SOFT_OUT;
3cb14f26
DS
10399 } else if (argv_find(argv, argc, "message-stats", &idx)) {
10400 clr_type = BGP_CLEAR_MESSAGE_STATS;
d62a17ae 10401 } else
10402 clr_type = BGP_CLEAR_SOFT_NONE;
10403
1ca2fd11 10404 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 10405}
01080f7c 10406
8ad7271d
DS
10407DEFUN (clear_ip_bgp_prefix,
10408 clear_ip_bgp_prefix_cmd,
18c57037 10409 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
10410 CLEAR_STR
10411 IP_STR
10412 BGP_STR
838758ac 10413 BGP_INSTANCE_HELP_STR
8ad7271d 10414 "Clear bestpath and re-advertise\n"
0c7b1b01 10415 "IPv4 prefix\n")
8ad7271d 10416{
d62a17ae 10417 char *vrf = NULL;
10418 char *prefix = NULL;
8ad7271d 10419
d62a17ae 10420 int idx = 0;
01080f7c 10421
d62a17ae 10422 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
10423 if (argv_find(argv, argc, "vrf", &idx)) {
10424 vrf = argv[idx + 1]->arg;
10425 idx += 2;
10426 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10427 vrf = NULL;
10428 } else if (argv_find(argv, argc, "view", &idx)) {
10429 /* [<view> VIEWVRFNAME] */
10430 vrf = argv[idx + 1]->arg;
10431 idx += 2;
10432 }
0c7b1b01 10433
d62a17ae 10434 prefix = argv[argc - 1]->arg;
8ad7271d 10435
d62a17ae 10436 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 10437}
8ad7271d 10438
b09b5ae0
DW
10439DEFUN (clear_bgp_ipv6_safi_prefix,
10440 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 10441 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10442 CLEAR_STR
3a2d747c 10443 IP_STR
718e3744 10444 BGP_STR
00e6edb9 10445 BGP_AF_STR
46f296b4 10446 BGP_SAFI_HELP_STR
b09b5ae0 10447 "Clear bestpath and re-advertise\n"
0c7b1b01 10448 "IPv6 prefix\n")
718e3744 10449{
9b475e76
PG
10450 int idx_safi = 0;
10451 int idx_ipv6_prefix = 0;
10452 safi_t safi = SAFI_UNICAST;
10453 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10454 argv[idx_ipv6_prefix]->arg : NULL;
10455
10456 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 10457 return bgp_clear_prefix(
9b475e76
PG
10458 vty, NULL, prefix, AFI_IP6,
10459 safi, NULL);
838758ac 10460}
01080f7c 10461
b09b5ae0
DW
10462DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10463 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 10464 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10465 CLEAR_STR
3a2d747c 10466 IP_STR
718e3744 10467 BGP_STR
838758ac 10468 BGP_INSTANCE_HELP_STR
00e6edb9 10469 BGP_AF_STR
46f296b4 10470 BGP_SAFI_HELP_STR
b09b5ae0 10471 "Clear bestpath and re-advertise\n"
0c7b1b01 10472 "IPv6 prefix\n")
718e3744 10473{
9b475e76 10474 int idx_safi = 0;
9a8bdf1c 10475 int idx_vrfview = 0;
9b475e76
PG
10476 int idx_ipv6_prefix = 0;
10477 safi_t safi = SAFI_UNICAST;
10478 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10479 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 10480 char *vrfview = NULL;
9b475e76 10481
9a8bdf1c
PG
10482 /* [<view|vrf> VIEWVRFNAME] */
10483 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10484 vrfview = argv[idx_vrfview + 1]->arg;
10485 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10486 vrfview = NULL;
10487 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10488 /* [<view> VIEWVRFNAME] */
10489 vrfview = argv[idx_vrfview + 1]->arg;
10490 }
9b475e76
PG
10491 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10492
d62a17ae 10493 return bgp_clear_prefix(
9b475e76
PG
10494 vty, vrfview, prefix,
10495 AFI_IP6, safi, NULL);
718e3744 10496}
10497
b09b5ae0
DW
10498DEFUN (show_bgp_views,
10499 show_bgp_views_cmd,
d6e3c605 10500 "show [ip] bgp views",
b09b5ae0 10501 SHOW_STR
d6e3c605 10502 IP_STR
01080f7c 10503 BGP_STR
b09b5ae0 10504 "Show the defined BGP views\n")
01080f7c 10505{
d62a17ae 10506 struct list *inst = bm->bgp;
10507 struct listnode *node;
10508 struct bgp *bgp;
01080f7c 10509
d62a17ae 10510 vty_out(vty, "Defined BGP views:\n");
10511 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10512 /* Skip VRFs. */
10513 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10514 continue;
9eb11997
PG
10515 vty_out(vty, "\t%s (AS%s)\n", bgp->name ? bgp->name : "(null)",
10516 bgp->as_pretty);
d62a17ae 10517 }
e52702f2 10518
d62a17ae 10519 return CMD_SUCCESS;
e0081f70
ML
10520}
10521
4acd6bc9
SPG
10522static inline void calc_peers_cfgd_estbd(struct bgp *bgp, int *peers_cfgd,
10523 int *peers_estbd)
10524{
10525 struct peer *peer;
10526 struct listnode *node;
10527
10528 *peers_cfgd = *peers_estbd = 0;
10529 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
10530 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10531 continue;
10532 (*peers_cfgd)++;
10533 if (peer_established(peer))
10534 (*peers_estbd)++;
10535 }
10536}
10537
10538static void print_bgp_vrfs(struct bgp *bgp, struct vty *vty, json_object *json,
10539 const char *type)
10540{
10541 int peers_cfg, peers_estb;
10542
10543 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10544
10545 if (json) {
10546 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10547 ? -1
10548 : (int64_t)bgp->vrf_id;
10549 json_object_string_add(json, "type", type);
10550 json_object_int_add(json, "vrfId", vrf_id_ui);
10551 json_object_string_addf(json, "routerId", "%pI4",
10552 &bgp->router_id);
10553 json_object_int_add(json, "numConfiguredPeers", peers_cfg);
10554 json_object_int_add(json, "numEstablishedPeers", peers_estb);
10555 json_object_int_add(json, "l3vni", bgp->l3vni);
10556 json_object_string_addf(json, "rmac", "%pEA", &bgp->rmac);
10557 json_object_string_add(
10558 json, "interface",
10559 ifindex2ifname(bgp->l3vni_svi_ifindex, bgp->vrf_id));
10560 }
10561}
10562
10563static int show_bgp_vrfs_detail_common(struct vty *vty, struct bgp *bgp,
10564 json_object *json, const char *name,
10565 const char *type, bool use_vrf)
10566{
10567 int peers_cfg, peers_estb;
10568
10569 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10570
10571 if (use_vrf) {
10572 if (json) {
10573 print_bgp_vrfs(bgp, vty, json, type);
10574 } else {
10575 vty_out(vty, "BGP instance %s VRF id %d\n",
10576 bgp->name_pretty,
10577 bgp->vrf_id == VRF_UNKNOWN ? -1
10578 : (int)bgp->vrf_id);
10579 vty_out(vty, "Router Id %pI4\n", &bgp->router_id);
10580 vty_out(vty,
10581 "Num Configured Peers %d, Established %d\n",
10582 peers_cfg, peers_estb);
10583 if (bgp->l3vni) {
10584 vty_out(vty,
10585 "L3VNI %u, L3VNI-SVI %s, Router MAC %pEA\n",
10586 bgp->l3vni,
10587 ifindex2ifname(bgp->l3vni_svi_ifindex,
10588 bgp->vrf_id),
10589 &bgp->rmac);
10590 }
10591 }
10592 } else {
10593 if (json) {
10594 print_bgp_vrfs(bgp, vty, json, type);
10595 } else {
10596 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10597 type,
10598 bgp->vrf_id == VRF_UNKNOWN ? -1
10599 : (int)bgp->vrf_id,
10600 &bgp->router_id, peers_cfg, peers_estb, name);
10601 vty_out(vty, "%11s %-16u %-21pEA %-20s\n", " ",
10602 bgp->l3vni, &bgp->rmac,
10603 ifindex2ifname(bgp->l3vni_svi_ifindex,
10604 bgp->vrf_id));
10605 }
10606 }
10607
10608 return CMD_SUCCESS;
10609}
10610
10611DEFPY (show_bgp_vrfs,
8386ac43 10612 show_bgp_vrfs_cmd,
4acd6bc9 10613 "show [ip] bgp vrfs [<VRFNAME$vrf_name>] [json]",
8386ac43 10614 SHOW_STR
d6e3c605 10615 IP_STR
8386ac43 10616 BGP_STR
10617 "Show BGP VRFs\n"
4acd6bc9 10618 "Specific VRF name\n"
9973d184 10619 JSON_STR)
8386ac43 10620{
d62a17ae 10621 struct list *inst = bm->bgp;
10622 struct listnode *node;
10623 struct bgp *bgp;
9f049418 10624 bool uj = use_json(argc, argv);
d62a17ae 10625 json_object *json = NULL;
10626 json_object *json_vrfs = NULL;
4acd6bc9 10627 json_object *json_vrf = NULL;
d62a17ae 10628 int count = 0;
4acd6bc9
SPG
10629 const char *name = vrf_name;
10630 const char *type;
d62a17ae 10631
4acd6bc9 10632 if (uj)
d62a17ae 10633 json = json_object_new_object();
4acd6bc9
SPG
10634
10635 if (name) {
10636 if (strmatch(name, VRF_DEFAULT_NAME)) {
10637 bgp = bgp_get_default();
10638 type = "DFLT";
10639 } else {
10640 bgp = bgp_lookup_by_name(name);
10641 type = "VRF";
10642 }
10643 if (!bgp) {
10644 if (uj)
10645 vty_json(vty, json);
10646 else
10647 vty_out(vty,
10648 "%% Specified BGP instance not found\n");
10649
10650 return CMD_WARNING;
10651 }
10652 }
10653
10654 if (vrf_name) {
10655 if (uj)
10656 json_vrf = json_object_new_object();
10657
10658 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10659 true);
10660
10661 if (uj) {
10662 json_object_object_add(json, name, json_vrf);
10663 vty_json(vty, json);
10664 }
10665
10666 return CMD_SUCCESS;
d62a17ae 10667 }
10668
4acd6bc9
SPG
10669 if (uj)
10670 json_vrfs = json_object_new_object();
10671
d62a17ae 10672 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
4acd6bc9 10673 const char *name;
d62a17ae 10674
10675 /* Skip Views. */
10676 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10677 continue;
10678
10679 count++;
efb4077a 10680 if (!uj && count == 1) {
fe1dc5a3 10681 vty_out(vty,
efb4077a 10682 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 10683 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
10684 "#PeersEstb", "Name");
10685 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10686 "L3-VNI", "RouterMAC", "Interface");
10687 }
d62a17ae 10688 if (uj)
10689 json_vrf = json_object_new_object();
10690
d62a17ae 10691 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 10692 name = VRF_DEFAULT_NAME;
d62a17ae 10693 type = "DFLT";
10694 } else {
10695 name = bgp->name;
10696 type = "VRF";
10697 }
10698
4acd6bc9
SPG
10699 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10700 false);
a8bf7d9c 10701
4acd6bc9 10702 if (uj)
d62a17ae 10703 json_object_object_add(json_vrfs, name, json_vrf);
d62a17ae 10704 }
10705
10706 if (uj) {
10707 json_object_object_add(json, "vrfs", json_vrfs);
d62a17ae 10708 json_object_int_add(json, "totalVrfs", count);
75eeda93 10709 vty_json(vty, json);
d62a17ae 10710 } else {
10711 if (count)
10712 vty_out(vty,
10713 "\nTotal number of VRFs (including default): %d\n",
10714 count);
10715 }
10716
10717 return CMD_SUCCESS;
8386ac43 10718}
10719
48ecf8f5
DS
10720DEFUN (show_bgp_mac_hash,
10721 show_bgp_mac_hash_cmd,
10722 "show bgp mac hash",
10723 SHOW_STR
10724 BGP_STR
10725 "Mac Address\n"
10726 "Mac Address database\n")
10727{
10728 bgp_mac_dump_table(vty);
10729
10730 return CMD_SUCCESS;
10731}
acf71666 10732
e3b78da8 10733static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 10734{
0291c246 10735 struct vty *vty = (struct vty *)args;
e3b78da8 10736 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 10737
23d0a753 10738 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
10739}
10740
10741static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10742{
10743 vty_out(vty, "self nexthop database:\n");
af97a18b 10744 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
10745
10746 vty_out(vty, "Tunnel-ip database:\n");
10747 hash_iterate(bgp->tip_hash,
e3b78da8 10748 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
10749 vty);
10750}
10751
15c81ca4
DS
10752DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10753 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10754 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
10755 "martian next-hops\n"
10756 "martian next-hop database\n")
acf71666 10757{
0291c246 10758 struct bgp *bgp = NULL;
15c81ca4 10759 int idx = 0;
9a8bdf1c
PG
10760 char *name = NULL;
10761
10762 /* [<vrf> VIEWVRFNAME] */
10763 if (argv_find(argv, argc, "vrf", &idx)) {
10764 name = argv[idx + 1]->arg;
10765 if (name && strmatch(name, VRF_DEFAULT_NAME))
10766 name = NULL;
10767 } else if (argv_find(argv, argc, "view", &idx))
10768 /* [<view> VIEWVRFNAME] */
10769 name = argv[idx + 1]->arg;
10770 if (name)
10771 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
10772 else
10773 bgp = bgp_get_default();
acf71666 10774
acf71666
MK
10775 if (!bgp) {
10776 vty_out(vty, "%% No BGP process is configured\n");
10777 return CMD_WARNING;
10778 }
10779 bgp_show_martian_nexthops(vty, bgp);
10780
10781 return CMD_SUCCESS;
10782}
10783
f412b39a 10784DEFUN (show_bgp_memory,
4bf6a362 10785 show_bgp_memory_cmd,
7fa12b13 10786 "show [ip] bgp memory",
4bf6a362 10787 SHOW_STR
3a2d747c 10788 IP_STR
4bf6a362
PJ
10789 BGP_STR
10790 "Global BGP memory statistics\n")
10791{
d62a17ae 10792 char memstrbuf[MTYPE_MEMSTR_LEN];
10793 unsigned long count;
10794
10795 /* RIB related usage stats */
10796 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10797 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10798 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 10799 count * sizeof(struct bgp_dest)));
d62a17ae 10800
10801 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10802 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10803 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 10804 count * sizeof(struct bgp_path_info)));
d62a17ae 10805 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10806 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10807 count,
4b7e6066
DS
10808 mtype_memstr(
10809 memstrbuf, sizeof(memstrbuf),
10810 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 10811
10812 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10813 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10814 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10815 count * sizeof(struct bgp_static)));
10816
10817 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10818 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10819 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10820 count * sizeof(struct bpacket)));
10821
10822 /* Adj-In/Out */
10823 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10824 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10825 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10826 count * sizeof(struct bgp_adj_in)));
10827 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10828 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10829 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10830 count * sizeof(struct bgp_adj_out)));
10831
10832 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10833 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10834 count,
10835 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10836 count * sizeof(struct bgp_nexthop_cache)));
10837
10838 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10839 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10840 count,
10841 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10842 count * sizeof(struct bgp_damp_info)));
10843
10844 /* Attributes */
10845 count = attr_count();
10846 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10847 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10848 count * sizeof(struct attr)));
10849
10850 if ((count = attr_unknown_count()))
10851 vty_out(vty, "%ld unknown attributes\n", count);
10852
10853 /* AS_PATH attributes */
10854 count = aspath_count();
10855 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10856 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10857 count * sizeof(struct aspath)));
10858
10859 count = mtype_stats_alloc(MTYPE_AS_SEG);
10860 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10861 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10862 count * sizeof(struct assegment)));
10863
10864 /* Other attributes */
10865 if ((count = community_count()))
10866 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10867 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10868 count * sizeof(struct community)));
d62a17ae 10869 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
145f7619
DA
10870 vty_out(vty,
10871 "%ld BGP ext-community entries, using %s of memory\n",
10872 count,
10873 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10874 count * sizeof(struct ecommunity)));
d62a17ae 10875 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10876 vty_out(vty,
10877 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10878 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10879 count * sizeof(struct lcommunity)));
d62a17ae 10880
10881 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10882 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10883 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10884 count * sizeof(struct cluster_list)));
10885
10886 /* Peer related usage */
10887 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10888 vty_out(vty, "%ld peers, using %s of memory\n", count,
10889 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10890 count * sizeof(struct peer)));
10891
10892 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10893 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10894 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10895 count * sizeof(struct peer_group)));
10896
10897 /* Other */
d62a17ae 10898 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10899 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10900 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10901 count * sizeof(regex_t)));
d62a17ae 10902 return CMD_SUCCESS;
4bf6a362 10903}
fee0f4c6 10904
57a9c8a8
DS
10905static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10906{
10907 json_object *bestpath = json_object_new_object();
10908
892fedb6 10909 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10910 json_object_string_add(bestpath, "asPath", "ignore");
10911
892fedb6 10912 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10913 json_object_string_add(bestpath, "asPath", "confed");
10914
892fedb6
DA
10915 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10916 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10917 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10918 "as-set");
10919 else
a4d82a8a 10920 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10921 "true");
10922 } else
a4d82a8a 10923 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10924
ee88563a
JM
10925 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10926 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10927
892fedb6 10928 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10929 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10930 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10931 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10932 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10933 json_object_string_add(bestpath, "med", "confed");
892fedb6 10934 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10935 json_object_string_add(bestpath, "med",
10936 "missing-as-worst");
10937 else
10938 json_object_string_add(bestpath, "med", "true");
10939 }
10940
10941 json_object_object_add(json, "bestPath", bestpath);
10942}
10943
3577f1c5
DD
10944/* Print the error code/subcode for why the peer is down */
10945static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10946 json_object *json_peer, bool use_json)
10947{
10948 const char *code_str;
10949 const char *subcode_str;
10950
10951 if (use_json) {
10952 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10953 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10954 char errorcodesubcode_hexstr[5];
10955 char errorcodesubcode_str[256];
10956
10957 code_str = bgp_notify_code_str(peer->notify.code);
10958 subcode_str = bgp_notify_subcode_str(
10959 peer->notify.code,
10960 peer->notify.subcode);
10961
772270f3
QY
10962 snprintf(errorcodesubcode_hexstr,
10963 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10964 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10965 json_object_string_add(json_peer,
10966 "lastErrorCodeSubcode",
10967 errorcodesubcode_hexstr);
10968 snprintf(errorcodesubcode_str, 255, "%s%s",
10969 code_str, subcode_str);
10970 json_object_string_add(json_peer,
10971 "lastNotificationReason",
10972 errorcodesubcode_str);
eea685b6
DA
10973 json_object_boolean_add(json_peer,
10974 "lastNotificationHardReset",
10975 peer->notify.hard_reset);
3577f1c5
DD
10976 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10977 && peer->notify.code == BGP_NOTIFY_CEASE
10978 && (peer->notify.subcode
10979 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10980 || peer->notify.subcode
10981 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10982 && peer->notify.length) {
10983 char msgbuf[1024];
10984 const char *msg_str;
10985
10986 msg_str = bgp_notify_admin_message(
10987 msgbuf, sizeof(msgbuf),
10988 (uint8_t *)peer->notify.data,
10989 peer->notify.length);
10990 if (msg_str)
10991 json_object_string_add(
10992 json_peer,
10993 "lastShutdownDescription",
10994 msg_str);
10995 }
10996
c258527b 10997 }
3577f1c5
DD
10998 json_object_string_add(json_peer, "lastResetDueTo",
10999 peer_down_str[(int)peer->last_reset]);
05912a17
DD
11000 json_object_int_add(json_peer, "lastResetCode",
11001 peer->last_reset);
234f6fd4
DA
11002 json_object_string_add(json_peer, "softwareVersion",
11003 peer->soft_version ? peer->soft_version
11004 : "n/a");
3577f1c5
DD
11005 } else {
11006 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
11007 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
11008 code_str = bgp_notify_code_str(peer->notify.code);
11009 subcode_str =
11010 bgp_notify_subcode_str(peer->notify.code,
11011 peer->notify.subcode);
eea685b6 11012 vty_out(vty, " Notification %s (%s%s%s)\n",
3577f1c5 11013 peer->last_reset == PEER_DOWN_NOTIFY_SEND
eea685b6
DA
11014 ? "sent"
11015 : "received",
11016 code_str, subcode_str,
11017 peer->notify.hard_reset
11018 ? bgp_notify_subcode_str(
11019 BGP_NOTIFY_CEASE,
11020 BGP_NOTIFY_CEASE_HARD_RESET)
11021 : "");
3577f1c5 11022 } else {
234f6fd4
DA
11023 vty_out(vty, " %s (%s)\n",
11024 peer_down_str[(int)peer->last_reset],
11025 peer->soft_version ? peer->soft_version
11026 : "n/a");
3577f1c5
DD
11027 }
11028 }
11029}
11030
11031static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
11032 safi_t safi)
11033{
feb17238 11034 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
3577f1c5
DD
11035}
11036
11037static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
11038 struct peer *peer, json_object *json_peer,
11039 int max_neighbor_width, bool use_json)
11040{
11041 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
11042 int len;
11043
11044 if (use_json) {
11045 if (peer_dynamic_neighbor(peer))
11046 json_object_boolean_true_add(json_peer,
11047 "dynamicPeer");
11048 if (peer->hostname)
11049 json_object_string_add(json_peer, "hostname",
11050 peer->hostname);
11051
11052 if (peer->domainname)
11053 json_object_string_add(json_peer, "domainname",
11054 peer->domainname);
11055 json_object_int_add(json_peer, "connectionsEstablished",
11056 peer->established);
11057 json_object_int_add(json_peer, "connectionsDropped",
11058 peer->dropped);
11059 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11060 use_json, json_peer);
feb17238 11061 if (peer_established(peer))
3577f1c5
DD
11062 json_object_string_add(json_peer, "lastResetDueTo",
11063 "AFI/SAFI Not Negotiated");
11064 else
11065 bgp_show_peer_reset(NULL, peer, json_peer, true);
11066 } else {
11067 dn_flag[1] = '\0';
11068 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
11069 if (peer->hostname
892fedb6 11070 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
11071 len = vty_out(vty, "%s%s(%s)", dn_flag,
11072 peer->hostname, peer->host);
11073 else
11074 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11075
11076 /* pad the neighbor column with spaces */
11077 if (len < max_neighbor_width)
11078 vty_out(vty, "%*s", max_neighbor_width - len,
11079 " ");
e91c24c8 11080 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
11081 peer->dropped,
11082 peer_uptime(peer->uptime, timebuf,
11083 BGP_UPTIME_LEN, 0, NULL));
feb17238 11084 if (peer_established(peer))
3577f1c5
DD
11085 vty_out(vty, " AFI/SAFI Not Negotiated\n");
11086 else
11087 bgp_show_peer_reset(vty, peer, NULL,
11088 false);
11089 }
11090}
c258527b 11091
565e9ddd 11092/* Strip peer's description to the given size. */
cb75bb31
DA
11093static char *bgp_peer_description_stripped(char *desc, uint32_t size)
11094{
11095 static char stripped[BUFSIZ];
64541ffa 11096 uint32_t i = 0;
420ac3d2 11097 uint32_t last_space = size;
cb75bb31 11098
64541ffa 11099 while (i < size) {
420ac3d2 11100 if (*(desc + i) == '\0') {
64541ffa
FD
11101 stripped[i] = '\0';
11102 return stripped;
11103 }
11104 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
11105 last_space = i;
11106 stripped[i] = *(desc + i);
11107 i++;
11108 }
11109
420ac3d2 11110 stripped[last_space] = '\0';
cb75bb31
DA
11111
11112 return stripped;
11113}
3577f1c5 11114
8c1d4cd5
LS
11115/* Determine whether var peer should be filtered out of the summary. */
11116static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
11117 struct peer *fpeer, int as_type,
11118 as_t as)
11119{
11120
11121 /* filter neighbor XXXX */
11122 if (fpeer && fpeer != peer)
11123 return true;
11124
11125 /* filter remote-as (internal|external) */
11126 if (as_type != AS_UNSPECIFIED) {
11127 if (peer->as_type == AS_SPECIFIED) {
11128 if (as_type == AS_INTERNAL) {
11129 if (peer->as != peer->local_as)
11130 return true;
11131 } else if (peer->as == peer->local_as)
11132 return true;
11133 } else if (as_type != peer->as_type)
11134 return true;
11135 } else if (as && as != peer->as) /* filter remote-as XXX */
11136 return true;
11137
11138 return false;
11139}
11140
565e9ddd
DA
11141/* Show BGP peer's summary information.
11142 *
11143 * Peer's description is stripped according to if `wide` option is given
11144 * or not.
11145 *
11146 * When adding new columns to `show bgp summary` output, please make
11147 * sure `Desc` is the lastest column to show because it can contain
11148 * whitespaces and the whole output will be tricky.
11149 */
d62a17ae 11150static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 11151 struct peer *fpeer, int as_type, as_t as,
96c81f66 11152 uint16_t show_flags)
d62a17ae 11153{
11154 struct peer *peer;
11155 struct listnode *node, *nnode;
11156 unsigned int count = 0, dn_count = 0;
11157 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
11158 char neighbor_buf[VTY_BUFSIZ];
11159 int neighbor_col_default_width = 16;
3577f1c5 11160 int len, failed_count = 0;
ce1944f0 11161 unsigned int filtered_count = 0;
d62a17ae 11162 int max_neighbor_width = 0;
11163 int pfx_rcd_safi;
3c13337d 11164 json_object *json = NULL;
d62a17ae 11165 json_object *json_peer = NULL;
11166 json_object *json_peers = NULL;
50e05855 11167 struct peer_af *paf;
d3ada366 11168 struct bgp_filter *filter;
85eeb029
DA
11169 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11170 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11171 bool show_established =
11172 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11173 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
96c81f66 11174 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
d62a17ae 11175
11176 /* labeled-unicast routes are installed in the unicast table so in order
11177 * to
11178 * display the correct PfxRcd value we must look at SAFI_UNICAST
11179 */
3577f1c5 11180
d62a17ae 11181 if (safi == SAFI_LABELED_UNICAST)
11182 pfx_rcd_safi = SAFI_UNICAST;
11183 else
11184 pfx_rcd_safi = safi;
11185
11186 if (use_json) {
3c13337d 11187 json = json_object_new_object();
d62a17ae 11188 json_peers = json_object_new_object();
3577f1c5 11189 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
11190 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11191 as_type, as)) {
ce1944f0 11192 filtered_count++;
8c1d4cd5
LS
11193 count++;
11194 continue;
11195 }
11196
3577f1c5
DD
11197 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11198 continue;
11199
11200 if (peer->afc[afi][safi]) {
11201 /* See if we have at least a single failed peer */
11202 if (bgp_has_peer_failed(peer, afi, safi))
11203 failed_count++;
11204 count++;
11205 }
11206 if (peer_dynamic_neighbor(peer))
11207 dn_count++;
11208 }
c258527b 11209
d62a17ae 11210 } else {
11211 /* Loop over all neighbors that will be displayed to determine
11212 * how many
11213 * characters are needed for the Neighbor column
11214 */
11215 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
11216 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11217 as_type, as)) {
ce1944f0 11218 filtered_count++;
8c1d4cd5
LS
11219 count++;
11220 continue;
11221 }
11222
d62a17ae 11223 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11224 continue;
11225
11226 if (peer->afc[afi][safi]) {
11227 memset(dn_flag, '\0', sizeof(dn_flag));
11228 if (peer_dynamic_neighbor(peer))
11229 dn_flag[0] = '*';
11230
11231 if (peer->hostname
892fedb6
DA
11232 && CHECK_FLAG(bgp->flags,
11233 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
11234 snprintf(neighbor_buf,
11235 sizeof(neighbor_buf),
11236 "%s%s(%s) ", dn_flag,
11237 peer->hostname, peer->host);
d62a17ae 11238 else
772270f3
QY
11239 snprintf(neighbor_buf,
11240 sizeof(neighbor_buf), "%s%s ",
11241 dn_flag, peer->host);
d62a17ae 11242
11243 len = strlen(neighbor_buf);
11244
11245 if (len > max_neighbor_width)
11246 max_neighbor_width = len;
c258527b 11247
3577f1c5
DD
11248 /* See if we have at least a single failed peer */
11249 if (bgp_has_peer_failed(peer, afi, safi))
11250 failed_count++;
11251 count++;
d62a17ae 11252 }
11253 }
f933309e 11254
d62a17ae 11255 /* Originally we displayed the Neighbor column as 16
11256 * characters wide so make that the default
11257 */
11258 if (max_neighbor_width < neighbor_col_default_width)
11259 max_neighbor_width = neighbor_col_default_width;
11260 }
f933309e 11261
3577f1c5
DD
11262 if (show_failed && !failed_count) {
11263 if (use_json) {
11264 json_object_int_add(json, "failedPeersCount", 0);
11265 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 11266 json_object_int_add(json, "totalPeers", count);
3577f1c5 11267
75eeda93 11268 vty_json(vty, json);
3577f1c5
DD
11269 } else {
11270 vty_out(vty, "%% No failed BGP neighbors found\n");
3577f1c5
DD
11271 }
11272 return CMD_SUCCESS;
11273 }
c258527b 11274
3577f1c5 11275 count = 0; /* Reset the value as its used again */
ce1944f0 11276 filtered_count = 0;
800867d8 11277 dn_count = 0;
d62a17ae 11278 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11279 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11280 continue;
11281
ea47320b
DL
11282 if (!peer->afc[afi][safi])
11283 continue;
d62a17ae 11284
ea47320b
DL
11285 if (!count) {
11286 unsigned long ents;
11287 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 11288 int64_t vrf_id_ui;
d62a17ae 11289
a4d82a8a
PZ
11290 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
11291 ? -1
11292 : (int64_t)bgp->vrf_id;
ea47320b
DL
11293
11294 /* Usage summary and header */
11295 if (use_json) {
c949c771
DA
11296 json_object_string_addf(json, "routerId",
11297 "%pI4",
11298 &bgp->router_id);
e84c7c12
PG
11299 asn_asn2json(json, "as", bgp->as,
11300 bgp->asnotation);
60466a63 11301 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
11302 json_object_string_add(
11303 json, "vrfName",
11304 (bgp->inst_type
11305 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11306 ? VRF_DEFAULT_NAME
ea47320b
DL
11307 : bgp->name);
11308 } else {
11309 vty_out(vty,
9eb11997
PG
11310 "BGP router identifier %pI4, local AS number %s vrf-id %d",
11311 &bgp->router_id, bgp->as_pretty,
a4d82a8a
PZ
11312 bgp->vrf_id == VRF_UNKNOWN
11313 ? -1
11314 : (int)bgp->vrf_id);
ea47320b
DL
11315 vty_out(vty, "\n");
11316 }
d62a17ae 11317
ea47320b 11318 if (bgp_update_delay_configured(bgp)) {
d62a17ae 11319 if (use_json) {
ea47320b 11320 json_object_int_add(
60466a63 11321 json, "updateDelayLimit",
ea47320b 11322 bgp->v_update_delay);
d62a17ae 11323
ea47320b
DL
11324 if (bgp->v_update_delay
11325 != bgp->v_establish_wait)
d62a17ae 11326 json_object_int_add(
11327 json,
ea47320b
DL
11328 "updateDelayEstablishWait",
11329 bgp->v_establish_wait);
d62a17ae 11330
60466a63 11331 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
11332 json_object_string_add(
11333 json,
11334 "updateDelayFirstNeighbor",
11335 bgp->update_delay_begin_time);
11336 json_object_boolean_true_add(
11337 json,
11338 "updateDelayInProgress");
11339 } else {
11340 if (bgp->update_delay_over) {
d62a17ae 11341 json_object_string_add(
11342 json,
11343 "updateDelayFirstNeighbor",
11344 bgp->update_delay_begin_time);
ea47320b 11345 json_object_string_add(
d62a17ae 11346 json,
ea47320b
DL
11347 "updateDelayBestpathResumed",
11348 bgp->update_delay_end_time);
11349 json_object_string_add(
d62a17ae 11350 json,
ea47320b
DL
11351 "updateDelayZebraUpdateResume",
11352 bgp->update_delay_zebra_resume_time);
11353 json_object_string_add(
11354 json,
11355 "updateDelayPeerUpdateResume",
11356 bgp->update_delay_peers_resume_time);
d62a17ae 11357 }
ea47320b
DL
11358 }
11359 } else {
11360 vty_out(vty,
11361 "Read-only mode update-delay limit: %d seconds\n",
11362 bgp->v_update_delay);
11363 if (bgp->v_update_delay
11364 != bgp->v_establish_wait)
d62a17ae 11365 vty_out(vty,
ea47320b
DL
11366 " Establish wait: %d seconds\n",
11367 bgp->v_establish_wait);
d62a17ae 11368
60466a63 11369 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
11370 vty_out(vty,
11371 " First neighbor established: %s\n",
11372 bgp->update_delay_begin_time);
11373 vty_out(vty,
11374 " Delay in progress\n");
11375 } else {
11376 if (bgp->update_delay_over) {
d62a17ae 11377 vty_out(vty,
11378 " First neighbor established: %s\n",
11379 bgp->update_delay_begin_time);
11380 vty_out(vty,
ea47320b
DL
11381 " Best-paths resumed: %s\n",
11382 bgp->update_delay_end_time);
11383 vty_out(vty,
11384 " zebra update resumed: %s\n",
11385 bgp->update_delay_zebra_resume_time);
11386 vty_out(vty,
11387 " peers update resumed: %s\n",
11388 bgp->update_delay_peers_resume_time);
d62a17ae 11389 }
11390 }
11391 }
ea47320b 11392 }
d62a17ae 11393
ea47320b
DL
11394 if (use_json) {
11395 if (bgp_maxmed_onstartup_configured(bgp)
11396 && bgp->maxmed_active)
11397 json_object_boolean_true_add(
60466a63 11398 json, "maxMedOnStartup");
ea47320b
DL
11399 if (bgp->v_maxmed_admin)
11400 json_object_boolean_true_add(
60466a63 11401 json, "maxMedAdministrative");
d62a17ae 11402
ea47320b
DL
11403 json_object_int_add(
11404 json, "tableVersion",
60466a63 11405 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 11406
60466a63
QY
11407 ents = bgp_table_count(bgp->rib[afi][safi]);
11408 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
11409 json_object_int_add(
11410 json, "ribMemory",
9bcb3eef 11411 ents * sizeof(struct bgp_dest));
d62a17ae 11412
210ec2a0 11413 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
11414 json_object_int_add(json, "peerCount", ents);
11415 json_object_int_add(json, "peerMemory",
11416 ents * sizeof(struct peer));
d62a17ae 11417
ea47320b
DL
11418 if ((ents = listcount(bgp->group))) {
11419 json_object_int_add(
60466a63 11420 json, "peerGroupCount", ents);
ea47320b
DL
11421 json_object_int_add(
11422 json, "peerGroupMemory",
996c9314
LB
11423 ents * sizeof(struct
11424 peer_group));
ea47320b 11425 }
d62a17ae 11426
ea47320b
DL
11427 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11428 BGP_CONFIG_DAMPENING))
11429 json_object_boolean_true_add(
60466a63 11430 json, "dampeningEnabled");
ea47320b 11431 } else {
96c81f66
LS
11432 if (!show_terse) {
11433 if (bgp_maxmed_onstartup_configured(bgp)
11434 && bgp->maxmed_active)
11435 vty_out(vty,
11436 "Max-med on-startup active\n");
11437 if (bgp->v_maxmed_admin)
11438 vty_out(vty,
11439 "Max-med administrative active\n");
d62a17ae 11440
96c81f66
LS
11441 vty_out(vty,
11442 "BGP table version %" PRIu64
11443 "\n",
11444 bgp_table_version(
11445 bgp->rib[afi][safi]));
ea47320b 11446
96c81f66
LS
11447 ents = bgp_table_count(
11448 bgp->rib[afi][safi]);
d62a17ae 11449 vty_out(vty,
96c81f66 11450 "RIB entries %ld, using %s of memory\n",
d62a17ae 11451 ents,
11452 mtype_memstr(
11453 memstrbuf,
11454 sizeof(memstrbuf),
96c81f66
LS
11455 ents
11456 * sizeof(
11457 struct
11458 bgp_dest)));
d62a17ae 11459
96c81f66
LS
11460 /* Peer related usage */
11461 ents = bgp->af_peer_count[afi][safi];
11462 vty_out(vty,
11463 "Peers %ld, using %s of memory\n",
11464 ents,
11465 mtype_memstr(
11466 memstrbuf,
11467 sizeof(memstrbuf),
11468 ents
11469 * sizeof(
11470 struct
11471 peer)));
d62a17ae 11472
96c81f66
LS
11473 if ((ents = listcount(bgp->group)))
11474 vty_out(vty,
11475 "Peer groups %ld, using %s of memory\n",
11476 ents,
11477 mtype_memstr(
11478 memstrbuf,
11479 sizeof(memstrbuf),
11480 ents
11481 * sizeof(
11482 struct
11483 peer_group)));
11484
11485 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11486 BGP_CONFIG_DAMPENING))
11487 vty_out(vty,
11488 "Dampening enabled.\n");
11489 }
11490 if (show_failed) {
11491 vty_out(vty, "\n");
11492
11493 /* Subtract 8 here because 'Neighbor' is
11494 * 8 characters */
11495 vty_out(vty, "Neighbor");
11496 vty_out(vty, "%*s",
11497 max_neighbor_width - 8, " ");
85eeb029
DA
11498 vty_out(vty,
11499 BGP_SHOW_SUMMARY_HEADER_FAILED);
96c81f66 11500 }
d62a17ae 11501 }
ea47320b 11502 }
d62a17ae 11503
d55811cc 11504 paf = peer_af_find(peer, afi, safi);
d3ada366 11505 filter = &peer->filter[afi][safi];
db92d226 11506
ea47320b 11507 count++;
3577f1c5
DD
11508 /* Works for both failed & successful cases */
11509 if (peer_dynamic_neighbor(peer))
11510 dn_count++;
d62a17ae 11511
ea47320b 11512 if (use_json) {
3577f1c5 11513 json_peer = NULL;
8c1d4cd5 11514 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
11515 as_type, as)) {
11516 filtered_count++;
8c1d4cd5 11517 continue;
ce1944f0 11518 }
3577f1c5
DD
11519 if (show_failed &&
11520 bgp_has_peer_failed(peer, afi, safi)) {
11521 json_peer = json_object_new_object();
11522 bgp_show_failed_summary(vty, bgp, peer,
11523 json_peer, 0, use_json);
11524 } else if (!show_failed) {
10b49f14 11525 if (show_established
ce1944f0
LS
11526 && bgp_has_peer_failed(peer, afi, safi)) {
11527 filtered_count++;
10b49f14 11528 continue;
ce1944f0 11529 }
10b49f14 11530
3577f1c5
DD
11531 json_peer = json_object_new_object();
11532 if (peer_dynamic_neighbor(peer)) {
11533 json_object_boolean_true_add(json_peer,
11534 "dynamicPeer");
11535 }
d62a17ae 11536
3577f1c5
DD
11537 if (peer->hostname)
11538 json_object_string_add(json_peer, "hostname",
11539 peer->hostname);
11540
11541 if (peer->domainname)
11542 json_object_string_add(json_peer, "domainname",
11543 peer->domainname);
11544
44a4d55e
PG
11545 asn_asn2json(json_peer, "remoteAs", peer->as,
11546 bgp->asnotation);
11547 asn_asn2json(json_peer, "localAs",
11548 peer->change_local_as
11549 ? peer->change_local_as
11550 : peer->local_as,
11551 bgp->asnotation);
3577f1c5
DD
11552 json_object_int_add(json_peer, "version", 4);
11553 json_object_int_add(json_peer, "msgRcvd",
11554 PEER_TOTAL_RX(peer));
11555 json_object_int_add(json_peer, "msgSent",
11556 PEER_TOTAL_TX(peer));
11557
43aa5965
QY
11558 atomic_size_t outq_count, inq_count;
11559 outq_count = atomic_load_explicit(
11560 &peer->obuf->count,
11561 memory_order_relaxed);
11562 inq_count = atomic_load_explicit(
11563 &peer->ibuf->count,
11564 memory_order_relaxed);
11565
3577f1c5
DD
11566 json_object_int_add(json_peer, "tableVersion",
11567 peer->version[afi][safi]);
11568 json_object_int_add(json_peer, "outq",
43aa5965
QY
11569 outq_count);
11570 json_object_int_add(json_peer, "inq",
11571 inq_count);
3577f1c5
DD
11572 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11573 use_json, json_peer);
11574
3577f1c5
DD
11575 json_object_int_add(json_peer, "pfxRcd",
11576 peer->pcount[afi][pfx_rcd_safi]);
11577
3577f1c5 11578 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
11579 json_object_int_add(
11580 json_peer, "pfxSnt",
11581 (PAF_SUBGRP(paf))->scount);
11582 else
11583 json_object_int_add(json_peer, "pfxSnt",
11584 0);
0e1f8ab5
DA
11585
11586 /* BGP FSM state */
cb9196e7 11587 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
11588 || CHECK_FLAG(peer->bgp->flags,
11589 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
11590 json_object_string_add(json_peer,
11591 "state",
3577f1c5
DD
11592 "Idle (Admin)");
11593 else if (peer->afc_recv[afi][safi])
11594 json_object_string_add(
0e1f8ab5
DA
11595 json_peer, "state",
11596 lookup_msg(bgp_status_msg,
11597 peer->status, NULL));
11598 else if (CHECK_FLAG(
11599 peer->sflags,
11600 PEER_STATUS_PREFIX_OVERFLOW))
11601 json_object_string_add(json_peer,
11602 "state",
3577f1c5
DD
11603 "Idle (PfxCt)");
11604 else
11605 json_object_string_add(
0e1f8ab5
DA
11606 json_peer, "state",
11607 lookup_msg(bgp_status_msg,
11608 peer->status, NULL));
11609
11610 /* BGP peer state */
11611 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11612 || CHECK_FLAG(peer->bgp->flags,
11613 BGP_FLAG_SHUTDOWN))
11614 json_object_string_add(json_peer,
11615 "peerState",
11616 "Admin");
11617 else if (CHECK_FLAG(
11618 peer->sflags,
11619 PEER_STATUS_PREFIX_OVERFLOW))
11620 json_object_string_add(json_peer,
11621 "peerState",
11622 "PfxCt");
11623 else if (CHECK_FLAG(peer->flags,
11624 PEER_FLAG_PASSIVE))
11625 json_object_string_add(json_peer,
11626 "peerState",
11627 "Passive");
11628 else if (CHECK_FLAG(peer->sflags,
11629 PEER_STATUS_NSF_WAIT))
11630 json_object_string_add(json_peer,
11631 "peerState",
11632 "NSF passive");
11633 else if (CHECK_FLAG(
11634 peer->bgp->flags,
11635 BGP_FLAG_EBGP_REQUIRES_POLICY)
11636 && (!bgp_inbound_policy_exists(peer,
11637 filter)
11638 || !bgp_outbound_policy_exists(
11639 peer, filter)))
11640 json_object_string_add(json_peer,
11641 "peerState",
11642 "Policy");
11643 else
11644 json_object_string_add(
11645 json_peer, "peerState", "OK");
11646
200116db
DD
11647 json_object_int_add(json_peer, "connectionsEstablished",
11648 peer->established);
11649 json_object_int_add(json_peer, "connectionsDropped",
11650 peer->dropped);
aa72bd7e
PG
11651 if (peer->desc)
11652 json_object_string_add(
11653 json_peer, "desc", peer->desc);
b4e9dcba 11654 }
3577f1c5
DD
11655 /* Avoid creating empty peer dicts in JSON */
11656 if (json_peer == NULL)
11657 continue;
ea47320b
DL
11658
11659 if (peer->conf_if)
60466a63 11660 json_object_string_add(json_peer, "idType",
ea47320b
DL
11661 "interface");
11662 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
11663 json_object_string_add(json_peer, "idType",
11664 "ipv4");
ea47320b 11665 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
11666 json_object_string_add(json_peer, "idType",
11667 "ipv6");
ea47320b
DL
11668 json_object_object_add(json_peers, peer->host,
11669 json_peer);
11670 } else {
8c1d4cd5 11671 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
11672 as_type, as)) {
11673 filtered_count++;
8c1d4cd5 11674 continue;
ce1944f0 11675 }
3577f1c5
DD
11676 if (show_failed &&
11677 bgp_has_peer_failed(peer, afi, safi)) {
11678 bgp_show_failed_summary(vty, bgp, peer, NULL,
11679 max_neighbor_width,
11680 use_json);
11681 } else if (!show_failed) {
10b49f14 11682 if (show_established
ce1944f0
LS
11683 && bgp_has_peer_failed(peer, afi, safi)) {
11684 filtered_count++;
10b49f14 11685 continue;
ce1944f0 11686 }
96c81f66
LS
11687
11688 if ((count - filtered_count) == 1) {
11689 /* display headline before the first
11690 * neighbor line */
11691 vty_out(vty, "\n");
11692
11693 /* Subtract 8 here because 'Neighbor' is
11694 * 8 characters */
11695 vty_out(vty, "Neighbor");
11696 vty_out(vty, "%*s",
11697 max_neighbor_width - 8, " ");
11698 vty_out(vty,
11699 show_wide
11700 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11701 : BGP_SHOW_SUMMARY_HEADER_ALL);
11702 }
11703
3577f1c5
DD
11704 memset(dn_flag, '\0', sizeof(dn_flag));
11705 if (peer_dynamic_neighbor(peer)) {
11706 dn_flag[0] = '*';
11707 }
d62a17ae 11708
3577f1c5 11709 if (peer->hostname
892fedb6
DA
11710 && CHECK_FLAG(bgp->flags,
11711 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 11712 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
11713 peer->hostname,
11714 peer->host);
d62a17ae 11715 else
3577f1c5
DD
11716 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11717
11718 /* pad the neighbor column with spaces */
11719 if (len < max_neighbor_width)
11720 vty_out(vty, "%*s", max_neighbor_width - len,
11721 " ");
11722
43aa5965
QY
11723 atomic_size_t outq_count, inq_count;
11724 outq_count = atomic_load_explicit(
11725 &peer->obuf->count,
11726 memory_order_relaxed);
11727 inq_count = atomic_load_explicit(
11728 &peer->ibuf->count,
11729 memory_order_relaxed);
11730
44a4d55e
PG
11731 vty_out(vty, "4 ");
11732 vty_out(vty, ASN_FORMAT_SPACE(bgp->asnotation),
11733 &peer->as);
344c7da0 11734 if (show_wide)
85eeb029 11735 vty_out(vty,
44a4d55e
PG
11736 ASN_FORMAT_SPACE(
11737 bgp->asnotation),
85eeb029 11738 peer->change_local_as
44a4d55e
PG
11739 ? &peer->change_local_as
11740 : &peer->local_as);
344c7da0 11741 vty_out(vty,
11742 " %9u %9u %8" PRIu64 " %4zu %4zu %8s",
11743 PEER_TOTAL_RX(peer),
11744 PEER_TOTAL_TX(peer),
11745 peer->version[afi][safi], inq_count,
11746 outq_count,
11747 peer_uptime(peer->uptime, timebuf,
11748 BGP_UPTIME_LEN, 0, NULL));
11749
feb17238 11750 if (peer_established(peer)) {
d3ada366
DA
11751 if (peer->afc_recv[afi][safi]) {
11752 if (CHECK_FLAG(
11753 bgp->flags,
11754 BGP_FLAG_EBGP_REQUIRES_POLICY)
11755 && !bgp_inbound_policy_exists(
11756 peer, filter))
11757 vty_out(vty, " %12s",
11758 "(Policy)");
11759 else
11760 vty_out(vty,
6cde4b45 11761 " %12u",
d3ada366
DA
11762 peer->pcount
11763 [afi]
11764 [pfx_rcd_safi]);
11765 } else {
749d0f27 11766 vty_out(vty, " NoNeg");
d3ada366 11767 }
db92d226 11768
d3ada366
DA
11769 if (paf && PAF_SUBGRP(paf)) {
11770 if (CHECK_FLAG(
11771 bgp->flags,
11772 BGP_FLAG_EBGP_REQUIRES_POLICY)
11773 && !bgp_outbound_policy_exists(
11774 peer, filter))
11775 vty_out(vty, " %8s",
11776 "(Policy)");
11777 else
11778 vty_out(vty,
6cde4b45 11779 " %8u",
d3ada366
DA
11780 (PAF_SUBGRP(
11781 paf))
11782 ->scount);
749d0f27
DA
11783 } else {
11784 vty_out(vty, " NoNeg");
d3ada366 11785 }
db92d226 11786 } else {
736b68f3
DS
11787 if (CHECK_FLAG(peer->flags,
11788 PEER_FLAG_SHUTDOWN)
11789 || CHECK_FLAG(peer->bgp->flags,
11790 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
11791 vty_out(vty, " Idle (Admin)");
11792 else if (CHECK_FLAG(
11793 peer->sflags,
11794 PEER_STATUS_PREFIX_OVERFLOW))
11795 vty_out(vty, " Idle (PfxCt)");
11796 else
11797 vty_out(vty, " %12s",
11798 lookup_msg(bgp_status_msg,
11799 peer->status, NULL));
db92d226 11800
6cde4b45 11801 vty_out(vty, " %8u", 0);
3577f1c5 11802 }
565e9ddd
DA
11803 /* Make sure `Desc` column is the lastest in
11804 * the output.
11805 */
aa72bd7e 11806 if (peer->desc)
cb75bb31
DA
11807 vty_out(vty, " %s",
11808 bgp_peer_description_stripped(
85eeb029
DA
11809 peer->desc,
11810 show_wide ? 64 : 20));
aa72bd7e
PG
11811 else
11812 vty_out(vty, " N/A");
3577f1c5 11813 vty_out(vty, "\n");
d62a17ae 11814 }
3577f1c5 11815
d62a17ae 11816 }
11817 }
f933309e 11818
d62a17ae 11819 if (use_json) {
11820 json_object_object_add(json, "peers", json_peers);
3577f1c5 11821 json_object_int_add(json, "failedPeers", failed_count);
ce1944f0
LS
11822 json_object_int_add(json, "displayedPeers",
11823 count - filtered_count);
d62a17ae 11824 json_object_int_add(json, "totalPeers", count);
11825 json_object_int_add(json, "dynamicPeers", dn_count);
11826
3577f1c5
DD
11827 if (!show_failed)
11828 bgp_show_bestpath_json(bgp, json);
57a9c8a8 11829
75eeda93 11830 vty_json(vty, json);
d62a17ae 11831 } else {
ce1944f0 11832 if (count) {
96c81f66
LS
11833 if (filtered_count == count)
11834 vty_out(vty, "\n%% No matching neighbor\n");
11835 else {
11836 if (show_failed)
11837 vty_out(vty, "\nDisplayed neighbors %d",
11838 failed_count);
11839 else if (as_type != AS_UNSPECIFIED || as
11840 || fpeer || show_established)
ce1944f0
LS
11841 vty_out(vty, "\nDisplayed neighbors %d",
11842 count - filtered_count);
96c81f66
LS
11843
11844 vty_out(vty, "\nTotal number of neighbors %d\n",
11845 count);
ce1944f0 11846 }
ce1944f0 11847 } else {
d6ceaca3 11848 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 11849 get_afi_safi_str(afi, safi, false));
d62a17ae 11850 }
b05a1c8b 11851
d6ceaca3 11852 if (dn_count) {
d62a17ae 11853 vty_out(vty, "* - dynamic neighbor\n");
11854 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11855 dn_count, bgp->dynamic_neighbors_limit);
11856 }
11857 }
1ff9a340 11858
d62a17ae 11859 return CMD_SUCCESS;
718e3744 11860}
11861
d62a17ae 11862static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5 11863 int safi, struct peer *fpeer, int as_type,
96c81f66 11864 as_t as, uint16_t show_flags)
d62a17ae 11865{
11866 int is_first = 1;
11867 int afi_wildcard = (afi == AFI_MAX);
11868 int safi_wildcard = (safi == SAFI_MAX);
11869 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 11870 bool nbr_output = false;
85eeb029 11871 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11872
11873 if (use_json && is_wildcard)
11874 vty_out(vty, "{\n");
11875 if (afi_wildcard)
11876 afi = 1; /* AFI_IP */
11877 while (afi < AFI_MAX) {
11878 if (safi_wildcard)
11879 safi = 1; /* SAFI_UNICAST */
11880 while (safi < SAFI_MAX) {
318cac96 11881 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 11882 nbr_output = true;
f86897b9 11883
d62a17ae 11884 if (is_wildcard) {
11885 /*
11886 * So limit output to those afi/safi
11887 * pairs that
11888 * actualy have something interesting in
11889 * them
11890 */
11891 if (use_json) {
d62a17ae 11892 if (!is_first)
11893 vty_out(vty, ",\n");
11894 else
11895 is_first = 0;
11896
11897 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11898 get_afi_safi_str(afi,
11899 safi,
11900 true));
d62a17ae 11901 } else {
6cac2fcc
LS
11902 vty_out(vty,
11903 "\n%s Summary (%s):\n",
5cb5f4d0
DD
11904 get_afi_safi_str(afi,
11905 safi,
6cac2fcc
LS
11906 false),
11907 bgp->name_pretty);
d62a17ae 11908 }
11909 }
8c1d4cd5
LS
11910 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11911 as_type, as, show_flags);
d62a17ae 11912 }
11913 safi++;
d62a17ae 11914 if (!safi_wildcard)
11915 safi = SAFI_MAX;
11916 }
11917 afi++;
ee851c8c 11918 if (!afi_wildcard)
d62a17ae 11919 afi = AFI_MAX;
11920 }
11921
11922 if (use_json && is_wildcard)
11923 vty_out(vty, "}\n");
ca61fd25
DS
11924 else if (!nbr_output) {
11925 if (use_json)
11926 vty_out(vty, "{}\n");
11927 else
6cac2fcc
LS
11928 vty_out(vty, "%% No BGP neighbors found in %s\n",
11929 bgp->name_pretty);
ca61fd25 11930 }
d62a17ae 11931}
11932
11933static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
11934 safi_t safi,
11935 const char *neighbor,
11936 int as_type, as_t as,
96c81f66 11937 uint16_t show_flags)
d62a17ae 11938{
11939 struct listnode *node, *nnode;
11940 struct bgp *bgp;
8c1d4cd5 11941 struct peer *fpeer = NULL;
d62a17ae 11942 int is_first = 1;
9f049418 11943 bool nbr_output = false;
85eeb029 11944 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11945
11946 if (use_json)
11947 vty_out(vty, "{\n");
11948
11949 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11950 nbr_output = true;
d62a17ae 11951 if (use_json) {
d62a17ae 11952 if (!is_first)
11953 vty_out(vty, ",\n");
11954 else
11955 is_first = 0;
11956
11957 vty_out(vty, "\"%s\":",
11958 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11959 ? VRF_DEFAULT_NAME
d62a17ae 11960 : bgp->name);
d62a17ae 11961 }
8c1d4cd5
LS
11962 if (neighbor) {
11963 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11964 use_json);
11965 if (!fpeer)
11966 continue;
11967 }
11968 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11969 as, show_flags);
d62a17ae 11970 }
11971
11972 if (use_json)
11973 vty_out(vty, "}\n");
9f049418
DS
11974 else if (!nbr_output)
11975 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11976}
11977
11978int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5 11979 safi_t safi, const char *neighbor, int as_type,
96c81f66 11980 as_t as, uint16_t show_flags)
d62a17ae 11981{
11982 struct bgp *bgp;
85eeb029 11983 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 11984 struct peer *fpeer = NULL;
d62a17ae 11985
11986 if (name) {
11987 if (strmatch(name, "all")) {
85eeb029 11988 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
11989 neighbor, as_type,
11990 as, show_flags);
d62a17ae 11991 return CMD_SUCCESS;
11992 } else {
11993 bgp = bgp_lookup_by_name(name);
11994
11995 if (!bgp) {
11996 if (use_json)
11997 vty_out(vty, "{}\n");
11998 else
11999 vty_out(vty,
ca61fd25 12000 "%% BGP instance not found\n");
d62a17ae 12001 return CMD_WARNING;
12002 }
12003
8c1d4cd5
LS
12004 if (neighbor) {
12005 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
12006 use_json);
12007 if (!fpeer)
12008 return CMD_WARNING;
12009 }
12010 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
12011 as_type, as, show_flags);
d62a17ae 12012 return CMD_SUCCESS;
12013 }
12014 }
12015
12016 bgp = bgp_get_default();
12017
8c1d4cd5
LS
12018 if (bgp) {
12019 if (neighbor) {
12020 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
12021 use_json);
12022 if (!fpeer)
12023 return CMD_WARNING;
12024 }
12025 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
12026 as, show_flags);
12027 } else {
ca61fd25
DS
12028 if (use_json)
12029 vty_out(vty, "{}\n");
12030 else
12031 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
12032 return CMD_WARNING;
12033 }
d62a17ae 12034
12035 return CMD_SUCCESS;
4fb25c53
DW
12036}
12037
716b2d8a 12038/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
12039DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
12040 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
12041 " [" BGP_SAFI_WITH_LABEL_CMD_STR
8079a413 12042 "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <ASNUM|internal|external>>] [terse] [wide] [json$uj]",
8c1d4cd5
LS
12043 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
12044 BGP_SAFI_WITH_LABEL_HELP_STR
12045 "Display the entries for all address families\n"
12046 "Summary of BGP neighbor status\n"
12047 "Show only sessions in Established state\n"
12048 "Show only sessions not in Established state\n"
12049 "Show only the specified neighbor session\n"
12050 "Neighbor to display information about\n"
12051 "Neighbor to display information about\n"
12052 "Neighbor on BGP configured interface\n"
8079a413 12053 "Show only the specified remote AS sessions\n" AS_STR
8c1d4cd5
LS
12054 "Internal (iBGP) AS sessions\n"
12055 "External (eBGP) AS sessions\n"
96c81f66 12056 "Shorten the information on BGP instances\n"
8c1d4cd5 12057 "Increase table width for longer output\n" JSON_STR)
718e3744 12058{
d62a17ae 12059 char *vrf = NULL;
12060 afi_t afi = AFI_MAX;
12061 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
12062 as_t as = 0; /* 0 means AS filter not set */
12063 int as_type = AS_UNSPECIFIED;
96c81f66 12064 uint16_t show_flags = 0;
d62a17ae 12065
12066 int idx = 0;
12067
12068 /* show [ip] bgp */
96f3485c 12069 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 12070 afi = AFI_IP;
9a8bdf1c
PG
12071 /* [<vrf> VIEWVRFNAME] */
12072 if (argv_find(argv, argc, "vrf", &idx)) {
12073 vrf = argv[idx + 1]->arg;
12074 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12075 vrf = NULL;
12076 } else if (argv_find(argv, argc, "view", &idx))
12077 /* [<view> VIEWVRFNAME] */
12078 vrf = argv[idx + 1]->arg;
d62a17ae 12079 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
12080 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
12081 argv_find_and_parse_safi(argv, argc, &idx, &safi);
12082 }
12083
3577f1c5 12084 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
12085 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
12086
10b49f14 12087 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
12088 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
12089
8c1d4cd5
LS
12090 if (argv_find(argv, argc, "remote-as", &idx)) {
12091 if (argv[idx + 1]->arg[0] == 'i')
12092 as_type = AS_INTERNAL;
12093 else if (argv[idx + 1]->arg[0] == 'e')
12094 as_type = AS_EXTERNAL;
8079a413
PG
12095 else if (!asn_str2asn(argv[idx + 1]->arg, &as)) {
12096 vty_out(vty,
12097 "%% Invalid neighbor remote-as value: %s\n",
12098 argv[idx + 1]->arg);
12099 return CMD_SUCCESS;
12100 }
8c1d4cd5
LS
12101 }
12102
96c81f66
LS
12103 if (argv_find(argv, argc, "terse", &idx))
12104 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
12105
85eeb029
DA
12106 if (argv_find(argv, argc, "wide", &idx))
12107 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
12108
12109 if (argv_find(argv, argc, "json", &idx))
12110 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 12111
8c1d4cd5
LS
12112 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
12113 show_flags);
d62a17ae 12114}
12115
5cb5f4d0 12116const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 12117{
5cb5f4d0
DD
12118 if (for_json)
12119 return get_afi_safi_json_str(afi, safi);
d62a17ae 12120 else
5cb5f4d0 12121 return get_afi_safi_vty_str(afi, safi);
27162734
LB
12122}
12123
d62a17ae 12124
12125static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
12126 afi_t afi, safi_t safi,
d7c0a89a
QY
12127 uint16_t adv_smcap, uint16_t adv_rmcap,
12128 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 12129 bool use_json, json_object *json_pref)
d62a17ae 12130{
12131 /* Send-Mode */
12132 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
12133 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
12134 if (use_json) {
12135 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
12136 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
12137 json_object_string_add(json_pref, "sendMode",
12138 "advertisedAndReceived");
12139 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
12140 json_object_string_add(json_pref, "sendMode",
12141 "advertised");
12142 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
12143 json_object_string_add(json_pref, "sendMode",
12144 "received");
12145 } else {
12146 vty_out(vty, " Send-mode: ");
12147 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
12148 vty_out(vty, "advertised");
12149 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
12150 vty_out(vty, "%sreceived",
12151 CHECK_FLAG(p->af_cap[afi][safi],
12152 adv_smcap)
12153 ? ", "
12154 : "");
12155 vty_out(vty, "\n");
12156 }
12157 }
12158
12159 /* Receive-Mode */
12160 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
12161 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
12162 if (use_json) {
12163 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
12164 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12165 json_object_string_add(json_pref, "recvMode",
12166 "advertisedAndReceived");
12167 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12168 json_object_string_add(json_pref, "recvMode",
12169 "advertised");
12170 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12171 json_object_string_add(json_pref, "recvMode",
12172 "received");
12173 } else {
12174 vty_out(vty, " Receive-mode: ");
12175 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12176 vty_out(vty, "advertised");
12177 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12178 vty_out(vty, "%sreceived",
12179 CHECK_FLAG(p->af_cap[afi][safi],
12180 adv_rmcap)
12181 ? ", "
12182 : "");
12183 vty_out(vty, "\n");
12184 }
12185 }
12186}
12187
eea685b6
DA
12188static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
12189 struct peer *p,
eea685b6 12190 json_object *json)
2986cac2 12191{
eea685b6
DA
12192 bool rbit = false;
12193 bool nbit = false;
2986cac2 12194
13909c4f
DS
12195 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
12196 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
feb17238 12197 && (peer_established(p))) {
eea685b6
DA
12198 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
12199 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
2986cac2 12200 }
12201
403e64f8 12202 if (json) {
eea685b6
DA
12203 json_object_boolean_add(json, "rBit", rbit);
12204 json_object_boolean_add(json, "nBit", nbit);
2986cac2 12205 } else {
eea685b6
DA
12206 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
12207 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
2986cac2 12208 }
12209}
12210
13909c4f
DS
12211static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
12212 struct peer *peer,
13909c4f 12213 json_object *json)
2986cac2 12214{
2bb5d39b 12215 const char *mode = "NotApplicable";
2986cac2 12216
403e64f8 12217 if (!json)
a53ca37b 12218 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 12219
13909c4f 12220 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
feb17238 12221 && (peer_established(peer))) {
2986cac2 12222
13909c4f
DS
12223 if ((peer->nsf_af_count == 0)
12224 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12225
2986cac2 12226 mode = "Disable";
12227
13909c4f
DS
12228 } else if (peer->nsf_af_count == 0
12229 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12230
2986cac2 12231 mode = "Helper";
12232
13909c4f
DS
12233 } else if (peer->nsf_af_count != 0
12234 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12235
2986cac2 12236 mode = "Restart";
2986cac2 12237 }
12238 }
12239
403e64f8 12240 if (json)
13909c4f 12241 json_object_string_add(json, "remoteGrMode", mode);
403e64f8 12242 else
0e4e879b 12243 vty_out(vty, "%s\n", mode);
2986cac2 12244}
12245
13909c4f
DS
12246static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
12247 struct peer *p,
13909c4f 12248 json_object *json)
2986cac2 12249{
12250 const char *mode = "Invalid";
12251
403e64f8 12252 if (!json)
a53ca37b 12253 vty_out(vty, " Local GR Mode: ");
2986cac2 12254
12255 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
12256 mode = "Helper";
12257 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
12258 mode = "Restart";
12259 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
12260 mode = "Disable";
2ba1fe69 12261 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 12262 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
12263 mode = "Helper*";
12264 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
12265 mode = "Restart*";
12266 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
12267 mode = "Disable*";
12268 else
12269 mode = "Invalid*";
2ba1fe69 12270 }
2986cac2 12271
403e64f8 12272 if (json)
13909c4f 12273 json_object_string_add(json, "localGrMode", mode);
403e64f8 12274 else
0e4e879b 12275 vty_out(vty, "%s\n", mode);
2986cac2 12276}
12277
13909c4f 12278static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
403e64f8 12279 struct vty *vty, struct peer *peer, json_object *json)
2986cac2 12280{
2ba1fe69 12281 afi_t afi;
12282 safi_t safi;
2986cac2 12283 json_object *json_afi_safi = NULL;
12284 json_object *json_timer = NULL;
12285 json_object *json_endofrib_status = NULL;
9e3b51a7 12286 bool eor_flag = false;
2986cac2 12287
df8d723c
DA
12288 FOREACH_AFI_SAFI_NSF (afi, safi) {
12289 if (!peer->afc[afi][safi])
12290 continue;
2986cac2 12291
df8d723c
DA
12292 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
12293 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
12294 continue;
9e3b51a7 12295
403e64f8 12296 if (json) {
df8d723c
DA
12297 json_afi_safi = json_object_new_object();
12298 json_endofrib_status = json_object_new_object();
12299 json_timer = json_object_new_object();
12300 }
2986cac2 12301
df8d723c
DA
12302 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
12303 eor_flag = true;
12304 else
12305 eor_flag = false;
2986cac2 12306
403e64f8 12307 if (!json) {
df8d723c
DA
12308 vty_out(vty, " %s:\n",
12309 get_afi_safi_str(afi, safi, false));
2986cac2 12310
df8d723c
DA
12311 vty_out(vty, " F bit: ");
12312 }
2986cac2 12313
df8d723c
DA
12314 if (peer->nsf[afi][safi] &&
12315 CHECK_FLAG(peer->af_cap[afi][safi],
12316 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 12317
403e64f8 12318 if (json) {
df8d723c
DA
12319 json_object_boolean_true_add(json_afi_safi,
12320 "fBit");
12321 } else
12322 vty_out(vty, "True\n");
12323 } else {
403e64f8 12324 if (json)
df8d723c
DA
12325 json_object_boolean_false_add(json_afi_safi,
12326 "fBit");
12327 else
12328 vty_out(vty, "False\n");
12329 }
2986cac2 12330
403e64f8 12331 if (!json)
df8d723c 12332 vty_out(vty, " End-of-RIB sent: ");
2986cac2 12333
df8d723c
DA
12334 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12335 PEER_STATUS_EOR_SEND)) {
403e64f8 12336 if (json) {
df8d723c
DA
12337 json_object_boolean_true_add(
12338 json_endofrib_status, "endOfRibSend");
9e3b51a7 12339
df8d723c
DA
12340 PRINT_EOR_JSON(eor_flag);
12341 } else {
12342 vty_out(vty, "Yes\n");
12343 vty_out(vty,
12344 " End-of-RIB sent after update: ");
2986cac2 12345
df8d723c
DA
12346 PRINT_EOR(eor_flag);
12347 }
12348 } else {
403e64f8 12349 if (json) {
df8d723c
DA
12350 json_object_boolean_false_add(
12351 json_endofrib_status, "endOfRibSend");
12352 json_object_boolean_false_add(
12353 json_endofrib_status,
12354 "endOfRibSentAfterUpdate");
13909c4f 12355 } else {
df8d723c
DA
12356 vty_out(vty, "No\n");
12357 vty_out(vty,
12358 " End-of-RIB sent after update: ");
12359 vty_out(vty, "No\n");
13909c4f 12360 }
df8d723c 12361 }
2986cac2 12362
403e64f8 12363 if (!json)
df8d723c 12364 vty_out(vty, " End-of-RIB received: ");
a53ca37b 12365
df8d723c
DA
12366 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12367 PEER_STATUS_EOR_RECEIVED)) {
403e64f8 12368 if (json)
df8d723c
DA
12369 json_object_boolean_true_add(
12370 json_endofrib_status, "endOfRibRecv");
12371 else
12372 vty_out(vty, "Yes\n");
12373 } else {
403e64f8 12374 if (json)
df8d723c
DA
12375 json_object_boolean_false_add(
12376 json_endofrib_status, "endOfRibRecv");
12377 else
12378 vty_out(vty, "No\n");
12379 }
12380
403e64f8 12381 if (json) {
df8d723c
DA
12382 json_object_int_add(json_timer, "stalePathTimer",
12383 peer->bgp->stalepath_time);
12384
12385 if (peer->t_gr_stale != NULL) {
12386 json_object_int_add(json_timer,
12387 "stalePathTimerRemaining",
4f830a07 12388 event_timer_remain_second(
df8d723c 12389 peer->t_gr_stale));
a53ca37b
DA
12390 }
12391
df8d723c
DA
12392 /* Display Configured Selection
12393 * Deferral only when when
12394 * Gr mode is enabled.
12395 */
12396 if (CHECK_FLAG(peer->flags,
12397 PEER_FLAG_GRACEFUL_RESTART)) {
13909c4f 12398 json_object_int_add(json_timer,
df8d723c 12399 "selectionDeferralTimer",
13909c4f 12400 peer->bgp->stalepath_time);
df8d723c 12401 }
2986cac2 12402
df8d723c
DA
12403 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12404 NULL) {
2986cac2 12405
df8d723c
DA
12406 json_object_int_add(
12407 json_timer,
12408 "selectionDeferralTimerRemaining",
4f830a07 12409 event_timer_remain_second(
df8d723c
DA
12410 peer->bgp->gr_info[afi][safi]
12411 .t_select_deferral));
12412 }
12413 } else {
12414 vty_out(vty, " Timers:\n");
12415 vty_out(vty,
12416 " Configured Stale Path Time(sec): %u\n",
12417 peer->bgp->stalepath_time);
2986cac2 12418
df8d723c 12419 if (peer->t_gr_stale != NULL)
13909c4f 12420 vty_out(vty,
df8d723c 12421 " Stale Path Remaining(sec): %ld\n",
4f830a07 12422 event_timer_remain_second(
df8d723c
DA
12423 peer->t_gr_stale));
12424 /* Display Configured Selection
12425 * Deferral only when when
12426 * Gr mode is enabled.
12427 */
12428 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12429 vty_out(vty,
12430 " Configured Selection Deferral Time(sec): %u\n",
12431 peer->bgp->select_defer_time);
2986cac2 12432
df8d723c
DA
12433 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12434 NULL)
12435 vty_out(vty,
12436 " Selection Deferral Time Remaining(sec): %ld\n",
4f830a07 12437 event_timer_remain_second(
df8d723c
DA
12438 peer->bgp->gr_info[afi][safi]
12439 .t_select_deferral));
12440 }
403e64f8 12441 if (json) {
df8d723c
DA
12442 json_object_object_add(json_afi_safi, "endOfRibStatus",
12443 json_endofrib_status);
12444 json_object_object_add(json_afi_safi, "timers",
12445 json_timer);
12446 json_object_object_add(
12447 json, get_afi_safi_str(afi, safi, true),
12448 json_afi_safi);
2986cac2 12449 }
12450 }
12451}
12452
36235319
QY
12453static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12454 struct peer *p,
36235319 12455 json_object *json)
2986cac2 12456{
403e64f8 12457 if (json) {
2986cac2 12458 json_object *json_timer = NULL;
12459
12460 json_timer = json_object_new_object();
12461
13909c4f
DS
12462 json_object_int_add(json_timer, "configuredRestartTimer",
12463 p->bgp->restart_time);
2986cac2 12464
13909c4f
DS
12465 json_object_int_add(json_timer, "receivedRestartTimer",
12466 p->v_gr_restart);
2986cac2 12467
13909c4f
DS
12468 if (p->t_gr_restart != NULL)
12469 json_object_int_add(
12470 json_timer, "restartTimerRemaining",
4f830a07 12471 event_timer_remain_second(p->t_gr_restart));
2986cac2 12472
12473 json_object_object_add(json, "timers", json_timer);
12474 } else {
12475
a53ca37b
DA
12476 vty_out(vty, " Timers:\n");
12477 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 12478 p->bgp->restart_time);
2986cac2 12479
a53ca37b 12480 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
12481 p->v_gr_restart);
12482 if (p->t_gr_restart != NULL)
a53ca37b 12483 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
4f830a07 12484 event_timer_remain_second(p->t_gr_restart));
36235319 12485 if (p->t_gr_restart != NULL) {
a53ca37b 12486 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
4f830a07 12487 event_timer_remain_second(p->t_gr_restart));
36235319 12488 }
2986cac2 12489 }
12490}
12491
12492static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
403e64f8 12493 json_object *json)
2986cac2 12494{
2986cac2 12495 char dn_flag[2] = {0};
2b7165e7
QY
12496 /* '*' + v6 address of neighbor */
12497 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 12498
2986cac2 12499 if (!p->conf_if && peer_dynamic_neighbor(p))
12500 dn_flag[0] = '*';
12501
12502 if (p->conf_if) {
403e64f8 12503 if (json)
47e12884
DA
12504 json_object_string_addf(json, "neighborAddr", "%pSU",
12505 &p->su);
2986cac2 12506 else
47e12884
DA
12507 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12508 &p->su);
2986cac2 12509 } else {
772270f3
QY
12510 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12511 p->host);
2986cac2 12512
403e64f8 12513 if (json)
36235319
QY
12514 json_object_string_add(json, "neighborAddr",
12515 neighborAddr);
2986cac2 12516 else
36235319 12517 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 12518 }
12519
12520 /* more gr info in new format */
403e64f8 12521 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json);
2986cac2 12522}
12523
d62a17ae 12524static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 12525 safi_t safi, bool use_json,
d62a17ae 12526 json_object *json_neigh)
12527{
0291c246
MK
12528 struct bgp_filter *filter;
12529 struct peer_af *paf;
12530 char orf_pfx_name[BUFSIZ];
12531 int orf_pfx_count;
12532 json_object *json_af = NULL;
12533 json_object *json_prefA = NULL;
12534 json_object *json_prefB = NULL;
12535 json_object *json_addr = NULL;
fa36596c 12536 json_object *json_advmap = NULL;
d62a17ae 12537
12538 if (use_json) {
12539 json_addr = json_object_new_object();
12540 json_af = json_object_new_object();
12541 filter = &p->filter[afi][safi];
12542
12543 if (peer_group_active(p))
12544 json_object_string_add(json_addr, "peerGroupMember",
12545 p->group->name);
12546
12547 paf = peer_af_find(p, afi, safi);
12548 if (paf && PAF_SUBGRP(paf)) {
12549 json_object_int_add(json_addr, "updateGroupId",
12550 PAF_UPDGRP(paf)->id);
12551 json_object_int_add(json_addr, "subGroupId",
12552 PAF_SUBGRP(paf)->id);
12553 json_object_int_add(json_addr, "packetQueueLength",
12554 bpacket_queue_virtual_length(paf));
12555 }
12556
12557 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12558 || CHECK_FLAG(p->af_cap[afi][safi],
12559 PEER_CAP_ORF_PREFIX_SM_RCV)
12560 || CHECK_FLAG(p->af_cap[afi][safi],
12561 PEER_CAP_ORF_PREFIX_RM_ADV)
12562 || CHECK_FLAG(p->af_cap[afi][safi],
12563 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12564 json_object_int_add(json_af, "orfType",
12565 ORF_TYPE_PREFIX);
12566 json_prefA = json_object_new_object();
12567 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12568 PEER_CAP_ORF_PREFIX_SM_ADV,
12569 PEER_CAP_ORF_PREFIX_RM_ADV,
12570 PEER_CAP_ORF_PREFIX_SM_RCV,
12571 PEER_CAP_ORF_PREFIX_RM_RCV,
12572 use_json, json_prefA);
12573 json_object_object_add(json_af, "orfPrefixList",
12574 json_prefA);
12575 }
12576
12577 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12578 || CHECK_FLAG(p->af_cap[afi][safi],
12579 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12580 || CHECK_FLAG(p->af_cap[afi][safi],
12581 PEER_CAP_ORF_PREFIX_RM_ADV)
12582 || CHECK_FLAG(p->af_cap[afi][safi],
12583 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12584 json_object_int_add(json_af, "orfOldType",
12585 ORF_TYPE_PREFIX_OLD);
12586 json_prefB = json_object_new_object();
12587 bgp_show_peer_afi_orf_cap(
12588 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12589 PEER_CAP_ORF_PREFIX_RM_ADV,
12590 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12591 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12592 json_prefB);
12593 json_object_object_add(json_af, "orfOldPrefixList",
12594 json_prefB);
12595 }
12596
12597 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12598 || CHECK_FLAG(p->af_cap[afi][safi],
12599 PEER_CAP_ORF_PREFIX_SM_RCV)
12600 || CHECK_FLAG(p->af_cap[afi][safi],
12601 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12602 || CHECK_FLAG(p->af_cap[afi][safi],
12603 PEER_CAP_ORF_PREFIX_RM_ADV)
12604 || CHECK_FLAG(p->af_cap[afi][safi],
12605 PEER_CAP_ORF_PREFIX_RM_RCV)
12606 || CHECK_FLAG(p->af_cap[afi][safi],
12607 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12608 json_object_object_add(json_addr, "afDependentCap",
12609 json_af);
12610 else
12611 json_object_free(json_af);
12612
772270f3
QY
12613 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12614 p->host, afi, safi);
d62a17ae 12615 orf_pfx_count = prefix_bgp_show_prefix_list(
12616 NULL, afi, orf_pfx_name, use_json);
12617
12618 if (CHECK_FLAG(p->af_sflags[afi][safi],
12619 PEER_STATUS_ORF_PREFIX_SEND)
12620 || orf_pfx_count) {
12621 if (CHECK_FLAG(p->af_sflags[afi][safi],
12622 PEER_STATUS_ORF_PREFIX_SEND))
12623 json_object_boolean_true_add(json_neigh,
12624 "orfSent");
12625 if (orf_pfx_count)
12626 json_object_int_add(json_addr, "orfRecvCounter",
12627 orf_pfx_count);
12628 }
12629 if (CHECK_FLAG(p->af_sflags[afi][safi],
12630 PEER_STATUS_ORF_WAIT_REFRESH))
12631 json_object_string_add(
12632 json_addr, "orfFirstUpdate",
12633 "deferredUntilORFOrRouteRefreshRecvd");
12634
12635 if (CHECK_FLAG(p->af_flags[afi][safi],
12636 PEER_FLAG_REFLECTOR_CLIENT))
12637 json_object_boolean_true_add(json_addr,
12638 "routeReflectorClient");
12639 if (CHECK_FLAG(p->af_flags[afi][safi],
12640 PEER_FLAG_RSERVER_CLIENT))
12641 json_object_boolean_true_add(json_addr,
12642 "routeServerClient");
12643 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12644 json_object_boolean_true_add(json_addr,
12645 "inboundSoftConfigPermit");
12646
12647 if (CHECK_FLAG(p->af_flags[afi][safi],
12648 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12649 json_object_boolean_true_add(
12650 json_addr,
12651 "privateAsNumsAllReplacedInUpdatesToNbr");
12652 else if (CHECK_FLAG(p->af_flags[afi][safi],
12653 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12654 json_object_boolean_true_add(
12655 json_addr,
12656 "privateAsNumsReplacedInUpdatesToNbr");
12657 else if (CHECK_FLAG(p->af_flags[afi][safi],
12658 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12659 json_object_boolean_true_add(
12660 json_addr,
12661 "privateAsNumsAllRemovedInUpdatesToNbr");
12662 else if (CHECK_FLAG(p->af_flags[afi][safi],
12663 PEER_FLAG_REMOVE_PRIVATE_AS))
12664 json_object_boolean_true_add(
12665 json_addr,
12666 "privateAsNumsRemovedInUpdatesToNbr");
12667
b2ac1d0d
MS
12668 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12669 if (CHECK_FLAG(p->af_flags[afi][safi],
12670 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12671 json_object_boolean_true_add(json_addr,
12672 "allowAsInOrigin");
12673 else
12674 json_object_int_add(json_addr, "allowAsInCount",
12675 p->allowas_in[afi][safi]);
12676 }
12677
dcc68b5e
MS
12678 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12679 json_object_boolean_true_add(
12680 json_addr,
12681 bgp_addpath_names(p->addpath_type[afi][safi])
12682 ->type_json_name);
d62a17ae 12683
12684 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12685 json_object_string_add(json_addr,
12686 "overrideASNsInOutboundUpdates",
12687 "ifAspathEqualRemoteAs");
12688
12689 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12690 || CHECK_FLAG(p->af_flags[afi][safi],
12691 PEER_FLAG_FORCE_NEXTHOP_SELF))
12692 json_object_boolean_true_add(json_addr,
12693 "routerAlwaysNextHop");
12694 if (CHECK_FLAG(p->af_flags[afi][safi],
12695 PEER_FLAG_AS_PATH_UNCHANGED))
12696 json_object_boolean_true_add(
12697 json_addr, "unchangedAsPathPropogatedToNbr");
12698 if (CHECK_FLAG(p->af_flags[afi][safi],
12699 PEER_FLAG_NEXTHOP_UNCHANGED))
12700 json_object_boolean_true_add(
12701 json_addr, "unchangedNextHopPropogatedToNbr");
12702 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12703 json_object_boolean_true_add(
12704 json_addr, "unchangedMedPropogatedToNbr");
12705 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12706 || CHECK_FLAG(p->af_flags[afi][safi],
12707 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12708 if (CHECK_FLAG(p->af_flags[afi][safi],
12709 PEER_FLAG_SEND_COMMUNITY)
12710 && CHECK_FLAG(p->af_flags[afi][safi],
12711 PEER_FLAG_SEND_EXT_COMMUNITY))
12712 json_object_string_add(json_addr,
12713 "commAttriSentToNbr",
12714 "extendedAndStandard");
12715 else if (CHECK_FLAG(p->af_flags[afi][safi],
12716 PEER_FLAG_SEND_EXT_COMMUNITY))
12717 json_object_string_add(json_addr,
12718 "commAttriSentToNbr",
12719 "extended");
12720 else
12721 json_object_string_add(json_addr,
12722 "commAttriSentToNbr",
12723 "standard");
12724 }
12725 if (CHECK_FLAG(p->af_flags[afi][safi],
12726 PEER_FLAG_DEFAULT_ORIGINATE)) {
12727 if (p->default_rmap[afi][safi].name)
12728 json_object_string_add(
12729 json_addr, "defaultRouteMap",
12730 p->default_rmap[afi][safi].name);
12731
12732 if (paf && PAF_SUBGRP(paf)
12733 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12734 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12735 json_object_boolean_true_add(json_addr,
12736 "defaultSent");
12737 else
12738 json_object_boolean_true_add(json_addr,
12739 "defaultNotSent");
12740 }
12741
dff8f48d 12742 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12743 if (is_evpn_enabled())
60466a63
QY
12744 json_object_boolean_true_add(
12745 json_addr, "advertiseAllVnis");
dff8f48d
MK
12746 }
12747
d62a17ae 12748 if (filter->plist[FILTER_IN].name
12749 || filter->dlist[FILTER_IN].name
12750 || filter->aslist[FILTER_IN].name
12751 || filter->map[RMAP_IN].name)
12752 json_object_boolean_true_add(json_addr,
12753 "inboundPathPolicyConfig");
12754 if (filter->plist[FILTER_OUT].name
12755 || filter->dlist[FILTER_OUT].name
12756 || filter->aslist[FILTER_OUT].name
12757 || filter->map[RMAP_OUT].name || filter->usmap.name)
12758 json_object_boolean_true_add(
12759 json_addr, "outboundPathPolicyConfig");
12760
12761 /* prefix-list */
12762 if (filter->plist[FILTER_IN].name)
12763 json_object_string_add(json_addr,
12764 "incomingUpdatePrefixFilterList",
12765 filter->plist[FILTER_IN].name);
12766 if (filter->plist[FILTER_OUT].name)
12767 json_object_string_add(json_addr,
12768 "outgoingUpdatePrefixFilterList",
12769 filter->plist[FILTER_OUT].name);
12770
12771 /* distribute-list */
12772 if (filter->dlist[FILTER_IN].name)
12773 json_object_string_add(
12774 json_addr, "incomingUpdateNetworkFilterList",
12775 filter->dlist[FILTER_IN].name);
12776 if (filter->dlist[FILTER_OUT].name)
12777 json_object_string_add(
12778 json_addr, "outgoingUpdateNetworkFilterList",
12779 filter->dlist[FILTER_OUT].name);
12780
12781 /* filter-list. */
12782 if (filter->aslist[FILTER_IN].name)
12783 json_object_string_add(json_addr,
12784 "incomingUpdateAsPathFilterList",
12785 filter->aslist[FILTER_IN].name);
12786 if (filter->aslist[FILTER_OUT].name)
12787 json_object_string_add(json_addr,
12788 "outgoingUpdateAsPathFilterList",
12789 filter->aslist[FILTER_OUT].name);
12790
12791 /* route-map. */
12792 if (filter->map[RMAP_IN].name)
12793 json_object_string_add(
12794 json_addr, "routeMapForIncomingAdvertisements",
12795 filter->map[RMAP_IN].name);
12796 if (filter->map[RMAP_OUT].name)
12797 json_object_string_add(
12798 json_addr, "routeMapForOutgoingAdvertisements",
12799 filter->map[RMAP_OUT].name);
12800
9dac9fc8 12801 /* ebgp-requires-policy (inbound) */
1d3fdccf 12802 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12803 && !bgp_inbound_policy_exists(p, filter))
12804 json_object_string_add(
12805 json_addr, "inboundEbgpRequiresPolicy",
12806 "Inbound updates discarded due to missing policy");
12807
12808 /* ebgp-requires-policy (outbound) */
1d3fdccf 12809 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12810 && (!bgp_outbound_policy_exists(p, filter)))
12811 json_object_string_add(
12812 json_addr, "outboundEbgpRequiresPolicy",
12813 "Outbound updates discarded due to missing policy");
12814
d62a17ae 12815 /* unsuppress-map */
12816 if (filter->usmap.name)
12817 json_object_string_add(json_addr,
12818 "selectiveUnsuppressRouteMap",
12819 filter->usmap.name);
12820
fa36596c
MK
12821 /* advertise-map */
12822 if (filter->advmap.aname) {
12823 json_advmap = json_object_new_object();
12824 json_object_string_add(json_advmap, "condition",
12825 filter->advmap.condition
12826 ? "EXIST"
12827 : "NON_EXIST");
12828 json_object_string_add(json_advmap, "conditionMap",
12829 filter->advmap.cname);
12830 json_object_string_add(json_advmap, "advertiseMap",
12831 filter->advmap.aname);
ecf2b628
QY
12832 json_object_string_add(
12833 json_advmap, "advertiseStatus",
12834 filter->advmap.update_type ==
12835 UPDATE_TYPE_ADVERTISE
12836 ? "Advertise"
12837 : "Withdraw");
fa36596c
MK
12838 json_object_object_add(json_addr, "advertiseMap",
12839 json_advmap);
12840 }
12841
d62a17ae 12842 /* Receive prefix count */
12843 json_object_int_add(json_addr, "acceptedPrefixCounter",
12844 p->pcount[afi][safi]);
50e05855
AD
12845 if (paf && PAF_SUBGRP(paf))
12846 json_object_int_add(json_addr, "sentPrefixCounter",
12847 (PAF_SUBGRP(paf))->scount);
d62a17ae 12848
fde246e8
DA
12849 /* Maximum prefix */
12850 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12851 json_object_int_add(json_addr, "prefixOutAllowedMax",
12852 p->pmax_out[afi][safi]);
12853
d62a17ae 12854 /* Maximum prefix */
12855 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12856 json_object_int_add(json_addr, "prefixAllowedMax",
12857 p->pmax[afi][safi]);
12858 if (CHECK_FLAG(p->af_flags[afi][safi],
12859 PEER_FLAG_MAX_PREFIX_WARNING))
12860 json_object_boolean_true_add(
12861 json_addr, "prefixAllowedMaxWarning");
12862 json_object_int_add(json_addr,
12863 "prefixAllowedWarningThresh",
12864 p->pmax_threshold[afi][safi]);
12865 if (p->pmax_restart[afi][safi])
12866 json_object_int_add(
12867 json_addr,
12868 "prefixAllowedRestartIntervalMsecs",
12869 p->pmax_restart[afi][safi] * 60000);
12870 }
2986cac2 12871 json_object_object_add(json_neigh,
36235319 12872 get_afi_safi_str(afi, safi, true),
d62a17ae 12873 json_addr);
12874
12875 } else {
12876 filter = &p->filter[afi][safi];
12877
12878 vty_out(vty, " For address family: %s\n",
5cb5f4d0 12879 get_afi_safi_str(afi, safi, false));
d62a17ae 12880
12881 if (peer_group_active(p))
12882 vty_out(vty, " %s peer-group member\n",
12883 p->group->name);
12884
12885 paf = peer_af_find(p, afi, safi);
12886 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 12887 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 12888 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12889 vty_out(vty, " Packet Queue length %d\n",
12890 bpacket_queue_virtual_length(paf));
12891 } else {
12892 vty_out(vty, " Not part of any update group\n");
12893 }
12894 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12895 || CHECK_FLAG(p->af_cap[afi][safi],
12896 PEER_CAP_ORF_PREFIX_SM_RCV)
12897 || CHECK_FLAG(p->af_cap[afi][safi],
12898 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12899 || CHECK_FLAG(p->af_cap[afi][safi],
12900 PEER_CAP_ORF_PREFIX_RM_ADV)
12901 || CHECK_FLAG(p->af_cap[afi][safi],
12902 PEER_CAP_ORF_PREFIX_RM_RCV)
12903 || CHECK_FLAG(p->af_cap[afi][safi],
12904 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12905 vty_out(vty, " AF-dependant capabilities:\n");
12906
12907 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12908 || CHECK_FLAG(p->af_cap[afi][safi],
12909 PEER_CAP_ORF_PREFIX_SM_RCV)
12910 || CHECK_FLAG(p->af_cap[afi][safi],
12911 PEER_CAP_ORF_PREFIX_RM_ADV)
12912 || CHECK_FLAG(p->af_cap[afi][safi],
12913 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12914 vty_out(vty,
12915 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12916 ORF_TYPE_PREFIX);
12917 bgp_show_peer_afi_orf_cap(
12918 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12919 PEER_CAP_ORF_PREFIX_RM_ADV,
12920 PEER_CAP_ORF_PREFIX_SM_RCV,
12921 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12922 }
12923 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12924 || CHECK_FLAG(p->af_cap[afi][safi],
12925 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12926 || CHECK_FLAG(p->af_cap[afi][safi],
12927 PEER_CAP_ORF_PREFIX_RM_ADV)
12928 || CHECK_FLAG(p->af_cap[afi][safi],
12929 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12930 vty_out(vty,
12931 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12932 ORF_TYPE_PREFIX_OLD);
12933 bgp_show_peer_afi_orf_cap(
12934 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12935 PEER_CAP_ORF_PREFIX_RM_ADV,
12936 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12937 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12938 }
12939
772270f3
QY
12940 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12941 p->host, afi, safi);
d62a17ae 12942 orf_pfx_count = prefix_bgp_show_prefix_list(
12943 NULL, afi, orf_pfx_name, use_json);
12944
12945 if (CHECK_FLAG(p->af_sflags[afi][safi],
12946 PEER_STATUS_ORF_PREFIX_SEND)
12947 || orf_pfx_count) {
12948 vty_out(vty, " Outbound Route Filter (ORF):");
12949 if (CHECK_FLAG(p->af_sflags[afi][safi],
12950 PEER_STATUS_ORF_PREFIX_SEND))
12951 vty_out(vty, " sent;");
12952 if (orf_pfx_count)
12953 vty_out(vty, " received (%d entries)",
12954 orf_pfx_count);
12955 vty_out(vty, "\n");
12956 }
12957 if (CHECK_FLAG(p->af_sflags[afi][safi],
12958 PEER_STATUS_ORF_WAIT_REFRESH))
12959 vty_out(vty,
12960 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12961
12962 if (CHECK_FLAG(p->af_flags[afi][safi],
12963 PEER_FLAG_REFLECTOR_CLIENT))
12964 vty_out(vty, " Route-Reflector Client\n");
12965 if (CHECK_FLAG(p->af_flags[afi][safi],
12966 PEER_FLAG_RSERVER_CLIENT))
12967 vty_out(vty, " Route-Server Client\n");
12968 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12969 vty_out(vty,
12970 " Inbound soft reconfiguration allowed\n");
12971
12972 if (CHECK_FLAG(p->af_flags[afi][safi],
12973 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12974 vty_out(vty,
12975 " Private AS numbers (all) replaced in updates to this neighbor\n");
12976 else if (CHECK_FLAG(p->af_flags[afi][safi],
12977 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12978 vty_out(vty,
12979 " Private AS numbers replaced in updates to this neighbor\n");
12980 else if (CHECK_FLAG(p->af_flags[afi][safi],
12981 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12982 vty_out(vty,
12983 " Private AS numbers (all) removed in updates to this neighbor\n");
12984 else if (CHECK_FLAG(p->af_flags[afi][safi],
12985 PEER_FLAG_REMOVE_PRIVATE_AS))
12986 vty_out(vty,
12987 " Private AS numbers removed in updates to this neighbor\n");
12988
b2ac1d0d
MS
12989 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12990 if (CHECK_FLAG(p->af_flags[afi][safi],
12991 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12992 vty_out(vty,
12993 " Local AS allowed as path origin\n");
12994 else
12995 vty_out(vty,
12996 " Local AS allowed in path, %d occurrences\n",
12997 p->allowas_in[afi][safi]);
12998 }
12999
dcc68b5e
MS
13000 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
13001 vty_out(vty, " %s\n",
13002 bgp_addpath_names(p->addpath_type[afi][safi])
13003 ->human_description);
d62a17ae 13004
13005 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
13006 vty_out(vty,
13007 " Override ASNs in outbound updates if aspath equals remote-as\n");
13008
13009 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
13010 || CHECK_FLAG(p->af_flags[afi][safi],
13011 PEER_FLAG_FORCE_NEXTHOP_SELF))
13012 vty_out(vty, " NEXT_HOP is always this router\n");
13013 if (CHECK_FLAG(p->af_flags[afi][safi],
13014 PEER_FLAG_AS_PATH_UNCHANGED))
13015 vty_out(vty,
13016 " AS_PATH is propagated unchanged to this neighbor\n");
13017 if (CHECK_FLAG(p->af_flags[afi][safi],
13018 PEER_FLAG_NEXTHOP_UNCHANGED))
13019 vty_out(vty,
13020 " NEXT_HOP is propagated unchanged to this neighbor\n");
13021 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
13022 vty_out(vty,
13023 " MED is propagated unchanged to this neighbor\n");
13024 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
13025 || CHECK_FLAG(p->af_flags[afi][safi],
13026 PEER_FLAG_SEND_EXT_COMMUNITY)
13027 || CHECK_FLAG(p->af_flags[afi][safi],
13028 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
13029 vty_out(vty,
13030 " Community attribute sent to this neighbor");
13031 if (CHECK_FLAG(p->af_flags[afi][safi],
13032 PEER_FLAG_SEND_COMMUNITY)
13033 && CHECK_FLAG(p->af_flags[afi][safi],
13034 PEER_FLAG_SEND_EXT_COMMUNITY)
13035 && CHECK_FLAG(p->af_flags[afi][safi],
13036 PEER_FLAG_SEND_LARGE_COMMUNITY))
13037 vty_out(vty, "(all)\n");
13038 else if (CHECK_FLAG(p->af_flags[afi][safi],
13039 PEER_FLAG_SEND_LARGE_COMMUNITY))
13040 vty_out(vty, "(large)\n");
13041 else if (CHECK_FLAG(p->af_flags[afi][safi],
13042 PEER_FLAG_SEND_EXT_COMMUNITY))
13043 vty_out(vty, "(extended)\n");
13044 else
13045 vty_out(vty, "(standard)\n");
13046 }
13047 if (CHECK_FLAG(p->af_flags[afi][safi],
13048 PEER_FLAG_DEFAULT_ORIGINATE)) {
13049 vty_out(vty, " Default information originate,");
13050
13051 if (p->default_rmap[afi][safi].name)
13052 vty_out(vty, " default route-map %s%s,",
13053 p->default_rmap[afi][safi].map ? "*"
13054 : "",
13055 p->default_rmap[afi][safi].name);
13056 if (paf && PAF_SUBGRP(paf)
13057 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
13058 SUBGRP_STATUS_DEFAULT_ORIGINATE))
13059 vty_out(vty, " default sent\n");
13060 else
13061 vty_out(vty, " default not sent\n");
13062 }
13063
dff8f48d
MK
13064 /* advertise-vni-all */
13065 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 13066 if (is_evpn_enabled())
dff8f48d
MK
13067 vty_out(vty, " advertise-all-vni\n");
13068 }
13069
d62a17ae 13070 if (filter->plist[FILTER_IN].name
13071 || filter->dlist[FILTER_IN].name
13072 || filter->aslist[FILTER_IN].name
13073 || filter->map[RMAP_IN].name)
13074 vty_out(vty, " Inbound path policy configured\n");
13075 if (filter->plist[FILTER_OUT].name
13076 || filter->dlist[FILTER_OUT].name
13077 || filter->aslist[FILTER_OUT].name
13078 || filter->map[RMAP_OUT].name || filter->usmap.name)
13079 vty_out(vty, " Outbound path policy configured\n");
13080
13081 /* prefix-list */
13082 if (filter->plist[FILTER_IN].name)
13083 vty_out(vty,
13084 " Incoming update prefix filter list is %s%s\n",
13085 filter->plist[FILTER_IN].plist ? "*" : "",
13086 filter->plist[FILTER_IN].name);
13087 if (filter->plist[FILTER_OUT].name)
13088 vty_out(vty,
13089 " Outgoing update prefix filter list is %s%s\n",
13090 filter->plist[FILTER_OUT].plist ? "*" : "",
13091 filter->plist[FILTER_OUT].name);
13092
13093 /* distribute-list */
13094 if (filter->dlist[FILTER_IN].name)
13095 vty_out(vty,
13096 " Incoming update network filter list is %s%s\n",
13097 filter->dlist[FILTER_IN].alist ? "*" : "",
13098 filter->dlist[FILTER_IN].name);
13099 if (filter->dlist[FILTER_OUT].name)
13100 vty_out(vty,
13101 " Outgoing update network filter list is %s%s\n",
13102 filter->dlist[FILTER_OUT].alist ? "*" : "",
13103 filter->dlist[FILTER_OUT].name);
13104
13105 /* filter-list. */
13106 if (filter->aslist[FILTER_IN].name)
13107 vty_out(vty,
13108 " Incoming update AS path filter list is %s%s\n",
13109 filter->aslist[FILTER_IN].aslist ? "*" : "",
13110 filter->aslist[FILTER_IN].name);
13111 if (filter->aslist[FILTER_OUT].name)
13112 vty_out(vty,
13113 " Outgoing update AS path filter list is %s%s\n",
13114 filter->aslist[FILTER_OUT].aslist ? "*" : "",
13115 filter->aslist[FILTER_OUT].name);
13116
13117 /* route-map. */
13118 if (filter->map[RMAP_IN].name)
13119 vty_out(vty,
13120 " Route map for incoming advertisements is %s%s\n",
13121 filter->map[RMAP_IN].map ? "*" : "",
13122 filter->map[RMAP_IN].name);
13123 if (filter->map[RMAP_OUT].name)
13124 vty_out(vty,
13125 " Route map for outgoing advertisements is %s%s\n",
13126 filter->map[RMAP_OUT].map ? "*" : "",
13127 filter->map[RMAP_OUT].name);
13128
9dac9fc8 13129 /* ebgp-requires-policy (inbound) */
1d3fdccf 13130 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
13131 && !bgp_inbound_policy_exists(p, filter))
13132 vty_out(vty,
13133 " Inbound updates discarded due to missing policy\n");
13134
13135 /* ebgp-requires-policy (outbound) */
1d3fdccf 13136 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
13137 && !bgp_outbound_policy_exists(p, filter))
13138 vty_out(vty,
13139 " Outbound updates discarded due to missing policy\n");
13140
d62a17ae 13141 /* unsuppress-map */
13142 if (filter->usmap.name)
13143 vty_out(vty,
13144 " Route map for selective unsuppress is %s%s\n",
13145 filter->usmap.map ? "*" : "",
13146 filter->usmap.name);
13147
7f7940e6
MK
13148 /* advertise-map */
13149 if (filter->advmap.aname && filter->advmap.cname)
13150 vty_out(vty,
13151 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
13152 filter->advmap.condition ? "EXIST"
13153 : "NON_EXIST",
13154 filter->advmap.cmap ? "*" : "",
13155 filter->advmap.cname,
13156 filter->advmap.amap ? "*" : "",
13157 filter->advmap.aname,
ecf2b628
QY
13158 filter->advmap.update_type ==
13159 UPDATE_TYPE_ADVERTISE
c385f82a
MK
13160 ? "Advertise"
13161 : "Withdraw");
7f7940e6 13162
d62a17ae 13163 /* Receive prefix count */
6cde4b45 13164 vty_out(vty, " %u accepted prefixes\n",
a0a87037 13165 p->pcount[afi][safi]);
d62a17ae 13166
fde246e8
DA
13167 /* maximum-prefix-out */
13168 if (CHECK_FLAG(p->af_flags[afi][safi],
13169 PEER_FLAG_MAX_PREFIX_OUT))
13170 vty_out(vty,
6cde4b45 13171 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
13172 p->pmax_out[afi][safi]);
13173
d62a17ae 13174 /* Maximum prefix */
13175 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 13176 vty_out(vty,
6cde4b45 13177 " Maximum prefixes allowed %u%s\n",
d62a17ae 13178 p->pmax[afi][safi],
13179 CHECK_FLAG(p->af_flags[afi][safi],
13180 PEER_FLAG_MAX_PREFIX_WARNING)
13181 ? " (warning-only)"
13182 : "");
13183 vty_out(vty, " Threshold for warning message %d%%",
13184 p->pmax_threshold[afi][safi]);
13185 if (p->pmax_restart[afi][safi])
13186 vty_out(vty, ", restart interval %d min",
13187 p->pmax_restart[afi][safi]);
13188 vty_out(vty, "\n");
13189 }
13190
13191 vty_out(vty, "\n");
13192 }
13193}
13194
9f049418 13195static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 13196 json_object *json)
718e3744 13197{
d62a17ae 13198 struct bgp *bgp;
d62a17ae 13199 char timebuf[BGP_UPTIME_LEN];
13200 char dn_flag[2];
d62a17ae 13201 afi_t afi;
13202 safi_t safi;
d7c0a89a
QY
13203 uint16_t i;
13204 uint8_t *msg;
d62a17ae 13205 json_object *json_neigh = NULL;
13206 time_t epoch_tbuf;
4ab46701 13207 uint32_t sync_tcp_mss;
718e3744 13208
d62a17ae 13209 bgp = p->bgp;
13210
13211 if (use_json)
13212 json_neigh = json_object_new_object();
13213
13214 memset(dn_flag, '\0', sizeof(dn_flag));
13215 if (!p->conf_if && peer_dynamic_neighbor(p))
13216 dn_flag[0] = '*';
13217
13218 if (!use_json) {
13219 if (p->conf_if) /* Configured interface name. */
47e12884
DA
13220 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
13221 &p->su);
d62a17ae 13222 else /* Configured IP address. */
13223 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
13224 p->host);
13225 }
13226
13227 if (use_json) {
13228 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
13229 json_object_string_add(json_neigh, "bgpNeighborAddr",
13230 "none");
13231 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
47e12884
DA
13232 json_object_string_addf(json_neigh, "bgpNeighborAddr",
13233 "%pSU", &p->su);
d62a17ae 13234
44a4d55e 13235 asn_asn2json(json_neigh, "remoteAs", p->as, bgp->asnotation);
d62a17ae 13236
13237 if (p->change_local_as)
44a4d55e
PG
13238 asn_asn2json(json_neigh, "localAs", p->change_local_as,
13239 bgp->asnotation);
d62a17ae 13240 else
44a4d55e
PG
13241 asn_asn2json(json_neigh, "localAs", p->local_as,
13242 bgp->asnotation);
d62a17ae 13243
13244 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
13245 json_object_boolean_true_add(json_neigh,
13246 "localAsNoPrepend");
13247
13248 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
13249 json_object_boolean_true_add(json_neigh,
13250 "localAsReplaceAs");
13251 } else {
44a4d55e
PG
13252 if ((p->as_type == AS_SPECIFIED) ||
13253 (p->as_type == AS_EXTERNAL) ||
13254 (p->as_type == AS_INTERNAL)) {
13255 vty_out(vty, "remote AS ");
13256 vty_out(vty, ASN_FORMAT(bgp->asnotation), &p->as);
13257 vty_out(vty, ", ");
13258 } else
d62a17ae 13259 vty_out(vty, "remote AS Unspecified, ");
44a4d55e
PG
13260 vty_out(vty, "local AS ");
13261 vty_out(vty, ASN_FORMAT(bgp->asnotation),
13262 p->change_local_as ? &p->change_local_as
13263 : &p->local_as);
13264 vty_out(vty, "%s%s, ",
d62a17ae 13265 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
13266 ? " no-prepend"
13267 : "",
13268 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
13269 ? " replace-as"
13270 : "");
13271 }
faa16034
DS
13272 /* peer type internal or confed-internal */
13273 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 13274 if (use_json) {
13275 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13276 json_object_boolean_true_add(
13277 json_neigh, "nbrConfedInternalLink");
13278 else
13279 json_object_boolean_true_add(json_neigh,
13280 "nbrInternalLink");
13281 } else {
13282 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13283 vty_out(vty, "confed-internal link\n");
13284 else
13285 vty_out(vty, "internal link\n");
13286 }
faa16034
DS
13287 /* peer type external or confed-external */
13288 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 13289 if (use_json) {
13290 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13291 json_object_boolean_true_add(
13292 json_neigh, "nbrConfedExternalLink");
13293 else
13294 json_object_boolean_true_add(json_neigh,
13295 "nbrExternalLink");
13296 } else {
13297 if (bgp_confederation_peers_check(bgp, p->as))
13298 vty_out(vty, "confed-external link\n");
13299 else
13300 vty_out(vty, "external link\n");
13301 }
faa16034
DS
13302 } else {
13303 if (use_json)
13304 json_object_boolean_true_add(json_neigh,
13305 "nbrUnspecifiedLink");
13306 else
13307 vty_out(vty, "unspecified link\n");
d62a17ae 13308 }
13309
d864dd9e
EB
13310 /* Roles */
13311 if (use_json) {
13312 json_object_string_add(json_neigh, "localRole",
8f2d6021
EB
13313 bgp_get_name_by_role(p->local_role));
13314 json_object_string_add(json_neigh, "remoteRole",
13315 bgp_get_name_by_role(p->remote_role));
d864dd9e
EB
13316 } else {
13317 vty_out(vty, " Local Role: %s\n",
8f2d6021
EB
13318 bgp_get_name_by_role(p->local_role));
13319 vty_out(vty, " Remote Role: %s\n",
13320 bgp_get_name_by_role(p->remote_role));
d864dd9e
EB
13321 }
13322
13323
d62a17ae 13324 /* Description. */
13325 if (p->desc) {
13326 if (use_json)
13327 json_object_string_add(json_neigh, "nbrDesc", p->desc);
13328 else
13329 vty_out(vty, " Description: %s\n", p->desc);
13330 }
13331
13332 if (p->hostname) {
13333 if (use_json) {
432e7e46
KQ
13334 json_object_string_add(json_neigh, "hostname",
13335 p->hostname);
d62a17ae 13336
13337 if (p->domainname)
13338 json_object_string_add(json_neigh, "domainname",
13339 p->domainname);
13340 } else {
13341 if (p->domainname && (p->domainname[0] != '\0'))
13342 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13343 p->domainname);
13344 else
13345 vty_out(vty, "Hostname: %s\n", p->hostname);
13346 }
432e7e46
KQ
13347 } else {
13348 if (use_json)
13349 json_object_string_add(json_neigh, "hostname",
13350 "Unknown");
d62a17ae 13351 }
13352
13353 /* Peer-group */
13354 if (p->group) {
13355 if (use_json) {
13356 json_object_string_add(json_neigh, "peerGroup",
13357 p->group->name);
13358
13359 if (dn_flag[0]) {
13360 struct prefix prefix, *range = NULL;
13361
0154d8ce
DS
13362 if (sockunion2hostprefix(&(p->su), &prefix))
13363 range = peer_group_lookup_dynamic_neighbor_range(
13364 p->group, &prefix);
d62a17ae 13365
13366 if (range) {
67d7e256 13367 json_object_string_addf(
d62a17ae 13368 json_neigh,
67d7e256
DA
13369 "peerSubnetRangeGroup", "%pFX",
13370 range);
d62a17ae 13371 }
13372 }
13373 } else {
13374 vty_out(vty,
13375 " Member of peer-group %s for session parameters\n",
13376 p->group->name);
13377
13378 if (dn_flag[0]) {
13379 struct prefix prefix, *range = NULL;
13380
0154d8ce
DS
13381 if (sockunion2hostprefix(&(p->su), &prefix))
13382 range = peer_group_lookup_dynamic_neighbor_range(
13383 p->group, &prefix);
d62a17ae 13384
13385 if (range) {
d62a17ae 13386 vty_out(vty,
1b78780b
DL
13387 " Belongs to the subnet range group: %pFX\n",
13388 range);
d62a17ae 13389 }
13390 }
13391 }
13392 }
13393
13394 if (use_json) {
13395 /* Administrative shutdown. */
cb9196e7
DS
13396 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13397 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13398 json_object_boolean_true_add(json_neigh,
13399 "adminShutDown");
13400
13401 /* BGP Version. */
13402 json_object_int_add(json_neigh, "bgpVersion", 4);
c949c771
DA
13403 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
13404 &p->remote_id);
13405 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
13406 &bgp->router_id);
d62a17ae 13407
13408 /* Confederation */
13409 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13410 && bgp_confederation_peers_check(bgp, p->as))
13411 json_object_boolean_true_add(json_neigh,
13412 "nbrCommonAdmin");
13413
13414 /* Status. */
13415 json_object_string_add(
13416 json_neigh, "bgpState",
13417 lookup_msg(bgp_status_msg, p->status, NULL));
13418
feb17238 13419 if (peer_established(p)) {
d62a17ae 13420 time_t uptime;
d62a17ae 13421
083ec940 13422 uptime = monotime(NULL);
d62a17ae 13423 uptime -= p->uptime;
d62a17ae 13424 epoch_tbuf = time(NULL) - uptime;
13425
d3c7efed
DS
13426 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13427 uptime * 1000);
d62a17ae 13428 json_object_string_add(json_neigh, "bgpTimerUpString",
13429 peer_uptime(p->uptime, timebuf,
13430 BGP_UPTIME_LEN, 0,
13431 NULL));
13432 json_object_int_add(json_neigh,
13433 "bgpTimerUpEstablishedEpoch",
13434 epoch_tbuf);
13435 }
13436
13437 else if (p->status == Active) {
13438 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13439 json_object_string_add(json_neigh, "bgpStateIs",
13440 "passive");
13441 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13442 json_object_string_add(json_neigh, "bgpStateIs",
13443 "passiveNSF");
13444 }
13445
13446 /* read timer */
13447 time_t uptime;
a2700b50 13448 struct tm tm;
d62a17ae 13449
083ec940 13450 uptime = monotime(NULL);
d62a17ae 13451 uptime -= p->readtime;
a2700b50
MS
13452 gmtime_r(&uptime, &tm);
13453
d62a17ae 13454 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
13455 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13456 + (tm.tm_hour * 3600000));
d62a17ae 13457
083ec940 13458 uptime = monotime(NULL);
d62a17ae 13459 uptime -= p->last_write;
a2700b50
MS
13460 gmtime_r(&uptime, &tm);
13461
d62a17ae 13462 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
13463 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13464 + (tm.tm_hour * 3600000));
d62a17ae 13465
083ec940 13466 uptime = monotime(NULL);
d62a17ae 13467 uptime -= p->update_time;
a2700b50
MS
13468 gmtime_r(&uptime, &tm);
13469
d62a17ae 13470 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
13471 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13472 + (tm.tm_hour * 3600000));
d62a17ae 13473
13474 /* Configured timer values. */
9b1b9623
TA
13475 json_object_int_add(json_neigh,
13476 "bgpTimerConfiguredHoldTimeMsecs",
e93d5c29
TA
13477 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13478 ? p->holdtime * 1000
13479 : bgp->default_holdtime * 1000);
13480 json_object_int_add(json_neigh,
13481 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13482 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13483 ? p->keepalive * 1000
13484 : bgp->default_keepalive * 1000);
d62a17ae 13485 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13486 p->v_holdtime * 1000);
13487 json_object_int_add(json_neigh,
13488 "bgpTimerKeepAliveIntervalMsecs",
13489 p->v_keepalive * 1000);
d43114f3
DS
13490 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13491 json_object_int_add(json_neigh,
13492 "bgpTimerDelayOpenTimeMsecs",
13493 p->v_delayopen * 1000);
13494 }
13495
4ab46701
AR
13496 /* Configured and Synced tcp-mss value for peer */
13497 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13498 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13499 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13500 p->tcp_mss);
13501 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13502 sync_tcp_mss);
13503 }
13504
d08c0c80
DA
13505 /* Extended Optional Parameters Length for BGP OPEN Message */
13506 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13507 json_object_boolean_true_add(
13508 json_neigh, "extendedOptionalParametersLength");
13509 else
13510 json_object_boolean_false_add(
13511 json_neigh, "extendedOptionalParametersLength");
6e37924b
DA
13512
13513 /* Conditional advertisements */
13514 json_object_int_add(
13515 json_neigh,
13516 "bgpTimerConfiguredConditionalAdvertisementsSec",
13517 bgp->condition_check_period);
5f6eaa9b 13518 if (event_is_scheduled(bgp->t_condition_check))
6e37924b
DA
13519 json_object_int_add(
13520 json_neigh,
13521 "bgpTimerUntilConditionalAdvertisementsSec",
4f830a07 13522 event_timer_remain_second(
6e37924b 13523 bgp->t_condition_check));
d62a17ae 13524 } else {
13525 /* Administrative shutdown. */
cb9196e7
DS
13526 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13527 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13528 vty_out(vty, " Administratively shut down\n");
13529
13530 /* BGP Version. */
13531 vty_out(vty, " BGP version 4");
07380148
DA
13532 vty_out(vty, ", remote router ID %pI4", &p->remote_id);
13533 vty_out(vty, ", local router ID %pI4\n", &bgp->router_id);
d62a17ae 13534
13535 /* Confederation */
13536 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13537 && bgp_confederation_peers_check(bgp, p->as))
13538 vty_out(vty,
13539 " Neighbor under common administration\n");
13540
13541 /* Status. */
13542 vty_out(vty, " BGP state = %s",
13543 lookup_msg(bgp_status_msg, p->status, NULL));
13544
feb17238 13545 if (peer_established(p))
d62a17ae 13546 vty_out(vty, ", up for %8s",
13547 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13548 0, NULL));
13549
13550 else if (p->status == Active) {
13551 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13552 vty_out(vty, " (passive)");
13553 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13554 vty_out(vty, " (NSF passive)");
13555 }
13556 vty_out(vty, "\n");
13557
13558 /* read timer */
13559 vty_out(vty, " Last read %s",
13560 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13561 NULL));
13562 vty_out(vty, ", Last write %s\n",
13563 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13564 NULL));
13565
13566 /* Configured timer values. */
13567 vty_out(vty,
e93d5c29 13568 " Hold time is %d seconds, keepalive interval is %d seconds\n",
d62a17ae 13569 p->v_holdtime, p->v_keepalive);
e93d5c29
TA
13570 vty_out(vty, " Configured hold time is %d seconds",
13571 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13572 ? p->holdtime
13573 : bgp->default_holdtime);
9b1b9623 13574 vty_out(vty, ", keepalive interval is %d seconds\n",
e93d5c29
TA
13575 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13576 ? p->keepalive
13577 : bgp->default_keepalive);
d43114f3
DS
13578 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13579 vty_out(vty,
13580 " Configured DelayOpenTime is %d seconds\n",
13581 p->delayopen);
4ab46701
AR
13582
13583 /* Configured and synced tcp-mss value for peer */
13584 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13585 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13586 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13587 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13588 }
d08c0c80
DA
13589
13590 /* Extended Optional Parameters Length for BGP OPEN Message */
13591 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13592 vty_out(vty,
13593 " Extended Optional Parameters Length is enabled\n");
6e37924b
DA
13594
13595 /* Conditional advertisements */
13596 vty_out(vty,
13597 " Configured conditional advertisements interval is %d seconds\n",
13598 bgp->condition_check_period);
5f6eaa9b 13599 if (event_is_scheduled(bgp->t_condition_check))
6e37924b
DA
13600 vty_out(vty,
13601 " Time until conditional advertisements begin is %lu seconds\n",
4f830a07 13602 event_timer_remain_second(
6e37924b 13603 bgp->t_condition_check));
d62a17ae 13604 }
13605 /* Capability. */
10711563
DA
13606 if (peer_established(p) &&
13607 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13608 if (use_json) {
13609 json_object *json_cap = NULL;
d62a17ae 13610
10711563 13611 json_cap = json_object_new_object();
d62a17ae 13612
10711563
DA
13613 /* AS4 */
13614 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13615 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13616 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13617 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
ef56aee4 13618 json_object_string_add(
10711563 13619 json_cap, "4byteAs",
ef56aee4 13620 "advertisedAndReceived");
10711563
DA
13621 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13622 json_object_string_add(json_cap,
13623 "4byteAs",
13624 "advertised");
13625 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13626 json_object_string_add(json_cap,
13627 "4byteAs",
13628 "received");
13629 }
ef56aee4 13630
10711563
DA
13631 /* Extended Message Support */
13632 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13633 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13634 json_object_string_add(json_cap,
13635 "extendedMessage",
13636 "advertisedAndReceived");
13637 else if (CHECK_FLAG(p->cap,
13638 PEER_CAP_EXTENDED_MESSAGE_ADV))
13639 json_object_string_add(json_cap,
13640 "extendedMessage",
13641 "advertised");
13642 else if (CHECK_FLAG(p->cap,
13643 PEER_CAP_EXTENDED_MESSAGE_RCV))
13644 json_object_string_add(json_cap,
13645 "extendedMessage",
13646 "received");
ef56aee4 13647
10711563
DA
13648 /* AddPath */
13649 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13650 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13651 json_object *json_add = NULL;
13652 const char *print_store;
d62a17ae 13653
10711563 13654 json_add = json_object_new_object();
d62a17ae 13655
10711563
DA
13656 FOREACH_AFI_SAFI (afi, safi) {
13657 json_object *json_sub = NULL;
13658 json_sub = json_object_new_object();
13659 print_store = get_afi_safi_str(
13660 afi, safi, true);
d62a17ae 13661
10711563
DA
13662 if (CHECK_FLAG(
13663 p->af_cap[afi][safi],
13664 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13665 CHECK_FLAG(
13666 p->af_cap[afi][safi],
13667 PEER_CAP_ADDPATH_AF_TX_RCV)) {
05c7a1cc
QY
13668 if (CHECK_FLAG(
13669 p->af_cap[afi]
13670 [safi],
10711563
DA
13671 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13672 CHECK_FLAG(
05c7a1cc
QY
13673 p->af_cap[afi]
13674 [safi],
10711563
DA
13675 PEER_CAP_ADDPATH_AF_TX_RCV))
13676 json_object_boolean_true_add(
13677 json_sub,
13678 "txAdvertisedAndReceived");
13679 else if (
13680 CHECK_FLAG(
13681 p->af_cap[afi]
13682 [safi],
13683 PEER_CAP_ADDPATH_AF_TX_ADV))
13684 json_object_boolean_true_add(
13685 json_sub,
13686 "txAdvertised");
13687 else if (
13688 CHECK_FLAG(
13689 p->af_cap[afi]
13690 [safi],
13691 PEER_CAP_ADDPATH_AF_TX_RCV))
13692 json_object_boolean_true_add(
13693 json_sub,
13694 "txReceived");
13695 }
d62a17ae 13696
10711563
DA
13697 if (CHECK_FLAG(
13698 p->af_cap[afi][safi],
13699 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13700 CHECK_FLAG(
13701 p->af_cap[afi][safi],
13702 PEER_CAP_ADDPATH_AF_RX_RCV)) {
05c7a1cc
QY
13703 if (CHECK_FLAG(
13704 p->af_cap[afi]
13705 [safi],
10711563
DA
13706 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13707 CHECK_FLAG(
13708 p->af_cap[afi]
13709 [safi],
13710 PEER_CAP_ADDPATH_AF_RX_RCV))
13711 json_object_boolean_true_add(
13712 json_sub,
13713 "rxAdvertisedAndReceived");
13714 else if (
13715 CHECK_FLAG(
13716 p->af_cap[afi]
13717 [safi],
13718 PEER_CAP_ADDPATH_AF_RX_ADV))
13719 json_object_boolean_true_add(
13720 json_sub,
13721 "rxAdvertised");
13722 else if (
13723 CHECK_FLAG(
13724 p->af_cap[afi]
13725 [safi],
13726 PEER_CAP_ADDPATH_AF_RX_RCV))
13727 json_object_boolean_true_add(
13728 json_sub,
13729 "rxReceived");
05c7a1cc
QY
13730 }
13731
10711563
DA
13732 if (CHECK_FLAG(
13733 p->af_cap[afi][safi],
13734 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13735 CHECK_FLAG(
13736 p->af_cap[afi][safi],
13737 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13738 CHECK_FLAG(
13739 p->af_cap[afi][safi],
13740 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13741 CHECK_FLAG(
13742 p->af_cap[afi][safi],
13743 PEER_CAP_ADDPATH_AF_RX_RCV))
13744 json_object_object_add(
13745 json_add, print_store,
13746 json_sub);
13747 else
13748 json_object_free(json_sub);
d62a17ae 13749 }
13750
10711563
DA
13751 json_object_object_add(json_cap, "addPath",
13752 json_add);
13753 }
d62a17ae 13754
10711563
DA
13755 /* Dynamic */
13756 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13757 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13758 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13759 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13760 json_object_string_add(
13761 json_cap, "dynamic",
13762 "advertisedAndReceived");
13763 else if (CHECK_FLAG(p->cap,
13764 PEER_CAP_DYNAMIC_ADV))
13765 json_object_string_add(json_cap,
13766 "dynamic",
13767 "advertised");
13768 else if (CHECK_FLAG(p->cap,
13769 PEER_CAP_DYNAMIC_RCV))
13770 json_object_string_add(json_cap,
13771 "dynamic",
13772 "received");
13773 }
d62a17ae 13774
d864dd9e
EB
13775 /* Role */
13776 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13777 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13778 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13779 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13780 json_object_string_add(
13781 json_cap, "role",
13782 "advertisedAndReceived");
13783 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13784 json_object_string_add(json_cap, "role",
13785 "advertised");
13786 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13787 json_object_string_add(json_cap, "role",
13788 "received");
13789 }
13790
10711563
DA
13791 /* Extended nexthop */
13792 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13793 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13794 json_object *json_nxt = NULL;
13795 const char *print_store;
d62a17ae 13796
d62a17ae 13797
10711563
DA
13798 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13799 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13800 json_object_string_add(
13801 json_cap, "extendedNexthop",
13802 "advertisedAndReceived");
13803 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13804 json_object_string_add(
13805 json_cap, "extendedNexthop",
13806 "advertised");
13807 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13808 json_object_string_add(
13809 json_cap, "extendedNexthop",
13810 "received");
d62a17ae 13811
10711563
DA
13812 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13813 json_nxt = json_object_new_object();
d62a17ae 13814
10711563
DA
13815 for (safi = SAFI_UNICAST;
13816 safi < SAFI_MAX; safi++) {
13817 if (CHECK_FLAG(
13818 p->af_cap[AFI_IP]
13819 [safi],
13820 PEER_CAP_ENHE_AF_RCV)) {
13821 print_store =
13822 get_afi_safi_str(
d62a17ae 13823 AFI_IP,
10711563
DA
13824 safi,
13825 true);
13826 json_object_string_add(
13827 json_nxt,
13828 print_store,
13829 "recieved"); /* misspelled for compatibility */
d62a17ae 13830 }
d62a17ae 13831 }
10711563
DA
13832 json_object_object_add(
13833 json_cap,
13834 "extendedNexthopFamililesByPeer",
13835 json_nxt);
d62a17ae 13836 }
10711563 13837 }
d62a17ae 13838
10711563
DA
13839 /* Long-lived Graceful Restart */
13840 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13841 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13842 json_object *json_llgr = NULL;
13843 const char *afi_safi_str;
8606be87 13844
10711563
DA
13845 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13846 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13847 json_object_string_add(
13848 json_cap,
13849 "longLivedGracefulRestart",
13850 "advertisedAndReceived");
13851 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13852 json_object_string_add(
13853 json_cap,
13854 "longLivedGracefulRestart",
13855 "advertised");
13856 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13857 json_object_string_add(
13858 json_cap,
13859 "longLivedGracefulRestart",
13860 "received");
8606be87 13861
10711563
DA
13862 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13863 json_llgr = json_object_new_object();
8606be87 13864
10711563
DA
13865 FOREACH_AFI_SAFI (afi, safi) {
13866 if (CHECK_FLAG(
13867 p->af_cap[afi]
13868 [safi],
13869 PEER_CAP_ENHE_AF_RCV)) {
13870 afi_safi_str =
13871 get_afi_safi_str(
8606be87
DA
13872 afi,
13873 safi,
13874 true);
10711563
DA
13875 json_object_string_add(
13876 json_llgr,
13877 afi_safi_str,
13878 "received");
8606be87 13879 }
8606be87 13880 }
10711563
DA
13881 json_object_object_add(
13882 json_cap,
13883 "longLivedGracefulRestartByPeer",
13884 json_llgr);
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 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13893 (CHECK_FLAG(p->cap,
13894 PEER_CAP_REFRESH_NEW_RCV) ||
13895 CHECK_FLAG(p->cap,
13896 PEER_CAP_REFRESH_OLD_RCV))) {
13897 if (CHECK_FLAG(
13898 p->cap,
13899 PEER_CAP_REFRESH_OLD_RCV) &&
13900 CHECK_FLAG(
13901 p->cap,
13902 PEER_CAP_REFRESH_NEW_RCV))
13903 json_object_string_add(
13904 json_cap,
13905 "routeRefresh",
13906 "advertisedAndReceivedOldNew");
13907 else {
d62a17ae 13908 if (CHECK_FLAG(
13909 p->cap,
10711563 13910 PEER_CAP_REFRESH_OLD_RCV))
d62a17ae 13911 json_object_string_add(
13912 json_cap,
13913 "routeRefresh",
10711563
DA
13914 "advertisedAndReceivedOld");
13915 else
13916 json_object_string_add(
13917 json_cap,
13918 "routeRefresh",
13919 "advertisedAndReceivedNew");
d62a17ae 13920 }
10711563
DA
13921 } else if (CHECK_FLAG(p->cap,
13922 PEER_CAP_REFRESH_ADV))
13923 json_object_string_add(json_cap,
13924 "routeRefresh",
13925 "advertised");
13926 else if (CHECK_FLAG(p->cap,
13927 PEER_CAP_REFRESH_NEW_RCV) ||
13928 CHECK_FLAG(p->cap,
13929 PEER_CAP_REFRESH_OLD_RCV))
13930 json_object_string_add(json_cap,
13931 "routeRefresh",
13932 "received");
13933 }
d62a17ae 13934
10711563
DA
13935 /* Enhanced Route Refresh */
13936 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13937 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13938 if (CHECK_FLAG(p->cap,
13939 PEER_CAP_ENHANCED_RR_ADV) &&
13940 CHECK_FLAG(p->cap,
13941 PEER_CAP_ENHANCED_RR_RCV))
d77114b7 13942 json_object_string_add(
10711563
DA
13943 json_cap,
13944 "enhancedRouteRefresh",
13945 "advertisedAndReceived");
13946 else if (CHECK_FLAG(p->cap,
13947 PEER_CAP_ENHANCED_RR_ADV))
d77114b7 13948 json_object_string_add(
10711563
DA
13949 json_cap,
13950 "enhancedRouteRefresh",
13951 "advertised");
13952 else if (CHECK_FLAG(p->cap,
9af52ccf 13953 PEER_CAP_ENHANCED_RR_RCV))
10711563
DA
13954 json_object_string_add(
13955 json_cap,
13956 "enhancedRouteRefresh",
13957 "received");
13958 }
d77114b7 13959
10711563
DA
13960 /* Multiprotocol Extensions */
13961 json_object *json_multi = NULL;
d77114b7 13962
10711563 13963 json_multi = json_object_new_object();
d77114b7 13964
10711563
DA
13965 FOREACH_AFI_SAFI (afi, safi) {
13966 if (p->afc_adv[afi][safi] ||
13967 p->afc_recv[afi][safi]) {
13968 json_object *json_exten = NULL;
13969 json_exten = json_object_new_object();
13970
13971 if (p->afc_adv[afi][safi] &&
13972 p->afc_recv[afi][safi])
13973 json_object_boolean_true_add(
13974 json_exten,
9af52ccf 13975 "advertisedAndReceived");
10711563
DA
13976 else if (p->afc_adv[afi][safi])
13977 json_object_boolean_true_add(
13978 json_exten,
9af52ccf 13979 "advertised");
10711563
DA
13980 else if (p->afc_recv[afi][safi])
13981 json_object_boolean_true_add(
13982 json_exten, "received");
9af52ccf 13983
10711563
DA
13984 json_object_object_add(
13985 json_multi,
13986 get_afi_safi_str(afi, safi,
13987 true),
13988 json_exten);
13989 }
13990 }
13991 json_object_object_add(json_cap,
13992 "multiprotocolExtensions",
13993 json_multi);
d62a17ae 13994
10711563
DA
13995 /* Hostname capabilities */
13996 json_object *json_hname = NULL;
d62a17ae 13997
10711563 13998 json_hname = json_object_new_object();
d62a17ae 13999
10711563
DA
14000 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14001 json_object_string_add(
14002 json_hname, "advHostName",
14003 bgp->peer_self->hostname
14004 ? bgp->peer_self->hostname
14005 : "n/a");
14006 json_object_string_add(
14007 json_hname, "advDomainName",
14008 bgp->peer_self->domainname
14009 ? bgp->peer_self->domainname
14010 : "n/a");
14011 }
d77114b7 14012
d77114b7 14013
10711563
DA
14014 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14015 json_object_string_add(
14016 json_hname, "rcvHostName",
14017 p->hostname ? p->hostname : "n/a");
14018 json_object_string_add(
14019 json_hname, "rcvDomainName",
14020 p->domainname ? p->domainname : "n/a");
14021 }
d77114b7 14022
10711563
DA
14023 json_object_object_add(json_cap, "hostName",
14024 json_hname);
d77114b7 14025
234f6fd4
DA
14026 /* Software Version capability */
14027 json_object *json_soft_version = NULL;
14028
14029 json_soft_version = json_object_new_object();
14030
14031 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_ADV))
14032 json_object_string_add(
14033 json_soft_version,
14034 "advertisedSoftwareVersion",
14035 cmd_software_version_get());
14036
14037 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_RCV))
14038 json_object_string_add(
14039 json_soft_version,
14040 "receivedSoftwareVersion",
14041 p->soft_version ? p->soft_version
14042 : "n/a");
14043
14044 json_object_object_add(json_cap, "softwareVersion",
14045 json_soft_version);
14046
17be83bf 14047 /* Graceful Restart */
10711563
DA
14048 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14049 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14050 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
14051 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
d77114b7 14052 json_object_string_add(
10711563
DA
14053 json_cap, "gracefulRestart",
14054 "advertisedAndReceived");
14055 else if (CHECK_FLAG(p->cap,
14056 PEER_CAP_RESTART_ADV))
d77114b7 14057 json_object_string_add(
10711563
DA
14058 json_cap,
14059 "gracefulRestartCapability",
14060 "advertised");
14061 else if (CHECK_FLAG(p->cap,
14062 PEER_CAP_RESTART_RCV))
14063 json_object_string_add(
14064 json_cap,
14065 "gracefulRestartCapability",
14066 "received");
d77114b7 14067
10711563
DA
14068 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14069 int restart_af_count = 0;
14070 json_object *json_restart = NULL;
14071 json_restart = json_object_new_object();
d62a17ae 14072
10711563
DA
14073 json_object_int_add(
14074 json_cap,
14075 "gracefulRestartRemoteTimerMsecs",
14076 p->v_gr_restart * 1000);
d62a17ae 14077
10711563 14078 FOREACH_AFI_SAFI (afi, safi) {
05c7a1cc
QY
14079 if (CHECK_FLAG(
14080 p->af_cap[afi]
14081 [safi],
10711563
DA
14082 PEER_CAP_RESTART_AF_RCV)) {
14083 json_object *json_sub =
14084 NULL;
14085 json_sub =
14086 json_object_new_object();
d62a17ae 14087
05c7a1cc
QY
14088 if (CHECK_FLAG(
14089 p->af_cap
14090 [afi]
14091 [safi],
10711563
DA
14092 PEER_CAP_RESTART_AF_PRESERVE_RCV))
14093 json_object_boolean_true_add(
14094 json_sub,
14095 "preserved");
14096 restart_af_count++;
d62a17ae 14097 json_object_object_add(
10711563
DA
14098 json_restart,
14099 get_afi_safi_str(
14100 afi,
14101 safi,
14102 true),
14103 json_sub);
d62a17ae 14104 }
d62a17ae 14105 }
10711563
DA
14106 if (!restart_af_count) {
14107 json_object_string_add(
14108 json_cap,
14109 "addressFamiliesByPeer",
14110 "none");
14111 json_object_free(json_restart);
14112 } else
14113 json_object_object_add(
14114 json_cap,
14115 "addressFamiliesByPeer",
14116 json_restart);
d62a17ae 14117 }
10711563
DA
14118 }
14119 json_object_object_add(
14120 json_neigh, "neighborCapabilities", json_cap);
14121 } else {
14122 vty_out(vty, " Neighbor capabilities:\n");
14123
14124 /* AS4 */
14125 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
14126 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
14127 vty_out(vty, " 4 Byte AS:");
14128 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
14129 vty_out(vty, " advertised");
14130 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
14131 vty_out(vty, " %sreceived",
14132 CHECK_FLAG(p->cap,
14133 PEER_CAP_AS4_ADV)
14134 ? "and "
14135 : "");
14136 vty_out(vty, "\n");
14137 }
d62a17ae 14138
10711563
DA
14139 /* Extended Message Support */
14140 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
14141 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
14142 vty_out(vty, " Extended Message:");
ef56aee4 14143 if (CHECK_FLAG(p->cap,
10711563
DA
14144 PEER_CAP_EXTENDED_MESSAGE_ADV))
14145 vty_out(vty, " advertised");
14146 if (CHECK_FLAG(p->cap,
14147 PEER_CAP_EXTENDED_MESSAGE_RCV))
14148 vty_out(vty, " %sreceived",
14149 CHECK_FLAG(
14150 p->cap,
14151 PEER_CAP_EXTENDED_MESSAGE_ADV)
14152 ? "and "
14153 : "");
14154 vty_out(vty, "\n");
14155 }
d62a17ae 14156
10711563
DA
14157 /* AddPath */
14158 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
14159 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
14160 vty_out(vty, " AddPath:\n");
d62a17ae 14161
10711563 14162 FOREACH_AFI_SAFI (afi, safi) {
ef56aee4 14163 if (CHECK_FLAG(
10711563
DA
14164 p->af_cap[afi][safi],
14165 PEER_CAP_ADDPATH_AF_TX_ADV) ||
14166 CHECK_FLAG(
14167 p->af_cap[afi][safi],
14168 PEER_CAP_ADDPATH_AF_TX_RCV)) {
14169 vty_out(vty, " %s: TX ",
14170 get_afi_safi_str(
14171 afi, safi,
14172 false));
ef56aee4 14173
10711563
DA
14174 if (CHECK_FLAG(
14175 p->af_cap[afi]
14176 [safi],
14177 PEER_CAP_ADDPATH_AF_TX_ADV))
14178 vty_out(vty,
14179 "advertised");
d62a17ae 14180
05c7a1cc
QY
14181 if (CHECK_FLAG(
14182 p->af_cap[afi]
14183 [safi],
10711563 14184 PEER_CAP_ADDPATH_AF_TX_RCV))
05c7a1cc 14185 vty_out(vty,
10711563
DA
14186 "%sreceived",
14187 CHECK_FLAG(
14188 p->af_cap
14189 [afi]
14190 [safi],
14191 PEER_CAP_ADDPATH_AF_TX_ADV)
14192 ? " and "
14193 : "");
05c7a1cc 14194
10711563
DA
14195 vty_out(vty, "\n");
14196 }
d62a17ae 14197
9af52ccf 14198 if (CHECK_FLAG(
10711563
DA
14199 p->af_cap[afi][safi],
14200 PEER_CAP_ADDPATH_AF_RX_ADV) ||
14201 CHECK_FLAG(
14202 p->af_cap[afi][safi],
14203 PEER_CAP_ADDPATH_AF_RX_RCV)) {
14204 vty_out(vty, " %s: RX ",
5cb5f4d0 14205 get_afi_safi_str(
10711563
DA
14206 afi, safi,
14207 false));
d62a17ae 14208
05c7a1cc
QY
14209 if (CHECK_FLAG(
14210 p->af_cap[afi]
14211 [safi],
10711563 14212 PEER_CAP_ADDPATH_AF_RX_ADV))
05c7a1cc 14213 vty_out(vty,
10711563 14214 "advertised");
d62a17ae 14215
10711563
DA
14216 if (CHECK_FLAG(
14217 p->af_cap[afi]
14218 [safi],
14219 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc 14220 vty_out(vty,
10711563
DA
14221 "%sreceived",
14222 CHECK_FLAG(
14223 p->af_cap
14224 [afi]
14225 [safi],
14226 PEER_CAP_ADDPATH_AF_RX_ADV)
14227 ? " and "
05c7a1cc 14228 : "");
d62a17ae 14229
05c7a1cc 14230 vty_out(vty, "\n");
05c7a1cc 14231 }
d62a17ae 14232 }
10711563 14233 }
d62a17ae 14234
10711563
DA
14235 /* Dynamic */
14236 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
14237 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
14238 vty_out(vty, " Dynamic:");
14239 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
14240 vty_out(vty, " advertised");
14241 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
14242 vty_out(vty, " %sreceived",
14243 CHECK_FLAG(p->cap,
14244 PEER_CAP_DYNAMIC_ADV)
14245 ? "and "
14246 : "");
14247 vty_out(vty, "\n");
14248 }
d62a17ae 14249
d864dd9e
EB
14250 /* Role */
14251 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
14252 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
14253 vty_out(vty, " Role:");
14254 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
14255 vty_out(vty, " advertised");
14256 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
14257 vty_out(vty, " %sreceived",
14258 CHECK_FLAG(p->cap,
14259 PEER_CAP_ROLE_ADV)
14260 ? "and "
14261 : "");
14262 vty_out(vty, "\n");
14263 }
14264
10711563
DA
14265 /* Extended nexthop */
14266 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
14267 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
14268 vty_out(vty, " Extended nexthop:");
14269 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
14270 vty_out(vty, " advertised");
14271 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
14272 vty_out(vty, " %sreceived",
14273 CHECK_FLAG(p->cap,
14274 PEER_CAP_ENHE_ADV)
14275 ? "and "
14276 : "");
14277 vty_out(vty, "\n");
d62a17ae 14278
10711563 14279 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
57f7feb6 14280 vty_out(vty,
10711563
DA
14281 " Address families by peer:\n ");
14282 for (safi = SAFI_UNICAST;
14283 safi < SAFI_MAX; safi++)
14284 if (CHECK_FLAG(
14285 p->af_cap[AFI_IP]
14286 [safi],
14287 PEER_CAP_ENHE_AF_RCV))
14288 vty_out(vty,
14289 " %s\n",
14290 get_afi_safi_str(
14291 AFI_IP,
14292 safi,
14293 false));
d62a17ae 14294 }
10711563 14295 }
d62a17ae 14296
10711563
DA
14297 /* Long-lived Graceful Restart */
14298 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
14299 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
14300 vty_out(vty,
14301 " Long-lived Graceful Restart:");
14302 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
14303 vty_out(vty, " advertised");
14304 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
14305 vty_out(vty, " %sreceived",
14306 CHECK_FLAG(p->cap,
14307 PEER_CAP_LLGR_ADV)
14308 ? "and "
14309 : "");
14310 vty_out(vty, "\n");
8606be87 14311
10711563 14312 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
57f7feb6 14313 vty_out(vty,
10711563
DA
14314 " Address families by peer:\n");
14315 FOREACH_AFI_SAFI (afi, safi)
14316 if (CHECK_FLAG(
14317 p->af_cap[afi]
14318 [safi],
14319 PEER_CAP_LLGR_AF_RCV))
14320 vty_out(vty,
14321 " %s\n",
14322 get_afi_safi_str(
14323 afi,
14324 safi,
14325 false));
8606be87 14326 }
10711563 14327 }
8606be87 14328
10711563
DA
14329 /* Route Refresh */
14330 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
14331 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
14332 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
14333 vty_out(vty, " Route refresh:");
14334 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
14335 vty_out(vty, " advertised");
14336 if (CHECK_FLAG(p->cap,
14337 PEER_CAP_REFRESH_NEW_RCV) ||
14338 CHECK_FLAG(p->cap,
14339 PEER_CAP_REFRESH_OLD_RCV))
14340 vty_out(vty, " %sreceived(%s)",
14341 CHECK_FLAG(p->cap,
14342 PEER_CAP_REFRESH_ADV)
14343 ? "and "
14344 : "",
14345 (CHECK_FLAG(
14346 p->cap,
14347 PEER_CAP_REFRESH_OLD_RCV) &&
14348 CHECK_FLAG(
14349 p->cap,
14350 PEER_CAP_REFRESH_NEW_RCV))
14351 ? "old & new"
14352 : CHECK_FLAG(
14353 p->cap,
14354 PEER_CAP_REFRESH_OLD_RCV)
14355 ? "old"
14356 : "new");
d62a17ae 14357
d77114b7 14358 vty_out(vty, "\n");
10711563 14359 }
d62a17ae 14360
10711563
DA
14361 /* Enhanced Route Refresh */
14362 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
14363 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
14364 vty_out(vty, " Enhanced Route Refresh:");
14365 if (CHECK_FLAG(p->cap,
14366 PEER_CAP_ENHANCED_RR_ADV))
14367 vty_out(vty, " advertised");
14368 if (CHECK_FLAG(p->cap,
14369 PEER_CAP_ENHANCED_RR_RCV))
14370 vty_out(vty, " %sreceived",
14371 CHECK_FLAG(p->cap,
14372 PEER_CAP_REFRESH_ADV)
14373 ? "and "
14374 : "");
14375 vty_out(vty, "\n");
14376 }
14377
14378 /* Multiprotocol Extensions */
14379 FOREACH_AFI_SAFI (afi, safi)
14380 if (p->afc_adv[afi][safi] ||
14381 p->afc_recv[afi][safi]) {
14382 vty_out(vty, " Address Family %s:",
14383 get_afi_safi_str(afi, safi,
14384 false));
14385 if (p->afc_adv[afi][safi])
9af52ccf 14386 vty_out(vty, " advertised");
10711563 14387 if (p->afc_recv[afi][safi])
9af52ccf 14388 vty_out(vty, " %sreceived",
10711563 14389 p->afc_adv[afi][safi]
9af52ccf
DA
14390 ? "and "
14391 : "");
14392 vty_out(vty, "\n");
14393 }
14394
10711563
DA
14395 /* Hostname capability */
14396 vty_out(vty, " Hostname Capability:");
d62a17ae 14397
10711563
DA
14398 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14399 vty_out(vty,
14400 " advertised (name: %s,domain name: %s)",
14401 bgp->peer_self->hostname
14402 ? bgp->peer_self->hostname
14403 : "n/a",
14404 bgp->peer_self->domainname
14405 ? bgp->peer_self->domainname
14406 : "n/a");
14407 } else {
14408 vty_out(vty, " not advertised");
14409 }
d77114b7 14410
10711563
DA
14411 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14412 vty_out(vty,
14413 " received (name: %s,domain name: %s)",
14414 p->hostname ? p->hostname : "n/a",
14415 p->domainname ? p->domainname : "n/a");
14416 } else {
14417 vty_out(vty, " not received");
d62a17ae 14418 }
d62a17ae 14419
10711563 14420 vty_out(vty, "\n");
d77114b7 14421
234f6fd4
DA
14422 /* Software Version capability */
14423 vty_out(vty, " Version Capability:");
14424
14425 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_ADV)) {
14426 vty_out(vty,
14427 " advertised software version (%s)",
14428 cmd_software_version_get());
14429 } else
14430 vty_out(vty, " not advertised");
14431
14432 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_RCV)) {
14433 vty_out(vty, " received software version (%s)",
14434 p->soft_version ? p->soft_version
14435 : "n/a");
14436 } else
14437 vty_out(vty, " not received");
14438
14439 vty_out(vty, "\n");
14440
10711563
DA
14441 /* Graceful Restart */
14442 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14443 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14444 vty_out(vty,
14445 " Graceful Restart Capability:");
14446 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
14447 vty_out(vty, " advertised");
14448 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14449 vty_out(vty, " %sreceived",
14450 CHECK_FLAG(p->cap,
14451 PEER_CAP_RESTART_ADV)
14452 ? "and "
14453 : "");
d77114b7
MK
14454 vty_out(vty, "\n");
14455
10711563
DA
14456 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14457 int restart_af_count = 0;
d62a17ae 14458
10711563
DA
14459 vty_out(vty,
14460 " Remote Restart timer is %d seconds\n",
14461 p->v_gr_restart);
14462 vty_out(vty,
14463 " Address families by peer:\n ");
d62a17ae 14464
10711563
DA
14465 FOREACH_AFI_SAFI (afi, safi)
14466 if (CHECK_FLAG(
14467 p->af_cap[afi]
14468 [safi],
14469 PEER_CAP_RESTART_AF_RCV)) {
14470 vty_out(vty, "%s%s(%s)",
14471 restart_af_count
14472 ? ", "
14473 : "",
14474 get_afi_safi_str(
14475 afi,
14476 safi,
14477 false),
14478 CHECK_FLAG(
14479 p->af_cap
14480 [afi]
14481 [safi],
14482 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14483 ? "preserved"
14484 : "not preserved");
14485 restart_af_count++;
14486 }
14487 if (!restart_af_count)
14488 vty_out(vty, "none");
14489 vty_out(vty, "\n");
14490 }
17be83bf 14491 } /* Graceful Restart */
d62a17ae 14492 }
14493 }
14494
14495 /* graceful restart information */
10711563
DA
14496 json_object *json_grace = NULL;
14497 json_object *json_grace_send = NULL;
14498 json_object *json_grace_recv = NULL;
14499 int eor_send_af_count = 0;
14500 int eor_receive_af_count = 0;
d62a17ae 14501
10711563
DA
14502 if (use_json) {
14503 json_grace = json_object_new_object();
14504 json_grace_send = json_object_new_object();
14505 json_grace_recv = json_object_new_object();
14506
14507 if ((peer_established(p)) &&
14508 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14509 FOREACH_AFI_SAFI (afi, safi) {
14510 if (CHECK_FLAG(p->af_sflags[afi][safi],
14511 PEER_STATUS_EOR_SEND)) {
14512 json_object_boolean_true_add(
14513 json_grace_send,
14514 get_afi_safi_str(afi, safi,
14515 true));
14516 eor_send_af_count++;
d62a17ae 14517 }
10711563
DA
14518 }
14519 FOREACH_AFI_SAFI (afi, safi) {
14520 if (CHECK_FLAG(p->af_sflags[afi][safi],
14521 PEER_STATUS_EOR_RECEIVED)) {
14522 json_object_boolean_true_add(
14523 json_grace_recv,
14524 get_afi_safi_str(afi, safi,
14525 true));
14526 eor_receive_af_count++;
d62a17ae 14527 }
14528 }
10711563
DA
14529 }
14530 json_object_object_add(json_grace, "endOfRibSend",
14531 json_grace_send);
14532 json_object_object_add(json_grace, "endOfRibRecv",
14533 json_grace_recv);
d62a17ae 14534
d62a17ae 14535
10711563
DA
14536 if (p->t_gr_restart)
14537 json_object_int_add(
14538 json_grace, "gracefulRestartTimerMsecs",
4f830a07 14539 event_timer_remain_second(p->t_gr_restart) *
10711563 14540 1000);
2986cac2 14541
10711563
DA
14542 if (p->t_gr_stale)
14543 json_object_int_add(
14544 json_grace, "gracefulStalepathTimerMsecs",
4f830a07 14545 event_timer_remain_second(p->t_gr_stale) *
10711563
DA
14546 1000);
14547 /* more gr info in new format */
403e64f8 14548 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json_grace);
10711563
DA
14549 json_object_object_add(json_neigh, "gracefulRestartInfo",
14550 json_grace);
14551 } else {
14552 vty_out(vty, " Graceful restart information:\n");
14553 if ((peer_established(p)) &&
14554 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14555
14556 vty_out(vty, " End-of-RIB send: ");
14557 FOREACH_AFI_SAFI (afi, safi) {
14558 if (CHECK_FLAG(p->af_sflags[afi][safi],
14559 PEER_STATUS_EOR_SEND)) {
14560 vty_out(vty, "%s%s",
14561 eor_send_af_count ? ", " : "",
14562 get_afi_safi_str(afi, safi,
14563 false));
14564 eor_send_af_count++;
d62a17ae 14565 }
10711563
DA
14566 }
14567 vty_out(vty, "\n");
14568 vty_out(vty, " End-of-RIB received: ");
14569 FOREACH_AFI_SAFI (afi, safi) {
14570 if (CHECK_FLAG(p->af_sflags[afi][safi],
14571 PEER_STATUS_EOR_RECEIVED)) {
14572 vty_out(vty, "%s%s",
14573 eor_receive_af_count ? ", "
14574 : "",
14575 get_afi_safi_str(afi, safi,
14576 false));
14577 eor_receive_af_count++;
d62a17ae 14578 }
d62a17ae 14579 }
10711563
DA
14580 vty_out(vty, "\n");
14581 }
d62a17ae 14582
10711563
DA
14583 if (p->t_gr_restart)
14584 vty_out(vty,
14585 " The remaining time of restart timer is %ld\n",
4f830a07 14586 event_timer_remain_second(p->t_gr_restart));
d62a17ae 14587
10711563
DA
14588 if (p->t_gr_stale)
14589 vty_out(vty,
14590 " The remaining time of stalepath timer is %ld\n",
4f830a07 14591 event_timer_remain_second(p->t_gr_stale));
2986cac2 14592
10711563 14593 /* more gr info in new format */
403e64f8 14594 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, NULL);
10711563 14595 }
2986cac2 14596
d62a17ae 14597 if (use_json) {
14598 json_object *json_stat = NULL;
14599 json_stat = json_object_new_object();
14600 /* Packet counts. */
43aa5965
QY
14601
14602 atomic_size_t outq_count, inq_count;
14603 outq_count = atomic_load_explicit(&p->obuf->count,
14604 memory_order_relaxed);
14605 inq_count = atomic_load_explicit(&p->ibuf->count,
14606 memory_order_relaxed);
14607
14608 json_object_int_add(json_stat, "depthInq",
14609 (unsigned long)inq_count);
d62a17ae 14610 json_object_int_add(json_stat, "depthOutq",
43aa5965 14611 (unsigned long)outq_count);
0112e9e0
QY
14612 json_object_int_add(json_stat, "opensSent",
14613 atomic_load_explicit(&p->open_out,
14614 memory_order_relaxed));
14615 json_object_int_add(json_stat, "opensRecv",
14616 atomic_load_explicit(&p->open_in,
14617 memory_order_relaxed));
d62a17ae 14618 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
14619 atomic_load_explicit(&p->notify_out,
14620 memory_order_relaxed));
d62a17ae 14621 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
14622 atomic_load_explicit(&p->notify_in,
14623 memory_order_relaxed));
14624 json_object_int_add(json_stat, "updatesSent",
14625 atomic_load_explicit(&p->update_out,
14626 memory_order_relaxed));
14627 json_object_int_add(json_stat, "updatesRecv",
14628 atomic_load_explicit(&p->update_in,
14629 memory_order_relaxed));
d62a17ae 14630 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
14631 atomic_load_explicit(&p->keepalive_out,
14632 memory_order_relaxed));
d62a17ae 14633 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
14634 atomic_load_explicit(&p->keepalive_in,
14635 memory_order_relaxed));
d62a17ae 14636 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
14637 atomic_load_explicit(&p->refresh_out,
14638 memory_order_relaxed));
d62a17ae 14639 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
14640 atomic_load_explicit(&p->refresh_in,
14641 memory_order_relaxed));
d62a17ae 14642 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
14643 atomic_load_explicit(&p->dynamic_cap_out,
14644 memory_order_relaxed));
d62a17ae 14645 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
14646 atomic_load_explicit(&p->dynamic_cap_in,
14647 memory_order_relaxed));
14648 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14649 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 14650 json_object_object_add(json_neigh, "messageStats", json_stat);
14651 } else {
cb93e0a2
IS
14652 atomic_size_t outq_count, inq_count, open_out, open_in,
14653 notify_out, notify_in, update_out, update_in,
14654 keepalive_out, keepalive_in, refresh_out, refresh_in,
14655 dynamic_cap_out, dynamic_cap_in;
43aa5965
QY
14656 outq_count = atomic_load_explicit(&p->obuf->count,
14657 memory_order_relaxed);
14658 inq_count = atomic_load_explicit(&p->ibuf->count,
14659 memory_order_relaxed);
cb93e0a2
IS
14660 open_out = atomic_load_explicit(&p->open_out,
14661 memory_order_relaxed);
14662 open_in =
14663 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14664 notify_out = atomic_load_explicit(&p->notify_out,
14665 memory_order_relaxed);
14666 notify_in = atomic_load_explicit(&p->notify_in,
14667 memory_order_relaxed);
14668 update_out = atomic_load_explicit(&p->update_out,
14669 memory_order_relaxed);
14670 update_in = atomic_load_explicit(&p->update_in,
14671 memory_order_relaxed);
14672 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14673 memory_order_relaxed);
14674 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14675 memory_order_relaxed);
14676 refresh_out = atomic_load_explicit(&p->refresh_out,
14677 memory_order_relaxed);
14678 refresh_in = atomic_load_explicit(&p->refresh_in,
14679 memory_order_relaxed);
14680 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14681 memory_order_relaxed);
14682 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14683 memory_order_relaxed);
43aa5965 14684
d62a17ae 14685 /* Packet counts. */
14686 vty_out(vty, " Message statistics:\n");
43aa5965
QY
14687 vty_out(vty, " Inq depth is %zu\n", inq_count);
14688 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 14689 vty_out(vty, " Sent Rcvd\n");
cb93e0a2
IS
14690 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14691 open_in);
14692 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14693 notify_in);
14694 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14695 update_in);
14696 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14697 keepalive_in);
14698 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14699 refresh_in);
14700 vty_out(vty, " Capability: %10zu %10zu\n",
14701 dynamic_cap_out, dynamic_cap_in);
14702 vty_out(vty, " Total: %10u %10u\n",
14703 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
d62a17ae 14704 }
14705
14706 if (use_json) {
14707 /* advertisement-interval */
14708 json_object_int_add(json_neigh,
14709 "minBtwnAdvertisementRunsTimerMsecs",
14710 p->v_routeadv * 1000);
14711
14712 /* Update-source. */
14713 if (p->update_if || p->update_source) {
14714 if (p->update_if)
14715 json_object_string_add(json_neigh,
14716 "updateSource",
14717 p->update_if);
14718 else if (p->update_source)
47e12884
DA
14719 json_object_string_addf(json_neigh,
14720 "updateSource", "%pSU",
14721 p->update_source);
d62a17ae 14722 }
14723 } else {
14724 /* advertisement-interval */
14725 vty_out(vty,
14726 " Minimum time between advertisement runs is %d seconds\n",
14727 p->v_routeadv);
14728
14729 /* Update-source. */
14730 if (p->update_if || p->update_source) {
14731 vty_out(vty, " Update source is ");
14732 if (p->update_if)
14733 vty_out(vty, "%s", p->update_if);
14734 else if (p->update_source)
47e12884 14735 vty_out(vty, "%pSU", p->update_source);
d62a17ae 14736 vty_out(vty, "\n");
14737 }
14738
14739 vty_out(vty, "\n");
14740 }
14741
14742 /* Address Family Information */
14743 json_object *json_hold = NULL;
14744
14745 if (use_json)
14746 json_hold = json_object_new_object();
14747
05c7a1cc
QY
14748 FOREACH_AFI_SAFI (afi, safi)
14749 if (p->afc[afi][safi])
14750 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14751 json_hold);
d62a17ae 14752
14753 if (use_json) {
14754 json_object_object_add(json_neigh, "addressFamilyInfo",
14755 json_hold);
14756 json_object_int_add(json_neigh, "connectionsEstablished",
14757 p->established);
14758 json_object_int_add(json_neigh, "connectionsDropped",
14759 p->dropped);
14760 } else
14761 vty_out(vty, " Connections established %d; dropped %d\n",
14762 p->established, p->dropped);
14763
14764 if (!p->last_reset) {
14765 if (use_json)
14766 json_object_string_add(json_neigh, "lastReset",
14767 "never");
14768 else
14769 vty_out(vty, " Last reset never\n");
14770 } else {
14771 if (use_json) {
14772 time_t uptime;
a2700b50 14773 struct tm tm;
d62a17ae 14774
083ec940 14775 uptime = monotime(NULL);
d62a17ae 14776 uptime -= p->resettime;
a2700b50
MS
14777 gmtime_r(&uptime, &tm);
14778
d62a17ae 14779 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
14780 (tm.tm_sec * 1000)
14781 + (tm.tm_min * 60000)
14782 + (tm.tm_hour * 3600000));
3577f1c5 14783 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 14784 } else {
14785 vty_out(vty, " Last reset %s, ",
14786 peer_uptime(p->resettime, timebuf,
14787 BGP_UPTIME_LEN, 0, NULL));
14788
3577f1c5 14789 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 14790 if (p->last_reset_cause_size) {
14791 msg = p->last_reset_cause;
14792 vty_out(vty,
14793 " Message received that caused BGP to send a NOTIFICATION:\n ");
14794 for (i = 1; i <= p->last_reset_cause_size;
14795 i++) {
14796 vty_out(vty, "%02X", *msg++);
14797
14798 if (i != p->last_reset_cause_size) {
14799 if (i % 16 == 0) {
14800 vty_out(vty, "\n ");
14801 } else if (i % 4 == 0) {
14802 vty_out(vty, " ");
14803 }
14804 }
14805 }
14806 vty_out(vty, "\n");
14807 }
14808 }
14809 }
14810
14811 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14812 if (use_json)
14813 json_object_boolean_true_add(json_neigh,
14814 "prefixesConfigExceedMax");
14815 else
14816 vty_out(vty,
14817 " Peer had exceeded the max. no. of prefixes configured.\n");
14818
14819 if (p->t_pmax_restart) {
14820 if (use_json) {
14821 json_object_boolean_true_add(
14822 json_neigh, "reducePrefixNumFrom");
14823 json_object_int_add(json_neigh,
14824 "restartInTimerMsec",
4f830a07
DS
14825 event_timer_remain_second(
14826 p->t_pmax_restart) *
14827 1000);
d62a17ae 14828 } else
14829 vty_out(vty,
14830 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
4f830a07
DS
14831 p->host,
14832 event_timer_remain_second(
14833 p->t_pmax_restart));
d62a17ae 14834 } else {
14835 if (use_json)
14836 json_object_boolean_true_add(
14837 json_neigh,
14838 "reducePrefixNumAndClearIpBgp");
14839 else
14840 vty_out(vty,
14841 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14842 p->host);
14843 }
14844 }
14845
14846 /* EBGP Multihop and GTSM */
14847 if (p->sort != BGP_PEER_IBGP) {
14848 if (use_json) {
e2521429 14849 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14850 json_object_int_add(json_neigh,
14851 "externalBgpNbrMaxHopsAway",
14852 p->gtsm_hops);
be8d1733 14853 else
d62a17ae 14854 json_object_int_add(json_neigh,
14855 "externalBgpNbrMaxHopsAway",
14856 p->ttl);
14857 } else {
e2521429 14858 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14859 vty_out(vty,
14860 " External BGP neighbor may be up to %d hops away.\n",
14861 p->gtsm_hops);
be8d1733 14862 else
d62a17ae 14863 vty_out(vty,
14864 " External BGP neighbor may be up to %d hops away.\n",
14865 p->ttl);
14866 }
14867 } else {
be8d1733
DA
14868 if (use_json) {
14869 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14870 json_object_int_add(json_neigh,
14871 "internalBgpNbrMaxHopsAway",
14872 p->gtsm_hops);
14873 else
be8d1733
DA
14874 json_object_int_add(json_neigh,
14875 "internalBgpNbrMaxHopsAway",
14876 p->ttl);
14877 } else {
14878 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14879 vty_out(vty,
14880 " Internal BGP neighbor may be up to %d hops away.\n",
14881 p->gtsm_hops);
be8d1733
DA
14882 else
14883 vty_out(vty,
14884 " Internal BGP neighbor may be up to %d hops away.\n",
14885 p->ttl);
d62a17ae 14886 }
14887 }
14888
14889 /* Local address. */
14890 if (p->su_local) {
14891 if (use_json) {
47e12884
DA
14892 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14893 p->su_local);
d62a17ae 14894 json_object_int_add(json_neigh, "portLocal",
14895 ntohs(p->su_local->sin.sin_port));
14896 } else
47e12884
DA
14897 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14898 p->su_local, ntohs(p->su_local->sin.sin_port));
1e592331
DS
14899 } else {
14900 if (use_json) {
14901 json_object_string_add(json_neigh, "hostLocal",
14902 "Unknown");
14903 json_object_int_add(json_neigh, "portLocal", -1);
14904 }
d62a17ae 14905 }
14906
14907 /* Remote address. */
14908 if (p->su_remote) {
14909 if (use_json) {
47e12884
DA
14910 json_object_string_addf(json_neigh, "hostForeign",
14911 "%pSU", p->su_remote);
d62a17ae 14912 json_object_int_add(json_neigh, "portForeign",
14913 ntohs(p->su_remote->sin.sin_port));
14914 } else
47e12884
DA
14915 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14916 p->su_remote,
d62a17ae 14917 ntohs(p->su_remote->sin.sin_port));
1e592331
DS
14918 } else {
14919 if (use_json) {
14920 json_object_string_add(json_neigh, "hostForeign",
14921 "Unknown");
14922 json_object_int_add(json_neigh, "portForeign", -1);
14923 }
d62a17ae 14924 }
14925
14926 /* Nexthop display. */
14927 if (p->su_local) {
14928 if (use_json) {
c949c771
DA
14929 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14930 &p->nexthop.v4);
14931 json_object_string_addf(json_neigh, "nexthopGlobal",
14932 "%pI6", &p->nexthop.v6_global);
14933 json_object_string_addf(json_neigh, "nexthopLocal",
14934 "%pI6", &p->nexthop.v6_local);
d62a17ae 14935 if (p->shared_network)
14936 json_object_string_add(json_neigh,
14937 "bgpConnection",
14938 "sharedNetwork");
14939 else
14940 json_object_string_add(json_neigh,
14941 "bgpConnection",
14942 "nonSharedNetwork");
14943 } else {
07380148
DA
14944 vty_out(vty, "Nexthop: %pI4\n", &p->nexthop.v4);
14945 vty_out(vty, "Nexthop global: %pI6\n",
14946 &p->nexthop.v6_global);
14947 vty_out(vty, "Nexthop local: %pI6\n",
14948 &p->nexthop.v6_local);
d62a17ae 14949 vty_out(vty, "BGP connection: %s\n",
14950 p->shared_network ? "shared network"
14951 : "non shared network");
14952 }
432e7e46
KQ
14953 } else {
14954 if (use_json) {
14955 json_object_string_add(json_neigh, "nexthop",
14956 "Unknown");
14957 json_object_string_add(json_neigh, "nexthopGlobal",
14958 "Unknown");
14959 json_object_string_add(json_neigh, "nexthopLocal",
14960 "Unknown");
14961 json_object_string_add(json_neigh, "bgpConnection",
14962 "Unknown");
14963 }
d62a17ae 14964 }
14965
14966 /* Timer information. */
14967 if (use_json) {
14968 json_object_int_add(json_neigh, "connectRetryTimer",
14969 p->v_connect);
f41255a0 14970 if (peer_established(p)) {
d62a17ae 14971 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14972 p->rtt);
f41255a0
DA
14973 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) {
14974 json_object_int_add(json_neigh,
14975 "shutdownRttInMsecs",
14976 p->rtt_expected);
14977 json_object_int_add(json_neigh,
14978 "shutdownRttAfterCount",
14979 p->rtt_keepalive_rcv);
14980 }
14981 }
d62a17ae 14982 if (p->t_start)
14983 json_object_int_add(
14984 json_neigh, "nextStartTimerDueInMsecs",
4f830a07 14985 event_timer_remain_second(p->t_start) * 1000);
d62a17ae 14986 if (p->t_connect)
14987 json_object_int_add(
14988 json_neigh, "nextConnectTimerDueInMsecs",
4f830a07 14989 event_timer_remain_second(p->t_connect) * 1000);
d62a17ae 14990 if (p->t_routeadv) {
14991 json_object_int_add(json_neigh, "mraiInterval",
14992 p->v_routeadv);
14993 json_object_int_add(
14994 json_neigh, "mraiTimerExpireInMsecs",
4f830a07
DS
14995 event_timer_remain_second(p->t_routeadv) *
14996 1000);
d62a17ae 14997 }
14998 if (p->password)
14999 json_object_int_add(json_neigh, "authenticationEnabled",
15000 1);
15001
15002 if (p->t_read)
15003 json_object_string_add(json_neigh, "readThread", "on");
15004 else
15005 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
15006
15007 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 15008 json_object_string_add(json_neigh, "writeThread", "on");
15009 else
15010 json_object_string_add(json_neigh, "writeThread",
15011 "off");
15012 } else {
15013 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
15014 p->v_connect);
f41255a0 15015 if (peer_established(p)) {
d62a17ae 15016 vty_out(vty, "Estimated round trip time: %d ms\n",
15017 p->rtt);
f41255a0
DA
15018 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN))
15019 vty_out(vty,
15020 "Shutdown when RTT > %dms, count > %u\n",
15021 p->rtt_expected, p->rtt_keepalive_rcv);
15022 }
d62a17ae 15023 if (p->t_start)
15024 vty_out(vty, "Next start timer due in %ld seconds\n",
4f830a07 15025 event_timer_remain_second(p->t_start));
d62a17ae 15026 if (p->t_connect)
15027 vty_out(vty, "Next connect timer due in %ld seconds\n",
4f830a07 15028 event_timer_remain_second(p->t_connect));
d62a17ae 15029 if (p->t_routeadv)
15030 vty_out(vty,
15031 "MRAI (interval %u) timer expires in %ld seconds\n",
15032 p->v_routeadv,
4f830a07 15033 event_timer_remain_second(p->t_routeadv));
d62a17ae 15034 if (p->password)
15035 vty_out(vty, "Peer Authentication Enabled\n");
15036
cac9e917 15037 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
15038 p->t_read ? "on" : "off",
15039 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
15040 ? "on"
cac9e917 15041 : "off", p->fd);
d62a17ae 15042 }
15043
15044 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
15045 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
15046 bgp_capability_vty_out(vty, p, use_json, json_neigh);
15047
15048 if (!use_json)
15049 vty_out(vty, "\n");
15050
15051 /* BFD information. */
21bfce98
RZ
15052 if (p->bfd_config)
15053 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 15054
15055 if (use_json) {
15056 if (p->conf_if) /* Configured interface name. */
15057 json_object_object_add(json, p->conf_if, json_neigh);
15058 else /* Configured IP address. */
15059 json_object_object_add(json, p->host, json_neigh);
15060 }
15061}
15062
36235319
QY
15063static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
15064 enum show_type type,
15065 union sockunion *su,
15066 const char *conf_if, afi_t afi,
403e64f8 15067 json_object *json)
2986cac2 15068{
15069 struct listnode *node, *nnode;
15070 struct peer *peer;
5a59e9b2 15071 bool found = false;
2986cac2 15072 safi_t safi = SAFI_UNICAST;
15073 json_object *json_neighbor = NULL;
15074
15075 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15076
15077 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15078 continue;
15079
15080 if ((peer->afc[afi][safi]) == 0)
15081 continue;
15082
403e64f8
DA
15083 if (json)
15084 json_neighbor = json_object_new_object();
15085
2ba1fe69 15086 if (type == show_all) {
403e64f8 15087 bgp_show_peer_gr_status(vty, peer, json_neighbor);
2986cac2 15088
403e64f8 15089 if (json)
13909c4f
DS
15090 json_object_object_add(json, peer->host,
15091 json_neighbor);
2986cac2 15092
2ba1fe69 15093 } else if (type == show_peer) {
2986cac2 15094 if (conf_if) {
15095 if ((peer->conf_if
13909c4f
DS
15096 && !strcmp(peer->conf_if, conf_if))
15097 || (peer->hostname
2986cac2 15098 && !strcmp(peer->hostname, conf_if))) {
5a59e9b2 15099 found = true;
13909c4f 15100 bgp_show_peer_gr_status(vty, peer,
13909c4f 15101 json_neighbor);
2986cac2 15102 }
15103 } else {
15104 if (sockunion_same(&peer->su, su)) {
5a59e9b2 15105 found = true;
13909c4f 15106 bgp_show_peer_gr_status(vty, peer,
13909c4f 15107 json_neighbor);
2986cac2 15108 }
15109 }
5a59e9b2
DS
15110 if (json) {
15111 if (found)
15112 json_object_object_add(json, peer->host,
15113 json_neighbor);
15114 else
15115 json_object_free(json_neighbor);
15116 }
2986cac2 15117 }
15118
5a59e9b2 15119 if (found)
2986cac2 15120 break;
15121 }
15122
5a59e9b2 15123 if (type == show_peer && !found) {
403e64f8 15124 if (json)
13909c4f 15125 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 15126 else
15127 vty_out(vty, "%% No such neighbor\n");
15128 }
403e64f8
DA
15129
15130 if (!json)
2986cac2 15131 vty_out(vty, "\n");
2986cac2 15132
15133 return CMD_SUCCESS;
15134}
15135
d62a17ae 15136static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
15137 enum show_type type, union sockunion *su,
9f049418 15138 const char *conf_if, bool use_json,
d62a17ae 15139 json_object *json)
15140{
15141 struct listnode *node, *nnode;
15142 struct peer *peer;
15143 int find = 0;
9f049418 15144 bool nbr_output = false;
d1927ebe
AS
15145 afi_t afi = AFI_MAX;
15146 safi_t safi = SAFI_MAX;
15147
15148 if (type == show_ipv4_peer || type == show_ipv4_all) {
15149 afi = AFI_IP;
15150 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
15151 afi = AFI_IP6;
15152 }
d62a17ae 15153
15154 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15155 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15156 continue;
15157
15158 switch (type) {
15159 case show_all:
15160 bgp_show_peer(vty, peer, use_json, json);
9f049418 15161 nbr_output = true;
d62a17ae 15162 break;
15163 case show_peer:
15164 if (conf_if) {
15165 if ((peer->conf_if
15166 && !strcmp(peer->conf_if, conf_if))
15167 || (peer->hostname
15168 && !strcmp(peer->hostname, conf_if))) {
15169 find = 1;
15170 bgp_show_peer(vty, peer, use_json,
15171 json);
15172 }
15173 } else {
15174 if (sockunion_same(&peer->su, su)) {
15175 find = 1;
15176 bgp_show_peer(vty, peer, use_json,
15177 json);
15178 }
15179 }
15180 break;
d1927ebe
AS
15181 case show_ipv4_peer:
15182 case show_ipv6_peer:
15183 FOREACH_SAFI (safi) {
15184 if (peer->afc[afi][safi]) {
15185 if (conf_if) {
15186 if ((peer->conf_if
15187 && !strcmp(peer->conf_if, conf_if))
15188 || (peer->hostname
15189 && !strcmp(peer->hostname, conf_if))) {
15190 find = 1;
15191 bgp_show_peer(vty, peer, use_json,
15192 json);
15193 break;
15194 }
15195 } else {
15196 if (sockunion_same(&peer->su, su)) {
15197 find = 1;
15198 bgp_show_peer(vty, peer, use_json,
15199 json);
15200 break;
15201 }
15202 }
15203 }
15204 }
15205 break;
15206 case show_ipv4_all:
15207 case show_ipv6_all:
15208 FOREACH_SAFI (safi) {
15209 if (peer->afc[afi][safi]) {
15210 bgp_show_peer(vty, peer, use_json, json);
15211 nbr_output = true;
15212 break;
15213 }
15214 }
15215 break;
d62a17ae 15216 }
15217 }
15218
d1927ebe
AS
15219 if ((type == show_peer || type == show_ipv4_peer ||
15220 type == show_ipv6_peer) && !find) {
d62a17ae 15221 if (use_json)
15222 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
15223 else
88b7d255 15224 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 15225 }
15226
d1927ebe
AS
15227 if (type != show_peer && type != show_ipv4_peer &&
15228 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 15229 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 15230
d62a17ae 15231 if (use_json) {
996c9314
LB
15232 vty_out(vty, "%s\n", json_object_to_json_string_ext(
15233 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 15234 } else {
15235 vty_out(vty, "\n");
15236 }
15237
15238 return CMD_SUCCESS;
15239}
15240
36235319
QY
15241static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
15242 enum show_type type,
15243 const char *ip_str,
403e64f8 15244 afi_t afi, json_object *json)
2986cac2 15245{
15246
15247 int ret;
15248 struct bgp *bgp;
15249 union sockunion su;
2986cac2 15250
15251 bgp = bgp_get_default();
15252
13909c4f
DS
15253 if (!bgp)
15254 return;
2986cac2 15255
403e64f8
DA
15256 if (!json)
15257 bgp_show_global_graceful_restart_mode_vty(vty, bgp);
2986cac2 15258
13909c4f
DS
15259 if (ip_str) {
15260 ret = str2sockunion(ip_str, &su);
15261 if (ret < 0)
403e64f8
DA
15262 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
15263 ip_str, afi, json);
74a630b6
NT
15264 else
15265 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
403e64f8 15266 NULL, afi, json);
13909c4f
DS
15267 } else
15268 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
403e64f8 15269 afi, json);
2986cac2 15270}
15271
d62a17ae 15272static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
15273 enum show_type type,
15274 const char *ip_str,
9f049418 15275 bool use_json)
d62a17ae 15276{
0291c246
MK
15277 struct listnode *node, *nnode;
15278 struct bgp *bgp;
71aedaa3 15279 union sockunion su;
0291c246 15280 json_object *json = NULL;
71aedaa3 15281 int ret, is_first = 1;
9f049418 15282 bool nbr_output = false;
d62a17ae 15283
15284 if (use_json)
15285 vty_out(vty, "{\n");
15286
15287 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 15288 nbr_output = true;
d62a17ae 15289 if (use_json) {
15290 if (!(json = json_object_new_object())) {
af4c2728 15291 flog_err(
e50f7cfd 15292 EC_BGP_JSON_MEM_ERROR,
d62a17ae 15293 "Unable to allocate memory for JSON object");
15294 vty_out(vty,
15295 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
15296 return;
15297 }
15298
15299 json_object_int_add(json, "vrfId",
15300 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
15301 ? -1
15302 : (int64_t)bgp->vrf_id);
d62a17ae 15303 json_object_string_add(
15304 json, "vrfName",
15305 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15306 ? VRF_DEFAULT_NAME
d62a17ae 15307 : bgp->name);
15308
15309 if (!is_first)
15310 vty_out(vty, ",\n");
15311 else
15312 is_first = 0;
15313
15314 vty_out(vty, "\"%s\":",
15315 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15316 ? VRF_DEFAULT_NAME
d62a17ae 15317 : bgp->name);
15318 } else {
15319 vty_out(vty, "\nInstance %s:\n",
15320 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15321 ? VRF_DEFAULT_NAME
d62a17ae 15322 : bgp->name);
15323 }
71aedaa3 15324
d1927ebe
AS
15325 if (type == show_peer || type == show_ipv4_peer ||
15326 type == show_ipv6_peer) {
71aedaa3
DS
15327 ret = str2sockunion(ip_str, &su);
15328 if (ret < 0)
15329 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15330 use_json, json);
15331 else
15332 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15333 use_json, json);
15334 } else {
d1927ebe 15335 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
15336 use_json, json);
15337 }
b77004d6 15338 json_object_free(json);
121067e9 15339 json = NULL;
d62a17ae 15340 }
15341
3e78a6ce 15342 if (use_json)
d62a17ae 15343 vty_out(vty, "}\n");
9f049418
DS
15344 else if (!nbr_output)
15345 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 15346}
15347
15348static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
15349 enum show_type type, const char *ip_str,
9f049418 15350 bool use_json)
d62a17ae 15351{
15352 int ret;
15353 struct bgp *bgp;
15354 union sockunion su;
15355 json_object *json = NULL;
15356
15357 if (name) {
15358 if (strmatch(name, "all")) {
71aedaa3
DS
15359 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
15360 use_json);
d62a17ae 15361 return CMD_SUCCESS;
15362 } else {
15363 bgp = bgp_lookup_by_name(name);
15364 if (!bgp) {
15365 if (use_json) {
15366 json = json_object_new_object();
75eeda93 15367 vty_json(vty, json);
d62a17ae 15368 } else
15369 vty_out(vty,
9f049418 15370 "%% BGP instance not found\n");
d62a17ae 15371
15372 return CMD_WARNING;
15373 }
15374 }
15375 } else {
15376 bgp = bgp_get_default();
15377 }
15378
15379 if (bgp) {
15380 json = json_object_new_object();
15381 if (ip_str) {
15382 ret = str2sockunion(ip_str, &su);
15383 if (ret < 0)
15384 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15385 use_json, json);
15386 else
15387 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15388 use_json, json);
15389 } else {
15390 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15391 json);
15392 }
15393 json_object_free(json);
ca61fd25
DS
15394 } else {
15395 if (use_json)
15396 vty_out(vty, "{}\n");
15397 else
15398 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 15399 }
15400
15401 return CMD_SUCCESS;
4fb25c53
DW
15402}
15403
2986cac2 15404
15405
15406/* "show [ip] bgp neighbors graceful-restart" commands. */
dcab9012 15407DEFUN (show_ip_bgp_neighbors_graceful_restart,
2986cac2 15408 show_ip_bgp_neighbors_graceful_restart_cmd,
15409 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15410 SHOW_STR
15411 BGP_STR
15412 IP_STR
15413 IPV6_STR
15414 NEIGHBOR_STR
15415 "Neighbor to display information about\n"
15416 "Neighbor to display information about\n"
15417 "Neighbor on BGP configured interface\n"
15418 GR_SHOW
15419 JSON_STR)
15420{
15421 char *sh_arg = NULL;
15422 enum show_type sh_type;
15423 int idx = 0;
15424 afi_t afi = AFI_MAX;
2986cac2 15425 bool uj = use_json(argc, argv);
15426
36235319 15427 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 15428 afi = AFI_MAX;
15429
15430 idx++;
15431
15432 if (argv_find(argv, argc, "A.B.C.D", &idx)
15433 || argv_find(argv, argc, "X:X::X:X", &idx)
15434 || argv_find(argv, argc, "WORD", &idx)) {
15435 sh_type = show_peer;
15436 sh_arg = argv[idx]->arg;
15437 } else
15438 sh_type = show_all;
15439
15440 if (!argv_find(argv, argc, "graceful-restart", &idx))
15441 return CMD_SUCCESS;
15442
15443
36235319
QY
15444 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15445 afi, uj);
2986cac2 15446}
15447
716b2d8a 15448/* "show [ip] bgp neighbors" commands. */
718e3744 15449DEFUN (show_ip_bgp_neighbors,
15450 show_ip_bgp_neighbors_cmd,
24345e82 15451 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 15452 SHOW_STR
15453 IP_STR
15454 BGP_STR
f2a8972b 15455 BGP_INSTANCE_HELP_STR
00e6edb9
DA
15456 BGP_AF_STR
15457 BGP_AF_STR
718e3744 15458 "Detailed information on TCP and BGP neighbor connections\n"
15459 "Neighbor to display information about\n"
a80beece 15460 "Neighbor to display information about\n"
91d37724 15461 "Neighbor on BGP configured interface\n"
9973d184 15462 JSON_STR)
718e3744 15463{
d62a17ae 15464 char *vrf = NULL;
15465 char *sh_arg = NULL;
15466 enum show_type sh_type;
d1927ebe 15467 afi_t afi = AFI_MAX;
718e3744 15468
9f049418 15469 bool uj = use_json(argc, argv);
718e3744 15470
d62a17ae 15471 int idx = 0;
718e3744 15472
9a8bdf1c
PG
15473 /* [<vrf> VIEWVRFNAME] */
15474 if (argv_find(argv, argc, "vrf", &idx)) {
15475 vrf = argv[idx + 1]->arg;
15476 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15477 vrf = NULL;
15478 } else if (argv_find(argv, argc, "view", &idx))
15479 /* [<view> VIEWVRFNAME] */
d62a17ae 15480 vrf = argv[idx + 1]->arg;
718e3744 15481
d62a17ae 15482 idx++;
d1927ebe
AS
15483
15484 if (argv_find(argv, argc, "ipv4", &idx)) {
15485 sh_type = show_ipv4_all;
15486 afi = AFI_IP;
15487 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15488 sh_type = show_ipv6_all;
15489 afi = AFI_IP6;
15490 } else {
15491 sh_type = show_all;
15492 }
15493
d62a17ae 15494 if (argv_find(argv, argc, "A.B.C.D", &idx)
15495 || argv_find(argv, argc, "X:X::X:X", &idx)
15496 || argv_find(argv, argc, "WORD", &idx)) {
15497 sh_type = show_peer;
15498 sh_arg = argv[idx]->arg;
d1927ebe
AS
15499 }
15500
15501 if (sh_type == show_peer && afi == AFI_IP) {
15502 sh_type = show_ipv4_peer;
15503 } else if (sh_type == show_peer && afi == AFI_IP6) {
15504 sh_type = show_ipv6_peer;
15505 }
856ca177 15506
d62a17ae 15507 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 15508}
15509
716b2d8a 15510/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 15511 paths' and `show ip mbgp paths'. Those functions results are the
15512 same.*/
f412b39a 15513DEFUN (show_ip_bgp_paths,
718e3744 15514 show_ip_bgp_paths_cmd,
46f296b4 15515 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 15516 SHOW_STR
15517 IP_STR
15518 BGP_STR
46f296b4 15519 BGP_SAFI_HELP_STR
718e3744 15520 "Path information\n")
15521{
d62a17ae 15522 vty_out(vty, "Address Refcnt Path\n");
15523 aspath_print_all_vty(vty);
15524 return CMD_SUCCESS;
718e3744 15525}
15526
718e3744 15527#include "hash.h"
15528
e3b78da8 15529static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15530 struct vty *vty)
718e3744 15531{
d62a17ae 15532 struct community *com;
718e3744 15533
e3b78da8 15534 com = (struct community *)bucket->data;
3f65c5b1 15535 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
c0945b78 15536 community_str(com, false, false));
718e3744 15537}
15538
15539/* Show BGP's community internal data. */
f412b39a 15540DEFUN (show_ip_bgp_community_info,
718e3744 15541 show_ip_bgp_community_info_cmd,
bec37ba5 15542 "show [ip] bgp community-info",
718e3744 15543 SHOW_STR
15544 IP_STR
15545 BGP_STR
15546 "List all bgp community information\n")
15547{
d62a17ae 15548 vty_out(vty, "Address Refcnt Community\n");
718e3744 15549
d62a17ae 15550 hash_iterate(community_hash(),
e3b78da8 15551 (void (*)(struct hash_bucket *,
d62a17ae 15552 void *))community_show_all_iterator,
15553 vty);
718e3744 15554
d62a17ae 15555 return CMD_SUCCESS;
718e3744 15556}
15557
e3b78da8 15558static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15559 struct vty *vty)
57d187bc 15560{
d62a17ae 15561 struct lcommunity *lcom;
57d187bc 15562
e3b78da8 15563 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 15564 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
c0945b78 15565 lcommunity_str(lcom, false, false));
57d187bc
JS
15566}
15567
15568/* Show BGP's community internal data. */
15569DEFUN (show_ip_bgp_lcommunity_info,
15570 show_ip_bgp_lcommunity_info_cmd,
15571 "show ip bgp large-community-info",
15572 SHOW_STR
15573 IP_STR
15574 BGP_STR
15575 "List all bgp large-community information\n")
15576{
d62a17ae 15577 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 15578
d62a17ae 15579 hash_iterate(lcommunity_hash(),
e3b78da8 15580 (void (*)(struct hash_bucket *,
d62a17ae 15581 void *))lcommunity_show_all_iterator,
15582 vty);
57d187bc 15583
d62a17ae 15584 return CMD_SUCCESS;
57d187bc 15585}
2986cac2 15586/* Graceful Restart */
15587
15588static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
403e64f8 15589 struct bgp *bgp)
2986cac2 15590{
57d187bc
JS
15591
15592
2986cac2 15593 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15594
7318ae88 15595 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 15596
15597 switch (bgp_global_gr_mode) {
15598
15599 case GLOBAL_HELPER:
13909c4f 15600 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 15601 break;
15602
15603 case GLOBAL_GR:
13909c4f 15604 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 15605 break;
15606
15607 case GLOBAL_DISABLE:
13909c4f 15608 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 15609 break;
15610
15611 case GLOBAL_INVALID:
2986cac2 15612 vty_out(vty,
2ba1fe69 15613 "Global BGP GR Mode Invalid\n");
2986cac2 15614 break;
15615 }
15616 vty_out(vty, "\n");
15617}
15618
36235319
QY
15619static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15620 enum show_type type,
15621 const char *ip_str,
15622 afi_t afi, bool use_json)
2986cac2 15623{
403e64f8
DA
15624 json_object *json = NULL;
15625
15626 if (use_json)
15627 json = json_object_new_object();
15628
2986cac2 15629 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15630 afi = AFI_IP;
15631
15632 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15633
36235319 15634 bgp_show_neighbor_graceful_restart_vty(
403e64f8 15635 vty, type, ip_str, afi, json);
2986cac2 15636 afi++;
15637 }
15638 } else if (afi != AFI_MAX) {
36235319 15639 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
403e64f8 15640 json);
2986cac2 15641 } else {
403e64f8
DA
15642 if (json)
15643 json_object_free(json);
2986cac2 15644 return CMD_ERR_INCOMPLETE;
15645 }
15646
403e64f8
DA
15647 if (json)
15648 vty_json(vty, json);
15649
2986cac2 15650 return CMD_SUCCESS;
15651}
15652/* Graceful Restart */
15653
f412b39a 15654DEFUN (show_ip_bgp_attr_info,
718e3744 15655 show_ip_bgp_attr_info_cmd,
bec37ba5 15656 "show [ip] bgp attribute-info",
718e3744 15657 SHOW_STR
15658 IP_STR
15659 BGP_STR
15660 "List all bgp attribute information\n")
15661{
d62a17ae 15662 attr_show_all(vty);
15663 return CMD_SUCCESS;
718e3744 15664}
6b0655a2 15665
03915806
CS
15666static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15667 afi_t afi, safi_t safi,
15668 bool use_json, json_object *json)
53089bec 15669{
15670 struct bgp *bgp;
15671 struct listnode *node;
15672 char *vname;
53089bec 15673 char *ecom_str;
9c2fd3fe 15674 enum vpn_policy_direction dir;
53089bec 15675
03915806 15676 if (json) {
b46dfd20
DS
15677 json_object *json_import_vrfs = NULL;
15678 json_object *json_export_vrfs = NULL;
15679
b46dfd20
DS
15680 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15681
53089bec 15682 if (!bgp) {
75eeda93 15683 vty_json(vty, json);
b46dfd20 15684
53089bec 15685 return CMD_WARNING;
15686 }
b46dfd20 15687
94d4c685
DS
15688 /* Provide context for the block */
15689 json_object_string_add(json, "vrf", name ? name : "default");
15690 json_object_string_add(json, "afiSafi",
5cb5f4d0 15691 get_afi_safi_str(afi, safi, true));
94d4c685 15692
b46dfd20
DS
15693 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15694 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15695 json_object_string_add(json, "importFromVrfs", "none");
15696 json_object_string_add(json, "importRts", "none");
15697 } else {
6ce24e52
DS
15698 json_import_vrfs = json_object_new_array();
15699
b46dfd20
DS
15700 for (ALL_LIST_ELEMENTS_RO(
15701 bgp->vpn_policy[afi].import_vrf,
15702 node, vname))
15703 json_object_array_add(json_import_vrfs,
15704 json_object_new_string(vname));
15705
b20875ea
CS
15706 json_object_object_add(json, "importFromVrfs",
15707 json_import_vrfs);
b46dfd20 15708 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15709 if (bgp->vpn_policy[afi].rtlist[dir]) {
15710 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15711 bgp->vpn_policy[afi].rtlist[dir],
15712 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15713 json_object_string_add(json, "importRts",
15714 ecom_str);
15715 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15716 } else
15717 json_object_string_add(json, "importRts",
15718 "none");
b46dfd20
DS
15719 }
15720
15721 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15722 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15723 json_object_string_add(json, "exportToVrfs", "none");
15724 json_object_string_add(json, "routeDistinguisher",
15725 "none");
15726 json_object_string_add(json, "exportRts", "none");
15727 } else {
6ce24e52
DS
15728 json_export_vrfs = json_object_new_array();
15729
b46dfd20
DS
15730 for (ALL_LIST_ELEMENTS_RO(
15731 bgp->vpn_policy[afi].export_vrf,
15732 node, vname))
15733 json_object_array_add(json_export_vrfs,
15734 json_object_new_string(vname));
15735 json_object_object_add(json, "exportToVrfs",
15736 json_export_vrfs);
fa566a94
PG
15737 json_object_string_addf(
15738 json, "routeDistinguisher", "%s",
15739 bgp->vpn_policy[afi].tovpn_rd_pretty);
b46dfd20 15740 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15741 if (bgp->vpn_policy[afi].rtlist[dir]) {
15742 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15743 bgp->vpn_policy[afi].rtlist[dir],
15744 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15745 json_object_string_add(json, "exportRts",
15746 ecom_str);
15747 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15748 } else
15749 json_object_string_add(json, "exportRts",
15750 "none");
b46dfd20
DS
15751 }
15752
03915806 15753 if (use_json) {
75eeda93 15754 vty_json(vty, json);
03915806 15755 }
53089bec 15756 } else {
b46dfd20
DS
15757 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15758
53089bec 15759 if (!bgp) {
b46dfd20 15760 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 15761 return CMD_WARNING;
15762 }
53089bec 15763
b46dfd20
DS
15764 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15765 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15766 vty_out(vty,
15767 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 15768 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15769 else {
15770 vty_out(vty,
15771 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 15772 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15773
15774 for (ALL_LIST_ELEMENTS_RO(
15775 bgp->vpn_policy[afi].import_vrf,
15776 node, vname))
15777 vty_out(vty, " %s\n", vname);
15778
15779 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15780 ecom_str = NULL;
15781 if (bgp->vpn_policy[afi].rtlist[dir]) {
15782 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15783 bgp->vpn_policy[afi].rtlist[dir],
15784 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 15785 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 15786
b20875ea
CS
15787 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15788 } else
15789 vty_out(vty, "Import RT(s):\n");
53089bec 15790 }
53089bec 15791
b46dfd20
DS
15792 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15793 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15794 vty_out(vty,
15795 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 15796 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15797 else {
15798 vty_out(vty,
04c9077f 15799 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 15800 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15801
15802 for (ALL_LIST_ELEMENTS_RO(
15803 bgp->vpn_policy[afi].export_vrf,
15804 node, vname))
15805 vty_out(vty, " %s\n", vname);
15806
4a8cd6ad
PG
15807 vty_out(vty, "RD: ");
15808 vty_out(vty, BGP_RD_AS_FORMAT(bgp->asnotation),
c4f64ea9 15809 &bgp->vpn_policy[afi].tovpn_rd);
4a8cd6ad 15810 vty_out(vty, "\n");
b46dfd20
DS
15811
15812 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15813 if (bgp->vpn_policy[afi].rtlist[dir]) {
15814 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15815 bgp->vpn_policy[afi].rtlist[dir],
15816 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15817 vty_out(vty, "Export RT: %s\n", ecom_str);
15818 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15819 } else
15820 vty_out(vty, "Import RT(s):\n");
53089bec 15821 }
53089bec 15822 }
15823
15824 return CMD_SUCCESS;
15825}
15826
03915806
CS
15827static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15828 safi_t safi, bool use_json)
15829{
15830 struct listnode *node, *nnode;
15831 struct bgp *bgp;
15832 char *vrf_name = NULL;
15833 json_object *json = NULL;
15834 json_object *json_vrf = NULL;
15835 json_object *json_vrfs = NULL;
15836
15837 if (use_json) {
15838 json = json_object_new_object();
15839 json_vrfs = json_object_new_object();
15840 }
15841
15842 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15843
15844 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15845 vrf_name = bgp->name;
15846
15847 if (use_json) {
15848 json_vrf = json_object_new_object();
15849 } else {
15850 vty_out(vty, "\nInstance %s:\n",
15851 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15852 ? VRF_DEFAULT_NAME : bgp->name);
15853 }
15854 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15855 if (use_json) {
15856 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15857 json_object_object_add(json_vrfs,
15858 VRF_DEFAULT_NAME, json_vrf);
15859 else
15860 json_object_object_add(json_vrfs, vrf_name,
15861 json_vrf);
15862 }
15863 }
15864
15865 if (use_json) {
15866 json_object_object_add(json, "vrfs", json_vrfs);
75eeda93 15867 vty_json(vty, json);
03915806
CS
15868 }
15869
15870 return CMD_SUCCESS;
15871}
15872
53089bec 15873/* "show [ip] bgp route-leak" command. */
15874DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
15875 show_ip_bgp_route_leak_cmd,
15876 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
15877 SHOW_STR
15878 IP_STR
15879 BGP_STR
15880 BGP_INSTANCE_HELP_STR
15881 BGP_AFI_HELP_STR
15882 BGP_SAFI_HELP_STR
15883 "Route leaking information\n"
15884 JSON_STR)
53089bec 15885{
15886 char *vrf = NULL;
15887 afi_t afi = AFI_MAX;
15888 safi_t safi = SAFI_MAX;
15889
9f049418 15890 bool uj = use_json(argc, argv);
53089bec 15891 int idx = 0;
03915806 15892 json_object *json = NULL;
53089bec 15893
15894 /* show [ip] bgp */
15895 if (argv_find(argv, argc, "ip", &idx)) {
15896 afi = AFI_IP;
15897 safi = SAFI_UNICAST;
15898 }
15899 /* [vrf VIEWVRFNAME] */
15900 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
15901 vty_out(vty,
15902 "%% This command is not applicable to BGP views\n");
53089bec 15903 return CMD_WARNING;
15904 }
15905
9a8bdf1c
PG
15906 if (argv_find(argv, argc, "vrf", &idx)) {
15907 vrf = argv[idx + 1]->arg;
15908 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15909 vrf = NULL;
15910 }
53089bec 15911 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
c48349e3 15912 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
53089bec 15913 argv_find_and_parse_safi(argv, argc, &idx, &safi);
53089bec 15914
15915 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
15916 vty_out(vty,
15917 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 15918 return CMD_WARNING;
15919 }
15920
03915806
CS
15921 if (vrf && strmatch(vrf, "all"))
15922 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15923
15924 if (uj)
15925 json = json_object_new_object();
15926
15927 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 15928}
15929
d62a17ae 15930static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
fa5a9276 15931 safi_t safi, bool uj)
f186de26 15932{
d62a17ae 15933 struct listnode *node, *nnode;
15934 struct bgp *bgp;
f186de26 15935
d62a17ae 15936 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
fa5a9276
AR
15937 if (!uj)
15938 vty_out(vty, "\nInstance %s:\n",
15939 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15940 ? VRF_DEFAULT_NAME
15941 : bgp->name);
15942
15943 update_group_show(bgp, afi, safi, vty, 0, uj);
d62a17ae 15944 }
f186de26 15945}
15946
d62a17ae 15947static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
fa5a9276 15948 int safi, uint64_t subgrp_id, bool uj)
4fb25c53 15949{
d62a17ae 15950 struct bgp *bgp;
4fb25c53 15951
d62a17ae 15952 if (name) {
15953 if (strmatch(name, "all")) {
fa5a9276 15954 bgp_show_all_instances_updgrps_vty(vty, afi, safi, uj);
d62a17ae 15955 return CMD_SUCCESS;
15956 } else {
15957 bgp = bgp_lookup_by_name(name);
15958 }
15959 } else {
15960 bgp = bgp_get_default();
15961 }
4fb25c53 15962
d62a17ae 15963 if (bgp)
fa5a9276 15964 update_group_show(bgp, afi, safi, vty, subgrp_id, uj);
d62a17ae 15965 return CMD_SUCCESS;
4fb25c53
DW
15966}
15967
8fe8a7f6
DS
15968DEFUN (show_ip_bgp_updgrps,
15969 show_ip_bgp_updgrps_cmd,
fa5a9276 15970 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID] [json]",
8386ac43 15971 SHOW_STR
15972 IP_STR
15973 BGP_STR
15974 BGP_INSTANCE_HELP_STR
c9e571b4 15975 BGP_AFI_HELP_STR
9bedbb1e 15976 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956 15977 "Detailed info about dynamic update groups\n"
fa5a9276
AR
15978 "Specific subgroup to display detailed info for\n"
15979 JSON_STR)
8386ac43 15980{
d62a17ae 15981 char *vrf = NULL;
15982 afi_t afi = AFI_IP6;
15983 safi_t safi = SAFI_UNICAST;
15984 uint64_t subgrp_id = 0;
15985
15986 int idx = 0;
15987
fa5a9276
AR
15988 bool uj = use_json(argc, argv);
15989
d62a17ae 15990 /* show [ip] bgp */
15991 if (argv_find(argv, argc, "ip", &idx))
15992 afi = AFI_IP;
9a8bdf1c
PG
15993 /* [<vrf> VIEWVRFNAME] */
15994 if (argv_find(argv, argc, "vrf", &idx)) {
15995 vrf = argv[idx + 1]->arg;
15996 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15997 vrf = NULL;
15998 } else if (argv_find(argv, argc, "view", &idx))
15999 /* [<view> VIEWVRFNAME] */
16000 vrf = argv[idx + 1]->arg;
d62a17ae 16001 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
16002 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
16003 argv_find_and_parse_safi(argv, argc, &idx, &safi);
16004 }
5bf15956 16005
d62a17ae 16006 /* get subgroup id, if provided */
16007 idx = argc - 1;
16008 if (argv[idx]->type == VARIABLE_TKN)
16009 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 16010
fa5a9276 16011 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id, uj));
8fe8a7f6
DS
16012}
16013
f186de26 16014DEFUN (show_bgp_instance_all_ipv6_updgrps,
16015 show_bgp_instance_all_ipv6_updgrps_cmd,
fa5a9276 16016 "show [ip] bgp <view|vrf> all update-groups [json]",
f186de26 16017 SHOW_STR
716b2d8a 16018 IP_STR
f186de26 16019 BGP_STR
16020 BGP_INSTANCE_ALL_HELP_STR
fa5a9276
AR
16021 "Detailed info about dynamic update groups\n"
16022 JSON_STR)
f186de26 16023{
fa5a9276
AR
16024 bool uj = use_json(argc, argv);
16025
16026 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST, uj);
d62a17ae 16027 return CMD_SUCCESS;
f186de26 16028}
16029
43d3f4fc
DS
16030DEFUN (show_bgp_l2vpn_evpn_updgrps,
16031 show_bgp_l2vpn_evpn_updgrps_cmd,
16032 "show [ip] bgp l2vpn evpn update-groups",
16033 SHOW_STR
16034 IP_STR
16035 BGP_STR
16036 "l2vpn address family\n"
16037 "evpn sub-address family\n"
16038 "Detailed info about dynamic update groups\n")
16039{
16040 char *vrf = NULL;
16041 uint64_t subgrp_id = 0;
16042
fa5a9276 16043 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id, 0);
43d3f4fc
DS
16044 return CMD_SUCCESS;
16045}
16046
5bf15956
DW
16047DEFUN (show_bgp_updgrps_stats,
16048 show_bgp_updgrps_stats_cmd,
716b2d8a 16049 "show [ip] bgp update-groups statistics",
3f9c7369 16050 SHOW_STR
716b2d8a 16051 IP_STR
3f9c7369 16052 BGP_STR
0c7b1b01 16053 "Detailed info about dynamic update groups\n"
3f9c7369
DS
16054 "Statistics\n")
16055{
d62a17ae 16056 struct bgp *bgp;
3f9c7369 16057
d62a17ae 16058 bgp = bgp_get_default();
16059 if (bgp)
16060 update_group_show_stats(bgp, vty);
3f9c7369 16061
d62a17ae 16062 return CMD_SUCCESS;
3f9c7369
DS
16063}
16064
8386ac43 16065DEFUN (show_bgp_instance_updgrps_stats,
16066 show_bgp_instance_updgrps_stats_cmd,
18c57037 16067 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 16068 SHOW_STR
716b2d8a 16069 IP_STR
8386ac43 16070 BGP_STR
16071 BGP_INSTANCE_HELP_STR
0c7b1b01 16072 "Detailed info about dynamic update groups\n"
8386ac43 16073 "Statistics\n")
16074{
d62a17ae 16075 int idx_word = 3;
16076 struct bgp *bgp;
8386ac43 16077
d62a17ae 16078 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
16079 if (bgp)
16080 update_group_show_stats(bgp, vty);
8386ac43 16081
d62a17ae 16082 return CMD_SUCCESS;
8386ac43 16083}
16084
d62a17ae 16085static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
16086 afi_t afi, safi_t safi,
16087 const char *what, uint64_t subgrp_id)
3f9c7369 16088{
d62a17ae 16089 struct bgp *bgp;
8386ac43 16090
d62a17ae 16091 if (name)
16092 bgp = bgp_lookup_by_name(name);
16093 else
16094 bgp = bgp_get_default();
8386ac43 16095
d62a17ae 16096 if (bgp) {
16097 if (!strcmp(what, "advertise-queue"))
16098 update_group_show_adj_queue(bgp, afi, safi, vty,
16099 subgrp_id);
16100 else if (!strcmp(what, "advertised-routes"))
16101 update_group_show_advertised(bgp, afi, safi, vty,
16102 subgrp_id);
16103 else if (!strcmp(what, "packet-queue"))
16104 update_group_show_packet_queue(bgp, afi, safi, vty,
16105 subgrp_id);
16106 }
3f9c7369
DS
16107}
16108
dc64bdec
QY
16109DEFPY(show_ip_bgp_instance_updgrps_adj_s,
16110 show_ip_bgp_instance_updgrps_adj_s_cmd,
16111 "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",
16112 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
16113 BGP_SAFI_HELP_STR
16114 "Detailed info about dynamic update groups\n"
16115 "Specific subgroup to display info for\n"
16116 "Advertisement queue\n"
16117 "Announced routes\n"
16118 "Packet queue\n")
3f9c7369 16119{
dc64bdec
QY
16120 uint64_t subgrp_id = 0;
16121 afi_t afiz;
16122 safi_t safiz;
16123 if (sgid)
16124 subgrp_id = strtoull(sgid, NULL, 10);
16125
16126 if (!ip && !afi)
16127 afiz = AFI_IP6;
16128 if (!ip && afi)
16129 afiz = bgp_vty_afi_from_str(afi);
16130 if (ip && !afi)
16131 afiz = AFI_IP;
16132 if (ip && afi) {
16133 afiz = bgp_vty_afi_from_str(afi);
16134 if (afiz != AFI_IP)
16135 vty_out(vty,
16136 "%% Cannot specify both 'ip' and 'ipv6'\n");
16137 return CMD_WARNING;
16138 }
d62a17ae 16139
dc64bdec 16140 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 16141
dc64bdec 16142 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 16143 return CMD_SUCCESS;
16144}
16145
6f4eacf3
DA
16146static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
16147 json_object *json)
d62a17ae 16148{
16149 struct listnode *node, *nnode;
16150 struct prefix *range;
16151 struct peer *conf;
16152 struct peer *peer;
d62a17ae 16153 afi_t afi;
16154 safi_t safi;
16155 const char *peer_status;
d62a17ae 16156 int lr_count;
16157 int dynamic;
6f4eacf3
DA
16158 bool af_cfgd;
16159 json_object *json_peer_group = NULL;
16160 json_object *json_peer_group_afc = NULL;
16161 json_object *json_peer_group_members = NULL;
16162 json_object *json_peer_group_dynamic = NULL;
16163 json_object *json_peer_group_dynamic_af = NULL;
16164 json_object *json_peer_group_ranges = NULL;
d62a17ae 16165
16166 conf = group->conf;
16167
6f4eacf3
DA
16168 if (json) {
16169 json_peer_group = json_object_new_object();
16170 json_peer_group_afc = json_object_new_array();
16171 }
16172
d62a17ae 16173 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3 16174 if (json)
44a4d55e
PG
16175 asn_asn2json(json_peer_group, "remoteAs", conf->as,
16176 bgp_get_asnotation(conf->bgp));
16177 else {
16178 vty_out(vty, "\nBGP peer-group %s, remote AS ",
16179 group->name);
16180 vty_out(vty, ASN_FORMAT(bgp_get_asnotation(conf->bgp)),
16181 &conf->as);
16182 vty_out(vty, "\n");
16183 }
d62a17ae 16184 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3 16185 if (json)
e84c7c12
PG
16186 asn_asn2json(json, "remoteAs", group->bgp->as,
16187 group->bgp->asnotation);
6f4eacf3 16188 else
9eb11997
PG
16189 vty_out(vty, "\nBGP peer-group %s, remote AS %s\n",
16190 group->name, group->bgp->as_pretty);
d62a17ae 16191 } else {
6f4eacf3
DA
16192 if (!json)
16193 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 16194 }
f14e6fdb 16195
6f4eacf3
DA
16196 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
16197 if (json)
16198 json_object_string_add(json_peer_group, "type",
16199 "internal");
16200 else
16201 vty_out(vty, " Peer-group type is internal\n");
16202 } else {
16203 if (json)
16204 json_object_string_add(json_peer_group, "type",
16205 "external");
16206 else
16207 vty_out(vty, " Peer-group type is external\n");
16208 }
d62a17ae 16209
16210 /* Display AFs configured. */
6f4eacf3
DA
16211 if (!json)
16212 vty_out(vty, " Configured address-families:");
16213
05c7a1cc
QY
16214 FOREACH_AFI_SAFI (afi, safi) {
16215 if (conf->afc[afi][safi]) {
6f4eacf3
DA
16216 af_cfgd = true;
16217 if (json)
16218 json_object_array_add(
16219 json_peer_group_afc,
16220 json_object_new_string(get_afi_safi_str(
16221 afi, safi, false)));
16222 else
16223 vty_out(vty, " %s;",
16224 get_afi_safi_str(afi, safi, false));
d62a17ae 16225 }
05c7a1cc 16226 }
6f4eacf3
DA
16227
16228 if (json) {
16229 json_object_object_add(json_peer_group,
16230 "addressFamiliesConfigured",
16231 json_peer_group_afc);
16232 } else {
16233 if (!af_cfgd)
16234 vty_out(vty, " none\n");
16235 else
16236 vty_out(vty, "\n");
16237 }
d62a17ae 16238
16239 /* Display listen ranges (for dynamic neighbors), if any */
16240 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 16241 lr_count = listcount(group->listen_range[afi]);
16242 if (lr_count) {
6f4eacf3
DA
16243 if (json) {
16244 if (!json_peer_group_dynamic)
16245 json_peer_group_dynamic =
16246 json_object_new_object();
16247
16248 json_peer_group_dynamic_af =
16249 json_object_new_object();
16250 json_peer_group_ranges =
16251 json_object_new_array();
16252 json_object_int_add(json_peer_group_dynamic_af,
16253 "count", lr_count);
16254 } else {
16255 vty_out(vty, " %d %s listen range(s)\n",
16256 lr_count, afi2str(afi));
16257 }
d62a17ae 16258
16259 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
16260 nnode, range)) {
16261 if (json) {
16262 char buf[BUFSIZ];
16263
16264 snprintfrr(buf, sizeof(buf), "%pFX",
16265 range);
16266
16267 json_object_array_add(
16268 json_peer_group_ranges,
16269 json_object_new_string(buf));
16270 } else {
16271 vty_out(vty, " %pFX\n", range);
16272 }
16273 }
16274
16275 if (json) {
16276 json_object_object_add(
16277 json_peer_group_dynamic_af, "ranges",
16278 json_peer_group_ranges);
16279
16280 json_object_object_add(
16281 json_peer_group_dynamic, afi2str(afi),
16282 json_peer_group_dynamic_af);
16283 }
d62a17ae 16284 }
16285 }
f14e6fdb 16286
6f4eacf3
DA
16287 if (json_peer_group_dynamic)
16288 json_object_object_add(json_peer_group, "dynamicRanges",
16289 json_peer_group_dynamic);
16290
d62a17ae 16291 /* Display group members and their status */
16292 if (listcount(group->peer)) {
6f4eacf3
DA
16293 if (json)
16294 json_peer_group_members = json_object_new_object();
16295 else
16296 vty_out(vty, " Peer-group members:\n");
d62a17ae 16297 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
16298 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
16299 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 16300 peer_status = "Idle (Admin)";
16301 else if (CHECK_FLAG(peer->sflags,
16302 PEER_STATUS_PREFIX_OVERFLOW))
16303 peer_status = "Idle (PfxCt)";
16304 else
16305 peer_status = lookup_msg(bgp_status_msg,
16306 peer->status, NULL);
16307
16308 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
16309
16310 if (json) {
16311 json_object *json_peer_group_member =
16312 json_object_new_object();
16313
16314 json_object_string_add(json_peer_group_member,
16315 "status", peer_status);
16316
16317 if (dynamic)
16318 json_object_boolean_true_add(
16319 json_peer_group_member,
16320 "dynamic");
16321
16322 json_object_object_add(json_peer_group_members,
16323 peer->host,
16324 json_peer_group_member);
16325 } else {
16326 vty_out(vty, " %s %s %s \n", peer->host,
16327 dynamic ? "(dynamic)" : "",
16328 peer_status);
16329 }
d62a17ae 16330 }
6f4eacf3
DA
16331 if (json)
16332 json_object_object_add(json_peer_group, "members",
16333 json_peer_group_members);
d62a17ae 16334 }
f14e6fdb 16335
6f4eacf3
DA
16336 if (json)
16337 json_object_object_add(json, group->name, json_peer_group);
16338
d62a17ae 16339 return CMD_SUCCESS;
16340}
16341
ff9959b0 16342static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 16343 const char *group_name, bool uj)
d62a17ae 16344{
ff9959b0 16345 struct bgp *bgp;
d62a17ae 16346 struct listnode *node, *nnode;
16347 struct peer_group *group;
ff9959b0 16348 bool found = false;
6f4eacf3
DA
16349 json_object *json = NULL;
16350
16351 if (uj)
16352 json = json_object_new_object();
ff9959b0
QY
16353
16354 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
16355
16356 if (!bgp) {
c48349e3 16357 if (uj)
75eeda93 16358 vty_json(vty, json);
c48349e3 16359 else
6f4eacf3 16360 vty_out(vty, "%% BGP instance not found\n");
6f4eacf3 16361
ff9959b0
QY
16362 return CMD_WARNING;
16363 }
d62a17ae 16364
16365 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
16366 if (group_name) {
16367 if (strmatch(group->name, group_name)) {
6f4eacf3 16368 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
16369 found = true;
16370 break;
d62a17ae 16371 }
ff9959b0 16372 } else {
6f4eacf3 16373 bgp_show_one_peer_group(vty, group, json);
d62a17ae 16374 }
f14e6fdb 16375 }
f14e6fdb 16376
6f4eacf3 16377 if (group_name && !found && !uj)
d62a17ae 16378 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 16379
c48349e3 16380 if (uj)
75eeda93 16381 vty_json(vty, json);
6f4eacf3 16382
d62a17ae 16383 return CMD_SUCCESS;
f14e6fdb
DS
16384}
16385
6f4eacf3
DA
16386DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
16387 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
16388 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
16389 "Detailed information on BGP peer groups\n"
16390 "Peer group name\n" JSON_STR)
f14e6fdb 16391{
d62a17ae 16392 char *vrf, *pg;
d62a17ae 16393 int idx = 0;
6f4eacf3 16394 bool uj = use_json(argc, argv);
f14e6fdb 16395
a4d82a8a
PZ
16396 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16397 : NULL;
d62a17ae 16398 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 16399
6f4eacf3 16400 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 16401}
3f9c7369 16402
d6e3c605 16403
718e3744 16404/* Redistribute VTY commands. */
16405
585f1adc
IR
16406DEFUN (bgp_redistribute_ipv4,
16407 bgp_redistribute_ipv4_cmd,
16408 "redistribute " FRR_IP_REDIST_STR_BGPD,
16409 "Redistribute information from another routing protocol\n"
16410 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 16411{
585f1adc 16412 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16413 int idx_protocol = 1;
585f1adc 16414 int type;
37a87b8f 16415
585f1adc
IR
16416 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16417 if (type < 0) {
16418 vty_out(vty, "%% Invalid route type\n");
16419 return CMD_WARNING_CONFIG_FAILED;
16420 }
7f323236 16421
585f1adc
IR
16422 bgp_redist_add(bgp, AFI_IP, type, 0);
16423 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 16424}
16425
d62a17ae 16426ALIAS_HIDDEN(
16427 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16428 "redistribute " FRR_IP_REDIST_STR_BGPD,
16429 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 16430
585f1adc
IR
16431DEFUN (bgp_redistribute_ipv4_rmap,
16432 bgp_redistribute_ipv4_rmap_cmd,
70dd370f 16433 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
585f1adc
IR
16434 "Redistribute information from another routing protocol\n"
16435 FRR_IP_REDIST_HELP_STR_BGPD
16436 "Route map reference\n"
16437 "Pointer to route-map entries\n")
718e3744 16438{
585f1adc 16439 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16440 int idx_protocol = 1;
16441 int idx_word = 3;
585f1adc
IR
16442 int type;
16443 struct bgp_redist *red;
16444 bool changed;
16445 struct route_map *route_map = route_map_lookup_warn_noexist(
16446 vty, argv[idx_word]->arg);
16447
16448 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16449 if (type < 0) {
16450 vty_out(vty, "%% Invalid route type\n");
16451 return CMD_WARNING_CONFIG_FAILED;
16452 }
37a87b8f 16453
585f1adc
IR
16454 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16455 changed =
16456 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16457 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 16458}
16459
d62a17ae 16460ALIAS_HIDDEN(
16461 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
70dd370f 16462 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
d62a17ae 16463 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16464 "Route map reference\n"
16465 "Pointer to route-map entries\n")
596c17ba 16466
585f1adc
IR
16467DEFUN (bgp_redistribute_ipv4_metric,
16468 bgp_redistribute_ipv4_metric_cmd,
16469 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16470 "Redistribute information from another routing protocol\n"
16471 FRR_IP_REDIST_HELP_STR_BGPD
16472 "Metric for redistributed routes\n"
16473 "Default metric\n")
718e3744 16474{
585f1adc 16475 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16476 int idx_protocol = 1;
16477 int idx_number = 3;
585f1adc
IR
16478 int type;
16479 uint32_t metric;
16480 struct bgp_redist *red;
16481 bool changed;
16482
16483 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16484 if (type < 0) {
16485 vty_out(vty, "%% Invalid route type\n");
16486 return CMD_WARNING_CONFIG_FAILED;
16487 }
16488 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16489
585f1adc
IR
16490 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16491 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16492 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16493}
16494
16495ALIAS_HIDDEN(
16496 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16497 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16498 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16499 "Metric for redistributed routes\n"
16500 "Default metric\n")
596c17ba 16501
585f1adc
IR
16502DEFUN (bgp_redistribute_ipv4_rmap_metric,
16503 bgp_redistribute_ipv4_rmap_metric_cmd,
70dd370f 16504 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16505 "Redistribute information from another routing protocol\n"
16506 FRR_IP_REDIST_HELP_STR_BGPD
16507 "Route map reference\n"
16508 "Pointer to route-map entries\n"
16509 "Metric for redistributed routes\n"
16510 "Default metric\n")
718e3744 16511{
585f1adc 16512 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16513 int idx_protocol = 1;
16514 int idx_word = 3;
16515 int idx_number = 5;
585f1adc
IR
16516 int type;
16517 uint32_t metric;
16518 struct bgp_redist *red;
16519 bool changed;
16520 struct route_map *route_map =
16521 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16522
16523 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16524 if (type < 0) {
16525 vty_out(vty, "%% Invalid route type\n");
16526 return CMD_WARNING_CONFIG_FAILED;
16527 }
16528 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 16529
585f1adc
IR
16530 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16531 changed =
16532 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16533 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16534 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16535}
16536
16537ALIAS_HIDDEN(
16538 bgp_redistribute_ipv4_rmap_metric,
16539 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16540 "redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16541 " route-map RMAP_NAME metric (0-4294967295)",
d62a17ae 16542 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16543 "Route map reference\n"
16544 "Pointer to route-map entries\n"
16545 "Metric for redistributed routes\n"
16546 "Default metric\n")
596c17ba 16547
585f1adc
IR
16548DEFUN (bgp_redistribute_ipv4_metric_rmap,
16549 bgp_redistribute_ipv4_metric_rmap_cmd,
70dd370f 16550 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16551 "Redistribute information from another routing protocol\n"
16552 FRR_IP_REDIST_HELP_STR_BGPD
16553 "Metric for redistributed routes\n"
16554 "Default metric\n"
16555 "Route map reference\n"
16556 "Pointer to route-map entries\n")
718e3744 16557{
585f1adc 16558 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16559 int idx_protocol = 1;
37a87b8f 16560 int idx_number = 3;
585f1adc
IR
16561 int idx_word = 5;
16562 int type;
16563 uint32_t metric;
16564 struct bgp_redist *red;
16565 bool changed;
16566 struct route_map *route_map =
16567 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16568
16569 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16570 if (type < 0) {
16571 vty_out(vty, "%% Invalid route type\n");
16572 return CMD_WARNING_CONFIG_FAILED;
16573 }
16574 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 16575
585f1adc
IR
16576 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16577 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16578 changed |=
16579 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16580 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16581}
16582
16583ALIAS_HIDDEN(
16584 bgp_redistribute_ipv4_metric_rmap,
16585 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16586 "redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16587 " metric (0-4294967295) route-map RMAP_NAME",
d62a17ae 16588 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16589 "Metric for redistributed routes\n"
16590 "Default metric\n"
16591 "Route map reference\n"
16592 "Pointer to route-map entries\n")
596c17ba 16593
585f1adc
IR
16594DEFUN (bgp_redistribute_ipv4_ospf,
16595 bgp_redistribute_ipv4_ospf_cmd,
16596 "redistribute <ospf|table> (1-65535)",
16597 "Redistribute information from another routing protocol\n"
16598 "Open Shortest Path First (OSPFv2)\n"
16599 "Non-main Kernel Routing Table\n"
16600 "Instance ID/Table ID\n")
7c8ff89e 16601{
585f1adc
IR
16602 VTY_DECLVAR_CONTEXT(bgp, bgp);
16603 int idx_ospf_table = 1;
d62a17ae 16604 int idx_number = 2;
585f1adc
IR
16605 unsigned short instance;
16606 unsigned short protocol;
7c8ff89e 16607
585f1adc 16608 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 16609
585f1adc
IR
16610 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16611 protocol = ZEBRA_ROUTE_OSPF;
16612 else
16613 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 16614
585f1adc
IR
16615 bgp_redist_add(bgp, AFI_IP, protocol, instance);
16616 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
16617}
16618
d62a17ae 16619ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16620 "redistribute <ospf|table> (1-65535)",
16621 "Redistribute information from another routing protocol\n"
16622 "Open Shortest Path First (OSPFv2)\n"
16623 "Non-main Kernel Routing Table\n"
16624 "Instance ID/Table ID\n")
596c17ba 16625
585f1adc
IR
16626DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16627 bgp_redistribute_ipv4_ospf_rmap_cmd,
70dd370f 16628 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
585f1adc
IR
16629 "Redistribute information from another routing protocol\n"
16630 "Open Shortest Path First (OSPFv2)\n"
16631 "Non-main Kernel Routing Table\n"
16632 "Instance ID/Table ID\n"
16633 "Route map reference\n"
16634 "Pointer to route-map entries\n")
7c8ff89e 16635{
585f1adc
IR
16636 VTY_DECLVAR_CONTEXT(bgp, bgp);
16637 int idx_ospf_table = 1;
d62a17ae 16638 int idx_number = 2;
16639 int idx_word = 4;
585f1adc
IR
16640 struct bgp_redist *red;
16641 unsigned short instance;
16642 int protocol;
16643 bool changed;
16644 struct route_map *route_map =
16645 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16646
16647 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16648 protocol = ZEBRA_ROUTE_OSPF;
16649 else
16650 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16651
585f1adc
IR
16652 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16653 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16654 changed =
16655 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16656 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16657}
16658
16659ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16660 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
70dd370f 16661 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
d62a17ae 16662 "Redistribute information from another routing protocol\n"
16663 "Open Shortest Path First (OSPFv2)\n"
16664 "Non-main Kernel Routing Table\n"
16665 "Instance ID/Table ID\n"
16666 "Route map reference\n"
16667 "Pointer to route-map entries\n")
596c17ba 16668
585f1adc
IR
16669DEFUN (bgp_redistribute_ipv4_ospf_metric,
16670 bgp_redistribute_ipv4_ospf_metric_cmd,
16671 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16672 "Redistribute information from another routing protocol\n"
16673 "Open Shortest Path First (OSPFv2)\n"
16674 "Non-main Kernel Routing Table\n"
16675 "Instance ID/Table ID\n"
16676 "Metric for redistributed routes\n"
16677 "Default metric\n")
7c8ff89e 16678{
585f1adc
IR
16679 VTY_DECLVAR_CONTEXT(bgp, bgp);
16680 int idx_ospf_table = 1;
d62a17ae 16681 int idx_number = 2;
16682 int idx_number_2 = 4;
585f1adc
IR
16683 uint32_t metric;
16684 struct bgp_redist *red;
16685 unsigned short instance;
16686 int protocol;
16687 bool changed;
16688
16689 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16690 protocol = ZEBRA_ROUTE_OSPF;
16691 else
16692 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16693
585f1adc
IR
16694 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16695 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16696
585f1adc
IR
16697 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16698 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16699 metric);
16700 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16701}
16702
16703ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16704 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16705 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16706 "Redistribute information from another routing protocol\n"
16707 "Open Shortest Path First (OSPFv2)\n"
16708 "Non-main Kernel Routing Table\n"
16709 "Instance ID/Table ID\n"
16710 "Metric for redistributed routes\n"
16711 "Default metric\n")
596c17ba 16712
585f1adc
IR
16713DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16714 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
70dd370f 16715 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16716 "Redistribute information from another routing protocol\n"
16717 "Open Shortest Path First (OSPFv2)\n"
16718 "Non-main Kernel Routing Table\n"
16719 "Instance ID/Table ID\n"
16720 "Route map reference\n"
16721 "Pointer to route-map entries\n"
16722 "Metric for redistributed routes\n"
16723 "Default metric\n")
7c8ff89e 16724{
585f1adc
IR
16725 VTY_DECLVAR_CONTEXT(bgp, bgp);
16726 int idx_ospf_table = 1;
d62a17ae 16727 int idx_number = 2;
16728 int idx_word = 4;
16729 int idx_number_2 = 6;
585f1adc
IR
16730 uint32_t metric;
16731 struct bgp_redist *red;
16732 unsigned short instance;
16733 int protocol;
16734 bool changed;
16735 struct route_map *route_map =
16736 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16737
16738 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16739 protocol = ZEBRA_ROUTE_OSPF;
16740 else
16741 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16742
585f1adc
IR
16743 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16744 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16745
585f1adc
IR
16746 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16747 changed =
16748 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16749 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16750 metric);
16751 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16752}
16753
16754ALIAS_HIDDEN(
16755 bgp_redistribute_ipv4_ospf_rmap_metric,
16756 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
70dd370f 16757 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
d62a17ae 16758 "Redistribute information from another routing protocol\n"
16759 "Open Shortest Path First (OSPFv2)\n"
16760 "Non-main Kernel Routing Table\n"
16761 "Instance ID/Table ID\n"
16762 "Route map reference\n"
16763 "Pointer to route-map entries\n"
16764 "Metric for redistributed routes\n"
16765 "Default metric\n")
596c17ba 16766
585f1adc
IR
16767DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16768 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
70dd370f 16769 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16770 "Redistribute information from another routing protocol\n"
16771 "Open Shortest Path First (OSPFv2)\n"
16772 "Non-main Kernel Routing Table\n"
16773 "Instance ID/Table ID\n"
16774 "Metric for redistributed routes\n"
16775 "Default metric\n"
16776 "Route map reference\n"
16777 "Pointer to route-map entries\n")
7c8ff89e 16778{
585f1adc
IR
16779 VTY_DECLVAR_CONTEXT(bgp, bgp);
16780 int idx_ospf_table = 1;
d62a17ae 16781 int idx_number = 2;
16782 int idx_number_2 = 4;
16783 int idx_word = 6;
585f1adc
IR
16784 uint32_t metric;
16785 struct bgp_redist *red;
16786 unsigned short instance;
16787 int protocol;
16788 bool changed;
16789 struct route_map *route_map =
16790 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16791
16792 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16793 protocol = ZEBRA_ROUTE_OSPF;
16794 else
16795 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16796
585f1adc
IR
16797 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16798 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16799
585f1adc
IR
16800 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16801 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16802 metric);
16803 changed |=
16804 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16805 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16806}
16807
16808ALIAS_HIDDEN(
16809 bgp_redistribute_ipv4_ospf_metric_rmap,
16810 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
70dd370f 16811 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
d62a17ae 16812 "Redistribute information from another routing protocol\n"
16813 "Open Shortest Path First (OSPFv2)\n"
16814 "Non-main Kernel Routing Table\n"
16815 "Instance ID/Table ID\n"
16816 "Metric for redistributed routes\n"
16817 "Default metric\n"
16818 "Route map reference\n"
16819 "Pointer to route-map entries\n")
596c17ba 16820
585f1adc
IR
16821DEFUN (no_bgp_redistribute_ipv4_ospf,
16822 no_bgp_redistribute_ipv4_ospf_cmd,
70dd370f 16823 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16824 NO_STR
16825 "Redistribute information from another routing protocol\n"
16826 "Open Shortest Path First (OSPFv2)\n"
16827 "Non-main Kernel Routing Table\n"
16828 "Instance ID/Table ID\n"
16829 "Metric for redistributed routes\n"
16830 "Default metric\n"
16831 "Route map reference\n"
16832 "Pointer to route-map entries\n")
7c8ff89e 16833{
585f1adc
IR
16834 VTY_DECLVAR_CONTEXT(bgp, bgp);
16835 int idx_ospf_table = 2;
d62a17ae 16836 int idx_number = 3;
585f1adc
IR
16837 unsigned short instance;
16838 int protocol;
37a87b8f 16839
585f1adc
IR
16840 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16841 protocol = ZEBRA_ROUTE_OSPF;
16842 else
16843 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16844
585f1adc
IR
16845 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16846 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
d62a17ae 16847}
16848
16849ALIAS_HIDDEN(
16850 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
70dd370f 16851 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
d62a17ae 16852 NO_STR
16853 "Redistribute information from another routing protocol\n"
16854 "Open Shortest Path First (OSPFv2)\n"
16855 "Non-main Kernel Routing Table\n"
16856 "Instance ID/Table ID\n"
16857 "Metric for redistributed routes\n"
16858 "Default metric\n"
16859 "Route map reference\n"
16860 "Pointer to route-map entries\n")
596c17ba 16861
585f1adc
IR
16862DEFUN (no_bgp_redistribute_ipv4,
16863 no_bgp_redistribute_ipv4_cmd,
70dd370f 16864 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16865 NO_STR
16866 "Redistribute information from another routing protocol\n"
16867 FRR_IP_REDIST_HELP_STR_BGPD
16868 "Metric for redistributed routes\n"
16869 "Default metric\n"
16870 "Route map reference\n"
16871 "Pointer to route-map entries\n")
718e3744 16872{
585f1adc 16873 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16874 int idx_protocol = 2;
585f1adc 16875 int type;
d62a17ae 16876
585f1adc
IR
16877 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16878 if (type < 0) {
16879 vty_out(vty, "%% Invalid route type\n");
16880 return CMD_WARNING_CONFIG_FAILED;
16881 }
16882 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
d62a17ae 16883}
16884
16885ALIAS_HIDDEN(
16886 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16887 "no redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16888 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
d62a17ae 16889 NO_STR
16890 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16891 "Metric for redistributed routes\n"
16892 "Default metric\n"
16893 "Route map reference\n"
16894 "Pointer to route-map entries\n")
596c17ba 16895
585f1adc
IR
16896DEFUN (bgp_redistribute_ipv6,
16897 bgp_redistribute_ipv6_cmd,
16898 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16899 "Redistribute information from another routing protocol\n"
16900 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 16901{
585f1adc 16902 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16903 int idx_protocol = 1;
585f1adc 16904 int type;
718e3744 16905
585f1adc
IR
16906 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16907 if (type < 0) {
16908 vty_out(vty, "%% Invalid route type\n");
16909 return CMD_WARNING_CONFIG_FAILED;
16910 }
718e3744 16911
585f1adc
IR
16912 bgp_redist_add(bgp, AFI_IP6, type, 0);
16913 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 16914}
16915
585f1adc
IR
16916DEFUN (bgp_redistribute_ipv6_rmap,
16917 bgp_redistribute_ipv6_rmap_cmd,
70dd370f 16918 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
585f1adc
IR
16919 "Redistribute information from another routing protocol\n"
16920 FRR_IP6_REDIST_HELP_STR_BGPD
16921 "Route map reference\n"
16922 "Pointer to route-map entries\n")
718e3744 16923{
585f1adc 16924 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16925 int idx_protocol = 1;
16926 int idx_word = 3;
585f1adc
IR
16927 int type;
16928 struct bgp_redist *red;
16929 bool changed;
16930 struct route_map *route_map =
16931 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16932
16933 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16934 if (type < 0) {
16935 vty_out(vty, "%% Invalid route type\n");
16936 return CMD_WARNING_CONFIG_FAILED;
16937 }
37a87b8f 16938
585f1adc
IR
16939 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16940 changed =
16941 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16942 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16943}
16944
585f1adc 16945DEFUN (bgp_redistribute_ipv6_metric,
718e3744 16946 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 16947 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 16948 "Redistribute information from another routing protocol\n"
ab0181ee 16949 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 16950 "Metric for redistributed routes\n"
16951 "Default metric\n")
16952{
585f1adc 16953 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16954 int idx_protocol = 1;
16955 int idx_number = 3;
585f1adc
IR
16956 int type;
16957 uint32_t metric;
16958 struct bgp_redist *red;
16959 bool changed;
16960
16961 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16962 if (type < 0) {
16963 vty_out(vty, "%% Invalid route type\n");
16964 return CMD_WARNING_CONFIG_FAILED;
16965 }
16966 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16967
585f1adc
IR
16968 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16969 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16970 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16971}
16972
585f1adc
IR
16973DEFUN (bgp_redistribute_ipv6_rmap_metric,
16974 bgp_redistribute_ipv6_rmap_metric_cmd,
70dd370f 16975 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16976 "Redistribute information from another routing protocol\n"
16977 FRR_IP6_REDIST_HELP_STR_BGPD
16978 "Route map reference\n"
16979 "Pointer to route-map entries\n"
16980 "Metric for redistributed routes\n"
16981 "Default metric\n")
718e3744 16982{
585f1adc 16983 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16984 int idx_protocol = 1;
16985 int idx_word = 3;
16986 int idx_number = 5;
585f1adc
IR
16987 int type;
16988 uint32_t metric;
16989 struct bgp_redist *red;
16990 bool changed;
16991 struct route_map *route_map =
16992 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16993
16994 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16995 if (type < 0) {
16996 vty_out(vty, "%% Invalid route type\n");
16997 return CMD_WARNING_CONFIG_FAILED;
16998 }
16999 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 17000
585f1adc
IR
17001 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
17002 changed =
17003 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
17004 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
17005 metric);
17006 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 17007}
17008
585f1adc
IR
17009DEFUN (bgp_redistribute_ipv6_metric_rmap,
17010 bgp_redistribute_ipv6_metric_rmap_cmd,
70dd370f 17011 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
17012 "Redistribute information from another routing protocol\n"
17013 FRR_IP6_REDIST_HELP_STR_BGPD
17014 "Metric for redistributed routes\n"
17015 "Default metric\n"
17016 "Route map reference\n"
17017 "Pointer to route-map entries\n")
718e3744 17018{
585f1adc 17019 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 17020 int idx_protocol = 1;
37a87b8f 17021 int idx_number = 3;
585f1adc
IR
17022 int idx_word = 5;
17023 int type;
17024 uint32_t metric;
17025 struct bgp_redist *red;
17026 bool changed;
17027 struct route_map *route_map =
17028 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
17029
17030 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
17031 if (type < 0) {
17032 vty_out(vty, "%% Invalid route type\n");
17033 return CMD_WARNING_CONFIG_FAILED;
17034 }
17035 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 17036
585f1adc
IR
17037 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
17038 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
17039 metric);
17040 changed |=
17041 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
17042 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 17043}
17044
585f1adc
IR
17045DEFUN (no_bgp_redistribute_ipv6,
17046 no_bgp_redistribute_ipv6_cmd,
70dd370f 17047 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
17048 NO_STR
17049 "Redistribute information from another routing protocol\n"
17050 FRR_IP6_REDIST_HELP_STR_BGPD
17051 "Metric for redistributed routes\n"
17052 "Default metric\n"
17053 "Route map reference\n"
17054 "Pointer to route-map entries\n")
718e3744 17055{
585f1adc 17056 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 17057 int idx_protocol = 2;
585f1adc 17058 int type;
37a87b8f 17059
585f1adc
IR
17060 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
17061 if (type < 0) {
17062 vty_out(vty, "%% Invalid route type\n");
17063 return CMD_WARNING_CONFIG_FAILED;
17064 }
718e3744 17065
585f1adc 17066 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
d62a17ae 17067}
17068
4ab46701
AR
17069/* Neighbor update tcp-mss. */
17070static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
17071 const char *tcp_mss_str)
17072{
17073 struct peer *peer;
17074 uint32_t tcp_mss_val = 0;
17075
17076 peer = peer_and_group_lookup_vty(vty, peer_str);
17077 if (!peer)
17078 return CMD_WARNING_CONFIG_FAILED;
17079
17080 if (tcp_mss_str) {
17081 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
17082 peer_tcp_mss_set(peer, tcp_mss_val);
17083 } else {
17084 peer_tcp_mss_unset(peer);
17085 }
17086
17087 return CMD_SUCCESS;
17088}
17089
17090DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
17091 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
17092 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
17093 "TCP max segment size\n"
17094 "TCP MSS value\n")
17095{
17096 int peer_index = 1;
17097 int mss_index = 3;
17098
17099 vty_out(vty,
17100 " Warning: Reset BGP session for tcp-mss value to take effect\n");
17101 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
17102 argv[mss_index]->arg);
17103}
17104
17105DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
17106 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
17107 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
17108 "TCP max segment size\n"
17109 "TCP MSS value\n")
17110{
17111 int peer_index = 2;
17112
17113 vty_out(vty,
17114 " Warning: Reset BGP session for tcp-mss value to take effect\n");
17115 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
17116}
17117
a486300b
PG
17118DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
17119 "[no$no] bgp retain route-target all",
17120 NO_STR BGP_STR
17121 "Retain BGP updates\n"
17122 "Retain BGP updates based on route-target values\n"
17123 "Retain all BGP updates\n")
17124{
17125 bool check;
17126 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
17127
17128 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
17129 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
17130 if (check != !no) {
17131 if (!no)
17132 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
17133 [bgp_node_safi(vty)],
17134 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
17135 else
17136 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
17137 [bgp_node_safi(vty)],
17138 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
17139 /* trigger a flush to re-sync with ADJ-RIB-in */
17140 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
17141 clear_all, BGP_CLEAR_SOFT_IN, NULL);
17142 }
17143 return CMD_SUCCESS;
17144}
17145
dd65f45e
DL
17146static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
17147 afi_t afi, safi_t safi)
d62a17ae 17148{
17149 int i;
17150
17151 /* Unicast redistribution only. */
17152 if (safi != SAFI_UNICAST)
2b791107 17153 return;
d62a17ae 17154
17155 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
17156 /* Redistribute BGP does not make sense. */
17157 if (i != ZEBRA_ROUTE_BGP) {
17158 struct list *red_list;
17159 struct listnode *node;
17160 struct bgp_redist *red;
17161
17162 red_list = bgp->redist[afi][i];
17163 if (!red_list)
17164 continue;
17165
17166 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 17167 /* "redistribute" configuration. */
17168 vty_out(vty, " redistribute %s",
17169 zebra_route_string(i));
17170 if (red->instance)
17171 vty_out(vty, " %d", red->instance);
17172 if (red->redist_metric_flag)
17173 vty_out(vty, " metric %u",
17174 red->redist_metric);
17175 if (red->rmap.name)
17176 vty_out(vty, " route-map %s",
17177 red->rmap.name);
17178 vty_out(vty, "\n");
17179 }
17180 }
17181 }
718e3744 17182}
6b0655a2 17183
dd65f45e
DL
17184/* peer-group helpers for config-write */
17185
234f6fd4 17186bool peergroup_flag_check(struct peer *peer, uint64_t flag)
dd65f45e
DL
17187{
17188 if (!peer_group_active(peer)) {
17189 if (CHECK_FLAG(peer->flags_invert, flag))
17190 return !CHECK_FLAG(peer->flags, flag);
17191 else
17192 return !!CHECK_FLAG(peer->flags, flag);
17193 }
17194
17195 return !!CHECK_FLAG(peer->flags_override, flag);
17196}
17197
17198static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
da5e1a58 17199 uint64_t flag)
dd65f45e
DL
17200{
17201 if (!peer_group_active(peer)) {
17202 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
17203 return !peer_af_flag_check(peer, afi, safi, flag);
17204 else
2c722516 17205 return peer_af_flag_check(peer, afi, safi, flag);
dd65f45e
DL
17206 }
17207
17208 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
17209}
17210
17211static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
17212 uint8_t type, int direct)
17213{
17214 struct bgp_filter *filter;
17215
17216 if (peer_group_active(peer))
17217 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
17218 type);
17219
17220 filter = &peer->filter[afi][safi];
17221 switch (type) {
17222 case PEER_FT_DISTRIBUTE_LIST:
17223 return !!(filter->dlist[direct].name);
17224 case PEER_FT_FILTER_LIST:
17225 return !!(filter->aslist[direct].name);
17226 case PEER_FT_PREFIX_LIST:
17227 return !!(filter->plist[direct].name);
17228 case PEER_FT_ROUTE_MAP:
17229 return !!(filter->map[direct].name);
17230 case PEER_FT_UNSUPPRESS_MAP:
17231 return !!(filter->usmap.name);
7f7940e6
MK
17232 case PEER_FT_ADVERTISE_MAP:
17233 return !!(filter->advmap.aname
17234 && ((filter->advmap.condition == direct)
17235 && filter->advmap.cname));
dd65f45e
DL
17236 default:
17237 return false;
17238 }
17239}
17240
17241/* Return true if the addpath type is set for peer and different from
17242 * peer-group.
17243 */
3dc339cd
DA
17244static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
17245 safi_t safi)
dd65f45e
DL
17246{
17247 enum bgp_addpath_strat type, g_type;
17248
17249 type = peer->addpath_type[afi][safi];
17250
17251 if (type != BGP_ADDPATH_NONE) {
17252 if (peer_group_active(peer)) {
17253 g_type = peer->group->conf->addpath_type[afi][safi];
17254
17255 if (type != g_type)
3dc339cd 17256 return true;
dd65f45e 17257 else
3dc339cd 17258 return false;
dd65f45e
DL
17259 }
17260
3dc339cd 17261 return true;
dd65f45e
DL
17262 }
17263
3dc339cd 17264 return false;
dd65f45e
DL
17265}
17266
b9c7bc5a 17267/* This is part of the address-family block (unicast only) */
dd65f45e 17268static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
17269 afi_t afi)
17270{
b9c7bc5a 17271 int indent = 2;
53970de3 17272 uint32_t tovpn_sid_index = 0;
ddb5b488 17273
8a066a70 17274 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
17275 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17276 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
17277 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
17278 bgp->vpn_policy[afi]
bb4f6190 17279 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
17280 else
17281 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
17282 bgp->vpn_policy[afi]
17283 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17284 }
12a844a5
DS
17285 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17286 BGP_CONFIG_VRF_TO_VRF_IMPORT)
17287 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17288 BGP_CONFIG_VRF_TO_VRF_EXPORT))
17289 return;
17290
e70e9f8e
PZ
17291 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17292 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
17293
17294 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
17295
17296 } else {
17297 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
17298 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
17299 bgp->vpn_policy[afi].tovpn_label);
17300 }
ddb5b488 17301 }
53970de3
RS
17302
17303 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
17304 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17305 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
17306 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
17307 } else if (tovpn_sid_index != 0) {
17308 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
17309 tovpn_sid_index);
17310 }
17311
c4f64ea9 17312 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
fa566a94
PG
17313 vty_out(vty, "%*srd vpn export %s\n", indent, "",
17314 bgp->vpn_policy[afi].tovpn_rd_pretty);
c4f64ea9 17315
ddb5b488
PZ
17316 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17317 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
17318
17319 char buf[PREFIX_STRLEN];
17320 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
17321 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
17322 sizeof(buf))) {
17323
b9c7bc5a
PZ
17324 vty_out(vty, "%*snexthop vpn export %s\n",
17325 indent, "", buf);
ddb5b488
PZ
17326 }
17327 }
17328 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
17329 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
17330 && ecommunity_cmp(
17331 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17332 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
17333
17334 char *b = ecommunity_ecom2str(
17335 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17336 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17337 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
17338 XFREE(MTYPE_ECOMMUNITY_STR, b);
17339 } else {
17340 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
17341 char *b = ecommunity_ecom2str(
17342 bgp->vpn_policy[afi]
17343 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17344 ECOMMUNITY_FORMAT_ROUTE_MAP,
17345 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17346 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
17347 XFREE(MTYPE_ECOMMUNITY_STR, b);
17348 }
17349 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
17350 char *b = ecommunity_ecom2str(
17351 bgp->vpn_policy[afi]
17352 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17353 ECOMMUNITY_FORMAT_ROUTE_MAP,
17354 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17355 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
17356 XFREE(MTYPE_ECOMMUNITY_STR, b);
17357 }
17358 }
bb4f6190
DS
17359
17360 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 17361 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
17362 bgp->vpn_policy[afi]
17363 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 17364
301ad80a
PG
17365 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
17366 char *b = ecommunity_ecom2str(
17367 bgp->vpn_policy[afi]
17368 .import_redirect_rtlist,
17369 ECOMMUNITY_FORMAT_ROUTE_MAP,
17370 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 17371
9a659715
PG
17372 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
17373 != ECOMMUNITY_SIZE)
c6423c31 17374 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
17375 indent, "", b);
17376 else
17377 vty_out(vty, "%*srt redirect import %s\n",
17378 indent, "", b);
301ad80a
PG
17379 XFREE(MTYPE_ECOMMUNITY_STR, b);
17380 }
ddb5b488
PZ
17381}
17382
dd65f45e
DL
17383static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
17384 afi_t afi, safi_t safi)
17385{
17386 struct bgp_filter *filter;
17387 char *addr;
17388
17389 addr = peer->host;
17390 filter = &peer->filter[afi][safi];
17391
17392 /* distribute-list. */
17393 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17394 FILTER_IN))
17395 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
17396 filter->dlist[FILTER_IN].name);
17397
17398 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17399 FILTER_OUT))
17400 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17401 filter->dlist[FILTER_OUT].name);
17402
17403 /* prefix-list. */
17404 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17405 FILTER_IN))
17406 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17407 filter->plist[FILTER_IN].name);
17408
17409 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17410 FILTER_OUT))
17411 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17412 filter->plist[FILTER_OUT].name);
17413
17414 /* route-map. */
17415 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17416 vty_out(vty, " neighbor %s route-map %s in\n", addr,
17417 filter->map[RMAP_IN].name);
17418
17419 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17420 RMAP_OUT))
17421 vty_out(vty, " neighbor %s route-map %s out\n", addr,
17422 filter->map[RMAP_OUT].name);
17423
17424 /* unsuppress-map */
17425 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17426 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17427 filter->usmap.name);
17428
7f7940e6
MK
17429 /* advertise-map : always applied in OUT direction*/
17430 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17431 CONDITION_NON_EXIST))
17432 vty_out(vty,
17433 " neighbor %s advertise-map %s non-exist-map %s\n",
17434 addr, filter->advmap.aname, filter->advmap.cname);
17435
17436 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17437 CONDITION_EXIST))
17438 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17439 addr, filter->advmap.aname, filter->advmap.cname);
17440
dd65f45e
DL
17441 /* filter-list. */
17442 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17443 FILTER_IN))
17444 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17445 filter->aslist[FILTER_IN].name);
17446
17447 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17448 FILTER_OUT))
17449 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17450 filter->aslist[FILTER_OUT].name);
17451}
17452
17453/* BGP peer configuration display function. */
17454static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17455 struct peer *peer)
17456{
17457 struct peer *g_peer = NULL;
dd65f45e
DL
17458 char *addr;
17459 int if_pg_printed = false;
17460 int if_ras_printed = false;
17461
17462 /* Skip dynamic neighbors. */
17463 if (peer_dynamic_neighbor(peer))
17464 return;
17465
17466 if (peer->conf_if)
17467 addr = peer->conf_if;
17468 else
17469 addr = peer->host;
17470
17471 /************************************
17472 ****** Global to the neighbor ******
17473 ************************************/
17474 if (peer->conf_if) {
17475 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17476 vty_out(vty, " neighbor %s interface v6only", addr);
17477 else
17478 vty_out(vty, " neighbor %s interface", addr);
17479
17480 if (peer_group_active(peer)) {
17481 vty_out(vty, " peer-group %s", peer->group->name);
17482 if_pg_printed = true;
17483 } else if (peer->as_type == AS_SPECIFIED) {
de76ed8a 17484 vty_out(vty, " remote-as %s", peer->as_pretty);
dd65f45e
DL
17485 if_ras_printed = true;
17486 } else if (peer->as_type == AS_INTERNAL) {
17487 vty_out(vty, " remote-as internal");
17488 if_ras_printed = true;
17489 } else if (peer->as_type == AS_EXTERNAL) {
17490 vty_out(vty, " remote-as external");
17491 if_ras_printed = true;
17492 }
17493
17494 vty_out(vty, "\n");
17495 }
17496
17497 /* remote-as and peer-group */
17498 /* peer is a member of a peer-group */
17499 if (peer_group_active(peer)) {
17500 g_peer = peer->group->conf;
17501
17502 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17503 if (peer->as_type == AS_SPECIFIED) {
de76ed8a
PG
17504 vty_out(vty, " neighbor %s remote-as %s\n",
17505 addr, peer->as_pretty);
dd65f45e
DL
17506 } else if (peer->as_type == AS_INTERNAL) {
17507 vty_out(vty,
17508 " neighbor %s remote-as internal\n",
17509 addr);
17510 } else if (peer->as_type == AS_EXTERNAL) {
17511 vty_out(vty,
17512 " neighbor %s remote-as external\n",
17513 addr);
17514 }
17515 }
17516
17517 /* For swpX peers we displayed the peer-group
17518 * via 'neighbor swpX interface peer-group PGNAME' */
17519 if (!if_pg_printed)
17520 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17521 peer->group->name);
17522 }
17523
17524 /* peer is NOT a member of a peer-group */
17525 else {
17526 /* peer is a peer-group, declare the peer-group */
17527 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17528 vty_out(vty, " neighbor %s peer-group\n", addr);
17529 }
17530
17531 if (!if_ras_printed) {
17532 if (peer->as_type == AS_SPECIFIED) {
de76ed8a
PG
17533 vty_out(vty, " neighbor %s remote-as %s\n",
17534 addr, peer->as_pretty);
dd65f45e
DL
17535 } else if (peer->as_type == AS_INTERNAL) {
17536 vty_out(vty,
17537 " neighbor %s remote-as internal\n",
17538 addr);
17539 } else if (peer->as_type == AS_EXTERNAL) {
17540 vty_out(vty,
17541 " neighbor %s remote-as external\n",
17542 addr);
17543 }
17544 }
17545 }
17546
17547 /* local-as */
17548 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
de76ed8a
PG
17549 vty_out(vty, " neighbor %s local-as %s", addr,
17550 peer->change_local_as_pretty);
dd65f45e
DL
17551 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17552 vty_out(vty, " no-prepend");
17553 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17554 vty_out(vty, " replace-as");
17555 vty_out(vty, "\n");
17556 }
17557
17558 /* description */
17559 if (peer->desc) {
17560 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17561 }
17562
17563 /* shutdown */
17564 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17565 if (peer->tx_shutdown_message)
17566 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17567 peer->tx_shutdown_message);
17568 else
17569 vty_out(vty, " neighbor %s shutdown\n", addr);
17570 }
17571
8336c896
DA
17572 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17573 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17574 peer->rtt_expected, peer->rtt_keepalive_conf);
17575
dd65f45e 17576 /* bfd */
21bfce98
RZ
17577 if (peer->bfd_config)
17578 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
17579
17580 /* password */
17581 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17582 vty_out(vty, " neighbor %s password %s\n", addr,
17583 peer->password);
17584
17585 /* neighbor solo */
17586 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17587 if (!peer_group_active(peer)) {
17588 vty_out(vty, " neighbor %s solo\n", addr);
17589 }
17590 }
17591
17592 /* BGP port */
17593 if (peer->port != BGP_PORT_DEFAULT) {
17594 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17595 }
17596
17597 /* Local interface name */
17598 if (peer->ifname) {
17599 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17600 }
17601
4ab46701
AR
17602 /* TCP max segment size */
17603 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17604 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17605
dd65f45e
DL
17606 /* passive */
17607 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17608 vty_out(vty, " neighbor %s passive\n", addr);
17609
17610 /* ebgp-multihop */
17611 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
17612 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17613 && peer->ttl == MAXTTL)) {
dd65f45e
DL
17614 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17615 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17616 peer->ttl);
17617 }
17618 }
17619
97a52c82
DA
17620 /* aigp */
17621 if (peergroup_flag_check(peer, PEER_FLAG_AIGP))
17622 vty_out(vty, " neighbor %s aigp\n", addr);
17623
4f770cf1
DA
17624 /* graceful-shutdown */
17625 if (peergroup_flag_check(peer, PEER_FLAG_GRACEFUL_SHUTDOWN))
17626 vty_out(vty, " neighbor %s graceful-shutdown\n", addr);
17627
d864dd9e 17628 /* role */
7dddd1f7
DA
17629 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17630 peer->local_role != ROLE_UNDEFINED)
d864dd9e 17631 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
8f2d6021 17632 bgp_get_name_by_role(peer->local_role),
7dddd1f7 17633 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
d864dd9e
EB
17634 ? " strict-mode"
17635 : "");
d864dd9e 17636
dd65f45e 17637 /* ttl-security hops */
e2521429 17638 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
17639 if (!peer_group_active(peer)
17640 || g_peer->gtsm_hops != peer->gtsm_hops) {
17641 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17642 addr, peer->gtsm_hops);
17643 }
17644 }
17645
17646 /* disable-connected-check */
17647 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17648 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17649
27aa23a4
DA
17650 /* link-bw-encoding-ieee */
17651 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17652 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17653 addr);
17654
d08c0c80
DA
17655 /* extended-optional-parameters */
17656 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17657 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17658 addr);
17659
dd65f45e
DL
17660 /* enforce-first-as */
17661 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17662 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17663
17664 /* update-source */
17665 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17666 if (peer->update_source)
47e12884
DA
17667 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17668 peer->update_source);
dd65f45e
DL
17669 else if (peer->update_if)
17670 vty_out(vty, " neighbor %s update-source %s\n", addr,
17671 peer->update_if);
17672 }
17673
17674 /* advertisement-interval */
17675 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17676 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17677 peer->routeadv);
17678
17679 /* timers */
17680 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17681 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17682 peer->keepalive, peer->holdtime);
17683
17684 /* timers connect */
17685 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17686 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17687 peer->connect);
5d5393b9
DL
17688 /* need special-case handling for changed default values due to
17689 * config profile / version (because there is no "timers bgp connect"
17690 * command, we need to save this per-peer :/)
17691 */
17692 else if (!peer_group_active(peer) && !peer->connect &&
17693 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17694 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17695 peer->bgp->default_connect_retry);
dd65f45e 17696
d43114f3
DS
17697 /* timers delayopen */
17698 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17699 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17700 peer->delayopen);
17701 /* Save config even though flag is not set if default values have been
17702 * changed
17703 */
17704 else if (!peer_group_active(peer) && !peer->delayopen
17705 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17706 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17707 peer->bgp->default_delayopen);
17708
dd65f45e
DL
17709 /* capability dynamic */
17710 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17711 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17712
17713 /* capability extended-nexthop */
17714 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
8e89adc1
DS
17715 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17716 !peer->conf_if)
843770f6
DA
17717 vty_out(vty,
17718 " no neighbor %s capability extended-nexthop\n",
17719 addr);
17720 else if (!peer->conf_if)
17721 vty_out(vty,
17722 " neighbor %s capability extended-nexthop\n",
17723 addr);
dd65f45e
DL
17724 }
17725
234f6fd4
DA
17726 /* capability software-version */
17727 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_SOFT_VERSION))
17728 vty_out(vty, " neighbor %s capability software-version\n",
17729 addr);
17730
dd65f45e
DL
17731 /* dont-capability-negotiation */
17732 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17733 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17734
17735 /* override-capability */
17736 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17737 vty_out(vty, " neighbor %s override-capability\n", addr);
17738
17739 /* strict-capability-match */
17740 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17741 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17742
17743 /* Sender side AS path loop detection. */
17744 if (peer->as_path_loop_detection)
17745 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17746 addr);
cfd47646 17747
a5c6a9b1
DA
17748 /* path-attribute discard */
17749 char discard_attrs_str[BUFSIZ] = {0};
17750 bool discard_attrs = bgp_path_attribute_discard(
17751 peer, discard_attrs_str, sizeof(discard_attrs_str));
17752
17753 if (discard_attrs)
17754 vty_out(vty, " neighbor %s path-attribute discard %s\n", addr,
17755 discard_attrs_str);
17756
e2863b4f
DA
17757 /* path-attribute treat-as-withdraw */
17758 char withdraw_attrs_str[BUFSIZ] = {0};
17759 bool withdraw_attrs = bgp_path_attribute_treat_as_withdraw(
17760 peer, withdraw_attrs_str, sizeof(withdraw_attrs_str));
17761
17762 if (withdraw_attrs)
17763 vty_out(vty,
17764 " neighbor %s path-attribute treat-as-withdraw %s\n",
17765 addr, withdraw_attrs_str);
17766
cfd47646 17767 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17768 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 17769
17770 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17771 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 17772 vty_out(vty,
17773 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
17774 } else if (CHECK_FLAG(
17775 peer->peer_gr_new_status_flag,
17776 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 17777 vty_out(vty,
17778 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
17779 } else if (
17780 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17781 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17782 && !(CHECK_FLAG(
17783 peer->peer_gr_new_status_flag,
17784 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17785 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17786 addr);
cfd47646 17787 }
17788 }
dd65f45e
DL
17789}
17790
17791/* BGP peer configuration display function. */
17792static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17793 struct peer *peer, afi_t afi, safi_t safi)
17794{
17795 struct peer *g_peer = NULL;
17796 char *addr;
17797 bool flag_scomm, flag_secomm, flag_slcomm;
17798
17799 /* Skip dynamic neighbors. */
17800 if (peer_dynamic_neighbor(peer))
17801 return;
17802
17803 if (peer->conf_if)
17804 addr = peer->conf_if;
17805 else
17806 addr = peer->host;
17807
17808 /************************************
17809 ****** Per AF to the neighbor ******
17810 ************************************/
17811 if (peer_group_active(peer)) {
17812 g_peer = peer->group->conf;
17813
17814 /* If the peer-group is active but peer is not, print a 'no
17815 * activate' */
17816 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17817 vty_out(vty, " no neighbor %s activate\n", addr);
17818 }
17819
17820 /* If the peer-group is not active but peer is, print an
17821 'activate' */
17822 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17823 vty_out(vty, " neighbor %s activate\n", addr);
17824 }
17825 } else {
17826 if (peer->afc[afi][safi]) {
38d11af5
TA
17827 if (safi == SAFI_ENCAP)
17828 vty_out(vty, " neighbor %s activate\n", addr);
17829 else if (!bgp->default_af[afi][safi])
dd65f45e
DL
17830 vty_out(vty, " neighbor %s activate\n", addr);
17831 } else {
38d11af5
TA
17832 if (bgp->default_af[afi][safi])
17833 vty_out(vty, " no neighbor %s activate\n",
17834 addr);
dd65f45e
DL
17835 }
17836 }
17837
17838 /* addpath TX knobs */
17839 if (peergroup_af_addpath_check(peer, afi, safi)) {
17840 switch (peer->addpath_type[afi][safi]) {
17841 case BGP_ADDPATH_ALL:
17842 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17843 addr);
17844 break;
17845 case BGP_ADDPATH_BEST_PER_AS:
17846 vty_out(vty,
17847 " neighbor %s addpath-tx-bestpath-per-AS\n",
17848 addr);
17849 break;
17850 case BGP_ADDPATH_MAX:
17851 case BGP_ADDPATH_NONE:
17852 break;
17853 }
17854 }
17855
7c0e4312
DA
17856 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17857 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17858
dd65f45e
DL
17859 /* ORF capability. */
17860 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17861 || peergroup_af_flag_check(peer, afi, safi,
17862 PEER_FLAG_ORF_PREFIX_RM)) {
17863 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17864
17865 if (peergroup_af_flag_check(peer, afi, safi,
17866 PEER_FLAG_ORF_PREFIX_SM)
17867 && peergroup_af_flag_check(peer, afi, safi,
17868 PEER_FLAG_ORF_PREFIX_RM))
17869 vty_out(vty, " both");
17870 else if (peergroup_af_flag_check(peer, afi, safi,
17871 PEER_FLAG_ORF_PREFIX_SM))
17872 vty_out(vty, " send");
17873 else
17874 vty_out(vty, " receive");
17875 vty_out(vty, "\n");
17876 }
17877
dd65f45e
DL
17878 /* Route reflector client. */
17879 if (peergroup_af_flag_check(peer, afi, safi,
17880 PEER_FLAG_REFLECTOR_CLIENT)) {
17881 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17882 }
17883
17884 /* next-hop-self force */
17885 if (peergroup_af_flag_check(peer, afi, safi,
17886 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17887 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17888 }
17889
17890 /* next-hop-self */
17891 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17892 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17893 }
17894
17895 /* remove-private-AS */
17896 if (peergroup_af_flag_check(peer, afi, safi,
17897 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17898 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17899 addr);
17900 }
17901
17902 else if (peergroup_af_flag_check(peer, afi, safi,
17903 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17904 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17905 addr);
17906 }
17907
17908 else if (peergroup_af_flag_check(peer, afi, safi,
17909 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17910 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17911 }
17912
17913 else if (peergroup_af_flag_check(peer, afi, safi,
17914 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17915 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17916 }
17917
17918 /* as-override */
17919 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17920 vty_out(vty, " neighbor %s as-override\n", addr);
17921 }
17922
17923 /* send-community print. */
17924 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17925 PEER_FLAG_SEND_COMMUNITY);
17926 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17927 PEER_FLAG_SEND_EXT_COMMUNITY);
17928 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17929 PEER_FLAG_SEND_LARGE_COMMUNITY);
17930
17931 if (flag_scomm && flag_secomm && flag_slcomm) {
17932 vty_out(vty, " no neighbor %s send-community all\n", addr);
17933 } else {
17934 if (flag_scomm)
17935 vty_out(vty, " no neighbor %s send-community\n", addr);
17936 if (flag_secomm)
17937 vty_out(vty,
17938 " no neighbor %s send-community extended\n",
17939 addr);
17940
17941 if (flag_slcomm)
17942 vty_out(vty, " no neighbor %s send-community large\n",
17943 addr);
17944 }
17945
17946 /* Default information */
17947 if (peergroup_af_flag_check(peer, afi, safi,
17948 PEER_FLAG_DEFAULT_ORIGINATE)) {
17949 vty_out(vty, " neighbor %s default-originate", addr);
17950
17951 if (peer->default_rmap[afi][safi].name)
17952 vty_out(vty, " route-map %s",
17953 peer->default_rmap[afi][safi].name);
17954
17955 vty_out(vty, "\n");
17956 }
17957
17958 /* Soft reconfiguration inbound. */
17959 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17960 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17961 addr);
17962 }
17963
17964 /* maximum-prefix. */
17965 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 17966 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
17967 peer->pmax[afi][safi]);
17968
17969 if (peer->pmax_threshold[afi][safi]
17970 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17971 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17972 if (peer_af_flag_check(peer, afi, safi,
17973 PEER_FLAG_MAX_PREFIX_WARNING))
17974 vty_out(vty, " warning-only");
17975 if (peer->pmax_restart[afi][safi])
17976 vty_out(vty, " restart %u",
17977 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
17978 if (peer_af_flag_check(peer, afi, safi,
17979 PEER_FLAG_MAX_PREFIX_FORCE))
17980 vty_out(vty, " force");
dd65f45e
DL
17981
17982 vty_out(vty, "\n");
17983 }
17984
fde246e8
DA
17985 /* maximum-prefix-out */
17986 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 17987 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
17988 addr, peer->pmax_out[afi][safi]);
17989
dd65f45e
DL
17990 /* Route server client. */
17991 if (peergroup_af_flag_check(peer, afi, safi,
17992 PEER_FLAG_RSERVER_CLIENT)) {
17993 vty_out(vty, " neighbor %s route-server-client\n", addr);
17994 }
17995
17996 /* Nexthop-local unchanged. */
17997 if (peergroup_af_flag_check(peer, afi, safi,
17998 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17999 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
18000 }
18001
18002 /* allowas-in <1-10> */
18003 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
18004 if (peer_af_flag_check(peer, afi, safi,
18005 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
18006 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
18007 } else if (peer->allowas_in[afi][safi] == 3) {
18008 vty_out(vty, " neighbor %s allowas-in\n", addr);
18009 } else {
18010 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
18011 peer->allowas_in[afi][safi]);
18012 }
18013 }
18014
46dbf9d0
DA
18015 /* accept-own */
18016 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
18017 vty_out(vty, " neighbor %s accept-own\n", addr);
18018
01da2d26
DA
18019 /* soo */
18020 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
18021 char *soo_str = ecommunity_ecom2str(
18022 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
18023
18024 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
18025 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
18026 }
18027
dd65f45e
DL
18028 /* weight */
18029 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
18030 vty_out(vty, " neighbor %s weight %lu\n", addr,
18031 peer->weight[afi][safi]);
18032
18033 /* Filter. */
18034 bgp_config_write_filter(vty, peer, afi, safi);
18035
18036 /* atribute-unchanged. */
18037 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
18038 || (safi != SAFI_EVPN
18039 && peer_af_flag_check(peer, afi, safi,
18040 PEER_FLAG_NEXTHOP_UNCHANGED))
18041 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
18042
18043 if (!peer_group_active(peer)
18044 || peergroup_af_flag_check(peer, afi, safi,
18045 PEER_FLAG_AS_PATH_UNCHANGED)
18046 || peergroup_af_flag_check(peer, afi, safi,
18047 PEER_FLAG_NEXTHOP_UNCHANGED)
18048 || peergroup_af_flag_check(peer, afi, safi,
18049 PEER_FLAG_MED_UNCHANGED)) {
18050
18051 vty_out(vty,
18052 " neighbor %s attribute-unchanged%s%s%s\n",
18053 addr,
18054 peer_af_flag_check(peer, afi, safi,
18055 PEER_FLAG_AS_PATH_UNCHANGED)
18056 ? " as-path"
18057 : "",
18058 peer_af_flag_check(peer, afi, safi,
18059 PEER_FLAG_NEXTHOP_UNCHANGED)
18060 ? " next-hop"
18061 : "",
18062 peer_af_flag_check(peer, afi, safi,
18063 PEER_FLAG_MED_UNCHANGED)
18064 ? " med"
18065 : "");
18066 }
18067 }
18068}
18069
a486300b
PG
18070static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
18071 safi_t safi)
18072{
18073 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
18074 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
18075 vty_out(vty, " no bgp retain route-target all\n");
18076}
18077
dd65f45e
DL
18078/* Address family based peer configuration display. */
18079static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
18080 safi_t safi)
18081{
18082 struct peer *peer;
18083 struct peer_group *group;
18084 struct listnode *node, *nnode;
18085
18086
18087 vty_frame(vty, " !\n address-family ");
18088 if (afi == AFI_IP) {
18089 if (safi == SAFI_UNICAST)
18090 vty_frame(vty, "ipv4 unicast");
18091 else if (safi == SAFI_LABELED_UNICAST)
18092 vty_frame(vty, "ipv4 labeled-unicast");
18093 else if (safi == SAFI_MULTICAST)
18094 vty_frame(vty, "ipv4 multicast");
18095 else if (safi == SAFI_MPLS_VPN)
18096 vty_frame(vty, "ipv4 vpn");
18097 else if (safi == SAFI_ENCAP)
18098 vty_frame(vty, "ipv4 encap");
18099 else if (safi == SAFI_FLOWSPEC)
18100 vty_frame(vty, "ipv4 flowspec");
18101 } else if (afi == AFI_IP6) {
18102 if (safi == SAFI_UNICAST)
18103 vty_frame(vty, "ipv6 unicast");
18104 else if (safi == SAFI_LABELED_UNICAST)
18105 vty_frame(vty, "ipv6 labeled-unicast");
18106 else if (safi == SAFI_MULTICAST)
18107 vty_frame(vty, "ipv6 multicast");
18108 else if (safi == SAFI_MPLS_VPN)
18109 vty_frame(vty, "ipv6 vpn");
18110 else if (safi == SAFI_ENCAP)
18111 vty_frame(vty, "ipv6 encap");
18112 else if (safi == SAFI_FLOWSPEC)
18113 vty_frame(vty, "ipv6 flowspec");
18114 } else if (afi == AFI_L2VPN) {
18115 if (safi == SAFI_EVPN)
18116 vty_frame(vty, "l2vpn evpn");
18117 }
18118 vty_frame(vty, "\n");
18119
18120 bgp_config_write_distance(vty, bgp, afi, safi);
18121
18122 bgp_config_write_network(vty, bgp, afi, safi);
18123
18124 bgp_config_write_redistribute(vty, bgp, afi, safi);
18125
8a4e7fe6
DA
18126 /* BGP flag dampening. */
18127 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6c75f4b3 18128 bgp_config_write_damp(vty, afi, safi);
8a4e7fe6 18129
dd65f45e
DL
18130 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
18131 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
18132
18133 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
18134 /* Do not display doppelganger peers */
18135 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18136 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
18137 }
18138
18139 bgp_config_write_maxpaths(vty, bgp, afi, safi);
18140 bgp_config_write_table_map(vty, bgp, afi, safi);
18141
18142 if (safi == SAFI_EVPN)
18143 bgp_config_write_evpn_info(vty, bgp, afi, safi);
18144
18145 if (safi == SAFI_FLOWSPEC)
18146 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
18147
a486300b
PG
18148 if (safi == SAFI_MPLS_VPN)
18149 bgp_vpn_config_write(vty, bgp, afi, safi);
18150
dd65f45e
DL
18151 if (safi == SAFI_UNICAST) {
18152 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
18153 if (CHECK_FLAG(bgp->af_flags[afi][safi],
18154 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
18155
18156 vty_out(vty, " export vpn\n");
18157 }
18158 if (CHECK_FLAG(bgp->af_flags[afi][safi],
18159 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
18160
18161 vty_out(vty, " import vpn\n");
18162 }
18163 if (CHECK_FLAG(bgp->af_flags[afi][safi],
18164 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
18165 char *name;
18166
18167 for (ALL_LIST_ELEMENTS_RO(
18168 bgp->vpn_policy[afi].import_vrf, node,
18169 name))
18170 vty_out(vty, " import vrf %s\n", name);
18171 }
18172 }
18173
18174 vty_endframe(vty, " exit-address-family\n");
18175}
18176
18177int bgp_config_write(struct vty *vty)
18178{
18179 struct bgp *bgp;
18180 struct peer_group *group;
18181 struct peer *peer;
18182 struct listnode *node, *nnode;
18183 struct listnode *mnode, *mnnode;
b16bcbba
TA
18184 afi_t afi;
18185 safi_t safi;
efc9b57d 18186 uint32_t tovpn_sid_index = 0;
dd65f45e
DL
18187
18188 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
18189 vty_out(vty, "bgp route-map delay-timer %u\n",
18190 bm->rmap_update_timer);
18191
d70583f7
D
18192 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
18193 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
18194 if (bm->v_update_delay != bm->v_establish_wait)
18195 vty_out(vty, " %d", bm->v_establish_wait);
18196 vty_out(vty, "\n");
18197 }
18198
9acb67cb
DS
18199 if (bm->wait_for_fib)
18200 vty_out(vty, "bgp suppress-fib-pending\n");
18201
05bd726c 18202 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18203 vty_out(vty, "bgp graceful-shutdown\n");
18204
c163f297
DS
18205 /* No-RIB (Zebra) option flag configuration */
18206 if (bgp_option_check(BGP_OPT_NO_FIB))
18207 vty_out(vty, "bgp no-rib\n");
18208
870791a3
IR
18209 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
18210 vty_out(vty, "bgp send-extra-data zebra\n");
e46723a5 18211
425bd64b
PS
18212 /* BGP session DSCP value */
18213 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
18214 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
18215
a0b937de 18216 /* BGP InQ limit */
963b7ee4 18217 if (bm->inq_limit != BM_DEFAULT_Q_LIMIT)
a0b937de
SW
18218 vty_out(vty, "bgp input-queue-limit %u\n", bm->inq_limit);
18219
963b7ee4
DS
18220 if (bm->outq_limit != BM_DEFAULT_Q_LIMIT)
18221 vty_out(vty, "bgp output-queue-limit %u\n", bm->outq_limit);
18222
dd65f45e
DL
18223 /* BGP configuration. */
18224 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
18225
18226 /* skip all auto created vrf as they dont have user config */
18227 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
18228 continue;
18229
18230 /* Router bgp ASN */
9eb11997 18231 vty_out(vty, "router bgp %s", bgp->as_pretty);
dd65f45e
DL
18232
18233 if (bgp->name)
18234 vty_out(vty, " %s %s",
18235 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
18236 ? "view" : "vrf", bgp->name);
e55b0883
PG
18237 if (CHECK_FLAG(bgp->config, BGP_CONFIG_ASNOTATION))
18238 vty_out(vty, " as-notation %s",
18239 asn_mode2str(bgp->asnotation));
18240
dd65f45e
DL
18241 vty_out(vty, "\n");
18242
18243 /* BGP fast-external-failover. */
18244 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
18245 vty_out(vty, " no bgp fast-external-failover\n");
18246
18247 /* BGP router ID. */
3a6290bd 18248 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
18249 vty_out(vty, " bgp router-id %pI4\n",
18250 &bgp->router_id_static);
dd65f45e 18251
c208c586
S
18252 /* Suppress fib pending */
18253 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
18254 vty_out(vty, " bgp suppress-fib-pending\n");
18255
dd65f45e 18256 /* BGP log-neighbor-changes. */
892fedb6 18257 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 18258 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 18259 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
18260 CHECK_FLAG(bgp->flags,
18261 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
18262 ? ""
18263 : "no ");
18264
18265 /* BGP configuration. */
892fedb6 18266 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
18267 vty_out(vty, " bgp always-compare-med\n");
18268
18269 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
18270 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
18271 != SAVE_BGP_EBGP_REQUIRES_POLICY)
18272 vty_out(vty, " %sbgp ebgp-requires-policy\n",
18273 CHECK_FLAG(bgp->flags,
18274 BGP_FLAG_EBGP_REQUIRES_POLICY)
18275 ? ""
18276 : "no ");
dd65f45e 18277
cf1c7e30
PG
18278 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_IPV4_EXPLICIT_NULL) &&
18279 !!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_IPV6_EXPLICIT_NULL))
7ee70320 18280 vty_out(vty, " bgp labeled-unicast explicit-null\n");
cf1c7e30
PG
18281 else if (!!CHECK_FLAG(bgp->flags,
18282 BGP_FLAG_LU_IPV4_EXPLICIT_NULL))
18283 vty_out(vty,
18284 " bgp labeled-unicast ipv4-explicit-null\n");
18285 else if (!!CHECK_FLAG(bgp->flags,
18286 BGP_FLAG_LU_IPV6_EXPLICIT_NULL))
18287 vty_out(vty,
18288 " bgp labeled-unicast ipv6-explicit-null\n");
7ee70320 18289
dd65f45e 18290 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 18291 if (bgp->reject_as_sets)
dd65f45e
DL
18292 vty_out(vty, " bgp reject-as-sets\n");
18293
2adac256
DA
18294 /* Suppress duplicate updates if the route actually not changed
18295 */
18296 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
18297 != SAVE_BGP_SUPPRESS_DUPLICATES)
18298 vty_out(vty, " %sbgp suppress-duplicates\n",
18299 CHECK_FLAG(bgp->flags,
18300 BGP_FLAG_SUPPRESS_DUPLICATES)
18301 ? ""
18302 : "no ");
18303
1ae314be
DA
18304 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
18305 */
18306 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
18307 SAVE_BGP_HARD_ADMIN_RESET)
18308 vty_out(vty, " %sbgp hard-administrative-reset\n",
18309 CHECK_FLAG(bgp->flags,
18310 BGP_FLAG_HARD_ADMIN_RESET)
18311 ? ""
18312 : "no ");
18313
b16bcbba
TA
18314 /* BGP default <afi>-<safi> */
18315 FOREACH_AFI_SAFI (afi, safi) {
18316 if (afi == AFI_IP && safi == SAFI_UNICAST) {
18317 if (!bgp->default_af[afi][safi])
18318 vty_out(vty, " no bgp default %s\n",
18319 get_bgp_default_af_flag(afi,
18320 safi));
18321 } else if (bgp->default_af[afi][safi])
18322 vty_out(vty, " bgp default %s\n",
18323 get_bgp_default_af_flag(afi, safi));
18324 }
e84c59af 18325
dd65f45e
DL
18326 /* BGP default local-preference. */
18327 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
18328 vty_out(vty, " bgp default local-preference %u\n",
18329 bgp->default_local_pref);
18330
18331 /* BGP default show-hostname */
892fedb6 18332 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 18333 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 18334 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 18335 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
18336 ? ""
18337 : "no ");
18338
aef999a2
DA
18339 /* BGP default show-nexthop-hostname */
18340 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18341 != SAVE_BGP_SHOW_HOSTNAME)
18342 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
18343 CHECK_FLAG(bgp->flags,
18344 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18345 ? ""
18346 : "no ");
18347
dd65f45e
DL
18348 /* BGP default subgroup-pkt-queue-max. */
18349 if (bgp->default_subgroup_pkt_queue_max
18350 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
18351 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
18352 bgp->default_subgroup_pkt_queue_max);
18353
18354 /* BGP client-to-client reflection. */
892fedb6 18355 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
18356 vty_out(vty, " no bgp client-to-client reflection\n");
18357
18358 /* BGP cluster ID. */
18359 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
18360 vty_out(vty, " bgp cluster-id %pI4\n",
18361 &bgp->cluster_id);
dd65f45e
DL
18362
18363 /* Disable ebgp connected nexthop check */
892fedb6 18364 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
18365 vty_out(vty,
18366 " bgp disable-ebgp-connected-route-check\n");
18367
18368 /* Confederation identifier*/
18369 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7e14d0fa
PG
18370 vty_out(vty, " bgp confederation identifier %s\n",
18371 bgp->confed_id_pretty);
dd65f45e
DL
18372
18373 /* Confederation peer */
18374 if (bgp->confed_peers_cnt > 0) {
18375 int i;
18376
18377 vty_out(vty, " bgp confederation peers");
18378
18379 for (i = 0; i < bgp->confed_peers_cnt; i++)
7e14d0fa
PG
18380 vty_out(vty, " %s",
18381 bgp->confed_peers[i].as_pretty);
dd65f45e
DL
18382
18383 vty_out(vty, "\n");
18384 }
18385
18386 /* BGP deterministic-med. */
892fedb6 18387 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 18388 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 18389 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
18390 CHECK_FLAG(bgp->flags,
18391 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
18392 ? ""
18393 : "no ");
18394
18395 /* BGP update-delay. */
18396 bgp_config_write_update_delay(vty, bgp);
18397
18398 if (bgp->v_maxmed_onstartup
18399 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
18400 vty_out(vty, " bgp max-med on-startup %u",
18401 bgp->v_maxmed_onstartup);
18402 if (bgp->maxmed_onstartup_value
18403 != BGP_MAXMED_VALUE_DEFAULT)
18404 vty_out(vty, " %u",
18405 bgp->maxmed_onstartup_value);
18406 vty_out(vty, "\n");
18407 }
18408 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
18409 vty_out(vty, " bgp max-med administrative");
18410 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
18411 vty_out(vty, " %u", bgp->maxmed_admin_value);
18412 vty_out(vty, "\n");
18413 }
18414
18415 /* write quanta */
18416 bgp_config_write_wpkt_quanta(vty, bgp);
18417 /* read quanta */
18418 bgp_config_write_rpkt_quanta(vty, bgp);
18419
18420 /* coalesce time */
18421 bgp_config_write_coalesce_time(vty, bgp);
18422
05bd726c 18423 /* BGP per-instance graceful-shutdown */
18424 /* BGP-wide settings and per-instance settings are mutually
18425 * exclusive.
18426 */
18427 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18428 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
18429 vty_out(vty, " bgp graceful-shutdown\n");
18430
8606be87
DA
18431 /* Long-lived Graceful Restart */
18432 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
18433 vty_out(vty,
18434 " bgp long-lived-graceful-restart stale-time %u\n",
18435 bgp->llgr_stale_time);
18436
dd65f45e
DL
18437 /* BGP graceful-restart. */
18438 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
18439 vty_out(vty,
18440 " bgp graceful-restart stalepath-time %u\n",
18441 bgp->stalepath_time);
cfd47646 18442
dd65f45e
DL
18443 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18444 vty_out(vty, " bgp graceful-restart restart-time %u\n",
18445 bgp->restart_time);
cfd47646 18446
f2ca5c5b
DA
18447 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
18448 SAVE_BGP_GRACEFUL_NOTIFICATION)
18449 vty_out(vty, " %sbgp graceful-restart notification\n",
18450 CHECK_FLAG(bgp->flags,
18451 BGP_FLAG_GRACEFUL_NOTIFICATION)
18452 ? ""
18453 : "no ");
18454
cfd47646 18455 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18456 vty_out(vty,
18457 " bgp graceful-restart select-defer-time %u\n",
18458 bgp->select_defer_time);
18459
18460 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
18461 vty_out(vty, " bgp graceful-restart\n");
18462
cfd47646 18463 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18464 vty_out(vty, " bgp graceful-restart-disable\n");
18465
dd65f45e 18466 /* BGP graceful-restart Preserve State F bit. */
892fedb6 18467 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
18468 vty_out(vty,
18469 " bgp graceful-restart preserve-fw-state\n");
18470
d1adb448
PG
18471 /* BGP TCP keepalive */
18472 bgp_config_tcp_keepalive(vty, bgp);
18473
dc95985f 18474 /* Stale timer for RIB */
18475 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18476 vty_out(vty,
18477 " bgp graceful-restart rib-stale-time %u\n",
18478 bgp->rib_stale_time);
18479
dd65f45e 18480 /* BGP bestpath method. */
892fedb6 18481 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 18482 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 18483 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
18484 vty_out(vty, " bgp bestpath as-path confed\n");
18485
892fedb6
DA
18486 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18487 if (CHECK_FLAG(bgp->flags,
18488 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
18489 vty_out(vty,
18490 " bgp bestpath as-path multipath-relax as-set\n");
18491 } else {
18492 vty_out(vty,
18493 " bgp bestpath as-path multipath-relax\n");
18494 }
18495 }
18496
892fedb6 18497 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
18498 vty_out(vty,
18499 " bgp route-reflector allow-outbound-policy\n");
18500 }
892fedb6 18501 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 18502 vty_out(vty, " bgp bestpath compare-routerid\n");
97a52c82
DA
18503 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP))
18504 vty_out(vty, " bgp bestpath aigp\n");
892fedb6
DA
18505 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18506 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 18507 vty_out(vty, " bgp bestpath med");
892fedb6 18508 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 18509 vty_out(vty, " confed");
892fedb6
DA
18510 if (CHECK_FLAG(bgp->flags,
18511 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
18512 vty_out(vty, " missing-as-worst");
18513 vty_out(vty, "\n");
18514 }
18515
ee88563a
JM
18516 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18517 vty_out(vty,
18518 " bgp bestpath peer-type multipath-relax\n");
18519
f7e1c681 18520 /* Link bandwidth handling. */
18521 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18522 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18523 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18524 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18525 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18526 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18527
dd65f45e 18528 /* BGP network import check. */
892fedb6 18529 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 18530 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 18531 vty_out(vty, " %sbgp network import-check\n",
892fedb6 18532 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
18533 ? ""
18534 : "no ");
18535
18536 /* BGP timers configuration. */
5d5393b9 18537 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 18538 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
18539 vty_out(vty, " timers bgp %u %u\n",
18540 bgp->default_keepalive, bgp->default_holdtime);
18541
b042667a
TI
18542 /* BGP minimum holdtime configuration. */
18543 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
18544 && bgp->default_min_holdtime != 0)
18545 vty_out(vty, " bgp minimum-holdtime %u\n",
18546 bgp->default_min_holdtime);
18547
389e4f92
QY
18548 /* Conditional advertisement timer configuration */
18549 if (bgp->condition_check_period
18550 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
18551 vty_out(vty,
18552 " bgp conditional-advertisement timer %u\n",
18553 bgp->condition_check_period);
18554
dd65f45e
DL
18555 /* peer-group */
18556 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18557 bgp_config_write_peer_global(vty, bgp, group->conf);
18558 }
18559
18560 /* Normal neighbor configuration. */
18561 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18562 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18563 bgp_config_write_peer_global(vty, bgp, peer);
18564 }
18565
18566 /* listen range and limit for dynamic BGP neighbors */
18567 bgp_config_write_listen(vty, bgp);
18568
18569 /*
18570 * BGP default autoshutdown neighbors
18571 *
18572 * This must be placed after any peer and peer-group
18573 * configuration, to avoid setting all peers to shutdown after
18574 * a daemon restart, which is undesired behavior. (see #2286)
18575 */
18576 if (bgp->autoshutdown)
18577 vty_out(vty, " bgp default shutdown\n");
18578
9cf59432
DS
18579 /* BGP instance administrative shutdown */
18580 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18581 vty_out(vty, " bgp shutdown\n");
18582
8666265e
DS
18583 if (bgp->allow_martian)
18584 vty_out(vty, " bgp allow-martian-nexthop\n");
18585
f852eb98
PG
18586 if (bgp->fast_convergence)
18587 vty_out(vty, " bgp fast-convergence\n");
18588
a0281b2e
HS
18589 if (bgp->srv6_enabled) {
18590 vty_frame(vty, " !\n segment-routing srv6\n");
96db4340 18591 if (strlen(bgp->srv6_locator_name))
a0281b2e
HS
18592 vty_out(vty, " locator %s\n",
18593 bgp->srv6_locator_name);
ff7c3ee1 18594 vty_endframe(vty, " exit\n");
a0281b2e
HS
18595 }
18596
efc9b57d
CS
18597 tovpn_sid_index = bgp->tovpn_sid_index;
18598 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
18599 vty_out(vty, " sid vpn per-vrf export auto\n");
18600 } else if (tovpn_sid_index != 0) {
18601 vty_out(vty, " sid vpn per-vrf export %d\n",
18602 tovpn_sid_index);
18603 }
a0281b2e 18604
dd65f45e
DL
18605 /* IPv4 unicast configuration. */
18606 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18607
18608 /* IPv4 multicast configuration. */
18609 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18610
18611 /* IPv4 labeled-unicast configuration. */
18612 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18613
18614 /* IPv4 VPN configuration. */
18615 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18616
18617 /* ENCAPv4 configuration. */
18618 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18619
18620 /* FLOWSPEC v4 configuration. */
18621 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18622
18623 /* IPv6 unicast configuration. */
18624 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18625
18626 /* IPv6 multicast configuration. */
18627 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18628
18629 /* IPv6 labeled-unicast configuration. */
18630 bgp_config_write_family(vty, bgp, AFI_IP6,
18631 SAFI_LABELED_UNICAST);
18632
18633 /* IPv6 VPN configuration. */
18634 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18635
18636 /* ENCAPv6 configuration. */
18637 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18638
18639 /* FLOWSPEC v6 configuration. */
18640 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18641
18642 /* EVPN configuration. */
18643 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18644
18645 hook_call(bgp_inst_config_write, bgp, vty);
18646
49e5a4a0 18647#ifdef ENABLE_BGP_VNC
dd65f45e
DL
18648 bgp_rfapi_cfg_write(vty, bgp);
18649#endif
18650
07679ad9 18651 vty_out(vty, "exit\n");
dd65f45e
DL
18652 vty_out(vty, "!\n");
18653 }
18654 return 0;
18655}
18656
ddb5b488 18657
718e3744 18658/* BGP node structure. */
d62a17ae 18659static struct cmd_node bgp_node = {
f4b8291f 18660 .name = "bgp",
62b346ee 18661 .node = BGP_NODE,
24389580 18662 .parent_node = CONFIG_NODE,
62b346ee 18663 .prompt = "%s(config-router)# ",
612c2c15 18664 .config_write = bgp_config_write,
718e3744 18665};
18666
d62a17ae 18667static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 18668 .name = "bgp ipv4 unicast",
62b346ee 18669 .node = BGP_IPV4_NODE,
24389580 18670 .parent_node = BGP_NODE,
62b346ee 18671 .prompt = "%s(config-router-af)# ",
dd2c81b8 18672 .no_xpath = true,
718e3744 18673};
18674
d62a17ae 18675static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 18676 .name = "bgp ipv4 multicast",
62b346ee 18677 .node = BGP_IPV4M_NODE,
24389580 18678 .parent_node = BGP_NODE,
62b346ee 18679 .prompt = "%s(config-router-af)# ",
dd2c81b8 18680 .no_xpath = true,
718e3744 18681};
18682
d62a17ae 18683static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 18684 .name = "bgp ipv4 labeled unicast",
62b346ee 18685 .node = BGP_IPV4L_NODE,
24389580 18686 .parent_node = BGP_NODE,
62b346ee 18687 .prompt = "%s(config-router-af)# ",
dd2c81b8 18688 .no_xpath = true,
f51bae9c
DS
18689};
18690
d62a17ae 18691static struct cmd_node bgp_ipv6_unicast_node = {
a17cfb3f 18692 .name = "bgp ipv6 unicast",
62b346ee 18693 .node = BGP_IPV6_NODE,
24389580 18694 .parent_node = BGP_NODE,
62b346ee 18695 .prompt = "%s(config-router-af)# ",
dd2c81b8 18696 .no_xpath = true,
718e3744 18697};
18698
d62a17ae 18699static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 18700 .name = "bgp ipv6 multicast",
62b346ee 18701 .node = BGP_IPV6M_NODE,
24389580 18702 .parent_node = BGP_NODE,
62b346ee 18703 .prompt = "%s(config-router-af)# ",
dd2c81b8 18704 .no_xpath = true,
25ffbdc1 18705};
18706
d62a17ae 18707static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 18708 .name = "bgp ipv6 labeled unicast",
62b346ee 18709 .node = BGP_IPV6L_NODE,
24389580 18710 .parent_node = BGP_NODE,
62b346ee 18711 .prompt = "%s(config-router-af)# ",
dd2c81b8 18712 .no_xpath = true,
f51bae9c
DS
18713};
18714
62b346ee 18715static struct cmd_node bgp_vpnv4_node = {
f4b8291f 18716 .name = "bgp vpnv4",
62b346ee 18717 .node = BGP_VPNV4_NODE,
24389580 18718 .parent_node = BGP_NODE,
62b346ee 18719 .prompt = "%s(config-router-af)# ",
dd2c81b8 18720 .no_xpath = true,
62b346ee 18721};
6b0655a2 18722
62b346ee 18723static struct cmd_node bgp_vpnv6_node = {
f4b8291f 18724 .name = "bgp vpnv6",
62b346ee 18725 .node = BGP_VPNV6_NODE,
24389580 18726 .parent_node = BGP_NODE,
62b346ee 18727 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 18728 .no_xpath = true,
62b346ee 18729};
8ecd3266 18730
62b346ee 18731static struct cmd_node bgp_evpn_node = {
f4b8291f 18732 .name = "bgp evpn",
62b346ee 18733 .node = BGP_EVPN_NODE,
24389580 18734 .parent_node = BGP_NODE,
62b346ee 18735 .prompt = "%s(config-router-evpn)# ",
dd2c81b8 18736 .no_xpath = true,
62b346ee 18737};
4e0b7b6d 18738
62b346ee 18739static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 18740 .name = "bgp evpn vni",
62b346ee 18741 .node = BGP_EVPN_VNI_NODE,
24389580 18742 .parent_node = BGP_EVPN_NODE,
62b346ee 18743 .prompt = "%s(config-router-af-vni)# ",
62b346ee 18744};
90e60aa7 18745
62b346ee 18746static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 18747 .name = "bgp ipv4 flowspec",
62b346ee 18748 .node = BGP_FLOWSPECV4_NODE,
24389580 18749 .parent_node = BGP_NODE,
62b346ee 18750 .prompt = "%s(config-router-af)# ",
dd2c81b8 18751 .no_xpath = true,
62b346ee 18752};
7c40bf39 18753
62b346ee 18754static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 18755 .name = "bgp ipv6 flowspec",
62b346ee 18756 .node = BGP_FLOWSPECV6_NODE,
24389580 18757 .parent_node = BGP_NODE,
62b346ee 18758 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 18759 .no_xpath = true,
62b346ee 18760};
7c40bf39 18761
bfaab44d
HS
18762static struct cmd_node bgp_srv6_node = {
18763 .name = "bgp srv6",
18764 .node = BGP_SRV6_NODE,
18765 .parent_node = BGP_NODE,
18766 .prompt = "%s(config-router-srv6)# ",
18767};
18768
d62a17ae 18769static void community_list_vty(void);
1f8ae70b 18770
8c20061f
DA
18771static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18772{
18773 struct bgp *bgp;
18774 struct peer_group *group;
18775 struct listnode *lnbgp, *lnpeer;
18776
18777 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18778 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18779 vector_set(comps,
18780 XSTRDUP(MTYPE_COMPLETION, group->name));
18781 }
18782}
18783
18784static void bgp_ac_peer(vector comps, struct cmd_token *token)
b8a815e5 18785{
d62a17ae 18786 struct bgp *bgp;
18787 struct peer *peer;
d62a17ae 18788 struct listnode *lnbgp, *lnpeer;
b8a815e5 18789
d62a17ae 18790 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18791 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18792 /* only provide suggestions on the appropriate input
18793 * token type,
18794 * they'll otherwise show up multiple times */
18795 enum cmd_token_type match_type;
18796 char *name = peer->host;
d48ed3e0 18797
d62a17ae 18798 if (peer->conf_if) {
18799 match_type = VARIABLE_TKN;
18800 name = peer->conf_if;
18801 } else if (strchr(peer->host, ':'))
18802 match_type = IPV6_TKN;
18803 else
18804 match_type = IPV4_TKN;
d48ed3e0 18805
d62a17ae 18806 if (token->type != match_type)
18807 continue;
d48ed3e0 18808
d62a17ae 18809 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18810 }
d62a17ae 18811 }
b8a815e5
DL
18812}
18813
8c20061f
DA
18814static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18815{
18816 bgp_ac_peer(comps, token);
84de1483
DA
18817
18818 if (token->type == VARIABLE_TKN)
18819 bgp_ac_peergroup(comps, token);
8c20061f
DA
18820}
18821
b8a815e5 18822static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 18823 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18824 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 18825 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 18826 {.completions = NULL}};
18827
47a306a0
DS
18828static const struct cmd_variable_handler bgp_var_peergroup[] = {
18829 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18830 {.completions = NULL} };
18831
aa24a36a
DA
18832DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18833
e6685141 18834static struct event *t_bgp_cfg;
aa24a36a
DA
18835
18836bool bgp_config_inprocess(void)
18837{
5f6eaa9b 18838 return event_is_scheduled(t_bgp_cfg);
aa24a36a
DA
18839}
18840
e6685141 18841static void bgp_config_finish(struct event *t)
aa24a36a
DA
18842{
18843 struct listnode *node;
18844 struct bgp *bgp;
18845
18846 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18847 hook_call(bgp_config_end, bgp);
18848}
18849
18850static void bgp_config_start(void)
18851{
18852#define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
e16d030c 18853 EVENT_OFF(t_bgp_cfg);
907a2395
DS
18854 event_add_timer(bm->master, bgp_config_finish, NULL,
18855 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
aa24a36a
DA
18856}
18857
18858/* When we receive a hook the configuration is read,
18859 * we start a timer to make sure we postpone sending
18860 * EoR before route-maps are processed.
18861 * This is especially valid if using `bgp route-map delay-timer`.
18862 */
18863static void bgp_config_end(void)
18864{
18865#define BGP_POST_CONFIG_DELAY_SECONDS 1
18866 uint32_t bgp_post_config_delay =
5f6eaa9b 18867 event_is_scheduled(bm->t_rmap_update)
4f830a07 18868 ? event_timer_remain_second(bm->t_rmap_update)
aa24a36a
DA
18869 : BGP_POST_CONFIG_DELAY_SECONDS;
18870
18871 /* If BGP config processing thread isn't running, then
18872 * we can return and rely it's properly handled.
18873 */
18874 if (!bgp_config_inprocess())
18875 return;
18876
e16d030c 18877 EVENT_OFF(t_bgp_cfg);
aa24a36a
DA
18878
18879 /* Start a new timer to make sure we don't send EoR
18880 * before route-maps are processed.
18881 */
907a2395
DS
18882 event_add_timer(bm->master, bgp_config_finish, NULL,
18883 bgp_post_config_delay, &t_bgp_cfg);
aa24a36a
DA
18884}
18885
4cd690ae
PG
18886static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18887{
18888 int write = 0;
18889 struct interface *ifp;
18890 struct bgp_interface *iifp;
18891
18892 FOR_ALL_INTERFACES (vrf, ifp) {
18893 iifp = ifp->info;
18894 if (!iifp)
18895 continue;
18896
18897 if_vty_config_start(vty, ifp);
18898
18899 if (CHECK_FLAG(iifp->flags,
18900 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18901 vty_out(vty, " mpls bgp forwarding\n");
18902 write++;
18903 }
18904
18905 if_vty_config_end(vty);
18906 }
18907
18908 return write;
18909}
18910
18911/* Configuration write function for bgpd. */
18912static int config_write_interface(struct vty *vty)
18913{
18914 int write = 0;
18915 struct vrf *vrf = NULL;
18916
18917 /* Display all VRF aware OSPF interface configuration */
18918 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18919 write += config_write_interface_one(vty, vrf);
18920 }
18921
18922 return write;
18923}
18924
18925DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18926 "[no$no] mpls bgp forwarding",
18927 NO_STR MPLS_STR BGP_STR
18928 "Enable MPLS forwarding for eBGP directly connected peers\n")
18929{
18930 bool check;
18931 struct bgp_interface *iifp;
18932
18933 VTY_DECLVAR_CONTEXT(interface, ifp);
18934 iifp = ifp->info;
18935 if (!iifp) {
18936 vty_out(vty, "Interface %s not available\n", ifp->name);
18937 return CMD_WARNING_CONFIG_FAILED;
18938 }
18939 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18940 if (check != !no) {
18941 if (no)
18942 UNSET_FLAG(iifp->flags,
18943 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18944 else
18945 SET_FLAG(iifp->flags,
18946 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18947 /* trigger a nht update on eBGP sessions */
18948 if (if_is_operative(ifp))
18949 bgp_nht_ifp_up(ifp);
18950 }
18951 return CMD_SUCCESS;
18952}
18953
a0b937de
SW
18954DEFPY (bgp_inq_limit,
18955 bgp_inq_limit_cmd,
18956 "bgp input-queue-limit (1-4294967295)$limit",
18957 BGP_STR
18958 "Set the BGP Input Queue limit for all peers when message parsing\n"
18959 "Input-Queue limit\n")
18960{
18961 bm->inq_limit = limit;
18962
18963 return CMD_SUCCESS;
18964}
18965
18966DEFPY (no_bgp_inq_limit,
18967 no_bgp_inq_limit_cmd,
18968 "no bgp input-queue-limit [(1-4294967295)$limit]",
18969 NO_STR
18970 BGP_STR
18971 "Set the BGP Input Queue limit for all peers when message parsing\n"
18972 "Input-Queue limit\n")
18973{
963b7ee4
DS
18974 bm->inq_limit = BM_DEFAULT_Q_LIMIT;
18975
18976 return CMD_SUCCESS;
18977}
18978
18979DEFPY (bgp_outq_limit,
18980 bgp_outq_limit_cmd,
18981 "bgp output-queue-limit (1-4294967295)$limit",
18982 BGP_STR
18983 "Set the BGP Output Queue limit for all peers when message parsing\n"
18984 "Output-Queue limit\n")
18985{
18986 bm->outq_limit = limit;
a0b937de
SW
18987
18988 return CMD_SUCCESS;
18989}
18990
963b7ee4
DS
18991DEFPY (no_bgp_outq_limit,
18992 no_bgp_outq_limit_cmd,
18993 "no bgp output-queue-limit [(1-4294967295)$limit]",
18994 NO_STR
18995 BGP_STR
18996 "Set the BGP Output Queue limit for all peers when message parsing\n"
18997 "Output-Queue limit\n")
18998{
18999 bm->outq_limit = BM_DEFAULT_Q_LIMIT;
a0b937de
SW
19000
19001 return CMD_SUCCESS;
19002}
19003
963b7ee4 19004
4cd690ae
PG
19005/* Initialization of BGP interface. */
19006static void bgp_vty_if_init(void)
19007{
19008 /* Install interface node. */
19009 if_cmd_init(config_write_interface);
19010
19011 /* "mpls bgp forwarding" commands. */
19012 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
19013}
19014
d62a17ae 19015void bgp_vty_init(void)
19016{
19017 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 19018 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 19019
aa24a36a
DA
19020 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
19021
d62a17ae 19022 /* Install bgp top node. */
612c2c15
DL
19023 install_node(&bgp_node);
19024 install_node(&bgp_ipv4_unicast_node);
19025 install_node(&bgp_ipv4_multicast_node);
19026 install_node(&bgp_ipv4_labeled_unicast_node);
19027 install_node(&bgp_ipv6_unicast_node);
19028 install_node(&bgp_ipv6_multicast_node);
19029 install_node(&bgp_ipv6_labeled_unicast_node);
19030 install_node(&bgp_vpnv4_node);
19031 install_node(&bgp_vpnv6_node);
19032 install_node(&bgp_evpn_node);
19033 install_node(&bgp_evpn_vni_node);
19034 install_node(&bgp_flowspecv4_node);
19035 install_node(&bgp_flowspecv6_node);
bfaab44d 19036 install_node(&bgp_srv6_node);
d62a17ae 19037
19038 /* Install default VTY commands to new nodes. */
19039 install_default(BGP_NODE);
19040 install_default(BGP_IPV4_NODE);
19041 install_default(BGP_IPV4M_NODE);
19042 install_default(BGP_IPV4L_NODE);
19043 install_default(BGP_IPV6_NODE);
19044 install_default(BGP_IPV6M_NODE);
19045 install_default(BGP_IPV6L_NODE);
19046 install_default(BGP_VPNV4_NODE);
19047 install_default(BGP_VPNV6_NODE);
7c40bf39 19048 install_default(BGP_FLOWSPECV4_NODE);
19049 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 19050 install_default(BGP_EVPN_NODE);
19051 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 19052 install_default(BGP_SRV6_NODE);
d62a17ae 19053
a0b937de
SW
19054 /* "global bgp inq-limit command */
19055 install_element(CONFIG_NODE, &bgp_inq_limit_cmd);
19056 install_element(CONFIG_NODE, &no_bgp_inq_limit_cmd);
963b7ee4
DS
19057 install_element(CONFIG_NODE, &bgp_outq_limit_cmd);
19058 install_element(CONFIG_NODE, &no_bgp_outq_limit_cmd);
a0b937de 19059
8029b216
AK
19060 /* "bgp local-mac" hidden commands. */
19061 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
19062 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
19063
9acb67cb
DS
19064 /* "bgp suppress-fib-pending" global */
19065 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
19066
d62a17ae 19067 /* bgp route-map delay-timer commands. */
19068 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
19069 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
19070
8666265e
DS
19071 install_element(BGP_NODE, &bgp_allow_martian_cmd);
19072
f852eb98
PG
19073 /* bgp fast-convergence command */
19074 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
19075 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
19076
d70583f7
D
19077 /* global bgp update-delay command */
19078 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
19079 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
19080
05bd726c 19081 /* global bgp graceful-shutdown command */
19082 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
19083 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
19084
d62a17ae 19085 /* Dummy commands (Currently not supported) */
19086 install_element(BGP_NODE, &no_synchronization_cmd);
19087 install_element(BGP_NODE, &no_auto_summary_cmd);
19088
19089 /* "router bgp" commands. */
19090 install_element(CONFIG_NODE, &router_bgp_cmd);
19091
19092 /* "no router bgp" commands. */
19093 install_element(CONFIG_NODE, &no_router_bgp_cmd);
19094
425bd64b
PS
19095 /* "bgp session-dscp command */
19096 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
19097 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
19098
d62a17ae 19099 /* "bgp router-id" commands. */
19100 install_element(BGP_NODE, &bgp_router_id_cmd);
19101 install_element(BGP_NODE, &no_bgp_router_id_cmd);
19102
c208c586
S
19103 /* "bgp suppress-fib-pending" command */
19104 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
19105
d62a17ae 19106 /* "bgp cluster-id" commands. */
19107 install_element(BGP_NODE, &bgp_cluster_id_cmd);
19108 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
19109
c163f297
DS
19110 /* "bgp no-rib" commands. */
19111 install_element(CONFIG_NODE, &bgp_norib_cmd);
19112 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
19113
e46723a5
DS
19114 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
19115
d62a17ae 19116 /* "bgp confederation" commands. */
19117 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
19118 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
19119
19120 /* "bgp confederation peers" commands. */
19121 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
19122 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
19123
19124 /* bgp max-med command */
19125 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
19126 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
19127 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
19128 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
19129 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
19130
d864dd9e
EB
19131 /* "neighbor role" commands. */
19132 install_element(BGP_NODE, &neighbor_role_cmd);
19133 install_element(BGP_NODE, &neighbor_role_strict_cmd);
19134 install_element(BGP_NODE, &no_neighbor_role_cmd);
19135
97a52c82
DA
19136 /* "neighbor aigp" commands. */
19137 install_element(BGP_NODE, &neighbor_aigp_cmd);
19138
4f770cf1
DA
19139 /* "neighbor graceful-shutdown" command */
19140 install_element(BGP_NODE, &neighbor_graceful_shutdown_cmd);
19141
d62a17ae 19142 /* bgp disable-ebgp-connected-nh-check */
19143 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
19144 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
19145
19146 /* bgp update-delay command */
19147 install_element(BGP_NODE, &bgp_update_delay_cmd);
19148 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 19149
19150 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 19151 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 19152
19153 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
19154 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
19155
19156 /* "maximum-paths" commands. */
19157 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
19158 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
19159 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
19160 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
19161 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
19162 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
19163 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
19164 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
19165 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
19166 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
19167 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
19168 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
19169 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
19170 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
19171 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
19172
39edabac
PG
19173 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
19174 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
19175 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
19176 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
19177 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 19178 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
19179 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
19180 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
19181 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
19182 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
19183
19184 /* "timers bgp" commands. */
19185 install_element(BGP_NODE, &bgp_timers_cmd);
19186 install_element(BGP_NODE, &no_bgp_timers_cmd);
19187
b042667a
TI
19188 /* "minimum-holdtime" commands. */
19189 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
19190 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
19191
d62a17ae 19192 /* route-map delay-timer commands - per instance for backwards compat.
19193 */
19194 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
19195 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
19196
19197 /* "bgp client-to-client reflection" commands */
19198 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
19199 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
19200
19201 /* "bgp always-compare-med" commands */
19202 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
19203 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
19204
9dac9fc8
DA
19205 /* bgp ebgp-requires-policy */
19206 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
19207 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
19208
7ee70320
PG
19209 /* bgp labeled-unicast explicit-null */
19210 install_element(BGP_NODE, &bgp_lu_uses_explicit_null_cmd);
19211
2adac256
DA
19212 /* bgp suppress-duplicates */
19213 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
19214 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
19215
fb29348a
DA
19216 /* bgp reject-as-sets */
19217 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
19218 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
19219
d62a17ae 19220 /* "bgp deterministic-med" commands */
19221 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
19222 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
19223
055679e9 19224 /* "bgp graceful-restart" command */
36235319
QY
19225 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
19226 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 19227
19228 /* "bgp graceful-restart-disable" command */
36235319
QY
19229 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
19230 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 19231
19232 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
19233 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
19234 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 19235
19236 /* "neighbor a:b:c:d graceful-restart-disable" command */
19237 install_element(BGP_NODE,
19238 &bgp_neighbor_graceful_restart_disable_set_cmd);
19239 install_element(BGP_NODE,
19240 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
19241
19242 /* "neighbor a:b:c:d graceful-restart-helper" command */
19243 install_element(BGP_NODE,
19244 &bgp_neighbor_graceful_restart_helper_set_cmd);
19245 install_element(BGP_NODE,
19246 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
19247
d62a17ae 19248 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
19249 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
19250 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
19251 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 19252 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 19253 install_element(BGP_NODE,
19254 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 19255 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
19256 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
f2ca5c5b 19257 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
d62a17ae 19258
d6e3c15b 19259 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
19260 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 19261 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
19262 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 19263
7f323236
DW
19264 /* "bgp graceful-shutdown" commands */
19265 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
19266 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
19267
1ae314be
DA
19268 /* "bgp hard-administrative-reset" commands */
19269 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
19270
8606be87
DA
19271 /* "bgp long-lived-graceful-restart" commands */
19272 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
19273 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
19274
d62a17ae 19275 /* "bgp fast-external-failover" commands */
19276 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
19277 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
19278
97a52c82
DA
19279 /* "bgp bestpath aigp" commands */
19280 install_element(BGP_NODE, &bgp_bestpath_aigp_cmd);
19281
d62a17ae 19282 /* "bgp bestpath compare-routerid" commands */
19283 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
19284 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
19285
19286 /* "bgp bestpath as-path ignore" commands */
19287 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
19288 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
19289
19290 /* "bgp bestpath as-path confed" commands */
19291 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
19292 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
19293
19294 /* "bgp bestpath as-path multipath-relax" commands */
19295 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
19296 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
19297
ee88563a
JM
19298 /* "bgp bestpath peer-type multipath-relax" commands */
19299 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
19300 install_element(BGP_NODE,
19301 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
19302
d62a17ae 19303 /* "bgp log-neighbor-changes" commands */
19304 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
19305 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
19306
19307 /* "bgp bestpath med" commands */
19308 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
19309 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
19310
f7e1c681 19311 /* "bgp bestpath bandwidth" commands */
19312 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 19313 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 19314
b16bcbba
TA
19315 /* "no bgp default <afi>-<safi>" commands. */
19316 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
e84c59af 19317
d62a17ae 19318 /* "bgp network import-check" commands. */
19319 install_element(BGP_NODE, &bgp_network_import_check_cmd);
19320 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
19321 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
19322
19323 /* "bgp default local-preference" commands. */
19324 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
19325 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
19326
19327 /* bgp default show-hostname */
19328 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
19329 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
19330
aef999a2
DA
19331 /* bgp default show-nexthop-hostname */
19332 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
19333 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
19334
d62a17ae 19335 /* "bgp default subgroup-pkt-queue-max" commands. */
19336 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
19337 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
19338
19339 /* bgp ibgp-allow-policy-mods command */
19340 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
19341 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
19342
19343 /* "bgp listen limit" commands. */
19344 install_element(BGP_NODE, &bgp_listen_limit_cmd);
19345 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
19346
19347 /* "bgp listen range" commands. */
19348 install_element(BGP_NODE, &bgp_listen_range_cmd);
19349 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
19350
8175f54a 19351 /* "bgp default shutdown" command */
f26845f9 19352 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
19353
19354 /* "bgp shutdown" commands */
19355 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 19356 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 19357 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 19358 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 19359
d62a17ae 19360 /* "neighbor remote-as" commands. */
19361 install_element(BGP_NODE, &neighbor_remote_as_cmd);
19362 install_element(BGP_NODE, &neighbor_interface_config_cmd);
19363 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
19364 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
19365 install_element(BGP_NODE,
19366 &neighbor_interface_v6only_config_remote_as_cmd);
19367 install_element(BGP_NODE, &no_neighbor_cmd);
19368 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
19369
19370 /* "neighbor peer-group" commands. */
19371 install_element(BGP_NODE, &neighbor_peer_group_cmd);
19372 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
19373 install_element(BGP_NODE,
19374 &no_neighbor_interface_peer_group_remote_as_cmd);
19375
19376 /* "neighbor local-as" commands. */
19377 install_element(BGP_NODE, &neighbor_local_as_cmd);
19378 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
19379 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
19380 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
19381
19382 /* "neighbor solo" commands. */
19383 install_element(BGP_NODE, &neighbor_solo_cmd);
19384 install_element(BGP_NODE, &no_neighbor_solo_cmd);
19385
19386 /* "neighbor password" commands. */
19387 install_element(BGP_NODE, &neighbor_password_cmd);
19388 install_element(BGP_NODE, &no_neighbor_password_cmd);
19389
19390 /* "neighbor activate" commands. */
19391 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
19392 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
19393 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
19394 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
19395 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
19396 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
19397 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
19398 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
19399 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 19400 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
19401 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 19402 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
19403
19404 /* "no neighbor activate" commands. */
19405 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
19406 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
19407 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
19408 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
19409 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
19410 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
19411 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
19412 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
19413 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 19414 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
19415 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 19416 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
19417
19418 /* "neighbor peer-group" set commands. */
19419 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
19420 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19421 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
19422 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19423 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
19424 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
19425 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19426 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 19427 install_element(BGP_FLOWSPECV4_NODE,
19428 &neighbor_set_peer_group_hidden_cmd);
19429 install_element(BGP_FLOWSPECV6_NODE,
19430 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 19431
19432 /* "no neighbor peer-group unset" commands. */
19433 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
19434 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19435 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19436 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19437 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19438 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19439 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19440 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 19441 install_element(BGP_FLOWSPECV4_NODE,
19442 &no_neighbor_set_peer_group_hidden_cmd);
19443 install_element(BGP_FLOWSPECV6_NODE,
19444 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 19445
19446 /* "neighbor softreconfiguration inbound" commands.*/
19447 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
19448 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
19449 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
19450 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19451 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
19452 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19453 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
19454 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19455 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
19456 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19457 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
19458 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19459 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
19460 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19461 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
19462 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19463 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
19464 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 19465 install_element(BGP_FLOWSPECV4_NODE,
19466 &neighbor_soft_reconfiguration_cmd);
19467 install_element(BGP_FLOWSPECV4_NODE,
19468 &no_neighbor_soft_reconfiguration_cmd);
19469 install_element(BGP_FLOWSPECV6_NODE,
19470 &neighbor_soft_reconfiguration_cmd);
19471 install_element(BGP_FLOWSPECV6_NODE,
19472 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
19473 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
19474 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 19475
19476 /* "neighbor attribute-unchanged" commands. */
19477 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
19478 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
19479 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
19480 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
19481 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
19482 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
19483 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
19484 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
19485 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
19486 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
19487 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
19488 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
19489 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
19490 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
19491 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
19492 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
19493 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
19494 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
19495
19496 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
19497 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
19498
b8ad84d2
PG
19499 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
19500 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
19501 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
19502 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
19503
d62a17ae 19504 /* "nexthop-local unchanged" commands */
19505 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
19506 install_element(BGP_IPV6_NODE,
19507 &no_neighbor_nexthop_local_unchanged_cmd);
19508
19509 /* "neighbor next-hop-self" commands. */
19510 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
19511 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
19512 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
19513 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
19514 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
19515 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
19516 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
19517 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
19518 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
19519 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
19520 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
19521 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
19522 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
19523 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
19524 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
19525 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
19526 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
19527 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
19528 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
19529 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 19530
19531 /* "neighbor next-hop-self force" commands. */
19532 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
19533 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
19534 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19535 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19536 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
19537 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19538 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19539 install_element(BGP_IPV4_NODE,
19540 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19541 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
19542 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19543 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19544 install_element(BGP_IPV4M_NODE,
19545 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19546 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
19547 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19548 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19549 install_element(BGP_IPV4L_NODE,
19550 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19551 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
19552 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19553 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19554 install_element(BGP_IPV6_NODE,
19555 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19556 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
19557 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19558 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19559 install_element(BGP_IPV6M_NODE,
19560 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19561 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
19562 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19563 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19564 install_element(BGP_IPV6L_NODE,
19565 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19566 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
19567 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19568 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19569 install_element(BGP_VPNV4_NODE,
19570 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19571 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
19572 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19573 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19574 install_element(BGP_VPNV6_NODE,
19575 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
19576 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
19577 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 19578
19579 /* "neighbor as-override" commands. */
19580 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
19581 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
19582 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
19583 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
19584 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
19585 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
19586 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
19587 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
19588 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
19589 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
19590 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
19591 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
19592 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
19593 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
19594 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
19595 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
19596 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
19597 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
19598
19599 /* "neighbor remove-private-AS" commands. */
19600 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
19601 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
19602 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
19603 install_element(BGP_NODE,
19604 &no_neighbor_remove_private_as_all_hidden_cmd);
19605 install_element(BGP_NODE,
19606 &neighbor_remove_private_as_replace_as_hidden_cmd);
19607 install_element(BGP_NODE,
19608 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
19609 install_element(BGP_NODE,
19610 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
19611 install_element(
19612 BGP_NODE,
19613 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
19614 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
19615 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
19616 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
19617 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19618 install_element(BGP_IPV4_NODE,
19619 &neighbor_remove_private_as_replace_as_cmd);
19620 install_element(BGP_IPV4_NODE,
19621 &no_neighbor_remove_private_as_replace_as_cmd);
19622 install_element(BGP_IPV4_NODE,
19623 &neighbor_remove_private_as_all_replace_as_cmd);
19624 install_element(BGP_IPV4_NODE,
19625 &no_neighbor_remove_private_as_all_replace_as_cmd);
19626 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
19627 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
19628 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
19629 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
19630 install_element(BGP_IPV4M_NODE,
19631 &neighbor_remove_private_as_replace_as_cmd);
19632 install_element(BGP_IPV4M_NODE,
19633 &no_neighbor_remove_private_as_replace_as_cmd);
19634 install_element(BGP_IPV4M_NODE,
19635 &neighbor_remove_private_as_all_replace_as_cmd);
19636 install_element(BGP_IPV4M_NODE,
19637 &no_neighbor_remove_private_as_all_replace_as_cmd);
19638 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
19639 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
19640 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
19641 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
19642 install_element(BGP_IPV4L_NODE,
19643 &neighbor_remove_private_as_replace_as_cmd);
19644 install_element(BGP_IPV4L_NODE,
19645 &no_neighbor_remove_private_as_replace_as_cmd);
19646 install_element(BGP_IPV4L_NODE,
19647 &neighbor_remove_private_as_all_replace_as_cmd);
19648 install_element(BGP_IPV4L_NODE,
19649 &no_neighbor_remove_private_as_all_replace_as_cmd);
19650 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
19651 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
19652 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
19653 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19654 install_element(BGP_IPV6_NODE,
19655 &neighbor_remove_private_as_replace_as_cmd);
19656 install_element(BGP_IPV6_NODE,
19657 &no_neighbor_remove_private_as_replace_as_cmd);
19658 install_element(BGP_IPV6_NODE,
19659 &neighbor_remove_private_as_all_replace_as_cmd);
19660 install_element(BGP_IPV6_NODE,
19661 &no_neighbor_remove_private_as_all_replace_as_cmd);
19662 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
19663 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
19664 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
19665 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
19666 install_element(BGP_IPV6M_NODE,
19667 &neighbor_remove_private_as_replace_as_cmd);
19668 install_element(BGP_IPV6M_NODE,
19669 &no_neighbor_remove_private_as_replace_as_cmd);
19670 install_element(BGP_IPV6M_NODE,
19671 &neighbor_remove_private_as_all_replace_as_cmd);
19672 install_element(BGP_IPV6M_NODE,
19673 &no_neighbor_remove_private_as_all_replace_as_cmd);
19674 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19675 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19676 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19677 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19678 install_element(BGP_IPV6L_NODE,
19679 &neighbor_remove_private_as_replace_as_cmd);
19680 install_element(BGP_IPV6L_NODE,
19681 &no_neighbor_remove_private_as_replace_as_cmd);
19682 install_element(BGP_IPV6L_NODE,
19683 &neighbor_remove_private_as_all_replace_as_cmd);
19684 install_element(BGP_IPV6L_NODE,
19685 &no_neighbor_remove_private_as_all_replace_as_cmd);
19686 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19687 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19688 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19689 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19690 install_element(BGP_VPNV4_NODE,
19691 &neighbor_remove_private_as_replace_as_cmd);
19692 install_element(BGP_VPNV4_NODE,
19693 &no_neighbor_remove_private_as_replace_as_cmd);
19694 install_element(BGP_VPNV4_NODE,
19695 &neighbor_remove_private_as_all_replace_as_cmd);
19696 install_element(BGP_VPNV4_NODE,
19697 &no_neighbor_remove_private_as_all_replace_as_cmd);
19698 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19699 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19700 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19701 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19702 install_element(BGP_VPNV6_NODE,
19703 &neighbor_remove_private_as_replace_as_cmd);
19704 install_element(BGP_VPNV6_NODE,
19705 &no_neighbor_remove_private_as_replace_as_cmd);
19706 install_element(BGP_VPNV6_NODE,
19707 &neighbor_remove_private_as_all_replace_as_cmd);
19708 install_element(BGP_VPNV6_NODE,
19709 &no_neighbor_remove_private_as_all_replace_as_cmd);
19710
19711 /* "neighbor send-community" commands.*/
19712 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19713 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19714 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19715 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19716 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19717 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19718 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19719 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19720 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19721 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19722 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19723 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19724 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19725 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19726 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19727 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19728 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19729 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19730 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19731 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19732 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19733 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19734 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19735 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19736 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19737 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19738 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19739 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19740 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19741 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19742 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19743 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19744 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19745 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19746 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19747 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19748
19749 /* "neighbor route-reflector" commands.*/
19750 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19751 install_element(BGP_NODE,
19752 &no_neighbor_route_reflector_client_hidden_cmd);
19753 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19754 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19755 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19756 install_element(BGP_IPV4M_NODE,
19757 &no_neighbor_route_reflector_client_cmd);
19758 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19759 install_element(BGP_IPV4L_NODE,
19760 &no_neighbor_route_reflector_client_cmd);
19761 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19762 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19763 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19764 install_element(BGP_IPV6M_NODE,
19765 &no_neighbor_route_reflector_client_cmd);
19766 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19767 install_element(BGP_IPV6L_NODE,
19768 &no_neighbor_route_reflector_client_cmd);
19769 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19770 install_element(BGP_VPNV4_NODE,
19771 &no_neighbor_route_reflector_client_cmd);
19772 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19773 install_element(BGP_VPNV6_NODE,
19774 &no_neighbor_route_reflector_client_cmd);
7c40bf39 19775 install_element(BGP_FLOWSPECV4_NODE,
19776 &neighbor_route_reflector_client_cmd);
19777 install_element(BGP_FLOWSPECV4_NODE,
19778 &no_neighbor_route_reflector_client_cmd);
19779 install_element(BGP_FLOWSPECV6_NODE,
19780 &neighbor_route_reflector_client_cmd);
19781 install_element(BGP_FLOWSPECV6_NODE,
19782 &no_neighbor_route_reflector_client_cmd);
d62a17ae 19783 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19784 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19785
19786 /* "neighbor route-server" commands.*/
19787 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19788 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19789 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19790 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19791 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19792 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19793 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19794 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19795 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19796 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19797 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19798 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19799 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19800 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19801 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19802 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19803 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19804 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
19805 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19806 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 19807 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19808 install_element(BGP_FLOWSPECV4_NODE,
19809 &no_neighbor_route_server_client_cmd);
19810 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19811 install_element(BGP_FLOWSPECV6_NODE,
19812 &no_neighbor_route_server_client_cmd);
d62a17ae 19813
7c0e4312
DA
19814 /* "neighbor disable-addpath-rx" commands. */
19815 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19816 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19817 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19818 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19819 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19820 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19821 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19822 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19823 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19824 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19825 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19826 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19827 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19828 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19829 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19830 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19831
d62a17ae 19832 /* "neighbor addpath-tx-all-paths" commands.*/
19833 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19834 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19835 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19836 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19837 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19838 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19839 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19840 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19841 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19842 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19843 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19844 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19845 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19846 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19847 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19848 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19849 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19850 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19851
19852 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19853 install_element(BGP_NODE,
19854 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19855 install_element(BGP_NODE,
19856 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19857 install_element(BGP_IPV4_NODE,
19858 &neighbor_addpath_tx_bestpath_per_as_cmd);
19859 install_element(BGP_IPV4_NODE,
19860 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19861 install_element(BGP_IPV4M_NODE,
19862 &neighbor_addpath_tx_bestpath_per_as_cmd);
19863 install_element(BGP_IPV4M_NODE,
19864 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19865 install_element(BGP_IPV4L_NODE,
19866 &neighbor_addpath_tx_bestpath_per_as_cmd);
19867 install_element(BGP_IPV4L_NODE,
19868 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19869 install_element(BGP_IPV6_NODE,
19870 &neighbor_addpath_tx_bestpath_per_as_cmd);
19871 install_element(BGP_IPV6_NODE,
19872 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19873 install_element(BGP_IPV6M_NODE,
19874 &neighbor_addpath_tx_bestpath_per_as_cmd);
19875 install_element(BGP_IPV6M_NODE,
19876 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19877 install_element(BGP_IPV6L_NODE,
19878 &neighbor_addpath_tx_bestpath_per_as_cmd);
19879 install_element(BGP_IPV6L_NODE,
19880 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19881 install_element(BGP_VPNV4_NODE,
19882 &neighbor_addpath_tx_bestpath_per_as_cmd);
19883 install_element(BGP_VPNV4_NODE,
19884 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19885 install_element(BGP_VPNV6_NODE,
19886 &neighbor_addpath_tx_bestpath_per_as_cmd);
19887 install_element(BGP_VPNV6_NODE,
19888 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19889
2b31007c
RZ
19890 /* "neighbor sender-as-path-loop-detection" commands. */
19891 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19892 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19893
a5c6a9b1
DA
19894 /* "neighbor path-attribute discard" commands. */
19895 install_element(BGP_NODE, &neighbor_path_attribute_discard_cmd);
b986d7f4 19896 install_element(BGP_NODE, &no_neighbor_path_attribute_discard_cmd);
a5c6a9b1 19897
e2863b4f
DA
19898 /* "neighbor path-attribute treat-as-withdraw" commands. */
19899 install_element(BGP_NODE,
19900 &neighbor_path_attribute_treat_as_withdraw_cmd);
19901 install_element(BGP_NODE,
19902 &no_neighbor_path_attribute_treat_as_withdraw_cmd);
19903
d62a17ae 19904 /* "neighbor passive" commands. */
19905 install_element(BGP_NODE, &neighbor_passive_cmd);
19906 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19907
19908
19909 /* "neighbor shutdown" commands. */
19910 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19911 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19912 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19913 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
19914 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19915 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 19916
19917 /* "neighbor capability extended-nexthop" commands.*/
19918 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19919 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19920
234f6fd4
DA
19921 /* "neighbor capability software-version" commands.*/
19922 install_element(BGP_NODE, &neighbor_capability_software_version_cmd);
19923
d62a17ae 19924 /* "neighbor capability orf prefix-list" commands.*/
19925 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19926 install_element(BGP_NODE,
19927 &no_neighbor_capability_orf_prefix_hidden_cmd);
19928 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19929 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19930 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19931 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19932 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19933 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19934 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19935 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19936 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19937 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19938 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19939 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19940
19941 /* "neighbor capability dynamic" commands.*/
19942 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19943 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19944
19945 /* "neighbor dont-capability-negotiate" commands. */
19946 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19947 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19948
19949 /* "neighbor ebgp-multihop" commands. */
19950 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19951 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19952 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19953
19954 /* "neighbor disable-connected-check" commands. */
19955 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19956 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19957
7ab294ea
DA
19958 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19959 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19960 install_element(BGP_NODE,
19961 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
27aa23a4 19962
d08c0c80
DA
19963 /* "neighbor extended-optional-parameters" commands. */
19964 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19965 install_element(BGP_NODE,
19966 &no_neighbor_extended_optional_parameters_cmd);
19967
47cbc09b
PM
19968 /* "neighbor enforce-first-as" commands. */
19969 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19970 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19971
d62a17ae 19972 /* "neighbor description" commands. */
19973 install_element(BGP_NODE, &neighbor_description_cmd);
19974 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 19975 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 19976
19977 /* "neighbor update-source" commands. "*/
19978 install_element(BGP_NODE, &neighbor_update_source_cmd);
19979 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19980
19981 /* "neighbor default-originate" commands. */
19982 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19983 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19984 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19985 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19986 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19987 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19988 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19989 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19990 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19991 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19992 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19993 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19994 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19995 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19996 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19997 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19998 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19999 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
20000 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
20001 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
20002 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
20003
20004 /* "neighbor port" commands. */
20005 install_element(BGP_NODE, &neighbor_port_cmd);
20006 install_element(BGP_NODE, &no_neighbor_port_cmd);
20007
20008 /* "neighbor weight" commands. */
20009 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
20010 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
20011
20012 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
20013 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
20014 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
20015 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
20016 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
20017 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
20018 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
20019 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
20020 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
20021 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
20022 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
20023 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
20024 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
20025 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
20026 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
20027 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
20028
20029 /* "neighbor override-capability" commands. */
20030 install_element(BGP_NODE, &neighbor_override_capability_cmd);
20031 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
20032
20033 /* "neighbor strict-capability-match" commands. */
20034 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
20035 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
20036
20037 /* "neighbor timers" commands. */
20038 install_element(BGP_NODE, &neighbor_timers_cmd);
20039 install_element(BGP_NODE, &no_neighbor_timers_cmd);
20040
20041 /* "neighbor timers connect" commands. */
20042 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
20043 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
20044
d43114f3
DS
20045 /* "neighbor timers delayopen" commands. */
20046 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
20047 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
20048
d62a17ae 20049 /* "neighbor advertisement-interval" commands. */
20050 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
20051 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
20052
20053 /* "neighbor interface" commands. */
20054 install_element(BGP_NODE, &neighbor_interface_cmd);
20055 install_element(BGP_NODE, &no_neighbor_interface_cmd);
20056
20057 /* "neighbor distribute" commands. */
20058 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
20059 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
20060 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
20061 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
20062 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
20063 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
20064 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
20065 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
20066 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
20067 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
20068 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
20069 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
20070 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
20071 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
20072 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
20073 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
20074 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
20075 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
20076
20077 /* "neighbor prefix-list" commands. */
20078 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
642ef664 20079 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
d62a17ae 20080 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
642ef664 20081 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20082 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
642ef664 20083 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20084 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
642ef664 20085 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20086 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
642ef664 20087 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20088 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
642ef664 20089 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20090 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
642ef664 20091 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20092 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
642ef664 20093 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20094 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
642ef664 20095 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 20096 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
642ef664 20097 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 20098 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
642ef664 20099 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20100
20101 /* "neighbor filter-list" commands. */
20102 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
20103 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
20104 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
20105 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
20106 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
20107 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
20108 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
20109 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
20110 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
20111 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
20112 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
20113 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
20114 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
20115 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
20116 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
20117 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
20118 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
20119 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 20120 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
20121 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
20122 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
20123 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 20124
20125 /* "neighbor route-map" commands. */
d6d7ed37
IR
20126 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
20127 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
d62a17ae 20128 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
0ea8d871 20129 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20130 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
0ea8d871 20131 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20132 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
0ea8d871 20133 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20134 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
0ea8d871 20135 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20136 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
0ea8d871 20137 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20138 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
0ea8d871 20139 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20140 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
0ea8d871 20141 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20142 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
0ea8d871 20143 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 20144 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
0ea8d871 20145 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
7c40bf39 20146 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
0ea8d871 20147 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549 20148 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
0ea8d871 20149 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20150
20151 /* "neighbor unsuppress-map" commands. */
20152 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
20153 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
20154 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
20155 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
20156 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
20157 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
20158 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
20159 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
20160 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
20161 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
20162 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
20163 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
20164 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
20165 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
20166 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
20167 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
20168 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
20169 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
20170
7f7940e6 20171 /* "neighbor advertise-map" commands. */
389e4f92 20172 install_element(BGP_NODE, &bgp_condadv_period_cmd);
7f7940e6 20173 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 20174 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20175 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20176 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20177 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20178 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20179 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20180 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20181 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20182
fde246e8
DA
20183 /* neighbor maximum-prefix-out commands. */
20184 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
20185 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
20186 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
20187 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
20188 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
20189 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
20190 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
20191 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
20192 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
20193 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
20194 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
20195 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
20196 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
20197 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
20198 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
20199 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
20200 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
20201 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
20202
d62a17ae 20203 /* "neighbor maximum-prefix" commands. */
20204 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
20205 install_element(BGP_NODE,
20206 &neighbor_maximum_prefix_threshold_hidden_cmd);
20207 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
20208 install_element(BGP_NODE,
20209 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
20210 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
20211 install_element(BGP_NODE,
20212 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
20213 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
20214 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
20215 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
20216 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
20217 install_element(BGP_IPV4_NODE,
20218 &neighbor_maximum_prefix_threshold_warning_cmd);
20219 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
20220 install_element(BGP_IPV4_NODE,
20221 &neighbor_maximum_prefix_threshold_restart_cmd);
20222 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
20223 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
20224 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
20225 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
20226 install_element(BGP_IPV4M_NODE,
20227 &neighbor_maximum_prefix_threshold_warning_cmd);
20228 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
20229 install_element(BGP_IPV4M_NODE,
20230 &neighbor_maximum_prefix_threshold_restart_cmd);
20231 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
20232 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
20233 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
20234 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
20235 install_element(BGP_IPV4L_NODE,
20236 &neighbor_maximum_prefix_threshold_warning_cmd);
20237 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
20238 install_element(BGP_IPV4L_NODE,
20239 &neighbor_maximum_prefix_threshold_restart_cmd);
20240 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
20241 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
20242 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
20243 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
20244 install_element(BGP_IPV6_NODE,
20245 &neighbor_maximum_prefix_threshold_warning_cmd);
20246 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
20247 install_element(BGP_IPV6_NODE,
20248 &neighbor_maximum_prefix_threshold_restart_cmd);
20249 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
20250 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
20251 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
20252 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
20253 install_element(BGP_IPV6M_NODE,
20254 &neighbor_maximum_prefix_threshold_warning_cmd);
20255 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
20256 install_element(BGP_IPV6M_NODE,
20257 &neighbor_maximum_prefix_threshold_restart_cmd);
20258 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
20259 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
20260 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
20261 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
20262 install_element(BGP_IPV6L_NODE,
20263 &neighbor_maximum_prefix_threshold_warning_cmd);
20264 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
20265 install_element(BGP_IPV6L_NODE,
20266 &neighbor_maximum_prefix_threshold_restart_cmd);
20267 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
20268 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
20269 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
20270 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
20271 install_element(BGP_VPNV4_NODE,
20272 &neighbor_maximum_prefix_threshold_warning_cmd);
20273 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
20274 install_element(BGP_VPNV4_NODE,
20275 &neighbor_maximum_prefix_threshold_restart_cmd);
20276 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
20277 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
20278 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
20279 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
20280 install_element(BGP_VPNV6_NODE,
20281 &neighbor_maximum_prefix_threshold_warning_cmd);
20282 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
20283 install_element(BGP_VPNV6_NODE,
20284 &neighbor_maximum_prefix_threshold_restart_cmd);
20285 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
20286
20287 /* "neighbor allowas-in" */
20288 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
20289 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
20290 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
20291 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
20292 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
20293 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
20294 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
20295 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
20296 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
20297 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
20298 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
20299 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
20300 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
20301 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
20302 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
20303 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
20304 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
20305 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
20306 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
20307 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
20308
46dbf9d0
DA
20309 /* neighbor accept-own */
20310 install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
20311 install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
20312
01da2d26
DA
20313 /* "neighbor soo" */
20314 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
20315 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
20316 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
20317 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
20318 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
20319 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
20320 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
20321 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
20322 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
20323 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
20324 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
20325 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
20326 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
20327 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
20328 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
20329 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
20330 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
20331 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
20332
d62a17ae 20333 /* address-family commands. */
20334 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
20335 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 20336#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 20337 install_element(BGP_NODE, &address_family_vpnv4_cmd);
20338 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 20339#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 20340
d62a17ae 20341 install_element(BGP_NODE, &address_family_evpn_cmd);
20342
20343 /* "exit-address-family" command. */
20344 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
20345 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
20346 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
20347 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
20348 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
20349 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
20350 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
20351 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 20352 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
20353 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 20354 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
20355
a486300b
PG
20356 /* BGP retain all route-target */
20357 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
20358 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
20359
d62a17ae 20360 /* "clear ip bgp commands" */
20361 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
20362
20363 /* clear ip bgp prefix */
20364 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
20365 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
20366 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
20367
20368 /* "show [ip] bgp summary" commands. */
20369 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 20370 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 20371 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 20372 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 20373 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
20374 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 20375 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
20376
20377 /* "show [ip] bgp neighbors" commands. */
20378 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
20379
36235319 20380 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 20381
d62a17ae 20382 /* "show [ip] bgp peer-group" commands. */
20383 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
20384
20385 /* "show [ip] bgp paths" commands. */
20386 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
20387
20388 /* "show [ip] bgp community" commands. */
20389 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
20390
20391 /* "show ip bgp large-community" commands. */
20392 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
20393 /* "show [ip] bgp attribute-info" commands. */
20394 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 20395 /* "show [ip] bgp route-leak" command */
20396 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 20397
20398 /* "redistribute" commands. */
20399 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
20400 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
20401 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
20402 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
20403 install_element(BGP_NODE,
20404 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
20405 install_element(BGP_NODE,
20406 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
20407 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
20408 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
20409 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
20410 install_element(BGP_NODE,
20411 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
20412 install_element(BGP_NODE,
20413 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
20414 install_element(BGP_NODE,
20415 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
20416 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
20417 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
20418 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
20419 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
20420 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
20421 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
20422 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
20423 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
20424 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
20425 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
20426 install_element(BGP_IPV4_NODE,
20427 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
20428 install_element(BGP_IPV4_NODE,
20429 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
20430 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
20431 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
20432 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
20433 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
20434 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
20435 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
20436
70dd370f 20437 /* import|export vpn [route-map RMAP_NAME] */
b9c7bc5a
PZ
20438 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
20439 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 20440
12a844a5
DS
20441 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
20442 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
20443
d62a17ae 20444 /* ttl_security commands */
20445 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
20446 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
20447
d1adb448
PG
20448 /* "bgp tcp-keepalive" commands */
20449 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
20450 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
20451
d62a17ae 20452 /* "show [ip] bgp memory" commands. */
20453 install_element(VIEW_NODE, &show_bgp_memory_cmd);
20454
acf71666
MK
20455 /* "show bgp martian next-hop" */
20456 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
20457
48ecf8f5
DS
20458 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
20459
d62a17ae 20460 /* "show [ip] bgp views" commands. */
20461 install_element(VIEW_NODE, &show_bgp_views_cmd);
20462
20463 /* "show [ip] bgp vrfs" commands. */
20464 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
20465
20466 /* Community-list. */
20467 community_list_vty();
ddb5b488 20468
ed0e57e3
DA
20469 community_alias_vty();
20470
ddb5b488 20471 /* vpn-policy commands */
b9c7bc5a
PZ
20472 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
20473 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
20474 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
20475 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
20476 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
20477 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
20478 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
20479 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
20480 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
20481 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
20482 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
20483 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 20484
301ad80a
PG
20485 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
20486 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
20487
b9c7bc5a
PZ
20488 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
20489 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
20490 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
20491 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
20492 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
20493 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
20494 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
20495 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
20496 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
20497 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
20498
20499 /* tcp-mss command */
20500 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
20501 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
20502
20503 /* srv6 commands */
ea372e81 20504 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
bfaab44d 20505 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
0249b8b6 20506 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
a0281b2e 20507 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
0249b8b6 20508 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
b72c9e14
HS
20509 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
20510 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
527588aa 20511 install_element(BGP_NODE, &bgp_sid_vpn_export_cmd);
e606d8ec 20512 install_element(BGP_NODE, &no_bgp_sid_vpn_export_cmd);
4cd690ae
PG
20513
20514 bgp_vty_if_init();
718e3744 20515}
6b0655a2 20516
718e3744 20517#include "memory.h"
20518#include "bgp_regex.h"
20519#include "bgp_clist.h"
20520#include "bgp_ecommunity.h"
20521
20522/* VTY functions. */
20523
20524/* Direction value to string conversion. */
d62a17ae 20525static const char *community_direct_str(int direct)
20526{
20527 switch (direct) {
20528 case COMMUNITY_DENY:
20529 return "deny";
20530 case COMMUNITY_PERMIT:
20531 return "permit";
20532 default:
20533 return "unknown";
20534 }
718e3744 20535}
20536
20537/* Display error string. */
d62a17ae 20538static void community_list_perror(struct vty *vty, int ret)
20539{
20540 switch (ret) {
20541 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
20542 vty_out(vty, "%% Can't find community-list\n");
20543 break;
20544 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
20545 vty_out(vty, "%% Malformed community-list value\n");
20546 break;
20547 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
20548 vty_out(vty,
20549 "%% Community name conflict, previously defined as standard community\n");
20550 break;
20551 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
20552 vty_out(vty,
20553 "%% Community name conflict, previously defined as expanded community\n");
20554 break;
20555 }
718e3744 20556}
20557
5bf15956
DW
20558/* "community-list" keyword help string. */
20559#define COMMUNITY_LIST_STR "Add a community list entry\n"
20560
7336e101
SP
20561/*community-list standard */
20562DEFUN (community_list_standard,
20563 bgp_community_list_standard_cmd,
a2099c1d 20564 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 20565 BGP_STR
718e3744 20566 COMMUNITY_LIST_STR
20567 "Community list number (standard)\n"
5bf15956 20568 "Add an standard community-list entry\n"
718e3744 20569 "Community list name\n"
2f8cc0e5
DA
20570 "Sequence number of an entry\n"
20571 "Sequence number\n"
718e3744 20572 "Specify community to reject\n"
20573 "Specify community to accept\n"
20574 COMMUNITY_VAL_STR)
20575{
d62a17ae 20576 char *cl_name_or_number = NULL;
2f8cc0e5 20577 char *seq = NULL;
d62a17ae 20578 int direct = 0;
20579 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 20580 int idx = 0;
7336e101 20581
e34627f9 20582 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20583 seq = argv[idx]->arg;
20584
20585 idx = 0;
d62a17ae 20586 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20587 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20588 cl_name_or_number = argv[idx]->arg;
20589 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20590 : COMMUNITY_DENY;
20591 argv_find(argv, argc, "AA:NN", &idx);
20592 char *str = argv_concat(argv, argc, idx);
42f914d4 20593
2f8cc0e5
DA
20594 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20595 direct, style);
42f914d4 20596
d62a17ae 20597 XFREE(MTYPE_TMP, str);
42f914d4 20598
d62a17ae 20599 if (ret < 0) {
20600 /* Display error string. */
20601 community_list_perror(vty, ret);
20602 return CMD_WARNING_CONFIG_FAILED;
20603 }
42f914d4 20604
d62a17ae 20605 return CMD_SUCCESS;
718e3744 20606}
20607
7336e101
SP
20608DEFUN (no_community_list_standard_all,
20609 no_bgp_community_list_standard_all_cmd,
a2099c1d 20610 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20611 NO_STR
20612 BGP_STR
20613 COMMUNITY_LIST_STR
20614 "Community list number (standard)\n"
20615 "Add an standard community-list entry\n"
20616 "Community list name\n"
2f8cc0e5
DA
20617 "Sequence number of an entry\n"
20618 "Sequence number\n"
7336e101
SP
20619 "Specify community to reject\n"
20620 "Specify community to accept\n"
20621 COMMUNITY_VAL_STR)
718e3744 20622{
d62a17ae 20623 char *cl_name_or_number = NULL;
174b5cb9 20624 char *str = NULL;
d62a17ae 20625 int direct = 0;
20626 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 20627 char *seq = NULL;
d62a17ae 20628 int idx = 0;
7336e101 20629
e34627f9 20630 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20631 seq = argv[idx]->arg;
20632
20633 idx = 0;
174b5cb9
DA
20634 argv_find(argv, argc, "permit", &idx);
20635 argv_find(argv, argc, "deny", &idx);
20636
20637 if (idx) {
20638 direct = argv_find(argv, argc, "permit", &idx)
20639 ? COMMUNITY_PERMIT
20640 : COMMUNITY_DENY;
20641
20642 idx = 0;
20643 argv_find(argv, argc, "AA:NN", &idx);
20644 str = argv_concat(argv, argc, idx);
20645 }
20646
20647 idx = 0;
d62a17ae 20648 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20649 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20650 cl_name_or_number = argv[idx]->arg;
42f914d4 20651
2f8cc0e5 20652 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 20653 direct, style);
42f914d4 20654
d62a17ae 20655 XFREE(MTYPE_TMP, str);
daf9ddbb 20656
d62a17ae 20657 if (ret < 0) {
20658 community_list_perror(vty, ret);
20659 return CMD_WARNING_CONFIG_FAILED;
20660 }
42f914d4 20661
d62a17ae 20662 return CMD_SUCCESS;
718e3744 20663}
7336e101 20664
174b5cb9 20665ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
a2099c1d 20666 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
174b5cb9
DA
20667 NO_STR BGP_STR COMMUNITY_LIST_STR
20668 "Community list number (standard)\n"
20669 "Add an standard community-list entry\n"
20670 "Community list name\n")
20671
7336e101
SP
20672/*community-list expanded */
20673DEFUN (community_list_expanded_all,
20674 bgp_community_list_expanded_all_cmd,
a2099c1d 20675 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20676 BGP_STR
20677 COMMUNITY_LIST_STR
718e3744 20678 "Community list number (expanded)\n"
5bf15956 20679 "Add an expanded community-list entry\n"
718e3744 20680 "Community list name\n"
2f8cc0e5
DA
20681 "Sequence number of an entry\n"
20682 "Sequence number\n"
718e3744 20683 "Specify community to reject\n"
20684 "Specify community to accept\n"
20685 COMMUNITY_VAL_STR)
20686{
d62a17ae 20687 char *cl_name_or_number = NULL;
2f8cc0e5 20688 char *seq = NULL;
d62a17ae 20689 int direct = 0;
20690 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 20691 int idx = 0;
7b9a4750 20692
e34627f9 20693 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20694 seq = argv[idx]->arg;
20695
20696 idx = 0;
20697
d62a17ae 20698 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20699 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20700 cl_name_or_number = argv[idx]->arg;
20701 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20702 : COMMUNITY_DENY;
20703 argv_find(argv, argc, "AA:NN", &idx);
20704 char *str = argv_concat(argv, argc, idx);
42f914d4 20705
2f8cc0e5
DA
20706 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20707 direct, style);
42f914d4 20708
d62a17ae 20709 XFREE(MTYPE_TMP, str);
42f914d4 20710
d62a17ae 20711 if (ret < 0) {
20712 /* Display error string. */
20713 community_list_perror(vty, ret);
20714 return CMD_WARNING_CONFIG_FAILED;
20715 }
42f914d4 20716
d62a17ae 20717 return CMD_SUCCESS;
718e3744 20718}
20719
7336e101
SP
20720DEFUN (no_community_list_expanded_all,
20721 no_bgp_community_list_expanded_all_cmd,
a2099c1d 20722 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20723 NO_STR
20724 BGP_STR
20725 COMMUNITY_LIST_STR
20726 "Community list number (expanded)\n"
20727 "Add an expanded community-list entry\n"
20728 "Community list name\n"
2f8cc0e5
DA
20729 "Sequence number of an entry\n"
20730 "Sequence number\n"
7336e101
SP
20731 "Specify community to reject\n"
20732 "Specify community to accept\n"
20733 COMMUNITY_VAL_STR)
718e3744 20734{
d62a17ae 20735 char *cl_name_or_number = NULL;
2f8cc0e5 20736 char *seq = NULL;
174b5cb9 20737 char *str = NULL;
d62a17ae 20738 int direct = 0;
20739 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 20740 int idx = 0;
174b5cb9 20741
e34627f9 20742 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20743 seq = argv[idx]->arg;
20744
20745 idx = 0;
174b5cb9
DA
20746 argv_find(argv, argc, "permit", &idx);
20747 argv_find(argv, argc, "deny", &idx);
20748
20749 if (idx) {
20750 direct = argv_find(argv, argc, "permit", &idx)
20751 ? COMMUNITY_PERMIT
20752 : COMMUNITY_DENY;
20753
20754 idx = 0;
20755 argv_find(argv, argc, "AA:NN", &idx);
20756 str = argv_concat(argv, argc, idx);
7336e101 20757 }
174b5cb9
DA
20758
20759 idx = 0;
d62a17ae 20760 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20761 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20762 cl_name_or_number = argv[idx]->arg;
42f914d4 20763
2f8cc0e5 20764 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 20765 direct, style);
42f914d4 20766
d62a17ae 20767 XFREE(MTYPE_TMP, str);
daf9ddbb 20768
d62a17ae 20769 if (ret < 0) {
20770 community_list_perror(vty, ret);
20771 return CMD_WARNING_CONFIG_FAILED;
20772 }
42f914d4 20773
d62a17ae 20774 return CMD_SUCCESS;
718e3744 20775}
20776
36d4bb44
EB
20777ALIAS(no_community_list_expanded_all,
20778 no_bgp_community_list_expanded_all_list_cmd,
a2099c1d 20779 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
36d4bb44 20780 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
20781 "Community list number (expanded)\n"
20782 "Add an expanded community-list entry\n"
20783 "Community list name\n")
20784
8d9b8ed9
PM
20785/* Return configuration string of community-list entry. */
20786static const char *community_list_config_str(struct community_entry *entry)
20787{
20788 const char *str;
20789
20790 if (entry->any)
20791 str = "";
20792 else {
20793 if (entry->style == COMMUNITY_LIST_STANDARD)
c0945b78 20794 str = community_str(entry->u.com, false, false);
8d9b8ed9 20795 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
c0945b78 20796 str = lcommunity_str(entry->u.lcom, false, false);
8d9b8ed9
PM
20797 else
20798 str = entry->config;
20799 }
20800 return str;
20801}
20802
d62a17ae 20803static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 20804{
d62a17ae 20805 struct community_entry *entry;
718e3744 20806
d62a17ae 20807 for (entry = list->head; entry; entry = entry->next) {
20808 if (entry == list->head) {
20809 if (all_digit(list->name))
20810 vty_out(vty, "Community %s list %s\n",
20811 entry->style == COMMUNITY_LIST_STANDARD
20812 ? "standard"
20813 : "(expanded) access",
20814 list->name);
20815 else
20816 vty_out(vty, "Named Community %s list %s\n",
20817 entry->style == COMMUNITY_LIST_STANDARD
20818 ? "standard"
20819 : "expanded",
20820 list->name);
20821 }
20822 if (entry->any)
20823 vty_out(vty, " %s\n",
20824 community_direct_str(entry->direct));
20825 else
20826 vty_out(vty, " %s %s\n",
20827 community_direct_str(entry->direct),
8d9b8ed9 20828 community_list_config_str(entry));
d62a17ae 20829 }
718e3744 20830}
20831
7336e101
SP
20832DEFUN (show_community_list,
20833 show_bgp_community_list_cmd,
20834 "show bgp community-list",
718e3744 20835 SHOW_STR
7336e101 20836 BGP_STR
718e3744 20837 "List community-list\n")
20838{
d62a17ae 20839 struct community_list *list;
20840 struct community_list_master *cm;
718e3744 20841
d62a17ae 20842 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20843 if (!cm)
20844 return CMD_SUCCESS;
718e3744 20845
d62a17ae 20846 for (list = cm->num.head; list; list = list->next)
20847 community_list_show(vty, list);
718e3744 20848
d62a17ae 20849 for (list = cm->str.head; list; list = list->next)
20850 community_list_show(vty, list);
718e3744 20851
d62a17ae 20852 return CMD_SUCCESS;
718e3744 20853}
20854
7336e101
SP
20855DEFUN (show_community_list_arg,
20856 show_bgp_community_list_arg_cmd,
a2099c1d 20857 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
7336e101
SP
20858 SHOW_STR
20859 BGP_STR
718e3744 20860 "List community-list\n"
20861 "Community-list number\n"
960b69b9 20862 "Community-list name\n"
20863 "Detailed information on community-list\n")
718e3744 20864{
d62a17ae 20865 int idx_comm_list = 3;
20866 struct community_list *list;
718e3744 20867
e237b0d2 20868 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20869 COMMUNITY_LIST_MASTER);
20870 if (!list) {
20871 vty_out(vty, "%% Can't find community-list\n");
20872 return CMD_WARNING;
20873 }
718e3744 20874
d62a17ae 20875 community_list_show(vty, list);
718e3744 20876
d62a17ae 20877 return CMD_SUCCESS;
718e3744 20878}
6b0655a2 20879
57d187bc
JS
20880/*
20881 * Large Community code.
20882 */
d62a17ae 20883static int lcommunity_list_set_vty(struct vty *vty, int argc,
20884 struct cmd_token **argv, int style,
20885 int reject_all_digit_name)
20886{
20887 int ret;
20888 int direct;
20889 char *str;
20890 int idx = 0;
20891 char *cl_name;
2f8cc0e5
DA
20892 char *seq = NULL;
20893
a08032fe 20894 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 20895 seq = argv[idx]->arg;
d62a17ae 20896
2f8cc0e5 20897 idx = 0;
d62a17ae 20898 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20899 : COMMUNITY_DENY;
20900
20901 /* All digit name check. */
20902 idx = 0;
a2099c1d 20903 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20904 argv_find(argv, argc, "(1-99)", &idx);
20905 argv_find(argv, argc, "(100-500)", &idx);
20906 cl_name = argv[idx]->arg;
20907 if (reject_all_digit_name && all_digit(cl_name)) {
20908 vty_out(vty, "%% Community name cannot have all digits\n");
20909 return CMD_WARNING_CONFIG_FAILED;
20910 }
20911
20912 idx = 0;
20913 argv_find(argv, argc, "AA:BB:CC", &idx);
20914 argv_find(argv, argc, "LINE", &idx);
20915 /* Concat community string argument. */
20916 if (idx)
20917 str = argv_concat(argv, argc, idx);
20918 else
20919 str = NULL;
20920
2f8cc0e5 20921 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 20922
20923 /* Free temporary community list string allocated by
20924 argv_concat(). */
0a22ddfb 20925 XFREE(MTYPE_TMP, str);
d62a17ae 20926
20927 if (ret < 0) {
20928 community_list_perror(vty, ret);
20929 return CMD_WARNING_CONFIG_FAILED;
20930 }
20931 return CMD_SUCCESS;
20932}
20933
20934static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20935 struct cmd_token **argv, int style)
20936{
20937 int ret;
20938 int direct = 0;
20939 char *str = NULL;
20940 int idx = 0;
2f8cc0e5 20941 char *seq = NULL;
d62a17ae 20942
a08032fe 20943 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 20944 seq = argv[idx]->arg;
d62a17ae 20945
2f8cc0e5 20946 idx = 0;
d62a17ae 20947 argv_find(argv, argc, "permit", &idx);
20948 argv_find(argv, argc, "deny", &idx);
20949
20950 if (idx) {
20951 /* Check the list direct. */
20952 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20953 direct = COMMUNITY_PERMIT;
20954 else
20955 direct = COMMUNITY_DENY;
20956
20957 idx = 0;
20958 argv_find(argv, argc, "LINE", &idx);
20959 argv_find(argv, argc, "AA:AA:NN", &idx);
20960 /* Concat community string argument. */
20961 str = argv_concat(argv, argc, idx);
20962 }
20963
20964 idx = 0;
20965 argv_find(argv, argc, "(1-99)", &idx);
20966 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20967 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20968
20969 /* Unset community list. */
2f8cc0e5 20970 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 20971 style);
20972
20973 /* Free temporary community list string allocated by
20974 argv_concat(). */
0a22ddfb 20975 XFREE(MTYPE_TMP, str);
d62a17ae 20976
20977 if (ret < 0) {
20978 community_list_perror(vty, ret);
20979 return CMD_WARNING_CONFIG_FAILED;
20980 }
20981
20982 return CMD_SUCCESS;
57d187bc
JS
20983}
20984
20985/* "large-community-list" keyword help string. */
20986#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20987#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20988
7336e101
SP
20989DEFUN (lcommunity_list_standard,
20990 bgp_lcommunity_list_standard_cmd,
a08032fe 20991 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
20992 BGP_STR
20993 LCOMMUNITY_LIST_STR
20994 "Large Community list number (standard)\n"
2f8cc0e5
DA
20995 "Sequence number of an entry\n"
20996 "Sequence number\n"
7336e101
SP
20997 "Specify large community to reject\n"
20998 "Specify large community to accept\n"
20999 LCOMMUNITY_VAL_STR)
52951b63 21000{
d62a17ae 21001 return lcommunity_list_set_vty(vty, argc, argv,
21002 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
21003}
21004
7336e101
SP
21005DEFUN (lcommunity_list_expanded,
21006 bgp_lcommunity_list_expanded_cmd,
a08032fe 21007 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21008 BGP_STR
21009 LCOMMUNITY_LIST_STR
21010 "Large Community list number (expanded)\n"
2f8cc0e5
DA
21011 "Sequence number of an entry\n"
21012 "Sequence number\n"
7336e101
SP
21013 "Specify large community to reject\n"
21014 "Specify large community to accept\n"
21015 "An ordered list as a regular-expression\n")
57d187bc 21016{
d62a17ae 21017 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 21018 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
21019}
21020
7336e101
SP
21021DEFUN (lcommunity_list_name_standard,
21022 bgp_lcommunity_list_name_standard_cmd,
a2099c1d 21023 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
21024 BGP_STR
21025 LCOMMUNITY_LIST_STR
21026 "Specify standard large-community-list\n"
21027 "Large Community list name\n"
2f8cc0e5
DA
21028 "Sequence number of an entry\n"
21029 "Sequence number\n"
7336e101
SP
21030 "Specify large community to reject\n"
21031 "Specify large community to accept\n"
21032 LCOMMUNITY_VAL_STR)
52951b63 21033{
d62a17ae 21034 return lcommunity_list_set_vty(vty, argc, argv,
21035 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
21036}
21037
7336e101
SP
21038DEFUN (lcommunity_list_name_expanded,
21039 bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 21040 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21041 BGP_STR
21042 LCOMMUNITY_LIST_STR
21043 "Specify expanded large-community-list\n"
21044 "Large Community list name\n"
2f8cc0e5
DA
21045 "Sequence number of an entry\n"
21046 "Sequence number\n"
7336e101
SP
21047 "Specify large community to reject\n"
21048 "Specify large community to accept\n"
21049 "An ordered list as a regular-expression\n")
57d187bc 21050{
d62a17ae 21051 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 21052 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
21053}
21054
4378f57c
DA
21055DEFUN (no_lcommunity_list_all,
21056 no_bgp_lcommunity_list_all_cmd,
a2099c1d 21057 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
7336e101
SP
21058 NO_STR
21059 BGP_STR
21060 LCOMMUNITY_LIST_STR
21061 "Large Community list number (standard)\n"
21062 "Large Community list number (expanded)\n"
21063 "Large Community list name\n")
57d187bc 21064{
7336e101
SP
21065 return lcommunity_list_unset_vty(vty, argc, argv,
21066 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
21067}
21068
4378f57c
DA
21069DEFUN (no_lcommunity_list_name_standard_all,
21070 no_bgp_lcommunity_list_name_standard_all_cmd,
a2099c1d 21071 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
4378f57c
DA
21072 NO_STR
21073 BGP_STR
21074 LCOMMUNITY_LIST_STR
21075 "Specify standard large-community-list\n"
21076 "Large Community list name\n")
21077{
21078 return lcommunity_list_unset_vty(vty, argc, argv,
21079 LARGE_COMMUNITY_LIST_STANDARD);
21080}
21081
7336e101
SP
21082DEFUN (no_lcommunity_list_name_expanded_all,
21083 no_bgp_lcommunity_list_name_expanded_all_cmd,
a2099c1d 21084 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
7336e101
SP
21085 NO_STR
21086 BGP_STR
21087 LCOMMUNITY_LIST_STR
21088 "Specify expanded large-community-list\n"
21089 "Large Community list name\n")
57d187bc 21090{
d62a17ae 21091 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 21092 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
21093}
21094
7336e101
SP
21095DEFUN (no_lcommunity_list_standard,
21096 no_bgp_lcommunity_list_standard_cmd,
a08032fe 21097 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
21098 NO_STR
21099 BGP_STR
21100 LCOMMUNITY_LIST_STR
21101 "Large Community list number (standard)\n"
2f8cc0e5
DA
21102 "Sequence number of an entry\n"
21103 "Sequence number\n"
7336e101
SP
21104 "Specify large community to reject\n"
21105 "Specify large community to accept\n"
21106 LCOMMUNITY_VAL_STR)
57d187bc 21107{
d62a17ae 21108 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 21109 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
21110}
21111
7336e101
SP
21112DEFUN (no_lcommunity_list_expanded,
21113 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 21114 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21115 NO_STR
21116 BGP_STR
21117 LCOMMUNITY_LIST_STR
21118 "Large Community list number (expanded)\n"
2f8cc0e5
DA
21119 "Sequence number of an entry\n"
21120 "Sequence number\n"
7336e101
SP
21121 "Specify large community to reject\n"
21122 "Specify large community to accept\n"
21123 "An ordered list as a regular-expression\n")
57d187bc 21124{
d62a17ae 21125 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 21126 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
21127}
21128
7336e101
SP
21129DEFUN (no_lcommunity_list_name_standard,
21130 no_bgp_lcommunity_list_name_standard_cmd,
a2099c1d 21131 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
21132 NO_STR
21133 BGP_STR
21134 LCOMMUNITY_LIST_STR
21135 "Specify standard large-community-list\n"
21136 "Large Community list name\n"
2f8cc0e5
DA
21137 "Sequence number of an entry\n"
21138 "Sequence number\n"
7336e101
SP
21139 "Specify large community to reject\n"
21140 "Specify large community to accept\n"
21141 LCOMMUNITY_VAL_STR)
57d187bc 21142{
d62a17ae 21143 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 21144 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
21145}
21146
7336e101
SP
21147DEFUN (no_lcommunity_list_name_expanded,
21148 no_bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 21149 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21150 NO_STR
21151 BGP_STR
21152 LCOMMUNITY_LIST_STR
21153 "Specify expanded large-community-list\n"
21154 "Large community list name\n"
2f8cc0e5
DA
21155 "Sequence number of an entry\n"
21156 "Sequence number\n"
7336e101
SP
21157 "Specify large community to reject\n"
21158 "Specify large community to accept\n"
21159 "An ordered list as a regular-expression\n")
57d187bc 21160{
d62a17ae 21161 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 21162 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
21163}
21164
d62a17ae 21165static void lcommunity_list_show(struct vty *vty, struct community_list *list)
21166{
21167 struct community_entry *entry;
21168
21169 for (entry = list->head; entry; entry = entry->next) {
21170 if (entry == list->head) {
21171 if (all_digit(list->name))
21172 vty_out(vty, "Large community %s list %s\n",
169b72c8 21173 entry->style ==
21174 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 21175 ? "standard"
21176 : "(expanded) access",
21177 list->name);
21178 else
21179 vty_out(vty,
21180 "Named large community %s list %s\n",
169b72c8 21181 entry->style ==
21182 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 21183 ? "standard"
21184 : "expanded",
21185 list->name);
21186 }
21187 if (entry->any)
21188 vty_out(vty, " %s\n",
21189 community_direct_str(entry->direct));
21190 else
21191 vty_out(vty, " %s %s\n",
21192 community_direct_str(entry->direct),
8d9b8ed9 21193 community_list_config_str(entry));
d62a17ae 21194 }
57d187bc
JS
21195}
21196
7336e101
SP
21197DEFUN (show_lcommunity_list,
21198 show_bgp_lcommunity_list_cmd,
21199 "show bgp large-community-list",
57d187bc 21200 SHOW_STR
7336e101 21201 BGP_STR
57d187bc
JS
21202 "List large-community list\n")
21203{
d62a17ae 21204 struct community_list *list;
21205 struct community_list_master *cm;
57d187bc 21206
d62a17ae 21207 cm = community_list_master_lookup(bgp_clist,
21208 LARGE_COMMUNITY_LIST_MASTER);
21209 if (!cm)
21210 return CMD_SUCCESS;
57d187bc 21211
d62a17ae 21212 for (list = cm->num.head; list; list = list->next)
21213 lcommunity_list_show(vty, list);
57d187bc 21214
d62a17ae 21215 for (list = cm->str.head; list; list = list->next)
21216 lcommunity_list_show(vty, list);
57d187bc 21217
d62a17ae 21218 return CMD_SUCCESS;
57d187bc
JS
21219}
21220
7336e101
SP
21221DEFUN (show_lcommunity_list_arg,
21222 show_bgp_lcommunity_list_arg_cmd,
a2099c1d 21223 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
7336e101
SP
21224 SHOW_STR
21225 BGP_STR
57d187bc 21226 "List large-community list\n"
960b69b9 21227 "Large-community-list number\n"
21228 "Large-community-list name\n"
21229 "Detailed information on large-community-list\n")
57d187bc 21230{
d62a17ae 21231 struct community_list *list;
57d187bc 21232
e237b0d2 21233 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 21234 LARGE_COMMUNITY_LIST_MASTER);
21235 if (!list) {
960b69b9 21236 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 21237 return CMD_WARNING;
21238 }
57d187bc 21239
d62a17ae 21240 lcommunity_list_show(vty, list);
57d187bc 21241
d62a17ae 21242 return CMD_SUCCESS;
57d187bc
JS
21243}
21244
718e3744 21245/* "extcommunity-list" keyword help string. */
21246#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
21247#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
21248
7336e101
SP
21249DEFUN (extcommunity_list_standard,
21250 bgp_extcommunity_list_standard_cmd,
a2099c1d 21251 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 21252 BGP_STR
718e3744 21253 EXTCOMMUNITY_LIST_STR
21254 "Extended Community list number (standard)\n"
718e3744 21255 "Specify standard extcommunity-list\n"
5bf15956 21256 "Community list name\n"
2f8cc0e5
DA
21257 "Sequence number of an entry\n"
21258 "Sequence number\n"
718e3744 21259 "Specify community to reject\n"
21260 "Specify community to accept\n"
21261 EXTCOMMUNITY_VAL_STR)
21262{
d62a17ae 21263 int style = EXTCOMMUNITY_LIST_STANDARD;
21264 int direct = 0;
21265 char *cl_number_or_name = NULL;
2f8cc0e5 21266 char *seq = NULL;
42f914d4 21267
d62a17ae 21268 int idx = 0;
7b9a4750 21269
d62a17ae 21270 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 21271 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21272 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 21273
a08032fe 21274 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21275 seq = argv[idx]->arg;
21276
d62a17ae 21277 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21278 : COMMUNITY_DENY;
21279 argv_find(argv, argc, "AA:NN", &idx);
21280 char *str = argv_concat(argv, argc, idx);
42f914d4 21281
2f8cc0e5 21282 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 21283 direct, style);
42f914d4 21284
d62a17ae 21285 XFREE(MTYPE_TMP, str);
42f914d4 21286
d62a17ae 21287 if (ret < 0) {
21288 community_list_perror(vty, ret);
21289 return CMD_WARNING_CONFIG_FAILED;
21290 }
42f914d4 21291
d62a17ae 21292 return CMD_SUCCESS;
718e3744 21293}
21294
7336e101
SP
21295DEFUN (extcommunity_list_name_expanded,
21296 bgp_extcommunity_list_name_expanded_cmd,
a2099c1d 21297 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21298 BGP_STR
21299 EXTCOMMUNITY_LIST_STR
5bf15956 21300 "Extended Community list number (expanded)\n"
718e3744 21301 "Specify expanded extcommunity-list\n"
21302 "Extended Community list name\n"
2f8cc0e5
DA
21303 "Sequence number of an entry\n"
21304 "Sequence number\n"
718e3744 21305 "Specify community to reject\n"
21306 "Specify community to accept\n"
21307 "An ordered list as a regular-expression\n")
21308{
d62a17ae 21309 int style = EXTCOMMUNITY_LIST_EXPANDED;
21310 int direct = 0;
21311 char *cl_number_or_name = NULL;
2f8cc0e5 21312 char *seq = NULL;
d62a17ae 21313 int idx = 0;
7336e101 21314
d62a17ae 21315 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 21316 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21317 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 21318
a08032fe 21319 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21320 seq = argv[idx]->arg;
21321
d62a17ae 21322 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21323 : COMMUNITY_DENY;
21324 argv_find(argv, argc, "LINE", &idx);
21325 char *str = argv_concat(argv, argc, idx);
42f914d4 21326
2f8cc0e5 21327 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 21328 direct, style);
42f914d4 21329
d62a17ae 21330 XFREE(MTYPE_TMP, str);
42f914d4 21331
d62a17ae 21332 if (ret < 0) {
21333 community_list_perror(vty, ret);
21334 return CMD_WARNING_CONFIG_FAILED;
21335 }
42f914d4 21336
d62a17ae 21337 return CMD_SUCCESS;
718e3744 21338}
21339
7336e101
SP
21340DEFUN (no_extcommunity_list_standard_all,
21341 no_bgp_extcommunity_list_standard_all_cmd,
a2099c1d 21342 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
21343 NO_STR
21344 BGP_STR
21345 EXTCOMMUNITY_LIST_STR
813d4307 21346 "Extended Community list number (standard)\n"
718e3744 21347 "Specify standard extcommunity-list\n"
5bf15956 21348 "Community list name\n"
2f8cc0e5
DA
21349 "Sequence number of an entry\n"
21350 "Sequence number\n"
718e3744 21351 "Specify community to reject\n"
21352 "Specify community to accept\n"
21353 EXTCOMMUNITY_VAL_STR)
21354{
d62a17ae 21355 int style = EXTCOMMUNITY_LIST_STANDARD;
21356 int direct = 0;
21357 char *cl_number_or_name = NULL;
d4455c89 21358 char *str = NULL;
2f8cc0e5 21359 char *seq = NULL;
d62a17ae 21360 int idx = 0;
d4455c89 21361
a08032fe 21362 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21363 seq = argv[idx]->arg;
21364
21365 idx = 0;
d4455c89
DA
21366 argv_find(argv, argc, "permit", &idx);
21367 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
21368 if (idx) {
21369 direct = argv_find(argv, argc, "permit", &idx)
21370 ? COMMUNITY_PERMIT
21371 : COMMUNITY_DENY;
21372
21373 idx = 0;
21374 argv_find(argv, argc, "AA:NN", &idx);
21375 str = argv_concat(argv, argc, idx);
21376 }
21377
21378 idx = 0;
d62a17ae 21379 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 21380 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21381 cl_number_or_name = argv[idx]->arg;
42f914d4 21382
d62a17ae 21383 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 21384 seq, direct, style);
42f914d4 21385
d62a17ae 21386 XFREE(MTYPE_TMP, str);
42f914d4 21387
d62a17ae 21388 if (ret < 0) {
21389 community_list_perror(vty, ret);
21390 return CMD_WARNING_CONFIG_FAILED;
21391 }
42f914d4 21392
d62a17ae 21393 return CMD_SUCCESS;
718e3744 21394}
21395
d4455c89
DA
21396ALIAS(no_extcommunity_list_standard_all,
21397 no_bgp_extcommunity_list_standard_all_list_cmd,
a2099c1d 21398 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
36d4bb44 21399 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
21400 "Extended Community list number (standard)\n"
21401 "Specify standard extcommunity-list\n"
21402 "Community list name\n")
21403
7336e101
SP
21404DEFUN (no_extcommunity_list_expanded_all,
21405 no_bgp_extcommunity_list_expanded_all_cmd,
a2099c1d 21406 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21407 NO_STR
21408 BGP_STR
21409 EXTCOMMUNITY_LIST_STR
718e3744 21410 "Extended Community list number (expanded)\n"
718e3744 21411 "Specify expanded extcommunity-list\n"
5bf15956 21412 "Extended Community list name\n"
2f8cc0e5
DA
21413 "Sequence number of an entry\n"
21414 "Sequence number\n"
718e3744 21415 "Specify community to reject\n"
21416 "Specify community to accept\n"
21417 "An ordered list as a regular-expression\n")
21418{
d62a17ae 21419 int style = EXTCOMMUNITY_LIST_EXPANDED;
21420 int direct = 0;
21421 char *cl_number_or_name = NULL;
d4455c89 21422 char *str = NULL;
2f8cc0e5 21423 char *seq = NULL;
d62a17ae 21424 int idx = 0;
d4455c89 21425
a08032fe 21426 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21427 seq = argv[idx]->arg;
21428
21429 idx = 0;
d4455c89
DA
21430 argv_find(argv, argc, "permit", &idx);
21431 argv_find(argv, argc, "deny", &idx);
21432
21433 if (idx) {
21434 direct = argv_find(argv, argc, "permit", &idx)
21435 ? COMMUNITY_PERMIT
21436 : COMMUNITY_DENY;
21437
21438 idx = 0;
21439 argv_find(argv, argc, "LINE", &idx);
21440 str = argv_concat(argv, argc, idx);
21441 }
21442
21443 idx = 0;
d62a17ae 21444 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 21445 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21446 cl_number_or_name = argv[idx]->arg;
42f914d4 21447
d62a17ae 21448 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 21449 seq, direct, style);
42f914d4 21450
d62a17ae 21451 XFREE(MTYPE_TMP, str);
42f914d4 21452
d62a17ae 21453 if (ret < 0) {
21454 community_list_perror(vty, ret);
21455 return CMD_WARNING_CONFIG_FAILED;
21456 }
42f914d4 21457
d62a17ae 21458 return CMD_SUCCESS;
718e3744 21459}
21460
d4455c89
DA
21461ALIAS(no_extcommunity_list_expanded_all,
21462 no_bgp_extcommunity_list_expanded_all_list_cmd,
a2099c1d 21463 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
36d4bb44 21464 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
21465 "Extended Community list number (expanded)\n"
21466 "Specify expanded extcommunity-list\n"
21467 "Extended Community list name\n")
21468
d62a17ae 21469static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 21470{
d62a17ae 21471 struct community_entry *entry;
718e3744 21472
d62a17ae 21473 for (entry = list->head; entry; entry = entry->next) {
21474 if (entry == list->head) {
21475 if (all_digit(list->name))
21476 vty_out(vty, "Extended community %s list %s\n",
21477 entry->style == EXTCOMMUNITY_LIST_STANDARD
21478 ? "standard"
21479 : "(expanded) access",
21480 list->name);
21481 else
21482 vty_out(vty,
21483 "Named extended community %s list %s\n",
21484 entry->style == EXTCOMMUNITY_LIST_STANDARD
21485 ? "standard"
21486 : "expanded",
21487 list->name);
21488 }
21489 if (entry->any)
21490 vty_out(vty, " %s\n",
21491 community_direct_str(entry->direct));
21492 else
21493 vty_out(vty, " %s %s\n",
21494 community_direct_str(entry->direct),
8d9b8ed9 21495 community_list_config_str(entry));
d62a17ae 21496 }
718e3744 21497}
21498
7336e101
SP
21499DEFUN (show_extcommunity_list,
21500 show_bgp_extcommunity_list_cmd,
21501 "show bgp extcommunity-list",
718e3744 21502 SHOW_STR
7336e101 21503 BGP_STR
718e3744 21504 "List extended-community list\n")
21505{
d62a17ae 21506 struct community_list *list;
21507 struct community_list_master *cm;
718e3744 21508
d62a17ae 21509 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21510 if (!cm)
21511 return CMD_SUCCESS;
718e3744 21512
d62a17ae 21513 for (list = cm->num.head; list; list = list->next)
21514 extcommunity_list_show(vty, list);
718e3744 21515
d62a17ae 21516 for (list = cm->str.head; list; list = list->next)
21517 extcommunity_list_show(vty, list);
718e3744 21518
d62a17ae 21519 return CMD_SUCCESS;
718e3744 21520}
21521
7336e101
SP
21522DEFUN (show_extcommunity_list_arg,
21523 show_bgp_extcommunity_list_arg_cmd,
a2099c1d 21524 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
7336e101
SP
21525 SHOW_STR
21526 BGP_STR
718e3744 21527 "List extended-community list\n"
21528 "Extcommunity-list number\n"
960b69b9 21529 "Extcommunity-list name\n"
21530 "Detailed information on extcommunity-list\n")
718e3744 21531{
d62a17ae 21532 int idx_comm_list = 3;
21533 struct community_list *list;
718e3744 21534
e237b0d2 21535 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 21536 EXTCOMMUNITY_LIST_MASTER);
21537 if (!list) {
21538 vty_out(vty, "%% Can't find extcommunity-list\n");
21539 return CMD_WARNING;
21540 }
718e3744 21541
d62a17ae 21542 extcommunity_list_show(vty, list);
718e3744 21543
d62a17ae 21544 return CMD_SUCCESS;
718e3744 21545}
6b0655a2 21546
718e3744 21547/* Display community-list and extcommunity-list configuration. */
d62a17ae 21548static int community_list_config_write(struct vty *vty)
21549{
21550 struct community_list *list;
21551 struct community_entry *entry;
21552 struct community_list_master *cm;
21553 int write = 0;
21554
21555 /* Community-list. */
21556 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
21557
21558 for (list = cm->num.head; list; list = list->next)
21559 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21560 vty_out(vty,
21561 "bgp community-list %s seq %" PRId64 " %s %s\n",
21562 list->name, entry->seq,
d62a17ae 21563 community_direct_str(entry->direct),
21564 community_list_config_str(entry));
21565 write++;
21566 }
21567 for (list = cm->str.head; list; list = list->next)
21568 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21569 vty_out(vty,
21570 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 21571 entry->style == COMMUNITY_LIST_STANDARD
21572 ? "standard"
21573 : "expanded",
2f8cc0e5
DA
21574 list->name, entry->seq,
21575 community_direct_str(entry->direct),
d62a17ae 21576 community_list_config_str(entry));
21577 write++;
21578 }
21579
21580 /* Extcommunity-list. */
21581 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21582
21583 for (list = cm->num.head; list; list = list->next)
21584 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21585 vty_out(vty,
21586 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
21587 list->name, entry->seq,
21588 community_direct_str(entry->direct),
d62a17ae 21589 community_list_config_str(entry));
21590 write++;
21591 }
21592 for (list = cm->str.head; list; list = list->next)
21593 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21594 vty_out(vty,
6cde4b45 21595 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 21596 entry->style == EXTCOMMUNITY_LIST_STANDARD
21597 ? "standard"
21598 : "expanded",
2f8cc0e5
DA
21599 list->name, entry->seq,
21600 community_direct_str(entry->direct),
d62a17ae 21601 community_list_config_str(entry));
21602 write++;
21603 }
21604
21605
21606 /* lcommunity-list. */
21607 cm = community_list_master_lookup(bgp_clist,
21608 LARGE_COMMUNITY_LIST_MASTER);
21609
21610 for (list = cm->num.head; list; list = list->next)
21611 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21612 vty_out(vty,
6cde4b45 21613 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
21614 list->name, entry->seq,
21615 community_direct_str(entry->direct),
d62a17ae 21616 community_list_config_str(entry));
21617 write++;
21618 }
21619 for (list = cm->str.head; list; list = list->next)
21620 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21621 vty_out(vty,
6cde4b45 21622 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 21623
d62a17ae 21624 entry->style == LARGE_COMMUNITY_LIST_STANDARD
21625 ? "standard"
21626 : "expanded",
2f8cc0e5 21627 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 21628 community_list_config_str(entry));
21629 write++;
21630 }
21631
21632 return write;
21633}
21634
612c2c15 21635static int community_list_config_write(struct vty *vty);
d62a17ae 21636static struct cmd_node community_list_node = {
f4b8291f 21637 .name = "community list",
62b346ee
DL
21638 .node = COMMUNITY_LIST_NODE,
21639 .prompt = "",
612c2c15 21640 .config_write = community_list_config_write,
718e3744 21641};
21642
d62a17ae 21643static void community_list_vty(void)
21644{
612c2c15 21645 install_node(&community_list_node);
d62a17ae 21646
21647 /* Community-list. */
7336e101
SP
21648 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
21649 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
21650 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 21651 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 21652 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 21653 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
21654 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
21655 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 21656
21657 /* Extcommunity-list. */
7336e101
SP
21658 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
21659 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
21660 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
21661 install_element(CONFIG_NODE,
21662 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 21663 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
21664 install_element(CONFIG_NODE,
21665 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
21666 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
21667 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 21668
21669 /* Large Community List */
7336e101 21670 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
21671 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
21672 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 21673 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
21674 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
21675 install_element(CONFIG_NODE,
21676 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
21677 install_element(CONFIG_NODE,
21678 &no_bgp_lcommunity_list_name_expanded_all_cmd);
21679 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
21680 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
21681 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
21682 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
21683 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
21684 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
225096bc
DA
21685
21686 bgp_community_list_command_completion_setup();
5bf15956 21687}
ed0e57e3
DA
21688
21689static struct cmd_node community_alias_node = {
21690 .name = "community alias",
21691 .node = COMMUNITY_ALIAS_NODE,
21692 .prompt = "",
21693 .config_write = bgp_community_alias_write,
21694};
21695
21696void community_alias_vty(void)
21697{
21698 install_node(&community_alias_node);
21699
21700 /* Community-list. */
21701 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
b4ad2fae
DS
21702
21703 bgp_community_alias_command_completion_setup();
ed0e57e3 21704}