]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: entry->any is never true
[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
d4cdcee5
PG
9186DEFPY(af_label_vpn_export_allocation_mode,
9187 af_label_vpn_export_allocation_mode_cmd,
9188 "[no$no] label vpn export allocation-mode <per-vrf$label_per_vrf|per-nexthop$label_per_nh>",
9189 NO_STR
9190 "label value for VRF\n"
9191 "Between current address-family and vpn\n"
9192 "For routes leaked from current address-family to vpn\n"
9193 "Label allocation mode\n"
9194 "Allocate one label for all BGP updates of the VRF\n"
9195 "Allocate a label per connected next-hop in the VRF\n")
9196{
9197 VTY_DECLVAR_CONTEXT(bgp, bgp);
9198 afi_t afi;
9199 bool old_per_nexthop, new_per_nexthop;
9200
9201 afi = vpn_policy_getafi(vty, bgp, false);
c36bd47d
DS
9202 if (afi == AFI_MAX)
9203 return CMD_WARNING_CONFIG_FAILED;
d4cdcee5
PG
9204
9205 old_per_nexthop = !!CHECK_FLAG(bgp->vpn_policy[afi].flags,
9206 BGP_VPN_POLICY_TOVPN_LABEL_PER_NEXTHOP);
9207 if (no) {
9208 if (old_per_nexthop == false && label_per_nh)
9209 return CMD_ERR_NO_MATCH;
9210 if (old_per_nexthop == true && label_per_vrf)
9211 return CMD_ERR_NO_MATCH;
9212 new_per_nexthop = false;
9213 } else {
9214 if (label_per_nh)
9215 new_per_nexthop = true;
9216 else
9217 new_per_nexthop = false;
9218 }
9219
9220 /* no change */
9221 if (old_per_nexthop == new_per_nexthop)
9222 return CMD_SUCCESS;
9223
9224 /*
9225 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9226 */
9227 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi, bgp_get_default(),
9228 bgp);
9229
9230 if (new_per_nexthop)
9231 SET_FLAG(bgp->vpn_policy[afi].flags,
9232 BGP_VPN_POLICY_TOVPN_LABEL_PER_NEXTHOP);
9233 else
9234 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9235 BGP_VPN_POLICY_TOVPN_LABEL_PER_NEXTHOP);
9236
9237 /* post-change: re-export vpn routes */
9238 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi, bgp_get_default(),
9239 bgp);
9240
9241 hook_call(bgp_snmp_update_last_changed, bgp);
9242 return CMD_SUCCESS;
9243}
9244
b9c7bc5a
PZ
9245DEFPY (af_label_vpn_export,
9246 af_label_vpn_export_cmd,
e70e9f8e 9247 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 9248 NO_STR
ddb5b488 9249 "label value for VRF\n"
b9c7bc5a
PZ
9250 "Between current address-family and vpn\n"
9251 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
9252 "Label Value <0-1048575>\n"
9253 "Automatically assign a label\n")
ddb5b488
PZ
9254{
9255 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 9256 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 9257 afi_t afi;
b9c7bc5a 9258 int idx = 0;
c6423c31 9259 bool yes = true;
b9c7bc5a
PZ
9260
9261 if (argv_find(argv, argc, "no", &idx))
c6423c31 9262 yes = false;
ddb5b488 9263
21a16cc2
PZ
9264 /* If "no ...", squash trailing parameter */
9265 if (!yes)
9266 label_auto = NULL;
9267
e70e9f8e
PZ
9268 if (yes) {
9269 if (!label_auto)
9270 label = label_val; /* parser should force unsigned */
9271 }
ddb5b488 9272
0ca70ba5 9273 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9274 if (afi == AFI_MAX)
9275 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 9276
e70e9f8e 9277
69b07479
DS
9278 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9279 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9280 /* no change */
9281 return CMD_SUCCESS;
e70e9f8e 9282
69b07479
DS
9283 /*
9284 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9285 */
9286 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9287 bgp_get_default(), bgp);
9288
9289 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9290 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9291
9292 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9293
9294 /*
9295 * label has previously been automatically
9296 * assigned by labelpool: release it
9297 *
9298 * NB if tovpn_label == MPLS_LABEL_NONE it
9299 * means the automatic assignment is in flight
9300 * and therefore the labelpool callback must
9301 * detect that the auto label is not needed.
9302 */
9303
9304 bgp_lp_release(LP_TYPE_VRF,
9305 &bgp->vpn_policy[afi],
9306 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 9307 }
69b07479
DS
9308 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9309 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9310 }
ddb5b488 9311
69b07479
DS
9312 bgp->vpn_policy[afi].tovpn_label = label;
9313 if (label_auto) {
9314 SET_FLAG(bgp->vpn_policy[afi].flags,
9315 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9316 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9317 vpn_leak_label_callback);
ddb5b488
PZ
9318 }
9319
69b07479
DS
9320 /* post-change: re-export vpn routes */
9321 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9322 bgp_get_default(), bgp);
9323
0d020cd6 9324 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
9325 return CMD_SUCCESS;
9326}
9327
b72c9e14
HS
9328DEFPY (af_sid_vpn_export,
9329 af_sid_vpn_export_cmd,
46279a11 9330 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
b72c9e14
HS
9331 NO_STR
9332 "sid value for VRF\n"
9333 "Between current address-family and vpn\n"
9334 "For routes leaked from current address-family to vpn\n"
9335 "Sid allocation index\n"
9336 "Automatically assign a label\n")
9337{
9338 VTY_DECLVAR_CONTEXT(bgp, bgp);
9339 afi_t afi;
9340 int debug = 0;
9341 int idx = 0;
9342 bool yes = true;
9343
9344 if (argv_find(argv, argc, "no", &idx))
9345 yes = false;
9346 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9347 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9348
9349 afi = vpn_policy_getafi(vty, bgp, false);
9350 if (afi == AFI_MAX)
9351 return CMD_WARNING_CONFIG_FAILED;
9352
9353 if (!yes) {
d7967830
DS
9354 /* when SID is not set, do nothing */
9355 if ((bgp->vpn_policy[afi].tovpn_sid_index == 0) &&
9356 !CHECK_FLAG(bgp->vpn_policy[afi].flags,
9357 BGP_VPN_POLICY_TOVPN_SID_AUTO))
9358 return CMD_SUCCESS;
9359
9360 /* pre-change */
9361 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9362 bgp_get_default(), bgp);
9363 bgp->vpn_policy[afi].tovpn_sid_index = 0;
9364 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9365 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9366
9367 /* post-change */
9368 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9369 bgp_get_default(), bgp);
9370
9371 return CMD_SUCCESS;
b72c9e14
HS
9372 }
9373
527588aa
CS
9374 if (bgp->tovpn_sid_index != 0 ||
9375 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
9376 vty_out(vty,
9377 "per-vrf sid and per-af sid are mutually exclusive\n"
9378 "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9379 return CMD_WARNING_CONFIG_FAILED;
9380 }
9381
b72c9e14
HS
9382 /* skip when it's already configured */
9383 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9384 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9385 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9386 return CMD_SUCCESS;
9387
7de4c885
HS
9388 /*
9389 * mode change between sid_idx and sid_auto isn't supported.
9390 * user must negate sid vpn export when they want to change the mode
9391 */
b72c9e14
HS
9392 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9393 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9394 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9395 vty_out(vty, "it's already configured as %s.\n",
9396 sid_auto ? "auto-mode" : "idx-mode");
9397 return CMD_WARNING_CONFIG_FAILED;
9398 }
9399
9400 /* pre-change */
9401 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9402 bgp_get_default(), bgp);
9403
9404 if (sid_auto) {
9405 /* SID allocation auto-mode */
9406 if (debug)
9407 zlog_debug("%s: auto sid alloc.", __func__);
9408 SET_FLAG(bgp->vpn_policy[afi].flags,
9409 BGP_VPN_POLICY_TOVPN_SID_AUTO);
d7967830 9410 } else if (sid_idx != 0) {
b72c9e14
HS
9411 /* SID allocation index-mode */
9412 if (debug)
9413 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9414 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9415 }
9416
9417 /* post-change */
9418 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9419 bgp_get_default(), bgp);
9420 return CMD_SUCCESS;
9421}
9422
527588aa
CS
9423DEFPY (bgp_sid_vpn_export,
9424 bgp_sid_vpn_export_cmd,
346bbb39 9425 "[no] sid vpn per-vrf export <(1-1048575)$sid_idx|auto$sid_auto>",
527588aa
CS
9426 NO_STR
9427 "sid value for VRF\n"
9428 "Between current vrf and vpn\n"
9429 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9430 "For routes leaked from current vrf to vpn\n"
9431 "Sid allocation index\n"
9432 "Automatically assign a label\n")
9433{
9434 VTY_DECLVAR_CONTEXT(bgp, bgp);
9435 int debug;
9436
9437 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9438 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9439
9440 if (no) {
e606d8ec
CS
9441 /* when per-VRF SID is not set, do nothing */
9442 if (bgp->tovpn_sid_index == 0 &&
9443 !CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))
9444 return CMD_SUCCESS;
9445
9446 sid_idx = 0;
9447 sid_auto = false;
9448 bgp->tovpn_sid_index = 0;
9449 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
527588aa
CS
9450 }
9451
9452 if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9453 CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9454 BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9455 bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9456 CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9457 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9458 vty_out(vty,
9459 "per-vrf sid and per-af sid are mutually exclusive\n"
9460 "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9461 return CMD_WARNING_CONFIG_FAILED;
9462 }
9463
9464 /* skip when it's already configured */
9465 if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9466 (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9467 return CMD_SUCCESS;
9468
9469 /*
9470 * mode change between sid_idx and sid_auto isn't supported.
9471 * user must negate sid vpn export when they want to change the mode
9472 */
9473 if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9474 (sid_idx != 0 &&
9475 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9476 vty_out(vty, "it's already configured as %s.\n",
9477 sid_auto ? "auto-mode" : "idx-mode");
9478 return CMD_WARNING_CONFIG_FAILED;
9479 }
9480
9481 /* pre-change */
9482 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9483 bgp);
9484 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9485 bgp);
9486
9487 if (sid_auto) {
9488 /* SID allocation auto-mode */
9489 if (debug)
9490 zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9491 SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
e606d8ec 9492 } else if (sid_idx != 0) {
527588aa
CS
9493 /* SID allocation index-mode */
9494 if (debug)
9495 zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9496 sid_idx);
9497 bgp->tovpn_sid_index = sid_idx;
9498 }
9499
9500 /* post-change */
9501 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9502 bgp);
9503 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9504 bgp_get_default(), bgp);
9505
9506 return CMD_SUCCESS;
9507}
9508
b9c7bc5a
PZ
9509ALIAS (af_label_vpn_export,
9510 af_no_label_vpn_export_cmd,
9511 "no label vpn export",
9512 NO_STR
9513 "label value for VRF\n"
9514 "Between current address-family and vpn\n"
9515 "For routes leaked from current address-family to vpn\n")
ddb5b488 9516
e606d8ec
CS
9517ALIAS (bgp_sid_vpn_export,
9518 no_bgp_sid_vpn_export_cmd,
9519 "no$no sid vpn per-vrf export",
9520 NO_STR
9521 "sid value for VRF\n"
9522 "Between current vrf and vpn\n"
9523 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9524 "For routes leaked from current vrf to vpn\n")
9525
585f1adc 9526DEFPY (af_nexthop_vpn_export,
b9c7bc5a 9527 af_nexthop_vpn_export_cmd,
8c85ca28 9528 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 9529 NO_STR
ddb5b488 9530 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
9531 "Between current address-family and vpn\n"
9532 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9533 "IPv4 prefix\n"
9534 "IPv6 prefix\n")
9535{
585f1adc 9536 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 9537 afi_t afi;
ddb5b488
PZ
9538 struct prefix p;
9539
8c85ca28
QY
9540 if (!no) {
9541 if (!nexthop_su) {
9542 vty_out(vty, "%% Nexthop required\n");
9543 return CMD_WARNING_CONFIG_FAILED;
9544 }
8c85ca28 9545 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
9546 return CMD_WARNING_CONFIG_FAILED;
9547 }
ddb5b488 9548
585f1adc
IR
9549 afi = vpn_policy_getafi(vty, bgp, false);
9550 if (afi == AFI_MAX)
9551 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9552
585f1adc
IR
9553 /*
9554 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9555 */
9556 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9557 bgp_get_default(), bgp);
ddb5b488 9558
585f1adc
IR
9559 if (!no) {
9560 bgp->vpn_policy[afi].tovpn_nexthop = p;
9561 SET_FLAG(bgp->vpn_policy[afi].flags,
9562 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9563 } else {
9564 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9565 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9566 }
69b07479 9567
585f1adc
IR
9568 /* post-change: re-export vpn routes */
9569 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9570 bgp_get_default(), bgp);
37a87b8f 9571
585f1adc 9572 return CMD_SUCCESS;
ddb5b488
PZ
9573}
9574
b9c7bc5a 9575static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 9576{
b9c7bc5a
PZ
9577 if (!strcmp(dstr, "import")) {
9578 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9579 } else if (!strcmp(dstr, "export")) {
9580 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9581 } else if (!strcmp(dstr, "both")) {
9582 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9583 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9584 } else {
9585 vty_out(vty, "%% direction parse error\n");
9586 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9587 }
ddb5b488
PZ
9588 return CMD_SUCCESS;
9589}
9590
b9c7bc5a
PZ
9591DEFPY (af_rt_vpn_imexport,
9592 af_rt_vpn_imexport_cmd,
9593 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9594 NO_STR
9595 "Specify route target list\n"
ddb5b488 9596 "Specify route target list\n"
b9c7bc5a
PZ
9597 "Between current address-family and vpn\n"
9598 "For routes leaked from vpn to current address-family: match any\n"
9599 "For routes leaked from current address-family to vpn: set\n"
9600 "both import: match any and export: set\n"
ddb5b488
PZ
9601 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9602{
9603 VTY_DECLVAR_CONTEXT(bgp, bgp);
9604 int ret;
9605 struct ecommunity *ecom = NULL;
9606 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 9607 enum vpn_policy_direction dir;
ddb5b488
PZ
9608 afi_t afi;
9609 int idx = 0;
c6423c31 9610 bool yes = true;
ddb5b488 9611
b9c7bc5a 9612 if (argv_find(argv, argc, "no", &idx))
c6423c31 9613 yes = false;
b9c7bc5a 9614
0ca70ba5 9615 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9616 if (afi == AFI_MAX)
9617 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9618
b9c7bc5a 9619 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
9620 if (ret != CMD_SUCCESS)
9621 return ret;
9622
b9c7bc5a
PZ
9623 if (yes) {
9624 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9625 vty_out(vty, "%% Missing RTLIST\n");
9626 return CMD_WARNING_CONFIG_FAILED;
9627 }
c6423c31 9628 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
9629 if (ret != CMD_SUCCESS) {
9630 return ret;
9631 }
ddb5b488
PZ
9632 }
9633
69b07479
DS
9634 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9635 if (!dodir[dir])
ddb5b488 9636 continue;
ddb5b488 9637
69b07479 9638 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9639
69b07479
DS
9640 if (yes) {
9641 if (bgp->vpn_policy[afi].rtlist[dir])
9642 ecommunity_free(
9643 &bgp->vpn_policy[afi].rtlist[dir]);
9644 bgp->vpn_policy[afi].rtlist[dir] =
9645 ecommunity_dup(ecom);
9646 } else {
9647 if (bgp->vpn_policy[afi].rtlist[dir])
9648 ecommunity_free(
9649 &bgp->vpn_policy[afi].rtlist[dir]);
9650 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 9651 }
69b07479
DS
9652
9653 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9654 }
69b07479 9655
d555f3e9
PZ
9656 if (ecom)
9657 ecommunity_free(&ecom);
ddb5b488
PZ
9658
9659 return CMD_SUCCESS;
9660}
9661
b9c7bc5a
PZ
9662ALIAS (af_rt_vpn_imexport,
9663 af_no_rt_vpn_imexport_cmd,
9664 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
9665 NO_STR
9666 "Specify route target list\n"
b9c7bc5a
PZ
9667 "Specify route target list\n"
9668 "Between current address-family and vpn\n"
9669 "For routes leaked from vpn to current address-family\n"
9670 "For routes leaked from current address-family to vpn\n"
9671 "both import and export\n")
9672
585f1adc 9673DEFPY (af_route_map_vpn_imexport,
b9c7bc5a
PZ
9674 af_route_map_vpn_imexport_cmd,
9675/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9676 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9677 NO_STR
ddb5b488 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"
ddb5b488
PZ
9682 "name of route-map\n")
9683{
585f1adc
IR
9684 VTY_DECLVAR_CONTEXT(bgp, bgp);
9685 int ret;
9686 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 9687 enum vpn_policy_direction dir;
ddb5b488 9688 afi_t afi;
ddb5b488 9689 int idx = 0;
585f1adc 9690 bool yes = true;
ddb5b488 9691
585f1adc
IR
9692 if (argv_find(argv, argc, "no", &idx))
9693 yes = false;
ddb5b488 9694
585f1adc
IR
9695 afi = vpn_policy_getafi(vty, bgp, false);
9696 if (afi == AFI_MAX)
9697 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9698
585f1adc
IR
9699 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9700 if (ret != CMD_SUCCESS)
9701 return ret;
ddb5b488 9702
585f1adc
IR
9703 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9704 if (!dodir[dir])
9705 continue;
69b07479 9706
585f1adc
IR
9707 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9708
9709 if (yes) {
9710 if (bgp->vpn_policy[afi].rmap_name[dir])
9711 XFREE(MTYPE_ROUTE_MAP_NAME,
9712 bgp->vpn_policy[afi].rmap_name[dir]);
9713 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9714 MTYPE_ROUTE_MAP_NAME, rmap_str);
9715 bgp->vpn_policy[afi].rmap[dir] =
9716 route_map_lookup_warn_noexist(vty, rmap_str);
9717 if (!bgp->vpn_policy[afi].rmap[dir])
9718 return CMD_SUCCESS;
9719 } else {
9720 if (bgp->vpn_policy[afi].rmap_name[dir])
9721 XFREE(MTYPE_ROUTE_MAP_NAME,
9722 bgp->vpn_policy[afi].rmap_name[dir]);
9723 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9724 bgp->vpn_policy[afi].rmap[dir] = NULL;
9725 }
9726
9727 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9728 }
ddb5b488 9729
585f1adc 9730 return CMD_SUCCESS;
ddb5b488
PZ
9731}
9732
b9c7bc5a
PZ
9733ALIAS (af_route_map_vpn_imexport,
9734 af_no_route_map_vpn_imexport_cmd,
9735 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
9736 NO_STR
9737 "Specify route map\n"
b9c7bc5a
PZ
9738 "Between current address-family and vpn\n"
9739 "For routes leaked from vpn to current address-family\n"
9740 "For routes leaked from current address-family to vpn\n")
9741
bb4f6190 9742DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 9743 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
9744 "Import routes from another VRF\n"
9745 "Vrf routes being filtered\n"
9746 "Specify route map\n"
9747 "name of route-map\n")
9748{
9749 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 9750 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
bb4f6190 9751 afi_t afi;
bb4f6190
DS
9752 struct bgp *bgp_default;
9753
0ca70ba5 9754 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
9755 if (afi == AFI_MAX)
9756 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
9757
9758 bgp_default = bgp_get_default();
9759 if (!bgp_default) {
9760 int32_t ret;
9761 as_t as = bgp->as;
9762
9763 /* Auto-create assuming the same AS */
5d5393b9 9764 ret = bgp_get_vty(&bgp_default, &as, NULL,
e55b0883
PG
9765 BGP_INSTANCE_TYPE_DEFAULT, NULL,
9766 ASNOTATION_UNDEFINED);
bb4f6190
DS
9767
9768 if (ret) {
9769 vty_out(vty,
9770 "VRF default is not configured as a bgp instance\n");
9771 return CMD_WARNING;
9772 }
9773 }
9774
69b07479 9775 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 9776
ae6a6fb4
DS
9777 if (bgp->vpn_policy[afi].rmap_name[dir])
9778 XFREE(MTYPE_ROUTE_MAP_NAME,
9779 bgp->vpn_policy[afi].rmap_name[dir]);
9780 bgp->vpn_policy[afi].rmap_name[dir] =
9781 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9782 bgp->vpn_policy[afi].rmap[dir] =
9783 route_map_lookup_warn_noexist(vty, rmap_str);
9784 if (!bgp->vpn_policy[afi].rmap[dir])
9785 return CMD_SUCCESS;
9786
9787 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9788 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 9789
69b07479
DS
9790 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9791
bb4f6190
DS
9792 return CMD_SUCCESS;
9793}
9794
ae6a6fb4
DS
9795DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9796 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
9797 NO_STR
9798 "Import routes from another VRF\n"
9799 "Vrf routes being filtered\n"
ae6a6fb4
DS
9800 "Specify route map\n"
9801 "name of route-map\n")
9802{
9803 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 9804 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
ae6a6fb4
DS
9805 afi_t afi;
9806
9807 afi = vpn_policy_getafi(vty, bgp, true);
9808 if (afi == AFI_MAX)
9809 return CMD_WARNING_CONFIG_FAILED;
9810
9811 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9812
9813 if (bgp->vpn_policy[afi].rmap_name[dir])
9814 XFREE(MTYPE_ROUTE_MAP_NAME,
9815 bgp->vpn_policy[afi].rmap_name[dir]);
9816 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9817 bgp->vpn_policy[afi].rmap[dir] = NULL;
9818
9819 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9820 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9821 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9822
9823 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9824
9825 return CMD_SUCCESS;
9826}
bb4f6190 9827
585f1adc
IR
9828DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9829 "[no] import vrf VIEWVRFNAME$import_name",
9830 NO_STR
9831 "Import routes from another VRF\n"
9832 "VRF to import from\n"
9833 "The name of the VRF\n")
12a844a5 9834{
585f1adc
IR
9835 VTY_DECLVAR_CONTEXT(bgp, bgp);
9836 struct listnode *node;
9837 struct bgp *vrf_bgp, *bgp_default;
9838 int32_t ret = 0;
9839 as_t as = bgp->as;
9840 bool remove = false;
9841 int32_t idx = 0;
9842 char *vname;
9843 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
9844 safi_t safi;
9845 afi_t afi;
9846
867f0cca 9847 if (import_name == NULL) {
9848 vty_out(vty, "%% Missing import name\n");
9849 return CMD_WARNING;
9850 }
9851
ae6a6fb4
DS
9852 if (strcmp(import_name, "route-map") == 0) {
9853 vty_out(vty, "%% Must include route-map name\n");
9854 return CMD_WARNING;
9855 }
9856
585f1adc
IR
9857 if (argv_find(argv, argc, "no", &idx))
9858 remove = true;
9859
9860 afi = vpn_policy_getafi(vty, bgp, true);
9861 if (afi == AFI_MAX)
9862 return CMD_WARNING_CONFIG_FAILED;
9863
12a844a5
DS
9864 safi = bgp_node_safi(vty);
9865
585f1adc
IR
9866 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9867 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9868 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9869 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9870 remove ? "unimport" : "import", import_name);
9871 return CMD_WARNING;
9872 }
25679caa 9873
585f1adc
IR
9874 bgp_default = bgp_get_default();
9875 if (!bgp_default) {
9876 /* Auto-create assuming the same AS */
9877 ret = bgp_get_vty(&bgp_default, &as, NULL,
e55b0883
PG
9878 BGP_INSTANCE_TYPE_DEFAULT, NULL,
9879 ASNOTATION_UNDEFINED);
12a844a5 9880
585f1adc
IR
9881 if (ret) {
9882 vty_out(vty,
9883 "VRF default is not configured as a bgp instance\n");
9884 return CMD_WARNING;
9885 }
9886 }
12a844a5 9887
585f1adc
IR
9888 vrf_bgp = bgp_lookup_by_name(import_name);
9889 if (!vrf_bgp) {
9890 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9891 vrf_bgp = bgp_default;
9892 else
9893 /* Auto-create assuming the same AS */
e55b0883
PG
9894 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type,
9895 NULL, ASNOTATION_UNDEFINED);
585f1adc
IR
9896 if (ret) {
9897 vty_out(vty,
9898 "VRF %s is not configured as a bgp instance\n",
9899 import_name);
9900 return CMD_WARNING;
9901 }
9902 }
9903
9904 if (remove) {
9905 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9906 } else {
9907 /* Already importing from "import_vrf"? */
9908 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9909 vname)) {
9910 if (strcmp(vname, import_name) == 0)
9911 return CMD_WARNING;
9912 }
9913
9914 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9915 }
9916
9917 return CMD_SUCCESS;
12a844a5
DS
9918}
9919
b9c7bc5a 9920/* This command is valid only in a bgp vrf instance or the default instance */
585f1adc 9921DEFPY (bgp_imexport_vpn,
b9c7bc5a
PZ
9922 bgp_imexport_vpn_cmd,
9923 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9924 NO_STR
9925 "Import routes to this address-family\n"
9926 "Export routes from this address-family\n"
9927 "to/from default instance VPN RIB\n")
ddb5b488 9928{
585f1adc
IR
9929 VTY_DECLVAR_CONTEXT(bgp, bgp);
9930 int previous_state;
37a87b8f 9931 afi_t afi;
585f1adc
IR
9932 safi_t safi;
9933 int idx = 0;
9934 bool yes = true;
9935 int flag;
9c2fd3fe 9936 enum vpn_policy_direction dir;
585f1adc
IR
9937
9938 if (argv_find(argv, argc, "no", &idx))
9939 yes = false;
9940
9941 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9942 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9943
9944 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9945 return CMD_WARNING_CONFIG_FAILED;
9946 }
ddb5b488 9947
b9c7bc5a
PZ
9948 afi = bgp_node_afi(vty);
9949 safi = bgp_node_safi(vty);
585f1adc
IR
9950 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9951 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9952 return CMD_WARNING_CONFIG_FAILED;
9953 }
ddb5b488 9954
b9c7bc5a 9955 if (!strcmp(direction_str, "import")) {
585f1adc
IR
9956 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9957 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b9c7bc5a 9958 } else if (!strcmp(direction_str, "export")) {
585f1adc
IR
9959 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9960 dir = BGP_VPN_POLICY_DIR_TOVPN;
b9c7bc5a
PZ
9961 } else {
9962 vty_out(vty, "%% unknown direction %s\n", direction_str);
9963 return CMD_WARNING_CONFIG_FAILED;
9964 }
9965
585f1adc 9966 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 9967
585f1adc
IR
9968 if (yes) {
9969 SET_FLAG(bgp->af_flags[afi][safi], flag);
9970 if (!previous_state) {
9971 /* trigger export current vrf */
9972 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9973 }
9974 } else {
9975 if (previous_state) {
9976 /* trigger un-export current vrf */
9977 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9978 }
9979 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9980 }
37a87b8f 9981
1ca2fd11
IR
9982 hook_call(bgp_snmp_init_stats, bgp);
9983
585f1adc 9984 return CMD_SUCCESS;
ddb5b488
PZ
9985}
9986
301ad80a
PG
9987DEFPY (af_routetarget_import,
9988 af_routetarget_import_cmd,
9a659715 9989 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9990 NO_STR
9991 "Specify route target list\n"
9992 "Specify route target list\n"
9a659715
PG
9993 "Specify route target list\n"
9994 "Specify route target list\n"
301ad80a
PG
9995 "Flow-spec redirect type route target\n"
9996 "Import routes to this address-family\n"
9a659715 9997 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9998{
9999 VTY_DECLVAR_CONTEXT(bgp, bgp);
10000 int ret;
10001 struct ecommunity *ecom = NULL;
301ad80a 10002 afi_t afi;
9a659715 10003 int idx = 0, idx_unused = 0;
c6423c31
PG
10004 bool yes = true;
10005 bool rt6 = false;
301ad80a
PG
10006
10007 if (argv_find(argv, argc, "no", &idx))
c6423c31 10008 yes = false;
301ad80a 10009
9a659715
PG
10010 if (argv_find(argv, argc, "rt6", &idx_unused) ||
10011 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 10012 rt6 = true;
301ad80a 10013
0ca70ba5 10014 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
10015 if (afi == AFI_MAX)
10016 return CMD_WARNING_CONFIG_FAILED;
10017
9a659715
PG
10018 if (rt6 && afi != AFI_IP6)
10019 return CMD_WARNING_CONFIG_FAILED;
10020
301ad80a
PG
10021 if (yes) {
10022 if (!argv_find(argv, argc, "RTLIST", &idx)) {
10023 vty_out(vty, "%% Missing RTLIST\n");
10024 return CMD_WARNING_CONFIG_FAILED;
10025 }
9a659715 10026 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
10027 if (ret != CMD_SUCCESS)
10028 return ret;
10029 }
69b07479
DS
10030
10031 if (yes) {
10032 if (bgp->vpn_policy[afi].import_redirect_rtlist)
10033 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 10034 .import_redirect_rtlist);
69b07479
DS
10035 bgp->vpn_policy[afi].import_redirect_rtlist =
10036 ecommunity_dup(ecom);
10037 } else {
10038 if (bgp->vpn_policy[afi].import_redirect_rtlist)
10039 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 10040 .import_redirect_rtlist);
69b07479 10041 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 10042 }
69b07479 10043
301ad80a
PG
10044 if (ecom)
10045 ecommunity_free(&ecom);
10046
10047 return CMD_SUCCESS;
10048}
10049
505e5056 10050DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 10051 address_family_ipv4_safi_cmd,
10052 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
10053 "Enter Address Family command mode\n"
00e6edb9 10054 BGP_AF_STR
7c40bf39 10055 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 10056{
f51bae9c 10057
d62a17ae 10058 if (argc == 3) {
585f1adc
IR
10059 VTY_DECLVAR_CONTEXT(bgp, bgp);
10060 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
10061 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 10062 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 10063 && safi != SAFI_EVPN) {
31947174
MK
10064 vty_out(vty,
10065 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
10066 return CMD_WARNING_CONFIG_FAILED;
10067 }
585f1adc
IR
10068 vty->node = bgp_node_type(AFI_IP, safi);
10069 } else
10070 vty->node = BGP_IPV4_NODE;
718e3744 10071
d62a17ae 10072 return CMD_SUCCESS;
718e3744 10073}
10074
505e5056 10075DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 10076 address_family_ipv6_safi_cmd,
10077 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
10078 "Enter Address Family command mode\n"
00e6edb9 10079 BGP_AF_STR
7c40bf39 10080 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 10081{
d62a17ae 10082 if (argc == 3) {
585f1adc
IR
10083 VTY_DECLVAR_CONTEXT(bgp, bgp);
10084 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
10085 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 10086 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 10087 && safi != SAFI_EVPN) {
31947174
MK
10088 vty_out(vty,
10089 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
10090 return CMD_WARNING_CONFIG_FAILED;
10091 }
585f1adc
IR
10092 vty->node = bgp_node_type(AFI_IP6, safi);
10093 } else
10094 vty->node = BGP_IPV6_NODE;
25ffbdc1 10095
d62a17ae 10096 return CMD_SUCCESS;
25ffbdc1 10097}
718e3744 10098
d6902373 10099#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 10100DEFUN_NOSH (address_family_vpnv4,
718e3744 10101 address_family_vpnv4_cmd,
8334fd5a 10102 "address-family vpnv4 [unicast]",
718e3744 10103 "Enter Address Family command mode\n"
00e6edb9
DA
10104 BGP_AF_STR
10105 BGP_AF_MODIFIER_STR)
718e3744 10106{
d62a17ae 10107 vty->node = BGP_VPNV4_NODE;
10108 return CMD_SUCCESS;
718e3744 10109}
10110
505e5056 10111DEFUN_NOSH (address_family_vpnv6,
8ecd3266 10112 address_family_vpnv6_cmd,
8334fd5a 10113 "address-family vpnv6 [unicast]",
8ecd3266 10114 "Enter Address Family command mode\n"
00e6edb9
DA
10115 BGP_AF_STR
10116 BGP_AF_MODIFIER_STR)
8ecd3266 10117{
d62a17ae 10118 vty->node = BGP_VPNV6_NODE;
10119 return CMD_SUCCESS;
8ecd3266 10120}
64e4a6c5 10121#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 10122
505e5056 10123DEFUN_NOSH (address_family_evpn,
4e0b7b6d 10124 address_family_evpn_cmd,
7111c1a0 10125 "address-family l2vpn evpn",
4e0b7b6d 10126 "Enter Address Family command mode\n"
00e6edb9
DA
10127 BGP_AF_STR
10128 BGP_AF_MODIFIER_STR)
4e0b7b6d 10129{
2131d5cf 10130 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 10131 vty->node = BGP_EVPN_NODE;
10132 return CMD_SUCCESS;
4e0b7b6d
PG
10133}
10134
bfaab44d
HS
10135DEFUN_NOSH (bgp_segment_routing_srv6,
10136 bgp_segment_routing_srv6_cmd,
10137 "segment-routing srv6",
10138 "Segment-Routing configuration\n"
10139 "Segment-Routing SRv6 configuration\n")
10140{
10141 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 10142 bgp->srv6_enabled = true;
bfaab44d
HS
10143 vty->node = BGP_SRV6_NODE;
10144 return CMD_SUCCESS;
10145}
10146
0249b8b6
HS
10147DEFUN (no_bgp_segment_routing_srv6,
10148 no_bgp_segment_routing_srv6_cmd,
10149 "no segment-routing srv6",
10150 NO_STR
10151 "Segment-Routing configuration\n"
10152 "Segment-Routing SRv6 configuration\n")
10153{
10154 VTY_DECLVAR_CONTEXT(bgp, bgp);
10155
10156 if (strlen(bgp->srv6_locator_name) > 0)
10157 if (bgp_srv6_locator_unset(bgp) < 0)
10158 return CMD_WARNING_CONFIG_FAILED;
10159
10160 bgp->srv6_enabled = false;
10161 return CMD_SUCCESS;
10162}
10163
a0281b2e
HS
10164DEFPY (bgp_srv6_locator,
10165 bgp_srv6_locator_cmd,
10166 "locator NAME$name",
10167 "Specify SRv6 locator\n"
10168 "Specify SRv6 locator\n")
10169{
10170 VTY_DECLVAR_CONTEXT(bgp, bgp);
7de4c885 10171 int ret;
a0281b2e
HS
10172
10173 if (strlen(bgp->srv6_locator_name) > 0
10174 && strcmp(name, bgp->srv6_locator_name) != 0) {
10175 vty_out(vty, "srv6 locator is already configured\n");
10176 return CMD_WARNING_CONFIG_FAILED;
7de4c885
HS
10177 }
10178
10179 snprintf(bgp->srv6_locator_name,
10180 sizeof(bgp->srv6_locator_name), "%s", name);
a0281b2e 10181
7de4c885 10182 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
a0281b2e
HS
10183 if (ret < 0)
10184 return CMD_WARNING_CONFIG_FAILED;
10185
10186 return CMD_SUCCESS;
10187}
10188
0249b8b6
HS
10189DEFPY (no_bgp_srv6_locator,
10190 no_bgp_srv6_locator_cmd,
10191 "no locator NAME$name",
10192 NO_STR
10193 "Specify SRv6 locator\n"
10194 "Specify SRv6 locator\n")
10195{
10196 VTY_DECLVAR_CONTEXT(bgp, bgp);
10197
10198 /* when locator isn't configured, do nothing */
10199 if (strlen(bgp->srv6_locator_name) < 1)
10200 return CMD_SUCCESS;
10201
10202 /* name validation */
10203 if (strcmp(name, bgp->srv6_locator_name) != 0) {
10204 vty_out(vty, "%% No srv6 locator is configured\n");
10205 return CMD_WARNING_CONFIG_FAILED;
10206 }
10207
10208 /* unset locator */
10209 if (bgp_srv6_locator_unset(bgp) < 0)
10210 return CMD_WARNING_CONFIG_FAILED;
10211
10212 return CMD_SUCCESS;
10213}
10214
ea372e81
HS
10215DEFPY (show_bgp_srv6,
10216 show_bgp_srv6_cmd,
10217 "show bgp segment-routing srv6",
10218 SHOW_STR
10219 BGP_STR
10220 "BGP Segment Routing\n"
10221 "BGP Segment Routing SRv6\n")
10222{
10223 struct bgp *bgp;
10224 struct listnode *node;
1c21a234 10225 struct srv6_locator_chunk *chunk;
ea372e81 10226 struct bgp_srv6_function *func;
ea372e81
HS
10227
10228 bgp = bgp_get_default();
96db4340 10229 if (!bgp)
ea372e81
HS
10230 return CMD_SUCCESS;
10231
10232 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
10233 vty_out(vty, "locator_chunks:\n");
dccef127 10234 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
511211bf 10235 vty_out(vty, "- %pFX\n", &chunk->prefix);
dccef127
CS
10236 vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
10237 vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
10238 vty_out(vty, " func-length: %d\n",
10239 chunk->function_bits_length);
10240 vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
10241 }
ea372e81
HS
10242
10243 vty_out(vty, "functions:\n");
10244 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
07380148 10245 vty_out(vty, "- sid: %pI6\n", &func->sid);
ea372e81
HS
10246 vty_out(vty, " locator: %s\n", func->locator_name);
10247 }
10248
10249 vty_out(vty, "bgps:\n");
10250 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
10251 vty_out(vty, "- name: %s\n",
10252 bgp->name ? bgp->name : "default");
10253
1830895a
CS
10254 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
10255 bgp->vpn_policy[AFI_IP].tovpn_sid);
10256 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
10257 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9f5d4430 10258 vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
ea372e81
HS
10259 }
10260
10261 return CMD_SUCCESS;
10262}
10263
505e5056 10264DEFUN_NOSH (exit_address_family,
718e3744 10265 exit_address_family_cmd,
10266 "exit-address-family",
10267 "Exit from Address Family configuration mode\n")
10268{
d62a17ae 10269 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
10270 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
10271 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
10272 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
10273 || vty->node == BGP_EVPN_NODE
10274 || vty->node == BGP_FLOWSPECV4_NODE
10275 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 10276 vty->node = BGP_NODE;
10277 return CMD_SUCCESS;
718e3744 10278}
6b0655a2 10279
8ad7271d 10280/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 10281static int bgp_clear_prefix(struct vty *vty, const char *view_name,
10282 const char *ip_str, afi_t afi, safi_t safi,
10283 struct prefix_rd *prd)
10284{
10285 int ret;
10286 struct prefix match;
9bcb3eef
DS
10287 struct bgp_dest *dest;
10288 struct bgp_dest *rm;
d62a17ae 10289 struct bgp *bgp;
10290 struct bgp_table *table;
10291 struct bgp_table *rib;
10292
10293 /* BGP structure lookup. */
10294 if (view_name) {
10295 bgp = bgp_lookup_by_name(view_name);
10296 if (bgp == NULL) {
10297 vty_out(vty, "%% Can't find BGP instance %s\n",
10298 view_name);
10299 return CMD_WARNING;
10300 }
10301 } else {
10302 bgp = bgp_get_default();
10303 if (bgp == NULL) {
10304 vty_out(vty, "%% No BGP process is configured\n");
10305 return CMD_WARNING;
10306 }
10307 }
10308
10309 /* Check IP address argument. */
10310 ret = str2prefix(ip_str, &match);
10311 if (!ret) {
10312 vty_out(vty, "%% address is malformed\n");
10313 return CMD_WARNING;
10314 }
10315
10316 match.family = afi2family(afi);
10317 rib = bgp->rib[afi][safi];
10318
10319 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
10320 for (dest = bgp_table_top(rib); dest;
10321 dest = bgp_route_next(dest)) {
10322 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 10323
9bcb3eef 10324 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 10325 continue;
10326
9bcb3eef 10327 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
10328 if (table == NULL)
10329 continue;
10330
4953391b
DA
10331 rm = bgp_node_match(table, &match);
10332 if (rm != NULL) {
b54892e0 10333 const struct prefix *rm_p =
9bcb3eef 10334 bgp_dest_get_prefix(rm);
b54892e0
DS
10335
10336 if (rm_p->prefixlen == match.prefixlen) {
10337 SET_FLAG(rm->flags,
10338 BGP_NODE_USER_CLEAR);
10339 bgp_process(bgp, rm, afi, safi);
d62a17ae 10340 }
9bcb3eef 10341 bgp_dest_unlock_node(rm);
d62a17ae 10342 }
10343 }
10344 } else {
4953391b
DA
10345 dest = bgp_node_match(rib, &match);
10346 if (dest != NULL) {
9bcb3eef 10347 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 10348
9bcb3eef
DS
10349 if (dest_p->prefixlen == match.prefixlen) {
10350 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10351 bgp_process(bgp, dest, afi, safi);
d62a17ae 10352 }
9bcb3eef 10353 bgp_dest_unlock_node(dest);
d62a17ae 10354 }
10355 }
10356
10357 return CMD_SUCCESS;
8ad7271d
DS
10358}
10359
b09b5ae0 10360/* one clear bgp command to rule them all */
718e3744 10361DEFUN (clear_ip_bgp_all,
10362 clear_ip_bgp_all_cmd,
8079a413 10363 "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 10364 CLEAR_STR
10365 IP_STR
10366 BGP_STR
838758ac 10367 BGP_INSTANCE_HELP_STR
510afcd6 10368 BGP_AFI_HELP_STR
00e6edb9 10369 BGP_AF_STR
510afcd6 10370 BGP_SAFI_WITH_LABEL_HELP_STR
00e6edb9 10371 BGP_AF_MODIFIER_STR
b09b5ae0 10372 "Clear all peers\n"
453c92f6 10373 "BGP IPv4 neighbor to clear\n"
a80beece 10374 "BGP IPv6 neighbor to clear\n"
838758ac 10375 "BGP neighbor on interface to clear\n"
8079a413 10376 "Clear peers with the AS number in plain or dotted format\n"
b09b5ae0 10377 "Clear all external peers\n"
718e3744 10378 "Clear all members of peer-group\n"
b09b5ae0 10379 "BGP peer-group name\n"
b09b5ae0
DW
10380 BGP_SOFT_STR
10381 BGP_SOFT_IN_STR
b09b5ae0
DW
10382 BGP_SOFT_OUT_STR
10383 BGP_SOFT_IN_STR
10384 "Push out prefix-list ORF and do inbound soft reconfig\n"
3cb14f26
DS
10385 BGP_SOFT_OUT_STR
10386 "Reset message statistics\n")
718e3744 10387{
d62a17ae 10388 char *vrf = NULL;
10389
dc912615
DS
10390 afi_t afi = AFI_UNSPEC;
10391 safi_t safi = SAFI_UNSPEC;
d62a17ae 10392 enum clear_sort clr_sort = clear_peer;
10393 enum bgp_clear_type clr_type;
10394 char *clr_arg = NULL;
10395
10396 int idx = 0;
10397
10398 /* clear [ip] bgp */
10399 if (argv_find(argv, argc, "ip", &idx))
10400 afi = AFI_IP;
10401
9a8bdf1c
PG
10402 /* [<vrf> VIEWVRFNAME] */
10403 if (argv_find(argv, argc, "vrf", &idx)) {
10404 vrf = argv[idx + 1]->arg;
10405 idx += 2;
10406 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10407 vrf = NULL;
10408 } else if (argv_find(argv, argc, "view", &idx)) {
10409 /* [<view> VIEWVRFNAME] */
d62a17ae 10410 vrf = argv[idx + 1]->arg;
10411 idx += 2;
10412 }
d62a17ae 10413 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10414 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10415 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10416
8079a413 10417 /* <*|A.B.C.D|X:X::X:X|WORD|ASNUM|external|peer-group PGNAME> */
d62a17ae 10418 if (argv_find(argv, argc, "*", &idx)) {
10419 clr_sort = clear_all;
10420 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10421 clr_sort = clear_peer;
10422 clr_arg = argv[idx]->arg;
10423 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10424 clr_sort = clear_peer;
10425 clr_arg = argv[idx]->arg;
10426 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10427 clr_sort = clear_group;
10428 idx++;
10429 clr_arg = argv[idx]->arg;
d7b9898c 10430 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 10431 clr_sort = clear_peer;
10432 clr_arg = argv[idx]->arg;
8fa7d444
DS
10433 } else if (argv_find(argv, argc, "WORD", &idx)) {
10434 clr_sort = clear_peer;
10435 clr_arg = argv[idx]->arg;
8079a413 10436 } else if (argv_find(argv, argc, "ASNUM", &idx)) {
d62a17ae 10437 clr_sort = clear_as;
10438 clr_arg = argv[idx]->arg;
10439 } else if (argv_find(argv, argc, "external", &idx)) {
10440 clr_sort = clear_external;
10441 }
10442
3cb14f26 10443 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
d62a17ae 10444 if (argv_find(argv, argc, "soft", &idx)) {
10445 if (argv_find(argv, argc, "in", &idx)
10446 || argv_find(argv, argc, "out", &idx))
10447 clr_type = strmatch(argv[idx]->text, "in")
10448 ? BGP_CLEAR_SOFT_IN
10449 : BGP_CLEAR_SOFT_OUT;
10450 else
10451 clr_type = BGP_CLEAR_SOFT_BOTH;
10452 } else if (argv_find(argv, argc, "in", &idx)) {
10453 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10454 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10455 : BGP_CLEAR_SOFT_IN;
10456 } else if (argv_find(argv, argc, "out", &idx)) {
10457 clr_type = BGP_CLEAR_SOFT_OUT;
3cb14f26
DS
10458 } else if (argv_find(argv, argc, "message-stats", &idx)) {
10459 clr_type = BGP_CLEAR_MESSAGE_STATS;
d62a17ae 10460 } else
10461 clr_type = BGP_CLEAR_SOFT_NONE;
10462
1ca2fd11 10463 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 10464}
01080f7c 10465
8ad7271d
DS
10466DEFUN (clear_ip_bgp_prefix,
10467 clear_ip_bgp_prefix_cmd,
18c57037 10468 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
10469 CLEAR_STR
10470 IP_STR
10471 BGP_STR
838758ac 10472 BGP_INSTANCE_HELP_STR
8ad7271d 10473 "Clear bestpath and re-advertise\n"
0c7b1b01 10474 "IPv4 prefix\n")
8ad7271d 10475{
d62a17ae 10476 char *vrf = NULL;
10477 char *prefix = NULL;
8ad7271d 10478
d62a17ae 10479 int idx = 0;
01080f7c 10480
d62a17ae 10481 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
10482 if (argv_find(argv, argc, "vrf", &idx)) {
10483 vrf = argv[idx + 1]->arg;
10484 idx += 2;
10485 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10486 vrf = NULL;
10487 } else if (argv_find(argv, argc, "view", &idx)) {
10488 /* [<view> VIEWVRFNAME] */
10489 vrf = argv[idx + 1]->arg;
10490 idx += 2;
10491 }
0c7b1b01 10492
d62a17ae 10493 prefix = argv[argc - 1]->arg;
8ad7271d 10494
d62a17ae 10495 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 10496}
8ad7271d 10497
b09b5ae0
DW
10498DEFUN (clear_bgp_ipv6_safi_prefix,
10499 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 10500 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10501 CLEAR_STR
3a2d747c 10502 IP_STR
718e3744 10503 BGP_STR
00e6edb9 10504 BGP_AF_STR
46f296b4 10505 BGP_SAFI_HELP_STR
b09b5ae0 10506 "Clear bestpath and re-advertise\n"
0c7b1b01 10507 "IPv6 prefix\n")
718e3744 10508{
9b475e76
PG
10509 int idx_safi = 0;
10510 int idx_ipv6_prefix = 0;
10511 safi_t safi = SAFI_UNICAST;
10512 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10513 argv[idx_ipv6_prefix]->arg : NULL;
10514
10515 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 10516 return bgp_clear_prefix(
9b475e76
PG
10517 vty, NULL, prefix, AFI_IP6,
10518 safi, NULL);
838758ac 10519}
01080f7c 10520
b09b5ae0
DW
10521DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10522 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 10523 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10524 CLEAR_STR
3a2d747c 10525 IP_STR
718e3744 10526 BGP_STR
838758ac 10527 BGP_INSTANCE_HELP_STR
00e6edb9 10528 BGP_AF_STR
46f296b4 10529 BGP_SAFI_HELP_STR
b09b5ae0 10530 "Clear bestpath and re-advertise\n"
0c7b1b01 10531 "IPv6 prefix\n")
718e3744 10532{
9b475e76 10533 int idx_safi = 0;
9a8bdf1c 10534 int idx_vrfview = 0;
9b475e76
PG
10535 int idx_ipv6_prefix = 0;
10536 safi_t safi = SAFI_UNICAST;
10537 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10538 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 10539 char *vrfview = NULL;
9b475e76 10540
9a8bdf1c
PG
10541 /* [<view|vrf> VIEWVRFNAME] */
10542 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10543 vrfview = argv[idx_vrfview + 1]->arg;
10544 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10545 vrfview = NULL;
10546 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10547 /* [<view> VIEWVRFNAME] */
10548 vrfview = argv[idx_vrfview + 1]->arg;
10549 }
9b475e76
PG
10550 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10551
d62a17ae 10552 return bgp_clear_prefix(
9b475e76
PG
10553 vty, vrfview, prefix,
10554 AFI_IP6, safi, NULL);
718e3744 10555}
10556
b09b5ae0
DW
10557DEFUN (show_bgp_views,
10558 show_bgp_views_cmd,
d6e3c605 10559 "show [ip] bgp views",
b09b5ae0 10560 SHOW_STR
d6e3c605 10561 IP_STR
01080f7c 10562 BGP_STR
b09b5ae0 10563 "Show the defined BGP views\n")
01080f7c 10564{
d62a17ae 10565 struct list *inst = bm->bgp;
10566 struct listnode *node;
10567 struct bgp *bgp;
01080f7c 10568
d62a17ae 10569 vty_out(vty, "Defined BGP views:\n");
10570 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10571 /* Skip VRFs. */
10572 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10573 continue;
9eb11997
PG
10574 vty_out(vty, "\t%s (AS%s)\n", bgp->name ? bgp->name : "(null)",
10575 bgp->as_pretty);
d62a17ae 10576 }
e52702f2 10577
d62a17ae 10578 return CMD_SUCCESS;
e0081f70
ML
10579}
10580
4acd6bc9
SPG
10581static inline void calc_peers_cfgd_estbd(struct bgp *bgp, int *peers_cfgd,
10582 int *peers_estbd)
10583{
10584 struct peer *peer;
10585 struct listnode *node;
10586
10587 *peers_cfgd = *peers_estbd = 0;
10588 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
10589 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10590 continue;
10591 (*peers_cfgd)++;
10592 if (peer_established(peer))
10593 (*peers_estbd)++;
10594 }
10595}
10596
10597static void print_bgp_vrfs(struct bgp *bgp, struct vty *vty, json_object *json,
10598 const char *type)
10599{
10600 int peers_cfg, peers_estb;
10601
10602 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10603
10604 if (json) {
10605 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10606 ? -1
10607 : (int64_t)bgp->vrf_id;
10608 json_object_string_add(json, "type", type);
10609 json_object_int_add(json, "vrfId", vrf_id_ui);
10610 json_object_string_addf(json, "routerId", "%pI4",
10611 &bgp->router_id);
10612 json_object_int_add(json, "numConfiguredPeers", peers_cfg);
10613 json_object_int_add(json, "numEstablishedPeers", peers_estb);
10614 json_object_int_add(json, "l3vni", bgp->l3vni);
10615 json_object_string_addf(json, "rmac", "%pEA", &bgp->rmac);
10616 json_object_string_add(
10617 json, "interface",
10618 ifindex2ifname(bgp->l3vni_svi_ifindex, bgp->vrf_id));
10619 }
10620}
10621
10622static int show_bgp_vrfs_detail_common(struct vty *vty, struct bgp *bgp,
10623 json_object *json, const char *name,
10624 const char *type, bool use_vrf)
10625{
10626 int peers_cfg, peers_estb;
10627
10628 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10629
10630 if (use_vrf) {
10631 if (json) {
10632 print_bgp_vrfs(bgp, vty, json, type);
10633 } else {
10634 vty_out(vty, "BGP instance %s VRF id %d\n",
10635 bgp->name_pretty,
10636 bgp->vrf_id == VRF_UNKNOWN ? -1
10637 : (int)bgp->vrf_id);
10638 vty_out(vty, "Router Id %pI4\n", &bgp->router_id);
10639 vty_out(vty,
10640 "Num Configured Peers %d, Established %d\n",
10641 peers_cfg, peers_estb);
10642 if (bgp->l3vni) {
10643 vty_out(vty,
10644 "L3VNI %u, L3VNI-SVI %s, Router MAC %pEA\n",
10645 bgp->l3vni,
10646 ifindex2ifname(bgp->l3vni_svi_ifindex,
10647 bgp->vrf_id),
10648 &bgp->rmac);
10649 }
10650 }
10651 } else {
10652 if (json) {
10653 print_bgp_vrfs(bgp, vty, json, type);
10654 } else {
10655 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10656 type,
10657 bgp->vrf_id == VRF_UNKNOWN ? -1
10658 : (int)bgp->vrf_id,
10659 &bgp->router_id, peers_cfg, peers_estb, name);
10660 vty_out(vty, "%11s %-16u %-21pEA %-20s\n", " ",
10661 bgp->l3vni, &bgp->rmac,
10662 ifindex2ifname(bgp->l3vni_svi_ifindex,
10663 bgp->vrf_id));
10664 }
10665 }
10666
10667 return CMD_SUCCESS;
10668}
10669
10670DEFPY (show_bgp_vrfs,
8386ac43 10671 show_bgp_vrfs_cmd,
4acd6bc9 10672 "show [ip] bgp vrfs [<VRFNAME$vrf_name>] [json]",
8386ac43 10673 SHOW_STR
d6e3c605 10674 IP_STR
8386ac43 10675 BGP_STR
10676 "Show BGP VRFs\n"
4acd6bc9 10677 "Specific VRF name\n"
9973d184 10678 JSON_STR)
8386ac43 10679{
d62a17ae 10680 struct list *inst = bm->bgp;
10681 struct listnode *node;
10682 struct bgp *bgp;
9f049418 10683 bool uj = use_json(argc, argv);
d62a17ae 10684 json_object *json = NULL;
10685 json_object *json_vrfs = NULL;
4acd6bc9 10686 json_object *json_vrf = NULL;
d62a17ae 10687 int count = 0;
4acd6bc9
SPG
10688 const char *name = vrf_name;
10689 const char *type;
d62a17ae 10690
4acd6bc9 10691 if (uj)
d62a17ae 10692 json = json_object_new_object();
4acd6bc9
SPG
10693
10694 if (name) {
10695 if (strmatch(name, VRF_DEFAULT_NAME)) {
10696 bgp = bgp_get_default();
10697 type = "DFLT";
10698 } else {
10699 bgp = bgp_lookup_by_name(name);
10700 type = "VRF";
10701 }
10702 if (!bgp) {
10703 if (uj)
10704 vty_json(vty, json);
10705 else
10706 vty_out(vty,
10707 "%% Specified BGP instance not found\n");
10708
10709 return CMD_WARNING;
10710 }
10711 }
10712
10713 if (vrf_name) {
10714 if (uj)
10715 json_vrf = json_object_new_object();
10716
10717 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10718 true);
10719
10720 if (uj) {
10721 json_object_object_add(json, name, json_vrf);
10722 vty_json(vty, json);
10723 }
10724
10725 return CMD_SUCCESS;
d62a17ae 10726 }
10727
4acd6bc9
SPG
10728 if (uj)
10729 json_vrfs = json_object_new_object();
10730
d62a17ae 10731 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
4acd6bc9 10732 const char *name;
d62a17ae 10733
10734 /* Skip Views. */
10735 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10736 continue;
10737
10738 count++;
efb4077a 10739 if (!uj && count == 1) {
fe1dc5a3 10740 vty_out(vty,
efb4077a 10741 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 10742 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
10743 "#PeersEstb", "Name");
10744 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10745 "L3-VNI", "RouterMAC", "Interface");
10746 }
d62a17ae 10747 if (uj)
10748 json_vrf = json_object_new_object();
10749
d62a17ae 10750 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 10751 name = VRF_DEFAULT_NAME;
d62a17ae 10752 type = "DFLT";
10753 } else {
10754 name = bgp->name;
10755 type = "VRF";
10756 }
10757
4acd6bc9
SPG
10758 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10759 false);
a8bf7d9c 10760
4acd6bc9 10761 if (uj)
d62a17ae 10762 json_object_object_add(json_vrfs, name, json_vrf);
d62a17ae 10763 }
10764
10765 if (uj) {
10766 json_object_object_add(json, "vrfs", json_vrfs);
d62a17ae 10767 json_object_int_add(json, "totalVrfs", count);
75eeda93 10768 vty_json(vty, json);
d62a17ae 10769 } else {
10770 if (count)
10771 vty_out(vty,
10772 "\nTotal number of VRFs (including default): %d\n",
10773 count);
10774 }
10775
10776 return CMD_SUCCESS;
8386ac43 10777}
10778
48ecf8f5
DS
10779DEFUN (show_bgp_mac_hash,
10780 show_bgp_mac_hash_cmd,
10781 "show bgp mac hash",
10782 SHOW_STR
10783 BGP_STR
10784 "Mac Address\n"
10785 "Mac Address database\n")
10786{
10787 bgp_mac_dump_table(vty);
10788
10789 return CMD_SUCCESS;
10790}
acf71666 10791
e3b78da8 10792static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 10793{
0291c246 10794 struct vty *vty = (struct vty *)args;
e3b78da8 10795 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 10796
23d0a753 10797 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
10798}
10799
10800static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10801{
10802 vty_out(vty, "self nexthop database:\n");
af97a18b 10803 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
10804
10805 vty_out(vty, "Tunnel-ip database:\n");
10806 hash_iterate(bgp->tip_hash,
e3b78da8 10807 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
10808 vty);
10809}
10810
15c81ca4
DS
10811DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10812 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10813 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
10814 "martian next-hops\n"
10815 "martian next-hop database\n")
acf71666 10816{
0291c246 10817 struct bgp *bgp = NULL;
15c81ca4 10818 int idx = 0;
9a8bdf1c
PG
10819 char *name = NULL;
10820
10821 /* [<vrf> VIEWVRFNAME] */
10822 if (argv_find(argv, argc, "vrf", &idx)) {
10823 name = argv[idx + 1]->arg;
10824 if (name && strmatch(name, VRF_DEFAULT_NAME))
10825 name = NULL;
10826 } else if (argv_find(argv, argc, "view", &idx))
10827 /* [<view> VIEWVRFNAME] */
10828 name = argv[idx + 1]->arg;
10829 if (name)
10830 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
10831 else
10832 bgp = bgp_get_default();
acf71666 10833
acf71666
MK
10834 if (!bgp) {
10835 vty_out(vty, "%% No BGP process is configured\n");
10836 return CMD_WARNING;
10837 }
10838 bgp_show_martian_nexthops(vty, bgp);
10839
10840 return CMD_SUCCESS;
10841}
10842
f412b39a 10843DEFUN (show_bgp_memory,
4bf6a362 10844 show_bgp_memory_cmd,
7fa12b13 10845 "show [ip] bgp memory",
4bf6a362 10846 SHOW_STR
3a2d747c 10847 IP_STR
4bf6a362
PJ
10848 BGP_STR
10849 "Global BGP memory statistics\n")
10850{
d62a17ae 10851 char memstrbuf[MTYPE_MEMSTR_LEN];
10852 unsigned long count;
10853
10854 /* RIB related usage stats */
10855 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10856 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10857 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 10858 count * sizeof(struct bgp_dest)));
d62a17ae 10859
10860 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10861 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10862 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 10863 count * sizeof(struct bgp_path_info)));
d62a17ae 10864 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10865 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10866 count,
4b7e6066
DS
10867 mtype_memstr(
10868 memstrbuf, sizeof(memstrbuf),
10869 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 10870
10871 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10872 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10873 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10874 count * sizeof(struct bgp_static)));
10875
10876 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10877 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10878 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10879 count * sizeof(struct bpacket)));
10880
10881 /* Adj-In/Out */
10882 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10883 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10884 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10885 count * sizeof(struct bgp_adj_in)));
10886 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10887 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10888 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10889 count * sizeof(struct bgp_adj_out)));
10890
10891 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10892 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10893 count,
10894 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10895 count * sizeof(struct bgp_nexthop_cache)));
10896
10897 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10898 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10899 count,
10900 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10901 count * sizeof(struct bgp_damp_info)));
10902
10903 /* Attributes */
10904 count = attr_count();
10905 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10906 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10907 count * sizeof(struct attr)));
10908
10909 if ((count = attr_unknown_count()))
10910 vty_out(vty, "%ld unknown attributes\n", count);
10911
10912 /* AS_PATH attributes */
10913 count = aspath_count();
10914 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10915 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10916 count * sizeof(struct aspath)));
10917
10918 count = mtype_stats_alloc(MTYPE_AS_SEG);
10919 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10920 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10921 count * sizeof(struct assegment)));
10922
10923 /* Other attributes */
10924 if ((count = community_count()))
10925 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10926 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10927 count * sizeof(struct community)));
d62a17ae 10928 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
145f7619
DA
10929 vty_out(vty,
10930 "%ld BGP ext-community entries, using %s of memory\n",
10931 count,
10932 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10933 count * sizeof(struct ecommunity)));
d62a17ae 10934 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10935 vty_out(vty,
10936 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10937 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10938 count * sizeof(struct lcommunity)));
d62a17ae 10939
10940 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10941 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10942 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10943 count * sizeof(struct cluster_list)));
10944
10945 /* Peer related usage */
10946 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10947 vty_out(vty, "%ld peers, using %s of memory\n", count,
10948 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10949 count * sizeof(struct peer)));
10950
10951 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10952 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10953 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10954 count * sizeof(struct peer_group)));
10955
10956 /* Other */
d62a17ae 10957 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10958 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10959 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10960 count * sizeof(regex_t)));
d62a17ae 10961 return CMD_SUCCESS;
4bf6a362 10962}
fee0f4c6 10963
57a9c8a8
DS
10964static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10965{
10966 json_object *bestpath = json_object_new_object();
10967
892fedb6 10968 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10969 json_object_string_add(bestpath, "asPath", "ignore");
10970
892fedb6 10971 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10972 json_object_string_add(bestpath, "asPath", "confed");
10973
892fedb6
DA
10974 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10975 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10976 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10977 "as-set");
10978 else
a4d82a8a 10979 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10980 "true");
10981 } else
a4d82a8a 10982 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10983
ee88563a
JM
10984 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10985 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10986
892fedb6 10987 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10988 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10989 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10990 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10991 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10992 json_object_string_add(bestpath, "med", "confed");
892fedb6 10993 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10994 json_object_string_add(bestpath, "med",
10995 "missing-as-worst");
10996 else
10997 json_object_string_add(bestpath, "med", "true");
10998 }
10999
11000 json_object_object_add(json, "bestPath", bestpath);
11001}
11002
3577f1c5
DD
11003/* Print the error code/subcode for why the peer is down */
11004static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
11005 json_object *json_peer, bool use_json)
11006{
11007 const char *code_str;
11008 const char *subcode_str;
11009
11010 if (use_json) {
11011 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
11012 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
11013 char errorcodesubcode_hexstr[5];
11014 char errorcodesubcode_str[256];
11015
11016 code_str = bgp_notify_code_str(peer->notify.code);
11017 subcode_str = bgp_notify_subcode_str(
11018 peer->notify.code,
11019 peer->notify.subcode);
11020
772270f3
QY
11021 snprintf(errorcodesubcode_hexstr,
11022 sizeof(errorcodesubcode_hexstr), "%02X%02X",
11023 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
11024 json_object_string_add(json_peer,
11025 "lastErrorCodeSubcode",
11026 errorcodesubcode_hexstr);
11027 snprintf(errorcodesubcode_str, 255, "%s%s",
11028 code_str, subcode_str);
11029 json_object_string_add(json_peer,
11030 "lastNotificationReason",
11031 errorcodesubcode_str);
eea685b6
DA
11032 json_object_boolean_add(json_peer,
11033 "lastNotificationHardReset",
11034 peer->notify.hard_reset);
3577f1c5
DD
11035 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
11036 && peer->notify.code == BGP_NOTIFY_CEASE
11037 && (peer->notify.subcode
11038 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
11039 || peer->notify.subcode
11040 == BGP_NOTIFY_CEASE_ADMIN_RESET)
11041 && peer->notify.length) {
11042 char msgbuf[1024];
11043 const char *msg_str;
11044
11045 msg_str = bgp_notify_admin_message(
11046 msgbuf, sizeof(msgbuf),
11047 (uint8_t *)peer->notify.data,
11048 peer->notify.length);
11049 if (msg_str)
11050 json_object_string_add(
11051 json_peer,
11052 "lastShutdownDescription",
11053 msg_str);
11054 }
11055
c258527b 11056 }
3577f1c5
DD
11057 json_object_string_add(json_peer, "lastResetDueTo",
11058 peer_down_str[(int)peer->last_reset]);
05912a17
DD
11059 json_object_int_add(json_peer, "lastResetCode",
11060 peer->last_reset);
234f6fd4
DA
11061 json_object_string_add(json_peer, "softwareVersion",
11062 peer->soft_version ? peer->soft_version
11063 : "n/a");
3577f1c5
DD
11064 } else {
11065 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
11066 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
11067 code_str = bgp_notify_code_str(peer->notify.code);
11068 subcode_str =
11069 bgp_notify_subcode_str(peer->notify.code,
11070 peer->notify.subcode);
eea685b6 11071 vty_out(vty, " Notification %s (%s%s%s)\n",
3577f1c5 11072 peer->last_reset == PEER_DOWN_NOTIFY_SEND
eea685b6
DA
11073 ? "sent"
11074 : "received",
11075 code_str, subcode_str,
11076 peer->notify.hard_reset
11077 ? bgp_notify_subcode_str(
11078 BGP_NOTIFY_CEASE,
11079 BGP_NOTIFY_CEASE_HARD_RESET)
11080 : "");
3577f1c5 11081 } else {
234f6fd4
DA
11082 vty_out(vty, " %s (%s)\n",
11083 peer_down_str[(int)peer->last_reset],
11084 peer->soft_version ? peer->soft_version
11085 : "n/a");
3577f1c5
DD
11086 }
11087 }
11088}
11089
11090static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
11091 safi_t safi)
11092{
feb17238 11093 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
3577f1c5
DD
11094}
11095
11096static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
11097 struct peer *peer, json_object *json_peer,
11098 int max_neighbor_width, bool use_json)
11099{
11100 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
11101 int len;
11102
11103 if (use_json) {
11104 if (peer_dynamic_neighbor(peer))
11105 json_object_boolean_true_add(json_peer,
11106 "dynamicPeer");
11107 if (peer->hostname)
11108 json_object_string_add(json_peer, "hostname",
11109 peer->hostname);
11110
11111 if (peer->domainname)
11112 json_object_string_add(json_peer, "domainname",
11113 peer->domainname);
11114 json_object_int_add(json_peer, "connectionsEstablished",
11115 peer->established);
11116 json_object_int_add(json_peer, "connectionsDropped",
11117 peer->dropped);
11118 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11119 use_json, json_peer);
feb17238 11120 if (peer_established(peer))
3577f1c5
DD
11121 json_object_string_add(json_peer, "lastResetDueTo",
11122 "AFI/SAFI Not Negotiated");
11123 else
11124 bgp_show_peer_reset(NULL, peer, json_peer, true);
11125 } else {
11126 dn_flag[1] = '\0';
11127 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
11128 if (peer->hostname
892fedb6 11129 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
11130 len = vty_out(vty, "%s%s(%s)", dn_flag,
11131 peer->hostname, peer->host);
11132 else
11133 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11134
11135 /* pad the neighbor column with spaces */
11136 if (len < max_neighbor_width)
11137 vty_out(vty, "%*s", max_neighbor_width - len,
11138 " ");
e91c24c8 11139 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
11140 peer->dropped,
11141 peer_uptime(peer->uptime, timebuf,
11142 BGP_UPTIME_LEN, 0, NULL));
feb17238 11143 if (peer_established(peer))
3577f1c5
DD
11144 vty_out(vty, " AFI/SAFI Not Negotiated\n");
11145 else
11146 bgp_show_peer_reset(vty, peer, NULL,
11147 false);
11148 }
11149}
c258527b 11150
565e9ddd 11151/* Strip peer's description to the given size. */
cb75bb31
DA
11152static char *bgp_peer_description_stripped(char *desc, uint32_t size)
11153{
11154 static char stripped[BUFSIZ];
64541ffa 11155 uint32_t i = 0;
420ac3d2 11156 uint32_t last_space = size;
cb75bb31 11157
64541ffa 11158 while (i < size) {
420ac3d2 11159 if (*(desc + i) == '\0') {
64541ffa
FD
11160 stripped[i] = '\0';
11161 return stripped;
11162 }
11163 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
11164 last_space = i;
11165 stripped[i] = *(desc + i);
11166 i++;
11167 }
11168
420ac3d2 11169 stripped[last_space] = '\0';
cb75bb31
DA
11170
11171 return stripped;
11172}
3577f1c5 11173
8c1d4cd5
LS
11174/* Determine whether var peer should be filtered out of the summary. */
11175static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
11176 struct peer *fpeer, int as_type,
11177 as_t as)
11178{
11179
11180 /* filter neighbor XXXX */
11181 if (fpeer && fpeer != peer)
11182 return true;
11183
11184 /* filter remote-as (internal|external) */
11185 if (as_type != AS_UNSPECIFIED) {
11186 if (peer->as_type == AS_SPECIFIED) {
11187 if (as_type == AS_INTERNAL) {
11188 if (peer->as != peer->local_as)
11189 return true;
11190 } else if (peer->as == peer->local_as)
11191 return true;
11192 } else if (as_type != peer->as_type)
11193 return true;
11194 } else if (as && as != peer->as) /* filter remote-as XXX */
11195 return true;
11196
11197 return false;
11198}
11199
565e9ddd
DA
11200/* Show BGP peer's summary information.
11201 *
11202 * Peer's description is stripped according to if `wide` option is given
11203 * or not.
11204 *
11205 * When adding new columns to `show bgp summary` output, please make
11206 * sure `Desc` is the lastest column to show because it can contain
11207 * whitespaces and the whole output will be tricky.
11208 */
d62a17ae 11209static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 11210 struct peer *fpeer, int as_type, as_t as,
96c81f66 11211 uint16_t show_flags)
d62a17ae 11212{
11213 struct peer *peer;
11214 struct listnode *node, *nnode;
11215 unsigned int count = 0, dn_count = 0;
11216 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
11217 char neighbor_buf[VTY_BUFSIZ];
11218 int neighbor_col_default_width = 16;
3577f1c5 11219 int len, failed_count = 0;
ce1944f0 11220 unsigned int filtered_count = 0;
d62a17ae 11221 int max_neighbor_width = 0;
11222 int pfx_rcd_safi;
3c13337d 11223 json_object *json = NULL;
d62a17ae 11224 json_object *json_peer = NULL;
11225 json_object *json_peers = NULL;
50e05855 11226 struct peer_af *paf;
d3ada366 11227 struct bgp_filter *filter;
85eeb029
DA
11228 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11229 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11230 bool show_established =
11231 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11232 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
96c81f66 11233 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
d62a17ae 11234
11235 /* labeled-unicast routes are installed in the unicast table so in order
11236 * to
11237 * display the correct PfxRcd value we must look at SAFI_UNICAST
11238 */
3577f1c5 11239
d62a17ae 11240 if (safi == SAFI_LABELED_UNICAST)
11241 pfx_rcd_safi = SAFI_UNICAST;
11242 else
11243 pfx_rcd_safi = safi;
11244
11245 if (use_json) {
3c13337d 11246 json = json_object_new_object();
d62a17ae 11247 json_peers = json_object_new_object();
3577f1c5 11248 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
11249 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11250 as_type, as)) {
ce1944f0 11251 filtered_count++;
8c1d4cd5
LS
11252 count++;
11253 continue;
11254 }
11255
3577f1c5
DD
11256 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11257 continue;
11258
11259 if (peer->afc[afi][safi]) {
11260 /* See if we have at least a single failed peer */
11261 if (bgp_has_peer_failed(peer, afi, safi))
11262 failed_count++;
11263 count++;
11264 }
11265 if (peer_dynamic_neighbor(peer))
11266 dn_count++;
11267 }
c258527b 11268
d62a17ae 11269 } else {
11270 /* Loop over all neighbors that will be displayed to determine
11271 * how many
11272 * characters are needed for the Neighbor column
11273 */
11274 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
11275 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11276 as_type, as)) {
ce1944f0 11277 filtered_count++;
8c1d4cd5
LS
11278 count++;
11279 continue;
11280 }
11281
d62a17ae 11282 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11283 continue;
11284
11285 if (peer->afc[afi][safi]) {
11286 memset(dn_flag, '\0', sizeof(dn_flag));
11287 if (peer_dynamic_neighbor(peer))
11288 dn_flag[0] = '*';
11289
11290 if (peer->hostname
892fedb6
DA
11291 && CHECK_FLAG(bgp->flags,
11292 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
11293 snprintf(neighbor_buf,
11294 sizeof(neighbor_buf),
11295 "%s%s(%s) ", dn_flag,
11296 peer->hostname, peer->host);
d62a17ae 11297 else
772270f3
QY
11298 snprintf(neighbor_buf,
11299 sizeof(neighbor_buf), "%s%s ",
11300 dn_flag, peer->host);
d62a17ae 11301
11302 len = strlen(neighbor_buf);
11303
11304 if (len > max_neighbor_width)
11305 max_neighbor_width = len;
c258527b 11306
3577f1c5
DD
11307 /* See if we have at least a single failed peer */
11308 if (bgp_has_peer_failed(peer, afi, safi))
11309 failed_count++;
11310 count++;
d62a17ae 11311 }
11312 }
f933309e 11313
d62a17ae 11314 /* Originally we displayed the Neighbor column as 16
11315 * characters wide so make that the default
11316 */
11317 if (max_neighbor_width < neighbor_col_default_width)
11318 max_neighbor_width = neighbor_col_default_width;
11319 }
f933309e 11320
3577f1c5
DD
11321 if (show_failed && !failed_count) {
11322 if (use_json) {
11323 json_object_int_add(json, "failedPeersCount", 0);
11324 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 11325 json_object_int_add(json, "totalPeers", count);
3577f1c5 11326
75eeda93 11327 vty_json(vty, json);
3577f1c5
DD
11328 } else {
11329 vty_out(vty, "%% No failed BGP neighbors found\n");
3577f1c5
DD
11330 }
11331 return CMD_SUCCESS;
11332 }
c258527b 11333
3577f1c5 11334 count = 0; /* Reset the value as its used again */
ce1944f0 11335 filtered_count = 0;
800867d8 11336 dn_count = 0;
d62a17ae 11337 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11338 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11339 continue;
11340
ea47320b
DL
11341 if (!peer->afc[afi][safi])
11342 continue;
d62a17ae 11343
ea47320b
DL
11344 if (!count) {
11345 unsigned long ents;
11346 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 11347 int64_t vrf_id_ui;
d62a17ae 11348
a4d82a8a
PZ
11349 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
11350 ? -1
11351 : (int64_t)bgp->vrf_id;
ea47320b
DL
11352
11353 /* Usage summary and header */
11354 if (use_json) {
c949c771
DA
11355 json_object_string_addf(json, "routerId",
11356 "%pI4",
11357 &bgp->router_id);
e84c7c12
PG
11358 asn_asn2json(json, "as", bgp->as,
11359 bgp->asnotation);
60466a63 11360 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
11361 json_object_string_add(
11362 json, "vrfName",
11363 (bgp->inst_type
11364 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11365 ? VRF_DEFAULT_NAME
ea47320b
DL
11366 : bgp->name);
11367 } else {
11368 vty_out(vty,
9eb11997
PG
11369 "BGP router identifier %pI4, local AS number %s vrf-id %d",
11370 &bgp->router_id, bgp->as_pretty,
a4d82a8a
PZ
11371 bgp->vrf_id == VRF_UNKNOWN
11372 ? -1
11373 : (int)bgp->vrf_id);
ea47320b
DL
11374 vty_out(vty, "\n");
11375 }
d62a17ae 11376
ea47320b 11377 if (bgp_update_delay_configured(bgp)) {
d62a17ae 11378 if (use_json) {
ea47320b 11379 json_object_int_add(
60466a63 11380 json, "updateDelayLimit",
ea47320b 11381 bgp->v_update_delay);
d62a17ae 11382
ea47320b
DL
11383 if (bgp->v_update_delay
11384 != bgp->v_establish_wait)
d62a17ae 11385 json_object_int_add(
11386 json,
ea47320b
DL
11387 "updateDelayEstablishWait",
11388 bgp->v_establish_wait);
d62a17ae 11389
60466a63 11390 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
11391 json_object_string_add(
11392 json,
11393 "updateDelayFirstNeighbor",
11394 bgp->update_delay_begin_time);
11395 json_object_boolean_true_add(
11396 json,
11397 "updateDelayInProgress");
11398 } else {
11399 if (bgp->update_delay_over) {
d62a17ae 11400 json_object_string_add(
11401 json,
11402 "updateDelayFirstNeighbor",
11403 bgp->update_delay_begin_time);
ea47320b 11404 json_object_string_add(
d62a17ae 11405 json,
ea47320b
DL
11406 "updateDelayBestpathResumed",
11407 bgp->update_delay_end_time);
11408 json_object_string_add(
d62a17ae 11409 json,
ea47320b
DL
11410 "updateDelayZebraUpdateResume",
11411 bgp->update_delay_zebra_resume_time);
11412 json_object_string_add(
11413 json,
11414 "updateDelayPeerUpdateResume",
11415 bgp->update_delay_peers_resume_time);
d62a17ae 11416 }
ea47320b
DL
11417 }
11418 } else {
11419 vty_out(vty,
11420 "Read-only mode update-delay limit: %d seconds\n",
11421 bgp->v_update_delay);
11422 if (bgp->v_update_delay
11423 != bgp->v_establish_wait)
d62a17ae 11424 vty_out(vty,
ea47320b
DL
11425 " Establish wait: %d seconds\n",
11426 bgp->v_establish_wait);
d62a17ae 11427
60466a63 11428 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
11429 vty_out(vty,
11430 " First neighbor established: %s\n",
11431 bgp->update_delay_begin_time);
11432 vty_out(vty,
11433 " Delay in progress\n");
11434 } else {
11435 if (bgp->update_delay_over) {
d62a17ae 11436 vty_out(vty,
11437 " First neighbor established: %s\n",
11438 bgp->update_delay_begin_time);
11439 vty_out(vty,
ea47320b
DL
11440 " Best-paths resumed: %s\n",
11441 bgp->update_delay_end_time);
11442 vty_out(vty,
11443 " zebra update resumed: %s\n",
11444 bgp->update_delay_zebra_resume_time);
11445 vty_out(vty,
11446 " peers update resumed: %s\n",
11447 bgp->update_delay_peers_resume_time);
d62a17ae 11448 }
11449 }
11450 }
ea47320b 11451 }
d62a17ae 11452
ea47320b
DL
11453 if (use_json) {
11454 if (bgp_maxmed_onstartup_configured(bgp)
11455 && bgp->maxmed_active)
11456 json_object_boolean_true_add(
60466a63 11457 json, "maxMedOnStartup");
ea47320b
DL
11458 if (bgp->v_maxmed_admin)
11459 json_object_boolean_true_add(
60466a63 11460 json, "maxMedAdministrative");
d62a17ae 11461
ea47320b
DL
11462 json_object_int_add(
11463 json, "tableVersion",
60466a63 11464 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 11465
60466a63
QY
11466 ents = bgp_table_count(bgp->rib[afi][safi]);
11467 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
11468 json_object_int_add(
11469 json, "ribMemory",
9bcb3eef 11470 ents * sizeof(struct bgp_dest));
d62a17ae 11471
210ec2a0 11472 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
11473 json_object_int_add(json, "peerCount", ents);
11474 json_object_int_add(json, "peerMemory",
11475 ents * sizeof(struct peer));
d62a17ae 11476
ea47320b
DL
11477 if ((ents = listcount(bgp->group))) {
11478 json_object_int_add(
60466a63 11479 json, "peerGroupCount", ents);
ea47320b
DL
11480 json_object_int_add(
11481 json, "peerGroupMemory",
996c9314
LB
11482 ents * sizeof(struct
11483 peer_group));
ea47320b 11484 }
d62a17ae 11485
ea47320b
DL
11486 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11487 BGP_CONFIG_DAMPENING))
11488 json_object_boolean_true_add(
60466a63 11489 json, "dampeningEnabled");
ea47320b 11490 } else {
96c81f66
LS
11491 if (!show_terse) {
11492 if (bgp_maxmed_onstartup_configured(bgp)
11493 && bgp->maxmed_active)
11494 vty_out(vty,
11495 "Max-med on-startup active\n");
11496 if (bgp->v_maxmed_admin)
11497 vty_out(vty,
11498 "Max-med administrative active\n");
d62a17ae 11499
96c81f66
LS
11500 vty_out(vty,
11501 "BGP table version %" PRIu64
11502 "\n",
11503 bgp_table_version(
11504 bgp->rib[afi][safi]));
ea47320b 11505
96c81f66
LS
11506 ents = bgp_table_count(
11507 bgp->rib[afi][safi]);
d62a17ae 11508 vty_out(vty,
96c81f66 11509 "RIB entries %ld, using %s of memory\n",
d62a17ae 11510 ents,
11511 mtype_memstr(
11512 memstrbuf,
11513 sizeof(memstrbuf),
96c81f66
LS
11514 ents
11515 * sizeof(
11516 struct
11517 bgp_dest)));
d62a17ae 11518
96c81f66
LS
11519 /* Peer related usage */
11520 ents = bgp->af_peer_count[afi][safi];
11521 vty_out(vty,
11522 "Peers %ld, using %s of memory\n",
11523 ents,
11524 mtype_memstr(
11525 memstrbuf,
11526 sizeof(memstrbuf),
11527 ents
11528 * sizeof(
11529 struct
11530 peer)));
d62a17ae 11531
96c81f66
LS
11532 if ((ents = listcount(bgp->group)))
11533 vty_out(vty,
11534 "Peer groups %ld, using %s of memory\n",
11535 ents,
11536 mtype_memstr(
11537 memstrbuf,
11538 sizeof(memstrbuf),
11539 ents
11540 * sizeof(
11541 struct
11542 peer_group)));
11543
11544 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11545 BGP_CONFIG_DAMPENING))
11546 vty_out(vty,
11547 "Dampening enabled.\n");
11548 }
11549 if (show_failed) {
11550 vty_out(vty, "\n");
11551
11552 /* Subtract 8 here because 'Neighbor' is
11553 * 8 characters */
11554 vty_out(vty, "Neighbor");
11555 vty_out(vty, "%*s",
11556 max_neighbor_width - 8, " ");
85eeb029
DA
11557 vty_out(vty,
11558 BGP_SHOW_SUMMARY_HEADER_FAILED);
96c81f66 11559 }
d62a17ae 11560 }
ea47320b 11561 }
d62a17ae 11562
d55811cc 11563 paf = peer_af_find(peer, afi, safi);
d3ada366 11564 filter = &peer->filter[afi][safi];
db92d226 11565
ea47320b 11566 count++;
3577f1c5
DD
11567 /* Works for both failed & successful cases */
11568 if (peer_dynamic_neighbor(peer))
11569 dn_count++;
d62a17ae 11570
ea47320b 11571 if (use_json) {
3577f1c5 11572 json_peer = NULL;
8c1d4cd5 11573 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
11574 as_type, as)) {
11575 filtered_count++;
8c1d4cd5 11576 continue;
ce1944f0 11577 }
3577f1c5
DD
11578 if (show_failed &&
11579 bgp_has_peer_failed(peer, afi, safi)) {
11580 json_peer = json_object_new_object();
11581 bgp_show_failed_summary(vty, bgp, peer,
11582 json_peer, 0, use_json);
11583 } else if (!show_failed) {
10b49f14 11584 if (show_established
ce1944f0
LS
11585 && bgp_has_peer_failed(peer, afi, safi)) {
11586 filtered_count++;
10b49f14 11587 continue;
ce1944f0 11588 }
10b49f14 11589
3577f1c5
DD
11590 json_peer = json_object_new_object();
11591 if (peer_dynamic_neighbor(peer)) {
11592 json_object_boolean_true_add(json_peer,
11593 "dynamicPeer");
11594 }
d62a17ae 11595
3577f1c5
DD
11596 if (peer->hostname)
11597 json_object_string_add(json_peer, "hostname",
11598 peer->hostname);
11599
11600 if (peer->domainname)
11601 json_object_string_add(json_peer, "domainname",
11602 peer->domainname);
11603
44a4d55e
PG
11604 asn_asn2json(json_peer, "remoteAs", peer->as,
11605 bgp->asnotation);
11606 asn_asn2json(json_peer, "localAs",
11607 peer->change_local_as
11608 ? peer->change_local_as
11609 : peer->local_as,
11610 bgp->asnotation);
3577f1c5
DD
11611 json_object_int_add(json_peer, "version", 4);
11612 json_object_int_add(json_peer, "msgRcvd",
11613 PEER_TOTAL_RX(peer));
11614 json_object_int_add(json_peer, "msgSent",
11615 PEER_TOTAL_TX(peer));
11616
43aa5965
QY
11617 atomic_size_t outq_count, inq_count;
11618 outq_count = atomic_load_explicit(
11619 &peer->obuf->count,
11620 memory_order_relaxed);
11621 inq_count = atomic_load_explicit(
11622 &peer->ibuf->count,
11623 memory_order_relaxed);
11624
bdf8b8dd
DA
11625 json_object_int_add(
11626 json_peer, "tableVersion",
11627 (paf && PAF_SUBGRP(paf))
11628 ? paf->subgroup->version
11629 : 0);
3577f1c5 11630 json_object_int_add(json_peer, "outq",
43aa5965
QY
11631 outq_count);
11632 json_object_int_add(json_peer, "inq",
11633 inq_count);
3577f1c5
DD
11634 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11635 use_json, json_peer);
11636
3577f1c5
DD
11637 json_object_int_add(json_peer, "pfxRcd",
11638 peer->pcount[afi][pfx_rcd_safi]);
11639
3577f1c5 11640 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
11641 json_object_int_add(
11642 json_peer, "pfxSnt",
11643 (PAF_SUBGRP(paf))->scount);
11644 else
11645 json_object_int_add(json_peer, "pfxSnt",
11646 0);
0e1f8ab5
DA
11647
11648 /* BGP FSM state */
cb9196e7 11649 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
11650 || CHECK_FLAG(peer->bgp->flags,
11651 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
11652 json_object_string_add(json_peer,
11653 "state",
3577f1c5
DD
11654 "Idle (Admin)");
11655 else if (peer->afc_recv[afi][safi])
11656 json_object_string_add(
0e1f8ab5
DA
11657 json_peer, "state",
11658 lookup_msg(bgp_status_msg,
11659 peer->status, NULL));
11660 else if (CHECK_FLAG(
11661 peer->sflags,
11662 PEER_STATUS_PREFIX_OVERFLOW))
11663 json_object_string_add(json_peer,
11664 "state",
3577f1c5
DD
11665 "Idle (PfxCt)");
11666 else
11667 json_object_string_add(
0e1f8ab5
DA
11668 json_peer, "state",
11669 lookup_msg(bgp_status_msg,
11670 peer->status, NULL));
11671
11672 /* BGP peer state */
11673 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11674 || CHECK_FLAG(peer->bgp->flags,
11675 BGP_FLAG_SHUTDOWN))
11676 json_object_string_add(json_peer,
11677 "peerState",
11678 "Admin");
11679 else if (CHECK_FLAG(
11680 peer->sflags,
11681 PEER_STATUS_PREFIX_OVERFLOW))
11682 json_object_string_add(json_peer,
11683 "peerState",
11684 "PfxCt");
11685 else if (CHECK_FLAG(peer->flags,
11686 PEER_FLAG_PASSIVE))
11687 json_object_string_add(json_peer,
11688 "peerState",
11689 "Passive");
11690 else if (CHECK_FLAG(peer->sflags,
11691 PEER_STATUS_NSF_WAIT))
11692 json_object_string_add(json_peer,
11693 "peerState",
11694 "NSF passive");
11695 else if (CHECK_FLAG(
11696 peer->bgp->flags,
11697 BGP_FLAG_EBGP_REQUIRES_POLICY)
11698 && (!bgp_inbound_policy_exists(peer,
11699 filter)
11700 || !bgp_outbound_policy_exists(
11701 peer, filter)))
11702 json_object_string_add(json_peer,
11703 "peerState",
11704 "Policy");
11705 else
11706 json_object_string_add(
11707 json_peer, "peerState", "OK");
11708
200116db
DD
11709 json_object_int_add(json_peer, "connectionsEstablished",
11710 peer->established);
11711 json_object_int_add(json_peer, "connectionsDropped",
11712 peer->dropped);
aa72bd7e
PG
11713 if (peer->desc)
11714 json_object_string_add(
11715 json_peer, "desc", peer->desc);
b4e9dcba 11716 }
3577f1c5
DD
11717 /* Avoid creating empty peer dicts in JSON */
11718 if (json_peer == NULL)
11719 continue;
ea47320b
DL
11720
11721 if (peer->conf_if)
60466a63 11722 json_object_string_add(json_peer, "idType",
ea47320b
DL
11723 "interface");
11724 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
11725 json_object_string_add(json_peer, "idType",
11726 "ipv4");
ea47320b 11727 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
11728 json_object_string_add(json_peer, "idType",
11729 "ipv6");
ea47320b
DL
11730 json_object_object_add(json_peers, peer->host,
11731 json_peer);
11732 } else {
8c1d4cd5 11733 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
11734 as_type, as)) {
11735 filtered_count++;
8c1d4cd5 11736 continue;
ce1944f0 11737 }
3577f1c5
DD
11738 if (show_failed &&
11739 bgp_has_peer_failed(peer, afi, safi)) {
11740 bgp_show_failed_summary(vty, bgp, peer, NULL,
11741 max_neighbor_width,
11742 use_json);
11743 } else if (!show_failed) {
10b49f14 11744 if (show_established
ce1944f0
LS
11745 && bgp_has_peer_failed(peer, afi, safi)) {
11746 filtered_count++;
10b49f14 11747 continue;
ce1944f0 11748 }
96c81f66
LS
11749
11750 if ((count - filtered_count) == 1) {
11751 /* display headline before the first
11752 * neighbor line */
11753 vty_out(vty, "\n");
11754
11755 /* Subtract 8 here because 'Neighbor' is
11756 * 8 characters */
11757 vty_out(vty, "Neighbor");
11758 vty_out(vty, "%*s",
11759 max_neighbor_width - 8, " ");
11760 vty_out(vty,
11761 show_wide
11762 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11763 : BGP_SHOW_SUMMARY_HEADER_ALL);
11764 }
11765
3577f1c5
DD
11766 memset(dn_flag, '\0', sizeof(dn_flag));
11767 if (peer_dynamic_neighbor(peer)) {
11768 dn_flag[0] = '*';
11769 }
d62a17ae 11770
3577f1c5 11771 if (peer->hostname
892fedb6
DA
11772 && CHECK_FLAG(bgp->flags,
11773 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 11774 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
11775 peer->hostname,
11776 peer->host);
d62a17ae 11777 else
3577f1c5
DD
11778 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11779
11780 /* pad the neighbor column with spaces */
11781 if (len < max_neighbor_width)
11782 vty_out(vty, "%*s", max_neighbor_width - len,
11783 " ");
11784
43aa5965
QY
11785 atomic_size_t outq_count, inq_count;
11786 outq_count = atomic_load_explicit(
11787 &peer->obuf->count,
11788 memory_order_relaxed);
11789 inq_count = atomic_load_explicit(
11790 &peer->ibuf->count,
11791 memory_order_relaxed);
11792
44a4d55e
PG
11793 vty_out(vty, "4 ");
11794 vty_out(vty, ASN_FORMAT_SPACE(bgp->asnotation),
11795 &peer->as);
344c7da0 11796 if (show_wide)
85eeb029 11797 vty_out(vty,
44a4d55e
PG
11798 ASN_FORMAT_SPACE(
11799 bgp->asnotation),
85eeb029 11800 peer->change_local_as
44a4d55e
PG
11801 ? &peer->change_local_as
11802 : &peer->local_as);
344c7da0 11803 vty_out(vty,
11804 " %9u %9u %8" PRIu64 " %4zu %4zu %8s",
11805 PEER_TOTAL_RX(peer),
11806 PEER_TOTAL_TX(peer),
bdf8b8dd
DA
11807 (paf && PAF_SUBGRP(paf))
11808 ? paf->subgroup->version
11809 : 0,
11810 inq_count, outq_count,
344c7da0 11811 peer_uptime(peer->uptime, timebuf,
11812 BGP_UPTIME_LEN, 0, NULL));
11813
feb17238 11814 if (peer_established(peer)) {
d3ada366
DA
11815 if (peer->afc_recv[afi][safi]) {
11816 if (CHECK_FLAG(
11817 bgp->flags,
11818 BGP_FLAG_EBGP_REQUIRES_POLICY)
11819 && !bgp_inbound_policy_exists(
11820 peer, filter))
11821 vty_out(vty, " %12s",
11822 "(Policy)");
11823 else
11824 vty_out(vty,
6cde4b45 11825 " %12u",
d3ada366
DA
11826 peer->pcount
11827 [afi]
11828 [pfx_rcd_safi]);
11829 } else {
749d0f27 11830 vty_out(vty, " NoNeg");
d3ada366 11831 }
db92d226 11832
d3ada366
DA
11833 if (paf && PAF_SUBGRP(paf)) {
11834 if (CHECK_FLAG(
11835 bgp->flags,
11836 BGP_FLAG_EBGP_REQUIRES_POLICY)
11837 && !bgp_outbound_policy_exists(
11838 peer, filter))
11839 vty_out(vty, " %8s",
11840 "(Policy)");
11841 else
11842 vty_out(vty,
6cde4b45 11843 " %8u",
d3ada366
DA
11844 (PAF_SUBGRP(
11845 paf))
11846 ->scount);
749d0f27
DA
11847 } else {
11848 vty_out(vty, " NoNeg");
d3ada366 11849 }
db92d226 11850 } else {
736b68f3
DS
11851 if (CHECK_FLAG(peer->flags,
11852 PEER_FLAG_SHUTDOWN)
11853 || CHECK_FLAG(peer->bgp->flags,
11854 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
11855 vty_out(vty, " Idle (Admin)");
11856 else if (CHECK_FLAG(
11857 peer->sflags,
11858 PEER_STATUS_PREFIX_OVERFLOW))
11859 vty_out(vty, " Idle (PfxCt)");
11860 else
11861 vty_out(vty, " %12s",
11862 lookup_msg(bgp_status_msg,
11863 peer->status, NULL));
db92d226 11864
6cde4b45 11865 vty_out(vty, " %8u", 0);
3577f1c5 11866 }
565e9ddd
DA
11867 /* Make sure `Desc` column is the lastest in
11868 * the output.
11869 */
aa72bd7e 11870 if (peer->desc)
cb75bb31
DA
11871 vty_out(vty, " %s",
11872 bgp_peer_description_stripped(
85eeb029
DA
11873 peer->desc,
11874 show_wide ? 64 : 20));
aa72bd7e
PG
11875 else
11876 vty_out(vty, " N/A");
3577f1c5 11877 vty_out(vty, "\n");
d62a17ae 11878 }
3577f1c5 11879
d62a17ae 11880 }
11881 }
f933309e 11882
d62a17ae 11883 if (use_json) {
11884 json_object_object_add(json, "peers", json_peers);
3577f1c5 11885 json_object_int_add(json, "failedPeers", failed_count);
ce1944f0
LS
11886 json_object_int_add(json, "displayedPeers",
11887 count - filtered_count);
d62a17ae 11888 json_object_int_add(json, "totalPeers", count);
11889 json_object_int_add(json, "dynamicPeers", dn_count);
11890
3577f1c5
DD
11891 if (!show_failed)
11892 bgp_show_bestpath_json(bgp, json);
57a9c8a8 11893
75eeda93 11894 vty_json(vty, json);
d62a17ae 11895 } else {
ce1944f0 11896 if (count) {
96c81f66
LS
11897 if (filtered_count == count)
11898 vty_out(vty, "\n%% No matching neighbor\n");
11899 else {
11900 if (show_failed)
11901 vty_out(vty, "\nDisplayed neighbors %d",
11902 failed_count);
11903 else if (as_type != AS_UNSPECIFIED || as
11904 || fpeer || show_established)
ce1944f0
LS
11905 vty_out(vty, "\nDisplayed neighbors %d",
11906 count - filtered_count);
96c81f66
LS
11907
11908 vty_out(vty, "\nTotal number of neighbors %d\n",
11909 count);
ce1944f0 11910 }
ce1944f0 11911 } else {
d6ceaca3 11912 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 11913 get_afi_safi_str(afi, safi, false));
d62a17ae 11914 }
b05a1c8b 11915
d6ceaca3 11916 if (dn_count) {
d62a17ae 11917 vty_out(vty, "* - dynamic neighbor\n");
11918 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11919 dn_count, bgp->dynamic_neighbors_limit);
11920 }
11921 }
1ff9a340 11922
d62a17ae 11923 return CMD_SUCCESS;
718e3744 11924}
11925
d62a17ae 11926static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5 11927 int safi, struct peer *fpeer, int as_type,
96c81f66 11928 as_t as, uint16_t show_flags)
d62a17ae 11929{
11930 int is_first = 1;
11931 int afi_wildcard = (afi == AFI_MAX);
11932 int safi_wildcard = (safi == SAFI_MAX);
11933 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 11934 bool nbr_output = false;
85eeb029 11935 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11936
11937 if (use_json && is_wildcard)
11938 vty_out(vty, "{\n");
11939 if (afi_wildcard)
11940 afi = 1; /* AFI_IP */
11941 while (afi < AFI_MAX) {
11942 if (safi_wildcard)
11943 safi = 1; /* SAFI_UNICAST */
11944 while (safi < SAFI_MAX) {
318cac96 11945 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 11946 nbr_output = true;
f86897b9 11947
d62a17ae 11948 if (is_wildcard) {
11949 /*
11950 * So limit output to those afi/safi
11951 * pairs that
11952 * actualy have something interesting in
11953 * them
11954 */
11955 if (use_json) {
d62a17ae 11956 if (!is_first)
11957 vty_out(vty, ",\n");
11958 else
11959 is_first = 0;
11960
11961 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11962 get_afi_safi_str(afi,
11963 safi,
11964 true));
d62a17ae 11965 } else {
6cac2fcc
LS
11966 vty_out(vty,
11967 "\n%s Summary (%s):\n",
5cb5f4d0
DD
11968 get_afi_safi_str(afi,
11969 safi,
6cac2fcc
LS
11970 false),
11971 bgp->name_pretty);
d62a17ae 11972 }
11973 }
8c1d4cd5
LS
11974 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11975 as_type, as, show_flags);
d62a17ae 11976 }
11977 safi++;
d62a17ae 11978 if (!safi_wildcard)
11979 safi = SAFI_MAX;
11980 }
11981 afi++;
ee851c8c 11982 if (!afi_wildcard)
d62a17ae 11983 afi = AFI_MAX;
11984 }
11985
11986 if (use_json && is_wildcard)
11987 vty_out(vty, "}\n");
ca61fd25
DS
11988 else if (!nbr_output) {
11989 if (use_json)
11990 vty_out(vty, "{}\n");
11991 else
6cac2fcc
LS
11992 vty_out(vty, "%% No BGP neighbors found in %s\n",
11993 bgp->name_pretty);
ca61fd25 11994 }
d62a17ae 11995}
11996
11997static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
11998 safi_t safi,
11999 const char *neighbor,
12000 int as_type, as_t as,
96c81f66 12001 uint16_t show_flags)
d62a17ae 12002{
12003 struct listnode *node, *nnode;
12004 struct bgp *bgp;
8c1d4cd5 12005 struct peer *fpeer = NULL;
d62a17ae 12006 int is_first = 1;
9f049418 12007 bool nbr_output = false;
85eeb029 12008 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 12009
12010 if (use_json)
12011 vty_out(vty, "{\n");
12012
12013 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 12014 nbr_output = true;
d62a17ae 12015 if (use_json) {
d62a17ae 12016 if (!is_first)
12017 vty_out(vty, ",\n");
12018 else
12019 is_first = 0;
12020
12021 vty_out(vty, "\"%s\":",
12022 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12023 ? VRF_DEFAULT_NAME
d62a17ae 12024 : bgp->name);
d62a17ae 12025 }
8c1d4cd5
LS
12026 if (neighbor) {
12027 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
12028 use_json);
12029 if (!fpeer)
12030 continue;
12031 }
12032 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
12033 as, show_flags);
d62a17ae 12034 }
12035
12036 if (use_json)
12037 vty_out(vty, "}\n");
9f049418
DS
12038 else if (!nbr_output)
12039 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 12040}
12041
12042int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5 12043 safi_t safi, const char *neighbor, int as_type,
96c81f66 12044 as_t as, uint16_t show_flags)
d62a17ae 12045{
12046 struct bgp *bgp;
85eeb029 12047 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 12048 struct peer *fpeer = NULL;
d62a17ae 12049
12050 if (name) {
12051 if (strmatch(name, "all")) {
85eeb029 12052 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
12053 neighbor, as_type,
12054 as, show_flags);
d62a17ae 12055 return CMD_SUCCESS;
12056 } else {
12057 bgp = bgp_lookup_by_name(name);
12058
12059 if (!bgp) {
12060 if (use_json)
12061 vty_out(vty, "{}\n");
12062 else
12063 vty_out(vty,
ca61fd25 12064 "%% BGP instance not found\n");
d62a17ae 12065 return CMD_WARNING;
12066 }
12067
8c1d4cd5
LS
12068 if (neighbor) {
12069 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
12070 use_json);
12071 if (!fpeer)
12072 return CMD_WARNING;
12073 }
12074 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
12075 as_type, as, show_flags);
d62a17ae 12076 return CMD_SUCCESS;
12077 }
12078 }
12079
12080 bgp = bgp_get_default();
12081
8c1d4cd5
LS
12082 if (bgp) {
12083 if (neighbor) {
12084 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
12085 use_json);
12086 if (!fpeer)
12087 return CMD_WARNING;
12088 }
12089 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
12090 as, show_flags);
12091 } else {
ca61fd25
DS
12092 if (use_json)
12093 vty_out(vty, "{}\n");
12094 else
12095 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
12096 return CMD_WARNING;
12097 }
d62a17ae 12098
12099 return CMD_SUCCESS;
4fb25c53
DW
12100}
12101
716b2d8a 12102/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
12103DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
12104 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
12105 " [" BGP_SAFI_WITH_LABEL_CMD_STR
8079a413 12106 "]] [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
12107 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
12108 BGP_SAFI_WITH_LABEL_HELP_STR
12109 "Display the entries for all address families\n"
12110 "Summary of BGP neighbor status\n"
12111 "Show only sessions in Established state\n"
12112 "Show only sessions not in Established state\n"
12113 "Show only the specified neighbor session\n"
12114 "Neighbor to display information about\n"
12115 "Neighbor to display information about\n"
12116 "Neighbor on BGP configured interface\n"
8079a413 12117 "Show only the specified remote AS sessions\n" AS_STR
8c1d4cd5
LS
12118 "Internal (iBGP) AS sessions\n"
12119 "External (eBGP) AS sessions\n"
96c81f66 12120 "Shorten the information on BGP instances\n"
8c1d4cd5 12121 "Increase table width for longer output\n" JSON_STR)
718e3744 12122{
d62a17ae 12123 char *vrf = NULL;
12124 afi_t afi = AFI_MAX;
12125 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
12126 as_t as = 0; /* 0 means AS filter not set */
12127 int as_type = AS_UNSPECIFIED;
96c81f66 12128 uint16_t show_flags = 0;
d62a17ae 12129
12130 int idx = 0;
12131
12132 /* show [ip] bgp */
96f3485c 12133 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 12134 afi = AFI_IP;
9a8bdf1c
PG
12135 /* [<vrf> VIEWVRFNAME] */
12136 if (argv_find(argv, argc, "vrf", &idx)) {
12137 vrf = argv[idx + 1]->arg;
12138 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12139 vrf = NULL;
12140 } else if (argv_find(argv, argc, "view", &idx))
12141 /* [<view> VIEWVRFNAME] */
12142 vrf = argv[idx + 1]->arg;
d62a17ae 12143 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
12144 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
12145 argv_find_and_parse_safi(argv, argc, &idx, &safi);
12146 }
12147
3577f1c5 12148 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
12149 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
12150
10b49f14 12151 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
12152 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
12153
8c1d4cd5
LS
12154 if (argv_find(argv, argc, "remote-as", &idx)) {
12155 if (argv[idx + 1]->arg[0] == 'i')
12156 as_type = AS_INTERNAL;
12157 else if (argv[idx + 1]->arg[0] == 'e')
12158 as_type = AS_EXTERNAL;
8079a413
PG
12159 else if (!asn_str2asn(argv[idx + 1]->arg, &as)) {
12160 vty_out(vty,
12161 "%% Invalid neighbor remote-as value: %s\n",
12162 argv[idx + 1]->arg);
12163 return CMD_SUCCESS;
12164 }
8c1d4cd5
LS
12165 }
12166
96c81f66
LS
12167 if (argv_find(argv, argc, "terse", &idx))
12168 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
12169
85eeb029
DA
12170 if (argv_find(argv, argc, "wide", &idx))
12171 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
12172
12173 if (argv_find(argv, argc, "json", &idx))
12174 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 12175
8c1d4cd5
LS
12176 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
12177 show_flags);
d62a17ae 12178}
12179
5cb5f4d0 12180const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 12181{
5cb5f4d0
DD
12182 if (for_json)
12183 return get_afi_safi_json_str(afi, safi);
d62a17ae 12184 else
5cb5f4d0 12185 return get_afi_safi_vty_str(afi, safi);
27162734
LB
12186}
12187
d62a17ae 12188
12189static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
12190 afi_t afi, safi_t safi,
d7c0a89a
QY
12191 uint16_t adv_smcap, uint16_t adv_rmcap,
12192 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 12193 bool use_json, json_object *json_pref)
d62a17ae 12194{
12195 /* Send-Mode */
12196 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
12197 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
12198 if (use_json) {
12199 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
12200 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
12201 json_object_string_add(json_pref, "sendMode",
12202 "advertisedAndReceived");
12203 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
12204 json_object_string_add(json_pref, "sendMode",
12205 "advertised");
12206 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
12207 json_object_string_add(json_pref, "sendMode",
12208 "received");
12209 } else {
12210 vty_out(vty, " Send-mode: ");
12211 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
12212 vty_out(vty, "advertised");
12213 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
12214 vty_out(vty, "%sreceived",
12215 CHECK_FLAG(p->af_cap[afi][safi],
12216 adv_smcap)
12217 ? ", "
12218 : "");
12219 vty_out(vty, "\n");
12220 }
12221 }
12222
12223 /* Receive-Mode */
12224 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
12225 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
12226 if (use_json) {
12227 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
12228 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12229 json_object_string_add(json_pref, "recvMode",
12230 "advertisedAndReceived");
12231 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12232 json_object_string_add(json_pref, "recvMode",
12233 "advertised");
12234 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12235 json_object_string_add(json_pref, "recvMode",
12236 "received");
12237 } else {
12238 vty_out(vty, " Receive-mode: ");
12239 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12240 vty_out(vty, "advertised");
12241 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12242 vty_out(vty, "%sreceived",
12243 CHECK_FLAG(p->af_cap[afi][safi],
12244 adv_rmcap)
12245 ? ", "
12246 : "");
12247 vty_out(vty, "\n");
12248 }
12249 }
12250}
12251
eea685b6
DA
12252static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
12253 struct peer *p,
eea685b6 12254 json_object *json)
2986cac2 12255{
eea685b6
DA
12256 bool rbit = false;
12257 bool nbit = false;
2986cac2 12258
13909c4f
DS
12259 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
12260 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
feb17238 12261 && (peer_established(p))) {
eea685b6
DA
12262 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
12263 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
2986cac2 12264 }
12265
403e64f8 12266 if (json) {
eea685b6
DA
12267 json_object_boolean_add(json, "rBit", rbit);
12268 json_object_boolean_add(json, "nBit", nbit);
2986cac2 12269 } else {
eea685b6
DA
12270 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
12271 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
2986cac2 12272 }
12273}
12274
13909c4f
DS
12275static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
12276 struct peer *peer,
13909c4f 12277 json_object *json)
2986cac2 12278{
2bb5d39b 12279 const char *mode = "NotApplicable";
2986cac2 12280
403e64f8 12281 if (!json)
a53ca37b 12282 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 12283
13909c4f 12284 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
feb17238 12285 && (peer_established(peer))) {
2986cac2 12286
13909c4f
DS
12287 if ((peer->nsf_af_count == 0)
12288 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12289
2986cac2 12290 mode = "Disable";
12291
13909c4f
DS
12292 } else if (peer->nsf_af_count == 0
12293 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12294
2986cac2 12295 mode = "Helper";
12296
13909c4f
DS
12297 } else if (peer->nsf_af_count != 0
12298 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12299
2986cac2 12300 mode = "Restart";
2986cac2 12301 }
12302 }
12303
403e64f8 12304 if (json)
13909c4f 12305 json_object_string_add(json, "remoteGrMode", mode);
403e64f8 12306 else
0e4e879b 12307 vty_out(vty, "%s\n", mode);
2986cac2 12308}
12309
13909c4f
DS
12310static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
12311 struct peer *p,
13909c4f 12312 json_object *json)
2986cac2 12313{
12314 const char *mode = "Invalid";
12315
403e64f8 12316 if (!json)
a53ca37b 12317 vty_out(vty, " Local GR Mode: ");
2986cac2 12318
12319 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
12320 mode = "Helper";
12321 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
12322 mode = "Restart";
12323 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
12324 mode = "Disable";
2ba1fe69 12325 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 12326 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
12327 mode = "Helper*";
12328 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
12329 mode = "Restart*";
12330 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
12331 mode = "Disable*";
12332 else
12333 mode = "Invalid*";
2ba1fe69 12334 }
2986cac2 12335
403e64f8 12336 if (json)
13909c4f 12337 json_object_string_add(json, "localGrMode", mode);
403e64f8 12338 else
0e4e879b 12339 vty_out(vty, "%s\n", mode);
2986cac2 12340}
12341
13909c4f 12342static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
403e64f8 12343 struct vty *vty, struct peer *peer, json_object *json)
2986cac2 12344{
2ba1fe69 12345 afi_t afi;
12346 safi_t safi;
2986cac2 12347 json_object *json_afi_safi = NULL;
12348 json_object *json_timer = NULL;
12349 json_object *json_endofrib_status = NULL;
9e3b51a7 12350 bool eor_flag = false;
2986cac2 12351
df8d723c
DA
12352 FOREACH_AFI_SAFI_NSF (afi, safi) {
12353 if (!peer->afc[afi][safi])
12354 continue;
2986cac2 12355
df8d723c
DA
12356 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
12357 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
12358 continue;
9e3b51a7 12359
403e64f8 12360 if (json) {
df8d723c
DA
12361 json_afi_safi = json_object_new_object();
12362 json_endofrib_status = json_object_new_object();
12363 json_timer = json_object_new_object();
12364 }
2986cac2 12365
df8d723c
DA
12366 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
12367 eor_flag = true;
12368 else
12369 eor_flag = false;
2986cac2 12370
403e64f8 12371 if (!json) {
df8d723c
DA
12372 vty_out(vty, " %s:\n",
12373 get_afi_safi_str(afi, safi, false));
2986cac2 12374
df8d723c
DA
12375 vty_out(vty, " F bit: ");
12376 }
2986cac2 12377
df8d723c
DA
12378 if (peer->nsf[afi][safi] &&
12379 CHECK_FLAG(peer->af_cap[afi][safi],
12380 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 12381
403e64f8 12382 if (json) {
df8d723c
DA
12383 json_object_boolean_true_add(json_afi_safi,
12384 "fBit");
12385 } else
12386 vty_out(vty, "True\n");
12387 } else {
403e64f8 12388 if (json)
df8d723c
DA
12389 json_object_boolean_false_add(json_afi_safi,
12390 "fBit");
12391 else
12392 vty_out(vty, "False\n");
12393 }
2986cac2 12394
403e64f8 12395 if (!json)
df8d723c 12396 vty_out(vty, " End-of-RIB sent: ");
2986cac2 12397
df8d723c
DA
12398 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12399 PEER_STATUS_EOR_SEND)) {
403e64f8 12400 if (json) {
df8d723c
DA
12401 json_object_boolean_true_add(
12402 json_endofrib_status, "endOfRibSend");
9e3b51a7 12403
df8d723c
DA
12404 PRINT_EOR_JSON(eor_flag);
12405 } else {
12406 vty_out(vty, "Yes\n");
12407 vty_out(vty,
12408 " End-of-RIB sent after update: ");
2986cac2 12409
df8d723c
DA
12410 PRINT_EOR(eor_flag);
12411 }
12412 } else {
403e64f8 12413 if (json) {
df8d723c
DA
12414 json_object_boolean_false_add(
12415 json_endofrib_status, "endOfRibSend");
12416 json_object_boolean_false_add(
12417 json_endofrib_status,
12418 "endOfRibSentAfterUpdate");
13909c4f 12419 } else {
df8d723c
DA
12420 vty_out(vty, "No\n");
12421 vty_out(vty,
12422 " End-of-RIB sent after update: ");
12423 vty_out(vty, "No\n");
13909c4f 12424 }
df8d723c 12425 }
2986cac2 12426
403e64f8 12427 if (!json)
df8d723c 12428 vty_out(vty, " End-of-RIB received: ");
a53ca37b 12429
df8d723c
DA
12430 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12431 PEER_STATUS_EOR_RECEIVED)) {
403e64f8 12432 if (json)
df8d723c
DA
12433 json_object_boolean_true_add(
12434 json_endofrib_status, "endOfRibRecv");
12435 else
12436 vty_out(vty, "Yes\n");
12437 } else {
403e64f8 12438 if (json)
df8d723c
DA
12439 json_object_boolean_false_add(
12440 json_endofrib_status, "endOfRibRecv");
12441 else
12442 vty_out(vty, "No\n");
12443 }
12444
403e64f8 12445 if (json) {
df8d723c
DA
12446 json_object_int_add(json_timer, "stalePathTimer",
12447 peer->bgp->stalepath_time);
12448
12449 if (peer->t_gr_stale != NULL) {
12450 json_object_int_add(json_timer,
12451 "stalePathTimerRemaining",
4f830a07 12452 event_timer_remain_second(
df8d723c 12453 peer->t_gr_stale));
a53ca37b
DA
12454 }
12455
df8d723c
DA
12456 /* Display Configured Selection
12457 * Deferral only when when
12458 * Gr mode is enabled.
12459 */
12460 if (CHECK_FLAG(peer->flags,
12461 PEER_FLAG_GRACEFUL_RESTART)) {
13909c4f 12462 json_object_int_add(json_timer,
df8d723c 12463 "selectionDeferralTimer",
13909c4f 12464 peer->bgp->stalepath_time);
df8d723c 12465 }
2986cac2 12466
df8d723c
DA
12467 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12468 NULL) {
2986cac2 12469
df8d723c
DA
12470 json_object_int_add(
12471 json_timer,
12472 "selectionDeferralTimerRemaining",
4f830a07 12473 event_timer_remain_second(
df8d723c
DA
12474 peer->bgp->gr_info[afi][safi]
12475 .t_select_deferral));
12476 }
12477 } else {
12478 vty_out(vty, " Timers:\n");
12479 vty_out(vty,
12480 " Configured Stale Path Time(sec): %u\n",
12481 peer->bgp->stalepath_time);
2986cac2 12482
df8d723c 12483 if (peer->t_gr_stale != NULL)
13909c4f 12484 vty_out(vty,
df8d723c 12485 " Stale Path Remaining(sec): %ld\n",
4f830a07 12486 event_timer_remain_second(
df8d723c
DA
12487 peer->t_gr_stale));
12488 /* Display Configured Selection
12489 * Deferral only when when
12490 * Gr mode is enabled.
12491 */
12492 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12493 vty_out(vty,
12494 " Configured Selection Deferral Time(sec): %u\n",
12495 peer->bgp->select_defer_time);
2986cac2 12496
df8d723c
DA
12497 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12498 NULL)
12499 vty_out(vty,
12500 " Selection Deferral Time Remaining(sec): %ld\n",
4f830a07 12501 event_timer_remain_second(
df8d723c
DA
12502 peer->bgp->gr_info[afi][safi]
12503 .t_select_deferral));
12504 }
403e64f8 12505 if (json) {
df8d723c
DA
12506 json_object_object_add(json_afi_safi, "endOfRibStatus",
12507 json_endofrib_status);
12508 json_object_object_add(json_afi_safi, "timers",
12509 json_timer);
12510 json_object_object_add(
12511 json, get_afi_safi_str(afi, safi, true),
12512 json_afi_safi);
2986cac2 12513 }
12514 }
12515}
12516
36235319
QY
12517static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12518 struct peer *p,
36235319 12519 json_object *json)
2986cac2 12520{
403e64f8 12521 if (json) {
2986cac2 12522 json_object *json_timer = NULL;
12523
12524 json_timer = json_object_new_object();
12525
13909c4f
DS
12526 json_object_int_add(json_timer, "configuredRestartTimer",
12527 p->bgp->restart_time);
2986cac2 12528
13909c4f
DS
12529 json_object_int_add(json_timer, "receivedRestartTimer",
12530 p->v_gr_restart);
2986cac2 12531
13909c4f
DS
12532 if (p->t_gr_restart != NULL)
12533 json_object_int_add(
12534 json_timer, "restartTimerRemaining",
4f830a07 12535 event_timer_remain_second(p->t_gr_restart));
2986cac2 12536
12537 json_object_object_add(json, "timers", json_timer);
12538 } else {
12539
a53ca37b
DA
12540 vty_out(vty, " Timers:\n");
12541 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 12542 p->bgp->restart_time);
2986cac2 12543
a53ca37b 12544 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
12545 p->v_gr_restart);
12546 if (p->t_gr_restart != NULL)
a53ca37b 12547 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
4f830a07 12548 event_timer_remain_second(p->t_gr_restart));
36235319 12549 if (p->t_gr_restart != NULL) {
a53ca37b 12550 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
4f830a07 12551 event_timer_remain_second(p->t_gr_restart));
36235319 12552 }
2986cac2 12553 }
12554}
12555
12556static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
403e64f8 12557 json_object *json)
2986cac2 12558{
2986cac2 12559 char dn_flag[2] = {0};
2b7165e7
QY
12560 /* '*' + v6 address of neighbor */
12561 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 12562
2986cac2 12563 if (!p->conf_if && peer_dynamic_neighbor(p))
12564 dn_flag[0] = '*';
12565
12566 if (p->conf_if) {
403e64f8 12567 if (json)
47e12884
DA
12568 json_object_string_addf(json, "neighborAddr", "%pSU",
12569 &p->su);
2986cac2 12570 else
47e12884
DA
12571 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12572 &p->su);
2986cac2 12573 } else {
772270f3
QY
12574 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12575 p->host);
2986cac2 12576
403e64f8 12577 if (json)
36235319
QY
12578 json_object_string_add(json, "neighborAddr",
12579 neighborAddr);
2986cac2 12580 else
36235319 12581 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 12582 }
12583
12584 /* more gr info in new format */
403e64f8 12585 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json);
2986cac2 12586}
12587
d62a17ae 12588static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 12589 safi_t safi, bool use_json,
d62a17ae 12590 json_object *json_neigh)
12591{
0291c246
MK
12592 struct bgp_filter *filter;
12593 struct peer_af *paf;
12594 char orf_pfx_name[BUFSIZ];
12595 int orf_pfx_count;
12596 json_object *json_af = NULL;
12597 json_object *json_prefA = NULL;
12598 json_object *json_prefB = NULL;
12599 json_object *json_addr = NULL;
fa36596c 12600 json_object *json_advmap = NULL;
d62a17ae 12601
12602 if (use_json) {
12603 json_addr = json_object_new_object();
12604 json_af = json_object_new_object();
12605 filter = &p->filter[afi][safi];
12606
12607 if (peer_group_active(p))
12608 json_object_string_add(json_addr, "peerGroupMember",
12609 p->group->name);
12610
12611 paf = peer_af_find(p, afi, safi);
12612 if (paf && PAF_SUBGRP(paf)) {
12613 json_object_int_add(json_addr, "updateGroupId",
12614 PAF_UPDGRP(paf)->id);
12615 json_object_int_add(json_addr, "subGroupId",
12616 PAF_SUBGRP(paf)->id);
12617 json_object_int_add(json_addr, "packetQueueLength",
12618 bpacket_queue_virtual_length(paf));
12619 }
12620
12621 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12622 || CHECK_FLAG(p->af_cap[afi][safi],
12623 PEER_CAP_ORF_PREFIX_SM_RCV)
12624 || CHECK_FLAG(p->af_cap[afi][safi],
12625 PEER_CAP_ORF_PREFIX_RM_ADV)
12626 || CHECK_FLAG(p->af_cap[afi][safi],
12627 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12628 json_object_int_add(json_af, "orfType",
12629 ORF_TYPE_PREFIX);
12630 json_prefA = json_object_new_object();
12631 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12632 PEER_CAP_ORF_PREFIX_SM_ADV,
12633 PEER_CAP_ORF_PREFIX_RM_ADV,
12634 PEER_CAP_ORF_PREFIX_SM_RCV,
12635 PEER_CAP_ORF_PREFIX_RM_RCV,
12636 use_json, json_prefA);
12637 json_object_object_add(json_af, "orfPrefixList",
12638 json_prefA);
12639 }
12640
12641 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12642 || CHECK_FLAG(p->af_cap[afi][safi],
12643 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12644 || CHECK_FLAG(p->af_cap[afi][safi],
12645 PEER_CAP_ORF_PREFIX_RM_ADV)
12646 || CHECK_FLAG(p->af_cap[afi][safi],
12647 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12648 json_object_int_add(json_af, "orfOldType",
12649 ORF_TYPE_PREFIX_OLD);
12650 json_prefB = json_object_new_object();
12651 bgp_show_peer_afi_orf_cap(
12652 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12653 PEER_CAP_ORF_PREFIX_RM_ADV,
12654 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12655 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12656 json_prefB);
12657 json_object_object_add(json_af, "orfOldPrefixList",
12658 json_prefB);
12659 }
12660
12661 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12662 || CHECK_FLAG(p->af_cap[afi][safi],
12663 PEER_CAP_ORF_PREFIX_SM_RCV)
12664 || CHECK_FLAG(p->af_cap[afi][safi],
12665 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12666 || CHECK_FLAG(p->af_cap[afi][safi],
12667 PEER_CAP_ORF_PREFIX_RM_ADV)
12668 || CHECK_FLAG(p->af_cap[afi][safi],
12669 PEER_CAP_ORF_PREFIX_RM_RCV)
12670 || CHECK_FLAG(p->af_cap[afi][safi],
12671 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12672 json_object_object_add(json_addr, "afDependentCap",
12673 json_af);
12674 else
12675 json_object_free(json_af);
12676
772270f3
QY
12677 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12678 p->host, afi, safi);
d62a17ae 12679 orf_pfx_count = prefix_bgp_show_prefix_list(
12680 NULL, afi, orf_pfx_name, use_json);
12681
12682 if (CHECK_FLAG(p->af_sflags[afi][safi],
12683 PEER_STATUS_ORF_PREFIX_SEND)
12684 || orf_pfx_count) {
12685 if (CHECK_FLAG(p->af_sflags[afi][safi],
12686 PEER_STATUS_ORF_PREFIX_SEND))
12687 json_object_boolean_true_add(json_neigh,
12688 "orfSent");
12689 if (orf_pfx_count)
12690 json_object_int_add(json_addr, "orfRecvCounter",
12691 orf_pfx_count);
12692 }
12693 if (CHECK_FLAG(p->af_sflags[afi][safi],
12694 PEER_STATUS_ORF_WAIT_REFRESH))
12695 json_object_string_add(
12696 json_addr, "orfFirstUpdate",
12697 "deferredUntilORFOrRouteRefreshRecvd");
12698
12699 if (CHECK_FLAG(p->af_flags[afi][safi],
12700 PEER_FLAG_REFLECTOR_CLIENT))
12701 json_object_boolean_true_add(json_addr,
12702 "routeReflectorClient");
12703 if (CHECK_FLAG(p->af_flags[afi][safi],
12704 PEER_FLAG_RSERVER_CLIENT))
12705 json_object_boolean_true_add(json_addr,
12706 "routeServerClient");
12707 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12708 json_object_boolean_true_add(json_addr,
12709 "inboundSoftConfigPermit");
12710
12711 if (CHECK_FLAG(p->af_flags[afi][safi],
12712 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12713 json_object_boolean_true_add(
12714 json_addr,
12715 "privateAsNumsAllReplacedInUpdatesToNbr");
12716 else if (CHECK_FLAG(p->af_flags[afi][safi],
12717 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12718 json_object_boolean_true_add(
12719 json_addr,
12720 "privateAsNumsReplacedInUpdatesToNbr");
12721 else if (CHECK_FLAG(p->af_flags[afi][safi],
12722 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12723 json_object_boolean_true_add(
12724 json_addr,
12725 "privateAsNumsAllRemovedInUpdatesToNbr");
12726 else if (CHECK_FLAG(p->af_flags[afi][safi],
12727 PEER_FLAG_REMOVE_PRIVATE_AS))
12728 json_object_boolean_true_add(
12729 json_addr,
12730 "privateAsNumsRemovedInUpdatesToNbr");
12731
b2ac1d0d
MS
12732 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12733 if (CHECK_FLAG(p->af_flags[afi][safi],
12734 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12735 json_object_boolean_true_add(json_addr,
12736 "allowAsInOrigin");
12737 else
12738 json_object_int_add(json_addr, "allowAsInCount",
12739 p->allowas_in[afi][safi]);
12740 }
12741
dcc68b5e
MS
12742 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12743 json_object_boolean_true_add(
12744 json_addr,
12745 bgp_addpath_names(p->addpath_type[afi][safi])
12746 ->type_json_name);
d62a17ae 12747
12748 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12749 json_object_string_add(json_addr,
12750 "overrideASNsInOutboundUpdates",
12751 "ifAspathEqualRemoteAs");
12752
12753 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12754 || CHECK_FLAG(p->af_flags[afi][safi],
12755 PEER_FLAG_FORCE_NEXTHOP_SELF))
12756 json_object_boolean_true_add(json_addr,
12757 "routerAlwaysNextHop");
12758 if (CHECK_FLAG(p->af_flags[afi][safi],
12759 PEER_FLAG_AS_PATH_UNCHANGED))
12760 json_object_boolean_true_add(
12761 json_addr, "unchangedAsPathPropogatedToNbr");
12762 if (CHECK_FLAG(p->af_flags[afi][safi],
12763 PEER_FLAG_NEXTHOP_UNCHANGED))
12764 json_object_boolean_true_add(
12765 json_addr, "unchangedNextHopPropogatedToNbr");
12766 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12767 json_object_boolean_true_add(
12768 json_addr, "unchangedMedPropogatedToNbr");
12769 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12770 || CHECK_FLAG(p->af_flags[afi][safi],
12771 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12772 if (CHECK_FLAG(p->af_flags[afi][safi],
12773 PEER_FLAG_SEND_COMMUNITY)
12774 && CHECK_FLAG(p->af_flags[afi][safi],
12775 PEER_FLAG_SEND_EXT_COMMUNITY))
12776 json_object_string_add(json_addr,
12777 "commAttriSentToNbr",
12778 "extendedAndStandard");
12779 else if (CHECK_FLAG(p->af_flags[afi][safi],
12780 PEER_FLAG_SEND_EXT_COMMUNITY))
12781 json_object_string_add(json_addr,
12782 "commAttriSentToNbr",
12783 "extended");
12784 else
12785 json_object_string_add(json_addr,
12786 "commAttriSentToNbr",
12787 "standard");
12788 }
12789 if (CHECK_FLAG(p->af_flags[afi][safi],
12790 PEER_FLAG_DEFAULT_ORIGINATE)) {
12791 if (p->default_rmap[afi][safi].name)
12792 json_object_string_add(
12793 json_addr, "defaultRouteMap",
12794 p->default_rmap[afi][safi].name);
12795
12796 if (paf && PAF_SUBGRP(paf)
12797 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12798 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12799 json_object_boolean_true_add(json_addr,
12800 "defaultSent");
12801 else
12802 json_object_boolean_true_add(json_addr,
12803 "defaultNotSent");
12804 }
12805
dff8f48d 12806 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12807 if (is_evpn_enabled())
60466a63
QY
12808 json_object_boolean_true_add(
12809 json_addr, "advertiseAllVnis");
dff8f48d
MK
12810 }
12811
d62a17ae 12812 if (filter->plist[FILTER_IN].name
12813 || filter->dlist[FILTER_IN].name
12814 || filter->aslist[FILTER_IN].name
12815 || filter->map[RMAP_IN].name)
12816 json_object_boolean_true_add(json_addr,
12817 "inboundPathPolicyConfig");
12818 if (filter->plist[FILTER_OUT].name
12819 || filter->dlist[FILTER_OUT].name
12820 || filter->aslist[FILTER_OUT].name
12821 || filter->map[RMAP_OUT].name || filter->usmap.name)
12822 json_object_boolean_true_add(
12823 json_addr, "outboundPathPolicyConfig");
12824
12825 /* prefix-list */
12826 if (filter->plist[FILTER_IN].name)
12827 json_object_string_add(json_addr,
12828 "incomingUpdatePrefixFilterList",
12829 filter->plist[FILTER_IN].name);
12830 if (filter->plist[FILTER_OUT].name)
12831 json_object_string_add(json_addr,
12832 "outgoingUpdatePrefixFilterList",
12833 filter->plist[FILTER_OUT].name);
12834
12835 /* distribute-list */
12836 if (filter->dlist[FILTER_IN].name)
12837 json_object_string_add(
12838 json_addr, "incomingUpdateNetworkFilterList",
12839 filter->dlist[FILTER_IN].name);
12840 if (filter->dlist[FILTER_OUT].name)
12841 json_object_string_add(
12842 json_addr, "outgoingUpdateNetworkFilterList",
12843 filter->dlist[FILTER_OUT].name);
12844
12845 /* filter-list. */
12846 if (filter->aslist[FILTER_IN].name)
12847 json_object_string_add(json_addr,
12848 "incomingUpdateAsPathFilterList",
12849 filter->aslist[FILTER_IN].name);
12850 if (filter->aslist[FILTER_OUT].name)
12851 json_object_string_add(json_addr,
12852 "outgoingUpdateAsPathFilterList",
12853 filter->aslist[FILTER_OUT].name);
12854
12855 /* route-map. */
12856 if (filter->map[RMAP_IN].name)
12857 json_object_string_add(
12858 json_addr, "routeMapForIncomingAdvertisements",
12859 filter->map[RMAP_IN].name);
12860 if (filter->map[RMAP_OUT].name)
12861 json_object_string_add(
12862 json_addr, "routeMapForOutgoingAdvertisements",
12863 filter->map[RMAP_OUT].name);
12864
9dac9fc8 12865 /* ebgp-requires-policy (inbound) */
1d3fdccf 12866 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12867 && !bgp_inbound_policy_exists(p, filter))
12868 json_object_string_add(
12869 json_addr, "inboundEbgpRequiresPolicy",
12870 "Inbound updates discarded due to missing policy");
12871
12872 /* ebgp-requires-policy (outbound) */
1d3fdccf 12873 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12874 && (!bgp_outbound_policy_exists(p, filter)))
12875 json_object_string_add(
12876 json_addr, "outboundEbgpRequiresPolicy",
12877 "Outbound updates discarded due to missing policy");
12878
d62a17ae 12879 /* unsuppress-map */
12880 if (filter->usmap.name)
12881 json_object_string_add(json_addr,
12882 "selectiveUnsuppressRouteMap",
12883 filter->usmap.name);
12884
fa36596c
MK
12885 /* advertise-map */
12886 if (filter->advmap.aname) {
12887 json_advmap = json_object_new_object();
12888 json_object_string_add(json_advmap, "condition",
12889 filter->advmap.condition
12890 ? "EXIST"
12891 : "NON_EXIST");
12892 json_object_string_add(json_advmap, "conditionMap",
12893 filter->advmap.cname);
12894 json_object_string_add(json_advmap, "advertiseMap",
12895 filter->advmap.aname);
ecf2b628
QY
12896 json_object_string_add(
12897 json_advmap, "advertiseStatus",
12898 filter->advmap.update_type ==
12899 UPDATE_TYPE_ADVERTISE
12900 ? "Advertise"
12901 : "Withdraw");
fa36596c
MK
12902 json_object_object_add(json_addr, "advertiseMap",
12903 json_advmap);
12904 }
12905
d62a17ae 12906 /* Receive prefix count */
12907 json_object_int_add(json_addr, "acceptedPrefixCounter",
12908 p->pcount[afi][safi]);
50e05855
AD
12909 if (paf && PAF_SUBGRP(paf))
12910 json_object_int_add(json_addr, "sentPrefixCounter",
12911 (PAF_SUBGRP(paf))->scount);
d62a17ae 12912
fde246e8
DA
12913 /* Maximum prefix */
12914 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12915 json_object_int_add(json_addr, "prefixOutAllowedMax",
12916 p->pmax_out[afi][safi]);
12917
d62a17ae 12918 /* Maximum prefix */
12919 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12920 json_object_int_add(json_addr, "prefixAllowedMax",
12921 p->pmax[afi][safi]);
12922 if (CHECK_FLAG(p->af_flags[afi][safi],
12923 PEER_FLAG_MAX_PREFIX_WARNING))
12924 json_object_boolean_true_add(
12925 json_addr, "prefixAllowedMaxWarning");
12926 json_object_int_add(json_addr,
12927 "prefixAllowedWarningThresh",
12928 p->pmax_threshold[afi][safi]);
12929 if (p->pmax_restart[afi][safi])
12930 json_object_int_add(
12931 json_addr,
12932 "prefixAllowedRestartIntervalMsecs",
12933 p->pmax_restart[afi][safi] * 60000);
12934 }
2986cac2 12935 json_object_object_add(json_neigh,
36235319 12936 get_afi_safi_str(afi, safi, true),
d62a17ae 12937 json_addr);
12938
12939 } else {
12940 filter = &p->filter[afi][safi];
12941
12942 vty_out(vty, " For address family: %s\n",
5cb5f4d0 12943 get_afi_safi_str(afi, safi, false));
d62a17ae 12944
12945 if (peer_group_active(p))
12946 vty_out(vty, " %s peer-group member\n",
12947 p->group->name);
12948
12949 paf = peer_af_find(p, afi, safi);
12950 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 12951 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 12952 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12953 vty_out(vty, " Packet Queue length %d\n",
12954 bpacket_queue_virtual_length(paf));
12955 } else {
12956 vty_out(vty, " Not part of any update group\n");
12957 }
12958 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12959 || CHECK_FLAG(p->af_cap[afi][safi],
12960 PEER_CAP_ORF_PREFIX_SM_RCV)
12961 || CHECK_FLAG(p->af_cap[afi][safi],
12962 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12963 || CHECK_FLAG(p->af_cap[afi][safi],
12964 PEER_CAP_ORF_PREFIX_RM_ADV)
12965 || CHECK_FLAG(p->af_cap[afi][safi],
12966 PEER_CAP_ORF_PREFIX_RM_RCV)
12967 || CHECK_FLAG(p->af_cap[afi][safi],
12968 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12969 vty_out(vty, " AF-dependant capabilities:\n");
12970
12971 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12972 || CHECK_FLAG(p->af_cap[afi][safi],
12973 PEER_CAP_ORF_PREFIX_SM_RCV)
12974 || CHECK_FLAG(p->af_cap[afi][safi],
12975 PEER_CAP_ORF_PREFIX_RM_ADV)
12976 || CHECK_FLAG(p->af_cap[afi][safi],
12977 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12978 vty_out(vty,
12979 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12980 ORF_TYPE_PREFIX);
12981 bgp_show_peer_afi_orf_cap(
12982 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12983 PEER_CAP_ORF_PREFIX_RM_ADV,
12984 PEER_CAP_ORF_PREFIX_SM_RCV,
12985 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12986 }
12987 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12988 || CHECK_FLAG(p->af_cap[afi][safi],
12989 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12990 || CHECK_FLAG(p->af_cap[afi][safi],
12991 PEER_CAP_ORF_PREFIX_RM_ADV)
12992 || CHECK_FLAG(p->af_cap[afi][safi],
12993 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12994 vty_out(vty,
12995 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12996 ORF_TYPE_PREFIX_OLD);
12997 bgp_show_peer_afi_orf_cap(
12998 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12999 PEER_CAP_ORF_PREFIX_RM_ADV,
13000 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
13001 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
13002 }
13003
772270f3
QY
13004 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
13005 p->host, afi, safi);
d62a17ae 13006 orf_pfx_count = prefix_bgp_show_prefix_list(
13007 NULL, afi, orf_pfx_name, use_json);
13008
13009 if (CHECK_FLAG(p->af_sflags[afi][safi],
13010 PEER_STATUS_ORF_PREFIX_SEND)
13011 || orf_pfx_count) {
13012 vty_out(vty, " Outbound Route Filter (ORF):");
13013 if (CHECK_FLAG(p->af_sflags[afi][safi],
13014 PEER_STATUS_ORF_PREFIX_SEND))
13015 vty_out(vty, " sent;");
13016 if (orf_pfx_count)
13017 vty_out(vty, " received (%d entries)",
13018 orf_pfx_count);
13019 vty_out(vty, "\n");
13020 }
13021 if (CHECK_FLAG(p->af_sflags[afi][safi],
13022 PEER_STATUS_ORF_WAIT_REFRESH))
13023 vty_out(vty,
13024 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
13025
13026 if (CHECK_FLAG(p->af_flags[afi][safi],
13027 PEER_FLAG_REFLECTOR_CLIENT))
13028 vty_out(vty, " Route-Reflector Client\n");
13029 if (CHECK_FLAG(p->af_flags[afi][safi],
13030 PEER_FLAG_RSERVER_CLIENT))
13031 vty_out(vty, " Route-Server Client\n");
13032 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
13033 vty_out(vty,
13034 " Inbound soft reconfiguration allowed\n");
13035
13036 if (CHECK_FLAG(p->af_flags[afi][safi],
13037 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
13038 vty_out(vty,
13039 " Private AS numbers (all) replaced in updates to this neighbor\n");
13040 else if (CHECK_FLAG(p->af_flags[afi][safi],
13041 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
13042 vty_out(vty,
13043 " Private AS numbers replaced in updates to this neighbor\n");
13044 else if (CHECK_FLAG(p->af_flags[afi][safi],
13045 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
13046 vty_out(vty,
13047 " Private AS numbers (all) removed in updates to this neighbor\n");
13048 else if (CHECK_FLAG(p->af_flags[afi][safi],
13049 PEER_FLAG_REMOVE_PRIVATE_AS))
13050 vty_out(vty,
13051 " Private AS numbers removed in updates to this neighbor\n");
13052
b2ac1d0d
MS
13053 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
13054 if (CHECK_FLAG(p->af_flags[afi][safi],
13055 PEER_FLAG_ALLOWAS_IN_ORIGIN))
13056 vty_out(vty,
13057 " Local AS allowed as path origin\n");
13058 else
13059 vty_out(vty,
13060 " Local AS allowed in path, %d occurrences\n",
13061 p->allowas_in[afi][safi]);
13062 }
13063
dcc68b5e
MS
13064 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
13065 vty_out(vty, " %s\n",
13066 bgp_addpath_names(p->addpath_type[afi][safi])
13067 ->human_description);
d62a17ae 13068
13069 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
13070 vty_out(vty,
13071 " Override ASNs in outbound updates if aspath equals remote-as\n");
13072
13073 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
13074 || CHECK_FLAG(p->af_flags[afi][safi],
13075 PEER_FLAG_FORCE_NEXTHOP_SELF))
13076 vty_out(vty, " NEXT_HOP is always this router\n");
13077 if (CHECK_FLAG(p->af_flags[afi][safi],
13078 PEER_FLAG_AS_PATH_UNCHANGED))
13079 vty_out(vty,
13080 " AS_PATH is propagated unchanged to this neighbor\n");
13081 if (CHECK_FLAG(p->af_flags[afi][safi],
13082 PEER_FLAG_NEXTHOP_UNCHANGED))
13083 vty_out(vty,
13084 " NEXT_HOP is propagated unchanged to this neighbor\n");
13085 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
13086 vty_out(vty,
13087 " MED is propagated unchanged to this neighbor\n");
13088 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
13089 || CHECK_FLAG(p->af_flags[afi][safi],
13090 PEER_FLAG_SEND_EXT_COMMUNITY)
13091 || CHECK_FLAG(p->af_flags[afi][safi],
13092 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
13093 vty_out(vty,
13094 " Community attribute sent to this neighbor");
13095 if (CHECK_FLAG(p->af_flags[afi][safi],
13096 PEER_FLAG_SEND_COMMUNITY)
13097 && CHECK_FLAG(p->af_flags[afi][safi],
13098 PEER_FLAG_SEND_EXT_COMMUNITY)
13099 && CHECK_FLAG(p->af_flags[afi][safi],
13100 PEER_FLAG_SEND_LARGE_COMMUNITY))
13101 vty_out(vty, "(all)\n");
13102 else if (CHECK_FLAG(p->af_flags[afi][safi],
13103 PEER_FLAG_SEND_LARGE_COMMUNITY))
13104 vty_out(vty, "(large)\n");
13105 else if (CHECK_FLAG(p->af_flags[afi][safi],
13106 PEER_FLAG_SEND_EXT_COMMUNITY))
13107 vty_out(vty, "(extended)\n");
13108 else
13109 vty_out(vty, "(standard)\n");
13110 }
13111 if (CHECK_FLAG(p->af_flags[afi][safi],
13112 PEER_FLAG_DEFAULT_ORIGINATE)) {
13113 vty_out(vty, " Default information originate,");
13114
13115 if (p->default_rmap[afi][safi].name)
13116 vty_out(vty, " default route-map %s%s,",
13117 p->default_rmap[afi][safi].map ? "*"
13118 : "",
13119 p->default_rmap[afi][safi].name);
13120 if (paf && PAF_SUBGRP(paf)
13121 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
13122 SUBGRP_STATUS_DEFAULT_ORIGINATE))
13123 vty_out(vty, " default sent\n");
13124 else
13125 vty_out(vty, " default not sent\n");
13126 }
13127
dff8f48d
MK
13128 /* advertise-vni-all */
13129 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 13130 if (is_evpn_enabled())
dff8f48d
MK
13131 vty_out(vty, " advertise-all-vni\n");
13132 }
13133
d62a17ae 13134 if (filter->plist[FILTER_IN].name
13135 || filter->dlist[FILTER_IN].name
13136 || filter->aslist[FILTER_IN].name
13137 || filter->map[RMAP_IN].name)
13138 vty_out(vty, " Inbound path policy configured\n");
13139 if (filter->plist[FILTER_OUT].name
13140 || filter->dlist[FILTER_OUT].name
13141 || filter->aslist[FILTER_OUT].name
13142 || filter->map[RMAP_OUT].name || filter->usmap.name)
13143 vty_out(vty, " Outbound path policy configured\n");
13144
13145 /* prefix-list */
13146 if (filter->plist[FILTER_IN].name)
13147 vty_out(vty,
13148 " Incoming update prefix filter list is %s%s\n",
13149 filter->plist[FILTER_IN].plist ? "*" : "",
13150 filter->plist[FILTER_IN].name);
13151 if (filter->plist[FILTER_OUT].name)
13152 vty_out(vty,
13153 " Outgoing update prefix filter list is %s%s\n",
13154 filter->plist[FILTER_OUT].plist ? "*" : "",
13155 filter->plist[FILTER_OUT].name);
13156
13157 /* distribute-list */
13158 if (filter->dlist[FILTER_IN].name)
13159 vty_out(vty,
13160 " Incoming update network filter list is %s%s\n",
13161 filter->dlist[FILTER_IN].alist ? "*" : "",
13162 filter->dlist[FILTER_IN].name);
13163 if (filter->dlist[FILTER_OUT].name)
13164 vty_out(vty,
13165 " Outgoing update network filter list is %s%s\n",
13166 filter->dlist[FILTER_OUT].alist ? "*" : "",
13167 filter->dlist[FILTER_OUT].name);
13168
13169 /* filter-list. */
13170 if (filter->aslist[FILTER_IN].name)
13171 vty_out(vty,
13172 " Incoming update AS path filter list is %s%s\n",
13173 filter->aslist[FILTER_IN].aslist ? "*" : "",
13174 filter->aslist[FILTER_IN].name);
13175 if (filter->aslist[FILTER_OUT].name)
13176 vty_out(vty,
13177 " Outgoing update AS path filter list is %s%s\n",
13178 filter->aslist[FILTER_OUT].aslist ? "*" : "",
13179 filter->aslist[FILTER_OUT].name);
13180
13181 /* route-map. */
13182 if (filter->map[RMAP_IN].name)
13183 vty_out(vty,
13184 " Route map for incoming advertisements is %s%s\n",
13185 filter->map[RMAP_IN].map ? "*" : "",
13186 filter->map[RMAP_IN].name);
13187 if (filter->map[RMAP_OUT].name)
13188 vty_out(vty,
13189 " Route map for outgoing advertisements is %s%s\n",
13190 filter->map[RMAP_OUT].map ? "*" : "",
13191 filter->map[RMAP_OUT].name);
13192
9dac9fc8 13193 /* ebgp-requires-policy (inbound) */
1d3fdccf 13194 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
13195 && !bgp_inbound_policy_exists(p, filter))
13196 vty_out(vty,
13197 " Inbound updates discarded due to missing policy\n");
13198
13199 /* ebgp-requires-policy (outbound) */
1d3fdccf 13200 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
13201 && !bgp_outbound_policy_exists(p, filter))
13202 vty_out(vty,
13203 " Outbound updates discarded due to missing policy\n");
13204
d62a17ae 13205 /* unsuppress-map */
13206 if (filter->usmap.name)
13207 vty_out(vty,
13208 " Route map for selective unsuppress is %s%s\n",
13209 filter->usmap.map ? "*" : "",
13210 filter->usmap.name);
13211
7f7940e6
MK
13212 /* advertise-map */
13213 if (filter->advmap.aname && filter->advmap.cname)
13214 vty_out(vty,
13215 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
13216 filter->advmap.condition ? "EXIST"
13217 : "NON_EXIST",
13218 filter->advmap.cmap ? "*" : "",
13219 filter->advmap.cname,
13220 filter->advmap.amap ? "*" : "",
13221 filter->advmap.aname,
ecf2b628
QY
13222 filter->advmap.update_type ==
13223 UPDATE_TYPE_ADVERTISE
c385f82a
MK
13224 ? "Advertise"
13225 : "Withdraw");
7f7940e6 13226
d62a17ae 13227 /* Receive prefix count */
6cde4b45 13228 vty_out(vty, " %u accepted prefixes\n",
a0a87037 13229 p->pcount[afi][safi]);
d62a17ae 13230
fde246e8
DA
13231 /* maximum-prefix-out */
13232 if (CHECK_FLAG(p->af_flags[afi][safi],
13233 PEER_FLAG_MAX_PREFIX_OUT))
13234 vty_out(vty,
6cde4b45 13235 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
13236 p->pmax_out[afi][safi]);
13237
d62a17ae 13238 /* Maximum prefix */
13239 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 13240 vty_out(vty,
6cde4b45 13241 " Maximum prefixes allowed %u%s\n",
d62a17ae 13242 p->pmax[afi][safi],
13243 CHECK_FLAG(p->af_flags[afi][safi],
13244 PEER_FLAG_MAX_PREFIX_WARNING)
13245 ? " (warning-only)"
13246 : "");
13247 vty_out(vty, " Threshold for warning message %d%%",
13248 p->pmax_threshold[afi][safi]);
13249 if (p->pmax_restart[afi][safi])
13250 vty_out(vty, ", restart interval %d min",
13251 p->pmax_restart[afi][safi]);
13252 vty_out(vty, "\n");
13253 }
13254
13255 vty_out(vty, "\n");
13256 }
13257}
13258
9f049418 13259static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 13260 json_object *json)
718e3744 13261{
d62a17ae 13262 struct bgp *bgp;
d62a17ae 13263 char timebuf[BGP_UPTIME_LEN];
13264 char dn_flag[2];
d62a17ae 13265 afi_t afi;
13266 safi_t safi;
d7c0a89a
QY
13267 uint16_t i;
13268 uint8_t *msg;
d62a17ae 13269 json_object *json_neigh = NULL;
13270 time_t epoch_tbuf;
4ab46701 13271 uint32_t sync_tcp_mss;
718e3744 13272
d62a17ae 13273 bgp = p->bgp;
13274
13275 if (use_json)
13276 json_neigh = json_object_new_object();
13277
13278 memset(dn_flag, '\0', sizeof(dn_flag));
13279 if (!p->conf_if && peer_dynamic_neighbor(p))
13280 dn_flag[0] = '*';
13281
13282 if (!use_json) {
13283 if (p->conf_if) /* Configured interface name. */
47e12884
DA
13284 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
13285 &p->su);
d62a17ae 13286 else /* Configured IP address. */
13287 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
13288 p->host);
13289 }
13290
13291 if (use_json) {
13292 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
13293 json_object_string_add(json_neigh, "bgpNeighborAddr",
13294 "none");
13295 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
47e12884
DA
13296 json_object_string_addf(json_neigh, "bgpNeighborAddr",
13297 "%pSU", &p->su);
d62a17ae 13298
44a4d55e 13299 asn_asn2json(json_neigh, "remoteAs", p->as, bgp->asnotation);
d62a17ae 13300
13301 if (p->change_local_as)
44a4d55e
PG
13302 asn_asn2json(json_neigh, "localAs", p->change_local_as,
13303 bgp->asnotation);
d62a17ae 13304 else
44a4d55e
PG
13305 asn_asn2json(json_neigh, "localAs", p->local_as,
13306 bgp->asnotation);
d62a17ae 13307
13308 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
13309 json_object_boolean_true_add(json_neigh,
13310 "localAsNoPrepend");
13311
13312 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
13313 json_object_boolean_true_add(json_neigh,
13314 "localAsReplaceAs");
13315 } else {
44a4d55e
PG
13316 if ((p->as_type == AS_SPECIFIED) ||
13317 (p->as_type == AS_EXTERNAL) ||
13318 (p->as_type == AS_INTERNAL)) {
13319 vty_out(vty, "remote AS ");
13320 vty_out(vty, ASN_FORMAT(bgp->asnotation), &p->as);
13321 vty_out(vty, ", ");
13322 } else
d62a17ae 13323 vty_out(vty, "remote AS Unspecified, ");
44a4d55e
PG
13324 vty_out(vty, "local AS ");
13325 vty_out(vty, ASN_FORMAT(bgp->asnotation),
13326 p->change_local_as ? &p->change_local_as
13327 : &p->local_as);
13328 vty_out(vty, "%s%s, ",
d62a17ae 13329 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
13330 ? " no-prepend"
13331 : "",
13332 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
13333 ? " replace-as"
13334 : "");
13335 }
faa16034
DS
13336 /* peer type internal or confed-internal */
13337 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 13338 if (use_json) {
13339 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13340 json_object_boolean_true_add(
13341 json_neigh, "nbrConfedInternalLink");
13342 else
13343 json_object_boolean_true_add(json_neigh,
13344 "nbrInternalLink");
13345 } else {
13346 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13347 vty_out(vty, "confed-internal link\n");
13348 else
13349 vty_out(vty, "internal link\n");
13350 }
faa16034
DS
13351 /* peer type external or confed-external */
13352 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 13353 if (use_json) {
13354 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13355 json_object_boolean_true_add(
13356 json_neigh, "nbrConfedExternalLink");
13357 else
13358 json_object_boolean_true_add(json_neigh,
13359 "nbrExternalLink");
13360 } else {
13361 if (bgp_confederation_peers_check(bgp, p->as))
13362 vty_out(vty, "confed-external link\n");
13363 else
13364 vty_out(vty, "external link\n");
13365 }
faa16034
DS
13366 } else {
13367 if (use_json)
13368 json_object_boolean_true_add(json_neigh,
13369 "nbrUnspecifiedLink");
13370 else
13371 vty_out(vty, "unspecified link\n");
d62a17ae 13372 }
13373
d864dd9e
EB
13374 /* Roles */
13375 if (use_json) {
13376 json_object_string_add(json_neigh, "localRole",
8f2d6021
EB
13377 bgp_get_name_by_role(p->local_role));
13378 json_object_string_add(json_neigh, "remoteRole",
13379 bgp_get_name_by_role(p->remote_role));
d864dd9e
EB
13380 } else {
13381 vty_out(vty, " Local Role: %s\n",
8f2d6021
EB
13382 bgp_get_name_by_role(p->local_role));
13383 vty_out(vty, " Remote Role: %s\n",
13384 bgp_get_name_by_role(p->remote_role));
d864dd9e
EB
13385 }
13386
13387
d62a17ae 13388 /* Description. */
13389 if (p->desc) {
13390 if (use_json)
13391 json_object_string_add(json_neigh, "nbrDesc", p->desc);
13392 else
13393 vty_out(vty, " Description: %s\n", p->desc);
13394 }
13395
13396 if (p->hostname) {
13397 if (use_json) {
432e7e46
KQ
13398 json_object_string_add(json_neigh, "hostname",
13399 p->hostname);
d62a17ae 13400
13401 if (p->domainname)
13402 json_object_string_add(json_neigh, "domainname",
13403 p->domainname);
13404 } else {
13405 if (p->domainname && (p->domainname[0] != '\0'))
13406 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13407 p->domainname);
13408 else
13409 vty_out(vty, "Hostname: %s\n", p->hostname);
13410 }
432e7e46
KQ
13411 } else {
13412 if (use_json)
13413 json_object_string_add(json_neigh, "hostname",
13414 "Unknown");
d62a17ae 13415 }
13416
13417 /* Peer-group */
13418 if (p->group) {
13419 if (use_json) {
13420 json_object_string_add(json_neigh, "peerGroup",
13421 p->group->name);
13422
13423 if (dn_flag[0]) {
13424 struct prefix prefix, *range = NULL;
13425
0154d8ce
DS
13426 if (sockunion2hostprefix(&(p->su), &prefix))
13427 range = peer_group_lookup_dynamic_neighbor_range(
13428 p->group, &prefix);
d62a17ae 13429
13430 if (range) {
67d7e256 13431 json_object_string_addf(
d62a17ae 13432 json_neigh,
67d7e256
DA
13433 "peerSubnetRangeGroup", "%pFX",
13434 range);
d62a17ae 13435 }
13436 }
13437 } else {
13438 vty_out(vty,
13439 " Member of peer-group %s for session parameters\n",
13440 p->group->name);
13441
13442 if (dn_flag[0]) {
13443 struct prefix prefix, *range = NULL;
13444
0154d8ce
DS
13445 if (sockunion2hostprefix(&(p->su), &prefix))
13446 range = peer_group_lookup_dynamic_neighbor_range(
13447 p->group, &prefix);
d62a17ae 13448
13449 if (range) {
d62a17ae 13450 vty_out(vty,
1b78780b
DL
13451 " Belongs to the subnet range group: %pFX\n",
13452 range);
d62a17ae 13453 }
13454 }
13455 }
13456 }
13457
13458 if (use_json) {
13459 /* Administrative shutdown. */
cb9196e7
DS
13460 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13461 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13462 json_object_boolean_true_add(json_neigh,
13463 "adminShutDown");
13464
13465 /* BGP Version. */
13466 json_object_int_add(json_neigh, "bgpVersion", 4);
c949c771
DA
13467 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
13468 &p->remote_id);
13469 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
13470 &bgp->router_id);
d62a17ae 13471
13472 /* Confederation */
13473 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13474 && bgp_confederation_peers_check(bgp, p->as))
13475 json_object_boolean_true_add(json_neigh,
13476 "nbrCommonAdmin");
13477
13478 /* Status. */
13479 json_object_string_add(
13480 json_neigh, "bgpState",
13481 lookup_msg(bgp_status_msg, p->status, NULL));
13482
feb17238 13483 if (peer_established(p)) {
d62a17ae 13484 time_t uptime;
d62a17ae 13485
083ec940 13486 uptime = monotime(NULL);
d62a17ae 13487 uptime -= p->uptime;
d62a17ae 13488 epoch_tbuf = time(NULL) - uptime;
13489
d3c7efed
DS
13490 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13491 uptime * 1000);
d62a17ae 13492 json_object_string_add(json_neigh, "bgpTimerUpString",
13493 peer_uptime(p->uptime, timebuf,
13494 BGP_UPTIME_LEN, 0,
13495 NULL));
13496 json_object_int_add(json_neigh,
13497 "bgpTimerUpEstablishedEpoch",
13498 epoch_tbuf);
13499 }
13500
13501 else if (p->status == Active) {
13502 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13503 json_object_string_add(json_neigh, "bgpStateIs",
13504 "passive");
13505 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13506 json_object_string_add(json_neigh, "bgpStateIs",
13507 "passiveNSF");
13508 }
13509
13510 /* read timer */
13511 time_t uptime;
a2700b50 13512 struct tm tm;
d62a17ae 13513
083ec940 13514 uptime = monotime(NULL);
d62a17ae 13515 uptime -= p->readtime;
a2700b50
MS
13516 gmtime_r(&uptime, &tm);
13517
d62a17ae 13518 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
13519 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13520 + (tm.tm_hour * 3600000));
d62a17ae 13521
083ec940 13522 uptime = monotime(NULL);
d62a17ae 13523 uptime -= p->last_write;
a2700b50
MS
13524 gmtime_r(&uptime, &tm);
13525
d62a17ae 13526 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
13527 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13528 + (tm.tm_hour * 3600000));
d62a17ae 13529
083ec940 13530 uptime = monotime(NULL);
d62a17ae 13531 uptime -= p->update_time;
a2700b50
MS
13532 gmtime_r(&uptime, &tm);
13533
d62a17ae 13534 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
13535 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13536 + (tm.tm_hour * 3600000));
d62a17ae 13537
13538 /* Configured timer values. */
9b1b9623
TA
13539 json_object_int_add(json_neigh,
13540 "bgpTimerConfiguredHoldTimeMsecs",
e93d5c29
TA
13541 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13542 ? p->holdtime * 1000
13543 : bgp->default_holdtime * 1000);
13544 json_object_int_add(json_neigh,
13545 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13546 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13547 ? p->keepalive * 1000
13548 : bgp->default_keepalive * 1000);
d62a17ae 13549 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13550 p->v_holdtime * 1000);
13551 json_object_int_add(json_neigh,
13552 "bgpTimerKeepAliveIntervalMsecs",
13553 p->v_keepalive * 1000);
d43114f3
DS
13554 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13555 json_object_int_add(json_neigh,
13556 "bgpTimerDelayOpenTimeMsecs",
13557 p->v_delayopen * 1000);
13558 }
13559
4ab46701
AR
13560 /* Configured and Synced tcp-mss value for peer */
13561 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13562 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13563 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13564 p->tcp_mss);
13565 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13566 sync_tcp_mss);
13567 }
13568
d08c0c80
DA
13569 /* Extended Optional Parameters Length for BGP OPEN Message */
13570 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13571 json_object_boolean_true_add(
13572 json_neigh, "extendedOptionalParametersLength");
13573 else
13574 json_object_boolean_false_add(
13575 json_neigh, "extendedOptionalParametersLength");
6e37924b
DA
13576
13577 /* Conditional advertisements */
13578 json_object_int_add(
13579 json_neigh,
13580 "bgpTimerConfiguredConditionalAdvertisementsSec",
13581 bgp->condition_check_period);
5f6eaa9b 13582 if (event_is_scheduled(bgp->t_condition_check))
6e37924b
DA
13583 json_object_int_add(
13584 json_neigh,
13585 "bgpTimerUntilConditionalAdvertisementsSec",
4f830a07 13586 event_timer_remain_second(
6e37924b 13587 bgp->t_condition_check));
d62a17ae 13588 } else {
13589 /* Administrative shutdown. */
cb9196e7
DS
13590 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13591 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13592 vty_out(vty, " Administratively shut down\n");
13593
13594 /* BGP Version. */
13595 vty_out(vty, " BGP version 4");
07380148
DA
13596 vty_out(vty, ", remote router ID %pI4", &p->remote_id);
13597 vty_out(vty, ", local router ID %pI4\n", &bgp->router_id);
d62a17ae 13598
13599 /* Confederation */
13600 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13601 && bgp_confederation_peers_check(bgp, p->as))
13602 vty_out(vty,
13603 " Neighbor under common administration\n");
13604
13605 /* Status. */
13606 vty_out(vty, " BGP state = %s",
13607 lookup_msg(bgp_status_msg, p->status, NULL));
13608
feb17238 13609 if (peer_established(p))
d62a17ae 13610 vty_out(vty, ", up for %8s",
13611 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13612 0, NULL));
13613
13614 else if (p->status == Active) {
13615 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13616 vty_out(vty, " (passive)");
13617 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13618 vty_out(vty, " (NSF passive)");
13619 }
13620 vty_out(vty, "\n");
13621
13622 /* read timer */
13623 vty_out(vty, " Last read %s",
13624 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13625 NULL));
13626 vty_out(vty, ", Last write %s\n",
13627 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13628 NULL));
13629
13630 /* Configured timer values. */
13631 vty_out(vty,
e93d5c29 13632 " Hold time is %d seconds, keepalive interval is %d seconds\n",
d62a17ae 13633 p->v_holdtime, p->v_keepalive);
e93d5c29
TA
13634 vty_out(vty, " Configured hold time is %d seconds",
13635 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13636 ? p->holdtime
13637 : bgp->default_holdtime);
9b1b9623 13638 vty_out(vty, ", keepalive interval is %d seconds\n",
e93d5c29
TA
13639 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13640 ? p->keepalive
13641 : bgp->default_keepalive);
d43114f3
DS
13642 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13643 vty_out(vty,
13644 " Configured DelayOpenTime is %d seconds\n",
13645 p->delayopen);
4ab46701
AR
13646
13647 /* Configured and synced tcp-mss value for peer */
13648 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13649 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13650 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13651 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13652 }
d08c0c80
DA
13653
13654 /* Extended Optional Parameters Length for BGP OPEN Message */
13655 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13656 vty_out(vty,
13657 " Extended Optional Parameters Length is enabled\n");
6e37924b
DA
13658
13659 /* Conditional advertisements */
13660 vty_out(vty,
13661 " Configured conditional advertisements interval is %d seconds\n",
13662 bgp->condition_check_period);
5f6eaa9b 13663 if (event_is_scheduled(bgp->t_condition_check))
6e37924b
DA
13664 vty_out(vty,
13665 " Time until conditional advertisements begin is %lu seconds\n",
4f830a07 13666 event_timer_remain_second(
6e37924b 13667 bgp->t_condition_check));
d62a17ae 13668 }
13669 /* Capability. */
10711563
DA
13670 if (peer_established(p) &&
13671 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13672 if (use_json) {
13673 json_object *json_cap = NULL;
d62a17ae 13674
10711563 13675 json_cap = json_object_new_object();
d62a17ae 13676
10711563
DA
13677 /* AS4 */
13678 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13679 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13680 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13681 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
ef56aee4 13682 json_object_string_add(
10711563 13683 json_cap, "4byteAs",
ef56aee4 13684 "advertisedAndReceived");
10711563
DA
13685 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13686 json_object_string_add(json_cap,
13687 "4byteAs",
13688 "advertised");
13689 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13690 json_object_string_add(json_cap,
13691 "4byteAs",
13692 "received");
13693 }
ef56aee4 13694
10711563
DA
13695 /* Extended Message Support */
13696 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13697 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13698 json_object_string_add(json_cap,
13699 "extendedMessage",
13700 "advertisedAndReceived");
13701 else if (CHECK_FLAG(p->cap,
13702 PEER_CAP_EXTENDED_MESSAGE_ADV))
13703 json_object_string_add(json_cap,
13704 "extendedMessage",
13705 "advertised");
13706 else if (CHECK_FLAG(p->cap,
13707 PEER_CAP_EXTENDED_MESSAGE_RCV))
13708 json_object_string_add(json_cap,
13709 "extendedMessage",
13710 "received");
ef56aee4 13711
10711563
DA
13712 /* AddPath */
13713 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13714 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13715 json_object *json_add = NULL;
13716 const char *print_store;
d62a17ae 13717
10711563 13718 json_add = json_object_new_object();
d62a17ae 13719
10711563
DA
13720 FOREACH_AFI_SAFI (afi, safi) {
13721 json_object *json_sub = NULL;
13722 json_sub = json_object_new_object();
13723 print_store = get_afi_safi_str(
13724 afi, safi, true);
d62a17ae 13725
10711563
DA
13726 if (CHECK_FLAG(
13727 p->af_cap[afi][safi],
13728 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13729 CHECK_FLAG(
13730 p->af_cap[afi][safi],
13731 PEER_CAP_ADDPATH_AF_TX_RCV)) {
05c7a1cc
QY
13732 if (CHECK_FLAG(
13733 p->af_cap[afi]
13734 [safi],
10711563
DA
13735 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13736 CHECK_FLAG(
05c7a1cc
QY
13737 p->af_cap[afi]
13738 [safi],
10711563
DA
13739 PEER_CAP_ADDPATH_AF_TX_RCV))
13740 json_object_boolean_true_add(
13741 json_sub,
13742 "txAdvertisedAndReceived");
13743 else if (
13744 CHECK_FLAG(
13745 p->af_cap[afi]
13746 [safi],
13747 PEER_CAP_ADDPATH_AF_TX_ADV))
13748 json_object_boolean_true_add(
13749 json_sub,
13750 "txAdvertised");
13751 else if (
13752 CHECK_FLAG(
13753 p->af_cap[afi]
13754 [safi],
13755 PEER_CAP_ADDPATH_AF_TX_RCV))
13756 json_object_boolean_true_add(
13757 json_sub,
13758 "txReceived");
13759 }
d62a17ae 13760
10711563
DA
13761 if (CHECK_FLAG(
13762 p->af_cap[afi][safi],
13763 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13764 CHECK_FLAG(
13765 p->af_cap[afi][safi],
13766 PEER_CAP_ADDPATH_AF_RX_RCV)) {
05c7a1cc
QY
13767 if (CHECK_FLAG(
13768 p->af_cap[afi]
13769 [safi],
10711563
DA
13770 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13771 CHECK_FLAG(
13772 p->af_cap[afi]
13773 [safi],
13774 PEER_CAP_ADDPATH_AF_RX_RCV))
13775 json_object_boolean_true_add(
13776 json_sub,
13777 "rxAdvertisedAndReceived");
13778 else if (
13779 CHECK_FLAG(
13780 p->af_cap[afi]
13781 [safi],
13782 PEER_CAP_ADDPATH_AF_RX_ADV))
13783 json_object_boolean_true_add(
13784 json_sub,
13785 "rxAdvertised");
13786 else if (
13787 CHECK_FLAG(
13788 p->af_cap[afi]
13789 [safi],
13790 PEER_CAP_ADDPATH_AF_RX_RCV))
13791 json_object_boolean_true_add(
13792 json_sub,
13793 "rxReceived");
05c7a1cc
QY
13794 }
13795
10711563
DA
13796 if (CHECK_FLAG(
13797 p->af_cap[afi][safi],
13798 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13799 CHECK_FLAG(
13800 p->af_cap[afi][safi],
13801 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13802 CHECK_FLAG(
13803 p->af_cap[afi][safi],
13804 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13805 CHECK_FLAG(
13806 p->af_cap[afi][safi],
13807 PEER_CAP_ADDPATH_AF_RX_RCV))
13808 json_object_object_add(
13809 json_add, print_store,
13810 json_sub);
13811 else
13812 json_object_free(json_sub);
d62a17ae 13813 }
13814
10711563
DA
13815 json_object_object_add(json_cap, "addPath",
13816 json_add);
13817 }
d62a17ae 13818
10711563
DA
13819 /* Dynamic */
13820 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13821 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13822 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13823 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13824 json_object_string_add(
13825 json_cap, "dynamic",
13826 "advertisedAndReceived");
13827 else if (CHECK_FLAG(p->cap,
13828 PEER_CAP_DYNAMIC_ADV))
13829 json_object_string_add(json_cap,
13830 "dynamic",
13831 "advertised");
13832 else if (CHECK_FLAG(p->cap,
13833 PEER_CAP_DYNAMIC_RCV))
13834 json_object_string_add(json_cap,
13835 "dynamic",
13836 "received");
13837 }
d62a17ae 13838
d864dd9e
EB
13839 /* Role */
13840 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13841 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13842 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13843 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13844 json_object_string_add(
13845 json_cap, "role",
13846 "advertisedAndReceived");
13847 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13848 json_object_string_add(json_cap, "role",
13849 "advertised");
13850 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13851 json_object_string_add(json_cap, "role",
13852 "received");
13853 }
13854
10711563
DA
13855 /* Extended nexthop */
13856 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13857 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13858 json_object *json_nxt = NULL;
13859 const char *print_store;
d62a17ae 13860
d62a17ae 13861
10711563
DA
13862 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13863 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13864 json_object_string_add(
13865 json_cap, "extendedNexthop",
13866 "advertisedAndReceived");
13867 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13868 json_object_string_add(
13869 json_cap, "extendedNexthop",
13870 "advertised");
13871 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13872 json_object_string_add(
13873 json_cap, "extendedNexthop",
13874 "received");
d62a17ae 13875
10711563
DA
13876 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13877 json_nxt = json_object_new_object();
d62a17ae 13878
10711563
DA
13879 for (safi = SAFI_UNICAST;
13880 safi < SAFI_MAX; safi++) {
13881 if (CHECK_FLAG(
13882 p->af_cap[AFI_IP]
13883 [safi],
13884 PEER_CAP_ENHE_AF_RCV)) {
13885 print_store =
13886 get_afi_safi_str(
d62a17ae 13887 AFI_IP,
10711563
DA
13888 safi,
13889 true);
13890 json_object_string_add(
13891 json_nxt,
13892 print_store,
13893 "recieved"); /* misspelled for compatibility */
d62a17ae 13894 }
d62a17ae 13895 }
10711563
DA
13896 json_object_object_add(
13897 json_cap,
13898 "extendedNexthopFamililesByPeer",
13899 json_nxt);
d62a17ae 13900 }
10711563 13901 }
d62a17ae 13902
10711563
DA
13903 /* Long-lived Graceful Restart */
13904 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13905 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13906 json_object *json_llgr = NULL;
13907 const char *afi_safi_str;
8606be87 13908
10711563
DA
13909 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13910 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13911 json_object_string_add(
13912 json_cap,
13913 "longLivedGracefulRestart",
13914 "advertisedAndReceived");
13915 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13916 json_object_string_add(
13917 json_cap,
13918 "longLivedGracefulRestart",
13919 "advertised");
13920 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13921 json_object_string_add(
13922 json_cap,
13923 "longLivedGracefulRestart",
13924 "received");
8606be87 13925
10711563
DA
13926 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13927 json_llgr = json_object_new_object();
8606be87 13928
10711563
DA
13929 FOREACH_AFI_SAFI (afi, safi) {
13930 if (CHECK_FLAG(
13931 p->af_cap[afi]
13932 [safi],
13933 PEER_CAP_ENHE_AF_RCV)) {
13934 afi_safi_str =
13935 get_afi_safi_str(
8606be87
DA
13936 afi,
13937 safi,
13938 true);
10711563
DA
13939 json_object_string_add(
13940 json_llgr,
13941 afi_safi_str,
13942 "received");
8606be87 13943 }
8606be87 13944 }
10711563
DA
13945 json_object_object_add(
13946 json_cap,
13947 "longLivedGracefulRestartByPeer",
13948 json_llgr);
8606be87 13949 }
10711563 13950 }
8606be87 13951
10711563
DA
13952 /* Route Refresh */
13953 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13954 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13955 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13956 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13957 (CHECK_FLAG(p->cap,
13958 PEER_CAP_REFRESH_NEW_RCV) ||
13959 CHECK_FLAG(p->cap,
13960 PEER_CAP_REFRESH_OLD_RCV))) {
13961 if (CHECK_FLAG(
13962 p->cap,
13963 PEER_CAP_REFRESH_OLD_RCV) &&
13964 CHECK_FLAG(
13965 p->cap,
13966 PEER_CAP_REFRESH_NEW_RCV))
13967 json_object_string_add(
13968 json_cap,
13969 "routeRefresh",
13970 "advertisedAndReceivedOldNew");
13971 else {
d62a17ae 13972 if (CHECK_FLAG(
13973 p->cap,
10711563 13974 PEER_CAP_REFRESH_OLD_RCV))
d62a17ae 13975 json_object_string_add(
13976 json_cap,
13977 "routeRefresh",
10711563
DA
13978 "advertisedAndReceivedOld");
13979 else
13980 json_object_string_add(
13981 json_cap,
13982 "routeRefresh",
13983 "advertisedAndReceivedNew");
d62a17ae 13984 }
10711563
DA
13985 } else if (CHECK_FLAG(p->cap,
13986 PEER_CAP_REFRESH_ADV))
13987 json_object_string_add(json_cap,
13988 "routeRefresh",
13989 "advertised");
13990 else if (CHECK_FLAG(p->cap,
13991 PEER_CAP_REFRESH_NEW_RCV) ||
13992 CHECK_FLAG(p->cap,
13993 PEER_CAP_REFRESH_OLD_RCV))
13994 json_object_string_add(json_cap,
13995 "routeRefresh",
13996 "received");
13997 }
d62a17ae 13998
10711563
DA
13999 /* Enhanced Route Refresh */
14000 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
14001 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
14002 if (CHECK_FLAG(p->cap,
14003 PEER_CAP_ENHANCED_RR_ADV) &&
14004 CHECK_FLAG(p->cap,
14005 PEER_CAP_ENHANCED_RR_RCV))
d77114b7 14006 json_object_string_add(
10711563
DA
14007 json_cap,
14008 "enhancedRouteRefresh",
14009 "advertisedAndReceived");
14010 else if (CHECK_FLAG(p->cap,
14011 PEER_CAP_ENHANCED_RR_ADV))
d77114b7 14012 json_object_string_add(
10711563
DA
14013 json_cap,
14014 "enhancedRouteRefresh",
14015 "advertised");
14016 else if (CHECK_FLAG(p->cap,
9af52ccf 14017 PEER_CAP_ENHANCED_RR_RCV))
10711563
DA
14018 json_object_string_add(
14019 json_cap,
14020 "enhancedRouteRefresh",
14021 "received");
14022 }
d77114b7 14023
10711563
DA
14024 /* Multiprotocol Extensions */
14025 json_object *json_multi = NULL;
d77114b7 14026
10711563 14027 json_multi = json_object_new_object();
d77114b7 14028
10711563
DA
14029 FOREACH_AFI_SAFI (afi, safi) {
14030 if (p->afc_adv[afi][safi] ||
14031 p->afc_recv[afi][safi]) {
14032 json_object *json_exten = NULL;
14033 json_exten = json_object_new_object();
14034
14035 if (p->afc_adv[afi][safi] &&
14036 p->afc_recv[afi][safi])
14037 json_object_boolean_true_add(
14038 json_exten,
9af52ccf 14039 "advertisedAndReceived");
10711563
DA
14040 else if (p->afc_adv[afi][safi])
14041 json_object_boolean_true_add(
14042 json_exten,
9af52ccf 14043 "advertised");
10711563
DA
14044 else if (p->afc_recv[afi][safi])
14045 json_object_boolean_true_add(
14046 json_exten, "received");
9af52ccf 14047
10711563
DA
14048 json_object_object_add(
14049 json_multi,
14050 get_afi_safi_str(afi, safi,
14051 true),
14052 json_exten);
14053 }
14054 }
14055 json_object_object_add(json_cap,
14056 "multiprotocolExtensions",
14057 json_multi);
d62a17ae 14058
10711563
DA
14059 /* Hostname capabilities */
14060 json_object *json_hname = NULL;
d62a17ae 14061
10711563 14062 json_hname = json_object_new_object();
d62a17ae 14063
10711563
DA
14064 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14065 json_object_string_add(
14066 json_hname, "advHostName",
14067 bgp->peer_self->hostname
14068 ? bgp->peer_self->hostname
14069 : "n/a");
14070 json_object_string_add(
14071 json_hname, "advDomainName",
14072 bgp->peer_self->domainname
14073 ? bgp->peer_self->domainname
14074 : "n/a");
14075 }
d77114b7 14076
d77114b7 14077
10711563
DA
14078 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14079 json_object_string_add(
14080 json_hname, "rcvHostName",
14081 p->hostname ? p->hostname : "n/a");
14082 json_object_string_add(
14083 json_hname, "rcvDomainName",
14084 p->domainname ? p->domainname : "n/a");
14085 }
d77114b7 14086
10711563
DA
14087 json_object_object_add(json_cap, "hostName",
14088 json_hname);
d77114b7 14089
234f6fd4
DA
14090 /* Software Version capability */
14091 json_object *json_soft_version = NULL;
14092
14093 json_soft_version = json_object_new_object();
14094
14095 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_ADV))
14096 json_object_string_add(
14097 json_soft_version,
14098 "advertisedSoftwareVersion",
14099 cmd_software_version_get());
14100
14101 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_RCV))
14102 json_object_string_add(
14103 json_soft_version,
14104 "receivedSoftwareVersion",
14105 p->soft_version ? p->soft_version
14106 : "n/a");
14107
14108 json_object_object_add(json_cap, "softwareVersion",
14109 json_soft_version);
14110
17be83bf 14111 /* Graceful Restart */
10711563
DA
14112 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14113 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14114 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
14115 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
d77114b7 14116 json_object_string_add(
10711563
DA
14117 json_cap, "gracefulRestart",
14118 "advertisedAndReceived");
14119 else if (CHECK_FLAG(p->cap,
14120 PEER_CAP_RESTART_ADV))
d77114b7 14121 json_object_string_add(
10711563
DA
14122 json_cap,
14123 "gracefulRestartCapability",
14124 "advertised");
14125 else if (CHECK_FLAG(p->cap,
14126 PEER_CAP_RESTART_RCV))
14127 json_object_string_add(
14128 json_cap,
14129 "gracefulRestartCapability",
14130 "received");
d77114b7 14131
10711563
DA
14132 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14133 int restart_af_count = 0;
14134 json_object *json_restart = NULL;
14135 json_restart = json_object_new_object();
d62a17ae 14136
10711563
DA
14137 json_object_int_add(
14138 json_cap,
14139 "gracefulRestartRemoteTimerMsecs",
14140 p->v_gr_restart * 1000);
d62a17ae 14141
10711563 14142 FOREACH_AFI_SAFI (afi, safi) {
05c7a1cc
QY
14143 if (CHECK_FLAG(
14144 p->af_cap[afi]
14145 [safi],
10711563
DA
14146 PEER_CAP_RESTART_AF_RCV)) {
14147 json_object *json_sub =
14148 NULL;
14149 json_sub =
14150 json_object_new_object();
d62a17ae 14151
05c7a1cc
QY
14152 if (CHECK_FLAG(
14153 p->af_cap
14154 [afi]
14155 [safi],
10711563
DA
14156 PEER_CAP_RESTART_AF_PRESERVE_RCV))
14157 json_object_boolean_true_add(
14158 json_sub,
14159 "preserved");
14160 restart_af_count++;
d62a17ae 14161 json_object_object_add(
10711563
DA
14162 json_restart,
14163 get_afi_safi_str(
14164 afi,
14165 safi,
14166 true),
14167 json_sub);
d62a17ae 14168 }
d62a17ae 14169 }
10711563
DA
14170 if (!restart_af_count) {
14171 json_object_string_add(
14172 json_cap,
14173 "addressFamiliesByPeer",
14174 "none");
14175 json_object_free(json_restart);
14176 } else
14177 json_object_object_add(
14178 json_cap,
14179 "addressFamiliesByPeer",
14180 json_restart);
d62a17ae 14181 }
10711563
DA
14182 }
14183 json_object_object_add(
14184 json_neigh, "neighborCapabilities", json_cap);
14185 } else {
14186 vty_out(vty, " Neighbor capabilities:\n");
14187
14188 /* AS4 */
14189 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
14190 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
14191 vty_out(vty, " 4 Byte AS:");
14192 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
14193 vty_out(vty, " advertised");
14194 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
14195 vty_out(vty, " %sreceived",
14196 CHECK_FLAG(p->cap,
14197 PEER_CAP_AS4_ADV)
14198 ? "and "
14199 : "");
14200 vty_out(vty, "\n");
14201 }
d62a17ae 14202
10711563
DA
14203 /* Extended Message Support */
14204 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
14205 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
14206 vty_out(vty, " Extended Message:");
ef56aee4 14207 if (CHECK_FLAG(p->cap,
10711563
DA
14208 PEER_CAP_EXTENDED_MESSAGE_ADV))
14209 vty_out(vty, " advertised");
14210 if (CHECK_FLAG(p->cap,
14211 PEER_CAP_EXTENDED_MESSAGE_RCV))
14212 vty_out(vty, " %sreceived",
14213 CHECK_FLAG(
14214 p->cap,
14215 PEER_CAP_EXTENDED_MESSAGE_ADV)
14216 ? "and "
14217 : "");
14218 vty_out(vty, "\n");
14219 }
d62a17ae 14220
10711563
DA
14221 /* AddPath */
14222 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
14223 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
14224 vty_out(vty, " AddPath:\n");
d62a17ae 14225
10711563 14226 FOREACH_AFI_SAFI (afi, safi) {
ef56aee4 14227 if (CHECK_FLAG(
10711563
DA
14228 p->af_cap[afi][safi],
14229 PEER_CAP_ADDPATH_AF_TX_ADV) ||
14230 CHECK_FLAG(
14231 p->af_cap[afi][safi],
14232 PEER_CAP_ADDPATH_AF_TX_RCV)) {
14233 vty_out(vty, " %s: TX ",
14234 get_afi_safi_str(
14235 afi, safi,
14236 false));
ef56aee4 14237
10711563
DA
14238 if (CHECK_FLAG(
14239 p->af_cap[afi]
14240 [safi],
14241 PEER_CAP_ADDPATH_AF_TX_ADV))
14242 vty_out(vty,
14243 "advertised");
d62a17ae 14244
05c7a1cc
QY
14245 if (CHECK_FLAG(
14246 p->af_cap[afi]
14247 [safi],
10711563 14248 PEER_CAP_ADDPATH_AF_TX_RCV))
05c7a1cc 14249 vty_out(vty,
10711563
DA
14250 "%sreceived",
14251 CHECK_FLAG(
14252 p->af_cap
14253 [afi]
14254 [safi],
14255 PEER_CAP_ADDPATH_AF_TX_ADV)
14256 ? " and "
14257 : "");
05c7a1cc 14258
10711563
DA
14259 vty_out(vty, "\n");
14260 }
d62a17ae 14261
9af52ccf 14262 if (CHECK_FLAG(
10711563
DA
14263 p->af_cap[afi][safi],
14264 PEER_CAP_ADDPATH_AF_RX_ADV) ||
14265 CHECK_FLAG(
14266 p->af_cap[afi][safi],
14267 PEER_CAP_ADDPATH_AF_RX_RCV)) {
14268 vty_out(vty, " %s: RX ",
5cb5f4d0 14269 get_afi_safi_str(
10711563
DA
14270 afi, safi,
14271 false));
d62a17ae 14272
05c7a1cc
QY
14273 if (CHECK_FLAG(
14274 p->af_cap[afi]
14275 [safi],
10711563 14276 PEER_CAP_ADDPATH_AF_RX_ADV))
05c7a1cc 14277 vty_out(vty,
10711563 14278 "advertised");
d62a17ae 14279
10711563
DA
14280 if (CHECK_FLAG(
14281 p->af_cap[afi]
14282 [safi],
14283 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc 14284 vty_out(vty,
10711563
DA
14285 "%sreceived",
14286 CHECK_FLAG(
14287 p->af_cap
14288 [afi]
14289 [safi],
14290 PEER_CAP_ADDPATH_AF_RX_ADV)
14291 ? " and "
05c7a1cc 14292 : "");
d62a17ae 14293
05c7a1cc 14294 vty_out(vty, "\n");
05c7a1cc 14295 }
d62a17ae 14296 }
10711563 14297 }
d62a17ae 14298
10711563
DA
14299 /* Dynamic */
14300 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
14301 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
14302 vty_out(vty, " Dynamic:");
14303 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
14304 vty_out(vty, " advertised");
14305 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
14306 vty_out(vty, " %sreceived",
14307 CHECK_FLAG(p->cap,
14308 PEER_CAP_DYNAMIC_ADV)
14309 ? "and "
14310 : "");
14311 vty_out(vty, "\n");
14312 }
d62a17ae 14313
d864dd9e
EB
14314 /* Role */
14315 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
14316 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
14317 vty_out(vty, " Role:");
14318 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
14319 vty_out(vty, " advertised");
14320 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
14321 vty_out(vty, " %sreceived",
14322 CHECK_FLAG(p->cap,
14323 PEER_CAP_ROLE_ADV)
14324 ? "and "
14325 : "");
14326 vty_out(vty, "\n");
14327 }
14328
10711563
DA
14329 /* Extended nexthop */
14330 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
14331 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
14332 vty_out(vty, " Extended nexthop:");
14333 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
14334 vty_out(vty, " advertised");
14335 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
14336 vty_out(vty, " %sreceived",
14337 CHECK_FLAG(p->cap,
14338 PEER_CAP_ENHE_ADV)
14339 ? "and "
14340 : "");
14341 vty_out(vty, "\n");
d62a17ae 14342
10711563 14343 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
57f7feb6 14344 vty_out(vty,
10711563
DA
14345 " Address families by peer:\n ");
14346 for (safi = SAFI_UNICAST;
14347 safi < SAFI_MAX; safi++)
14348 if (CHECK_FLAG(
14349 p->af_cap[AFI_IP]
14350 [safi],
14351 PEER_CAP_ENHE_AF_RCV))
14352 vty_out(vty,
14353 " %s\n",
14354 get_afi_safi_str(
14355 AFI_IP,
14356 safi,
14357 false));
d62a17ae 14358 }
10711563 14359 }
d62a17ae 14360
10711563
DA
14361 /* Long-lived Graceful Restart */
14362 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
14363 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
14364 vty_out(vty,
14365 " Long-lived Graceful Restart:");
14366 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
14367 vty_out(vty, " advertised");
14368 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
14369 vty_out(vty, " %sreceived",
14370 CHECK_FLAG(p->cap,
14371 PEER_CAP_LLGR_ADV)
14372 ? "and "
14373 : "");
14374 vty_out(vty, "\n");
8606be87 14375
10711563 14376 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
57f7feb6 14377 vty_out(vty,
10711563
DA
14378 " Address families by peer:\n");
14379 FOREACH_AFI_SAFI (afi, safi)
14380 if (CHECK_FLAG(
14381 p->af_cap[afi]
14382 [safi],
14383 PEER_CAP_LLGR_AF_RCV))
14384 vty_out(vty,
14385 " %s\n",
14386 get_afi_safi_str(
14387 afi,
14388 safi,
14389 false));
8606be87 14390 }
10711563 14391 }
8606be87 14392
10711563
DA
14393 /* Route Refresh */
14394 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
14395 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
14396 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
14397 vty_out(vty, " Route refresh:");
14398 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
14399 vty_out(vty, " advertised");
14400 if (CHECK_FLAG(p->cap,
14401 PEER_CAP_REFRESH_NEW_RCV) ||
14402 CHECK_FLAG(p->cap,
14403 PEER_CAP_REFRESH_OLD_RCV))
14404 vty_out(vty, " %sreceived(%s)",
14405 CHECK_FLAG(p->cap,
14406 PEER_CAP_REFRESH_ADV)
14407 ? "and "
14408 : "",
14409 (CHECK_FLAG(
14410 p->cap,
14411 PEER_CAP_REFRESH_OLD_RCV) &&
14412 CHECK_FLAG(
14413 p->cap,
14414 PEER_CAP_REFRESH_NEW_RCV))
14415 ? "old & new"
14416 : CHECK_FLAG(
14417 p->cap,
14418 PEER_CAP_REFRESH_OLD_RCV)
14419 ? "old"
14420 : "new");
d62a17ae 14421
d77114b7 14422 vty_out(vty, "\n");
10711563 14423 }
d62a17ae 14424
10711563
DA
14425 /* Enhanced Route Refresh */
14426 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
14427 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
14428 vty_out(vty, " Enhanced Route Refresh:");
14429 if (CHECK_FLAG(p->cap,
14430 PEER_CAP_ENHANCED_RR_ADV))
14431 vty_out(vty, " advertised");
14432 if (CHECK_FLAG(p->cap,
14433 PEER_CAP_ENHANCED_RR_RCV))
14434 vty_out(vty, " %sreceived",
14435 CHECK_FLAG(p->cap,
14436 PEER_CAP_REFRESH_ADV)
14437 ? "and "
14438 : "");
14439 vty_out(vty, "\n");
14440 }
14441
14442 /* Multiprotocol Extensions */
14443 FOREACH_AFI_SAFI (afi, safi)
14444 if (p->afc_adv[afi][safi] ||
14445 p->afc_recv[afi][safi]) {
14446 vty_out(vty, " Address Family %s:",
14447 get_afi_safi_str(afi, safi,
14448 false));
14449 if (p->afc_adv[afi][safi])
9af52ccf 14450 vty_out(vty, " advertised");
10711563 14451 if (p->afc_recv[afi][safi])
9af52ccf 14452 vty_out(vty, " %sreceived",
10711563 14453 p->afc_adv[afi][safi]
9af52ccf
DA
14454 ? "and "
14455 : "");
14456 vty_out(vty, "\n");
14457 }
14458
10711563
DA
14459 /* Hostname capability */
14460 vty_out(vty, " Hostname Capability:");
d62a17ae 14461
10711563
DA
14462 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14463 vty_out(vty,
14464 " advertised (name: %s,domain name: %s)",
14465 bgp->peer_self->hostname
14466 ? bgp->peer_self->hostname
14467 : "n/a",
14468 bgp->peer_self->domainname
14469 ? bgp->peer_self->domainname
14470 : "n/a");
14471 } else {
14472 vty_out(vty, " not advertised");
14473 }
d77114b7 14474
10711563
DA
14475 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14476 vty_out(vty,
14477 " received (name: %s,domain name: %s)",
14478 p->hostname ? p->hostname : "n/a",
14479 p->domainname ? p->domainname : "n/a");
14480 } else {
14481 vty_out(vty, " not received");
d62a17ae 14482 }
d62a17ae 14483
10711563 14484 vty_out(vty, "\n");
d77114b7 14485
234f6fd4
DA
14486 /* Software Version capability */
14487 vty_out(vty, " Version Capability:");
14488
14489 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_ADV)) {
14490 vty_out(vty,
14491 " advertised software version (%s)",
14492 cmd_software_version_get());
14493 } else
14494 vty_out(vty, " not advertised");
14495
14496 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_RCV)) {
14497 vty_out(vty, " received software version (%s)",
14498 p->soft_version ? p->soft_version
14499 : "n/a");
14500 } else
14501 vty_out(vty, " not received");
14502
14503 vty_out(vty, "\n");
14504
10711563
DA
14505 /* Graceful Restart */
14506 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14507 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14508 vty_out(vty,
14509 " Graceful Restart Capability:");
14510 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
14511 vty_out(vty, " advertised");
14512 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14513 vty_out(vty, " %sreceived",
14514 CHECK_FLAG(p->cap,
14515 PEER_CAP_RESTART_ADV)
14516 ? "and "
14517 : "");
d77114b7
MK
14518 vty_out(vty, "\n");
14519
10711563
DA
14520 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14521 int restart_af_count = 0;
d62a17ae 14522
10711563
DA
14523 vty_out(vty,
14524 " Remote Restart timer is %d seconds\n",
14525 p->v_gr_restart);
14526 vty_out(vty,
14527 " Address families by peer:\n ");
d62a17ae 14528
10711563
DA
14529 FOREACH_AFI_SAFI (afi, safi)
14530 if (CHECK_FLAG(
14531 p->af_cap[afi]
14532 [safi],
14533 PEER_CAP_RESTART_AF_RCV)) {
14534 vty_out(vty, "%s%s(%s)",
14535 restart_af_count
14536 ? ", "
14537 : "",
14538 get_afi_safi_str(
14539 afi,
14540 safi,
14541 false),
14542 CHECK_FLAG(
14543 p->af_cap
14544 [afi]
14545 [safi],
14546 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14547 ? "preserved"
14548 : "not preserved");
14549 restart_af_count++;
14550 }
14551 if (!restart_af_count)
14552 vty_out(vty, "none");
14553 vty_out(vty, "\n");
14554 }
17be83bf 14555 } /* Graceful Restart */
d62a17ae 14556 }
14557 }
14558
14559 /* graceful restart information */
10711563
DA
14560 json_object *json_grace = NULL;
14561 json_object *json_grace_send = NULL;
14562 json_object *json_grace_recv = NULL;
14563 int eor_send_af_count = 0;
14564 int eor_receive_af_count = 0;
d62a17ae 14565
10711563
DA
14566 if (use_json) {
14567 json_grace = json_object_new_object();
14568 json_grace_send = json_object_new_object();
14569 json_grace_recv = json_object_new_object();
14570
14571 if ((peer_established(p)) &&
14572 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14573 FOREACH_AFI_SAFI (afi, safi) {
14574 if (CHECK_FLAG(p->af_sflags[afi][safi],
14575 PEER_STATUS_EOR_SEND)) {
14576 json_object_boolean_true_add(
14577 json_grace_send,
14578 get_afi_safi_str(afi, safi,
14579 true));
14580 eor_send_af_count++;
d62a17ae 14581 }
10711563
DA
14582 }
14583 FOREACH_AFI_SAFI (afi, safi) {
14584 if (CHECK_FLAG(p->af_sflags[afi][safi],
14585 PEER_STATUS_EOR_RECEIVED)) {
14586 json_object_boolean_true_add(
14587 json_grace_recv,
14588 get_afi_safi_str(afi, safi,
14589 true));
14590 eor_receive_af_count++;
d62a17ae 14591 }
14592 }
10711563
DA
14593 }
14594 json_object_object_add(json_grace, "endOfRibSend",
14595 json_grace_send);
14596 json_object_object_add(json_grace, "endOfRibRecv",
14597 json_grace_recv);
d62a17ae 14598
d62a17ae 14599
10711563
DA
14600 if (p->t_gr_restart)
14601 json_object_int_add(
14602 json_grace, "gracefulRestartTimerMsecs",
4f830a07 14603 event_timer_remain_second(p->t_gr_restart) *
10711563 14604 1000);
2986cac2 14605
10711563
DA
14606 if (p->t_gr_stale)
14607 json_object_int_add(
14608 json_grace, "gracefulStalepathTimerMsecs",
4f830a07 14609 event_timer_remain_second(p->t_gr_stale) *
10711563
DA
14610 1000);
14611 /* more gr info in new format */
403e64f8 14612 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json_grace);
10711563
DA
14613 json_object_object_add(json_neigh, "gracefulRestartInfo",
14614 json_grace);
14615 } else {
14616 vty_out(vty, " Graceful restart information:\n");
14617 if ((peer_established(p)) &&
14618 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14619
14620 vty_out(vty, " End-of-RIB send: ");
14621 FOREACH_AFI_SAFI (afi, safi) {
14622 if (CHECK_FLAG(p->af_sflags[afi][safi],
14623 PEER_STATUS_EOR_SEND)) {
14624 vty_out(vty, "%s%s",
14625 eor_send_af_count ? ", " : "",
14626 get_afi_safi_str(afi, safi,
14627 false));
14628 eor_send_af_count++;
d62a17ae 14629 }
10711563
DA
14630 }
14631 vty_out(vty, "\n");
14632 vty_out(vty, " End-of-RIB received: ");
14633 FOREACH_AFI_SAFI (afi, safi) {
14634 if (CHECK_FLAG(p->af_sflags[afi][safi],
14635 PEER_STATUS_EOR_RECEIVED)) {
14636 vty_out(vty, "%s%s",
14637 eor_receive_af_count ? ", "
14638 : "",
14639 get_afi_safi_str(afi, safi,
14640 false));
14641 eor_receive_af_count++;
d62a17ae 14642 }
d62a17ae 14643 }
10711563
DA
14644 vty_out(vty, "\n");
14645 }
d62a17ae 14646
10711563
DA
14647 if (p->t_gr_restart)
14648 vty_out(vty,
14649 " The remaining time of restart timer is %ld\n",
4f830a07 14650 event_timer_remain_second(p->t_gr_restart));
d62a17ae 14651
10711563
DA
14652 if (p->t_gr_stale)
14653 vty_out(vty,
14654 " The remaining time of stalepath timer is %ld\n",
4f830a07 14655 event_timer_remain_second(p->t_gr_stale));
2986cac2 14656
10711563 14657 /* more gr info in new format */
403e64f8 14658 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, NULL);
10711563 14659 }
2986cac2 14660
d62a17ae 14661 if (use_json) {
14662 json_object *json_stat = NULL;
14663 json_stat = json_object_new_object();
14664 /* Packet counts. */
43aa5965
QY
14665
14666 atomic_size_t outq_count, inq_count;
14667 outq_count = atomic_load_explicit(&p->obuf->count,
14668 memory_order_relaxed);
14669 inq_count = atomic_load_explicit(&p->ibuf->count,
14670 memory_order_relaxed);
14671
14672 json_object_int_add(json_stat, "depthInq",
14673 (unsigned long)inq_count);
d62a17ae 14674 json_object_int_add(json_stat, "depthOutq",
43aa5965 14675 (unsigned long)outq_count);
0112e9e0
QY
14676 json_object_int_add(json_stat, "opensSent",
14677 atomic_load_explicit(&p->open_out,
14678 memory_order_relaxed));
14679 json_object_int_add(json_stat, "opensRecv",
14680 atomic_load_explicit(&p->open_in,
14681 memory_order_relaxed));
d62a17ae 14682 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
14683 atomic_load_explicit(&p->notify_out,
14684 memory_order_relaxed));
d62a17ae 14685 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
14686 atomic_load_explicit(&p->notify_in,
14687 memory_order_relaxed));
14688 json_object_int_add(json_stat, "updatesSent",
14689 atomic_load_explicit(&p->update_out,
14690 memory_order_relaxed));
14691 json_object_int_add(json_stat, "updatesRecv",
14692 atomic_load_explicit(&p->update_in,
14693 memory_order_relaxed));
d62a17ae 14694 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
14695 atomic_load_explicit(&p->keepalive_out,
14696 memory_order_relaxed));
d62a17ae 14697 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
14698 atomic_load_explicit(&p->keepalive_in,
14699 memory_order_relaxed));
d62a17ae 14700 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
14701 atomic_load_explicit(&p->refresh_out,
14702 memory_order_relaxed));
d62a17ae 14703 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
14704 atomic_load_explicit(&p->refresh_in,
14705 memory_order_relaxed));
d62a17ae 14706 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
14707 atomic_load_explicit(&p->dynamic_cap_out,
14708 memory_order_relaxed));
d62a17ae 14709 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
14710 atomic_load_explicit(&p->dynamic_cap_in,
14711 memory_order_relaxed));
14712 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14713 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 14714 json_object_object_add(json_neigh, "messageStats", json_stat);
14715 } else {
cb93e0a2
IS
14716 atomic_size_t outq_count, inq_count, open_out, open_in,
14717 notify_out, notify_in, update_out, update_in,
14718 keepalive_out, keepalive_in, refresh_out, refresh_in,
14719 dynamic_cap_out, dynamic_cap_in;
43aa5965
QY
14720 outq_count = atomic_load_explicit(&p->obuf->count,
14721 memory_order_relaxed);
14722 inq_count = atomic_load_explicit(&p->ibuf->count,
14723 memory_order_relaxed);
cb93e0a2
IS
14724 open_out = atomic_load_explicit(&p->open_out,
14725 memory_order_relaxed);
14726 open_in =
14727 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14728 notify_out = atomic_load_explicit(&p->notify_out,
14729 memory_order_relaxed);
14730 notify_in = atomic_load_explicit(&p->notify_in,
14731 memory_order_relaxed);
14732 update_out = atomic_load_explicit(&p->update_out,
14733 memory_order_relaxed);
14734 update_in = atomic_load_explicit(&p->update_in,
14735 memory_order_relaxed);
14736 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14737 memory_order_relaxed);
14738 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14739 memory_order_relaxed);
14740 refresh_out = atomic_load_explicit(&p->refresh_out,
14741 memory_order_relaxed);
14742 refresh_in = atomic_load_explicit(&p->refresh_in,
14743 memory_order_relaxed);
14744 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14745 memory_order_relaxed);
14746 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14747 memory_order_relaxed);
43aa5965 14748
d62a17ae 14749 /* Packet counts. */
14750 vty_out(vty, " Message statistics:\n");
43aa5965
QY
14751 vty_out(vty, " Inq depth is %zu\n", inq_count);
14752 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 14753 vty_out(vty, " Sent Rcvd\n");
cb93e0a2
IS
14754 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14755 open_in);
14756 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14757 notify_in);
14758 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14759 update_in);
14760 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14761 keepalive_in);
14762 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14763 refresh_in);
14764 vty_out(vty, " Capability: %10zu %10zu\n",
14765 dynamic_cap_out, dynamic_cap_in);
14766 vty_out(vty, " Total: %10u %10u\n",
14767 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
d62a17ae 14768 }
14769
14770 if (use_json) {
14771 /* advertisement-interval */
14772 json_object_int_add(json_neigh,
14773 "minBtwnAdvertisementRunsTimerMsecs",
14774 p->v_routeadv * 1000);
14775
14776 /* Update-source. */
14777 if (p->update_if || p->update_source) {
14778 if (p->update_if)
14779 json_object_string_add(json_neigh,
14780 "updateSource",
14781 p->update_if);
14782 else if (p->update_source)
47e12884
DA
14783 json_object_string_addf(json_neigh,
14784 "updateSource", "%pSU",
14785 p->update_source);
d62a17ae 14786 }
14787 } else {
14788 /* advertisement-interval */
14789 vty_out(vty,
14790 " Minimum time between advertisement runs is %d seconds\n",
14791 p->v_routeadv);
14792
14793 /* Update-source. */
14794 if (p->update_if || p->update_source) {
14795 vty_out(vty, " Update source is ");
14796 if (p->update_if)
14797 vty_out(vty, "%s", p->update_if);
14798 else if (p->update_source)
47e12884 14799 vty_out(vty, "%pSU", p->update_source);
d62a17ae 14800 vty_out(vty, "\n");
14801 }
14802
14803 vty_out(vty, "\n");
14804 }
14805
14806 /* Address Family Information */
14807 json_object *json_hold = NULL;
14808
14809 if (use_json)
14810 json_hold = json_object_new_object();
14811
05c7a1cc
QY
14812 FOREACH_AFI_SAFI (afi, safi)
14813 if (p->afc[afi][safi])
14814 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14815 json_hold);
d62a17ae 14816
14817 if (use_json) {
14818 json_object_object_add(json_neigh, "addressFamilyInfo",
14819 json_hold);
14820 json_object_int_add(json_neigh, "connectionsEstablished",
14821 p->established);
14822 json_object_int_add(json_neigh, "connectionsDropped",
14823 p->dropped);
14824 } else
14825 vty_out(vty, " Connections established %d; dropped %d\n",
14826 p->established, p->dropped);
14827
14828 if (!p->last_reset) {
14829 if (use_json)
14830 json_object_string_add(json_neigh, "lastReset",
14831 "never");
14832 else
14833 vty_out(vty, " Last reset never\n");
14834 } else {
14835 if (use_json) {
14836 time_t uptime;
a2700b50 14837 struct tm tm;
d62a17ae 14838
083ec940 14839 uptime = monotime(NULL);
d62a17ae 14840 uptime -= p->resettime;
a2700b50
MS
14841 gmtime_r(&uptime, &tm);
14842
d62a17ae 14843 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
14844 (tm.tm_sec * 1000)
14845 + (tm.tm_min * 60000)
14846 + (tm.tm_hour * 3600000));
3577f1c5 14847 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 14848 } else {
14849 vty_out(vty, " Last reset %s, ",
14850 peer_uptime(p->resettime, timebuf,
14851 BGP_UPTIME_LEN, 0, NULL));
14852
3577f1c5 14853 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 14854 if (p->last_reset_cause_size) {
14855 msg = p->last_reset_cause;
14856 vty_out(vty,
14857 " Message received that caused BGP to send a NOTIFICATION:\n ");
14858 for (i = 1; i <= p->last_reset_cause_size;
14859 i++) {
14860 vty_out(vty, "%02X", *msg++);
14861
14862 if (i != p->last_reset_cause_size) {
14863 if (i % 16 == 0) {
14864 vty_out(vty, "\n ");
14865 } else if (i % 4 == 0) {
14866 vty_out(vty, " ");
14867 }
14868 }
14869 }
14870 vty_out(vty, "\n");
14871 }
14872 }
14873 }
14874
14875 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14876 if (use_json)
14877 json_object_boolean_true_add(json_neigh,
14878 "prefixesConfigExceedMax");
14879 else
14880 vty_out(vty,
14881 " Peer had exceeded the max. no. of prefixes configured.\n");
14882
14883 if (p->t_pmax_restart) {
14884 if (use_json) {
14885 json_object_boolean_true_add(
14886 json_neigh, "reducePrefixNumFrom");
14887 json_object_int_add(json_neigh,
14888 "restartInTimerMsec",
4f830a07
DS
14889 event_timer_remain_second(
14890 p->t_pmax_restart) *
14891 1000);
d62a17ae 14892 } else
14893 vty_out(vty,
14894 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
4f830a07
DS
14895 p->host,
14896 event_timer_remain_second(
14897 p->t_pmax_restart));
d62a17ae 14898 } else {
14899 if (use_json)
14900 json_object_boolean_true_add(
14901 json_neigh,
14902 "reducePrefixNumAndClearIpBgp");
14903 else
14904 vty_out(vty,
14905 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14906 p->host);
14907 }
14908 }
14909
14910 /* EBGP Multihop and GTSM */
14911 if (p->sort != BGP_PEER_IBGP) {
14912 if (use_json) {
e2521429 14913 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14914 json_object_int_add(json_neigh,
14915 "externalBgpNbrMaxHopsAway",
14916 p->gtsm_hops);
be8d1733 14917 else
d62a17ae 14918 json_object_int_add(json_neigh,
14919 "externalBgpNbrMaxHopsAway",
14920 p->ttl);
14921 } else {
e2521429 14922 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14923 vty_out(vty,
14924 " External BGP neighbor may be up to %d hops away.\n",
14925 p->gtsm_hops);
be8d1733 14926 else
d62a17ae 14927 vty_out(vty,
14928 " External BGP neighbor may be up to %d hops away.\n",
14929 p->ttl);
14930 }
14931 } else {
be8d1733
DA
14932 if (use_json) {
14933 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14934 json_object_int_add(json_neigh,
14935 "internalBgpNbrMaxHopsAway",
14936 p->gtsm_hops);
14937 else
be8d1733
DA
14938 json_object_int_add(json_neigh,
14939 "internalBgpNbrMaxHopsAway",
14940 p->ttl);
14941 } else {
14942 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14943 vty_out(vty,
14944 " Internal BGP neighbor may be up to %d hops away.\n",
14945 p->gtsm_hops);
be8d1733
DA
14946 else
14947 vty_out(vty,
14948 " Internal BGP neighbor may be up to %d hops away.\n",
14949 p->ttl);
d62a17ae 14950 }
14951 }
14952
14953 /* Local address. */
14954 if (p->su_local) {
14955 if (use_json) {
47e12884
DA
14956 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14957 p->su_local);
d62a17ae 14958 json_object_int_add(json_neigh, "portLocal",
14959 ntohs(p->su_local->sin.sin_port));
14960 } else
47e12884
DA
14961 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14962 p->su_local, ntohs(p->su_local->sin.sin_port));
1e592331
DS
14963 } else {
14964 if (use_json) {
14965 json_object_string_add(json_neigh, "hostLocal",
14966 "Unknown");
14967 json_object_int_add(json_neigh, "portLocal", -1);
14968 }
d62a17ae 14969 }
14970
14971 /* Remote address. */
14972 if (p->su_remote) {
14973 if (use_json) {
47e12884
DA
14974 json_object_string_addf(json_neigh, "hostForeign",
14975 "%pSU", p->su_remote);
d62a17ae 14976 json_object_int_add(json_neigh, "portForeign",
14977 ntohs(p->su_remote->sin.sin_port));
14978 } else
47e12884
DA
14979 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14980 p->su_remote,
d62a17ae 14981 ntohs(p->su_remote->sin.sin_port));
1e592331
DS
14982 } else {
14983 if (use_json) {
14984 json_object_string_add(json_neigh, "hostForeign",
14985 "Unknown");
14986 json_object_int_add(json_neigh, "portForeign", -1);
14987 }
d62a17ae 14988 }
14989
14990 /* Nexthop display. */
14991 if (p->su_local) {
14992 if (use_json) {
c949c771
DA
14993 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14994 &p->nexthop.v4);
14995 json_object_string_addf(json_neigh, "nexthopGlobal",
14996 "%pI6", &p->nexthop.v6_global);
14997 json_object_string_addf(json_neigh, "nexthopLocal",
14998 "%pI6", &p->nexthop.v6_local);
d62a17ae 14999 if (p->shared_network)
15000 json_object_string_add(json_neigh,
15001 "bgpConnection",
15002 "sharedNetwork");
15003 else
15004 json_object_string_add(json_neigh,
15005 "bgpConnection",
15006 "nonSharedNetwork");
15007 } else {
07380148
DA
15008 vty_out(vty, "Nexthop: %pI4\n", &p->nexthop.v4);
15009 vty_out(vty, "Nexthop global: %pI6\n",
15010 &p->nexthop.v6_global);
15011 vty_out(vty, "Nexthop local: %pI6\n",
15012 &p->nexthop.v6_local);
d62a17ae 15013 vty_out(vty, "BGP connection: %s\n",
15014 p->shared_network ? "shared network"
15015 : "non shared network");
15016 }
432e7e46
KQ
15017 } else {
15018 if (use_json) {
15019 json_object_string_add(json_neigh, "nexthop",
15020 "Unknown");
15021 json_object_string_add(json_neigh, "nexthopGlobal",
15022 "Unknown");
15023 json_object_string_add(json_neigh, "nexthopLocal",
15024 "Unknown");
15025 json_object_string_add(json_neigh, "bgpConnection",
15026 "Unknown");
15027 }
d62a17ae 15028 }
15029
15030 /* Timer information. */
15031 if (use_json) {
15032 json_object_int_add(json_neigh, "connectRetryTimer",
15033 p->v_connect);
f41255a0 15034 if (peer_established(p)) {
d62a17ae 15035 json_object_int_add(json_neigh, "estimatedRttInMsecs",
15036 p->rtt);
f41255a0
DA
15037 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) {
15038 json_object_int_add(json_neigh,
15039 "shutdownRttInMsecs",
15040 p->rtt_expected);
15041 json_object_int_add(json_neigh,
15042 "shutdownRttAfterCount",
15043 p->rtt_keepalive_rcv);
15044 }
15045 }
d62a17ae 15046 if (p->t_start)
15047 json_object_int_add(
15048 json_neigh, "nextStartTimerDueInMsecs",
4f830a07 15049 event_timer_remain_second(p->t_start) * 1000);
d62a17ae 15050 if (p->t_connect)
15051 json_object_int_add(
15052 json_neigh, "nextConnectTimerDueInMsecs",
4f830a07 15053 event_timer_remain_second(p->t_connect) * 1000);
d62a17ae 15054 if (p->t_routeadv) {
15055 json_object_int_add(json_neigh, "mraiInterval",
15056 p->v_routeadv);
15057 json_object_int_add(
15058 json_neigh, "mraiTimerExpireInMsecs",
4f830a07
DS
15059 event_timer_remain_second(p->t_routeadv) *
15060 1000);
d62a17ae 15061 }
15062 if (p->password)
15063 json_object_int_add(json_neigh, "authenticationEnabled",
15064 1);
15065
15066 if (p->t_read)
15067 json_object_string_add(json_neigh, "readThread", "on");
15068 else
15069 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
15070
15071 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 15072 json_object_string_add(json_neigh, "writeThread", "on");
15073 else
15074 json_object_string_add(json_neigh, "writeThread",
15075 "off");
15076 } else {
15077 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
15078 p->v_connect);
f41255a0 15079 if (peer_established(p)) {
d62a17ae 15080 vty_out(vty, "Estimated round trip time: %d ms\n",
15081 p->rtt);
f41255a0
DA
15082 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN))
15083 vty_out(vty,
15084 "Shutdown when RTT > %dms, count > %u\n",
15085 p->rtt_expected, p->rtt_keepalive_rcv);
15086 }
d62a17ae 15087 if (p->t_start)
15088 vty_out(vty, "Next start timer due in %ld seconds\n",
4f830a07 15089 event_timer_remain_second(p->t_start));
d62a17ae 15090 if (p->t_connect)
15091 vty_out(vty, "Next connect timer due in %ld seconds\n",
4f830a07 15092 event_timer_remain_second(p->t_connect));
d62a17ae 15093 if (p->t_routeadv)
15094 vty_out(vty,
15095 "MRAI (interval %u) timer expires in %ld seconds\n",
15096 p->v_routeadv,
4f830a07 15097 event_timer_remain_second(p->t_routeadv));
d62a17ae 15098 if (p->password)
15099 vty_out(vty, "Peer Authentication Enabled\n");
15100
cac9e917 15101 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
15102 p->t_read ? "on" : "off",
15103 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
15104 ? "on"
cac9e917 15105 : "off", p->fd);
d62a17ae 15106 }
15107
15108 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
15109 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
15110 bgp_capability_vty_out(vty, p, use_json, json_neigh);
15111
15112 if (!use_json)
15113 vty_out(vty, "\n");
15114
15115 /* BFD information. */
21bfce98
RZ
15116 if (p->bfd_config)
15117 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 15118
15119 if (use_json) {
15120 if (p->conf_if) /* Configured interface name. */
15121 json_object_object_add(json, p->conf_if, json_neigh);
15122 else /* Configured IP address. */
15123 json_object_object_add(json, p->host, json_neigh);
15124 }
15125}
15126
36235319
QY
15127static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
15128 enum show_type type,
15129 union sockunion *su,
15130 const char *conf_if, afi_t afi,
403e64f8 15131 json_object *json)
2986cac2 15132{
15133 struct listnode *node, *nnode;
15134 struct peer *peer;
5a59e9b2 15135 bool found = false;
2986cac2 15136 safi_t safi = SAFI_UNICAST;
15137 json_object *json_neighbor = NULL;
15138
15139 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15140
15141 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15142 continue;
15143
15144 if ((peer->afc[afi][safi]) == 0)
15145 continue;
15146
403e64f8
DA
15147 if (json)
15148 json_neighbor = json_object_new_object();
15149
2ba1fe69 15150 if (type == show_all) {
403e64f8 15151 bgp_show_peer_gr_status(vty, peer, json_neighbor);
2986cac2 15152
403e64f8 15153 if (json)
13909c4f
DS
15154 json_object_object_add(json, peer->host,
15155 json_neighbor);
2986cac2 15156
2ba1fe69 15157 } else if (type == show_peer) {
2986cac2 15158 if (conf_if) {
15159 if ((peer->conf_if
13909c4f
DS
15160 && !strcmp(peer->conf_if, conf_if))
15161 || (peer->hostname
2986cac2 15162 && !strcmp(peer->hostname, conf_if))) {
5a59e9b2 15163 found = true;
13909c4f 15164 bgp_show_peer_gr_status(vty, peer,
13909c4f 15165 json_neighbor);
2986cac2 15166 }
15167 } else {
15168 if (sockunion_same(&peer->su, su)) {
5a59e9b2 15169 found = true;
13909c4f 15170 bgp_show_peer_gr_status(vty, peer,
13909c4f 15171 json_neighbor);
2986cac2 15172 }
15173 }
5a59e9b2
DS
15174 if (json) {
15175 if (found)
15176 json_object_object_add(json, peer->host,
15177 json_neighbor);
15178 else
15179 json_object_free(json_neighbor);
15180 }
2986cac2 15181 }
15182
5a59e9b2 15183 if (found)
2986cac2 15184 break;
15185 }
15186
5a59e9b2 15187 if (type == show_peer && !found) {
403e64f8 15188 if (json)
13909c4f 15189 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 15190 else
15191 vty_out(vty, "%% No such neighbor\n");
15192 }
403e64f8
DA
15193
15194 if (!json)
2986cac2 15195 vty_out(vty, "\n");
2986cac2 15196
15197 return CMD_SUCCESS;
15198}
15199
d62a17ae 15200static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
15201 enum show_type type, union sockunion *su,
9f049418 15202 const char *conf_if, bool use_json,
d62a17ae 15203 json_object *json)
15204{
15205 struct listnode *node, *nnode;
15206 struct peer *peer;
15207 int find = 0;
9f049418 15208 bool nbr_output = false;
d1927ebe
AS
15209 afi_t afi = AFI_MAX;
15210 safi_t safi = SAFI_MAX;
15211
15212 if (type == show_ipv4_peer || type == show_ipv4_all) {
15213 afi = AFI_IP;
15214 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
15215 afi = AFI_IP6;
15216 }
d62a17ae 15217
15218 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15219 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15220 continue;
15221
15222 switch (type) {
15223 case show_all:
15224 bgp_show_peer(vty, peer, use_json, json);
9f049418 15225 nbr_output = true;
d62a17ae 15226 break;
15227 case show_peer:
15228 if (conf_if) {
15229 if ((peer->conf_if
15230 && !strcmp(peer->conf_if, conf_if))
15231 || (peer->hostname
15232 && !strcmp(peer->hostname, conf_if))) {
15233 find = 1;
15234 bgp_show_peer(vty, peer, use_json,
15235 json);
15236 }
15237 } else {
15238 if (sockunion_same(&peer->su, su)) {
15239 find = 1;
15240 bgp_show_peer(vty, peer, use_json,
15241 json);
15242 }
15243 }
15244 break;
d1927ebe
AS
15245 case show_ipv4_peer:
15246 case show_ipv6_peer:
15247 FOREACH_SAFI (safi) {
15248 if (peer->afc[afi][safi]) {
15249 if (conf_if) {
15250 if ((peer->conf_if
15251 && !strcmp(peer->conf_if, conf_if))
15252 || (peer->hostname
15253 && !strcmp(peer->hostname, conf_if))) {
15254 find = 1;
15255 bgp_show_peer(vty, peer, use_json,
15256 json);
15257 break;
15258 }
15259 } else {
15260 if (sockunion_same(&peer->su, su)) {
15261 find = 1;
15262 bgp_show_peer(vty, peer, use_json,
15263 json);
15264 break;
15265 }
15266 }
15267 }
15268 }
15269 break;
15270 case show_ipv4_all:
15271 case show_ipv6_all:
15272 FOREACH_SAFI (safi) {
15273 if (peer->afc[afi][safi]) {
15274 bgp_show_peer(vty, peer, use_json, json);
15275 nbr_output = true;
15276 break;
15277 }
15278 }
15279 break;
d62a17ae 15280 }
15281 }
15282
d1927ebe
AS
15283 if ((type == show_peer || type == show_ipv4_peer ||
15284 type == show_ipv6_peer) && !find) {
d62a17ae 15285 if (use_json)
15286 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
15287 else
88b7d255 15288 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 15289 }
15290
d1927ebe
AS
15291 if (type != show_peer && type != show_ipv4_peer &&
15292 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 15293 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 15294
d62a17ae 15295 if (use_json) {
996c9314
LB
15296 vty_out(vty, "%s\n", json_object_to_json_string_ext(
15297 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 15298 } else {
15299 vty_out(vty, "\n");
15300 }
15301
15302 return CMD_SUCCESS;
15303}
15304
36235319
QY
15305static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
15306 enum show_type type,
15307 const char *ip_str,
403e64f8 15308 afi_t afi, json_object *json)
2986cac2 15309{
15310
15311 int ret;
15312 struct bgp *bgp;
15313 union sockunion su;
2986cac2 15314
15315 bgp = bgp_get_default();
15316
13909c4f
DS
15317 if (!bgp)
15318 return;
2986cac2 15319
403e64f8
DA
15320 if (!json)
15321 bgp_show_global_graceful_restart_mode_vty(vty, bgp);
2986cac2 15322
13909c4f
DS
15323 if (ip_str) {
15324 ret = str2sockunion(ip_str, &su);
15325 if (ret < 0)
403e64f8
DA
15326 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
15327 ip_str, afi, json);
74a630b6
NT
15328 else
15329 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
403e64f8 15330 NULL, afi, json);
13909c4f
DS
15331 } else
15332 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
403e64f8 15333 afi, json);
2986cac2 15334}
15335
d62a17ae 15336static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
15337 enum show_type type,
15338 const char *ip_str,
9f049418 15339 bool use_json)
d62a17ae 15340{
0291c246
MK
15341 struct listnode *node, *nnode;
15342 struct bgp *bgp;
71aedaa3 15343 union sockunion su;
0291c246 15344 json_object *json = NULL;
71aedaa3 15345 int ret, is_first = 1;
9f049418 15346 bool nbr_output = false;
d62a17ae 15347
15348 if (use_json)
15349 vty_out(vty, "{\n");
15350
15351 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 15352 nbr_output = true;
d62a17ae 15353 if (use_json) {
15354 if (!(json = json_object_new_object())) {
af4c2728 15355 flog_err(
e50f7cfd 15356 EC_BGP_JSON_MEM_ERROR,
d62a17ae 15357 "Unable to allocate memory for JSON object");
15358 vty_out(vty,
15359 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
15360 return;
15361 }
15362
15363 json_object_int_add(json, "vrfId",
15364 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
15365 ? -1
15366 : (int64_t)bgp->vrf_id);
d62a17ae 15367 json_object_string_add(
15368 json, "vrfName",
15369 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15370 ? VRF_DEFAULT_NAME
d62a17ae 15371 : bgp->name);
15372
15373 if (!is_first)
15374 vty_out(vty, ",\n");
15375 else
15376 is_first = 0;
15377
15378 vty_out(vty, "\"%s\":",
15379 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15380 ? VRF_DEFAULT_NAME
d62a17ae 15381 : bgp->name);
15382 } else {
15383 vty_out(vty, "\nInstance %s:\n",
15384 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15385 ? VRF_DEFAULT_NAME
d62a17ae 15386 : bgp->name);
15387 }
71aedaa3 15388
d1927ebe
AS
15389 if (type == show_peer || type == show_ipv4_peer ||
15390 type == show_ipv6_peer) {
71aedaa3
DS
15391 ret = str2sockunion(ip_str, &su);
15392 if (ret < 0)
15393 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15394 use_json, json);
15395 else
15396 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15397 use_json, json);
15398 } else {
d1927ebe 15399 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
15400 use_json, json);
15401 }
b77004d6 15402 json_object_free(json);
121067e9 15403 json = NULL;
d62a17ae 15404 }
15405
3e78a6ce 15406 if (use_json)
d62a17ae 15407 vty_out(vty, "}\n");
9f049418
DS
15408 else if (!nbr_output)
15409 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 15410}
15411
15412static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
15413 enum show_type type, const char *ip_str,
9f049418 15414 bool use_json)
d62a17ae 15415{
15416 int ret;
15417 struct bgp *bgp;
15418 union sockunion su;
15419 json_object *json = NULL;
15420
15421 if (name) {
15422 if (strmatch(name, "all")) {
71aedaa3
DS
15423 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
15424 use_json);
d62a17ae 15425 return CMD_SUCCESS;
15426 } else {
15427 bgp = bgp_lookup_by_name(name);
15428 if (!bgp) {
15429 if (use_json) {
15430 json = json_object_new_object();
75eeda93 15431 vty_json(vty, json);
d62a17ae 15432 } else
15433 vty_out(vty,
9f049418 15434 "%% BGP instance not found\n");
d62a17ae 15435
15436 return CMD_WARNING;
15437 }
15438 }
15439 } else {
15440 bgp = bgp_get_default();
15441 }
15442
15443 if (bgp) {
15444 json = json_object_new_object();
15445 if (ip_str) {
15446 ret = str2sockunion(ip_str, &su);
15447 if (ret < 0)
15448 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15449 use_json, json);
15450 else
15451 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15452 use_json, json);
15453 } else {
15454 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15455 json);
15456 }
15457 json_object_free(json);
ca61fd25
DS
15458 } else {
15459 if (use_json)
15460 vty_out(vty, "{}\n");
15461 else
15462 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 15463 }
15464
15465 return CMD_SUCCESS;
4fb25c53
DW
15466}
15467
2986cac2 15468
15469
15470/* "show [ip] bgp neighbors graceful-restart" commands. */
dcab9012 15471DEFUN (show_ip_bgp_neighbors_graceful_restart,
2986cac2 15472 show_ip_bgp_neighbors_graceful_restart_cmd,
15473 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15474 SHOW_STR
15475 BGP_STR
15476 IP_STR
15477 IPV6_STR
15478 NEIGHBOR_STR
15479 "Neighbor to display information about\n"
15480 "Neighbor to display information about\n"
15481 "Neighbor on BGP configured interface\n"
15482 GR_SHOW
15483 JSON_STR)
15484{
15485 char *sh_arg = NULL;
15486 enum show_type sh_type;
15487 int idx = 0;
15488 afi_t afi = AFI_MAX;
2986cac2 15489 bool uj = use_json(argc, argv);
15490
36235319 15491 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 15492 afi = AFI_MAX;
15493
15494 idx++;
15495
15496 if (argv_find(argv, argc, "A.B.C.D", &idx)
15497 || argv_find(argv, argc, "X:X::X:X", &idx)
15498 || argv_find(argv, argc, "WORD", &idx)) {
15499 sh_type = show_peer;
15500 sh_arg = argv[idx]->arg;
15501 } else
15502 sh_type = show_all;
15503
15504 if (!argv_find(argv, argc, "graceful-restart", &idx))
15505 return CMD_SUCCESS;
15506
15507
36235319
QY
15508 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15509 afi, uj);
2986cac2 15510}
15511
716b2d8a 15512/* "show [ip] bgp neighbors" commands. */
718e3744 15513DEFUN (show_ip_bgp_neighbors,
15514 show_ip_bgp_neighbors_cmd,
24345e82 15515 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 15516 SHOW_STR
15517 IP_STR
15518 BGP_STR
f2a8972b 15519 BGP_INSTANCE_HELP_STR
00e6edb9
DA
15520 BGP_AF_STR
15521 BGP_AF_STR
718e3744 15522 "Detailed information on TCP and BGP neighbor connections\n"
15523 "Neighbor to display information about\n"
a80beece 15524 "Neighbor to display information about\n"
91d37724 15525 "Neighbor on BGP configured interface\n"
9973d184 15526 JSON_STR)
718e3744 15527{
d62a17ae 15528 char *vrf = NULL;
15529 char *sh_arg = NULL;
15530 enum show_type sh_type;
d1927ebe 15531 afi_t afi = AFI_MAX;
718e3744 15532
9f049418 15533 bool uj = use_json(argc, argv);
718e3744 15534
d62a17ae 15535 int idx = 0;
718e3744 15536
9a8bdf1c
PG
15537 /* [<vrf> VIEWVRFNAME] */
15538 if (argv_find(argv, argc, "vrf", &idx)) {
15539 vrf = argv[idx + 1]->arg;
15540 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15541 vrf = NULL;
15542 } else if (argv_find(argv, argc, "view", &idx))
15543 /* [<view> VIEWVRFNAME] */
d62a17ae 15544 vrf = argv[idx + 1]->arg;
718e3744 15545
d62a17ae 15546 idx++;
d1927ebe
AS
15547
15548 if (argv_find(argv, argc, "ipv4", &idx)) {
15549 sh_type = show_ipv4_all;
15550 afi = AFI_IP;
15551 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15552 sh_type = show_ipv6_all;
15553 afi = AFI_IP6;
15554 } else {
15555 sh_type = show_all;
15556 }
15557
d62a17ae 15558 if (argv_find(argv, argc, "A.B.C.D", &idx)
15559 || argv_find(argv, argc, "X:X::X:X", &idx)
15560 || argv_find(argv, argc, "WORD", &idx)) {
15561 sh_type = show_peer;
15562 sh_arg = argv[idx]->arg;
d1927ebe
AS
15563 }
15564
15565 if (sh_type == show_peer && afi == AFI_IP) {
15566 sh_type = show_ipv4_peer;
15567 } else if (sh_type == show_peer && afi == AFI_IP6) {
15568 sh_type = show_ipv6_peer;
15569 }
856ca177 15570
d62a17ae 15571 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 15572}
15573
716b2d8a 15574/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 15575 paths' and `show ip mbgp paths'. Those functions results are the
15576 same.*/
f412b39a 15577DEFUN (show_ip_bgp_paths,
718e3744 15578 show_ip_bgp_paths_cmd,
46f296b4 15579 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 15580 SHOW_STR
15581 IP_STR
15582 BGP_STR
46f296b4 15583 BGP_SAFI_HELP_STR
718e3744 15584 "Path information\n")
15585{
d62a17ae 15586 vty_out(vty, "Address Refcnt Path\n");
15587 aspath_print_all_vty(vty);
15588 return CMD_SUCCESS;
718e3744 15589}
15590
718e3744 15591#include "hash.h"
15592
e3b78da8 15593static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15594 struct vty *vty)
718e3744 15595{
d62a17ae 15596 struct community *com;
718e3744 15597
e3b78da8 15598 com = (struct community *)bucket->data;
3f65c5b1 15599 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
c0945b78 15600 community_str(com, false, false));
718e3744 15601}
15602
15603/* Show BGP's community internal data. */
f412b39a 15604DEFUN (show_ip_bgp_community_info,
718e3744 15605 show_ip_bgp_community_info_cmd,
bec37ba5 15606 "show [ip] bgp community-info",
718e3744 15607 SHOW_STR
15608 IP_STR
15609 BGP_STR
15610 "List all bgp community information\n")
15611{
d62a17ae 15612 vty_out(vty, "Address Refcnt Community\n");
718e3744 15613
d62a17ae 15614 hash_iterate(community_hash(),
e3b78da8 15615 (void (*)(struct hash_bucket *,
d62a17ae 15616 void *))community_show_all_iterator,
15617 vty);
718e3744 15618
d62a17ae 15619 return CMD_SUCCESS;
718e3744 15620}
15621
e3b78da8 15622static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15623 struct vty *vty)
57d187bc 15624{
d62a17ae 15625 struct lcommunity *lcom;
57d187bc 15626
e3b78da8 15627 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 15628 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
c0945b78 15629 lcommunity_str(lcom, false, false));
57d187bc
JS
15630}
15631
15632/* Show BGP's community internal data. */
15633DEFUN (show_ip_bgp_lcommunity_info,
15634 show_ip_bgp_lcommunity_info_cmd,
15635 "show ip bgp large-community-info",
15636 SHOW_STR
15637 IP_STR
15638 BGP_STR
15639 "List all bgp large-community information\n")
15640{
d62a17ae 15641 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 15642
d62a17ae 15643 hash_iterate(lcommunity_hash(),
e3b78da8 15644 (void (*)(struct hash_bucket *,
d62a17ae 15645 void *))lcommunity_show_all_iterator,
15646 vty);
57d187bc 15647
d62a17ae 15648 return CMD_SUCCESS;
57d187bc 15649}
2986cac2 15650/* Graceful Restart */
15651
15652static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
403e64f8 15653 struct bgp *bgp)
2986cac2 15654{
57d187bc
JS
15655
15656
2986cac2 15657 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15658
7318ae88 15659 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 15660
15661 switch (bgp_global_gr_mode) {
15662
15663 case GLOBAL_HELPER:
13909c4f 15664 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 15665 break;
15666
15667 case GLOBAL_GR:
13909c4f 15668 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 15669 break;
15670
15671 case GLOBAL_DISABLE:
13909c4f 15672 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 15673 break;
15674
15675 case GLOBAL_INVALID:
2986cac2 15676 vty_out(vty,
2ba1fe69 15677 "Global BGP GR Mode Invalid\n");
2986cac2 15678 break;
15679 }
15680 vty_out(vty, "\n");
15681}
15682
36235319
QY
15683static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15684 enum show_type type,
15685 const char *ip_str,
15686 afi_t afi, bool use_json)
2986cac2 15687{
403e64f8
DA
15688 json_object *json = NULL;
15689
15690 if (use_json)
15691 json = json_object_new_object();
15692
2986cac2 15693 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15694 afi = AFI_IP;
15695
15696 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15697
36235319 15698 bgp_show_neighbor_graceful_restart_vty(
403e64f8 15699 vty, type, ip_str, afi, json);
2986cac2 15700 afi++;
15701 }
15702 } else if (afi != AFI_MAX) {
36235319 15703 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
403e64f8 15704 json);
2986cac2 15705 } else {
403e64f8
DA
15706 if (json)
15707 json_object_free(json);
2986cac2 15708 return CMD_ERR_INCOMPLETE;
15709 }
15710
403e64f8
DA
15711 if (json)
15712 vty_json(vty, json);
15713
2986cac2 15714 return CMD_SUCCESS;
15715}
15716/* Graceful Restart */
15717
f412b39a 15718DEFUN (show_ip_bgp_attr_info,
718e3744 15719 show_ip_bgp_attr_info_cmd,
bec37ba5 15720 "show [ip] bgp attribute-info",
718e3744 15721 SHOW_STR
15722 IP_STR
15723 BGP_STR
15724 "List all bgp attribute information\n")
15725{
d62a17ae 15726 attr_show_all(vty);
15727 return CMD_SUCCESS;
718e3744 15728}
6b0655a2 15729
03915806
CS
15730static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15731 afi_t afi, safi_t safi,
15732 bool use_json, json_object *json)
53089bec 15733{
15734 struct bgp *bgp;
15735 struct listnode *node;
15736 char *vname;
53089bec 15737 char *ecom_str;
9c2fd3fe 15738 enum vpn_policy_direction dir;
53089bec 15739
03915806 15740 if (json) {
b46dfd20
DS
15741 json_object *json_import_vrfs = NULL;
15742 json_object *json_export_vrfs = NULL;
15743
b46dfd20
DS
15744 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15745
53089bec 15746 if (!bgp) {
75eeda93 15747 vty_json(vty, json);
b46dfd20 15748
53089bec 15749 return CMD_WARNING;
15750 }
b46dfd20 15751
94d4c685
DS
15752 /* Provide context for the block */
15753 json_object_string_add(json, "vrf", name ? name : "default");
15754 json_object_string_add(json, "afiSafi",
5cb5f4d0 15755 get_afi_safi_str(afi, safi, true));
94d4c685 15756
b46dfd20
DS
15757 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15758 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15759 json_object_string_add(json, "importFromVrfs", "none");
15760 json_object_string_add(json, "importRts", "none");
15761 } else {
6ce24e52
DS
15762 json_import_vrfs = json_object_new_array();
15763
b46dfd20
DS
15764 for (ALL_LIST_ELEMENTS_RO(
15765 bgp->vpn_policy[afi].import_vrf,
15766 node, vname))
15767 json_object_array_add(json_import_vrfs,
15768 json_object_new_string(vname));
15769
b20875ea
CS
15770 json_object_object_add(json, "importFromVrfs",
15771 json_import_vrfs);
b46dfd20 15772 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15773 if (bgp->vpn_policy[afi].rtlist[dir]) {
15774 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15775 bgp->vpn_policy[afi].rtlist[dir],
15776 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15777 json_object_string_add(json, "importRts",
15778 ecom_str);
15779 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15780 } else
15781 json_object_string_add(json, "importRts",
15782 "none");
b46dfd20
DS
15783 }
15784
15785 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15786 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15787 json_object_string_add(json, "exportToVrfs", "none");
15788 json_object_string_add(json, "routeDistinguisher",
15789 "none");
15790 json_object_string_add(json, "exportRts", "none");
15791 } else {
6ce24e52
DS
15792 json_export_vrfs = json_object_new_array();
15793
b46dfd20
DS
15794 for (ALL_LIST_ELEMENTS_RO(
15795 bgp->vpn_policy[afi].export_vrf,
15796 node, vname))
15797 json_object_array_add(json_export_vrfs,
15798 json_object_new_string(vname));
15799 json_object_object_add(json, "exportToVrfs",
15800 json_export_vrfs);
fa566a94
PG
15801 json_object_string_addf(
15802 json, "routeDistinguisher", "%s",
15803 bgp->vpn_policy[afi].tovpn_rd_pretty);
b46dfd20 15804 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15805 if (bgp->vpn_policy[afi].rtlist[dir]) {
15806 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15807 bgp->vpn_policy[afi].rtlist[dir],
15808 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15809 json_object_string_add(json, "exportRts",
15810 ecom_str);
15811 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15812 } else
15813 json_object_string_add(json, "exportRts",
15814 "none");
b46dfd20
DS
15815 }
15816
03915806 15817 if (use_json) {
75eeda93 15818 vty_json(vty, json);
03915806 15819 }
53089bec 15820 } else {
b46dfd20
DS
15821 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15822
53089bec 15823 if (!bgp) {
b46dfd20 15824 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 15825 return CMD_WARNING;
15826 }
53089bec 15827
b46dfd20
DS
15828 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15829 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15830 vty_out(vty,
15831 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 15832 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15833 else {
15834 vty_out(vty,
15835 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 15836 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15837
15838 for (ALL_LIST_ELEMENTS_RO(
15839 bgp->vpn_policy[afi].import_vrf,
15840 node, vname))
15841 vty_out(vty, " %s\n", vname);
15842
15843 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15844 ecom_str = NULL;
15845 if (bgp->vpn_policy[afi].rtlist[dir]) {
15846 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15847 bgp->vpn_policy[afi].rtlist[dir],
15848 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 15849 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 15850
b20875ea
CS
15851 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15852 } else
15853 vty_out(vty, "Import RT(s):\n");
53089bec 15854 }
53089bec 15855
b46dfd20
DS
15856 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15857 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15858 vty_out(vty,
15859 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 15860 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15861 else {
15862 vty_out(vty,
04c9077f 15863 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 15864 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15865
15866 for (ALL_LIST_ELEMENTS_RO(
15867 bgp->vpn_policy[afi].export_vrf,
15868 node, vname))
15869 vty_out(vty, " %s\n", vname);
15870
4a8cd6ad
PG
15871 vty_out(vty, "RD: ");
15872 vty_out(vty, BGP_RD_AS_FORMAT(bgp->asnotation),
c4f64ea9 15873 &bgp->vpn_policy[afi].tovpn_rd);
4a8cd6ad 15874 vty_out(vty, "\n");
b46dfd20
DS
15875
15876 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15877 if (bgp->vpn_policy[afi].rtlist[dir]) {
15878 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15879 bgp->vpn_policy[afi].rtlist[dir],
15880 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15881 vty_out(vty, "Export RT: %s\n", ecom_str);
15882 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15883 } else
15884 vty_out(vty, "Import RT(s):\n");
53089bec 15885 }
53089bec 15886 }
15887
15888 return CMD_SUCCESS;
15889}
15890
03915806
CS
15891static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15892 safi_t safi, bool use_json)
15893{
15894 struct listnode *node, *nnode;
15895 struct bgp *bgp;
15896 char *vrf_name = NULL;
15897 json_object *json = NULL;
15898 json_object *json_vrf = NULL;
15899 json_object *json_vrfs = NULL;
15900
15901 if (use_json) {
15902 json = json_object_new_object();
15903 json_vrfs = json_object_new_object();
15904 }
15905
15906 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15907
15908 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15909 vrf_name = bgp->name;
15910
15911 if (use_json) {
15912 json_vrf = json_object_new_object();
15913 } else {
15914 vty_out(vty, "\nInstance %s:\n",
15915 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15916 ? VRF_DEFAULT_NAME : bgp->name);
15917 }
15918 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15919 if (use_json) {
15920 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15921 json_object_object_add(json_vrfs,
15922 VRF_DEFAULT_NAME, json_vrf);
15923 else
15924 json_object_object_add(json_vrfs, vrf_name,
15925 json_vrf);
15926 }
15927 }
15928
15929 if (use_json) {
15930 json_object_object_add(json, "vrfs", json_vrfs);
75eeda93 15931 vty_json(vty, json);
03915806
CS
15932 }
15933
15934 return CMD_SUCCESS;
15935}
15936
53089bec 15937/* "show [ip] bgp route-leak" command. */
15938DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
15939 show_ip_bgp_route_leak_cmd,
15940 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
15941 SHOW_STR
15942 IP_STR
15943 BGP_STR
15944 BGP_INSTANCE_HELP_STR
15945 BGP_AFI_HELP_STR
15946 BGP_SAFI_HELP_STR
15947 "Route leaking information\n"
15948 JSON_STR)
53089bec 15949{
15950 char *vrf = NULL;
15951 afi_t afi = AFI_MAX;
15952 safi_t safi = SAFI_MAX;
15953
9f049418 15954 bool uj = use_json(argc, argv);
53089bec 15955 int idx = 0;
03915806 15956 json_object *json = NULL;
53089bec 15957
15958 /* show [ip] bgp */
15959 if (argv_find(argv, argc, "ip", &idx)) {
15960 afi = AFI_IP;
15961 safi = SAFI_UNICAST;
15962 }
15963 /* [vrf VIEWVRFNAME] */
15964 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
15965 vty_out(vty,
15966 "%% This command is not applicable to BGP views\n");
53089bec 15967 return CMD_WARNING;
15968 }
15969
9a8bdf1c
PG
15970 if (argv_find(argv, argc, "vrf", &idx)) {
15971 vrf = argv[idx + 1]->arg;
15972 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15973 vrf = NULL;
15974 }
53089bec 15975 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
c48349e3 15976 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
53089bec 15977 argv_find_and_parse_safi(argv, argc, &idx, &safi);
53089bec 15978
15979 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
15980 vty_out(vty,
15981 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 15982 return CMD_WARNING;
15983 }
15984
03915806
CS
15985 if (vrf && strmatch(vrf, "all"))
15986 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15987
15988 if (uj)
15989 json = json_object_new_object();
15990
15991 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 15992}
15993
d62a17ae 15994static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
fa5a9276 15995 safi_t safi, bool uj)
f186de26 15996{
d62a17ae 15997 struct listnode *node, *nnode;
15998 struct bgp *bgp;
f186de26 15999
d62a17ae 16000 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
fa5a9276
AR
16001 if (!uj)
16002 vty_out(vty, "\nInstance %s:\n",
16003 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
16004 ? VRF_DEFAULT_NAME
16005 : bgp->name);
16006
16007 update_group_show(bgp, afi, safi, vty, 0, uj);
d62a17ae 16008 }
f186de26 16009}
16010
d62a17ae 16011static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
fa5a9276 16012 int safi, uint64_t subgrp_id, bool uj)
4fb25c53 16013{
d62a17ae 16014 struct bgp *bgp;
4fb25c53 16015
d62a17ae 16016 if (name) {
16017 if (strmatch(name, "all")) {
fa5a9276 16018 bgp_show_all_instances_updgrps_vty(vty, afi, safi, uj);
d62a17ae 16019 return CMD_SUCCESS;
16020 } else {
16021 bgp = bgp_lookup_by_name(name);
16022 }
16023 } else {
16024 bgp = bgp_get_default();
16025 }
4fb25c53 16026
d62a17ae 16027 if (bgp)
fa5a9276 16028 update_group_show(bgp, afi, safi, vty, subgrp_id, uj);
d62a17ae 16029 return CMD_SUCCESS;
4fb25c53
DW
16030}
16031
8fe8a7f6
DS
16032DEFUN (show_ip_bgp_updgrps,
16033 show_ip_bgp_updgrps_cmd,
fa5a9276 16034 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID] [json]",
8386ac43 16035 SHOW_STR
16036 IP_STR
16037 BGP_STR
16038 BGP_INSTANCE_HELP_STR
c9e571b4 16039 BGP_AFI_HELP_STR
9bedbb1e 16040 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956 16041 "Detailed info about dynamic update groups\n"
fa5a9276
AR
16042 "Specific subgroup to display detailed info for\n"
16043 JSON_STR)
8386ac43 16044{
d62a17ae 16045 char *vrf = NULL;
16046 afi_t afi = AFI_IP6;
16047 safi_t safi = SAFI_UNICAST;
16048 uint64_t subgrp_id = 0;
16049
16050 int idx = 0;
16051
fa5a9276
AR
16052 bool uj = use_json(argc, argv);
16053
d62a17ae 16054 /* show [ip] bgp */
16055 if (argv_find(argv, argc, "ip", &idx))
16056 afi = AFI_IP;
9a8bdf1c
PG
16057 /* [<vrf> VIEWVRFNAME] */
16058 if (argv_find(argv, argc, "vrf", &idx)) {
16059 vrf = argv[idx + 1]->arg;
16060 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
16061 vrf = NULL;
16062 } else if (argv_find(argv, argc, "view", &idx))
16063 /* [<view> VIEWVRFNAME] */
16064 vrf = argv[idx + 1]->arg;
d62a17ae 16065 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
16066 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
16067 argv_find_and_parse_safi(argv, argc, &idx, &safi);
16068 }
5bf15956 16069
d62a17ae 16070 /* get subgroup id, if provided */
16071 idx = argc - 1;
16072 if (argv[idx]->type == VARIABLE_TKN)
16073 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 16074
fa5a9276 16075 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id, uj));
8fe8a7f6
DS
16076}
16077
f186de26 16078DEFUN (show_bgp_instance_all_ipv6_updgrps,
16079 show_bgp_instance_all_ipv6_updgrps_cmd,
fa5a9276 16080 "show [ip] bgp <view|vrf> all update-groups [json]",
f186de26 16081 SHOW_STR
716b2d8a 16082 IP_STR
f186de26 16083 BGP_STR
16084 BGP_INSTANCE_ALL_HELP_STR
fa5a9276
AR
16085 "Detailed info about dynamic update groups\n"
16086 JSON_STR)
f186de26 16087{
fa5a9276
AR
16088 bool uj = use_json(argc, argv);
16089
16090 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST, uj);
d62a17ae 16091 return CMD_SUCCESS;
f186de26 16092}
16093
43d3f4fc
DS
16094DEFUN (show_bgp_l2vpn_evpn_updgrps,
16095 show_bgp_l2vpn_evpn_updgrps_cmd,
16096 "show [ip] bgp l2vpn evpn update-groups",
16097 SHOW_STR
16098 IP_STR
16099 BGP_STR
16100 "l2vpn address family\n"
16101 "evpn sub-address family\n"
16102 "Detailed info about dynamic update groups\n")
16103{
16104 char *vrf = NULL;
16105 uint64_t subgrp_id = 0;
16106
fa5a9276 16107 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id, 0);
43d3f4fc
DS
16108 return CMD_SUCCESS;
16109}
16110
5bf15956
DW
16111DEFUN (show_bgp_updgrps_stats,
16112 show_bgp_updgrps_stats_cmd,
716b2d8a 16113 "show [ip] bgp update-groups statistics",
3f9c7369 16114 SHOW_STR
716b2d8a 16115 IP_STR
3f9c7369 16116 BGP_STR
0c7b1b01 16117 "Detailed info about dynamic update groups\n"
3f9c7369
DS
16118 "Statistics\n")
16119{
d62a17ae 16120 struct bgp *bgp;
3f9c7369 16121
d62a17ae 16122 bgp = bgp_get_default();
16123 if (bgp)
16124 update_group_show_stats(bgp, vty);
3f9c7369 16125
d62a17ae 16126 return CMD_SUCCESS;
3f9c7369
DS
16127}
16128
8386ac43 16129DEFUN (show_bgp_instance_updgrps_stats,
16130 show_bgp_instance_updgrps_stats_cmd,
18c57037 16131 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 16132 SHOW_STR
716b2d8a 16133 IP_STR
8386ac43 16134 BGP_STR
16135 BGP_INSTANCE_HELP_STR
0c7b1b01 16136 "Detailed info about dynamic update groups\n"
8386ac43 16137 "Statistics\n")
16138{
d62a17ae 16139 int idx_word = 3;
16140 struct bgp *bgp;
8386ac43 16141
d62a17ae 16142 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
16143 if (bgp)
16144 update_group_show_stats(bgp, vty);
8386ac43 16145
d62a17ae 16146 return CMD_SUCCESS;
8386ac43 16147}
16148
d62a17ae 16149static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
16150 afi_t afi, safi_t safi,
16151 const char *what, uint64_t subgrp_id)
3f9c7369 16152{
d62a17ae 16153 struct bgp *bgp;
8386ac43 16154
d62a17ae 16155 if (name)
16156 bgp = bgp_lookup_by_name(name);
16157 else
16158 bgp = bgp_get_default();
8386ac43 16159
d62a17ae 16160 if (bgp) {
16161 if (!strcmp(what, "advertise-queue"))
16162 update_group_show_adj_queue(bgp, afi, safi, vty,
16163 subgrp_id);
16164 else if (!strcmp(what, "advertised-routes"))
16165 update_group_show_advertised(bgp, afi, safi, vty,
16166 subgrp_id);
16167 else if (!strcmp(what, "packet-queue"))
16168 update_group_show_packet_queue(bgp, afi, safi, vty,
16169 subgrp_id);
16170 }
3f9c7369
DS
16171}
16172
dc64bdec
QY
16173DEFPY(show_ip_bgp_instance_updgrps_adj_s,
16174 show_ip_bgp_instance_updgrps_adj_s_cmd,
16175 "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",
16176 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
16177 BGP_SAFI_HELP_STR
16178 "Detailed info about dynamic update groups\n"
16179 "Specific subgroup to display info for\n"
16180 "Advertisement queue\n"
16181 "Announced routes\n"
16182 "Packet queue\n")
3f9c7369 16183{
dc64bdec
QY
16184 uint64_t subgrp_id = 0;
16185 afi_t afiz;
16186 safi_t safiz;
16187 if (sgid)
16188 subgrp_id = strtoull(sgid, NULL, 10);
16189
16190 if (!ip && !afi)
16191 afiz = AFI_IP6;
16192 if (!ip && afi)
16193 afiz = bgp_vty_afi_from_str(afi);
16194 if (ip && !afi)
16195 afiz = AFI_IP;
16196 if (ip && afi) {
16197 afiz = bgp_vty_afi_from_str(afi);
16198 if (afiz != AFI_IP)
16199 vty_out(vty,
16200 "%% Cannot specify both 'ip' and 'ipv6'\n");
16201 return CMD_WARNING;
16202 }
d62a17ae 16203
dc64bdec 16204 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 16205
dc64bdec 16206 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 16207 return CMD_SUCCESS;
16208}
16209
6f4eacf3
DA
16210static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
16211 json_object *json)
d62a17ae 16212{
16213 struct listnode *node, *nnode;
16214 struct prefix *range;
16215 struct peer *conf;
16216 struct peer *peer;
d62a17ae 16217 afi_t afi;
16218 safi_t safi;
16219 const char *peer_status;
d62a17ae 16220 int lr_count;
16221 int dynamic;
6f4eacf3
DA
16222 bool af_cfgd;
16223 json_object *json_peer_group = NULL;
16224 json_object *json_peer_group_afc = NULL;
16225 json_object *json_peer_group_members = NULL;
16226 json_object *json_peer_group_dynamic = NULL;
16227 json_object *json_peer_group_dynamic_af = NULL;
16228 json_object *json_peer_group_ranges = NULL;
d62a17ae 16229
16230 conf = group->conf;
16231
6f4eacf3
DA
16232 if (json) {
16233 json_peer_group = json_object_new_object();
16234 json_peer_group_afc = json_object_new_array();
16235 }
16236
d62a17ae 16237 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3 16238 if (json)
44a4d55e
PG
16239 asn_asn2json(json_peer_group, "remoteAs", conf->as,
16240 bgp_get_asnotation(conf->bgp));
16241 else {
16242 vty_out(vty, "\nBGP peer-group %s, remote AS ",
16243 group->name);
16244 vty_out(vty, ASN_FORMAT(bgp_get_asnotation(conf->bgp)),
16245 &conf->as);
16246 vty_out(vty, "\n");
16247 }
d62a17ae 16248 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3 16249 if (json)
e84c7c12
PG
16250 asn_asn2json(json, "remoteAs", group->bgp->as,
16251 group->bgp->asnotation);
6f4eacf3 16252 else
9eb11997
PG
16253 vty_out(vty, "\nBGP peer-group %s, remote AS %s\n",
16254 group->name, group->bgp->as_pretty);
d62a17ae 16255 } else {
6f4eacf3
DA
16256 if (!json)
16257 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 16258 }
f14e6fdb 16259
6f4eacf3
DA
16260 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
16261 if (json)
16262 json_object_string_add(json_peer_group, "type",
16263 "internal");
16264 else
16265 vty_out(vty, " Peer-group type is internal\n");
16266 } else {
16267 if (json)
16268 json_object_string_add(json_peer_group, "type",
16269 "external");
16270 else
16271 vty_out(vty, " Peer-group type is external\n");
16272 }
d62a17ae 16273
16274 /* Display AFs configured. */
6f4eacf3
DA
16275 if (!json)
16276 vty_out(vty, " Configured address-families:");
16277
05c7a1cc
QY
16278 FOREACH_AFI_SAFI (afi, safi) {
16279 if (conf->afc[afi][safi]) {
6f4eacf3
DA
16280 af_cfgd = true;
16281 if (json)
16282 json_object_array_add(
16283 json_peer_group_afc,
16284 json_object_new_string(get_afi_safi_str(
16285 afi, safi, false)));
16286 else
16287 vty_out(vty, " %s;",
16288 get_afi_safi_str(afi, safi, false));
d62a17ae 16289 }
05c7a1cc 16290 }
6f4eacf3
DA
16291
16292 if (json) {
16293 json_object_object_add(json_peer_group,
16294 "addressFamiliesConfigured",
16295 json_peer_group_afc);
16296 } else {
16297 if (!af_cfgd)
16298 vty_out(vty, " none\n");
16299 else
16300 vty_out(vty, "\n");
16301 }
d62a17ae 16302
16303 /* Display listen ranges (for dynamic neighbors), if any */
16304 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 16305 lr_count = listcount(group->listen_range[afi]);
16306 if (lr_count) {
6f4eacf3
DA
16307 if (json) {
16308 if (!json_peer_group_dynamic)
16309 json_peer_group_dynamic =
16310 json_object_new_object();
16311
16312 json_peer_group_dynamic_af =
16313 json_object_new_object();
16314 json_peer_group_ranges =
16315 json_object_new_array();
16316 json_object_int_add(json_peer_group_dynamic_af,
16317 "count", lr_count);
16318 } else {
16319 vty_out(vty, " %d %s listen range(s)\n",
16320 lr_count, afi2str(afi));
16321 }
d62a17ae 16322
16323 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
16324 nnode, range)) {
16325 if (json) {
16326 char buf[BUFSIZ];
16327
16328 snprintfrr(buf, sizeof(buf), "%pFX",
16329 range);
16330
16331 json_object_array_add(
16332 json_peer_group_ranges,
16333 json_object_new_string(buf));
16334 } else {
16335 vty_out(vty, " %pFX\n", range);
16336 }
16337 }
16338
16339 if (json) {
16340 json_object_object_add(
16341 json_peer_group_dynamic_af, "ranges",
16342 json_peer_group_ranges);
16343
16344 json_object_object_add(
16345 json_peer_group_dynamic, afi2str(afi),
16346 json_peer_group_dynamic_af);
16347 }
d62a17ae 16348 }
16349 }
f14e6fdb 16350
6f4eacf3
DA
16351 if (json_peer_group_dynamic)
16352 json_object_object_add(json_peer_group, "dynamicRanges",
16353 json_peer_group_dynamic);
16354
d62a17ae 16355 /* Display group members and their status */
16356 if (listcount(group->peer)) {
6f4eacf3
DA
16357 if (json)
16358 json_peer_group_members = json_object_new_object();
16359 else
16360 vty_out(vty, " Peer-group members:\n");
d62a17ae 16361 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
16362 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
16363 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 16364 peer_status = "Idle (Admin)";
16365 else if (CHECK_FLAG(peer->sflags,
16366 PEER_STATUS_PREFIX_OVERFLOW))
16367 peer_status = "Idle (PfxCt)";
16368 else
16369 peer_status = lookup_msg(bgp_status_msg,
16370 peer->status, NULL);
16371
16372 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
16373
16374 if (json) {
16375 json_object *json_peer_group_member =
16376 json_object_new_object();
16377
16378 json_object_string_add(json_peer_group_member,
16379 "status", peer_status);
16380
16381 if (dynamic)
16382 json_object_boolean_true_add(
16383 json_peer_group_member,
16384 "dynamic");
16385
16386 json_object_object_add(json_peer_group_members,
16387 peer->host,
16388 json_peer_group_member);
16389 } else {
16390 vty_out(vty, " %s %s %s \n", peer->host,
16391 dynamic ? "(dynamic)" : "",
16392 peer_status);
16393 }
d62a17ae 16394 }
6f4eacf3
DA
16395 if (json)
16396 json_object_object_add(json_peer_group, "members",
16397 json_peer_group_members);
d62a17ae 16398 }
f14e6fdb 16399
6f4eacf3
DA
16400 if (json)
16401 json_object_object_add(json, group->name, json_peer_group);
16402
d62a17ae 16403 return CMD_SUCCESS;
16404}
16405
ff9959b0 16406static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 16407 const char *group_name, bool uj)
d62a17ae 16408{
ff9959b0 16409 struct bgp *bgp;
d62a17ae 16410 struct listnode *node, *nnode;
16411 struct peer_group *group;
ff9959b0 16412 bool found = false;
6f4eacf3
DA
16413 json_object *json = NULL;
16414
16415 if (uj)
16416 json = json_object_new_object();
ff9959b0
QY
16417
16418 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
16419
16420 if (!bgp) {
c48349e3 16421 if (uj)
75eeda93 16422 vty_json(vty, json);
c48349e3 16423 else
6f4eacf3 16424 vty_out(vty, "%% BGP instance not found\n");
6f4eacf3 16425
ff9959b0
QY
16426 return CMD_WARNING;
16427 }
d62a17ae 16428
16429 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
16430 if (group_name) {
16431 if (strmatch(group->name, group_name)) {
6f4eacf3 16432 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
16433 found = true;
16434 break;
d62a17ae 16435 }
ff9959b0 16436 } else {
6f4eacf3 16437 bgp_show_one_peer_group(vty, group, json);
d62a17ae 16438 }
f14e6fdb 16439 }
f14e6fdb 16440
6f4eacf3 16441 if (group_name && !found && !uj)
d62a17ae 16442 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 16443
c48349e3 16444 if (uj)
75eeda93 16445 vty_json(vty, json);
6f4eacf3 16446
d62a17ae 16447 return CMD_SUCCESS;
f14e6fdb
DS
16448}
16449
6f4eacf3
DA
16450DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
16451 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
16452 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
16453 "Detailed information on BGP peer groups\n"
16454 "Peer group name\n" JSON_STR)
f14e6fdb 16455{
d62a17ae 16456 char *vrf, *pg;
d62a17ae 16457 int idx = 0;
6f4eacf3 16458 bool uj = use_json(argc, argv);
f14e6fdb 16459
a4d82a8a
PZ
16460 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16461 : NULL;
d62a17ae 16462 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 16463
6f4eacf3 16464 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 16465}
3f9c7369 16466
d6e3c605 16467
718e3744 16468/* Redistribute VTY commands. */
16469
585f1adc
IR
16470DEFUN (bgp_redistribute_ipv4,
16471 bgp_redistribute_ipv4_cmd,
16472 "redistribute " FRR_IP_REDIST_STR_BGPD,
16473 "Redistribute information from another routing protocol\n"
16474 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 16475{
585f1adc 16476 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16477 int idx_protocol = 1;
585f1adc 16478 int type;
37a87b8f 16479
585f1adc
IR
16480 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16481 if (type < 0) {
16482 vty_out(vty, "%% Invalid route type\n");
16483 return CMD_WARNING_CONFIG_FAILED;
16484 }
7f323236 16485
585f1adc
IR
16486 bgp_redist_add(bgp, AFI_IP, type, 0);
16487 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 16488}
16489
d62a17ae 16490ALIAS_HIDDEN(
16491 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16492 "redistribute " FRR_IP_REDIST_STR_BGPD,
16493 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 16494
585f1adc
IR
16495DEFUN (bgp_redistribute_ipv4_rmap,
16496 bgp_redistribute_ipv4_rmap_cmd,
70dd370f 16497 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
585f1adc
IR
16498 "Redistribute information from another routing protocol\n"
16499 FRR_IP_REDIST_HELP_STR_BGPD
16500 "Route map reference\n"
16501 "Pointer to route-map entries\n")
718e3744 16502{
585f1adc 16503 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16504 int idx_protocol = 1;
16505 int idx_word = 3;
585f1adc
IR
16506 int type;
16507 struct bgp_redist *red;
16508 bool changed;
16509 struct route_map *route_map = route_map_lookup_warn_noexist(
16510 vty, argv[idx_word]->arg);
16511
16512 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16513 if (type < 0) {
16514 vty_out(vty, "%% Invalid route type\n");
16515 return CMD_WARNING_CONFIG_FAILED;
16516 }
37a87b8f 16517
585f1adc
IR
16518 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16519 changed =
16520 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16521 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 16522}
16523
d62a17ae 16524ALIAS_HIDDEN(
16525 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
70dd370f 16526 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
d62a17ae 16527 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16528 "Route map reference\n"
16529 "Pointer to route-map entries\n")
596c17ba 16530
585f1adc
IR
16531DEFUN (bgp_redistribute_ipv4_metric,
16532 bgp_redistribute_ipv4_metric_cmd,
16533 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16534 "Redistribute information from another routing protocol\n"
16535 FRR_IP_REDIST_HELP_STR_BGPD
16536 "Metric for redistributed routes\n"
16537 "Default metric\n")
718e3744 16538{
585f1adc 16539 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16540 int idx_protocol = 1;
16541 int idx_number = 3;
585f1adc
IR
16542 int type;
16543 uint32_t metric;
16544 struct bgp_redist *red;
16545 bool changed;
16546
16547 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16548 if (type < 0) {
16549 vty_out(vty, "%% Invalid route type\n");
16550 return CMD_WARNING_CONFIG_FAILED;
16551 }
16552 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16553
585f1adc
IR
16554 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16555 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16556 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16557}
16558
16559ALIAS_HIDDEN(
16560 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16561 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16562 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16563 "Metric for redistributed routes\n"
16564 "Default metric\n")
596c17ba 16565
585f1adc
IR
16566DEFUN (bgp_redistribute_ipv4_rmap_metric,
16567 bgp_redistribute_ipv4_rmap_metric_cmd,
70dd370f 16568 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16569 "Redistribute information from another routing protocol\n"
16570 FRR_IP_REDIST_HELP_STR_BGPD
16571 "Route map reference\n"
16572 "Pointer to route-map entries\n"
16573 "Metric for redistributed routes\n"
16574 "Default metric\n")
718e3744 16575{
585f1adc 16576 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16577 int idx_protocol = 1;
16578 int idx_word = 3;
16579 int idx_number = 5;
585f1adc
IR
16580 int type;
16581 uint32_t metric;
16582 struct bgp_redist *red;
16583 bool changed;
16584 struct route_map *route_map =
16585 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16586
16587 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16588 if (type < 0) {
16589 vty_out(vty, "%% Invalid route type\n");
16590 return CMD_WARNING_CONFIG_FAILED;
16591 }
16592 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 16593
585f1adc
IR
16594 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16595 changed =
16596 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16597 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16598 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16599}
16600
16601ALIAS_HIDDEN(
16602 bgp_redistribute_ipv4_rmap_metric,
16603 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16604 "redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16605 " route-map RMAP_NAME metric (0-4294967295)",
d62a17ae 16606 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16607 "Route map reference\n"
16608 "Pointer to route-map entries\n"
16609 "Metric for redistributed routes\n"
16610 "Default metric\n")
596c17ba 16611
585f1adc
IR
16612DEFUN (bgp_redistribute_ipv4_metric_rmap,
16613 bgp_redistribute_ipv4_metric_rmap_cmd,
70dd370f 16614 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16615 "Redistribute information from another routing protocol\n"
16616 FRR_IP_REDIST_HELP_STR_BGPD
16617 "Metric for redistributed routes\n"
16618 "Default metric\n"
16619 "Route map reference\n"
16620 "Pointer to route-map entries\n")
718e3744 16621{
585f1adc 16622 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16623 int idx_protocol = 1;
37a87b8f 16624 int idx_number = 3;
585f1adc
IR
16625 int idx_word = 5;
16626 int type;
16627 uint32_t metric;
16628 struct bgp_redist *red;
16629 bool changed;
16630 struct route_map *route_map =
16631 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16632
16633 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16634 if (type < 0) {
16635 vty_out(vty, "%% Invalid route type\n");
16636 return CMD_WARNING_CONFIG_FAILED;
16637 }
16638 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 16639
585f1adc
IR
16640 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16641 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16642 changed |=
16643 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16644 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16645}
16646
16647ALIAS_HIDDEN(
16648 bgp_redistribute_ipv4_metric_rmap,
16649 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16650 "redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16651 " metric (0-4294967295) route-map RMAP_NAME",
d62a17ae 16652 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16653 "Metric for redistributed routes\n"
16654 "Default metric\n"
16655 "Route map reference\n"
16656 "Pointer to route-map entries\n")
596c17ba 16657
585f1adc
IR
16658DEFUN (bgp_redistribute_ipv4_ospf,
16659 bgp_redistribute_ipv4_ospf_cmd,
16660 "redistribute <ospf|table> (1-65535)",
16661 "Redistribute information from another routing protocol\n"
16662 "Open Shortest Path First (OSPFv2)\n"
16663 "Non-main Kernel Routing Table\n"
16664 "Instance ID/Table ID\n")
7c8ff89e 16665{
585f1adc
IR
16666 VTY_DECLVAR_CONTEXT(bgp, bgp);
16667 int idx_ospf_table = 1;
d62a17ae 16668 int idx_number = 2;
585f1adc
IR
16669 unsigned short instance;
16670 unsigned short protocol;
7c8ff89e 16671
585f1adc 16672 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 16673
585f1adc
IR
16674 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16675 protocol = ZEBRA_ROUTE_OSPF;
16676 else
16677 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 16678
585f1adc
IR
16679 bgp_redist_add(bgp, AFI_IP, protocol, instance);
16680 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
16681}
16682
d62a17ae 16683ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16684 "redistribute <ospf|table> (1-65535)",
16685 "Redistribute information from another routing protocol\n"
16686 "Open Shortest Path First (OSPFv2)\n"
16687 "Non-main Kernel Routing Table\n"
16688 "Instance ID/Table ID\n")
596c17ba 16689
585f1adc
IR
16690DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16691 bgp_redistribute_ipv4_ospf_rmap_cmd,
70dd370f 16692 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
585f1adc
IR
16693 "Redistribute information from another routing protocol\n"
16694 "Open Shortest Path First (OSPFv2)\n"
16695 "Non-main Kernel Routing Table\n"
16696 "Instance ID/Table ID\n"
16697 "Route map reference\n"
16698 "Pointer to route-map entries\n")
7c8ff89e 16699{
585f1adc
IR
16700 VTY_DECLVAR_CONTEXT(bgp, bgp);
16701 int idx_ospf_table = 1;
d62a17ae 16702 int idx_number = 2;
16703 int idx_word = 4;
585f1adc
IR
16704 struct bgp_redist *red;
16705 unsigned short instance;
16706 int protocol;
16707 bool changed;
16708 struct route_map *route_map =
16709 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16710
16711 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16712 protocol = ZEBRA_ROUTE_OSPF;
16713 else
16714 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16715
585f1adc
IR
16716 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16717 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16718 changed =
16719 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16720 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16721}
16722
16723ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16724 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
70dd370f 16725 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
d62a17ae 16726 "Redistribute information from another routing protocol\n"
16727 "Open Shortest Path First (OSPFv2)\n"
16728 "Non-main Kernel Routing Table\n"
16729 "Instance ID/Table ID\n"
16730 "Route map reference\n"
16731 "Pointer to route-map entries\n")
596c17ba 16732
585f1adc
IR
16733DEFUN (bgp_redistribute_ipv4_ospf_metric,
16734 bgp_redistribute_ipv4_ospf_metric_cmd,
16735 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16736 "Redistribute information from another routing protocol\n"
16737 "Open Shortest Path First (OSPFv2)\n"
16738 "Non-main Kernel Routing Table\n"
16739 "Instance ID/Table ID\n"
16740 "Metric for redistributed routes\n"
16741 "Default metric\n")
7c8ff89e 16742{
585f1adc
IR
16743 VTY_DECLVAR_CONTEXT(bgp, bgp);
16744 int idx_ospf_table = 1;
d62a17ae 16745 int idx_number = 2;
16746 int idx_number_2 = 4;
585f1adc
IR
16747 uint32_t metric;
16748 struct bgp_redist *red;
16749 unsigned short instance;
16750 int protocol;
16751 bool changed;
16752
16753 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16754 protocol = ZEBRA_ROUTE_OSPF;
16755 else
16756 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16757
585f1adc
IR
16758 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16759 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16760
585f1adc
IR
16761 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16762 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16763 metric);
16764 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16765}
16766
16767ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16768 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16769 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
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")
596c17ba 16776
585f1adc
IR
16777DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16778 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
70dd370f 16779 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16780 "Redistribute information from another routing protocol\n"
16781 "Open Shortest Path First (OSPFv2)\n"
16782 "Non-main Kernel Routing Table\n"
16783 "Instance ID/Table ID\n"
16784 "Route map reference\n"
16785 "Pointer to route-map entries\n"
16786 "Metric for redistributed routes\n"
16787 "Default metric\n")
7c8ff89e 16788{
585f1adc
IR
16789 VTY_DECLVAR_CONTEXT(bgp, bgp);
16790 int idx_ospf_table = 1;
d62a17ae 16791 int idx_number = 2;
16792 int idx_word = 4;
16793 int idx_number_2 = 6;
585f1adc
IR
16794 uint32_t metric;
16795 struct bgp_redist *red;
16796 unsigned short instance;
16797 int protocol;
16798 bool changed;
16799 struct route_map *route_map =
16800 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16801
16802 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16803 protocol = ZEBRA_ROUTE_OSPF;
16804 else
16805 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16806
585f1adc
IR
16807 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16808 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16809
585f1adc
IR
16810 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16811 changed =
16812 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16813 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16814 metric);
16815 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16816}
16817
16818ALIAS_HIDDEN(
16819 bgp_redistribute_ipv4_ospf_rmap_metric,
16820 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
70dd370f 16821 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
d62a17ae 16822 "Redistribute information from another routing protocol\n"
16823 "Open Shortest Path First (OSPFv2)\n"
16824 "Non-main Kernel Routing Table\n"
16825 "Instance ID/Table ID\n"
16826 "Route map reference\n"
16827 "Pointer to route-map entries\n"
16828 "Metric for redistributed routes\n"
16829 "Default metric\n")
596c17ba 16830
585f1adc
IR
16831DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16832 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
70dd370f 16833 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16834 "Redistribute information from another routing protocol\n"
16835 "Open Shortest Path First (OSPFv2)\n"
16836 "Non-main Kernel Routing Table\n"
16837 "Instance ID/Table ID\n"
16838 "Metric for redistributed routes\n"
16839 "Default metric\n"
16840 "Route map reference\n"
16841 "Pointer to route-map entries\n")
7c8ff89e 16842{
585f1adc
IR
16843 VTY_DECLVAR_CONTEXT(bgp, bgp);
16844 int idx_ospf_table = 1;
d62a17ae 16845 int idx_number = 2;
16846 int idx_number_2 = 4;
16847 int idx_word = 6;
585f1adc
IR
16848 uint32_t metric;
16849 struct bgp_redist *red;
16850 unsigned short instance;
16851 int protocol;
16852 bool changed;
16853 struct route_map *route_map =
16854 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16855
16856 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16857 protocol = ZEBRA_ROUTE_OSPF;
16858 else
16859 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16860
585f1adc
IR
16861 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16862 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16863
585f1adc
IR
16864 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16865 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16866 metric);
16867 changed |=
16868 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16869 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16870}
16871
16872ALIAS_HIDDEN(
16873 bgp_redistribute_ipv4_ospf_metric_rmap,
16874 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
70dd370f 16875 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
d62a17ae 16876 "Redistribute information from another routing protocol\n"
16877 "Open Shortest Path First (OSPFv2)\n"
16878 "Non-main Kernel Routing Table\n"
16879 "Instance ID/Table ID\n"
16880 "Metric for redistributed routes\n"
16881 "Default metric\n"
16882 "Route map reference\n"
16883 "Pointer to route-map entries\n")
596c17ba 16884
585f1adc
IR
16885DEFUN (no_bgp_redistribute_ipv4_ospf,
16886 no_bgp_redistribute_ipv4_ospf_cmd,
70dd370f 16887 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16888 NO_STR
16889 "Redistribute information from another routing protocol\n"
16890 "Open Shortest Path First (OSPFv2)\n"
16891 "Non-main Kernel Routing Table\n"
16892 "Instance ID/Table ID\n"
16893 "Metric for redistributed routes\n"
16894 "Default metric\n"
16895 "Route map reference\n"
16896 "Pointer to route-map entries\n")
7c8ff89e 16897{
585f1adc
IR
16898 VTY_DECLVAR_CONTEXT(bgp, bgp);
16899 int idx_ospf_table = 2;
d62a17ae 16900 int idx_number = 3;
585f1adc
IR
16901 unsigned short instance;
16902 int protocol;
37a87b8f 16903
585f1adc
IR
16904 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16905 protocol = ZEBRA_ROUTE_OSPF;
16906 else
16907 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16908
585f1adc
IR
16909 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16910 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
d62a17ae 16911}
16912
16913ALIAS_HIDDEN(
16914 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
70dd370f 16915 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
d62a17ae 16916 NO_STR
16917 "Redistribute information from another routing protocol\n"
16918 "Open Shortest Path First (OSPFv2)\n"
16919 "Non-main Kernel Routing Table\n"
16920 "Instance ID/Table ID\n"
16921 "Metric for redistributed routes\n"
16922 "Default metric\n"
16923 "Route map reference\n"
16924 "Pointer to route-map entries\n")
596c17ba 16925
585f1adc
IR
16926DEFUN (no_bgp_redistribute_ipv4,
16927 no_bgp_redistribute_ipv4_cmd,
70dd370f 16928 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16929 NO_STR
16930 "Redistribute information from another routing protocol\n"
16931 FRR_IP_REDIST_HELP_STR_BGPD
16932 "Metric for redistributed routes\n"
16933 "Default metric\n"
16934 "Route map reference\n"
16935 "Pointer to route-map entries\n")
718e3744 16936{
585f1adc 16937 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16938 int idx_protocol = 2;
585f1adc 16939 int type;
d62a17ae 16940
585f1adc
IR
16941 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16942 if (type < 0) {
16943 vty_out(vty, "%% Invalid route type\n");
16944 return CMD_WARNING_CONFIG_FAILED;
16945 }
16946 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
d62a17ae 16947}
16948
16949ALIAS_HIDDEN(
16950 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16951 "no redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16952 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
d62a17ae 16953 NO_STR
16954 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16955 "Metric for redistributed routes\n"
16956 "Default metric\n"
16957 "Route map reference\n"
16958 "Pointer to route-map entries\n")
596c17ba 16959
585f1adc
IR
16960DEFUN (bgp_redistribute_ipv6,
16961 bgp_redistribute_ipv6_cmd,
16962 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16963 "Redistribute information from another routing protocol\n"
16964 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 16965{
585f1adc 16966 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16967 int idx_protocol = 1;
585f1adc 16968 int type;
718e3744 16969
585f1adc
IR
16970 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16971 if (type < 0) {
16972 vty_out(vty, "%% Invalid route type\n");
16973 return CMD_WARNING_CONFIG_FAILED;
16974 }
718e3744 16975
585f1adc
IR
16976 bgp_redist_add(bgp, AFI_IP6, type, 0);
16977 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 16978}
16979
585f1adc
IR
16980DEFUN (bgp_redistribute_ipv6_rmap,
16981 bgp_redistribute_ipv6_rmap_cmd,
70dd370f 16982 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
585f1adc
IR
16983 "Redistribute information from another routing protocol\n"
16984 FRR_IP6_REDIST_HELP_STR_BGPD
16985 "Route map reference\n"
16986 "Pointer to route-map entries\n")
718e3744 16987{
585f1adc 16988 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16989 int idx_protocol = 1;
16990 int idx_word = 3;
585f1adc
IR
16991 int type;
16992 struct bgp_redist *red;
16993 bool changed;
16994 struct route_map *route_map =
16995 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16996
16997 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16998 if (type < 0) {
16999 vty_out(vty, "%% Invalid route type\n");
17000 return CMD_WARNING_CONFIG_FAILED;
17001 }
37a87b8f 17002
585f1adc
IR
17003 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
17004 changed =
17005 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
17006 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 17007}
17008
585f1adc 17009DEFUN (bgp_redistribute_ipv6_metric,
718e3744 17010 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 17011 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 17012 "Redistribute information from another routing protocol\n"
ab0181ee 17013 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 17014 "Metric for redistributed routes\n"
17015 "Default metric\n")
17016{
585f1adc 17017 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 17018 int idx_protocol = 1;
17019 int idx_number = 3;
585f1adc
IR
17020 int type;
17021 uint32_t metric;
17022 struct bgp_redist *red;
17023 bool changed;
17024
17025 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
17026 if (type < 0) {
17027 vty_out(vty, "%% Invalid route type\n");
17028 return CMD_WARNING_CONFIG_FAILED;
17029 }
17030 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 17031
585f1adc
IR
17032 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
17033 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
17034 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 17035}
17036
585f1adc
IR
17037DEFUN (bgp_redistribute_ipv6_rmap_metric,
17038 bgp_redistribute_ipv6_rmap_metric_cmd,
70dd370f 17039 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
17040 "Redistribute information from another routing protocol\n"
17041 FRR_IP6_REDIST_HELP_STR_BGPD
17042 "Route map reference\n"
17043 "Pointer to route-map entries\n"
17044 "Metric for redistributed routes\n"
17045 "Default metric\n")
718e3744 17046{
585f1adc 17047 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 17048 int idx_protocol = 1;
17049 int idx_word = 3;
17050 int idx_number = 5;
585f1adc
IR
17051 int type;
17052 uint32_t metric;
17053 struct bgp_redist *red;
17054 bool changed;
17055 struct route_map *route_map =
17056 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
17057
17058 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
17059 if (type < 0) {
17060 vty_out(vty, "%% Invalid route type\n");
17061 return CMD_WARNING_CONFIG_FAILED;
17062 }
17063 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 17064
585f1adc
IR
17065 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
17066 changed =
17067 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
17068 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
17069 metric);
17070 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 17071}
17072
585f1adc
IR
17073DEFUN (bgp_redistribute_ipv6_metric_rmap,
17074 bgp_redistribute_ipv6_metric_rmap_cmd,
70dd370f 17075 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
17076 "Redistribute information from another routing protocol\n"
17077 FRR_IP6_REDIST_HELP_STR_BGPD
17078 "Metric for redistributed routes\n"
17079 "Default metric\n"
17080 "Route map reference\n"
17081 "Pointer to route-map entries\n")
718e3744 17082{
585f1adc 17083 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 17084 int idx_protocol = 1;
37a87b8f 17085 int idx_number = 3;
585f1adc
IR
17086 int idx_word = 5;
17087 int type;
17088 uint32_t metric;
17089 struct bgp_redist *red;
17090 bool changed;
17091 struct route_map *route_map =
17092 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
17093
17094 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
17095 if (type < 0) {
17096 vty_out(vty, "%% Invalid route type\n");
17097 return CMD_WARNING_CONFIG_FAILED;
17098 }
17099 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 17100
585f1adc
IR
17101 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
17102 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
17103 metric);
17104 changed |=
17105 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
17106 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 17107}
17108
585f1adc
IR
17109DEFUN (no_bgp_redistribute_ipv6,
17110 no_bgp_redistribute_ipv6_cmd,
70dd370f 17111 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
17112 NO_STR
17113 "Redistribute information from another routing protocol\n"
17114 FRR_IP6_REDIST_HELP_STR_BGPD
17115 "Metric for redistributed routes\n"
17116 "Default metric\n"
17117 "Route map reference\n"
17118 "Pointer to route-map entries\n")
718e3744 17119{
585f1adc 17120 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 17121 int idx_protocol = 2;
585f1adc 17122 int type;
37a87b8f 17123
585f1adc
IR
17124 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
17125 if (type < 0) {
17126 vty_out(vty, "%% Invalid route type\n");
17127 return CMD_WARNING_CONFIG_FAILED;
17128 }
718e3744 17129
585f1adc 17130 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
d62a17ae 17131}
17132
4ab46701
AR
17133/* Neighbor update tcp-mss. */
17134static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
17135 const char *tcp_mss_str)
17136{
17137 struct peer *peer;
17138 uint32_t tcp_mss_val = 0;
17139
17140 peer = peer_and_group_lookup_vty(vty, peer_str);
17141 if (!peer)
17142 return CMD_WARNING_CONFIG_FAILED;
17143
17144 if (tcp_mss_str) {
17145 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
17146 peer_tcp_mss_set(peer, tcp_mss_val);
17147 } else {
17148 peer_tcp_mss_unset(peer);
17149 }
17150
17151 return CMD_SUCCESS;
17152}
17153
17154DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
17155 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
17156 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
17157 "TCP max segment size\n"
17158 "TCP MSS value\n")
17159{
17160 int peer_index = 1;
17161 int mss_index = 3;
17162
17163 vty_out(vty,
17164 " Warning: Reset BGP session for tcp-mss value to take effect\n");
17165 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
17166 argv[mss_index]->arg);
17167}
17168
17169DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
17170 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
17171 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
17172 "TCP max segment size\n"
17173 "TCP MSS value\n")
17174{
17175 int peer_index = 2;
17176
17177 vty_out(vty,
17178 " Warning: Reset BGP session for tcp-mss value to take effect\n");
17179 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
17180}
17181
a486300b
PG
17182DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
17183 "[no$no] bgp retain route-target all",
17184 NO_STR BGP_STR
17185 "Retain BGP updates\n"
17186 "Retain BGP updates based on route-target values\n"
17187 "Retain all BGP updates\n")
17188{
17189 bool check;
17190 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
17191
17192 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
17193 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
17194 if (check != !no) {
17195 if (!no)
17196 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
17197 [bgp_node_safi(vty)],
17198 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
17199 else
17200 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
17201 [bgp_node_safi(vty)],
17202 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
17203 /* trigger a flush to re-sync with ADJ-RIB-in */
17204 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
17205 clear_all, BGP_CLEAR_SOFT_IN, NULL);
17206 }
17207 return CMD_SUCCESS;
17208}
17209
dd65f45e
DL
17210static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
17211 afi_t afi, safi_t safi)
d62a17ae 17212{
17213 int i;
17214
17215 /* Unicast redistribution only. */
17216 if (safi != SAFI_UNICAST)
2b791107 17217 return;
d62a17ae 17218
17219 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
17220 /* Redistribute BGP does not make sense. */
17221 if (i != ZEBRA_ROUTE_BGP) {
17222 struct list *red_list;
17223 struct listnode *node;
17224 struct bgp_redist *red;
17225
17226 red_list = bgp->redist[afi][i];
17227 if (!red_list)
17228 continue;
17229
17230 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 17231 /* "redistribute" configuration. */
17232 vty_out(vty, " redistribute %s",
17233 zebra_route_string(i));
17234 if (red->instance)
17235 vty_out(vty, " %d", red->instance);
17236 if (red->redist_metric_flag)
17237 vty_out(vty, " metric %u",
17238 red->redist_metric);
17239 if (red->rmap.name)
17240 vty_out(vty, " route-map %s",
17241 red->rmap.name);
17242 vty_out(vty, "\n");
17243 }
17244 }
17245 }
718e3744 17246}
6b0655a2 17247
dd65f45e
DL
17248/* peer-group helpers for config-write */
17249
234f6fd4 17250bool peergroup_flag_check(struct peer *peer, uint64_t flag)
dd65f45e
DL
17251{
17252 if (!peer_group_active(peer)) {
17253 if (CHECK_FLAG(peer->flags_invert, flag))
17254 return !CHECK_FLAG(peer->flags, flag);
17255 else
17256 return !!CHECK_FLAG(peer->flags, flag);
17257 }
17258
17259 return !!CHECK_FLAG(peer->flags_override, flag);
17260}
17261
17262static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
da5e1a58 17263 uint64_t flag)
dd65f45e
DL
17264{
17265 if (!peer_group_active(peer)) {
17266 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
17267 return !peer_af_flag_check(peer, afi, safi, flag);
17268 else
2c722516 17269 return peer_af_flag_check(peer, afi, safi, flag);
dd65f45e
DL
17270 }
17271
17272 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
17273}
17274
17275static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
17276 uint8_t type, int direct)
17277{
17278 struct bgp_filter *filter;
17279
17280 if (peer_group_active(peer))
17281 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
17282 type);
17283
17284 filter = &peer->filter[afi][safi];
17285 switch (type) {
17286 case PEER_FT_DISTRIBUTE_LIST:
17287 return !!(filter->dlist[direct].name);
17288 case PEER_FT_FILTER_LIST:
17289 return !!(filter->aslist[direct].name);
17290 case PEER_FT_PREFIX_LIST:
17291 return !!(filter->plist[direct].name);
17292 case PEER_FT_ROUTE_MAP:
17293 return !!(filter->map[direct].name);
17294 case PEER_FT_UNSUPPRESS_MAP:
17295 return !!(filter->usmap.name);
7f7940e6
MK
17296 case PEER_FT_ADVERTISE_MAP:
17297 return !!(filter->advmap.aname
17298 && ((filter->advmap.condition == direct)
17299 && filter->advmap.cname));
dd65f45e
DL
17300 default:
17301 return false;
17302 }
17303}
17304
17305/* Return true if the addpath type is set for peer and different from
17306 * peer-group.
17307 */
3dc339cd
DA
17308static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
17309 safi_t safi)
dd65f45e
DL
17310{
17311 enum bgp_addpath_strat type, g_type;
17312
17313 type = peer->addpath_type[afi][safi];
17314
17315 if (type != BGP_ADDPATH_NONE) {
17316 if (peer_group_active(peer)) {
17317 g_type = peer->group->conf->addpath_type[afi][safi];
17318
17319 if (type != g_type)
3dc339cd 17320 return true;
dd65f45e 17321 else
3dc339cd 17322 return false;
dd65f45e
DL
17323 }
17324
3dc339cd 17325 return true;
dd65f45e
DL
17326 }
17327
3dc339cd 17328 return false;
dd65f45e
DL
17329}
17330
b9c7bc5a 17331/* This is part of the address-family block (unicast only) */
dd65f45e 17332static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
17333 afi_t afi)
17334{
b9c7bc5a 17335 int indent = 2;
53970de3 17336 uint32_t tovpn_sid_index = 0;
ddb5b488 17337
8a066a70 17338 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
17339 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17340 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
17341 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
17342 bgp->vpn_policy[afi]
bb4f6190 17343 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
17344 else
17345 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
17346 bgp->vpn_policy[afi]
17347 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17348 }
12a844a5
DS
17349 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17350 BGP_CONFIG_VRF_TO_VRF_IMPORT)
17351 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17352 BGP_CONFIG_VRF_TO_VRF_EXPORT))
17353 return;
17354
e70e9f8e
PZ
17355 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17356 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
17357
17358 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
17359
17360 } else {
17361 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
17362 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
17363 bgp->vpn_policy[afi].tovpn_label);
17364 }
ddb5b488 17365 }
53970de3 17366
d4cdcee5
PG
17367 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17368 BGP_VPN_POLICY_TOVPN_LABEL_PER_NEXTHOP))
17369 vty_out(vty,
17370 "%*slabel vpn export allocation-mode per-nexthop\n",
17371 indent, "");
17372
53970de3
RS
17373 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
17374 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17375 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
17376 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
17377 } else if (tovpn_sid_index != 0) {
17378 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
17379 tovpn_sid_index);
17380 }
17381
c4f64ea9 17382 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
fa566a94
PG
17383 vty_out(vty, "%*srd vpn export %s\n", indent, "",
17384 bgp->vpn_policy[afi].tovpn_rd_pretty);
c4f64ea9 17385
ddb5b488
PZ
17386 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17387 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
17388
17389 char buf[PREFIX_STRLEN];
17390 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
17391 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
17392 sizeof(buf))) {
17393
b9c7bc5a
PZ
17394 vty_out(vty, "%*snexthop vpn export %s\n",
17395 indent, "", buf);
ddb5b488
PZ
17396 }
17397 }
17398 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
17399 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
17400 && ecommunity_cmp(
17401 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17402 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
17403
17404 char *b = ecommunity_ecom2str(
17405 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17406 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17407 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
17408 XFREE(MTYPE_ECOMMUNITY_STR, b);
17409 } else {
17410 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
17411 char *b = ecommunity_ecom2str(
17412 bgp->vpn_policy[afi]
17413 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17414 ECOMMUNITY_FORMAT_ROUTE_MAP,
17415 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17416 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
17417 XFREE(MTYPE_ECOMMUNITY_STR, b);
17418 }
17419 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
17420 char *b = ecommunity_ecom2str(
17421 bgp->vpn_policy[afi]
17422 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17423 ECOMMUNITY_FORMAT_ROUTE_MAP,
17424 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17425 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
17426 XFREE(MTYPE_ECOMMUNITY_STR, b);
17427 }
17428 }
bb4f6190
DS
17429
17430 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 17431 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
17432 bgp->vpn_policy[afi]
17433 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 17434
301ad80a
PG
17435 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
17436 char *b = ecommunity_ecom2str(
17437 bgp->vpn_policy[afi]
17438 .import_redirect_rtlist,
17439 ECOMMUNITY_FORMAT_ROUTE_MAP,
17440 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 17441
9a659715
PG
17442 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
17443 != ECOMMUNITY_SIZE)
c6423c31 17444 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
17445 indent, "", b);
17446 else
17447 vty_out(vty, "%*srt redirect import %s\n",
17448 indent, "", b);
301ad80a
PG
17449 XFREE(MTYPE_ECOMMUNITY_STR, b);
17450 }
ddb5b488
PZ
17451}
17452
dd65f45e
DL
17453static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
17454 afi_t afi, safi_t safi)
17455{
17456 struct bgp_filter *filter;
17457 char *addr;
17458
17459 addr = peer->host;
17460 filter = &peer->filter[afi][safi];
17461
17462 /* distribute-list. */
17463 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17464 FILTER_IN))
17465 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
17466 filter->dlist[FILTER_IN].name);
17467
17468 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17469 FILTER_OUT))
17470 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17471 filter->dlist[FILTER_OUT].name);
17472
17473 /* prefix-list. */
17474 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17475 FILTER_IN))
17476 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17477 filter->plist[FILTER_IN].name);
17478
17479 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17480 FILTER_OUT))
17481 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17482 filter->plist[FILTER_OUT].name);
17483
17484 /* route-map. */
17485 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17486 vty_out(vty, " neighbor %s route-map %s in\n", addr,
17487 filter->map[RMAP_IN].name);
17488
17489 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17490 RMAP_OUT))
17491 vty_out(vty, " neighbor %s route-map %s out\n", addr,
17492 filter->map[RMAP_OUT].name);
17493
17494 /* unsuppress-map */
17495 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17496 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17497 filter->usmap.name);
17498
7f7940e6
MK
17499 /* advertise-map : always applied in OUT direction*/
17500 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17501 CONDITION_NON_EXIST))
17502 vty_out(vty,
17503 " neighbor %s advertise-map %s non-exist-map %s\n",
17504 addr, filter->advmap.aname, filter->advmap.cname);
17505
17506 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17507 CONDITION_EXIST))
17508 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17509 addr, filter->advmap.aname, filter->advmap.cname);
17510
dd65f45e
DL
17511 /* filter-list. */
17512 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17513 FILTER_IN))
17514 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17515 filter->aslist[FILTER_IN].name);
17516
17517 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17518 FILTER_OUT))
17519 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17520 filter->aslist[FILTER_OUT].name);
17521}
17522
17523/* BGP peer configuration display function. */
17524static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17525 struct peer *peer)
17526{
17527 struct peer *g_peer = NULL;
dd65f45e
DL
17528 char *addr;
17529 int if_pg_printed = false;
17530 int if_ras_printed = false;
17531
17532 /* Skip dynamic neighbors. */
17533 if (peer_dynamic_neighbor(peer))
17534 return;
17535
17536 if (peer->conf_if)
17537 addr = peer->conf_if;
17538 else
17539 addr = peer->host;
17540
17541 /************************************
17542 ****** Global to the neighbor ******
17543 ************************************/
17544 if (peer->conf_if) {
17545 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17546 vty_out(vty, " neighbor %s interface v6only", addr);
17547 else
17548 vty_out(vty, " neighbor %s interface", addr);
17549
17550 if (peer_group_active(peer)) {
17551 vty_out(vty, " peer-group %s", peer->group->name);
17552 if_pg_printed = true;
17553 } else if (peer->as_type == AS_SPECIFIED) {
de76ed8a 17554 vty_out(vty, " remote-as %s", peer->as_pretty);
dd65f45e
DL
17555 if_ras_printed = true;
17556 } else if (peer->as_type == AS_INTERNAL) {
17557 vty_out(vty, " remote-as internal");
17558 if_ras_printed = true;
17559 } else if (peer->as_type == AS_EXTERNAL) {
17560 vty_out(vty, " remote-as external");
17561 if_ras_printed = true;
17562 }
17563
17564 vty_out(vty, "\n");
17565 }
17566
17567 /* remote-as and peer-group */
17568 /* peer is a member of a peer-group */
17569 if (peer_group_active(peer)) {
17570 g_peer = peer->group->conf;
17571
17572 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17573 if (peer->as_type == AS_SPECIFIED) {
de76ed8a
PG
17574 vty_out(vty, " neighbor %s remote-as %s\n",
17575 addr, peer->as_pretty);
dd65f45e
DL
17576 } else if (peer->as_type == AS_INTERNAL) {
17577 vty_out(vty,
17578 " neighbor %s remote-as internal\n",
17579 addr);
17580 } else if (peer->as_type == AS_EXTERNAL) {
17581 vty_out(vty,
17582 " neighbor %s remote-as external\n",
17583 addr);
17584 }
17585 }
17586
17587 /* For swpX peers we displayed the peer-group
17588 * via 'neighbor swpX interface peer-group PGNAME' */
17589 if (!if_pg_printed)
17590 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17591 peer->group->name);
17592 }
17593
17594 /* peer is NOT a member of a peer-group */
17595 else {
17596 /* peer is a peer-group, declare the peer-group */
17597 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17598 vty_out(vty, " neighbor %s peer-group\n", addr);
17599 }
17600
17601 if (!if_ras_printed) {
17602 if (peer->as_type == AS_SPECIFIED) {
de76ed8a
PG
17603 vty_out(vty, " neighbor %s remote-as %s\n",
17604 addr, peer->as_pretty);
dd65f45e
DL
17605 } else if (peer->as_type == AS_INTERNAL) {
17606 vty_out(vty,
17607 " neighbor %s remote-as internal\n",
17608 addr);
17609 } else if (peer->as_type == AS_EXTERNAL) {
17610 vty_out(vty,
17611 " neighbor %s remote-as external\n",
17612 addr);
17613 }
17614 }
17615 }
17616
17617 /* local-as */
17618 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
de76ed8a
PG
17619 vty_out(vty, " neighbor %s local-as %s", addr,
17620 peer->change_local_as_pretty);
dd65f45e
DL
17621 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17622 vty_out(vty, " no-prepend");
17623 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17624 vty_out(vty, " replace-as");
17625 vty_out(vty, "\n");
17626 }
17627
17628 /* description */
17629 if (peer->desc) {
17630 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17631 }
17632
17633 /* shutdown */
17634 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17635 if (peer->tx_shutdown_message)
17636 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17637 peer->tx_shutdown_message);
17638 else
17639 vty_out(vty, " neighbor %s shutdown\n", addr);
17640 }
17641
8336c896
DA
17642 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17643 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17644 peer->rtt_expected, peer->rtt_keepalive_conf);
17645
dd65f45e 17646 /* bfd */
21bfce98
RZ
17647 if (peer->bfd_config)
17648 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
17649
17650 /* password */
17651 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17652 vty_out(vty, " neighbor %s password %s\n", addr,
17653 peer->password);
17654
17655 /* neighbor solo */
17656 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17657 if (!peer_group_active(peer)) {
17658 vty_out(vty, " neighbor %s solo\n", addr);
17659 }
17660 }
17661
17662 /* BGP port */
17663 if (peer->port != BGP_PORT_DEFAULT) {
17664 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17665 }
17666
17667 /* Local interface name */
17668 if (peer->ifname) {
17669 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17670 }
17671
4ab46701
AR
17672 /* TCP max segment size */
17673 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17674 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17675
dd65f45e
DL
17676 /* passive */
17677 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17678 vty_out(vty, " neighbor %s passive\n", addr);
17679
17680 /* ebgp-multihop */
17681 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
17682 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17683 && peer->ttl == MAXTTL)) {
dd65f45e
DL
17684 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17685 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17686 peer->ttl);
17687 }
17688 }
17689
97a52c82
DA
17690 /* aigp */
17691 if (peergroup_flag_check(peer, PEER_FLAG_AIGP))
17692 vty_out(vty, " neighbor %s aigp\n", addr);
17693
4f770cf1
DA
17694 /* graceful-shutdown */
17695 if (peergroup_flag_check(peer, PEER_FLAG_GRACEFUL_SHUTDOWN))
17696 vty_out(vty, " neighbor %s graceful-shutdown\n", addr);
17697
d864dd9e 17698 /* role */
7dddd1f7
DA
17699 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17700 peer->local_role != ROLE_UNDEFINED)
d864dd9e 17701 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
8f2d6021 17702 bgp_get_name_by_role(peer->local_role),
7dddd1f7 17703 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
d864dd9e
EB
17704 ? " strict-mode"
17705 : "");
d864dd9e 17706
dd65f45e 17707 /* ttl-security hops */
e2521429 17708 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
17709 if (!peer_group_active(peer)
17710 || g_peer->gtsm_hops != peer->gtsm_hops) {
17711 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17712 addr, peer->gtsm_hops);
17713 }
17714 }
17715
17716 /* disable-connected-check */
17717 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17718 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17719
27aa23a4
DA
17720 /* link-bw-encoding-ieee */
17721 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17722 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17723 addr);
17724
d08c0c80
DA
17725 /* extended-optional-parameters */
17726 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17727 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17728 addr);
17729
dd65f45e
DL
17730 /* enforce-first-as */
17731 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17732 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17733
17734 /* update-source */
17735 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17736 if (peer->update_source)
47e12884
DA
17737 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17738 peer->update_source);
dd65f45e
DL
17739 else if (peer->update_if)
17740 vty_out(vty, " neighbor %s update-source %s\n", addr,
17741 peer->update_if);
17742 }
17743
17744 /* advertisement-interval */
17745 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17746 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17747 peer->routeadv);
17748
17749 /* timers */
17750 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17751 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17752 peer->keepalive, peer->holdtime);
17753
17754 /* timers connect */
17755 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17756 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17757 peer->connect);
5d5393b9
DL
17758 /* need special-case handling for changed default values due to
17759 * config profile / version (because there is no "timers bgp connect"
17760 * command, we need to save this per-peer :/)
17761 */
17762 else if (!peer_group_active(peer) && !peer->connect &&
17763 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17764 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17765 peer->bgp->default_connect_retry);
dd65f45e 17766
d43114f3
DS
17767 /* timers delayopen */
17768 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17769 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17770 peer->delayopen);
17771 /* Save config even though flag is not set if default values have been
17772 * changed
17773 */
17774 else if (!peer_group_active(peer) && !peer->delayopen
17775 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17776 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17777 peer->bgp->default_delayopen);
17778
dd65f45e
DL
17779 /* capability dynamic */
17780 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17781 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17782
17783 /* capability extended-nexthop */
17784 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
8e89adc1
DS
17785 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17786 !peer->conf_if)
843770f6
DA
17787 vty_out(vty,
17788 " no neighbor %s capability extended-nexthop\n",
17789 addr);
17790 else if (!peer->conf_if)
17791 vty_out(vty,
17792 " neighbor %s capability extended-nexthop\n",
17793 addr);
dd65f45e
DL
17794 }
17795
234f6fd4
DA
17796 /* capability software-version */
17797 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_SOFT_VERSION))
17798 vty_out(vty, " neighbor %s capability software-version\n",
17799 addr);
17800
dd65f45e
DL
17801 /* dont-capability-negotiation */
17802 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17803 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17804
17805 /* override-capability */
17806 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17807 vty_out(vty, " neighbor %s override-capability\n", addr);
17808
17809 /* strict-capability-match */
17810 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17811 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17812
17813 /* Sender side AS path loop detection. */
17814 if (peer->as_path_loop_detection)
17815 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17816 addr);
cfd47646 17817
a5c6a9b1
DA
17818 /* path-attribute discard */
17819 char discard_attrs_str[BUFSIZ] = {0};
17820 bool discard_attrs = bgp_path_attribute_discard(
17821 peer, discard_attrs_str, sizeof(discard_attrs_str));
17822
17823 if (discard_attrs)
17824 vty_out(vty, " neighbor %s path-attribute discard %s\n", addr,
17825 discard_attrs_str);
17826
e2863b4f
DA
17827 /* path-attribute treat-as-withdraw */
17828 char withdraw_attrs_str[BUFSIZ] = {0};
17829 bool withdraw_attrs = bgp_path_attribute_treat_as_withdraw(
17830 peer, withdraw_attrs_str, sizeof(withdraw_attrs_str));
17831
17832 if (withdraw_attrs)
17833 vty_out(vty,
17834 " neighbor %s path-attribute treat-as-withdraw %s\n",
17835 addr, withdraw_attrs_str);
17836
cfd47646 17837 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17838 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 17839
17840 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17841 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 17842 vty_out(vty,
17843 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
17844 } else if (CHECK_FLAG(
17845 peer->peer_gr_new_status_flag,
17846 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 17847 vty_out(vty,
17848 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
17849 } else if (
17850 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17851 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17852 && !(CHECK_FLAG(
17853 peer->peer_gr_new_status_flag,
17854 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17855 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17856 addr);
cfd47646 17857 }
17858 }
dd65f45e
DL
17859}
17860
17861/* BGP peer configuration display function. */
17862static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17863 struct peer *peer, afi_t afi, safi_t safi)
17864{
17865 struct peer *g_peer = NULL;
17866 char *addr;
17867 bool flag_scomm, flag_secomm, flag_slcomm;
17868
17869 /* Skip dynamic neighbors. */
17870 if (peer_dynamic_neighbor(peer))
17871 return;
17872
17873 if (peer->conf_if)
17874 addr = peer->conf_if;
17875 else
17876 addr = peer->host;
17877
17878 /************************************
17879 ****** Per AF to the neighbor ******
17880 ************************************/
17881 if (peer_group_active(peer)) {
17882 g_peer = peer->group->conf;
17883
17884 /* If the peer-group is active but peer is not, print a 'no
17885 * activate' */
17886 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17887 vty_out(vty, " no neighbor %s activate\n", addr);
17888 }
17889
17890 /* If the peer-group is not active but peer is, print an
17891 'activate' */
17892 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17893 vty_out(vty, " neighbor %s activate\n", addr);
17894 }
17895 } else {
17896 if (peer->afc[afi][safi]) {
38d11af5
TA
17897 if (safi == SAFI_ENCAP)
17898 vty_out(vty, " neighbor %s activate\n", addr);
17899 else if (!bgp->default_af[afi][safi])
dd65f45e
DL
17900 vty_out(vty, " neighbor %s activate\n", addr);
17901 } else {
38d11af5
TA
17902 if (bgp->default_af[afi][safi])
17903 vty_out(vty, " no neighbor %s activate\n",
17904 addr);
dd65f45e
DL
17905 }
17906 }
17907
17908 /* addpath TX knobs */
17909 if (peergroup_af_addpath_check(peer, afi, safi)) {
17910 switch (peer->addpath_type[afi][safi]) {
17911 case BGP_ADDPATH_ALL:
17912 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17913 addr);
17914 break;
17915 case BGP_ADDPATH_BEST_PER_AS:
17916 vty_out(vty,
17917 " neighbor %s addpath-tx-bestpath-per-AS\n",
17918 addr);
17919 break;
17920 case BGP_ADDPATH_MAX:
17921 case BGP_ADDPATH_NONE:
17922 break;
17923 }
17924 }
17925
7c0e4312
DA
17926 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17927 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17928
dd65f45e
DL
17929 /* ORF capability. */
17930 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17931 || peergroup_af_flag_check(peer, afi, safi,
17932 PEER_FLAG_ORF_PREFIX_RM)) {
17933 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17934
17935 if (peergroup_af_flag_check(peer, afi, safi,
17936 PEER_FLAG_ORF_PREFIX_SM)
17937 && peergroup_af_flag_check(peer, afi, safi,
17938 PEER_FLAG_ORF_PREFIX_RM))
17939 vty_out(vty, " both");
17940 else if (peergroup_af_flag_check(peer, afi, safi,
17941 PEER_FLAG_ORF_PREFIX_SM))
17942 vty_out(vty, " send");
17943 else
17944 vty_out(vty, " receive");
17945 vty_out(vty, "\n");
17946 }
17947
dd65f45e
DL
17948 /* Route reflector client. */
17949 if (peergroup_af_flag_check(peer, afi, safi,
17950 PEER_FLAG_REFLECTOR_CLIENT)) {
17951 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17952 }
17953
17954 /* next-hop-self force */
17955 if (peergroup_af_flag_check(peer, afi, safi,
17956 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17957 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17958 }
17959
17960 /* next-hop-self */
17961 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17962 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17963 }
17964
17965 /* remove-private-AS */
17966 if (peergroup_af_flag_check(peer, afi, safi,
17967 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17968 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17969 addr);
17970 }
17971
17972 else if (peergroup_af_flag_check(peer, afi, safi,
17973 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17974 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17975 addr);
17976 }
17977
17978 else if (peergroup_af_flag_check(peer, afi, safi,
17979 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17980 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17981 }
17982
17983 else if (peergroup_af_flag_check(peer, afi, safi,
17984 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17985 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17986 }
17987
17988 /* as-override */
17989 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17990 vty_out(vty, " neighbor %s as-override\n", addr);
17991 }
17992
17993 /* send-community print. */
17994 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17995 PEER_FLAG_SEND_COMMUNITY);
17996 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17997 PEER_FLAG_SEND_EXT_COMMUNITY);
17998 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17999 PEER_FLAG_SEND_LARGE_COMMUNITY);
18000
18001 if (flag_scomm && flag_secomm && flag_slcomm) {
18002 vty_out(vty, " no neighbor %s send-community all\n", addr);
18003 } else {
18004 if (flag_scomm)
18005 vty_out(vty, " no neighbor %s send-community\n", addr);
18006 if (flag_secomm)
18007 vty_out(vty,
18008 " no neighbor %s send-community extended\n",
18009 addr);
18010
18011 if (flag_slcomm)
18012 vty_out(vty, " no neighbor %s send-community large\n",
18013 addr);
18014 }
18015
18016 /* Default information */
18017 if (peergroup_af_flag_check(peer, afi, safi,
18018 PEER_FLAG_DEFAULT_ORIGINATE)) {
18019 vty_out(vty, " neighbor %s default-originate", addr);
18020
18021 if (peer->default_rmap[afi][safi].name)
18022 vty_out(vty, " route-map %s",
18023 peer->default_rmap[afi][safi].name);
18024
18025 vty_out(vty, "\n");
18026 }
18027
18028 /* Soft reconfiguration inbound. */
18029 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
18030 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
18031 addr);
18032 }
18033
18034 /* maximum-prefix. */
18035 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 18036 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
18037 peer->pmax[afi][safi]);
18038
18039 if (peer->pmax_threshold[afi][safi]
18040 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
18041 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
18042 if (peer_af_flag_check(peer, afi, safi,
18043 PEER_FLAG_MAX_PREFIX_WARNING))
18044 vty_out(vty, " warning-only");
18045 if (peer->pmax_restart[afi][safi])
18046 vty_out(vty, " restart %u",
18047 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
18048 if (peer_af_flag_check(peer, afi, safi,
18049 PEER_FLAG_MAX_PREFIX_FORCE))
18050 vty_out(vty, " force");
dd65f45e
DL
18051
18052 vty_out(vty, "\n");
18053 }
18054
fde246e8
DA
18055 /* maximum-prefix-out */
18056 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 18057 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
18058 addr, peer->pmax_out[afi][safi]);
18059
dd65f45e
DL
18060 /* Route server client. */
18061 if (peergroup_af_flag_check(peer, afi, safi,
18062 PEER_FLAG_RSERVER_CLIENT)) {
18063 vty_out(vty, " neighbor %s route-server-client\n", addr);
18064 }
18065
18066 /* Nexthop-local unchanged. */
18067 if (peergroup_af_flag_check(peer, afi, safi,
18068 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
18069 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
18070 }
18071
18072 /* allowas-in <1-10> */
18073 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
18074 if (peer_af_flag_check(peer, afi, safi,
18075 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
18076 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
18077 } else if (peer->allowas_in[afi][safi] == 3) {
18078 vty_out(vty, " neighbor %s allowas-in\n", addr);
18079 } else {
18080 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
18081 peer->allowas_in[afi][safi]);
18082 }
18083 }
18084
46dbf9d0
DA
18085 /* accept-own */
18086 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
18087 vty_out(vty, " neighbor %s accept-own\n", addr);
18088
01da2d26
DA
18089 /* soo */
18090 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
18091 char *soo_str = ecommunity_ecom2str(
18092 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
18093
18094 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
18095 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
18096 }
18097
dd65f45e
DL
18098 /* weight */
18099 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
18100 vty_out(vty, " neighbor %s weight %lu\n", addr,
18101 peer->weight[afi][safi]);
18102
18103 /* Filter. */
18104 bgp_config_write_filter(vty, peer, afi, safi);
18105
18106 /* atribute-unchanged. */
18107 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
18108 || (safi != SAFI_EVPN
18109 && peer_af_flag_check(peer, afi, safi,
18110 PEER_FLAG_NEXTHOP_UNCHANGED))
18111 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
18112
18113 if (!peer_group_active(peer)
18114 || peergroup_af_flag_check(peer, afi, safi,
18115 PEER_FLAG_AS_PATH_UNCHANGED)
18116 || peergroup_af_flag_check(peer, afi, safi,
18117 PEER_FLAG_NEXTHOP_UNCHANGED)
18118 || peergroup_af_flag_check(peer, afi, safi,
18119 PEER_FLAG_MED_UNCHANGED)) {
18120
18121 vty_out(vty,
18122 " neighbor %s attribute-unchanged%s%s%s\n",
18123 addr,
18124 peer_af_flag_check(peer, afi, safi,
18125 PEER_FLAG_AS_PATH_UNCHANGED)
18126 ? " as-path"
18127 : "",
18128 peer_af_flag_check(peer, afi, safi,
18129 PEER_FLAG_NEXTHOP_UNCHANGED)
18130 ? " next-hop"
18131 : "",
18132 peer_af_flag_check(peer, afi, safi,
18133 PEER_FLAG_MED_UNCHANGED)
18134 ? " med"
18135 : "");
18136 }
18137 }
18138}
18139
a486300b
PG
18140static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
18141 safi_t safi)
18142{
18143 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
18144 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
18145 vty_out(vty, " no bgp retain route-target all\n");
18146}
18147
dd65f45e
DL
18148/* Address family based peer configuration display. */
18149static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
18150 safi_t safi)
18151{
18152 struct peer *peer;
18153 struct peer_group *group;
18154 struct listnode *node, *nnode;
18155
18156
18157 vty_frame(vty, " !\n address-family ");
18158 if (afi == AFI_IP) {
18159 if (safi == SAFI_UNICAST)
18160 vty_frame(vty, "ipv4 unicast");
18161 else if (safi == SAFI_LABELED_UNICAST)
18162 vty_frame(vty, "ipv4 labeled-unicast");
18163 else if (safi == SAFI_MULTICAST)
18164 vty_frame(vty, "ipv4 multicast");
18165 else if (safi == SAFI_MPLS_VPN)
18166 vty_frame(vty, "ipv4 vpn");
18167 else if (safi == SAFI_ENCAP)
18168 vty_frame(vty, "ipv4 encap");
18169 else if (safi == SAFI_FLOWSPEC)
18170 vty_frame(vty, "ipv4 flowspec");
18171 } else if (afi == AFI_IP6) {
18172 if (safi == SAFI_UNICAST)
18173 vty_frame(vty, "ipv6 unicast");
18174 else if (safi == SAFI_LABELED_UNICAST)
18175 vty_frame(vty, "ipv6 labeled-unicast");
18176 else if (safi == SAFI_MULTICAST)
18177 vty_frame(vty, "ipv6 multicast");
18178 else if (safi == SAFI_MPLS_VPN)
18179 vty_frame(vty, "ipv6 vpn");
18180 else if (safi == SAFI_ENCAP)
18181 vty_frame(vty, "ipv6 encap");
18182 else if (safi == SAFI_FLOWSPEC)
18183 vty_frame(vty, "ipv6 flowspec");
18184 } else if (afi == AFI_L2VPN) {
18185 if (safi == SAFI_EVPN)
18186 vty_frame(vty, "l2vpn evpn");
18187 }
18188 vty_frame(vty, "\n");
18189
18190 bgp_config_write_distance(vty, bgp, afi, safi);
18191
18192 bgp_config_write_network(vty, bgp, afi, safi);
18193
18194 bgp_config_write_redistribute(vty, bgp, afi, safi);
18195
8a4e7fe6
DA
18196 /* BGP flag dampening. */
18197 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6c75f4b3 18198 bgp_config_write_damp(vty, afi, safi);
8a4e7fe6 18199
dd65f45e
DL
18200 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
18201 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
18202
18203 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
18204 /* Do not display doppelganger peers */
18205 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18206 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
18207 }
18208
18209 bgp_config_write_maxpaths(vty, bgp, afi, safi);
18210 bgp_config_write_table_map(vty, bgp, afi, safi);
18211
18212 if (safi == SAFI_EVPN)
18213 bgp_config_write_evpn_info(vty, bgp, afi, safi);
18214
18215 if (safi == SAFI_FLOWSPEC)
18216 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
18217
a486300b
PG
18218 if (safi == SAFI_MPLS_VPN)
18219 bgp_vpn_config_write(vty, bgp, afi, safi);
18220
dd65f45e
DL
18221 if (safi == SAFI_UNICAST) {
18222 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
18223 if (CHECK_FLAG(bgp->af_flags[afi][safi],
18224 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
18225
18226 vty_out(vty, " export vpn\n");
18227 }
18228 if (CHECK_FLAG(bgp->af_flags[afi][safi],
18229 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
18230
18231 vty_out(vty, " import vpn\n");
18232 }
18233 if (CHECK_FLAG(bgp->af_flags[afi][safi],
18234 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
18235 char *name;
18236
18237 for (ALL_LIST_ELEMENTS_RO(
18238 bgp->vpn_policy[afi].import_vrf, node,
18239 name))
18240 vty_out(vty, " import vrf %s\n", name);
18241 }
18242 }
18243
18244 vty_endframe(vty, " exit-address-family\n");
18245}
18246
18247int bgp_config_write(struct vty *vty)
18248{
18249 struct bgp *bgp;
18250 struct peer_group *group;
18251 struct peer *peer;
18252 struct listnode *node, *nnode;
18253 struct listnode *mnode, *mnnode;
b16bcbba
TA
18254 afi_t afi;
18255 safi_t safi;
efc9b57d 18256 uint32_t tovpn_sid_index = 0;
dd65f45e
DL
18257
18258 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
18259 vty_out(vty, "bgp route-map delay-timer %u\n",
18260 bm->rmap_update_timer);
18261
d70583f7
D
18262 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
18263 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
18264 if (bm->v_update_delay != bm->v_establish_wait)
18265 vty_out(vty, " %d", bm->v_establish_wait);
18266 vty_out(vty, "\n");
18267 }
18268
9acb67cb
DS
18269 if (bm->wait_for_fib)
18270 vty_out(vty, "bgp suppress-fib-pending\n");
18271
05bd726c 18272 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18273 vty_out(vty, "bgp graceful-shutdown\n");
18274
c163f297
DS
18275 /* No-RIB (Zebra) option flag configuration */
18276 if (bgp_option_check(BGP_OPT_NO_FIB))
18277 vty_out(vty, "bgp no-rib\n");
18278
870791a3
IR
18279 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
18280 vty_out(vty, "bgp send-extra-data zebra\n");
e46723a5 18281
425bd64b
PS
18282 /* BGP session DSCP value */
18283 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
18284 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
18285
a0b937de 18286 /* BGP InQ limit */
963b7ee4 18287 if (bm->inq_limit != BM_DEFAULT_Q_LIMIT)
a0b937de
SW
18288 vty_out(vty, "bgp input-queue-limit %u\n", bm->inq_limit);
18289
963b7ee4
DS
18290 if (bm->outq_limit != BM_DEFAULT_Q_LIMIT)
18291 vty_out(vty, "bgp output-queue-limit %u\n", bm->outq_limit);
18292
dd65f45e
DL
18293 /* BGP configuration. */
18294 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
18295
18296 /* skip all auto created vrf as they dont have user config */
18297 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
18298 continue;
18299
18300 /* Router bgp ASN */
9eb11997 18301 vty_out(vty, "router bgp %s", bgp->as_pretty);
dd65f45e
DL
18302
18303 if (bgp->name)
18304 vty_out(vty, " %s %s",
18305 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
18306 ? "view" : "vrf", bgp->name);
e55b0883
PG
18307 if (CHECK_FLAG(bgp->config, BGP_CONFIG_ASNOTATION))
18308 vty_out(vty, " as-notation %s",
18309 asn_mode2str(bgp->asnotation));
18310
dd65f45e
DL
18311 vty_out(vty, "\n");
18312
18313 /* BGP fast-external-failover. */
18314 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
18315 vty_out(vty, " no bgp fast-external-failover\n");
18316
18317 /* BGP router ID. */
3a6290bd 18318 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
18319 vty_out(vty, " bgp router-id %pI4\n",
18320 &bgp->router_id_static);
dd65f45e 18321
c208c586
S
18322 /* Suppress fib pending */
18323 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
18324 vty_out(vty, " bgp suppress-fib-pending\n");
18325
dd65f45e 18326 /* BGP log-neighbor-changes. */
892fedb6 18327 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 18328 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 18329 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
18330 CHECK_FLAG(bgp->flags,
18331 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
18332 ? ""
18333 : "no ");
18334
18335 /* BGP configuration. */
892fedb6 18336 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
18337 vty_out(vty, " bgp always-compare-med\n");
18338
18339 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
18340 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
18341 != SAVE_BGP_EBGP_REQUIRES_POLICY)
18342 vty_out(vty, " %sbgp ebgp-requires-policy\n",
18343 CHECK_FLAG(bgp->flags,
18344 BGP_FLAG_EBGP_REQUIRES_POLICY)
18345 ? ""
18346 : "no ");
dd65f45e 18347
cf1c7e30
PG
18348 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_IPV4_EXPLICIT_NULL) &&
18349 !!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_IPV6_EXPLICIT_NULL))
7ee70320 18350 vty_out(vty, " bgp labeled-unicast explicit-null\n");
cf1c7e30
PG
18351 else if (!!CHECK_FLAG(bgp->flags,
18352 BGP_FLAG_LU_IPV4_EXPLICIT_NULL))
18353 vty_out(vty,
18354 " bgp labeled-unicast ipv4-explicit-null\n");
18355 else if (!!CHECK_FLAG(bgp->flags,
18356 BGP_FLAG_LU_IPV6_EXPLICIT_NULL))
18357 vty_out(vty,
18358 " bgp labeled-unicast ipv6-explicit-null\n");
7ee70320 18359
dd65f45e 18360 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 18361 if (bgp->reject_as_sets)
dd65f45e
DL
18362 vty_out(vty, " bgp reject-as-sets\n");
18363
2adac256
DA
18364 /* Suppress duplicate updates if the route actually not changed
18365 */
18366 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
18367 != SAVE_BGP_SUPPRESS_DUPLICATES)
18368 vty_out(vty, " %sbgp suppress-duplicates\n",
18369 CHECK_FLAG(bgp->flags,
18370 BGP_FLAG_SUPPRESS_DUPLICATES)
18371 ? ""
18372 : "no ");
18373
1ae314be
DA
18374 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
18375 */
18376 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
18377 SAVE_BGP_HARD_ADMIN_RESET)
18378 vty_out(vty, " %sbgp hard-administrative-reset\n",
18379 CHECK_FLAG(bgp->flags,
18380 BGP_FLAG_HARD_ADMIN_RESET)
18381 ? ""
18382 : "no ");
18383
b16bcbba
TA
18384 /* BGP default <afi>-<safi> */
18385 FOREACH_AFI_SAFI (afi, safi) {
18386 if (afi == AFI_IP && safi == SAFI_UNICAST) {
18387 if (!bgp->default_af[afi][safi])
18388 vty_out(vty, " no bgp default %s\n",
18389 get_bgp_default_af_flag(afi,
18390 safi));
18391 } else if (bgp->default_af[afi][safi])
18392 vty_out(vty, " bgp default %s\n",
18393 get_bgp_default_af_flag(afi, safi));
18394 }
e84c59af 18395
dd65f45e
DL
18396 /* BGP default local-preference. */
18397 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
18398 vty_out(vty, " bgp default local-preference %u\n",
18399 bgp->default_local_pref);
18400
18401 /* BGP default show-hostname */
892fedb6 18402 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 18403 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 18404 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 18405 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
18406 ? ""
18407 : "no ");
18408
aef999a2
DA
18409 /* BGP default show-nexthop-hostname */
18410 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18411 != SAVE_BGP_SHOW_HOSTNAME)
18412 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
18413 CHECK_FLAG(bgp->flags,
18414 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18415 ? ""
18416 : "no ");
18417
dd65f45e
DL
18418 /* BGP default subgroup-pkt-queue-max. */
18419 if (bgp->default_subgroup_pkt_queue_max
18420 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
18421 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
18422 bgp->default_subgroup_pkt_queue_max);
18423
18424 /* BGP client-to-client reflection. */
892fedb6 18425 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
18426 vty_out(vty, " no bgp client-to-client reflection\n");
18427
18428 /* BGP cluster ID. */
18429 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
18430 vty_out(vty, " bgp cluster-id %pI4\n",
18431 &bgp->cluster_id);
dd65f45e
DL
18432
18433 /* Disable ebgp connected nexthop check */
892fedb6 18434 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
18435 vty_out(vty,
18436 " bgp disable-ebgp-connected-route-check\n");
18437
18438 /* Confederation identifier*/
18439 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7e14d0fa
PG
18440 vty_out(vty, " bgp confederation identifier %s\n",
18441 bgp->confed_id_pretty);
dd65f45e
DL
18442
18443 /* Confederation peer */
18444 if (bgp->confed_peers_cnt > 0) {
18445 int i;
18446
18447 vty_out(vty, " bgp confederation peers");
18448
18449 for (i = 0; i < bgp->confed_peers_cnt; i++)
7e14d0fa
PG
18450 vty_out(vty, " %s",
18451 bgp->confed_peers[i].as_pretty);
dd65f45e
DL
18452
18453 vty_out(vty, "\n");
18454 }
18455
18456 /* BGP deterministic-med. */
892fedb6 18457 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 18458 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 18459 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
18460 CHECK_FLAG(bgp->flags,
18461 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
18462 ? ""
18463 : "no ");
18464
18465 /* BGP update-delay. */
18466 bgp_config_write_update_delay(vty, bgp);
18467
18468 if (bgp->v_maxmed_onstartup
18469 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
18470 vty_out(vty, " bgp max-med on-startup %u",
18471 bgp->v_maxmed_onstartup);
18472 if (bgp->maxmed_onstartup_value
18473 != BGP_MAXMED_VALUE_DEFAULT)
18474 vty_out(vty, " %u",
18475 bgp->maxmed_onstartup_value);
18476 vty_out(vty, "\n");
18477 }
18478 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
18479 vty_out(vty, " bgp max-med administrative");
18480 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
18481 vty_out(vty, " %u", bgp->maxmed_admin_value);
18482 vty_out(vty, "\n");
18483 }
18484
18485 /* write quanta */
18486 bgp_config_write_wpkt_quanta(vty, bgp);
18487 /* read quanta */
18488 bgp_config_write_rpkt_quanta(vty, bgp);
18489
18490 /* coalesce time */
18491 bgp_config_write_coalesce_time(vty, bgp);
18492
05bd726c 18493 /* BGP per-instance graceful-shutdown */
18494 /* BGP-wide settings and per-instance settings are mutually
18495 * exclusive.
18496 */
18497 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18498 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
18499 vty_out(vty, " bgp graceful-shutdown\n");
18500
8606be87
DA
18501 /* Long-lived Graceful Restart */
18502 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
18503 vty_out(vty,
18504 " bgp long-lived-graceful-restart stale-time %u\n",
18505 bgp->llgr_stale_time);
18506
dd65f45e
DL
18507 /* BGP graceful-restart. */
18508 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
18509 vty_out(vty,
18510 " bgp graceful-restart stalepath-time %u\n",
18511 bgp->stalepath_time);
cfd47646 18512
dd65f45e
DL
18513 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18514 vty_out(vty, " bgp graceful-restart restart-time %u\n",
18515 bgp->restart_time);
cfd47646 18516
f2ca5c5b
DA
18517 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
18518 SAVE_BGP_GRACEFUL_NOTIFICATION)
18519 vty_out(vty, " %sbgp graceful-restart notification\n",
18520 CHECK_FLAG(bgp->flags,
18521 BGP_FLAG_GRACEFUL_NOTIFICATION)
18522 ? ""
18523 : "no ");
18524
cfd47646 18525 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18526 vty_out(vty,
18527 " bgp graceful-restart select-defer-time %u\n",
18528 bgp->select_defer_time);
18529
18530 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
18531 vty_out(vty, " bgp graceful-restart\n");
18532
cfd47646 18533 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18534 vty_out(vty, " bgp graceful-restart-disable\n");
18535
dd65f45e 18536 /* BGP graceful-restart Preserve State F bit. */
892fedb6 18537 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
18538 vty_out(vty,
18539 " bgp graceful-restart preserve-fw-state\n");
18540
d1adb448
PG
18541 /* BGP TCP keepalive */
18542 bgp_config_tcp_keepalive(vty, bgp);
18543
dc95985f 18544 /* Stale timer for RIB */
18545 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18546 vty_out(vty,
18547 " bgp graceful-restart rib-stale-time %u\n",
18548 bgp->rib_stale_time);
18549
dd65f45e 18550 /* BGP bestpath method. */
892fedb6 18551 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 18552 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 18553 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
18554 vty_out(vty, " bgp bestpath as-path confed\n");
18555
892fedb6
DA
18556 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18557 if (CHECK_FLAG(bgp->flags,
18558 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
18559 vty_out(vty,
18560 " bgp bestpath as-path multipath-relax as-set\n");
18561 } else {
18562 vty_out(vty,
18563 " bgp bestpath as-path multipath-relax\n");
18564 }
18565 }
18566
892fedb6 18567 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
18568 vty_out(vty,
18569 " bgp route-reflector allow-outbound-policy\n");
18570 }
892fedb6 18571 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 18572 vty_out(vty, " bgp bestpath compare-routerid\n");
97a52c82
DA
18573 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP))
18574 vty_out(vty, " bgp bestpath aigp\n");
892fedb6
DA
18575 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18576 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 18577 vty_out(vty, " bgp bestpath med");
892fedb6 18578 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 18579 vty_out(vty, " confed");
892fedb6
DA
18580 if (CHECK_FLAG(bgp->flags,
18581 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
18582 vty_out(vty, " missing-as-worst");
18583 vty_out(vty, "\n");
18584 }
18585
ee88563a
JM
18586 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18587 vty_out(vty,
18588 " bgp bestpath peer-type multipath-relax\n");
18589
f7e1c681 18590 /* Link bandwidth handling. */
18591 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18592 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18593 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18594 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18595 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18596 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18597
dd65f45e 18598 /* BGP network import check. */
892fedb6 18599 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 18600 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 18601 vty_out(vty, " %sbgp network import-check\n",
892fedb6 18602 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
18603 ? ""
18604 : "no ");
18605
18606 /* BGP timers configuration. */
5d5393b9 18607 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 18608 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
18609 vty_out(vty, " timers bgp %u %u\n",
18610 bgp->default_keepalive, bgp->default_holdtime);
18611
b042667a
TI
18612 /* BGP minimum holdtime configuration. */
18613 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
18614 && bgp->default_min_holdtime != 0)
18615 vty_out(vty, " bgp minimum-holdtime %u\n",
18616 bgp->default_min_holdtime);
18617
389e4f92
QY
18618 /* Conditional advertisement timer configuration */
18619 if (bgp->condition_check_period
18620 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
18621 vty_out(vty,
18622 " bgp conditional-advertisement timer %u\n",
18623 bgp->condition_check_period);
18624
dd65f45e
DL
18625 /* peer-group */
18626 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18627 bgp_config_write_peer_global(vty, bgp, group->conf);
18628 }
18629
18630 /* Normal neighbor configuration. */
18631 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18632 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18633 bgp_config_write_peer_global(vty, bgp, peer);
18634 }
18635
18636 /* listen range and limit for dynamic BGP neighbors */
18637 bgp_config_write_listen(vty, bgp);
18638
18639 /*
18640 * BGP default autoshutdown neighbors
18641 *
18642 * This must be placed after any peer and peer-group
18643 * configuration, to avoid setting all peers to shutdown after
18644 * a daemon restart, which is undesired behavior. (see #2286)
18645 */
18646 if (bgp->autoshutdown)
18647 vty_out(vty, " bgp default shutdown\n");
18648
9cf59432
DS
18649 /* BGP instance administrative shutdown */
18650 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18651 vty_out(vty, " bgp shutdown\n");
18652
8666265e
DS
18653 if (bgp->allow_martian)
18654 vty_out(vty, " bgp allow-martian-nexthop\n");
18655
f852eb98
PG
18656 if (bgp->fast_convergence)
18657 vty_out(vty, " bgp fast-convergence\n");
18658
a0281b2e
HS
18659 if (bgp->srv6_enabled) {
18660 vty_frame(vty, " !\n segment-routing srv6\n");
96db4340 18661 if (strlen(bgp->srv6_locator_name))
a0281b2e
HS
18662 vty_out(vty, " locator %s\n",
18663 bgp->srv6_locator_name);
ff7c3ee1 18664 vty_endframe(vty, " exit\n");
a0281b2e
HS
18665 }
18666
efc9b57d
CS
18667 tovpn_sid_index = bgp->tovpn_sid_index;
18668 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
18669 vty_out(vty, " sid vpn per-vrf export auto\n");
18670 } else if (tovpn_sid_index != 0) {
18671 vty_out(vty, " sid vpn per-vrf export %d\n",
18672 tovpn_sid_index);
18673 }
a0281b2e 18674
dd65f45e
DL
18675 /* IPv4 unicast configuration. */
18676 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18677
18678 /* IPv4 multicast configuration. */
18679 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18680
18681 /* IPv4 labeled-unicast configuration. */
18682 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18683
18684 /* IPv4 VPN configuration. */
18685 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18686
18687 /* ENCAPv4 configuration. */
18688 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18689
18690 /* FLOWSPEC v4 configuration. */
18691 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18692
18693 /* IPv6 unicast configuration. */
18694 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18695
18696 /* IPv6 multicast configuration. */
18697 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18698
18699 /* IPv6 labeled-unicast configuration. */
18700 bgp_config_write_family(vty, bgp, AFI_IP6,
18701 SAFI_LABELED_UNICAST);
18702
18703 /* IPv6 VPN configuration. */
18704 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18705
18706 /* ENCAPv6 configuration. */
18707 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18708
18709 /* FLOWSPEC v6 configuration. */
18710 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18711
18712 /* EVPN configuration. */
18713 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18714
18715 hook_call(bgp_inst_config_write, bgp, vty);
18716
49e5a4a0 18717#ifdef ENABLE_BGP_VNC
dd65f45e
DL
18718 bgp_rfapi_cfg_write(vty, bgp);
18719#endif
18720
07679ad9 18721 vty_out(vty, "exit\n");
dd65f45e
DL
18722 vty_out(vty, "!\n");
18723 }
18724 return 0;
18725}
18726
ddb5b488 18727
718e3744 18728/* BGP node structure. */
d62a17ae 18729static struct cmd_node bgp_node = {
f4b8291f 18730 .name = "bgp",
62b346ee 18731 .node = BGP_NODE,
24389580 18732 .parent_node = CONFIG_NODE,
62b346ee 18733 .prompt = "%s(config-router)# ",
612c2c15 18734 .config_write = bgp_config_write,
718e3744 18735};
18736
d62a17ae 18737static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 18738 .name = "bgp ipv4 unicast",
62b346ee 18739 .node = BGP_IPV4_NODE,
24389580 18740 .parent_node = BGP_NODE,
62b346ee 18741 .prompt = "%s(config-router-af)# ",
dd2c81b8 18742 .no_xpath = true,
718e3744 18743};
18744
d62a17ae 18745static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 18746 .name = "bgp ipv4 multicast",
62b346ee 18747 .node = BGP_IPV4M_NODE,
24389580 18748 .parent_node = BGP_NODE,
62b346ee 18749 .prompt = "%s(config-router-af)# ",
dd2c81b8 18750 .no_xpath = true,
718e3744 18751};
18752
d62a17ae 18753static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 18754 .name = "bgp ipv4 labeled unicast",
62b346ee 18755 .node = BGP_IPV4L_NODE,
24389580 18756 .parent_node = BGP_NODE,
62b346ee 18757 .prompt = "%s(config-router-af)# ",
dd2c81b8 18758 .no_xpath = true,
f51bae9c
DS
18759};
18760
d62a17ae 18761static struct cmd_node bgp_ipv6_unicast_node = {
a17cfb3f 18762 .name = "bgp ipv6 unicast",
62b346ee 18763 .node = BGP_IPV6_NODE,
24389580 18764 .parent_node = BGP_NODE,
62b346ee 18765 .prompt = "%s(config-router-af)# ",
dd2c81b8 18766 .no_xpath = true,
718e3744 18767};
18768
d62a17ae 18769static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 18770 .name = "bgp ipv6 multicast",
62b346ee 18771 .node = BGP_IPV6M_NODE,
24389580 18772 .parent_node = BGP_NODE,
62b346ee 18773 .prompt = "%s(config-router-af)# ",
dd2c81b8 18774 .no_xpath = true,
25ffbdc1 18775};
18776
d62a17ae 18777static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 18778 .name = "bgp ipv6 labeled unicast",
62b346ee 18779 .node = BGP_IPV6L_NODE,
24389580 18780 .parent_node = BGP_NODE,
62b346ee 18781 .prompt = "%s(config-router-af)# ",
dd2c81b8 18782 .no_xpath = true,
f51bae9c
DS
18783};
18784
62b346ee 18785static struct cmd_node bgp_vpnv4_node = {
f4b8291f 18786 .name = "bgp vpnv4",
62b346ee 18787 .node = BGP_VPNV4_NODE,
24389580 18788 .parent_node = BGP_NODE,
62b346ee 18789 .prompt = "%s(config-router-af)# ",
dd2c81b8 18790 .no_xpath = true,
62b346ee 18791};
6b0655a2 18792
62b346ee 18793static struct cmd_node bgp_vpnv6_node = {
f4b8291f 18794 .name = "bgp vpnv6",
62b346ee 18795 .node = BGP_VPNV6_NODE,
24389580 18796 .parent_node = BGP_NODE,
62b346ee 18797 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 18798 .no_xpath = true,
62b346ee 18799};
8ecd3266 18800
62b346ee 18801static struct cmd_node bgp_evpn_node = {
f4b8291f 18802 .name = "bgp evpn",
62b346ee 18803 .node = BGP_EVPN_NODE,
24389580 18804 .parent_node = BGP_NODE,
62b346ee 18805 .prompt = "%s(config-router-evpn)# ",
dd2c81b8 18806 .no_xpath = true,
62b346ee 18807};
4e0b7b6d 18808
62b346ee 18809static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 18810 .name = "bgp evpn vni",
62b346ee 18811 .node = BGP_EVPN_VNI_NODE,
24389580 18812 .parent_node = BGP_EVPN_NODE,
62b346ee 18813 .prompt = "%s(config-router-af-vni)# ",
62b346ee 18814};
90e60aa7 18815
62b346ee 18816static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 18817 .name = "bgp ipv4 flowspec",
62b346ee 18818 .node = BGP_FLOWSPECV4_NODE,
24389580 18819 .parent_node = BGP_NODE,
62b346ee 18820 .prompt = "%s(config-router-af)# ",
dd2c81b8 18821 .no_xpath = true,
62b346ee 18822};
7c40bf39 18823
62b346ee 18824static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 18825 .name = "bgp ipv6 flowspec",
62b346ee 18826 .node = BGP_FLOWSPECV6_NODE,
24389580 18827 .parent_node = BGP_NODE,
62b346ee 18828 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 18829 .no_xpath = true,
62b346ee 18830};
7c40bf39 18831
bfaab44d
HS
18832static struct cmd_node bgp_srv6_node = {
18833 .name = "bgp srv6",
18834 .node = BGP_SRV6_NODE,
18835 .parent_node = BGP_NODE,
18836 .prompt = "%s(config-router-srv6)# ",
18837};
18838
d62a17ae 18839static void community_list_vty(void);
1f8ae70b 18840
8c20061f
DA
18841static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18842{
18843 struct bgp *bgp;
18844 struct peer_group *group;
18845 struct listnode *lnbgp, *lnpeer;
18846
18847 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18848 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18849 vector_set(comps,
18850 XSTRDUP(MTYPE_COMPLETION, group->name));
18851 }
18852}
18853
18854static void bgp_ac_peer(vector comps, struct cmd_token *token)
b8a815e5 18855{
d62a17ae 18856 struct bgp *bgp;
18857 struct peer *peer;
d62a17ae 18858 struct listnode *lnbgp, *lnpeer;
b8a815e5 18859
d62a17ae 18860 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18861 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18862 /* only provide suggestions on the appropriate input
18863 * token type,
18864 * they'll otherwise show up multiple times */
18865 enum cmd_token_type match_type;
18866 char *name = peer->host;
d48ed3e0 18867
d62a17ae 18868 if (peer->conf_if) {
18869 match_type = VARIABLE_TKN;
18870 name = peer->conf_if;
18871 } else if (strchr(peer->host, ':'))
18872 match_type = IPV6_TKN;
18873 else
18874 match_type = IPV4_TKN;
d48ed3e0 18875
d62a17ae 18876 if (token->type != match_type)
18877 continue;
d48ed3e0 18878
d62a17ae 18879 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18880 }
d62a17ae 18881 }
b8a815e5
DL
18882}
18883
8c20061f
DA
18884static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18885{
18886 bgp_ac_peer(comps, token);
84de1483
DA
18887
18888 if (token->type == VARIABLE_TKN)
18889 bgp_ac_peergroup(comps, token);
8c20061f
DA
18890}
18891
b8a815e5 18892static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 18893 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18894 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 18895 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 18896 {.completions = NULL}};
18897
47a306a0
DS
18898static const struct cmd_variable_handler bgp_var_peergroup[] = {
18899 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18900 {.completions = NULL} };
18901
aa24a36a
DA
18902DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18903
e6685141 18904static struct event *t_bgp_cfg;
aa24a36a
DA
18905
18906bool bgp_config_inprocess(void)
18907{
5f6eaa9b 18908 return event_is_scheduled(t_bgp_cfg);
aa24a36a
DA
18909}
18910
e6685141 18911static void bgp_config_finish(struct event *t)
aa24a36a
DA
18912{
18913 struct listnode *node;
18914 struct bgp *bgp;
18915
18916 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18917 hook_call(bgp_config_end, bgp);
18918}
18919
18920static void bgp_config_start(void)
18921{
18922#define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
e16d030c 18923 EVENT_OFF(t_bgp_cfg);
907a2395
DS
18924 event_add_timer(bm->master, bgp_config_finish, NULL,
18925 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
aa24a36a
DA
18926}
18927
18928/* When we receive a hook the configuration is read,
18929 * we start a timer to make sure we postpone sending
18930 * EoR before route-maps are processed.
18931 * This is especially valid if using `bgp route-map delay-timer`.
18932 */
18933static void bgp_config_end(void)
18934{
18935#define BGP_POST_CONFIG_DELAY_SECONDS 1
18936 uint32_t bgp_post_config_delay =
5f6eaa9b 18937 event_is_scheduled(bm->t_rmap_update)
4f830a07 18938 ? event_timer_remain_second(bm->t_rmap_update)
aa24a36a
DA
18939 : BGP_POST_CONFIG_DELAY_SECONDS;
18940
18941 /* If BGP config processing thread isn't running, then
18942 * we can return and rely it's properly handled.
18943 */
18944 if (!bgp_config_inprocess())
18945 return;
18946
e16d030c 18947 EVENT_OFF(t_bgp_cfg);
aa24a36a
DA
18948
18949 /* Start a new timer to make sure we don't send EoR
18950 * before route-maps are processed.
18951 */
907a2395
DS
18952 event_add_timer(bm->master, bgp_config_finish, NULL,
18953 bgp_post_config_delay, &t_bgp_cfg);
aa24a36a
DA
18954}
18955
4cd690ae
PG
18956static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18957{
18958 int write = 0;
18959 struct interface *ifp;
18960 struct bgp_interface *iifp;
18961
18962 FOR_ALL_INTERFACES (vrf, ifp) {
18963 iifp = ifp->info;
18964 if (!iifp)
18965 continue;
18966
18967 if_vty_config_start(vty, ifp);
18968
18969 if (CHECK_FLAG(iifp->flags,
18970 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18971 vty_out(vty, " mpls bgp forwarding\n");
18972 write++;
18973 }
18974
18975 if_vty_config_end(vty);
18976 }
18977
18978 return write;
18979}
18980
18981/* Configuration write function for bgpd. */
18982static int config_write_interface(struct vty *vty)
18983{
18984 int write = 0;
18985 struct vrf *vrf = NULL;
18986
18987 /* Display all VRF aware OSPF interface configuration */
18988 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18989 write += config_write_interface_one(vty, vrf);
18990 }
18991
18992 return write;
18993}
18994
18995DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18996 "[no$no] mpls bgp forwarding",
18997 NO_STR MPLS_STR BGP_STR
18998 "Enable MPLS forwarding for eBGP directly connected peers\n")
18999{
19000 bool check;
19001 struct bgp_interface *iifp;
19002
19003 VTY_DECLVAR_CONTEXT(interface, ifp);
19004 iifp = ifp->info;
19005 if (!iifp) {
19006 vty_out(vty, "Interface %s not available\n", ifp->name);
19007 return CMD_WARNING_CONFIG_FAILED;
19008 }
19009 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
19010 if (check != !no) {
19011 if (no)
19012 UNSET_FLAG(iifp->flags,
19013 BGP_INTERFACE_MPLS_BGP_FORWARDING);
19014 else
19015 SET_FLAG(iifp->flags,
19016 BGP_INTERFACE_MPLS_BGP_FORWARDING);
19017 /* trigger a nht update on eBGP sessions */
19018 if (if_is_operative(ifp))
19019 bgp_nht_ifp_up(ifp);
19020 }
19021 return CMD_SUCCESS;
19022}
19023
a0b937de
SW
19024DEFPY (bgp_inq_limit,
19025 bgp_inq_limit_cmd,
19026 "bgp input-queue-limit (1-4294967295)$limit",
19027 BGP_STR
19028 "Set the BGP Input Queue limit for all peers when message parsing\n"
19029 "Input-Queue limit\n")
19030{
19031 bm->inq_limit = limit;
19032
19033 return CMD_SUCCESS;
19034}
19035
19036DEFPY (no_bgp_inq_limit,
19037 no_bgp_inq_limit_cmd,
19038 "no bgp input-queue-limit [(1-4294967295)$limit]",
19039 NO_STR
19040 BGP_STR
19041 "Set the BGP Input Queue limit for all peers when message parsing\n"
19042 "Input-Queue limit\n")
19043{
963b7ee4
DS
19044 bm->inq_limit = BM_DEFAULT_Q_LIMIT;
19045
19046 return CMD_SUCCESS;
19047}
19048
19049DEFPY (bgp_outq_limit,
19050 bgp_outq_limit_cmd,
19051 "bgp output-queue-limit (1-4294967295)$limit",
19052 BGP_STR
19053 "Set the BGP Output Queue limit for all peers when message parsing\n"
19054 "Output-Queue limit\n")
19055{
19056 bm->outq_limit = limit;
a0b937de
SW
19057
19058 return CMD_SUCCESS;
19059}
19060
963b7ee4
DS
19061DEFPY (no_bgp_outq_limit,
19062 no_bgp_outq_limit_cmd,
19063 "no bgp output-queue-limit [(1-4294967295)$limit]",
19064 NO_STR
19065 BGP_STR
19066 "Set the BGP Output Queue limit for all peers when message parsing\n"
19067 "Output-Queue limit\n")
19068{
19069 bm->outq_limit = BM_DEFAULT_Q_LIMIT;
a0b937de
SW
19070
19071 return CMD_SUCCESS;
19072}
19073
963b7ee4 19074
4cd690ae
PG
19075/* Initialization of BGP interface. */
19076static void bgp_vty_if_init(void)
19077{
19078 /* Install interface node. */
19079 if_cmd_init(config_write_interface);
19080
19081 /* "mpls bgp forwarding" commands. */
19082 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
19083}
19084
d62a17ae 19085void bgp_vty_init(void)
19086{
19087 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 19088 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 19089
aa24a36a
DA
19090 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
19091
d62a17ae 19092 /* Install bgp top node. */
612c2c15
DL
19093 install_node(&bgp_node);
19094 install_node(&bgp_ipv4_unicast_node);
19095 install_node(&bgp_ipv4_multicast_node);
19096 install_node(&bgp_ipv4_labeled_unicast_node);
19097 install_node(&bgp_ipv6_unicast_node);
19098 install_node(&bgp_ipv6_multicast_node);
19099 install_node(&bgp_ipv6_labeled_unicast_node);
19100 install_node(&bgp_vpnv4_node);
19101 install_node(&bgp_vpnv6_node);
19102 install_node(&bgp_evpn_node);
19103 install_node(&bgp_evpn_vni_node);
19104 install_node(&bgp_flowspecv4_node);
19105 install_node(&bgp_flowspecv6_node);
bfaab44d 19106 install_node(&bgp_srv6_node);
d62a17ae 19107
19108 /* Install default VTY commands to new nodes. */
19109 install_default(BGP_NODE);
19110 install_default(BGP_IPV4_NODE);
19111 install_default(BGP_IPV4M_NODE);
19112 install_default(BGP_IPV4L_NODE);
19113 install_default(BGP_IPV6_NODE);
19114 install_default(BGP_IPV6M_NODE);
19115 install_default(BGP_IPV6L_NODE);
19116 install_default(BGP_VPNV4_NODE);
19117 install_default(BGP_VPNV6_NODE);
7c40bf39 19118 install_default(BGP_FLOWSPECV4_NODE);
19119 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 19120 install_default(BGP_EVPN_NODE);
19121 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 19122 install_default(BGP_SRV6_NODE);
d62a17ae 19123
a0b937de
SW
19124 /* "global bgp inq-limit command */
19125 install_element(CONFIG_NODE, &bgp_inq_limit_cmd);
19126 install_element(CONFIG_NODE, &no_bgp_inq_limit_cmd);
963b7ee4
DS
19127 install_element(CONFIG_NODE, &bgp_outq_limit_cmd);
19128 install_element(CONFIG_NODE, &no_bgp_outq_limit_cmd);
a0b937de 19129
8029b216
AK
19130 /* "bgp local-mac" hidden commands. */
19131 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
19132 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
19133
9acb67cb
DS
19134 /* "bgp suppress-fib-pending" global */
19135 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
19136
d62a17ae 19137 /* bgp route-map delay-timer commands. */
19138 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
19139 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
19140
8666265e
DS
19141 install_element(BGP_NODE, &bgp_allow_martian_cmd);
19142
f852eb98
PG
19143 /* bgp fast-convergence command */
19144 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
19145 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
19146
d70583f7
D
19147 /* global bgp update-delay command */
19148 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
19149 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
19150
05bd726c 19151 /* global bgp graceful-shutdown command */
19152 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
19153 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
19154
d62a17ae 19155 /* Dummy commands (Currently not supported) */
19156 install_element(BGP_NODE, &no_synchronization_cmd);
19157 install_element(BGP_NODE, &no_auto_summary_cmd);
19158
19159 /* "router bgp" commands. */
19160 install_element(CONFIG_NODE, &router_bgp_cmd);
19161
19162 /* "no router bgp" commands. */
19163 install_element(CONFIG_NODE, &no_router_bgp_cmd);
19164
425bd64b
PS
19165 /* "bgp session-dscp command */
19166 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
19167 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
19168
d62a17ae 19169 /* "bgp router-id" commands. */
19170 install_element(BGP_NODE, &bgp_router_id_cmd);
19171 install_element(BGP_NODE, &no_bgp_router_id_cmd);
19172
c208c586
S
19173 /* "bgp suppress-fib-pending" command */
19174 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
19175
d62a17ae 19176 /* "bgp cluster-id" commands. */
19177 install_element(BGP_NODE, &bgp_cluster_id_cmd);
19178 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
19179
c163f297
DS
19180 /* "bgp no-rib" commands. */
19181 install_element(CONFIG_NODE, &bgp_norib_cmd);
19182 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
19183
e46723a5
DS
19184 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
19185
d62a17ae 19186 /* "bgp confederation" commands. */
19187 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
19188 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
19189
19190 /* "bgp confederation peers" commands. */
19191 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
19192 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
19193
19194 /* bgp max-med command */
19195 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
19196 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
19197 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
19198 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
19199 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
19200
d864dd9e
EB
19201 /* "neighbor role" commands. */
19202 install_element(BGP_NODE, &neighbor_role_cmd);
19203 install_element(BGP_NODE, &neighbor_role_strict_cmd);
19204 install_element(BGP_NODE, &no_neighbor_role_cmd);
19205
97a52c82
DA
19206 /* "neighbor aigp" commands. */
19207 install_element(BGP_NODE, &neighbor_aigp_cmd);
19208
4f770cf1
DA
19209 /* "neighbor graceful-shutdown" command */
19210 install_element(BGP_NODE, &neighbor_graceful_shutdown_cmd);
19211
d62a17ae 19212 /* bgp disable-ebgp-connected-nh-check */
19213 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
19214 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
19215
19216 /* bgp update-delay command */
19217 install_element(BGP_NODE, &bgp_update_delay_cmd);
19218 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 19219
19220 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 19221 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 19222
19223 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
19224 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
19225
19226 /* "maximum-paths" commands. */
19227 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
19228 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
19229 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
19230 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
19231 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
19232 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
19233 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
19234 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
19235 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
19236 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
19237 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
19238 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
19239 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
19240 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
19241 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
19242
39edabac
PG
19243 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
19244 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
19245 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
19246 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
19247 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 19248 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
19249 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
19250 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
19251 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
19252 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
19253
19254 /* "timers bgp" commands. */
19255 install_element(BGP_NODE, &bgp_timers_cmd);
19256 install_element(BGP_NODE, &no_bgp_timers_cmd);
19257
b042667a
TI
19258 /* "minimum-holdtime" commands. */
19259 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
19260 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
19261
d62a17ae 19262 /* route-map delay-timer commands - per instance for backwards compat.
19263 */
19264 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
19265 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
19266
19267 /* "bgp client-to-client reflection" commands */
19268 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
19269 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
19270
19271 /* "bgp always-compare-med" commands */
19272 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
19273 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
19274
9dac9fc8
DA
19275 /* bgp ebgp-requires-policy */
19276 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
19277 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
19278
7ee70320
PG
19279 /* bgp labeled-unicast explicit-null */
19280 install_element(BGP_NODE, &bgp_lu_uses_explicit_null_cmd);
19281
2adac256
DA
19282 /* bgp suppress-duplicates */
19283 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
19284 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
19285
fb29348a
DA
19286 /* bgp reject-as-sets */
19287 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
19288 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
19289
d62a17ae 19290 /* "bgp deterministic-med" commands */
19291 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
19292 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
19293
055679e9 19294 /* "bgp graceful-restart" command */
36235319
QY
19295 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
19296 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 19297
19298 /* "bgp graceful-restart-disable" command */
36235319
QY
19299 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
19300 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 19301
19302 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
19303 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
19304 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 19305
19306 /* "neighbor a:b:c:d graceful-restart-disable" command */
19307 install_element(BGP_NODE,
19308 &bgp_neighbor_graceful_restart_disable_set_cmd);
19309 install_element(BGP_NODE,
19310 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
19311
19312 /* "neighbor a:b:c:d graceful-restart-helper" command */
19313 install_element(BGP_NODE,
19314 &bgp_neighbor_graceful_restart_helper_set_cmd);
19315 install_element(BGP_NODE,
19316 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
19317
d62a17ae 19318 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
19319 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
19320 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
19321 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 19322 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 19323 install_element(BGP_NODE,
19324 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 19325 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
19326 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
f2ca5c5b 19327 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
d62a17ae 19328
d6e3c15b 19329 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
19330 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 19331 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
19332 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 19333
7f323236
DW
19334 /* "bgp graceful-shutdown" commands */
19335 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
19336 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
19337
1ae314be
DA
19338 /* "bgp hard-administrative-reset" commands */
19339 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
19340
8606be87
DA
19341 /* "bgp long-lived-graceful-restart" commands */
19342 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
19343 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
19344
d62a17ae 19345 /* "bgp fast-external-failover" commands */
19346 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
19347 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
19348
97a52c82
DA
19349 /* "bgp bestpath aigp" commands */
19350 install_element(BGP_NODE, &bgp_bestpath_aigp_cmd);
19351
d62a17ae 19352 /* "bgp bestpath compare-routerid" commands */
19353 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
19354 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
19355
19356 /* "bgp bestpath as-path ignore" commands */
19357 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
19358 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
19359
19360 /* "bgp bestpath as-path confed" commands */
19361 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
19362 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
19363
19364 /* "bgp bestpath as-path multipath-relax" commands */
19365 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
19366 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
19367
ee88563a
JM
19368 /* "bgp bestpath peer-type multipath-relax" commands */
19369 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
19370 install_element(BGP_NODE,
19371 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
19372
d62a17ae 19373 /* "bgp log-neighbor-changes" commands */
19374 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
19375 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
19376
19377 /* "bgp bestpath med" commands */
19378 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
19379 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
19380
f7e1c681 19381 /* "bgp bestpath bandwidth" commands */
19382 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 19383 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 19384
b16bcbba
TA
19385 /* "no bgp default <afi>-<safi>" commands. */
19386 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
e84c59af 19387
d62a17ae 19388 /* "bgp network import-check" commands. */
19389 install_element(BGP_NODE, &bgp_network_import_check_cmd);
19390 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
19391 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
19392
19393 /* "bgp default local-preference" commands. */
19394 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
19395 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
19396
19397 /* bgp default show-hostname */
19398 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
19399 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
19400
aef999a2
DA
19401 /* bgp default show-nexthop-hostname */
19402 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
19403 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
19404
d62a17ae 19405 /* "bgp default subgroup-pkt-queue-max" commands. */
19406 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
19407 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
19408
19409 /* bgp ibgp-allow-policy-mods command */
19410 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
19411 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
19412
19413 /* "bgp listen limit" commands. */
19414 install_element(BGP_NODE, &bgp_listen_limit_cmd);
19415 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
19416
19417 /* "bgp listen range" commands. */
19418 install_element(BGP_NODE, &bgp_listen_range_cmd);
19419 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
19420
8175f54a 19421 /* "bgp default shutdown" command */
f26845f9 19422 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
19423
19424 /* "bgp shutdown" commands */
19425 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 19426 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 19427 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 19428 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 19429
d62a17ae 19430 /* "neighbor remote-as" commands. */
19431 install_element(BGP_NODE, &neighbor_remote_as_cmd);
19432 install_element(BGP_NODE, &neighbor_interface_config_cmd);
19433 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
19434 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
19435 install_element(BGP_NODE,
19436 &neighbor_interface_v6only_config_remote_as_cmd);
19437 install_element(BGP_NODE, &no_neighbor_cmd);
19438 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
19439
19440 /* "neighbor peer-group" commands. */
19441 install_element(BGP_NODE, &neighbor_peer_group_cmd);
19442 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
19443 install_element(BGP_NODE,
19444 &no_neighbor_interface_peer_group_remote_as_cmd);
19445
19446 /* "neighbor local-as" commands. */
19447 install_element(BGP_NODE, &neighbor_local_as_cmd);
19448 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
19449 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
19450 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
19451
19452 /* "neighbor solo" commands. */
19453 install_element(BGP_NODE, &neighbor_solo_cmd);
19454 install_element(BGP_NODE, &no_neighbor_solo_cmd);
19455
19456 /* "neighbor password" commands. */
19457 install_element(BGP_NODE, &neighbor_password_cmd);
19458 install_element(BGP_NODE, &no_neighbor_password_cmd);
19459
19460 /* "neighbor activate" commands. */
19461 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
19462 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
19463 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
19464 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
19465 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
19466 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
19467 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
19468 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
19469 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 19470 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
19471 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 19472 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
19473
19474 /* "no neighbor activate" commands. */
19475 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
19476 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
19477 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
19478 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
19479 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
19480 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
19481 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
19482 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
19483 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 19484 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
19485 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 19486 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
19487
19488 /* "neighbor peer-group" set commands. */
19489 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
19490 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19491 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
19492 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19493 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
19494 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
19495 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19496 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 19497 install_element(BGP_FLOWSPECV4_NODE,
19498 &neighbor_set_peer_group_hidden_cmd);
19499 install_element(BGP_FLOWSPECV6_NODE,
19500 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 19501
19502 /* "no neighbor peer-group unset" commands. */
19503 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
19504 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19505 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19506 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19507 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19508 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19509 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19510 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 19511 install_element(BGP_FLOWSPECV4_NODE,
19512 &no_neighbor_set_peer_group_hidden_cmd);
19513 install_element(BGP_FLOWSPECV6_NODE,
19514 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 19515
19516 /* "neighbor softreconfiguration inbound" commands.*/
19517 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
19518 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
19519 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
19520 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19521 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
19522 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19523 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
19524 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19525 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
19526 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19527 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
19528 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19529 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
19530 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19531 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
19532 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19533 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
19534 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 19535 install_element(BGP_FLOWSPECV4_NODE,
19536 &neighbor_soft_reconfiguration_cmd);
19537 install_element(BGP_FLOWSPECV4_NODE,
19538 &no_neighbor_soft_reconfiguration_cmd);
19539 install_element(BGP_FLOWSPECV6_NODE,
19540 &neighbor_soft_reconfiguration_cmd);
19541 install_element(BGP_FLOWSPECV6_NODE,
19542 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
19543 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
19544 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 19545
19546 /* "neighbor attribute-unchanged" commands. */
19547 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
19548 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
19549 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
19550 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
19551 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
19552 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
19553 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
19554 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
19555 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
19556 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
19557 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
19558 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
19559 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
19560 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
19561 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
19562 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
19563 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
19564 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
19565
19566 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
19567 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
19568
b8ad84d2
PG
19569 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
19570 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
19571 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
19572 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
19573
d62a17ae 19574 /* "nexthop-local unchanged" commands */
19575 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
19576 install_element(BGP_IPV6_NODE,
19577 &no_neighbor_nexthop_local_unchanged_cmd);
19578
19579 /* "neighbor next-hop-self" commands. */
19580 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
19581 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
19582 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
19583 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
19584 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
19585 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
19586 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
19587 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
19588 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
19589 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
19590 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
19591 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
19592 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
19593 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
19594 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
19595 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
19596 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
19597 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
19598 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
19599 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 19600
19601 /* "neighbor next-hop-self force" commands. */
19602 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
19603 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
19604 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19605 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19606 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
19607 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19608 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19609 install_element(BGP_IPV4_NODE,
19610 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19611 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
19612 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19613 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19614 install_element(BGP_IPV4M_NODE,
19615 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19616 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
19617 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19618 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19619 install_element(BGP_IPV4L_NODE,
19620 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19621 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
19622 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19623 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19624 install_element(BGP_IPV6_NODE,
19625 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19626 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
19627 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19628 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19629 install_element(BGP_IPV6M_NODE,
19630 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19631 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
19632 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19633 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19634 install_element(BGP_IPV6L_NODE,
19635 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19636 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
19637 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19638 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19639 install_element(BGP_VPNV4_NODE,
19640 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19641 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
19642 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19643 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19644 install_element(BGP_VPNV6_NODE,
19645 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
19646 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
19647 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 19648
19649 /* "neighbor as-override" commands. */
19650 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
19651 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
19652 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
19653 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
19654 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
19655 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
19656 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
19657 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
19658 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
19659 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
19660 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
19661 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
19662 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
19663 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
19664 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
19665 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
19666 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
19667 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
19668
19669 /* "neighbor remove-private-AS" commands. */
19670 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
19671 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
19672 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
19673 install_element(BGP_NODE,
19674 &no_neighbor_remove_private_as_all_hidden_cmd);
19675 install_element(BGP_NODE,
19676 &neighbor_remove_private_as_replace_as_hidden_cmd);
19677 install_element(BGP_NODE,
19678 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
19679 install_element(BGP_NODE,
19680 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
19681 install_element(
19682 BGP_NODE,
19683 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
19684 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
19685 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
19686 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
19687 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19688 install_element(BGP_IPV4_NODE,
19689 &neighbor_remove_private_as_replace_as_cmd);
19690 install_element(BGP_IPV4_NODE,
19691 &no_neighbor_remove_private_as_replace_as_cmd);
19692 install_element(BGP_IPV4_NODE,
19693 &neighbor_remove_private_as_all_replace_as_cmd);
19694 install_element(BGP_IPV4_NODE,
19695 &no_neighbor_remove_private_as_all_replace_as_cmd);
19696 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
19697 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
19698 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
19699 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
19700 install_element(BGP_IPV4M_NODE,
19701 &neighbor_remove_private_as_replace_as_cmd);
19702 install_element(BGP_IPV4M_NODE,
19703 &no_neighbor_remove_private_as_replace_as_cmd);
19704 install_element(BGP_IPV4M_NODE,
19705 &neighbor_remove_private_as_all_replace_as_cmd);
19706 install_element(BGP_IPV4M_NODE,
19707 &no_neighbor_remove_private_as_all_replace_as_cmd);
19708 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
19709 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
19710 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
19711 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
19712 install_element(BGP_IPV4L_NODE,
19713 &neighbor_remove_private_as_replace_as_cmd);
19714 install_element(BGP_IPV4L_NODE,
19715 &no_neighbor_remove_private_as_replace_as_cmd);
19716 install_element(BGP_IPV4L_NODE,
19717 &neighbor_remove_private_as_all_replace_as_cmd);
19718 install_element(BGP_IPV4L_NODE,
19719 &no_neighbor_remove_private_as_all_replace_as_cmd);
19720 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
19721 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
19722 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
19723 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19724 install_element(BGP_IPV6_NODE,
19725 &neighbor_remove_private_as_replace_as_cmd);
19726 install_element(BGP_IPV6_NODE,
19727 &no_neighbor_remove_private_as_replace_as_cmd);
19728 install_element(BGP_IPV6_NODE,
19729 &neighbor_remove_private_as_all_replace_as_cmd);
19730 install_element(BGP_IPV6_NODE,
19731 &no_neighbor_remove_private_as_all_replace_as_cmd);
19732 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
19733 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
19734 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
19735 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
19736 install_element(BGP_IPV6M_NODE,
19737 &neighbor_remove_private_as_replace_as_cmd);
19738 install_element(BGP_IPV6M_NODE,
19739 &no_neighbor_remove_private_as_replace_as_cmd);
19740 install_element(BGP_IPV6M_NODE,
19741 &neighbor_remove_private_as_all_replace_as_cmd);
19742 install_element(BGP_IPV6M_NODE,
19743 &no_neighbor_remove_private_as_all_replace_as_cmd);
19744 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19745 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19746 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19747 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19748 install_element(BGP_IPV6L_NODE,
19749 &neighbor_remove_private_as_replace_as_cmd);
19750 install_element(BGP_IPV6L_NODE,
19751 &no_neighbor_remove_private_as_replace_as_cmd);
19752 install_element(BGP_IPV6L_NODE,
19753 &neighbor_remove_private_as_all_replace_as_cmd);
19754 install_element(BGP_IPV6L_NODE,
19755 &no_neighbor_remove_private_as_all_replace_as_cmd);
19756 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19757 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19758 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19759 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19760 install_element(BGP_VPNV4_NODE,
19761 &neighbor_remove_private_as_replace_as_cmd);
19762 install_element(BGP_VPNV4_NODE,
19763 &no_neighbor_remove_private_as_replace_as_cmd);
19764 install_element(BGP_VPNV4_NODE,
19765 &neighbor_remove_private_as_all_replace_as_cmd);
19766 install_element(BGP_VPNV4_NODE,
19767 &no_neighbor_remove_private_as_all_replace_as_cmd);
19768 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19769 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19770 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19771 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19772 install_element(BGP_VPNV6_NODE,
19773 &neighbor_remove_private_as_replace_as_cmd);
19774 install_element(BGP_VPNV6_NODE,
19775 &no_neighbor_remove_private_as_replace_as_cmd);
19776 install_element(BGP_VPNV6_NODE,
19777 &neighbor_remove_private_as_all_replace_as_cmd);
19778 install_element(BGP_VPNV6_NODE,
19779 &no_neighbor_remove_private_as_all_replace_as_cmd);
19780
19781 /* "neighbor send-community" commands.*/
19782 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19783 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19784 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19785 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19786 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19787 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19788 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19789 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19790 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19791 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19792 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19793 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19794 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19795 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19796 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19797 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19798 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19799 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19800 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19801 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19802 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19803 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19804 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19805 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19806 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19807 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19808 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19809 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19810 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19811 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19812 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19813 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19814 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19815 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19816 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19817 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19818
19819 /* "neighbor route-reflector" commands.*/
19820 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19821 install_element(BGP_NODE,
19822 &no_neighbor_route_reflector_client_hidden_cmd);
19823 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19824 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19825 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19826 install_element(BGP_IPV4M_NODE,
19827 &no_neighbor_route_reflector_client_cmd);
19828 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19829 install_element(BGP_IPV4L_NODE,
19830 &no_neighbor_route_reflector_client_cmd);
19831 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19832 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19833 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19834 install_element(BGP_IPV6M_NODE,
19835 &no_neighbor_route_reflector_client_cmd);
19836 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19837 install_element(BGP_IPV6L_NODE,
19838 &no_neighbor_route_reflector_client_cmd);
19839 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19840 install_element(BGP_VPNV4_NODE,
19841 &no_neighbor_route_reflector_client_cmd);
19842 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19843 install_element(BGP_VPNV6_NODE,
19844 &no_neighbor_route_reflector_client_cmd);
7c40bf39 19845 install_element(BGP_FLOWSPECV4_NODE,
19846 &neighbor_route_reflector_client_cmd);
19847 install_element(BGP_FLOWSPECV4_NODE,
19848 &no_neighbor_route_reflector_client_cmd);
19849 install_element(BGP_FLOWSPECV6_NODE,
19850 &neighbor_route_reflector_client_cmd);
19851 install_element(BGP_FLOWSPECV6_NODE,
19852 &no_neighbor_route_reflector_client_cmd);
d62a17ae 19853 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19854 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19855
19856 /* "neighbor route-server" commands.*/
19857 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19858 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19859 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19860 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19861 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19862 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19863 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19864 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19865 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19866 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19867 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19868 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19869 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19870 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19871 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19872 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19873 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19874 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
19875 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19876 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 19877 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19878 install_element(BGP_FLOWSPECV4_NODE,
19879 &no_neighbor_route_server_client_cmd);
19880 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19881 install_element(BGP_FLOWSPECV6_NODE,
19882 &no_neighbor_route_server_client_cmd);
d62a17ae 19883
7c0e4312
DA
19884 /* "neighbor disable-addpath-rx" commands. */
19885 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19886 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19887 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19888 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19889 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19890 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19891 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19892 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19893 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19894 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19895 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19896 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19897 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19898 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19899 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19900 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19901
d62a17ae 19902 /* "neighbor addpath-tx-all-paths" commands.*/
19903 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19904 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19905 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19906 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19907 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19908 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19909 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19910 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19911 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19912 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19913 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19914 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19915 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19916 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19917 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19918 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19919 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19920 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19921
19922 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19923 install_element(BGP_NODE,
19924 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19925 install_element(BGP_NODE,
19926 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19927 install_element(BGP_IPV4_NODE,
19928 &neighbor_addpath_tx_bestpath_per_as_cmd);
19929 install_element(BGP_IPV4_NODE,
19930 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19931 install_element(BGP_IPV4M_NODE,
19932 &neighbor_addpath_tx_bestpath_per_as_cmd);
19933 install_element(BGP_IPV4M_NODE,
19934 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19935 install_element(BGP_IPV4L_NODE,
19936 &neighbor_addpath_tx_bestpath_per_as_cmd);
19937 install_element(BGP_IPV4L_NODE,
19938 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19939 install_element(BGP_IPV6_NODE,
19940 &neighbor_addpath_tx_bestpath_per_as_cmd);
19941 install_element(BGP_IPV6_NODE,
19942 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19943 install_element(BGP_IPV6M_NODE,
19944 &neighbor_addpath_tx_bestpath_per_as_cmd);
19945 install_element(BGP_IPV6M_NODE,
19946 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19947 install_element(BGP_IPV6L_NODE,
19948 &neighbor_addpath_tx_bestpath_per_as_cmd);
19949 install_element(BGP_IPV6L_NODE,
19950 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19951 install_element(BGP_VPNV4_NODE,
19952 &neighbor_addpath_tx_bestpath_per_as_cmd);
19953 install_element(BGP_VPNV4_NODE,
19954 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19955 install_element(BGP_VPNV6_NODE,
19956 &neighbor_addpath_tx_bestpath_per_as_cmd);
19957 install_element(BGP_VPNV6_NODE,
19958 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19959
2b31007c
RZ
19960 /* "neighbor sender-as-path-loop-detection" commands. */
19961 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19962 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19963
a5c6a9b1
DA
19964 /* "neighbor path-attribute discard" commands. */
19965 install_element(BGP_NODE, &neighbor_path_attribute_discard_cmd);
b986d7f4 19966 install_element(BGP_NODE, &no_neighbor_path_attribute_discard_cmd);
a5c6a9b1 19967
e2863b4f
DA
19968 /* "neighbor path-attribute treat-as-withdraw" commands. */
19969 install_element(BGP_NODE,
19970 &neighbor_path_attribute_treat_as_withdraw_cmd);
19971 install_element(BGP_NODE,
19972 &no_neighbor_path_attribute_treat_as_withdraw_cmd);
19973
d62a17ae 19974 /* "neighbor passive" commands. */
19975 install_element(BGP_NODE, &neighbor_passive_cmd);
19976 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19977
19978
19979 /* "neighbor shutdown" commands. */
19980 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19981 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19982 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19983 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
19984 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19985 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 19986
19987 /* "neighbor capability extended-nexthop" commands.*/
19988 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19989 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19990
234f6fd4
DA
19991 /* "neighbor capability software-version" commands.*/
19992 install_element(BGP_NODE, &neighbor_capability_software_version_cmd);
19993
d62a17ae 19994 /* "neighbor capability orf prefix-list" commands.*/
19995 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19996 install_element(BGP_NODE,
19997 &no_neighbor_capability_orf_prefix_hidden_cmd);
19998 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19999 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
20000 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
20001 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
20002 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
20003 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
20004 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
20005 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
20006 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
20007 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
20008 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
20009 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
20010
20011 /* "neighbor capability dynamic" commands.*/
20012 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
20013 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
20014
20015 /* "neighbor dont-capability-negotiate" commands. */
20016 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
20017 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
20018
20019 /* "neighbor ebgp-multihop" commands. */
20020 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
20021 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
20022 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
20023
20024 /* "neighbor disable-connected-check" commands. */
20025 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
20026 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
20027
7ab294ea
DA
20028 /* "neighbor disable-link-bw-encoding-ieee" commands. */
20029 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
20030 install_element(BGP_NODE,
20031 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
27aa23a4 20032
d08c0c80
DA
20033 /* "neighbor extended-optional-parameters" commands. */
20034 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
20035 install_element(BGP_NODE,
20036 &no_neighbor_extended_optional_parameters_cmd);
20037
47cbc09b
PM
20038 /* "neighbor enforce-first-as" commands. */
20039 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
20040 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
20041
d62a17ae 20042 /* "neighbor description" commands. */
20043 install_element(BGP_NODE, &neighbor_description_cmd);
20044 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 20045 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 20046
20047 /* "neighbor update-source" commands. "*/
20048 install_element(BGP_NODE, &neighbor_update_source_cmd);
20049 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
20050
20051 /* "neighbor default-originate" commands. */
20052 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
20053 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
20054 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
20055 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
20056 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
20057 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
20058 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
20059 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
20060 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
20061 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
20062 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
20063 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
20064 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
20065 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
20066 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
20067 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
20068 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
20069 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
20070 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
20071 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
20072 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
20073
20074 /* "neighbor port" commands. */
20075 install_element(BGP_NODE, &neighbor_port_cmd);
20076 install_element(BGP_NODE, &no_neighbor_port_cmd);
20077
20078 /* "neighbor weight" commands. */
20079 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
20080 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
20081
20082 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
20083 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
20084 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
20085 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
20086 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
20087 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
20088 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
20089 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
20090 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
20091 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
20092 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
20093 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
20094 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
20095 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
20096 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
20097 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
20098
20099 /* "neighbor override-capability" commands. */
20100 install_element(BGP_NODE, &neighbor_override_capability_cmd);
20101 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
20102
20103 /* "neighbor strict-capability-match" commands. */
20104 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
20105 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
20106
20107 /* "neighbor timers" commands. */
20108 install_element(BGP_NODE, &neighbor_timers_cmd);
20109 install_element(BGP_NODE, &no_neighbor_timers_cmd);
20110
20111 /* "neighbor timers connect" commands. */
20112 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
20113 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
20114
d43114f3
DS
20115 /* "neighbor timers delayopen" commands. */
20116 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
20117 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
20118
d62a17ae 20119 /* "neighbor advertisement-interval" commands. */
20120 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
20121 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
20122
20123 /* "neighbor interface" commands. */
20124 install_element(BGP_NODE, &neighbor_interface_cmd);
20125 install_element(BGP_NODE, &no_neighbor_interface_cmd);
20126
20127 /* "neighbor distribute" commands. */
20128 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
20129 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
20130 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
20131 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
20132 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
20133 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
20134 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
20135 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
20136 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
20137 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
20138 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
20139 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
20140 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
20141 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
20142 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
20143 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
20144 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
20145 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
20146
20147 /* "neighbor prefix-list" commands. */
20148 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
642ef664 20149 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
d62a17ae 20150 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
642ef664 20151 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20152 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
642ef664 20153 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20154 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
642ef664 20155 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20156 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
642ef664 20157 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20158 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
642ef664 20159 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20160 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
642ef664 20161 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20162 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
642ef664 20163 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20164 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
642ef664 20165 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 20166 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
642ef664 20167 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 20168 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
642ef664 20169 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20170
20171 /* "neighbor filter-list" commands. */
20172 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
20173 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
20174 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
20175 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
20176 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
20177 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
20178 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
20179 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
20180 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
20181 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
20182 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
20183 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
20184 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
20185 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
20186 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
20187 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
20188 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
20189 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 20190 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
20191 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
20192 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
20193 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 20194
20195 /* "neighbor route-map" commands. */
d6d7ed37
IR
20196 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
20197 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
d62a17ae 20198 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
0ea8d871 20199 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20200 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
0ea8d871 20201 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20202 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
0ea8d871 20203 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20204 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
0ea8d871 20205 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20206 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
0ea8d871 20207 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20208 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
0ea8d871 20209 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20210 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
0ea8d871 20211 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20212 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
0ea8d871 20213 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 20214 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
0ea8d871 20215 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
7c40bf39 20216 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
0ea8d871 20217 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549 20218 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
0ea8d871 20219 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20220
20221 /* "neighbor unsuppress-map" commands. */
20222 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
20223 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
20224 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
20225 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
20226 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
20227 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
20228 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
20229 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
20230 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
20231 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
20232 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
20233 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
20234 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
20235 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
20236 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
20237 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
20238 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
20239 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
20240
7f7940e6 20241 /* "neighbor advertise-map" commands. */
389e4f92 20242 install_element(BGP_NODE, &bgp_condadv_period_cmd);
7f7940e6 20243 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 20244 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20245 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20246 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20247 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20248 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20249 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20250 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20251 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20252
fde246e8
DA
20253 /* neighbor maximum-prefix-out commands. */
20254 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
20255 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
20256 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
20257 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
20258 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
20259 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
20260 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
20261 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
20262 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
20263 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
20264 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
20265 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
20266 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
20267 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
20268 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
20269 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
20270 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
20271 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
20272
d62a17ae 20273 /* "neighbor maximum-prefix" commands. */
20274 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
20275 install_element(BGP_NODE,
20276 &neighbor_maximum_prefix_threshold_hidden_cmd);
20277 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
20278 install_element(BGP_NODE,
20279 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
20280 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
20281 install_element(BGP_NODE,
20282 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
20283 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
20284 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
20285 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
20286 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
20287 install_element(BGP_IPV4_NODE,
20288 &neighbor_maximum_prefix_threshold_warning_cmd);
20289 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
20290 install_element(BGP_IPV4_NODE,
20291 &neighbor_maximum_prefix_threshold_restart_cmd);
20292 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
20293 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
20294 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
20295 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
20296 install_element(BGP_IPV4M_NODE,
20297 &neighbor_maximum_prefix_threshold_warning_cmd);
20298 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
20299 install_element(BGP_IPV4M_NODE,
20300 &neighbor_maximum_prefix_threshold_restart_cmd);
20301 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
20302 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
20303 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
20304 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
20305 install_element(BGP_IPV4L_NODE,
20306 &neighbor_maximum_prefix_threshold_warning_cmd);
20307 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
20308 install_element(BGP_IPV4L_NODE,
20309 &neighbor_maximum_prefix_threshold_restart_cmd);
20310 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
20311 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
20312 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
20313 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
20314 install_element(BGP_IPV6_NODE,
20315 &neighbor_maximum_prefix_threshold_warning_cmd);
20316 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
20317 install_element(BGP_IPV6_NODE,
20318 &neighbor_maximum_prefix_threshold_restart_cmd);
20319 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
20320 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
20321 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
20322 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
20323 install_element(BGP_IPV6M_NODE,
20324 &neighbor_maximum_prefix_threshold_warning_cmd);
20325 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
20326 install_element(BGP_IPV6M_NODE,
20327 &neighbor_maximum_prefix_threshold_restart_cmd);
20328 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
20329 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
20330 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
20331 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
20332 install_element(BGP_IPV6L_NODE,
20333 &neighbor_maximum_prefix_threshold_warning_cmd);
20334 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
20335 install_element(BGP_IPV6L_NODE,
20336 &neighbor_maximum_prefix_threshold_restart_cmd);
20337 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
20338 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
20339 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
20340 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
20341 install_element(BGP_VPNV4_NODE,
20342 &neighbor_maximum_prefix_threshold_warning_cmd);
20343 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
20344 install_element(BGP_VPNV4_NODE,
20345 &neighbor_maximum_prefix_threshold_restart_cmd);
20346 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
20347 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
20348 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
20349 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
20350 install_element(BGP_VPNV6_NODE,
20351 &neighbor_maximum_prefix_threshold_warning_cmd);
20352 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
20353 install_element(BGP_VPNV6_NODE,
20354 &neighbor_maximum_prefix_threshold_restart_cmd);
20355 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
20356
20357 /* "neighbor allowas-in" */
20358 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
20359 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
20360 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
20361 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
20362 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
20363 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
20364 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
20365 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
20366 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
20367 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
20368 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
20369 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
20370 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
20371 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
20372 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
20373 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
20374 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
20375 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
20376 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
20377 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
20378
46dbf9d0
DA
20379 /* neighbor accept-own */
20380 install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
20381 install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
20382
01da2d26
DA
20383 /* "neighbor soo" */
20384 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
20385 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
20386 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
20387 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
20388 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
20389 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
20390 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
20391 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
20392 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
20393 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
20394 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
20395 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
20396 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
20397 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
20398 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
20399 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
20400 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
20401 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
20402
d62a17ae 20403 /* address-family commands. */
20404 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
20405 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 20406#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 20407 install_element(BGP_NODE, &address_family_vpnv4_cmd);
20408 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 20409#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 20410
d62a17ae 20411 install_element(BGP_NODE, &address_family_evpn_cmd);
20412
20413 /* "exit-address-family" command. */
20414 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
20415 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
20416 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
20417 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
20418 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
20419 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
20420 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
20421 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 20422 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
20423 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 20424 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
20425
a486300b
PG
20426 /* BGP retain all route-target */
20427 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
20428 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
20429
d62a17ae 20430 /* "clear ip bgp commands" */
20431 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
20432
20433 /* clear ip bgp prefix */
20434 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
20435 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
20436 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
20437
20438 /* "show [ip] bgp summary" commands. */
20439 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 20440 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 20441 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 20442 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 20443 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
20444 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 20445 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
20446
20447 /* "show [ip] bgp neighbors" commands. */
20448 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
20449
36235319 20450 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 20451
d62a17ae 20452 /* "show [ip] bgp peer-group" commands. */
20453 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
20454
20455 /* "show [ip] bgp paths" commands. */
20456 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
20457
20458 /* "show [ip] bgp community" commands. */
20459 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
20460
20461 /* "show ip bgp large-community" commands. */
20462 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
20463 /* "show [ip] bgp attribute-info" commands. */
20464 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 20465 /* "show [ip] bgp route-leak" command */
20466 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 20467
20468 /* "redistribute" commands. */
20469 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
20470 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
20471 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
20472 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
20473 install_element(BGP_NODE,
20474 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
20475 install_element(BGP_NODE,
20476 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
20477 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
20478 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
20479 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
20480 install_element(BGP_NODE,
20481 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
20482 install_element(BGP_NODE,
20483 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
20484 install_element(BGP_NODE,
20485 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
20486 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
20487 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
20488 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
20489 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
20490 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
20491 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
20492 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
20493 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
20494 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
20495 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
20496 install_element(BGP_IPV4_NODE,
20497 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
20498 install_element(BGP_IPV4_NODE,
20499 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
20500 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
20501 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
20502 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
20503 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
20504 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
20505 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
20506
70dd370f 20507 /* import|export vpn [route-map RMAP_NAME] */
b9c7bc5a
PZ
20508 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
20509 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 20510
12a844a5
DS
20511 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
20512 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
20513
d62a17ae 20514 /* ttl_security commands */
20515 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
20516 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
20517
d1adb448
PG
20518 /* "bgp tcp-keepalive" commands */
20519 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
20520 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
20521
d62a17ae 20522 /* "show [ip] bgp memory" commands. */
20523 install_element(VIEW_NODE, &show_bgp_memory_cmd);
20524
acf71666
MK
20525 /* "show bgp martian next-hop" */
20526 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
20527
48ecf8f5
DS
20528 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
20529
d62a17ae 20530 /* "show [ip] bgp views" commands. */
20531 install_element(VIEW_NODE, &show_bgp_views_cmd);
20532
20533 /* "show [ip] bgp vrfs" commands. */
20534 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
20535
20536 /* Community-list. */
20537 community_list_vty();
ddb5b488 20538
ed0e57e3
DA
20539 community_alias_vty();
20540
ddb5b488 20541 /* vpn-policy commands */
b9c7bc5a
PZ
20542 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
20543 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
20544 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
20545 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
d4cdcee5
PG
20546 install_element(BGP_IPV4_NODE,
20547 &af_label_vpn_export_allocation_mode_cmd);
20548 install_element(BGP_IPV6_NODE,
20549 &af_label_vpn_export_allocation_mode_cmd);
b9c7bc5a
PZ
20550 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
20551 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
20552 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
20553 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
20554 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
20555 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
20556 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
20557 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 20558
301ad80a
PG
20559 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
20560 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
20561
b9c7bc5a
PZ
20562 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
20563 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
20564 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
20565 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
20566 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
20567 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
20568 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
20569 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
20570 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
20571 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
20572
20573 /* tcp-mss command */
20574 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
20575 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
20576
20577 /* srv6 commands */
ea372e81 20578 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
bfaab44d 20579 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
0249b8b6 20580 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
a0281b2e 20581 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
0249b8b6 20582 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
b72c9e14
HS
20583 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
20584 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
527588aa 20585 install_element(BGP_NODE, &bgp_sid_vpn_export_cmd);
e606d8ec 20586 install_element(BGP_NODE, &no_bgp_sid_vpn_export_cmd);
4cd690ae
PG
20587
20588 bgp_vty_if_init();
718e3744 20589}
6b0655a2 20590
718e3744 20591#include "memory.h"
20592#include "bgp_regex.h"
20593#include "bgp_clist.h"
20594#include "bgp_ecommunity.h"
20595
20596/* VTY functions. */
20597
20598/* Direction value to string conversion. */
d62a17ae 20599static const char *community_direct_str(int direct)
20600{
20601 switch (direct) {
20602 case COMMUNITY_DENY:
20603 return "deny";
20604 case COMMUNITY_PERMIT:
20605 return "permit";
20606 default:
20607 return "unknown";
20608 }
718e3744 20609}
20610
20611/* Display error string. */
d62a17ae 20612static void community_list_perror(struct vty *vty, int ret)
20613{
20614 switch (ret) {
20615 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
20616 vty_out(vty, "%% Can't find community-list\n");
20617 break;
20618 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
20619 vty_out(vty, "%% Malformed community-list value\n");
20620 break;
20621 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
20622 vty_out(vty,
20623 "%% Community name conflict, previously defined as standard community\n");
20624 break;
20625 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
20626 vty_out(vty,
20627 "%% Community name conflict, previously defined as expanded community\n");
20628 break;
20629 }
718e3744 20630}
20631
5bf15956
DW
20632/* "community-list" keyword help string. */
20633#define COMMUNITY_LIST_STR "Add a community list entry\n"
20634
7336e101
SP
20635/*community-list standard */
20636DEFUN (community_list_standard,
20637 bgp_community_list_standard_cmd,
a2099c1d 20638 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 20639 BGP_STR
718e3744 20640 COMMUNITY_LIST_STR
20641 "Community list number (standard)\n"
5bf15956 20642 "Add an standard community-list entry\n"
718e3744 20643 "Community list name\n"
2f8cc0e5
DA
20644 "Sequence number of an entry\n"
20645 "Sequence number\n"
718e3744 20646 "Specify community to reject\n"
20647 "Specify community to accept\n"
20648 COMMUNITY_VAL_STR)
20649{
d62a17ae 20650 char *cl_name_or_number = NULL;
2f8cc0e5 20651 char *seq = NULL;
d62a17ae 20652 int direct = 0;
20653 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 20654 int idx = 0;
7336e101 20655
e34627f9 20656 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20657 seq = argv[idx]->arg;
20658
20659 idx = 0;
d62a17ae 20660 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20661 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20662 cl_name_or_number = argv[idx]->arg;
20663 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20664 : COMMUNITY_DENY;
20665 argv_find(argv, argc, "AA:NN", &idx);
20666 char *str = argv_concat(argv, argc, idx);
42f914d4 20667
1f703838 20668 assert(str);
2f8cc0e5
DA
20669 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20670 direct, style);
42f914d4 20671
d62a17ae 20672 XFREE(MTYPE_TMP, str);
42f914d4 20673
d62a17ae 20674 if (ret < 0) {
20675 /* Display error string. */
20676 community_list_perror(vty, ret);
20677 return CMD_WARNING_CONFIG_FAILED;
20678 }
42f914d4 20679
d62a17ae 20680 return CMD_SUCCESS;
718e3744 20681}
20682
7336e101
SP
20683DEFUN (no_community_list_standard_all,
20684 no_bgp_community_list_standard_all_cmd,
a2099c1d 20685 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20686 NO_STR
20687 BGP_STR
20688 COMMUNITY_LIST_STR
20689 "Community list number (standard)\n"
20690 "Add an standard community-list entry\n"
20691 "Community list name\n"
2f8cc0e5
DA
20692 "Sequence number of an entry\n"
20693 "Sequence number\n"
7336e101
SP
20694 "Specify community to reject\n"
20695 "Specify community to accept\n"
20696 COMMUNITY_VAL_STR)
718e3744 20697{
d62a17ae 20698 char *cl_name_or_number = NULL;
174b5cb9 20699 char *str = NULL;
d62a17ae 20700 int direct = 0;
20701 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 20702 char *seq = NULL;
d62a17ae 20703 int idx = 0;
7336e101 20704
e34627f9 20705 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20706 seq = argv[idx]->arg;
20707
20708 idx = 0;
174b5cb9
DA
20709 argv_find(argv, argc, "permit", &idx);
20710 argv_find(argv, argc, "deny", &idx);
20711
20712 if (idx) {
20713 direct = argv_find(argv, argc, "permit", &idx)
20714 ? COMMUNITY_PERMIT
20715 : COMMUNITY_DENY;
20716
20717 idx = 0;
20718 argv_find(argv, argc, "AA:NN", &idx);
20719 str = argv_concat(argv, argc, idx);
20720 }
20721
20722 idx = 0;
d62a17ae 20723 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20724 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20725 cl_name_or_number = argv[idx]->arg;
42f914d4 20726
2f8cc0e5 20727 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 20728 direct, style);
42f914d4 20729
d62a17ae 20730 XFREE(MTYPE_TMP, str);
daf9ddbb 20731
d62a17ae 20732 if (ret < 0) {
20733 community_list_perror(vty, ret);
20734 return CMD_WARNING_CONFIG_FAILED;
20735 }
42f914d4 20736
d62a17ae 20737 return CMD_SUCCESS;
718e3744 20738}
7336e101 20739
174b5cb9 20740ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
a2099c1d 20741 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
174b5cb9
DA
20742 NO_STR BGP_STR COMMUNITY_LIST_STR
20743 "Community list number (standard)\n"
20744 "Add an standard community-list entry\n"
20745 "Community list name\n")
20746
7336e101
SP
20747/*community-list expanded */
20748DEFUN (community_list_expanded_all,
20749 bgp_community_list_expanded_all_cmd,
a2099c1d 20750 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20751 BGP_STR
20752 COMMUNITY_LIST_STR
718e3744 20753 "Community list number (expanded)\n"
5bf15956 20754 "Add an expanded community-list entry\n"
718e3744 20755 "Community list name\n"
2f8cc0e5
DA
20756 "Sequence number of an entry\n"
20757 "Sequence number\n"
718e3744 20758 "Specify community to reject\n"
20759 "Specify community to accept\n"
20760 COMMUNITY_VAL_STR)
20761{
d62a17ae 20762 char *cl_name_or_number = NULL;
2f8cc0e5 20763 char *seq = NULL;
d62a17ae 20764 int direct = 0;
20765 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 20766 int idx = 0;
7b9a4750 20767
e34627f9 20768 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20769 seq = argv[idx]->arg;
20770
20771 idx = 0;
20772
d62a17ae 20773 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20774 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20775 cl_name_or_number = argv[idx]->arg;
20776 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20777 : COMMUNITY_DENY;
20778 argv_find(argv, argc, "AA:NN", &idx);
20779 char *str = argv_concat(argv, argc, idx);
42f914d4 20780
1f703838 20781 assert(str);
2f8cc0e5
DA
20782 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20783 direct, style);
42f914d4 20784
d62a17ae 20785 XFREE(MTYPE_TMP, str);
42f914d4 20786
d62a17ae 20787 if (ret < 0) {
20788 /* Display error string. */
20789 community_list_perror(vty, ret);
20790 return CMD_WARNING_CONFIG_FAILED;
20791 }
42f914d4 20792
d62a17ae 20793 return CMD_SUCCESS;
718e3744 20794}
20795
7336e101
SP
20796DEFUN (no_community_list_expanded_all,
20797 no_bgp_community_list_expanded_all_cmd,
a2099c1d 20798 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20799 NO_STR
20800 BGP_STR
20801 COMMUNITY_LIST_STR
20802 "Community list number (expanded)\n"
20803 "Add an expanded community-list entry\n"
20804 "Community list name\n"
2f8cc0e5
DA
20805 "Sequence number of an entry\n"
20806 "Sequence number\n"
7336e101
SP
20807 "Specify community to reject\n"
20808 "Specify community to accept\n"
20809 COMMUNITY_VAL_STR)
718e3744 20810{
d62a17ae 20811 char *cl_name_or_number = NULL;
2f8cc0e5 20812 char *seq = NULL;
174b5cb9 20813 char *str = NULL;
d62a17ae 20814 int direct = 0;
20815 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 20816 int idx = 0;
174b5cb9 20817
e34627f9 20818 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20819 seq = argv[idx]->arg;
20820
20821 idx = 0;
174b5cb9
DA
20822 argv_find(argv, argc, "permit", &idx);
20823 argv_find(argv, argc, "deny", &idx);
20824
20825 if (idx) {
20826 direct = argv_find(argv, argc, "permit", &idx)
20827 ? COMMUNITY_PERMIT
20828 : COMMUNITY_DENY;
20829
20830 idx = 0;
20831 argv_find(argv, argc, "AA:NN", &idx);
20832 str = argv_concat(argv, argc, idx);
7336e101 20833 }
174b5cb9
DA
20834
20835 idx = 0;
d62a17ae 20836 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20837 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20838 cl_name_or_number = argv[idx]->arg;
42f914d4 20839
2f8cc0e5 20840 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 20841 direct, style);
42f914d4 20842
d62a17ae 20843 XFREE(MTYPE_TMP, str);
daf9ddbb 20844
d62a17ae 20845 if (ret < 0) {
20846 community_list_perror(vty, ret);
20847 return CMD_WARNING_CONFIG_FAILED;
20848 }
42f914d4 20849
d62a17ae 20850 return CMD_SUCCESS;
718e3744 20851}
20852
36d4bb44
EB
20853ALIAS(no_community_list_expanded_all,
20854 no_bgp_community_list_expanded_all_list_cmd,
a2099c1d 20855 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
36d4bb44 20856 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
20857 "Community list number (expanded)\n"
20858 "Add an expanded community-list entry\n"
20859 "Community list name\n")
20860
8d9b8ed9
PM
20861/* Return configuration string of community-list entry. */
20862static const char *community_list_config_str(struct community_entry *entry)
20863{
20864 const char *str;
20865
75aaf03f
DS
20866 if (entry->style == COMMUNITY_LIST_STANDARD)
20867 str = community_str(entry->u.com, false, false);
20868 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
20869 str = lcommunity_str(entry->u.lcom, false, false);
20870 else
20871 str = entry->config;
20872
8d9b8ed9
PM
20873 return str;
20874}
20875
d62a17ae 20876static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 20877{
d62a17ae 20878 struct community_entry *entry;
718e3744 20879
d62a17ae 20880 for (entry = list->head; entry; entry = entry->next) {
20881 if (entry == list->head) {
20882 if (all_digit(list->name))
20883 vty_out(vty, "Community %s list %s\n",
20884 entry->style == COMMUNITY_LIST_STANDARD
20885 ? "standard"
20886 : "(expanded) access",
20887 list->name);
20888 else
20889 vty_out(vty, "Named Community %s list %s\n",
20890 entry->style == COMMUNITY_LIST_STANDARD
20891 ? "standard"
20892 : "expanded",
20893 list->name);
20894 }
75aaf03f
DS
20895 vty_out(vty, " %s %s\n", community_direct_str(entry->direct),
20896 community_list_config_str(entry));
d62a17ae 20897 }
718e3744 20898}
20899
7336e101
SP
20900DEFUN (show_community_list,
20901 show_bgp_community_list_cmd,
20902 "show bgp community-list",
718e3744 20903 SHOW_STR
7336e101 20904 BGP_STR
718e3744 20905 "List community-list\n")
20906{
d62a17ae 20907 struct community_list *list;
20908 struct community_list_master *cm;
718e3744 20909
d62a17ae 20910 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20911 if (!cm)
20912 return CMD_SUCCESS;
718e3744 20913
d62a17ae 20914 for (list = cm->num.head; list; list = list->next)
20915 community_list_show(vty, list);
718e3744 20916
d62a17ae 20917 for (list = cm->str.head; list; list = list->next)
20918 community_list_show(vty, list);
718e3744 20919
d62a17ae 20920 return CMD_SUCCESS;
718e3744 20921}
20922
7336e101
SP
20923DEFUN (show_community_list_arg,
20924 show_bgp_community_list_arg_cmd,
a2099c1d 20925 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
7336e101
SP
20926 SHOW_STR
20927 BGP_STR
718e3744 20928 "List community-list\n"
20929 "Community-list number\n"
960b69b9 20930 "Community-list name\n"
20931 "Detailed information on community-list\n")
718e3744 20932{
d62a17ae 20933 int idx_comm_list = 3;
20934 struct community_list *list;
718e3744 20935
e237b0d2 20936 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20937 COMMUNITY_LIST_MASTER);
20938 if (!list) {
20939 vty_out(vty, "%% Can't find community-list\n");
20940 return CMD_WARNING;
20941 }
718e3744 20942
d62a17ae 20943 community_list_show(vty, list);
718e3744 20944
d62a17ae 20945 return CMD_SUCCESS;
718e3744 20946}
6b0655a2 20947
57d187bc
JS
20948/*
20949 * Large Community code.
20950 */
d62a17ae 20951static int lcommunity_list_set_vty(struct vty *vty, int argc,
20952 struct cmd_token **argv, int style,
20953 int reject_all_digit_name)
20954{
20955 int ret;
20956 int direct;
20957 char *str;
20958 int idx = 0;
20959 char *cl_name;
2f8cc0e5
DA
20960 char *seq = NULL;
20961
a08032fe 20962 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 20963 seq = argv[idx]->arg;
d62a17ae 20964
2f8cc0e5 20965 idx = 0;
d62a17ae 20966 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20967 : COMMUNITY_DENY;
20968
20969 /* All digit name check. */
20970 idx = 0;
a2099c1d 20971 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20972 argv_find(argv, argc, "(1-99)", &idx);
20973 argv_find(argv, argc, "(100-500)", &idx);
20974 cl_name = argv[idx]->arg;
20975 if (reject_all_digit_name && all_digit(cl_name)) {
20976 vty_out(vty, "%% Community name cannot have all digits\n");
20977 return CMD_WARNING_CONFIG_FAILED;
20978 }
20979
20980 idx = 0;
20981 argv_find(argv, argc, "AA:BB:CC", &idx);
20982 argv_find(argv, argc, "LINE", &idx);
20983 /* Concat community string argument. */
20984 if (idx)
20985 str = argv_concat(argv, argc, idx);
20986 else
20987 str = NULL;
20988
2f8cc0e5 20989 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 20990
20991 /* Free temporary community list string allocated by
20992 argv_concat(). */
0a22ddfb 20993 XFREE(MTYPE_TMP, str);
d62a17ae 20994
20995 if (ret < 0) {
20996 community_list_perror(vty, ret);
20997 return CMD_WARNING_CONFIG_FAILED;
20998 }
20999 return CMD_SUCCESS;
21000}
21001
21002static int lcommunity_list_unset_vty(struct vty *vty, int argc,
21003 struct cmd_token **argv, int style)
21004{
21005 int ret;
21006 int direct = 0;
21007 char *str = NULL;
21008 int idx = 0;
2f8cc0e5 21009 char *seq = NULL;
d62a17ae 21010
a08032fe 21011 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 21012 seq = argv[idx]->arg;
d62a17ae 21013
2f8cc0e5 21014 idx = 0;
d62a17ae 21015 argv_find(argv, argc, "permit", &idx);
21016 argv_find(argv, argc, "deny", &idx);
21017
21018 if (idx) {
21019 /* Check the list direct. */
21020 if (strncmp(argv[idx]->arg, "p", 1) == 0)
21021 direct = COMMUNITY_PERMIT;
21022 else
21023 direct = COMMUNITY_DENY;
21024
21025 idx = 0;
21026 argv_find(argv, argc, "LINE", &idx);
21027 argv_find(argv, argc, "AA:AA:NN", &idx);
21028 /* Concat community string argument. */
21029 str = argv_concat(argv, argc, idx);
21030 }
21031
21032 idx = 0;
21033 argv_find(argv, argc, "(1-99)", &idx);
21034 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 21035 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21036
21037 /* Unset community list. */
2f8cc0e5 21038 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 21039 style);
21040
21041 /* Free temporary community list string allocated by
21042 argv_concat(). */
0a22ddfb 21043 XFREE(MTYPE_TMP, str);
d62a17ae 21044
21045 if (ret < 0) {
21046 community_list_perror(vty, ret);
21047 return CMD_WARNING_CONFIG_FAILED;
21048 }
21049
21050 return CMD_SUCCESS;
57d187bc
JS
21051}
21052
21053/* "large-community-list" keyword help string. */
21054#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
21055#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
21056
7336e101
SP
21057DEFUN (lcommunity_list_standard,
21058 bgp_lcommunity_list_standard_cmd,
a08032fe 21059 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
21060 BGP_STR
21061 LCOMMUNITY_LIST_STR
21062 "Large Community list number (standard)\n"
2f8cc0e5
DA
21063 "Sequence number of an entry\n"
21064 "Sequence number\n"
7336e101
SP
21065 "Specify large community to reject\n"
21066 "Specify large community to accept\n"
21067 LCOMMUNITY_VAL_STR)
52951b63 21068{
d62a17ae 21069 return lcommunity_list_set_vty(vty, argc, argv,
21070 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
21071}
21072
7336e101
SP
21073DEFUN (lcommunity_list_expanded,
21074 bgp_lcommunity_list_expanded_cmd,
a08032fe 21075 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21076 BGP_STR
21077 LCOMMUNITY_LIST_STR
21078 "Large Community list number (expanded)\n"
2f8cc0e5
DA
21079 "Sequence number of an entry\n"
21080 "Sequence number\n"
7336e101
SP
21081 "Specify large community to reject\n"
21082 "Specify large community to accept\n"
21083 "An ordered list as a regular-expression\n")
57d187bc 21084{
d62a17ae 21085 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 21086 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
21087}
21088
7336e101
SP
21089DEFUN (lcommunity_list_name_standard,
21090 bgp_lcommunity_list_name_standard_cmd,
a2099c1d 21091 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
21092 BGP_STR
21093 LCOMMUNITY_LIST_STR
21094 "Specify standard large-community-list\n"
21095 "Large Community list name\n"
2f8cc0e5
DA
21096 "Sequence number of an entry\n"
21097 "Sequence number\n"
7336e101
SP
21098 "Specify large community to reject\n"
21099 "Specify large community to accept\n"
21100 LCOMMUNITY_VAL_STR)
52951b63 21101{
d62a17ae 21102 return lcommunity_list_set_vty(vty, argc, argv,
21103 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
21104}
21105
7336e101
SP
21106DEFUN (lcommunity_list_name_expanded,
21107 bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 21108 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21109 BGP_STR
21110 LCOMMUNITY_LIST_STR
21111 "Specify expanded large-community-list\n"
21112 "Large Community list name\n"
2f8cc0e5
DA
21113 "Sequence number of an entry\n"
21114 "Sequence number\n"
7336e101
SP
21115 "Specify large community to reject\n"
21116 "Specify large community to accept\n"
21117 "An ordered list as a regular-expression\n")
57d187bc 21118{
d62a17ae 21119 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 21120 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
21121}
21122
4378f57c
DA
21123DEFUN (no_lcommunity_list_all,
21124 no_bgp_lcommunity_list_all_cmd,
a2099c1d 21125 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
7336e101
SP
21126 NO_STR
21127 BGP_STR
21128 LCOMMUNITY_LIST_STR
21129 "Large Community list number (standard)\n"
21130 "Large Community list number (expanded)\n"
21131 "Large Community list name\n")
57d187bc 21132{
7336e101
SP
21133 return lcommunity_list_unset_vty(vty, argc, argv,
21134 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
21135}
21136
4378f57c
DA
21137DEFUN (no_lcommunity_list_name_standard_all,
21138 no_bgp_lcommunity_list_name_standard_all_cmd,
a2099c1d 21139 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
4378f57c
DA
21140 NO_STR
21141 BGP_STR
21142 LCOMMUNITY_LIST_STR
21143 "Specify standard large-community-list\n"
21144 "Large Community list name\n")
21145{
21146 return lcommunity_list_unset_vty(vty, argc, argv,
21147 LARGE_COMMUNITY_LIST_STANDARD);
21148}
21149
7336e101
SP
21150DEFUN (no_lcommunity_list_name_expanded_all,
21151 no_bgp_lcommunity_list_name_expanded_all_cmd,
a2099c1d 21152 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
7336e101
SP
21153 NO_STR
21154 BGP_STR
21155 LCOMMUNITY_LIST_STR
21156 "Specify expanded large-community-list\n"
21157 "Large Community list name\n")
57d187bc 21158{
d62a17ae 21159 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 21160 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
21161}
21162
7336e101
SP
21163DEFUN (no_lcommunity_list_standard,
21164 no_bgp_lcommunity_list_standard_cmd,
a08032fe 21165 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
21166 NO_STR
21167 BGP_STR
21168 LCOMMUNITY_LIST_STR
21169 "Large Community list number (standard)\n"
2f8cc0e5
DA
21170 "Sequence number of an entry\n"
21171 "Sequence number\n"
7336e101
SP
21172 "Specify large community to reject\n"
21173 "Specify large community to accept\n"
21174 LCOMMUNITY_VAL_STR)
57d187bc 21175{
d62a17ae 21176 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 21177 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
21178}
21179
7336e101
SP
21180DEFUN (no_lcommunity_list_expanded,
21181 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 21182 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21183 NO_STR
21184 BGP_STR
21185 LCOMMUNITY_LIST_STR
21186 "Large Community list number (expanded)\n"
2f8cc0e5
DA
21187 "Sequence number of an entry\n"
21188 "Sequence number\n"
7336e101
SP
21189 "Specify large community to reject\n"
21190 "Specify large community to accept\n"
21191 "An ordered list as a regular-expression\n")
57d187bc 21192{
d62a17ae 21193 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 21194 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
21195}
21196
7336e101
SP
21197DEFUN (no_lcommunity_list_name_standard,
21198 no_bgp_lcommunity_list_name_standard_cmd,
a2099c1d 21199 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
21200 NO_STR
21201 BGP_STR
21202 LCOMMUNITY_LIST_STR
21203 "Specify standard large-community-list\n"
21204 "Large Community list name\n"
2f8cc0e5
DA
21205 "Sequence number of an entry\n"
21206 "Sequence number\n"
7336e101
SP
21207 "Specify large community to reject\n"
21208 "Specify large community to accept\n"
21209 LCOMMUNITY_VAL_STR)
57d187bc 21210{
d62a17ae 21211 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 21212 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
21213}
21214
7336e101
SP
21215DEFUN (no_lcommunity_list_name_expanded,
21216 no_bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 21217 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21218 NO_STR
21219 BGP_STR
21220 LCOMMUNITY_LIST_STR
21221 "Specify expanded large-community-list\n"
21222 "Large community list name\n"
2f8cc0e5
DA
21223 "Sequence number of an entry\n"
21224 "Sequence number\n"
7336e101
SP
21225 "Specify large community to reject\n"
21226 "Specify large community to accept\n"
21227 "An ordered list as a regular-expression\n")
57d187bc 21228{
d62a17ae 21229 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 21230 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
21231}
21232
d62a17ae 21233static void lcommunity_list_show(struct vty *vty, struct community_list *list)
21234{
21235 struct community_entry *entry;
21236
21237 for (entry = list->head; entry; entry = entry->next) {
21238 if (entry == list->head) {
21239 if (all_digit(list->name))
21240 vty_out(vty, "Large community %s list %s\n",
169b72c8 21241 entry->style ==
21242 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 21243 ? "standard"
21244 : "(expanded) access",
21245 list->name);
21246 else
21247 vty_out(vty,
21248 "Named large community %s list %s\n",
169b72c8 21249 entry->style ==
21250 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 21251 ? "standard"
21252 : "expanded",
21253 list->name);
21254 }
75aaf03f
DS
21255 vty_out(vty, " %s %s\n", community_direct_str(entry->direct),
21256 community_list_config_str(entry));
d62a17ae 21257 }
57d187bc
JS
21258}
21259
7336e101
SP
21260DEFUN (show_lcommunity_list,
21261 show_bgp_lcommunity_list_cmd,
21262 "show bgp large-community-list",
57d187bc 21263 SHOW_STR
7336e101 21264 BGP_STR
57d187bc
JS
21265 "List large-community list\n")
21266{
d62a17ae 21267 struct community_list *list;
21268 struct community_list_master *cm;
57d187bc 21269
d62a17ae 21270 cm = community_list_master_lookup(bgp_clist,
21271 LARGE_COMMUNITY_LIST_MASTER);
21272 if (!cm)
21273 return CMD_SUCCESS;
57d187bc 21274
d62a17ae 21275 for (list = cm->num.head; list; list = list->next)
21276 lcommunity_list_show(vty, list);
57d187bc 21277
d62a17ae 21278 for (list = cm->str.head; list; list = list->next)
21279 lcommunity_list_show(vty, list);
57d187bc 21280
d62a17ae 21281 return CMD_SUCCESS;
57d187bc
JS
21282}
21283
7336e101
SP
21284DEFUN (show_lcommunity_list_arg,
21285 show_bgp_lcommunity_list_arg_cmd,
a2099c1d 21286 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
7336e101
SP
21287 SHOW_STR
21288 BGP_STR
57d187bc 21289 "List large-community list\n"
960b69b9 21290 "Large-community-list number\n"
21291 "Large-community-list name\n"
21292 "Detailed information on large-community-list\n")
57d187bc 21293{
d62a17ae 21294 struct community_list *list;
57d187bc 21295
e237b0d2 21296 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 21297 LARGE_COMMUNITY_LIST_MASTER);
21298 if (!list) {
960b69b9 21299 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 21300 return CMD_WARNING;
21301 }
57d187bc 21302
d62a17ae 21303 lcommunity_list_show(vty, list);
57d187bc 21304
d62a17ae 21305 return CMD_SUCCESS;
57d187bc
JS
21306}
21307
718e3744 21308/* "extcommunity-list" keyword help string. */
21309#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
21310#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
21311
7336e101
SP
21312DEFUN (extcommunity_list_standard,
21313 bgp_extcommunity_list_standard_cmd,
a2099c1d 21314 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 21315 BGP_STR
718e3744 21316 EXTCOMMUNITY_LIST_STR
21317 "Extended Community list number (standard)\n"
718e3744 21318 "Specify standard extcommunity-list\n"
5bf15956 21319 "Community list name\n"
2f8cc0e5
DA
21320 "Sequence number of an entry\n"
21321 "Sequence number\n"
718e3744 21322 "Specify community to reject\n"
21323 "Specify community to accept\n"
21324 EXTCOMMUNITY_VAL_STR)
21325{
d62a17ae 21326 int style = EXTCOMMUNITY_LIST_STANDARD;
21327 int direct = 0;
21328 char *cl_number_or_name = NULL;
2f8cc0e5 21329 char *seq = NULL;
42f914d4 21330
d62a17ae 21331 int idx = 0;
7b9a4750 21332
d62a17ae 21333 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 21334 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21335 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 21336
a08032fe 21337 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21338 seq = argv[idx]->arg;
21339
d62a17ae 21340 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21341 : COMMUNITY_DENY;
21342 argv_find(argv, argc, "AA:NN", &idx);
21343 char *str = argv_concat(argv, argc, idx);
42f914d4 21344
2f8cc0e5 21345 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 21346 direct, style);
42f914d4 21347
d62a17ae 21348 XFREE(MTYPE_TMP, str);
42f914d4 21349
d62a17ae 21350 if (ret < 0) {
21351 community_list_perror(vty, ret);
21352 return CMD_WARNING_CONFIG_FAILED;
21353 }
42f914d4 21354
d62a17ae 21355 return CMD_SUCCESS;
718e3744 21356}
21357
7336e101
SP
21358DEFUN (extcommunity_list_name_expanded,
21359 bgp_extcommunity_list_name_expanded_cmd,
a2099c1d 21360 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21361 BGP_STR
21362 EXTCOMMUNITY_LIST_STR
5bf15956 21363 "Extended Community list number (expanded)\n"
718e3744 21364 "Specify expanded extcommunity-list\n"
21365 "Extended Community list name\n"
2f8cc0e5
DA
21366 "Sequence number of an entry\n"
21367 "Sequence number\n"
718e3744 21368 "Specify community to reject\n"
21369 "Specify community to accept\n"
21370 "An ordered list as a regular-expression\n")
21371{
d62a17ae 21372 int style = EXTCOMMUNITY_LIST_EXPANDED;
21373 int direct = 0;
21374 char *cl_number_or_name = NULL;
2f8cc0e5 21375 char *seq = NULL;
d62a17ae 21376 int idx = 0;
7336e101 21377
d62a17ae 21378 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 21379 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21380 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 21381
a08032fe 21382 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21383 seq = argv[idx]->arg;
21384
d62a17ae 21385 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21386 : COMMUNITY_DENY;
21387 argv_find(argv, argc, "LINE", &idx);
21388 char *str = argv_concat(argv, argc, idx);
42f914d4 21389
2f8cc0e5 21390 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 21391 direct, style);
42f914d4 21392
d62a17ae 21393 XFREE(MTYPE_TMP, str);
42f914d4 21394
d62a17ae 21395 if (ret < 0) {
21396 community_list_perror(vty, ret);
21397 return CMD_WARNING_CONFIG_FAILED;
21398 }
42f914d4 21399
d62a17ae 21400 return CMD_SUCCESS;
718e3744 21401}
21402
7336e101
SP
21403DEFUN (no_extcommunity_list_standard_all,
21404 no_bgp_extcommunity_list_standard_all_cmd,
a2099c1d 21405 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
21406 NO_STR
21407 BGP_STR
21408 EXTCOMMUNITY_LIST_STR
813d4307 21409 "Extended Community list number (standard)\n"
718e3744 21410 "Specify standard extcommunity-list\n"
5bf15956 21411 "Community list name\n"
2f8cc0e5
DA
21412 "Sequence number of an entry\n"
21413 "Sequence number\n"
718e3744 21414 "Specify community to reject\n"
21415 "Specify community to accept\n"
21416 EXTCOMMUNITY_VAL_STR)
21417{
d62a17ae 21418 int style = EXTCOMMUNITY_LIST_STANDARD;
21419 int direct = 0;
21420 char *cl_number_or_name = NULL;
d4455c89 21421 char *str = NULL;
2f8cc0e5 21422 char *seq = NULL;
d62a17ae 21423 int idx = 0;
d4455c89 21424
a08032fe 21425 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21426 seq = argv[idx]->arg;
21427
21428 idx = 0;
d4455c89
DA
21429 argv_find(argv, argc, "permit", &idx);
21430 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
21431 if (idx) {
21432 direct = argv_find(argv, argc, "permit", &idx)
21433 ? COMMUNITY_PERMIT
21434 : COMMUNITY_DENY;
21435
21436 idx = 0;
21437 argv_find(argv, argc, "AA:NN", &idx);
21438 str = argv_concat(argv, argc, idx);
21439 }
21440
21441 idx = 0;
d62a17ae 21442 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 21443 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21444 cl_number_or_name = argv[idx]->arg;
42f914d4 21445
d62a17ae 21446 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 21447 seq, direct, style);
42f914d4 21448
d62a17ae 21449 XFREE(MTYPE_TMP, str);
42f914d4 21450
d62a17ae 21451 if (ret < 0) {
21452 community_list_perror(vty, ret);
21453 return CMD_WARNING_CONFIG_FAILED;
21454 }
42f914d4 21455
d62a17ae 21456 return CMD_SUCCESS;
718e3744 21457}
21458
d4455c89
DA
21459ALIAS(no_extcommunity_list_standard_all,
21460 no_bgp_extcommunity_list_standard_all_list_cmd,
a2099c1d 21461 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
36d4bb44 21462 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
21463 "Extended Community list number (standard)\n"
21464 "Specify standard extcommunity-list\n"
21465 "Community list name\n")
21466
7336e101
SP
21467DEFUN (no_extcommunity_list_expanded_all,
21468 no_bgp_extcommunity_list_expanded_all_cmd,
a2099c1d 21469 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21470 NO_STR
21471 BGP_STR
21472 EXTCOMMUNITY_LIST_STR
718e3744 21473 "Extended Community list number (expanded)\n"
718e3744 21474 "Specify expanded extcommunity-list\n"
5bf15956 21475 "Extended Community list name\n"
2f8cc0e5
DA
21476 "Sequence number of an entry\n"
21477 "Sequence number\n"
718e3744 21478 "Specify community to reject\n"
21479 "Specify community to accept\n"
21480 "An ordered list as a regular-expression\n")
21481{
d62a17ae 21482 int style = EXTCOMMUNITY_LIST_EXPANDED;
21483 int direct = 0;
21484 char *cl_number_or_name = NULL;
d4455c89 21485 char *str = NULL;
2f8cc0e5 21486 char *seq = NULL;
d62a17ae 21487 int idx = 0;
d4455c89 21488
a08032fe 21489 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21490 seq = argv[idx]->arg;
21491
21492 idx = 0;
d4455c89
DA
21493 argv_find(argv, argc, "permit", &idx);
21494 argv_find(argv, argc, "deny", &idx);
21495
21496 if (idx) {
21497 direct = argv_find(argv, argc, "permit", &idx)
21498 ? COMMUNITY_PERMIT
21499 : COMMUNITY_DENY;
21500
21501 idx = 0;
21502 argv_find(argv, argc, "LINE", &idx);
21503 str = argv_concat(argv, argc, idx);
21504 }
21505
21506 idx = 0;
d62a17ae 21507 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 21508 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21509 cl_number_or_name = argv[idx]->arg;
42f914d4 21510
d62a17ae 21511 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 21512 seq, direct, style);
42f914d4 21513
d62a17ae 21514 XFREE(MTYPE_TMP, str);
42f914d4 21515
d62a17ae 21516 if (ret < 0) {
21517 community_list_perror(vty, ret);
21518 return CMD_WARNING_CONFIG_FAILED;
21519 }
42f914d4 21520
d62a17ae 21521 return CMD_SUCCESS;
718e3744 21522}
21523
d4455c89
DA
21524ALIAS(no_extcommunity_list_expanded_all,
21525 no_bgp_extcommunity_list_expanded_all_list_cmd,
a2099c1d 21526 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
36d4bb44 21527 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
21528 "Extended Community list number (expanded)\n"
21529 "Specify expanded extcommunity-list\n"
21530 "Extended Community list name\n")
21531
d62a17ae 21532static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 21533{
d62a17ae 21534 struct community_entry *entry;
718e3744 21535
d62a17ae 21536 for (entry = list->head; entry; entry = entry->next) {
21537 if (entry == list->head) {
21538 if (all_digit(list->name))
21539 vty_out(vty, "Extended community %s list %s\n",
21540 entry->style == EXTCOMMUNITY_LIST_STANDARD
21541 ? "standard"
21542 : "(expanded) access",
21543 list->name);
21544 else
21545 vty_out(vty,
21546 "Named extended community %s list %s\n",
21547 entry->style == EXTCOMMUNITY_LIST_STANDARD
21548 ? "standard"
21549 : "expanded",
21550 list->name);
21551 }
75aaf03f
DS
21552 vty_out(vty, " %s %s\n", community_direct_str(entry->direct),
21553 community_list_config_str(entry));
d62a17ae 21554 }
718e3744 21555}
21556
7336e101
SP
21557DEFUN (show_extcommunity_list,
21558 show_bgp_extcommunity_list_cmd,
21559 "show bgp extcommunity-list",
718e3744 21560 SHOW_STR
7336e101 21561 BGP_STR
718e3744 21562 "List extended-community list\n")
21563{
d62a17ae 21564 struct community_list *list;
21565 struct community_list_master *cm;
718e3744 21566
d62a17ae 21567 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21568 if (!cm)
21569 return CMD_SUCCESS;
718e3744 21570
d62a17ae 21571 for (list = cm->num.head; list; list = list->next)
21572 extcommunity_list_show(vty, list);
718e3744 21573
d62a17ae 21574 for (list = cm->str.head; list; list = list->next)
21575 extcommunity_list_show(vty, list);
718e3744 21576
d62a17ae 21577 return CMD_SUCCESS;
718e3744 21578}
21579
7336e101
SP
21580DEFUN (show_extcommunity_list_arg,
21581 show_bgp_extcommunity_list_arg_cmd,
a2099c1d 21582 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
7336e101
SP
21583 SHOW_STR
21584 BGP_STR
718e3744 21585 "List extended-community list\n"
21586 "Extcommunity-list number\n"
960b69b9 21587 "Extcommunity-list name\n"
21588 "Detailed information on extcommunity-list\n")
718e3744 21589{
d62a17ae 21590 int idx_comm_list = 3;
21591 struct community_list *list;
718e3744 21592
e237b0d2 21593 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 21594 EXTCOMMUNITY_LIST_MASTER);
21595 if (!list) {
21596 vty_out(vty, "%% Can't find extcommunity-list\n");
21597 return CMD_WARNING;
21598 }
718e3744 21599
d62a17ae 21600 extcommunity_list_show(vty, list);
718e3744 21601
d62a17ae 21602 return CMD_SUCCESS;
718e3744 21603}
6b0655a2 21604
718e3744 21605/* Display community-list and extcommunity-list configuration. */
d62a17ae 21606static int community_list_config_write(struct vty *vty)
21607{
21608 struct community_list *list;
21609 struct community_entry *entry;
21610 struct community_list_master *cm;
21611 int write = 0;
21612
21613 /* Community-list. */
21614 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
21615
21616 for (list = cm->num.head; list; list = list->next)
21617 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21618 vty_out(vty,
21619 "bgp community-list %s seq %" PRId64 " %s %s\n",
21620 list->name, entry->seq,
d62a17ae 21621 community_direct_str(entry->direct),
21622 community_list_config_str(entry));
21623 write++;
21624 }
21625 for (list = cm->str.head; list; list = list->next)
21626 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21627 vty_out(vty,
21628 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 21629 entry->style == COMMUNITY_LIST_STANDARD
21630 ? "standard"
21631 : "expanded",
2f8cc0e5
DA
21632 list->name, entry->seq,
21633 community_direct_str(entry->direct),
d62a17ae 21634 community_list_config_str(entry));
21635 write++;
21636 }
21637
21638 /* Extcommunity-list. */
21639 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21640
21641 for (list = cm->num.head; list; list = list->next)
21642 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21643 vty_out(vty,
21644 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
21645 list->name, entry->seq,
21646 community_direct_str(entry->direct),
d62a17ae 21647 community_list_config_str(entry));
21648 write++;
21649 }
21650 for (list = cm->str.head; list; list = list->next)
21651 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21652 vty_out(vty,
6cde4b45 21653 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 21654 entry->style == EXTCOMMUNITY_LIST_STANDARD
21655 ? "standard"
21656 : "expanded",
2f8cc0e5
DA
21657 list->name, entry->seq,
21658 community_direct_str(entry->direct),
d62a17ae 21659 community_list_config_str(entry));
21660 write++;
21661 }
21662
21663
21664 /* lcommunity-list. */
21665 cm = community_list_master_lookup(bgp_clist,
21666 LARGE_COMMUNITY_LIST_MASTER);
21667
21668 for (list = cm->num.head; list; list = list->next)
21669 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21670 vty_out(vty,
6cde4b45 21671 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
21672 list->name, entry->seq,
21673 community_direct_str(entry->direct),
d62a17ae 21674 community_list_config_str(entry));
21675 write++;
21676 }
21677 for (list = cm->str.head; list; list = list->next)
21678 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21679 vty_out(vty,
6cde4b45 21680 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 21681
d62a17ae 21682 entry->style == LARGE_COMMUNITY_LIST_STANDARD
21683 ? "standard"
21684 : "expanded",
2f8cc0e5 21685 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 21686 community_list_config_str(entry));
21687 write++;
21688 }
21689
21690 return write;
21691}
21692
612c2c15 21693static int community_list_config_write(struct vty *vty);
d62a17ae 21694static struct cmd_node community_list_node = {
f4b8291f 21695 .name = "community list",
62b346ee
DL
21696 .node = COMMUNITY_LIST_NODE,
21697 .prompt = "",
612c2c15 21698 .config_write = community_list_config_write,
718e3744 21699};
21700
d62a17ae 21701static void community_list_vty(void)
21702{
612c2c15 21703 install_node(&community_list_node);
d62a17ae 21704
21705 /* Community-list. */
7336e101
SP
21706 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
21707 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
21708 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 21709 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 21710 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 21711 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
21712 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
21713 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 21714
21715 /* Extcommunity-list. */
7336e101
SP
21716 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
21717 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
21718 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
21719 install_element(CONFIG_NODE,
21720 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 21721 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
21722 install_element(CONFIG_NODE,
21723 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
21724 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
21725 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 21726
21727 /* Large Community List */
7336e101 21728 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
21729 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
21730 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 21731 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
21732 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
21733 install_element(CONFIG_NODE,
21734 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
21735 install_element(CONFIG_NODE,
21736 &no_bgp_lcommunity_list_name_expanded_all_cmd);
21737 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
21738 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
21739 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
21740 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
21741 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
21742 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
225096bc
DA
21743
21744 bgp_community_list_command_completion_setup();
5bf15956 21745}
ed0e57e3
DA
21746
21747static struct cmd_node community_alias_node = {
21748 .name = "community alias",
21749 .node = COMMUNITY_ALIAS_NODE,
21750 .prompt = "",
21751 .config_write = bgp_community_alias_write,
21752};
21753
21754void community_alias_vty(void)
21755{
21756 install_node(&community_alias_node);
21757
21758 /* Community-list. */
21759 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
b4ad2fae
DS
21760
21761 bgp_community_alias_command_completion_setup();
ed0e57e3 21762}