]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[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"
19#include "thread.h"
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;
1678 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1679 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1680 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1681 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1682 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1683 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1684 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1685 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1686 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1687 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1688 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1689 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1690 (bgp == bgp_get_evpn() &&
1691 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1692 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1693 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1694 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1695 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1696 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1697 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1698 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
f33bf7c0 1699 (hashcount(tmp_bgp->vnihash))) {
4fd9919e
IR
1700 vty_out(vty,
1701 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1702 return CMD_WARNING_CONFIG_FAILED;
1703 }
1704 }
1705 }
d62a17ae 1706 }
718e3744 1707
1ca2fd11 1708 bgp_delete(bgp);
718e3744 1709
1ca2fd11 1710 return CMD_SUCCESS;
718e3744 1711}
1712
425bd64b
PS
1713/* bgp session-dscp */
1714
1715DEFPY (bgp_session_dscp,
1716 bgp_session_dscp_cmd,
1717 "bgp session-dscp (0-63)$dscp",
1718 BGP_STR
1719 "Override default (C6) bgp TCP session DSCP value\n"
1720 "Manually configured dscp parameter\n")
1721{
1722 bm->tcp_dscp = dscp << 2;
1723
1724 return CMD_SUCCESS;
1725}
1726
1727DEFPY (no_bgp_session_dscp,
1728 no_bgp_session_dscp_cmd,
1729 "no bgp session-dscp [(0-63)]",
1730 NO_STR
1731 BGP_STR
1732 "Override default (C6) bgp TCP session DSCP value\n"
1733 "Manually configured dscp parameter\n")
1734{
1735 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1736
1737 return CMD_SUCCESS;
1738}
718e3744 1739
ff8a8a7a
CS
1740/* BGP router-id. */
1741
1ca2fd11
IR
1742DEFPY (bgp_router_id,
1743 bgp_router_id_cmd,
1744 "bgp router-id A.B.C.D",
1745 BGP_STR
1746 "Override configured router identifier\n"
1747 "Manually configured router identifier\n")
718e3744 1748{
1ca2fd11
IR
1749 VTY_DECLVAR_CONTEXT(bgp, bgp);
1750 bgp_router_id_static_set(bgp, router_id);
1751 return CMD_SUCCESS;
ff8a8a7a 1752}
718e3744 1753
1ca2fd11
IR
1754DEFPY (no_bgp_router_id,
1755 no_bgp_router_id_cmd,
1756 "no bgp router-id [A.B.C.D]",
1757 NO_STR
1758 BGP_STR
1759 "Override configured router identifier\n"
1760 "Manually configured router identifier\n")
ff8a8a7a 1761{
1ca2fd11 1762 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1763
1ca2fd11
IR
1764 if (router_id_str) {
1765 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1766 vty_out(vty, "%% BGP router-id doesn't match\n");
1767 return CMD_WARNING_CONFIG_FAILED;
1768 }
1769 }
718e3744 1770
1ca2fd11
IR
1771 router_id.s_addr = 0;
1772 bgp_router_id_static_set(bgp, router_id);
1773
1774 return CMD_SUCCESS;
ff8a8a7a 1775}
6b0655a2 1776
ed0e57e3 1777DEFPY(bgp_community_alias, bgp_community_alias_cmd,
b4ad2fae 1778 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
ed0e57e3
DA
1779 NO_STR BGP_STR
1780 "Add community specific parameters\n"
1781 "Create an alias for a community\n"
1782 "Community (AA:BB or AA:BB:CC)\n"
1783 "Alias name\n")
1784{
8cfa1e78 1785 struct community_alias ca = {};
ed0e57e3
DA
1786 struct community_alias *lookup_community;
1787 struct community_alias *lookup_alias;
d13d137a
DA
1788 struct community *comm;
1789 struct lcommunity *lcomm;
1790 uint8_t invalid = 0;
ed0e57e3 1791
d13d137a
DA
1792 comm = community_str2com(community);
1793 if (!comm)
1794 invalid++;
1795 community_free(&comm);
1796
1797 lcomm = lcommunity_str2com(community);
1798 if (!lcomm)
1799 invalid++;
1800 lcommunity_free(&lcomm);
1801
1802 if (invalid > 1) {
ed0e57e3
DA
1803 vty_out(vty, "Invalid community format\n");
1804 return CMD_WARNING;
1805 }
1806
8cfa1e78
DA
1807 strlcpy(ca.community, community, sizeof(ca.community));
1808 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
ed0e57e3 1809
8cfa1e78
DA
1810 lookup_community = bgp_ca_community_lookup(&ca);
1811 lookup_alias = bgp_ca_alias_lookup(&ca);
ed0e57e3
DA
1812
1813 if (no) {
8cfa1e78
DA
1814 bgp_ca_alias_delete(&ca);
1815 bgp_ca_community_delete(&ca);
ed0e57e3
DA
1816 } else {
1817 if (lookup_alias) {
1818 /* Lookup if community hash table has an item
1819 * with the same alias name.
1820 */
8cfa1e78
DA
1821 strlcpy(ca.community, lookup_alias->community,
1822 sizeof(ca.community));
1823 if (bgp_ca_community_lookup(&ca)) {
ed0e57e3
DA
1824 vty_out(vty,
1825 "community (%s) already has this alias (%s)\n",
1826 lookup_alias->community,
1827 lookup_alias->alias);
1828 return CMD_WARNING;
1829 }
8cfa1e78 1830 bgp_ca_alias_delete(&ca);
ed0e57e3
DA
1831 }
1832
8cfa1e78
DA
1833 if (lookup_community) {
1834 /* Lookup if alias hash table has an item
1835 * with the same community.
1836 */
1837 strlcpy(ca.alias, lookup_community->alias,
1838 sizeof(ca.alias));
1839 if (bgp_ca_alias_lookup(&ca)) {
1840 vty_out(vty,
1841 "alias (%s) already has this community (%s)\n",
1842 lookup_community->alias,
1843 lookup_community->community);
1844 return CMD_WARNING;
1845 }
1846 bgp_ca_community_delete(&ca);
1847 }
ed0e57e3 1848
8cfa1e78
DA
1849 bgp_ca_alias_insert(&ca);
1850 bgp_ca_community_insert(&ca);
ed0e57e3
DA
1851 }
1852
1853 return CMD_SUCCESS;
1854}
1855
9acb67cb
DS
1856DEFPY (bgp_global_suppress_fib_pending,
1857 bgp_global_suppress_fib_pending_cmd,
1858 "[no] bgp suppress-fib-pending",
1859 NO_STR
1860 BGP_STR
1861 "Advertise only routes that are programmed in kernel to peers globally\n")
1862{
1863 bm_wait_for_fib_set(!no);
1864
1865 return CMD_SUCCESS;
1866}
1867
c208c586
S
1868DEFPY (bgp_suppress_fib_pending,
1869 bgp_suppress_fib_pending_cmd,
1870 "[no] bgp suppress-fib-pending",
1871 NO_STR
1872 BGP_STR
1873 "Advertise only routes that are programmed in kernel to peers\n")
1874{
1875 VTY_DECLVAR_CONTEXT(bgp, bgp);
1876
1877 bgp_suppress_fib_pending_set(bgp, !no);
1878 return CMD_SUCCESS;
1879}
1880
718e3744 1881/* BGP Cluster ID. */
1ca2fd11
IR
1882DEFUN (bgp_cluster_id,
1883 bgp_cluster_id_cmd,
1884 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1885 BGP_STR
1886 "Configure Route-Reflector Cluster-id\n"
1887 "Route-Reflector Cluster-id in IP address format\n"
1888 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1889{
1ca2fd11 1890 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1891 int idx_ipv4 = 2;
1ca2fd11
IR
1892 int ret;
1893 struct in_addr cluster;
1894
1895 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1896 if (!ret) {
1897 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1898 return CMD_WARNING_CONFIG_FAILED;
1899 }
718e3744 1900
1ca2fd11
IR
1901 bgp_cluster_id_set(bgp, &cluster);
1902 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1903
1ca2fd11 1904 return CMD_SUCCESS;
718e3744 1905}
1906
1ca2fd11
IR
1907DEFUN (no_bgp_cluster_id,
1908 no_bgp_cluster_id_cmd,
1909 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1910 NO_STR
1911 BGP_STR
1912 "Configure Route-Reflector Cluster-id\n"
1913 "Route-Reflector Cluster-id in IP address format\n"
1914 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1915{
1ca2fd11
IR
1916 VTY_DECLVAR_CONTEXT(bgp, bgp);
1917 bgp_cluster_id_unset(bgp);
1918 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1919
1ca2fd11 1920 return CMD_SUCCESS;
718e3744 1921}
1922
c163f297
DS
1923DEFPY (bgp_norib,
1924 bgp_norib_cmd,
1925 "bgp no-rib",
1926 BGP_STR
1927 "Disable BGP route installation to RIB (Zebra)\n")
1928{
1929 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1930 vty_out(vty,
1931 "%% No-RIB option is already set, nothing to do here.\n");
1932 return CMD_SUCCESS;
1933 }
1934
1935 bgp_option_norib_set_runtime();
1936
1937 return CMD_SUCCESS;
1938}
1939
1940DEFPY (no_bgp_norib,
1941 no_bgp_norib_cmd,
1942 "no bgp no-rib",
1943 NO_STR
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 not set, nothing to do here.\n");
1950 return CMD_SUCCESS;
1951 }
1952
1953 bgp_option_norib_unset_runtime();
1954
1955 return CMD_SUCCESS;
1956}
1957
e46723a5
DS
1958DEFPY (no_bgp_send_extra_data,
1959 no_bgp_send_extra_data_cmd,
1960 "[no] bgp send-extra-data zebra",
1961 NO_STR
1962 BGP_STR
1963 "Extra data to Zebra for display/use\n"
1964 "To zebra\n")
1965{
ec0acb80
DA
1966 if (no)
1967 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1968 else
1969 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1970
1971 return CMD_SUCCESS;
1972}
1973
1ca2fd11
IR
1974DEFUN (bgp_confederation_identifier,
1975 bgp_confederation_identifier_cmd,
8079a413 1976 "bgp confederation identifier ASNUM",
e9273987 1977 BGP_STR
1ca2fd11 1978 "AS confederation parameters\n"
8079a413 1979 AS_STR
1ca2fd11 1980 "Set routing domain confederation AS\n")
718e3744 1981{
1ca2fd11 1982 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1983 int idx_number = 3;
1ca2fd11 1984 as_t as;
718e3744 1985
8079a413
PG
1986 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
1987 vty_out(vty, "%% BGP: No such AS %s\n", argv[idx_number]->arg);
1988 return CMD_WARNING_CONFIG_FAILED;
1989 }
718e3744 1990
7e14d0fa 1991 bgp_confederation_id_set(bgp, as, argv[idx_number]->arg);
718e3744 1992
1ca2fd11 1993 return CMD_SUCCESS;
718e3744 1994}
1995
1ca2fd11
IR
1996DEFUN (no_bgp_confederation_identifier,
1997 no_bgp_confederation_identifier_cmd,
8079a413 1998 "no bgp confederation identifier [ASNUM]",
1ca2fd11 1999 NO_STR
e9273987 2000 BGP_STR
1ca2fd11 2001 "AS confederation parameters\n"
8079a413 2002 AS_STR
1ca2fd11 2003 "Set routing domain confederation AS\n")
ff8a8a7a 2004{
1ca2fd11
IR
2005 VTY_DECLVAR_CONTEXT(bgp, bgp);
2006 bgp_confederation_id_unset(bgp);
2007
2008 return CMD_SUCCESS;
ff8a8a7a
CS
2009}
2010
1ca2fd11
IR
2011DEFUN (bgp_confederation_peers,
2012 bgp_confederation_peers_cmd,
8079a413 2013 "bgp confederation peers ASNUM...",
e9273987 2014 BGP_STR
1ca2fd11
IR
2015 "AS confederation parameters\n"
2016 "Peer ASs in BGP confederation\n"
2017 AS_STR)
718e3744 2018{
1ca2fd11 2019 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2020 int idx_asn = 3;
1ca2fd11 2021 as_t as;
d62a17ae 2022 int i;
718e3744 2023
1ca2fd11 2024 for (i = idx_asn; i < argc; i++) {
8079a413
PG
2025 if (!asn_str2asn(argv[i]->arg, &as)) {
2026 vty_out(vty, "%% Invalid confed peer AS value: %s\n",
2027 argv[i]->arg);
2028 continue;
2029 }
2030
7e14d0fa 2031 bgp_confederation_peers_add(bgp, as, argv[i]->arg);
1ca2fd11
IR
2032 }
2033 return CMD_SUCCESS;
718e3744 2034}
2035
1ca2fd11
IR
2036DEFUN (no_bgp_confederation_peers,
2037 no_bgp_confederation_peers_cmd,
8079a413 2038 "no bgp confederation peers ASNUM...",
1ca2fd11 2039 NO_STR
e9273987 2040 BGP_STR
1ca2fd11
IR
2041 "AS confederation parameters\n"
2042 "Peer ASs in BGP confederation\n"
2043 AS_STR)
718e3744 2044{
1ca2fd11 2045 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2046 int idx_asn = 4;
1ca2fd11 2047 as_t as;
d62a17ae 2048 int i;
718e3744 2049
1ca2fd11 2050 for (i = idx_asn; i < argc; i++) {
8079a413
PG
2051 if (!asn_str2asn(argv[i]->arg, &as)) {
2052 vty_out(vty, "%% Invalid confed peer AS value: %s\n",
2053 argv[i]->arg);
2054 continue;
2055 }
1ca2fd11
IR
2056 bgp_confederation_peers_remove(bgp, as);
2057 }
2058 return CMD_SUCCESS;
718e3744 2059}
6b0655a2 2060
5e242b0d
DS
2061/**
2062 * Central routine for maximum-paths configuration.
2063 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
2064 * @set: 1 for setting values, 0 for removing the max-paths config.
2065 */
585f1adc
IR
2066static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
2067 const char *mpaths, uint16_t options,
2068 int set)
d62a17ae 2069{
585f1adc
IR
2070 VTY_DECLVAR_CONTEXT(bgp, bgp);
2071 uint16_t maxpaths = 0;
d62a17ae 2072 int ret;
585f1adc
IR
2073 afi_t afi;
2074 safi_t safi;
2075
2076 afi = bgp_node_afi(vty);
2077 safi = bgp_node_safi(vty);
d62a17ae 2078
2079 if (set) {
585f1adc 2080 maxpaths = strtol(mpaths, NULL, 10);
d62a17ae 2081 if (maxpaths > multipath_num) {
585f1adc 2082 vty_out(vty,
d62a17ae 2083 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
2084 maxpaths, multipath_num);
2085 return CMD_WARNING_CONFIG_FAILED;
2086 }
2087 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
2088 options);
2089 } else
2090 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
2091
2092 if (ret < 0) {
585f1adc 2093 vty_out(vty,
d62a17ae 2094 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
2095 (set == 1) ? "" : "un",
2096 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
2097 maxpaths, afi, safi);
2098 return CMD_WARNING_CONFIG_FAILED;
2099 }
2100
2101 bgp_recalculate_all_bestpaths(bgp);
2102
2103 return CMD_SUCCESS;
165b5fff
JB
2104}
2105
1ca2fd11
IR
2106DEFUN (bgp_maxmed_admin,
2107 bgp_maxmed_admin_cmd,
2108 "bgp max-med administrative ",
2109 BGP_STR
2110 "Advertise routes with max-med\n"
2111 "Administratively applied, for an indefinite period\n")
abc920f8 2112{
1ca2fd11 2113 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 2114
1ca2fd11
IR
2115 bgp->v_maxmed_admin = 1;
2116 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
ff8a8a7a 2117
1ca2fd11 2118 bgp_maxmed_update(bgp);
abc920f8 2119
1ca2fd11 2120 return CMD_SUCCESS;
ff8a8a7a
CS
2121}
2122
1ca2fd11
IR
2123DEFUN (bgp_maxmed_admin_medv,
2124 bgp_maxmed_admin_medv_cmd,
2125 "bgp max-med administrative (0-4294967295)",
2126 BGP_STR
2127 "Advertise routes with max-med\n"
2128 "Administratively applied, for an indefinite period\n"
2129 "Max MED value to be used\n")
abc920f8 2130{
1ca2fd11 2131 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2132 int idx_number = 3;
abc920f8 2133
1ca2fd11
IR
2134 bgp->v_maxmed_admin = 1;
2135 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 2136
1ca2fd11 2137 bgp_maxmed_update(bgp);
abc920f8 2138
1ca2fd11 2139 return CMD_SUCCESS;
abc920f8
DS
2140}
2141
1ca2fd11
IR
2142DEFUN (no_bgp_maxmed_admin,
2143 no_bgp_maxmed_admin_cmd,
2144 "no bgp max-med administrative [(0-4294967295)]",
2145 NO_STR
2146 BGP_STR
2147 "Advertise routes with max-med\n"
2148 "Administratively applied, for an indefinite period\n"
2149 "Max MED value to be used\n")
abc920f8 2150{
1ca2fd11
IR
2151 VTY_DECLVAR_CONTEXT(bgp, bgp);
2152 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2153 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2154 bgp_maxmed_update(bgp);
ff8a8a7a 2155
1ca2fd11 2156 return CMD_SUCCESS;
abc920f8
DS
2157}
2158
1ca2fd11
IR
2159DEFUN (bgp_maxmed_onstartup,
2160 bgp_maxmed_onstartup_cmd,
2161 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2162 BGP_STR
2163 "Advertise routes with max-med\n"
2164 "Effective on a startup\n"
2165 "Time (seconds) period for max-med\n"
2166 "Max MED value to be used\n")
abc920f8 2167{
1ca2fd11 2168 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2169 int idx = 0;
4668a151 2170
9b01d289
DA
2171 if (argv_find(argv, argc, "(5-86400)", &idx))
2172 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 2173 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1ca2fd11 2174 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 2175 else
1ca2fd11 2176 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 2177
1ca2fd11
IR
2178 bgp_maxmed_update(bgp);
2179
2180 return CMD_SUCCESS;
abc920f8
DS
2181}
2182
1ca2fd11
IR
2183DEFUN (no_bgp_maxmed_onstartup,
2184 no_bgp_maxmed_onstartup_cmd,
2185 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2186 NO_STR
2187 BGP_STR
2188 "Advertise routes with max-med\n"
2189 "Effective on a startup\n"
2190 "Time (seconds) period for max-med\n"
2191 "Max MED value to be used\n")
abc920f8 2192{
1ca2fd11
IR
2193 VTY_DECLVAR_CONTEXT(bgp, bgp);
2194
2195 /* Cancel max-med onstartup if its on */
2196 if (bgp->t_maxmed_onstartup) {
c3aaa89a 2197 THREAD_OFF(bgp->t_maxmed_onstartup);
1ca2fd11
IR
2198 bgp->maxmed_onstartup_over = 1;
2199 }
abc920f8 2200
1ca2fd11
IR
2201 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2202 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 2203
1ca2fd11
IR
2204 bgp_maxmed_update(bgp);
2205
2206 return CMD_SUCCESS;
abc920f8
DS
2207}
2208
d70583f7
D
2209static int bgp_global_update_delay_config_vty(struct vty *vty,
2210 uint16_t update_delay,
2211 uint16_t establish_wait)
2212{
2213 struct listnode *node, *nnode;
2214 struct bgp *bgp;
2215 bool vrf_cfg = false;
2216
2217 /*
2218 * See if update-delay is set per-vrf and warn user to delete it
2219 * Note that we only need to check this if this is the first time
2220 * setting the global config.
2221 */
2222 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2223 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2224 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2225 vty_out(vty,
2226 "%% update-delay configuration found in vrf %s\n",
2227 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2228 ? VRF_DEFAULT_NAME
2229 : bgp->name);
2230 vrf_cfg = true;
2231 }
2232 }
2233 }
2234
2235 if (vrf_cfg) {
2236 vty_out(vty,
2237 "%%Failed: global update-delay config not permitted\n");
2238 return CMD_WARNING;
2239 }
2240
2241 if (!establish_wait) { /* update-delay <delay> */
2242 bm->v_update_delay = update_delay;
2243 bm->v_establish_wait = bm->v_update_delay;
2244 } else {
2245 /* update-delay <delay> <establish-wait> */
2246 if (update_delay < establish_wait) {
2247 vty_out(vty,
2248 "%%Failed: update-delay less than the establish-wait!\n");
2249 return CMD_WARNING_CONFIG_FAILED;
2250 }
2251
2252 bm->v_update_delay = update_delay;
2253 bm->v_establish_wait = establish_wait;
2254 }
2255
2256 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2257 bgp->v_update_delay = bm->v_update_delay;
2258 bgp->v_establish_wait = bm->v_establish_wait;
2259 }
2260
2261 return CMD_SUCCESS;
2262}
2263
2264static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2265{
2266 struct listnode *node, *nnode;
2267 struct bgp *bgp;
2268
2269 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2270 bm->v_establish_wait = bm->v_update_delay;
2271
2272 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2273 bgp->v_update_delay = bm->v_update_delay;
2274 bgp->v_establish_wait = bm->v_establish_wait;
2275 }
2276
2277 return CMD_SUCCESS;
2278}
2279
2280static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2281 uint16_t establish_wait)
f188f2c4 2282{
d62a17ae 2283 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2284
d70583f7
D
2285 /* if configured globally, per-instance config is not allowed */
2286 if (bm->v_update_delay) {
2287 vty_out(vty,
2288 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2289 return CMD_WARNING_CONFIG_FAILED;
2290 }
2291
f188f2c4 2292
d70583f7 2293 if (!establish_wait) /* update-delay <delay> */
d62a17ae 2294 {
2295 bgp->v_update_delay = update_delay;
2296 bgp->v_establish_wait = bgp->v_update_delay;
2297 return CMD_SUCCESS;
2298 }
f188f2c4 2299
d62a17ae 2300 /* update-delay <delay> <establish-wait> */
d62a17ae 2301 if (update_delay < establish_wait) {
2302 vty_out(vty,
2303 "%%Failed: update-delay less than the establish-wait!\n");
2304 return CMD_WARNING_CONFIG_FAILED;
2305 }
f188f2c4 2306
d62a17ae 2307 bgp->v_update_delay = update_delay;
2308 bgp->v_establish_wait = establish_wait;
f188f2c4 2309
d62a17ae 2310 return CMD_SUCCESS;
f188f2c4
DS
2311}
2312
d62a17ae 2313static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2314{
d62a17ae 2315 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2316
d70583f7
D
2317 /* If configured globally, cannot remove from one bgp instance */
2318 if (bm->v_update_delay) {
2319 vty_out(vty,
2320 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2321 return CMD_WARNING_CONFIG_FAILED;
2322 }
d62a17ae 2323 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2324 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2325
d62a17ae 2326 return CMD_SUCCESS;
f188f2c4
DS
2327}
2328
2b791107 2329void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2330{
d70583f7
D
2331 /* If configured globally, no need to display per-instance value */
2332 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2333 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2334 if (bgp->v_update_delay != bgp->v_establish_wait)
2335 vty_out(vty, " %d", bgp->v_establish_wait);
2336 vty_out(vty, "\n");
2337 }
f188f2c4
DS
2338}
2339
d70583f7
D
2340/* Global update-delay configuration */
2341DEFPY (bgp_global_update_delay,
2342 bgp_global_update_delay_cmd,
2343 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2344 BGP_STR
2345 "Force initial delay for best-path and updates for all bgp instances\n"
2346 "Max delay in seconds\n"
2347 "Establish wait in seconds\n")
2348{
2349 return bgp_global_update_delay_config_vty(vty, delay, wait);
2350}
f188f2c4 2351
d70583f7
D
2352/* Global update-delay deconfiguration */
2353DEFPY (no_bgp_global_update_delay,
2354 no_bgp_global_update_delay_cmd,
2355 "no bgp update-delay [(0-3600) [(1-3600)]]",
2356 NO_STR
2357 BGP_STR
f188f2c4 2358 "Force initial delay for best-path and updates\n"
d70583f7
D
2359 "Max delay in seconds\n"
2360 "Establish wait in seconds\n")
f188f2c4 2361{
d70583f7 2362 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2363}
2364
d70583f7
D
2365/* Update-delay configuration */
2366
2367DEFPY (bgp_update_delay,
2368 bgp_update_delay_cmd,
2369 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2370 "Force initial delay for best-path and updates\n"
d70583f7
D
2371 "Max delay in seconds\n"
2372 "Establish wait in seconds\n")
f188f2c4 2373{
d70583f7 2374 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2375}
2376
2377/* Update-delay deconfiguration */
d70583f7 2378DEFPY (no_bgp_update_delay,
f188f2c4 2379 no_bgp_update_delay_cmd,
838758ac
DW
2380 "no update-delay [(0-3600) [(1-3600)]]",
2381 NO_STR
f188f2c4 2382 "Force initial delay for best-path and updates\n"
d70583f7
D
2383 "Max delay in seconds\n"
2384 "Establish wait in seconds\n")
f188f2c4 2385{
d62a17ae 2386 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2387}
2388
5e242b0d 2389
1ca2fd11
IR
2390static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2391 bool set)
cb1faec9 2392{
1ca2fd11
IR
2393 VTY_DECLVAR_CONTEXT(bgp, bgp);
2394
8fa7732f
QY
2395 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2396 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2397
2398 return CMD_SUCCESS;
2399}
2400
1ca2fd11
IR
2401static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2402 bool set)
555e09d4 2403{
1ca2fd11
IR
2404 VTY_DECLVAR_CONTEXT(bgp, bgp);
2405
8fa7732f
QY
2406 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2407 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2408
d62a17ae 2409 return CMD_SUCCESS;
cb1faec9
DS
2410}
2411
2b791107 2412void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2413{
555e09d4
QY
2414 uint32_t quanta =
2415 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2416 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2417 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2418}
2419
555e09d4
QY
2420void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2421{
2422 uint32_t quanta =
2423 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2424 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2425 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2426}
cb1faec9 2427
8fa7732f
QY
2428/* Packet quanta configuration
2429 *
2430 * XXX: The value set here controls the size of a stack buffer in the IO
2431 * thread. When changing these limits be careful to prevent stack overflow.
2432 *
2433 * Furthermore, the maximums used here should correspond to
2434 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2435 */
1ca2fd11
IR
2436DEFPY (bgp_wpkt_quanta,
2437 bgp_wpkt_quanta_cmd,
2438 "[no] write-quanta (1-64)$quanta",
2439 NO_STR
2440 "How many packets to write to peer socket per run\n"
2441 "Number of packets\n")
2442{
2443 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2444}
cb1faec9 2445
1ca2fd11
IR
2446DEFPY (bgp_rpkt_quanta,
2447 bgp_rpkt_quanta_cmd,
2448 "[no] read-quanta (1-10)$quanta",
2449 NO_STR
2450 "How many packets to read from peer socket per I/O cycle\n"
2451 "Number of packets\n")
2452{
2453 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
2454}
2455
2b791107 2456void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2457{
37a333fe 2458 if (!bgp->heuristic_coalesce)
d62a17ae 2459 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2460}
2461
d1adb448
PG
2462/* BGP TCP keepalive */
2463static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2464{
2465 if (bgp->tcp_keepalive_idle) {
2466 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2467 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2468 bgp->tcp_keepalive_probes);
2469 }
2470}
4668a151 2471
1ca2fd11
IR
2472DEFUN (bgp_coalesce_time,
2473 bgp_coalesce_time_cmd,
2474 "coalesce-time (0-4294967295)",
2475 "Subgroup coalesce timer\n"
2476 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2477{
1ca2fd11 2478 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 2479
1ca2fd11 2480 int idx = 0;
9b01d289 2481
1ca2fd11 2482 bgp->heuristic_coalesce = false;
9b01d289
DA
2483
2484 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2485 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2486
1ca2fd11 2487 return CMD_SUCCESS;
3f9c7369
DS
2488}
2489
1ca2fd11
IR
2490DEFUN (no_bgp_coalesce_time,
2491 no_bgp_coalesce_time_cmd,
2492 "no coalesce-time (0-4294967295)",
2493 NO_STR
2494 "Subgroup coalesce timer\n"
2495 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2496{
1ca2fd11 2497 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 2498
1ca2fd11
IR
2499 bgp->heuristic_coalesce = true;
2500 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2501 return CMD_SUCCESS;
3f9c7369
DS
2502}
2503
5e242b0d 2504/* Maximum-paths configuration */
585f1adc
IR
2505DEFUN (bgp_maxpaths,
2506 bgp_maxpaths_cmd,
2507 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2508 "Forward packets over multiple paths\n"
2509 "Number of paths\n")
5e242b0d 2510{
d62a17ae 2511 int idx_number = 1;
585f1adc
IR
2512 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2513 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
2514}
2515
d62a17ae 2516ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2517 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2518 "Forward packets over multiple paths\n"
2519 "Number of paths\n")
596c17ba 2520
585f1adc
IR
2521DEFUN (bgp_maxpaths_ibgp,
2522 bgp_maxpaths_ibgp_cmd,
2523 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2524 "Forward packets over multiple paths\n"
2525 "iBGP-multipath\n"
2526 "Number of paths\n")
165b5fff 2527{
d62a17ae 2528 int idx_number = 2;
585f1adc
IR
2529 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2530 argv[idx_number]->arg, 0, 1);
5e242b0d 2531}
165b5fff 2532
d62a17ae 2533ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2534 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2535 "Forward packets over multiple paths\n"
2536 "iBGP-multipath\n"
2537 "Number of paths\n")
596c17ba 2538
585f1adc
IR
2539DEFUN (bgp_maxpaths_ibgp_cluster,
2540 bgp_maxpaths_ibgp_cluster_cmd,
2541 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2542 "Forward packets over multiple paths\n"
2543 "iBGP-multipath\n"
2544 "Number of paths\n"
2545 "Match the cluster length\n")
5e242b0d 2546{
d62a17ae 2547 int idx_number = 2;
aa53c036
DS
2548 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2549 argv[idx_number]->arg, true, 1);
165b5fff
JB
2550}
2551
d62a17ae 2552ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2553 "maximum-paths ibgp " CMD_RANGE_STR(
2554 1, MULTIPATH_NUM) " equal-cluster-length",
2555 "Forward packets over multiple paths\n"
2556 "iBGP-multipath\n"
2557 "Number of paths\n"
2558 "Match the cluster length\n")
596c17ba 2559
585f1adc
IR
2560DEFUN (no_bgp_maxpaths,
2561 no_bgp_maxpaths_cmd,
2562 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2563 NO_STR
2564 "Forward packets over multiple paths\n"
2565 "Number of paths\n")
165b5fff 2566{
585f1adc 2567 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
2568}
2569
d62a17ae 2570ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2571 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2572 "Forward packets over multiple paths\n"
2573 "Number of paths\n")
596c17ba 2574
585f1adc
IR
2575DEFUN (no_bgp_maxpaths_ibgp,
2576 no_bgp_maxpaths_ibgp_cmd,
2577 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2578 NO_STR
2579 "Forward packets over multiple paths\n"
2580 "iBGP-multipath\n"
2581 "Number of paths\n"
2582 "Match the cluster length\n")
165b5fff 2583{
585f1adc 2584 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
2585}
2586
d62a17ae 2587ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2588 "no maximum-paths ibgp [" CMD_RANGE_STR(
2589 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2590 NO_STR
2591 "Forward packets over multiple paths\n"
2592 "iBGP-multipath\n"
2593 "Number of paths\n"
2594 "Match the cluster length\n")
596c17ba 2595
dd65f45e
DL
2596static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2597 afi_t afi, safi_t safi)
165b5fff 2598{
00908b7a 2599 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2600 vty_out(vty, " maximum-paths %d\n",
2601 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2602 }
165b5fff 2603
00908b7a 2604 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2605 vty_out(vty, " maximum-paths ibgp %d",
2606 bgp->maxpaths[afi][safi].maxpaths_ibgp);
aa53c036 2607 if (bgp->maxpaths[afi][safi].same_clusterlen)
d62a17ae 2608 vty_out(vty, " equal-cluster-length");
2609 vty_out(vty, "\n");
2610 }
165b5fff 2611}
6b0655a2 2612
718e3744 2613/* BGP timers. */
2614
1ca2fd11
IR
2615DEFUN (bgp_timers,
2616 bgp_timers_cmd,
2617 "timers bgp (0-65535) (0-65535)",
2618 "Adjust routing timers\n"
2619 "BGP timers\n"
2620 "Keepalive interval\n"
2621 "Holdtime\n")
718e3744 2622{
1ca2fd11 2623 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2624 int idx_number = 2;
2625 int idx_number_2 = 3;
1ca2fd11
IR
2626 unsigned long keepalive = 0;
2627 unsigned long holdtime = 0;
718e3744 2628
1ca2fd11
IR
2629 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2630 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 2631
1ca2fd11
IR
2632 /* Holdtime value check. */
2633 if (holdtime < 3 && holdtime != 0) {
2634 vty_out(vty,
2635 "%% hold time value must be either 0 or greater than 3\n");
2636 return CMD_WARNING_CONFIG_FAILED;
2637 }
718e3744 2638
1ca2fd11
IR
2639 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2640 BGP_DEFAULT_DELAYOPEN);
718e3744 2641
1ca2fd11 2642 return CMD_SUCCESS;
718e3744 2643}
2644
1ca2fd11
IR
2645DEFUN (no_bgp_timers,
2646 no_bgp_timers_cmd,
2647 "no timers bgp [(0-65535) (0-65535)]",
2648 NO_STR
2649 "Adjust routing timers\n"
2650 "BGP timers\n"
2651 "Keepalive interval\n"
2652 "Holdtime\n")
718e3744 2653{
1ca2fd11
IR
2654 VTY_DECLVAR_CONTEXT(bgp, bgp);
2655 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2656 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
ff8a8a7a 2657
1ca2fd11 2658 return CMD_SUCCESS;
718e3744 2659}
2660
b042667a
TI
2661/* BGP minimum holdtime. */
2662
2663DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2664 "bgp minimum-holdtime (1-65535)",
2665 "BGP specific commands\n"
2666 "BGP minimum holdtime\n"
2667 "Seconds\n")
2668{
2669 VTY_DECLVAR_CONTEXT(bgp, bgp);
2670 int idx_number = 2;
2671 unsigned long min_holdtime;
2672
2673 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2674
2675 bgp->default_min_holdtime = min_holdtime;
2676
2677 return CMD_SUCCESS;
2678}
2679
2680DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2681 "no bgp minimum-holdtime [(1-65535)]",
2682 NO_STR
2683 "BGP specific commands\n"
2684 "BGP minimum holdtime\n"
2685 "Seconds\n")
2686{
2687 VTY_DECLVAR_CONTEXT(bgp, bgp);
2688
2689 bgp->default_min_holdtime = 0;
2690
2691 return CMD_SUCCESS;
2692}
ff8a8a7a 2693
d1adb448
PG
2694DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2695 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2696 BGP_STR
2697 "TCP keepalive parameters\n"
2698 "TCP keepalive idle time (seconds)\n"
2699 "TCP keepalive interval (seconds)\n"
2700 "TCP keepalive maximum probes\n")
2701{
2702 VTY_DECLVAR_CONTEXT(bgp, bgp);
2703
2704 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2705 (uint16_t)probes);
2706
2707 return CMD_SUCCESS;
2708}
2709
2710DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2711 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2712 NO_STR
2713 BGP_STR
2714 "TCP keepalive parameters\n"
2715 "TCP keepalive idle time (seconds)\n"
2716 "TCP keepalive interval (seconds)\n"
2717 "TCP keepalive maximum probes\n")
2718{
2719 VTY_DECLVAR_CONTEXT(bgp, bgp);
2720
2721 bgp_tcp_keepalive_unset(bgp);
2722
2723 return CMD_SUCCESS;
2724}
2725
1ca2fd11
IR
2726DEFUN (bgp_client_to_client_reflection,
2727 bgp_client_to_client_reflection_cmd,
2728 "bgp client-to-client reflection",
e9273987 2729 BGP_STR
1ca2fd11
IR
2730 "Configure client to client route reflection\n"
2731 "reflection of routes allowed\n")
718e3744 2732{
1ca2fd11
IR
2733 VTY_DECLVAR_CONTEXT(bgp, bgp);
2734 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2735 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2736
1ca2fd11 2737 return CMD_SUCCESS;
718e3744 2738}
2739
1ca2fd11
IR
2740DEFUN (no_bgp_client_to_client_reflection,
2741 no_bgp_client_to_client_reflection_cmd,
2742 "no bgp client-to-client reflection",
2743 NO_STR
e9273987 2744 BGP_STR
1ca2fd11
IR
2745 "Configure client to client route reflection\n"
2746 "reflection of routes allowed\n")
718e3744 2747{
1ca2fd11
IR
2748 VTY_DECLVAR_CONTEXT(bgp, bgp);
2749 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2750 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2751
1ca2fd11 2752 return CMD_SUCCESS;
718e3744 2753}
2754
2755/* "bgp always-compare-med" configuration. */
1ca2fd11
IR
2756DEFUN (bgp_always_compare_med,
2757 bgp_always_compare_med_cmd,
2758 "bgp always-compare-med",
e9273987 2759 BGP_STR
1ca2fd11 2760 "Allow comparing MED from different neighbors\n")
718e3744 2761{
1ca2fd11
IR
2762 VTY_DECLVAR_CONTEXT(bgp, bgp);
2763 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2764 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2765
1ca2fd11 2766 return CMD_SUCCESS;
718e3744 2767}
2768
1ca2fd11
IR
2769DEFUN (no_bgp_always_compare_med,
2770 no_bgp_always_compare_med_cmd,
2771 "no bgp always-compare-med",
2772 NO_STR
e9273987 2773 BGP_STR
1ca2fd11 2774 "Allow comparing MED from different neighbors\n")
718e3744 2775{
1ca2fd11
IR
2776 VTY_DECLVAR_CONTEXT(bgp, bgp);
2777 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2778 bgp_recalculate_all_bestpaths(bgp);
6b0655a2 2779
1ca2fd11 2780 return CMD_SUCCESS;
2adac256
DA
2781}
2782
2adac256 2783
1ca2fd11
IR
2784DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2785 "bgp ebgp-requires-policy",
e9273987 2786 BGP_STR
1ca2fd11 2787 "Require in and out policy for eBGP peers (RFC8212)\n")
2adac256 2788{
1ca2fd11
IR
2789 VTY_DECLVAR_CONTEXT(bgp, bgp);
2790 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2791 return CMD_SUCCESS;
2adac256
DA
2792}
2793
1ca2fd11
IR
2794DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2795 "no bgp ebgp-requires-policy",
2796 NO_STR
e9273987 2797 BGP_STR
1ca2fd11 2798 "Require in and out policy for eBGP peers (RFC8212)\n")
ff8a8a7a 2799{
1ca2fd11
IR
2800 VTY_DECLVAR_CONTEXT(bgp, bgp);
2801 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2802 return CMD_SUCCESS;
ff8a8a7a 2803}
9dac9fc8 2804
1ca2fd11
IR
2805DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2806 "bgp suppress-duplicates",
e9273987 2807 BGP_STR
1ca2fd11 2808 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2809{
1ca2fd11
IR
2810 VTY_DECLVAR_CONTEXT(bgp, bgp);
2811 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2812 return CMD_SUCCESS;
9dac9fc8
DA
2813}
2814
1ca2fd11
IR
2815DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2816 "no bgp suppress-duplicates",
2817 NO_STR
e9273987 2818 BGP_STR
1ca2fd11 2819 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2820{
1ca2fd11
IR
2821 VTY_DECLVAR_CONTEXT(bgp, bgp);
2822 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2823 return CMD_SUCCESS;
9dac9fc8
DA
2824}
2825
fb29348a
DA
2826DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2827 "bgp reject-as-sets",
e9273987 2828 BGP_STR
fb29348a
DA
2829 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2830{
2831 VTY_DECLVAR_CONTEXT(bgp, bgp);
2832 struct listnode *node, *nnode;
2833 struct peer *peer;
2834
7f972cd8 2835 bgp->reject_as_sets = true;
fb29348a
DA
2836
2837 /* Reset existing BGP sessions to reject routes
2838 * with aspath containing AS_SET or AS_CONFED_SET.
2839 */
2840 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2841 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2842 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2843 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2844 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2845 }
2846 }
2847
2848 return CMD_SUCCESS;
2849}
2850
2851DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2852 "no bgp reject-as-sets",
2853 NO_STR
e9273987 2854 BGP_STR
fb29348a
DA
2855 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2856{
2857 VTY_DECLVAR_CONTEXT(bgp, bgp);
2858 struct listnode *node, *nnode;
2859 struct peer *peer;
2860
7f972cd8 2861 bgp->reject_as_sets = false;
fb29348a
DA
2862
2863 /* Reset existing BGP sessions to reject routes
2864 * with aspath containing AS_SET or AS_CONFED_SET.
2865 */
2866 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2867 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2868 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2869 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2870 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2871 }
2872 }
2873
2874 return CMD_SUCCESS;
2875}
9dac9fc8 2876
718e3744 2877/* "bgp deterministic-med" configuration. */
1ca2fd11 2878DEFUN (bgp_deterministic_med,
718e3744 2879 bgp_deterministic_med_cmd,
2880 "bgp deterministic-med",
e9273987 2881 BGP_STR
718e3744 2882 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2883{
1ca2fd11
IR
2884 VTY_DECLVAR_CONTEXT(bgp, bgp);
2885
2886 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2887 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2888 bgp_recalculate_all_bestpaths(bgp);
2889 }
7aafcaca 2890
1ca2fd11 2891 return CMD_SUCCESS;
718e3744 2892}
2893
1ca2fd11 2894DEFUN (no_bgp_deterministic_med,
718e3744 2895 no_bgp_deterministic_med_cmd,
2896 "no bgp deterministic-med",
2897 NO_STR
e9273987 2898 BGP_STR
718e3744 2899 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2900{
1ca2fd11
IR
2901 VTY_DECLVAR_CONTEXT(bgp, bgp);
2902 int bestpath_per_as_used;
2903 afi_t afi;
2904 safi_t safi;
2905 struct peer *peer;
2906 struct listnode *node, *nnode;
2907
2908 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2909 bestpath_per_as_used = 0;
2910
2911 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2912 FOREACH_AFI_SAFI (afi, safi)
2913 if (bgp_addpath_dmed_required(
2914 peer->addpath_type[afi][safi])) {
2915 bestpath_per_as_used = 1;
2916 break;
2917 }
2918
2919 if (bestpath_per_as_used)
2920 break;
2921 }
2922
2923 if (bestpath_per_as_used) {
2924 vty_out(vty,
2925 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2926 return CMD_WARNING_CONFIG_FAILED;
2927 } else {
2928 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2929 bgp_recalculate_all_bestpaths(bgp);
2930 }
2931 }
d62a17ae 2932
1ca2fd11 2933 return CMD_SUCCESS;
718e3744 2934}
538621f2 2935
055679e9 2936/* "bgp graceful-restart mode" configuration. */
538621f2 2937DEFUN (bgp_graceful_restart,
2ba1fe69 2938 bgp_graceful_restart_cmd,
2939 "bgp graceful-restart",
e9273987 2940 BGP_STR
2ba1fe69 2941 GR_CMD
055679e9 2942 )
538621f2 2943{
055679e9 2944 int ret = BGP_GR_FAILURE;
2945
2946 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2947 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2948
d62a17ae 2949 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2950
2951 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2952
36235319
QY
2953 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2954 ret);
5cce3f05 2955
055679e9 2956 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2957 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2958 vty_out(vty,
2959 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2960 return bgp_vty_return(vty, ret);
538621f2 2961}
2962
2963DEFUN (no_bgp_graceful_restart,
2ba1fe69 2964 no_bgp_graceful_restart_cmd,
2965 "no bgp graceful-restart",
2966 NO_STR
e9273987 2967 BGP_STR
2ba1fe69 2968 NO_GR_CMD
055679e9 2969 )
538621f2 2970{
d62a17ae 2971 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2972
2973 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2974 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2975
2976 int ret = BGP_GR_FAILURE;
2977
2978 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2979
36235319
QY
2980 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2981 ret);
5cce3f05 2982
055679e9 2983 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2984 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2985 vty_out(vty,
2986 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2987
2988 return bgp_vty_return(vty, ret);
538621f2 2989}
2990
93406d87 2991DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2992 bgp_graceful_restart_stalepath_time_cmd,
2993 "bgp graceful-restart stalepath-time (1-4095)",
e9273987 2994 BGP_STR
2ba1fe69 2995 "Graceful restart capability parameters\n"
2996 "Set the max time to hold onto restarting peer's stale paths\n"
2997 "Delay value (seconds)\n")
93406d87 2998{
d62a17ae 2999 VTY_DECLVAR_CONTEXT(bgp, bgp);
3000 int idx_number = 3;
d7c0a89a 3001 uint32_t stalepath;
93406d87 3002
d62a17ae 3003 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
3004 bgp->stalepath_time = stalepath;
3005 return CMD_SUCCESS;
93406d87 3006}
3007
eb6f1b41 3008DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 3009 bgp_graceful_restart_restart_time_cmd,
dcbebfd3 3010 "bgp graceful-restart restart-time (0-4095)",
e9273987 3011 BGP_STR
2ba1fe69 3012 "Graceful restart capability parameters\n"
3013 "Set the time to wait to delete stale routes before a BGP open message is received\n"
3014 "Delay value (seconds)\n")
eb6f1b41 3015{
d62a17ae 3016 VTY_DECLVAR_CONTEXT(bgp, bgp);
3017 int idx_number = 3;
d7c0a89a 3018 uint32_t restart;
eb6f1b41 3019
d62a17ae 3020 restart = strtoul(argv[idx_number]->arg, NULL, 10);
3021 bgp->restart_time = restart;
3022 return CMD_SUCCESS;
eb6f1b41
PG
3023}
3024
cfd47646 3025DEFUN (bgp_graceful_restart_select_defer_time,
3026 bgp_graceful_restart_select_defer_time_cmd,
3027 "bgp graceful-restart select-defer-time (0-3600)",
e9273987 3028 BGP_STR
cfd47646 3029 "Graceful restart capability parameters\n"
3030 "Set the time to defer the BGP route selection after restart\n"
3031 "Delay value (seconds, 0 - disable)\n")
3032{
3033 VTY_DECLVAR_CONTEXT(bgp, bgp);
3034 int idx_number = 3;
3035 uint32_t defer_time;
3036
3037 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
3038 bgp->select_defer_time = defer_time;
3039 if (defer_time == 0)
892fedb6 3040 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 3041 else
892fedb6 3042 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 3043
3044 return CMD_SUCCESS;
3045}
3046
93406d87 3047DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 3048 no_bgp_graceful_restart_stalepath_time_cmd,
3049 "no bgp graceful-restart stalepath-time [(1-4095)]",
3050 NO_STR
e9273987 3051 BGP_STR
2ba1fe69 3052 "Graceful restart capability parameters\n"
3053 "Set the max time to hold onto restarting peer's stale paths\n"
3054 "Delay value (seconds)\n")
93406d87 3055{
d62a17ae 3056 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 3057
d62a17ae 3058 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
3059 return CMD_SUCCESS;
93406d87 3060}
3061
eb6f1b41 3062DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 3063 no_bgp_graceful_restart_restart_time_cmd,
dcbebfd3 3064 "no bgp graceful-restart restart-time [(0-4095)]",
2ba1fe69 3065 NO_STR
e9273987 3066 BGP_STR
2ba1fe69 3067 "Graceful restart capability parameters\n"
3068 "Set the time to wait to delete stale routes before a BGP open message is received\n"
3069 "Delay value (seconds)\n")
eb6f1b41 3070{
d62a17ae 3071 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 3072
d62a17ae 3073 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
3074 return CMD_SUCCESS;
eb6f1b41
PG
3075}
3076
cfd47646 3077DEFUN (no_bgp_graceful_restart_select_defer_time,
3078 no_bgp_graceful_restart_select_defer_time_cmd,
3079 "no bgp graceful-restart select-defer-time [(0-3600)]",
3080 NO_STR
e9273987 3081 BGP_STR
cfd47646 3082 "Graceful restart capability parameters\n"
3083 "Set the time to defer the BGP route selection after restart\n"
3084 "Delay value (seconds)\n")
3085{
3086 VTY_DECLVAR_CONTEXT(bgp, bgp);
3087
3088 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 3089 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 3090
3091 return CMD_SUCCESS;
3092}
3093
43fc21b3 3094DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 3095 bgp_graceful_restart_preserve_fw_cmd,
3096 "bgp graceful-restart preserve-fw-state",
e9273987 3097 BGP_STR
2ba1fe69 3098 "Graceful restart capability parameters\n"
3099 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 3100{
d62a17ae 3101 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3102 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 3103 return CMD_SUCCESS;
43fc21b3
JC
3104}
3105
3106DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 3107 no_bgp_graceful_restart_preserve_fw_cmd,
3108 "no bgp graceful-restart preserve-fw-state",
3109 NO_STR
e9273987 3110 BGP_STR
2ba1fe69 3111 "Graceful restart capability parameters\n"
3112 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 3113{
d62a17ae 3114 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3115 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 3116 return CMD_SUCCESS;
43fc21b3
JC
3117}
3118
f2ca5c5b
DA
3119DEFPY (bgp_graceful_restart_notification,
3120 bgp_graceful_restart_notification_cmd,
3121 "[no$no] bgp graceful-restart notification",
3122 NO_STR
3123 BGP_STR
3124 "Graceful restart capability parameters\n"
3125 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3126{
3127 VTY_DECLVAR_CONTEXT(bgp, bgp);
3128
3129 if (no)
3130 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3131 else
3132 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3133
3134 return CMD_SUCCESS;
3135}
3136
1ae314be
DA
3137DEFPY (bgp_administrative_reset,
3138 bgp_administrative_reset_cmd,
3139 "[no$no] bgp hard-administrative-reset",
3140 NO_STR
3141 BGP_STR
3142 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3143{
3144 VTY_DECLVAR_CONTEXT(bgp, bgp);
3145
3146 if (no)
3147 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3148 else
3149 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3150
3151 return CMD_SUCCESS;
3152}
3153
055679e9 3154DEFUN (bgp_graceful_restart_disable,
2ba1fe69 3155 bgp_graceful_restart_disable_cmd,
3156 "bgp graceful-restart-disable",
e9273987 3157 BGP_STR
2ba1fe69 3158 GR_DISABLE)
055679e9 3159{
3160 int ret = BGP_GR_FAILURE;
3161
3162 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3163 zlog_debug(
2ba1fe69 3164 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 3165
055679e9 3166 VTY_DECLVAR_CONTEXT(bgp, bgp);
3167
3168 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3169
dc95985f 3170 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3171 bgp->peer, ret);
5cce3f05 3172
055679e9 3173 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3174 zlog_debug(
2ba1fe69 3175 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 3176 vty_out(vty,
3177 "Graceful restart configuration changed, reset all peers to take effect\n");
3178
055679e9 3179 return bgp_vty_return(vty, ret);
3180}
3181
3182DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 3183 no_bgp_graceful_restart_disable_cmd,
3184 "no bgp graceful-restart-disable",
3185 NO_STR
e9273987 3186 BGP_STR
2ba1fe69 3187 NO_GR_DISABLE
055679e9 3188 )
3189{
3190 VTY_DECLVAR_CONTEXT(bgp, bgp);
3191
3192 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3193 zlog_debug(
2ba1fe69 3194 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 3195
3196 int ret = BGP_GR_FAILURE;
3197
3198 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3199
36235319
QY
3200 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3201 ret);
5cce3f05 3202
055679e9 3203 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3204 zlog_debug(
2ba1fe69 3205 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 3206 vty_out(vty,
3207 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 3208
3209 return bgp_vty_return(vty, ret);
3210}
3211
3212DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 3213 bgp_neighbor_graceful_restart_set_cmd,
3214 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3215 NEIGHBOR_STR
3216 NEIGHBOR_ADDR_STR2
3217 GR_NEIGHBOR_CMD
055679e9 3218 )
3219{
3220 int idx_peer = 1;
3221 struct peer *peer;
3222 int ret = BGP_GR_FAILURE;
3223
dc95985f 3224 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3225
055679e9 3226 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3227 zlog_debug(
2ba1fe69 3228 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 3229
055679e9 3230 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3231 if (!peer)
3232 return CMD_WARNING_CONFIG_FAILED;
3233
3234 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3235
dc95985f 3236 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3237 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3238
3239 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3240 zlog_debug(
2ba1fe69 3241 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3242 vty_out(vty,
3243 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3244
3245 return bgp_vty_return(vty, ret);
3246}
3247
3248DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 3249 no_bgp_neighbor_graceful_restart_set_cmd,
3250 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3251 NO_STR
3252 NEIGHBOR_STR
3253 NEIGHBOR_ADDR_STR2
3254 NO_GR_NEIGHBOR_CMD
055679e9 3255 )
3256{
3257 int idx_peer = 2;
3258 int ret = BGP_GR_FAILURE;
3259 struct peer *peer;
3260
dc95985f 3261 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3262
055679e9 3263 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3264 if (!peer)
3265 return CMD_WARNING_CONFIG_FAILED;
3266
3267 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3268 zlog_debug(
2ba1fe69 3269 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 3270
3271 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3272
dc95985f 3273 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3274 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3275
3276 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3277 zlog_debug(
2ba1fe69 3278 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3279 vty_out(vty,
3280 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3281
3282 return bgp_vty_return(vty, ret);
3283}
3284
3285DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 3286 bgp_neighbor_graceful_restart_helper_set_cmd,
3287 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3288 NEIGHBOR_STR
3289 NEIGHBOR_ADDR_STR2
3290 GR_NEIGHBOR_HELPER_CMD
055679e9 3291 )
3292{
3293 int idx_peer = 1;
3294 struct peer *peer;
3295 int ret = BGP_GR_FAILURE;
3296
dc95985f 3297 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3298
055679e9 3299 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3300 zlog_debug(
2ba1fe69 3301 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 3302
055679e9 3303 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3304
055679e9 3305 if (!peer)
3306 return CMD_WARNING_CONFIG_FAILED;
3307
3308
3309 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 3310
dc95985f 3311 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3312 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 3313
055679e9 3314 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3315 zlog_debug(
2ba1fe69 3316 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3317 vty_out(vty,
3318 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3319
3320 return bgp_vty_return(vty, ret);
3321}
3322
3323DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3324 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3325 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3326 NO_STR
3327 NEIGHBOR_STR
3328 NEIGHBOR_ADDR_STR2
3329 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3330 )
3331{
3332 int idx_peer = 2;
3333 int ret = BGP_GR_FAILURE;
3334 struct peer *peer;
3335
dc95985f 3336 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3337
055679e9 3338 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3339 if (!peer)
3340 return CMD_WARNING_CONFIG_FAILED;
3341
3342 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3343 zlog_debug(
2ba1fe69 3344 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3345
36235319 3346 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3347
dc95985f 3348 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3349 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3350
3351 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3352 zlog_debug(
2ba1fe69 3353 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3354 vty_out(vty,
3355 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3356
3357 return bgp_vty_return(vty, ret);
3358}
3359
3360DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3361 bgp_neighbor_graceful_restart_disable_set_cmd,
3362 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3363 NEIGHBOR_STR
3364 NEIGHBOR_ADDR_STR2
3365 GR_NEIGHBOR_DISABLE_CMD
055679e9 3366 )
3367{
3368 int idx_peer = 1;
3369 struct peer *peer;
3370 int ret = BGP_GR_FAILURE;
3371
dc95985f 3372 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3373
055679e9 3374 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3375 zlog_debug(
2ba1fe69 3376 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3377
3378 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3379 if (!peer)
3380 return CMD_WARNING_CONFIG_FAILED;
3381
36235319 3382 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3383
3384 if (peer->bgp->t_startup)
3385 bgp_peer_gr_flags_update(peer);
3386
dc95985f 3387 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3388 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3389
055679e9 3390 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3391 zlog_debug(
2ba1fe69 3392 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3393 vty_out(vty,
3394 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3395
3396 return bgp_vty_return(vty, ret);
3397}
3398
3399DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3400 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3401 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3402 NO_STR
3403 NEIGHBOR_STR
3404 NEIGHBOR_ADDR_STR2
3405 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3406 )
3407{
3408 int idx_peer = 2;
3409 int ret = BGP_GR_FAILURE;
3410 struct peer *peer;
3411
dc95985f 3412 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3413
055679e9 3414 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3415 if (!peer)
3416 return CMD_WARNING_CONFIG_FAILED;
3417
3418 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3419 zlog_debug(
2ba1fe69 3420 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3421
3422 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3423
dc95985f 3424 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3425 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3426
3427 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3428 zlog_debug(
2ba1fe69 3429 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3430 vty_out(vty,
3431 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3432
3433 return bgp_vty_return(vty, ret);
3434}
3435
4f770cf1
DA
3436DEFPY (neighbor_graceful_shutdown,
3437 neighbor_graceful_shutdown_cmd,
3438 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor graceful-shutdown",
3439 NO_STR
3440 NEIGHBOR_STR
3441 NEIGHBOR_ADDR_STR2
3442 "Graceful shutdown\n")
3443{
3444 afi_t afi;
3445 safi_t safi;
3446 struct peer *peer;
3447 VTY_DECLVAR_CONTEXT(bgp, bgp);
3448 int ret;
3449
3450 peer = peer_and_group_lookup_vty(vty, neighbor);
3451 if (!peer)
3452 return CMD_WARNING_CONFIG_FAILED;
3453
3454 if (no)
3455 ret = peer_flag_unset_vty(vty, neighbor,
3456 PEER_FLAG_GRACEFUL_SHUTDOWN);
3457 else
3458 ret = peer_flag_set_vty(vty, neighbor,
3459 PEER_FLAG_GRACEFUL_SHUTDOWN);
3460
3461 FOREACH_AFI_SAFI (afi, safi) {
3462 if (!peer->afc[afi][safi])
3463 continue;
3464
3465 bgp_clear(vty, bgp, afi, safi, clear_peer, BGP_CLEAR_SOFT_IN,
3466 neighbor);
3467 }
3468
3469 return ret;
3470}
3471
d6e3c15b 3472DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3473 bgp_graceful_restart_disable_eor_cmd,
3474 "bgp graceful-restart disable-eor",
e9273987 3475 BGP_STR
d6e3c15b 3476 "Graceful restart configuration parameters\n"
3477 "Disable EOR Check\n")
3478{
3479 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3480 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3481
d6e3c15b 3482 return CMD_SUCCESS;
3483}
3484
3485DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3486 no_bgp_graceful_restart_disable_eor_cmd,
3487 "no bgp graceful-restart disable-eor",
3488 NO_STR
e9273987 3489 BGP_STR
d6e3c15b 3490 "Graceful restart configuration parameters\n"
3491 "Disable EOR Check\n")
3492{
3493 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3494 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3495
3496 return CMD_SUCCESS;
3497}
3498
3499DEFUN (bgp_graceful_restart_rib_stale_time,
3500 bgp_graceful_restart_rib_stale_time_cmd,
3501 "bgp graceful-restart rib-stale-time (1-3600)",
e9273987 3502 BGP_STR
dc95985f 3503 "Graceful restart configuration parameters\n"
3504 "Specify the stale route removal timer in rib\n"
3505 "Delay value (seconds)\n")
3506{
3507 VTY_DECLVAR_CONTEXT(bgp, bgp);
3508 int idx_number = 3;
3509 uint32_t stale_time;
3510
3511 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3512 bgp->rib_stale_time = stale_time;
3513 /* Send the stale timer update message to RIB */
3514 if (bgp_zebra_stale_timer_update(bgp))
3515 return CMD_WARNING;
3516
3517 return CMD_SUCCESS;
3518}
3519
3520DEFUN (no_bgp_graceful_restart_rib_stale_time,
3521 no_bgp_graceful_restart_rib_stale_time_cmd,
3522 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3523 NO_STR
e9273987 3524 BGP_STR
dc95985f 3525 "Graceful restart configuration parameters\n"
3526 "Specify the stale route removal timer in rib\n"
3527 "Delay value (seconds)\n")
3528{
3529 VTY_DECLVAR_CONTEXT(bgp, bgp);
3530
3531 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3532 /* Send the stale timer update message to RIB */
3533 if (bgp_zebra_stale_timer_update(bgp))
3534 return CMD_WARNING;
3535
d6e3c15b 3536 return CMD_SUCCESS;
3537}
3538
8606be87 3539DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
5970204c 3540 "bgp long-lived-graceful-restart stale-time (1-16777215)",
7f8a9a24 3541 BGP_STR
8606be87
DA
3542 "Enable Long-lived Graceful Restart\n"
3543 "Specifies maximum time to wait before purging long-lived stale routes\n"
3544 "Stale time value (seconds)\n")
3545{
3546 VTY_DECLVAR_CONTEXT(bgp, bgp);
3547
3548 uint32_t llgr_stale_time;
3549
3550 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3551 bgp->llgr_stale_time = llgr_stale_time;
3552
3553 return CMD_SUCCESS;
3554}
3555
3556DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
5970204c 3557 "no bgp long-lived-graceful-restart stale-time [(1-16777215)]",
8606be87
DA
3558 NO_STR BGP_STR
3559 "Enable Long-lived Graceful Restart\n"
3560 "Specifies maximum time to wait before purging long-lived stale routes\n"
3561 "Stale time value (seconds)\n")
3562{
3563 VTY_DECLVAR_CONTEXT(bgp, bgp);
3564
3565 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3566
3567 return CMD_SUCCESS;
3568}
3569
1ca2fd11
IR
3570static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3571 struct bgp *bgp)
05bd726c 3572{
3573 bgp_static_redo_import_check(bgp);
3574 bgp_redistribute_redo(bgp);
1ca2fd11
IR
3575 bgp_clear_star_soft_out(vty, bgp->name);
3576 bgp_clear_star_soft_in(vty, bgp->name);
05bd726c 3577}
3578
3579static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3580{
3581 struct listnode *node, *nnode;
3582 struct bgp *bgp;
3583 bool vrf_cfg = false;
3584
3585 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3586 return CMD_SUCCESS;
3587
3588 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3589 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3590 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3591 vty_out(vty,
3592 "%% graceful-shutdown configuration found in vrf %s\n",
3593 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3594 VRF_DEFAULT_NAME : bgp->name);
3595 vrf_cfg = true;
3596 }
3597 }
3598
3599 if (vrf_cfg) {
3600 vty_out(vty,
3601 "%%Failed: global graceful-shutdown not permitted\n");
3602 return CMD_WARNING;
3603 }
3604
3605 /* Set flag globally */
3606 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3607
3608 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3609 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3610 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3611
3612 return CMD_SUCCESS;
3613}
3614
3615static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3616{
3617 struct listnode *node, *nnode;
3618 struct bgp *bgp;
3619
3620 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3621 return CMD_SUCCESS;
3622
3623 /* Unset flag globally */
3624 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3625
3626 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3627 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3628 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3629
3630 return CMD_SUCCESS;
3631}
3632
7f323236
DW
3633/* "bgp graceful-shutdown" configuration */
3634DEFUN (bgp_graceful_shutdown,
3635 bgp_graceful_shutdown_cmd,
3636 "bgp graceful-shutdown",
3637 BGP_STR
3638 "Graceful shutdown parameters\n")
3639{
05bd726c 3640 if (vty->node == CONFIG_NODE)
3641 return bgp_global_graceful_shutdown_config_vty(vty);
3642
1ca2fd11 3643 VTY_DECLVAR_CONTEXT(bgp, bgp);
7f323236 3644
1ca2fd11
IR
3645 /* if configured globally, per-instance config is not allowed */
3646 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3647 vty_out(vty,
3648 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3649 return CMD_WARNING_CONFIG_FAILED;
3650 }
3651
3652 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3653 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3654 bgp_initiate_graceful_shut_unshut(vty, bgp);
3655 }
3656
3657 return CMD_SUCCESS;
7f323236
DW
3658}
3659
1ca2fd11 3660DEFUN (no_bgp_graceful_shutdown,
7f323236
DW
3661 no_bgp_graceful_shutdown_cmd,
3662 "no bgp graceful-shutdown",
3663 NO_STR
3664 BGP_STR
3665 "Graceful shutdown parameters\n")
3666{
05bd726c 3667 if (vty->node == CONFIG_NODE)
3668 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3669
1ca2fd11 3670 VTY_DECLVAR_CONTEXT(bgp, bgp);
05bd726c 3671
1ca2fd11
IR
3672 /* If configured globally, cannot remove from one bgp instance */
3673 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3674 vty_out(vty,
3675 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3676 return CMD_WARNING_CONFIG_FAILED;
3677 }
7f323236 3678
1ca2fd11
IR
3679 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3680 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3681 bgp_initiate_graceful_shut_unshut(vty, bgp);
3682 }
3683
3684 return CMD_SUCCESS;
7f323236
DW
3685}
3686
718e3744 3687/* "bgp fast-external-failover" configuration. */
1ca2fd11 3688DEFUN (bgp_fast_external_failover,
718e3744 3689 bgp_fast_external_failover_cmd,
3690 "bgp fast-external-failover",
3691 BGP_STR
3692 "Immediately reset session if a link to a directly connected external peer goes down\n")
3693{
1ca2fd11
IR
3694 VTY_DECLVAR_CONTEXT(bgp, bgp);
3695 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3696 return CMD_SUCCESS;
718e3744 3697}
3698
1ca2fd11 3699DEFUN (no_bgp_fast_external_failover,
718e3744 3700 no_bgp_fast_external_failover_cmd,
3701 "no bgp fast-external-failover",
3702 NO_STR
3703 BGP_STR
3704 "Immediately reset session if a link to a directly connected external peer goes down\n")
3705{
1ca2fd11
IR
3706 VTY_DECLVAR_CONTEXT(bgp, bgp);
3707 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3708 return CMD_SUCCESS;
718e3744 3709}
6b0655a2 3710
97a52c82
DA
3711DEFPY (bgp_bestpath_aigp,
3712 bgp_bestpath_aigp_cmd,
3713 "[no$no] bgp bestpath aigp",
3714 NO_STR
3715 BGP_STR
3716 "Change the default bestpath selection\n"
3717 "Evaluate the AIGP attribute during the best path selection process\n")
3718{
3719 VTY_DECLVAR_CONTEXT(bgp, bgp);
3720
3721 if (no)
3722 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3723 else
3724 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3725
3726 bgp_recalculate_all_bestpaths(bgp);
3727
3728 return CMD_SUCCESS;
3729}
3730
718e3744 3731/* "bgp bestpath compare-routerid" configuration. */
1ca2fd11
IR
3732DEFUN (bgp_bestpath_compare_router_id,
3733 bgp_bestpath_compare_router_id_cmd,
3734 "bgp bestpath compare-routerid",
e9273987 3735 BGP_STR
1ca2fd11
IR
3736 "Change the default bestpath selection\n"
3737 "Compare router-id for identical EBGP paths\n")
718e3744 3738{
1ca2fd11
IR
3739 VTY_DECLVAR_CONTEXT(bgp, bgp);
3740 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3741 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3742
1ca2fd11 3743 return CMD_SUCCESS;
718e3744 3744}
3745
1ca2fd11
IR
3746DEFUN (no_bgp_bestpath_compare_router_id,
3747 no_bgp_bestpath_compare_router_id_cmd,
3748 "no bgp bestpath compare-routerid",
3749 NO_STR
e9273987 3750 BGP_STR
1ca2fd11
IR
3751 "Change the default bestpath selection\n"
3752 "Compare router-id for identical EBGP paths\n")
718e3744 3753{
1ca2fd11
IR
3754 VTY_DECLVAR_CONTEXT(bgp, bgp);
3755 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3756 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3757
1ca2fd11 3758 return CMD_SUCCESS;
718e3744 3759}
6b0655a2 3760
718e3744 3761/* "bgp bestpath as-path ignore" configuration. */
1ca2fd11
IR
3762DEFUN (bgp_bestpath_aspath_ignore,
3763 bgp_bestpath_aspath_ignore_cmd,
3764 "bgp bestpath as-path ignore",
e9273987 3765 BGP_STR
1ca2fd11
IR
3766 "Change the default bestpath selection\n"
3767 "AS-path attribute\n"
3768 "Ignore as-path length in selecting a route\n")
718e3744 3769{
1ca2fd11
IR
3770 VTY_DECLVAR_CONTEXT(bgp, bgp);
3771 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3772 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3773
1ca2fd11 3774 return CMD_SUCCESS;
718e3744 3775}
3776
1ca2fd11
IR
3777DEFUN (no_bgp_bestpath_aspath_ignore,
3778 no_bgp_bestpath_aspath_ignore_cmd,
3779 "no bgp bestpath as-path ignore",
3780 NO_STR
e9273987 3781 BGP_STR
1ca2fd11
IR
3782 "Change the default bestpath selection\n"
3783 "AS-path attribute\n"
3784 "Ignore as-path length in selecting a route\n")
718e3744 3785{
1ca2fd11
IR
3786 VTY_DECLVAR_CONTEXT(bgp, bgp);
3787 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3788 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3789
1ca2fd11 3790 return CMD_SUCCESS;
718e3744 3791}
6b0655a2 3792
6811845b 3793/* "bgp bestpath as-path confed" configuration. */
1ca2fd11 3794DEFUN (bgp_bestpath_aspath_confed,
6811845b 3795 bgp_bestpath_aspath_confed_cmd,
3796 "bgp bestpath as-path confed",
e9273987 3797 BGP_STR
6811845b 3798 "Change the default bestpath selection\n"
3799 "AS-path attribute\n"
3800 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3801{
1ca2fd11
IR
3802 VTY_DECLVAR_CONTEXT(bgp, bgp);
3803 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3804 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3805
1ca2fd11 3806 return CMD_SUCCESS;
6811845b 3807}
3808
1ca2fd11 3809DEFUN (no_bgp_bestpath_aspath_confed,
6811845b 3810 no_bgp_bestpath_aspath_confed_cmd,
3811 "no bgp bestpath as-path confed",
3812 NO_STR
e9273987 3813 BGP_STR
6811845b 3814 "Change the default bestpath selection\n"
3815 "AS-path attribute\n"
3816 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3817{
1ca2fd11
IR
3818 VTY_DECLVAR_CONTEXT(bgp, bgp);
3819 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3820 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3821
1ca2fd11 3822 return CMD_SUCCESS;
6811845b 3823}
6b0655a2 3824
2fdd455c 3825/* "bgp bestpath as-path multipath-relax" configuration. */
1ca2fd11 3826DEFUN (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3827 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3828 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
e9273987 3829 BGP_STR
16fc1eec
DS
3830 "Change the default bestpath selection\n"
3831 "AS-path attribute\n"
3832 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3833 "Generate an AS_SET\n"
16fc1eec
DS
3834 "Do not generate an AS_SET\n")
3835{
1ca2fd11 3836 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3837 int idx = 0;
1ca2fd11 3838 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 3839
1ca2fd11
IR
3840 /* no-as-set is now the default behavior so we can silently
3841 * ignore it */
d62a17ae 3842 if (argv_find(argv, argc, "as-set", &idx))
1ca2fd11 3843 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 3844 else
1ca2fd11 3845 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
7aafcaca 3846
1ca2fd11
IR
3847 bgp_recalculate_all_bestpaths(bgp);
3848
3849 return CMD_SUCCESS;
16fc1eec
DS
3850}
3851
1ca2fd11 3852DEFUN (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3853 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3854 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec 3855 NO_STR
e9273987 3856 BGP_STR
16fc1eec
DS
3857 "Change the default bestpath selection\n"
3858 "AS-path attribute\n"
3859 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3860 "Generate an AS_SET\n"
16fc1eec
DS
3861 "Do not generate an AS_SET\n")
3862{
1ca2fd11
IR
3863 VTY_DECLVAR_CONTEXT(bgp, bgp);
3864 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3865 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3866 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3867
1ca2fd11 3868 return CMD_SUCCESS;
2fdd455c 3869}
6b0655a2 3870
ee88563a
JM
3871/* "bgp bestpath peer-type multipath-relax" configuration. */
3872DEFUN(bgp_bestpath_peer_type_multipath_relax,
3873 bgp_bestpath_peer_type_multipath_relax_cmd,
3874 "bgp bestpath peer-type multipath-relax",
3875 BGP_STR
3876 "Change the default bestpath selection\n"
3877 "Peer type\n"
3878 "Allow load sharing across routes learned from different peer types\n")
3879{
3880 VTY_DECLVAR_CONTEXT(bgp, bgp);
3881 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3882 bgp_recalculate_all_bestpaths(bgp);
3883
3884 return CMD_SUCCESS;
3885}
3886
3887DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3888 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3889 "no bgp bestpath peer-type multipath-relax",
3890 NO_STR BGP_STR
3891 "Change the default bestpath selection\n"
3892 "Peer type\n"
3893 "Allow load sharing across routes learned from different peer types\n")
3894{
3895 VTY_DECLVAR_CONTEXT(bgp, bgp);
3896 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3897 bgp_recalculate_all_bestpaths(bgp);
3898
3899 return CMD_SUCCESS;
3900}
3901
848973c7 3902/* "bgp log-neighbor-changes" configuration. */
1ca2fd11
IR
3903DEFUN (bgp_log_neighbor_changes,
3904 bgp_log_neighbor_changes_cmd,
3905 "bgp log-neighbor-changes",
e9273987 3906 BGP_STR
1ca2fd11 3907 "Log neighbor up/down and reset reason\n")
848973c7 3908{
1ca2fd11
IR
3909 VTY_DECLVAR_CONTEXT(bgp, bgp);
3910 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3911 return CMD_SUCCESS;
848973c7 3912}
3913
1ca2fd11
IR
3914DEFUN (no_bgp_log_neighbor_changes,
3915 no_bgp_log_neighbor_changes_cmd,
3916 "no bgp log-neighbor-changes",
3917 NO_STR
e9273987 3918 BGP_STR
1ca2fd11 3919 "Log neighbor up/down and reset reason\n")
848973c7 3920{
1ca2fd11
IR
3921 VTY_DECLVAR_CONTEXT(bgp, bgp);
3922 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3923 return CMD_SUCCESS;
848973c7 3924}
6b0655a2 3925
718e3744 3926/* "bgp bestpath med" configuration. */
1ca2fd11 3927DEFUN (bgp_bestpath_med,
718e3744 3928 bgp_bestpath_med_cmd,
2d8c1a4d 3929 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
e9273987 3930 BGP_STR
718e3744 3931 "Change the default bestpath selection\n"
3932 "MED attribute\n"
3933 "Compare MED among confederation paths\n"
838758ac
DW
3934 "Treat missing MED as the least preferred one\n"
3935 "Treat missing MED as the least preferred one\n"
3936 "Compare MED among confederation paths\n")
718e3744 3937{
1ca2fd11 3938 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3939
1ca2fd11 3940 int idx = 0;
d62a17ae 3941 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3942 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3943 idx = 0;
3944 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11 3945 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 3946
1ca2fd11 3947 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3948
1ca2fd11 3949 return CMD_SUCCESS;
718e3744 3950}
3951
1ca2fd11 3952DEFUN (no_bgp_bestpath_med,
718e3744 3953 no_bgp_bestpath_med_cmd,
2d8c1a4d 3954 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3955 NO_STR
e9273987 3956 BGP_STR
718e3744 3957 "Change the default bestpath selection\n"
3958 "MED attribute\n"
3959 "Compare MED among confederation paths\n"
3a2d747c
QY
3960 "Treat missing MED as the least preferred one\n"
3961 "Treat missing MED as the least preferred one\n"
3962 "Compare MED among confederation paths\n")
718e3744 3963{
1ca2fd11 3964 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3965
1ca2fd11 3966 int idx = 0;
d62a17ae 3967 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3968 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3969 idx = 0;
3970 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11
IR
3971 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3972
3973 bgp_recalculate_all_bestpaths(bgp);
718e3744 3974
1ca2fd11 3975 return CMD_SUCCESS;
718e3744 3976}
3977
f7e1c681 3978/* "bgp bestpath bandwidth" configuration. */
3979DEFPY (bgp_bestpath_bw,
3980 bgp_bestpath_bw_cmd,
ad36d216 3981 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
e9273987 3982 BGP_STR
f7e1c681 3983 "Change the default bestpath selection\n"
3984 "Link Bandwidth attribute\n"
3985 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3986 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3987 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3988{
3989 VTY_DECLVAR_CONTEXT(bgp, bgp);
3990 afi_t afi;
3991 safi_t safi;
3992
ad36d216
DS
3993 if (!bw_cfg) {
3994 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3995 return CMD_ERR_INCOMPLETE;
f7e1c681 3996 }
ad36d216
DS
3997 if (!strcmp(bw_cfg, "ignore"))
3998 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3999 else if (!strcmp(bw_cfg, "skip-missing"))
4000 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
4001 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
4002 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
4003 else
4004 return CMD_ERR_NO_MATCH;
f7e1c681 4005
4006 /* This config is used in route install, so redo that. */
4007 FOREACH_AFI_SAFI (afi, safi) {
4008 if (!bgp_fibupd_safi(safi))
4009 continue;
4010 bgp_zebra_announce_table(bgp, afi, safi);
4011 }
4012
4013 return CMD_SUCCESS;
4014}
4015
ad36d216
DS
4016DEFPY (no_bgp_bestpath_bw,
4017 no_bgp_bestpath_bw_cmd,
4018 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
4019 NO_STR
e9273987 4020 BGP_STR
ad36d216
DS
4021 "Change the default bestpath selection\n"
4022 "Link Bandwidth attribute\n"
4023 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
4024 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
4025 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
4026{
4027 VTY_DECLVAR_CONTEXT(bgp, bgp);
4028 afi_t afi;
4029 safi_t safi;
4030
4031 bgp->lb_handling = BGP_LINK_BW_ECMP;
4032
4033 /* This config is used in route install, so redo that. */
4034 FOREACH_AFI_SAFI (afi, safi) {
4035 if (!bgp_fibupd_safi(safi))
4036 continue;
4037 bgp_zebra_announce_table(bgp, afi, safi);
4038 }
4039 return CMD_SUCCESS;
4040}
4041
b16bcbba 4042DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
38d11af5
TA
4043 "[no] bgp default <ipv4-unicast|"
4044 "ipv4-multicast|"
4045 "ipv4-vpn|"
4046 "ipv4-labeled-unicast|"
4047 "ipv4-flowspec|"
4048 "ipv6-unicast|"
4049 "ipv6-multicast|"
4050 "ipv6-vpn|"
4051 "ipv6-labeled-unicast|"
4052 "ipv6-flowspec|"
4053 "l2vpn-evpn>$afi_safi",
b16bcbba 4054 NO_STR
e9273987 4055 BGP_STR
e84c59af 4056 "Configure BGP defaults\n"
b16bcbba 4057 "Activate ipv4-unicast for a peer by default\n"
38d11af5
TA
4058 "Activate ipv4-multicast for a peer by default\n"
4059 "Activate ipv4-vpn for a peer by default\n"
4060 "Activate ipv4-labeled-unicast for a peer by default\n"
4061 "Activate ipv4-flowspec for a peer by default\n"
4062 "Activate ipv6-unicast for a peer by default\n"
4063 "Activate ipv6-multicast for a peer by default\n"
4064 "Activate ipv6-vpn for a peer by default\n"
4065 "Activate ipv6-labeled-unicast for a peer by default\n"
4066 "Activate ipv6-flowspec for a peer by default\n"
4067 "Activate l2vpn-evpn for a peer by default\n")
e84c59af
DA
4068{
4069 VTY_DECLVAR_CONTEXT(bgp, bgp);
b16bcbba
TA
4070 char afi_safi_str[strlen(afi_safi) + 1];
4071 char *afi_safi_str_tok;
e84c59af 4072
b16bcbba
TA
4073 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
4074 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
4075 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
4076 afi_t afi = bgp_vty_afi_from_str(afi_str);
38d11af5 4077 safi_t safi;
e84c59af 4078
d880a643
DS
4079 /*
4080 * Impossible situation but making coverity happy
4081 */
4082 assert(afi != AFI_MAX);
4083
38d11af5
TA
4084 if (strmatch(safi_str, "labeled"))
4085 safi = bgp_vty_safi_from_str("labeled-unicast");
4086 else
4087 safi = bgp_vty_safi_from_str(safi_str);
b16bcbba 4088
f609bcd6 4089 assert(safi != SAFI_MAX);
b16bcbba
TA
4090 if (no)
4091 bgp->default_af[afi][safi] = false;
38d11af5
TA
4092 else {
4093 if ((safi == SAFI_LABELED_UNICAST
4094 && bgp->default_af[afi][SAFI_UNICAST])
4095 || (safi == SAFI_UNICAST
4096 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
4097 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
4098 else
4099 bgp->default_af[afi][safi] = true;
4100 }
718e3744 4101
d62a17ae 4102 return CMD_SUCCESS;
718e3744 4103}
6b0655a2 4104
04b6bdc0 4105/* Display hostname in certain command outputs */
1ca2fd11 4106DEFUN (bgp_default_show_hostname,
04b6bdc0
DW
4107 bgp_default_show_hostname_cmd,
4108 "bgp default show-hostname",
e9273987 4109 BGP_STR
04b6bdc0 4110 "Configure BGP defaults\n"
0437e105 4111 "Show hostname in certain command outputs\n")
04b6bdc0 4112{
1ca2fd11
IR
4113 VTY_DECLVAR_CONTEXT(bgp, bgp);
4114 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4115 return CMD_SUCCESS;
ff8a8a7a
CS
4116}
4117
1ca2fd11
IR
4118DEFUN (no_bgp_default_show_hostname,
4119 no_bgp_default_show_hostname_cmd,
4120 "no bgp default show-hostname",
4121 NO_STR
e9273987 4122 BGP_STR
1ca2fd11
IR
4123 "Configure BGP defaults\n"
4124 "Show hostname in certain command outputs\n")
ff8a8a7a 4125{
1ca2fd11
IR
4126 VTY_DECLVAR_CONTEXT(bgp, bgp);
4127 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4128 return CMD_SUCCESS;
04b6bdc0
DW
4129}
4130
aef999a2 4131/* Display hostname in certain command outputs */
1d80f243
IR
4132DEFUN (bgp_default_show_nexthop_hostname,
4133 bgp_default_show_nexthop_hostname_cmd,
4134 "bgp default show-nexthop-hostname",
e9273987 4135 BGP_STR
1d80f243
IR
4136 "Configure BGP defaults\n"
4137 "Show hostname for nexthop in certain command outputs\n")
aef999a2 4138{
1ca2fd11
IR
4139 VTY_DECLVAR_CONTEXT(bgp, bgp);
4140 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4141 return CMD_SUCCESS;
aef999a2
DA
4142}
4143
4144DEFUN (no_bgp_default_show_nexthop_hostname,
4145 no_bgp_default_show_nexthop_hostname_cmd,
4146 "no bgp default show-nexthop-hostname",
4147 NO_STR
e9273987 4148 BGP_STR
aef999a2
DA
4149 "Configure BGP defaults\n"
4150 "Show hostname for nexthop in certain command outputs\n")
4151{
1ca2fd11
IR
4152 VTY_DECLVAR_CONTEXT(bgp, bgp);
4153 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4154 return CMD_SUCCESS;
aef999a2
DA
4155}
4156
8233ef81 4157/* "bgp network import-check" configuration. */
1ca2fd11
IR
4158DEFUN (bgp_network_import_check,
4159 bgp_network_import_check_cmd,
4160 "bgp network import-check",
e9273987 4161 BGP_STR
1ca2fd11
IR
4162 "BGP network command\n"
4163 "Check BGP network route exists in IGP\n")
718e3744 4164{
1ca2fd11
IR
4165 VTY_DECLVAR_CONTEXT(bgp, bgp);
4166 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4167 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4168 bgp_static_redo_import_check(bgp);
4169 }
078430f6 4170
1ca2fd11 4171 return CMD_SUCCESS;
718e3744 4172}
4173
d62a17ae 4174ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4175 "bgp network import-check exact",
e9273987 4176 BGP_STR
d62a17ae 4177 "BGP network command\n"
4178 "Check BGP network route exists in IGP\n"
4179 "Match route precisely\n")
8233ef81 4180
1ca2fd11
IR
4181DEFUN (no_bgp_network_import_check,
4182 no_bgp_network_import_check_cmd,
4183 "no bgp network import-check",
4184 NO_STR
e9273987 4185 BGP_STR
1ca2fd11
IR
4186 "BGP network command\n"
4187 "Check BGP network route exists in IGP\n")
718e3744 4188{
1ca2fd11
IR
4189 VTY_DECLVAR_CONTEXT(bgp, bgp);
4190 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4191 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4192 bgp_static_redo_import_check(bgp);
4193 }
6b0655a2 4194
1ca2fd11 4195 return CMD_SUCCESS;
ff8a8a7a 4196}
718e3744 4197
1ca2fd11
IR
4198DEFUN (bgp_default_local_preference,
4199 bgp_default_local_preference_cmd,
4200 "bgp default local-preference (0-4294967295)",
e9273987 4201 BGP_STR
1ca2fd11
IR
4202 "Configure BGP defaults\n"
4203 "local preference (higher=more preferred)\n"
4204 "Configure default local preference value\n")
ff8a8a7a 4205{
1ca2fd11 4206 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 4207 int idx_number = 3;
1ca2fd11 4208 uint32_t local_pref;
718e3744 4209
1ca2fd11 4210 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 4211
1ca2fd11
IR
4212 bgp_default_local_preference_set(bgp, local_pref);
4213 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 4214
1ca2fd11 4215 return CMD_SUCCESS;
718e3744 4216}
4217
1ca2fd11
IR
4218DEFUN (no_bgp_default_local_preference,
4219 no_bgp_default_local_preference_cmd,
4220 "no bgp default local-preference [(0-4294967295)]",
4221 NO_STR
e9273987 4222 BGP_STR
1ca2fd11
IR
4223 "Configure BGP defaults\n"
4224 "local preference (higher=more preferred)\n"
4225 "Configure default local preference value\n")
ff8a8a7a 4226{
1ca2fd11
IR
4227 VTY_DECLVAR_CONTEXT(bgp, bgp);
4228 bgp_default_local_preference_unset(bgp);
4229 bgp_clear_star_soft_in(vty, bgp->name);
4230
4231 return CMD_SUCCESS;
ff8a8a7a 4232}
6b0655a2 4233
ff8a8a7a 4234
1ca2fd11
IR
4235DEFUN (bgp_default_subgroup_pkt_queue_max,
4236 bgp_default_subgroup_pkt_queue_max_cmd,
4237 "bgp default subgroup-pkt-queue-max (20-100)",
e9273987 4238 BGP_STR
1ca2fd11
IR
4239 "Configure BGP defaults\n"
4240 "subgroup-pkt-queue-max\n"
4241 "Configure subgroup packet queue max\n")
8bd9d948 4242{
1ca2fd11 4243 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4244 int idx_number = 3;
1ca2fd11 4245 uint32_t max_size;
3f9c7369 4246
1ca2fd11 4247 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 4248
1ca2fd11 4249 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
ff8a8a7a 4250
1ca2fd11 4251 return CMD_SUCCESS;
8bd9d948
DS
4252}
4253
1ca2fd11
IR
4254DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4255 no_bgp_default_subgroup_pkt_queue_max_cmd,
4256 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4257 NO_STR
e9273987 4258 BGP_STR
1ca2fd11
IR
4259 "Configure BGP defaults\n"
4260 "subgroup-pkt-queue-max\n"
4261 "Configure subgroup packet queue max\n")
ff8a8a7a 4262{
1ca2fd11
IR
4263 VTY_DECLVAR_CONTEXT(bgp, bgp);
4264 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4265 return CMD_SUCCESS;
ff8a8a7a 4266}
813d4307 4267
8bd9d948 4268
1ca2fd11
IR
4269DEFUN (bgp_rr_allow_outbound_policy,
4270 bgp_rr_allow_outbound_policy_cmd,
4271 "bgp route-reflector allow-outbound-policy",
e9273987 4272 BGP_STR
1ca2fd11
IR
4273 "Allow modifications made by out route-map\n"
4274 "on ibgp neighbors\n")
ff8a8a7a 4275{
1ca2fd11 4276 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 4277
1ca2fd11
IR
4278 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4279 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4280 update_group_announce_rrclients(bgp);
4281 bgp_clear_star_soft_out(vty, bgp->name);
4282 }
8bd9d948 4283
1ca2fd11
IR
4284 return CMD_SUCCESS;
4285}
ff8a8a7a 4286
1ca2fd11
IR
4287DEFUN (no_bgp_rr_allow_outbound_policy,
4288 no_bgp_rr_allow_outbound_policy_cmd,
4289 "no bgp route-reflector allow-outbound-policy",
4290 NO_STR
e9273987 4291 BGP_STR
1ca2fd11
IR
4292 "Allow modifications made by out route-map\n"
4293 "on ibgp neighbors\n")
8bd9d948 4294{
1ca2fd11 4295 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 4296
1ca2fd11
IR
4297 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4298 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4299 update_group_announce_rrclients(bgp);
4300 bgp_clear_star_soft_out(vty, bgp->name);
d62a17ae 4301 }
8bd9d948 4302
1ca2fd11 4303 return CMD_SUCCESS;
8bd9d948
DS
4304}
4305
1ca2fd11
IR
4306DEFUN (bgp_listen_limit,
4307 bgp_listen_limit_cmd,
4308 "bgp listen limit (1-65535)",
e9273987 4309 BGP_STR
1ca2fd11
IR
4310 "BGP Dynamic Neighbors listen commands\n"
4311 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4312 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4313{
1ca2fd11 4314 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4315 int idx_number = 3;
1ca2fd11
IR
4316 int listen_limit;
4317
4318 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 4319
1ca2fd11 4320 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 4321
1ca2fd11 4322 return CMD_SUCCESS;
f14e6fdb
DS
4323}
4324
1ca2fd11
IR
4325DEFUN (no_bgp_listen_limit,
4326 no_bgp_listen_limit_cmd,
4327 "no bgp listen limit [(1-65535)]",
4328 NO_STR
e9273987 4329 BGP_STR
1ca2fd11
IR
4330 "BGP Dynamic Neighbors listen commands\n"
4331 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4332 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4333{
1ca2fd11
IR
4334 VTY_DECLVAR_CONTEXT(bgp, bgp);
4335 bgp_listen_limit_unset(bgp);
4336 return CMD_SUCCESS;
f14e6fdb
DS
4337}
4338
4339
20eb8864 4340/*
4341 * Check if this listen range is already configured. Check for exact
4342 * match or overlap based on input.
4343 */
d62a17ae 4344static struct peer_group *listen_range_exists(struct bgp *bgp,
4345 struct prefix *range, int exact)
4346{
4347 struct listnode *node, *nnode;
4348 struct listnode *node1, *nnode1;
4349 struct peer_group *group;
4350 struct prefix *lr;
4351 afi_t afi;
4352 int match;
4353
4354 afi = family2afi(range->family);
4355 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4356 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4357 lr)) {
4358 if (exact)
4359 match = prefix_same(range, lr);
4360 else
4361 match = (prefix_match(range, lr)
4362 || prefix_match(lr, range));
4363 if (match)
4364 return group;
4365 }
4366 }
4367
4368 return NULL;
20eb8864 4369}
4370
f14e6fdb
DS
4371DEFUN (bgp_listen_range,
4372 bgp_listen_range_cmd,
d7b9898c 4373 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
e9273987 4374 BGP_STR
d7fa34c1
QY
4375 "Configure BGP dynamic neighbors listen range\n"
4376 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
4377 NEIGHBOR_ADDR_STR
4378 "Member of the peer-group\n"
4379 "Peer-group name\n")
f14e6fdb 4380{
d62a17ae 4381 VTY_DECLVAR_CONTEXT(bgp, bgp);
4382 struct prefix range;
4383 struct peer_group *group, *existing_group;
4384 afi_t afi;
4385 int ret;
4386 int idx = 0;
4387
4388 argv_find(argv, argc, "A.B.C.D/M", &idx);
4389 argv_find(argv, argc, "X:X::X:X/M", &idx);
4390 char *prefix = argv[idx]->arg;
d7b9898c 4391 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4392 char *peergroup = argv[idx]->arg;
4393
4394 /* Convert IP prefix string to struct prefix. */
4395 ret = str2prefix(prefix, &range);
4396 if (!ret) {
4397 vty_out(vty, "%% Malformed listen range\n");
4398 return CMD_WARNING_CONFIG_FAILED;
4399 }
4400
4401 afi = family2afi(range.family);
4402
4403 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4404 vty_out(vty,
4405 "%% Malformed listen range (link-local address)\n");
4406 return CMD_WARNING_CONFIG_FAILED;
4407 }
4408
4409 apply_mask(&range);
4410
4411 /* Check if same listen range is already configured. */
4412 existing_group = listen_range_exists(bgp, &range, 1);
4413 if (existing_group) {
4414 if (strcmp(existing_group->name, peergroup) == 0)
4415 return CMD_SUCCESS;
4416 else {
4417 vty_out(vty,
4418 "%% Same listen range is attached to peer-group %s\n",
4419 existing_group->name);
4420 return CMD_WARNING_CONFIG_FAILED;
4421 }
4422 }
4423
4424 /* Check if an overlapping listen range exists. */
4425 if (listen_range_exists(bgp, &range, 0)) {
4426 vty_out(vty,
4427 "%% Listen range overlaps with existing listen range\n");
4428 return CMD_WARNING_CONFIG_FAILED;
4429 }
4430
4431 group = peer_group_lookup(bgp, peergroup);
4432 if (!group) {
4433 vty_out(vty, "%% Configure the peer-group first\n");
4434 return CMD_WARNING_CONFIG_FAILED;
4435 }
4436
4437 ret = peer_group_listen_range_add(group, &range);
4438 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4439}
4440
4441DEFUN (no_bgp_listen_range,
4442 no_bgp_listen_range_cmd,
d7b9898c 4443 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4444 NO_STR
e9273987 4445 BGP_STR
d7fa34c1
QY
4446 "Unconfigure BGP dynamic neighbors listen range\n"
4447 "Unconfigure BGP dynamic neighbors listen range\n"
4448 NEIGHBOR_ADDR_STR
4449 "Member of the peer-group\n"
4450 "Peer-group name\n")
f14e6fdb 4451{
d62a17ae 4452 VTY_DECLVAR_CONTEXT(bgp, bgp);
4453 struct prefix range;
4454 struct peer_group *group;
4455 afi_t afi;
4456 int ret;
4457 int idx = 0;
4458
4459 argv_find(argv, argc, "A.B.C.D/M", &idx);
4460 argv_find(argv, argc, "X:X::X:X/M", &idx);
4461 char *prefix = argv[idx]->arg;
21d88a71 4462 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4463 char *peergroup = argv[idx]->arg;
4464
4465 /* Convert IP prefix string to struct prefix. */
4466 ret = str2prefix(prefix, &range);
4467 if (!ret) {
4468 vty_out(vty, "%% Malformed listen range\n");
4469 return CMD_WARNING_CONFIG_FAILED;
4470 }
4471
4472 afi = family2afi(range.family);
4473
4474 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4475 vty_out(vty,
4476 "%% Malformed listen range (link-local address)\n");
4477 return CMD_WARNING_CONFIG_FAILED;
4478 }
4479
4480 apply_mask(&range);
4481
4482 group = peer_group_lookup(bgp, peergroup);
4483 if (!group) {
4484 vty_out(vty, "%% Peer-group does not exist\n");
4485 return CMD_WARNING_CONFIG_FAILED;
4486 }
4487
4488 ret = peer_group_listen_range_del(group, &range);
4489 return bgp_vty_return(vty, ret);
4490}
4491
2b791107 4492void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4493{
4494 struct peer_group *group;
4495 struct listnode *node, *nnode, *rnode, *nrnode;
4496 struct prefix *range;
4497 afi_t afi;
d62a17ae 4498
4499 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4500 vty_out(vty, " bgp listen limit %d\n",
4501 bgp->dynamic_neighbors_limit);
4502
4503 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4504 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4505 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4506 nrnode, range)) {
d62a17ae 4507 vty_out(vty,
2dbe669b
DA
4508 " bgp listen range %pFX peer-group %s\n",
4509 range, group->name);
d62a17ae 4510 }
4511 }
4512 }
f14e6fdb
DS
4513}
4514
4515
1ca2fd11
IR
4516DEFUN (bgp_disable_connected_route_check,
4517 bgp_disable_connected_route_check_cmd,
4518 "bgp disable-ebgp-connected-route-check",
e9273987 4519 BGP_STR
1ca2fd11 4520 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4521{
1ca2fd11
IR
4522 VTY_DECLVAR_CONTEXT(bgp, bgp);
4523 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4524 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 4525
1ca2fd11 4526 return CMD_SUCCESS;
907f92c8
DS
4527}
4528
1ca2fd11
IR
4529DEFUN (no_bgp_disable_connected_route_check,
4530 no_bgp_disable_connected_route_check_cmd,
4531 "no bgp disable-ebgp-connected-route-check",
4532 NO_STR
e9273987 4533 BGP_STR
1ca2fd11 4534 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4535{
1ca2fd11
IR
4536 VTY_DECLVAR_CONTEXT(bgp, bgp);
4537 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4538 bgp_clear_star_soft_in(vty, bgp->name);
d62a17ae 4539
1ca2fd11 4540 return CMD_SUCCESS;
d62a17ae 4541}
4542
4543
28c6e247
IR
4544static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4545 const char *as_str)
4546{
4547 VTY_DECLVAR_CONTEXT(bgp, bgp);
4548 int ret;
4549 as_t as;
4550 int as_type = AS_SPECIFIED;
4551 union sockunion su;
4552
4553 if (as_str[0] == 'i') {
4554 as = 0;
4555 as_type = AS_INTERNAL;
4556 } else if (as_str[0] == 'e') {
4557 as = 0;
4558 as_type = AS_EXTERNAL;
8079a413
PG
4559 } else if (!asn_str2asn(as_str, &as))
4560 as_type = AS_UNSPECIFIED;
28c6e247 4561
8079a413
PG
4562 if (as_type == AS_UNSPECIFIED) {
4563 vty_out(vty, "%% Invalid peer AS: %s\n", as_str);
4564 return CMD_WARNING_CONFIG_FAILED;
4565 }
28c6e247
IR
4566 /* If peer is peer group or interface peer, call proper function. */
4567 ret = str2sockunion(peer_str, &su);
4568 if (ret < 0) {
4569 struct peer *peer;
4570
4571 /* Check if existing interface peer */
4572 peer = peer_lookup_by_conf_if(bgp, peer_str);
4573
de76ed8a 4574 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, as_str);
28c6e247
IR
4575
4576 /* if not interface peer, check peer-group settings */
4577 if (ret < 0 && !peer) {
de76ed8a
PG
4578 ret = peer_group_remote_as(bgp, peer_str, &as, as_type,
4579 as_str);
28c6e247
IR
4580 if (ret < 0) {
4581 vty_out(vty,
4582 "%% Create the peer-group or interface first\n");
4583 return CMD_WARNING_CONFIG_FAILED;
4584 }
4585 return CMD_SUCCESS;
4586 }
4587 } else {
4588 if (peer_address_self_check(bgp, &su)) {
4589 vty_out(vty,
4590 "%% Can not configure the local system as neighbor\n");
4591 return CMD_WARNING_CONFIG_FAILED;
4592 }
de76ed8a 4593 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, as_str);
28c6e247
IR
4594 }
4595
28c6e247
IR
4596 return bgp_vty_return(vty, ret);
4597}
4598
1ca2fd11
IR
4599DEFUN (bgp_default_shutdown,
4600 bgp_default_shutdown_cmd,
4601 "[no] bgp default shutdown",
4602 NO_STR
4603 BGP_STR
4604 "Configure BGP defaults\n"
4605 "Apply administrative shutdown to newly configured peers\n")
ff8a8a7a 4606{
1ca2fd11
IR
4607 VTY_DECLVAR_CONTEXT(bgp, bgp);
4608 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4609 return CMD_SUCCESS;
f26845f9
QY
4610}
4611
736b68f3
DS
4612DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4613 BGP_STR
9ddf4b81 4614 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4615 "Add a shutdown message (RFC 8203)\n"
4616 "Shutdown message\n")
9cf59432 4617{
736b68f3 4618 char *msgstr = NULL;
8389c83a 4619
9cf59432
DS
4620 VTY_DECLVAR_CONTEXT(bgp, bgp);
4621
8389c83a 4622 if (argc > 3)
f80e35b6 4623 msgstr = argv_concat(argv, argc, 3);
8389c83a 4624
b776f48c
DA
4625 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4626 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4627 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4628 return CMD_WARNING_CONFIG_FAILED;
4629 }
4630
8389c83a
DS
4631 bgp_shutdown_enable(bgp, msgstr);
4632 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4633
4634 return CMD_SUCCESS;
4635}
4636
736b68f3 4637DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4638 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4639{
4640 VTY_DECLVAR_CONTEXT(bgp, bgp);
4641
4642 bgp_shutdown_enable(bgp, NULL);
4643
4644 return CMD_SUCCESS;
4645}
8389c83a 4646
736b68f3 4647DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4648 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4649{
4650 VTY_DECLVAR_CONTEXT(bgp, bgp);
4651
4652 bgp_shutdown_disable(bgp);
4653
4654 return CMD_SUCCESS;
4655}
4656
9ddf4b81 4657ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4658 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4659 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4660 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4661
28c6e247
IR
4662DEFUN (neighbor_remote_as,
4663 neighbor_remote_as_cmd,
8079a413 4664 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <ASNUM|internal|external>",
28c6e247
IR
4665 NEIGHBOR_STR
4666 NEIGHBOR_ADDR_STR2
4667 "Specify a BGP neighbor\n"
4668 AS_STR
4669 "Internal BGP peer\n"
4670 "External BGP peer\n")
718e3744 4671{
d62a17ae 4672 int idx_peer = 1;
4673 int idx_remote_as = 3;
28c6e247
IR
4674 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4675 argv[idx_remote_as]->arg);
d62a17ae 4676}
8666265e
DS
4677
4678DEFPY (bgp_allow_martian,
4679 bgp_allow_martian_cmd,
4680 "[no]$no bgp allow-martian-nexthop",
4681 NO_STR
4682 BGP_STR
4683 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4684{
4685 VTY_DECLVAR_CONTEXT(bgp, bgp);
4686
4687 if (no)
4688 bgp->allow_martian = false;
4689 else
4690 bgp->allow_martian = true;
4691
4692 return CMD_SUCCESS;
4693}
4694
f852eb98
PG
4695/* Enable fast convergence of bgp sessions. If this is enabled, bgp
4696 * sessions do not wait for hold timer expiry to bring down the sessions
4697 * when nexthop becomes unreachable
4698 */
4699DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4700 BGP_STR "Fast convergence for bgp sessions\n")
4701{
4702 VTY_DECLVAR_CONTEXT(bgp, bgp);
4703 bgp->fast_convergence = true;
4704
4705 return CMD_SUCCESS;
4706}
4707
4708DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4709 "no bgp fast-convergence",
4710 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4711{
4712 VTY_DECLVAR_CONTEXT(bgp, bgp);
4713 bgp->fast_convergence = false;
4714
4715 return CMD_SUCCESS;
4716}
d62a17ae 4717
28c6e247
IR
4718static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4719 int v6only,
4720 const char *peer_group_name,
4721 const char *as_str)
d62a17ae 4722{
28c6e247
IR
4723 VTY_DECLVAR_CONTEXT(bgp, bgp);
4724 as_t as = 0;
4725 int as_type = AS_UNSPECIFIED;
d62a17ae 4726 struct peer *peer;
4727 struct peer_group *group;
4728 int ret = 0;
d62a17ae 4729
4730 group = peer_group_lookup(bgp, conf_if);
4731
4732 if (group) {
28c6e247
IR
4733 vty_out(vty, "%% Name conflict with peer-group \n");
4734 return CMD_WARNING_CONFIG_FAILED;
4735 }
4736
4737 if (as_str) {
4738 if (as_str[0] == 'i') {
4739 as_type = AS_INTERNAL;
4740 } else if (as_str[0] == 'e') {
4741 as_type = AS_EXTERNAL;
4742 } else {
4743 /* Get AS number. */
8079a413
PG
4744 if (asn_str2asn(as_str, &as))
4745 as_type = AS_SPECIFIED;
28c6e247 4746 }
d62a17ae 4747 }
4748
4749 peer = peer_lookup_by_conf_if(bgp, conf_if);
4750 if (peer) {
28c6e247 4751 if (as_str)
de76ed8a
PG
4752 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
4753 as_str);
d62a17ae 4754 } else {
e84c59af 4755 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
de76ed8a 4756 NULL, true, as_str);
d62a17ae 4757
4758 if (!peer) {
28c6e247
IR
4759 vty_out(vty, "%% BGP failed to create peer\n");
4760 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4761 }
4762
4763 if (v6only)
527de3dc 4764 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4765
4766 /* Request zebra to initiate IPv6 RAs on this interface. We do
4767 * this
4768 * any unnumbered peer in order to not worry about run-time
4769 * transitions
4770 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4771 * address
4772 * gets deleted later etc.)
4773 */
4774 if (peer->ifp)
4775 bgp_zebra_initiate_radv(bgp, peer);
4776 }
4777
4778 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4779 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4780 if (v6only)
527de3dc 4781 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4782 else
527de3dc 4783 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4784
4785 /* v6only flag changed. Reset bgp seesion */
4786 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4787 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4788 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4789 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4790 } else
4791 bgp_session_reset(peer);
4792 }
4793
9fb964de
PM
4794 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4795 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4796 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4797 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4798 }
d62a17ae 4799
4800 if (peer_group_name) {
4801 group = peer_group_lookup(bgp, peer_group_name);
4802 if (!group) {
28c6e247
IR
4803 vty_out(vty, "%% Configure the peer-group first\n");
4804 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4805 }
4806
8395c1f8 4807 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4808 }
4809
28c6e247 4810 return bgp_vty_return(vty, ret);
a80beece
DS
4811}
4812
28c6e247
IR
4813DEFUN (neighbor_interface_config,
4814 neighbor_interface_config_cmd,
4815 "neighbor WORD interface [peer-group PGNAME]",
4816 NEIGHBOR_STR
4817 "Interface name or neighbor tag\n"
4818 "Enable BGP on interface\n"
4819 "Member of the peer-group\n"
4820 "Peer-group name\n")
4c48cf63 4821{
d62a17ae 4822 int idx_word = 1;
4823 int idx_peer_group_word = 4;
f4b8ec07 4824
d62a17ae 4825 if (argc > idx_peer_group_word)
28c6e247
IR
4826 return peer_conf_interface_get(
4827 vty, argv[idx_word]->arg, 0,
4828 argv[idx_peer_group_word]->arg, NULL);
4829 else
4830 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4831 NULL, NULL);
4c48cf63
DW
4832}
4833
28c6e247
IR
4834DEFUN (neighbor_interface_config_v6only,
4835 neighbor_interface_config_v6only_cmd,
4836 "neighbor WORD interface v6only [peer-group PGNAME]",
4837 NEIGHBOR_STR
4838 "Interface name or neighbor tag\n"
4839 "Enable BGP on interface\n"
4840 "Enable BGP with v6 link-local only\n"
4841 "Member of the peer-group\n"
4842 "Peer-group name\n")
4c48cf63 4843{
d62a17ae 4844 int idx_word = 1;
4845 int idx_peer_group_word = 5;
31500417 4846
d62a17ae 4847 if (argc > idx_peer_group_word)
28c6e247
IR
4848 return peer_conf_interface_get(
4849 vty, argv[idx_word]->arg, 1,
4850 argv[idx_peer_group_word]->arg, NULL);
31500417 4851
28c6e247 4852 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4c48cf63
DW
4853}
4854
a80beece 4855
28c6e247
IR
4856DEFUN (neighbor_interface_config_remote_as,
4857 neighbor_interface_config_remote_as_cmd,
8079a413 4858 "neighbor WORD interface remote-as <ASNUM|internal|external>",
28c6e247
IR
4859 NEIGHBOR_STR
4860 "Interface name or neighbor tag\n"
4861 "Enable BGP on interface\n"
4862 "Specify a BGP neighbor\n"
4863 AS_STR
4864 "Internal BGP peer\n"
4865 "External BGP peer\n")
b3a39dc5 4866{
d62a17ae 4867 int idx_word = 1;
4868 int idx_remote_as = 4;
28c6e247
IR
4869 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4870 argv[idx_remote_as]->arg);
b3a39dc5
DD
4871}
4872
28c6e247
IR
4873DEFUN (neighbor_interface_v6only_config_remote_as,
4874 neighbor_interface_v6only_config_remote_as_cmd,
8079a413 4875 "neighbor WORD interface v6only remote-as <ASNUM|internal|external>",
28c6e247
IR
4876 NEIGHBOR_STR
4877 "Interface name or neighbor tag\n"
4878 "Enable BGP with v6 link-local only\n"
4879 "Enable BGP on interface\n"
4880 "Specify a BGP neighbor\n"
4881 AS_STR
4882 "Internal BGP peer\n"
4883 "External BGP peer\n")
b3a39dc5 4884{
d62a17ae 4885 int idx_word = 1;
4886 int idx_remote_as = 5;
28c6e247
IR
4887 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4888 argv[idx_remote_as]->arg);
b3a39dc5
DD
4889}
4890
28c6e247
IR
4891DEFUN (neighbor_peer_group,
4892 neighbor_peer_group_cmd,
4893 "neighbor WORD peer-group",
4894 NEIGHBOR_STR
4895 "Interface name or neighbor tag\n"
4896 "Configure peer-group\n")
718e3744 4897{
28c6e247 4898 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4899 int idx_word = 1;
28c6e247
IR
4900 struct peer *peer;
4901 struct peer_group *group;
718e3744 4902
28c6e247
IR
4903 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4904 if (peer) {
4905 vty_out(vty, "%% Name conflict with interface: \n");
4906 return CMD_WARNING_CONFIG_FAILED;
4907 }
718e3744 4908
28c6e247
IR
4909 group = peer_group_get(bgp, argv[idx_word]->arg);
4910 if (!group) {
4911 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4912 return CMD_WARNING_CONFIG_FAILED;
4913 }
718e3744 4914
28c6e247 4915 return CMD_SUCCESS;
718e3744 4916}
4917
1d80f243
IR
4918DEFUN (no_neighbor,
4919 no_neighbor_cmd,
4920 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4921 NO_STR
4922 NEIGHBOR_STR
4923 NEIGHBOR_ADDR_STR2
4924 "Specify a BGP neighbor\n"
4925 AS_STR
4926 "Internal BGP peer\n"
4927 "External BGP peer\n")
718e3744 4928{
28c6e247 4929 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4930 int idx_peer = 2;
28c6e247 4931 int ret;
d62a17ae 4932 union sockunion su;
28c6e247
IR
4933 struct peer_group *group;
4934 struct peer *peer;
4935 struct peer *other;
d62a17ae 4936
28c6e247
IR
4937 ret = str2sockunion(argv[idx_peer]->arg, &su);
4938 if (ret < 0) {
4939 /* look up for neighbor by interface name config. */
4940 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4941 if (peer) {
4942 /* Request zebra to terminate IPv6 RAs on this
4943 * interface. */
4944 if (peer->ifp)
4945 bgp_zebra_terminate_radv(peer->bgp, peer);
4946 peer_notify_unconfig(peer);
4947 peer_delete(peer);
4948 return CMD_SUCCESS;
d62a17ae 4949 }
28c6e247
IR
4950
4951 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4952 if (group) {
4953 peer_group_notify_unconfig(group);
4954 peer_group_delete(group);
4e2786df 4955 } else {
28c6e247 4956 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4957 return CMD_WARNING_CONFIG_FAILED;
4958 }
28c6e247
IR
4959 } else {
4960 peer = peer_lookup(bgp, &su);
4961 if (peer) {
4962 if (peer_dynamic_neighbor(peer)) {
4963 vty_out(vty,
4964 "%% Operation not allowed on a dynamic neighbor\n");
4965 return CMD_WARNING_CONFIG_FAILED;
4966 }
d62a17ae 4967
28c6e247 4968 other = peer->doppelganger;
f4b8ec07 4969
28c6e247
IR
4970 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4971 bgp_zebra_terminate_radv(peer->bgp, peer);
f4b8ec07 4972
28c6e247
IR
4973 peer_notify_unconfig(peer);
4974 peer_delete(peer);
4975 if (other && other->status != Deleted) {
4976 peer_notify_unconfig(other);
4977 peer_delete(other);
4978 }
4979 }
4980 }
4981
4982 return CMD_SUCCESS;
a80beece
DS
4983}
4984
28c6e247
IR
4985DEFUN (no_neighbor_interface_config,
4986 no_neighbor_interface_config_cmd,
4987 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4988 NO_STR
4989 NEIGHBOR_STR
4990 "Interface name\n"
4991 "Configure BGP on interface\n"
4992 "Enable BGP with v6 link-local only\n"
4993 "Member of the peer-group\n"
4994 "Peer-group name\n"
4995 "Specify a BGP neighbor\n"
4996 AS_STR
4997 "Internal BGP peer\n"
4998 "External BGP peer\n")
718e3744 4999{
28c6e247 5000 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5001 int idx_word = 2;
28c6e247 5002 struct peer *peer;
718e3744 5003
28c6e247
IR
5004 /* look up for neighbor by interface name config. */
5005 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
5006 if (peer) {
5007 /* Request zebra to terminate IPv6 RAs on this interface. */
5008 if (peer->ifp)
5009 bgp_zebra_terminate_radv(peer->bgp, peer);
5010 peer_notify_unconfig(peer);
5011 peer_delete(peer);
5012 } else {
5013 vty_out(vty, "%% Create the bgp interface first\n");
5014 return CMD_WARNING_CONFIG_FAILED;
5015 }
5016 return CMD_SUCCESS;
718e3744 5017}
5018
28c6e247
IR
5019DEFUN (no_neighbor_peer_group,
5020 no_neighbor_peer_group_cmd,
5021 "no neighbor WORD peer-group",
5022 NO_STR
5023 NEIGHBOR_STR
5024 "Neighbor tag\n"
5025 "Configure peer-group\n")
718e3744 5026{
28c6e247
IR
5027 VTY_DECLVAR_CONTEXT(bgp, bgp);
5028 int idx_word = 2;
5029 struct peer_group *group;
f4b8ec07 5030
28c6e247
IR
5031 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5032 if (group) {
5033 peer_group_notify_unconfig(group);
5034 peer_group_delete(group);
f4b8ec07 5035 } else {
28c6e247 5036 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 5037 return CMD_WARNING_CONFIG_FAILED;
5038 }
28c6e247
IR
5039 return CMD_SUCCESS;
5040}
f4b8ec07 5041
28c6e247
IR
5042DEFUN (no_neighbor_interface_peer_group_remote_as,
5043 no_neighbor_interface_peer_group_remote_as_cmd,
8079a413 5044 "no neighbor WORD remote-as <ASNUM|internal|external>",
28c6e247
IR
5045 NO_STR
5046 NEIGHBOR_STR
5047 "Interface name or neighbor tag\n"
5048 "Specify a BGP neighbor\n"
5049 AS_STR
5050 "Internal BGP peer\n"
5051 "External BGP peer\n")
5052{
5053 VTY_DECLVAR_CONTEXT(bgp, bgp);
5054 int idx_word = 2;
5055 struct peer_group *group;
5056 struct peer *peer;
f4b8ec07 5057
28c6e247
IR
5058 /* look up for neighbor by interface name config. */
5059 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
5060 if (peer) {
de76ed8a 5061 peer_as_change(peer, 0, AS_UNSPECIFIED, NULL);
28c6e247
IR
5062 return CMD_SUCCESS;
5063 }
f4b8ec07 5064
28c6e247
IR
5065 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5066 if (group)
5067 peer_group_remote_as_delete(group);
5068 else {
5069 vty_out(vty, "%% Create the peer-group or interface first\n");
5070 return CMD_WARNING_CONFIG_FAILED;
5071 }
5072 return CMD_SUCCESS;
718e3744 5073}
6b0655a2 5074
28c6e247
IR
5075DEFUN (neighbor_local_as,
5076 neighbor_local_as_cmd,
8079a413 5077 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM",
28c6e247
IR
5078 NEIGHBOR_STR
5079 NEIGHBOR_ADDR_STR2
5080 "Specify a local-as number\n"
8079a413 5081 "AS number expressed in dotted or plain format used as local AS\n")
718e3744 5082{
d62a17ae 5083 int idx_peer = 1;
5084 int idx_number = 3;
28c6e247
IR
5085 struct peer *peer;
5086 int ret;
5087 as_t as;
718e3744 5088
28c6e247
IR
5089 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5090 if (!peer)
d62a17ae 5091 return CMD_WARNING_CONFIG_FAILED;
718e3744 5092
8079a413
PG
5093 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
5094 vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
5095 argv[idx_number]->arg);
5096 return CMD_WARNING_CONFIG_FAILED;
5097 }
5098
de76ed8a 5099 ret = peer_local_as_set(peer, as, 0, 0, argv[idx_number]->arg);
28c6e247 5100 return bgp_vty_return(vty, ret);
718e3744 5101}
5102
28c6e247
IR
5103DEFUN (neighbor_local_as_no_prepend,
5104 neighbor_local_as_no_prepend_cmd,
8079a413 5105 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM no-prepend",
28c6e247
IR
5106 NEIGHBOR_STR
5107 NEIGHBOR_ADDR_STR2
5108 "Specify a local-as number\n"
8079a413 5109 "AS number expressed in dotted or plain format used as local AS\n"
28c6e247 5110 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 5111{
d62a17ae 5112 int idx_peer = 1;
5113 int idx_number = 3;
28c6e247
IR
5114 struct peer *peer;
5115 int ret;
5116 as_t as;
718e3744 5117
28c6e247
IR
5118 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5119 if (!peer)
d62a17ae 5120 return CMD_WARNING_CONFIG_FAILED;
718e3744 5121
8079a413
PG
5122 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
5123 vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
5124 argv[idx_number]->arg);
5125 return CMD_WARNING_CONFIG_FAILED;
5126 }
5127
de76ed8a 5128 ret = peer_local_as_set(peer, as, 1, 0, argv[idx_number]->arg);
28c6e247 5129 return bgp_vty_return(vty, ret);
718e3744 5130}
5131
28c6e247
IR
5132DEFUN (neighbor_local_as_no_prepend_replace_as,
5133 neighbor_local_as_no_prepend_replace_as_cmd,
8079a413 5134 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM no-prepend replace-as",
28c6e247
IR
5135 NEIGHBOR_STR
5136 NEIGHBOR_ADDR_STR2
5137 "Specify a local-as number\n"
8079a413 5138 "AS number expressed in dotted or plain format used as local AS\n"
28c6e247
IR
5139 "Do not prepend local-as to updates from ebgp peers\n"
5140 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 5141{
d62a17ae 5142 int idx_peer = 1;
5143 int idx_number = 3;
28c6e247
IR
5144 struct peer *peer;
5145 int ret;
5146 as_t as;
9d3f9705 5147
28c6e247
IR
5148 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5149 if (!peer)
d62a17ae 5150 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 5151
8079a413
PG
5152 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
5153 vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
5154 argv[idx_number]->arg);
5155 return CMD_WARNING_CONFIG_FAILED;
5156 }
5157
de76ed8a 5158 ret = peer_local_as_set(peer, as, 1, 1, argv[idx_number]->arg);
28c6e247 5159 return bgp_vty_return(vty, ret);
9d3f9705
AC
5160}
5161
28c6e247
IR
5162DEFUN (no_neighbor_local_as,
5163 no_neighbor_local_as_cmd,
8079a413 5164 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [ASNUM [no-prepend [replace-as]]]",
28c6e247
IR
5165 NO_STR
5166 NEIGHBOR_STR
5167 NEIGHBOR_ADDR_STR2
5168 "Specify a local-as number\n"
8079a413 5169 "AS number expressed in dotted or plain format used as local AS\n"
28c6e247
IR
5170 "Do not prepend local-as to updates from ebgp peers\n"
5171 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 5172{
d62a17ae 5173 int idx_peer = 2;
28c6e247
IR
5174 struct peer *peer;
5175 int ret;
718e3744 5176
28c6e247
IR
5177 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5178 if (!peer)
d62a17ae 5179 return CMD_WARNING_CONFIG_FAILED;
718e3744 5180
28c6e247
IR
5181 ret = peer_local_as_unset(peer);
5182 return bgp_vty_return(vty, ret);
718e3744 5183}
5184
718e3744 5185
3f9c7369
DS
5186DEFUN (neighbor_solo,
5187 neighbor_solo_cmd,
9ccf14f7 5188 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
5189 NEIGHBOR_STR
5190 NEIGHBOR_ADDR_STR2
5191 "Solo peer - part of its own update group\n")
5192{
d62a17ae 5193 int idx_peer = 1;
5194 struct peer *peer;
5195 int ret;
3f9c7369 5196
d62a17ae 5197 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5198 if (!peer)
5199 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 5200
d62a17ae 5201 ret = update_group_adjust_soloness(peer, 1);
5202 return bgp_vty_return(vty, ret);
3f9c7369
DS
5203}
5204
5205DEFUN (no_neighbor_solo,
5206 no_neighbor_solo_cmd,
9ccf14f7 5207 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
5208 NO_STR
5209 NEIGHBOR_STR
5210 NEIGHBOR_ADDR_STR2
5211 "Solo peer - part of its own update group\n")
5212{
d62a17ae 5213 int idx_peer = 2;
5214 struct peer *peer;
5215 int ret;
3f9c7369 5216
d62a17ae 5217 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5218 if (!peer)
5219 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 5220
d62a17ae 5221 ret = update_group_adjust_soloness(peer, 0);
5222 return bgp_vty_return(vty, ret);
3f9c7369
DS
5223}
5224
28c6e247
IR
5225DEFUN (neighbor_password,
5226 neighbor_password_cmd,
5227 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5228 NEIGHBOR_STR
5229 NEIGHBOR_ADDR_STR2
5230 "Set a password\n"
5231 "The password\n")
0df7c91f 5232{
d62a17ae 5233 int idx_peer = 1;
5234 int idx_line = 3;
28c6e247
IR
5235 struct peer *peer;
5236 int ret;
0df7c91f 5237
28c6e247
IR
5238 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5239 if (!peer)
d62a17ae 5240 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 5241
28c6e247
IR
5242 ret = peer_password_set(peer, argv[idx_line]->arg);
5243 return bgp_vty_return(vty, ret);
0df7c91f
PJ
5244}
5245
28c6e247
IR
5246DEFUN (no_neighbor_password,
5247 no_neighbor_password_cmd,
5248 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5249 NO_STR
5250 NEIGHBOR_STR
5251 NEIGHBOR_ADDR_STR2
5252 "Set a password\n"
5253 "The password\n")
0df7c91f 5254{
d62a17ae 5255 int idx_peer = 2;
28c6e247
IR
5256 struct peer *peer;
5257 int ret;
0df7c91f 5258
28c6e247
IR
5259 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5260 if (!peer)
d62a17ae 5261 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 5262
28c6e247
IR
5263 ret = peer_password_unset(peer);
5264 return bgp_vty_return(vty, ret);
0df7c91f 5265}
6b0655a2 5266
28c6e247
IR
5267DEFUN (neighbor_activate,
5268 neighbor_activate_cmd,
5269 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5270 NEIGHBOR_STR
5271 NEIGHBOR_ADDR_STR2
5272 "Enable the Address Family for this Neighbor\n")
718e3744 5273{
d62a17ae 5274 int idx_peer = 1;
28c6e247
IR
5275 int ret;
5276 struct peer *peer;
56ceae84 5277
28c6e247
IR
5278 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5279 if (!peer)
d62a17ae 5280 return CMD_WARNING_CONFIG_FAILED;
718e3744 5281
28c6e247
IR
5282 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5283 return bgp_vty_return(vty, ret);
718e3744 5284}
5285
d62a17ae 5286ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5287 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5288 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5289 "Enable the Address Family for this Neighbor\n")
596c17ba 5290
28c6e247
IR
5291DEFUN (no_neighbor_activate,
5292 no_neighbor_activate_cmd,
5293 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5294 NO_STR
5295 NEIGHBOR_STR
5296 NEIGHBOR_ADDR_STR2
5297 "Enable the Address Family for this Neighbor\n")
718e3744 5298{
d62a17ae 5299 int idx_peer = 2;
28c6e247
IR
5300 int ret;
5301 struct peer *peer;
f4b8ec07 5302
28c6e247
IR
5303 /* Lookup peer. */
5304 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5305 if (!peer)
d62a17ae 5306 return CMD_WARNING_CONFIG_FAILED;
718e3744 5307
28c6e247
IR
5308 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5309 return bgp_vty_return(vty, ret);
718e3744 5310}
6b0655a2 5311
d62a17ae 5312ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5313 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5314 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5315 "Enable the Address Family for this Neighbor\n")
596c17ba 5316
28c6e247
IR
5317DEFUN (neighbor_set_peer_group,
5318 neighbor_set_peer_group_cmd,
5319 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5320 NEIGHBOR_STR
5321 NEIGHBOR_ADDR_STR2
5322 "Member of the peer-group\n"
5323 "Peer-group name\n")
718e3744 5324{
28c6e247 5325 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5326 int idx_peer = 1;
5327 int idx_word = 3;
28c6e247
IR
5328 int ret;
5329 as_t as;
5330 union sockunion su;
5331 struct peer *peer;
5332 struct peer_group *group;
5333
5334 ret = str2sockunion(argv[idx_peer]->arg, &su);
5335 if (ret < 0) {
5336 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5337 if (!peer) {
5338 vty_out(vty, "%% Malformed address or name: %s\n",
5339 argv[idx_peer]->arg);
5340 return CMD_WARNING_CONFIG_FAILED;
5341 }
5342 } else {
5343 if (peer_address_self_check(bgp, &su)) {
5344 vty_out(vty,
5345 "%% Can not configure the local system as neighbor\n");
5346 return CMD_WARNING_CONFIG_FAILED;
5347 }
2a059a54 5348
28c6e247
IR
5349 /* Disallow for dynamic neighbor. */
5350 peer = peer_lookup(bgp, &su);
5351 if (peer && peer_dynamic_neighbor(peer)) {
5352 vty_out(vty,
5353 "%% Operation not allowed on a dynamic neighbor\n");
5354 return CMD_WARNING_CONFIG_FAILED;
5355 }
5356 }
5357
5358 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5359 if (!group) {
5360 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 5361 return CMD_WARNING_CONFIG_FAILED;
28c6e247 5362 }
d62a17ae 5363
28c6e247 5364 ret = peer_group_bind(bgp, &su, peer, group, &as);
2a059a54 5365
28c6e247 5366 return bgp_vty_return(vty, ret);
d62a17ae 5367}
5368
5369ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 5370 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5371 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5372 "Member of the peer-group\n"
5373 "Peer-group name\n")
596c17ba 5374
28c6e247
IR
5375DEFUN (no_neighbor_set_peer_group,
5376 no_neighbor_set_peer_group_cmd,
5377 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5378 NO_STR
5379 NEIGHBOR_STR
5380 NEIGHBOR_ADDR_STR2
5381 "Member of the peer-group\n"
5382 "Peer-group name\n")
718e3744 5383{
28c6e247 5384 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5385 int idx_peer = 2;
28c6e247
IR
5386 int idx_word = 4;
5387 int ret;
5388 struct peer *peer;
5389 struct peer_group *group;
d62a17ae 5390
28c6e247
IR
5391 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5392 if (!peer)
d62a17ae 5393 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 5394
28c6e247
IR
5395 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5396 if (!group) {
5397 vty_out(vty, "%% Configure the peer-group first\n");
5398 return CMD_WARNING_CONFIG_FAILED;
5399 }
718e3744 5400
28c6e247
IR
5401 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5402 bgp_zebra_terminate_radv(peer->bgp, peer);
5403
5404 peer_notify_unconfig(peer);
5405 ret = peer_delete(peer);
5406
5407 return bgp_vty_return(vty, ret);
718e3744 5408}
6b0655a2 5409
d62a17ae 5410ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
71cc0c88 5411 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5412 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5413 "Member of the peer-group\n"
5414 "Peer-group name\n")
596c17ba 5415
718e3744 5416/* neighbor passive. */
28c6e247
IR
5417DEFUN (neighbor_passive,
5418 neighbor_passive_cmd,
5419 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5420 NEIGHBOR_STR
5421 NEIGHBOR_ADDR_STR2
5422 "Don't send open messages to this neighbor\n")
718e3744 5423{
d62a17ae 5424 int idx_peer = 1;
28c6e247 5425 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5426}
5427
28c6e247
IR
5428DEFUN (no_neighbor_passive,
5429 no_neighbor_passive_cmd,
5430 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5431 NO_STR
5432 NEIGHBOR_STR
5433 NEIGHBOR_ADDR_STR2
5434 "Don't send open messages to this neighbor\n")
718e3744 5435{
d62a17ae 5436 int idx_peer = 2;
28c6e247 5437 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5438}
6b0655a2 5439
718e3744 5440/* neighbor shutdown. */
28c6e247
IR
5441DEFUN (neighbor_shutdown_msg,
5442 neighbor_shutdown_msg_cmd,
5443 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5444 NEIGHBOR_STR
5445 NEIGHBOR_ADDR_STR2
5446 "Administratively shut down this neighbor\n"
5447 "Add a shutdown message (RFC 8203)\n"
5448 "Shutdown message\n")
718e3744 5449{
d62a17ae 5450 int idx_peer = 1;
73d70fa6 5451
d62a17ae 5452 if (argc >= 5) {
28c6e247
IR
5453 struct peer *peer =
5454 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
d62a17ae 5455 char *message;
73d70fa6 5456
28c6e247
IR
5457 if (!peer)
5458 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5459 message = argv_concat(argv, argc, 4);
28c6e247
IR
5460 peer_tx_shutdown_message_set(peer, message);
5461 XFREE(MTYPE_TMP, message);
d62a17ae 5462 }
73d70fa6 5463
28c6e247 5464 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 5465}
5466
1d80f243 5467ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5468 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5469 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5470 "Administratively shut down this neighbor\n")
73d70fa6 5471
28c6e247
IR
5472DEFUN (no_neighbor_shutdown_msg,
5473 no_neighbor_shutdown_msg_cmd,
5474 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5475 NO_STR
5476 NEIGHBOR_STR
5477 NEIGHBOR_ADDR_STR2
5478 "Administratively shut down this neighbor\n"
5479 "Remove a shutdown message (RFC 8203)\n"
5480 "Shutdown message\n")
718e3744 5481{
d62a17ae 5482 int idx_peer = 2;
73d70fa6 5483
28c6e247
IR
5484 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5485 PEER_FLAG_SHUTDOWN);
718e3744 5486}
6b0655a2 5487
1d80f243 5488ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5489 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5490 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5491 "Administratively shut down this neighbor\n")
73d70fa6 5492
8336c896
DA
5493DEFUN(neighbor_shutdown_rtt,
5494 neighbor_shutdown_rtt_cmd,
5495 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5496 NEIGHBOR_STR
5497 NEIGHBOR_ADDR_STR2
5498 "Administratively shut down this neighbor\n"
5499 "Shutdown if round-trip-time is higher than expected\n"
5500 "Round-trip-time in milliseconds\n"
5501 "Specify the number of keepalives before shutdown\n"
5502 "The number of keepalives with higher RTT to shutdown\n")
5503{
5504 int idx_peer = 1;
5505 int idx_rtt = 4;
5506 int idx_count = 0;
5507 struct peer *peer;
5508
5509 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5510
5511 if (!peer)
5512 return CMD_WARNING_CONFIG_FAILED;
5513
5514 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5515
5516 if (argv_find(argv, argc, "count", &idx_count))
5517 peer->rtt_keepalive_conf =
5518 strtol(argv[idx_count + 1]->arg, NULL, 10);
5519
5520 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5521 PEER_FLAG_RTT_SHUTDOWN);
5522}
5523
5524DEFUN(no_neighbor_shutdown_rtt,
5525 no_neighbor_shutdown_rtt_cmd,
5526 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5527 NO_STR
5528 NEIGHBOR_STR
5529 NEIGHBOR_ADDR_STR2
5530 "Administratively shut down this neighbor\n"
5531 "Shutdown if round-trip-time is higher than expected\n"
5532 "Round-trip-time in milliseconds\n"
5533 "Specify the number of keepalives before shutdown\n"
5534 "The number of keepalives with higher RTT to shutdown\n")
5535{
5536 int idx_peer = 2;
5537 struct peer *peer;
5538
5539 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5540
5541 if (!peer)
5542 return CMD_WARNING_CONFIG_FAILED;
5543
5544 peer->rtt_expected = 0;
5545 peer->rtt_keepalive_conf = 1;
5546
5547 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5548 PEER_FLAG_RTT_SHUTDOWN);
5549}
5550
718e3744 5551/* neighbor capability dynamic. */
28c6e247
IR
5552DEFUN (neighbor_capability_dynamic,
5553 neighbor_capability_dynamic_cmd,
5554 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5555 NEIGHBOR_STR
5556 NEIGHBOR_ADDR_STR2
5557 "Advertise capability to the peer\n"
5558 "Advertise dynamic capability to this neighbor\n")
718e3744 5559{
d62a17ae 5560 int idx_peer = 1;
28c6e247
IR
5561 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5562 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5563}
5564
28c6e247
IR
5565DEFUN (no_neighbor_capability_dynamic,
5566 no_neighbor_capability_dynamic_cmd,
5567 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5568 NO_STR
5569 NEIGHBOR_STR
5570 NEIGHBOR_ADDR_STR2
5571 "Advertise capability to the peer\n"
5572 "Advertise dynamic capability to this neighbor\n")
718e3744 5573{
d62a17ae 5574 int idx_peer = 2;
28c6e247
IR
5575 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5576 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5577}
6b0655a2 5578
718e3744 5579/* neighbor dont-capability-negotiate */
5580DEFUN (neighbor_dont_capability_negotiate,
5581 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5582 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5583 NEIGHBOR_STR
5584 NEIGHBOR_ADDR_STR2
5585 "Do not perform capability negotiation\n")
5586{
d62a17ae 5587 int idx_peer = 1;
5588 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5589 PEER_FLAG_DONT_CAPABILITY);
718e3744 5590}
5591
5592DEFUN (no_neighbor_dont_capability_negotiate,
5593 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5594 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5595 NO_STR
5596 NEIGHBOR_STR
5597 NEIGHBOR_ADDR_STR2
5598 "Do not perform capability negotiation\n")
5599{
28c6e247
IR
5600 int idx_peer = 2;
5601 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5602 PEER_FLAG_DONT_CAPABILITY);
f4b8ec07
CS
5603}
5604
28c6e247
IR
5605/* neighbor capability extended next hop encoding */
5606DEFUN (neighbor_capability_enhe,
5607 neighbor_capability_enhe_cmd,
5608 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5609 NEIGHBOR_STR
5610 NEIGHBOR_ADDR_STR2
5611 "Advertise capability to the peer\n"
5612 "Advertise extended next-hop capability to the peer\n")
f4b8ec07 5613{
28c6e247 5614 int idx_peer = 1;
c4786405
DS
5615 struct peer *peer;
5616
5617 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5618 if (peer && peer->conf_if)
5619 return CMD_SUCCESS;
5620
28c6e247
IR
5621 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5622 PEER_FLAG_CAPABILITY_ENHE);
5623}
f4b8ec07 5624
28c6e247
IR
5625DEFUN (no_neighbor_capability_enhe,
5626 no_neighbor_capability_enhe_cmd,
5627 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5628 NO_STR
5629 NEIGHBOR_STR
5630 NEIGHBOR_ADDR_STR2
5631 "Advertise capability to the peer\n"
5632 "Advertise extended next-hop capability to the peer\n")
5633{
5634 int idx_peer = 2;
c4786405
DS
5635 struct peer *peer;
5636
5637 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5638 if (peer && peer->conf_if) {
5639 vty_out(vty,
5640 "Peer %s cannot have capability extended-nexthop turned off\n",
5641 argv[idx_peer]->arg);
5642 return CMD_WARNING_CONFIG_FAILED;
5643 }
5644
28c6e247
IR
5645 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5646 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5647}
5648
234f6fd4
DA
5649/* neighbor capability software-version */
5650DEFPY(neighbor_capability_software_version,
5651 neighbor_capability_software_version_cmd,
5652 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor capability software-version",
5653 NO_STR
5654 NEIGHBOR_STR
5655 NEIGHBOR_ADDR_STR2
5656 "Advertise capability to the peer\n"
5657 "Advertise Software Version capability to the peer\n")
5658{
5659 struct peer *peer;
5660
5661 peer = peer_and_group_lookup_vty(vty, neighbor);
5662 if (peer && peer->conf_if)
5663 return CMD_SUCCESS;
5664
5665 if (no)
5666 return peer_flag_unset_vty(vty, neighbor,
5667 PEER_FLAG_CAPABILITY_SOFT_VERSION);
5668 else
5669 return peer_flag_set_vty(vty, neighbor,
5670 PEER_FLAG_CAPABILITY_SOFT_VERSION);
5671}
5672
d62a17ae 5673static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5674 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5675 int set)
718e3744 5676{
d62a17ae 5677 int ret;
5678 struct peer *peer;
718e3744 5679
d62a17ae 5680 peer = peer_and_group_lookup_vty(vty, peer_str);
5681 if (!peer)
5682 return CMD_WARNING_CONFIG_FAILED;
718e3744 5683
d62a17ae 5684 if (set)
5685 ret = peer_af_flag_set(peer, afi, safi, flag);
5686 else
5687 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5688
d62a17ae 5689 return bgp_vty_return(vty, ret);
718e3744 5690}
5691
d62a17ae 5692static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5693 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5694{
d62a17ae 5695 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5696}
5697
d62a17ae 5698static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5699 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5700{
d62a17ae 5701 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5702}
6b0655a2 5703
718e3744 5704/* neighbor capability orf prefix-list. */
5705DEFUN (neighbor_capability_orf_prefix,
5706 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5707 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5708 NEIGHBOR_STR
5709 NEIGHBOR_ADDR_STR2
5710 "Advertise capability to the peer\n"
5711 "Advertise ORF capability to the peer\n"
5712 "Advertise prefixlist ORF capability to this neighbor\n"
5713 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5714 "Capability to RECEIVE the ORF from this neighbor\n"
5715 "Capability to SEND the ORF to this neighbor\n")
5716{
d62a17ae 5717 int idx_send_recv = 5;
db45f64d
DS
5718 char *peer_str = argv[1]->arg;
5719 struct peer *peer;
5720 afi_t afi = bgp_node_afi(vty);
5721 safi_t safi = bgp_node_safi(vty);
d62a17ae 5722
db45f64d
DS
5723 peer = peer_and_group_lookup_vty(vty, peer_str);
5724 if (!peer)
d62a17ae 5725 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5726
db45f64d
DS
5727 if (strmatch(argv[idx_send_recv]->text, "send"))
5728 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5729 PEER_FLAG_ORF_PREFIX_SM);
5730
5731 if (strmatch(argv[idx_send_recv]->text, "receive"))
5732 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5733 PEER_FLAG_ORF_PREFIX_RM);
5734
5735 if (strmatch(argv[idx_send_recv]->text, "both"))
5736 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5737 PEER_FLAG_ORF_PREFIX_SM)
5738 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5739 PEER_FLAG_ORF_PREFIX_RM);
5740
5741 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5742}
5743
5744ALIAS_HIDDEN(
5745 neighbor_capability_orf_prefix,
5746 neighbor_capability_orf_prefix_hidden_cmd,
5747 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5748 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5749 "Advertise capability to the peer\n"
5750 "Advertise ORF capability to the peer\n"
5751 "Advertise prefixlist ORF capability to this neighbor\n"
5752 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5753 "Capability to RECEIVE the ORF from this neighbor\n"
5754 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5755
718e3744 5756DEFUN (no_neighbor_capability_orf_prefix,
5757 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5758 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5759 NO_STR
5760 NEIGHBOR_STR
5761 NEIGHBOR_ADDR_STR2
5762 "Advertise capability to the peer\n"
5763 "Advertise ORF capability to the peer\n"
5764 "Advertise prefixlist ORF capability to this neighbor\n"
5765 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5766 "Capability to RECEIVE the ORF from this neighbor\n"
5767 "Capability to SEND the ORF to this neighbor\n")
5768{
d62a17ae 5769 int idx_send_recv = 6;
db45f64d
DS
5770 char *peer_str = argv[2]->arg;
5771 struct peer *peer;
5772 afi_t afi = bgp_node_afi(vty);
5773 safi_t safi = bgp_node_safi(vty);
d62a17ae 5774
db45f64d
DS
5775 peer = peer_and_group_lookup_vty(vty, peer_str);
5776 if (!peer)
d62a17ae 5777 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5778
db45f64d
DS
5779 if (strmatch(argv[idx_send_recv]->text, "send"))
5780 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5781 PEER_FLAG_ORF_PREFIX_SM);
5782
5783 if (strmatch(argv[idx_send_recv]->text, "receive"))
5784 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5785 PEER_FLAG_ORF_PREFIX_RM);
5786
5787 if (strmatch(argv[idx_send_recv]->text, "both"))
5788 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5789 PEER_FLAG_ORF_PREFIX_SM)
5790 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5791 PEER_FLAG_ORF_PREFIX_RM);
5792
5793 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5794}
5795
5796ALIAS_HIDDEN(
5797 no_neighbor_capability_orf_prefix,
5798 no_neighbor_capability_orf_prefix_hidden_cmd,
5799 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5800 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5801 "Advertise capability to the peer\n"
5802 "Advertise ORF capability to the peer\n"
5803 "Advertise prefixlist ORF capability to this neighbor\n"
5804 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5805 "Capability to RECEIVE the ORF from this neighbor\n"
5806 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5807
718e3744 5808/* neighbor next-hop-self. */
28c6e247
IR
5809DEFUN (neighbor_nexthop_self,
5810 neighbor_nexthop_self_cmd,
5811 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5812 NEIGHBOR_STR
5813 NEIGHBOR_ADDR_STR2
5814 "Disable the next hop calculation for this neighbor\n")
718e3744 5815{
d62a17ae 5816 int idx_peer = 1;
28c6e247
IR
5817 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5818 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 5819}
9e7a53c1 5820
d62a17ae 5821ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5822 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5823 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5824 "Disable the next hop calculation for this neighbor\n")
596c17ba 5825
f4b8ec07 5826/* neighbor next-hop-self. */
28c6e247
IR
5827DEFUN (neighbor_nexthop_self_force,
5828 neighbor_nexthop_self_force_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5830 NEIGHBOR_STR
5831 NEIGHBOR_ADDR_STR2
5832 "Disable the next hop calculation for this neighbor\n"
5833 "Set the next hop to self for reflected routes\n")
f4b8ec07
CS
5834{
5835 int idx_peer = 1;
28c6e247
IR
5836 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5837 bgp_node_safi(vty),
5838 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 5839}
5840
d62a17ae 5841ALIAS_HIDDEN(neighbor_nexthop_self_force,
5842 neighbor_nexthop_self_force_hidden_cmd,
5843 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5844 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5845 "Disable the next hop calculation for this neighbor\n"
5846 "Set the next hop to self for reflected routes\n")
596c17ba 5847
1bc4e531
DA
5848ALIAS_HIDDEN(neighbor_nexthop_self_force,
5849 neighbor_nexthop_self_all_hidden_cmd,
5850 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5851 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5852 "Disable the next hop calculation for this neighbor\n"
5853 "Set the next hop to self for reflected routes\n")
5854
28c6e247
IR
5855DEFUN (no_neighbor_nexthop_self,
5856 no_neighbor_nexthop_self_cmd,
5857 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5858 NO_STR
5859 NEIGHBOR_STR
5860 NEIGHBOR_ADDR_STR2
5861 "Disable the next hop calculation for this neighbor\n")
718e3744 5862{
d62a17ae 5863 int idx_peer = 2;
28c6e247
IR
5864 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5865 bgp_node_afi(vty), bgp_node_safi(vty),
5866 PEER_FLAG_NEXTHOP_SELF);
718e3744 5867}
6b0655a2 5868
d62a17ae 5869ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5870 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5871 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5872 "Disable the next hop calculation for this neighbor\n")
596c17ba 5873
28c6e247
IR
5874DEFUN (no_neighbor_nexthop_self_force,
5875 no_neighbor_nexthop_self_force_cmd,
5876 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5877 NO_STR
5878 NEIGHBOR_STR
5879 NEIGHBOR_ADDR_STR2
5880 "Disable the next hop calculation for this neighbor\n"
5881 "Set the next hop to self for reflected routes\n")
88b8ed8d 5882{
d62a17ae 5883 int idx_peer = 2;
28c6e247
IR
5884 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5885 bgp_node_afi(vty), bgp_node_safi(vty),
5886 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5887}
a538debe 5888
d62a17ae 5889ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5890 no_neighbor_nexthop_self_force_hidden_cmd,
5891 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5892 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5893 "Disable the next hop calculation for this neighbor\n"
5894 "Set the next hop to self for reflected routes\n")
596c17ba 5895
1bc4e531
DA
5896ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5897 no_neighbor_nexthop_self_all_hidden_cmd,
5898 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5899 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5900 "Disable the next hop calculation for this neighbor\n"
5901 "Set the next hop to self for reflected routes\n")
5902
c7122e14 5903/* neighbor as-override */
28c6e247
IR
5904DEFUN (neighbor_as_override,
5905 neighbor_as_override_cmd,
5906 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5907 NEIGHBOR_STR
5908 NEIGHBOR_ADDR_STR2
5909 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5910{
d62a17ae 5911 int idx_peer = 1;
28c6e247
IR
5912 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5913 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5914}
5915
d62a17ae 5916ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5917 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5918 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5919 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5920
28c6e247
IR
5921DEFUN (no_neighbor_as_override,
5922 no_neighbor_as_override_cmd,
5923 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5924 NO_STR
5925 NEIGHBOR_STR
5926 NEIGHBOR_ADDR_STR2
5927 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5928{
d62a17ae 5929 int idx_peer = 2;
28c6e247
IR
5930 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5931 bgp_node_afi(vty), bgp_node_safi(vty),
5932 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5933}
5934
d62a17ae 5935ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5936 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5937 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5938 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5939
718e3744 5940/* neighbor remove-private-AS. */
28c6e247
IR
5941DEFUN (neighbor_remove_private_as,
5942 neighbor_remove_private_as_cmd,
5943 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5944 NEIGHBOR_STR
5945 NEIGHBOR_ADDR_STR2
5946 "Remove private ASNs in outbound updates\n")
718e3744 5947{
d62a17ae 5948 int idx_peer = 1;
28c6e247
IR
5949 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5950 bgp_node_safi(vty),
5951 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5952}
5953
d62a17ae 5954ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5955 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5956 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5957 "Remove private ASNs in outbound updates\n")
596c17ba 5958
28c6e247
IR
5959DEFUN (neighbor_remove_private_as_all,
5960 neighbor_remove_private_as_all_cmd,
5961 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5962 NEIGHBOR_STR
5963 NEIGHBOR_ADDR_STR2
5964 "Remove private ASNs in outbound updates\n"
5965 "Apply to all AS numbers\n")
5000f21c 5966{
d62a17ae 5967 int idx_peer = 1;
28c6e247
IR
5968 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5969 bgp_node_safi(vty),
5970 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
5971}
5972
d62a17ae 5973ALIAS_HIDDEN(neighbor_remove_private_as_all,
5974 neighbor_remove_private_as_all_hidden_cmd,
5975 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5976 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5977 "Remove private ASNs in outbound updates\n"
a0dfca37 5978 "Apply to all AS numbers\n")
596c17ba 5979
28c6e247
IR
5980DEFUN (neighbor_remove_private_as_replace_as,
5981 neighbor_remove_private_as_replace_as_cmd,
5982 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5983 NEIGHBOR_STR
5984 NEIGHBOR_ADDR_STR2
5985 "Remove private ASNs in outbound updates\n"
5986 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5987{
d62a17ae 5988 int idx_peer = 1;
28c6e247
IR
5989 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5990 bgp_node_safi(vty),
5991 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
5992}
5993
d62a17ae 5994ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5995 neighbor_remove_private_as_replace_as_hidden_cmd,
5996 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5997 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5998 "Remove private ASNs in outbound updates\n"
5999 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6000
28c6e247
IR
6001DEFUN (neighbor_remove_private_as_all_replace_as,
6002 neighbor_remove_private_as_all_replace_as_cmd,
6003 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6004 NEIGHBOR_STR
6005 NEIGHBOR_ADDR_STR2
6006 "Remove private ASNs in outbound updates\n"
6007 "Apply to all AS numbers\n"
6008 "Replace private ASNs with our ASN in outbound updates\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_REPLACE);
5000f21c
DS
6014}
6015
d62a17ae 6016ALIAS_HIDDEN(
6017 neighbor_remove_private_as_all_replace_as,
6018 neighbor_remove_private_as_all_replace_as_hidden_cmd,
6019 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6020 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6021 "Remove private ASNs in outbound updates\n"
6022 "Apply to all AS numbers\n"
6023 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6024
28c6e247
IR
6025DEFUN (no_neighbor_remove_private_as,
6026 no_neighbor_remove_private_as_cmd,
6027 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6028 NO_STR
6029 NEIGHBOR_STR
6030 NEIGHBOR_ADDR_STR2
6031 "Remove private ASNs in outbound updates\n")
718e3744 6032{
d62a17ae 6033 int idx_peer = 2;
28c6e247
IR
6034 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6035 bgp_node_afi(vty), bgp_node_safi(vty),
6036 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 6037}
6b0655a2 6038
d62a17ae 6039ALIAS_HIDDEN(no_neighbor_remove_private_as,
6040 no_neighbor_remove_private_as_hidden_cmd,
6041 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6042 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6043 "Remove private ASNs in outbound updates\n")
596c17ba 6044
28c6e247
IR
6045DEFUN (no_neighbor_remove_private_as_all,
6046 no_neighbor_remove_private_as_all_cmd,
6047 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6048 NO_STR
6049 NEIGHBOR_STR
6050 NEIGHBOR_ADDR_STR2
6051 "Remove private ASNs in outbound updates\n"
6052 "Apply to all AS numbers\n")
88b8ed8d 6053{
d62a17ae 6054 int idx_peer = 2;
28c6e247
IR
6055 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6056 bgp_node_afi(vty), bgp_node_safi(vty),
6057 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 6058}
5000f21c 6059
d62a17ae 6060ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
6061 no_neighbor_remove_private_as_all_hidden_cmd,
6062 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6063 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6064 "Remove private ASNs in outbound updates\n"
6065 "Apply to all AS numbers\n")
596c17ba 6066
28c6e247
IR
6067DEFUN (no_neighbor_remove_private_as_replace_as,
6068 no_neighbor_remove_private_as_replace_as_cmd,
6069 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6070 NO_STR
6071 NEIGHBOR_STR
6072 NEIGHBOR_ADDR_STR2
6073 "Remove private ASNs in outbound updates\n"
6074 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 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_REPLACE);
88b8ed8d 6080}
5000f21c 6081
d62a17ae 6082ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
6083 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6084 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6085 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6086 "Remove private ASNs in outbound updates\n"
6087 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6088
28c6e247
IR
6089DEFUN (no_neighbor_remove_private_as_all_replace_as,
6090 no_neighbor_remove_private_as_all_replace_as_cmd,
6091 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6092 NO_STR
6093 NEIGHBOR_STR
6094 NEIGHBOR_ADDR_STR2
6095 "Remove private ASNs in outbound updates\n"
6096 "Apply to all AS numbers\n"
6097 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 6098{
d62a17ae 6099 int idx_peer = 2;
28c6e247
IR
6100 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6101 bgp_node_afi(vty), bgp_node_safi(vty),
6102 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 6103}
5000f21c 6104
d62a17ae 6105ALIAS_HIDDEN(
6106 no_neighbor_remove_private_as_all_replace_as,
6107 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6108 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6109 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6110 "Remove private ASNs in outbound updates\n"
6111 "Apply to all AS numbers\n"
6112 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6113
5000f21c 6114
718e3744 6115/* neighbor send-community. */
28c6e247
IR
6116DEFUN (neighbor_send_community,
6117 neighbor_send_community_cmd,
6118 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6119 NEIGHBOR_STR
6120 NEIGHBOR_ADDR_STR2
6121 "Send Community attribute to this neighbor\n")
718e3744 6122{
d62a17ae 6123 int idx_peer = 1;
27c05d4d 6124
f63d4054
IR
6125 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6126 bgp_node_safi(vty),
6127 PEER_FLAG_SEND_COMMUNITY);
718e3744 6128}
6129
d62a17ae 6130ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6131 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6132 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6133 "Send Community attribute to this neighbor\n")
596c17ba 6134
28c6e247
IR
6135DEFUN (no_neighbor_send_community,
6136 no_neighbor_send_community_cmd,
6137 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6138 NO_STR
6139 NEIGHBOR_STR
6140 NEIGHBOR_ADDR_STR2
6141 "Send Community attribute to this neighbor\n")
718e3744 6142{
d62a17ae 6143 int idx_peer = 2;
27c05d4d 6144
f63d4054
IR
6145 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6146 bgp_node_afi(vty), bgp_node_safi(vty),
6147 PEER_FLAG_SEND_COMMUNITY);
718e3744 6148}
6b0655a2 6149
d62a17ae 6150ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6151 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6152 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6153 "Send Community attribute to this neighbor\n")
596c17ba 6154
718e3744 6155/* neighbor send-community extended. */
28c6e247
IR
6156DEFUN (neighbor_send_community_type,
6157 neighbor_send_community_type_cmd,
6158 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6159 NEIGHBOR_STR
6160 NEIGHBOR_ADDR_STR2
6161 "Send Community attribute to this neighbor\n"
6162 "Send Standard and Extended Community attributes\n"
6163 "Send Standard, Large and Extended Community attributes\n"
6164 "Send Extended Community attributes\n"
6165 "Send Standard Community attributes\n"
6166 "Send Large Community attributes\n")
718e3744 6167{
27c05d4d 6168 const char *type = argv[argc - 1]->text;
db45f64d 6169 char *peer_str = argv[1]->arg;
28c6e247 6170 struct peer *peer;
db45f64d 6171 afi_t afi = bgp_node_afi(vty);
28c6e247 6172 safi_t safi = bgp_node_safi(vty);
f4b8ec07 6173
28c6e247
IR
6174 peer = peer_and_group_lookup_vty(vty, peer_str);
6175 if (!peer)
6176 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07 6177
28c6e247
IR
6178 if (strmatch(type, "standard"))
6179 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6180 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 6181
28c6e247
IR
6182 if (strmatch(type, "extended"))
6183 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6184 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6185
28c6e247
IR
6186 if (strmatch(type, "large"))
6187 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6188 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07 6189
28c6e247
IR
6190 if (strmatch(type, "both")) {
6191 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6192 PEER_FLAG_SEND_COMMUNITY)
6193 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6194 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6195 }
28c6e247
IR
6196 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6197 PEER_FLAG_SEND_COMMUNITY)
6198 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6199 PEER_FLAG_SEND_EXT_COMMUNITY)
6200 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6201 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 6202}
6203
6204ALIAS_HIDDEN(
6205 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6206 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6207 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6208 "Send Community attribute to this neighbor\n"
6209 "Send Standard and Extended Community attributes\n"
6210 "Send Standard, Large and Extended Community attributes\n"
6211 "Send Extended Community attributes\n"
6212 "Send Standard Community attributes\n"
6213 "Send Large Community attributes\n")
596c17ba 6214
28c6e247
IR
6215DEFUN (no_neighbor_send_community_type,
6216 no_neighbor_send_community_type_cmd,
6217 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6218 NO_STR
6219 NEIGHBOR_STR
6220 NEIGHBOR_ADDR_STR2
6221 "Send Community attribute to this neighbor\n"
6222 "Send Standard and Extended Community attributes\n"
6223 "Send Standard, Large and Extended Community attributes\n"
6224 "Send Extended Community attributes\n"
6225 "Send Standard Community attributes\n"
6226 "Send Large Community attributes\n")
718e3744 6227{
d62a17ae 6228 const char *type = argv[argc - 1]->text;
db45f64d 6229 char *peer_str = argv[2]->arg;
28c6e247 6230 struct peer *peer;
db45f64d
DS
6231 afi_t afi = bgp_node_afi(vty);
6232 safi_t safi = bgp_node_safi(vty);
6233
28c6e247
IR
6234 peer = peer_and_group_lookup_vty(vty, peer_str);
6235 if (!peer)
f4b8ec07
CS
6236 return CMD_WARNING_CONFIG_FAILED;
6237
28c6e247
IR
6238 if (strmatch(type, "standard"))
6239 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6240 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 6241
28c6e247
IR
6242 if (strmatch(type, "extended"))
6243 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6244 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6245
28c6e247
IR
6246 if (strmatch(type, "large"))
6247 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6248 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07
CS
6249
6250 if (strmatch(type, "both")) {
db45f64d 6251
28c6e247
IR
6252 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6253 PEER_FLAG_SEND_COMMUNITY)
6254 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6255 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
6256 }
6257
28c6e247
IR
6258 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6259 PEER_FLAG_SEND_COMMUNITY)
6260 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6261 PEER_FLAG_SEND_EXT_COMMUNITY)
6262 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6263 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 6264}
6265
6266ALIAS_HIDDEN(
6267 no_neighbor_send_community_type,
6268 no_neighbor_send_community_type_hidden_cmd,
6269 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6270 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6271 "Send Community attribute to this neighbor\n"
6272 "Send Standard and Extended Community attributes\n"
6273 "Send Standard, Large and Extended Community attributes\n"
6274 "Send Extended Community attributes\n"
6275 "Send Standard Community attributes\n"
6276 "Send Large Community attributes\n")
596c17ba 6277
718e3744 6278/* neighbor soft-reconfig. */
28c6e247
IR
6279DEFUN (neighbor_soft_reconfiguration,
6280 neighbor_soft_reconfiguration_cmd,
6281 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6282 NEIGHBOR_STR
6283 NEIGHBOR_ADDR_STR2
6284 "Per neighbor soft reconfiguration\n"
6285 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6286{
d62a17ae 6287 int idx_peer = 1;
28c6e247
IR
6288 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6289 bgp_node_safi(vty),
6290 PEER_FLAG_SOFT_RECONFIG);
718e3744 6291}
6292
d62a17ae 6293ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6294 neighbor_soft_reconfiguration_hidden_cmd,
6295 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6296 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6297 "Per neighbor soft reconfiguration\n"
6298 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6299
28c6e247
IR
6300DEFUN (no_neighbor_soft_reconfiguration,
6301 no_neighbor_soft_reconfiguration_cmd,
6302 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6303 NO_STR
6304 NEIGHBOR_STR
6305 NEIGHBOR_ADDR_STR2
6306 "Per neighbor soft reconfiguration\n"
6307 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6308{
d62a17ae 6309 int idx_peer = 2;
28c6e247
IR
6310 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6311 bgp_node_afi(vty), bgp_node_safi(vty),
6312 PEER_FLAG_SOFT_RECONFIG);
718e3744 6313}
6b0655a2 6314
d62a17ae 6315ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6316 no_neighbor_soft_reconfiguration_hidden_cmd,
6317 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6318 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6319 "Per neighbor soft reconfiguration\n"
6320 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6321
28c6e247
IR
6322DEFUN (neighbor_route_reflector_client,
6323 neighbor_route_reflector_client_cmd,
6324 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6325 NEIGHBOR_STR
6326 NEIGHBOR_ADDR_STR2
6327 "Configure a neighbor as Route Reflector client\n")
718e3744 6328{
d62a17ae 6329 int idx_peer = 1;
28c6e247 6330 struct peer *peer;
718e3744 6331
6332
28c6e247
IR
6333 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6334 if (!peer)
d62a17ae 6335 return CMD_WARNING_CONFIG_FAILED;
718e3744 6336
28c6e247
IR
6337 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6338 bgp_node_safi(vty),
6339 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 6340}
6341
d62a17ae 6342ALIAS_HIDDEN(neighbor_route_reflector_client,
6343 neighbor_route_reflector_client_hidden_cmd,
6344 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6345 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6346 "Configure a neighbor as Route Reflector client\n")
596c17ba 6347
28c6e247
IR
6348DEFUN (no_neighbor_route_reflector_client,
6349 no_neighbor_route_reflector_client_cmd,
6350 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6351 NO_STR
6352 NEIGHBOR_STR
6353 NEIGHBOR_ADDR_STR2
6354 "Configure a neighbor as Route Reflector client\n")
718e3744 6355{
d62a17ae 6356 int idx_peer = 2;
28c6e247
IR
6357 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6358 bgp_node_afi(vty), bgp_node_safi(vty),
6359 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 6360}
6b0655a2 6361
d62a17ae 6362ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6363 no_neighbor_route_reflector_client_hidden_cmd,
6364 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6365 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6366 "Configure a neighbor as Route Reflector client\n")
596c17ba 6367
718e3744 6368/* neighbor route-server-client. */
28c6e247
IR
6369DEFUN (neighbor_route_server_client,
6370 neighbor_route_server_client_cmd,
6371 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6372 NEIGHBOR_STR
6373 NEIGHBOR_ADDR_STR2
6374 "Configure a neighbor as Route Server client\n")
718e3744 6375{
d62a17ae 6376 int idx_peer = 1;
28c6e247 6377 struct peer *peer;
f4b8ec07 6378
28c6e247
IR
6379 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6380 if (!peer)
d62a17ae 6381 return CMD_WARNING_CONFIG_FAILED;
28c6e247
IR
6382 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6383 bgp_node_safi(vty),
6384 PEER_FLAG_RSERVER_CLIENT);
718e3744 6385}
6386
d62a17ae 6387ALIAS_HIDDEN(neighbor_route_server_client,
6388 neighbor_route_server_client_hidden_cmd,
6389 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6390 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6391 "Configure a neighbor as Route Server client\n")
596c17ba 6392
28c6e247
IR
6393DEFUN (no_neighbor_route_server_client,
6394 no_neighbor_route_server_client_cmd,
6395 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6396 NO_STR
6397 NEIGHBOR_STR
6398 NEIGHBOR_ADDR_STR2
6399 "Configure a neighbor as Route Server client\n")
fee0f4c6 6400{
d62a17ae 6401 int idx_peer = 2;
28c6e247
IR
6402 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6403 bgp_node_afi(vty), bgp_node_safi(vty),
6404 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 6405}
6b0655a2 6406
d62a17ae 6407ALIAS_HIDDEN(no_neighbor_route_server_client,
6408 no_neighbor_route_server_client_hidden_cmd,
6409 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6410 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6411 "Configure a neighbor as Route Server client\n")
596c17ba 6412
fee0f4c6 6413DEFUN (neighbor_nexthop_local_unchanged,
6414 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6415 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6416 NEIGHBOR_STR
6417 NEIGHBOR_ADDR_STR2
6418 "Configure treatment of outgoing link-local nexthop attribute\n"
6419 "Leave link-local nexthop unchanged for this peer\n")
6420{
d62a17ae 6421 int idx_peer = 1;
6422 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6423 bgp_node_safi(vty),
6424 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6425}
6b0655a2 6426
fee0f4c6 6427DEFUN (no_neighbor_nexthop_local_unchanged,
6428 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6429 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6430 NO_STR
6431 NEIGHBOR_STR
6432 NEIGHBOR_ADDR_STR2
6433 "Configure treatment of outgoing link-local-nexthop attribute\n"
6434 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6435{
d62a17ae 6436 int idx_peer = 2;
6437 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6438 bgp_node_afi(vty), bgp_node_safi(vty),
6439 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6440}
6b0655a2 6441
28c6e247
IR
6442DEFUN (neighbor_attr_unchanged,
6443 neighbor_attr_unchanged_cmd,
6444 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6445 NEIGHBOR_STR
6446 NEIGHBOR_ADDR_STR2
6447 "BGP attribute is propagated unchanged to this neighbor\n"
6448 "As-path attribute\n"
6449 "Nexthop attribute\n"
6450 "Med attribute\n")
718e3744 6451{
d62a17ae 6452 int idx = 0;
8eeb0335 6453 char *peer_str = argv[1]->arg;
28c6e247 6454 struct peer *peer;
db45f64d
DS
6455 bool aspath = false;
6456 bool nexthop = false;
6457 bool med = false;
8eeb0335
DW
6458 afi_t afi = bgp_node_afi(vty);
6459 safi_t safi = bgp_node_safi(vty);
28c6e247 6460 int ret = 0;
f4b8ec07 6461
28c6e247
IR
6462 peer = peer_and_group_lookup_vty(vty, peer_str);
6463 if (!peer)
8eeb0335 6464 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6465
6466 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6467 aspath = true;
6468
d62a17ae 6469 idx = 0;
6470 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6471 nexthop = true;
6472
d62a17ae 6473 idx = 0;
6474 if (argv_find(argv, argc, "med", &idx))
db45f64d 6475 med = true;
d62a17ae 6476
8eeb0335 6477 /* no flags means all of them! */
db45f64d 6478 if (!aspath && !nexthop && !med) {
28c6e247
IR
6479 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6480 PEER_FLAG_AS_PATH_UNCHANGED);
6481 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6482 PEER_FLAG_NEXTHOP_UNCHANGED);
6483 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6484 PEER_FLAG_MED_UNCHANGED);
8eeb0335 6485 } else {
28c6e247
IR
6486 if (!aspath) {
6487 if (peer_af_flag_check(peer, afi, safi,
6488 PEER_FLAG_AS_PATH_UNCHANGED)) {
6489 ret |= peer_af_flag_unset_vty(
6490 vty, peer_str, afi, safi,
6491 PEER_FLAG_AS_PATH_UNCHANGED);
6492 }
6493 } else
6494 ret |= peer_af_flag_set_vty(
6495 vty, peer_str, afi, safi,
6496 PEER_FLAG_AS_PATH_UNCHANGED);
6497
6498 if (!nexthop) {
6499 if (peer_af_flag_check(peer, afi, safi,
6500 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6501 ret |= peer_af_flag_unset_vty(
6502 vty, peer_str, afi, safi,
6503 PEER_FLAG_NEXTHOP_UNCHANGED);
6504 }
6505 } else
6506 ret |= peer_af_flag_set_vty(
6507 vty, peer_str, afi, safi,
6508 PEER_FLAG_NEXTHOP_UNCHANGED);
6509
6510 if (!med) {
6511 if (peer_af_flag_check(peer, afi, safi,
6512 PEER_FLAG_MED_UNCHANGED)) {
6513 ret |= peer_af_flag_unset_vty(
6514 vty, peer_str, afi, safi,
6515 PEER_FLAG_MED_UNCHANGED);
6516 }
6517 } else
6518 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6519 PEER_FLAG_MED_UNCHANGED);
d62a17ae 6520 }
6521
28c6e247 6522 return ret;
d62a17ae 6523}
6524
6525ALIAS_HIDDEN(
6526 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6527 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6528 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6529 "BGP attribute is propagated unchanged to this neighbor\n"
6530 "As-path attribute\n"
6531 "Nexthop attribute\n"
6532 "Med attribute\n")
596c17ba 6533
28c6e247
IR
6534DEFUN (no_neighbor_attr_unchanged,
6535 no_neighbor_attr_unchanged_cmd,
6536 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6537 NO_STR
6538 NEIGHBOR_STR
6539 NEIGHBOR_ADDR_STR2
6540 "BGP attribute is propagated unchanged to this neighbor\n"
6541 "As-path attribute\n"
6542 "Nexthop attribute\n"
6543 "Med attribute\n")
718e3744 6544{
d62a17ae 6545 int idx = 0;
db45f64d 6546 char *peer_str = argv[2]->arg;
28c6e247 6547 struct peer *peer;
db45f64d
DS
6548 bool aspath = false;
6549 bool nexthop = false;
6550 bool med = false;
6551 afi_t afi = bgp_node_afi(vty);
6552 safi_t safi = bgp_node_safi(vty);
28c6e247 6553 int ret = 0;
f4b8ec07 6554
28c6e247
IR
6555 peer = peer_and_group_lookup_vty(vty, peer_str);
6556 if (!peer)
db45f64d 6557 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6558
6559 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6560 aspath = true;
6561
d62a17ae 6562 idx = 0;
6563 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6564 nexthop = true;
6565
d62a17ae 6566 idx = 0;
6567 if (argv_find(argv, argc, "med", &idx))
db45f64d 6568 med = true;
d62a17ae 6569
28c6e247
IR
6570 if (!aspath && !nexthop && !med) // no flags means all of them!
6571 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6572 PEER_FLAG_AS_PATH_UNCHANGED)
6573 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6574 PEER_FLAG_NEXTHOP_UNCHANGED)
6575 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6576 PEER_FLAG_MED_UNCHANGED);
db45f64d
DS
6577
6578 if (aspath)
28c6e247
IR
6579 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6580 PEER_FLAG_AS_PATH_UNCHANGED);
db45f64d
DS
6581
6582 if (nexthop)
28c6e247
IR
6583 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6584 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 6585
db45f64d 6586 if (med)
28c6e247
IR
6587 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6588 PEER_FLAG_MED_UNCHANGED);
db45f64d 6589
28c6e247 6590 return ret;
d62a17ae 6591}
6592
6593ALIAS_HIDDEN(
6594 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6595 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6596 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6597 "BGP attribute is propagated unchanged to this neighbor\n"
6598 "As-path attribute\n"
6599 "Nexthop attribute\n"
6600 "Med attribute\n")
718e3744 6601
28c6e247
IR
6602/* EBGP multihop configuration. */
6603static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6604 const char *ttl_str)
718e3744 6605{
28c6e247
IR
6606 struct peer *peer;
6607 unsigned int ttl;
718e3744 6608
28c6e247
IR
6609 peer = peer_and_group_lookup_vty(vty, ip_str);
6610 if (!peer)
d62a17ae 6611 return CMD_WARNING_CONFIG_FAILED;
718e3744 6612
28c6e247
IR
6613 if (peer->conf_if)
6614 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6615
6616 if (!ttl_str)
6617 ttl = MAXTTL;
6618 else
6619 ttl = strtoul(ttl_str, NULL, 10);
718e3744 6620
28c6e247 6621 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 6622}
6623
28c6e247 6624static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6625{
28c6e247 6626 struct peer *peer;
718e3744 6627
28c6e247
IR
6628 peer = peer_and_group_lookup_vty(vty, ip_str);
6629 if (!peer)
d62a17ae 6630 return CMD_WARNING_CONFIG_FAILED;
718e3744 6631
28c6e247 6632 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 6633}
6634
28c6e247
IR
6635/* neighbor ebgp-multihop. */
6636DEFUN (neighbor_ebgp_multihop,
6637 neighbor_ebgp_multihop_cmd,
6638 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6639 NEIGHBOR_STR
6640 NEIGHBOR_ADDR_STR2
6641 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6642{
28c6e247
IR
6643 int idx_peer = 1;
6644 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6645}
f4b8ec07 6646
28c6e247
IR
6647DEFUN (neighbor_ebgp_multihop_ttl,
6648 neighbor_ebgp_multihop_ttl_cmd,
6649 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6650 NEIGHBOR_STR
6651 NEIGHBOR_ADDR_STR2
6652 "Allow EBGP neighbors not on directly connected networks\n"
6653 "maximum hop count\n")
6654{
6655 int idx_peer = 1;
6656 int idx_number = 3;
6657 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6658 argv[idx_number]->arg);
6659}
f4b8ec07 6660
28c6e247
IR
6661DEFUN (no_neighbor_ebgp_multihop,
6662 no_neighbor_ebgp_multihop_cmd,
6663 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6664 NO_STR
6665 NEIGHBOR_STR
6666 NEIGHBOR_ADDR_STR2
6667 "Allow EBGP neighbors not on directly connected networks\n"
6668 "maximum hop count\n")
6669{
6670 int idx_peer = 2;
6671 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6672}
6673
97a52c82
DA
6674DEFPY (neighbor_aigp,
6675 neighbor_aigp_cmd,
6676 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor aigp",
6677 NO_STR
6678 NEIGHBOR_STR
6679 NEIGHBOR_ADDR_STR2
6680 "Enable send and receive of the AIGP attribute per neighbor\n")
6681{
6682 struct peer *peer;
6683
6684 peer = peer_and_group_lookup_vty(vty, neighbor);
6685 if (!peer)
6686 return CMD_WARNING_CONFIG_FAILED;
6687
6688 if (no)
6689 return peer_flag_unset_vty(vty, neighbor, PEER_FLAG_AIGP);
6690 else
6691 return peer_flag_set_vty(vty, neighbor, PEER_FLAG_AIGP);
6692}
6693
d864dd9e
EB
6694static uint8_t get_role_by_name(const char *role_str)
6695{
6696 if (strncmp(role_str, "peer", 2) == 0)
6697 return ROLE_PEER;
6698 if (strncmp(role_str, "provider", 2) == 0)
6699 return ROLE_PROVIDER;
6700 if (strncmp(role_str, "customer", 2) == 0)
6701 return ROLE_CUSTOMER;
6702 if (strncmp(role_str, "rs-server", 4) == 0)
6703 return ROLE_RS_SERVER;
6704 if (strncmp(role_str, "rs-client", 4) == 0)
6705 return ROLE_RS_CLIENT;
8f2d6021 6706 return ROLE_UNDEFINED;
d864dd9e
EB
6707}
6708
6709static int peer_role_set_vty(struct vty *vty, const char *ip_str,
8f2d6021 6710 const char *role_str, bool strict_mode)
d864dd9e
EB
6711{
6712 struct peer *peer;
6713
7dddd1f7 6714 peer = peer_and_group_lookup_vty(vty, ip_str);
d864dd9e
EB
6715 if (!peer)
6716 return CMD_WARNING_CONFIG_FAILED;
6717 uint8_t role = get_role_by_name(role_str);
6718
8f2d6021 6719 if (role == ROLE_UNDEFINED)
d864dd9e
EB
6720 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6721 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6722}
6723
6724static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6725{
6726 struct peer *peer;
6727
7dddd1f7 6728 peer = peer_and_group_lookup_vty(vty, ip_str);
d864dd9e
EB
6729 if (!peer)
6730 return CMD_WARNING_CONFIG_FAILED;
6731 return bgp_vty_return(vty, peer_role_unset(peer));
6732}
6733
8f2d6021 6734DEFPY(neighbor_role,
d864dd9e
EB
6735 neighbor_role_cmd,
6736 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6737 NEIGHBOR_STR
6738 NEIGHBOR_ADDR_STR2
6739 "Set session role\n"
6740 ROLE_STR)
6741{
6742 int idx_peer = 1;
6743 int idx_role = 3;
6744
6745 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
8f2d6021 6746 false);
d864dd9e
EB
6747}
6748
8f2d6021 6749DEFPY(neighbor_role_strict,
d864dd9e
EB
6750 neighbor_role_strict_cmd,
6751 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6752 NEIGHBOR_STR
6753 NEIGHBOR_ADDR_STR2
6754 "Set session role\n"
6755 ROLE_STR
6756 "Use additional restriction on peer\n")
6757{
6758 int idx_peer = 1;
6759 int idx_role = 3;
6760
6761 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
8f2d6021 6762 true);
d864dd9e
EB
6763}
6764
8f2d6021 6765DEFPY(no_neighbor_role,
d864dd9e
EB
6766 no_neighbor_role_cmd,
6767 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6768 NO_STR
6769 NEIGHBOR_STR
6770 NEIGHBOR_ADDR_STR2
8f2d6021 6771 "Set session role\n"
d864dd9e 6772 ROLE_STR
8f2d6021 6773 "Use additional restriction on peer\n")
d864dd9e
EB
6774{
6775 int idx_peer = 2;
6776
6777 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6778}
6b0655a2 6779
6ffd2079 6780/* disable-connected-check */
28c6e247
IR
6781DEFUN (neighbor_disable_connected_check,
6782 neighbor_disable_connected_check_cmd,
6783 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6784 NEIGHBOR_STR
6785 NEIGHBOR_ADDR_STR2
6786 "one-hop away EBGP peer using loopback address\n"
6787 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6788{
d62a17ae 6789 int idx_peer = 1;
28c6e247
IR
6790 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6791 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6792}
6793
28c6e247
IR
6794DEFUN (no_neighbor_disable_connected_check,
6795 no_neighbor_disable_connected_check_cmd,
6796 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6797 NO_STR
6798 NEIGHBOR_STR
6799 NEIGHBOR_ADDR_STR2
6800 "one-hop away EBGP peer using loopback address\n"
6801 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6802{
d62a17ae 6803 int idx_peer = 2;
28c6e247
IR
6804 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6805 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6806}
6807
7ab294ea
DA
6808/* disable-link-bw-encoding-ieee */
6809DEFUN(neighbor_disable_link_bw_encoding_ieee,
6810 neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6811 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6812 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6813 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6814{
6815 int idx_peer = 1;
6816
6817 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6818 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6819}
6820
7ab294ea
DA
6821DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6822 no_neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6823 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6824 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6825 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6826{
6827 int idx_peer = 2;
6828
6829 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6830 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6831}
6832
d08c0c80
DA
6833/* extended-optional-parameters */
6834DEFUN(neighbor_extended_optional_parameters,
6835 neighbor_extended_optional_parameters_cmd,
6836 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6837 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6838 "Force the extended optional parameters format for OPEN messages\n")
6839{
6840 int idx_peer = 1;
6841
6842 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6843 PEER_FLAG_EXTENDED_OPT_PARAMS);
6844}
6845
6846DEFUN(no_neighbor_extended_optional_parameters,
6847 no_neighbor_extended_optional_parameters_cmd,
6848 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6849 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6850 "Force the extended optional parameters format for OPEN messages\n")
6851{
6852 int idx_peer = 2;
6853
6854 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6855 PEER_FLAG_EXTENDED_OPT_PARAMS);
6856}
47cbc09b
PM
6857
6858/* enforce-first-as */
28c6e247
IR
6859DEFUN (neighbor_enforce_first_as,
6860 neighbor_enforce_first_as_cmd,
6861 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6862 NEIGHBOR_STR
6863 NEIGHBOR_ADDR_STR2
6864 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6865{
6866 int idx_peer = 1;
f4b8ec07 6867
28c6e247
IR
6868 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6869 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6870}
6871
28c6e247
IR
6872DEFUN (no_neighbor_enforce_first_as,
6873 no_neighbor_enforce_first_as_cmd,
6874 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6875 NO_STR
6876 NEIGHBOR_STR
6877 NEIGHBOR_ADDR_STR2
6878 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6879{
6880 int idx_peer = 2;
f4b8ec07 6881
28c6e247
IR
6882 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6883 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6884}
6885
6886
28c6e247
IR
6887DEFUN (neighbor_description,
6888 neighbor_description_cmd,
6889 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6890 NEIGHBOR_STR
6891 NEIGHBOR_ADDR_STR2
6892 "Neighbor specific description\n"
6893 "Up to 80 characters describing this neighbor\n")
718e3744 6894{
d62a17ae 6895 int idx_peer = 1;
6896 int idx_line = 3;
28c6e247 6897 struct peer *peer;
d62a17ae 6898 char *str;
718e3744 6899
28c6e247
IR
6900 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6901 if (!peer)
d62a17ae 6902 return CMD_WARNING_CONFIG_FAILED;
718e3744 6903
d62a17ae 6904 str = argv_concat(argv, argc, idx_line);
718e3744 6905
28c6e247 6906 peer_description_set(peer, str);
718e3744 6907
d62a17ae 6908 XFREE(MTYPE_TMP, str);
718e3744 6909
28c6e247 6910 return CMD_SUCCESS;
718e3744 6911}
6912
28c6e247
IR
6913DEFUN (no_neighbor_description,
6914 no_neighbor_description_cmd,
6915 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6916 NO_STR
6917 NEIGHBOR_STR
6918 NEIGHBOR_ADDR_STR2
6919 "Neighbor specific description\n")
718e3744 6920{
d62a17ae 6921 int idx_peer = 2;
28c6e247 6922 struct peer *peer;
f4b8ec07 6923
28c6e247
IR
6924 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6925 if (!peer)
d62a17ae 6926 return CMD_WARNING_CONFIG_FAILED;
718e3744 6927
28c6e247 6928 peer_description_unset(peer);
718e3744 6929
28c6e247 6930 return CMD_SUCCESS;
718e3744 6931}
6932
1d80f243 6933ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
6934 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6935 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6936 "Neighbor specific description\n"
6937 "Up to 80 characters describing this neighbor\n")
6b0655a2 6938
28c6e247
IR
6939/* Neighbor update-source. */
6940static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6941 const char *source_str)
6942{
6943 struct peer *peer;
6944 struct prefix p;
6945 union sockunion su;
6946
6947 peer = peer_and_group_lookup_vty(vty, peer_str);
6948 if (!peer)
6949 return CMD_WARNING_CONFIG_FAILED;
6950
6951 if (peer->conf_if)
6952 return CMD_WARNING;
6953
6954 if (source_str) {
6955 if (str2sockunion(source_str, &su) == 0)
6956 peer_update_source_addr_set(peer, &su);
6957 else {
6958 if (str2prefix(source_str, &p)) {
6959 vty_out(vty,
6960 "%% Invalid update-source, remove prefix length \n");
6961 return CMD_WARNING_CONFIG_FAILED;
6962 } else
6963 peer_update_source_if_set(peer, source_str);
6964 }
6965 } else
6966 peer_update_source_unset(peer);
6967
6968 return CMD_SUCCESS;
6969}
6970
d62a17ae 6971#define BGP_UPDATE_SOURCE_HELP_STR \
6972 "IPv4 address\n" \
6973 "IPv6 address\n" \
6974 "Interface name (requires zebra to be running)\n"
369688c0 6975
28c6e247
IR
6976DEFUN (neighbor_update_source,
6977 neighbor_update_source_cmd,
6978 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6979 NEIGHBOR_STR
6980 NEIGHBOR_ADDR_STR2
6981 "Source of routing updates\n"
6982 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6983{
d62a17ae 6984 int idx_peer = 1;
6985 int idx_peer_2 = 3;
28c6e247 6986 return peer_update_source_vty(vty, argv[idx_peer]->arg,
d62a17ae 6987 argv[idx_peer_2]->arg);
718e3744 6988}
6989
28c6e247
IR
6990DEFUN (no_neighbor_update_source,
6991 no_neighbor_update_source_cmd,
6992 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6993 NO_STR
6994 NEIGHBOR_STR
6995 NEIGHBOR_ADDR_STR2
6996 "Source of routing updates\n"
6997 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6998{
d62a17ae 6999 int idx_peer = 2;
28c6e247 7000 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 7001}
6b0655a2 7002
d62a17ae 7003static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
7004 afi_t afi, safi_t safi,
7005 const char *rmap, int set)
718e3744 7006{
d62a17ae 7007 int ret;
7008 struct peer *peer;
80912664 7009 struct route_map *route_map = NULL;
718e3744 7010
d62a17ae 7011 peer = peer_and_group_lookup_vty(vty, peer_str);
7012 if (!peer)
7013 return CMD_WARNING_CONFIG_FAILED;
718e3744 7014
1de27621 7015 if (set) {
80912664
DS
7016 if (rmap)
7017 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
7018 ret = peer_default_originate_set(peer, afi, safi,
7019 rmap, route_map);
7020 } else
d62a17ae 7021 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 7022
d62a17ae 7023 return bgp_vty_return(vty, ret);
718e3744 7024}
7025
7026/* neighbor default-originate. */
7027DEFUN (neighbor_default_originate,
7028 neighbor_default_originate_cmd,
9ccf14f7 7029 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 7030 NEIGHBOR_STR
7031 NEIGHBOR_ADDR_STR2
7032 "Originate default route to this neighbor\n")
7033{
d62a17ae 7034 int idx_peer = 1;
7035 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7036 bgp_node_afi(vty),
7037 bgp_node_safi(vty), NULL, 1);
718e3744 7038}
7039
d62a17ae 7040ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7041 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7042 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7043 "Originate default route to this neighbor\n")
596c17ba 7044
718e3744 7045DEFUN (neighbor_default_originate_rmap,
7046 neighbor_default_originate_rmap_cmd,
70dd370f 7047 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
718e3744 7048 NEIGHBOR_STR
7049 NEIGHBOR_ADDR_STR2
7050 "Originate default route to this neighbor\n"
7051 "Route-map to specify criteria to originate default\n"
7052 "route-map name\n")
7053{
d62a17ae 7054 int idx_peer = 1;
7055 int idx_word = 4;
7056 return peer_default_originate_set_vty(
7057 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7058 argv[idx_word]->arg, 1);
718e3744 7059}
7060
d62a17ae 7061ALIAS_HIDDEN(
7062 neighbor_default_originate_rmap,
7063 neighbor_default_originate_rmap_hidden_cmd,
70dd370f 7064 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
d62a17ae 7065 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7066 "Originate default route to this neighbor\n"
7067 "Route-map to specify criteria to originate default\n"
7068 "route-map name\n")
596c17ba 7069
718e3744 7070DEFUN (no_neighbor_default_originate,
7071 no_neighbor_default_originate_cmd,
70dd370f 7072 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
718e3744 7073 NO_STR
7074 NEIGHBOR_STR
7075 NEIGHBOR_ADDR_STR2
a636c635
DW
7076 "Originate default route to this neighbor\n"
7077 "Route-map to specify criteria to originate default\n"
7078 "route-map name\n")
718e3744 7079{
d62a17ae 7080 int idx_peer = 2;
7081 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7082 bgp_node_afi(vty),
7083 bgp_node_safi(vty), NULL, 0);
718e3744 7084}
7085
d62a17ae 7086ALIAS_HIDDEN(
7087 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
70dd370f 7088 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
d62a17ae 7089 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7090 "Originate default route to this neighbor\n"
7091 "Route-map to specify criteria to originate default\n"
7092 "route-map name\n")
596c17ba 7093
6b0655a2 7094
28c6e247
IR
7095/* Set neighbor's BGP port. */
7096static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
7097 const char *port_str)
718e3744 7098{
28c6e247
IR
7099 struct peer *peer;
7100 uint16_t port;
7101 struct servent *sp;
7102
a3aecc99 7103 peer = peer_and_group_lookup_vty(vty, ip_str);
28c6e247
IR
7104 if (!peer)
7105 return CMD_WARNING_CONFIG_FAILED;
7106
7107 if (!port_str) {
7108 sp = getservbyname("bgp", "tcp");
7109 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
7110 } else {
7111 port = strtoul(port_str, NULL, 10);
7112 }
718e3744 7113
28c6e247 7114 peer_port_set(peer, port);
718e3744 7115
28c6e247
IR
7116 return CMD_SUCCESS;
7117}
f4b8ec07 7118
28c6e247
IR
7119/* Set specified peer's BGP port. */
7120DEFUN (neighbor_port,
7121 neighbor_port_cmd,
a3aecc99 7122 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
28c6e247 7123 NEIGHBOR_STR
a3aecc99 7124 NEIGHBOR_ADDR_STR2
28c6e247
IR
7125 "Neighbor's BGP port\n"
7126 "TCP port number\n")
7127{
7128 int idx_ip = 1;
7129 int idx_number = 3;
7130 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
7131 argv[idx_number]->arg);
f4b8ec07 7132}
6b0655a2 7133
28c6e247
IR
7134DEFUN (no_neighbor_port,
7135 no_neighbor_port_cmd,
a3aecc99 7136 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
28c6e247
IR
7137 NO_STR
7138 NEIGHBOR_STR
a3aecc99 7139 NEIGHBOR_ADDR_STR2
28c6e247
IR
7140 "Neighbor's BGP port\n"
7141 "TCP port number\n")
718e3744 7142{
f4b8ec07 7143 int idx_ip = 2;
28c6e247
IR
7144 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
7145}
7146
7147
7148/* neighbor weight. */
7149static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7150 safi_t safi, const char *weight_str)
7151{
7152 int ret;
7153 struct peer *peer;
7154 unsigned long weight;
718e3744 7155
28c6e247
IR
7156 peer = peer_and_group_lookup_vty(vty, ip_str);
7157 if (!peer)
7158 return CMD_WARNING_CONFIG_FAILED;
718e3744 7159
28c6e247 7160 weight = strtoul(weight_str, NULL, 10);
718e3744 7161
28c6e247
IR
7162 ret = peer_weight_set(peer, afi, safi, weight);
7163 return bgp_vty_return(vty, ret);
718e3744 7164}
7165
28c6e247
IR
7166static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7167 safi_t safi)
718e3744 7168{
28c6e247
IR
7169 int ret;
7170 struct peer *peer;
f4b8ec07 7171
28c6e247
IR
7172 peer = peer_and_group_lookup_vty(vty, ip_str);
7173 if (!peer)
d62a17ae 7174 return CMD_WARNING_CONFIG_FAILED;
718e3744 7175
28c6e247
IR
7176 ret = peer_weight_unset(peer, afi, safi);
7177 return bgp_vty_return(vty, ret);
7178}
f4b8ec07 7179
28c6e247
IR
7180DEFUN (neighbor_weight,
7181 neighbor_weight_cmd,
7182 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7183 NEIGHBOR_STR
7184 NEIGHBOR_ADDR_STR2
7185 "Set default weight for routes from this neighbor\n"
7186 "default weight\n")
7187{
7188 int idx_peer = 1;
7189 int idx_number = 3;
7190 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7191 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 7192}
7193
d62a17ae 7194ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7195 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7196 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7197 "Set default weight for routes from this neighbor\n"
7198 "default weight\n")
596c17ba 7199
28c6e247
IR
7200DEFUN (no_neighbor_weight,
7201 no_neighbor_weight_cmd,
7202 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7203 NO_STR
7204 NEIGHBOR_STR
7205 NEIGHBOR_ADDR_STR2
7206 "Set default weight for routes from this neighbor\n"
7207 "default weight\n")
718e3744 7208{
d62a17ae 7209 int idx_peer = 2;
28c6e247
IR
7210 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7211 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 7212}
7213
d62a17ae 7214ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7215 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7216 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7217 "Set default weight for routes from this neighbor\n"
7218 "default weight\n")
596c17ba 7219
6b0655a2 7220
718e3744 7221/* Override capability negotiation. */
c36bc05f
IR
7222DEFUN (neighbor_override_capability,
7223 neighbor_override_capability_cmd,
7224 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7225 NEIGHBOR_STR
7226 NEIGHBOR_ADDR_STR2
7227 "Override capability negotiation result\n")
718e3744 7228{
d62a17ae 7229 int idx_peer = 1;
c36bc05f
IR
7230 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7231 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 7232}
7233
c36bc05f
IR
7234DEFUN (no_neighbor_override_capability,
7235 no_neighbor_override_capability_cmd,
7236 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7237 NO_STR
7238 NEIGHBOR_STR
7239 NEIGHBOR_ADDR_STR2
7240 "Override capability negotiation result\n")
718e3744 7241{
d62a17ae 7242 int idx_peer = 2;
c36bc05f
IR
7243 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7244 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 7245}
6b0655a2 7246
c36bc05f
IR
7247DEFUN (neighbor_strict_capability,
7248 neighbor_strict_capability_cmd,
7249 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7250 NEIGHBOR_STR
7251 NEIGHBOR_ADDR_STR2
7252 "Strict capability negotiation match\n")
718e3744 7253{
9fb964de
PM
7254 int idx_peer = 1;
7255
c36bc05f
IR
7256 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7257 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 7258}
7259
c36bc05f
IR
7260DEFUN (no_neighbor_strict_capability,
7261 no_neighbor_strict_capability_cmd,
7262 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7263 NO_STR
7264 NEIGHBOR_STR
7265 NEIGHBOR_ADDR_STR2
7266 "Strict capability negotiation match\n")
718e3744 7267{
9fb964de 7268 int idx_peer = 2;
8611c7f3 7269
c36bc05f
IR
7270 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7271 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 7272}
6b0655a2 7273
28c6e247
IR
7274static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7275 const char *keep_str, const char *hold_str)
718e3744 7276{
28c6e247
IR
7277 int ret;
7278 struct peer *peer;
7279 uint32_t keepalive;
7280 uint32_t holdtime;
718e3744 7281
28c6e247
IR
7282 peer = peer_and_group_lookup_vty(vty, ip_str);
7283 if (!peer)
d62a17ae 7284 return CMD_WARNING_CONFIG_FAILED;
718e3744 7285
28c6e247
IR
7286 keepalive = strtoul(keep_str, NULL, 10);
7287 holdtime = strtoul(hold_str, NULL, 10);
718e3744 7288
28c6e247 7289 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 7290
28c6e247 7291 return bgp_vty_return(vty, ret);
718e3744 7292}
6b0655a2 7293
28c6e247 7294static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 7295{
28c6e247
IR
7296 int ret;
7297 struct peer *peer;
718e3744 7298
28c6e247
IR
7299 peer = peer_and_group_lookup_vty(vty, ip_str);
7300 if (!peer)
d62a17ae 7301 return CMD_WARNING_CONFIG_FAILED;
718e3744 7302
28c6e247 7303 ret = peer_timers_unset(peer);
718e3744 7304
28c6e247 7305 return bgp_vty_return(vty, ret);
718e3744 7306}
6b0655a2 7307
28c6e247
IR
7308DEFUN (neighbor_timers,
7309 neighbor_timers_cmd,
7310 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7311 NEIGHBOR_STR
7312 NEIGHBOR_ADDR_STR2
7313 "BGP per neighbor timers\n"
7314 "Keepalive interval\n"
7315 "Holdtime\n")
718e3744 7316{
f4b8ec07 7317 int idx_peer = 1;
28c6e247
IR
7318 int idx_number = 3;
7319 int idx_number_2 = 4;
7320 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7321 argv[idx_number]->arg,
7322 argv[idx_number_2]->arg);
7323}
7324
7325DEFUN (no_neighbor_timers,
7326 no_neighbor_timers_cmd,
7327 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7328 NO_STR
7329 NEIGHBOR_STR
7330 NEIGHBOR_ADDR_STR2
7331 "BGP per neighbor timers\n"
7332 "Keepalive interval\n"
7333 "Holdtime\n")
7334{
7335 int idx_peer = 2;
7336 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7337}
7338
7339
7340static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7341 const char *time_str)
7342{
7343 int ret;
7344 struct peer *peer;
7345 uint32_t connect;
718e3744 7346
28c6e247
IR
7347 peer = peer_and_group_lookup_vty(vty, ip_str);
7348 if (!peer)
d62a17ae 7349 return CMD_WARNING_CONFIG_FAILED;
718e3744 7350
28c6e247
IR
7351 connect = strtoul(time_str, NULL, 10);
7352
7353 ret = peer_timers_connect_set(peer, connect);
718e3744 7354
28c6e247 7355 return bgp_vty_return(vty, ret);
718e3744 7356}
7357
28c6e247 7358static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 7359{
28c6e247
IR
7360 int ret;
7361 struct peer *peer;
718e3744 7362
28c6e247
IR
7363 peer = peer_and_group_lookup_vty(vty, ip_str);
7364 if (!peer)
d62a17ae 7365 return CMD_WARNING_CONFIG_FAILED;
718e3744 7366
28c6e247
IR
7367 ret = peer_timers_connect_unset(peer);
7368
7369 return bgp_vty_return(vty, ret);
7370}
7371
7372DEFUN (neighbor_timers_connect,
7373 neighbor_timers_connect_cmd,
7374 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7375 NEIGHBOR_STR
7376 NEIGHBOR_ADDR_STR2
7377 "BGP per neighbor timers\n"
7378 "BGP connect timer\n"
7379 "Connect timer\n")
7380{
7381 int idx_peer = 1;
7382 int idx_number = 4;
7383 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7384 argv[idx_number]->arg);
7385}
718e3744 7386
28c6e247
IR
7387DEFUN (no_neighbor_timers_connect,
7388 no_neighbor_timers_connect_cmd,
7389 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7390 NO_STR
7391 NEIGHBOR_STR
7392 NEIGHBOR_ADDR_STR2
7393 "BGP per neighbor timers\n"
7394 "BGP connect timer\n"
7395 "Connect timer\n")
7396{
7397 int idx_peer = 2;
7398 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 7399}
7400
d43114f3
DS
7401DEFPY (neighbor_timers_delayopen,
7402 neighbor_timers_delayopen_cmd,
7403 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7404 NEIGHBOR_STR
7405 NEIGHBOR_ADDR_STR2
7406 "BGP per neighbor timers\n"
7407 "RFC 4271 DelayOpenTimer\n"
7408 "DelayOpenTime timer interval\n")
7409{
7410 struct peer *peer;
7411
7412 peer = peer_and_group_lookup_vty(vty, neighbor);
7413 if (!peer)
7414 return CMD_WARNING_CONFIG_FAILED;
7415
7416 if (!interval) {
7417 if (peer_timers_delayopen_unset(peer))
7418 return CMD_WARNING_CONFIG_FAILED;
7419 } else {
7420 if (peer_timers_delayopen_set(peer, interval))
7421 return CMD_WARNING_CONFIG_FAILED;
7422 }
7423
7424 return CMD_SUCCESS;
7425}
7426
7427DEFPY (no_neighbor_timers_delayopen,
7428 no_neighbor_timers_delayopen_cmd,
7429 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7430 NO_STR
7431 NEIGHBOR_STR
7432 NEIGHBOR_ADDR_STR2
7433 "BGP per neighbor timers\n"
7434 "RFC 4271 DelayOpenTimer\n"
7435 "DelayOpenTime timer interval\n")
7436{
7437 struct peer *peer;
7438
7439 peer = peer_and_group_lookup_vty(vty, neighbor);
7440 if (!peer)
7441 return CMD_WARNING_CONFIG_FAILED;
7442
7443 if (peer_timers_delayopen_unset(peer))
7444 return CMD_WARNING_CONFIG_FAILED;
7445
7446 return CMD_SUCCESS;
7447}
7448
28c6e247
IR
7449static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7450 const char *time_str, int set)
718e3744 7451{
28c6e247
IR
7452 int ret;
7453 struct peer *peer;
7454 uint32_t routeadv = 0;
718e3744 7455
28c6e247
IR
7456 peer = peer_and_group_lookup_vty(vty, ip_str);
7457 if (!peer)
d62a17ae 7458 return CMD_WARNING_CONFIG_FAILED;
718e3744 7459
28c6e247
IR
7460 if (time_str)
7461 routeadv = strtoul(time_str, NULL, 10);
7462
7463 if (set)
7464 ret = peer_advertise_interval_set(peer, routeadv);
7465 else
7466 ret = peer_advertise_interval_unset(peer);
718e3744 7467
28c6e247 7468 return bgp_vty_return(vty, ret);
718e3744 7469}
7470
28c6e247
IR
7471DEFUN (neighbor_advertise_interval,
7472 neighbor_advertise_interval_cmd,
7473 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7474 NEIGHBOR_STR
7475 NEIGHBOR_ADDR_STR2
7476 "Minimum interval between sending BGP routing updates\n"
7477 "time in seconds\n")
718e3744 7478{
28c6e247
IR
7479 int idx_peer = 1;
7480 int idx_number = 3;
7481 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7482 argv[idx_number]->arg, 1);
7483}
f4b8ec07 7484
28c6e247
IR
7485DEFUN (no_neighbor_advertise_interval,
7486 no_neighbor_advertise_interval_cmd,
7487 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7488 NO_STR
7489 NEIGHBOR_STR
7490 NEIGHBOR_ADDR_STR2
7491 "Minimum interval between sending BGP routing updates\n"
7492 "time in seconds\n")
7493{
7494 int idx_peer = 2;
7495 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 7496}
7497
6b0655a2 7498
518f0eb1
DS
7499/* Time to wait before processing route-map updates */
7500DEFUN (bgp_set_route_map_delay_timer,
7501 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7502 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7503 SET_STR
7504 "BGP route-map delay timer\n"
7505 "Time in secs to wait before processing route-map changes\n"
f414725f 7506 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7507{
d62a17ae 7508 int idx_number = 3;
d7c0a89a 7509 uint32_t rmap_delay_timer;
d62a17ae 7510
7511 if (argv[idx_number]->arg) {
7512 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7513 bm->rmap_update_timer = rmap_delay_timer;
7514
7515 /* if the dynamic update handling is being disabled, and a timer
7516 * is
7517 * running, stop the timer and act as if the timer has already
7518 * fired.
7519 */
7520 if (!rmap_delay_timer && bm->t_rmap_update) {
fa5806c3 7521 THREAD_OFF(bm->t_rmap_update);
d62a17ae 7522 thread_execute(bm->master, bgp_route_map_update_timer,
7523 NULL, 0);
7524 }
7525 return CMD_SUCCESS;
7526 } else {
7527 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7528 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7529 }
518f0eb1
DS
7530}
7531
7532DEFUN (no_bgp_set_route_map_delay_timer,
7533 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7534 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7535 NO_STR
3a2d747c 7536 BGP_STR
518f0eb1 7537 "Default BGP route-map delay timer\n"
8334fd5a
DW
7538 "Reset to default time to wait for processing route-map changes\n"
7539 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7540{
518f0eb1 7541
d62a17ae 7542 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7543
d62a17ae 7544 return CMD_SUCCESS;
518f0eb1
DS
7545}
7546
28c6e247
IR
7547/* neighbor interface */
7548static int peer_interface_vty(struct vty *vty, const char *ip_str,
7549 const char *str)
718e3744 7550{
28c6e247 7551 struct peer *peer;
718e3744 7552
28c6e247
IR
7553 peer = peer_lookup_vty(vty, ip_str);
7554 if (!peer || peer->conf_if) {
7555 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7556 return CMD_WARNING_CONFIG_FAILED;
7557 }
718e3744 7558
28c6e247
IR
7559 if (str)
7560 peer_interface_set(peer, str);
7561 else
7562 peer_interface_unset(peer);
718e3744 7563
28c6e247 7564 return CMD_SUCCESS;
718e3744 7565}
7566
28c6e247
IR
7567DEFUN (neighbor_interface,
7568 neighbor_interface_cmd,
7569 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7570 NEIGHBOR_STR
7571 NEIGHBOR_ADDR_STR
7572 "Interface\n"
7573 "Interface name\n")
718e3744 7574{
28c6e247
IR
7575 int idx_ip = 1;
7576 int idx_word = 3;
294d8425 7577
28c6e247
IR
7578 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7579}
f4b8ec07 7580
28c6e247
IR
7581DEFUN (no_neighbor_interface,
7582 no_neighbor_interface_cmd,
294d8425 7583 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
28c6e247
IR
7584 NO_STR
7585 NEIGHBOR_STR
294d8425 7586 NEIGHBOR_ADDR_STR
28c6e247
IR
7587 "Interface\n"
7588 "Interface name\n")
7589{
7590 int idx_peer = 2;
294d8425 7591
28c6e247 7592 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 7593}
6b0655a2 7594
718e3744 7595DEFUN (neighbor_distribute_list,
7596 neighbor_distribute_list_cmd,
c60dec36 7597 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7598 NEIGHBOR_STR
7599 NEIGHBOR_ADDR_STR2
7600 "Filter updates to/from this neighbor\n"
718e3744 7601 "IP Access-list name\n"
7602 "Filter incoming updates\n"
7603 "Filter outgoing updates\n")
7604{
d62a17ae 7605 int idx_peer = 1;
7606 int idx_acl = 3;
7607 int direct, ret;
7608 struct peer *peer;
a8206004 7609
d62a17ae 7610 const char *pstr = argv[idx_peer]->arg;
7611 const char *acl = argv[idx_acl]->arg;
7612 const char *inout = argv[argc - 1]->text;
a8206004 7613
d62a17ae 7614 peer = peer_and_group_lookup_vty(vty, pstr);
7615 if (!peer)
7616 return CMD_WARNING_CONFIG_FAILED;
a8206004 7617
d62a17ae 7618 /* Check filter direction. */
7619 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7620 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7621 direct, acl);
a8206004 7622
d62a17ae 7623 return bgp_vty_return(vty, ret);
718e3744 7624}
7625
d62a17ae 7626ALIAS_HIDDEN(
7627 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
c60dec36 7628 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7629 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7630 "Filter updates to/from this neighbor\n"
d62a17ae 7631 "IP Access-list name\n"
7632 "Filter incoming updates\n"
7633 "Filter outgoing updates\n")
596c17ba 7634
718e3744 7635DEFUN (no_neighbor_distribute_list,
7636 no_neighbor_distribute_list_cmd,
c60dec36 7637 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7638 NO_STR
7639 NEIGHBOR_STR
7640 NEIGHBOR_ADDR_STR2
7641 "Filter updates to/from this neighbor\n"
718e3744 7642 "IP Access-list name\n"
7643 "Filter incoming updates\n"
7644 "Filter outgoing updates\n")
7645{
d62a17ae 7646 int idx_peer = 2;
7647 int direct, ret;
7648 struct peer *peer;
a8206004 7649
d62a17ae 7650 const char *pstr = argv[idx_peer]->arg;
7651 const char *inout = argv[argc - 1]->text;
a8206004 7652
d62a17ae 7653 peer = peer_and_group_lookup_vty(vty, pstr);
7654 if (!peer)
7655 return CMD_WARNING_CONFIG_FAILED;
a8206004 7656
d62a17ae 7657 /* Check filter direction. */
7658 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7659 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7660 direct);
a8206004 7661
d62a17ae 7662 return bgp_vty_return(vty, ret);
718e3744 7663}
6b0655a2 7664
d62a17ae 7665ALIAS_HIDDEN(
7666 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
c60dec36 7667 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7668 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7669 "Filter updates to/from this neighbor\n"
d62a17ae 7670 "IP Access-list name\n"
7671 "Filter incoming updates\n"
7672 "Filter outgoing updates\n")
596c17ba 7673
718e3744 7674/* Set prefix list to the peer. */
642ef664
IR
7675static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7676 afi_t afi, safi_t safi,
7677 const char *name_str,
7678 const char *direct_str)
718e3744 7679{
642ef664
IR
7680 int ret;
7681 int direct = FILTER_IN;
7682 struct peer *peer;
718e3744 7683
642ef664
IR
7684 peer = peer_and_group_lookup_vty(vty, ip_str);
7685 if (!peer)
d62a17ae 7686 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7687
642ef664
IR
7688 /* Check filter direction. */
7689 if (strncmp(direct_str, "i", 1) == 0)
7690 direct = FILTER_IN;
7691 else if (strncmp(direct_str, "o", 1) == 0)
7692 direct = FILTER_OUT;
718e3744 7693
642ef664 7694 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 7695
642ef664
IR
7696 return bgp_vty_return(vty, ret);
7697}
7698
7699static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7700 afi_t afi, safi_t safi,
7701 const char *direct_str)
7702{
7703 int ret;
7704 struct peer *peer;
7705 int direct = FILTER_IN;
7706
7707 peer = peer_and_group_lookup_vty(vty, ip_str);
7708 if (!peer)
7709 return CMD_WARNING_CONFIG_FAILED;
7710
7711 /* Check filter direction. */
7712 if (strncmp(direct_str, "i", 1) == 0)
7713 direct = FILTER_IN;
7714 else if (strncmp(direct_str, "o", 1) == 0)
7715 direct = FILTER_OUT;
7716
7717 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7718
7719 return bgp_vty_return(vty, ret);
7720}
7721
7722DEFUN (neighbor_prefix_list,
7723 neighbor_prefix_list_cmd,
7724 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7725 NEIGHBOR_STR
7726 NEIGHBOR_ADDR_STR2
7727 "Filter updates to/from this neighbor\n"
7728 "Name of a prefix list\n"
7729 "Filter incoming updates\n"
7730 "Filter outgoing updates\n")
7731{
7732 int idx_peer = 1;
7733 int idx_word = 3;
7734 int idx_in_out = 4;
7735 return peer_prefix_list_set_vty(
7736 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7737 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7738}
7739
d62a17ae 7740ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7741 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7742 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7743 "Filter updates to/from this neighbor\n"
7744 "Name of a prefix list\n"
7745 "Filter incoming updates\n"
7746 "Filter outgoing updates\n")
596c17ba 7747
642ef664
IR
7748DEFUN (no_neighbor_prefix_list,
7749 no_neighbor_prefix_list_cmd,
7750 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7751 NO_STR
7752 NEIGHBOR_STR
7753 NEIGHBOR_ADDR_STR2
7754 "Filter updates to/from this neighbor\n"
7755 "Name of a prefix list\n"
7756 "Filter incoming updates\n"
7757 "Filter outgoing updates\n")
7758{
7759 int idx_peer = 2;
7760 int idx_in_out = 5;
7761 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7762 bgp_node_afi(vty), bgp_node_safi(vty),
7763 argv[idx_in_out]->arg);
7764}
7765
7766ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7767 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7768 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7769 "Filter updates to/from this neighbor\n"
7770 "Name of a prefix list\n"
7771 "Filter incoming updates\n"
7772 "Filter outgoing updates\n")
7773
d62a17ae 7774static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7775 safi_t safi, const char *name_str,
7776 const char *direct_str)
718e3744 7777{
d62a17ae 7778 int ret;
7779 struct peer *peer;
7780 int direct = FILTER_IN;
718e3744 7781
d62a17ae 7782 peer = peer_and_group_lookup_vty(vty, ip_str);
7783 if (!peer)
7784 return CMD_WARNING_CONFIG_FAILED;
718e3744 7785
d62a17ae 7786 /* Check filter direction. */
7787 if (strncmp(direct_str, "i", 1) == 0)
7788 direct = FILTER_IN;
7789 else if (strncmp(direct_str, "o", 1) == 0)
7790 direct = FILTER_OUT;
718e3744 7791
d62a17ae 7792 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7793
d62a17ae 7794 return bgp_vty_return(vty, ret);
718e3744 7795}
7796
d62a17ae 7797static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7798 safi_t safi, const char *direct_str)
718e3744 7799{
d62a17ae 7800 int ret;
7801 struct peer *peer;
7802 int direct = FILTER_IN;
718e3744 7803
d62a17ae 7804 peer = peer_and_group_lookup_vty(vty, ip_str);
7805 if (!peer)
7806 return CMD_WARNING_CONFIG_FAILED;
718e3744 7807
d62a17ae 7808 /* Check filter direction. */
7809 if (strncmp(direct_str, "i", 1) == 0)
7810 direct = FILTER_IN;
7811 else if (strncmp(direct_str, "o", 1) == 0)
7812 direct = FILTER_OUT;
718e3744 7813
d62a17ae 7814 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7815
d62a17ae 7816 return bgp_vty_return(vty, ret);
718e3744 7817}
7818
7819DEFUN (neighbor_filter_list,
7820 neighbor_filter_list_cmd,
de71d43e 7821 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7822 NEIGHBOR_STR
7823 NEIGHBOR_ADDR_STR2
7824 "Establish BGP filters\n"
7825 "AS path access-list name\n"
7826 "Filter incoming routes\n"
7827 "Filter outgoing routes\n")
7828{
d62a17ae 7829 int idx_peer = 1;
7830 int idx_word = 3;
7831 int idx_in_out = 4;
7832 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7833 bgp_node_safi(vty), argv[idx_word]->arg,
7834 argv[idx_in_out]->arg);
718e3744 7835}
7836
d62a17ae 7837ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
de71d43e 7838 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7839 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7840 "Establish BGP filters\n"
7841 "AS path access-list name\n"
7842 "Filter incoming routes\n"
7843 "Filter outgoing routes\n")
596c17ba 7844
718e3744 7845DEFUN (no_neighbor_filter_list,
7846 no_neighbor_filter_list_cmd,
de71d43e 7847 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7848 NO_STR
7849 NEIGHBOR_STR
7850 NEIGHBOR_ADDR_STR2
7851 "Establish BGP filters\n"
7852 "AS path access-list name\n"
7853 "Filter incoming routes\n"
7854 "Filter outgoing routes\n")
7855{
d62a17ae 7856 int idx_peer = 2;
7857 int idx_in_out = 5;
7858 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7859 bgp_node_afi(vty), bgp_node_safi(vty),
7860 argv[idx_in_out]->arg);
718e3744 7861}
6b0655a2 7862
d62a17ae 7863ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
de71d43e 7864 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7865 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7866 "Establish BGP filters\n"
7867 "AS path access-list name\n"
7868 "Filter incoming routes\n"
7869 "Filter outgoing routes\n")
596c17ba 7870
7f7940e6
MK
7871/* Set advertise-map to the peer. */
7872static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7873 afi_t afi, safi_t safi,
cf2ad4d8
MK
7874 const char *advertise_str,
7875 const char *condition_str, bool condition,
7876 bool set)
7f7940e6
MK
7877{
7878 int ret = CMD_WARNING_CONFIG_FAILED;
7879 struct peer *peer;
7880 struct route_map *advertise_map;
7881 struct route_map *condition_map;
7882
7883 peer = peer_and_group_lookup_vty(vty, ip_str);
7884 if (!peer)
7885 return ret;
7886
7887 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7888 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7889
cf2ad4d8
MK
7890 if (set)
7891 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7892 advertise_map, condition_str,
7893 condition_map, condition);
7894 else
7895 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7896 advertise_map, condition_str,
7897 condition_map, condition);
7f7940e6
MK
7898
7899 return bgp_vty_return(vty, ret);
7900}
7901
389e4f92
QY
7902DEFPY (bgp_condadv_period,
7903 bgp_condadv_period_cmd,
7904 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7905 NO_STR
7906 BGP_STR
7907 "Conditional advertisement settings\n"
7908 "Set period to rescan BGP table to check if condition is met\n"
7909 "Period between BGP table scans, in seconds; default 60\n")
7910{
7911 VTY_DECLVAR_CONTEXT(bgp, bgp);
7912
7913 bgp->condition_check_period =
7914 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7915
7916 return CMD_SUCCESS;
7917}
7918
cf2ad4d8 7919DEFPY (neighbor_advertise_map,
7f7940e6 7920 neighbor_advertise_map_cmd,
3ccddc25 7921 "[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 7922 NO_STR
7f7940e6
MK
7923 NEIGHBOR_STR
7924 NEIGHBOR_ADDR_STR2
7925 "Route-map to conditionally advertise routes\n"
7926 "Name of advertise map\n"
7927 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7928 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7929 "Name of the exist or non exist map\n")
7f7940e6 7930{
7f7940e6
MK
7931 bool condition = CONDITION_EXIST;
7932
52b84062 7933 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7934 condition = CONDITION_NON_EXIST;
7935
52b84062
MK
7936 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7937 bgp_node_safi(vty), advertise_str,
7938 condition_str, condition, !no);
7f7940e6
MK
7939}
7940
7941ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
3ccddc25 7942 "[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
7943 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7944 "Route-map to conditionally advertise routes\n"
7945 "Name of advertise map\n"
7946 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7947 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7948 "Name of the exist or non exist map\n")
7f7940e6 7949
718e3744 7950/* Set route-map to the peer. */
0ea8d871
IR
7951static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7952 afi_t afi, safi_t safi, const char *name_str,
7953 const char *direct_str)
718e3744 7954{
0ea8d871
IR
7955 int ret;
7956 struct peer *peer;
7957 int direct = RMAP_IN;
7958 struct route_map *route_map;
718e3744 7959
0ea8d871
IR
7960 peer = peer_and_group_lookup_vty(vty, ip_str);
7961 if (!peer)
d62a17ae 7962 return CMD_WARNING_CONFIG_FAILED;
718e3744 7963
0ea8d871
IR
7964 /* Check filter direction. */
7965 if (strncmp(direct_str, "in", 2) == 0)
7966 direct = RMAP_IN;
7967 else if (strncmp(direct_str, "o", 1) == 0)
7968 direct = RMAP_OUT;
718e3744 7969
0ea8d871
IR
7970 route_map = route_map_lookup_warn_noexist(vty, name_str);
7971 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7972
0ea8d871
IR
7973 return bgp_vty_return(vty, ret);
7974}
7975
7976static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7977 afi_t afi, safi_t safi,
7978 const char *direct_str)
7979{
7980 int ret;
7981 struct peer *peer;
7982 int direct = RMAP_IN;
7983
7984 peer = peer_and_group_lookup_vty(vty, ip_str);
7985 if (!peer)
7986 return CMD_WARNING_CONFIG_FAILED;
7987
7988 /* Check filter direction. */
7989 if (strncmp(direct_str, "in", 2) == 0)
7990 direct = RMAP_IN;
7991 else if (strncmp(direct_str, "o", 1) == 0)
7992 direct = RMAP_OUT;
7993
7994 ret = peer_route_map_unset(peer, afi, safi, direct);
7995
7996 return bgp_vty_return(vty, ret);
7997}
7998
7999DEFUN (neighbor_route_map,
8000 neighbor_route_map_cmd,
70dd370f 8001 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
0ea8d871
IR
8002 NEIGHBOR_STR
8003 NEIGHBOR_ADDR_STR2
8004 "Apply route map to neighbor\n"
8005 "Name of route map\n"
8006 "Apply map to incoming routes\n"
8007 "Apply map to outbound routes\n")
8008{
8009 int idx_peer = 1;
8010 int idx_word = 3;
8011 int idx_in_out = 4;
8012 return peer_route_map_set_vty(
8013 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8014 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 8015}
8016
d6d7ed37 8017ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
70dd370f 8018 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
d6d7ed37
IR
8019 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8020 "Apply route map to neighbor\n"
8021 "Name of route map\n"
8022 "Apply map to incoming routes\n"
8023 "Apply map to outbound routes\n")
8024
0ea8d871
IR
8025DEFUN (no_neighbor_route_map,
8026 no_neighbor_route_map_cmd,
70dd370f 8027 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
0ea8d871
IR
8028 NO_STR
8029 NEIGHBOR_STR
8030 NEIGHBOR_ADDR_STR2
8031 "Apply route map to neighbor\n"
8032 "Name of route map\n"
8033 "Apply map to incoming routes\n"
8034 "Apply map to outbound routes\n")
8035{
8036 int idx_peer = 2;
8037 int idx_in_out = 5;
8038 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
8039 bgp_node_afi(vty), bgp_node_safi(vty),
8040 argv[idx_in_out]->arg);
8041}
8042
8043ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
70dd370f 8044 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
d6d7ed37
IR
8045 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8046 "Apply route map to neighbor\n"
8047 "Name of route map\n"
8048 "Apply map to incoming routes\n"
8049 "Apply map to outbound routes\n")
8050
718e3744 8051/* Set unsuppress-map to the peer. */
d62a17ae 8052static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8053 afi_t afi, safi_t safi,
8054 const char *name_str)
718e3744 8055{
d62a17ae 8056 int ret;
8057 struct peer *peer;
1de27621 8058 struct route_map *route_map;
718e3744 8059
d62a17ae 8060 peer = peer_and_group_lookup_vty(vty, ip_str);
8061 if (!peer)
8062 return CMD_WARNING_CONFIG_FAILED;
718e3744 8063
1de27621
DA
8064 route_map = route_map_lookup_warn_noexist(vty, name_str);
8065 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 8066
d62a17ae 8067 return bgp_vty_return(vty, ret);
718e3744 8068}
8069
8070/* Unset route-map from the peer. */
d62a17ae 8071static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8072 afi_t afi, safi_t safi)
718e3744 8073{
d62a17ae 8074 int ret;
8075 struct peer *peer;
718e3744 8076
d62a17ae 8077 peer = peer_and_group_lookup_vty(vty, ip_str);
8078 if (!peer)
8079 return CMD_WARNING_CONFIG_FAILED;
718e3744 8080
d62a17ae 8081 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 8082
d62a17ae 8083 return bgp_vty_return(vty, ret);
718e3744 8084}
8085
8086DEFUN (neighbor_unsuppress_map,
8087 neighbor_unsuppress_map_cmd,
9ccf14f7 8088 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8089 NEIGHBOR_STR
8090 NEIGHBOR_ADDR_STR2
8091 "Route-map to selectively unsuppress suppressed routes\n"
8092 "Name of route map\n")
8093{
d62a17ae 8094 int idx_peer = 1;
8095 int idx_word = 3;
8096 return peer_unsuppress_map_set_vty(
8097 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8098 argv[idx_word]->arg);
718e3744 8099}
8100
d62a17ae 8101ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8102 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8103 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8104 "Route-map to selectively unsuppress suppressed routes\n"
8105 "Name of route map\n")
596c17ba 8106
718e3744 8107DEFUN (no_neighbor_unsuppress_map,
8108 no_neighbor_unsuppress_map_cmd,
9ccf14f7 8109 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8110 NO_STR
8111 NEIGHBOR_STR
8112 NEIGHBOR_ADDR_STR2
8113 "Route-map to selectively unsuppress suppressed routes\n"
8114 "Name of route map\n")
8115{
d62a17ae 8116 int idx_peer = 2;
8117 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8118 bgp_node_afi(vty),
8119 bgp_node_safi(vty));
718e3744 8120}
6b0655a2 8121
d62a17ae 8122ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8123 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8124 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8125 "Route-map to selectively unsuppress suppressed routes\n"
8126 "Name of route map\n")
596c17ba 8127
7e62b792
IR
8128static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
8129 afi_t afi, safi_t safi,
8130 const char *num_str,
8131 const char *threshold_str, int warning,
8132 const char *restart_str,
8133 const char *force_str)
8134{
8135 int ret;
8136 struct peer *peer;
8137 uint32_t max;
8138 uint8_t threshold;
8139 uint16_t restart;
8140
8141 peer = peer_and_group_lookup_vty(vty, ip_str);
8142 if (!peer)
8143 return CMD_WARNING_CONFIG_FAILED;
8144
8145 max = strtoul(num_str, NULL, 10);
8146 if (threshold_str)
8147 threshold = atoi(threshold_str);
8148 else
8149 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
8150
8151 if (restart_str)
8152 restart = atoi(restart_str);
8153 else
8154 restart = 0;
8155
8156 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
8157 restart, force_str ? true : false);
8158
8159 return bgp_vty_return(vty, ret);
8160}
8161
8162static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
8163 afi_t afi, safi_t safi)
8164{
8165 int ret;
8166 struct peer *peer;
8167
8168 peer = peer_and_group_lookup_vty(vty, ip_str);
8169 if (!peer)
8170 return CMD_WARNING_CONFIG_FAILED;
8171
8172 ret = peer_maximum_prefix_unset(peer, afi, safi);
8173
8174 return bgp_vty_return(vty, ret);
8175}
8176
fde246e8 8177/* Maximum number of prefix to be sent to the neighbor. */
1d80f243
IR
8178DEFUN(neighbor_maximum_prefix_out,
8179 neighbor_maximum_prefix_out_cmd,
8180 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8181 NEIGHBOR_STR
8182 NEIGHBOR_ADDR_STR2
8183 "Maximum number of prefixes to be sent to this peer\n"
8184 "Maximum no. of prefix limit\n")
fde246e8 8185{
80444d30 8186 int ret;
fde246e8
DA
8187 int idx_peer = 1;
8188 int idx_number = 3;
7e62b792
IR
8189 struct peer *peer;
8190 uint32_t max;
fde246e8
DA
8191 afi_t afi = bgp_node_afi(vty);
8192 safi_t safi = bgp_node_safi(vty);
8193
7e62b792
IR
8194 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8195 if (!peer)
fde246e8
DA
8196 return CMD_WARNING_CONFIG_FAILED;
8197
7e62b792 8198 max = strtoul(argv[idx_number]->arg, NULL, 10);
fde246e8 8199
80444d30 8200 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
fde246e8 8201
80444d30 8202 return bgp_vty_return(vty, ret);
fde246e8
DA
8203}
8204
1d80f243
IR
8205DEFUN(no_neighbor_maximum_prefix_out,
8206 no_neighbor_maximum_prefix_out_cmd,
bc03c622 8207 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
1d80f243
IR
8208 NO_STR
8209 NEIGHBOR_STR
8210 NEIGHBOR_ADDR_STR2
bc03c622
LS
8211 "Maximum number of prefixes to be sent to this peer\n"
8212 "Maximum no. of prefix limit\n")
fde246e8 8213{
80444d30 8214 int ret;
fde246e8 8215 int idx_peer = 2;
7e62b792 8216 struct peer *peer;
fde246e8
DA
8217 afi_t afi = bgp_node_afi(vty);
8218 safi_t safi = bgp_node_safi(vty);
8219
7e62b792
IR
8220 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8221 if (!peer)
fde246e8
DA
8222 return CMD_WARNING_CONFIG_FAILED;
8223
80444d30 8224 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
fde246e8 8225
80444d30 8226 return bgp_vty_return(vty, ret);
fde246e8
DA
8227}
8228
9cbd06e0
DA
8229/* Maximum number of prefix configuration. Prefix count is different
8230 for each peer configuration. So this configuration can be set for
718e3744 8231 each peer configuration. */
1d80f243
IR
8232DEFUN (neighbor_maximum_prefix,
8233 neighbor_maximum_prefix_cmd,
8234 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8235 NEIGHBOR_STR
8236 NEIGHBOR_ADDR_STR2
8237 "Maximum number of prefix accept from this peer\n"
8238 "maximum no. of prefix limit\n"
8239 "Force checking all received routes not only accepted\n")
718e3744 8240{
d62a17ae 8241 int idx_peer = 1;
8242 int idx_number = 3;
9cbd06e0 8243 int idx_force = 0;
7e62b792 8244 char *force = NULL;
9cbd06e0
DA
8245
8246 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8247 force = argv[idx_force]->arg;
9cbd06e0 8248
7e62b792
IR
8249 return peer_maximum_prefix_set_vty(
8250 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8251 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 8252}
8253
d62a17ae 8254ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8255 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 8256 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8257 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
8258 "maximum no. of prefix limit\n"
8259 "Force checking all received routes not only accepted\n")
596c17ba 8260
1d80f243
IR
8261DEFUN (neighbor_maximum_prefix_threshold,
8262 neighbor_maximum_prefix_threshold_cmd,
8263 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8264 NEIGHBOR_STR
8265 NEIGHBOR_ADDR_STR2
8266 "Maximum number of prefix accept from this peer\n"
8267 "maximum no. of prefix limit\n"
8268 "Threshold value (%) at which to generate a warning msg\n"
8269 "Force checking all received routes not only accepted\n")
e0701b79 8270{
d62a17ae 8271 int idx_peer = 1;
8272 int idx_number = 3;
8273 int idx_number_2 = 4;
9cbd06e0 8274 int idx_force = 0;
7e62b792 8275 char *force = NULL;
9cbd06e0
DA
8276
8277 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8278 force = argv[idx_force]->arg;
9cbd06e0 8279
7e62b792
IR
8280 return peer_maximum_prefix_set_vty(
8281 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8282 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 8283}
e0701b79 8284
d62a17ae 8285ALIAS_HIDDEN(
8286 neighbor_maximum_prefix_threshold,
8287 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 8288 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 8289 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8290 "Maximum number of prefix accept from this peer\n"
8291 "maximum no. of prefix limit\n"
9cbd06e0
DA
8292 "Threshold value (%) at which to generate a warning msg\n"
8293 "Force checking all received routes not only accepted\n")
596c17ba 8294
1d80f243
IR
8295DEFUN (neighbor_maximum_prefix_warning,
8296 neighbor_maximum_prefix_warning_cmd,
8297 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8298 NEIGHBOR_STR
8299 NEIGHBOR_ADDR_STR2
8300 "Maximum number of prefix accept from this peer\n"
8301 "maximum no. of prefix limit\n"
8302 "Only give warning message when limit is exceeded\n"
8303 "Force checking all received routes not only accepted\n")
718e3744 8304{
d62a17ae 8305 int idx_peer = 1;
8306 int idx_number = 3;
9cbd06e0 8307 int idx_force = 0;
7e62b792 8308 char *force = NULL;
9cbd06e0
DA
8309
8310 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8311 force = argv[idx_force]->arg;
9cbd06e0 8312
7e62b792
IR
8313 return peer_maximum_prefix_set_vty(
8314 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8315 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 8316}
8317
d62a17ae 8318ALIAS_HIDDEN(
8319 neighbor_maximum_prefix_warning,
8320 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 8321 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 8322 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8323 "Maximum number of prefix accept from this peer\n"
8324 "maximum no. of prefix limit\n"
9cbd06e0
DA
8325 "Only give warning message when limit is exceeded\n"
8326 "Force checking all received routes not only accepted\n")
596c17ba 8327
1d80f243
IR
8328DEFUN (neighbor_maximum_prefix_threshold_warning,
8329 neighbor_maximum_prefix_threshold_warning_cmd,
8330 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8331 NEIGHBOR_STR
8332 NEIGHBOR_ADDR_STR2
8333 "Maximum number of prefix accept from this peer\n"
8334 "maximum no. of prefix limit\n"
8335 "Threshold value (%) at which to generate a warning msg\n"
8336 "Only give warning message when limit is exceeded\n"
8337 "Force checking all received routes not only accepted\n")
e0701b79 8338{
d62a17ae 8339 int idx_peer = 1;
8340 int idx_number = 3;
8341 int idx_number_2 = 4;
9cbd06e0 8342 int idx_force = 0;
7e62b792 8343 char *force = NULL;
9cbd06e0
DA
8344
8345 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8346 force = argv[idx_force]->arg;
9cbd06e0 8347
7e62b792
IR
8348 return peer_maximum_prefix_set_vty(
8349 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8350 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 8351}
8352
d62a17ae 8353ALIAS_HIDDEN(
8354 neighbor_maximum_prefix_threshold_warning,
8355 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 8356 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 8357 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8358 "Maximum number of prefix accept from this peer\n"
8359 "maximum no. of prefix limit\n"
8360 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
8361 "Only give warning message when limit is exceeded\n"
8362 "Force checking all received routes not only accepted\n")
596c17ba 8363
1d80f243
IR
8364DEFUN (neighbor_maximum_prefix_restart,
8365 neighbor_maximum_prefix_restart_cmd,
8366 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8367 NEIGHBOR_STR
8368 NEIGHBOR_ADDR_STR2
8369 "Maximum number of prefix accept from this peer\n"
8370 "maximum no. of prefix limit\n"
8371 "Restart bgp connection after limit is exceeded\n"
8372 "Restart interval in minutes\n"
8373 "Force checking all received routes not only accepted\n")
0a486e5f 8374{
d62a17ae 8375 int idx_peer = 1;
8376 int idx_number = 3;
8377 int idx_number_2 = 5;
9cbd06e0 8378 int idx_force = 0;
7e62b792 8379 char *force = NULL;
9cbd06e0
DA
8380
8381 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8382 force = argv[idx_force]->arg;
9cbd06e0 8383
7e62b792
IR
8384 return peer_maximum_prefix_set_vty(
8385 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8386 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 8387}
8388
d62a17ae 8389ALIAS_HIDDEN(
8390 neighbor_maximum_prefix_restart,
8391 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 8392 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 8393 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8394 "Maximum number of prefix accept from this peer\n"
8395 "maximum no. of prefix limit\n"
8396 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8397 "Restart interval in minutes\n"
8398 "Force checking all received routes not only accepted\n")
596c17ba 8399
1d80f243
IR
8400DEFUN (neighbor_maximum_prefix_threshold_restart,
8401 neighbor_maximum_prefix_threshold_restart_cmd,
8402 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8403 NEIGHBOR_STR
8404 NEIGHBOR_ADDR_STR2
8405 "Maximum number of prefixes to accept from this peer\n"
8406 "maximum no. of prefix limit\n"
8407 "Threshold value (%) at which to generate a warning msg\n"
8408 "Restart bgp connection after limit is exceeded\n"
8409 "Restart interval in minutes\n"
8410 "Force checking all received routes not only accepted\n")
0a486e5f 8411{
d62a17ae 8412 int idx_peer = 1;
8413 int idx_number = 3;
8414 int idx_number_2 = 4;
8415 int idx_number_3 = 6;
9cbd06e0 8416 int idx_force = 0;
7e62b792 8417 char *force = NULL;
9cbd06e0
DA
8418
8419 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8420 force = argv[idx_force]->arg;
9cbd06e0 8421
7e62b792
IR
8422 return peer_maximum_prefix_set_vty(
8423 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8424 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8425 argv[idx_number_3]->arg, force);
d62a17ae 8426}
8427
8428ALIAS_HIDDEN(
8429 neighbor_maximum_prefix_threshold_restart,
8430 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 8431 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 8432 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8433 "Maximum number of prefixes to accept from this peer\n"
8434 "maximum no. of prefix limit\n"
8435 "Threshold value (%) at which to generate a warning msg\n"
8436 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8437 "Restart interval in minutes\n"
8438 "Force checking all received routes not only accepted\n")
596c17ba 8439
1d80f243
IR
8440DEFUN (no_neighbor_maximum_prefix,
8441 no_neighbor_maximum_prefix_cmd,
8442 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8443 NO_STR
8444 NEIGHBOR_STR
8445 NEIGHBOR_ADDR_STR2
8446 "Maximum number of prefixes to accept from this peer\n"
8447 "maximum no. of prefix limit\n"
8448 "Threshold value (%) at which to generate a warning msg\n"
8449 "Restart bgp connection after limit is exceeded\n"
8450 "Restart interval in minutes\n"
8451 "Only give warning message when limit is exceeded\n"
8452 "Force checking all received routes not only accepted\n")
718e3744 8453{
d62a17ae 8454 int idx_peer = 2;
7e62b792
IR
8455 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8456 bgp_node_afi(vty),
8457 bgp_node_safi(vty));
718e3744 8458}
e52702f2 8459
d62a17ae 8460ALIAS_HIDDEN(
8461 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8462 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 8463 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8464 "Maximum number of prefixes to accept from this peer\n"
8465 "maximum no. of prefix limit\n"
8466 "Threshold value (%) at which to generate a warning msg\n"
8467 "Restart bgp connection after limit is exceeded\n"
8468 "Restart interval in minutes\n"
9cbd06e0
DA
8469 "Only give warning message when limit is exceeded\n"
8470 "Force checking all received routes not only accepted\n")
596c17ba 8471
46dbf9d0
DA
8472/* "neighbor accept-own" */
8473DEFPY (neighbor_accept_own,
8474 neighbor_accept_own_cmd,
8475 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor accept-own",
8476 NO_STR
8477 NEIGHBOR_STR
8478 NEIGHBOR_ADDR_STR2
8479 "Enable handling of self-originated VPN routes containing ACCEPT_OWN community\n")
8480{
8481 struct peer *peer;
8482 afi_t afi = bgp_node_afi(vty);
8483 safi_t safi = bgp_node_safi(vty);
8484 int ret;
8485
8486 peer = peer_and_group_lookup_vty(vty, neighbor);
8487 if (!peer)
8488 return CMD_WARNING_CONFIG_FAILED;
8489
8490 if (no)
8491 ret = peer_af_flag_unset(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8492 else
8493 ret = peer_af_flag_set(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8494
8495 return bgp_vty_return(vty, ret);
8496}
8497
01da2d26
DA
8498/* "neighbor soo" */
8499DEFPY (neighbor_soo,
8500 neighbor_soo_cmd,
8501 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8502 NEIGHBOR_STR
8503 NEIGHBOR_ADDR_STR2
8504 "Set the Site-of-Origin (SoO) extended community\n"
8505 "VPN extended community\n")
8506{
8507 struct peer *peer;
8508 afi_t afi = bgp_node_afi(vty);
8509 safi_t safi = bgp_node_safi(vty);
8510 struct ecommunity *ecomm_soo;
8511
8512 peer = peer_and_group_lookup_vty(vty, neighbor);
8513 if (!peer)
8514 return CMD_WARNING_CONFIG_FAILED;
8515
8516 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8517 if (!ecomm_soo) {
8518 vty_out(vty, "%% Malformed SoO extended community\n");
8519 return CMD_WARNING;
8520 }
8521 ecommunity_str(ecomm_soo);
8522
8523 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8524 ecommunity_free(&peer->soo[afi][safi]);
8525 peer->soo[afi][safi] = ecomm_soo;
8526 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8527 }
8528
8529 return bgp_vty_return(vty,
8530 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8531}
8532
8533DEFPY (no_neighbor_soo,
8534 no_neighbor_soo_cmd,
8535 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8536 NO_STR
8537 NEIGHBOR_STR
8538 NEIGHBOR_ADDR_STR2
8539 "Set the Site-of-Origin (SoO) extended community\n"
8540 "VPN extended community\n")
8541{
8542 struct peer *peer;
8543 afi_t afi = bgp_node_afi(vty);
8544 safi_t safi = bgp_node_safi(vty);
8545
8546 peer = peer_and_group_lookup_vty(vty, neighbor);
8547 if (!peer)
8548 return CMD_WARNING_CONFIG_FAILED;
8549
8550 ecommunity_free(&peer->soo[afi][safi]);
8551
8552 return bgp_vty_return(
8553 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8554}
718e3744 8555
718e3744 8556/* "neighbor allowas-in" */
8557DEFUN (neighbor_allowas_in,
8558 neighbor_allowas_in_cmd,
fd8503f5 8559 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8560 NEIGHBOR_STR
8561 NEIGHBOR_ADDR_STR2
31500417 8562 "Accept as-path with my AS present in it\n"
f79f7a7b 8563 "Number of occurrences of AS number\n"
fd8503f5 8564 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8565{
d62a17ae 8566 int idx_peer = 1;
8567 int idx_number_origin = 3;
8568 int ret;
8569 int origin = 0;
8570 struct peer *peer;
8571 int allow_num = 0;
8572
8573 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8574 if (!peer)
8575 return CMD_WARNING_CONFIG_FAILED;
8576
8577 if (argc <= idx_number_origin)
8578 allow_num = 3;
8579 else {
8580 if (argv[idx_number_origin]->type == WORD_TKN)
8581 origin = 1;
8582 else
8583 allow_num = atoi(argv[idx_number_origin]->arg);
8584 }
8585
8586 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8587 allow_num, origin);
8588
8589 return bgp_vty_return(vty, ret);
8590}
8591
8592ALIAS_HIDDEN(
8593 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8594 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8595 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8596 "Accept as-path with my AS present in it\n"
f79f7a7b 8597 "Number of occurrences of AS number\n"
d62a17ae 8598 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8599
718e3744 8600DEFUN (no_neighbor_allowas_in,
8601 no_neighbor_allowas_in_cmd,
fd8503f5 8602 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8603 NO_STR
8604 NEIGHBOR_STR
8605 NEIGHBOR_ADDR_STR2
8334fd5a 8606 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8607 "Number of occurrences of AS number\n"
fd8503f5 8608 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8609{
d62a17ae 8610 int idx_peer = 2;
8611 int ret;
8612 struct peer *peer;
718e3744 8613
d62a17ae 8614 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8615 if (!peer)
8616 return CMD_WARNING_CONFIG_FAILED;
718e3744 8617
d62a17ae 8618 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8619 bgp_node_safi(vty));
718e3744 8620
d62a17ae 8621 return bgp_vty_return(vty, ret);
718e3744 8622}
6b0655a2 8623
d62a17ae 8624ALIAS_HIDDEN(
8625 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8626 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8627 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8628 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8629 "Number of occurrences of AS number\n"
d62a17ae 8630 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8631
28c6e247
IR
8632DEFUN (neighbor_ttl_security,
8633 neighbor_ttl_security_cmd,
8634 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8635 NEIGHBOR_STR
8636 NEIGHBOR_ADDR_STR2
8637 "BGP ttl-security parameters\n"
8638 "Specify the maximum number of hops to the BGP peer\n"
8639 "Number of hops to BGP peer\n")
fa411a21 8640{
d62a17ae 8641 int idx_peer = 1;
8642 int idx_number = 4;
28c6e247
IR
8643 struct peer *peer;
8644 int gtsm_hops;
d62a17ae 8645
28c6e247
IR
8646 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8647 if (!peer)
d62a17ae 8648 return CMD_WARNING_CONFIG_FAILED;
8649
28c6e247
IR
8650 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8651
8652 /*
8653 * If 'neighbor swpX', then this is for directly connected peers,
8654 * we should not accept a ttl-security hops value greater than 1.
8655 */
8656 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8657 vty_out(vty,
8658 "%s is directly connected peer, hops cannot exceed 1\n",
8659 argv[idx_peer]->arg);
8660 return CMD_WARNING_CONFIG_FAILED;
8661 }
7ebe625c 8662
28c6e247 8663 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
8664}
8665
1d80f243
IR
8666DEFUN (no_neighbor_ttl_security,
8667 no_neighbor_ttl_security_cmd,
8668 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8669 NO_STR
8670 NEIGHBOR_STR
8671 NEIGHBOR_ADDR_STR2
8672 "BGP ttl-security parameters\n"
8673 "Specify the maximum number of hops to the BGP peer\n"
8674 "Number of hops to BGP peer\n")
fa411a21 8675{
d62a17ae 8676 int idx_peer = 2;
28c6e247 8677 struct peer *peer;
fa411a21 8678
28c6e247
IR
8679 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8680 if (!peer)
d62a17ae 8681 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8682
28c6e247 8683 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 8684}
6b0655a2 8685
7c0e4312
DA
8686/* disable-addpath-rx */
8687DEFUN(neighbor_disable_addpath_rx,
8688 neighbor_disable_addpath_rx_cmd,
8689 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8690 NEIGHBOR_STR
8691 NEIGHBOR_ADDR_STR2
8692 "Do not accept additional paths\n")
8693{
8694 char *peer_str = argv[1]->arg;
8695 struct peer *peer;
8696 afi_t afi = bgp_node_afi(vty);
8697 safi_t safi = bgp_node_safi(vty);
8698
8699 peer = peer_and_group_lookup_vty(vty, peer_str);
8700 if (!peer)
8701 return CMD_WARNING_CONFIG_FAILED;
8702
8703 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8704 PEER_FLAG_DISABLE_ADDPATH_RX);
8705}
8706
8707DEFUN(no_neighbor_disable_addpath_rx,
8708 no_neighbor_disable_addpath_rx_cmd,
8709 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8710 NO_STR
8711 NEIGHBOR_STR
8712 NEIGHBOR_ADDR_STR2
8713 "Do not accept additional paths\n")
8714{
8715 char *peer_str = argv[2]->arg;
8716 struct peer *peer;
8717 afi_t afi = bgp_node_afi(vty);
8718 safi_t safi = bgp_node_safi(vty);
8719
8720 peer = peer_and_group_lookup_vty(vty, peer_str);
8721 if (!peer)
8722 return CMD_WARNING_CONFIG_FAILED;
8723
8724 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8725 PEER_FLAG_DISABLE_ADDPATH_RX);
8726}
8727
adbac85e
DW
8728DEFUN (neighbor_addpath_tx_all_paths,
8729 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8730 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8731 NEIGHBOR_STR
8732 NEIGHBOR_ADDR_STR2
8733 "Use addpath to advertise all paths to a neighbor\n")
8734{
d62a17ae 8735 int idx_peer = 1;
8736 struct peer *peer;
adbac85e 8737
d62a17ae 8738 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8739 if (!peer)
8740 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8741
dcc68b5e
MS
8742 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8743 BGP_ADDPATH_ALL);
8744 return CMD_SUCCESS;
adbac85e
DW
8745}
8746
d62a17ae 8747ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8748 neighbor_addpath_tx_all_paths_hidden_cmd,
8749 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8750 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8751 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8752
adbac85e
DW
8753DEFUN (no_neighbor_addpath_tx_all_paths,
8754 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8755 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8756 NO_STR
8757 NEIGHBOR_STR
8758 NEIGHBOR_ADDR_STR2
8759 "Use addpath to advertise all paths to a neighbor\n")
8760{
d62a17ae 8761 int idx_peer = 2;
dcc68b5e
MS
8762 struct peer *peer;
8763
8764 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8765 if (!peer)
8766 return CMD_WARNING_CONFIG_FAILED;
8767
8768 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8769 != BGP_ADDPATH_ALL) {
8770 vty_out(vty,
8771 "%% Peer not currently configured to transmit all paths.");
8772 return CMD_WARNING_CONFIG_FAILED;
8773 }
8774
8775 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8776 BGP_ADDPATH_NONE);
8777
8778 return CMD_SUCCESS;
adbac85e
DW
8779}
8780
d62a17ae 8781ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8782 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8783 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8784 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8785 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8786
06370dac
DW
8787DEFUN (neighbor_addpath_tx_bestpath_per_as,
8788 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8789 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8790 NEIGHBOR_STR
8791 NEIGHBOR_ADDR_STR2
8792 "Use addpath to advertise the bestpath per each neighboring AS\n")
8793{
d62a17ae 8794 int idx_peer = 1;
8795 struct peer *peer;
06370dac 8796
d62a17ae 8797 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8798 if (!peer)
8799 return CMD_WARNING_CONFIG_FAILED;
06370dac 8800
dcc68b5e
MS
8801 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8802 BGP_ADDPATH_BEST_PER_AS);
8803
8804 return CMD_SUCCESS;
06370dac
DW
8805}
8806
d62a17ae 8807ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8808 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8809 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8810 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8811 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8812
06370dac
DW
8813DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8814 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8815 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8816 NO_STR
8817 NEIGHBOR_STR
8818 NEIGHBOR_ADDR_STR2
8819 "Use addpath to advertise the bestpath per each neighboring AS\n")
8820{
d62a17ae 8821 int idx_peer = 2;
dcc68b5e
MS
8822 struct peer *peer;
8823
8824 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8825 if (!peer)
8826 return CMD_WARNING_CONFIG_FAILED;
8827
8828 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8829 != BGP_ADDPATH_BEST_PER_AS) {
8830 vty_out(vty,
8831 "%% Peer not currently configured to transmit all best path per as.");
8832 return CMD_WARNING_CONFIG_FAILED;
8833 }
8834
8835 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8836 BGP_ADDPATH_NONE);
8837
8838 return CMD_SUCCESS;
06370dac
DW
8839}
8840
d62a17ae 8841ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8842 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8843 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8844 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8845 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8846
2b31007c
RZ
8847DEFPY(
8848 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8849 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8850 NEIGHBOR_STR
8851 NEIGHBOR_ADDR_STR2
8852 "Detect AS loops before sending to neighbor\n")
8853{
8854 struct peer *peer;
8855
8856 peer = peer_and_group_lookup_vty(vty, neighbor);
8857 if (!peer)
8858 return CMD_WARNING_CONFIG_FAILED;
8859
8860 peer->as_path_loop_detection = true;
8861
8862 return CMD_SUCCESS;
8863}
8864
8865DEFPY(
8866 no_neighbor_aspath_loop_detection,
8867 no_neighbor_aspath_loop_detection_cmd,
8868 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8869 NO_STR
8870 NEIGHBOR_STR
8871 NEIGHBOR_ADDR_STR2
8872 "Detect AS loops before sending to neighbor\n")
8873{
8874 struct peer *peer;
8875
8876 peer = peer_and_group_lookup_vty(vty, neighbor);
8877 if (!peer)
8878 return CMD_WARNING_CONFIG_FAILED;
8879
8880 peer->as_path_loop_detection = false;
8881
8882 return CMD_SUCCESS;
8883}
8884
a5c6a9b1
DA
8885DEFPY(neighbor_path_attribute_discard,
8886 neighbor_path_attribute_discard_cmd,
8887 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard (1-255)...",
8888 NEIGHBOR_STR
8889 NEIGHBOR_ADDR_STR2
8890 "Manipulate path attributes from incoming UPDATE messages\n"
8891 "Drop specified attributes from incoming UPDATE messages\n"
8892 "Attribute number\n")
8893{
8894 struct peer *peer;
8895 int idx = 0;
8896 const char *discard_attrs = NULL;
8897
8898 peer = peer_and_group_lookup_vty(vty, neighbor);
8899 if (!peer)
8900 return CMD_WARNING_CONFIG_FAILED;
8901
8902 argv_find(argv, argc, "(1-255)", &idx);
8903 if (idx)
8904 discard_attrs = argv_concat(argv, argc, idx);
8905
b986d7f4
DA
8906 bgp_path_attribute_discard_vty(vty, peer, discard_attrs, true);
8907
8908 return CMD_SUCCESS;
8909}
8910
8911DEFPY(no_neighbor_path_attribute_discard,
8912 no_neighbor_path_attribute_discard_cmd,
8913 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard [(1-255)]",
8914 NO_STR
8915 NEIGHBOR_STR
8916 NEIGHBOR_ADDR_STR2
8917 "Manipulate path attributes from incoming UPDATE messages\n"
8918 "Drop specified attributes from incoming UPDATE messages\n"
8919 "Attribute number\n")
8920{
8921 struct peer *peer;
8922 int idx = 0;
8923 const char *discard_attrs = NULL;
8924
8925 peer = peer_and_group_lookup_vty(vty, neighbor);
8926 if (!peer)
8927 return CMD_WARNING_CONFIG_FAILED;
8928
8929 argv_find(argv, argc, "(1-255)", &idx);
8930 if (idx)
8931 discard_attrs = argv[idx]->arg;
8932
8933 bgp_path_attribute_discard_vty(vty, peer, discard_attrs, false);
a5c6a9b1
DA
8934
8935 return CMD_SUCCESS;
8936}
8937
e2863b4f
DA
8938DEFPY(neighbor_path_attribute_treat_as_withdraw,
8939 neighbor_path_attribute_treat_as_withdraw_cmd,
8940 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute treat-as-withdraw (1-255)...",
8941 NEIGHBOR_STR
8942 NEIGHBOR_ADDR_STR2
8943 "Manipulate path attributes from incoming UPDATE messages\n"
8944 "Treat-as-withdraw any incoming BGP UPDATE messages that contain the specified attribute\n"
8945 "Attribute number\n")
8946{
8947 struct peer *peer;
8948 int idx = 0;
8949 const char *withdraw_attrs = NULL;
8950
8951 peer = peer_and_group_lookup_vty(vty, neighbor);
8952 if (!peer)
8953 return CMD_WARNING_CONFIG_FAILED;
8954
8955 argv_find(argv, argc, "(1-255)", &idx);
8956 if (idx)
8957 withdraw_attrs = argv_concat(argv, argc, idx);
8958
8959 bgp_path_attribute_withdraw_vty(vty, peer, withdraw_attrs, true);
8960
8961 return CMD_SUCCESS;
8962}
8963
8964DEFPY(no_neighbor_path_attribute_treat_as_withdraw,
8965 no_neighbor_path_attribute_treat_as_withdraw_cmd,
8966 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute treat-as-withdraw (1-255)...",
8967 NO_STR
8968 NEIGHBOR_STR
8969 NEIGHBOR_ADDR_STR2
8970 "Manipulate path attributes from incoming UPDATE messages\n"
8971 "Treat-as-withdraw any incoming BGP UPDATE messages that contain the specified attribute\n"
8972 "Attribute number\n")
8973{
8974 struct peer *peer;
8975 int idx = 0;
8976 const char *withdraw_attrs = NULL;
8977
8978 peer = peer_and_group_lookup_vty(vty, neighbor);
8979 if (!peer)
8980 return CMD_WARNING_CONFIG_FAILED;
8981
8982 argv_find(argv, argc, "(1-255)", &idx);
8983 if (idx)
8984 withdraw_attrs = argv_concat(argv, argc, idx);
8985
8986 bgp_path_attribute_withdraw_vty(vty, peer, withdraw_attrs, false);
8987
8988 return CMD_SUCCESS;
8989}
8990
b9c7bc5a 8991static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8992 struct ecommunity **list, bool is_rt6)
ddb5b488 8993{
b9c7bc5a
PZ
8994 struct ecommunity *ecom = NULL;
8995 struct ecommunity *ecomadd;
ddb5b488 8996
b9c7bc5a 8997 for (; argc; --argc, ++argv) {
9a659715
PG
8998 if (is_rt6)
8999 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
9000 ECOMMUNITY_ROUTE_TARGET,
9001 0);
9002 else
9003 ecomadd = ecommunity_str2com(argv[0]->arg,
9004 ECOMMUNITY_ROUTE_TARGET,
9005 0);
b9c7bc5a
PZ
9006 if (!ecomadd) {
9007 vty_out(vty, "Malformed community-list value\n");
9008 if (ecom)
9009 ecommunity_free(&ecom);
9010 return CMD_WARNING_CONFIG_FAILED;
9011 }
ddb5b488 9012
b9c7bc5a
PZ
9013 if (ecom) {
9014 ecommunity_merge(ecom, ecomadd);
9015 ecommunity_free(&ecomadd);
9016 } else {
9017 ecom = ecomadd;
9018 }
9019 }
9020
9021 if (*list) {
9022 ecommunity_free(&*list);
ddb5b488 9023 }
b9c7bc5a
PZ
9024 *list = ecom;
9025
9026 return CMD_SUCCESS;
ddb5b488
PZ
9027}
9028
0ca70ba5
DS
9029/*
9030 * v2vimport is true if we are handling a `import vrf ...` command
9031 */
9032static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 9033{
0ca70ba5
DS
9034 afi_t afi;
9035
ddb5b488 9036 switch (vty->node) {
b9c7bc5a 9037 case BGP_IPV4_NODE:
0ca70ba5
DS
9038 afi = AFI_IP;
9039 break;
b9c7bc5a 9040 case BGP_IPV6_NODE:
0ca70ba5
DS
9041 afi = AFI_IP6;
9042 break;
ddb5b488
PZ
9043 default:
9044 vty_out(vty,
b9c7bc5a 9045 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 9046 return AFI_MAX;
ddb5b488 9047 }
69b07479 9048
0ca70ba5
DS
9049 if (!v2vimport) {
9050 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9051 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9052 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9053 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9054 vty_out(vty,
9055 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
9056 return AFI_MAX;
9057 }
9058 } else {
9059 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9060 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9061 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9062 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9063 vty_out(vty,
9064 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
9065 return AFI_MAX;
9066 }
9067 }
9068 return afi;
ddb5b488
PZ
9069}
9070
585f1adc
IR
9071DEFPY (af_rd_vpn_export,
9072 af_rd_vpn_export_cmd,
9073 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
9074 NO_STR
9075 "Specify route distinguisher\n"
9076 "Between current address-family and vpn\n"
9077 "For routes leaked from current address-family to vpn\n"
9078 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 9079{
585f1adc
IR
9080 VTY_DECLVAR_CONTEXT(bgp, bgp);
9081 struct prefix_rd prd;
9082 int ret;
ddb5b488 9083 afi_t afi;
b9c7bc5a 9084 int idx = 0;
585f1adc 9085 bool yes = true;
b9c7bc5a 9086
585f1adc
IR
9087 if (argv_find(argv, argc, "no", &idx))
9088 yes = false;
ddb5b488 9089
585f1adc
IR
9090 if (yes) {
9091 ret = str2prefix_rd(rd_str, &prd);
9092 if (!ret) {
9093 vty_out(vty, "%% Malformed rd\n");
9094 return CMD_WARNING_CONFIG_FAILED;
9095 }
9096 }
ddb5b488 9097
585f1adc
IR
9098 afi = vpn_policy_getafi(vty, bgp, false);
9099 if (afi == AFI_MAX)
9100 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9101
585f1adc
IR
9102 /*
9103 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9104 */
9105 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9106 bgp_get_default(), bgp);
ddb5b488 9107
585f1adc 9108 if (yes) {
fa566a94
PG
9109 bgp->vpn_policy[afi].tovpn_rd_pretty =
9110 XSTRDUP(MTYPE_BGP, rd_str);
585f1adc
IR
9111 bgp->vpn_policy[afi].tovpn_rd = prd;
9112 SET_FLAG(bgp->vpn_policy[afi].flags,
9113 BGP_VPN_POLICY_TOVPN_RD_SET);
9114 } else {
fa566a94 9115 XFREE(MTYPE_BGP, bgp->vpn_policy[afi].tovpn_rd_pretty);
585f1adc
IR
9116 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9117 BGP_VPN_POLICY_TOVPN_RD_SET);
9118 }
69b07479 9119
585f1adc
IR
9120 /* post-change: re-export vpn routes */
9121 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9122 bgp_get_default(), bgp);
9123
9124 return CMD_SUCCESS;
ddb5b488
PZ
9125}
9126
b9c7bc5a
PZ
9127ALIAS (af_rd_vpn_export,
9128 af_no_rd_vpn_export_cmd,
9129 "no rd vpn export",
ddb5b488 9130 NO_STR
b9c7bc5a
PZ
9131 "Specify route distinguisher\n"
9132 "Between current address-family and vpn\n"
9133 "For routes leaked from current address-family to vpn\n")
ddb5b488 9134
b9c7bc5a
PZ
9135DEFPY (af_label_vpn_export,
9136 af_label_vpn_export_cmd,
e70e9f8e 9137 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 9138 NO_STR
ddb5b488 9139 "label value for VRF\n"
b9c7bc5a
PZ
9140 "Between current address-family and vpn\n"
9141 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
9142 "Label Value <0-1048575>\n"
9143 "Automatically assign a label\n")
ddb5b488
PZ
9144{
9145 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 9146 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 9147 afi_t afi;
b9c7bc5a 9148 int idx = 0;
c6423c31 9149 bool yes = true;
b9c7bc5a
PZ
9150
9151 if (argv_find(argv, argc, "no", &idx))
c6423c31 9152 yes = false;
ddb5b488 9153
21a16cc2
PZ
9154 /* If "no ...", squash trailing parameter */
9155 if (!yes)
9156 label_auto = NULL;
9157
e70e9f8e
PZ
9158 if (yes) {
9159 if (!label_auto)
9160 label = label_val; /* parser should force unsigned */
9161 }
ddb5b488 9162
0ca70ba5 9163 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9164 if (afi == AFI_MAX)
9165 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 9166
e70e9f8e 9167
69b07479
DS
9168 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9169 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9170 /* no change */
9171 return CMD_SUCCESS;
e70e9f8e 9172
69b07479
DS
9173 /*
9174 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9175 */
9176 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9177 bgp_get_default(), bgp);
9178
9179 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9180 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9181
9182 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9183
9184 /*
9185 * label has previously been automatically
9186 * assigned by labelpool: release it
9187 *
9188 * NB if tovpn_label == MPLS_LABEL_NONE it
9189 * means the automatic assignment is in flight
9190 * and therefore the labelpool callback must
9191 * detect that the auto label is not needed.
9192 */
9193
9194 bgp_lp_release(LP_TYPE_VRF,
9195 &bgp->vpn_policy[afi],
9196 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 9197 }
69b07479
DS
9198 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9199 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9200 }
ddb5b488 9201
69b07479
DS
9202 bgp->vpn_policy[afi].tovpn_label = label;
9203 if (label_auto) {
9204 SET_FLAG(bgp->vpn_policy[afi].flags,
9205 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9206 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9207 vpn_leak_label_callback);
ddb5b488
PZ
9208 }
9209
69b07479
DS
9210 /* post-change: re-export vpn routes */
9211 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9212 bgp_get_default(), bgp);
9213
0d020cd6 9214 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
9215 return CMD_SUCCESS;
9216}
9217
b72c9e14
HS
9218DEFPY (af_sid_vpn_export,
9219 af_sid_vpn_export_cmd,
46279a11 9220 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
b72c9e14
HS
9221 NO_STR
9222 "sid value for VRF\n"
9223 "Between current address-family and vpn\n"
9224 "For routes leaked from current address-family to vpn\n"
9225 "Sid allocation index\n"
9226 "Automatically assign a label\n")
9227{
9228 VTY_DECLVAR_CONTEXT(bgp, bgp);
9229 afi_t afi;
9230 int debug = 0;
9231 int idx = 0;
9232 bool yes = true;
9233
9234 if (argv_find(argv, argc, "no", &idx))
9235 yes = false;
9236 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9237 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9238
9239 afi = vpn_policy_getafi(vty, bgp, false);
9240 if (afi == AFI_MAX)
9241 return CMD_WARNING_CONFIG_FAILED;
9242
9243 if (!yes) {
9244 /* implement me */
4d4c404b 9245 vty_out(vty, "It's not implemented\n");
b72c9e14
HS
9246 return CMD_WARNING_CONFIG_FAILED;
9247 }
9248
527588aa
CS
9249 if (bgp->tovpn_sid_index != 0 ||
9250 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
9251 vty_out(vty,
9252 "per-vrf sid and per-af sid are mutually exclusive\n"
9253 "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9254 return CMD_WARNING_CONFIG_FAILED;
9255 }
9256
b72c9e14
HS
9257 /* skip when it's already configured */
9258 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9259 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9260 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9261 return CMD_SUCCESS;
9262
7de4c885
HS
9263 /*
9264 * mode change between sid_idx and sid_auto isn't supported.
9265 * user must negate sid vpn export when they want to change the mode
9266 */
b72c9e14
HS
9267 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9268 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9269 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9270 vty_out(vty, "it's already configured as %s.\n",
9271 sid_auto ? "auto-mode" : "idx-mode");
9272 return CMD_WARNING_CONFIG_FAILED;
9273 }
9274
9275 /* pre-change */
9276 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9277 bgp_get_default(), bgp);
9278
9279 if (sid_auto) {
9280 /* SID allocation auto-mode */
9281 if (debug)
9282 zlog_debug("%s: auto sid alloc.", __func__);
9283 SET_FLAG(bgp->vpn_policy[afi].flags,
9284 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9285 } else {
9286 /* SID allocation index-mode */
9287 if (debug)
9288 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9289 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9290 }
9291
9292 /* post-change */
9293 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9294 bgp_get_default(), bgp);
9295 return CMD_SUCCESS;
9296}
9297
527588aa
CS
9298DEFPY (bgp_sid_vpn_export,
9299 bgp_sid_vpn_export_cmd,
346bbb39 9300 "[no] sid vpn per-vrf export <(1-1048575)$sid_idx|auto$sid_auto>",
527588aa
CS
9301 NO_STR
9302 "sid value for VRF\n"
9303 "Between current vrf and vpn\n"
9304 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9305 "For routes leaked from current vrf to vpn\n"
9306 "Sid allocation index\n"
9307 "Automatically assign a label\n")
9308{
9309 VTY_DECLVAR_CONTEXT(bgp, bgp);
9310 int debug;
9311
9312 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9313 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9314
9315 if (no) {
e606d8ec
CS
9316 /* when per-VRF SID is not set, do nothing */
9317 if (bgp->tovpn_sid_index == 0 &&
9318 !CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))
9319 return CMD_SUCCESS;
9320
9321 sid_idx = 0;
9322 sid_auto = false;
9323 bgp->tovpn_sid_index = 0;
9324 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
527588aa
CS
9325 }
9326
9327 if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9328 CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9329 BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9330 bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9331 CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9332 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9333 vty_out(vty,
9334 "per-vrf sid and per-af sid are mutually exclusive\n"
9335 "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9336 return CMD_WARNING_CONFIG_FAILED;
9337 }
9338
9339 /* skip when it's already configured */
9340 if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9341 (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9342 return CMD_SUCCESS;
9343
9344 /*
9345 * mode change between sid_idx and sid_auto isn't supported.
9346 * user must negate sid vpn export when they want to change the mode
9347 */
9348 if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9349 (sid_idx != 0 &&
9350 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9351 vty_out(vty, "it's already configured as %s.\n",
9352 sid_auto ? "auto-mode" : "idx-mode");
9353 return CMD_WARNING_CONFIG_FAILED;
9354 }
9355
9356 /* pre-change */
9357 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9358 bgp);
9359 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9360 bgp);
9361
9362 if (sid_auto) {
9363 /* SID allocation auto-mode */
9364 if (debug)
9365 zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9366 SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
e606d8ec 9367 } else if (sid_idx != 0) {
527588aa
CS
9368 /* SID allocation index-mode */
9369 if (debug)
9370 zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9371 sid_idx);
9372 bgp->tovpn_sid_index = sid_idx;
9373 }
9374
9375 /* post-change */
9376 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9377 bgp);
9378 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9379 bgp_get_default(), bgp);
9380
9381 return CMD_SUCCESS;
9382}
9383
b9c7bc5a
PZ
9384ALIAS (af_label_vpn_export,
9385 af_no_label_vpn_export_cmd,
9386 "no label vpn export",
9387 NO_STR
9388 "label value for VRF\n"
9389 "Between current address-family and vpn\n"
9390 "For routes leaked from current address-family to vpn\n")
ddb5b488 9391
e606d8ec
CS
9392ALIAS (bgp_sid_vpn_export,
9393 no_bgp_sid_vpn_export_cmd,
9394 "no$no sid vpn per-vrf export",
9395 NO_STR
9396 "sid value for VRF\n"
9397 "Between current vrf and vpn\n"
9398 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9399 "For routes leaked from current vrf to vpn\n")
9400
585f1adc 9401DEFPY (af_nexthop_vpn_export,
b9c7bc5a 9402 af_nexthop_vpn_export_cmd,
8c85ca28 9403 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 9404 NO_STR
ddb5b488 9405 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
9406 "Between current address-family and vpn\n"
9407 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9408 "IPv4 prefix\n"
9409 "IPv6 prefix\n")
9410{
585f1adc 9411 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 9412 afi_t afi;
ddb5b488
PZ
9413 struct prefix p;
9414
8c85ca28
QY
9415 if (!no) {
9416 if (!nexthop_su) {
9417 vty_out(vty, "%% Nexthop required\n");
9418 return CMD_WARNING_CONFIG_FAILED;
9419 }
8c85ca28 9420 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
9421 return CMD_WARNING_CONFIG_FAILED;
9422 }
ddb5b488 9423
585f1adc
IR
9424 afi = vpn_policy_getafi(vty, bgp, false);
9425 if (afi == AFI_MAX)
9426 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9427
585f1adc
IR
9428 /*
9429 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9430 */
9431 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9432 bgp_get_default(), bgp);
ddb5b488 9433
585f1adc
IR
9434 if (!no) {
9435 bgp->vpn_policy[afi].tovpn_nexthop = p;
9436 SET_FLAG(bgp->vpn_policy[afi].flags,
9437 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9438 } else {
9439 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9440 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9441 }
69b07479 9442
585f1adc
IR
9443 /* post-change: re-export vpn routes */
9444 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9445 bgp_get_default(), bgp);
37a87b8f 9446
585f1adc 9447 return CMD_SUCCESS;
ddb5b488
PZ
9448}
9449
b9c7bc5a 9450static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 9451{
b9c7bc5a
PZ
9452 if (!strcmp(dstr, "import")) {
9453 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9454 } else if (!strcmp(dstr, "export")) {
9455 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9456 } else if (!strcmp(dstr, "both")) {
9457 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9458 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9459 } else {
9460 vty_out(vty, "%% direction parse error\n");
9461 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9462 }
ddb5b488
PZ
9463 return CMD_SUCCESS;
9464}
9465
b9c7bc5a
PZ
9466DEFPY (af_rt_vpn_imexport,
9467 af_rt_vpn_imexport_cmd,
9468 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9469 NO_STR
9470 "Specify route target list\n"
ddb5b488 9471 "Specify route target list\n"
b9c7bc5a
PZ
9472 "Between current address-family and vpn\n"
9473 "For routes leaked from vpn to current address-family: match any\n"
9474 "For routes leaked from current address-family to vpn: set\n"
9475 "both import: match any and export: set\n"
ddb5b488
PZ
9476 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9477{
9478 VTY_DECLVAR_CONTEXT(bgp, bgp);
9479 int ret;
9480 struct ecommunity *ecom = NULL;
9481 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 9482 enum vpn_policy_direction dir;
ddb5b488
PZ
9483 afi_t afi;
9484 int idx = 0;
c6423c31 9485 bool yes = true;
ddb5b488 9486
b9c7bc5a 9487 if (argv_find(argv, argc, "no", &idx))
c6423c31 9488 yes = false;
b9c7bc5a 9489
0ca70ba5 9490 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9491 if (afi == AFI_MAX)
9492 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9493
b9c7bc5a 9494 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
9495 if (ret != CMD_SUCCESS)
9496 return ret;
9497
b9c7bc5a
PZ
9498 if (yes) {
9499 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9500 vty_out(vty, "%% Missing RTLIST\n");
9501 return CMD_WARNING_CONFIG_FAILED;
9502 }
c6423c31 9503 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
9504 if (ret != CMD_SUCCESS) {
9505 return ret;
9506 }
ddb5b488
PZ
9507 }
9508
69b07479
DS
9509 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9510 if (!dodir[dir])
ddb5b488 9511 continue;
ddb5b488 9512
69b07479 9513 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9514
69b07479
DS
9515 if (yes) {
9516 if (bgp->vpn_policy[afi].rtlist[dir])
9517 ecommunity_free(
9518 &bgp->vpn_policy[afi].rtlist[dir]);
9519 bgp->vpn_policy[afi].rtlist[dir] =
9520 ecommunity_dup(ecom);
9521 } else {
9522 if (bgp->vpn_policy[afi].rtlist[dir])
9523 ecommunity_free(
9524 &bgp->vpn_policy[afi].rtlist[dir]);
9525 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 9526 }
69b07479
DS
9527
9528 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9529 }
69b07479 9530
d555f3e9
PZ
9531 if (ecom)
9532 ecommunity_free(&ecom);
ddb5b488
PZ
9533
9534 return CMD_SUCCESS;
9535}
9536
b9c7bc5a
PZ
9537ALIAS (af_rt_vpn_imexport,
9538 af_no_rt_vpn_imexport_cmd,
9539 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
9540 NO_STR
9541 "Specify route target list\n"
b9c7bc5a
PZ
9542 "Specify route target list\n"
9543 "Between current address-family and vpn\n"
9544 "For routes leaked from vpn to current address-family\n"
9545 "For routes leaked from current address-family to vpn\n"
9546 "both import and export\n")
9547
585f1adc 9548DEFPY (af_route_map_vpn_imexport,
b9c7bc5a
PZ
9549 af_route_map_vpn_imexport_cmd,
9550/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9551 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9552 NO_STR
ddb5b488 9553 "Specify route map\n"
b9c7bc5a
PZ
9554 "Between current address-family and vpn\n"
9555 "For routes leaked from vpn to current address-family\n"
9556 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9557 "name of route-map\n")
9558{
585f1adc
IR
9559 VTY_DECLVAR_CONTEXT(bgp, bgp);
9560 int ret;
9561 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 9562 enum vpn_policy_direction dir;
ddb5b488 9563 afi_t afi;
ddb5b488 9564 int idx = 0;
585f1adc 9565 bool yes = true;
ddb5b488 9566
585f1adc
IR
9567 if (argv_find(argv, argc, "no", &idx))
9568 yes = false;
ddb5b488 9569
585f1adc
IR
9570 afi = vpn_policy_getafi(vty, bgp, false);
9571 if (afi == AFI_MAX)
9572 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9573
585f1adc
IR
9574 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9575 if (ret != CMD_SUCCESS)
9576 return ret;
ddb5b488 9577
585f1adc
IR
9578 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9579 if (!dodir[dir])
9580 continue;
69b07479 9581
585f1adc
IR
9582 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9583
9584 if (yes) {
9585 if (bgp->vpn_policy[afi].rmap_name[dir])
9586 XFREE(MTYPE_ROUTE_MAP_NAME,
9587 bgp->vpn_policy[afi].rmap_name[dir]);
9588 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9589 MTYPE_ROUTE_MAP_NAME, rmap_str);
9590 bgp->vpn_policy[afi].rmap[dir] =
9591 route_map_lookup_warn_noexist(vty, rmap_str);
9592 if (!bgp->vpn_policy[afi].rmap[dir])
9593 return CMD_SUCCESS;
9594 } else {
9595 if (bgp->vpn_policy[afi].rmap_name[dir])
9596 XFREE(MTYPE_ROUTE_MAP_NAME,
9597 bgp->vpn_policy[afi].rmap_name[dir]);
9598 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9599 bgp->vpn_policy[afi].rmap[dir] = NULL;
9600 }
9601
9602 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9603 }
ddb5b488 9604
585f1adc 9605 return CMD_SUCCESS;
ddb5b488
PZ
9606}
9607
b9c7bc5a
PZ
9608ALIAS (af_route_map_vpn_imexport,
9609 af_no_route_map_vpn_imexport_cmd,
9610 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
9611 NO_STR
9612 "Specify route map\n"
b9c7bc5a
PZ
9613 "Between current address-family and vpn\n"
9614 "For routes leaked from vpn to current address-family\n"
9615 "For routes leaked from current address-family to vpn\n")
9616
bb4f6190 9617DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 9618 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
9619 "Import routes from another VRF\n"
9620 "Vrf routes being filtered\n"
9621 "Specify route map\n"
9622 "name of route-map\n")
9623{
9624 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 9625 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
bb4f6190 9626 afi_t afi;
bb4f6190
DS
9627 struct bgp *bgp_default;
9628
0ca70ba5 9629 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
9630 if (afi == AFI_MAX)
9631 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
9632
9633 bgp_default = bgp_get_default();
9634 if (!bgp_default) {
9635 int32_t ret;
9636 as_t as = bgp->as;
9637
9638 /* Auto-create assuming the same AS */
5d5393b9 9639 ret = bgp_get_vty(&bgp_default, &as, NULL,
e55b0883
PG
9640 BGP_INSTANCE_TYPE_DEFAULT, NULL,
9641 ASNOTATION_UNDEFINED);
bb4f6190
DS
9642
9643 if (ret) {
9644 vty_out(vty,
9645 "VRF default is not configured as a bgp instance\n");
9646 return CMD_WARNING;
9647 }
9648 }
9649
69b07479 9650 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 9651
ae6a6fb4
DS
9652 if (bgp->vpn_policy[afi].rmap_name[dir])
9653 XFREE(MTYPE_ROUTE_MAP_NAME,
9654 bgp->vpn_policy[afi].rmap_name[dir]);
9655 bgp->vpn_policy[afi].rmap_name[dir] =
9656 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9657 bgp->vpn_policy[afi].rmap[dir] =
9658 route_map_lookup_warn_noexist(vty, rmap_str);
9659 if (!bgp->vpn_policy[afi].rmap[dir])
9660 return CMD_SUCCESS;
9661
9662 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9663 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 9664
69b07479
DS
9665 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9666
bb4f6190
DS
9667 return CMD_SUCCESS;
9668}
9669
ae6a6fb4
DS
9670DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9671 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
9672 NO_STR
9673 "Import routes from another VRF\n"
9674 "Vrf routes being filtered\n"
ae6a6fb4
DS
9675 "Specify route map\n"
9676 "name of route-map\n")
9677{
9678 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 9679 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
ae6a6fb4
DS
9680 afi_t afi;
9681
9682 afi = vpn_policy_getafi(vty, bgp, true);
9683 if (afi == AFI_MAX)
9684 return CMD_WARNING_CONFIG_FAILED;
9685
9686 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9687
9688 if (bgp->vpn_policy[afi].rmap_name[dir])
9689 XFREE(MTYPE_ROUTE_MAP_NAME,
9690 bgp->vpn_policy[afi].rmap_name[dir]);
9691 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9692 bgp->vpn_policy[afi].rmap[dir] = NULL;
9693
9694 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9695 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9696 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9697
9698 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9699
9700 return CMD_SUCCESS;
9701}
bb4f6190 9702
585f1adc
IR
9703DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9704 "[no] import vrf VIEWVRFNAME$import_name",
9705 NO_STR
9706 "Import routes from another VRF\n"
9707 "VRF to import from\n"
9708 "The name of the VRF\n")
12a844a5 9709{
585f1adc
IR
9710 VTY_DECLVAR_CONTEXT(bgp, bgp);
9711 struct listnode *node;
9712 struct bgp *vrf_bgp, *bgp_default;
9713 int32_t ret = 0;
9714 as_t as = bgp->as;
9715 bool remove = false;
9716 int32_t idx = 0;
9717 char *vname;
9718 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
9719 safi_t safi;
9720 afi_t afi;
9721
867f0cca 9722 if (import_name == NULL) {
9723 vty_out(vty, "%% Missing import name\n");
9724 return CMD_WARNING;
9725 }
9726
ae6a6fb4
DS
9727 if (strcmp(import_name, "route-map") == 0) {
9728 vty_out(vty, "%% Must include route-map name\n");
9729 return CMD_WARNING;
9730 }
9731
585f1adc
IR
9732 if (argv_find(argv, argc, "no", &idx))
9733 remove = true;
9734
9735 afi = vpn_policy_getafi(vty, bgp, true);
9736 if (afi == AFI_MAX)
9737 return CMD_WARNING_CONFIG_FAILED;
9738
12a844a5
DS
9739 safi = bgp_node_safi(vty);
9740
585f1adc
IR
9741 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9742 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9743 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9744 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9745 remove ? "unimport" : "import", import_name);
9746 return CMD_WARNING;
9747 }
25679caa 9748
585f1adc
IR
9749 bgp_default = bgp_get_default();
9750 if (!bgp_default) {
9751 /* Auto-create assuming the same AS */
9752 ret = bgp_get_vty(&bgp_default, &as, NULL,
e55b0883
PG
9753 BGP_INSTANCE_TYPE_DEFAULT, NULL,
9754 ASNOTATION_UNDEFINED);
12a844a5 9755
585f1adc
IR
9756 if (ret) {
9757 vty_out(vty,
9758 "VRF default is not configured as a bgp instance\n");
9759 return CMD_WARNING;
9760 }
9761 }
12a844a5 9762
585f1adc
IR
9763 vrf_bgp = bgp_lookup_by_name(import_name);
9764 if (!vrf_bgp) {
9765 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9766 vrf_bgp = bgp_default;
9767 else
9768 /* Auto-create assuming the same AS */
e55b0883
PG
9769 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type,
9770 NULL, ASNOTATION_UNDEFINED);
585f1adc
IR
9771 if (ret) {
9772 vty_out(vty,
9773 "VRF %s is not configured as a bgp instance\n",
9774 import_name);
9775 return CMD_WARNING;
9776 }
9777 }
9778
9779 if (remove) {
9780 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9781 } else {
9782 /* Already importing from "import_vrf"? */
9783 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9784 vname)) {
9785 if (strcmp(vname, import_name) == 0)
9786 return CMD_WARNING;
9787 }
9788
9789 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9790 }
9791
9792 return CMD_SUCCESS;
12a844a5
DS
9793}
9794
b9c7bc5a 9795/* This command is valid only in a bgp vrf instance or the default instance */
585f1adc 9796DEFPY (bgp_imexport_vpn,
b9c7bc5a
PZ
9797 bgp_imexport_vpn_cmd,
9798 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9799 NO_STR
9800 "Import routes to this address-family\n"
9801 "Export routes from this address-family\n"
9802 "to/from default instance VPN RIB\n")
ddb5b488 9803{
585f1adc
IR
9804 VTY_DECLVAR_CONTEXT(bgp, bgp);
9805 int previous_state;
37a87b8f 9806 afi_t afi;
585f1adc
IR
9807 safi_t safi;
9808 int idx = 0;
9809 bool yes = true;
9810 int flag;
9c2fd3fe 9811 enum vpn_policy_direction dir;
585f1adc
IR
9812
9813 if (argv_find(argv, argc, "no", &idx))
9814 yes = false;
9815
9816 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9817 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9818
9819 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9820 return CMD_WARNING_CONFIG_FAILED;
9821 }
ddb5b488 9822
b9c7bc5a
PZ
9823 afi = bgp_node_afi(vty);
9824 safi = bgp_node_safi(vty);
585f1adc
IR
9825 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9826 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9827 return CMD_WARNING_CONFIG_FAILED;
9828 }
ddb5b488 9829
b9c7bc5a 9830 if (!strcmp(direction_str, "import")) {
585f1adc
IR
9831 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9832 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b9c7bc5a 9833 } else if (!strcmp(direction_str, "export")) {
585f1adc
IR
9834 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9835 dir = BGP_VPN_POLICY_DIR_TOVPN;
b9c7bc5a
PZ
9836 } else {
9837 vty_out(vty, "%% unknown direction %s\n", direction_str);
9838 return CMD_WARNING_CONFIG_FAILED;
9839 }
9840
585f1adc 9841 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 9842
585f1adc
IR
9843 if (yes) {
9844 SET_FLAG(bgp->af_flags[afi][safi], flag);
9845 if (!previous_state) {
9846 /* trigger export current vrf */
9847 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9848 }
9849 } else {
9850 if (previous_state) {
9851 /* trigger un-export current vrf */
9852 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9853 }
9854 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9855 }
37a87b8f 9856
1ca2fd11
IR
9857 hook_call(bgp_snmp_init_stats, bgp);
9858
585f1adc 9859 return CMD_SUCCESS;
ddb5b488
PZ
9860}
9861
301ad80a
PG
9862DEFPY (af_routetarget_import,
9863 af_routetarget_import_cmd,
9a659715 9864 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9865 NO_STR
9866 "Specify route target list\n"
9867 "Specify route target list\n"
9a659715
PG
9868 "Specify route target list\n"
9869 "Specify route target list\n"
301ad80a
PG
9870 "Flow-spec redirect type route target\n"
9871 "Import routes to this address-family\n"
9a659715 9872 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9873{
9874 VTY_DECLVAR_CONTEXT(bgp, bgp);
9875 int ret;
9876 struct ecommunity *ecom = NULL;
301ad80a 9877 afi_t afi;
9a659715 9878 int idx = 0, idx_unused = 0;
c6423c31
PG
9879 bool yes = true;
9880 bool rt6 = false;
301ad80a
PG
9881
9882 if (argv_find(argv, argc, "no", &idx))
c6423c31 9883 yes = false;
301ad80a 9884
9a659715
PG
9885 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9886 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9887 rt6 = true;
301ad80a 9888
0ca70ba5 9889 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9890 if (afi == AFI_MAX)
9891 return CMD_WARNING_CONFIG_FAILED;
9892
9a659715
PG
9893 if (rt6 && afi != AFI_IP6)
9894 return CMD_WARNING_CONFIG_FAILED;
9895
301ad80a
PG
9896 if (yes) {
9897 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9898 vty_out(vty, "%% Missing RTLIST\n");
9899 return CMD_WARNING_CONFIG_FAILED;
9900 }
9a659715 9901 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9902 if (ret != CMD_SUCCESS)
9903 return ret;
9904 }
69b07479
DS
9905
9906 if (yes) {
9907 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9908 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9909 .import_redirect_rtlist);
69b07479
DS
9910 bgp->vpn_policy[afi].import_redirect_rtlist =
9911 ecommunity_dup(ecom);
9912 } else {
9913 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9914 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9915 .import_redirect_rtlist);
69b07479 9916 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9917 }
69b07479 9918
301ad80a
PG
9919 if (ecom)
9920 ecommunity_free(&ecom);
9921
9922 return CMD_SUCCESS;
9923}
9924
505e5056 9925DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9926 address_family_ipv4_safi_cmd,
9927 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9928 "Enter Address Family command mode\n"
00e6edb9 9929 BGP_AF_STR
7c40bf39 9930 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9931{
f51bae9c 9932
d62a17ae 9933 if (argc == 3) {
585f1adc
IR
9934 VTY_DECLVAR_CONTEXT(bgp, bgp);
9935 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9936 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9937 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9938 && safi != SAFI_EVPN) {
31947174
MK
9939 vty_out(vty,
9940 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9941 return CMD_WARNING_CONFIG_FAILED;
9942 }
585f1adc
IR
9943 vty->node = bgp_node_type(AFI_IP, safi);
9944 } else
9945 vty->node = BGP_IPV4_NODE;
718e3744 9946
d62a17ae 9947 return CMD_SUCCESS;
718e3744 9948}
9949
505e5056 9950DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9951 address_family_ipv6_safi_cmd,
9952 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9953 "Enter Address Family command mode\n"
00e6edb9 9954 BGP_AF_STR
7c40bf39 9955 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9956{
d62a17ae 9957 if (argc == 3) {
585f1adc
IR
9958 VTY_DECLVAR_CONTEXT(bgp, bgp);
9959 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9960 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9961 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9962 && safi != SAFI_EVPN) {
31947174
MK
9963 vty_out(vty,
9964 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9965 return CMD_WARNING_CONFIG_FAILED;
9966 }
585f1adc
IR
9967 vty->node = bgp_node_type(AFI_IP6, safi);
9968 } else
9969 vty->node = BGP_IPV6_NODE;
25ffbdc1 9970
d62a17ae 9971 return CMD_SUCCESS;
25ffbdc1 9972}
718e3744 9973
d6902373 9974#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9975DEFUN_NOSH (address_family_vpnv4,
718e3744 9976 address_family_vpnv4_cmd,
8334fd5a 9977 "address-family vpnv4 [unicast]",
718e3744 9978 "Enter Address Family command mode\n"
00e6edb9
DA
9979 BGP_AF_STR
9980 BGP_AF_MODIFIER_STR)
718e3744 9981{
d62a17ae 9982 vty->node = BGP_VPNV4_NODE;
9983 return CMD_SUCCESS;
718e3744 9984}
9985
505e5056 9986DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9987 address_family_vpnv6_cmd,
8334fd5a 9988 "address-family vpnv6 [unicast]",
8ecd3266 9989 "Enter Address Family command mode\n"
00e6edb9
DA
9990 BGP_AF_STR
9991 BGP_AF_MODIFIER_STR)
8ecd3266 9992{
d62a17ae 9993 vty->node = BGP_VPNV6_NODE;
9994 return CMD_SUCCESS;
8ecd3266 9995}
64e4a6c5 9996#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9997
505e5056 9998DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9999 address_family_evpn_cmd,
7111c1a0 10000 "address-family l2vpn evpn",
4e0b7b6d 10001 "Enter Address Family command mode\n"
00e6edb9
DA
10002 BGP_AF_STR
10003 BGP_AF_MODIFIER_STR)
4e0b7b6d 10004{
2131d5cf 10005 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 10006 vty->node = BGP_EVPN_NODE;
10007 return CMD_SUCCESS;
4e0b7b6d
PG
10008}
10009
bfaab44d
HS
10010DEFUN_NOSH (bgp_segment_routing_srv6,
10011 bgp_segment_routing_srv6_cmd,
10012 "segment-routing srv6",
10013 "Segment-Routing configuration\n"
10014 "Segment-Routing SRv6 configuration\n")
10015{
10016 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 10017 bgp->srv6_enabled = true;
bfaab44d
HS
10018 vty->node = BGP_SRV6_NODE;
10019 return CMD_SUCCESS;
10020}
10021
0249b8b6
HS
10022DEFUN (no_bgp_segment_routing_srv6,
10023 no_bgp_segment_routing_srv6_cmd,
10024 "no segment-routing srv6",
10025 NO_STR
10026 "Segment-Routing configuration\n"
10027 "Segment-Routing SRv6 configuration\n")
10028{
10029 VTY_DECLVAR_CONTEXT(bgp, bgp);
10030
10031 if (strlen(bgp->srv6_locator_name) > 0)
10032 if (bgp_srv6_locator_unset(bgp) < 0)
10033 return CMD_WARNING_CONFIG_FAILED;
10034
10035 bgp->srv6_enabled = false;
10036 return CMD_SUCCESS;
10037}
10038
a0281b2e
HS
10039DEFPY (bgp_srv6_locator,
10040 bgp_srv6_locator_cmd,
10041 "locator NAME$name",
10042 "Specify SRv6 locator\n"
10043 "Specify SRv6 locator\n")
10044{
10045 VTY_DECLVAR_CONTEXT(bgp, bgp);
7de4c885 10046 int ret;
a0281b2e
HS
10047
10048 if (strlen(bgp->srv6_locator_name) > 0
10049 && strcmp(name, bgp->srv6_locator_name) != 0) {
10050 vty_out(vty, "srv6 locator is already configured\n");
10051 return CMD_WARNING_CONFIG_FAILED;
7de4c885
HS
10052 }
10053
10054 snprintf(bgp->srv6_locator_name,
10055 sizeof(bgp->srv6_locator_name), "%s", name);
a0281b2e 10056
7de4c885 10057 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
a0281b2e
HS
10058 if (ret < 0)
10059 return CMD_WARNING_CONFIG_FAILED;
10060
10061 return CMD_SUCCESS;
10062}
10063
0249b8b6
HS
10064DEFPY (no_bgp_srv6_locator,
10065 no_bgp_srv6_locator_cmd,
10066 "no locator NAME$name",
10067 NO_STR
10068 "Specify SRv6 locator\n"
10069 "Specify SRv6 locator\n")
10070{
10071 VTY_DECLVAR_CONTEXT(bgp, bgp);
10072
10073 /* when locator isn't configured, do nothing */
10074 if (strlen(bgp->srv6_locator_name) < 1)
10075 return CMD_SUCCESS;
10076
10077 /* name validation */
10078 if (strcmp(name, bgp->srv6_locator_name) != 0) {
10079 vty_out(vty, "%% No srv6 locator is configured\n");
10080 return CMD_WARNING_CONFIG_FAILED;
10081 }
10082
10083 /* unset locator */
10084 if (bgp_srv6_locator_unset(bgp) < 0)
10085 return CMD_WARNING_CONFIG_FAILED;
10086
10087 return CMD_SUCCESS;
10088}
10089
ea372e81
HS
10090DEFPY (show_bgp_srv6,
10091 show_bgp_srv6_cmd,
10092 "show bgp segment-routing srv6",
10093 SHOW_STR
10094 BGP_STR
10095 "BGP Segment Routing\n"
10096 "BGP Segment Routing SRv6\n")
10097{
10098 struct bgp *bgp;
10099 struct listnode *node;
1c21a234 10100 struct srv6_locator_chunk *chunk;
ea372e81 10101 struct bgp_srv6_function *func;
ea372e81
HS
10102
10103 bgp = bgp_get_default();
96db4340 10104 if (!bgp)
ea372e81
HS
10105 return CMD_SUCCESS;
10106
10107 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
10108 vty_out(vty, "locator_chunks:\n");
dccef127 10109 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
511211bf 10110 vty_out(vty, "- %pFX\n", &chunk->prefix);
dccef127
CS
10111 vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
10112 vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
10113 vty_out(vty, " func-length: %d\n",
10114 chunk->function_bits_length);
10115 vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
10116 }
ea372e81
HS
10117
10118 vty_out(vty, "functions:\n");
10119 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
07380148 10120 vty_out(vty, "- sid: %pI6\n", &func->sid);
ea372e81
HS
10121 vty_out(vty, " locator: %s\n", func->locator_name);
10122 }
10123
10124 vty_out(vty, "bgps:\n");
10125 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
10126 vty_out(vty, "- name: %s\n",
10127 bgp->name ? bgp->name : "default");
10128
1830895a
CS
10129 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
10130 bgp->vpn_policy[AFI_IP].tovpn_sid);
10131 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
10132 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9f5d4430 10133 vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
ea372e81
HS
10134 }
10135
10136 return CMD_SUCCESS;
10137}
10138
505e5056 10139DEFUN_NOSH (exit_address_family,
718e3744 10140 exit_address_family_cmd,
10141 "exit-address-family",
10142 "Exit from Address Family configuration mode\n")
10143{
d62a17ae 10144 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
10145 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
10146 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
10147 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
10148 || vty->node == BGP_EVPN_NODE
10149 || vty->node == BGP_FLOWSPECV4_NODE
10150 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 10151 vty->node = BGP_NODE;
10152 return CMD_SUCCESS;
718e3744 10153}
6b0655a2 10154
8ad7271d 10155/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 10156static int bgp_clear_prefix(struct vty *vty, const char *view_name,
10157 const char *ip_str, afi_t afi, safi_t safi,
10158 struct prefix_rd *prd)
10159{
10160 int ret;
10161 struct prefix match;
9bcb3eef
DS
10162 struct bgp_dest *dest;
10163 struct bgp_dest *rm;
d62a17ae 10164 struct bgp *bgp;
10165 struct bgp_table *table;
10166 struct bgp_table *rib;
10167
10168 /* BGP structure lookup. */
10169 if (view_name) {
10170 bgp = bgp_lookup_by_name(view_name);
10171 if (bgp == NULL) {
10172 vty_out(vty, "%% Can't find BGP instance %s\n",
10173 view_name);
10174 return CMD_WARNING;
10175 }
10176 } else {
10177 bgp = bgp_get_default();
10178 if (bgp == NULL) {
10179 vty_out(vty, "%% No BGP process is configured\n");
10180 return CMD_WARNING;
10181 }
10182 }
10183
10184 /* Check IP address argument. */
10185 ret = str2prefix(ip_str, &match);
10186 if (!ret) {
10187 vty_out(vty, "%% address is malformed\n");
10188 return CMD_WARNING;
10189 }
10190
10191 match.family = afi2family(afi);
10192 rib = bgp->rib[afi][safi];
10193
10194 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
10195 for (dest = bgp_table_top(rib); dest;
10196 dest = bgp_route_next(dest)) {
10197 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 10198
9bcb3eef 10199 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 10200 continue;
10201
9bcb3eef 10202 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
10203 if (table == NULL)
10204 continue;
10205
4953391b
DA
10206 rm = bgp_node_match(table, &match);
10207 if (rm != NULL) {
b54892e0 10208 const struct prefix *rm_p =
9bcb3eef 10209 bgp_dest_get_prefix(rm);
b54892e0
DS
10210
10211 if (rm_p->prefixlen == match.prefixlen) {
10212 SET_FLAG(rm->flags,
10213 BGP_NODE_USER_CLEAR);
10214 bgp_process(bgp, rm, afi, safi);
d62a17ae 10215 }
9bcb3eef 10216 bgp_dest_unlock_node(rm);
d62a17ae 10217 }
10218 }
10219 } else {
4953391b
DA
10220 dest = bgp_node_match(rib, &match);
10221 if (dest != NULL) {
9bcb3eef 10222 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 10223
9bcb3eef
DS
10224 if (dest_p->prefixlen == match.prefixlen) {
10225 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10226 bgp_process(bgp, dest, afi, safi);
d62a17ae 10227 }
9bcb3eef 10228 bgp_dest_unlock_node(dest);
d62a17ae 10229 }
10230 }
10231
10232 return CMD_SUCCESS;
8ad7271d
DS
10233}
10234
b09b5ae0 10235/* one clear bgp command to rule them all */
718e3744 10236DEFUN (clear_ip_bgp_all,
10237 clear_ip_bgp_all_cmd,
8079a413 10238 "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 10239 CLEAR_STR
10240 IP_STR
10241 BGP_STR
838758ac 10242 BGP_INSTANCE_HELP_STR
510afcd6 10243 BGP_AFI_HELP_STR
00e6edb9 10244 BGP_AF_STR
510afcd6 10245 BGP_SAFI_WITH_LABEL_HELP_STR
00e6edb9 10246 BGP_AF_MODIFIER_STR
b09b5ae0 10247 "Clear all peers\n"
453c92f6 10248 "BGP IPv4 neighbor to clear\n"
a80beece 10249 "BGP IPv6 neighbor to clear\n"
838758ac 10250 "BGP neighbor on interface to clear\n"
8079a413 10251 "Clear peers with the AS number in plain or dotted format\n"
b09b5ae0 10252 "Clear all external peers\n"
718e3744 10253 "Clear all members of peer-group\n"
b09b5ae0 10254 "BGP peer-group name\n"
b09b5ae0
DW
10255 BGP_SOFT_STR
10256 BGP_SOFT_IN_STR
b09b5ae0
DW
10257 BGP_SOFT_OUT_STR
10258 BGP_SOFT_IN_STR
10259 "Push out prefix-list ORF and do inbound soft reconfig\n"
3cb14f26
DS
10260 BGP_SOFT_OUT_STR
10261 "Reset message statistics\n")
718e3744 10262{
d62a17ae 10263 char *vrf = NULL;
10264
dc912615
DS
10265 afi_t afi = AFI_UNSPEC;
10266 safi_t safi = SAFI_UNSPEC;
d62a17ae 10267 enum clear_sort clr_sort = clear_peer;
10268 enum bgp_clear_type clr_type;
10269 char *clr_arg = NULL;
10270
10271 int idx = 0;
10272
10273 /* clear [ip] bgp */
10274 if (argv_find(argv, argc, "ip", &idx))
10275 afi = AFI_IP;
10276
9a8bdf1c
PG
10277 /* [<vrf> VIEWVRFNAME] */
10278 if (argv_find(argv, argc, "vrf", &idx)) {
10279 vrf = argv[idx + 1]->arg;
10280 idx += 2;
10281 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10282 vrf = NULL;
10283 } else if (argv_find(argv, argc, "view", &idx)) {
10284 /* [<view> VIEWVRFNAME] */
d62a17ae 10285 vrf = argv[idx + 1]->arg;
10286 idx += 2;
10287 }
d62a17ae 10288 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10289 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10290 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10291
8079a413 10292 /* <*|A.B.C.D|X:X::X:X|WORD|ASNUM|external|peer-group PGNAME> */
d62a17ae 10293 if (argv_find(argv, argc, "*", &idx)) {
10294 clr_sort = clear_all;
10295 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10296 clr_sort = clear_peer;
10297 clr_arg = argv[idx]->arg;
10298 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10299 clr_sort = clear_peer;
10300 clr_arg = argv[idx]->arg;
10301 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10302 clr_sort = clear_group;
10303 idx++;
10304 clr_arg = argv[idx]->arg;
d7b9898c 10305 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 10306 clr_sort = clear_peer;
10307 clr_arg = argv[idx]->arg;
8fa7d444
DS
10308 } else if (argv_find(argv, argc, "WORD", &idx)) {
10309 clr_sort = clear_peer;
10310 clr_arg = argv[idx]->arg;
8079a413 10311 } else if (argv_find(argv, argc, "ASNUM", &idx)) {
d62a17ae 10312 clr_sort = clear_as;
10313 clr_arg = argv[idx]->arg;
10314 } else if (argv_find(argv, argc, "external", &idx)) {
10315 clr_sort = clear_external;
10316 }
10317
3cb14f26 10318 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
d62a17ae 10319 if (argv_find(argv, argc, "soft", &idx)) {
10320 if (argv_find(argv, argc, "in", &idx)
10321 || argv_find(argv, argc, "out", &idx))
10322 clr_type = strmatch(argv[idx]->text, "in")
10323 ? BGP_CLEAR_SOFT_IN
10324 : BGP_CLEAR_SOFT_OUT;
10325 else
10326 clr_type = BGP_CLEAR_SOFT_BOTH;
10327 } else if (argv_find(argv, argc, "in", &idx)) {
10328 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10329 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10330 : BGP_CLEAR_SOFT_IN;
10331 } else if (argv_find(argv, argc, "out", &idx)) {
10332 clr_type = BGP_CLEAR_SOFT_OUT;
3cb14f26
DS
10333 } else if (argv_find(argv, argc, "message-stats", &idx)) {
10334 clr_type = BGP_CLEAR_MESSAGE_STATS;
d62a17ae 10335 } else
10336 clr_type = BGP_CLEAR_SOFT_NONE;
10337
1ca2fd11 10338 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 10339}
01080f7c 10340
8ad7271d
DS
10341DEFUN (clear_ip_bgp_prefix,
10342 clear_ip_bgp_prefix_cmd,
18c57037 10343 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
10344 CLEAR_STR
10345 IP_STR
10346 BGP_STR
838758ac 10347 BGP_INSTANCE_HELP_STR
8ad7271d 10348 "Clear bestpath and re-advertise\n"
0c7b1b01 10349 "IPv4 prefix\n")
8ad7271d 10350{
d62a17ae 10351 char *vrf = NULL;
10352 char *prefix = NULL;
8ad7271d 10353
d62a17ae 10354 int idx = 0;
01080f7c 10355
d62a17ae 10356 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
10357 if (argv_find(argv, argc, "vrf", &idx)) {
10358 vrf = argv[idx + 1]->arg;
10359 idx += 2;
10360 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10361 vrf = NULL;
10362 } else if (argv_find(argv, argc, "view", &idx)) {
10363 /* [<view> VIEWVRFNAME] */
10364 vrf = argv[idx + 1]->arg;
10365 idx += 2;
10366 }
0c7b1b01 10367
d62a17ae 10368 prefix = argv[argc - 1]->arg;
8ad7271d 10369
d62a17ae 10370 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 10371}
8ad7271d 10372
b09b5ae0
DW
10373DEFUN (clear_bgp_ipv6_safi_prefix,
10374 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 10375 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10376 CLEAR_STR
3a2d747c 10377 IP_STR
718e3744 10378 BGP_STR
00e6edb9 10379 BGP_AF_STR
46f296b4 10380 BGP_SAFI_HELP_STR
b09b5ae0 10381 "Clear bestpath and re-advertise\n"
0c7b1b01 10382 "IPv6 prefix\n")
718e3744 10383{
9b475e76
PG
10384 int idx_safi = 0;
10385 int idx_ipv6_prefix = 0;
10386 safi_t safi = SAFI_UNICAST;
10387 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10388 argv[idx_ipv6_prefix]->arg : NULL;
10389
10390 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 10391 return bgp_clear_prefix(
9b475e76
PG
10392 vty, NULL, prefix, AFI_IP6,
10393 safi, NULL);
838758ac 10394}
01080f7c 10395
b09b5ae0
DW
10396DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10397 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 10398 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10399 CLEAR_STR
3a2d747c 10400 IP_STR
718e3744 10401 BGP_STR
838758ac 10402 BGP_INSTANCE_HELP_STR
00e6edb9 10403 BGP_AF_STR
46f296b4 10404 BGP_SAFI_HELP_STR
b09b5ae0 10405 "Clear bestpath and re-advertise\n"
0c7b1b01 10406 "IPv6 prefix\n")
718e3744 10407{
9b475e76 10408 int idx_safi = 0;
9a8bdf1c 10409 int idx_vrfview = 0;
9b475e76
PG
10410 int idx_ipv6_prefix = 0;
10411 safi_t safi = SAFI_UNICAST;
10412 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10413 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 10414 char *vrfview = NULL;
9b475e76 10415
9a8bdf1c
PG
10416 /* [<view|vrf> VIEWVRFNAME] */
10417 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10418 vrfview = argv[idx_vrfview + 1]->arg;
10419 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10420 vrfview = NULL;
10421 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10422 /* [<view> VIEWVRFNAME] */
10423 vrfview = argv[idx_vrfview + 1]->arg;
10424 }
9b475e76
PG
10425 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10426
d62a17ae 10427 return bgp_clear_prefix(
9b475e76
PG
10428 vty, vrfview, prefix,
10429 AFI_IP6, safi, NULL);
718e3744 10430}
10431
b09b5ae0
DW
10432DEFUN (show_bgp_views,
10433 show_bgp_views_cmd,
d6e3c605 10434 "show [ip] bgp views",
b09b5ae0 10435 SHOW_STR
d6e3c605 10436 IP_STR
01080f7c 10437 BGP_STR
b09b5ae0 10438 "Show the defined BGP views\n")
01080f7c 10439{
d62a17ae 10440 struct list *inst = bm->bgp;
10441 struct listnode *node;
10442 struct bgp *bgp;
01080f7c 10443
d62a17ae 10444 vty_out(vty, "Defined BGP views:\n");
10445 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10446 /* Skip VRFs. */
10447 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10448 continue;
9eb11997
PG
10449 vty_out(vty, "\t%s (AS%s)\n", bgp->name ? bgp->name : "(null)",
10450 bgp->as_pretty);
d62a17ae 10451 }
e52702f2 10452
d62a17ae 10453 return CMD_SUCCESS;
e0081f70
ML
10454}
10455
4acd6bc9
SPG
10456static inline void calc_peers_cfgd_estbd(struct bgp *bgp, int *peers_cfgd,
10457 int *peers_estbd)
10458{
10459 struct peer *peer;
10460 struct listnode *node;
10461
10462 *peers_cfgd = *peers_estbd = 0;
10463 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
10464 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10465 continue;
10466 (*peers_cfgd)++;
10467 if (peer_established(peer))
10468 (*peers_estbd)++;
10469 }
10470}
10471
10472static void print_bgp_vrfs(struct bgp *bgp, struct vty *vty, json_object *json,
10473 const char *type)
10474{
10475 int peers_cfg, peers_estb;
10476
10477 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10478
10479 if (json) {
10480 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10481 ? -1
10482 : (int64_t)bgp->vrf_id;
10483 json_object_string_add(json, "type", type);
10484 json_object_int_add(json, "vrfId", vrf_id_ui);
10485 json_object_string_addf(json, "routerId", "%pI4",
10486 &bgp->router_id);
10487 json_object_int_add(json, "numConfiguredPeers", peers_cfg);
10488 json_object_int_add(json, "numEstablishedPeers", peers_estb);
10489 json_object_int_add(json, "l3vni", bgp->l3vni);
10490 json_object_string_addf(json, "rmac", "%pEA", &bgp->rmac);
10491 json_object_string_add(
10492 json, "interface",
10493 ifindex2ifname(bgp->l3vni_svi_ifindex, bgp->vrf_id));
10494 }
10495}
10496
10497static int show_bgp_vrfs_detail_common(struct vty *vty, struct bgp *bgp,
10498 json_object *json, const char *name,
10499 const char *type, bool use_vrf)
10500{
10501 int peers_cfg, peers_estb;
10502
10503 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10504
10505 if (use_vrf) {
10506 if (json) {
10507 print_bgp_vrfs(bgp, vty, json, type);
10508 } else {
10509 vty_out(vty, "BGP instance %s VRF id %d\n",
10510 bgp->name_pretty,
10511 bgp->vrf_id == VRF_UNKNOWN ? -1
10512 : (int)bgp->vrf_id);
10513 vty_out(vty, "Router Id %pI4\n", &bgp->router_id);
10514 vty_out(vty,
10515 "Num Configured Peers %d, Established %d\n",
10516 peers_cfg, peers_estb);
10517 if (bgp->l3vni) {
10518 vty_out(vty,
10519 "L3VNI %u, L3VNI-SVI %s, Router MAC %pEA\n",
10520 bgp->l3vni,
10521 ifindex2ifname(bgp->l3vni_svi_ifindex,
10522 bgp->vrf_id),
10523 &bgp->rmac);
10524 }
10525 }
10526 } else {
10527 if (json) {
10528 print_bgp_vrfs(bgp, vty, json, type);
10529 } else {
10530 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10531 type,
10532 bgp->vrf_id == VRF_UNKNOWN ? -1
10533 : (int)bgp->vrf_id,
10534 &bgp->router_id, peers_cfg, peers_estb, name);
10535 vty_out(vty, "%11s %-16u %-21pEA %-20s\n", " ",
10536 bgp->l3vni, &bgp->rmac,
10537 ifindex2ifname(bgp->l3vni_svi_ifindex,
10538 bgp->vrf_id));
10539 }
10540 }
10541
10542 return CMD_SUCCESS;
10543}
10544
10545DEFPY (show_bgp_vrfs,
8386ac43 10546 show_bgp_vrfs_cmd,
4acd6bc9 10547 "show [ip] bgp vrfs [<VRFNAME$vrf_name>] [json]",
8386ac43 10548 SHOW_STR
d6e3c605 10549 IP_STR
8386ac43 10550 BGP_STR
10551 "Show BGP VRFs\n"
4acd6bc9 10552 "Specific VRF name\n"
9973d184 10553 JSON_STR)
8386ac43 10554{
d62a17ae 10555 struct list *inst = bm->bgp;
10556 struct listnode *node;
10557 struct bgp *bgp;
9f049418 10558 bool uj = use_json(argc, argv);
d62a17ae 10559 json_object *json = NULL;
10560 json_object *json_vrfs = NULL;
4acd6bc9 10561 json_object *json_vrf = NULL;
d62a17ae 10562 int count = 0;
4acd6bc9
SPG
10563 const char *name = vrf_name;
10564 const char *type;
d62a17ae 10565
4acd6bc9 10566 if (uj)
d62a17ae 10567 json = json_object_new_object();
4acd6bc9
SPG
10568
10569 if (name) {
10570 if (strmatch(name, VRF_DEFAULT_NAME)) {
10571 bgp = bgp_get_default();
10572 type = "DFLT";
10573 } else {
10574 bgp = bgp_lookup_by_name(name);
10575 type = "VRF";
10576 }
10577 if (!bgp) {
10578 if (uj)
10579 vty_json(vty, json);
10580 else
10581 vty_out(vty,
10582 "%% Specified BGP instance not found\n");
10583
10584 return CMD_WARNING;
10585 }
10586 }
10587
10588 if (vrf_name) {
10589 if (uj)
10590 json_vrf = json_object_new_object();
10591
10592 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10593 true);
10594
10595 if (uj) {
10596 json_object_object_add(json, name, json_vrf);
10597 vty_json(vty, json);
10598 }
10599
10600 return CMD_SUCCESS;
d62a17ae 10601 }
10602
4acd6bc9
SPG
10603 if (uj)
10604 json_vrfs = json_object_new_object();
10605
d62a17ae 10606 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
4acd6bc9 10607 const char *name;
d62a17ae 10608
10609 /* Skip Views. */
10610 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10611 continue;
10612
10613 count++;
efb4077a 10614 if (!uj && count == 1) {
fe1dc5a3 10615 vty_out(vty,
efb4077a 10616 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 10617 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
10618 "#PeersEstb", "Name");
10619 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10620 "L3-VNI", "RouterMAC", "Interface");
10621 }
d62a17ae 10622 if (uj)
10623 json_vrf = json_object_new_object();
10624
d62a17ae 10625 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 10626 name = VRF_DEFAULT_NAME;
d62a17ae 10627 type = "DFLT";
10628 } else {
10629 name = bgp->name;
10630 type = "VRF";
10631 }
10632
4acd6bc9
SPG
10633 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10634 false);
a8bf7d9c 10635
4acd6bc9 10636 if (uj)
d62a17ae 10637 json_object_object_add(json_vrfs, name, json_vrf);
d62a17ae 10638 }
10639
10640 if (uj) {
10641 json_object_object_add(json, "vrfs", json_vrfs);
d62a17ae 10642 json_object_int_add(json, "totalVrfs", count);
75eeda93 10643 vty_json(vty, json);
d62a17ae 10644 } else {
10645 if (count)
10646 vty_out(vty,
10647 "\nTotal number of VRFs (including default): %d\n",
10648 count);
10649 }
10650
10651 return CMD_SUCCESS;
8386ac43 10652}
10653
48ecf8f5
DS
10654DEFUN (show_bgp_mac_hash,
10655 show_bgp_mac_hash_cmd,
10656 "show bgp mac hash",
10657 SHOW_STR
10658 BGP_STR
10659 "Mac Address\n"
10660 "Mac Address database\n")
10661{
10662 bgp_mac_dump_table(vty);
10663
10664 return CMD_SUCCESS;
10665}
acf71666 10666
e3b78da8 10667static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 10668{
0291c246 10669 struct vty *vty = (struct vty *)args;
e3b78da8 10670 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 10671
23d0a753 10672 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
10673}
10674
10675static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10676{
10677 vty_out(vty, "self nexthop database:\n");
af97a18b 10678 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
10679
10680 vty_out(vty, "Tunnel-ip database:\n");
10681 hash_iterate(bgp->tip_hash,
e3b78da8 10682 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
10683 vty);
10684}
10685
15c81ca4
DS
10686DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10687 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10688 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
10689 "martian next-hops\n"
10690 "martian next-hop database\n")
acf71666 10691{
0291c246 10692 struct bgp *bgp = NULL;
15c81ca4 10693 int idx = 0;
9a8bdf1c
PG
10694 char *name = NULL;
10695
10696 /* [<vrf> VIEWVRFNAME] */
10697 if (argv_find(argv, argc, "vrf", &idx)) {
10698 name = argv[idx + 1]->arg;
10699 if (name && strmatch(name, VRF_DEFAULT_NAME))
10700 name = NULL;
10701 } else if (argv_find(argv, argc, "view", &idx))
10702 /* [<view> VIEWVRFNAME] */
10703 name = argv[idx + 1]->arg;
10704 if (name)
10705 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
10706 else
10707 bgp = bgp_get_default();
acf71666 10708
acf71666
MK
10709 if (!bgp) {
10710 vty_out(vty, "%% No BGP process is configured\n");
10711 return CMD_WARNING;
10712 }
10713 bgp_show_martian_nexthops(vty, bgp);
10714
10715 return CMD_SUCCESS;
10716}
10717
f412b39a 10718DEFUN (show_bgp_memory,
4bf6a362 10719 show_bgp_memory_cmd,
7fa12b13 10720 "show [ip] bgp memory",
4bf6a362 10721 SHOW_STR
3a2d747c 10722 IP_STR
4bf6a362
PJ
10723 BGP_STR
10724 "Global BGP memory statistics\n")
10725{
d62a17ae 10726 char memstrbuf[MTYPE_MEMSTR_LEN];
10727 unsigned long count;
10728
10729 /* RIB related usage stats */
10730 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10731 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10732 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 10733 count * sizeof(struct bgp_dest)));
d62a17ae 10734
10735 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10736 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10737 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 10738 count * sizeof(struct bgp_path_info)));
d62a17ae 10739 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10740 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10741 count,
4b7e6066
DS
10742 mtype_memstr(
10743 memstrbuf, sizeof(memstrbuf),
10744 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 10745
10746 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10747 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10748 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10749 count * sizeof(struct bgp_static)));
10750
10751 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10752 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10753 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10754 count * sizeof(struct bpacket)));
10755
10756 /* Adj-In/Out */
10757 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10758 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10759 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10760 count * sizeof(struct bgp_adj_in)));
10761 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10762 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10763 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10764 count * sizeof(struct bgp_adj_out)));
10765
10766 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10767 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10768 count,
10769 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10770 count * sizeof(struct bgp_nexthop_cache)));
10771
10772 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10773 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10774 count,
10775 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10776 count * sizeof(struct bgp_damp_info)));
10777
10778 /* Attributes */
10779 count = attr_count();
10780 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10781 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10782 count * sizeof(struct attr)));
10783
10784 if ((count = attr_unknown_count()))
10785 vty_out(vty, "%ld unknown attributes\n", count);
10786
10787 /* AS_PATH attributes */
10788 count = aspath_count();
10789 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10790 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10791 count * sizeof(struct aspath)));
10792
10793 count = mtype_stats_alloc(MTYPE_AS_SEG);
10794 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10795 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10796 count * sizeof(struct assegment)));
10797
10798 /* Other attributes */
10799 if ((count = community_count()))
10800 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10801 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10802 count * sizeof(struct community)));
d62a17ae 10803 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
145f7619
DA
10804 vty_out(vty,
10805 "%ld BGP ext-community entries, using %s of memory\n",
10806 count,
10807 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10808 count * sizeof(struct ecommunity)));
d62a17ae 10809 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10810 vty_out(vty,
10811 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10812 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10813 count * sizeof(struct lcommunity)));
d62a17ae 10814
10815 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10816 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10817 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10818 count * sizeof(struct cluster_list)));
10819
10820 /* Peer related usage */
10821 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10822 vty_out(vty, "%ld peers, using %s of memory\n", count,
10823 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10824 count * sizeof(struct peer)));
10825
10826 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10827 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10828 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10829 count * sizeof(struct peer_group)));
10830
10831 /* Other */
d62a17ae 10832 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10833 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10834 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10835 count * sizeof(regex_t)));
d62a17ae 10836 return CMD_SUCCESS;
4bf6a362 10837}
fee0f4c6 10838
57a9c8a8
DS
10839static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10840{
10841 json_object *bestpath = json_object_new_object();
10842
892fedb6 10843 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10844 json_object_string_add(bestpath, "asPath", "ignore");
10845
892fedb6 10846 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10847 json_object_string_add(bestpath, "asPath", "confed");
10848
892fedb6
DA
10849 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10850 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10851 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10852 "as-set");
10853 else
a4d82a8a 10854 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10855 "true");
10856 } else
a4d82a8a 10857 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10858
ee88563a
JM
10859 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10860 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10861
892fedb6 10862 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10863 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10864 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10865 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10866 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10867 json_object_string_add(bestpath, "med", "confed");
892fedb6 10868 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10869 json_object_string_add(bestpath, "med",
10870 "missing-as-worst");
10871 else
10872 json_object_string_add(bestpath, "med", "true");
10873 }
10874
10875 json_object_object_add(json, "bestPath", bestpath);
10876}
10877
3577f1c5
DD
10878/* Print the error code/subcode for why the peer is down */
10879static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10880 json_object *json_peer, bool use_json)
10881{
10882 const char *code_str;
10883 const char *subcode_str;
10884
10885 if (use_json) {
10886 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10887 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10888 char errorcodesubcode_hexstr[5];
10889 char errorcodesubcode_str[256];
10890
10891 code_str = bgp_notify_code_str(peer->notify.code);
10892 subcode_str = bgp_notify_subcode_str(
10893 peer->notify.code,
10894 peer->notify.subcode);
10895
772270f3
QY
10896 snprintf(errorcodesubcode_hexstr,
10897 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10898 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10899 json_object_string_add(json_peer,
10900 "lastErrorCodeSubcode",
10901 errorcodesubcode_hexstr);
10902 snprintf(errorcodesubcode_str, 255, "%s%s",
10903 code_str, subcode_str);
10904 json_object_string_add(json_peer,
10905 "lastNotificationReason",
10906 errorcodesubcode_str);
eea685b6
DA
10907 json_object_boolean_add(json_peer,
10908 "lastNotificationHardReset",
10909 peer->notify.hard_reset);
3577f1c5
DD
10910 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10911 && peer->notify.code == BGP_NOTIFY_CEASE
10912 && (peer->notify.subcode
10913 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10914 || peer->notify.subcode
10915 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10916 && peer->notify.length) {
10917 char msgbuf[1024];
10918 const char *msg_str;
10919
10920 msg_str = bgp_notify_admin_message(
10921 msgbuf, sizeof(msgbuf),
10922 (uint8_t *)peer->notify.data,
10923 peer->notify.length);
10924 if (msg_str)
10925 json_object_string_add(
10926 json_peer,
10927 "lastShutdownDescription",
10928 msg_str);
10929 }
10930
c258527b 10931 }
3577f1c5
DD
10932 json_object_string_add(json_peer, "lastResetDueTo",
10933 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10934 json_object_int_add(json_peer, "lastResetCode",
10935 peer->last_reset);
234f6fd4
DA
10936 json_object_string_add(json_peer, "softwareVersion",
10937 peer->soft_version ? peer->soft_version
10938 : "n/a");
3577f1c5
DD
10939 } else {
10940 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10941 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10942 code_str = bgp_notify_code_str(peer->notify.code);
10943 subcode_str =
10944 bgp_notify_subcode_str(peer->notify.code,
10945 peer->notify.subcode);
eea685b6 10946 vty_out(vty, " Notification %s (%s%s%s)\n",
3577f1c5 10947 peer->last_reset == PEER_DOWN_NOTIFY_SEND
eea685b6
DA
10948 ? "sent"
10949 : "received",
10950 code_str, subcode_str,
10951 peer->notify.hard_reset
10952 ? bgp_notify_subcode_str(
10953 BGP_NOTIFY_CEASE,
10954 BGP_NOTIFY_CEASE_HARD_RESET)
10955 : "");
3577f1c5 10956 } else {
234f6fd4
DA
10957 vty_out(vty, " %s (%s)\n",
10958 peer_down_str[(int)peer->last_reset],
10959 peer->soft_version ? peer->soft_version
10960 : "n/a");
3577f1c5
DD
10961 }
10962 }
10963}
10964
10965static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10966 safi_t safi)
10967{
feb17238 10968 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
3577f1c5
DD
10969}
10970
10971static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10972 struct peer *peer, json_object *json_peer,
10973 int max_neighbor_width, bool use_json)
10974{
10975 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10976 int len;
10977
10978 if (use_json) {
10979 if (peer_dynamic_neighbor(peer))
10980 json_object_boolean_true_add(json_peer,
10981 "dynamicPeer");
10982 if (peer->hostname)
10983 json_object_string_add(json_peer, "hostname",
10984 peer->hostname);
10985
10986 if (peer->domainname)
10987 json_object_string_add(json_peer, "domainname",
10988 peer->domainname);
10989 json_object_int_add(json_peer, "connectionsEstablished",
10990 peer->established);
10991 json_object_int_add(json_peer, "connectionsDropped",
10992 peer->dropped);
10993 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10994 use_json, json_peer);
feb17238 10995 if (peer_established(peer))
3577f1c5
DD
10996 json_object_string_add(json_peer, "lastResetDueTo",
10997 "AFI/SAFI Not Negotiated");
10998 else
10999 bgp_show_peer_reset(NULL, peer, json_peer, true);
11000 } else {
11001 dn_flag[1] = '\0';
11002 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
11003 if (peer->hostname
892fedb6 11004 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
11005 len = vty_out(vty, "%s%s(%s)", dn_flag,
11006 peer->hostname, peer->host);
11007 else
11008 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11009
11010 /* pad the neighbor column with spaces */
11011 if (len < max_neighbor_width)
11012 vty_out(vty, "%*s", max_neighbor_width - len,
11013 " ");
e91c24c8 11014 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
11015 peer->dropped,
11016 peer_uptime(peer->uptime, timebuf,
11017 BGP_UPTIME_LEN, 0, NULL));
feb17238 11018 if (peer_established(peer))
3577f1c5
DD
11019 vty_out(vty, " AFI/SAFI Not Negotiated\n");
11020 else
11021 bgp_show_peer_reset(vty, peer, NULL,
11022 false);
11023 }
11024}
c258527b 11025
565e9ddd 11026/* Strip peer's description to the given size. */
cb75bb31
DA
11027static char *bgp_peer_description_stripped(char *desc, uint32_t size)
11028{
11029 static char stripped[BUFSIZ];
64541ffa
FD
11030 uint32_t i = 0;
11031 uint32_t last_space = 0;
cb75bb31 11032
64541ffa
FD
11033 while (i < size) {
11034 if (*(desc + i) == 0) {
11035 stripped[i] = '\0';
11036 return stripped;
11037 }
11038 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
11039 last_space = i;
11040 stripped[i] = *(desc + i);
11041 i++;
11042 }
11043
11044 if (last_space > size)
11045 stripped[size + 1] = '\0';
11046 else
11047 stripped[last_space] = '\0';
cb75bb31
DA
11048
11049 return stripped;
11050}
3577f1c5 11051
8c1d4cd5
LS
11052/* Determine whether var peer should be filtered out of the summary. */
11053static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
11054 struct peer *fpeer, int as_type,
11055 as_t as)
11056{
11057
11058 /* filter neighbor XXXX */
11059 if (fpeer && fpeer != peer)
11060 return true;
11061
11062 /* filter remote-as (internal|external) */
11063 if (as_type != AS_UNSPECIFIED) {
11064 if (peer->as_type == AS_SPECIFIED) {
11065 if (as_type == AS_INTERNAL) {
11066 if (peer->as != peer->local_as)
11067 return true;
11068 } else if (peer->as == peer->local_as)
11069 return true;
11070 } else if (as_type != peer->as_type)
11071 return true;
11072 } else if (as && as != peer->as) /* filter remote-as XXX */
11073 return true;
11074
11075 return false;
11076}
11077
565e9ddd
DA
11078/* Show BGP peer's summary information.
11079 *
11080 * Peer's description is stripped according to if `wide` option is given
11081 * or not.
11082 *
11083 * When adding new columns to `show bgp summary` output, please make
11084 * sure `Desc` is the lastest column to show because it can contain
11085 * whitespaces and the whole output will be tricky.
11086 */
d62a17ae 11087static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 11088 struct peer *fpeer, int as_type, as_t as,
96c81f66 11089 uint16_t show_flags)
d62a17ae 11090{
11091 struct peer *peer;
11092 struct listnode *node, *nnode;
11093 unsigned int count = 0, dn_count = 0;
11094 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
11095 char neighbor_buf[VTY_BUFSIZ];
11096 int neighbor_col_default_width = 16;
3577f1c5 11097 int len, failed_count = 0;
ce1944f0 11098 unsigned int filtered_count = 0;
d62a17ae 11099 int max_neighbor_width = 0;
11100 int pfx_rcd_safi;
3c13337d 11101 json_object *json = NULL;
d62a17ae 11102 json_object *json_peer = NULL;
11103 json_object *json_peers = NULL;
50e05855 11104 struct peer_af *paf;
d3ada366 11105 struct bgp_filter *filter;
85eeb029
DA
11106 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11107 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11108 bool show_established =
11109 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11110 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
96c81f66 11111 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
d62a17ae 11112
11113 /* labeled-unicast routes are installed in the unicast table so in order
11114 * to
11115 * display the correct PfxRcd value we must look at SAFI_UNICAST
11116 */
3577f1c5 11117
d62a17ae 11118 if (safi == SAFI_LABELED_UNICAST)
11119 pfx_rcd_safi = SAFI_UNICAST;
11120 else
11121 pfx_rcd_safi = safi;
11122
11123 if (use_json) {
3c13337d 11124 json = json_object_new_object();
d62a17ae 11125 json_peers = json_object_new_object();
3577f1c5 11126 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
11127 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11128 as_type, as)) {
ce1944f0 11129 filtered_count++;
8c1d4cd5
LS
11130 count++;
11131 continue;
11132 }
11133
3577f1c5
DD
11134 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11135 continue;
11136
11137 if (peer->afc[afi][safi]) {
11138 /* See if we have at least a single failed peer */
11139 if (bgp_has_peer_failed(peer, afi, safi))
11140 failed_count++;
11141 count++;
11142 }
11143 if (peer_dynamic_neighbor(peer))
11144 dn_count++;
11145 }
c258527b 11146
d62a17ae 11147 } else {
11148 /* Loop over all neighbors that will be displayed to determine
11149 * how many
11150 * characters are needed for the Neighbor column
11151 */
11152 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
11153 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11154 as_type, as)) {
ce1944f0 11155 filtered_count++;
8c1d4cd5
LS
11156 count++;
11157 continue;
11158 }
11159
d62a17ae 11160 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11161 continue;
11162
11163 if (peer->afc[afi][safi]) {
11164 memset(dn_flag, '\0', sizeof(dn_flag));
11165 if (peer_dynamic_neighbor(peer))
11166 dn_flag[0] = '*';
11167
11168 if (peer->hostname
892fedb6
DA
11169 && CHECK_FLAG(bgp->flags,
11170 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
11171 snprintf(neighbor_buf,
11172 sizeof(neighbor_buf),
11173 "%s%s(%s) ", dn_flag,
11174 peer->hostname, peer->host);
d62a17ae 11175 else
772270f3
QY
11176 snprintf(neighbor_buf,
11177 sizeof(neighbor_buf), "%s%s ",
11178 dn_flag, peer->host);
d62a17ae 11179
11180 len = strlen(neighbor_buf);
11181
11182 if (len > max_neighbor_width)
11183 max_neighbor_width = len;
c258527b 11184
3577f1c5
DD
11185 /* See if we have at least a single failed peer */
11186 if (bgp_has_peer_failed(peer, afi, safi))
11187 failed_count++;
11188 count++;
d62a17ae 11189 }
11190 }
f933309e 11191
d62a17ae 11192 /* Originally we displayed the Neighbor column as 16
11193 * characters wide so make that the default
11194 */
11195 if (max_neighbor_width < neighbor_col_default_width)
11196 max_neighbor_width = neighbor_col_default_width;
11197 }
f933309e 11198
3577f1c5
DD
11199 if (show_failed && !failed_count) {
11200 if (use_json) {
11201 json_object_int_add(json, "failedPeersCount", 0);
11202 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 11203 json_object_int_add(json, "totalPeers", count);
3577f1c5 11204
75eeda93 11205 vty_json(vty, json);
3577f1c5
DD
11206 } else {
11207 vty_out(vty, "%% No failed BGP neighbors found\n");
3577f1c5
DD
11208 }
11209 return CMD_SUCCESS;
11210 }
c258527b 11211
3577f1c5 11212 count = 0; /* Reset the value as its used again */
ce1944f0 11213 filtered_count = 0;
800867d8 11214 dn_count = 0;
d62a17ae 11215 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11216 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11217 continue;
11218
ea47320b
DL
11219 if (!peer->afc[afi][safi])
11220 continue;
d62a17ae 11221
ea47320b
DL
11222 if (!count) {
11223 unsigned long ents;
11224 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 11225 int64_t vrf_id_ui;
d62a17ae 11226
a4d82a8a
PZ
11227 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
11228 ? -1
11229 : (int64_t)bgp->vrf_id;
ea47320b
DL
11230
11231 /* Usage summary and header */
11232 if (use_json) {
c949c771
DA
11233 json_object_string_addf(json, "routerId",
11234 "%pI4",
11235 &bgp->router_id);
e84c7c12
PG
11236 asn_asn2json(json, "as", bgp->as,
11237 bgp->asnotation);
60466a63 11238 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
11239 json_object_string_add(
11240 json, "vrfName",
11241 (bgp->inst_type
11242 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11243 ? VRF_DEFAULT_NAME
ea47320b
DL
11244 : bgp->name);
11245 } else {
11246 vty_out(vty,
9eb11997
PG
11247 "BGP router identifier %pI4, local AS number %s vrf-id %d",
11248 &bgp->router_id, bgp->as_pretty,
a4d82a8a
PZ
11249 bgp->vrf_id == VRF_UNKNOWN
11250 ? -1
11251 : (int)bgp->vrf_id);
ea47320b
DL
11252 vty_out(vty, "\n");
11253 }
d62a17ae 11254
ea47320b 11255 if (bgp_update_delay_configured(bgp)) {
d62a17ae 11256 if (use_json) {
ea47320b 11257 json_object_int_add(
60466a63 11258 json, "updateDelayLimit",
ea47320b 11259 bgp->v_update_delay);
d62a17ae 11260
ea47320b
DL
11261 if (bgp->v_update_delay
11262 != bgp->v_establish_wait)
d62a17ae 11263 json_object_int_add(
11264 json,
ea47320b
DL
11265 "updateDelayEstablishWait",
11266 bgp->v_establish_wait);
d62a17ae 11267
60466a63 11268 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
11269 json_object_string_add(
11270 json,
11271 "updateDelayFirstNeighbor",
11272 bgp->update_delay_begin_time);
11273 json_object_boolean_true_add(
11274 json,
11275 "updateDelayInProgress");
11276 } else {
11277 if (bgp->update_delay_over) {
d62a17ae 11278 json_object_string_add(
11279 json,
11280 "updateDelayFirstNeighbor",
11281 bgp->update_delay_begin_time);
ea47320b 11282 json_object_string_add(
d62a17ae 11283 json,
ea47320b
DL
11284 "updateDelayBestpathResumed",
11285 bgp->update_delay_end_time);
11286 json_object_string_add(
d62a17ae 11287 json,
ea47320b
DL
11288 "updateDelayZebraUpdateResume",
11289 bgp->update_delay_zebra_resume_time);
11290 json_object_string_add(
11291 json,
11292 "updateDelayPeerUpdateResume",
11293 bgp->update_delay_peers_resume_time);
d62a17ae 11294 }
ea47320b
DL
11295 }
11296 } else {
11297 vty_out(vty,
11298 "Read-only mode update-delay limit: %d seconds\n",
11299 bgp->v_update_delay);
11300 if (bgp->v_update_delay
11301 != bgp->v_establish_wait)
d62a17ae 11302 vty_out(vty,
ea47320b
DL
11303 " Establish wait: %d seconds\n",
11304 bgp->v_establish_wait);
d62a17ae 11305
60466a63 11306 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
11307 vty_out(vty,
11308 " First neighbor established: %s\n",
11309 bgp->update_delay_begin_time);
11310 vty_out(vty,
11311 " Delay in progress\n");
11312 } else {
11313 if (bgp->update_delay_over) {
d62a17ae 11314 vty_out(vty,
11315 " First neighbor established: %s\n",
11316 bgp->update_delay_begin_time);
11317 vty_out(vty,
ea47320b
DL
11318 " Best-paths resumed: %s\n",
11319 bgp->update_delay_end_time);
11320 vty_out(vty,
11321 " zebra update resumed: %s\n",
11322 bgp->update_delay_zebra_resume_time);
11323 vty_out(vty,
11324 " peers update resumed: %s\n",
11325 bgp->update_delay_peers_resume_time);
d62a17ae 11326 }
11327 }
11328 }
ea47320b 11329 }
d62a17ae 11330
ea47320b
DL
11331 if (use_json) {
11332 if (bgp_maxmed_onstartup_configured(bgp)
11333 && bgp->maxmed_active)
11334 json_object_boolean_true_add(
60466a63 11335 json, "maxMedOnStartup");
ea47320b
DL
11336 if (bgp->v_maxmed_admin)
11337 json_object_boolean_true_add(
60466a63 11338 json, "maxMedAdministrative");
d62a17ae 11339
ea47320b
DL
11340 json_object_int_add(
11341 json, "tableVersion",
60466a63 11342 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 11343
60466a63
QY
11344 ents = bgp_table_count(bgp->rib[afi][safi]);
11345 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
11346 json_object_int_add(
11347 json, "ribMemory",
9bcb3eef 11348 ents * sizeof(struct bgp_dest));
d62a17ae 11349
210ec2a0 11350 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
11351 json_object_int_add(json, "peerCount", ents);
11352 json_object_int_add(json, "peerMemory",
11353 ents * sizeof(struct peer));
d62a17ae 11354
ea47320b
DL
11355 if ((ents = listcount(bgp->group))) {
11356 json_object_int_add(
60466a63 11357 json, "peerGroupCount", ents);
ea47320b
DL
11358 json_object_int_add(
11359 json, "peerGroupMemory",
996c9314
LB
11360 ents * sizeof(struct
11361 peer_group));
ea47320b 11362 }
d62a17ae 11363
ea47320b
DL
11364 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11365 BGP_CONFIG_DAMPENING))
11366 json_object_boolean_true_add(
60466a63 11367 json, "dampeningEnabled");
ea47320b 11368 } else {
96c81f66
LS
11369 if (!show_terse) {
11370 if (bgp_maxmed_onstartup_configured(bgp)
11371 && bgp->maxmed_active)
11372 vty_out(vty,
11373 "Max-med on-startup active\n");
11374 if (bgp->v_maxmed_admin)
11375 vty_out(vty,
11376 "Max-med administrative active\n");
d62a17ae 11377
96c81f66
LS
11378 vty_out(vty,
11379 "BGP table version %" PRIu64
11380 "\n",
11381 bgp_table_version(
11382 bgp->rib[afi][safi]));
ea47320b 11383
96c81f66
LS
11384 ents = bgp_table_count(
11385 bgp->rib[afi][safi]);
d62a17ae 11386 vty_out(vty,
96c81f66 11387 "RIB entries %ld, using %s of memory\n",
d62a17ae 11388 ents,
11389 mtype_memstr(
11390 memstrbuf,
11391 sizeof(memstrbuf),
96c81f66
LS
11392 ents
11393 * sizeof(
11394 struct
11395 bgp_dest)));
d62a17ae 11396
96c81f66
LS
11397 /* Peer related usage */
11398 ents = bgp->af_peer_count[afi][safi];
11399 vty_out(vty,
11400 "Peers %ld, using %s of memory\n",
11401 ents,
11402 mtype_memstr(
11403 memstrbuf,
11404 sizeof(memstrbuf),
11405 ents
11406 * sizeof(
11407 struct
11408 peer)));
d62a17ae 11409
96c81f66
LS
11410 if ((ents = listcount(bgp->group)))
11411 vty_out(vty,
11412 "Peer groups %ld, using %s of memory\n",
11413 ents,
11414 mtype_memstr(
11415 memstrbuf,
11416 sizeof(memstrbuf),
11417 ents
11418 * sizeof(
11419 struct
11420 peer_group)));
11421
11422 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11423 BGP_CONFIG_DAMPENING))
11424 vty_out(vty,
11425 "Dampening enabled.\n");
11426 }
11427 if (show_failed) {
11428 vty_out(vty, "\n");
11429
11430 /* Subtract 8 here because 'Neighbor' is
11431 * 8 characters */
11432 vty_out(vty, "Neighbor");
11433 vty_out(vty, "%*s",
11434 max_neighbor_width - 8, " ");
85eeb029
DA
11435 vty_out(vty,
11436 BGP_SHOW_SUMMARY_HEADER_FAILED);
96c81f66 11437 }
d62a17ae 11438 }
ea47320b 11439 }
d62a17ae 11440
d55811cc 11441 paf = peer_af_find(peer, afi, safi);
d3ada366 11442 filter = &peer->filter[afi][safi];
db92d226 11443
ea47320b 11444 count++;
3577f1c5
DD
11445 /* Works for both failed & successful cases */
11446 if (peer_dynamic_neighbor(peer))
11447 dn_count++;
d62a17ae 11448
ea47320b 11449 if (use_json) {
3577f1c5 11450 json_peer = NULL;
8c1d4cd5 11451 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
11452 as_type, as)) {
11453 filtered_count++;
8c1d4cd5 11454 continue;
ce1944f0 11455 }
3577f1c5
DD
11456 if (show_failed &&
11457 bgp_has_peer_failed(peer, afi, safi)) {
11458 json_peer = json_object_new_object();
11459 bgp_show_failed_summary(vty, bgp, peer,
11460 json_peer, 0, use_json);
11461 } else if (!show_failed) {
10b49f14 11462 if (show_established
ce1944f0
LS
11463 && bgp_has_peer_failed(peer, afi, safi)) {
11464 filtered_count++;
10b49f14 11465 continue;
ce1944f0 11466 }
10b49f14 11467
3577f1c5
DD
11468 json_peer = json_object_new_object();
11469 if (peer_dynamic_neighbor(peer)) {
11470 json_object_boolean_true_add(json_peer,
11471 "dynamicPeer");
11472 }
d62a17ae 11473
3577f1c5
DD
11474 if (peer->hostname)
11475 json_object_string_add(json_peer, "hostname",
11476 peer->hostname);
11477
11478 if (peer->domainname)
11479 json_object_string_add(json_peer, "domainname",
11480 peer->domainname);
11481
44a4d55e
PG
11482 asn_asn2json(json_peer, "remoteAs", peer->as,
11483 bgp->asnotation);
11484 asn_asn2json(json_peer, "localAs",
11485 peer->change_local_as
11486 ? peer->change_local_as
11487 : peer->local_as,
11488 bgp->asnotation);
3577f1c5
DD
11489 json_object_int_add(json_peer, "version", 4);
11490 json_object_int_add(json_peer, "msgRcvd",
11491 PEER_TOTAL_RX(peer));
11492 json_object_int_add(json_peer, "msgSent",
11493 PEER_TOTAL_TX(peer));
11494
43aa5965
QY
11495 atomic_size_t outq_count, inq_count;
11496 outq_count = atomic_load_explicit(
11497 &peer->obuf->count,
11498 memory_order_relaxed);
11499 inq_count = atomic_load_explicit(
11500 &peer->ibuf->count,
11501 memory_order_relaxed);
11502
3577f1c5
DD
11503 json_object_int_add(json_peer, "tableVersion",
11504 peer->version[afi][safi]);
11505 json_object_int_add(json_peer, "outq",
43aa5965
QY
11506 outq_count);
11507 json_object_int_add(json_peer, "inq",
11508 inq_count);
3577f1c5
DD
11509 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11510 use_json, json_peer);
11511
3577f1c5
DD
11512 json_object_int_add(json_peer, "pfxRcd",
11513 peer->pcount[afi][pfx_rcd_safi]);
11514
3577f1c5 11515 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
11516 json_object_int_add(
11517 json_peer, "pfxSnt",
11518 (PAF_SUBGRP(paf))->scount);
11519 else
11520 json_object_int_add(json_peer, "pfxSnt",
11521 0);
0e1f8ab5
DA
11522
11523 /* BGP FSM state */
cb9196e7 11524 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
11525 || CHECK_FLAG(peer->bgp->flags,
11526 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
11527 json_object_string_add(json_peer,
11528 "state",
3577f1c5
DD
11529 "Idle (Admin)");
11530 else if (peer->afc_recv[afi][safi])
11531 json_object_string_add(
0e1f8ab5
DA
11532 json_peer, "state",
11533 lookup_msg(bgp_status_msg,
11534 peer->status, NULL));
11535 else if (CHECK_FLAG(
11536 peer->sflags,
11537 PEER_STATUS_PREFIX_OVERFLOW))
11538 json_object_string_add(json_peer,
11539 "state",
3577f1c5
DD
11540 "Idle (PfxCt)");
11541 else
11542 json_object_string_add(
0e1f8ab5
DA
11543 json_peer, "state",
11544 lookup_msg(bgp_status_msg,
11545 peer->status, NULL));
11546
11547 /* BGP peer state */
11548 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11549 || CHECK_FLAG(peer->bgp->flags,
11550 BGP_FLAG_SHUTDOWN))
11551 json_object_string_add(json_peer,
11552 "peerState",
11553 "Admin");
11554 else if (CHECK_FLAG(
11555 peer->sflags,
11556 PEER_STATUS_PREFIX_OVERFLOW))
11557 json_object_string_add(json_peer,
11558 "peerState",
11559 "PfxCt");
11560 else if (CHECK_FLAG(peer->flags,
11561 PEER_FLAG_PASSIVE))
11562 json_object_string_add(json_peer,
11563 "peerState",
11564 "Passive");
11565 else if (CHECK_FLAG(peer->sflags,
11566 PEER_STATUS_NSF_WAIT))
11567 json_object_string_add(json_peer,
11568 "peerState",
11569 "NSF passive");
11570 else if (CHECK_FLAG(
11571 peer->bgp->flags,
11572 BGP_FLAG_EBGP_REQUIRES_POLICY)
11573 && (!bgp_inbound_policy_exists(peer,
11574 filter)
11575 || !bgp_outbound_policy_exists(
11576 peer, filter)))
11577 json_object_string_add(json_peer,
11578 "peerState",
11579 "Policy");
11580 else
11581 json_object_string_add(
11582 json_peer, "peerState", "OK");
11583
200116db
DD
11584 json_object_int_add(json_peer, "connectionsEstablished",
11585 peer->established);
11586 json_object_int_add(json_peer, "connectionsDropped",
11587 peer->dropped);
aa72bd7e
PG
11588 if (peer->desc)
11589 json_object_string_add(
11590 json_peer, "desc", peer->desc);
b4e9dcba 11591 }
3577f1c5
DD
11592 /* Avoid creating empty peer dicts in JSON */
11593 if (json_peer == NULL)
11594 continue;
ea47320b
DL
11595
11596 if (peer->conf_if)
60466a63 11597 json_object_string_add(json_peer, "idType",
ea47320b
DL
11598 "interface");
11599 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
11600 json_object_string_add(json_peer, "idType",
11601 "ipv4");
ea47320b 11602 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
11603 json_object_string_add(json_peer, "idType",
11604 "ipv6");
ea47320b
DL
11605 json_object_object_add(json_peers, peer->host,
11606 json_peer);
11607 } else {
8c1d4cd5 11608 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
11609 as_type, as)) {
11610 filtered_count++;
8c1d4cd5 11611 continue;
ce1944f0 11612 }
3577f1c5
DD
11613 if (show_failed &&
11614 bgp_has_peer_failed(peer, afi, safi)) {
11615 bgp_show_failed_summary(vty, bgp, peer, NULL,
11616 max_neighbor_width,
11617 use_json);
11618 } else if (!show_failed) {
10b49f14 11619 if (show_established
ce1944f0
LS
11620 && bgp_has_peer_failed(peer, afi, safi)) {
11621 filtered_count++;
10b49f14 11622 continue;
ce1944f0 11623 }
96c81f66
LS
11624
11625 if ((count - filtered_count) == 1) {
11626 /* display headline before the first
11627 * neighbor line */
11628 vty_out(vty, "\n");
11629
11630 /* Subtract 8 here because 'Neighbor' is
11631 * 8 characters */
11632 vty_out(vty, "Neighbor");
11633 vty_out(vty, "%*s",
11634 max_neighbor_width - 8, " ");
11635 vty_out(vty,
11636 show_wide
11637 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11638 : BGP_SHOW_SUMMARY_HEADER_ALL);
11639 }
11640
3577f1c5
DD
11641 memset(dn_flag, '\0', sizeof(dn_flag));
11642 if (peer_dynamic_neighbor(peer)) {
11643 dn_flag[0] = '*';
11644 }
d62a17ae 11645
3577f1c5 11646 if (peer->hostname
892fedb6
DA
11647 && CHECK_FLAG(bgp->flags,
11648 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 11649 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
11650 peer->hostname,
11651 peer->host);
d62a17ae 11652 else
3577f1c5
DD
11653 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11654
11655 /* pad the neighbor column with spaces */
11656 if (len < max_neighbor_width)
11657 vty_out(vty, "%*s", max_neighbor_width - len,
11658 " ");
11659
43aa5965
QY
11660 atomic_size_t outq_count, inq_count;
11661 outq_count = atomic_load_explicit(
11662 &peer->obuf->count,
11663 memory_order_relaxed);
11664 inq_count = atomic_load_explicit(
11665 &peer->ibuf->count,
11666 memory_order_relaxed);
11667
44a4d55e
PG
11668 vty_out(vty, "4 ");
11669 vty_out(vty, ASN_FORMAT_SPACE(bgp->asnotation),
11670 &peer->as);
11671 if (show_wide) {
85eeb029 11672 vty_out(vty,
44a4d55e
PG
11673 ASN_FORMAT_SPACE(
11674 bgp->asnotation),
85eeb029 11675 peer->change_local_as
44a4d55e
PG
11676 ? &peer->change_local_as
11677 : &peer->local_as);
11678 vty_out(vty,
11679 " %9u %9u %8" PRIu64
11680 " %4zu %4zu %8s",
85eeb029
DA
11681 PEER_TOTAL_RX(peer),
11682 PEER_TOTAL_TX(peer),
11683 peer->version[afi][safi],
11684 inq_count, outq_count,
11685 peer_uptime(peer->uptime,
11686 timebuf,
11687 BGP_UPTIME_LEN, 0,
11688 NULL));
44a4d55e
PG
11689 } else {
11690 vty_out(vty,
11691 " %9u %9u %8" PRIu64
11692 " %4zu %4zu %8s",
11693 PEER_TOTAL_RX(peer),
85eeb029
DA
11694 PEER_TOTAL_TX(peer),
11695 peer->version[afi][safi],
11696 inq_count, outq_count,
11697 peer_uptime(peer->uptime,
11698 timebuf,
11699 BGP_UPTIME_LEN, 0,
11700 NULL));
44a4d55e 11701 }
feb17238 11702 if (peer_established(peer)) {
d3ada366
DA
11703 if (peer->afc_recv[afi][safi]) {
11704 if (CHECK_FLAG(
11705 bgp->flags,
11706 BGP_FLAG_EBGP_REQUIRES_POLICY)
11707 && !bgp_inbound_policy_exists(
11708 peer, filter))
11709 vty_out(vty, " %12s",
11710 "(Policy)");
11711 else
11712 vty_out(vty,
6cde4b45 11713 " %12u",
d3ada366
DA
11714 peer->pcount
11715 [afi]
11716 [pfx_rcd_safi]);
11717 } else {
749d0f27 11718 vty_out(vty, " NoNeg");
d3ada366 11719 }
db92d226 11720
d3ada366
DA
11721 if (paf && PAF_SUBGRP(paf)) {
11722 if (CHECK_FLAG(
11723 bgp->flags,
11724 BGP_FLAG_EBGP_REQUIRES_POLICY)
11725 && !bgp_outbound_policy_exists(
11726 peer, filter))
11727 vty_out(vty, " %8s",
11728 "(Policy)");
11729 else
11730 vty_out(vty,
6cde4b45 11731 " %8u",
d3ada366
DA
11732 (PAF_SUBGRP(
11733 paf))
11734 ->scount);
749d0f27
DA
11735 } else {
11736 vty_out(vty, " NoNeg");
d3ada366 11737 }
db92d226 11738 } else {
736b68f3
DS
11739 if (CHECK_FLAG(peer->flags,
11740 PEER_FLAG_SHUTDOWN)
11741 || CHECK_FLAG(peer->bgp->flags,
11742 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
11743 vty_out(vty, " Idle (Admin)");
11744 else if (CHECK_FLAG(
11745 peer->sflags,
11746 PEER_STATUS_PREFIX_OVERFLOW))
11747 vty_out(vty, " Idle (PfxCt)");
11748 else
11749 vty_out(vty, " %12s",
11750 lookup_msg(bgp_status_msg,
11751 peer->status, NULL));
db92d226 11752
6cde4b45 11753 vty_out(vty, " %8u", 0);
3577f1c5 11754 }
565e9ddd
DA
11755 /* Make sure `Desc` column is the lastest in
11756 * the output.
11757 */
aa72bd7e 11758 if (peer->desc)
cb75bb31
DA
11759 vty_out(vty, " %s",
11760 bgp_peer_description_stripped(
85eeb029
DA
11761 peer->desc,
11762 show_wide ? 64 : 20));
aa72bd7e
PG
11763 else
11764 vty_out(vty, " N/A");
3577f1c5 11765 vty_out(vty, "\n");
d62a17ae 11766 }
3577f1c5 11767
d62a17ae 11768 }
11769 }
f933309e 11770
d62a17ae 11771 if (use_json) {
11772 json_object_object_add(json, "peers", json_peers);
3577f1c5 11773 json_object_int_add(json, "failedPeers", failed_count);
ce1944f0
LS
11774 json_object_int_add(json, "displayedPeers",
11775 count - filtered_count);
d62a17ae 11776 json_object_int_add(json, "totalPeers", count);
11777 json_object_int_add(json, "dynamicPeers", dn_count);
11778
3577f1c5
DD
11779 if (!show_failed)
11780 bgp_show_bestpath_json(bgp, json);
57a9c8a8 11781
75eeda93 11782 vty_json(vty, json);
d62a17ae 11783 } else {
ce1944f0 11784 if (count) {
96c81f66
LS
11785 if (filtered_count == count)
11786 vty_out(vty, "\n%% No matching neighbor\n");
11787 else {
11788 if (show_failed)
11789 vty_out(vty, "\nDisplayed neighbors %d",
11790 failed_count);
11791 else if (as_type != AS_UNSPECIFIED || as
11792 || fpeer || show_established)
ce1944f0
LS
11793 vty_out(vty, "\nDisplayed neighbors %d",
11794 count - filtered_count);
96c81f66
LS
11795
11796 vty_out(vty, "\nTotal number of neighbors %d\n",
11797 count);
ce1944f0 11798 }
ce1944f0 11799 } else {
d6ceaca3 11800 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 11801 get_afi_safi_str(afi, safi, false));
d62a17ae 11802 }
b05a1c8b 11803
d6ceaca3 11804 if (dn_count) {
d62a17ae 11805 vty_out(vty, "* - dynamic neighbor\n");
11806 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11807 dn_count, bgp->dynamic_neighbors_limit);
11808 }
11809 }
1ff9a340 11810
d62a17ae 11811 return CMD_SUCCESS;
718e3744 11812}
11813
d62a17ae 11814static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5 11815 int safi, struct peer *fpeer, int as_type,
96c81f66 11816 as_t as, uint16_t show_flags)
d62a17ae 11817{
11818 int is_first = 1;
11819 int afi_wildcard = (afi == AFI_MAX);
11820 int safi_wildcard = (safi == SAFI_MAX);
11821 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 11822 bool nbr_output = false;
85eeb029 11823 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11824
11825 if (use_json && is_wildcard)
11826 vty_out(vty, "{\n");
11827 if (afi_wildcard)
11828 afi = 1; /* AFI_IP */
11829 while (afi < AFI_MAX) {
11830 if (safi_wildcard)
11831 safi = 1; /* SAFI_UNICAST */
11832 while (safi < SAFI_MAX) {
318cac96 11833 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 11834 nbr_output = true;
f86897b9 11835
d62a17ae 11836 if (is_wildcard) {
11837 /*
11838 * So limit output to those afi/safi
11839 * pairs that
11840 * actualy have something interesting in
11841 * them
11842 */
11843 if (use_json) {
d62a17ae 11844 if (!is_first)
11845 vty_out(vty, ",\n");
11846 else
11847 is_first = 0;
11848
11849 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11850 get_afi_safi_str(afi,
11851 safi,
11852 true));
d62a17ae 11853 } else {
6cac2fcc
LS
11854 vty_out(vty,
11855 "\n%s Summary (%s):\n",
5cb5f4d0
DD
11856 get_afi_safi_str(afi,
11857 safi,
6cac2fcc
LS
11858 false),
11859 bgp->name_pretty);
d62a17ae 11860 }
11861 }
8c1d4cd5
LS
11862 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11863 as_type, as, show_flags);
d62a17ae 11864 }
11865 safi++;
d62a17ae 11866 if (!safi_wildcard)
11867 safi = SAFI_MAX;
11868 }
11869 afi++;
ee851c8c 11870 if (!afi_wildcard)
d62a17ae 11871 afi = AFI_MAX;
11872 }
11873
11874 if (use_json && is_wildcard)
11875 vty_out(vty, "}\n");
ca61fd25
DS
11876 else if (!nbr_output) {
11877 if (use_json)
11878 vty_out(vty, "{}\n");
11879 else
6cac2fcc
LS
11880 vty_out(vty, "%% No BGP neighbors found in %s\n",
11881 bgp->name_pretty);
ca61fd25 11882 }
d62a17ae 11883}
11884
11885static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
11886 safi_t safi,
11887 const char *neighbor,
11888 int as_type, as_t as,
96c81f66 11889 uint16_t show_flags)
d62a17ae 11890{
11891 struct listnode *node, *nnode;
11892 struct bgp *bgp;
8c1d4cd5 11893 struct peer *fpeer = NULL;
d62a17ae 11894 int is_first = 1;
9f049418 11895 bool nbr_output = false;
85eeb029 11896 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11897
11898 if (use_json)
11899 vty_out(vty, "{\n");
11900
11901 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11902 nbr_output = true;
d62a17ae 11903 if (use_json) {
d62a17ae 11904 if (!is_first)
11905 vty_out(vty, ",\n");
11906 else
11907 is_first = 0;
11908
11909 vty_out(vty, "\"%s\":",
11910 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11911 ? VRF_DEFAULT_NAME
d62a17ae 11912 : bgp->name);
d62a17ae 11913 }
8c1d4cd5
LS
11914 if (neighbor) {
11915 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11916 use_json);
11917 if (!fpeer)
11918 continue;
11919 }
11920 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11921 as, show_flags);
d62a17ae 11922 }
11923
11924 if (use_json)
11925 vty_out(vty, "}\n");
9f049418
DS
11926 else if (!nbr_output)
11927 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11928}
11929
11930int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5 11931 safi_t safi, const char *neighbor, int as_type,
96c81f66 11932 as_t as, uint16_t show_flags)
d62a17ae 11933{
11934 struct bgp *bgp;
85eeb029 11935 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 11936 struct peer *fpeer = NULL;
d62a17ae 11937
11938 if (name) {
11939 if (strmatch(name, "all")) {
85eeb029 11940 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
11941 neighbor, as_type,
11942 as, show_flags);
d62a17ae 11943 return CMD_SUCCESS;
11944 } else {
11945 bgp = bgp_lookup_by_name(name);
11946
11947 if (!bgp) {
11948 if (use_json)
11949 vty_out(vty, "{}\n");
11950 else
11951 vty_out(vty,
ca61fd25 11952 "%% BGP instance not found\n");
d62a17ae 11953 return CMD_WARNING;
11954 }
11955
8c1d4cd5
LS
11956 if (neighbor) {
11957 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11958 use_json);
11959 if (!fpeer)
11960 return CMD_WARNING;
11961 }
11962 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11963 as_type, as, show_flags);
d62a17ae 11964 return CMD_SUCCESS;
11965 }
11966 }
11967
11968 bgp = bgp_get_default();
11969
8c1d4cd5
LS
11970 if (bgp) {
11971 if (neighbor) {
11972 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11973 use_json);
11974 if (!fpeer)
11975 return CMD_WARNING;
11976 }
11977 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11978 as, show_flags);
11979 } else {
ca61fd25
DS
11980 if (use_json)
11981 vty_out(vty, "{}\n");
11982 else
11983 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11984 return CMD_WARNING;
11985 }
d62a17ae 11986
11987 return CMD_SUCCESS;
4fb25c53
DW
11988}
11989
716b2d8a 11990/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
11991DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11992 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11993 " [" BGP_SAFI_WITH_LABEL_CMD_STR
8079a413 11994 "]] [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
11995 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11996 BGP_SAFI_WITH_LABEL_HELP_STR
11997 "Display the entries for all address families\n"
11998 "Summary of BGP neighbor status\n"
11999 "Show only sessions in Established state\n"
12000 "Show only sessions not in Established state\n"
12001 "Show only the specified neighbor session\n"
12002 "Neighbor to display information about\n"
12003 "Neighbor to display information about\n"
12004 "Neighbor on BGP configured interface\n"
8079a413 12005 "Show only the specified remote AS sessions\n" AS_STR
8c1d4cd5
LS
12006 "Internal (iBGP) AS sessions\n"
12007 "External (eBGP) AS sessions\n"
96c81f66 12008 "Shorten the information on BGP instances\n"
8c1d4cd5 12009 "Increase table width for longer output\n" JSON_STR)
718e3744 12010{
d62a17ae 12011 char *vrf = NULL;
12012 afi_t afi = AFI_MAX;
12013 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
12014 as_t as = 0; /* 0 means AS filter not set */
12015 int as_type = AS_UNSPECIFIED;
96c81f66 12016 uint16_t show_flags = 0;
d62a17ae 12017
12018 int idx = 0;
12019
12020 /* show [ip] bgp */
96f3485c 12021 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 12022 afi = AFI_IP;
9a8bdf1c
PG
12023 /* [<vrf> VIEWVRFNAME] */
12024 if (argv_find(argv, argc, "vrf", &idx)) {
12025 vrf = argv[idx + 1]->arg;
12026 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12027 vrf = NULL;
12028 } else if (argv_find(argv, argc, "view", &idx))
12029 /* [<view> VIEWVRFNAME] */
12030 vrf = argv[idx + 1]->arg;
d62a17ae 12031 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
12032 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
12033 argv_find_and_parse_safi(argv, argc, &idx, &safi);
12034 }
12035
3577f1c5 12036 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
12037 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
12038
10b49f14 12039 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
12040 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
12041
8c1d4cd5
LS
12042 if (argv_find(argv, argc, "remote-as", &idx)) {
12043 if (argv[idx + 1]->arg[0] == 'i')
12044 as_type = AS_INTERNAL;
12045 else if (argv[idx + 1]->arg[0] == 'e')
12046 as_type = AS_EXTERNAL;
8079a413
PG
12047 else if (!asn_str2asn(argv[idx + 1]->arg, &as)) {
12048 vty_out(vty,
12049 "%% Invalid neighbor remote-as value: %s\n",
12050 argv[idx + 1]->arg);
12051 return CMD_SUCCESS;
12052 }
8c1d4cd5
LS
12053 }
12054
96c81f66
LS
12055 if (argv_find(argv, argc, "terse", &idx))
12056 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
12057
85eeb029
DA
12058 if (argv_find(argv, argc, "wide", &idx))
12059 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
12060
12061 if (argv_find(argv, argc, "json", &idx))
12062 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 12063
8c1d4cd5
LS
12064 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
12065 show_flags);
d62a17ae 12066}
12067
5cb5f4d0 12068const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 12069{
5cb5f4d0
DD
12070 if (for_json)
12071 return get_afi_safi_json_str(afi, safi);
d62a17ae 12072 else
5cb5f4d0 12073 return get_afi_safi_vty_str(afi, safi);
27162734
LB
12074}
12075
d62a17ae 12076
12077static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
12078 afi_t afi, safi_t safi,
d7c0a89a
QY
12079 uint16_t adv_smcap, uint16_t adv_rmcap,
12080 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 12081 bool use_json, json_object *json_pref)
d62a17ae 12082{
12083 /* Send-Mode */
12084 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
12085 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
12086 if (use_json) {
12087 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
12088 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
12089 json_object_string_add(json_pref, "sendMode",
12090 "advertisedAndReceived");
12091 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
12092 json_object_string_add(json_pref, "sendMode",
12093 "advertised");
12094 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
12095 json_object_string_add(json_pref, "sendMode",
12096 "received");
12097 } else {
12098 vty_out(vty, " Send-mode: ");
12099 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
12100 vty_out(vty, "advertised");
12101 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
12102 vty_out(vty, "%sreceived",
12103 CHECK_FLAG(p->af_cap[afi][safi],
12104 adv_smcap)
12105 ? ", "
12106 : "");
12107 vty_out(vty, "\n");
12108 }
12109 }
12110
12111 /* Receive-Mode */
12112 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
12113 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
12114 if (use_json) {
12115 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
12116 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12117 json_object_string_add(json_pref, "recvMode",
12118 "advertisedAndReceived");
12119 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12120 json_object_string_add(json_pref, "recvMode",
12121 "advertised");
12122 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12123 json_object_string_add(json_pref, "recvMode",
12124 "received");
12125 } else {
12126 vty_out(vty, " Receive-mode: ");
12127 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12128 vty_out(vty, "advertised");
12129 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12130 vty_out(vty, "%sreceived",
12131 CHECK_FLAG(p->af_cap[afi][safi],
12132 adv_rmcap)
12133 ? ", "
12134 : "");
12135 vty_out(vty, "\n");
12136 }
12137 }
12138}
12139
eea685b6
DA
12140static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
12141 struct peer *p,
eea685b6 12142 json_object *json)
2986cac2 12143{
eea685b6
DA
12144 bool rbit = false;
12145 bool nbit = false;
2986cac2 12146
13909c4f
DS
12147 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
12148 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
feb17238 12149 && (peer_established(p))) {
eea685b6
DA
12150 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
12151 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
2986cac2 12152 }
12153
403e64f8 12154 if (json) {
eea685b6
DA
12155 json_object_boolean_add(json, "rBit", rbit);
12156 json_object_boolean_add(json, "nBit", nbit);
2986cac2 12157 } else {
eea685b6
DA
12158 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
12159 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
2986cac2 12160 }
12161}
12162
13909c4f
DS
12163static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
12164 struct peer *peer,
13909c4f 12165 json_object *json)
2986cac2 12166{
2bb5d39b 12167 const char *mode = "NotApplicable";
2986cac2 12168
403e64f8 12169 if (!json)
a53ca37b 12170 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 12171
13909c4f 12172 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
feb17238 12173 && (peer_established(peer))) {
2986cac2 12174
13909c4f
DS
12175 if ((peer->nsf_af_count == 0)
12176 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12177
2986cac2 12178 mode = "Disable";
12179
13909c4f
DS
12180 } else if (peer->nsf_af_count == 0
12181 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12182
2986cac2 12183 mode = "Helper";
12184
13909c4f
DS
12185 } else if (peer->nsf_af_count != 0
12186 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12187
2986cac2 12188 mode = "Restart";
2986cac2 12189 }
12190 }
12191
403e64f8 12192 if (json)
13909c4f 12193 json_object_string_add(json, "remoteGrMode", mode);
403e64f8 12194 else
0e4e879b 12195 vty_out(vty, "%s\n", mode);
2986cac2 12196}
12197
13909c4f
DS
12198static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
12199 struct peer *p,
13909c4f 12200 json_object *json)
2986cac2 12201{
12202 const char *mode = "Invalid";
12203
403e64f8 12204 if (!json)
a53ca37b 12205 vty_out(vty, " Local GR Mode: ");
2986cac2 12206
12207 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
12208 mode = "Helper";
12209 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
12210 mode = "Restart";
12211 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
12212 mode = "Disable";
2ba1fe69 12213 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 12214 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
12215 mode = "Helper*";
12216 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
12217 mode = "Restart*";
12218 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
12219 mode = "Disable*";
12220 else
12221 mode = "Invalid*";
2ba1fe69 12222 }
2986cac2 12223
403e64f8 12224 if (json)
13909c4f 12225 json_object_string_add(json, "localGrMode", mode);
403e64f8 12226 else
0e4e879b 12227 vty_out(vty, "%s\n", mode);
2986cac2 12228}
12229
13909c4f 12230static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
403e64f8 12231 struct vty *vty, struct peer *peer, json_object *json)
2986cac2 12232{
2ba1fe69 12233 afi_t afi;
12234 safi_t safi;
2986cac2 12235 json_object *json_afi_safi = NULL;
12236 json_object *json_timer = NULL;
12237 json_object *json_endofrib_status = NULL;
9e3b51a7 12238 bool eor_flag = false;
2986cac2 12239
df8d723c
DA
12240 FOREACH_AFI_SAFI_NSF (afi, safi) {
12241 if (!peer->afc[afi][safi])
12242 continue;
2986cac2 12243
df8d723c
DA
12244 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
12245 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
12246 continue;
9e3b51a7 12247
403e64f8 12248 if (json) {
df8d723c
DA
12249 json_afi_safi = json_object_new_object();
12250 json_endofrib_status = json_object_new_object();
12251 json_timer = json_object_new_object();
12252 }
2986cac2 12253
df8d723c
DA
12254 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
12255 eor_flag = true;
12256 else
12257 eor_flag = false;
2986cac2 12258
403e64f8 12259 if (!json) {
df8d723c
DA
12260 vty_out(vty, " %s:\n",
12261 get_afi_safi_str(afi, safi, false));
2986cac2 12262
df8d723c
DA
12263 vty_out(vty, " F bit: ");
12264 }
2986cac2 12265
df8d723c
DA
12266 if (peer->nsf[afi][safi] &&
12267 CHECK_FLAG(peer->af_cap[afi][safi],
12268 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 12269
403e64f8 12270 if (json) {
df8d723c
DA
12271 json_object_boolean_true_add(json_afi_safi,
12272 "fBit");
12273 } else
12274 vty_out(vty, "True\n");
12275 } else {
403e64f8 12276 if (json)
df8d723c
DA
12277 json_object_boolean_false_add(json_afi_safi,
12278 "fBit");
12279 else
12280 vty_out(vty, "False\n");
12281 }
2986cac2 12282
403e64f8 12283 if (!json)
df8d723c 12284 vty_out(vty, " End-of-RIB sent: ");
2986cac2 12285
df8d723c
DA
12286 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12287 PEER_STATUS_EOR_SEND)) {
403e64f8 12288 if (json) {
df8d723c
DA
12289 json_object_boolean_true_add(
12290 json_endofrib_status, "endOfRibSend");
9e3b51a7 12291
df8d723c
DA
12292 PRINT_EOR_JSON(eor_flag);
12293 } else {
12294 vty_out(vty, "Yes\n");
12295 vty_out(vty,
12296 " End-of-RIB sent after update: ");
2986cac2 12297
df8d723c
DA
12298 PRINT_EOR(eor_flag);
12299 }
12300 } else {
403e64f8 12301 if (json) {
df8d723c
DA
12302 json_object_boolean_false_add(
12303 json_endofrib_status, "endOfRibSend");
12304 json_object_boolean_false_add(
12305 json_endofrib_status,
12306 "endOfRibSentAfterUpdate");
13909c4f 12307 } else {
df8d723c
DA
12308 vty_out(vty, "No\n");
12309 vty_out(vty,
12310 " End-of-RIB sent after update: ");
12311 vty_out(vty, "No\n");
13909c4f 12312 }
df8d723c 12313 }
2986cac2 12314
403e64f8 12315 if (!json)
df8d723c 12316 vty_out(vty, " End-of-RIB received: ");
a53ca37b 12317
df8d723c
DA
12318 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12319 PEER_STATUS_EOR_RECEIVED)) {
403e64f8 12320 if (json)
df8d723c
DA
12321 json_object_boolean_true_add(
12322 json_endofrib_status, "endOfRibRecv");
12323 else
12324 vty_out(vty, "Yes\n");
12325 } else {
403e64f8 12326 if (json)
df8d723c
DA
12327 json_object_boolean_false_add(
12328 json_endofrib_status, "endOfRibRecv");
12329 else
12330 vty_out(vty, "No\n");
12331 }
12332
403e64f8 12333 if (json) {
df8d723c
DA
12334 json_object_int_add(json_timer, "stalePathTimer",
12335 peer->bgp->stalepath_time);
12336
12337 if (peer->t_gr_stale != NULL) {
12338 json_object_int_add(json_timer,
12339 "stalePathTimerRemaining",
12340 thread_timer_remain_second(
12341 peer->t_gr_stale));
a53ca37b
DA
12342 }
12343
df8d723c
DA
12344 /* Display Configured Selection
12345 * Deferral only when when
12346 * Gr mode is enabled.
12347 */
12348 if (CHECK_FLAG(peer->flags,
12349 PEER_FLAG_GRACEFUL_RESTART)) {
13909c4f 12350 json_object_int_add(json_timer,
df8d723c 12351 "selectionDeferralTimer",
13909c4f 12352 peer->bgp->stalepath_time);
df8d723c 12353 }
2986cac2 12354
df8d723c
DA
12355 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12356 NULL) {
2986cac2 12357
df8d723c
DA
12358 json_object_int_add(
12359 json_timer,
12360 "selectionDeferralTimerRemaining",
12361 thread_timer_remain_second(
12362 peer->bgp->gr_info[afi][safi]
12363 .t_select_deferral));
12364 }
12365 } else {
12366 vty_out(vty, " Timers:\n");
12367 vty_out(vty,
12368 " Configured Stale Path Time(sec): %u\n",
12369 peer->bgp->stalepath_time);
2986cac2 12370
df8d723c 12371 if (peer->t_gr_stale != NULL)
13909c4f 12372 vty_out(vty,
df8d723c
DA
12373 " Stale Path Remaining(sec): %ld\n",
12374 thread_timer_remain_second(
12375 peer->t_gr_stale));
12376 /* Display Configured Selection
12377 * Deferral only when when
12378 * Gr mode is enabled.
12379 */
12380 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12381 vty_out(vty,
12382 " Configured Selection Deferral Time(sec): %u\n",
12383 peer->bgp->select_defer_time);
2986cac2 12384
df8d723c
DA
12385 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12386 NULL)
12387 vty_out(vty,
12388 " Selection Deferral Time Remaining(sec): %ld\n",
12389 thread_timer_remain_second(
12390 peer->bgp->gr_info[afi][safi]
12391 .t_select_deferral));
12392 }
403e64f8 12393 if (json) {
df8d723c
DA
12394 json_object_object_add(json_afi_safi, "endOfRibStatus",
12395 json_endofrib_status);
12396 json_object_object_add(json_afi_safi, "timers",
12397 json_timer);
12398 json_object_object_add(
12399 json, get_afi_safi_str(afi, safi, true),
12400 json_afi_safi);
2986cac2 12401 }
12402 }
12403}
12404
36235319
QY
12405static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12406 struct peer *p,
36235319 12407 json_object *json)
2986cac2 12408{
403e64f8 12409 if (json) {
2986cac2 12410 json_object *json_timer = NULL;
12411
12412 json_timer = json_object_new_object();
12413
13909c4f
DS
12414 json_object_int_add(json_timer, "configuredRestartTimer",
12415 p->bgp->restart_time);
2986cac2 12416
13909c4f
DS
12417 json_object_int_add(json_timer, "receivedRestartTimer",
12418 p->v_gr_restart);
2986cac2 12419
13909c4f
DS
12420 if (p->t_gr_restart != NULL)
12421 json_object_int_add(
12422 json_timer, "restartTimerRemaining",
12423 thread_timer_remain_second(p->t_gr_restart));
2986cac2 12424
12425 json_object_object_add(json, "timers", json_timer);
12426 } else {
12427
a53ca37b
DA
12428 vty_out(vty, " Timers:\n");
12429 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 12430 p->bgp->restart_time);
2986cac2 12431
a53ca37b 12432 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
12433 p->v_gr_restart);
12434 if (p->t_gr_restart != NULL)
a53ca37b 12435 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 12436 thread_timer_remain_second(p->t_gr_restart));
36235319 12437 if (p->t_gr_restart != NULL) {
a53ca37b 12438 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
12439 thread_timer_remain_second(p->t_gr_restart));
12440 }
2986cac2 12441 }
12442}
12443
12444static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
403e64f8 12445 json_object *json)
2986cac2 12446{
2986cac2 12447 char dn_flag[2] = {0};
2b7165e7
QY
12448 /* '*' + v6 address of neighbor */
12449 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 12450
2986cac2 12451 if (!p->conf_if && peer_dynamic_neighbor(p))
12452 dn_flag[0] = '*';
12453
12454 if (p->conf_if) {
403e64f8 12455 if (json)
47e12884
DA
12456 json_object_string_addf(json, "neighborAddr", "%pSU",
12457 &p->su);
2986cac2 12458 else
47e12884
DA
12459 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12460 &p->su);
2986cac2 12461 } else {
772270f3
QY
12462 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12463 p->host);
2986cac2 12464
403e64f8 12465 if (json)
36235319
QY
12466 json_object_string_add(json, "neighborAddr",
12467 neighborAddr);
2986cac2 12468 else
36235319 12469 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 12470 }
12471
12472 /* more gr info in new format */
403e64f8 12473 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json);
2986cac2 12474}
12475
d62a17ae 12476static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 12477 safi_t safi, bool use_json,
d62a17ae 12478 json_object *json_neigh)
12479{
0291c246
MK
12480 struct bgp_filter *filter;
12481 struct peer_af *paf;
12482 char orf_pfx_name[BUFSIZ];
12483 int orf_pfx_count;
12484 json_object *json_af = NULL;
12485 json_object *json_prefA = NULL;
12486 json_object *json_prefB = NULL;
12487 json_object *json_addr = NULL;
fa36596c 12488 json_object *json_advmap = NULL;
d62a17ae 12489
12490 if (use_json) {
12491 json_addr = json_object_new_object();
12492 json_af = json_object_new_object();
12493 filter = &p->filter[afi][safi];
12494
12495 if (peer_group_active(p))
12496 json_object_string_add(json_addr, "peerGroupMember",
12497 p->group->name);
12498
12499 paf = peer_af_find(p, afi, safi);
12500 if (paf && PAF_SUBGRP(paf)) {
12501 json_object_int_add(json_addr, "updateGroupId",
12502 PAF_UPDGRP(paf)->id);
12503 json_object_int_add(json_addr, "subGroupId",
12504 PAF_SUBGRP(paf)->id);
12505 json_object_int_add(json_addr, "packetQueueLength",
12506 bpacket_queue_virtual_length(paf));
12507 }
12508
12509 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12510 || CHECK_FLAG(p->af_cap[afi][safi],
12511 PEER_CAP_ORF_PREFIX_SM_RCV)
12512 || CHECK_FLAG(p->af_cap[afi][safi],
12513 PEER_CAP_ORF_PREFIX_RM_ADV)
12514 || CHECK_FLAG(p->af_cap[afi][safi],
12515 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12516 json_object_int_add(json_af, "orfType",
12517 ORF_TYPE_PREFIX);
12518 json_prefA = json_object_new_object();
12519 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12520 PEER_CAP_ORF_PREFIX_SM_ADV,
12521 PEER_CAP_ORF_PREFIX_RM_ADV,
12522 PEER_CAP_ORF_PREFIX_SM_RCV,
12523 PEER_CAP_ORF_PREFIX_RM_RCV,
12524 use_json, json_prefA);
12525 json_object_object_add(json_af, "orfPrefixList",
12526 json_prefA);
12527 }
12528
12529 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12530 || CHECK_FLAG(p->af_cap[afi][safi],
12531 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12532 || CHECK_FLAG(p->af_cap[afi][safi],
12533 PEER_CAP_ORF_PREFIX_RM_ADV)
12534 || CHECK_FLAG(p->af_cap[afi][safi],
12535 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12536 json_object_int_add(json_af, "orfOldType",
12537 ORF_TYPE_PREFIX_OLD);
12538 json_prefB = json_object_new_object();
12539 bgp_show_peer_afi_orf_cap(
12540 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12541 PEER_CAP_ORF_PREFIX_RM_ADV,
12542 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12543 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12544 json_prefB);
12545 json_object_object_add(json_af, "orfOldPrefixList",
12546 json_prefB);
12547 }
12548
12549 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12550 || CHECK_FLAG(p->af_cap[afi][safi],
12551 PEER_CAP_ORF_PREFIX_SM_RCV)
12552 || CHECK_FLAG(p->af_cap[afi][safi],
12553 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12554 || CHECK_FLAG(p->af_cap[afi][safi],
12555 PEER_CAP_ORF_PREFIX_RM_ADV)
12556 || CHECK_FLAG(p->af_cap[afi][safi],
12557 PEER_CAP_ORF_PREFIX_RM_RCV)
12558 || CHECK_FLAG(p->af_cap[afi][safi],
12559 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12560 json_object_object_add(json_addr, "afDependentCap",
12561 json_af);
12562 else
12563 json_object_free(json_af);
12564
772270f3
QY
12565 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12566 p->host, afi, safi);
d62a17ae 12567 orf_pfx_count = prefix_bgp_show_prefix_list(
12568 NULL, afi, orf_pfx_name, use_json);
12569
12570 if (CHECK_FLAG(p->af_sflags[afi][safi],
12571 PEER_STATUS_ORF_PREFIX_SEND)
12572 || orf_pfx_count) {
12573 if (CHECK_FLAG(p->af_sflags[afi][safi],
12574 PEER_STATUS_ORF_PREFIX_SEND))
12575 json_object_boolean_true_add(json_neigh,
12576 "orfSent");
12577 if (orf_pfx_count)
12578 json_object_int_add(json_addr, "orfRecvCounter",
12579 orf_pfx_count);
12580 }
12581 if (CHECK_FLAG(p->af_sflags[afi][safi],
12582 PEER_STATUS_ORF_WAIT_REFRESH))
12583 json_object_string_add(
12584 json_addr, "orfFirstUpdate",
12585 "deferredUntilORFOrRouteRefreshRecvd");
12586
12587 if (CHECK_FLAG(p->af_flags[afi][safi],
12588 PEER_FLAG_REFLECTOR_CLIENT))
12589 json_object_boolean_true_add(json_addr,
12590 "routeReflectorClient");
12591 if (CHECK_FLAG(p->af_flags[afi][safi],
12592 PEER_FLAG_RSERVER_CLIENT))
12593 json_object_boolean_true_add(json_addr,
12594 "routeServerClient");
12595 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12596 json_object_boolean_true_add(json_addr,
12597 "inboundSoftConfigPermit");
12598
12599 if (CHECK_FLAG(p->af_flags[afi][safi],
12600 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12601 json_object_boolean_true_add(
12602 json_addr,
12603 "privateAsNumsAllReplacedInUpdatesToNbr");
12604 else if (CHECK_FLAG(p->af_flags[afi][safi],
12605 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12606 json_object_boolean_true_add(
12607 json_addr,
12608 "privateAsNumsReplacedInUpdatesToNbr");
12609 else if (CHECK_FLAG(p->af_flags[afi][safi],
12610 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12611 json_object_boolean_true_add(
12612 json_addr,
12613 "privateAsNumsAllRemovedInUpdatesToNbr");
12614 else if (CHECK_FLAG(p->af_flags[afi][safi],
12615 PEER_FLAG_REMOVE_PRIVATE_AS))
12616 json_object_boolean_true_add(
12617 json_addr,
12618 "privateAsNumsRemovedInUpdatesToNbr");
12619
b2ac1d0d
MS
12620 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12621 if (CHECK_FLAG(p->af_flags[afi][safi],
12622 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12623 json_object_boolean_true_add(json_addr,
12624 "allowAsInOrigin");
12625 else
12626 json_object_int_add(json_addr, "allowAsInCount",
12627 p->allowas_in[afi][safi]);
12628 }
12629
dcc68b5e
MS
12630 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12631 json_object_boolean_true_add(
12632 json_addr,
12633 bgp_addpath_names(p->addpath_type[afi][safi])
12634 ->type_json_name);
d62a17ae 12635
12636 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12637 json_object_string_add(json_addr,
12638 "overrideASNsInOutboundUpdates",
12639 "ifAspathEqualRemoteAs");
12640
12641 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12642 || CHECK_FLAG(p->af_flags[afi][safi],
12643 PEER_FLAG_FORCE_NEXTHOP_SELF))
12644 json_object_boolean_true_add(json_addr,
12645 "routerAlwaysNextHop");
12646 if (CHECK_FLAG(p->af_flags[afi][safi],
12647 PEER_FLAG_AS_PATH_UNCHANGED))
12648 json_object_boolean_true_add(
12649 json_addr, "unchangedAsPathPropogatedToNbr");
12650 if (CHECK_FLAG(p->af_flags[afi][safi],
12651 PEER_FLAG_NEXTHOP_UNCHANGED))
12652 json_object_boolean_true_add(
12653 json_addr, "unchangedNextHopPropogatedToNbr");
12654 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12655 json_object_boolean_true_add(
12656 json_addr, "unchangedMedPropogatedToNbr");
12657 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12658 || CHECK_FLAG(p->af_flags[afi][safi],
12659 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12660 if (CHECK_FLAG(p->af_flags[afi][safi],
12661 PEER_FLAG_SEND_COMMUNITY)
12662 && CHECK_FLAG(p->af_flags[afi][safi],
12663 PEER_FLAG_SEND_EXT_COMMUNITY))
12664 json_object_string_add(json_addr,
12665 "commAttriSentToNbr",
12666 "extendedAndStandard");
12667 else if (CHECK_FLAG(p->af_flags[afi][safi],
12668 PEER_FLAG_SEND_EXT_COMMUNITY))
12669 json_object_string_add(json_addr,
12670 "commAttriSentToNbr",
12671 "extended");
12672 else
12673 json_object_string_add(json_addr,
12674 "commAttriSentToNbr",
12675 "standard");
12676 }
12677 if (CHECK_FLAG(p->af_flags[afi][safi],
12678 PEER_FLAG_DEFAULT_ORIGINATE)) {
12679 if (p->default_rmap[afi][safi].name)
12680 json_object_string_add(
12681 json_addr, "defaultRouteMap",
12682 p->default_rmap[afi][safi].name);
12683
12684 if (paf && PAF_SUBGRP(paf)
12685 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12686 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12687 json_object_boolean_true_add(json_addr,
12688 "defaultSent");
12689 else
12690 json_object_boolean_true_add(json_addr,
12691 "defaultNotSent");
12692 }
12693
dff8f48d 12694 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12695 if (is_evpn_enabled())
60466a63
QY
12696 json_object_boolean_true_add(
12697 json_addr, "advertiseAllVnis");
dff8f48d
MK
12698 }
12699
d62a17ae 12700 if (filter->plist[FILTER_IN].name
12701 || filter->dlist[FILTER_IN].name
12702 || filter->aslist[FILTER_IN].name
12703 || filter->map[RMAP_IN].name)
12704 json_object_boolean_true_add(json_addr,
12705 "inboundPathPolicyConfig");
12706 if (filter->plist[FILTER_OUT].name
12707 || filter->dlist[FILTER_OUT].name
12708 || filter->aslist[FILTER_OUT].name
12709 || filter->map[RMAP_OUT].name || filter->usmap.name)
12710 json_object_boolean_true_add(
12711 json_addr, "outboundPathPolicyConfig");
12712
12713 /* prefix-list */
12714 if (filter->plist[FILTER_IN].name)
12715 json_object_string_add(json_addr,
12716 "incomingUpdatePrefixFilterList",
12717 filter->plist[FILTER_IN].name);
12718 if (filter->plist[FILTER_OUT].name)
12719 json_object_string_add(json_addr,
12720 "outgoingUpdatePrefixFilterList",
12721 filter->plist[FILTER_OUT].name);
12722
12723 /* distribute-list */
12724 if (filter->dlist[FILTER_IN].name)
12725 json_object_string_add(
12726 json_addr, "incomingUpdateNetworkFilterList",
12727 filter->dlist[FILTER_IN].name);
12728 if (filter->dlist[FILTER_OUT].name)
12729 json_object_string_add(
12730 json_addr, "outgoingUpdateNetworkFilterList",
12731 filter->dlist[FILTER_OUT].name);
12732
12733 /* filter-list. */
12734 if (filter->aslist[FILTER_IN].name)
12735 json_object_string_add(json_addr,
12736 "incomingUpdateAsPathFilterList",
12737 filter->aslist[FILTER_IN].name);
12738 if (filter->aslist[FILTER_OUT].name)
12739 json_object_string_add(json_addr,
12740 "outgoingUpdateAsPathFilterList",
12741 filter->aslist[FILTER_OUT].name);
12742
12743 /* route-map. */
12744 if (filter->map[RMAP_IN].name)
12745 json_object_string_add(
12746 json_addr, "routeMapForIncomingAdvertisements",
12747 filter->map[RMAP_IN].name);
12748 if (filter->map[RMAP_OUT].name)
12749 json_object_string_add(
12750 json_addr, "routeMapForOutgoingAdvertisements",
12751 filter->map[RMAP_OUT].name);
12752
9dac9fc8 12753 /* ebgp-requires-policy (inbound) */
1d3fdccf 12754 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12755 && !bgp_inbound_policy_exists(p, filter))
12756 json_object_string_add(
12757 json_addr, "inboundEbgpRequiresPolicy",
12758 "Inbound updates discarded due to missing policy");
12759
12760 /* ebgp-requires-policy (outbound) */
1d3fdccf 12761 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12762 && (!bgp_outbound_policy_exists(p, filter)))
12763 json_object_string_add(
12764 json_addr, "outboundEbgpRequiresPolicy",
12765 "Outbound updates discarded due to missing policy");
12766
d62a17ae 12767 /* unsuppress-map */
12768 if (filter->usmap.name)
12769 json_object_string_add(json_addr,
12770 "selectiveUnsuppressRouteMap",
12771 filter->usmap.name);
12772
fa36596c
MK
12773 /* advertise-map */
12774 if (filter->advmap.aname) {
12775 json_advmap = json_object_new_object();
12776 json_object_string_add(json_advmap, "condition",
12777 filter->advmap.condition
12778 ? "EXIST"
12779 : "NON_EXIST");
12780 json_object_string_add(json_advmap, "conditionMap",
12781 filter->advmap.cname);
12782 json_object_string_add(json_advmap, "advertiseMap",
12783 filter->advmap.aname);
ecf2b628
QY
12784 json_object_string_add(
12785 json_advmap, "advertiseStatus",
12786 filter->advmap.update_type ==
12787 UPDATE_TYPE_ADVERTISE
12788 ? "Advertise"
12789 : "Withdraw");
fa36596c
MK
12790 json_object_object_add(json_addr, "advertiseMap",
12791 json_advmap);
12792 }
12793
d62a17ae 12794 /* Receive prefix count */
12795 json_object_int_add(json_addr, "acceptedPrefixCounter",
12796 p->pcount[afi][safi]);
50e05855
AD
12797 if (paf && PAF_SUBGRP(paf))
12798 json_object_int_add(json_addr, "sentPrefixCounter",
12799 (PAF_SUBGRP(paf))->scount);
d62a17ae 12800
fde246e8
DA
12801 /* Maximum prefix */
12802 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12803 json_object_int_add(json_addr, "prefixOutAllowedMax",
12804 p->pmax_out[afi][safi]);
12805
d62a17ae 12806 /* Maximum prefix */
12807 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12808 json_object_int_add(json_addr, "prefixAllowedMax",
12809 p->pmax[afi][safi]);
12810 if (CHECK_FLAG(p->af_flags[afi][safi],
12811 PEER_FLAG_MAX_PREFIX_WARNING))
12812 json_object_boolean_true_add(
12813 json_addr, "prefixAllowedMaxWarning");
12814 json_object_int_add(json_addr,
12815 "prefixAllowedWarningThresh",
12816 p->pmax_threshold[afi][safi]);
12817 if (p->pmax_restart[afi][safi])
12818 json_object_int_add(
12819 json_addr,
12820 "prefixAllowedRestartIntervalMsecs",
12821 p->pmax_restart[afi][safi] * 60000);
12822 }
2986cac2 12823 json_object_object_add(json_neigh,
36235319 12824 get_afi_safi_str(afi, safi, true),
d62a17ae 12825 json_addr);
12826
12827 } else {
12828 filter = &p->filter[afi][safi];
12829
12830 vty_out(vty, " For address family: %s\n",
5cb5f4d0 12831 get_afi_safi_str(afi, safi, false));
d62a17ae 12832
12833 if (peer_group_active(p))
12834 vty_out(vty, " %s peer-group member\n",
12835 p->group->name);
12836
12837 paf = peer_af_find(p, afi, safi);
12838 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 12839 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 12840 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12841 vty_out(vty, " Packet Queue length %d\n",
12842 bpacket_queue_virtual_length(paf));
12843 } else {
12844 vty_out(vty, " Not part of any update group\n");
12845 }
12846 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12847 || CHECK_FLAG(p->af_cap[afi][safi],
12848 PEER_CAP_ORF_PREFIX_SM_RCV)
12849 || CHECK_FLAG(p->af_cap[afi][safi],
12850 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12851 || CHECK_FLAG(p->af_cap[afi][safi],
12852 PEER_CAP_ORF_PREFIX_RM_ADV)
12853 || CHECK_FLAG(p->af_cap[afi][safi],
12854 PEER_CAP_ORF_PREFIX_RM_RCV)
12855 || CHECK_FLAG(p->af_cap[afi][safi],
12856 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12857 vty_out(vty, " AF-dependant capabilities:\n");
12858
12859 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12860 || CHECK_FLAG(p->af_cap[afi][safi],
12861 PEER_CAP_ORF_PREFIX_SM_RCV)
12862 || CHECK_FLAG(p->af_cap[afi][safi],
12863 PEER_CAP_ORF_PREFIX_RM_ADV)
12864 || CHECK_FLAG(p->af_cap[afi][safi],
12865 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12866 vty_out(vty,
12867 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12868 ORF_TYPE_PREFIX);
12869 bgp_show_peer_afi_orf_cap(
12870 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12871 PEER_CAP_ORF_PREFIX_RM_ADV,
12872 PEER_CAP_ORF_PREFIX_SM_RCV,
12873 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12874 }
12875 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12876 || CHECK_FLAG(p->af_cap[afi][safi],
12877 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12878 || CHECK_FLAG(p->af_cap[afi][safi],
12879 PEER_CAP_ORF_PREFIX_RM_ADV)
12880 || CHECK_FLAG(p->af_cap[afi][safi],
12881 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12882 vty_out(vty,
12883 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12884 ORF_TYPE_PREFIX_OLD);
12885 bgp_show_peer_afi_orf_cap(
12886 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12887 PEER_CAP_ORF_PREFIX_RM_ADV,
12888 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12889 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12890 }
12891
772270f3
QY
12892 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12893 p->host, afi, safi);
d62a17ae 12894 orf_pfx_count = prefix_bgp_show_prefix_list(
12895 NULL, afi, orf_pfx_name, use_json);
12896
12897 if (CHECK_FLAG(p->af_sflags[afi][safi],
12898 PEER_STATUS_ORF_PREFIX_SEND)
12899 || orf_pfx_count) {
12900 vty_out(vty, " Outbound Route Filter (ORF):");
12901 if (CHECK_FLAG(p->af_sflags[afi][safi],
12902 PEER_STATUS_ORF_PREFIX_SEND))
12903 vty_out(vty, " sent;");
12904 if (orf_pfx_count)
12905 vty_out(vty, " received (%d entries)",
12906 orf_pfx_count);
12907 vty_out(vty, "\n");
12908 }
12909 if (CHECK_FLAG(p->af_sflags[afi][safi],
12910 PEER_STATUS_ORF_WAIT_REFRESH))
12911 vty_out(vty,
12912 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12913
12914 if (CHECK_FLAG(p->af_flags[afi][safi],
12915 PEER_FLAG_REFLECTOR_CLIENT))
12916 vty_out(vty, " Route-Reflector Client\n");
12917 if (CHECK_FLAG(p->af_flags[afi][safi],
12918 PEER_FLAG_RSERVER_CLIENT))
12919 vty_out(vty, " Route-Server Client\n");
12920 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12921 vty_out(vty,
12922 " Inbound soft reconfiguration allowed\n");
12923
12924 if (CHECK_FLAG(p->af_flags[afi][safi],
12925 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12926 vty_out(vty,
12927 " Private AS numbers (all) replaced in updates to this neighbor\n");
12928 else if (CHECK_FLAG(p->af_flags[afi][safi],
12929 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12930 vty_out(vty,
12931 " Private AS numbers replaced in updates to this neighbor\n");
12932 else if (CHECK_FLAG(p->af_flags[afi][safi],
12933 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12934 vty_out(vty,
12935 " Private AS numbers (all) removed in updates to this neighbor\n");
12936 else if (CHECK_FLAG(p->af_flags[afi][safi],
12937 PEER_FLAG_REMOVE_PRIVATE_AS))
12938 vty_out(vty,
12939 " Private AS numbers removed in updates to this neighbor\n");
12940
b2ac1d0d
MS
12941 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12942 if (CHECK_FLAG(p->af_flags[afi][safi],
12943 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12944 vty_out(vty,
12945 " Local AS allowed as path origin\n");
12946 else
12947 vty_out(vty,
12948 " Local AS allowed in path, %d occurrences\n",
12949 p->allowas_in[afi][safi]);
12950 }
12951
dcc68b5e
MS
12952 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12953 vty_out(vty, " %s\n",
12954 bgp_addpath_names(p->addpath_type[afi][safi])
12955 ->human_description);
d62a17ae 12956
12957 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12958 vty_out(vty,
12959 " Override ASNs in outbound updates if aspath equals remote-as\n");
12960
12961 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12962 || CHECK_FLAG(p->af_flags[afi][safi],
12963 PEER_FLAG_FORCE_NEXTHOP_SELF))
12964 vty_out(vty, " NEXT_HOP is always this router\n");
12965 if (CHECK_FLAG(p->af_flags[afi][safi],
12966 PEER_FLAG_AS_PATH_UNCHANGED))
12967 vty_out(vty,
12968 " AS_PATH is propagated unchanged to this neighbor\n");
12969 if (CHECK_FLAG(p->af_flags[afi][safi],
12970 PEER_FLAG_NEXTHOP_UNCHANGED))
12971 vty_out(vty,
12972 " NEXT_HOP is propagated unchanged to this neighbor\n");
12973 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12974 vty_out(vty,
12975 " MED is propagated unchanged to this neighbor\n");
12976 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12977 || CHECK_FLAG(p->af_flags[afi][safi],
12978 PEER_FLAG_SEND_EXT_COMMUNITY)
12979 || CHECK_FLAG(p->af_flags[afi][safi],
12980 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12981 vty_out(vty,
12982 " Community attribute sent to this neighbor");
12983 if (CHECK_FLAG(p->af_flags[afi][safi],
12984 PEER_FLAG_SEND_COMMUNITY)
12985 && CHECK_FLAG(p->af_flags[afi][safi],
12986 PEER_FLAG_SEND_EXT_COMMUNITY)
12987 && CHECK_FLAG(p->af_flags[afi][safi],
12988 PEER_FLAG_SEND_LARGE_COMMUNITY))
12989 vty_out(vty, "(all)\n");
12990 else if (CHECK_FLAG(p->af_flags[afi][safi],
12991 PEER_FLAG_SEND_LARGE_COMMUNITY))
12992 vty_out(vty, "(large)\n");
12993 else if (CHECK_FLAG(p->af_flags[afi][safi],
12994 PEER_FLAG_SEND_EXT_COMMUNITY))
12995 vty_out(vty, "(extended)\n");
12996 else
12997 vty_out(vty, "(standard)\n");
12998 }
12999 if (CHECK_FLAG(p->af_flags[afi][safi],
13000 PEER_FLAG_DEFAULT_ORIGINATE)) {
13001 vty_out(vty, " Default information originate,");
13002
13003 if (p->default_rmap[afi][safi].name)
13004 vty_out(vty, " default route-map %s%s,",
13005 p->default_rmap[afi][safi].map ? "*"
13006 : "",
13007 p->default_rmap[afi][safi].name);
13008 if (paf && PAF_SUBGRP(paf)
13009 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
13010 SUBGRP_STATUS_DEFAULT_ORIGINATE))
13011 vty_out(vty, " default sent\n");
13012 else
13013 vty_out(vty, " default not sent\n");
13014 }
13015
dff8f48d
MK
13016 /* advertise-vni-all */
13017 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 13018 if (is_evpn_enabled())
dff8f48d
MK
13019 vty_out(vty, " advertise-all-vni\n");
13020 }
13021
d62a17ae 13022 if (filter->plist[FILTER_IN].name
13023 || filter->dlist[FILTER_IN].name
13024 || filter->aslist[FILTER_IN].name
13025 || filter->map[RMAP_IN].name)
13026 vty_out(vty, " Inbound path policy configured\n");
13027 if (filter->plist[FILTER_OUT].name
13028 || filter->dlist[FILTER_OUT].name
13029 || filter->aslist[FILTER_OUT].name
13030 || filter->map[RMAP_OUT].name || filter->usmap.name)
13031 vty_out(vty, " Outbound path policy configured\n");
13032
13033 /* prefix-list */
13034 if (filter->plist[FILTER_IN].name)
13035 vty_out(vty,
13036 " Incoming update prefix filter list is %s%s\n",
13037 filter->plist[FILTER_IN].plist ? "*" : "",
13038 filter->plist[FILTER_IN].name);
13039 if (filter->plist[FILTER_OUT].name)
13040 vty_out(vty,
13041 " Outgoing update prefix filter list is %s%s\n",
13042 filter->plist[FILTER_OUT].plist ? "*" : "",
13043 filter->plist[FILTER_OUT].name);
13044
13045 /* distribute-list */
13046 if (filter->dlist[FILTER_IN].name)
13047 vty_out(vty,
13048 " Incoming update network filter list is %s%s\n",
13049 filter->dlist[FILTER_IN].alist ? "*" : "",
13050 filter->dlist[FILTER_IN].name);
13051 if (filter->dlist[FILTER_OUT].name)
13052 vty_out(vty,
13053 " Outgoing update network filter list is %s%s\n",
13054 filter->dlist[FILTER_OUT].alist ? "*" : "",
13055 filter->dlist[FILTER_OUT].name);
13056
13057 /* filter-list. */
13058 if (filter->aslist[FILTER_IN].name)
13059 vty_out(vty,
13060 " Incoming update AS path filter list is %s%s\n",
13061 filter->aslist[FILTER_IN].aslist ? "*" : "",
13062 filter->aslist[FILTER_IN].name);
13063 if (filter->aslist[FILTER_OUT].name)
13064 vty_out(vty,
13065 " Outgoing update AS path filter list is %s%s\n",
13066 filter->aslist[FILTER_OUT].aslist ? "*" : "",
13067 filter->aslist[FILTER_OUT].name);
13068
13069 /* route-map. */
13070 if (filter->map[RMAP_IN].name)
13071 vty_out(vty,
13072 " Route map for incoming advertisements is %s%s\n",
13073 filter->map[RMAP_IN].map ? "*" : "",
13074 filter->map[RMAP_IN].name);
13075 if (filter->map[RMAP_OUT].name)
13076 vty_out(vty,
13077 " Route map for outgoing advertisements is %s%s\n",
13078 filter->map[RMAP_OUT].map ? "*" : "",
13079 filter->map[RMAP_OUT].name);
13080
9dac9fc8 13081 /* ebgp-requires-policy (inbound) */
1d3fdccf 13082 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
13083 && !bgp_inbound_policy_exists(p, filter))
13084 vty_out(vty,
13085 " Inbound updates discarded due to missing policy\n");
13086
13087 /* ebgp-requires-policy (outbound) */
1d3fdccf 13088 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
13089 && !bgp_outbound_policy_exists(p, filter))
13090 vty_out(vty,
13091 " Outbound updates discarded due to missing policy\n");
13092
d62a17ae 13093 /* unsuppress-map */
13094 if (filter->usmap.name)
13095 vty_out(vty,
13096 " Route map for selective unsuppress is %s%s\n",
13097 filter->usmap.map ? "*" : "",
13098 filter->usmap.name);
13099
7f7940e6
MK
13100 /* advertise-map */
13101 if (filter->advmap.aname && filter->advmap.cname)
13102 vty_out(vty,
13103 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
13104 filter->advmap.condition ? "EXIST"
13105 : "NON_EXIST",
13106 filter->advmap.cmap ? "*" : "",
13107 filter->advmap.cname,
13108 filter->advmap.amap ? "*" : "",
13109 filter->advmap.aname,
ecf2b628
QY
13110 filter->advmap.update_type ==
13111 UPDATE_TYPE_ADVERTISE
c385f82a
MK
13112 ? "Advertise"
13113 : "Withdraw");
7f7940e6 13114
d62a17ae 13115 /* Receive prefix count */
6cde4b45 13116 vty_out(vty, " %u accepted prefixes\n",
a0a87037 13117 p->pcount[afi][safi]);
d62a17ae 13118
fde246e8
DA
13119 /* maximum-prefix-out */
13120 if (CHECK_FLAG(p->af_flags[afi][safi],
13121 PEER_FLAG_MAX_PREFIX_OUT))
13122 vty_out(vty,
6cde4b45 13123 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
13124 p->pmax_out[afi][safi]);
13125
d62a17ae 13126 /* Maximum prefix */
13127 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 13128 vty_out(vty,
6cde4b45 13129 " Maximum prefixes allowed %u%s\n",
d62a17ae 13130 p->pmax[afi][safi],
13131 CHECK_FLAG(p->af_flags[afi][safi],
13132 PEER_FLAG_MAX_PREFIX_WARNING)
13133 ? " (warning-only)"
13134 : "");
13135 vty_out(vty, " Threshold for warning message %d%%",
13136 p->pmax_threshold[afi][safi]);
13137 if (p->pmax_restart[afi][safi])
13138 vty_out(vty, ", restart interval %d min",
13139 p->pmax_restart[afi][safi]);
13140 vty_out(vty, "\n");
13141 }
13142
13143 vty_out(vty, "\n");
13144 }
13145}
13146
9f049418 13147static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 13148 json_object *json)
718e3744 13149{
d62a17ae 13150 struct bgp *bgp;
d62a17ae 13151 char timebuf[BGP_UPTIME_LEN];
13152 char dn_flag[2];
d62a17ae 13153 afi_t afi;
13154 safi_t safi;
d7c0a89a
QY
13155 uint16_t i;
13156 uint8_t *msg;
d62a17ae 13157 json_object *json_neigh = NULL;
13158 time_t epoch_tbuf;
4ab46701 13159 uint32_t sync_tcp_mss;
718e3744 13160
d62a17ae 13161 bgp = p->bgp;
13162
13163 if (use_json)
13164 json_neigh = json_object_new_object();
13165
13166 memset(dn_flag, '\0', sizeof(dn_flag));
13167 if (!p->conf_if && peer_dynamic_neighbor(p))
13168 dn_flag[0] = '*';
13169
13170 if (!use_json) {
13171 if (p->conf_if) /* Configured interface name. */
47e12884
DA
13172 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
13173 &p->su);
d62a17ae 13174 else /* Configured IP address. */
13175 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
13176 p->host);
13177 }
13178
13179 if (use_json) {
13180 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
13181 json_object_string_add(json_neigh, "bgpNeighborAddr",
13182 "none");
13183 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
47e12884
DA
13184 json_object_string_addf(json_neigh, "bgpNeighborAddr",
13185 "%pSU", &p->su);
d62a17ae 13186
44a4d55e 13187 asn_asn2json(json_neigh, "remoteAs", p->as, bgp->asnotation);
d62a17ae 13188
13189 if (p->change_local_as)
44a4d55e
PG
13190 asn_asn2json(json_neigh, "localAs", p->change_local_as,
13191 bgp->asnotation);
d62a17ae 13192 else
44a4d55e
PG
13193 asn_asn2json(json_neigh, "localAs", p->local_as,
13194 bgp->asnotation);
d62a17ae 13195
13196 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
13197 json_object_boolean_true_add(json_neigh,
13198 "localAsNoPrepend");
13199
13200 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
13201 json_object_boolean_true_add(json_neigh,
13202 "localAsReplaceAs");
13203 } else {
44a4d55e
PG
13204 if ((p->as_type == AS_SPECIFIED) ||
13205 (p->as_type == AS_EXTERNAL) ||
13206 (p->as_type == AS_INTERNAL)) {
13207 vty_out(vty, "remote AS ");
13208 vty_out(vty, ASN_FORMAT(bgp->asnotation), &p->as);
13209 vty_out(vty, ", ");
13210 } else
d62a17ae 13211 vty_out(vty, "remote AS Unspecified, ");
44a4d55e
PG
13212 vty_out(vty, "local AS ");
13213 vty_out(vty, ASN_FORMAT(bgp->asnotation),
13214 p->change_local_as ? &p->change_local_as
13215 : &p->local_as);
13216 vty_out(vty, "%s%s, ",
d62a17ae 13217 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
13218 ? " no-prepend"
13219 : "",
13220 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
13221 ? " replace-as"
13222 : "");
13223 }
faa16034
DS
13224 /* peer type internal or confed-internal */
13225 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 13226 if (use_json) {
13227 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13228 json_object_boolean_true_add(
13229 json_neigh, "nbrConfedInternalLink");
13230 else
13231 json_object_boolean_true_add(json_neigh,
13232 "nbrInternalLink");
13233 } else {
13234 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13235 vty_out(vty, "confed-internal link\n");
13236 else
13237 vty_out(vty, "internal link\n");
13238 }
faa16034
DS
13239 /* peer type external or confed-external */
13240 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 13241 if (use_json) {
13242 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13243 json_object_boolean_true_add(
13244 json_neigh, "nbrConfedExternalLink");
13245 else
13246 json_object_boolean_true_add(json_neigh,
13247 "nbrExternalLink");
13248 } else {
13249 if (bgp_confederation_peers_check(bgp, p->as))
13250 vty_out(vty, "confed-external link\n");
13251 else
13252 vty_out(vty, "external link\n");
13253 }
faa16034
DS
13254 } else {
13255 if (use_json)
13256 json_object_boolean_true_add(json_neigh,
13257 "nbrUnspecifiedLink");
13258 else
13259 vty_out(vty, "unspecified link\n");
d62a17ae 13260 }
13261
d864dd9e
EB
13262 /* Roles */
13263 if (use_json) {
13264 json_object_string_add(json_neigh, "localRole",
8f2d6021
EB
13265 bgp_get_name_by_role(p->local_role));
13266 json_object_string_add(json_neigh, "remoteRole",
13267 bgp_get_name_by_role(p->remote_role));
d864dd9e
EB
13268 } else {
13269 vty_out(vty, " Local Role: %s\n",
8f2d6021
EB
13270 bgp_get_name_by_role(p->local_role));
13271 vty_out(vty, " Remote Role: %s\n",
13272 bgp_get_name_by_role(p->remote_role));
d864dd9e
EB
13273 }
13274
13275
d62a17ae 13276 /* Description. */
13277 if (p->desc) {
13278 if (use_json)
13279 json_object_string_add(json_neigh, "nbrDesc", p->desc);
13280 else
13281 vty_out(vty, " Description: %s\n", p->desc);
13282 }
13283
13284 if (p->hostname) {
13285 if (use_json) {
432e7e46
KQ
13286 json_object_string_add(json_neigh, "hostname",
13287 p->hostname);
d62a17ae 13288
13289 if (p->domainname)
13290 json_object_string_add(json_neigh, "domainname",
13291 p->domainname);
13292 } else {
13293 if (p->domainname && (p->domainname[0] != '\0'))
13294 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13295 p->domainname);
13296 else
13297 vty_out(vty, "Hostname: %s\n", p->hostname);
13298 }
432e7e46
KQ
13299 } else {
13300 if (use_json)
13301 json_object_string_add(json_neigh, "hostname",
13302 "Unknown");
d62a17ae 13303 }
13304
13305 /* Peer-group */
13306 if (p->group) {
13307 if (use_json) {
13308 json_object_string_add(json_neigh, "peerGroup",
13309 p->group->name);
13310
13311 if (dn_flag[0]) {
13312 struct prefix prefix, *range = NULL;
13313
0154d8ce
DS
13314 if (sockunion2hostprefix(&(p->su), &prefix))
13315 range = peer_group_lookup_dynamic_neighbor_range(
13316 p->group, &prefix);
d62a17ae 13317
13318 if (range) {
67d7e256 13319 json_object_string_addf(
d62a17ae 13320 json_neigh,
67d7e256
DA
13321 "peerSubnetRangeGroup", "%pFX",
13322 range);
d62a17ae 13323 }
13324 }
13325 } else {
13326 vty_out(vty,
13327 " Member of peer-group %s for session parameters\n",
13328 p->group->name);
13329
13330 if (dn_flag[0]) {
13331 struct prefix prefix, *range = NULL;
13332
0154d8ce
DS
13333 if (sockunion2hostprefix(&(p->su), &prefix))
13334 range = peer_group_lookup_dynamic_neighbor_range(
13335 p->group, &prefix);
d62a17ae 13336
13337 if (range) {
d62a17ae 13338 vty_out(vty,
1b78780b
DL
13339 " Belongs to the subnet range group: %pFX\n",
13340 range);
d62a17ae 13341 }
13342 }
13343 }
13344 }
13345
13346 if (use_json) {
13347 /* Administrative shutdown. */
cb9196e7
DS
13348 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13349 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13350 json_object_boolean_true_add(json_neigh,
13351 "adminShutDown");
13352
13353 /* BGP Version. */
13354 json_object_int_add(json_neigh, "bgpVersion", 4);
c949c771
DA
13355 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
13356 &p->remote_id);
13357 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
13358 &bgp->router_id);
d62a17ae 13359
13360 /* Confederation */
13361 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13362 && bgp_confederation_peers_check(bgp, p->as))
13363 json_object_boolean_true_add(json_neigh,
13364 "nbrCommonAdmin");
13365
13366 /* Status. */
13367 json_object_string_add(
13368 json_neigh, "bgpState",
13369 lookup_msg(bgp_status_msg, p->status, NULL));
13370
feb17238 13371 if (peer_established(p)) {
d62a17ae 13372 time_t uptime;
d62a17ae 13373
083ec940 13374 uptime = monotime(NULL);
d62a17ae 13375 uptime -= p->uptime;
d62a17ae 13376 epoch_tbuf = time(NULL) - uptime;
13377
d3c7efed
DS
13378 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13379 uptime * 1000);
d62a17ae 13380 json_object_string_add(json_neigh, "bgpTimerUpString",
13381 peer_uptime(p->uptime, timebuf,
13382 BGP_UPTIME_LEN, 0,
13383 NULL));
13384 json_object_int_add(json_neigh,
13385 "bgpTimerUpEstablishedEpoch",
13386 epoch_tbuf);
13387 }
13388
13389 else if (p->status == Active) {
13390 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13391 json_object_string_add(json_neigh, "bgpStateIs",
13392 "passive");
13393 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13394 json_object_string_add(json_neigh, "bgpStateIs",
13395 "passiveNSF");
13396 }
13397
13398 /* read timer */
13399 time_t uptime;
a2700b50 13400 struct tm tm;
d62a17ae 13401
083ec940 13402 uptime = monotime(NULL);
d62a17ae 13403 uptime -= p->readtime;
a2700b50
MS
13404 gmtime_r(&uptime, &tm);
13405
d62a17ae 13406 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
13407 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13408 + (tm.tm_hour * 3600000));
d62a17ae 13409
083ec940 13410 uptime = monotime(NULL);
d62a17ae 13411 uptime -= p->last_write;
a2700b50
MS
13412 gmtime_r(&uptime, &tm);
13413
d62a17ae 13414 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
13415 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13416 + (tm.tm_hour * 3600000));
d62a17ae 13417
083ec940 13418 uptime = monotime(NULL);
d62a17ae 13419 uptime -= p->update_time;
a2700b50
MS
13420 gmtime_r(&uptime, &tm);
13421
d62a17ae 13422 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
13423 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13424 + (tm.tm_hour * 3600000));
d62a17ae 13425
13426 /* Configured timer values. */
9b1b9623
TA
13427 json_object_int_add(json_neigh,
13428 "bgpTimerConfiguredHoldTimeMsecs",
e93d5c29
TA
13429 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13430 ? p->holdtime * 1000
13431 : bgp->default_holdtime * 1000);
13432 json_object_int_add(json_neigh,
13433 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13434 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13435 ? p->keepalive * 1000
13436 : bgp->default_keepalive * 1000);
d62a17ae 13437 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13438 p->v_holdtime * 1000);
13439 json_object_int_add(json_neigh,
13440 "bgpTimerKeepAliveIntervalMsecs",
13441 p->v_keepalive * 1000);
d43114f3
DS
13442 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13443 json_object_int_add(json_neigh,
13444 "bgpTimerDelayOpenTimeMsecs",
13445 p->v_delayopen * 1000);
13446 }
13447
4ab46701
AR
13448 /* Configured and Synced tcp-mss value for peer */
13449 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13450 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13451 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13452 p->tcp_mss);
13453 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13454 sync_tcp_mss);
13455 }
13456
d08c0c80
DA
13457 /* Extended Optional Parameters Length for BGP OPEN Message */
13458 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13459 json_object_boolean_true_add(
13460 json_neigh, "extendedOptionalParametersLength");
13461 else
13462 json_object_boolean_false_add(
13463 json_neigh, "extendedOptionalParametersLength");
6e37924b
DA
13464
13465 /* Conditional advertisements */
13466 json_object_int_add(
13467 json_neigh,
13468 "bgpTimerConfiguredConditionalAdvertisementsSec",
13469 bgp->condition_check_period);
13470 if (thread_is_scheduled(bgp->t_condition_check))
13471 json_object_int_add(
13472 json_neigh,
13473 "bgpTimerUntilConditionalAdvertisementsSec",
13474 thread_timer_remain_second(
13475 bgp->t_condition_check));
d62a17ae 13476 } else {
13477 /* Administrative shutdown. */
cb9196e7
DS
13478 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13479 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13480 vty_out(vty, " Administratively shut down\n");
13481
13482 /* BGP Version. */
13483 vty_out(vty, " BGP version 4");
07380148
DA
13484 vty_out(vty, ", remote router ID %pI4", &p->remote_id);
13485 vty_out(vty, ", local router ID %pI4\n", &bgp->router_id);
d62a17ae 13486
13487 /* Confederation */
13488 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13489 && bgp_confederation_peers_check(bgp, p->as))
13490 vty_out(vty,
13491 " Neighbor under common administration\n");
13492
13493 /* Status. */
13494 vty_out(vty, " BGP state = %s",
13495 lookup_msg(bgp_status_msg, p->status, NULL));
13496
feb17238 13497 if (peer_established(p))
d62a17ae 13498 vty_out(vty, ", up for %8s",
13499 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13500 0, NULL));
13501
13502 else if (p->status == Active) {
13503 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13504 vty_out(vty, " (passive)");
13505 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13506 vty_out(vty, " (NSF passive)");
13507 }
13508 vty_out(vty, "\n");
13509
13510 /* read timer */
13511 vty_out(vty, " Last read %s",
13512 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13513 NULL));
13514 vty_out(vty, ", Last write %s\n",
13515 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13516 NULL));
13517
13518 /* Configured timer values. */
13519 vty_out(vty,
e93d5c29 13520 " Hold time is %d seconds, keepalive interval is %d seconds\n",
d62a17ae 13521 p->v_holdtime, p->v_keepalive);
e93d5c29
TA
13522 vty_out(vty, " Configured hold time is %d seconds",
13523 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13524 ? p->holdtime
13525 : bgp->default_holdtime);
9b1b9623 13526 vty_out(vty, ", keepalive interval is %d seconds\n",
e93d5c29
TA
13527 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13528 ? p->keepalive
13529 : bgp->default_keepalive);
d43114f3
DS
13530 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13531 vty_out(vty,
13532 " Configured DelayOpenTime is %d seconds\n",
13533 p->delayopen);
4ab46701
AR
13534
13535 /* Configured and synced tcp-mss value for peer */
13536 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13537 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13538 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13539 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13540 }
d08c0c80
DA
13541
13542 /* Extended Optional Parameters Length for BGP OPEN Message */
13543 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13544 vty_out(vty,
13545 " Extended Optional Parameters Length is enabled\n");
6e37924b
DA
13546
13547 /* Conditional advertisements */
13548 vty_out(vty,
13549 " Configured conditional advertisements interval is %d seconds\n",
13550 bgp->condition_check_period);
13551 if (thread_is_scheduled(bgp->t_condition_check))
13552 vty_out(vty,
13553 " Time until conditional advertisements begin is %lu seconds\n",
13554 thread_timer_remain_second(
13555 bgp->t_condition_check));
d62a17ae 13556 }
13557 /* Capability. */
10711563
DA
13558 if (peer_established(p) &&
13559 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13560 if (use_json) {
13561 json_object *json_cap = NULL;
d62a17ae 13562
10711563 13563 json_cap = json_object_new_object();
d62a17ae 13564
10711563
DA
13565 /* AS4 */
13566 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13567 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13568 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13569 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
ef56aee4 13570 json_object_string_add(
10711563 13571 json_cap, "4byteAs",
ef56aee4 13572 "advertisedAndReceived");
10711563
DA
13573 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13574 json_object_string_add(json_cap,
13575 "4byteAs",
13576 "advertised");
13577 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13578 json_object_string_add(json_cap,
13579 "4byteAs",
13580 "received");
13581 }
ef56aee4 13582
10711563
DA
13583 /* Extended Message Support */
13584 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13585 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13586 json_object_string_add(json_cap,
13587 "extendedMessage",
13588 "advertisedAndReceived");
13589 else if (CHECK_FLAG(p->cap,
13590 PEER_CAP_EXTENDED_MESSAGE_ADV))
13591 json_object_string_add(json_cap,
13592 "extendedMessage",
13593 "advertised");
13594 else if (CHECK_FLAG(p->cap,
13595 PEER_CAP_EXTENDED_MESSAGE_RCV))
13596 json_object_string_add(json_cap,
13597 "extendedMessage",
13598 "received");
ef56aee4 13599
10711563
DA
13600 /* AddPath */
13601 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13602 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13603 json_object *json_add = NULL;
13604 const char *print_store;
d62a17ae 13605
10711563 13606 json_add = json_object_new_object();
d62a17ae 13607
10711563
DA
13608 FOREACH_AFI_SAFI (afi, safi) {
13609 json_object *json_sub = NULL;
13610 json_sub = json_object_new_object();
13611 print_store = get_afi_safi_str(
13612 afi, safi, true);
d62a17ae 13613
10711563
DA
13614 if (CHECK_FLAG(
13615 p->af_cap[afi][safi],
13616 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13617 CHECK_FLAG(
13618 p->af_cap[afi][safi],
13619 PEER_CAP_ADDPATH_AF_TX_RCV)) {
05c7a1cc
QY
13620 if (CHECK_FLAG(
13621 p->af_cap[afi]
13622 [safi],
10711563
DA
13623 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13624 CHECK_FLAG(
05c7a1cc
QY
13625 p->af_cap[afi]
13626 [safi],
10711563
DA
13627 PEER_CAP_ADDPATH_AF_TX_RCV))
13628 json_object_boolean_true_add(
13629 json_sub,
13630 "txAdvertisedAndReceived");
13631 else if (
13632 CHECK_FLAG(
13633 p->af_cap[afi]
13634 [safi],
13635 PEER_CAP_ADDPATH_AF_TX_ADV))
13636 json_object_boolean_true_add(
13637 json_sub,
13638 "txAdvertised");
13639 else if (
13640 CHECK_FLAG(
13641 p->af_cap[afi]
13642 [safi],
13643 PEER_CAP_ADDPATH_AF_TX_RCV))
13644 json_object_boolean_true_add(
13645 json_sub,
13646 "txReceived");
13647 }
d62a17ae 13648
10711563
DA
13649 if (CHECK_FLAG(
13650 p->af_cap[afi][safi],
13651 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13652 CHECK_FLAG(
13653 p->af_cap[afi][safi],
13654 PEER_CAP_ADDPATH_AF_RX_RCV)) {
05c7a1cc
QY
13655 if (CHECK_FLAG(
13656 p->af_cap[afi]
13657 [safi],
10711563
DA
13658 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13659 CHECK_FLAG(
13660 p->af_cap[afi]
13661 [safi],
13662 PEER_CAP_ADDPATH_AF_RX_RCV))
13663 json_object_boolean_true_add(
13664 json_sub,
13665 "rxAdvertisedAndReceived");
13666 else if (
13667 CHECK_FLAG(
13668 p->af_cap[afi]
13669 [safi],
13670 PEER_CAP_ADDPATH_AF_RX_ADV))
13671 json_object_boolean_true_add(
13672 json_sub,
13673 "rxAdvertised");
13674 else if (
13675 CHECK_FLAG(
13676 p->af_cap[afi]
13677 [safi],
13678 PEER_CAP_ADDPATH_AF_RX_RCV))
13679 json_object_boolean_true_add(
13680 json_sub,
13681 "rxReceived");
05c7a1cc
QY
13682 }
13683
10711563
DA
13684 if (CHECK_FLAG(
13685 p->af_cap[afi][safi],
13686 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13687 CHECK_FLAG(
13688 p->af_cap[afi][safi],
13689 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13690 CHECK_FLAG(
13691 p->af_cap[afi][safi],
13692 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13693 CHECK_FLAG(
13694 p->af_cap[afi][safi],
13695 PEER_CAP_ADDPATH_AF_RX_RCV))
13696 json_object_object_add(
13697 json_add, print_store,
13698 json_sub);
13699 else
13700 json_object_free(json_sub);
d62a17ae 13701 }
13702
10711563
DA
13703 json_object_object_add(json_cap, "addPath",
13704 json_add);
13705 }
d62a17ae 13706
10711563
DA
13707 /* Dynamic */
13708 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13709 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13710 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13711 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13712 json_object_string_add(
13713 json_cap, "dynamic",
13714 "advertisedAndReceived");
13715 else if (CHECK_FLAG(p->cap,
13716 PEER_CAP_DYNAMIC_ADV))
13717 json_object_string_add(json_cap,
13718 "dynamic",
13719 "advertised");
13720 else if (CHECK_FLAG(p->cap,
13721 PEER_CAP_DYNAMIC_RCV))
13722 json_object_string_add(json_cap,
13723 "dynamic",
13724 "received");
13725 }
d62a17ae 13726
d864dd9e
EB
13727 /* Role */
13728 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13729 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13730 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13731 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13732 json_object_string_add(
13733 json_cap, "role",
13734 "advertisedAndReceived");
13735 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13736 json_object_string_add(json_cap, "role",
13737 "advertised");
13738 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13739 json_object_string_add(json_cap, "role",
13740 "received");
13741 }
13742
10711563
DA
13743 /* Extended nexthop */
13744 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13745 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13746 json_object *json_nxt = NULL;
13747 const char *print_store;
d62a17ae 13748
d62a17ae 13749
10711563
DA
13750 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13751 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13752 json_object_string_add(
13753 json_cap, "extendedNexthop",
13754 "advertisedAndReceived");
13755 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13756 json_object_string_add(
13757 json_cap, "extendedNexthop",
13758 "advertised");
13759 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13760 json_object_string_add(
13761 json_cap, "extendedNexthop",
13762 "received");
d62a17ae 13763
10711563
DA
13764 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13765 json_nxt = json_object_new_object();
d62a17ae 13766
10711563
DA
13767 for (safi = SAFI_UNICAST;
13768 safi < SAFI_MAX; safi++) {
13769 if (CHECK_FLAG(
13770 p->af_cap[AFI_IP]
13771 [safi],
13772 PEER_CAP_ENHE_AF_RCV)) {
13773 print_store =
13774 get_afi_safi_str(
d62a17ae 13775 AFI_IP,
10711563
DA
13776 safi,
13777 true);
13778 json_object_string_add(
13779 json_nxt,
13780 print_store,
13781 "recieved"); /* misspelled for compatibility */
d62a17ae 13782 }
d62a17ae 13783 }
10711563
DA
13784 json_object_object_add(
13785 json_cap,
13786 "extendedNexthopFamililesByPeer",
13787 json_nxt);
d62a17ae 13788 }
10711563 13789 }
d62a17ae 13790
10711563
DA
13791 /* Long-lived Graceful Restart */
13792 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13793 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13794 json_object *json_llgr = NULL;
13795 const char *afi_safi_str;
8606be87 13796
10711563
DA
13797 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13798 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13799 json_object_string_add(
13800 json_cap,
13801 "longLivedGracefulRestart",
13802 "advertisedAndReceived");
13803 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13804 json_object_string_add(
13805 json_cap,
13806 "longLivedGracefulRestart",
13807 "advertised");
13808 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13809 json_object_string_add(
13810 json_cap,
13811 "longLivedGracefulRestart",
13812 "received");
8606be87 13813
10711563
DA
13814 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13815 json_llgr = json_object_new_object();
8606be87 13816
10711563
DA
13817 FOREACH_AFI_SAFI (afi, safi) {
13818 if (CHECK_FLAG(
13819 p->af_cap[afi]
13820 [safi],
13821 PEER_CAP_ENHE_AF_RCV)) {
13822 afi_safi_str =
13823 get_afi_safi_str(
8606be87
DA
13824 afi,
13825 safi,
13826 true);
10711563
DA
13827 json_object_string_add(
13828 json_llgr,
13829 afi_safi_str,
13830 "received");
8606be87 13831 }
8606be87 13832 }
10711563
DA
13833 json_object_object_add(
13834 json_cap,
13835 "longLivedGracefulRestartByPeer",
13836 json_llgr);
8606be87 13837 }
10711563 13838 }
8606be87 13839
10711563
DA
13840 /* Route Refresh */
13841 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13842 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13843 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13844 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13845 (CHECK_FLAG(p->cap,
13846 PEER_CAP_REFRESH_NEW_RCV) ||
13847 CHECK_FLAG(p->cap,
13848 PEER_CAP_REFRESH_OLD_RCV))) {
13849 if (CHECK_FLAG(
13850 p->cap,
13851 PEER_CAP_REFRESH_OLD_RCV) &&
13852 CHECK_FLAG(
13853 p->cap,
13854 PEER_CAP_REFRESH_NEW_RCV))
13855 json_object_string_add(
13856 json_cap,
13857 "routeRefresh",
13858 "advertisedAndReceivedOldNew");
13859 else {
d62a17ae 13860 if (CHECK_FLAG(
13861 p->cap,
10711563 13862 PEER_CAP_REFRESH_OLD_RCV))
d62a17ae 13863 json_object_string_add(
13864 json_cap,
13865 "routeRefresh",
10711563
DA
13866 "advertisedAndReceivedOld");
13867 else
13868 json_object_string_add(
13869 json_cap,
13870 "routeRefresh",
13871 "advertisedAndReceivedNew");
d62a17ae 13872 }
10711563
DA
13873 } else if (CHECK_FLAG(p->cap,
13874 PEER_CAP_REFRESH_ADV))
13875 json_object_string_add(json_cap,
13876 "routeRefresh",
13877 "advertised");
13878 else if (CHECK_FLAG(p->cap,
13879 PEER_CAP_REFRESH_NEW_RCV) ||
13880 CHECK_FLAG(p->cap,
13881 PEER_CAP_REFRESH_OLD_RCV))
13882 json_object_string_add(json_cap,
13883 "routeRefresh",
13884 "received");
13885 }
d62a17ae 13886
10711563
DA
13887 /* Enhanced Route Refresh */
13888 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13889 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13890 if (CHECK_FLAG(p->cap,
13891 PEER_CAP_ENHANCED_RR_ADV) &&
13892 CHECK_FLAG(p->cap,
13893 PEER_CAP_ENHANCED_RR_RCV))
d77114b7 13894 json_object_string_add(
10711563
DA
13895 json_cap,
13896 "enhancedRouteRefresh",
13897 "advertisedAndReceived");
13898 else if (CHECK_FLAG(p->cap,
13899 PEER_CAP_ENHANCED_RR_ADV))
d77114b7 13900 json_object_string_add(
10711563
DA
13901 json_cap,
13902 "enhancedRouteRefresh",
13903 "advertised");
13904 else if (CHECK_FLAG(p->cap,
9af52ccf 13905 PEER_CAP_ENHANCED_RR_RCV))
10711563
DA
13906 json_object_string_add(
13907 json_cap,
13908 "enhancedRouteRefresh",
13909 "received");
13910 }
d77114b7 13911
10711563
DA
13912 /* Multiprotocol Extensions */
13913 json_object *json_multi = NULL;
d77114b7 13914
10711563 13915 json_multi = json_object_new_object();
d77114b7 13916
10711563
DA
13917 FOREACH_AFI_SAFI (afi, safi) {
13918 if (p->afc_adv[afi][safi] ||
13919 p->afc_recv[afi][safi]) {
13920 json_object *json_exten = NULL;
13921 json_exten = json_object_new_object();
13922
13923 if (p->afc_adv[afi][safi] &&
13924 p->afc_recv[afi][safi])
13925 json_object_boolean_true_add(
13926 json_exten,
9af52ccf 13927 "advertisedAndReceived");
10711563
DA
13928 else if (p->afc_adv[afi][safi])
13929 json_object_boolean_true_add(
13930 json_exten,
9af52ccf 13931 "advertised");
10711563
DA
13932 else if (p->afc_recv[afi][safi])
13933 json_object_boolean_true_add(
13934 json_exten, "received");
9af52ccf 13935
10711563
DA
13936 json_object_object_add(
13937 json_multi,
13938 get_afi_safi_str(afi, safi,
13939 true),
13940 json_exten);
13941 }
13942 }
13943 json_object_object_add(json_cap,
13944 "multiprotocolExtensions",
13945 json_multi);
d62a17ae 13946
10711563
DA
13947 /* Hostname capabilities */
13948 json_object *json_hname = NULL;
d62a17ae 13949
10711563 13950 json_hname = json_object_new_object();
d62a17ae 13951
10711563
DA
13952 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13953 json_object_string_add(
13954 json_hname, "advHostName",
13955 bgp->peer_self->hostname
13956 ? bgp->peer_self->hostname
13957 : "n/a");
13958 json_object_string_add(
13959 json_hname, "advDomainName",
13960 bgp->peer_self->domainname
13961 ? bgp->peer_self->domainname
13962 : "n/a");
13963 }
d77114b7 13964
d77114b7 13965
10711563
DA
13966 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13967 json_object_string_add(
13968 json_hname, "rcvHostName",
13969 p->hostname ? p->hostname : "n/a");
13970 json_object_string_add(
13971 json_hname, "rcvDomainName",
13972 p->domainname ? p->domainname : "n/a");
13973 }
d77114b7 13974
10711563
DA
13975 json_object_object_add(json_cap, "hostName",
13976 json_hname);
d77114b7 13977
234f6fd4
DA
13978 /* Software Version capability */
13979 json_object *json_soft_version = NULL;
13980
13981 json_soft_version = json_object_new_object();
13982
13983 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_ADV))
13984 json_object_string_add(
13985 json_soft_version,
13986 "advertisedSoftwareVersion",
13987 cmd_software_version_get());
13988
13989 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_RCV))
13990 json_object_string_add(
13991 json_soft_version,
13992 "receivedSoftwareVersion",
13993 p->soft_version ? p->soft_version
13994 : "n/a");
13995
13996 json_object_object_add(json_cap, "softwareVersion",
13997 json_soft_version);
13998
17be83bf 13999 /* Graceful Restart */
10711563
DA
14000 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14001 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14002 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
14003 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
d77114b7 14004 json_object_string_add(
10711563
DA
14005 json_cap, "gracefulRestart",
14006 "advertisedAndReceived");
14007 else if (CHECK_FLAG(p->cap,
14008 PEER_CAP_RESTART_ADV))
d77114b7 14009 json_object_string_add(
10711563
DA
14010 json_cap,
14011 "gracefulRestartCapability",
14012 "advertised");
14013 else if (CHECK_FLAG(p->cap,
14014 PEER_CAP_RESTART_RCV))
14015 json_object_string_add(
14016 json_cap,
14017 "gracefulRestartCapability",
14018 "received");
d77114b7 14019
10711563
DA
14020 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14021 int restart_af_count = 0;
14022 json_object *json_restart = NULL;
14023 json_restart = json_object_new_object();
d62a17ae 14024
10711563
DA
14025 json_object_int_add(
14026 json_cap,
14027 "gracefulRestartRemoteTimerMsecs",
14028 p->v_gr_restart * 1000);
d62a17ae 14029
10711563 14030 FOREACH_AFI_SAFI (afi, safi) {
05c7a1cc
QY
14031 if (CHECK_FLAG(
14032 p->af_cap[afi]
14033 [safi],
10711563
DA
14034 PEER_CAP_RESTART_AF_RCV)) {
14035 json_object *json_sub =
14036 NULL;
14037 json_sub =
14038 json_object_new_object();
d62a17ae 14039
05c7a1cc
QY
14040 if (CHECK_FLAG(
14041 p->af_cap
14042 [afi]
14043 [safi],
10711563
DA
14044 PEER_CAP_RESTART_AF_PRESERVE_RCV))
14045 json_object_boolean_true_add(
14046 json_sub,
14047 "preserved");
14048 restart_af_count++;
d62a17ae 14049 json_object_object_add(
10711563
DA
14050 json_restart,
14051 get_afi_safi_str(
14052 afi,
14053 safi,
14054 true),
14055 json_sub);
d62a17ae 14056 }
d62a17ae 14057 }
10711563
DA
14058 if (!restart_af_count) {
14059 json_object_string_add(
14060 json_cap,
14061 "addressFamiliesByPeer",
14062 "none");
14063 json_object_free(json_restart);
14064 } else
14065 json_object_object_add(
14066 json_cap,
14067 "addressFamiliesByPeer",
14068 json_restart);
d62a17ae 14069 }
10711563
DA
14070 }
14071 json_object_object_add(
14072 json_neigh, "neighborCapabilities", json_cap);
14073 } else {
14074 vty_out(vty, " Neighbor capabilities:\n");
14075
14076 /* AS4 */
14077 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
14078 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
14079 vty_out(vty, " 4 Byte AS:");
14080 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
14081 vty_out(vty, " advertised");
14082 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
14083 vty_out(vty, " %sreceived",
14084 CHECK_FLAG(p->cap,
14085 PEER_CAP_AS4_ADV)
14086 ? "and "
14087 : "");
14088 vty_out(vty, "\n");
14089 }
d62a17ae 14090
10711563
DA
14091 /* Extended Message Support */
14092 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
14093 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
14094 vty_out(vty, " Extended Message:");
ef56aee4 14095 if (CHECK_FLAG(p->cap,
10711563
DA
14096 PEER_CAP_EXTENDED_MESSAGE_ADV))
14097 vty_out(vty, " advertised");
14098 if (CHECK_FLAG(p->cap,
14099 PEER_CAP_EXTENDED_MESSAGE_RCV))
14100 vty_out(vty, " %sreceived",
14101 CHECK_FLAG(
14102 p->cap,
14103 PEER_CAP_EXTENDED_MESSAGE_ADV)
14104 ? "and "
14105 : "");
14106 vty_out(vty, "\n");
14107 }
d62a17ae 14108
10711563
DA
14109 /* AddPath */
14110 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
14111 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
14112 vty_out(vty, " AddPath:\n");
d62a17ae 14113
10711563 14114 FOREACH_AFI_SAFI (afi, safi) {
ef56aee4 14115 if (CHECK_FLAG(
10711563
DA
14116 p->af_cap[afi][safi],
14117 PEER_CAP_ADDPATH_AF_TX_ADV) ||
14118 CHECK_FLAG(
14119 p->af_cap[afi][safi],
14120 PEER_CAP_ADDPATH_AF_TX_RCV)) {
14121 vty_out(vty, " %s: TX ",
14122 get_afi_safi_str(
14123 afi, safi,
14124 false));
ef56aee4 14125
10711563
DA
14126 if (CHECK_FLAG(
14127 p->af_cap[afi]
14128 [safi],
14129 PEER_CAP_ADDPATH_AF_TX_ADV))
14130 vty_out(vty,
14131 "advertised");
d62a17ae 14132
05c7a1cc
QY
14133 if (CHECK_FLAG(
14134 p->af_cap[afi]
14135 [safi],
10711563 14136 PEER_CAP_ADDPATH_AF_TX_RCV))
05c7a1cc 14137 vty_out(vty,
10711563
DA
14138 "%sreceived",
14139 CHECK_FLAG(
14140 p->af_cap
14141 [afi]
14142 [safi],
14143 PEER_CAP_ADDPATH_AF_TX_ADV)
14144 ? " and "
14145 : "");
05c7a1cc 14146
10711563
DA
14147 vty_out(vty, "\n");
14148 }
d62a17ae 14149
9af52ccf 14150 if (CHECK_FLAG(
10711563
DA
14151 p->af_cap[afi][safi],
14152 PEER_CAP_ADDPATH_AF_RX_ADV) ||
14153 CHECK_FLAG(
14154 p->af_cap[afi][safi],
14155 PEER_CAP_ADDPATH_AF_RX_RCV)) {
14156 vty_out(vty, " %s: RX ",
5cb5f4d0 14157 get_afi_safi_str(
10711563
DA
14158 afi, safi,
14159 false));
d62a17ae 14160
05c7a1cc
QY
14161 if (CHECK_FLAG(
14162 p->af_cap[afi]
14163 [safi],
10711563 14164 PEER_CAP_ADDPATH_AF_RX_ADV))
05c7a1cc 14165 vty_out(vty,
10711563 14166 "advertised");
d62a17ae 14167
10711563
DA
14168 if (CHECK_FLAG(
14169 p->af_cap[afi]
14170 [safi],
14171 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc 14172 vty_out(vty,
10711563
DA
14173 "%sreceived",
14174 CHECK_FLAG(
14175 p->af_cap
14176 [afi]
14177 [safi],
14178 PEER_CAP_ADDPATH_AF_RX_ADV)
14179 ? " and "
05c7a1cc 14180 : "");
d62a17ae 14181
05c7a1cc 14182 vty_out(vty, "\n");
05c7a1cc 14183 }
d62a17ae 14184 }
10711563 14185 }
d62a17ae 14186
10711563
DA
14187 /* Dynamic */
14188 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
14189 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
14190 vty_out(vty, " Dynamic:");
14191 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
14192 vty_out(vty, " advertised");
14193 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
14194 vty_out(vty, " %sreceived",
14195 CHECK_FLAG(p->cap,
14196 PEER_CAP_DYNAMIC_ADV)
14197 ? "and "
14198 : "");
14199 vty_out(vty, "\n");
14200 }
d62a17ae 14201
d864dd9e
EB
14202 /* Role */
14203 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
14204 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
14205 vty_out(vty, " Role:");
14206 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
14207 vty_out(vty, " advertised");
14208 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
14209 vty_out(vty, " %sreceived",
14210 CHECK_FLAG(p->cap,
14211 PEER_CAP_ROLE_ADV)
14212 ? "and "
14213 : "");
14214 vty_out(vty, "\n");
14215 }
14216
10711563
DA
14217 /* Extended nexthop */
14218 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
14219 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
14220 vty_out(vty, " Extended nexthop:");
14221 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
14222 vty_out(vty, " advertised");
14223 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
14224 vty_out(vty, " %sreceived",
14225 CHECK_FLAG(p->cap,
14226 PEER_CAP_ENHE_ADV)
14227 ? "and "
14228 : "");
14229 vty_out(vty, "\n");
d62a17ae 14230
10711563 14231 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
57f7feb6 14232 vty_out(vty,
10711563
DA
14233 " Address families by peer:\n ");
14234 for (safi = SAFI_UNICAST;
14235 safi < SAFI_MAX; safi++)
14236 if (CHECK_FLAG(
14237 p->af_cap[AFI_IP]
14238 [safi],
14239 PEER_CAP_ENHE_AF_RCV))
14240 vty_out(vty,
14241 " %s\n",
14242 get_afi_safi_str(
14243 AFI_IP,
14244 safi,
14245 false));
d62a17ae 14246 }
10711563 14247 }
d62a17ae 14248
10711563
DA
14249 /* Long-lived Graceful Restart */
14250 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
14251 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
14252 vty_out(vty,
14253 " Long-lived Graceful Restart:");
14254 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
14255 vty_out(vty, " advertised");
14256 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
14257 vty_out(vty, " %sreceived",
14258 CHECK_FLAG(p->cap,
14259 PEER_CAP_LLGR_ADV)
14260 ? "and "
14261 : "");
14262 vty_out(vty, "\n");
8606be87 14263
10711563 14264 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
57f7feb6 14265 vty_out(vty,
10711563
DA
14266 " Address families by peer:\n");
14267 FOREACH_AFI_SAFI (afi, safi)
14268 if (CHECK_FLAG(
14269 p->af_cap[afi]
14270 [safi],
14271 PEER_CAP_LLGR_AF_RCV))
14272 vty_out(vty,
14273 " %s\n",
14274 get_afi_safi_str(
14275 afi,
14276 safi,
14277 false));
8606be87 14278 }
10711563 14279 }
8606be87 14280
10711563
DA
14281 /* Route Refresh */
14282 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
14283 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
14284 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
14285 vty_out(vty, " Route refresh:");
14286 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
14287 vty_out(vty, " advertised");
14288 if (CHECK_FLAG(p->cap,
14289 PEER_CAP_REFRESH_NEW_RCV) ||
14290 CHECK_FLAG(p->cap,
14291 PEER_CAP_REFRESH_OLD_RCV))
14292 vty_out(vty, " %sreceived(%s)",
14293 CHECK_FLAG(p->cap,
14294 PEER_CAP_REFRESH_ADV)
14295 ? "and "
14296 : "",
14297 (CHECK_FLAG(
14298 p->cap,
14299 PEER_CAP_REFRESH_OLD_RCV) &&
14300 CHECK_FLAG(
14301 p->cap,
14302 PEER_CAP_REFRESH_NEW_RCV))
14303 ? "old & new"
14304 : CHECK_FLAG(
14305 p->cap,
14306 PEER_CAP_REFRESH_OLD_RCV)
14307 ? "old"
14308 : "new");
d62a17ae 14309
d77114b7 14310 vty_out(vty, "\n");
10711563 14311 }
d62a17ae 14312
10711563
DA
14313 /* Enhanced Route Refresh */
14314 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
14315 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
14316 vty_out(vty, " Enhanced Route Refresh:");
14317 if (CHECK_FLAG(p->cap,
14318 PEER_CAP_ENHANCED_RR_ADV))
14319 vty_out(vty, " advertised");
14320 if (CHECK_FLAG(p->cap,
14321 PEER_CAP_ENHANCED_RR_RCV))
14322 vty_out(vty, " %sreceived",
14323 CHECK_FLAG(p->cap,
14324 PEER_CAP_REFRESH_ADV)
14325 ? "and "
14326 : "");
14327 vty_out(vty, "\n");
14328 }
14329
14330 /* Multiprotocol Extensions */
14331 FOREACH_AFI_SAFI (afi, safi)
14332 if (p->afc_adv[afi][safi] ||
14333 p->afc_recv[afi][safi]) {
14334 vty_out(vty, " Address Family %s:",
14335 get_afi_safi_str(afi, safi,
14336 false));
14337 if (p->afc_adv[afi][safi])
9af52ccf 14338 vty_out(vty, " advertised");
10711563 14339 if (p->afc_recv[afi][safi])
9af52ccf 14340 vty_out(vty, " %sreceived",
10711563 14341 p->afc_adv[afi][safi]
9af52ccf
DA
14342 ? "and "
14343 : "");
14344 vty_out(vty, "\n");
14345 }
14346
10711563
DA
14347 /* Hostname capability */
14348 vty_out(vty, " Hostname Capability:");
d62a17ae 14349
10711563
DA
14350 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14351 vty_out(vty,
14352 " advertised (name: %s,domain name: %s)",
14353 bgp->peer_self->hostname
14354 ? bgp->peer_self->hostname
14355 : "n/a",
14356 bgp->peer_self->domainname
14357 ? bgp->peer_self->domainname
14358 : "n/a");
14359 } else {
14360 vty_out(vty, " not advertised");
14361 }
d77114b7 14362
10711563
DA
14363 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14364 vty_out(vty,
14365 " received (name: %s,domain name: %s)",
14366 p->hostname ? p->hostname : "n/a",
14367 p->domainname ? p->domainname : "n/a");
14368 } else {
14369 vty_out(vty, " not received");
d62a17ae 14370 }
d62a17ae 14371
10711563 14372 vty_out(vty, "\n");
d77114b7 14373
234f6fd4
DA
14374 /* Software Version capability */
14375 vty_out(vty, " Version Capability:");
14376
14377 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_ADV)) {
14378 vty_out(vty,
14379 " advertised software version (%s)",
14380 cmd_software_version_get());
14381 } else
14382 vty_out(vty, " not advertised");
14383
14384 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_RCV)) {
14385 vty_out(vty, " received software version (%s)",
14386 p->soft_version ? p->soft_version
14387 : "n/a");
14388 } else
14389 vty_out(vty, " not received");
14390
14391 vty_out(vty, "\n");
14392
10711563
DA
14393 /* Graceful Restart */
14394 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14395 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14396 vty_out(vty,
14397 " Graceful Restart Capability:");
14398 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
14399 vty_out(vty, " advertised");
14400 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14401 vty_out(vty, " %sreceived",
14402 CHECK_FLAG(p->cap,
14403 PEER_CAP_RESTART_ADV)
14404 ? "and "
14405 : "");
d77114b7
MK
14406 vty_out(vty, "\n");
14407
10711563
DA
14408 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14409 int restart_af_count = 0;
d62a17ae 14410
10711563
DA
14411 vty_out(vty,
14412 " Remote Restart timer is %d seconds\n",
14413 p->v_gr_restart);
14414 vty_out(vty,
14415 " Address families by peer:\n ");
d62a17ae 14416
10711563
DA
14417 FOREACH_AFI_SAFI (afi, safi)
14418 if (CHECK_FLAG(
14419 p->af_cap[afi]
14420 [safi],
14421 PEER_CAP_RESTART_AF_RCV)) {
14422 vty_out(vty, "%s%s(%s)",
14423 restart_af_count
14424 ? ", "
14425 : "",
14426 get_afi_safi_str(
14427 afi,
14428 safi,
14429 false),
14430 CHECK_FLAG(
14431 p->af_cap
14432 [afi]
14433 [safi],
14434 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14435 ? "preserved"
14436 : "not preserved");
14437 restart_af_count++;
14438 }
14439 if (!restart_af_count)
14440 vty_out(vty, "none");
14441 vty_out(vty, "\n");
14442 }
17be83bf 14443 } /* Graceful Restart */
d62a17ae 14444 }
14445 }
14446
14447 /* graceful restart information */
10711563
DA
14448 json_object *json_grace = NULL;
14449 json_object *json_grace_send = NULL;
14450 json_object *json_grace_recv = NULL;
14451 int eor_send_af_count = 0;
14452 int eor_receive_af_count = 0;
d62a17ae 14453
10711563
DA
14454 if (use_json) {
14455 json_grace = json_object_new_object();
14456 json_grace_send = json_object_new_object();
14457 json_grace_recv = json_object_new_object();
14458
14459 if ((peer_established(p)) &&
14460 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14461 FOREACH_AFI_SAFI (afi, safi) {
14462 if (CHECK_FLAG(p->af_sflags[afi][safi],
14463 PEER_STATUS_EOR_SEND)) {
14464 json_object_boolean_true_add(
14465 json_grace_send,
14466 get_afi_safi_str(afi, safi,
14467 true));
14468 eor_send_af_count++;
d62a17ae 14469 }
10711563
DA
14470 }
14471 FOREACH_AFI_SAFI (afi, safi) {
14472 if (CHECK_FLAG(p->af_sflags[afi][safi],
14473 PEER_STATUS_EOR_RECEIVED)) {
14474 json_object_boolean_true_add(
14475 json_grace_recv,
14476 get_afi_safi_str(afi, safi,
14477 true));
14478 eor_receive_af_count++;
d62a17ae 14479 }
14480 }
10711563
DA
14481 }
14482 json_object_object_add(json_grace, "endOfRibSend",
14483 json_grace_send);
14484 json_object_object_add(json_grace, "endOfRibRecv",
14485 json_grace_recv);
d62a17ae 14486
d62a17ae 14487
10711563
DA
14488 if (p->t_gr_restart)
14489 json_object_int_add(
14490 json_grace, "gracefulRestartTimerMsecs",
14491 thread_timer_remain_second(p->t_gr_restart) *
14492 1000);
2986cac2 14493
10711563
DA
14494 if (p->t_gr_stale)
14495 json_object_int_add(
14496 json_grace, "gracefulStalepathTimerMsecs",
14497 thread_timer_remain_second(p->t_gr_stale) *
14498 1000);
14499 /* more gr info in new format */
403e64f8 14500 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json_grace);
10711563
DA
14501 json_object_object_add(json_neigh, "gracefulRestartInfo",
14502 json_grace);
14503 } else {
14504 vty_out(vty, " Graceful restart information:\n");
14505 if ((peer_established(p)) &&
14506 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14507
14508 vty_out(vty, " End-of-RIB send: ");
14509 FOREACH_AFI_SAFI (afi, safi) {
14510 if (CHECK_FLAG(p->af_sflags[afi][safi],
14511 PEER_STATUS_EOR_SEND)) {
14512 vty_out(vty, "%s%s",
14513 eor_send_af_count ? ", " : "",
14514 get_afi_safi_str(afi, safi,
14515 false));
14516 eor_send_af_count++;
d62a17ae 14517 }
10711563
DA
14518 }
14519 vty_out(vty, "\n");
14520 vty_out(vty, " End-of-RIB received: ");
14521 FOREACH_AFI_SAFI (afi, safi) {
14522 if (CHECK_FLAG(p->af_sflags[afi][safi],
14523 PEER_STATUS_EOR_RECEIVED)) {
14524 vty_out(vty, "%s%s",
14525 eor_receive_af_count ? ", "
14526 : "",
14527 get_afi_safi_str(afi, safi,
14528 false));
14529 eor_receive_af_count++;
d62a17ae 14530 }
d62a17ae 14531 }
10711563
DA
14532 vty_out(vty, "\n");
14533 }
d62a17ae 14534
10711563
DA
14535 if (p->t_gr_restart)
14536 vty_out(vty,
14537 " The remaining time of restart timer is %ld\n",
14538 thread_timer_remain_second(p->t_gr_restart));
d62a17ae 14539
10711563
DA
14540 if (p->t_gr_stale)
14541 vty_out(vty,
14542 " The remaining time of stalepath timer is %ld\n",
14543 thread_timer_remain_second(p->t_gr_stale));
2986cac2 14544
10711563 14545 /* more gr info in new format */
403e64f8 14546 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, NULL);
10711563 14547 }
2986cac2 14548
d62a17ae 14549 if (use_json) {
14550 json_object *json_stat = NULL;
14551 json_stat = json_object_new_object();
14552 /* Packet counts. */
43aa5965
QY
14553
14554 atomic_size_t outq_count, inq_count;
14555 outq_count = atomic_load_explicit(&p->obuf->count,
14556 memory_order_relaxed);
14557 inq_count = atomic_load_explicit(&p->ibuf->count,
14558 memory_order_relaxed);
14559
14560 json_object_int_add(json_stat, "depthInq",
14561 (unsigned long)inq_count);
d62a17ae 14562 json_object_int_add(json_stat, "depthOutq",
43aa5965 14563 (unsigned long)outq_count);
0112e9e0
QY
14564 json_object_int_add(json_stat, "opensSent",
14565 atomic_load_explicit(&p->open_out,
14566 memory_order_relaxed));
14567 json_object_int_add(json_stat, "opensRecv",
14568 atomic_load_explicit(&p->open_in,
14569 memory_order_relaxed));
d62a17ae 14570 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
14571 atomic_load_explicit(&p->notify_out,
14572 memory_order_relaxed));
d62a17ae 14573 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
14574 atomic_load_explicit(&p->notify_in,
14575 memory_order_relaxed));
14576 json_object_int_add(json_stat, "updatesSent",
14577 atomic_load_explicit(&p->update_out,
14578 memory_order_relaxed));
14579 json_object_int_add(json_stat, "updatesRecv",
14580 atomic_load_explicit(&p->update_in,
14581 memory_order_relaxed));
d62a17ae 14582 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
14583 atomic_load_explicit(&p->keepalive_out,
14584 memory_order_relaxed));
d62a17ae 14585 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
14586 atomic_load_explicit(&p->keepalive_in,
14587 memory_order_relaxed));
d62a17ae 14588 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
14589 atomic_load_explicit(&p->refresh_out,
14590 memory_order_relaxed));
d62a17ae 14591 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
14592 atomic_load_explicit(&p->refresh_in,
14593 memory_order_relaxed));
d62a17ae 14594 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
14595 atomic_load_explicit(&p->dynamic_cap_out,
14596 memory_order_relaxed));
d62a17ae 14597 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
14598 atomic_load_explicit(&p->dynamic_cap_in,
14599 memory_order_relaxed));
14600 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14601 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 14602 json_object_object_add(json_neigh, "messageStats", json_stat);
14603 } else {
cb93e0a2
IS
14604 atomic_size_t outq_count, inq_count, open_out, open_in,
14605 notify_out, notify_in, update_out, update_in,
14606 keepalive_out, keepalive_in, refresh_out, refresh_in,
14607 dynamic_cap_out, dynamic_cap_in;
43aa5965
QY
14608 outq_count = atomic_load_explicit(&p->obuf->count,
14609 memory_order_relaxed);
14610 inq_count = atomic_load_explicit(&p->ibuf->count,
14611 memory_order_relaxed);
cb93e0a2
IS
14612 open_out = atomic_load_explicit(&p->open_out,
14613 memory_order_relaxed);
14614 open_in =
14615 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14616 notify_out = atomic_load_explicit(&p->notify_out,
14617 memory_order_relaxed);
14618 notify_in = atomic_load_explicit(&p->notify_in,
14619 memory_order_relaxed);
14620 update_out = atomic_load_explicit(&p->update_out,
14621 memory_order_relaxed);
14622 update_in = atomic_load_explicit(&p->update_in,
14623 memory_order_relaxed);
14624 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14625 memory_order_relaxed);
14626 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14627 memory_order_relaxed);
14628 refresh_out = atomic_load_explicit(&p->refresh_out,
14629 memory_order_relaxed);
14630 refresh_in = atomic_load_explicit(&p->refresh_in,
14631 memory_order_relaxed);
14632 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14633 memory_order_relaxed);
14634 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14635 memory_order_relaxed);
43aa5965 14636
d62a17ae 14637 /* Packet counts. */
14638 vty_out(vty, " Message statistics:\n");
43aa5965
QY
14639 vty_out(vty, " Inq depth is %zu\n", inq_count);
14640 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 14641 vty_out(vty, " Sent Rcvd\n");
cb93e0a2
IS
14642 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14643 open_in);
14644 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14645 notify_in);
14646 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14647 update_in);
14648 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14649 keepalive_in);
14650 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14651 refresh_in);
14652 vty_out(vty, " Capability: %10zu %10zu\n",
14653 dynamic_cap_out, dynamic_cap_in);
14654 vty_out(vty, " Total: %10u %10u\n",
14655 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
d62a17ae 14656 }
14657
14658 if (use_json) {
14659 /* advertisement-interval */
14660 json_object_int_add(json_neigh,
14661 "minBtwnAdvertisementRunsTimerMsecs",
14662 p->v_routeadv * 1000);
14663
14664 /* Update-source. */
14665 if (p->update_if || p->update_source) {
14666 if (p->update_if)
14667 json_object_string_add(json_neigh,
14668 "updateSource",
14669 p->update_if);
14670 else if (p->update_source)
47e12884
DA
14671 json_object_string_addf(json_neigh,
14672 "updateSource", "%pSU",
14673 p->update_source);
d62a17ae 14674 }
14675 } else {
14676 /* advertisement-interval */
14677 vty_out(vty,
14678 " Minimum time between advertisement runs is %d seconds\n",
14679 p->v_routeadv);
14680
14681 /* Update-source. */
14682 if (p->update_if || p->update_source) {
14683 vty_out(vty, " Update source is ");
14684 if (p->update_if)
14685 vty_out(vty, "%s", p->update_if);
14686 else if (p->update_source)
47e12884 14687 vty_out(vty, "%pSU", p->update_source);
d62a17ae 14688 vty_out(vty, "\n");
14689 }
14690
14691 vty_out(vty, "\n");
14692 }
14693
14694 /* Address Family Information */
14695 json_object *json_hold = NULL;
14696
14697 if (use_json)
14698 json_hold = json_object_new_object();
14699
05c7a1cc
QY
14700 FOREACH_AFI_SAFI (afi, safi)
14701 if (p->afc[afi][safi])
14702 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14703 json_hold);
d62a17ae 14704
14705 if (use_json) {
14706 json_object_object_add(json_neigh, "addressFamilyInfo",
14707 json_hold);
14708 json_object_int_add(json_neigh, "connectionsEstablished",
14709 p->established);
14710 json_object_int_add(json_neigh, "connectionsDropped",
14711 p->dropped);
14712 } else
14713 vty_out(vty, " Connections established %d; dropped %d\n",
14714 p->established, p->dropped);
14715
14716 if (!p->last_reset) {
14717 if (use_json)
14718 json_object_string_add(json_neigh, "lastReset",
14719 "never");
14720 else
14721 vty_out(vty, " Last reset never\n");
14722 } else {
14723 if (use_json) {
14724 time_t uptime;
a2700b50 14725 struct tm tm;
d62a17ae 14726
083ec940 14727 uptime = monotime(NULL);
d62a17ae 14728 uptime -= p->resettime;
a2700b50
MS
14729 gmtime_r(&uptime, &tm);
14730
d62a17ae 14731 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
14732 (tm.tm_sec * 1000)
14733 + (tm.tm_min * 60000)
14734 + (tm.tm_hour * 3600000));
3577f1c5 14735 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 14736 } else {
14737 vty_out(vty, " Last reset %s, ",
14738 peer_uptime(p->resettime, timebuf,
14739 BGP_UPTIME_LEN, 0, NULL));
14740
3577f1c5 14741 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 14742 if (p->last_reset_cause_size) {
14743 msg = p->last_reset_cause;
14744 vty_out(vty,
14745 " Message received that caused BGP to send a NOTIFICATION:\n ");
14746 for (i = 1; i <= p->last_reset_cause_size;
14747 i++) {
14748 vty_out(vty, "%02X", *msg++);
14749
14750 if (i != p->last_reset_cause_size) {
14751 if (i % 16 == 0) {
14752 vty_out(vty, "\n ");
14753 } else if (i % 4 == 0) {
14754 vty_out(vty, " ");
14755 }
14756 }
14757 }
14758 vty_out(vty, "\n");
14759 }
14760 }
14761 }
14762
14763 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14764 if (use_json)
14765 json_object_boolean_true_add(json_neigh,
14766 "prefixesConfigExceedMax");
14767 else
14768 vty_out(vty,
14769 " Peer had exceeded the max. no. of prefixes configured.\n");
14770
14771 if (p->t_pmax_restart) {
14772 if (use_json) {
14773 json_object_boolean_true_add(
14774 json_neigh, "reducePrefixNumFrom");
14775 json_object_int_add(json_neigh,
14776 "restartInTimerMsec",
14777 thread_timer_remain_second(
14778 p->t_pmax_restart)
14779 * 1000);
14780 } else
14781 vty_out(vty,
14782 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
14783 p->host, thread_timer_remain_second(
14784 p->t_pmax_restart));
d62a17ae 14785 } else {
14786 if (use_json)
14787 json_object_boolean_true_add(
14788 json_neigh,
14789 "reducePrefixNumAndClearIpBgp");
14790 else
14791 vty_out(vty,
14792 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14793 p->host);
14794 }
14795 }
14796
14797 /* EBGP Multihop and GTSM */
14798 if (p->sort != BGP_PEER_IBGP) {
14799 if (use_json) {
e2521429 14800 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14801 json_object_int_add(json_neigh,
14802 "externalBgpNbrMaxHopsAway",
14803 p->gtsm_hops);
be8d1733 14804 else
d62a17ae 14805 json_object_int_add(json_neigh,
14806 "externalBgpNbrMaxHopsAway",
14807 p->ttl);
14808 } else {
e2521429 14809 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14810 vty_out(vty,
14811 " External BGP neighbor may be up to %d hops away.\n",
14812 p->gtsm_hops);
be8d1733 14813 else
d62a17ae 14814 vty_out(vty,
14815 " External BGP neighbor may be up to %d hops away.\n",
14816 p->ttl);
14817 }
14818 } else {
be8d1733
DA
14819 if (use_json) {
14820 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14821 json_object_int_add(json_neigh,
14822 "internalBgpNbrMaxHopsAway",
14823 p->gtsm_hops);
14824 else
be8d1733
DA
14825 json_object_int_add(json_neigh,
14826 "internalBgpNbrMaxHopsAway",
14827 p->ttl);
14828 } else {
14829 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14830 vty_out(vty,
14831 " Internal BGP neighbor may be up to %d hops away.\n",
14832 p->gtsm_hops);
be8d1733
DA
14833 else
14834 vty_out(vty,
14835 " Internal BGP neighbor may be up to %d hops away.\n",
14836 p->ttl);
d62a17ae 14837 }
14838 }
14839
14840 /* Local address. */
14841 if (p->su_local) {
14842 if (use_json) {
47e12884
DA
14843 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14844 p->su_local);
d62a17ae 14845 json_object_int_add(json_neigh, "portLocal",
14846 ntohs(p->su_local->sin.sin_port));
14847 } else
47e12884
DA
14848 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14849 p->su_local, ntohs(p->su_local->sin.sin_port));
1e592331
DS
14850 } else {
14851 if (use_json) {
14852 json_object_string_add(json_neigh, "hostLocal",
14853 "Unknown");
14854 json_object_int_add(json_neigh, "portLocal", -1);
14855 }
d62a17ae 14856 }
14857
14858 /* Remote address. */
14859 if (p->su_remote) {
14860 if (use_json) {
47e12884
DA
14861 json_object_string_addf(json_neigh, "hostForeign",
14862 "%pSU", p->su_remote);
d62a17ae 14863 json_object_int_add(json_neigh, "portForeign",
14864 ntohs(p->su_remote->sin.sin_port));
14865 } else
47e12884
DA
14866 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14867 p->su_remote,
d62a17ae 14868 ntohs(p->su_remote->sin.sin_port));
1e592331
DS
14869 } else {
14870 if (use_json) {
14871 json_object_string_add(json_neigh, "hostForeign",
14872 "Unknown");
14873 json_object_int_add(json_neigh, "portForeign", -1);
14874 }
d62a17ae 14875 }
14876
14877 /* Nexthop display. */
14878 if (p->su_local) {
14879 if (use_json) {
c949c771
DA
14880 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14881 &p->nexthop.v4);
14882 json_object_string_addf(json_neigh, "nexthopGlobal",
14883 "%pI6", &p->nexthop.v6_global);
14884 json_object_string_addf(json_neigh, "nexthopLocal",
14885 "%pI6", &p->nexthop.v6_local);
d62a17ae 14886 if (p->shared_network)
14887 json_object_string_add(json_neigh,
14888 "bgpConnection",
14889 "sharedNetwork");
14890 else
14891 json_object_string_add(json_neigh,
14892 "bgpConnection",
14893 "nonSharedNetwork");
14894 } else {
07380148
DA
14895 vty_out(vty, "Nexthop: %pI4\n", &p->nexthop.v4);
14896 vty_out(vty, "Nexthop global: %pI6\n",
14897 &p->nexthop.v6_global);
14898 vty_out(vty, "Nexthop local: %pI6\n",
14899 &p->nexthop.v6_local);
d62a17ae 14900 vty_out(vty, "BGP connection: %s\n",
14901 p->shared_network ? "shared network"
14902 : "non shared network");
14903 }
432e7e46
KQ
14904 } else {
14905 if (use_json) {
14906 json_object_string_add(json_neigh, "nexthop",
14907 "Unknown");
14908 json_object_string_add(json_neigh, "nexthopGlobal",
14909 "Unknown");
14910 json_object_string_add(json_neigh, "nexthopLocal",
14911 "Unknown");
14912 json_object_string_add(json_neigh, "bgpConnection",
14913 "Unknown");
14914 }
d62a17ae 14915 }
14916
14917 /* Timer information. */
14918 if (use_json) {
14919 json_object_int_add(json_neigh, "connectRetryTimer",
14920 p->v_connect);
f41255a0 14921 if (peer_established(p)) {
d62a17ae 14922 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14923 p->rtt);
f41255a0
DA
14924 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) {
14925 json_object_int_add(json_neigh,
14926 "shutdownRttInMsecs",
14927 p->rtt_expected);
14928 json_object_int_add(json_neigh,
14929 "shutdownRttAfterCount",
14930 p->rtt_keepalive_rcv);
14931 }
14932 }
d62a17ae 14933 if (p->t_start)
14934 json_object_int_add(
14935 json_neigh, "nextStartTimerDueInMsecs",
14936 thread_timer_remain_second(p->t_start) * 1000);
14937 if (p->t_connect)
14938 json_object_int_add(
14939 json_neigh, "nextConnectTimerDueInMsecs",
14940 thread_timer_remain_second(p->t_connect)
14941 * 1000);
14942 if (p->t_routeadv) {
14943 json_object_int_add(json_neigh, "mraiInterval",
14944 p->v_routeadv);
14945 json_object_int_add(
14946 json_neigh, "mraiTimerExpireInMsecs",
14947 thread_timer_remain_second(p->t_routeadv)
14948 * 1000);
14949 }
14950 if (p->password)
14951 json_object_int_add(json_neigh, "authenticationEnabled",
14952 1);
14953
14954 if (p->t_read)
14955 json_object_string_add(json_neigh, "readThread", "on");
14956 else
14957 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
14958
14959 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 14960 json_object_string_add(json_neigh, "writeThread", "on");
14961 else
14962 json_object_string_add(json_neigh, "writeThread",
14963 "off");
14964 } else {
14965 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14966 p->v_connect);
f41255a0 14967 if (peer_established(p)) {
d62a17ae 14968 vty_out(vty, "Estimated round trip time: %d ms\n",
14969 p->rtt);
f41255a0
DA
14970 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN))
14971 vty_out(vty,
14972 "Shutdown when RTT > %dms, count > %u\n",
14973 p->rtt_expected, p->rtt_keepalive_rcv);
14974 }
d62a17ae 14975 if (p->t_start)
14976 vty_out(vty, "Next start timer due in %ld seconds\n",
14977 thread_timer_remain_second(p->t_start));
14978 if (p->t_connect)
14979 vty_out(vty, "Next connect timer due in %ld seconds\n",
14980 thread_timer_remain_second(p->t_connect));
14981 if (p->t_routeadv)
14982 vty_out(vty,
14983 "MRAI (interval %u) timer expires in %ld seconds\n",
14984 p->v_routeadv,
14985 thread_timer_remain_second(p->t_routeadv));
14986 if (p->password)
14987 vty_out(vty, "Peer Authentication Enabled\n");
14988
cac9e917 14989 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
14990 p->t_read ? "on" : "off",
14991 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14992 ? "on"
cac9e917 14993 : "off", p->fd);
d62a17ae 14994 }
14995
14996 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14997 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14998 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14999
15000 if (!use_json)
15001 vty_out(vty, "\n");
15002
15003 /* BFD information. */
21bfce98
RZ
15004 if (p->bfd_config)
15005 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 15006
15007 if (use_json) {
15008 if (p->conf_if) /* Configured interface name. */
15009 json_object_object_add(json, p->conf_if, json_neigh);
15010 else /* Configured IP address. */
15011 json_object_object_add(json, p->host, json_neigh);
15012 }
15013}
15014
36235319
QY
15015static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
15016 enum show_type type,
15017 union sockunion *su,
15018 const char *conf_if, afi_t afi,
403e64f8 15019 json_object *json)
2986cac2 15020{
15021 struct listnode *node, *nnode;
15022 struct peer *peer;
5a59e9b2 15023 bool found = false;
2986cac2 15024 safi_t safi = SAFI_UNICAST;
15025 json_object *json_neighbor = NULL;
15026
15027 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15028
15029 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15030 continue;
15031
15032 if ((peer->afc[afi][safi]) == 0)
15033 continue;
15034
403e64f8
DA
15035 if (json)
15036 json_neighbor = json_object_new_object();
15037
2ba1fe69 15038 if (type == show_all) {
403e64f8 15039 bgp_show_peer_gr_status(vty, peer, json_neighbor);
2986cac2 15040
403e64f8 15041 if (json)
13909c4f
DS
15042 json_object_object_add(json, peer->host,
15043 json_neighbor);
2986cac2 15044
2ba1fe69 15045 } else if (type == show_peer) {
2986cac2 15046 if (conf_if) {
15047 if ((peer->conf_if
13909c4f
DS
15048 && !strcmp(peer->conf_if, conf_if))
15049 || (peer->hostname
2986cac2 15050 && !strcmp(peer->hostname, conf_if))) {
5a59e9b2 15051 found = true;
13909c4f 15052 bgp_show_peer_gr_status(vty, peer,
13909c4f 15053 json_neighbor);
2986cac2 15054 }
15055 } else {
15056 if (sockunion_same(&peer->su, su)) {
5a59e9b2 15057 found = true;
13909c4f 15058 bgp_show_peer_gr_status(vty, peer,
13909c4f 15059 json_neighbor);
2986cac2 15060 }
15061 }
5a59e9b2
DS
15062 if (json) {
15063 if (found)
15064 json_object_object_add(json, peer->host,
15065 json_neighbor);
15066 else
15067 json_object_free(json_neighbor);
15068 }
2986cac2 15069 }
15070
5a59e9b2 15071 if (found)
2986cac2 15072 break;
15073 }
15074
5a59e9b2 15075 if (type == show_peer && !found) {
403e64f8 15076 if (json)
13909c4f 15077 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 15078 else
15079 vty_out(vty, "%% No such neighbor\n");
15080 }
403e64f8
DA
15081
15082 if (!json)
2986cac2 15083 vty_out(vty, "\n");
2986cac2 15084
15085 return CMD_SUCCESS;
15086}
15087
d62a17ae 15088static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
15089 enum show_type type, union sockunion *su,
9f049418 15090 const char *conf_if, bool use_json,
d62a17ae 15091 json_object *json)
15092{
15093 struct listnode *node, *nnode;
15094 struct peer *peer;
15095 int find = 0;
9f049418 15096 bool nbr_output = false;
d1927ebe
AS
15097 afi_t afi = AFI_MAX;
15098 safi_t safi = SAFI_MAX;
15099
15100 if (type == show_ipv4_peer || type == show_ipv4_all) {
15101 afi = AFI_IP;
15102 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
15103 afi = AFI_IP6;
15104 }
d62a17ae 15105
15106 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15107 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15108 continue;
15109
15110 switch (type) {
15111 case show_all:
15112 bgp_show_peer(vty, peer, use_json, json);
9f049418 15113 nbr_output = true;
d62a17ae 15114 break;
15115 case show_peer:
15116 if (conf_if) {
15117 if ((peer->conf_if
15118 && !strcmp(peer->conf_if, conf_if))
15119 || (peer->hostname
15120 && !strcmp(peer->hostname, conf_if))) {
15121 find = 1;
15122 bgp_show_peer(vty, peer, use_json,
15123 json);
15124 }
15125 } else {
15126 if (sockunion_same(&peer->su, su)) {
15127 find = 1;
15128 bgp_show_peer(vty, peer, use_json,
15129 json);
15130 }
15131 }
15132 break;
d1927ebe
AS
15133 case show_ipv4_peer:
15134 case show_ipv6_peer:
15135 FOREACH_SAFI (safi) {
15136 if (peer->afc[afi][safi]) {
15137 if (conf_if) {
15138 if ((peer->conf_if
15139 && !strcmp(peer->conf_if, conf_if))
15140 || (peer->hostname
15141 && !strcmp(peer->hostname, conf_if))) {
15142 find = 1;
15143 bgp_show_peer(vty, peer, use_json,
15144 json);
15145 break;
15146 }
15147 } else {
15148 if (sockunion_same(&peer->su, su)) {
15149 find = 1;
15150 bgp_show_peer(vty, peer, use_json,
15151 json);
15152 break;
15153 }
15154 }
15155 }
15156 }
15157 break;
15158 case show_ipv4_all:
15159 case show_ipv6_all:
15160 FOREACH_SAFI (safi) {
15161 if (peer->afc[afi][safi]) {
15162 bgp_show_peer(vty, peer, use_json, json);
15163 nbr_output = true;
15164 break;
15165 }
15166 }
15167 break;
d62a17ae 15168 }
15169 }
15170
d1927ebe
AS
15171 if ((type == show_peer || type == show_ipv4_peer ||
15172 type == show_ipv6_peer) && !find) {
d62a17ae 15173 if (use_json)
15174 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
15175 else
88b7d255 15176 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 15177 }
15178
d1927ebe
AS
15179 if (type != show_peer && type != show_ipv4_peer &&
15180 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 15181 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 15182
d62a17ae 15183 if (use_json) {
996c9314
LB
15184 vty_out(vty, "%s\n", json_object_to_json_string_ext(
15185 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 15186 } else {
15187 vty_out(vty, "\n");
15188 }
15189
15190 return CMD_SUCCESS;
15191}
15192
36235319
QY
15193static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
15194 enum show_type type,
15195 const char *ip_str,
403e64f8 15196 afi_t afi, json_object *json)
2986cac2 15197{
15198
15199 int ret;
15200 struct bgp *bgp;
15201 union sockunion su;
2986cac2 15202
15203 bgp = bgp_get_default();
15204
13909c4f
DS
15205 if (!bgp)
15206 return;
2986cac2 15207
403e64f8
DA
15208 if (!json)
15209 bgp_show_global_graceful_restart_mode_vty(vty, bgp);
2986cac2 15210
13909c4f
DS
15211 if (ip_str) {
15212 ret = str2sockunion(ip_str, &su);
15213 if (ret < 0)
403e64f8
DA
15214 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
15215 ip_str, afi, json);
74a630b6
NT
15216 else
15217 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
403e64f8 15218 NULL, afi, json);
13909c4f
DS
15219 } else
15220 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
403e64f8 15221 afi, json);
2986cac2 15222}
15223
d62a17ae 15224static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
15225 enum show_type type,
15226 const char *ip_str,
9f049418 15227 bool use_json)
d62a17ae 15228{
0291c246
MK
15229 struct listnode *node, *nnode;
15230 struct bgp *bgp;
71aedaa3 15231 union sockunion su;
0291c246 15232 json_object *json = NULL;
71aedaa3 15233 int ret, is_first = 1;
9f049418 15234 bool nbr_output = false;
d62a17ae 15235
15236 if (use_json)
15237 vty_out(vty, "{\n");
15238
15239 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 15240 nbr_output = true;
d62a17ae 15241 if (use_json) {
15242 if (!(json = json_object_new_object())) {
af4c2728 15243 flog_err(
e50f7cfd 15244 EC_BGP_JSON_MEM_ERROR,
d62a17ae 15245 "Unable to allocate memory for JSON object");
15246 vty_out(vty,
15247 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
15248 return;
15249 }
15250
15251 json_object_int_add(json, "vrfId",
15252 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
15253 ? -1
15254 : (int64_t)bgp->vrf_id);
d62a17ae 15255 json_object_string_add(
15256 json, "vrfName",
15257 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15258 ? VRF_DEFAULT_NAME
d62a17ae 15259 : bgp->name);
15260
15261 if (!is_first)
15262 vty_out(vty, ",\n");
15263 else
15264 is_first = 0;
15265
15266 vty_out(vty, "\"%s\":",
15267 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15268 ? VRF_DEFAULT_NAME
d62a17ae 15269 : bgp->name);
15270 } else {
15271 vty_out(vty, "\nInstance %s:\n",
15272 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15273 ? VRF_DEFAULT_NAME
d62a17ae 15274 : bgp->name);
15275 }
71aedaa3 15276
d1927ebe
AS
15277 if (type == show_peer || type == show_ipv4_peer ||
15278 type == show_ipv6_peer) {
71aedaa3
DS
15279 ret = str2sockunion(ip_str, &su);
15280 if (ret < 0)
15281 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15282 use_json, json);
15283 else
15284 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15285 use_json, json);
15286 } else {
d1927ebe 15287 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
15288 use_json, json);
15289 }
b77004d6 15290 json_object_free(json);
121067e9 15291 json = NULL;
d62a17ae 15292 }
15293
3e78a6ce 15294 if (use_json)
d62a17ae 15295 vty_out(vty, "}\n");
9f049418
DS
15296 else if (!nbr_output)
15297 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 15298}
15299
15300static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
15301 enum show_type type, const char *ip_str,
9f049418 15302 bool use_json)
d62a17ae 15303{
15304 int ret;
15305 struct bgp *bgp;
15306 union sockunion su;
15307 json_object *json = NULL;
15308
15309 if (name) {
15310 if (strmatch(name, "all")) {
71aedaa3
DS
15311 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
15312 use_json);
d62a17ae 15313 return CMD_SUCCESS;
15314 } else {
15315 bgp = bgp_lookup_by_name(name);
15316 if (!bgp) {
15317 if (use_json) {
15318 json = json_object_new_object();
75eeda93 15319 vty_json(vty, json);
d62a17ae 15320 } else
15321 vty_out(vty,
9f049418 15322 "%% BGP instance not found\n");
d62a17ae 15323
15324 return CMD_WARNING;
15325 }
15326 }
15327 } else {
15328 bgp = bgp_get_default();
15329 }
15330
15331 if (bgp) {
15332 json = json_object_new_object();
15333 if (ip_str) {
15334 ret = str2sockunion(ip_str, &su);
15335 if (ret < 0)
15336 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15337 use_json, json);
15338 else
15339 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15340 use_json, json);
15341 } else {
15342 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15343 json);
15344 }
15345 json_object_free(json);
ca61fd25
DS
15346 } else {
15347 if (use_json)
15348 vty_out(vty, "{}\n");
15349 else
15350 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 15351 }
15352
15353 return CMD_SUCCESS;
4fb25c53
DW
15354}
15355
2986cac2 15356
15357
15358/* "show [ip] bgp neighbors graceful-restart" commands. */
dcab9012 15359DEFUN (show_ip_bgp_neighbors_graceful_restart,
2986cac2 15360 show_ip_bgp_neighbors_graceful_restart_cmd,
15361 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15362 SHOW_STR
15363 BGP_STR
15364 IP_STR
15365 IPV6_STR
15366 NEIGHBOR_STR
15367 "Neighbor to display information about\n"
15368 "Neighbor to display information about\n"
15369 "Neighbor on BGP configured interface\n"
15370 GR_SHOW
15371 JSON_STR)
15372{
15373 char *sh_arg = NULL;
15374 enum show_type sh_type;
15375 int idx = 0;
15376 afi_t afi = AFI_MAX;
2986cac2 15377 bool uj = use_json(argc, argv);
15378
36235319 15379 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 15380 afi = AFI_MAX;
15381
15382 idx++;
15383
15384 if (argv_find(argv, argc, "A.B.C.D", &idx)
15385 || argv_find(argv, argc, "X:X::X:X", &idx)
15386 || argv_find(argv, argc, "WORD", &idx)) {
15387 sh_type = show_peer;
15388 sh_arg = argv[idx]->arg;
15389 } else
15390 sh_type = show_all;
15391
15392 if (!argv_find(argv, argc, "graceful-restart", &idx))
15393 return CMD_SUCCESS;
15394
15395
36235319
QY
15396 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15397 afi, uj);
2986cac2 15398}
15399
716b2d8a 15400/* "show [ip] bgp neighbors" commands. */
718e3744 15401DEFUN (show_ip_bgp_neighbors,
15402 show_ip_bgp_neighbors_cmd,
24345e82 15403 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 15404 SHOW_STR
15405 IP_STR
15406 BGP_STR
f2a8972b 15407 BGP_INSTANCE_HELP_STR
00e6edb9
DA
15408 BGP_AF_STR
15409 BGP_AF_STR
718e3744 15410 "Detailed information on TCP and BGP neighbor connections\n"
15411 "Neighbor to display information about\n"
a80beece 15412 "Neighbor to display information about\n"
91d37724 15413 "Neighbor on BGP configured interface\n"
9973d184 15414 JSON_STR)
718e3744 15415{
d62a17ae 15416 char *vrf = NULL;
15417 char *sh_arg = NULL;
15418 enum show_type sh_type;
d1927ebe 15419 afi_t afi = AFI_MAX;
718e3744 15420
9f049418 15421 bool uj = use_json(argc, argv);
718e3744 15422
d62a17ae 15423 int idx = 0;
718e3744 15424
9a8bdf1c
PG
15425 /* [<vrf> VIEWVRFNAME] */
15426 if (argv_find(argv, argc, "vrf", &idx)) {
15427 vrf = argv[idx + 1]->arg;
15428 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15429 vrf = NULL;
15430 } else if (argv_find(argv, argc, "view", &idx))
15431 /* [<view> VIEWVRFNAME] */
d62a17ae 15432 vrf = argv[idx + 1]->arg;
718e3744 15433
d62a17ae 15434 idx++;
d1927ebe
AS
15435
15436 if (argv_find(argv, argc, "ipv4", &idx)) {
15437 sh_type = show_ipv4_all;
15438 afi = AFI_IP;
15439 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15440 sh_type = show_ipv6_all;
15441 afi = AFI_IP6;
15442 } else {
15443 sh_type = show_all;
15444 }
15445
d62a17ae 15446 if (argv_find(argv, argc, "A.B.C.D", &idx)
15447 || argv_find(argv, argc, "X:X::X:X", &idx)
15448 || argv_find(argv, argc, "WORD", &idx)) {
15449 sh_type = show_peer;
15450 sh_arg = argv[idx]->arg;
d1927ebe
AS
15451 }
15452
15453 if (sh_type == show_peer && afi == AFI_IP) {
15454 sh_type = show_ipv4_peer;
15455 } else if (sh_type == show_peer && afi == AFI_IP6) {
15456 sh_type = show_ipv6_peer;
15457 }
856ca177 15458
d62a17ae 15459 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 15460}
15461
716b2d8a 15462/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 15463 paths' and `show ip mbgp paths'. Those functions results are the
15464 same.*/
f412b39a 15465DEFUN (show_ip_bgp_paths,
718e3744 15466 show_ip_bgp_paths_cmd,
46f296b4 15467 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 15468 SHOW_STR
15469 IP_STR
15470 BGP_STR
46f296b4 15471 BGP_SAFI_HELP_STR
718e3744 15472 "Path information\n")
15473{
d62a17ae 15474 vty_out(vty, "Address Refcnt Path\n");
15475 aspath_print_all_vty(vty);
15476 return CMD_SUCCESS;
718e3744 15477}
15478
718e3744 15479#include "hash.h"
15480
e3b78da8 15481static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15482 struct vty *vty)
718e3744 15483{
d62a17ae 15484 struct community *com;
718e3744 15485
e3b78da8 15486 com = (struct community *)bucket->data;
3f65c5b1 15487 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
c0945b78 15488 community_str(com, false, false));
718e3744 15489}
15490
15491/* Show BGP's community internal data. */
f412b39a 15492DEFUN (show_ip_bgp_community_info,
718e3744 15493 show_ip_bgp_community_info_cmd,
bec37ba5 15494 "show [ip] bgp community-info",
718e3744 15495 SHOW_STR
15496 IP_STR
15497 BGP_STR
15498 "List all bgp community information\n")
15499{
d62a17ae 15500 vty_out(vty, "Address Refcnt Community\n");
718e3744 15501
d62a17ae 15502 hash_iterate(community_hash(),
e3b78da8 15503 (void (*)(struct hash_bucket *,
d62a17ae 15504 void *))community_show_all_iterator,
15505 vty);
718e3744 15506
d62a17ae 15507 return CMD_SUCCESS;
718e3744 15508}
15509
e3b78da8 15510static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15511 struct vty *vty)
57d187bc 15512{
d62a17ae 15513 struct lcommunity *lcom;
57d187bc 15514
e3b78da8 15515 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 15516 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
c0945b78 15517 lcommunity_str(lcom, false, false));
57d187bc
JS
15518}
15519
15520/* Show BGP's community internal data. */
15521DEFUN (show_ip_bgp_lcommunity_info,
15522 show_ip_bgp_lcommunity_info_cmd,
15523 "show ip bgp large-community-info",
15524 SHOW_STR
15525 IP_STR
15526 BGP_STR
15527 "List all bgp large-community information\n")
15528{
d62a17ae 15529 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 15530
d62a17ae 15531 hash_iterate(lcommunity_hash(),
e3b78da8 15532 (void (*)(struct hash_bucket *,
d62a17ae 15533 void *))lcommunity_show_all_iterator,
15534 vty);
57d187bc 15535
d62a17ae 15536 return CMD_SUCCESS;
57d187bc 15537}
2986cac2 15538/* Graceful Restart */
15539
15540static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
403e64f8 15541 struct bgp *bgp)
2986cac2 15542{
57d187bc
JS
15543
15544
2986cac2 15545 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15546
7318ae88 15547 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 15548
15549 switch (bgp_global_gr_mode) {
15550
15551 case GLOBAL_HELPER:
13909c4f 15552 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 15553 break;
15554
15555 case GLOBAL_GR:
13909c4f 15556 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 15557 break;
15558
15559 case GLOBAL_DISABLE:
13909c4f 15560 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 15561 break;
15562
15563 case GLOBAL_INVALID:
2986cac2 15564 vty_out(vty,
2ba1fe69 15565 "Global BGP GR Mode Invalid\n");
2986cac2 15566 break;
15567 }
15568 vty_out(vty, "\n");
15569}
15570
36235319
QY
15571static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15572 enum show_type type,
15573 const char *ip_str,
15574 afi_t afi, bool use_json)
2986cac2 15575{
403e64f8
DA
15576 json_object *json = NULL;
15577
15578 if (use_json)
15579 json = json_object_new_object();
15580
2986cac2 15581 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15582 afi = AFI_IP;
15583
15584 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15585
36235319 15586 bgp_show_neighbor_graceful_restart_vty(
403e64f8 15587 vty, type, ip_str, afi, json);
2986cac2 15588 afi++;
15589 }
15590 } else if (afi != AFI_MAX) {
36235319 15591 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
403e64f8 15592 json);
2986cac2 15593 } else {
403e64f8
DA
15594 if (json)
15595 json_object_free(json);
2986cac2 15596 return CMD_ERR_INCOMPLETE;
15597 }
15598
403e64f8
DA
15599 if (json)
15600 vty_json(vty, json);
15601
2986cac2 15602 return CMD_SUCCESS;
15603}
15604/* Graceful Restart */
15605
f412b39a 15606DEFUN (show_ip_bgp_attr_info,
718e3744 15607 show_ip_bgp_attr_info_cmd,
bec37ba5 15608 "show [ip] bgp attribute-info",
718e3744 15609 SHOW_STR
15610 IP_STR
15611 BGP_STR
15612 "List all bgp attribute information\n")
15613{
d62a17ae 15614 attr_show_all(vty);
15615 return CMD_SUCCESS;
718e3744 15616}
6b0655a2 15617
03915806
CS
15618static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15619 afi_t afi, safi_t safi,
15620 bool use_json, json_object *json)
53089bec 15621{
15622 struct bgp *bgp;
15623 struct listnode *node;
15624 char *vname;
53089bec 15625 char *ecom_str;
9c2fd3fe 15626 enum vpn_policy_direction dir;
53089bec 15627
03915806 15628 if (json) {
b46dfd20
DS
15629 json_object *json_import_vrfs = NULL;
15630 json_object *json_export_vrfs = NULL;
15631
b46dfd20
DS
15632 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15633
53089bec 15634 if (!bgp) {
75eeda93 15635 vty_json(vty, json);
b46dfd20 15636
53089bec 15637 return CMD_WARNING;
15638 }
b46dfd20 15639
94d4c685
DS
15640 /* Provide context for the block */
15641 json_object_string_add(json, "vrf", name ? name : "default");
15642 json_object_string_add(json, "afiSafi",
5cb5f4d0 15643 get_afi_safi_str(afi, safi, true));
94d4c685 15644
b46dfd20
DS
15645 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15646 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15647 json_object_string_add(json, "importFromVrfs", "none");
15648 json_object_string_add(json, "importRts", "none");
15649 } else {
6ce24e52
DS
15650 json_import_vrfs = json_object_new_array();
15651
b46dfd20
DS
15652 for (ALL_LIST_ELEMENTS_RO(
15653 bgp->vpn_policy[afi].import_vrf,
15654 node, vname))
15655 json_object_array_add(json_import_vrfs,
15656 json_object_new_string(vname));
15657
b20875ea
CS
15658 json_object_object_add(json, "importFromVrfs",
15659 json_import_vrfs);
b46dfd20 15660 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15661 if (bgp->vpn_policy[afi].rtlist[dir]) {
15662 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15663 bgp->vpn_policy[afi].rtlist[dir],
15664 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15665 json_object_string_add(json, "importRts",
15666 ecom_str);
15667 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15668 } else
15669 json_object_string_add(json, "importRts",
15670 "none");
b46dfd20
DS
15671 }
15672
15673 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15674 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15675 json_object_string_add(json, "exportToVrfs", "none");
15676 json_object_string_add(json, "routeDistinguisher",
15677 "none");
15678 json_object_string_add(json, "exportRts", "none");
15679 } else {
6ce24e52
DS
15680 json_export_vrfs = json_object_new_array();
15681
b46dfd20
DS
15682 for (ALL_LIST_ELEMENTS_RO(
15683 bgp->vpn_policy[afi].export_vrf,
15684 node, vname))
15685 json_object_array_add(json_export_vrfs,
15686 json_object_new_string(vname));
15687 json_object_object_add(json, "exportToVrfs",
15688 json_export_vrfs);
fa566a94
PG
15689 json_object_string_addf(
15690 json, "routeDistinguisher", "%s",
15691 bgp->vpn_policy[afi].tovpn_rd_pretty);
b46dfd20 15692 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15693 if (bgp->vpn_policy[afi].rtlist[dir]) {
15694 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15695 bgp->vpn_policy[afi].rtlist[dir],
15696 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15697 json_object_string_add(json, "exportRts",
15698 ecom_str);
15699 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15700 } else
15701 json_object_string_add(json, "exportRts",
15702 "none");
b46dfd20
DS
15703 }
15704
03915806 15705 if (use_json) {
75eeda93 15706 vty_json(vty, json);
03915806 15707 }
53089bec 15708 } else {
b46dfd20
DS
15709 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15710
53089bec 15711 if (!bgp) {
b46dfd20 15712 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 15713 return CMD_WARNING;
15714 }
53089bec 15715
b46dfd20
DS
15716 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15717 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15718 vty_out(vty,
15719 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 15720 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15721 else {
15722 vty_out(vty,
15723 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 15724 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15725
15726 for (ALL_LIST_ELEMENTS_RO(
15727 bgp->vpn_policy[afi].import_vrf,
15728 node, vname))
15729 vty_out(vty, " %s\n", vname);
15730
15731 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15732 ecom_str = NULL;
15733 if (bgp->vpn_policy[afi].rtlist[dir]) {
15734 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15735 bgp->vpn_policy[afi].rtlist[dir],
15736 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 15737 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 15738
b20875ea
CS
15739 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15740 } else
15741 vty_out(vty, "Import RT(s):\n");
53089bec 15742 }
53089bec 15743
b46dfd20
DS
15744 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15745 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15746 vty_out(vty,
15747 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 15748 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15749 else {
15750 vty_out(vty,
04c9077f 15751 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 15752 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15753
15754 for (ALL_LIST_ELEMENTS_RO(
15755 bgp->vpn_policy[afi].export_vrf,
15756 node, vname))
15757 vty_out(vty, " %s\n", vname);
15758
4a8cd6ad
PG
15759 vty_out(vty, "RD: ");
15760 vty_out(vty, BGP_RD_AS_FORMAT(bgp->asnotation),
c4f64ea9 15761 &bgp->vpn_policy[afi].tovpn_rd);
4a8cd6ad 15762 vty_out(vty, "\n");
b46dfd20
DS
15763
15764 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15765 if (bgp->vpn_policy[afi].rtlist[dir]) {
15766 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15767 bgp->vpn_policy[afi].rtlist[dir],
15768 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15769 vty_out(vty, "Export RT: %s\n", ecom_str);
15770 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15771 } else
15772 vty_out(vty, "Import RT(s):\n");
53089bec 15773 }
53089bec 15774 }
15775
15776 return CMD_SUCCESS;
15777}
15778
03915806
CS
15779static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15780 safi_t safi, bool use_json)
15781{
15782 struct listnode *node, *nnode;
15783 struct bgp *bgp;
15784 char *vrf_name = NULL;
15785 json_object *json = NULL;
15786 json_object *json_vrf = NULL;
15787 json_object *json_vrfs = NULL;
15788
15789 if (use_json) {
15790 json = json_object_new_object();
15791 json_vrfs = json_object_new_object();
15792 }
15793
15794 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15795
15796 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15797 vrf_name = bgp->name;
15798
15799 if (use_json) {
15800 json_vrf = json_object_new_object();
15801 } else {
15802 vty_out(vty, "\nInstance %s:\n",
15803 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15804 ? VRF_DEFAULT_NAME : bgp->name);
15805 }
15806 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15807 if (use_json) {
15808 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15809 json_object_object_add(json_vrfs,
15810 VRF_DEFAULT_NAME, json_vrf);
15811 else
15812 json_object_object_add(json_vrfs, vrf_name,
15813 json_vrf);
15814 }
15815 }
15816
15817 if (use_json) {
15818 json_object_object_add(json, "vrfs", json_vrfs);
75eeda93 15819 vty_json(vty, json);
03915806
CS
15820 }
15821
15822 return CMD_SUCCESS;
15823}
15824
53089bec 15825/* "show [ip] bgp route-leak" command. */
15826DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
15827 show_ip_bgp_route_leak_cmd,
15828 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
15829 SHOW_STR
15830 IP_STR
15831 BGP_STR
15832 BGP_INSTANCE_HELP_STR
15833 BGP_AFI_HELP_STR
15834 BGP_SAFI_HELP_STR
15835 "Route leaking information\n"
15836 JSON_STR)
53089bec 15837{
15838 char *vrf = NULL;
15839 afi_t afi = AFI_MAX;
15840 safi_t safi = SAFI_MAX;
15841
9f049418 15842 bool uj = use_json(argc, argv);
53089bec 15843 int idx = 0;
03915806 15844 json_object *json = NULL;
53089bec 15845
15846 /* show [ip] bgp */
15847 if (argv_find(argv, argc, "ip", &idx)) {
15848 afi = AFI_IP;
15849 safi = SAFI_UNICAST;
15850 }
15851 /* [vrf VIEWVRFNAME] */
15852 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
15853 vty_out(vty,
15854 "%% This command is not applicable to BGP views\n");
53089bec 15855 return CMD_WARNING;
15856 }
15857
9a8bdf1c
PG
15858 if (argv_find(argv, argc, "vrf", &idx)) {
15859 vrf = argv[idx + 1]->arg;
15860 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15861 vrf = NULL;
15862 }
53089bec 15863 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
c48349e3 15864 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
53089bec 15865 argv_find_and_parse_safi(argv, argc, &idx, &safi);
53089bec 15866
15867 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
15868 vty_out(vty,
15869 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 15870 return CMD_WARNING;
15871 }
15872
03915806
CS
15873 if (vrf && strmatch(vrf, "all"))
15874 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15875
15876 if (uj)
15877 json = json_object_new_object();
15878
15879 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 15880}
15881
d62a17ae 15882static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
fa5a9276 15883 safi_t safi, bool uj)
f186de26 15884{
d62a17ae 15885 struct listnode *node, *nnode;
15886 struct bgp *bgp;
f186de26 15887
d62a17ae 15888 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
fa5a9276
AR
15889 if (!uj)
15890 vty_out(vty, "\nInstance %s:\n",
15891 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15892 ? VRF_DEFAULT_NAME
15893 : bgp->name);
15894
15895 update_group_show(bgp, afi, safi, vty, 0, uj);
d62a17ae 15896 }
f186de26 15897}
15898
d62a17ae 15899static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
fa5a9276 15900 int safi, uint64_t subgrp_id, bool uj)
4fb25c53 15901{
d62a17ae 15902 struct bgp *bgp;
4fb25c53 15903
d62a17ae 15904 if (name) {
15905 if (strmatch(name, "all")) {
fa5a9276 15906 bgp_show_all_instances_updgrps_vty(vty, afi, safi, uj);
d62a17ae 15907 return CMD_SUCCESS;
15908 } else {
15909 bgp = bgp_lookup_by_name(name);
15910 }
15911 } else {
15912 bgp = bgp_get_default();
15913 }
4fb25c53 15914
d62a17ae 15915 if (bgp)
fa5a9276 15916 update_group_show(bgp, afi, safi, vty, subgrp_id, uj);
d62a17ae 15917 return CMD_SUCCESS;
4fb25c53
DW
15918}
15919
8fe8a7f6
DS
15920DEFUN (show_ip_bgp_updgrps,
15921 show_ip_bgp_updgrps_cmd,
fa5a9276 15922 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID] [json]",
8386ac43 15923 SHOW_STR
15924 IP_STR
15925 BGP_STR
15926 BGP_INSTANCE_HELP_STR
c9e571b4 15927 BGP_AFI_HELP_STR
9bedbb1e 15928 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956 15929 "Detailed info about dynamic update groups\n"
fa5a9276
AR
15930 "Specific subgroup to display detailed info for\n"
15931 JSON_STR)
8386ac43 15932{
d62a17ae 15933 char *vrf = NULL;
15934 afi_t afi = AFI_IP6;
15935 safi_t safi = SAFI_UNICAST;
15936 uint64_t subgrp_id = 0;
15937
15938 int idx = 0;
15939
fa5a9276
AR
15940 bool uj = use_json(argc, argv);
15941
d62a17ae 15942 /* show [ip] bgp */
15943 if (argv_find(argv, argc, "ip", &idx))
15944 afi = AFI_IP;
9a8bdf1c
PG
15945 /* [<vrf> VIEWVRFNAME] */
15946 if (argv_find(argv, argc, "vrf", &idx)) {
15947 vrf = argv[idx + 1]->arg;
15948 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15949 vrf = NULL;
15950 } else if (argv_find(argv, argc, "view", &idx))
15951 /* [<view> VIEWVRFNAME] */
15952 vrf = argv[idx + 1]->arg;
d62a17ae 15953 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15954 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15955 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15956 }
5bf15956 15957
d62a17ae 15958 /* get subgroup id, if provided */
15959 idx = argc - 1;
15960 if (argv[idx]->type == VARIABLE_TKN)
15961 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 15962
fa5a9276 15963 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id, uj));
8fe8a7f6
DS
15964}
15965
f186de26 15966DEFUN (show_bgp_instance_all_ipv6_updgrps,
15967 show_bgp_instance_all_ipv6_updgrps_cmd,
fa5a9276 15968 "show [ip] bgp <view|vrf> all update-groups [json]",
f186de26 15969 SHOW_STR
716b2d8a 15970 IP_STR
f186de26 15971 BGP_STR
15972 BGP_INSTANCE_ALL_HELP_STR
fa5a9276
AR
15973 "Detailed info about dynamic update groups\n"
15974 JSON_STR)
f186de26 15975{
fa5a9276
AR
15976 bool uj = use_json(argc, argv);
15977
15978 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST, uj);
d62a17ae 15979 return CMD_SUCCESS;
f186de26 15980}
15981
43d3f4fc
DS
15982DEFUN (show_bgp_l2vpn_evpn_updgrps,
15983 show_bgp_l2vpn_evpn_updgrps_cmd,
15984 "show [ip] bgp l2vpn evpn update-groups",
15985 SHOW_STR
15986 IP_STR
15987 BGP_STR
15988 "l2vpn address family\n"
15989 "evpn sub-address family\n"
15990 "Detailed info about dynamic update groups\n")
15991{
15992 char *vrf = NULL;
15993 uint64_t subgrp_id = 0;
15994
fa5a9276 15995 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id, 0);
43d3f4fc
DS
15996 return CMD_SUCCESS;
15997}
15998
5bf15956
DW
15999DEFUN (show_bgp_updgrps_stats,
16000 show_bgp_updgrps_stats_cmd,
716b2d8a 16001 "show [ip] bgp update-groups statistics",
3f9c7369 16002 SHOW_STR
716b2d8a 16003 IP_STR
3f9c7369 16004 BGP_STR
0c7b1b01 16005 "Detailed info about dynamic update groups\n"
3f9c7369
DS
16006 "Statistics\n")
16007{
d62a17ae 16008 struct bgp *bgp;
3f9c7369 16009
d62a17ae 16010 bgp = bgp_get_default();
16011 if (bgp)
16012 update_group_show_stats(bgp, vty);
3f9c7369 16013
d62a17ae 16014 return CMD_SUCCESS;
3f9c7369
DS
16015}
16016
8386ac43 16017DEFUN (show_bgp_instance_updgrps_stats,
16018 show_bgp_instance_updgrps_stats_cmd,
18c57037 16019 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 16020 SHOW_STR
716b2d8a 16021 IP_STR
8386ac43 16022 BGP_STR
16023 BGP_INSTANCE_HELP_STR
0c7b1b01 16024 "Detailed info about dynamic update groups\n"
8386ac43 16025 "Statistics\n")
16026{
d62a17ae 16027 int idx_word = 3;
16028 struct bgp *bgp;
8386ac43 16029
d62a17ae 16030 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
16031 if (bgp)
16032 update_group_show_stats(bgp, vty);
8386ac43 16033
d62a17ae 16034 return CMD_SUCCESS;
8386ac43 16035}
16036
d62a17ae 16037static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
16038 afi_t afi, safi_t safi,
16039 const char *what, uint64_t subgrp_id)
3f9c7369 16040{
d62a17ae 16041 struct bgp *bgp;
8386ac43 16042
d62a17ae 16043 if (name)
16044 bgp = bgp_lookup_by_name(name);
16045 else
16046 bgp = bgp_get_default();
8386ac43 16047
d62a17ae 16048 if (bgp) {
16049 if (!strcmp(what, "advertise-queue"))
16050 update_group_show_adj_queue(bgp, afi, safi, vty,
16051 subgrp_id);
16052 else if (!strcmp(what, "advertised-routes"))
16053 update_group_show_advertised(bgp, afi, safi, vty,
16054 subgrp_id);
16055 else if (!strcmp(what, "packet-queue"))
16056 update_group_show_packet_queue(bgp, afi, safi, vty,
16057 subgrp_id);
16058 }
3f9c7369
DS
16059}
16060
dc64bdec
QY
16061DEFPY(show_ip_bgp_instance_updgrps_adj_s,
16062 show_ip_bgp_instance_updgrps_adj_s_cmd,
16063 "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",
16064 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
16065 BGP_SAFI_HELP_STR
16066 "Detailed info about dynamic update groups\n"
16067 "Specific subgroup to display info for\n"
16068 "Advertisement queue\n"
16069 "Announced routes\n"
16070 "Packet queue\n")
3f9c7369 16071{
dc64bdec
QY
16072 uint64_t subgrp_id = 0;
16073 afi_t afiz;
16074 safi_t safiz;
16075 if (sgid)
16076 subgrp_id = strtoull(sgid, NULL, 10);
16077
16078 if (!ip && !afi)
16079 afiz = AFI_IP6;
16080 if (!ip && afi)
16081 afiz = bgp_vty_afi_from_str(afi);
16082 if (ip && !afi)
16083 afiz = AFI_IP;
16084 if (ip && afi) {
16085 afiz = bgp_vty_afi_from_str(afi);
16086 if (afiz != AFI_IP)
16087 vty_out(vty,
16088 "%% Cannot specify both 'ip' and 'ipv6'\n");
16089 return CMD_WARNING;
16090 }
d62a17ae 16091
dc64bdec 16092 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 16093
dc64bdec 16094 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 16095 return CMD_SUCCESS;
16096}
16097
6f4eacf3
DA
16098static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
16099 json_object *json)
d62a17ae 16100{
16101 struct listnode *node, *nnode;
16102 struct prefix *range;
16103 struct peer *conf;
16104 struct peer *peer;
d62a17ae 16105 afi_t afi;
16106 safi_t safi;
16107 const char *peer_status;
d62a17ae 16108 int lr_count;
16109 int dynamic;
6f4eacf3
DA
16110 bool af_cfgd;
16111 json_object *json_peer_group = NULL;
16112 json_object *json_peer_group_afc = NULL;
16113 json_object *json_peer_group_members = NULL;
16114 json_object *json_peer_group_dynamic = NULL;
16115 json_object *json_peer_group_dynamic_af = NULL;
16116 json_object *json_peer_group_ranges = NULL;
d62a17ae 16117
16118 conf = group->conf;
16119
6f4eacf3
DA
16120 if (json) {
16121 json_peer_group = json_object_new_object();
16122 json_peer_group_afc = json_object_new_array();
16123 }
16124
d62a17ae 16125 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3 16126 if (json)
44a4d55e
PG
16127 asn_asn2json(json_peer_group, "remoteAs", conf->as,
16128 bgp_get_asnotation(conf->bgp));
16129 else {
16130 vty_out(vty, "\nBGP peer-group %s, remote AS ",
16131 group->name);
16132 vty_out(vty, ASN_FORMAT(bgp_get_asnotation(conf->bgp)),
16133 &conf->as);
16134 vty_out(vty, "\n");
16135 }
d62a17ae 16136 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3 16137 if (json)
e84c7c12
PG
16138 asn_asn2json(json, "remoteAs", group->bgp->as,
16139 group->bgp->asnotation);
6f4eacf3 16140 else
9eb11997
PG
16141 vty_out(vty, "\nBGP peer-group %s, remote AS %s\n",
16142 group->name, group->bgp->as_pretty);
d62a17ae 16143 } else {
6f4eacf3
DA
16144 if (!json)
16145 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 16146 }
f14e6fdb 16147
6f4eacf3
DA
16148 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
16149 if (json)
16150 json_object_string_add(json_peer_group, "type",
16151 "internal");
16152 else
16153 vty_out(vty, " Peer-group type is internal\n");
16154 } else {
16155 if (json)
16156 json_object_string_add(json_peer_group, "type",
16157 "external");
16158 else
16159 vty_out(vty, " Peer-group type is external\n");
16160 }
d62a17ae 16161
16162 /* Display AFs configured. */
6f4eacf3
DA
16163 if (!json)
16164 vty_out(vty, " Configured address-families:");
16165
05c7a1cc
QY
16166 FOREACH_AFI_SAFI (afi, safi) {
16167 if (conf->afc[afi][safi]) {
6f4eacf3
DA
16168 af_cfgd = true;
16169 if (json)
16170 json_object_array_add(
16171 json_peer_group_afc,
16172 json_object_new_string(get_afi_safi_str(
16173 afi, safi, false)));
16174 else
16175 vty_out(vty, " %s;",
16176 get_afi_safi_str(afi, safi, false));
d62a17ae 16177 }
05c7a1cc 16178 }
6f4eacf3
DA
16179
16180 if (json) {
16181 json_object_object_add(json_peer_group,
16182 "addressFamiliesConfigured",
16183 json_peer_group_afc);
16184 } else {
16185 if (!af_cfgd)
16186 vty_out(vty, " none\n");
16187 else
16188 vty_out(vty, "\n");
16189 }
d62a17ae 16190
16191 /* Display listen ranges (for dynamic neighbors), if any */
16192 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 16193 lr_count = listcount(group->listen_range[afi]);
16194 if (lr_count) {
6f4eacf3
DA
16195 if (json) {
16196 if (!json_peer_group_dynamic)
16197 json_peer_group_dynamic =
16198 json_object_new_object();
16199
16200 json_peer_group_dynamic_af =
16201 json_object_new_object();
16202 json_peer_group_ranges =
16203 json_object_new_array();
16204 json_object_int_add(json_peer_group_dynamic_af,
16205 "count", lr_count);
16206 } else {
16207 vty_out(vty, " %d %s listen range(s)\n",
16208 lr_count, afi2str(afi));
16209 }
d62a17ae 16210
16211 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
16212 nnode, range)) {
16213 if (json) {
16214 char buf[BUFSIZ];
16215
16216 snprintfrr(buf, sizeof(buf), "%pFX",
16217 range);
16218
16219 json_object_array_add(
16220 json_peer_group_ranges,
16221 json_object_new_string(buf));
16222 } else {
16223 vty_out(vty, " %pFX\n", range);
16224 }
16225 }
16226
16227 if (json) {
16228 json_object_object_add(
16229 json_peer_group_dynamic_af, "ranges",
16230 json_peer_group_ranges);
16231
16232 json_object_object_add(
16233 json_peer_group_dynamic, afi2str(afi),
16234 json_peer_group_dynamic_af);
16235 }
d62a17ae 16236 }
16237 }
f14e6fdb 16238
6f4eacf3
DA
16239 if (json_peer_group_dynamic)
16240 json_object_object_add(json_peer_group, "dynamicRanges",
16241 json_peer_group_dynamic);
16242
d62a17ae 16243 /* Display group members and their status */
16244 if (listcount(group->peer)) {
6f4eacf3
DA
16245 if (json)
16246 json_peer_group_members = json_object_new_object();
16247 else
16248 vty_out(vty, " Peer-group members:\n");
d62a17ae 16249 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
16250 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
16251 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 16252 peer_status = "Idle (Admin)";
16253 else if (CHECK_FLAG(peer->sflags,
16254 PEER_STATUS_PREFIX_OVERFLOW))
16255 peer_status = "Idle (PfxCt)";
16256 else
16257 peer_status = lookup_msg(bgp_status_msg,
16258 peer->status, NULL);
16259
16260 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
16261
16262 if (json) {
16263 json_object *json_peer_group_member =
16264 json_object_new_object();
16265
16266 json_object_string_add(json_peer_group_member,
16267 "status", peer_status);
16268
16269 if (dynamic)
16270 json_object_boolean_true_add(
16271 json_peer_group_member,
16272 "dynamic");
16273
16274 json_object_object_add(json_peer_group_members,
16275 peer->host,
16276 json_peer_group_member);
16277 } else {
16278 vty_out(vty, " %s %s %s \n", peer->host,
16279 dynamic ? "(dynamic)" : "",
16280 peer_status);
16281 }
d62a17ae 16282 }
6f4eacf3
DA
16283 if (json)
16284 json_object_object_add(json_peer_group, "members",
16285 json_peer_group_members);
d62a17ae 16286 }
f14e6fdb 16287
6f4eacf3
DA
16288 if (json)
16289 json_object_object_add(json, group->name, json_peer_group);
16290
d62a17ae 16291 return CMD_SUCCESS;
16292}
16293
ff9959b0 16294static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 16295 const char *group_name, bool uj)
d62a17ae 16296{
ff9959b0 16297 struct bgp *bgp;
d62a17ae 16298 struct listnode *node, *nnode;
16299 struct peer_group *group;
ff9959b0 16300 bool found = false;
6f4eacf3
DA
16301 json_object *json = NULL;
16302
16303 if (uj)
16304 json = json_object_new_object();
ff9959b0
QY
16305
16306 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
16307
16308 if (!bgp) {
c48349e3 16309 if (uj)
75eeda93 16310 vty_json(vty, json);
c48349e3 16311 else
6f4eacf3 16312 vty_out(vty, "%% BGP instance not found\n");
6f4eacf3 16313
ff9959b0
QY
16314 return CMD_WARNING;
16315 }
d62a17ae 16316
16317 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
16318 if (group_name) {
16319 if (strmatch(group->name, group_name)) {
6f4eacf3 16320 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
16321 found = true;
16322 break;
d62a17ae 16323 }
ff9959b0 16324 } else {
6f4eacf3 16325 bgp_show_one_peer_group(vty, group, json);
d62a17ae 16326 }
f14e6fdb 16327 }
f14e6fdb 16328
6f4eacf3 16329 if (group_name && !found && !uj)
d62a17ae 16330 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 16331
c48349e3 16332 if (uj)
75eeda93 16333 vty_json(vty, json);
6f4eacf3 16334
d62a17ae 16335 return CMD_SUCCESS;
f14e6fdb
DS
16336}
16337
6f4eacf3
DA
16338DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
16339 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
16340 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
16341 "Detailed information on BGP peer groups\n"
16342 "Peer group name\n" JSON_STR)
f14e6fdb 16343{
d62a17ae 16344 char *vrf, *pg;
d62a17ae 16345 int idx = 0;
6f4eacf3 16346 bool uj = use_json(argc, argv);
f14e6fdb 16347
a4d82a8a
PZ
16348 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16349 : NULL;
d62a17ae 16350 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 16351
6f4eacf3 16352 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 16353}
3f9c7369 16354
d6e3c605 16355
718e3744 16356/* Redistribute VTY commands. */
16357
585f1adc
IR
16358DEFUN (bgp_redistribute_ipv4,
16359 bgp_redistribute_ipv4_cmd,
16360 "redistribute " FRR_IP_REDIST_STR_BGPD,
16361 "Redistribute information from another routing protocol\n"
16362 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 16363{
585f1adc 16364 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16365 int idx_protocol = 1;
585f1adc 16366 int type;
37a87b8f 16367
585f1adc
IR
16368 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16369 if (type < 0) {
16370 vty_out(vty, "%% Invalid route type\n");
16371 return CMD_WARNING_CONFIG_FAILED;
16372 }
7f323236 16373
585f1adc
IR
16374 bgp_redist_add(bgp, AFI_IP, type, 0);
16375 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 16376}
16377
d62a17ae 16378ALIAS_HIDDEN(
16379 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16380 "redistribute " FRR_IP_REDIST_STR_BGPD,
16381 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 16382
585f1adc
IR
16383DEFUN (bgp_redistribute_ipv4_rmap,
16384 bgp_redistribute_ipv4_rmap_cmd,
70dd370f 16385 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
585f1adc
IR
16386 "Redistribute information from another routing protocol\n"
16387 FRR_IP_REDIST_HELP_STR_BGPD
16388 "Route map reference\n"
16389 "Pointer to route-map entries\n")
718e3744 16390{
585f1adc 16391 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16392 int idx_protocol = 1;
16393 int idx_word = 3;
585f1adc
IR
16394 int type;
16395 struct bgp_redist *red;
16396 bool changed;
16397 struct route_map *route_map = route_map_lookup_warn_noexist(
16398 vty, argv[idx_word]->arg);
16399
16400 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16401 if (type < 0) {
16402 vty_out(vty, "%% Invalid route type\n");
16403 return CMD_WARNING_CONFIG_FAILED;
16404 }
37a87b8f 16405
585f1adc
IR
16406 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16407 changed =
16408 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16409 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 16410}
16411
d62a17ae 16412ALIAS_HIDDEN(
16413 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
70dd370f 16414 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
d62a17ae 16415 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16416 "Route map reference\n"
16417 "Pointer to route-map entries\n")
596c17ba 16418
585f1adc
IR
16419DEFUN (bgp_redistribute_ipv4_metric,
16420 bgp_redistribute_ipv4_metric_cmd,
16421 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16422 "Redistribute information from another routing protocol\n"
16423 FRR_IP_REDIST_HELP_STR_BGPD
16424 "Metric for redistributed routes\n"
16425 "Default metric\n")
718e3744 16426{
585f1adc 16427 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16428 int idx_protocol = 1;
16429 int idx_number = 3;
585f1adc
IR
16430 int type;
16431 uint32_t metric;
16432 struct bgp_redist *red;
16433 bool changed;
16434
16435 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16436 if (type < 0) {
16437 vty_out(vty, "%% Invalid route type\n");
16438 return CMD_WARNING_CONFIG_FAILED;
16439 }
16440 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16441
585f1adc
IR
16442 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16443 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16444 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16445}
16446
16447ALIAS_HIDDEN(
16448 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16449 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16450 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16451 "Metric for redistributed routes\n"
16452 "Default metric\n")
596c17ba 16453
585f1adc
IR
16454DEFUN (bgp_redistribute_ipv4_rmap_metric,
16455 bgp_redistribute_ipv4_rmap_metric_cmd,
70dd370f 16456 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16457 "Redistribute information from another routing protocol\n"
16458 FRR_IP_REDIST_HELP_STR_BGPD
16459 "Route map reference\n"
16460 "Pointer to route-map entries\n"
16461 "Metric for redistributed routes\n"
16462 "Default metric\n")
718e3744 16463{
585f1adc 16464 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16465 int idx_protocol = 1;
16466 int idx_word = 3;
16467 int idx_number = 5;
585f1adc
IR
16468 int type;
16469 uint32_t metric;
16470 struct bgp_redist *red;
16471 bool changed;
16472 struct route_map *route_map =
16473 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16474
16475 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16476 if (type < 0) {
16477 vty_out(vty, "%% Invalid route type\n");
16478 return CMD_WARNING_CONFIG_FAILED;
16479 }
16480 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 16481
585f1adc
IR
16482 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16483 changed =
16484 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16485 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16486 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16487}
16488
16489ALIAS_HIDDEN(
16490 bgp_redistribute_ipv4_rmap_metric,
16491 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16492 "redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16493 " route-map RMAP_NAME metric (0-4294967295)",
d62a17ae 16494 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16495 "Route map reference\n"
16496 "Pointer to route-map entries\n"
16497 "Metric for redistributed routes\n"
16498 "Default metric\n")
596c17ba 16499
585f1adc
IR
16500DEFUN (bgp_redistribute_ipv4_metric_rmap,
16501 bgp_redistribute_ipv4_metric_rmap_cmd,
70dd370f 16502 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16503 "Redistribute information from another routing protocol\n"
16504 FRR_IP_REDIST_HELP_STR_BGPD
16505 "Metric for redistributed routes\n"
16506 "Default metric\n"
16507 "Route map reference\n"
16508 "Pointer to route-map entries\n")
718e3744 16509{
585f1adc 16510 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16511 int idx_protocol = 1;
37a87b8f 16512 int idx_number = 3;
585f1adc
IR
16513 int idx_word = 5;
16514 int type;
16515 uint32_t metric;
16516 struct bgp_redist *red;
16517 bool changed;
16518 struct route_map *route_map =
16519 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16520
16521 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16522 if (type < 0) {
16523 vty_out(vty, "%% Invalid route type\n");
16524 return CMD_WARNING_CONFIG_FAILED;
16525 }
16526 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 16527
585f1adc
IR
16528 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16529 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16530 changed |=
16531 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16532 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16533}
16534
16535ALIAS_HIDDEN(
16536 bgp_redistribute_ipv4_metric_rmap,
16537 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16538 "redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16539 " metric (0-4294967295) route-map RMAP_NAME",
d62a17ae 16540 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16541 "Metric for redistributed routes\n"
16542 "Default metric\n"
16543 "Route map reference\n"
16544 "Pointer to route-map entries\n")
596c17ba 16545
585f1adc
IR
16546DEFUN (bgp_redistribute_ipv4_ospf,
16547 bgp_redistribute_ipv4_ospf_cmd,
16548 "redistribute <ospf|table> (1-65535)",
16549 "Redistribute information from another routing protocol\n"
16550 "Open Shortest Path First (OSPFv2)\n"
16551 "Non-main Kernel Routing Table\n"
16552 "Instance ID/Table ID\n")
7c8ff89e 16553{
585f1adc
IR
16554 VTY_DECLVAR_CONTEXT(bgp, bgp);
16555 int idx_ospf_table = 1;
d62a17ae 16556 int idx_number = 2;
585f1adc
IR
16557 unsigned short instance;
16558 unsigned short protocol;
7c8ff89e 16559
585f1adc 16560 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 16561
585f1adc
IR
16562 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16563 protocol = ZEBRA_ROUTE_OSPF;
16564 else
16565 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 16566
585f1adc
IR
16567 bgp_redist_add(bgp, AFI_IP, protocol, instance);
16568 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
16569}
16570
d62a17ae 16571ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16572 "redistribute <ospf|table> (1-65535)",
16573 "Redistribute information from another routing protocol\n"
16574 "Open Shortest Path First (OSPFv2)\n"
16575 "Non-main Kernel Routing Table\n"
16576 "Instance ID/Table ID\n")
596c17ba 16577
585f1adc
IR
16578DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16579 bgp_redistribute_ipv4_ospf_rmap_cmd,
70dd370f 16580 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
585f1adc
IR
16581 "Redistribute information from another routing protocol\n"
16582 "Open Shortest Path First (OSPFv2)\n"
16583 "Non-main Kernel Routing Table\n"
16584 "Instance ID/Table ID\n"
16585 "Route map reference\n"
16586 "Pointer to route-map entries\n")
7c8ff89e 16587{
585f1adc
IR
16588 VTY_DECLVAR_CONTEXT(bgp, bgp);
16589 int idx_ospf_table = 1;
d62a17ae 16590 int idx_number = 2;
16591 int idx_word = 4;
585f1adc
IR
16592 struct bgp_redist *red;
16593 unsigned short instance;
16594 int protocol;
16595 bool changed;
16596 struct route_map *route_map =
16597 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16598
16599 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16600 protocol = ZEBRA_ROUTE_OSPF;
16601 else
16602 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16603
585f1adc
IR
16604 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16605 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16606 changed =
16607 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16608 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16609}
16610
16611ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16612 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
70dd370f 16613 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
d62a17ae 16614 "Redistribute information from another routing protocol\n"
16615 "Open Shortest Path First (OSPFv2)\n"
16616 "Non-main Kernel Routing Table\n"
16617 "Instance ID/Table ID\n"
16618 "Route map reference\n"
16619 "Pointer to route-map entries\n")
596c17ba 16620
585f1adc
IR
16621DEFUN (bgp_redistribute_ipv4_ospf_metric,
16622 bgp_redistribute_ipv4_ospf_metric_cmd,
16623 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16624 "Redistribute information from another routing protocol\n"
16625 "Open Shortest Path First (OSPFv2)\n"
16626 "Non-main Kernel Routing Table\n"
16627 "Instance ID/Table ID\n"
16628 "Metric for redistributed routes\n"
16629 "Default metric\n")
7c8ff89e 16630{
585f1adc
IR
16631 VTY_DECLVAR_CONTEXT(bgp, bgp);
16632 int idx_ospf_table = 1;
d62a17ae 16633 int idx_number = 2;
16634 int idx_number_2 = 4;
585f1adc
IR
16635 uint32_t metric;
16636 struct bgp_redist *red;
16637 unsigned short instance;
16638 int protocol;
16639 bool changed;
16640
16641 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16642 protocol = ZEBRA_ROUTE_OSPF;
16643 else
16644 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16645
585f1adc
IR
16646 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16647 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16648
585f1adc
IR
16649 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16650 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16651 metric);
16652 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16653}
16654
16655ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16656 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16657 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16658 "Redistribute information from another routing protocol\n"
16659 "Open Shortest Path First (OSPFv2)\n"
16660 "Non-main Kernel Routing Table\n"
16661 "Instance ID/Table ID\n"
16662 "Metric for redistributed routes\n"
16663 "Default metric\n")
596c17ba 16664
585f1adc
IR
16665DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16666 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
70dd370f 16667 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16668 "Redistribute information from another routing protocol\n"
16669 "Open Shortest Path First (OSPFv2)\n"
16670 "Non-main Kernel Routing Table\n"
16671 "Instance ID/Table ID\n"
16672 "Route map reference\n"
16673 "Pointer to route-map entries\n"
16674 "Metric for redistributed routes\n"
16675 "Default metric\n")
7c8ff89e 16676{
585f1adc
IR
16677 VTY_DECLVAR_CONTEXT(bgp, bgp);
16678 int idx_ospf_table = 1;
d62a17ae 16679 int idx_number = 2;
16680 int idx_word = 4;
16681 int idx_number_2 = 6;
585f1adc
IR
16682 uint32_t metric;
16683 struct bgp_redist *red;
16684 unsigned short instance;
16685 int protocol;
16686 bool changed;
16687 struct route_map *route_map =
16688 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16689
16690 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16691 protocol = ZEBRA_ROUTE_OSPF;
16692 else
16693 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16694
585f1adc
IR
16695 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16696 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16697
585f1adc
IR
16698 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16699 changed =
16700 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16701 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16702 metric);
16703 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16704}
16705
16706ALIAS_HIDDEN(
16707 bgp_redistribute_ipv4_ospf_rmap_metric,
16708 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
70dd370f 16709 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
d62a17ae 16710 "Redistribute information from another routing protocol\n"
16711 "Open Shortest Path First (OSPFv2)\n"
16712 "Non-main Kernel Routing Table\n"
16713 "Instance ID/Table ID\n"
16714 "Route map reference\n"
16715 "Pointer to route-map entries\n"
16716 "Metric for redistributed routes\n"
16717 "Default metric\n")
596c17ba 16718
585f1adc
IR
16719DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16720 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
70dd370f 16721 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16722 "Redistribute information from another routing protocol\n"
16723 "Open Shortest Path First (OSPFv2)\n"
16724 "Non-main Kernel Routing Table\n"
16725 "Instance ID/Table ID\n"
16726 "Metric for redistributed routes\n"
16727 "Default metric\n"
16728 "Route map reference\n"
16729 "Pointer to route-map entries\n")
7c8ff89e 16730{
585f1adc
IR
16731 VTY_DECLVAR_CONTEXT(bgp, bgp);
16732 int idx_ospf_table = 1;
d62a17ae 16733 int idx_number = 2;
16734 int idx_number_2 = 4;
16735 int idx_word = 6;
585f1adc
IR
16736 uint32_t metric;
16737 struct bgp_redist *red;
16738 unsigned short instance;
16739 int protocol;
16740 bool changed;
16741 struct route_map *route_map =
16742 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16743
16744 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16745 protocol = ZEBRA_ROUTE_OSPF;
16746 else
16747 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16748
585f1adc
IR
16749 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16750 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16751
585f1adc
IR
16752 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16753 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16754 metric);
16755 changed |=
16756 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16757 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16758}
16759
16760ALIAS_HIDDEN(
16761 bgp_redistribute_ipv4_ospf_metric_rmap,
16762 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
70dd370f 16763 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
d62a17ae 16764 "Redistribute information from another routing protocol\n"
16765 "Open Shortest Path First (OSPFv2)\n"
16766 "Non-main Kernel Routing Table\n"
16767 "Instance ID/Table ID\n"
16768 "Metric for redistributed routes\n"
16769 "Default metric\n"
16770 "Route map reference\n"
16771 "Pointer to route-map entries\n")
596c17ba 16772
585f1adc
IR
16773DEFUN (no_bgp_redistribute_ipv4_ospf,
16774 no_bgp_redistribute_ipv4_ospf_cmd,
70dd370f 16775 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16776 NO_STR
16777 "Redistribute information from another routing protocol\n"
16778 "Open Shortest Path First (OSPFv2)\n"
16779 "Non-main Kernel Routing Table\n"
16780 "Instance ID/Table ID\n"
16781 "Metric for redistributed routes\n"
16782 "Default metric\n"
16783 "Route map reference\n"
16784 "Pointer to route-map entries\n")
7c8ff89e 16785{
585f1adc
IR
16786 VTY_DECLVAR_CONTEXT(bgp, bgp);
16787 int idx_ospf_table = 2;
d62a17ae 16788 int idx_number = 3;
585f1adc
IR
16789 unsigned short instance;
16790 int protocol;
37a87b8f 16791
585f1adc
IR
16792 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16793 protocol = ZEBRA_ROUTE_OSPF;
16794 else
16795 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16796
585f1adc
IR
16797 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16798 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
d62a17ae 16799}
16800
16801ALIAS_HIDDEN(
16802 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
70dd370f 16803 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
d62a17ae 16804 NO_STR
16805 "Redistribute information from another routing protocol\n"
16806 "Open Shortest Path First (OSPFv2)\n"
16807 "Non-main Kernel Routing Table\n"
16808 "Instance ID/Table ID\n"
16809 "Metric for redistributed routes\n"
16810 "Default metric\n"
16811 "Route map reference\n"
16812 "Pointer to route-map entries\n")
596c17ba 16813
585f1adc
IR
16814DEFUN (no_bgp_redistribute_ipv4,
16815 no_bgp_redistribute_ipv4_cmd,
70dd370f 16816 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16817 NO_STR
16818 "Redistribute information from another routing protocol\n"
16819 FRR_IP_REDIST_HELP_STR_BGPD
16820 "Metric for redistributed routes\n"
16821 "Default metric\n"
16822 "Route map reference\n"
16823 "Pointer to route-map entries\n")
718e3744 16824{
585f1adc 16825 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16826 int idx_protocol = 2;
585f1adc 16827 int type;
d62a17ae 16828
585f1adc
IR
16829 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16830 if (type < 0) {
16831 vty_out(vty, "%% Invalid route type\n");
16832 return CMD_WARNING_CONFIG_FAILED;
16833 }
16834 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
d62a17ae 16835}
16836
16837ALIAS_HIDDEN(
16838 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16839 "no redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16840 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
d62a17ae 16841 NO_STR
16842 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16843 "Metric for redistributed routes\n"
16844 "Default metric\n"
16845 "Route map reference\n"
16846 "Pointer to route-map entries\n")
596c17ba 16847
585f1adc
IR
16848DEFUN (bgp_redistribute_ipv6,
16849 bgp_redistribute_ipv6_cmd,
16850 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16851 "Redistribute information from another routing protocol\n"
16852 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 16853{
585f1adc 16854 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16855 int idx_protocol = 1;
585f1adc 16856 int type;
718e3744 16857
585f1adc
IR
16858 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16859 if (type < 0) {
16860 vty_out(vty, "%% Invalid route type\n");
16861 return CMD_WARNING_CONFIG_FAILED;
16862 }
718e3744 16863
585f1adc
IR
16864 bgp_redist_add(bgp, AFI_IP6, type, 0);
16865 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 16866}
16867
585f1adc
IR
16868DEFUN (bgp_redistribute_ipv6_rmap,
16869 bgp_redistribute_ipv6_rmap_cmd,
70dd370f 16870 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
585f1adc
IR
16871 "Redistribute information from another routing protocol\n"
16872 FRR_IP6_REDIST_HELP_STR_BGPD
16873 "Route map reference\n"
16874 "Pointer to route-map entries\n")
718e3744 16875{
585f1adc 16876 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16877 int idx_protocol = 1;
16878 int idx_word = 3;
585f1adc
IR
16879 int type;
16880 struct bgp_redist *red;
16881 bool changed;
16882 struct route_map *route_map =
16883 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16884
16885 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16886 if (type < 0) {
16887 vty_out(vty, "%% Invalid route type\n");
16888 return CMD_WARNING_CONFIG_FAILED;
16889 }
37a87b8f 16890
585f1adc
IR
16891 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16892 changed =
16893 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16894 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16895}
16896
585f1adc 16897DEFUN (bgp_redistribute_ipv6_metric,
718e3744 16898 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 16899 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 16900 "Redistribute information from another routing protocol\n"
ab0181ee 16901 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 16902 "Metric for redistributed routes\n"
16903 "Default metric\n")
16904{
585f1adc 16905 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16906 int idx_protocol = 1;
16907 int idx_number = 3;
585f1adc
IR
16908 int type;
16909 uint32_t metric;
16910 struct bgp_redist *red;
16911 bool changed;
16912
16913 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16914 if (type < 0) {
16915 vty_out(vty, "%% Invalid route type\n");
16916 return CMD_WARNING_CONFIG_FAILED;
16917 }
16918 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16919
585f1adc
IR
16920 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16921 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16922 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16923}
16924
585f1adc
IR
16925DEFUN (bgp_redistribute_ipv6_rmap_metric,
16926 bgp_redistribute_ipv6_rmap_metric_cmd,
70dd370f 16927 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16928 "Redistribute information from another routing protocol\n"
16929 FRR_IP6_REDIST_HELP_STR_BGPD
16930 "Route map reference\n"
16931 "Pointer to route-map entries\n"
16932 "Metric for redistributed routes\n"
16933 "Default metric\n")
718e3744 16934{
585f1adc 16935 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16936 int idx_protocol = 1;
16937 int idx_word = 3;
16938 int idx_number = 5;
585f1adc
IR
16939 int type;
16940 uint32_t metric;
16941 struct bgp_redist *red;
16942 bool changed;
16943 struct route_map *route_map =
16944 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16945
16946 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16947 if (type < 0) {
16948 vty_out(vty, "%% Invalid route type\n");
16949 return CMD_WARNING_CONFIG_FAILED;
16950 }
16951 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16952
585f1adc
IR
16953 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16954 changed =
16955 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16956 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16957 metric);
16958 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16959}
16960
585f1adc
IR
16961DEFUN (bgp_redistribute_ipv6_metric_rmap,
16962 bgp_redistribute_ipv6_metric_rmap_cmd,
70dd370f 16963 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16964 "Redistribute information from another routing protocol\n"
16965 FRR_IP6_REDIST_HELP_STR_BGPD
16966 "Metric for redistributed routes\n"
16967 "Default metric\n"
16968 "Route map reference\n"
16969 "Pointer to route-map entries\n")
718e3744 16970{
585f1adc 16971 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16972 int idx_protocol = 1;
37a87b8f 16973 int idx_number = 3;
585f1adc
IR
16974 int idx_word = 5;
16975 int type;
16976 uint32_t metric;
16977 struct bgp_redist *red;
16978 bool changed;
16979 struct route_map *route_map =
16980 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16981
16982 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16983 if (type < 0) {
16984 vty_out(vty, "%% Invalid route type\n");
16985 return CMD_WARNING_CONFIG_FAILED;
16986 }
16987 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16988
585f1adc
IR
16989 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16990 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16991 metric);
16992 changed |=
16993 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16994 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16995}
16996
585f1adc
IR
16997DEFUN (no_bgp_redistribute_ipv6,
16998 no_bgp_redistribute_ipv6_cmd,
70dd370f 16999 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
17000 NO_STR
17001 "Redistribute information from another routing protocol\n"
17002 FRR_IP6_REDIST_HELP_STR_BGPD
17003 "Metric for redistributed routes\n"
17004 "Default metric\n"
17005 "Route map reference\n"
17006 "Pointer to route-map entries\n")
718e3744 17007{
585f1adc 17008 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 17009 int idx_protocol = 2;
585f1adc 17010 int type;
37a87b8f 17011
585f1adc
IR
17012 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
17013 if (type < 0) {
17014 vty_out(vty, "%% Invalid route type\n");
17015 return CMD_WARNING_CONFIG_FAILED;
17016 }
718e3744 17017
585f1adc 17018 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
d62a17ae 17019}
17020
4ab46701
AR
17021/* Neighbor update tcp-mss. */
17022static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
17023 const char *tcp_mss_str)
17024{
17025 struct peer *peer;
17026 uint32_t tcp_mss_val = 0;
17027
17028 peer = peer_and_group_lookup_vty(vty, peer_str);
17029 if (!peer)
17030 return CMD_WARNING_CONFIG_FAILED;
17031
17032 if (tcp_mss_str) {
17033 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
17034 peer_tcp_mss_set(peer, tcp_mss_val);
17035 } else {
17036 peer_tcp_mss_unset(peer);
17037 }
17038
17039 return CMD_SUCCESS;
17040}
17041
17042DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
17043 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
17044 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
17045 "TCP max segment size\n"
17046 "TCP MSS value\n")
17047{
17048 int peer_index = 1;
17049 int mss_index = 3;
17050
17051 vty_out(vty,
17052 " Warning: Reset BGP session for tcp-mss value to take effect\n");
17053 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
17054 argv[mss_index]->arg);
17055}
17056
17057DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
17058 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
17059 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
17060 "TCP max segment size\n"
17061 "TCP MSS value\n")
17062{
17063 int peer_index = 2;
17064
17065 vty_out(vty,
17066 " Warning: Reset BGP session for tcp-mss value to take effect\n");
17067 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
17068}
17069
a486300b
PG
17070DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
17071 "[no$no] bgp retain route-target all",
17072 NO_STR BGP_STR
17073 "Retain BGP updates\n"
17074 "Retain BGP updates based on route-target values\n"
17075 "Retain all BGP updates\n")
17076{
17077 bool check;
17078 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
17079
17080 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
17081 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
17082 if (check != !no) {
17083 if (!no)
17084 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
17085 [bgp_node_safi(vty)],
17086 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
17087 else
17088 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
17089 [bgp_node_safi(vty)],
17090 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
17091 /* trigger a flush to re-sync with ADJ-RIB-in */
17092 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
17093 clear_all, BGP_CLEAR_SOFT_IN, NULL);
17094 }
17095 return CMD_SUCCESS;
17096}
17097
dd65f45e
DL
17098static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
17099 afi_t afi, safi_t safi)
d62a17ae 17100{
17101 int i;
17102
17103 /* Unicast redistribution only. */
17104 if (safi != SAFI_UNICAST)
2b791107 17105 return;
d62a17ae 17106
17107 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
17108 /* Redistribute BGP does not make sense. */
17109 if (i != ZEBRA_ROUTE_BGP) {
17110 struct list *red_list;
17111 struct listnode *node;
17112 struct bgp_redist *red;
17113
17114 red_list = bgp->redist[afi][i];
17115 if (!red_list)
17116 continue;
17117
17118 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 17119 /* "redistribute" configuration. */
17120 vty_out(vty, " redistribute %s",
17121 zebra_route_string(i));
17122 if (red->instance)
17123 vty_out(vty, " %d", red->instance);
17124 if (red->redist_metric_flag)
17125 vty_out(vty, " metric %u",
17126 red->redist_metric);
17127 if (red->rmap.name)
17128 vty_out(vty, " route-map %s",
17129 red->rmap.name);
17130 vty_out(vty, "\n");
17131 }
17132 }
17133 }
718e3744 17134}
6b0655a2 17135
dd65f45e
DL
17136/* peer-group helpers for config-write */
17137
234f6fd4 17138bool peergroup_flag_check(struct peer *peer, uint64_t flag)
dd65f45e
DL
17139{
17140 if (!peer_group_active(peer)) {
17141 if (CHECK_FLAG(peer->flags_invert, flag))
17142 return !CHECK_FLAG(peer->flags, flag);
17143 else
17144 return !!CHECK_FLAG(peer->flags, flag);
17145 }
17146
17147 return !!CHECK_FLAG(peer->flags_override, flag);
17148}
17149
17150static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
da5e1a58 17151 uint64_t flag)
dd65f45e
DL
17152{
17153 if (!peer_group_active(peer)) {
17154 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
17155 return !peer_af_flag_check(peer, afi, safi, flag);
17156 else
17157 return !!peer_af_flag_check(peer, afi, safi, flag);
17158 }
17159
17160 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
17161}
17162
17163static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
17164 uint8_t type, int direct)
17165{
17166 struct bgp_filter *filter;
17167
17168 if (peer_group_active(peer))
17169 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
17170 type);
17171
17172 filter = &peer->filter[afi][safi];
17173 switch (type) {
17174 case PEER_FT_DISTRIBUTE_LIST:
17175 return !!(filter->dlist[direct].name);
17176 case PEER_FT_FILTER_LIST:
17177 return !!(filter->aslist[direct].name);
17178 case PEER_FT_PREFIX_LIST:
17179 return !!(filter->plist[direct].name);
17180 case PEER_FT_ROUTE_MAP:
17181 return !!(filter->map[direct].name);
17182 case PEER_FT_UNSUPPRESS_MAP:
17183 return !!(filter->usmap.name);
7f7940e6
MK
17184 case PEER_FT_ADVERTISE_MAP:
17185 return !!(filter->advmap.aname
17186 && ((filter->advmap.condition == direct)
17187 && filter->advmap.cname));
dd65f45e
DL
17188 default:
17189 return false;
17190 }
17191}
17192
17193/* Return true if the addpath type is set for peer and different from
17194 * peer-group.
17195 */
3dc339cd
DA
17196static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
17197 safi_t safi)
dd65f45e
DL
17198{
17199 enum bgp_addpath_strat type, g_type;
17200
17201 type = peer->addpath_type[afi][safi];
17202
17203 if (type != BGP_ADDPATH_NONE) {
17204 if (peer_group_active(peer)) {
17205 g_type = peer->group->conf->addpath_type[afi][safi];
17206
17207 if (type != g_type)
3dc339cd 17208 return true;
dd65f45e 17209 else
3dc339cd 17210 return false;
dd65f45e
DL
17211 }
17212
3dc339cd 17213 return true;
dd65f45e
DL
17214 }
17215
3dc339cd 17216 return false;
dd65f45e
DL
17217}
17218
b9c7bc5a 17219/* This is part of the address-family block (unicast only) */
dd65f45e 17220static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
17221 afi_t afi)
17222{
b9c7bc5a 17223 int indent = 2;
53970de3 17224 uint32_t tovpn_sid_index = 0;
ddb5b488 17225
8a066a70 17226 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
17227 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17228 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
17229 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
17230 bgp->vpn_policy[afi]
bb4f6190 17231 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
17232 else
17233 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
17234 bgp->vpn_policy[afi]
17235 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17236 }
12a844a5
DS
17237 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17238 BGP_CONFIG_VRF_TO_VRF_IMPORT)
17239 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17240 BGP_CONFIG_VRF_TO_VRF_EXPORT))
17241 return;
17242
e70e9f8e
PZ
17243 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17244 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
17245
17246 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
17247
17248 } else {
17249 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
17250 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
17251 bgp->vpn_policy[afi].tovpn_label);
17252 }
ddb5b488 17253 }
53970de3
RS
17254
17255 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
17256 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17257 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
17258 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
17259 } else if (tovpn_sid_index != 0) {
17260 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
17261 tovpn_sid_index);
17262 }
17263
c4f64ea9 17264 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
fa566a94
PG
17265 vty_out(vty, "%*srd vpn export %s\n", indent, "",
17266 bgp->vpn_policy[afi].tovpn_rd_pretty);
c4f64ea9 17267
ddb5b488
PZ
17268 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17269 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
17270
17271 char buf[PREFIX_STRLEN];
17272 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
17273 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
17274 sizeof(buf))) {
17275
b9c7bc5a
PZ
17276 vty_out(vty, "%*snexthop vpn export %s\n",
17277 indent, "", buf);
ddb5b488
PZ
17278 }
17279 }
17280 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
17281 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
17282 && ecommunity_cmp(
17283 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17284 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
17285
17286 char *b = ecommunity_ecom2str(
17287 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17288 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17289 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
17290 XFREE(MTYPE_ECOMMUNITY_STR, b);
17291 } else {
17292 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
17293 char *b = ecommunity_ecom2str(
17294 bgp->vpn_policy[afi]
17295 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17296 ECOMMUNITY_FORMAT_ROUTE_MAP,
17297 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17298 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
17299 XFREE(MTYPE_ECOMMUNITY_STR, b);
17300 }
17301 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
17302 char *b = ecommunity_ecom2str(
17303 bgp->vpn_policy[afi]
17304 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17305 ECOMMUNITY_FORMAT_ROUTE_MAP,
17306 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17307 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
17308 XFREE(MTYPE_ECOMMUNITY_STR, b);
17309 }
17310 }
bb4f6190
DS
17311
17312 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 17313 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
17314 bgp->vpn_policy[afi]
17315 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 17316
301ad80a
PG
17317 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
17318 char *b = ecommunity_ecom2str(
17319 bgp->vpn_policy[afi]
17320 .import_redirect_rtlist,
17321 ECOMMUNITY_FORMAT_ROUTE_MAP,
17322 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 17323
9a659715
PG
17324 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
17325 != ECOMMUNITY_SIZE)
c6423c31 17326 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
17327 indent, "", b);
17328 else
17329 vty_out(vty, "%*srt redirect import %s\n",
17330 indent, "", b);
301ad80a
PG
17331 XFREE(MTYPE_ECOMMUNITY_STR, b);
17332 }
ddb5b488
PZ
17333}
17334
dd65f45e
DL
17335static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
17336 afi_t afi, safi_t safi)
17337{
17338 struct bgp_filter *filter;
17339 char *addr;
17340
17341 addr = peer->host;
17342 filter = &peer->filter[afi][safi];
17343
17344 /* distribute-list. */
17345 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17346 FILTER_IN))
17347 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
17348 filter->dlist[FILTER_IN].name);
17349
17350 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17351 FILTER_OUT))
17352 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17353 filter->dlist[FILTER_OUT].name);
17354
17355 /* prefix-list. */
17356 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17357 FILTER_IN))
17358 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17359 filter->plist[FILTER_IN].name);
17360
17361 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17362 FILTER_OUT))
17363 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17364 filter->plist[FILTER_OUT].name);
17365
17366 /* route-map. */
17367 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17368 vty_out(vty, " neighbor %s route-map %s in\n", addr,
17369 filter->map[RMAP_IN].name);
17370
17371 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17372 RMAP_OUT))
17373 vty_out(vty, " neighbor %s route-map %s out\n", addr,
17374 filter->map[RMAP_OUT].name);
17375
17376 /* unsuppress-map */
17377 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17378 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17379 filter->usmap.name);
17380
7f7940e6
MK
17381 /* advertise-map : always applied in OUT direction*/
17382 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17383 CONDITION_NON_EXIST))
17384 vty_out(vty,
17385 " neighbor %s advertise-map %s non-exist-map %s\n",
17386 addr, filter->advmap.aname, filter->advmap.cname);
17387
17388 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17389 CONDITION_EXIST))
17390 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17391 addr, filter->advmap.aname, filter->advmap.cname);
17392
dd65f45e
DL
17393 /* filter-list. */
17394 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17395 FILTER_IN))
17396 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17397 filter->aslist[FILTER_IN].name);
17398
17399 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17400 FILTER_OUT))
17401 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17402 filter->aslist[FILTER_OUT].name);
17403}
17404
17405/* BGP peer configuration display function. */
17406static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17407 struct peer *peer)
17408{
17409 struct peer *g_peer = NULL;
dd65f45e
DL
17410 char *addr;
17411 int if_pg_printed = false;
17412 int if_ras_printed = false;
17413
17414 /* Skip dynamic neighbors. */
17415 if (peer_dynamic_neighbor(peer))
17416 return;
17417
17418 if (peer->conf_if)
17419 addr = peer->conf_if;
17420 else
17421 addr = peer->host;
17422
17423 /************************************
17424 ****** Global to the neighbor ******
17425 ************************************/
17426 if (peer->conf_if) {
17427 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17428 vty_out(vty, " neighbor %s interface v6only", addr);
17429 else
17430 vty_out(vty, " neighbor %s interface", addr);
17431
17432 if (peer_group_active(peer)) {
17433 vty_out(vty, " peer-group %s", peer->group->name);
17434 if_pg_printed = true;
17435 } else if (peer->as_type == AS_SPECIFIED) {
de76ed8a 17436 vty_out(vty, " remote-as %s", peer->as_pretty);
dd65f45e
DL
17437 if_ras_printed = true;
17438 } else if (peer->as_type == AS_INTERNAL) {
17439 vty_out(vty, " remote-as internal");
17440 if_ras_printed = true;
17441 } else if (peer->as_type == AS_EXTERNAL) {
17442 vty_out(vty, " remote-as external");
17443 if_ras_printed = true;
17444 }
17445
17446 vty_out(vty, "\n");
17447 }
17448
17449 /* remote-as and peer-group */
17450 /* peer is a member of a peer-group */
17451 if (peer_group_active(peer)) {
17452 g_peer = peer->group->conf;
17453
17454 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17455 if (peer->as_type == AS_SPECIFIED) {
de76ed8a
PG
17456 vty_out(vty, " neighbor %s remote-as %s\n",
17457 addr, peer->as_pretty);
dd65f45e
DL
17458 } else if (peer->as_type == AS_INTERNAL) {
17459 vty_out(vty,
17460 " neighbor %s remote-as internal\n",
17461 addr);
17462 } else if (peer->as_type == AS_EXTERNAL) {
17463 vty_out(vty,
17464 " neighbor %s remote-as external\n",
17465 addr);
17466 }
17467 }
17468
17469 /* For swpX peers we displayed the peer-group
17470 * via 'neighbor swpX interface peer-group PGNAME' */
17471 if (!if_pg_printed)
17472 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17473 peer->group->name);
17474 }
17475
17476 /* peer is NOT a member of a peer-group */
17477 else {
17478 /* peer is a peer-group, declare the peer-group */
17479 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17480 vty_out(vty, " neighbor %s peer-group\n", addr);
17481 }
17482
17483 if (!if_ras_printed) {
17484 if (peer->as_type == AS_SPECIFIED) {
de76ed8a
PG
17485 vty_out(vty, " neighbor %s remote-as %s\n",
17486 addr, peer->as_pretty);
dd65f45e
DL
17487 } else if (peer->as_type == AS_INTERNAL) {
17488 vty_out(vty,
17489 " neighbor %s remote-as internal\n",
17490 addr);
17491 } else if (peer->as_type == AS_EXTERNAL) {
17492 vty_out(vty,
17493 " neighbor %s remote-as external\n",
17494 addr);
17495 }
17496 }
17497 }
17498
17499 /* local-as */
17500 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
de76ed8a
PG
17501 vty_out(vty, " neighbor %s local-as %s", addr,
17502 peer->change_local_as_pretty);
dd65f45e
DL
17503 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17504 vty_out(vty, " no-prepend");
17505 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17506 vty_out(vty, " replace-as");
17507 vty_out(vty, "\n");
17508 }
17509
17510 /* description */
17511 if (peer->desc) {
17512 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17513 }
17514
17515 /* shutdown */
17516 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17517 if (peer->tx_shutdown_message)
17518 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17519 peer->tx_shutdown_message);
17520 else
17521 vty_out(vty, " neighbor %s shutdown\n", addr);
17522 }
17523
8336c896
DA
17524 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17525 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17526 peer->rtt_expected, peer->rtt_keepalive_conf);
17527
dd65f45e 17528 /* bfd */
21bfce98
RZ
17529 if (peer->bfd_config)
17530 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
17531
17532 /* password */
17533 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17534 vty_out(vty, " neighbor %s password %s\n", addr,
17535 peer->password);
17536
17537 /* neighbor solo */
17538 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17539 if (!peer_group_active(peer)) {
17540 vty_out(vty, " neighbor %s solo\n", addr);
17541 }
17542 }
17543
17544 /* BGP port */
17545 if (peer->port != BGP_PORT_DEFAULT) {
17546 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17547 }
17548
17549 /* Local interface name */
17550 if (peer->ifname) {
17551 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17552 }
17553
4ab46701
AR
17554 /* TCP max segment size */
17555 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17556 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17557
dd65f45e
DL
17558 /* passive */
17559 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17560 vty_out(vty, " neighbor %s passive\n", addr);
17561
17562 /* ebgp-multihop */
17563 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
17564 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17565 && peer->ttl == MAXTTL)) {
dd65f45e
DL
17566 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17567 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17568 peer->ttl);
17569 }
17570 }
17571
97a52c82
DA
17572 /* aigp */
17573 if (peergroup_flag_check(peer, PEER_FLAG_AIGP))
17574 vty_out(vty, " neighbor %s aigp\n", addr);
17575
4f770cf1
DA
17576 /* graceful-shutdown */
17577 if (peergroup_flag_check(peer, PEER_FLAG_GRACEFUL_SHUTDOWN))
17578 vty_out(vty, " neighbor %s graceful-shutdown\n", addr);
17579
d864dd9e 17580 /* role */
7dddd1f7
DA
17581 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17582 peer->local_role != ROLE_UNDEFINED)
d864dd9e 17583 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
8f2d6021 17584 bgp_get_name_by_role(peer->local_role),
7dddd1f7 17585 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
d864dd9e
EB
17586 ? " strict-mode"
17587 : "");
d864dd9e 17588
dd65f45e 17589 /* ttl-security hops */
e2521429 17590 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
17591 if (!peer_group_active(peer)
17592 || g_peer->gtsm_hops != peer->gtsm_hops) {
17593 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17594 addr, peer->gtsm_hops);
17595 }
17596 }
17597
17598 /* disable-connected-check */
17599 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17600 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17601
27aa23a4
DA
17602 /* link-bw-encoding-ieee */
17603 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17604 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17605 addr);
17606
d08c0c80
DA
17607 /* extended-optional-parameters */
17608 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17609 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17610 addr);
17611
dd65f45e
DL
17612 /* enforce-first-as */
17613 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17614 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17615
17616 /* update-source */
17617 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17618 if (peer->update_source)
47e12884
DA
17619 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17620 peer->update_source);
dd65f45e
DL
17621 else if (peer->update_if)
17622 vty_out(vty, " neighbor %s update-source %s\n", addr,
17623 peer->update_if);
17624 }
17625
17626 /* advertisement-interval */
17627 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17628 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17629 peer->routeadv);
17630
17631 /* timers */
17632 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17633 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17634 peer->keepalive, peer->holdtime);
17635
17636 /* timers connect */
17637 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17638 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17639 peer->connect);
5d5393b9
DL
17640 /* need special-case handling for changed default values due to
17641 * config profile / version (because there is no "timers bgp connect"
17642 * command, we need to save this per-peer :/)
17643 */
17644 else if (!peer_group_active(peer) && !peer->connect &&
17645 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17646 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17647 peer->bgp->default_connect_retry);
dd65f45e 17648
d43114f3
DS
17649 /* timers delayopen */
17650 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17651 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17652 peer->delayopen);
17653 /* Save config even though flag is not set if default values have been
17654 * changed
17655 */
17656 else if (!peer_group_active(peer) && !peer->delayopen
17657 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17658 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17659 peer->bgp->default_delayopen);
17660
dd65f45e
DL
17661 /* capability dynamic */
17662 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17663 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17664
17665 /* capability extended-nexthop */
17666 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
8e89adc1
DS
17667 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17668 !peer->conf_if)
843770f6
DA
17669 vty_out(vty,
17670 " no neighbor %s capability extended-nexthop\n",
17671 addr);
17672 else if (!peer->conf_if)
17673 vty_out(vty,
17674 " neighbor %s capability extended-nexthop\n",
17675 addr);
dd65f45e
DL
17676 }
17677
234f6fd4
DA
17678 /* capability software-version */
17679 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_SOFT_VERSION))
17680 vty_out(vty, " neighbor %s capability software-version\n",
17681 addr);
17682
dd65f45e
DL
17683 /* dont-capability-negotiation */
17684 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17685 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17686
17687 /* override-capability */
17688 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17689 vty_out(vty, " neighbor %s override-capability\n", addr);
17690
17691 /* strict-capability-match */
17692 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17693 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17694
17695 /* Sender side AS path loop detection. */
17696 if (peer->as_path_loop_detection)
17697 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17698 addr);
cfd47646 17699
a5c6a9b1
DA
17700 /* path-attribute discard */
17701 char discard_attrs_str[BUFSIZ] = {0};
17702 bool discard_attrs = bgp_path_attribute_discard(
17703 peer, discard_attrs_str, sizeof(discard_attrs_str));
17704
17705 if (discard_attrs)
17706 vty_out(vty, " neighbor %s path-attribute discard %s\n", addr,
17707 discard_attrs_str);
17708
e2863b4f
DA
17709 /* path-attribute treat-as-withdraw */
17710 char withdraw_attrs_str[BUFSIZ] = {0};
17711 bool withdraw_attrs = bgp_path_attribute_treat_as_withdraw(
17712 peer, withdraw_attrs_str, sizeof(withdraw_attrs_str));
17713
17714 if (withdraw_attrs)
17715 vty_out(vty,
17716 " neighbor %s path-attribute treat-as-withdraw %s\n",
17717 addr, withdraw_attrs_str);
17718
cfd47646 17719 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17720 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 17721
17722 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17723 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 17724 vty_out(vty,
17725 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
17726 } else if (CHECK_FLAG(
17727 peer->peer_gr_new_status_flag,
17728 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 17729 vty_out(vty,
17730 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
17731 } else if (
17732 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17733 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17734 && !(CHECK_FLAG(
17735 peer->peer_gr_new_status_flag,
17736 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17737 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17738 addr);
cfd47646 17739 }
17740 }
dd65f45e
DL
17741}
17742
17743/* BGP peer configuration display function. */
17744static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17745 struct peer *peer, afi_t afi, safi_t safi)
17746{
17747 struct peer *g_peer = NULL;
17748 char *addr;
17749 bool flag_scomm, flag_secomm, flag_slcomm;
17750
17751 /* Skip dynamic neighbors. */
17752 if (peer_dynamic_neighbor(peer))
17753 return;
17754
17755 if (peer->conf_if)
17756 addr = peer->conf_if;
17757 else
17758 addr = peer->host;
17759
17760 /************************************
17761 ****** Per AF to the neighbor ******
17762 ************************************/
17763 if (peer_group_active(peer)) {
17764 g_peer = peer->group->conf;
17765
17766 /* If the peer-group is active but peer is not, print a 'no
17767 * activate' */
17768 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17769 vty_out(vty, " no neighbor %s activate\n", addr);
17770 }
17771
17772 /* If the peer-group is not active but peer is, print an
17773 'activate' */
17774 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17775 vty_out(vty, " neighbor %s activate\n", addr);
17776 }
17777 } else {
17778 if (peer->afc[afi][safi]) {
38d11af5
TA
17779 if (safi == SAFI_ENCAP)
17780 vty_out(vty, " neighbor %s activate\n", addr);
17781 else if (!bgp->default_af[afi][safi])
dd65f45e
DL
17782 vty_out(vty, " neighbor %s activate\n", addr);
17783 } else {
38d11af5
TA
17784 if (bgp->default_af[afi][safi])
17785 vty_out(vty, " no neighbor %s activate\n",
17786 addr);
dd65f45e
DL
17787 }
17788 }
17789
17790 /* addpath TX knobs */
17791 if (peergroup_af_addpath_check(peer, afi, safi)) {
17792 switch (peer->addpath_type[afi][safi]) {
17793 case BGP_ADDPATH_ALL:
17794 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17795 addr);
17796 break;
17797 case BGP_ADDPATH_BEST_PER_AS:
17798 vty_out(vty,
17799 " neighbor %s addpath-tx-bestpath-per-AS\n",
17800 addr);
17801 break;
17802 case BGP_ADDPATH_MAX:
17803 case BGP_ADDPATH_NONE:
17804 break;
17805 }
17806 }
17807
7c0e4312
DA
17808 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17809 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17810
dd65f45e
DL
17811 /* ORF capability. */
17812 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17813 || peergroup_af_flag_check(peer, afi, safi,
17814 PEER_FLAG_ORF_PREFIX_RM)) {
17815 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17816
17817 if (peergroup_af_flag_check(peer, afi, safi,
17818 PEER_FLAG_ORF_PREFIX_SM)
17819 && peergroup_af_flag_check(peer, afi, safi,
17820 PEER_FLAG_ORF_PREFIX_RM))
17821 vty_out(vty, " both");
17822 else if (peergroup_af_flag_check(peer, afi, safi,
17823 PEER_FLAG_ORF_PREFIX_SM))
17824 vty_out(vty, " send");
17825 else
17826 vty_out(vty, " receive");
17827 vty_out(vty, "\n");
17828 }
17829
dd65f45e
DL
17830 /* Route reflector client. */
17831 if (peergroup_af_flag_check(peer, afi, safi,
17832 PEER_FLAG_REFLECTOR_CLIENT)) {
17833 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17834 }
17835
17836 /* next-hop-self force */
17837 if (peergroup_af_flag_check(peer, afi, safi,
17838 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17839 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17840 }
17841
17842 /* next-hop-self */
17843 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17844 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17845 }
17846
17847 /* remove-private-AS */
17848 if (peergroup_af_flag_check(peer, afi, safi,
17849 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17850 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17851 addr);
17852 }
17853
17854 else if (peergroup_af_flag_check(peer, afi, safi,
17855 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17856 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17857 addr);
17858 }
17859
17860 else if (peergroup_af_flag_check(peer, afi, safi,
17861 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17862 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17863 }
17864
17865 else if (peergroup_af_flag_check(peer, afi, safi,
17866 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17867 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17868 }
17869
17870 /* as-override */
17871 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17872 vty_out(vty, " neighbor %s as-override\n", addr);
17873 }
17874
17875 /* send-community print. */
17876 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17877 PEER_FLAG_SEND_COMMUNITY);
17878 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17879 PEER_FLAG_SEND_EXT_COMMUNITY);
17880 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17881 PEER_FLAG_SEND_LARGE_COMMUNITY);
17882
17883 if (flag_scomm && flag_secomm && flag_slcomm) {
17884 vty_out(vty, " no neighbor %s send-community all\n", addr);
17885 } else {
17886 if (flag_scomm)
17887 vty_out(vty, " no neighbor %s send-community\n", addr);
17888 if (flag_secomm)
17889 vty_out(vty,
17890 " no neighbor %s send-community extended\n",
17891 addr);
17892
17893 if (flag_slcomm)
17894 vty_out(vty, " no neighbor %s send-community large\n",
17895 addr);
17896 }
17897
17898 /* Default information */
17899 if (peergroup_af_flag_check(peer, afi, safi,
17900 PEER_FLAG_DEFAULT_ORIGINATE)) {
17901 vty_out(vty, " neighbor %s default-originate", addr);
17902
17903 if (peer->default_rmap[afi][safi].name)
17904 vty_out(vty, " route-map %s",
17905 peer->default_rmap[afi][safi].name);
17906
17907 vty_out(vty, "\n");
17908 }
17909
17910 /* Soft reconfiguration inbound. */
17911 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17912 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17913 addr);
17914 }
17915
17916 /* maximum-prefix. */
17917 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 17918 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
17919 peer->pmax[afi][safi]);
17920
17921 if (peer->pmax_threshold[afi][safi]
17922 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17923 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17924 if (peer_af_flag_check(peer, afi, safi,
17925 PEER_FLAG_MAX_PREFIX_WARNING))
17926 vty_out(vty, " warning-only");
17927 if (peer->pmax_restart[afi][safi])
17928 vty_out(vty, " restart %u",
17929 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
17930 if (peer_af_flag_check(peer, afi, safi,
17931 PEER_FLAG_MAX_PREFIX_FORCE))
17932 vty_out(vty, " force");
dd65f45e
DL
17933
17934 vty_out(vty, "\n");
17935 }
17936
fde246e8
DA
17937 /* maximum-prefix-out */
17938 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 17939 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
17940 addr, peer->pmax_out[afi][safi]);
17941
dd65f45e
DL
17942 /* Route server client. */
17943 if (peergroup_af_flag_check(peer, afi, safi,
17944 PEER_FLAG_RSERVER_CLIENT)) {
17945 vty_out(vty, " neighbor %s route-server-client\n", addr);
17946 }
17947
17948 /* Nexthop-local unchanged. */
17949 if (peergroup_af_flag_check(peer, afi, safi,
17950 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17951 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17952 }
17953
17954 /* allowas-in <1-10> */
17955 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17956 if (peer_af_flag_check(peer, afi, safi,
17957 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17958 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17959 } else if (peer->allowas_in[afi][safi] == 3) {
17960 vty_out(vty, " neighbor %s allowas-in\n", addr);
17961 } else {
17962 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17963 peer->allowas_in[afi][safi]);
17964 }
17965 }
17966
46dbf9d0
DA
17967 /* accept-own */
17968 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
17969 vty_out(vty, " neighbor %s accept-own\n", addr);
17970
01da2d26
DA
17971 /* soo */
17972 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17973 char *soo_str = ecommunity_ecom2str(
17974 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17975
17976 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17977 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17978 }
17979
dd65f45e
DL
17980 /* weight */
17981 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17982 vty_out(vty, " neighbor %s weight %lu\n", addr,
17983 peer->weight[afi][safi]);
17984
17985 /* Filter. */
17986 bgp_config_write_filter(vty, peer, afi, safi);
17987
17988 /* atribute-unchanged. */
17989 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17990 || (safi != SAFI_EVPN
17991 && peer_af_flag_check(peer, afi, safi,
17992 PEER_FLAG_NEXTHOP_UNCHANGED))
17993 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17994
17995 if (!peer_group_active(peer)
17996 || peergroup_af_flag_check(peer, afi, safi,
17997 PEER_FLAG_AS_PATH_UNCHANGED)
17998 || peergroup_af_flag_check(peer, afi, safi,
17999 PEER_FLAG_NEXTHOP_UNCHANGED)
18000 || peergroup_af_flag_check(peer, afi, safi,
18001 PEER_FLAG_MED_UNCHANGED)) {
18002
18003 vty_out(vty,
18004 " neighbor %s attribute-unchanged%s%s%s\n",
18005 addr,
18006 peer_af_flag_check(peer, afi, safi,
18007 PEER_FLAG_AS_PATH_UNCHANGED)
18008 ? " as-path"
18009 : "",
18010 peer_af_flag_check(peer, afi, safi,
18011 PEER_FLAG_NEXTHOP_UNCHANGED)
18012 ? " next-hop"
18013 : "",
18014 peer_af_flag_check(peer, afi, safi,
18015 PEER_FLAG_MED_UNCHANGED)
18016 ? " med"
18017 : "");
18018 }
18019 }
18020}
18021
a486300b
PG
18022static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
18023 safi_t safi)
18024{
18025 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
18026 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
18027 vty_out(vty, " no bgp retain route-target all\n");
18028}
18029
dd65f45e
DL
18030/* Address family based peer configuration display. */
18031static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
18032 safi_t safi)
18033{
18034 struct peer *peer;
18035 struct peer_group *group;
18036 struct listnode *node, *nnode;
18037
18038
18039 vty_frame(vty, " !\n address-family ");
18040 if (afi == AFI_IP) {
18041 if (safi == SAFI_UNICAST)
18042 vty_frame(vty, "ipv4 unicast");
18043 else if (safi == SAFI_LABELED_UNICAST)
18044 vty_frame(vty, "ipv4 labeled-unicast");
18045 else if (safi == SAFI_MULTICAST)
18046 vty_frame(vty, "ipv4 multicast");
18047 else if (safi == SAFI_MPLS_VPN)
18048 vty_frame(vty, "ipv4 vpn");
18049 else if (safi == SAFI_ENCAP)
18050 vty_frame(vty, "ipv4 encap");
18051 else if (safi == SAFI_FLOWSPEC)
18052 vty_frame(vty, "ipv4 flowspec");
18053 } else if (afi == AFI_IP6) {
18054 if (safi == SAFI_UNICAST)
18055 vty_frame(vty, "ipv6 unicast");
18056 else if (safi == SAFI_LABELED_UNICAST)
18057 vty_frame(vty, "ipv6 labeled-unicast");
18058 else if (safi == SAFI_MULTICAST)
18059 vty_frame(vty, "ipv6 multicast");
18060 else if (safi == SAFI_MPLS_VPN)
18061 vty_frame(vty, "ipv6 vpn");
18062 else if (safi == SAFI_ENCAP)
18063 vty_frame(vty, "ipv6 encap");
18064 else if (safi == SAFI_FLOWSPEC)
18065 vty_frame(vty, "ipv6 flowspec");
18066 } else if (afi == AFI_L2VPN) {
18067 if (safi == SAFI_EVPN)
18068 vty_frame(vty, "l2vpn evpn");
18069 }
18070 vty_frame(vty, "\n");
18071
18072 bgp_config_write_distance(vty, bgp, afi, safi);
18073
18074 bgp_config_write_network(vty, bgp, afi, safi);
18075
18076 bgp_config_write_redistribute(vty, bgp, afi, safi);
18077
8a4e7fe6
DA
18078 /* BGP flag dampening. */
18079 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6c75f4b3 18080 bgp_config_write_damp(vty, afi, safi);
8a4e7fe6 18081
dd65f45e
DL
18082 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
18083 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
18084
18085 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
18086 /* Do not display doppelganger peers */
18087 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18088 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
18089 }
18090
18091 bgp_config_write_maxpaths(vty, bgp, afi, safi);
18092 bgp_config_write_table_map(vty, bgp, afi, safi);
18093
18094 if (safi == SAFI_EVPN)
18095 bgp_config_write_evpn_info(vty, bgp, afi, safi);
18096
18097 if (safi == SAFI_FLOWSPEC)
18098 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
18099
a486300b
PG
18100 if (safi == SAFI_MPLS_VPN)
18101 bgp_vpn_config_write(vty, bgp, afi, safi);
18102
dd65f45e
DL
18103 if (safi == SAFI_UNICAST) {
18104 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
18105 if (CHECK_FLAG(bgp->af_flags[afi][safi],
18106 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
18107
18108 vty_out(vty, " export vpn\n");
18109 }
18110 if (CHECK_FLAG(bgp->af_flags[afi][safi],
18111 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
18112
18113 vty_out(vty, " import vpn\n");
18114 }
18115 if (CHECK_FLAG(bgp->af_flags[afi][safi],
18116 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
18117 char *name;
18118
18119 for (ALL_LIST_ELEMENTS_RO(
18120 bgp->vpn_policy[afi].import_vrf, node,
18121 name))
18122 vty_out(vty, " import vrf %s\n", name);
18123 }
18124 }
18125
18126 vty_endframe(vty, " exit-address-family\n");
18127}
18128
18129int bgp_config_write(struct vty *vty)
18130{
18131 struct bgp *bgp;
18132 struct peer_group *group;
18133 struct peer *peer;
18134 struct listnode *node, *nnode;
18135 struct listnode *mnode, *mnnode;
b16bcbba
TA
18136 afi_t afi;
18137 safi_t safi;
efc9b57d 18138 uint32_t tovpn_sid_index = 0;
dd65f45e
DL
18139
18140 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
18141 vty_out(vty, "bgp route-map delay-timer %u\n",
18142 bm->rmap_update_timer);
18143
d70583f7
D
18144 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
18145 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
18146 if (bm->v_update_delay != bm->v_establish_wait)
18147 vty_out(vty, " %d", bm->v_establish_wait);
18148 vty_out(vty, "\n");
18149 }
18150
9acb67cb
DS
18151 if (bm->wait_for_fib)
18152 vty_out(vty, "bgp suppress-fib-pending\n");
18153
05bd726c 18154 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18155 vty_out(vty, "bgp graceful-shutdown\n");
18156
c163f297
DS
18157 /* No-RIB (Zebra) option flag configuration */
18158 if (bgp_option_check(BGP_OPT_NO_FIB))
18159 vty_out(vty, "bgp no-rib\n");
18160
870791a3
IR
18161 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
18162 vty_out(vty, "bgp send-extra-data zebra\n");
e46723a5 18163
425bd64b
PS
18164 /* BGP session DSCP value */
18165 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
18166 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
18167
a0b937de 18168 /* BGP InQ limit */
963b7ee4 18169 if (bm->inq_limit != BM_DEFAULT_Q_LIMIT)
a0b937de
SW
18170 vty_out(vty, "bgp input-queue-limit %u\n", bm->inq_limit);
18171
963b7ee4
DS
18172 if (bm->outq_limit != BM_DEFAULT_Q_LIMIT)
18173 vty_out(vty, "bgp output-queue-limit %u\n", bm->outq_limit);
18174
dd65f45e
DL
18175 /* BGP configuration. */
18176 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
18177
18178 /* skip all auto created vrf as they dont have user config */
18179 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
18180 continue;
18181
18182 /* Router bgp ASN */
9eb11997 18183 vty_out(vty, "router bgp %s", bgp->as_pretty);
dd65f45e
DL
18184
18185 if (bgp->name)
18186 vty_out(vty, " %s %s",
18187 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
18188 ? "view" : "vrf", bgp->name);
e55b0883
PG
18189 if (CHECK_FLAG(bgp->config, BGP_CONFIG_ASNOTATION))
18190 vty_out(vty, " as-notation %s",
18191 asn_mode2str(bgp->asnotation));
18192
dd65f45e
DL
18193 vty_out(vty, "\n");
18194
18195 /* BGP fast-external-failover. */
18196 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
18197 vty_out(vty, " no bgp fast-external-failover\n");
18198
18199 /* BGP router ID. */
3a6290bd 18200 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
18201 vty_out(vty, " bgp router-id %pI4\n",
18202 &bgp->router_id_static);
dd65f45e 18203
c208c586
S
18204 /* Suppress fib pending */
18205 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
18206 vty_out(vty, " bgp suppress-fib-pending\n");
18207
dd65f45e 18208 /* BGP log-neighbor-changes. */
892fedb6 18209 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 18210 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 18211 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
18212 CHECK_FLAG(bgp->flags,
18213 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
18214 ? ""
18215 : "no ");
18216
18217 /* BGP configuration. */
892fedb6 18218 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
18219 vty_out(vty, " bgp always-compare-med\n");
18220
18221 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
18222 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
18223 != SAVE_BGP_EBGP_REQUIRES_POLICY)
18224 vty_out(vty, " %sbgp ebgp-requires-policy\n",
18225 CHECK_FLAG(bgp->flags,
18226 BGP_FLAG_EBGP_REQUIRES_POLICY)
18227 ? ""
18228 : "no ");
dd65f45e
DL
18229
18230 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 18231 if (bgp->reject_as_sets)
dd65f45e
DL
18232 vty_out(vty, " bgp reject-as-sets\n");
18233
2adac256
DA
18234 /* Suppress duplicate updates if the route actually not changed
18235 */
18236 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
18237 != SAVE_BGP_SUPPRESS_DUPLICATES)
18238 vty_out(vty, " %sbgp suppress-duplicates\n",
18239 CHECK_FLAG(bgp->flags,
18240 BGP_FLAG_SUPPRESS_DUPLICATES)
18241 ? ""
18242 : "no ");
18243
1ae314be
DA
18244 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
18245 */
18246 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
18247 SAVE_BGP_HARD_ADMIN_RESET)
18248 vty_out(vty, " %sbgp hard-administrative-reset\n",
18249 CHECK_FLAG(bgp->flags,
18250 BGP_FLAG_HARD_ADMIN_RESET)
18251 ? ""
18252 : "no ");
18253
b16bcbba
TA
18254 /* BGP default <afi>-<safi> */
18255 FOREACH_AFI_SAFI (afi, safi) {
18256 if (afi == AFI_IP && safi == SAFI_UNICAST) {
18257 if (!bgp->default_af[afi][safi])
18258 vty_out(vty, " no bgp default %s\n",
18259 get_bgp_default_af_flag(afi,
18260 safi));
18261 } else if (bgp->default_af[afi][safi])
18262 vty_out(vty, " bgp default %s\n",
18263 get_bgp_default_af_flag(afi, safi));
18264 }
e84c59af 18265
dd65f45e
DL
18266 /* BGP default local-preference. */
18267 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
18268 vty_out(vty, " bgp default local-preference %u\n",
18269 bgp->default_local_pref);
18270
18271 /* BGP default show-hostname */
892fedb6 18272 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 18273 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 18274 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 18275 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
18276 ? ""
18277 : "no ");
18278
aef999a2
DA
18279 /* BGP default show-nexthop-hostname */
18280 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18281 != SAVE_BGP_SHOW_HOSTNAME)
18282 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
18283 CHECK_FLAG(bgp->flags,
18284 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18285 ? ""
18286 : "no ");
18287
dd65f45e
DL
18288 /* BGP default subgroup-pkt-queue-max. */
18289 if (bgp->default_subgroup_pkt_queue_max
18290 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
18291 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
18292 bgp->default_subgroup_pkt_queue_max);
18293
18294 /* BGP client-to-client reflection. */
892fedb6 18295 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
18296 vty_out(vty, " no bgp client-to-client reflection\n");
18297
18298 /* BGP cluster ID. */
18299 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
18300 vty_out(vty, " bgp cluster-id %pI4\n",
18301 &bgp->cluster_id);
dd65f45e
DL
18302
18303 /* Disable ebgp connected nexthop check */
892fedb6 18304 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
18305 vty_out(vty,
18306 " bgp disable-ebgp-connected-route-check\n");
18307
18308 /* Confederation identifier*/
18309 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7e14d0fa
PG
18310 vty_out(vty, " bgp confederation identifier %s\n",
18311 bgp->confed_id_pretty);
dd65f45e
DL
18312
18313 /* Confederation peer */
18314 if (bgp->confed_peers_cnt > 0) {
18315 int i;
18316
18317 vty_out(vty, " bgp confederation peers");
18318
18319 for (i = 0; i < bgp->confed_peers_cnt; i++)
7e14d0fa
PG
18320 vty_out(vty, " %s",
18321 bgp->confed_peers[i].as_pretty);
dd65f45e
DL
18322
18323 vty_out(vty, "\n");
18324 }
18325
18326 /* BGP deterministic-med. */
892fedb6 18327 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 18328 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 18329 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
18330 CHECK_FLAG(bgp->flags,
18331 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
18332 ? ""
18333 : "no ");
18334
18335 /* BGP update-delay. */
18336 bgp_config_write_update_delay(vty, bgp);
18337
18338 if (bgp->v_maxmed_onstartup
18339 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
18340 vty_out(vty, " bgp max-med on-startup %u",
18341 bgp->v_maxmed_onstartup);
18342 if (bgp->maxmed_onstartup_value
18343 != BGP_MAXMED_VALUE_DEFAULT)
18344 vty_out(vty, " %u",
18345 bgp->maxmed_onstartup_value);
18346 vty_out(vty, "\n");
18347 }
18348 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
18349 vty_out(vty, " bgp max-med administrative");
18350 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
18351 vty_out(vty, " %u", bgp->maxmed_admin_value);
18352 vty_out(vty, "\n");
18353 }
18354
18355 /* write quanta */
18356 bgp_config_write_wpkt_quanta(vty, bgp);
18357 /* read quanta */
18358 bgp_config_write_rpkt_quanta(vty, bgp);
18359
18360 /* coalesce time */
18361 bgp_config_write_coalesce_time(vty, bgp);
18362
05bd726c 18363 /* BGP per-instance graceful-shutdown */
18364 /* BGP-wide settings and per-instance settings are mutually
18365 * exclusive.
18366 */
18367 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18368 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
18369 vty_out(vty, " bgp graceful-shutdown\n");
18370
8606be87
DA
18371 /* Long-lived Graceful Restart */
18372 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
18373 vty_out(vty,
18374 " bgp long-lived-graceful-restart stale-time %u\n",
18375 bgp->llgr_stale_time);
18376
dd65f45e
DL
18377 /* BGP graceful-restart. */
18378 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
18379 vty_out(vty,
18380 " bgp graceful-restart stalepath-time %u\n",
18381 bgp->stalepath_time);
cfd47646 18382
dd65f45e
DL
18383 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18384 vty_out(vty, " bgp graceful-restart restart-time %u\n",
18385 bgp->restart_time);
cfd47646 18386
f2ca5c5b
DA
18387 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
18388 SAVE_BGP_GRACEFUL_NOTIFICATION)
18389 vty_out(vty, " %sbgp graceful-restart notification\n",
18390 CHECK_FLAG(bgp->flags,
18391 BGP_FLAG_GRACEFUL_NOTIFICATION)
18392 ? ""
18393 : "no ");
18394
cfd47646 18395 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18396 vty_out(vty,
18397 " bgp graceful-restart select-defer-time %u\n",
18398 bgp->select_defer_time);
18399
18400 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
18401 vty_out(vty, " bgp graceful-restart\n");
18402
cfd47646 18403 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18404 vty_out(vty, " bgp graceful-restart-disable\n");
18405
dd65f45e 18406 /* BGP graceful-restart Preserve State F bit. */
892fedb6 18407 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
18408 vty_out(vty,
18409 " bgp graceful-restart preserve-fw-state\n");
18410
d1adb448
PG
18411 /* BGP TCP keepalive */
18412 bgp_config_tcp_keepalive(vty, bgp);
18413
dc95985f 18414 /* Stale timer for RIB */
18415 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18416 vty_out(vty,
18417 " bgp graceful-restart rib-stale-time %u\n",
18418 bgp->rib_stale_time);
18419
dd65f45e 18420 /* BGP bestpath method. */
892fedb6 18421 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 18422 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 18423 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
18424 vty_out(vty, " bgp bestpath as-path confed\n");
18425
892fedb6
DA
18426 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18427 if (CHECK_FLAG(bgp->flags,
18428 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
18429 vty_out(vty,
18430 " bgp bestpath as-path multipath-relax as-set\n");
18431 } else {
18432 vty_out(vty,
18433 " bgp bestpath as-path multipath-relax\n");
18434 }
18435 }
18436
892fedb6 18437 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
18438 vty_out(vty,
18439 " bgp route-reflector allow-outbound-policy\n");
18440 }
892fedb6 18441 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 18442 vty_out(vty, " bgp bestpath compare-routerid\n");
97a52c82
DA
18443 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP))
18444 vty_out(vty, " bgp bestpath aigp\n");
892fedb6
DA
18445 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18446 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 18447 vty_out(vty, " bgp bestpath med");
892fedb6 18448 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 18449 vty_out(vty, " confed");
892fedb6
DA
18450 if (CHECK_FLAG(bgp->flags,
18451 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
18452 vty_out(vty, " missing-as-worst");
18453 vty_out(vty, "\n");
18454 }
18455
ee88563a
JM
18456 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18457 vty_out(vty,
18458 " bgp bestpath peer-type multipath-relax\n");
18459
f7e1c681 18460 /* Link bandwidth handling. */
18461 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18462 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18463 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18464 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18465 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18466 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18467
dd65f45e 18468 /* BGP network import check. */
892fedb6 18469 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 18470 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 18471 vty_out(vty, " %sbgp network import-check\n",
892fedb6 18472 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
18473 ? ""
18474 : "no ");
18475
18476 /* BGP timers configuration. */
5d5393b9 18477 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 18478 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
18479 vty_out(vty, " timers bgp %u %u\n",
18480 bgp->default_keepalive, bgp->default_holdtime);
18481
b042667a
TI
18482 /* BGP minimum holdtime configuration. */
18483 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
18484 && bgp->default_min_holdtime != 0)
18485 vty_out(vty, " bgp minimum-holdtime %u\n",
18486 bgp->default_min_holdtime);
18487
389e4f92
QY
18488 /* Conditional advertisement timer configuration */
18489 if (bgp->condition_check_period
18490 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
18491 vty_out(vty,
18492 " bgp conditional-advertisement timer %u\n",
18493 bgp->condition_check_period);
18494
dd65f45e
DL
18495 /* peer-group */
18496 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18497 bgp_config_write_peer_global(vty, bgp, group->conf);
18498 }
18499
18500 /* Normal neighbor configuration. */
18501 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18502 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18503 bgp_config_write_peer_global(vty, bgp, peer);
18504 }
18505
18506 /* listen range and limit for dynamic BGP neighbors */
18507 bgp_config_write_listen(vty, bgp);
18508
18509 /*
18510 * BGP default autoshutdown neighbors
18511 *
18512 * This must be placed after any peer and peer-group
18513 * configuration, to avoid setting all peers to shutdown after
18514 * a daemon restart, which is undesired behavior. (see #2286)
18515 */
18516 if (bgp->autoshutdown)
18517 vty_out(vty, " bgp default shutdown\n");
18518
9cf59432
DS
18519 /* BGP instance administrative shutdown */
18520 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18521 vty_out(vty, " bgp shutdown\n");
18522
8666265e
DS
18523 if (bgp->allow_martian)
18524 vty_out(vty, " bgp allow-martian-nexthop\n");
18525
f852eb98
PG
18526 if (bgp->fast_convergence)
18527 vty_out(vty, " bgp fast-convergence\n");
18528
a0281b2e
HS
18529 if (bgp->srv6_enabled) {
18530 vty_frame(vty, " !\n segment-routing srv6\n");
96db4340 18531 if (strlen(bgp->srv6_locator_name))
a0281b2e
HS
18532 vty_out(vty, " locator %s\n",
18533 bgp->srv6_locator_name);
ff7c3ee1 18534 vty_endframe(vty, " exit\n");
a0281b2e
HS
18535 }
18536
efc9b57d
CS
18537 tovpn_sid_index = bgp->tovpn_sid_index;
18538 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
18539 vty_out(vty, " sid vpn per-vrf export auto\n");
18540 } else if (tovpn_sid_index != 0) {
18541 vty_out(vty, " sid vpn per-vrf export %d\n",
18542 tovpn_sid_index);
18543 }
a0281b2e 18544
dd65f45e
DL
18545 /* IPv4 unicast configuration. */
18546 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18547
18548 /* IPv4 multicast configuration. */
18549 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18550
18551 /* IPv4 labeled-unicast configuration. */
18552 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18553
18554 /* IPv4 VPN configuration. */
18555 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18556
18557 /* ENCAPv4 configuration. */
18558 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18559
18560 /* FLOWSPEC v4 configuration. */
18561 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18562
18563 /* IPv6 unicast configuration. */
18564 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18565
18566 /* IPv6 multicast configuration. */
18567 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18568
18569 /* IPv6 labeled-unicast configuration. */
18570 bgp_config_write_family(vty, bgp, AFI_IP6,
18571 SAFI_LABELED_UNICAST);
18572
18573 /* IPv6 VPN configuration. */
18574 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18575
18576 /* ENCAPv6 configuration. */
18577 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18578
18579 /* FLOWSPEC v6 configuration. */
18580 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18581
18582 /* EVPN configuration. */
18583 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18584
18585 hook_call(bgp_inst_config_write, bgp, vty);
18586
49e5a4a0 18587#ifdef ENABLE_BGP_VNC
dd65f45e
DL
18588 bgp_rfapi_cfg_write(vty, bgp);
18589#endif
18590
07679ad9 18591 vty_out(vty, "exit\n");
dd65f45e
DL
18592 vty_out(vty, "!\n");
18593 }
18594 return 0;
18595}
18596
ddb5b488 18597
718e3744 18598/* BGP node structure. */
d62a17ae 18599static struct cmd_node bgp_node = {
f4b8291f 18600 .name = "bgp",
62b346ee 18601 .node = BGP_NODE,
24389580 18602 .parent_node = CONFIG_NODE,
62b346ee 18603 .prompt = "%s(config-router)# ",
612c2c15 18604 .config_write = bgp_config_write,
718e3744 18605};
18606
d62a17ae 18607static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 18608 .name = "bgp ipv4 unicast",
62b346ee 18609 .node = BGP_IPV4_NODE,
24389580 18610 .parent_node = BGP_NODE,
62b346ee 18611 .prompt = "%s(config-router-af)# ",
dd2c81b8 18612 .no_xpath = true,
718e3744 18613};
18614
d62a17ae 18615static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 18616 .name = "bgp ipv4 multicast",
62b346ee 18617 .node = BGP_IPV4M_NODE,
24389580 18618 .parent_node = BGP_NODE,
62b346ee 18619 .prompt = "%s(config-router-af)# ",
dd2c81b8 18620 .no_xpath = true,
718e3744 18621};
18622
d62a17ae 18623static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 18624 .name = "bgp ipv4 labeled unicast",
62b346ee 18625 .node = BGP_IPV4L_NODE,
24389580 18626 .parent_node = BGP_NODE,
62b346ee 18627 .prompt = "%s(config-router-af)# ",
dd2c81b8 18628 .no_xpath = true,
f51bae9c
DS
18629};
18630
d62a17ae 18631static struct cmd_node bgp_ipv6_unicast_node = {
a17cfb3f 18632 .name = "bgp ipv6 unicast",
62b346ee 18633 .node = BGP_IPV6_NODE,
24389580 18634 .parent_node = BGP_NODE,
62b346ee 18635 .prompt = "%s(config-router-af)# ",
dd2c81b8 18636 .no_xpath = true,
718e3744 18637};
18638
d62a17ae 18639static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 18640 .name = "bgp ipv6 multicast",
62b346ee 18641 .node = BGP_IPV6M_NODE,
24389580 18642 .parent_node = BGP_NODE,
62b346ee 18643 .prompt = "%s(config-router-af)# ",
dd2c81b8 18644 .no_xpath = true,
25ffbdc1 18645};
18646
d62a17ae 18647static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 18648 .name = "bgp ipv6 labeled unicast",
62b346ee 18649 .node = BGP_IPV6L_NODE,
24389580 18650 .parent_node = BGP_NODE,
62b346ee 18651 .prompt = "%s(config-router-af)# ",
dd2c81b8 18652 .no_xpath = true,
f51bae9c
DS
18653};
18654
62b346ee 18655static struct cmd_node bgp_vpnv4_node = {
f4b8291f 18656 .name = "bgp vpnv4",
62b346ee 18657 .node = BGP_VPNV4_NODE,
24389580 18658 .parent_node = BGP_NODE,
62b346ee 18659 .prompt = "%s(config-router-af)# ",
dd2c81b8 18660 .no_xpath = true,
62b346ee 18661};
6b0655a2 18662
62b346ee 18663static struct cmd_node bgp_vpnv6_node = {
f4b8291f 18664 .name = "bgp vpnv6",
62b346ee 18665 .node = BGP_VPNV6_NODE,
24389580 18666 .parent_node = BGP_NODE,
62b346ee 18667 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 18668 .no_xpath = true,
62b346ee 18669};
8ecd3266 18670
62b346ee 18671static struct cmd_node bgp_evpn_node = {
f4b8291f 18672 .name = "bgp evpn",
62b346ee 18673 .node = BGP_EVPN_NODE,
24389580 18674 .parent_node = BGP_NODE,
62b346ee 18675 .prompt = "%s(config-router-evpn)# ",
dd2c81b8 18676 .no_xpath = true,
62b346ee 18677};
4e0b7b6d 18678
62b346ee 18679static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 18680 .name = "bgp evpn vni",
62b346ee 18681 .node = BGP_EVPN_VNI_NODE,
24389580 18682 .parent_node = BGP_EVPN_NODE,
62b346ee 18683 .prompt = "%s(config-router-af-vni)# ",
62b346ee 18684};
90e60aa7 18685
62b346ee 18686static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 18687 .name = "bgp ipv4 flowspec",
62b346ee 18688 .node = BGP_FLOWSPECV4_NODE,
24389580 18689 .parent_node = BGP_NODE,
62b346ee 18690 .prompt = "%s(config-router-af)# ",
dd2c81b8 18691 .no_xpath = true,
62b346ee 18692};
7c40bf39 18693
62b346ee 18694static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 18695 .name = "bgp ipv6 flowspec",
62b346ee 18696 .node = BGP_FLOWSPECV6_NODE,
24389580 18697 .parent_node = BGP_NODE,
62b346ee 18698 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 18699 .no_xpath = true,
62b346ee 18700};
7c40bf39 18701
bfaab44d
HS
18702static struct cmd_node bgp_srv6_node = {
18703 .name = "bgp srv6",
18704 .node = BGP_SRV6_NODE,
18705 .parent_node = BGP_NODE,
18706 .prompt = "%s(config-router-srv6)# ",
18707};
18708
d62a17ae 18709static void community_list_vty(void);
1f8ae70b 18710
8c20061f
DA
18711static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18712{
18713 struct bgp *bgp;
18714 struct peer_group *group;
18715 struct listnode *lnbgp, *lnpeer;
18716
18717 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18718 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18719 vector_set(comps,
18720 XSTRDUP(MTYPE_COMPLETION, group->name));
18721 }
18722}
18723
18724static void bgp_ac_peer(vector comps, struct cmd_token *token)
b8a815e5 18725{
d62a17ae 18726 struct bgp *bgp;
18727 struct peer *peer;
d62a17ae 18728 struct listnode *lnbgp, *lnpeer;
b8a815e5 18729
d62a17ae 18730 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18731 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18732 /* only provide suggestions on the appropriate input
18733 * token type,
18734 * they'll otherwise show up multiple times */
18735 enum cmd_token_type match_type;
18736 char *name = peer->host;
d48ed3e0 18737
d62a17ae 18738 if (peer->conf_if) {
18739 match_type = VARIABLE_TKN;
18740 name = peer->conf_if;
18741 } else if (strchr(peer->host, ':'))
18742 match_type = IPV6_TKN;
18743 else
18744 match_type = IPV4_TKN;
d48ed3e0 18745
d62a17ae 18746 if (token->type != match_type)
18747 continue;
d48ed3e0 18748
d62a17ae 18749 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18750 }
d62a17ae 18751 }
b8a815e5
DL
18752}
18753
8c20061f
DA
18754static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18755{
18756 bgp_ac_peer(comps, token);
84de1483
DA
18757
18758 if (token->type == VARIABLE_TKN)
18759 bgp_ac_peergroup(comps, token);
8c20061f
DA
18760}
18761
b8a815e5 18762static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 18763 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18764 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 18765 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 18766 {.completions = NULL}};
18767
47a306a0
DS
18768static const struct cmd_variable_handler bgp_var_peergroup[] = {
18769 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18770 {.completions = NULL} };
18771
aa24a36a
DA
18772DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18773
18774static struct thread *t_bgp_cfg;
18775
18776bool bgp_config_inprocess(void)
18777{
18778 return thread_is_scheduled(t_bgp_cfg);
18779}
18780
18781static void bgp_config_finish(struct thread *t)
18782{
18783 struct listnode *node;
18784 struct bgp *bgp;
18785
18786 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18787 hook_call(bgp_config_end, bgp);
18788}
18789
18790static void bgp_config_start(void)
18791{
18792#define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18793 THREAD_OFF(t_bgp_cfg);
18794 thread_add_timer(bm->master, bgp_config_finish, NULL,
18795 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18796}
18797
18798/* When we receive a hook the configuration is read,
18799 * we start a timer to make sure we postpone sending
18800 * EoR before route-maps are processed.
18801 * This is especially valid if using `bgp route-map delay-timer`.
18802 */
18803static void bgp_config_end(void)
18804{
18805#define BGP_POST_CONFIG_DELAY_SECONDS 1
18806 uint32_t bgp_post_config_delay =
18807 thread_is_scheduled(bm->t_rmap_update)
18808 ? thread_timer_remain_second(bm->t_rmap_update)
18809 : BGP_POST_CONFIG_DELAY_SECONDS;
18810
18811 /* If BGP config processing thread isn't running, then
18812 * we can return and rely it's properly handled.
18813 */
18814 if (!bgp_config_inprocess())
18815 return;
18816
18817 THREAD_OFF(t_bgp_cfg);
18818
18819 /* Start a new timer to make sure we don't send EoR
18820 * before route-maps are processed.
18821 */
18822 thread_add_timer(bm->master, bgp_config_finish, NULL,
18823 bgp_post_config_delay, &t_bgp_cfg);
18824}
18825
4cd690ae
PG
18826static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18827{
18828 int write = 0;
18829 struct interface *ifp;
18830 struct bgp_interface *iifp;
18831
18832 FOR_ALL_INTERFACES (vrf, ifp) {
18833 iifp = ifp->info;
18834 if (!iifp)
18835 continue;
18836
18837 if_vty_config_start(vty, ifp);
18838
18839 if (CHECK_FLAG(iifp->flags,
18840 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18841 vty_out(vty, " mpls bgp forwarding\n");
18842 write++;
18843 }
18844
18845 if_vty_config_end(vty);
18846 }
18847
18848 return write;
18849}
18850
18851/* Configuration write function for bgpd. */
18852static int config_write_interface(struct vty *vty)
18853{
18854 int write = 0;
18855 struct vrf *vrf = NULL;
18856
18857 /* Display all VRF aware OSPF interface configuration */
18858 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18859 write += config_write_interface_one(vty, vrf);
18860 }
18861
18862 return write;
18863}
18864
18865DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18866 "[no$no] mpls bgp forwarding",
18867 NO_STR MPLS_STR BGP_STR
18868 "Enable MPLS forwarding for eBGP directly connected peers\n")
18869{
18870 bool check;
18871 struct bgp_interface *iifp;
18872
18873 VTY_DECLVAR_CONTEXT(interface, ifp);
18874 iifp = ifp->info;
18875 if (!iifp) {
18876 vty_out(vty, "Interface %s not available\n", ifp->name);
18877 return CMD_WARNING_CONFIG_FAILED;
18878 }
18879 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18880 if (check != !no) {
18881 if (no)
18882 UNSET_FLAG(iifp->flags,
18883 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18884 else
18885 SET_FLAG(iifp->flags,
18886 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18887 /* trigger a nht update on eBGP sessions */
18888 if (if_is_operative(ifp))
18889 bgp_nht_ifp_up(ifp);
18890 }
18891 return CMD_SUCCESS;
18892}
18893
a0b937de
SW
18894DEFPY (bgp_inq_limit,
18895 bgp_inq_limit_cmd,
18896 "bgp input-queue-limit (1-4294967295)$limit",
18897 BGP_STR
18898 "Set the BGP Input Queue limit for all peers when message parsing\n"
18899 "Input-Queue limit\n")
18900{
18901 bm->inq_limit = limit;
18902
18903 return CMD_SUCCESS;
18904}
18905
18906DEFPY (no_bgp_inq_limit,
18907 no_bgp_inq_limit_cmd,
18908 "no bgp input-queue-limit [(1-4294967295)$limit]",
18909 NO_STR
18910 BGP_STR
18911 "Set the BGP Input Queue limit for all peers when message parsing\n"
18912 "Input-Queue limit\n")
18913{
963b7ee4
DS
18914 bm->inq_limit = BM_DEFAULT_Q_LIMIT;
18915
18916 return CMD_SUCCESS;
18917}
18918
18919DEFPY (bgp_outq_limit,
18920 bgp_outq_limit_cmd,
18921 "bgp output-queue-limit (1-4294967295)$limit",
18922 BGP_STR
18923 "Set the BGP Output Queue limit for all peers when message parsing\n"
18924 "Output-Queue limit\n")
18925{
18926 bm->outq_limit = limit;
a0b937de
SW
18927
18928 return CMD_SUCCESS;
18929}
18930
963b7ee4
DS
18931DEFPY (no_bgp_outq_limit,
18932 no_bgp_outq_limit_cmd,
18933 "no bgp output-queue-limit [(1-4294967295)$limit]",
18934 NO_STR
18935 BGP_STR
18936 "Set the BGP Output Queue limit for all peers when message parsing\n"
18937 "Output-Queue limit\n")
18938{
18939 bm->outq_limit = BM_DEFAULT_Q_LIMIT;
a0b937de
SW
18940
18941 return CMD_SUCCESS;
18942}
18943
963b7ee4 18944
4cd690ae
PG
18945/* Initialization of BGP interface. */
18946static void bgp_vty_if_init(void)
18947{
18948 /* Install interface node. */
18949 if_cmd_init(config_write_interface);
18950
18951 /* "mpls bgp forwarding" commands. */
18952 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18953}
18954
d62a17ae 18955void bgp_vty_init(void)
18956{
18957 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 18958 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 18959
aa24a36a
DA
18960 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18961
d62a17ae 18962 /* Install bgp top node. */
612c2c15
DL
18963 install_node(&bgp_node);
18964 install_node(&bgp_ipv4_unicast_node);
18965 install_node(&bgp_ipv4_multicast_node);
18966 install_node(&bgp_ipv4_labeled_unicast_node);
18967 install_node(&bgp_ipv6_unicast_node);
18968 install_node(&bgp_ipv6_multicast_node);
18969 install_node(&bgp_ipv6_labeled_unicast_node);
18970 install_node(&bgp_vpnv4_node);
18971 install_node(&bgp_vpnv6_node);
18972 install_node(&bgp_evpn_node);
18973 install_node(&bgp_evpn_vni_node);
18974 install_node(&bgp_flowspecv4_node);
18975 install_node(&bgp_flowspecv6_node);
bfaab44d 18976 install_node(&bgp_srv6_node);
d62a17ae 18977
18978 /* Install default VTY commands to new nodes. */
18979 install_default(BGP_NODE);
18980 install_default(BGP_IPV4_NODE);
18981 install_default(BGP_IPV4M_NODE);
18982 install_default(BGP_IPV4L_NODE);
18983 install_default(BGP_IPV6_NODE);
18984 install_default(BGP_IPV6M_NODE);
18985 install_default(BGP_IPV6L_NODE);
18986 install_default(BGP_VPNV4_NODE);
18987 install_default(BGP_VPNV6_NODE);
7c40bf39 18988 install_default(BGP_FLOWSPECV4_NODE);
18989 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 18990 install_default(BGP_EVPN_NODE);
18991 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 18992 install_default(BGP_SRV6_NODE);
d62a17ae 18993
a0b937de
SW
18994 /* "global bgp inq-limit command */
18995 install_element(CONFIG_NODE, &bgp_inq_limit_cmd);
18996 install_element(CONFIG_NODE, &no_bgp_inq_limit_cmd);
963b7ee4
DS
18997 install_element(CONFIG_NODE, &bgp_outq_limit_cmd);
18998 install_element(CONFIG_NODE, &no_bgp_outq_limit_cmd);
a0b937de 18999
8029b216
AK
19000 /* "bgp local-mac" hidden commands. */
19001 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
19002 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
19003
9acb67cb
DS
19004 /* "bgp suppress-fib-pending" global */
19005 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
19006
d62a17ae 19007 /* bgp route-map delay-timer commands. */
19008 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
19009 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
19010
8666265e
DS
19011 install_element(BGP_NODE, &bgp_allow_martian_cmd);
19012
f852eb98
PG
19013 /* bgp fast-convergence command */
19014 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
19015 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
19016
d70583f7
D
19017 /* global bgp update-delay command */
19018 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
19019 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
19020
05bd726c 19021 /* global bgp graceful-shutdown command */
19022 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
19023 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
19024
d62a17ae 19025 /* Dummy commands (Currently not supported) */
19026 install_element(BGP_NODE, &no_synchronization_cmd);
19027 install_element(BGP_NODE, &no_auto_summary_cmd);
19028
19029 /* "router bgp" commands. */
19030 install_element(CONFIG_NODE, &router_bgp_cmd);
19031
19032 /* "no router bgp" commands. */
19033 install_element(CONFIG_NODE, &no_router_bgp_cmd);
19034
425bd64b
PS
19035 /* "bgp session-dscp command */
19036 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
19037 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
19038
d62a17ae 19039 /* "bgp router-id" commands. */
19040 install_element(BGP_NODE, &bgp_router_id_cmd);
19041 install_element(BGP_NODE, &no_bgp_router_id_cmd);
19042
c208c586
S
19043 /* "bgp suppress-fib-pending" command */
19044 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
19045
d62a17ae 19046 /* "bgp cluster-id" commands. */
19047 install_element(BGP_NODE, &bgp_cluster_id_cmd);
19048 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
19049
c163f297
DS
19050 /* "bgp no-rib" commands. */
19051 install_element(CONFIG_NODE, &bgp_norib_cmd);
19052 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
19053
e46723a5
DS
19054 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
19055
d62a17ae 19056 /* "bgp confederation" commands. */
19057 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
19058 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
19059
19060 /* "bgp confederation peers" commands. */
19061 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
19062 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
19063
19064 /* bgp max-med command */
19065 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
19066 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
19067 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
19068 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
19069 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
19070
d864dd9e
EB
19071 /* "neighbor role" commands. */
19072 install_element(BGP_NODE, &neighbor_role_cmd);
19073 install_element(BGP_NODE, &neighbor_role_strict_cmd);
19074 install_element(BGP_NODE, &no_neighbor_role_cmd);
19075
97a52c82
DA
19076 /* "neighbor aigp" commands. */
19077 install_element(BGP_NODE, &neighbor_aigp_cmd);
19078
4f770cf1
DA
19079 /* "neighbor graceful-shutdown" command */
19080 install_element(BGP_NODE, &neighbor_graceful_shutdown_cmd);
19081
d62a17ae 19082 /* bgp disable-ebgp-connected-nh-check */
19083 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
19084 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
19085
19086 /* bgp update-delay command */
19087 install_element(BGP_NODE, &bgp_update_delay_cmd);
19088 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 19089
19090 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 19091 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 19092
19093 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
19094 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
19095
19096 /* "maximum-paths" commands. */
19097 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
19098 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
19099 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
19100 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
19101 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
19102 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
19103 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
19104 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
19105 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
19106 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
19107 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
19108 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
19109 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
19110 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
19111 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
19112
39edabac
PG
19113 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
19114 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
19115 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
19116 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
19117 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 19118 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
19119 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
19120 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
19121 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
19122 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
19123
19124 /* "timers bgp" commands. */
19125 install_element(BGP_NODE, &bgp_timers_cmd);
19126 install_element(BGP_NODE, &no_bgp_timers_cmd);
19127
b042667a
TI
19128 /* "minimum-holdtime" commands. */
19129 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
19130 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
19131
d62a17ae 19132 /* route-map delay-timer commands - per instance for backwards compat.
19133 */
19134 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
19135 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
19136
19137 /* "bgp client-to-client reflection" commands */
19138 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
19139 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
19140
19141 /* "bgp always-compare-med" commands */
19142 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
19143 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
19144
9dac9fc8
DA
19145 /* bgp ebgp-requires-policy */
19146 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
19147 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
19148
2adac256
DA
19149 /* bgp suppress-duplicates */
19150 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
19151 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
19152
fb29348a
DA
19153 /* bgp reject-as-sets */
19154 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
19155 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
19156
d62a17ae 19157 /* "bgp deterministic-med" commands */
19158 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
19159 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
19160
055679e9 19161 /* "bgp graceful-restart" command */
36235319
QY
19162 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
19163 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 19164
19165 /* "bgp graceful-restart-disable" command */
36235319
QY
19166 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
19167 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 19168
19169 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
19170 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
19171 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 19172
19173 /* "neighbor a:b:c:d graceful-restart-disable" command */
19174 install_element(BGP_NODE,
19175 &bgp_neighbor_graceful_restart_disable_set_cmd);
19176 install_element(BGP_NODE,
19177 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
19178
19179 /* "neighbor a:b:c:d graceful-restart-helper" command */
19180 install_element(BGP_NODE,
19181 &bgp_neighbor_graceful_restart_helper_set_cmd);
19182 install_element(BGP_NODE,
19183 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
19184
d62a17ae 19185 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
19186 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
19187 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
19188 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 19189 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 19190 install_element(BGP_NODE,
19191 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 19192 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
19193 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
f2ca5c5b 19194 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
d62a17ae 19195
d6e3c15b 19196 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
19197 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 19198 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
19199 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 19200
7f323236
DW
19201 /* "bgp graceful-shutdown" commands */
19202 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
19203 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
19204
1ae314be
DA
19205 /* "bgp hard-administrative-reset" commands */
19206 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
19207
8606be87
DA
19208 /* "bgp long-lived-graceful-restart" commands */
19209 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
19210 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
19211
d62a17ae 19212 /* "bgp fast-external-failover" commands */
19213 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
19214 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
19215
97a52c82
DA
19216 /* "bgp bestpath aigp" commands */
19217 install_element(BGP_NODE, &bgp_bestpath_aigp_cmd);
19218
d62a17ae 19219 /* "bgp bestpath compare-routerid" commands */
19220 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
19221 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
19222
19223 /* "bgp bestpath as-path ignore" commands */
19224 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
19225 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
19226
19227 /* "bgp bestpath as-path confed" commands */
19228 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
19229 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
19230
19231 /* "bgp bestpath as-path multipath-relax" commands */
19232 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
19233 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
19234
ee88563a
JM
19235 /* "bgp bestpath peer-type multipath-relax" commands */
19236 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
19237 install_element(BGP_NODE,
19238 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
19239
d62a17ae 19240 /* "bgp log-neighbor-changes" commands */
19241 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
19242 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
19243
19244 /* "bgp bestpath med" commands */
19245 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
19246 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
19247
f7e1c681 19248 /* "bgp bestpath bandwidth" commands */
19249 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 19250 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 19251
b16bcbba
TA
19252 /* "no bgp default <afi>-<safi>" commands. */
19253 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
e84c59af 19254
d62a17ae 19255 /* "bgp network import-check" commands. */
19256 install_element(BGP_NODE, &bgp_network_import_check_cmd);
19257 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
19258 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
19259
19260 /* "bgp default local-preference" commands. */
19261 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
19262 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
19263
19264 /* bgp default show-hostname */
19265 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
19266 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
19267
aef999a2
DA
19268 /* bgp default show-nexthop-hostname */
19269 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
19270 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
19271
d62a17ae 19272 /* "bgp default subgroup-pkt-queue-max" commands. */
19273 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
19274 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
19275
19276 /* bgp ibgp-allow-policy-mods command */
19277 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
19278 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
19279
19280 /* "bgp listen limit" commands. */
19281 install_element(BGP_NODE, &bgp_listen_limit_cmd);
19282 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
19283
19284 /* "bgp listen range" commands. */
19285 install_element(BGP_NODE, &bgp_listen_range_cmd);
19286 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
19287
8175f54a 19288 /* "bgp default shutdown" command */
f26845f9 19289 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
19290
19291 /* "bgp shutdown" commands */
19292 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 19293 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 19294 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 19295 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 19296
d62a17ae 19297 /* "neighbor remote-as" commands. */
19298 install_element(BGP_NODE, &neighbor_remote_as_cmd);
19299 install_element(BGP_NODE, &neighbor_interface_config_cmd);
19300 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
19301 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
19302 install_element(BGP_NODE,
19303 &neighbor_interface_v6only_config_remote_as_cmd);
19304 install_element(BGP_NODE, &no_neighbor_cmd);
19305 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
19306
19307 /* "neighbor peer-group" commands. */
19308 install_element(BGP_NODE, &neighbor_peer_group_cmd);
19309 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
19310 install_element(BGP_NODE,
19311 &no_neighbor_interface_peer_group_remote_as_cmd);
19312
19313 /* "neighbor local-as" commands. */
19314 install_element(BGP_NODE, &neighbor_local_as_cmd);
19315 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
19316 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
19317 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
19318
19319 /* "neighbor solo" commands. */
19320 install_element(BGP_NODE, &neighbor_solo_cmd);
19321 install_element(BGP_NODE, &no_neighbor_solo_cmd);
19322
19323 /* "neighbor password" commands. */
19324 install_element(BGP_NODE, &neighbor_password_cmd);
19325 install_element(BGP_NODE, &no_neighbor_password_cmd);
19326
19327 /* "neighbor activate" commands. */
19328 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
19329 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
19330 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
19331 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
19332 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
19333 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
19334 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
19335 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
19336 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 19337 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
19338 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 19339 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
19340
19341 /* "no neighbor activate" commands. */
19342 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
19343 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
19344 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
19345 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
19346 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
19347 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
19348 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
19349 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
19350 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 19351 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
19352 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 19353 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
19354
19355 /* "neighbor peer-group" set commands. */
19356 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
19357 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19358 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
19359 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19360 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
19361 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
19362 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19363 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 19364 install_element(BGP_FLOWSPECV4_NODE,
19365 &neighbor_set_peer_group_hidden_cmd);
19366 install_element(BGP_FLOWSPECV6_NODE,
19367 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 19368
19369 /* "no neighbor peer-group unset" commands. */
19370 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
19371 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19372 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19373 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19374 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19375 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19376 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19377 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 19378 install_element(BGP_FLOWSPECV4_NODE,
19379 &no_neighbor_set_peer_group_hidden_cmd);
19380 install_element(BGP_FLOWSPECV6_NODE,
19381 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 19382
19383 /* "neighbor softreconfiguration inbound" commands.*/
19384 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
19385 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
19386 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
19387 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19388 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
19389 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19390 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
19391 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19392 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
19393 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19394 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
19395 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19396 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
19397 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19398 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
19399 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19400 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
19401 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 19402 install_element(BGP_FLOWSPECV4_NODE,
19403 &neighbor_soft_reconfiguration_cmd);
19404 install_element(BGP_FLOWSPECV4_NODE,
19405 &no_neighbor_soft_reconfiguration_cmd);
19406 install_element(BGP_FLOWSPECV6_NODE,
19407 &neighbor_soft_reconfiguration_cmd);
19408 install_element(BGP_FLOWSPECV6_NODE,
19409 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
19410 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
19411 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 19412
19413 /* "neighbor attribute-unchanged" commands. */
19414 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
19415 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
19416 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
19417 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
19418 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
19419 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
19420 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
19421 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
19422 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
19423 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
19424 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
19425 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
19426 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
19427 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
19428 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
19429 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
19430 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
19431 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
19432
19433 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
19434 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
19435
b8ad84d2
PG
19436 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
19437 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
19438 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
19439 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
19440
d62a17ae 19441 /* "nexthop-local unchanged" commands */
19442 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
19443 install_element(BGP_IPV6_NODE,
19444 &no_neighbor_nexthop_local_unchanged_cmd);
19445
19446 /* "neighbor next-hop-self" commands. */
19447 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
19448 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
19449 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
19450 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
19451 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
19452 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
19453 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
19454 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
19455 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
19456 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
19457 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
19458 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
19459 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
19460 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
19461 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
19462 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
19463 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
19464 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
19465 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
19466 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 19467
19468 /* "neighbor next-hop-self force" commands. */
19469 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
19470 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
19471 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19472 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19473 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
19474 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19475 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19476 install_element(BGP_IPV4_NODE,
19477 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19478 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
19479 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19480 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19481 install_element(BGP_IPV4M_NODE,
19482 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19483 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
19484 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19485 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19486 install_element(BGP_IPV4L_NODE,
19487 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19488 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
19489 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19490 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19491 install_element(BGP_IPV6_NODE,
19492 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19493 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
19494 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19495 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19496 install_element(BGP_IPV6M_NODE,
19497 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19498 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
19499 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19500 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19501 install_element(BGP_IPV6L_NODE,
19502 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19503 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
19504 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19505 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19506 install_element(BGP_VPNV4_NODE,
19507 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19508 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
19509 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19510 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19511 install_element(BGP_VPNV6_NODE,
19512 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
19513 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
19514 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 19515
19516 /* "neighbor as-override" commands. */
19517 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
19518 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
19519 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
19520 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
19521 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
19522 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
19523 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
19524 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
19525 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
19526 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
19527 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
19528 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
19529 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
19530 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
19531 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
19532 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
19533 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
19534 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
19535
19536 /* "neighbor remove-private-AS" commands. */
19537 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
19538 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
19539 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
19540 install_element(BGP_NODE,
19541 &no_neighbor_remove_private_as_all_hidden_cmd);
19542 install_element(BGP_NODE,
19543 &neighbor_remove_private_as_replace_as_hidden_cmd);
19544 install_element(BGP_NODE,
19545 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
19546 install_element(BGP_NODE,
19547 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
19548 install_element(
19549 BGP_NODE,
19550 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
19551 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
19552 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
19553 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
19554 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19555 install_element(BGP_IPV4_NODE,
19556 &neighbor_remove_private_as_replace_as_cmd);
19557 install_element(BGP_IPV4_NODE,
19558 &no_neighbor_remove_private_as_replace_as_cmd);
19559 install_element(BGP_IPV4_NODE,
19560 &neighbor_remove_private_as_all_replace_as_cmd);
19561 install_element(BGP_IPV4_NODE,
19562 &no_neighbor_remove_private_as_all_replace_as_cmd);
19563 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
19564 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
19565 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
19566 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
19567 install_element(BGP_IPV4M_NODE,
19568 &neighbor_remove_private_as_replace_as_cmd);
19569 install_element(BGP_IPV4M_NODE,
19570 &no_neighbor_remove_private_as_replace_as_cmd);
19571 install_element(BGP_IPV4M_NODE,
19572 &neighbor_remove_private_as_all_replace_as_cmd);
19573 install_element(BGP_IPV4M_NODE,
19574 &no_neighbor_remove_private_as_all_replace_as_cmd);
19575 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
19576 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
19577 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
19578 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
19579 install_element(BGP_IPV4L_NODE,
19580 &neighbor_remove_private_as_replace_as_cmd);
19581 install_element(BGP_IPV4L_NODE,
19582 &no_neighbor_remove_private_as_replace_as_cmd);
19583 install_element(BGP_IPV4L_NODE,
19584 &neighbor_remove_private_as_all_replace_as_cmd);
19585 install_element(BGP_IPV4L_NODE,
19586 &no_neighbor_remove_private_as_all_replace_as_cmd);
19587 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
19588 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
19589 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
19590 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19591 install_element(BGP_IPV6_NODE,
19592 &neighbor_remove_private_as_replace_as_cmd);
19593 install_element(BGP_IPV6_NODE,
19594 &no_neighbor_remove_private_as_replace_as_cmd);
19595 install_element(BGP_IPV6_NODE,
19596 &neighbor_remove_private_as_all_replace_as_cmd);
19597 install_element(BGP_IPV6_NODE,
19598 &no_neighbor_remove_private_as_all_replace_as_cmd);
19599 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
19600 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
19601 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
19602 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
19603 install_element(BGP_IPV6M_NODE,
19604 &neighbor_remove_private_as_replace_as_cmd);
19605 install_element(BGP_IPV6M_NODE,
19606 &no_neighbor_remove_private_as_replace_as_cmd);
19607 install_element(BGP_IPV6M_NODE,
19608 &neighbor_remove_private_as_all_replace_as_cmd);
19609 install_element(BGP_IPV6M_NODE,
19610 &no_neighbor_remove_private_as_all_replace_as_cmd);
19611 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19612 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19613 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19614 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19615 install_element(BGP_IPV6L_NODE,
19616 &neighbor_remove_private_as_replace_as_cmd);
19617 install_element(BGP_IPV6L_NODE,
19618 &no_neighbor_remove_private_as_replace_as_cmd);
19619 install_element(BGP_IPV6L_NODE,
19620 &neighbor_remove_private_as_all_replace_as_cmd);
19621 install_element(BGP_IPV6L_NODE,
19622 &no_neighbor_remove_private_as_all_replace_as_cmd);
19623 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19624 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19625 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19626 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19627 install_element(BGP_VPNV4_NODE,
19628 &neighbor_remove_private_as_replace_as_cmd);
19629 install_element(BGP_VPNV4_NODE,
19630 &no_neighbor_remove_private_as_replace_as_cmd);
19631 install_element(BGP_VPNV4_NODE,
19632 &neighbor_remove_private_as_all_replace_as_cmd);
19633 install_element(BGP_VPNV4_NODE,
19634 &no_neighbor_remove_private_as_all_replace_as_cmd);
19635 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19636 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19637 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19638 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19639 install_element(BGP_VPNV6_NODE,
19640 &neighbor_remove_private_as_replace_as_cmd);
19641 install_element(BGP_VPNV6_NODE,
19642 &no_neighbor_remove_private_as_replace_as_cmd);
19643 install_element(BGP_VPNV6_NODE,
19644 &neighbor_remove_private_as_all_replace_as_cmd);
19645 install_element(BGP_VPNV6_NODE,
19646 &no_neighbor_remove_private_as_all_replace_as_cmd);
19647
19648 /* "neighbor send-community" commands.*/
19649 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19650 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19651 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19652 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19653 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19654 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19655 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19656 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19657 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19658 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19659 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19660 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19661 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19662 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19663 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19664 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19665 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19666 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19667 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19668 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19669 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19670 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19671 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19672 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19673 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19674 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19675 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19676 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19677 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19678 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19679 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19680 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19681 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19682 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19683 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19684 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19685
19686 /* "neighbor route-reflector" commands.*/
19687 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19688 install_element(BGP_NODE,
19689 &no_neighbor_route_reflector_client_hidden_cmd);
19690 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19691 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19692 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19693 install_element(BGP_IPV4M_NODE,
19694 &no_neighbor_route_reflector_client_cmd);
19695 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19696 install_element(BGP_IPV4L_NODE,
19697 &no_neighbor_route_reflector_client_cmd);
19698 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19699 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19700 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19701 install_element(BGP_IPV6M_NODE,
19702 &no_neighbor_route_reflector_client_cmd);
19703 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19704 install_element(BGP_IPV6L_NODE,
19705 &no_neighbor_route_reflector_client_cmd);
19706 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19707 install_element(BGP_VPNV4_NODE,
19708 &no_neighbor_route_reflector_client_cmd);
19709 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19710 install_element(BGP_VPNV6_NODE,
19711 &no_neighbor_route_reflector_client_cmd);
7c40bf39 19712 install_element(BGP_FLOWSPECV4_NODE,
19713 &neighbor_route_reflector_client_cmd);
19714 install_element(BGP_FLOWSPECV4_NODE,
19715 &no_neighbor_route_reflector_client_cmd);
19716 install_element(BGP_FLOWSPECV6_NODE,
19717 &neighbor_route_reflector_client_cmd);
19718 install_element(BGP_FLOWSPECV6_NODE,
19719 &no_neighbor_route_reflector_client_cmd);
d62a17ae 19720 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19721 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19722
19723 /* "neighbor route-server" commands.*/
19724 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19725 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19726 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19727 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19728 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19729 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19730 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19731 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19732 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19733 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19734 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19735 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19736 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19737 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19738 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19739 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19740 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19741 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
19742 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19743 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 19744 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19745 install_element(BGP_FLOWSPECV4_NODE,
19746 &no_neighbor_route_server_client_cmd);
19747 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19748 install_element(BGP_FLOWSPECV6_NODE,
19749 &no_neighbor_route_server_client_cmd);
d62a17ae 19750
7c0e4312
DA
19751 /* "neighbor disable-addpath-rx" commands. */
19752 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19753 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19754 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19755 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19756 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19757 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19758 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19759 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19760 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19761 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19762 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19763 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19764 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19765 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19766 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19767 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19768
d62a17ae 19769 /* "neighbor addpath-tx-all-paths" commands.*/
19770 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19771 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19772 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19773 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19774 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19775 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19776 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19777 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19778 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19779 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19780 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19781 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19782 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19783 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19784 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19785 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19786 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19787 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19788
19789 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19790 install_element(BGP_NODE,
19791 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19792 install_element(BGP_NODE,
19793 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19794 install_element(BGP_IPV4_NODE,
19795 &neighbor_addpath_tx_bestpath_per_as_cmd);
19796 install_element(BGP_IPV4_NODE,
19797 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19798 install_element(BGP_IPV4M_NODE,
19799 &neighbor_addpath_tx_bestpath_per_as_cmd);
19800 install_element(BGP_IPV4M_NODE,
19801 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19802 install_element(BGP_IPV4L_NODE,
19803 &neighbor_addpath_tx_bestpath_per_as_cmd);
19804 install_element(BGP_IPV4L_NODE,
19805 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19806 install_element(BGP_IPV6_NODE,
19807 &neighbor_addpath_tx_bestpath_per_as_cmd);
19808 install_element(BGP_IPV6_NODE,
19809 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19810 install_element(BGP_IPV6M_NODE,
19811 &neighbor_addpath_tx_bestpath_per_as_cmd);
19812 install_element(BGP_IPV6M_NODE,
19813 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19814 install_element(BGP_IPV6L_NODE,
19815 &neighbor_addpath_tx_bestpath_per_as_cmd);
19816 install_element(BGP_IPV6L_NODE,
19817 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19818 install_element(BGP_VPNV4_NODE,
19819 &neighbor_addpath_tx_bestpath_per_as_cmd);
19820 install_element(BGP_VPNV4_NODE,
19821 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19822 install_element(BGP_VPNV6_NODE,
19823 &neighbor_addpath_tx_bestpath_per_as_cmd);
19824 install_element(BGP_VPNV6_NODE,
19825 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19826
2b31007c
RZ
19827 /* "neighbor sender-as-path-loop-detection" commands. */
19828 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19829 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19830
a5c6a9b1
DA
19831 /* "neighbor path-attribute discard" commands. */
19832 install_element(BGP_NODE, &neighbor_path_attribute_discard_cmd);
b986d7f4 19833 install_element(BGP_NODE, &no_neighbor_path_attribute_discard_cmd);
a5c6a9b1 19834
e2863b4f
DA
19835 /* "neighbor path-attribute treat-as-withdraw" commands. */
19836 install_element(BGP_NODE,
19837 &neighbor_path_attribute_treat_as_withdraw_cmd);
19838 install_element(BGP_NODE,
19839 &no_neighbor_path_attribute_treat_as_withdraw_cmd);
19840
d62a17ae 19841 /* "neighbor passive" commands. */
19842 install_element(BGP_NODE, &neighbor_passive_cmd);
19843 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19844
19845
19846 /* "neighbor shutdown" commands. */
19847 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19848 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19849 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19850 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
19851 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19852 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 19853
19854 /* "neighbor capability extended-nexthop" commands.*/
19855 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19856 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19857
234f6fd4
DA
19858 /* "neighbor capability software-version" commands.*/
19859 install_element(BGP_NODE, &neighbor_capability_software_version_cmd);
19860
d62a17ae 19861 /* "neighbor capability orf prefix-list" commands.*/
19862 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19863 install_element(BGP_NODE,
19864 &no_neighbor_capability_orf_prefix_hidden_cmd);
19865 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19866 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19867 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19868 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19869 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19870 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19871 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19872 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19873 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19874 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19875 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19876 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19877
19878 /* "neighbor capability dynamic" commands.*/
19879 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19880 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19881
19882 /* "neighbor dont-capability-negotiate" commands. */
19883 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19884 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19885
19886 /* "neighbor ebgp-multihop" commands. */
19887 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19888 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19889 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19890
19891 /* "neighbor disable-connected-check" commands. */
19892 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19893 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19894
7ab294ea
DA
19895 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19896 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19897 install_element(BGP_NODE,
19898 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
27aa23a4 19899
d08c0c80
DA
19900 /* "neighbor extended-optional-parameters" commands. */
19901 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19902 install_element(BGP_NODE,
19903 &no_neighbor_extended_optional_parameters_cmd);
19904
47cbc09b
PM
19905 /* "neighbor enforce-first-as" commands. */
19906 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19907 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19908
d62a17ae 19909 /* "neighbor description" commands. */
19910 install_element(BGP_NODE, &neighbor_description_cmd);
19911 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 19912 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 19913
19914 /* "neighbor update-source" commands. "*/
19915 install_element(BGP_NODE, &neighbor_update_source_cmd);
19916 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19917
19918 /* "neighbor default-originate" commands. */
19919 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19920 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19921 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19922 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19923 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19924 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19925 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19926 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19927 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19928 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19929 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19930 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19931 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19932 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19933 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19934 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19935 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19936 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19937 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19938 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19939 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19940
19941 /* "neighbor port" commands. */
19942 install_element(BGP_NODE, &neighbor_port_cmd);
19943 install_element(BGP_NODE, &no_neighbor_port_cmd);
19944
19945 /* "neighbor weight" commands. */
19946 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19947 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19948
19949 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19950 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19951 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19952 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19953 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19954 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19955 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19956 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19957 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19958 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19959 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19960 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19961 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19962 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19963 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19964 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19965
19966 /* "neighbor override-capability" commands. */
19967 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19968 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19969
19970 /* "neighbor strict-capability-match" commands. */
19971 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19972 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19973
19974 /* "neighbor timers" commands. */
19975 install_element(BGP_NODE, &neighbor_timers_cmd);
19976 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19977
19978 /* "neighbor timers connect" commands. */
19979 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19980 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19981
d43114f3
DS
19982 /* "neighbor timers delayopen" commands. */
19983 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19984 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19985
d62a17ae 19986 /* "neighbor advertisement-interval" commands. */
19987 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19988 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19989
19990 /* "neighbor interface" commands. */
19991 install_element(BGP_NODE, &neighbor_interface_cmd);
19992 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19993
19994 /* "neighbor distribute" commands. */
19995 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19996 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19997 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19998 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19999 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
20000 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
20001 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
20002 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
20003 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
20004 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
20005 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
20006 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
20007 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
20008 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
20009 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
20010 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
20011 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
20012 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
20013
20014 /* "neighbor prefix-list" commands. */
20015 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
642ef664 20016 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
d62a17ae 20017 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
642ef664 20018 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20019 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
642ef664 20020 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20021 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
642ef664 20022 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20023 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
642ef664 20024 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20025 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
642ef664 20026 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20027 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
642ef664 20028 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20029 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
642ef664 20030 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20031 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
642ef664 20032 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 20033 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
642ef664 20034 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 20035 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
642ef664 20036 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 20037
20038 /* "neighbor filter-list" commands. */
20039 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
20040 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
20041 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
20042 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
20043 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
20044 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
20045 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
20046 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
20047 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
20048 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
20049 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
20050 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
20051 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
20052 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
20053 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
20054 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
20055 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
20056 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 20057 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
20058 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
20059 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
20060 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 20061
20062 /* "neighbor route-map" commands. */
d6d7ed37
IR
20063 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
20064 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
d62a17ae 20065 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
0ea8d871 20066 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20067 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
0ea8d871 20068 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20069 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
0ea8d871 20070 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20071 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
0ea8d871 20072 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20073 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
0ea8d871 20074 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20075 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
0ea8d871 20076 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20077 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
0ea8d871 20078 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20079 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
0ea8d871 20080 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 20081 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
0ea8d871 20082 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
7c40bf39 20083 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
0ea8d871 20084 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549 20085 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
0ea8d871 20086 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 20087
20088 /* "neighbor unsuppress-map" commands. */
20089 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
20090 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
20091 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
20092 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
20093 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
20094 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
20095 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
20096 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
20097 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
20098 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
20099 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
20100 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
20101 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
20102 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
20103 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
20104 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
20105 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
20106 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
20107
7f7940e6 20108 /* "neighbor advertise-map" commands. */
389e4f92 20109 install_element(BGP_NODE, &bgp_condadv_period_cmd);
7f7940e6 20110 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 20111 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20112 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20113 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20114 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20115 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20116 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20117 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20118 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 20119
fde246e8
DA
20120 /* neighbor maximum-prefix-out commands. */
20121 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
20122 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
20123 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
20124 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
20125 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
20126 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
20127 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
20128 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
20129 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
20130 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
20131 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
20132 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
20133 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
20134 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
20135 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
20136 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
20137 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
20138 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
20139
d62a17ae 20140 /* "neighbor maximum-prefix" commands. */
20141 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
20142 install_element(BGP_NODE,
20143 &neighbor_maximum_prefix_threshold_hidden_cmd);
20144 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
20145 install_element(BGP_NODE,
20146 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
20147 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
20148 install_element(BGP_NODE,
20149 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
20150 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
20151 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
20152 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
20153 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
20154 install_element(BGP_IPV4_NODE,
20155 &neighbor_maximum_prefix_threshold_warning_cmd);
20156 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
20157 install_element(BGP_IPV4_NODE,
20158 &neighbor_maximum_prefix_threshold_restart_cmd);
20159 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
20160 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
20161 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
20162 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
20163 install_element(BGP_IPV4M_NODE,
20164 &neighbor_maximum_prefix_threshold_warning_cmd);
20165 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
20166 install_element(BGP_IPV4M_NODE,
20167 &neighbor_maximum_prefix_threshold_restart_cmd);
20168 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
20169 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
20170 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
20171 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
20172 install_element(BGP_IPV4L_NODE,
20173 &neighbor_maximum_prefix_threshold_warning_cmd);
20174 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
20175 install_element(BGP_IPV4L_NODE,
20176 &neighbor_maximum_prefix_threshold_restart_cmd);
20177 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
20178 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
20179 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
20180 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
20181 install_element(BGP_IPV6_NODE,
20182 &neighbor_maximum_prefix_threshold_warning_cmd);
20183 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
20184 install_element(BGP_IPV6_NODE,
20185 &neighbor_maximum_prefix_threshold_restart_cmd);
20186 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
20187 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
20188 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
20189 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
20190 install_element(BGP_IPV6M_NODE,
20191 &neighbor_maximum_prefix_threshold_warning_cmd);
20192 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
20193 install_element(BGP_IPV6M_NODE,
20194 &neighbor_maximum_prefix_threshold_restart_cmd);
20195 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
20196 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
20197 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
20198 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
20199 install_element(BGP_IPV6L_NODE,
20200 &neighbor_maximum_prefix_threshold_warning_cmd);
20201 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
20202 install_element(BGP_IPV6L_NODE,
20203 &neighbor_maximum_prefix_threshold_restart_cmd);
20204 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
20205 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
20206 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
20207 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
20208 install_element(BGP_VPNV4_NODE,
20209 &neighbor_maximum_prefix_threshold_warning_cmd);
20210 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
20211 install_element(BGP_VPNV4_NODE,
20212 &neighbor_maximum_prefix_threshold_restart_cmd);
20213 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
20214 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
20215 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
20216 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
20217 install_element(BGP_VPNV6_NODE,
20218 &neighbor_maximum_prefix_threshold_warning_cmd);
20219 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
20220 install_element(BGP_VPNV6_NODE,
20221 &neighbor_maximum_prefix_threshold_restart_cmd);
20222 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
20223
20224 /* "neighbor allowas-in" */
20225 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
20226 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
20227 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
20228 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
20229 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
20230 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
20231 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
20232 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
20233 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
20234 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
20235 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
20236 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
20237 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
20238 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
20239 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
20240 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
20241 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
20242 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
20243 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
20244 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
20245
46dbf9d0
DA
20246 /* neighbor accept-own */
20247 install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
20248 install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
20249
01da2d26
DA
20250 /* "neighbor soo" */
20251 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
20252 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
20253 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
20254 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
20255 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
20256 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
20257 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
20258 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
20259 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
20260 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
20261 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
20262 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
20263 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
20264 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
20265 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
20266 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
20267 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
20268 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
20269
d62a17ae 20270 /* address-family commands. */
20271 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
20272 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 20273#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 20274 install_element(BGP_NODE, &address_family_vpnv4_cmd);
20275 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 20276#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 20277
d62a17ae 20278 install_element(BGP_NODE, &address_family_evpn_cmd);
20279
20280 /* "exit-address-family" command. */
20281 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
20282 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
20283 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
20284 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
20285 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
20286 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
20287 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
20288 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 20289 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
20290 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 20291 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
20292
a486300b
PG
20293 /* BGP retain all route-target */
20294 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
20295 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
20296
d62a17ae 20297 /* "clear ip bgp commands" */
20298 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
20299
20300 /* clear ip bgp prefix */
20301 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
20302 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
20303 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
20304
20305 /* "show [ip] bgp summary" commands. */
20306 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 20307 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 20308 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 20309 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 20310 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
20311 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 20312 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
20313
20314 /* "show [ip] bgp neighbors" commands. */
20315 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
20316
36235319 20317 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 20318
d62a17ae 20319 /* "show [ip] bgp peer-group" commands. */
20320 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
20321
20322 /* "show [ip] bgp paths" commands. */
20323 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
20324
20325 /* "show [ip] bgp community" commands. */
20326 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
20327
20328 /* "show ip bgp large-community" commands. */
20329 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
20330 /* "show [ip] bgp attribute-info" commands. */
20331 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 20332 /* "show [ip] bgp route-leak" command */
20333 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 20334
20335 /* "redistribute" commands. */
20336 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
20337 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
20338 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
20339 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
20340 install_element(BGP_NODE,
20341 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
20342 install_element(BGP_NODE,
20343 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
20344 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
20345 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
20346 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
20347 install_element(BGP_NODE,
20348 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
20349 install_element(BGP_NODE,
20350 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
20351 install_element(BGP_NODE,
20352 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
20353 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
20354 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
20355 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
20356 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
20357 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
20358 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
20359 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
20360 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
20361 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
20362 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
20363 install_element(BGP_IPV4_NODE,
20364 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
20365 install_element(BGP_IPV4_NODE,
20366 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
20367 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
20368 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
20369 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
20370 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
20371 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
20372 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
20373
70dd370f 20374 /* import|export vpn [route-map RMAP_NAME] */
b9c7bc5a
PZ
20375 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
20376 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 20377
12a844a5
DS
20378 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
20379 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
20380
d62a17ae 20381 /* ttl_security commands */
20382 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
20383 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
20384
d1adb448
PG
20385 /* "bgp tcp-keepalive" commands */
20386 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
20387 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
20388
d62a17ae 20389 /* "show [ip] bgp memory" commands. */
20390 install_element(VIEW_NODE, &show_bgp_memory_cmd);
20391
acf71666
MK
20392 /* "show bgp martian next-hop" */
20393 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
20394
48ecf8f5
DS
20395 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
20396
d62a17ae 20397 /* "show [ip] bgp views" commands. */
20398 install_element(VIEW_NODE, &show_bgp_views_cmd);
20399
20400 /* "show [ip] bgp vrfs" commands. */
20401 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
20402
20403 /* Community-list. */
20404 community_list_vty();
ddb5b488 20405
ed0e57e3
DA
20406 community_alias_vty();
20407
ddb5b488 20408 /* vpn-policy commands */
b9c7bc5a
PZ
20409 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
20410 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
20411 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
20412 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
20413 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
20414 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
20415 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
20416 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
20417 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
20418 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
20419 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
20420 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 20421
301ad80a
PG
20422 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
20423 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
20424
b9c7bc5a
PZ
20425 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
20426 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
20427 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
20428 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
20429 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
20430 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
20431 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
20432 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
20433 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
20434 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
20435
20436 /* tcp-mss command */
20437 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
20438 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
20439
20440 /* srv6 commands */
ea372e81 20441 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
bfaab44d 20442 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
0249b8b6 20443 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
a0281b2e 20444 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
0249b8b6 20445 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
b72c9e14
HS
20446 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
20447 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
527588aa 20448 install_element(BGP_NODE, &bgp_sid_vpn_export_cmd);
e606d8ec 20449 install_element(BGP_NODE, &no_bgp_sid_vpn_export_cmd);
4cd690ae
PG
20450
20451 bgp_vty_if_init();
718e3744 20452}
6b0655a2 20453
718e3744 20454#include "memory.h"
20455#include "bgp_regex.h"
20456#include "bgp_clist.h"
20457#include "bgp_ecommunity.h"
20458
20459/* VTY functions. */
20460
20461/* Direction value to string conversion. */
d62a17ae 20462static const char *community_direct_str(int direct)
20463{
20464 switch (direct) {
20465 case COMMUNITY_DENY:
20466 return "deny";
20467 case COMMUNITY_PERMIT:
20468 return "permit";
20469 default:
20470 return "unknown";
20471 }
718e3744 20472}
20473
20474/* Display error string. */
d62a17ae 20475static void community_list_perror(struct vty *vty, int ret)
20476{
20477 switch (ret) {
20478 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
20479 vty_out(vty, "%% Can't find community-list\n");
20480 break;
20481 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
20482 vty_out(vty, "%% Malformed community-list value\n");
20483 break;
20484 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
20485 vty_out(vty,
20486 "%% Community name conflict, previously defined as standard community\n");
20487 break;
20488 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
20489 vty_out(vty,
20490 "%% Community name conflict, previously defined as expanded community\n");
20491 break;
20492 }
718e3744 20493}
20494
5bf15956
DW
20495/* "community-list" keyword help string. */
20496#define COMMUNITY_LIST_STR "Add a community list entry\n"
20497
7336e101
SP
20498/*community-list standard */
20499DEFUN (community_list_standard,
20500 bgp_community_list_standard_cmd,
a2099c1d 20501 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 20502 BGP_STR
718e3744 20503 COMMUNITY_LIST_STR
20504 "Community list number (standard)\n"
5bf15956 20505 "Add an standard community-list entry\n"
718e3744 20506 "Community list name\n"
2f8cc0e5
DA
20507 "Sequence number of an entry\n"
20508 "Sequence number\n"
718e3744 20509 "Specify community to reject\n"
20510 "Specify community to accept\n"
20511 COMMUNITY_VAL_STR)
20512{
d62a17ae 20513 char *cl_name_or_number = NULL;
2f8cc0e5 20514 char *seq = NULL;
d62a17ae 20515 int direct = 0;
20516 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 20517 int idx = 0;
7336e101 20518
e34627f9 20519 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20520 seq = argv[idx]->arg;
20521
20522 idx = 0;
d62a17ae 20523 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20524 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20525 cl_name_or_number = argv[idx]->arg;
20526 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20527 : COMMUNITY_DENY;
20528 argv_find(argv, argc, "AA:NN", &idx);
20529 char *str = argv_concat(argv, argc, idx);
42f914d4 20530
2f8cc0e5
DA
20531 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20532 direct, style);
42f914d4 20533
d62a17ae 20534 XFREE(MTYPE_TMP, str);
42f914d4 20535
d62a17ae 20536 if (ret < 0) {
20537 /* Display error string. */
20538 community_list_perror(vty, ret);
20539 return CMD_WARNING_CONFIG_FAILED;
20540 }
42f914d4 20541
d62a17ae 20542 return CMD_SUCCESS;
718e3744 20543}
20544
7336e101
SP
20545DEFUN (no_community_list_standard_all,
20546 no_bgp_community_list_standard_all_cmd,
a2099c1d 20547 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20548 NO_STR
20549 BGP_STR
20550 COMMUNITY_LIST_STR
20551 "Community list number (standard)\n"
20552 "Add an standard community-list entry\n"
20553 "Community list name\n"
2f8cc0e5
DA
20554 "Sequence number of an entry\n"
20555 "Sequence number\n"
7336e101
SP
20556 "Specify community to reject\n"
20557 "Specify community to accept\n"
20558 COMMUNITY_VAL_STR)
718e3744 20559{
d62a17ae 20560 char *cl_name_or_number = NULL;
174b5cb9 20561 char *str = NULL;
d62a17ae 20562 int direct = 0;
20563 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 20564 char *seq = NULL;
d62a17ae 20565 int idx = 0;
7336e101 20566
e34627f9 20567 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20568 seq = argv[idx]->arg;
20569
20570 idx = 0;
174b5cb9
DA
20571 argv_find(argv, argc, "permit", &idx);
20572 argv_find(argv, argc, "deny", &idx);
20573
20574 if (idx) {
20575 direct = argv_find(argv, argc, "permit", &idx)
20576 ? COMMUNITY_PERMIT
20577 : COMMUNITY_DENY;
20578
20579 idx = 0;
20580 argv_find(argv, argc, "AA:NN", &idx);
20581 str = argv_concat(argv, argc, idx);
20582 }
20583
20584 idx = 0;
d62a17ae 20585 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20586 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20587 cl_name_or_number = argv[idx]->arg;
42f914d4 20588
2f8cc0e5 20589 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 20590 direct, style);
42f914d4 20591
d62a17ae 20592 XFREE(MTYPE_TMP, str);
daf9ddbb 20593
d62a17ae 20594 if (ret < 0) {
20595 community_list_perror(vty, ret);
20596 return CMD_WARNING_CONFIG_FAILED;
20597 }
42f914d4 20598
d62a17ae 20599 return CMD_SUCCESS;
718e3744 20600}
7336e101 20601
174b5cb9 20602ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
a2099c1d 20603 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
174b5cb9
DA
20604 NO_STR BGP_STR COMMUNITY_LIST_STR
20605 "Community list number (standard)\n"
20606 "Add an standard community-list entry\n"
20607 "Community list name\n")
20608
7336e101
SP
20609/*community-list expanded */
20610DEFUN (community_list_expanded_all,
20611 bgp_community_list_expanded_all_cmd,
a2099c1d 20612 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20613 BGP_STR
20614 COMMUNITY_LIST_STR
718e3744 20615 "Community list number (expanded)\n"
5bf15956 20616 "Add an expanded community-list entry\n"
718e3744 20617 "Community list name\n"
2f8cc0e5
DA
20618 "Sequence number of an entry\n"
20619 "Sequence number\n"
718e3744 20620 "Specify community to reject\n"
20621 "Specify community to accept\n"
20622 COMMUNITY_VAL_STR)
20623{
d62a17ae 20624 char *cl_name_or_number = NULL;
2f8cc0e5 20625 char *seq = NULL;
d62a17ae 20626 int direct = 0;
20627 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 20628 int idx = 0;
7b9a4750 20629
e34627f9 20630 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20631 seq = argv[idx]->arg;
20632
20633 idx = 0;
20634
d62a17ae 20635 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20636 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20637 cl_name_or_number = argv[idx]->arg;
20638 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20639 : COMMUNITY_DENY;
20640 argv_find(argv, argc, "AA:NN", &idx);
20641 char *str = argv_concat(argv, argc, idx);
42f914d4 20642
2f8cc0e5
DA
20643 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20644 direct, style);
42f914d4 20645
d62a17ae 20646 XFREE(MTYPE_TMP, str);
42f914d4 20647
d62a17ae 20648 if (ret < 0) {
20649 /* Display error string. */
20650 community_list_perror(vty, ret);
20651 return CMD_WARNING_CONFIG_FAILED;
20652 }
42f914d4 20653
d62a17ae 20654 return CMD_SUCCESS;
718e3744 20655}
20656
7336e101
SP
20657DEFUN (no_community_list_expanded_all,
20658 no_bgp_community_list_expanded_all_cmd,
a2099c1d 20659 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20660 NO_STR
20661 BGP_STR
20662 COMMUNITY_LIST_STR
20663 "Community list number (expanded)\n"
20664 "Add an expanded community-list entry\n"
20665 "Community list name\n"
2f8cc0e5
DA
20666 "Sequence number of an entry\n"
20667 "Sequence number\n"
7336e101
SP
20668 "Specify community to reject\n"
20669 "Specify community to accept\n"
20670 COMMUNITY_VAL_STR)
718e3744 20671{
d62a17ae 20672 char *cl_name_or_number = NULL;
2f8cc0e5 20673 char *seq = NULL;
174b5cb9 20674 char *str = NULL;
d62a17ae 20675 int direct = 0;
20676 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 20677 int idx = 0;
174b5cb9 20678
e34627f9 20679 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20680 seq = argv[idx]->arg;
20681
20682 idx = 0;
174b5cb9
DA
20683 argv_find(argv, argc, "permit", &idx);
20684 argv_find(argv, argc, "deny", &idx);
20685
20686 if (idx) {
20687 direct = argv_find(argv, argc, "permit", &idx)
20688 ? COMMUNITY_PERMIT
20689 : COMMUNITY_DENY;
20690
20691 idx = 0;
20692 argv_find(argv, argc, "AA:NN", &idx);
20693 str = argv_concat(argv, argc, idx);
7336e101 20694 }
174b5cb9
DA
20695
20696 idx = 0;
d62a17ae 20697 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20698 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20699 cl_name_or_number = argv[idx]->arg;
42f914d4 20700
2f8cc0e5 20701 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 20702 direct, style);
42f914d4 20703
d62a17ae 20704 XFREE(MTYPE_TMP, str);
daf9ddbb 20705
d62a17ae 20706 if (ret < 0) {
20707 community_list_perror(vty, ret);
20708 return CMD_WARNING_CONFIG_FAILED;
20709 }
42f914d4 20710
d62a17ae 20711 return CMD_SUCCESS;
718e3744 20712}
20713
36d4bb44
EB
20714ALIAS(no_community_list_expanded_all,
20715 no_bgp_community_list_expanded_all_list_cmd,
a2099c1d 20716 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
36d4bb44 20717 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
20718 "Community list number (expanded)\n"
20719 "Add an expanded community-list entry\n"
20720 "Community list name\n")
20721
8d9b8ed9
PM
20722/* Return configuration string of community-list entry. */
20723static const char *community_list_config_str(struct community_entry *entry)
20724{
20725 const char *str;
20726
20727 if (entry->any)
20728 str = "";
20729 else {
20730 if (entry->style == COMMUNITY_LIST_STANDARD)
c0945b78 20731 str = community_str(entry->u.com, false, false);
8d9b8ed9 20732 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
c0945b78 20733 str = lcommunity_str(entry->u.lcom, false, false);
8d9b8ed9
PM
20734 else
20735 str = entry->config;
20736 }
20737 return str;
20738}
20739
d62a17ae 20740static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 20741{
d62a17ae 20742 struct community_entry *entry;
718e3744 20743
d62a17ae 20744 for (entry = list->head; entry; entry = entry->next) {
20745 if (entry == list->head) {
20746 if (all_digit(list->name))
20747 vty_out(vty, "Community %s list %s\n",
20748 entry->style == COMMUNITY_LIST_STANDARD
20749 ? "standard"
20750 : "(expanded) access",
20751 list->name);
20752 else
20753 vty_out(vty, "Named Community %s list %s\n",
20754 entry->style == COMMUNITY_LIST_STANDARD
20755 ? "standard"
20756 : "expanded",
20757 list->name);
20758 }
20759 if (entry->any)
20760 vty_out(vty, " %s\n",
20761 community_direct_str(entry->direct));
20762 else
20763 vty_out(vty, " %s %s\n",
20764 community_direct_str(entry->direct),
8d9b8ed9 20765 community_list_config_str(entry));
d62a17ae 20766 }
718e3744 20767}
20768
7336e101
SP
20769DEFUN (show_community_list,
20770 show_bgp_community_list_cmd,
20771 "show bgp community-list",
718e3744 20772 SHOW_STR
7336e101 20773 BGP_STR
718e3744 20774 "List community-list\n")
20775{
d62a17ae 20776 struct community_list *list;
20777 struct community_list_master *cm;
718e3744 20778
d62a17ae 20779 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20780 if (!cm)
20781 return CMD_SUCCESS;
718e3744 20782
d62a17ae 20783 for (list = cm->num.head; list; list = list->next)
20784 community_list_show(vty, list);
718e3744 20785
d62a17ae 20786 for (list = cm->str.head; list; list = list->next)
20787 community_list_show(vty, list);
718e3744 20788
d62a17ae 20789 return CMD_SUCCESS;
718e3744 20790}
20791
7336e101
SP
20792DEFUN (show_community_list_arg,
20793 show_bgp_community_list_arg_cmd,
a2099c1d 20794 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
7336e101
SP
20795 SHOW_STR
20796 BGP_STR
718e3744 20797 "List community-list\n"
20798 "Community-list number\n"
960b69b9 20799 "Community-list name\n"
20800 "Detailed information on community-list\n")
718e3744 20801{
d62a17ae 20802 int idx_comm_list = 3;
20803 struct community_list *list;
718e3744 20804
e237b0d2 20805 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20806 COMMUNITY_LIST_MASTER);
20807 if (!list) {
20808 vty_out(vty, "%% Can't find community-list\n");
20809 return CMD_WARNING;
20810 }
718e3744 20811
d62a17ae 20812 community_list_show(vty, list);
718e3744 20813
d62a17ae 20814 return CMD_SUCCESS;
718e3744 20815}
6b0655a2 20816
57d187bc
JS
20817/*
20818 * Large Community code.
20819 */
d62a17ae 20820static int lcommunity_list_set_vty(struct vty *vty, int argc,
20821 struct cmd_token **argv, int style,
20822 int reject_all_digit_name)
20823{
20824 int ret;
20825 int direct;
20826 char *str;
20827 int idx = 0;
20828 char *cl_name;
2f8cc0e5
DA
20829 char *seq = NULL;
20830
a08032fe 20831 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 20832 seq = argv[idx]->arg;
d62a17ae 20833
2f8cc0e5 20834 idx = 0;
d62a17ae 20835 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20836 : COMMUNITY_DENY;
20837
20838 /* All digit name check. */
20839 idx = 0;
a2099c1d 20840 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20841 argv_find(argv, argc, "(1-99)", &idx);
20842 argv_find(argv, argc, "(100-500)", &idx);
20843 cl_name = argv[idx]->arg;
20844 if (reject_all_digit_name && all_digit(cl_name)) {
20845 vty_out(vty, "%% Community name cannot have all digits\n");
20846 return CMD_WARNING_CONFIG_FAILED;
20847 }
20848
20849 idx = 0;
20850 argv_find(argv, argc, "AA:BB:CC", &idx);
20851 argv_find(argv, argc, "LINE", &idx);
20852 /* Concat community string argument. */
20853 if (idx)
20854 str = argv_concat(argv, argc, idx);
20855 else
20856 str = NULL;
20857
2f8cc0e5 20858 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 20859
20860 /* Free temporary community list string allocated by
20861 argv_concat(). */
0a22ddfb 20862 XFREE(MTYPE_TMP, str);
d62a17ae 20863
20864 if (ret < 0) {
20865 community_list_perror(vty, ret);
20866 return CMD_WARNING_CONFIG_FAILED;
20867 }
20868 return CMD_SUCCESS;
20869}
20870
20871static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20872 struct cmd_token **argv, int style)
20873{
20874 int ret;
20875 int direct = 0;
20876 char *str = NULL;
20877 int idx = 0;
2f8cc0e5 20878 char *seq = NULL;
d62a17ae 20879
a08032fe 20880 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 20881 seq = argv[idx]->arg;
d62a17ae 20882
2f8cc0e5 20883 idx = 0;
d62a17ae 20884 argv_find(argv, argc, "permit", &idx);
20885 argv_find(argv, argc, "deny", &idx);
20886
20887 if (idx) {
20888 /* Check the list direct. */
20889 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20890 direct = COMMUNITY_PERMIT;
20891 else
20892 direct = COMMUNITY_DENY;
20893
20894 idx = 0;
20895 argv_find(argv, argc, "LINE", &idx);
20896 argv_find(argv, argc, "AA:AA:NN", &idx);
20897 /* Concat community string argument. */
20898 str = argv_concat(argv, argc, idx);
20899 }
20900
20901 idx = 0;
20902 argv_find(argv, argc, "(1-99)", &idx);
20903 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20904 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20905
20906 /* Unset community list. */
2f8cc0e5 20907 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 20908 style);
20909
20910 /* Free temporary community list string allocated by
20911 argv_concat(). */
0a22ddfb 20912 XFREE(MTYPE_TMP, str);
d62a17ae 20913
20914 if (ret < 0) {
20915 community_list_perror(vty, ret);
20916 return CMD_WARNING_CONFIG_FAILED;
20917 }
20918
20919 return CMD_SUCCESS;
57d187bc
JS
20920}
20921
20922/* "large-community-list" keyword help string. */
20923#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20924#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20925
7336e101
SP
20926DEFUN (lcommunity_list_standard,
20927 bgp_lcommunity_list_standard_cmd,
a08032fe 20928 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
20929 BGP_STR
20930 LCOMMUNITY_LIST_STR
20931 "Large Community list number (standard)\n"
2f8cc0e5
DA
20932 "Sequence number of an entry\n"
20933 "Sequence number\n"
7336e101
SP
20934 "Specify large community to reject\n"
20935 "Specify large community to accept\n"
20936 LCOMMUNITY_VAL_STR)
52951b63 20937{
d62a17ae 20938 return lcommunity_list_set_vty(vty, argc, argv,
20939 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
20940}
20941
7336e101
SP
20942DEFUN (lcommunity_list_expanded,
20943 bgp_lcommunity_list_expanded_cmd,
a08032fe 20944 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20945 BGP_STR
20946 LCOMMUNITY_LIST_STR
20947 "Large Community list number (expanded)\n"
2f8cc0e5
DA
20948 "Sequence number of an entry\n"
20949 "Sequence number\n"
7336e101
SP
20950 "Specify large community to reject\n"
20951 "Specify large community to accept\n"
20952 "An ordered list as a regular-expression\n")
57d187bc 20953{
d62a17ae 20954 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 20955 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
20956}
20957
7336e101
SP
20958DEFUN (lcommunity_list_name_standard,
20959 bgp_lcommunity_list_name_standard_cmd,
a2099c1d 20960 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
20961 BGP_STR
20962 LCOMMUNITY_LIST_STR
20963 "Specify standard large-community-list\n"
20964 "Large Community list name\n"
2f8cc0e5
DA
20965 "Sequence number of an entry\n"
20966 "Sequence number\n"
7336e101
SP
20967 "Specify large community to reject\n"
20968 "Specify large community to accept\n"
20969 LCOMMUNITY_VAL_STR)
52951b63 20970{
d62a17ae 20971 return lcommunity_list_set_vty(vty, argc, argv,
20972 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
20973}
20974
7336e101
SP
20975DEFUN (lcommunity_list_name_expanded,
20976 bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 20977 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20978 BGP_STR
20979 LCOMMUNITY_LIST_STR
20980 "Specify expanded large-community-list\n"
20981 "Large Community list name\n"
2f8cc0e5
DA
20982 "Sequence number of an entry\n"
20983 "Sequence number\n"
7336e101
SP
20984 "Specify large community to reject\n"
20985 "Specify large community to accept\n"
20986 "An ordered list as a regular-expression\n")
57d187bc 20987{
d62a17ae 20988 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 20989 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
20990}
20991
4378f57c
DA
20992DEFUN (no_lcommunity_list_all,
20993 no_bgp_lcommunity_list_all_cmd,
a2099c1d 20994 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
7336e101
SP
20995 NO_STR
20996 BGP_STR
20997 LCOMMUNITY_LIST_STR
20998 "Large Community list number (standard)\n"
20999 "Large Community list number (expanded)\n"
21000 "Large Community list name\n")
57d187bc 21001{
7336e101
SP
21002 return lcommunity_list_unset_vty(vty, argc, argv,
21003 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
21004}
21005
4378f57c
DA
21006DEFUN (no_lcommunity_list_name_standard_all,
21007 no_bgp_lcommunity_list_name_standard_all_cmd,
a2099c1d 21008 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
4378f57c
DA
21009 NO_STR
21010 BGP_STR
21011 LCOMMUNITY_LIST_STR
21012 "Specify standard large-community-list\n"
21013 "Large Community list name\n")
21014{
21015 return lcommunity_list_unset_vty(vty, argc, argv,
21016 LARGE_COMMUNITY_LIST_STANDARD);
21017}
21018
7336e101
SP
21019DEFUN (no_lcommunity_list_name_expanded_all,
21020 no_bgp_lcommunity_list_name_expanded_all_cmd,
a2099c1d 21021 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
7336e101
SP
21022 NO_STR
21023 BGP_STR
21024 LCOMMUNITY_LIST_STR
21025 "Specify expanded large-community-list\n"
21026 "Large Community list name\n")
57d187bc 21027{
d62a17ae 21028 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 21029 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
21030}
21031
7336e101
SP
21032DEFUN (no_lcommunity_list_standard,
21033 no_bgp_lcommunity_list_standard_cmd,
a08032fe 21034 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
21035 NO_STR
21036 BGP_STR
21037 LCOMMUNITY_LIST_STR
21038 "Large Community list number (standard)\n"
2f8cc0e5
DA
21039 "Sequence number of an entry\n"
21040 "Sequence number\n"
7336e101
SP
21041 "Specify large community to reject\n"
21042 "Specify large community to accept\n"
21043 LCOMMUNITY_VAL_STR)
57d187bc 21044{
d62a17ae 21045 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 21046 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
21047}
21048
7336e101
SP
21049DEFUN (no_lcommunity_list_expanded,
21050 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 21051 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21052 NO_STR
21053 BGP_STR
21054 LCOMMUNITY_LIST_STR
21055 "Large Community list number (expanded)\n"
2f8cc0e5
DA
21056 "Sequence number of an entry\n"
21057 "Sequence number\n"
7336e101
SP
21058 "Specify large community to reject\n"
21059 "Specify large community to accept\n"
21060 "An ordered list as a regular-expression\n")
57d187bc 21061{
d62a17ae 21062 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 21063 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
21064}
21065
7336e101
SP
21066DEFUN (no_lcommunity_list_name_standard,
21067 no_bgp_lcommunity_list_name_standard_cmd,
a2099c1d 21068 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
21069 NO_STR
21070 BGP_STR
21071 LCOMMUNITY_LIST_STR
21072 "Specify standard large-community-list\n"
21073 "Large Community list name\n"
2f8cc0e5
DA
21074 "Sequence number of an entry\n"
21075 "Sequence number\n"
7336e101
SP
21076 "Specify large community to reject\n"
21077 "Specify large community to accept\n"
21078 LCOMMUNITY_VAL_STR)
57d187bc 21079{
d62a17ae 21080 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 21081 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
21082}
21083
7336e101
SP
21084DEFUN (no_lcommunity_list_name_expanded,
21085 no_bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 21086 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21087 NO_STR
21088 BGP_STR
21089 LCOMMUNITY_LIST_STR
21090 "Specify expanded large-community-list\n"
21091 "Large community list name\n"
2f8cc0e5
DA
21092 "Sequence number of an entry\n"
21093 "Sequence number\n"
7336e101
SP
21094 "Specify large community to reject\n"
21095 "Specify large community to accept\n"
21096 "An ordered list as a regular-expression\n")
57d187bc 21097{
d62a17ae 21098 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 21099 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
21100}
21101
d62a17ae 21102static void lcommunity_list_show(struct vty *vty, struct community_list *list)
21103{
21104 struct community_entry *entry;
21105
21106 for (entry = list->head; entry; entry = entry->next) {
21107 if (entry == list->head) {
21108 if (all_digit(list->name))
21109 vty_out(vty, "Large community %s list %s\n",
169b72c8 21110 entry->style ==
21111 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 21112 ? "standard"
21113 : "(expanded) access",
21114 list->name);
21115 else
21116 vty_out(vty,
21117 "Named large community %s list %s\n",
169b72c8 21118 entry->style ==
21119 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 21120 ? "standard"
21121 : "expanded",
21122 list->name);
21123 }
21124 if (entry->any)
21125 vty_out(vty, " %s\n",
21126 community_direct_str(entry->direct));
21127 else
21128 vty_out(vty, " %s %s\n",
21129 community_direct_str(entry->direct),
8d9b8ed9 21130 community_list_config_str(entry));
d62a17ae 21131 }
57d187bc
JS
21132}
21133
7336e101
SP
21134DEFUN (show_lcommunity_list,
21135 show_bgp_lcommunity_list_cmd,
21136 "show bgp large-community-list",
57d187bc 21137 SHOW_STR
7336e101 21138 BGP_STR
57d187bc
JS
21139 "List large-community list\n")
21140{
d62a17ae 21141 struct community_list *list;
21142 struct community_list_master *cm;
57d187bc 21143
d62a17ae 21144 cm = community_list_master_lookup(bgp_clist,
21145 LARGE_COMMUNITY_LIST_MASTER);
21146 if (!cm)
21147 return CMD_SUCCESS;
57d187bc 21148
d62a17ae 21149 for (list = cm->num.head; list; list = list->next)
21150 lcommunity_list_show(vty, list);
57d187bc 21151
d62a17ae 21152 for (list = cm->str.head; list; list = list->next)
21153 lcommunity_list_show(vty, list);
57d187bc 21154
d62a17ae 21155 return CMD_SUCCESS;
57d187bc
JS
21156}
21157
7336e101
SP
21158DEFUN (show_lcommunity_list_arg,
21159 show_bgp_lcommunity_list_arg_cmd,
a2099c1d 21160 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
7336e101
SP
21161 SHOW_STR
21162 BGP_STR
57d187bc 21163 "List large-community list\n"
960b69b9 21164 "Large-community-list number\n"
21165 "Large-community-list name\n"
21166 "Detailed information on large-community-list\n")
57d187bc 21167{
d62a17ae 21168 struct community_list *list;
57d187bc 21169
e237b0d2 21170 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 21171 LARGE_COMMUNITY_LIST_MASTER);
21172 if (!list) {
960b69b9 21173 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 21174 return CMD_WARNING;
21175 }
57d187bc 21176
d62a17ae 21177 lcommunity_list_show(vty, list);
57d187bc 21178
d62a17ae 21179 return CMD_SUCCESS;
57d187bc
JS
21180}
21181
718e3744 21182/* "extcommunity-list" keyword help string. */
21183#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
21184#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
21185
7336e101
SP
21186DEFUN (extcommunity_list_standard,
21187 bgp_extcommunity_list_standard_cmd,
a2099c1d 21188 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 21189 BGP_STR
718e3744 21190 EXTCOMMUNITY_LIST_STR
21191 "Extended Community list number (standard)\n"
718e3744 21192 "Specify standard extcommunity-list\n"
5bf15956 21193 "Community list name\n"
2f8cc0e5
DA
21194 "Sequence number of an entry\n"
21195 "Sequence number\n"
718e3744 21196 "Specify community to reject\n"
21197 "Specify community to accept\n"
21198 EXTCOMMUNITY_VAL_STR)
21199{
d62a17ae 21200 int style = EXTCOMMUNITY_LIST_STANDARD;
21201 int direct = 0;
21202 char *cl_number_or_name = NULL;
2f8cc0e5 21203 char *seq = NULL;
42f914d4 21204
d62a17ae 21205 int idx = 0;
7b9a4750 21206
d62a17ae 21207 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 21208 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21209 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 21210
a08032fe 21211 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21212 seq = argv[idx]->arg;
21213
d62a17ae 21214 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21215 : COMMUNITY_DENY;
21216 argv_find(argv, argc, "AA:NN", &idx);
21217 char *str = argv_concat(argv, argc, idx);
42f914d4 21218
2f8cc0e5 21219 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 21220 direct, style);
42f914d4 21221
d62a17ae 21222 XFREE(MTYPE_TMP, str);
42f914d4 21223
d62a17ae 21224 if (ret < 0) {
21225 community_list_perror(vty, ret);
21226 return CMD_WARNING_CONFIG_FAILED;
21227 }
42f914d4 21228
d62a17ae 21229 return CMD_SUCCESS;
718e3744 21230}
21231
7336e101
SP
21232DEFUN (extcommunity_list_name_expanded,
21233 bgp_extcommunity_list_name_expanded_cmd,
a2099c1d 21234 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21235 BGP_STR
21236 EXTCOMMUNITY_LIST_STR
5bf15956 21237 "Extended Community list number (expanded)\n"
718e3744 21238 "Specify expanded extcommunity-list\n"
21239 "Extended Community list name\n"
2f8cc0e5
DA
21240 "Sequence number of an entry\n"
21241 "Sequence number\n"
718e3744 21242 "Specify community to reject\n"
21243 "Specify community to accept\n"
21244 "An ordered list as a regular-expression\n")
21245{
d62a17ae 21246 int style = EXTCOMMUNITY_LIST_EXPANDED;
21247 int direct = 0;
21248 char *cl_number_or_name = NULL;
2f8cc0e5 21249 char *seq = NULL;
d62a17ae 21250 int idx = 0;
7336e101 21251
d62a17ae 21252 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 21253 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21254 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 21255
a08032fe 21256 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21257 seq = argv[idx]->arg;
21258
d62a17ae 21259 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21260 : COMMUNITY_DENY;
21261 argv_find(argv, argc, "LINE", &idx);
21262 char *str = argv_concat(argv, argc, idx);
42f914d4 21263
2f8cc0e5 21264 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 21265 direct, style);
42f914d4 21266
d62a17ae 21267 XFREE(MTYPE_TMP, str);
42f914d4 21268
d62a17ae 21269 if (ret < 0) {
21270 community_list_perror(vty, ret);
21271 return CMD_WARNING_CONFIG_FAILED;
21272 }
42f914d4 21273
d62a17ae 21274 return CMD_SUCCESS;
718e3744 21275}
21276
7336e101
SP
21277DEFUN (no_extcommunity_list_standard_all,
21278 no_bgp_extcommunity_list_standard_all_cmd,
a2099c1d 21279 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
21280 NO_STR
21281 BGP_STR
21282 EXTCOMMUNITY_LIST_STR
813d4307 21283 "Extended Community list number (standard)\n"
718e3744 21284 "Specify standard extcommunity-list\n"
5bf15956 21285 "Community list name\n"
2f8cc0e5
DA
21286 "Sequence number of an entry\n"
21287 "Sequence number\n"
718e3744 21288 "Specify community to reject\n"
21289 "Specify community to accept\n"
21290 EXTCOMMUNITY_VAL_STR)
21291{
d62a17ae 21292 int style = EXTCOMMUNITY_LIST_STANDARD;
21293 int direct = 0;
21294 char *cl_number_or_name = NULL;
d4455c89 21295 char *str = NULL;
2f8cc0e5 21296 char *seq = NULL;
d62a17ae 21297 int idx = 0;
d4455c89 21298
a08032fe 21299 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21300 seq = argv[idx]->arg;
21301
21302 idx = 0;
d4455c89
DA
21303 argv_find(argv, argc, "permit", &idx);
21304 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
21305 if (idx) {
21306 direct = argv_find(argv, argc, "permit", &idx)
21307 ? COMMUNITY_PERMIT
21308 : COMMUNITY_DENY;
21309
21310 idx = 0;
21311 argv_find(argv, argc, "AA:NN", &idx);
21312 str = argv_concat(argv, argc, idx);
21313 }
21314
21315 idx = 0;
d62a17ae 21316 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 21317 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21318 cl_number_or_name = argv[idx]->arg;
42f914d4 21319
d62a17ae 21320 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 21321 seq, direct, style);
42f914d4 21322
d62a17ae 21323 XFREE(MTYPE_TMP, str);
42f914d4 21324
d62a17ae 21325 if (ret < 0) {
21326 community_list_perror(vty, ret);
21327 return CMD_WARNING_CONFIG_FAILED;
21328 }
42f914d4 21329
d62a17ae 21330 return CMD_SUCCESS;
718e3744 21331}
21332
d4455c89
DA
21333ALIAS(no_extcommunity_list_standard_all,
21334 no_bgp_extcommunity_list_standard_all_list_cmd,
a2099c1d 21335 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
36d4bb44 21336 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
21337 "Extended Community list number (standard)\n"
21338 "Specify standard extcommunity-list\n"
21339 "Community list name\n")
21340
7336e101
SP
21341DEFUN (no_extcommunity_list_expanded_all,
21342 no_bgp_extcommunity_list_expanded_all_cmd,
a2099c1d 21343 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21344 NO_STR
21345 BGP_STR
21346 EXTCOMMUNITY_LIST_STR
718e3744 21347 "Extended Community list number (expanded)\n"
718e3744 21348 "Specify expanded extcommunity-list\n"
5bf15956 21349 "Extended Community list name\n"
2f8cc0e5
DA
21350 "Sequence number of an entry\n"
21351 "Sequence number\n"
718e3744 21352 "Specify community to reject\n"
21353 "Specify community to accept\n"
21354 "An ordered list as a regular-expression\n")
21355{
d62a17ae 21356 int style = EXTCOMMUNITY_LIST_EXPANDED;
21357 int direct = 0;
21358 char *cl_number_or_name = NULL;
d4455c89 21359 char *str = NULL;
2f8cc0e5 21360 char *seq = NULL;
d62a17ae 21361 int idx = 0;
d4455c89 21362
a08032fe 21363 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21364 seq = argv[idx]->arg;
21365
21366 idx = 0;
d4455c89
DA
21367 argv_find(argv, argc, "permit", &idx);
21368 argv_find(argv, argc, "deny", &idx);
21369
21370 if (idx) {
21371 direct = argv_find(argv, argc, "permit", &idx)
21372 ? COMMUNITY_PERMIT
21373 : COMMUNITY_DENY;
21374
21375 idx = 0;
21376 argv_find(argv, argc, "LINE", &idx);
21377 str = argv_concat(argv, argc, idx);
21378 }
21379
21380 idx = 0;
d62a17ae 21381 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 21382 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21383 cl_number_or_name = argv[idx]->arg;
42f914d4 21384
d62a17ae 21385 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 21386 seq, direct, style);
42f914d4 21387
d62a17ae 21388 XFREE(MTYPE_TMP, str);
42f914d4 21389
d62a17ae 21390 if (ret < 0) {
21391 community_list_perror(vty, ret);
21392 return CMD_WARNING_CONFIG_FAILED;
21393 }
42f914d4 21394
d62a17ae 21395 return CMD_SUCCESS;
718e3744 21396}
21397
d4455c89
DA
21398ALIAS(no_extcommunity_list_expanded_all,
21399 no_bgp_extcommunity_list_expanded_all_list_cmd,
a2099c1d 21400 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
36d4bb44 21401 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
21402 "Extended Community list number (expanded)\n"
21403 "Specify expanded extcommunity-list\n"
21404 "Extended Community list name\n")
21405
d62a17ae 21406static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 21407{
d62a17ae 21408 struct community_entry *entry;
718e3744 21409
d62a17ae 21410 for (entry = list->head; entry; entry = entry->next) {
21411 if (entry == list->head) {
21412 if (all_digit(list->name))
21413 vty_out(vty, "Extended community %s list %s\n",
21414 entry->style == EXTCOMMUNITY_LIST_STANDARD
21415 ? "standard"
21416 : "(expanded) access",
21417 list->name);
21418 else
21419 vty_out(vty,
21420 "Named extended community %s list %s\n",
21421 entry->style == EXTCOMMUNITY_LIST_STANDARD
21422 ? "standard"
21423 : "expanded",
21424 list->name);
21425 }
21426 if (entry->any)
21427 vty_out(vty, " %s\n",
21428 community_direct_str(entry->direct));
21429 else
21430 vty_out(vty, " %s %s\n",
21431 community_direct_str(entry->direct),
8d9b8ed9 21432 community_list_config_str(entry));
d62a17ae 21433 }
718e3744 21434}
21435
7336e101
SP
21436DEFUN (show_extcommunity_list,
21437 show_bgp_extcommunity_list_cmd,
21438 "show bgp extcommunity-list",
718e3744 21439 SHOW_STR
7336e101 21440 BGP_STR
718e3744 21441 "List extended-community list\n")
21442{
d62a17ae 21443 struct community_list *list;
21444 struct community_list_master *cm;
718e3744 21445
d62a17ae 21446 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21447 if (!cm)
21448 return CMD_SUCCESS;
718e3744 21449
d62a17ae 21450 for (list = cm->num.head; list; list = list->next)
21451 extcommunity_list_show(vty, list);
718e3744 21452
d62a17ae 21453 for (list = cm->str.head; list; list = list->next)
21454 extcommunity_list_show(vty, list);
718e3744 21455
d62a17ae 21456 return CMD_SUCCESS;
718e3744 21457}
21458
7336e101
SP
21459DEFUN (show_extcommunity_list_arg,
21460 show_bgp_extcommunity_list_arg_cmd,
a2099c1d 21461 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
7336e101
SP
21462 SHOW_STR
21463 BGP_STR
718e3744 21464 "List extended-community list\n"
21465 "Extcommunity-list number\n"
960b69b9 21466 "Extcommunity-list name\n"
21467 "Detailed information on extcommunity-list\n")
718e3744 21468{
d62a17ae 21469 int idx_comm_list = 3;
21470 struct community_list *list;
718e3744 21471
e237b0d2 21472 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 21473 EXTCOMMUNITY_LIST_MASTER);
21474 if (!list) {
21475 vty_out(vty, "%% Can't find extcommunity-list\n");
21476 return CMD_WARNING;
21477 }
718e3744 21478
d62a17ae 21479 extcommunity_list_show(vty, list);
718e3744 21480
d62a17ae 21481 return CMD_SUCCESS;
718e3744 21482}
6b0655a2 21483
718e3744 21484/* Display community-list and extcommunity-list configuration. */
d62a17ae 21485static int community_list_config_write(struct vty *vty)
21486{
21487 struct community_list *list;
21488 struct community_entry *entry;
21489 struct community_list_master *cm;
21490 int write = 0;
21491
21492 /* Community-list. */
21493 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
21494
21495 for (list = cm->num.head; list; list = list->next)
21496 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21497 vty_out(vty,
21498 "bgp community-list %s seq %" PRId64 " %s %s\n",
21499 list->name, entry->seq,
d62a17ae 21500 community_direct_str(entry->direct),
21501 community_list_config_str(entry));
21502 write++;
21503 }
21504 for (list = cm->str.head; list; list = list->next)
21505 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21506 vty_out(vty,
21507 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 21508 entry->style == COMMUNITY_LIST_STANDARD
21509 ? "standard"
21510 : "expanded",
2f8cc0e5
DA
21511 list->name, entry->seq,
21512 community_direct_str(entry->direct),
d62a17ae 21513 community_list_config_str(entry));
21514 write++;
21515 }
21516
21517 /* Extcommunity-list. */
21518 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21519
21520 for (list = cm->num.head; list; list = list->next)
21521 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21522 vty_out(vty,
21523 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
21524 list->name, entry->seq,
21525 community_direct_str(entry->direct),
d62a17ae 21526 community_list_config_str(entry));
21527 write++;
21528 }
21529 for (list = cm->str.head; list; list = list->next)
21530 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21531 vty_out(vty,
6cde4b45 21532 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 21533 entry->style == EXTCOMMUNITY_LIST_STANDARD
21534 ? "standard"
21535 : "expanded",
2f8cc0e5
DA
21536 list->name, entry->seq,
21537 community_direct_str(entry->direct),
d62a17ae 21538 community_list_config_str(entry));
21539 write++;
21540 }
21541
21542
21543 /* lcommunity-list. */
21544 cm = community_list_master_lookup(bgp_clist,
21545 LARGE_COMMUNITY_LIST_MASTER);
21546
21547 for (list = cm->num.head; list; list = list->next)
21548 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21549 vty_out(vty,
6cde4b45 21550 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
21551 list->name, entry->seq,
21552 community_direct_str(entry->direct),
d62a17ae 21553 community_list_config_str(entry));
21554 write++;
21555 }
21556 for (list = cm->str.head; list; list = list->next)
21557 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21558 vty_out(vty,
6cde4b45 21559 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 21560
d62a17ae 21561 entry->style == LARGE_COMMUNITY_LIST_STANDARD
21562 ? "standard"
21563 : "expanded",
2f8cc0e5 21564 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 21565 community_list_config_str(entry));
21566 write++;
21567 }
21568
21569 return write;
21570}
21571
612c2c15 21572static int community_list_config_write(struct vty *vty);
d62a17ae 21573static struct cmd_node community_list_node = {
f4b8291f 21574 .name = "community list",
62b346ee
DL
21575 .node = COMMUNITY_LIST_NODE,
21576 .prompt = "",
612c2c15 21577 .config_write = community_list_config_write,
718e3744 21578};
21579
d62a17ae 21580static void community_list_vty(void)
21581{
612c2c15 21582 install_node(&community_list_node);
d62a17ae 21583
21584 /* Community-list. */
7336e101
SP
21585 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
21586 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
21587 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 21588 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 21589 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 21590 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
21591 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
21592 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 21593
21594 /* Extcommunity-list. */
7336e101
SP
21595 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
21596 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
21597 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
21598 install_element(CONFIG_NODE,
21599 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 21600 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
21601 install_element(CONFIG_NODE,
21602 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
21603 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
21604 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 21605
21606 /* Large Community List */
7336e101 21607 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
21608 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
21609 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 21610 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
21611 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
21612 install_element(CONFIG_NODE,
21613 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
21614 install_element(CONFIG_NODE,
21615 &no_bgp_lcommunity_list_name_expanded_all_cmd);
21616 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
21617 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
21618 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
21619 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
21620 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
21621 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
225096bc
DA
21622
21623 bgp_community_list_command_completion_setup();
5bf15956 21624}
ed0e57e3
DA
21625
21626static struct cmd_node community_alias_node = {
21627 .name = "community alias",
21628 .node = COMMUNITY_ALIAS_NODE,
21629 .prompt = "",
21630 .config_write = bgp_community_alias_write,
21631};
21632
21633void community_alias_vty(void)
21634{
21635 install_node(&community_alias_node);
21636
21637 /* Community-list. */
21638 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
b4ad2fae
DS
21639
21640 bgp_community_alias_command_completion_setup();
ed0e57e3 21641}