]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
topotests: apply bgp maximum-prefix-out without clearing the neighbor
[mirror_frr.git] / bgpd / bgp_vty.c
CommitLineData
718e3744 1/* BGP VTY interface.
896014f4
DL
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 20
21#include <zebra.h>
22
23#include "command.h"
afec25d9 24#include "lib/json.h"
4ab46701 25#include "lib/sockopt.h"
5cb5f4d0 26#include "lib_errors.h"
ec0ab544 27#include "lib/zclient.h"
6f4eacf3 28#include "lib/printfrr.h"
718e3744 29#include "prefix.h"
30#include "plist.h"
31#include "buffer.h"
32#include "linklist.h"
33#include "stream.h"
34#include "thread.h"
35#include "log.h"
3b8b1855 36#include "memory.h"
1c0d8808 37#include "lib_vty.h"
4bf6a362 38#include "hash.h"
3f9c7369 39#include "queue.h"
039f3a34 40#include "filter.h"
5d5ba018 41#include "frrstr.h"
718e3744 42
43#include "bgpd/bgpd.h"
48ecf8f5 44#include "bgpd/bgp_attr_evpn.h"
4bf6a362 45#include "bgpd/bgp_advertise.h"
718e3744 46#include "bgpd/bgp_attr.h"
47#include "bgpd/bgp_aspath.h"
48#include "bgpd/bgp_community.h"
ed0e57e3 49#include "bgpd/bgp_community_alias.h"
4bf6a362 50#include "bgpd/bgp_ecommunity.h"
57d187bc 51#include "bgpd/bgp_lcommunity.h"
4bf6a362 52#include "bgpd/bgp_damp.h"
718e3744 53#include "bgpd/bgp_debug.h"
14454c9f 54#include "bgpd/bgp_errors.h"
e0701b79 55#include "bgpd/bgp_fsm.h"
4bf6a362 56#include "bgpd/bgp_nexthop.h"
718e3744 57#include "bgpd/bgp_open.h"
4bf6a362 58#include "bgpd/bgp_regex.h"
718e3744 59#include "bgpd/bgp_route.h"
c016b6c7 60#include "bgpd/bgp_mplsvpn.h"
718e3744 61#include "bgpd/bgp_zebra.h"
fee0f4c6 62#include "bgpd/bgp_table.h"
94f2b392 63#include "bgpd/bgp_vty.h"
165b5fff 64#include "bgpd/bgp_mpath.h"
cb1faec9 65#include "bgpd/bgp_packet.h"
3f9c7369 66#include "bgpd/bgp_updgrp.h"
c43ed2e4 67#include "bgpd/bgp_bfd.h"
555e09d4 68#include "bgpd/bgp_io.h"
94c2f693 69#include "bgpd/bgp_evpn.h"
dd65f45e 70#include "bgpd/bgp_evpn_vty.h"
b5e140c8 71#include "bgpd/bgp_evpn_mh.h"
dcc68b5e 72#include "bgpd/bgp_addpath.h"
48ecf8f5 73#include "bgpd/bgp_mac.h"
dd65f45e 74#include "bgpd/bgp_flowspec.h"
389e4f92 75#include "bgpd/bgp_conditional_adv.h"
49e5a4a0 76#ifdef ENABLE_BGP_VNC
dd65f45e
DL
77#include "bgpd/rfapi/bgp_rfapi_cfg.h"
78#endif
79
5d5393b9 80FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
62282e83
DS
81 {
82 .val_bool = false,
83 .match_profile = "traditional",
84 .match_version = "< 7.4",
85 },
86 { .val_bool = true },
67b0f40c 87);
5d5393b9 88FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
4c1458b5
DL
89 { .val_bool = true, .match_profile = "datacenter", },
90 { .val_bool = false },
67b0f40c 91);
aef999a2
DA
92FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
93 { .val_bool = true, .match_profile = "datacenter", },
94 { .val_bool = false },
67b0f40c 95);
5d5393b9 96FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
4c1458b5
DL
97 { .val_bool = true, .match_profile = "datacenter", },
98 { .val_bool = false },
67b0f40c 99);
5d5393b9 100FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
4c1458b5
DL
101 { .val_bool = true, .match_profile = "datacenter", },
102 { .val_bool = false },
67b0f40c 103);
5d5393b9
DL
104FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
105 { .val_ulong = 10, .match_profile = "datacenter", },
106 { .val_ulong = 120 },
67b0f40c 107);
5d5393b9
DL
108FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
109 { .val_ulong = 9, .match_profile = "datacenter", },
110 { .val_ulong = 180 },
67b0f40c 111);
5d5393b9
DL
112FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
113 { .val_ulong = 3, .match_profile = "datacenter", },
114 { .val_ulong = 60 },
67b0f40c 115);
1d3fdccf
DA
116FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
117 { .val_bool = false, .match_profile = "datacenter", },
118 { .val_bool = false, .match_version = "< 7.4", },
119 { .val_bool = true },
67b0f40c 120);
2adac256
DA
121FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
122 { .val_bool = false, .match_version = "< 7.6", },
123 { .val_bool = true },
67b0f40c 124);
5d5393b9 125
dd65f45e
DL
126DEFINE_HOOK(bgp_inst_config_write,
127 (struct bgp *bgp, struct vty *vty),
8451921b
DL
128 (bgp, vty));
129DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
1ca2fd11 130DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
718e3744 131
d62a17ae 132static struct peer_group *listen_range_exists(struct bgp *bgp,
133 struct prefix *range, int exact);
134
055679e9 135/* Show BGP peer's information. */
136enum show_type {
137 show_all,
138 show_peer,
139 show_ipv4_all,
140 show_ipv6_all,
141 show_ipv4_peer,
142 show_ipv6_peer
143};
144
36235319
QY
145static struct peer_group *listen_range_exists(struct bgp *bgp,
146 struct prefix *range, int exact);
2986cac2 147
36235319
QY
148static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
149 struct bgp *bgp,
150 bool use_json,
151 json_object *json);
2986cac2 152
36235319
QY
153static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
154 enum show_type type,
155 const char *ip_str,
156 afi_t afi, bool use_json);
2986cac2 157
d62a17ae 158static enum node_type bgp_node_type(afi_t afi, safi_t safi)
159{
160 switch (afi) {
161 case AFI_IP:
162 switch (safi) {
163 case SAFI_UNICAST:
164 return BGP_IPV4_NODE;
d62a17ae 165 case SAFI_MULTICAST:
166 return BGP_IPV4M_NODE;
d62a17ae 167 case SAFI_LABELED_UNICAST:
168 return BGP_IPV4L_NODE;
d62a17ae 169 case SAFI_MPLS_VPN:
170 return BGP_VPNV4_NODE;
7c40bf39 171 case SAFI_FLOWSPEC:
172 return BGP_FLOWSPECV4_NODE;
5c525538
RW
173 default:
174 /* not expected */
175 return BGP_IPV4_NODE;
d62a17ae 176 }
177 break;
178 case AFI_IP6:
179 switch (safi) {
180 case SAFI_UNICAST:
181 return BGP_IPV6_NODE;
d62a17ae 182 case SAFI_MULTICAST:
183 return BGP_IPV6M_NODE;
d62a17ae 184 case SAFI_LABELED_UNICAST:
185 return BGP_IPV6L_NODE;
d62a17ae 186 case SAFI_MPLS_VPN:
187 return BGP_VPNV6_NODE;
7c40bf39 188 case SAFI_FLOWSPEC:
189 return BGP_FLOWSPECV6_NODE;
5c525538
RW
190 default:
191 /* not expected */
192 return BGP_IPV4_NODE;
d62a17ae 193 }
194 break;
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;
290 struct prefix_ipv6 *chunk;
291 struct bgp_srv6_function *func;
292 struct bgp *bgp_vrf;
293 struct in6_addr *tovpn_sid;
294
295 /* release chunk notification via ZAPI */
296 ret = bgp_zebra_srv6_manager_release_locator_chunk(
297 bgp->srv6_locator_name);
298 if (ret < 0)
299 return -1;
300
301 /* refresh chunks */
302 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk))
303 listnode_delete(bgp->srv6_locator_chunks, chunk);
304
305 /* refresh functions */
306 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func))
307 listnode_delete(bgp->srv6_functions, func);
308
309 /* refresh tovpn_sid */
310 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
311 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
312 continue;
313
314 /* refresh vpnv4 tovpn_sid */
315 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP].tovpn_sid;
316 if (tovpn_sid)
317 XFREE(MTYPE_BGP_SRV6_SID,
318 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
319
320 /* refresh vpnv6 tovpn_sid */
321 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid;
322 if (tovpn_sid)
323 XFREE(MTYPE_BGP_SRV6_SID,
324 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
325 }
326
327 /* update vpn bgp processes */
328 vpn_leak_postchange_all();
329
330 /* clear locator name */
331 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
332
333 return 0;
334}
335
718e3744 336/* Utility function to get address family from current node. */
d62a17ae 337afi_t bgp_node_afi(struct vty *vty)
338{
339 afi_t afi;
340 switch (vty->node) {
341 case BGP_IPV6_NODE:
342 case BGP_IPV6M_NODE:
343 case BGP_IPV6L_NODE:
344 case BGP_VPNV6_NODE:
7c40bf39 345 case BGP_FLOWSPECV6_NODE:
d62a17ae 346 afi = AFI_IP6;
347 break;
348 case BGP_EVPN_NODE:
349 afi = AFI_L2VPN;
350 break;
351 default:
352 afi = AFI_IP;
353 break;
354 }
355 return afi;
718e3744 356}
357
358/* Utility function to get subsequent address family from current
359 node. */
d62a17ae 360safi_t bgp_node_safi(struct vty *vty)
361{
362 safi_t safi;
363 switch (vty->node) {
364 case BGP_VPNV4_NODE:
365 case BGP_VPNV6_NODE:
366 safi = SAFI_MPLS_VPN;
367 break;
368 case BGP_IPV4M_NODE:
369 case BGP_IPV6M_NODE:
370 safi = SAFI_MULTICAST;
371 break;
372 case BGP_EVPN_NODE:
373 safi = SAFI_EVPN;
374 break;
375 case BGP_IPV4L_NODE:
376 case BGP_IPV6L_NODE:
377 safi = SAFI_LABELED_UNICAST;
378 break;
7c40bf39 379 case BGP_FLOWSPECV4_NODE:
380 case BGP_FLOWSPECV6_NODE:
381 safi = SAFI_FLOWSPEC;
382 break;
d62a17ae 383 default:
384 safi = SAFI_UNICAST;
385 break;
386 }
387 return safi;
718e3744 388}
389
55f91488
QY
390/**
391 * Converts an AFI in string form to afi_t
392 *
393 * @param afi string, one of
394 * - "ipv4"
395 * - "ipv6"
81cf0de5 396 * - "l2vpn"
55f91488
QY
397 * @return the corresponding afi_t
398 */
d62a17ae 399afi_t bgp_vty_afi_from_str(const char *afi_str)
400{
401 afi_t afi = AFI_MAX; /* unknown */
402 if (strmatch(afi_str, "ipv4"))
403 afi = AFI_IP;
404 else if (strmatch(afi_str, "ipv6"))
405 afi = AFI_IP6;
81cf0de5
CS
406 else if (strmatch(afi_str, "l2vpn"))
407 afi = AFI_L2VPN;
d62a17ae 408 return afi;
409}
410
411int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
412 afi_t *afi)
413{
414 int ret = 0;
415 if (argv_find(argv, argc, "ipv4", index)) {
416 ret = 1;
417 if (afi)
418 *afi = AFI_IP;
419 } else if (argv_find(argv, argc, "ipv6", index)) {
420 ret = 1;
421 if (afi)
422 *afi = AFI_IP6;
8688b3e7
DS
423 } else if (argv_find(argv, argc, "l2vpn", index)) {
424 ret = 1;
425 if (afi)
426 *afi = AFI_L2VPN;
d62a17ae 427 }
428 return ret;
46f296b4
LB
429}
430
375a2e67 431/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 432safi_t bgp_vty_safi_from_str(const char *safi_str)
433{
434 safi_t safi = SAFI_MAX; /* unknown */
435 if (strmatch(safi_str, "multicast"))
436 safi = SAFI_MULTICAST;
437 else if (strmatch(safi_str, "unicast"))
438 safi = SAFI_UNICAST;
439 else if (strmatch(safi_str, "vpn"))
440 safi = SAFI_MPLS_VPN;
81cf0de5
CS
441 else if (strmatch(safi_str, "evpn"))
442 safi = SAFI_EVPN;
d62a17ae 443 else if (strmatch(safi_str, "labeled-unicast"))
444 safi = SAFI_LABELED_UNICAST;
7c40bf39 445 else if (strmatch(safi_str, "flowspec"))
446 safi = SAFI_FLOWSPEC;
d62a17ae 447 return safi;
448}
449
450int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
451 safi_t *safi)
452{
453 int ret = 0;
454 if (argv_find(argv, argc, "unicast", index)) {
455 ret = 1;
456 if (safi)
457 *safi = SAFI_UNICAST;
458 } else if (argv_find(argv, argc, "multicast", index)) {
459 ret = 1;
460 if (safi)
461 *safi = SAFI_MULTICAST;
462 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
463 ret = 1;
464 if (safi)
465 *safi = SAFI_LABELED_UNICAST;
466 } else if (argv_find(argv, argc, "vpn", index)) {
467 ret = 1;
468 if (safi)
469 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
470 } else if (argv_find(argv, argc, "evpn", index)) {
471 ret = 1;
472 if (safi)
473 *safi = SAFI_EVPN;
7c40bf39 474 } else if (argv_find(argv, argc, "flowspec", index)) {
475 ret = 1;
476 if (safi)
477 *safi = SAFI_FLOWSPEC;
d62a17ae 478 }
479 return ret;
46f296b4
LB
480}
481
b16bcbba
TA
482/*
483 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
484 *
485 * afi
486 * address-family identifier
487 *
488 * safi
489 * subsequent address-family identifier
490 *
491 * Returns:
492 * default_af string corresponding to the supplied afi/safi pair.
493 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
494 * return -1.
495 */
496static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
497{
498 switch (afi) {
499 case AFI_IP:
500 switch (safi) {
501 case SAFI_UNICAST:
502 return "ipv4-unicast";
503 case SAFI_MULTICAST:
504 return "ipv4-multicast";
505 case SAFI_MPLS_VPN:
506 return "ipv4-vpn";
507 case SAFI_ENCAP:
508 return "ipv4-encap";
509 case SAFI_LABELED_UNICAST:
510 return "ipv4-labeled-unicast";
511 case SAFI_FLOWSPEC:
512 return "ipv4-flowspec";
513 default:
514 return "unknown-afi/safi";
515 }
516 break;
517 case AFI_IP6:
518 switch (safi) {
519 case SAFI_UNICAST:
520 return "ipv6-unicast";
521 case SAFI_MULTICAST:
522 return "ipv6-multicast";
523 case SAFI_MPLS_VPN:
524 return "ipv6-vpn";
525 case SAFI_ENCAP:
526 return "ipv6-encap";
527 case SAFI_LABELED_UNICAST:
528 return "ipv6-labeled-unicast";
529 case SAFI_FLOWSPEC:
530 return "ipv6-flowspec";
531 default:
532 return "unknown-afi/safi";
533 }
534 break;
535 case AFI_L2VPN:
536 switch (safi) {
537 case SAFI_EVPN:
538 return "l2vpn-evpn";
539 default:
540 return "unknown-afi/safi";
541 }
542 case AFI_UNSPEC:
543 case AFI_MAX:
544 return "unknown-afi/safi";
545 }
546 /* all AFIs are accounted for above, so this shouldn't happen */
547 return "unknown-afi/safi";
548}
549
5d5393b9
DL
550int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
551 enum bgp_instance_type inst_type)
552{
553 int ret = bgp_get(bgp, as, name, inst_type);
554
555 if (ret == BGP_CREATED) {
556 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
d43114f3 557 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
5d5393b9
DL
558
559 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 560 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 561 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 562 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
563 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
564 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 565 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 566 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 567 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 568 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
569 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
570 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2adac256
DA
571 if (DFLT_BGP_SUPPRESS_DUPLICATES)
572 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
5d5393b9
DL
573
574 ret = BGP_SUCCESS;
575 }
576 return ret;
577}
578
7eeee51e 579/*
f212a857 580 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 581 *
f212a857
DS
582 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
583 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
584 * to appropriate values for the calling function. This is to allow the
585 * calling function to make decisions appropriate for the show command
586 * that is being parsed.
587 *
588 * The show commands are generally of the form:
d62a17ae 589 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
590 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
591 *
592 * Since we use argv_find if the show command in particular doesn't have:
593 * [ip]
18c57037 594 * [<view|vrf> VIEWVRFNAME]
375a2e67 595 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
596 * The command parsing should still be ok.
597 *
598 * vty -> The vty for the command so we can output some useful data in
599 * the event of a parse error in the vrf.
600 * argv -> The command tokens
601 * argc -> How many command tokens we have
d62a17ae 602 * idx -> The current place in the command, generally should be 0 for this
603 * function
7eeee51e
DS
604 * afi -> The parsed afi if it was included in the show command, returned here
605 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 606 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 607 * use_json -> json is configured or not
7eeee51e
DS
608 *
609 * The function returns the correct location in the parse tree for the
610 * last token found.
0e37c258
DS
611 *
612 * Returns 0 for failure to parse correctly, else the idx position of where
613 * it found the last token.
7eeee51e 614 */
d62a17ae 615int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
616 struct cmd_token **argv, int argc,
617 int *idx, afi_t *afi, safi_t *safi,
9f049418 618 struct bgp **bgp, bool use_json)
d62a17ae 619{
620 char *vrf_name = NULL;
621
622 assert(afi);
623 assert(safi);
624 assert(bgp);
625
626 if (argv_find(argv, argc, "ip", idx))
627 *afi = AFI_IP;
628
9a8bdf1c 629 if (argv_find(argv, argc, "view", idx))
d62a17ae 630 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
631 else if (argv_find(argv, argc, "vrf", idx)) {
632 vrf_name = argv[*idx + 1]->arg;
633 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
634 vrf_name = NULL;
635 }
636 if (vrf_name) {
d62a17ae 637 if (strmatch(vrf_name, "all"))
638 *bgp = NULL;
639 else {
640 *bgp = bgp_lookup_by_name(vrf_name);
641 if (!*bgp) {
52e5b8c4
SP
642 if (use_json) {
643 json_object *json = NULL;
644 json = json_object_new_object();
645 json_object_string_add(
646 json, "warning",
647 "View/Vrf is unknown");
75eeda93 648 vty_json(vty, json);
52e5b8c4 649 }
ca61fd25
DS
650 else
651 vty_out(vty, "View/Vrf %s is unknown\n",
652 vrf_name);
d62a17ae 653 *idx = 0;
654 return 0;
655 }
656 }
657 } else {
658 *bgp = bgp_get_default();
659 if (!*bgp) {
52e5b8c4
SP
660 if (use_json) {
661 json_object *json = NULL;
662 json = json_object_new_object();
663 json_object_string_add(
664 json, "warning",
665 "Default BGP instance not found");
75eeda93 666 vty_json(vty, json);
52e5b8c4 667 }
ca61fd25
DS
668 else
669 vty_out(vty,
670 "Default BGP instance not found\n");
d62a17ae 671 *idx = 0;
672 return 0;
673 }
674 }
675
676 if (argv_find_and_parse_afi(argv, argc, idx, afi))
677 argv_find_and_parse_safi(argv, argc, idx, safi);
678
679 *idx += 1;
680 return *idx;
681}
682
28c6e247 683static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 684{
685 struct interface *ifp = NULL;
686
687 if (su->sa.sa_family == AF_INET)
688 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
689 else if (su->sa.sa_family == AF_INET6)
690 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
691 su->sin6.sin6_scope_id,
692 bgp->vrf_id);
693
694 if (ifp)
3dc339cd 695 return true;
d62a17ae 696
3dc339cd 697 return false;
718e3744 698}
699
28c6e247
IR
700/* Utility function for looking up peer from VTY. */
701/* This is used only for configuration, so disallow if attempted on
702 * a dynamic neighbor.
703 */
704static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
705{
706 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
707 int ret;
708 union sockunion su;
709 struct peer *peer;
710
711 if (!bgp) {
712 return NULL;
713 }
714
715 ret = str2sockunion(ip_str, &su);
716 if (ret < 0) {
717 peer = peer_lookup_by_conf_if(bgp, ip_str);
718 if (!peer) {
719 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
720 == NULL) {
721 vty_out(vty,
722 "%% Malformed address or name: %s\n",
723 ip_str);
724 return NULL;
725 }
726 }
727 } else {
728 peer = peer_lookup(bgp, &su);
729 if (!peer) {
730 vty_out(vty,
731 "%% Specify remote-as or peer-group commands first\n");
732 return NULL;
733 }
734 if (peer_dynamic_neighbor(peer)) {
735 vty_out(vty,
736 "%% Operation not allowed on a dynamic neighbor\n");
737 return NULL;
738 }
739 }
740 return peer;
741}
742
718e3744 743/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
744/* This is used only for configuration, so disallow if attempted on
745 * a dynamic neighbor.
746 */
d62a17ae 747struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
748{
749 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
750 int ret;
751 union sockunion su;
752 struct peer *peer = NULL;
753 struct peer_group *group = NULL;
754
755 if (!bgp) {
756 return NULL;
757 }
758
759 ret = str2sockunion(peer_str, &su);
760 if (ret == 0) {
761 /* IP address, locate peer. */
762 peer = peer_lookup(bgp, &su);
763 } else {
764 /* Not IP, could match either peer configured on interface or a
765 * group. */
766 peer = peer_lookup_by_conf_if(bgp, peer_str);
767 if (!peer)
768 group = peer_group_lookup(bgp, peer_str);
769 }
770
771 if (peer) {
772 if (peer_dynamic_neighbor(peer)) {
773 vty_out(vty,
774 "%% Operation not allowed on a dynamic neighbor\n");
775 return NULL;
776 }
777
778 return peer;
779 }
780
781 if (group)
782 return group->conf;
783
784 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
785
786 return NULL;
787}
788
789int bgp_vty_return(struct vty *vty, int ret)
790{
791 const char *str = NULL;
792
793 switch (ret) {
794 case BGP_ERR_INVALID_VALUE:
795 str = "Invalid value";
796 break;
797 case BGP_ERR_INVALID_FLAG:
798 str = "Invalid flag";
799 break;
800 case BGP_ERR_PEER_GROUP_SHUTDOWN:
801 str = "Peer-group has been shutdown. Activate the peer-group first";
802 break;
803 case BGP_ERR_PEER_FLAG_CONFLICT:
804 str = "Can't set override-capability and strict-capability-match at the same time";
805 break;
806 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
807 str = "Specify remote-as or peer-group remote AS first";
808 break;
809 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
810 str = "Cannot change the peer-group. Deconfigure first";
811 break;
812 case BGP_ERR_PEER_GROUP_MISMATCH:
813 str = "Peer is not a member of this peer-group";
814 break;
815 case BGP_ERR_PEER_FILTER_CONFLICT:
816 str = "Prefix/distribute list can not co-exist";
817 break;
818 case BGP_ERR_NOT_INTERNAL_PEER:
819 str = "Invalid command. Not an internal neighbor";
820 break;
821 case BGP_ERR_REMOVE_PRIVATE_AS:
822 str = "remove-private-AS cannot be configured for IBGP peers";
823 break;
824 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
825 str = "Local-AS allowed only for EBGP peers";
826 break;
827 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
828 str = "Cannot have local-as same as BGP AS number";
829 break;
830 case BGP_ERR_TCPSIG_FAILED:
831 str = "Error while applying TCP-Sig to session(s)";
832 break;
833 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
834 str = "ebgp-multihop and ttl-security cannot be configured together";
835 break;
836 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
837 str = "ttl-security only allowed for EBGP peers";
838 break;
839 case BGP_ERR_AS_OVERRIDE:
840 str = "as-override cannot be configured for IBGP peers";
841 break;
842 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
843 str = "Invalid limit for number of dynamic neighbors";
844 break;
845 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
846 str = "Dynamic neighbor listen range already exists";
847 break;
848 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
849 str = "Operation not allowed on a dynamic neighbor";
850 break;
851 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
852 str = "Operation not allowed on a directly connected neighbor";
853 break;
854 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 855 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
055679e9 856 break;
857 case BGP_ERR_GR_INVALID_CMD:
858 str = "The Graceful Restart command used is not valid at this moment.";
859 break;
860 case BGP_ERR_GR_OPERATION_FAILED:
861 str = "The Graceful Restart Operation failed due to an err.";
862 break;
d62a17ae 863 }
864 if (str) {
865 vty_out(vty, "%% %s\n", str);
866 return CMD_WARNING_CONFIG_FAILED;
867 }
868 return CMD_SUCCESS;
718e3744 869}
870
7aafcaca 871/* BGP clear sort. */
d62a17ae 872enum clear_sort {
873 clear_all,
874 clear_peer,
875 clear_group,
876 clear_external,
877 clear_as
7aafcaca
DS
878};
879
1ca2fd11
IR
880static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
881 safi_t safi, int error)
d62a17ae 882{
883 switch (error) {
884 case BGP_ERR_AF_UNCONFIGURED:
1ca2fd11
IR
885 vty_out(vty,
886 "%%BGP: Enable %s address family for the neighbor %s\n",
887 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 888 break;
889 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
1ca2fd11
IR
890 vty_out(vty,
891 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
d62a17ae 892 peer->host);
893 break;
894 default:
895 break;
896 }
7aafcaca
DS
897}
898
dc912615 899static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 900 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
901{
902 int ret = 0;
2adac256 903 struct peer_af *paf;
dc912615
DS
904
905 /* if afi/.safi not specified, spin thru all of them */
906 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
907 afi_t tmp_afi;
908 safi_t tmp_safi;
0e5cdd59
DS
909 enum bgp_af_index index;
910
911 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
912 paf = peer->peer_af_array[index];
913 if (!paf)
914 continue;
dc912615 915
2adac256
DA
916 if (paf && paf->subgroup)
917 SET_FLAG(paf->subgroup->sflags,
918 SUBGRP_STATUS_FORCE_UPDATES);
919
0e5cdd59
DS
920 tmp_afi = paf->afi;
921 tmp_safi = paf->safi;
dc912615
DS
922 if (!peer->afc[tmp_afi][tmp_safi])
923 continue;
924
925 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 926 ret = peer_clear(peer, nnode);
dc912615
DS
927 else
928 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
929 stype);
930 }
931 /* if afi specified and safi not, spin thru safis on this afi */
932 } else if (safi == SAFI_UNSPEC) {
933 safi_t tmp_safi;
934
935 for (tmp_safi = SAFI_UNICAST;
936 tmp_safi < SAFI_MAX; tmp_safi++) {
937 if (!peer->afc[afi][tmp_safi])
938 continue;
939
2adac256
DA
940 paf = peer_af_find(peer, afi, tmp_safi);
941 if (paf && paf->subgroup)
942 SET_FLAG(paf->subgroup->sflags,
943 SUBGRP_STATUS_FORCE_UPDATES);
944
dc912615 945 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 946 ret = peer_clear(peer, nnode);
dc912615
DS
947 else
948 ret = peer_clear_soft(peer, afi,
949 tmp_safi, stype);
950 }
951 /* both afi/safi specified, let the caller know if not defined */
952 } else {
953 if (!peer->afc[afi][safi])
954 return 1;
955
2adac256
DA
956 paf = peer_af_find(peer, afi, safi);
957 if (paf && paf->subgroup)
958 SET_FLAG(paf->subgroup->sflags,
959 SUBGRP_STATUS_FORCE_UPDATES);
960
dc912615 961 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 962 ret = peer_clear(peer, nnode);
dc912615
DS
963 else
964 ret = peer_clear_soft(peer, afi, safi, stype);
965 }
966
967 return ret;
968}
969
7aafcaca 970/* `clear ip bgp' functions. */
1ca2fd11 971static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 972 enum clear_sort sort, enum bgp_clear_type stype,
1ca2fd11 973 const char *arg)
d62a17ae 974{
dc912615 975 int ret = 0;
3ae8bfa5 976 bool found = false;
d62a17ae 977 struct peer *peer;
dc95985f 978
979 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 980
981 /* Clear all neighbors. */
982 /*
983 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
984 * nodes on the BGP instance as that may get freed if it is a
985 * doppelganger
d62a17ae 986 */
987 if (sort == clear_all) {
988 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 989
990 bgp_peer_gr_flags_update(peer);
991
36235319 992 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 993 gr_router_detected = true;
994
c368171c 995 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 996 stype);
d62a17ae 997
998 if (ret < 0)
1ca2fd11 999 bgp_clear_vty_error(vty, peer, afi, safi, ret);
dc95985f 1000 }
1001
36235319
QY
1002 if (gr_router_detected
1003 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1004 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1005 } else if (!gr_router_detected
1006 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1007 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 1008 }
d62a17ae 1009
1010 /* This is to apply read-only mode on this clear. */
1011 if (stype == BGP_CLEAR_SOFT_NONE)
1012 bgp->update_delay_over = 0;
1013
1014 return CMD_SUCCESS;
7aafcaca
DS
1015 }
1016
3ae8bfa5 1017 /* Clear specified neighbor. */
d62a17ae 1018 if (sort == clear_peer) {
1019 union sockunion su;
d62a17ae 1020
1021 /* Make sockunion for lookup. */
1022 ret = str2sockunion(arg, &su);
1023 if (ret < 0) {
1024 peer = peer_lookup_by_conf_if(bgp, arg);
1025 if (!peer) {
1026 peer = peer_lookup_by_hostname(bgp, arg);
1027 if (!peer) {
1ca2fd11
IR
1028 vty_out(vty,
1029 "Malformed address or name: %s\n",
d62a17ae 1030 arg);
1031 return CMD_WARNING;
1032 }
1033 }
1034 } else {
1035 peer = peer_lookup(bgp, &su);
1036 if (!peer) {
1ca2fd11
IR
1037 vty_out(vty,
1038 "%%BGP: Unknown neighbor - \"%s\"\n",
1039 arg);
d62a17ae 1040 return CMD_WARNING;
1041 }
1042 }
7aafcaca 1043
dc95985f 1044 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1045 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1046
dc912615
DS
1047 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1048
1049 /* if afi/safi not defined for this peer, let caller know */
1050 if (ret == 1)
3ae8bfa5 1051 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1052
d62a17ae 1053 if (ret < 0)
1ca2fd11 1054 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 1055
d62a17ae 1056 return CMD_SUCCESS;
7aafcaca 1057 }
7aafcaca 1058
3ae8bfa5 1059 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1060 if (sort == clear_group) {
1061 struct peer_group *group;
7aafcaca 1062
d62a17ae 1063 group = peer_group_lookup(bgp, arg);
1064 if (!group) {
1ca2fd11 1065 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
d62a17ae 1066 return CMD_WARNING;
1067 }
1068
1069 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1070 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1071
d62a17ae 1072 if (ret < 0)
1ca2fd11 1073 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1074 else
1075 found = true;
d62a17ae 1076 }
3ae8bfa5
PM
1077
1078 if (!found)
1ca2fd11
IR
1079 vty_out(vty,
1080 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 1081 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1082
d62a17ae 1083 return CMD_SUCCESS;
7aafcaca 1084 }
7aafcaca 1085
3ae8bfa5 1086 /* Clear all external (eBGP) neighbors. */
d62a17ae 1087 if (sort == clear_external) {
1088 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1089 if (peer->sort == BGP_PEER_IBGP)
1090 continue;
7aafcaca 1091
dc95985f 1092 bgp_peer_gr_flags_update(peer);
1093
36235319 1094 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1095 gr_router_detected = true;
dc95985f 1096
c368171c 1097 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1098
d62a17ae 1099 if (ret < 0)
1ca2fd11 1100 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1101 else
1102 found = true;
d62a17ae 1103 }
3ae8bfa5 1104
36235319
QY
1105 if (gr_router_detected
1106 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1107 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1108 } else if (!gr_router_detected
1109 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1110 bgp_zebra_send_capabilities(bgp, true);
1111 }
1112
3ae8bfa5 1113 if (!found)
1ca2fd11
IR
1114 vty_out(vty,
1115 "%%BGP: No external %s peer is configured\n",
1116 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1117
d62a17ae 1118 return CMD_SUCCESS;
1119 }
1120
3ae8bfa5 1121 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1122 if (sort == clear_as) {
3ae8bfa5 1123 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1124
1125 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1126 if (peer->as != as)
1127 continue;
1128
dc95985f 1129 bgp_peer_gr_flags_update(peer);
1130
36235319 1131 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1132 gr_router_detected = true;
dc95985f 1133
c368171c 1134 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1135
1136 if (ret < 0)
1ca2fd11 1137 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1138 else
1139 found = true;
d62a17ae 1140 }
3ae8bfa5 1141
36235319
QY
1142 if (gr_router_detected
1143 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1144 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1145 } else if (!gr_router_detected
1146 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1147 bgp_zebra_send_capabilities(bgp, true);
1148 }
1149
3ae8bfa5 1150 if (!found)
1ca2fd11
IR
1151 vty_out(vty,
1152 "%%BGP: No %s peer is configured with AS %s\n",
1153 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1154
d62a17ae 1155 return CMD_SUCCESS;
1156 }
1157
1158 return CMD_SUCCESS;
1159}
1160
1ca2fd11
IR
1161static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1162 safi_t safi, enum clear_sort sort,
1163 enum bgp_clear_type stype, const char *arg)
d62a17ae 1164{
1165 struct bgp *bgp;
1166
1167 /* BGP structure lookup. */
1168 if (name) {
1169 bgp = bgp_lookup_by_name(name);
1170 if (bgp == NULL) {
1ca2fd11 1171 vty_out(vty, "Can't find BGP instance %s\n", name);
d62a17ae 1172 return CMD_WARNING;
1173 }
1174 } else {
1175 bgp = bgp_get_default();
1176 if (bgp == NULL) {
1ca2fd11 1177 vty_out(vty, "No BGP process is configured\n");
d62a17ae 1178 return CMD_WARNING;
1179 }
1180 }
1181
1ca2fd11 1182 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
1183}
1184
1185/* clear soft inbound */
1ca2fd11 1186static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 1187{
99b3ebd3
NS
1188 afi_t afi;
1189 safi_t safi;
1190
1ca2fd11
IR
1191 FOREACH_AFI_SAFI (afi, safi)
1192 bgp_clear_vty(vty, name, afi, safi, clear_all,
1193 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
1194}
1195
1196/* clear soft outbound */
1ca2fd11 1197static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 1198{
99b3ebd3
NS
1199 afi_t afi;
1200 safi_t safi;
1201
1ca2fd11
IR
1202 FOREACH_AFI_SAFI (afi, safi)
1203 bgp_clear_vty(vty, name, afi, safi, clear_all,
1204 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
1205}
1206
1207
f787d7a0 1208#ifndef VTYSH_EXTRACT_PL
2e4c2296 1209#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1210#endif
1211
8029b216
AK
1212DEFUN_HIDDEN (bgp_local_mac,
1213 bgp_local_mac_cmd,
093e3f23 1214 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1215 BGP_STR
1216 "Local MAC config\n"
1217 "VxLAN Network Identifier\n"
1218 "VNI number\n"
1219 "local mac\n"
1220 "mac address\n"
1221 "mac-mobility sequence\n"
1222 "seq number\n")
1223{
1224 int rv;
1225 vni_t vni;
1226 struct ethaddr mac;
1227 struct ipaddr ip;
1228 uint32_t seq;
1229 struct bgp *bgp;
1230
1231 vni = strtoul(argv[3]->arg, NULL, 10);
1232 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1233 vty_out(vty, "%% Malformed MAC address\n");
1234 return CMD_WARNING;
1235 }
1236 memset(&ip, 0, sizeof(ip));
1237 seq = strtoul(argv[7]->arg, NULL, 10);
1238
1239 bgp = bgp_get_default();
1240 if (!bgp) {
1241 vty_out(vty, "Default BGP instance is not there\n");
1242 return CMD_WARNING;
1243 }
1244
b5e140c8
AK
1245 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1246 zero_esi);
8029b216
AK
1247 if (rv < 0) {
1248 vty_out(vty, "Internal error\n");
1249 return CMD_WARNING;
1250 }
1251
1252 return CMD_SUCCESS;
1253}
1254
1255DEFUN_HIDDEN (no_bgp_local_mac,
1256 no_bgp_local_mac_cmd,
093e3f23 1257 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1258 NO_STR
1259 BGP_STR
1260 "Local MAC config\n"
1261 "VxLAN Network Identifier\n"
1262 "VNI number\n"
1263 "local mac\n"
1264 "mac address\n")
1265{
1266 int rv;
1267 vni_t vni;
1268 struct ethaddr mac;
1269 struct ipaddr ip;
1270 struct bgp *bgp;
1271
1272 vni = strtoul(argv[4]->arg, NULL, 10);
1273 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1274 vty_out(vty, "%% Malformed MAC address\n");
1275 return CMD_WARNING;
1276 }
1277 memset(&ip, 0, sizeof(ip));
1278
1279 bgp = bgp_get_default();
1280 if (!bgp) {
1281 vty_out(vty, "Default BGP instance is not there\n");
1282 return CMD_WARNING;
1283 }
1284
ec0ab544 1285 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1286 if (rv < 0) {
1287 vty_out(vty, "Internal error\n");
1288 return CMD_WARNING;
1289 }
1290
1291 return CMD_SUCCESS;
1292}
1293
718e3744 1294DEFUN (no_synchronization,
1295 no_synchronization_cmd,
1296 "no synchronization",
1297 NO_STR
1298 "Perform IGP synchronization\n")
1299{
d62a17ae 1300 return CMD_SUCCESS;
718e3744 1301}
1302
1303DEFUN (no_auto_summary,
1304 no_auto_summary_cmd,
1305 "no auto-summary",
1306 NO_STR
1307 "Enable automatic network number summarization\n")
1308{
d62a17ae 1309 return CMD_SUCCESS;
718e3744 1310}
3d515fd9 1311
718e3744 1312/* "router bgp" commands. */
1ca2fd11
IR
1313DEFUN_NOSH (router_bgp,
1314 router_bgp_cmd,
1315 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1316 ROUTER_STR
1317 BGP_STR
1318 AS_STR
1319 BGP_INSTANCE_HELP_STR)
718e3744 1320{
d62a17ae 1321 int idx_asn = 2;
1322 int idx_view_vrf = 3;
1323 int idx_vrf = 4;
1ca2fd11
IR
1324 int is_new_bgp = 0;
1325 int ret;
d62a17ae 1326 as_t as;
1327 struct bgp *bgp;
1328 const char *name = NULL;
1329 enum bgp_instance_type inst_type;
1330
1331 // "router bgp" without an ASN
1332 if (argc == 2) {
1333 // Pending: Make VRF option available for ASN less config
1abef40f 1334 bgp = bgp_get_default();
d62a17ae 1335
1abef40f 1336 if (bgp == NULL) {
d62a17ae 1337 vty_out(vty, "%% No BGP process is configured\n");
1338 return CMD_WARNING_CONFIG_FAILED;
1339 }
1340
1341 if (listcount(bm->bgp) > 1) {
996c9314 1342 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1343 return CMD_WARNING_CONFIG_FAILED;
1344 }
1345 }
1346
1347 // "router bgp X"
1348 else {
ff8a8a7a 1349 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1ca2fd11 1350
cc413e2a
DA
1351 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1352 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1353 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1354
d62a17ae 1355 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1356 if (argc > 3) {
1357 name = argv[idx_vrf]->arg;
1358
9a8bdf1c
PG
1359 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1360 if (strmatch(name, VRF_DEFAULT_NAME))
1361 name = NULL;
1362 else
1363 inst_type = BGP_INSTANCE_TYPE_VRF;
1ca2fd11 1364 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1365 inst_type = BGP_INSTANCE_TYPE_VIEW;
d62a17ae 1366 }
1367
1ca2fd11
IR
1368 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1369 is_new_bgp = (bgp_lookup(as, name) == NULL);
3bd70bf8 1370
1ca2fd11
IR
1371 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1372 switch (ret) {
1373 case BGP_ERR_AS_MISMATCH:
1374 vty_out(vty, "BGP is already running; AS is %u\n", as);
1375 return CMD_WARNING_CONFIG_FAILED;
1376 case BGP_ERR_INSTANCE_MISMATCH:
1377 vty_out(vty,
1378 "BGP instance name and AS number mismatch\n");
1379 vty_out(vty,
1380 "BGP instance is already running; AS is %u\n",
1381 as);
1382 return CMD_WARNING_CONFIG_FAILED;
ff8a8a7a 1383 }
1ca2fd11
IR
1384
1385 /*
1386 * If we just instantiated the default instance, complete
1387 * any pending VRF-VPN leaking that was configured via
1388 * earlier "router bgp X vrf FOO" blocks.
1389 */
1390 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1391 vpn_leak_postchange_all();
1392
1393 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1394 bgp_vpn_leak_export(bgp);
1395 /* Pending: handle when user tries to change a view to vrf n vv.
1396 */
d62a17ae 1397 }
1398
1ca2fd11
IR
1399 /* unset the auto created flag as the user config is now present */
1400 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1401 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1402
1403 return CMD_SUCCESS;
718e3744 1404}
1405
718e3744 1406/* "no router bgp" commands. */
1ca2fd11
IR
1407DEFUN (no_router_bgp,
1408 no_router_bgp_cmd,
1409 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1410 NO_STR
1411 ROUTER_STR
1412 BGP_STR
1413 AS_STR
1414 BGP_INSTANCE_HELP_STR)
718e3744 1415{
4fd9919e 1416 int idx_asn = 3;
d62a17ae 1417 int idx_vrf = 5;
1ca2fd11 1418 as_t as;
4fd9919e 1419 struct bgp *bgp;
d62a17ae 1420 const char *name = NULL;
718e3744 1421
d62a17ae 1422 // "no router bgp" without an ASN
1423 if (argc == 3) {
1424 // Pending: Make VRF option available for ASN less config
8382083a 1425 bgp = bgp_get_default();
718e3744 1426
8382083a 1427 if (bgp == NULL) {
d62a17ae 1428 vty_out(vty, "%% No BGP process is configured\n");
1429 return CMD_WARNING_CONFIG_FAILED;
1430 }
7fb21a9f 1431
d62a17ae 1432 if (listcount(bm->bgp) > 1) {
996c9314 1433 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1434 return CMD_WARNING_CONFIG_FAILED;
1435 }
4fd9919e 1436
4fd9919e
IR
1437 if (bgp->l3vni) {
1438 vty_out(vty, "%% Please unconfigure l3vni %u",
1439 bgp->l3vni);
1440 return CMD_WARNING_CONFIG_FAILED;
1441 }
d62a17ae 1442 } else {
4fd9919e
IR
1443 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1444
1ca42c8d 1445 if (argc > 4) {
d62a17ae 1446 name = argv[idx_vrf]->arg;
1ca42c8d
IR
1447 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1448 && strmatch(name, VRF_DEFAULT_NAME))
1449 name = NULL;
1450 }
7fb21a9f 1451
4fd9919e
IR
1452 /* Lookup bgp structure. */
1453 bgp = bgp_lookup(as, name);
1454 if (!bgp) {
1455 vty_out(vty, "%% Can't find BGP instance\n");
1456 return CMD_WARNING_CONFIG_FAILED;
1457 }
1458
1459 if (bgp->l3vni) {
1460 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1461 bgp->l3vni);
1462 return CMD_WARNING_CONFIG_FAILED;
1463 }
1464
1465 /* Cannot delete default instance if vrf instances exist */
1466 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1467 struct listnode *node;
1468 struct bgp *tmp_bgp;
1469
1470 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1471 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1472 continue;
1473 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1474 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1475 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1476 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1477 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1478 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1479 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1480 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1481 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1482 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1483 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1484 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1485 (bgp == bgp_get_evpn() &&
1486 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1487 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1488 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1489 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1490 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1491 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1492 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1493 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1494 (tmp_bgp->vnihash && hashcount(tmp_bgp->vnihash))) {
1495 vty_out(vty,
1496 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1497 return CMD_WARNING_CONFIG_FAILED;
1498 }
1499 }
1500 }
d62a17ae 1501 }
718e3744 1502
1ca2fd11 1503 bgp_delete(bgp);
718e3744 1504
1ca2fd11 1505 return CMD_SUCCESS;
718e3744 1506}
1507
718e3744 1508
ff8a8a7a
CS
1509/* BGP router-id. */
1510
1ca2fd11
IR
1511DEFPY (bgp_router_id,
1512 bgp_router_id_cmd,
1513 "bgp router-id A.B.C.D",
1514 BGP_STR
1515 "Override configured router identifier\n"
1516 "Manually configured router identifier\n")
718e3744 1517{
1ca2fd11
IR
1518 VTY_DECLVAR_CONTEXT(bgp, bgp);
1519 bgp_router_id_static_set(bgp, router_id);
1520 return CMD_SUCCESS;
ff8a8a7a 1521}
718e3744 1522
1ca2fd11
IR
1523DEFPY (no_bgp_router_id,
1524 no_bgp_router_id_cmd,
1525 "no bgp router-id [A.B.C.D]",
1526 NO_STR
1527 BGP_STR
1528 "Override configured router identifier\n"
1529 "Manually configured router identifier\n")
ff8a8a7a 1530{
1ca2fd11 1531 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1532
1ca2fd11
IR
1533 if (router_id_str) {
1534 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1535 vty_out(vty, "%% BGP router-id doesn't match\n");
1536 return CMD_WARNING_CONFIG_FAILED;
1537 }
1538 }
718e3744 1539
1ca2fd11
IR
1540 router_id.s_addr = 0;
1541 bgp_router_id_static_set(bgp, router_id);
1542
1543 return CMD_SUCCESS;
ff8a8a7a 1544}
6b0655a2 1545
ed0e57e3 1546DEFPY(bgp_community_alias, bgp_community_alias_cmd,
b4ad2fae 1547 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
ed0e57e3
DA
1548 NO_STR BGP_STR
1549 "Add community specific parameters\n"
1550 "Create an alias for a community\n"
1551 "Community (AA:BB or AA:BB:CC)\n"
1552 "Alias name\n")
1553{
1554 struct community_alias ca1;
1555 struct community_alias ca2;
1556 struct community_alias *lookup_community;
1557 struct community_alias *lookup_alias;
1558
1559 if (!community_str2com(community) && !lcommunity_str2com(community)) {
1560 vty_out(vty, "Invalid community format\n");
1561 return CMD_WARNING;
1562 }
1563
1564 memset(&ca1, 0, sizeof(ca1));
1565 memset(&ca2, 0, sizeof(ca2));
1566 strlcpy(ca1.community, community, sizeof(ca1.community));
b4ad2fae 1567 strlcpy(ca1.alias, alias_name, sizeof(ca1.alias));
ed0e57e3
DA
1568
1569 lookup_community = bgp_ca_community_lookup(&ca1);
1570 lookup_alias = bgp_ca_alias_lookup(&ca1);
1571
1572 if (no) {
1573 bgp_ca_alias_delete(&ca1);
1574 bgp_ca_community_delete(&ca1);
1575 } else {
1576 if (lookup_alias) {
1577 /* Lookup if community hash table has an item
1578 * with the same alias name.
1579 */
1580 strlcpy(ca2.community, lookup_alias->community,
1581 sizeof(ca2.community));
1582 if (bgp_ca_community_lookup(&ca2)) {
1583 vty_out(vty,
1584 "community (%s) already has this alias (%s)\n",
1585 lookup_alias->community,
1586 lookup_alias->alias);
1587 return CMD_WARNING;
1588 }
1589 bgp_ca_alias_delete(&ca1);
1590 }
1591
1592 if (lookup_community)
1593 bgp_ca_community_delete(&ca1);
1594
1595 bgp_ca_alias_insert(&ca1);
1596 bgp_ca_community_insert(&ca1);
1597 }
1598
1599 return CMD_SUCCESS;
1600}
1601
9acb67cb
DS
1602DEFPY (bgp_global_suppress_fib_pending,
1603 bgp_global_suppress_fib_pending_cmd,
1604 "[no] bgp suppress-fib-pending",
1605 NO_STR
1606 BGP_STR
1607 "Advertise only routes that are programmed in kernel to peers globally\n")
1608{
1609 bm_wait_for_fib_set(!no);
1610
1611 return CMD_SUCCESS;
1612}
1613
c208c586
S
1614DEFPY (bgp_suppress_fib_pending,
1615 bgp_suppress_fib_pending_cmd,
1616 "[no] bgp suppress-fib-pending",
1617 NO_STR
1618 BGP_STR
1619 "Advertise only routes that are programmed in kernel to peers\n")
1620{
1621 VTY_DECLVAR_CONTEXT(bgp, bgp);
1622
1623 bgp_suppress_fib_pending_set(bgp, !no);
1624 return CMD_SUCCESS;
1625}
1626
1627
718e3744 1628/* BGP Cluster ID. */
1ca2fd11
IR
1629DEFUN (bgp_cluster_id,
1630 bgp_cluster_id_cmd,
1631 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1632 BGP_STR
1633 "Configure Route-Reflector Cluster-id\n"
1634 "Route-Reflector Cluster-id in IP address format\n"
1635 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1636{
1ca2fd11 1637 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1638 int idx_ipv4 = 2;
1ca2fd11
IR
1639 int ret;
1640 struct in_addr cluster;
1641
1642 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1643 if (!ret) {
1644 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1645 return CMD_WARNING_CONFIG_FAILED;
1646 }
718e3744 1647
1ca2fd11
IR
1648 bgp_cluster_id_set(bgp, &cluster);
1649 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1650
1ca2fd11 1651 return CMD_SUCCESS;
718e3744 1652}
1653
1ca2fd11
IR
1654DEFUN (no_bgp_cluster_id,
1655 no_bgp_cluster_id_cmd,
1656 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1657 NO_STR
1658 BGP_STR
1659 "Configure Route-Reflector Cluster-id\n"
1660 "Route-Reflector Cluster-id in IP address format\n"
1661 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1662{
1ca2fd11
IR
1663 VTY_DECLVAR_CONTEXT(bgp, bgp);
1664 bgp_cluster_id_unset(bgp);
1665 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1666
1ca2fd11 1667 return CMD_SUCCESS;
718e3744 1668}
1669
c163f297
DS
1670DEFPY (bgp_norib,
1671 bgp_norib_cmd,
1672 "bgp no-rib",
1673 BGP_STR
1674 "Disable BGP route installation to RIB (Zebra)\n")
1675{
1676 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1677 vty_out(vty,
1678 "%% No-RIB option is already set, nothing to do here.\n");
1679 return CMD_SUCCESS;
1680 }
1681
1682 bgp_option_norib_set_runtime();
1683
1684 return CMD_SUCCESS;
1685}
1686
1687DEFPY (no_bgp_norib,
1688 no_bgp_norib_cmd,
1689 "no bgp no-rib",
1690 NO_STR
1691 BGP_STR
1692 "Disable BGP route installation to RIB (Zebra)\n")
1693{
1694 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1695 vty_out(vty,
1696 "%% No-RIB option is not set, nothing to do here.\n");
1697 return CMD_SUCCESS;
1698 }
1699
1700 bgp_option_norib_unset_runtime();
1701
1702 return CMD_SUCCESS;
1703}
1704
e46723a5
DS
1705DEFPY (no_bgp_send_extra_data,
1706 no_bgp_send_extra_data_cmd,
1707 "[no] bgp send-extra-data zebra",
1708 NO_STR
1709 BGP_STR
1710 "Extra data to Zebra for display/use\n"
1711 "To zebra\n")
1712{
ec0acb80
DA
1713 if (no)
1714 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1715 else
1716 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1717
1718 return CMD_SUCCESS;
1719}
1720
1ca2fd11
IR
1721DEFUN (bgp_confederation_identifier,
1722 bgp_confederation_identifier_cmd,
1723 "bgp confederation identifier (1-4294967295)",
e9273987 1724 BGP_STR
1ca2fd11
IR
1725 "AS confederation parameters\n"
1726 "AS number\n"
1727 "Set routing domain confederation AS\n")
718e3744 1728{
1ca2fd11 1729 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1730 int idx_number = 3;
1ca2fd11 1731 as_t as;
718e3744 1732
1ca2fd11 1733 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1734
1ca2fd11 1735 bgp_confederation_id_set(bgp, as);
718e3744 1736
1ca2fd11 1737 return CMD_SUCCESS;
718e3744 1738}
1739
1ca2fd11
IR
1740DEFUN (no_bgp_confederation_identifier,
1741 no_bgp_confederation_identifier_cmd,
1742 "no bgp confederation identifier [(1-4294967295)]",
1743 NO_STR
e9273987 1744 BGP_STR
1ca2fd11
IR
1745 "AS confederation parameters\n"
1746 "AS number\n"
1747 "Set routing domain confederation AS\n")
ff8a8a7a 1748{
1ca2fd11
IR
1749 VTY_DECLVAR_CONTEXT(bgp, bgp);
1750 bgp_confederation_id_unset(bgp);
1751
1752 return CMD_SUCCESS;
ff8a8a7a
CS
1753}
1754
1ca2fd11
IR
1755DEFUN (bgp_confederation_peers,
1756 bgp_confederation_peers_cmd,
1757 "bgp confederation peers (1-4294967295)...",
e9273987 1758 BGP_STR
1ca2fd11
IR
1759 "AS confederation parameters\n"
1760 "Peer ASs in BGP confederation\n"
1761 AS_STR)
718e3744 1762{
1ca2fd11 1763 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1764 int idx_asn = 3;
1ca2fd11 1765 as_t as;
d62a17ae 1766 int i;
718e3744 1767
1ca2fd11
IR
1768 for (i = idx_asn; i < argc; i++) {
1769 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1770
1ca2fd11
IR
1771 if (bgp->as == as) {
1772 vty_out(vty,
1773 "%% Local member-AS not allowed in confed peer list\n");
1774 continue;
1775 }
1776
1777 bgp_confederation_peers_add(bgp, as);
1778 }
1779 return CMD_SUCCESS;
718e3744 1780}
1781
1ca2fd11
IR
1782DEFUN (no_bgp_confederation_peers,
1783 no_bgp_confederation_peers_cmd,
1784 "no bgp confederation peers (1-4294967295)...",
1785 NO_STR
e9273987 1786 BGP_STR
1ca2fd11
IR
1787 "AS confederation parameters\n"
1788 "Peer ASs in BGP confederation\n"
1789 AS_STR)
718e3744 1790{
1ca2fd11 1791 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1792 int idx_asn = 4;
1ca2fd11 1793 as_t as;
d62a17ae 1794 int i;
718e3744 1795
1ca2fd11
IR
1796 for (i = idx_asn; i < argc; i++) {
1797 as = strtoul(argv[i]->arg, NULL, 10);
ff8a8a7a 1798
1ca2fd11
IR
1799 bgp_confederation_peers_remove(bgp, as);
1800 }
1801 return CMD_SUCCESS;
718e3744 1802}
6b0655a2 1803
5e242b0d
DS
1804/**
1805 * Central routine for maximum-paths configuration.
1806 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1807 * @set: 1 for setting values, 0 for removing the max-paths config.
1808 */
585f1adc
IR
1809static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1810 const char *mpaths, uint16_t options,
1811 int set)
d62a17ae 1812{
585f1adc
IR
1813 VTY_DECLVAR_CONTEXT(bgp, bgp);
1814 uint16_t maxpaths = 0;
d62a17ae 1815 int ret;
585f1adc
IR
1816 afi_t afi;
1817 safi_t safi;
1818
1819 afi = bgp_node_afi(vty);
1820 safi = bgp_node_safi(vty);
d62a17ae 1821
1822 if (set) {
585f1adc 1823 maxpaths = strtol(mpaths, NULL, 10);
d62a17ae 1824 if (maxpaths > multipath_num) {
585f1adc 1825 vty_out(vty,
d62a17ae 1826 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1827 maxpaths, multipath_num);
1828 return CMD_WARNING_CONFIG_FAILED;
1829 }
1830 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1831 options);
1832 } else
1833 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1834
1835 if (ret < 0) {
585f1adc 1836 vty_out(vty,
d62a17ae 1837 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1838 (set == 1) ? "" : "un",
1839 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1840 maxpaths, afi, safi);
1841 return CMD_WARNING_CONFIG_FAILED;
1842 }
1843
1844 bgp_recalculate_all_bestpaths(bgp);
1845
1846 return CMD_SUCCESS;
165b5fff
JB
1847}
1848
1ca2fd11
IR
1849DEFUN (bgp_maxmed_admin,
1850 bgp_maxmed_admin_cmd,
1851 "bgp max-med administrative ",
1852 BGP_STR
1853 "Advertise routes with max-med\n"
1854 "Administratively applied, for an indefinite period\n")
abc920f8 1855{
1ca2fd11 1856 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1857
1ca2fd11
IR
1858 bgp->v_maxmed_admin = 1;
1859 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
ff8a8a7a 1860
1ca2fd11 1861 bgp_maxmed_update(bgp);
abc920f8 1862
1ca2fd11 1863 return CMD_SUCCESS;
ff8a8a7a
CS
1864}
1865
1ca2fd11
IR
1866DEFUN (bgp_maxmed_admin_medv,
1867 bgp_maxmed_admin_medv_cmd,
1868 "bgp max-med administrative (0-4294967295)",
1869 BGP_STR
1870 "Advertise routes with max-med\n"
1871 "Administratively applied, for an indefinite period\n"
1872 "Max MED value to be used\n")
abc920f8 1873{
1ca2fd11 1874 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1875 int idx_number = 3;
abc920f8 1876
1ca2fd11
IR
1877 bgp->v_maxmed_admin = 1;
1878 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1879
1ca2fd11 1880 bgp_maxmed_update(bgp);
abc920f8 1881
1ca2fd11 1882 return CMD_SUCCESS;
abc920f8
DS
1883}
1884
1ca2fd11
IR
1885DEFUN (no_bgp_maxmed_admin,
1886 no_bgp_maxmed_admin_cmd,
1887 "no bgp max-med administrative [(0-4294967295)]",
1888 NO_STR
1889 BGP_STR
1890 "Advertise routes with max-med\n"
1891 "Administratively applied, for an indefinite period\n"
1892 "Max MED value to be used\n")
abc920f8 1893{
1ca2fd11
IR
1894 VTY_DECLVAR_CONTEXT(bgp, bgp);
1895 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1896 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1897 bgp_maxmed_update(bgp);
ff8a8a7a 1898
1ca2fd11 1899 return CMD_SUCCESS;
abc920f8
DS
1900}
1901
1ca2fd11
IR
1902DEFUN (bgp_maxmed_onstartup,
1903 bgp_maxmed_onstartup_cmd,
1904 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1905 BGP_STR
1906 "Advertise routes with max-med\n"
1907 "Effective on a startup\n"
1908 "Time (seconds) period for max-med\n"
1909 "Max MED value to be used\n")
abc920f8 1910{
1ca2fd11 1911 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1912 int idx = 0;
4668a151 1913
d62a17ae 1914 argv_find(argv, argc, "(5-86400)", &idx);
1ca2fd11 1915 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 1916 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1ca2fd11 1917 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 1918 else
1ca2fd11 1919 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1920
1ca2fd11
IR
1921 bgp_maxmed_update(bgp);
1922
1923 return CMD_SUCCESS;
abc920f8
DS
1924}
1925
1ca2fd11
IR
1926DEFUN (no_bgp_maxmed_onstartup,
1927 no_bgp_maxmed_onstartup_cmd,
1928 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1929 NO_STR
1930 BGP_STR
1931 "Advertise routes with max-med\n"
1932 "Effective on a startup\n"
1933 "Time (seconds) period for max-med\n"
1934 "Max MED value to be used\n")
abc920f8 1935{
1ca2fd11
IR
1936 VTY_DECLVAR_CONTEXT(bgp, bgp);
1937
1938 /* Cancel max-med onstartup if its on */
1939 if (bgp->t_maxmed_onstartup) {
1940 thread_cancel(&bgp->t_maxmed_onstartup);
1941 bgp->maxmed_onstartup_over = 1;
1942 }
abc920f8 1943
1ca2fd11
IR
1944 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1945 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1946
1ca2fd11
IR
1947 bgp_maxmed_update(bgp);
1948
1949 return CMD_SUCCESS;
abc920f8
DS
1950}
1951
d70583f7
D
1952static int bgp_global_update_delay_config_vty(struct vty *vty,
1953 uint16_t update_delay,
1954 uint16_t establish_wait)
1955{
1956 struct listnode *node, *nnode;
1957 struct bgp *bgp;
1958 bool vrf_cfg = false;
1959
1960 /*
1961 * See if update-delay is set per-vrf and warn user to delete it
1962 * Note that we only need to check this if this is the first time
1963 * setting the global config.
1964 */
1965 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1966 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1967 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1968 vty_out(vty,
1969 "%% update-delay configuration found in vrf %s\n",
1970 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1971 ? VRF_DEFAULT_NAME
1972 : bgp->name);
1973 vrf_cfg = true;
1974 }
1975 }
1976 }
1977
1978 if (vrf_cfg) {
1979 vty_out(vty,
1980 "%%Failed: global update-delay config not permitted\n");
1981 return CMD_WARNING;
1982 }
1983
1984 if (!establish_wait) { /* update-delay <delay> */
1985 bm->v_update_delay = update_delay;
1986 bm->v_establish_wait = bm->v_update_delay;
1987 } else {
1988 /* update-delay <delay> <establish-wait> */
1989 if (update_delay < establish_wait) {
1990 vty_out(vty,
1991 "%%Failed: update-delay less than the establish-wait!\n");
1992 return CMD_WARNING_CONFIG_FAILED;
1993 }
1994
1995 bm->v_update_delay = update_delay;
1996 bm->v_establish_wait = establish_wait;
1997 }
1998
1999 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2000 bgp->v_update_delay = bm->v_update_delay;
2001 bgp->v_establish_wait = bm->v_establish_wait;
2002 }
2003
2004 return CMD_SUCCESS;
2005}
2006
2007static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2008{
2009 struct listnode *node, *nnode;
2010 struct bgp *bgp;
2011
2012 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2013 bm->v_establish_wait = bm->v_update_delay;
2014
2015 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2016 bgp->v_update_delay = bm->v_update_delay;
2017 bgp->v_establish_wait = bm->v_establish_wait;
2018 }
2019
2020 return CMD_SUCCESS;
2021}
2022
2023static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2024 uint16_t establish_wait)
f188f2c4 2025{
d62a17ae 2026 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2027
d70583f7
D
2028 /* if configured globally, per-instance config is not allowed */
2029 if (bm->v_update_delay) {
2030 vty_out(vty,
2031 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2032 return CMD_WARNING_CONFIG_FAILED;
2033 }
2034
f188f2c4 2035
d70583f7 2036 if (!establish_wait) /* update-delay <delay> */
d62a17ae 2037 {
2038 bgp->v_update_delay = update_delay;
2039 bgp->v_establish_wait = bgp->v_update_delay;
2040 return CMD_SUCCESS;
2041 }
f188f2c4 2042
d62a17ae 2043 /* update-delay <delay> <establish-wait> */
d62a17ae 2044 if (update_delay < establish_wait) {
2045 vty_out(vty,
2046 "%%Failed: update-delay less than the establish-wait!\n");
2047 return CMD_WARNING_CONFIG_FAILED;
2048 }
f188f2c4 2049
d62a17ae 2050 bgp->v_update_delay = update_delay;
2051 bgp->v_establish_wait = establish_wait;
f188f2c4 2052
d62a17ae 2053 return CMD_SUCCESS;
f188f2c4
DS
2054}
2055
d62a17ae 2056static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2057{
d62a17ae 2058 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2059
d70583f7
D
2060 /* If configured globally, cannot remove from one bgp instance */
2061 if (bm->v_update_delay) {
2062 vty_out(vty,
2063 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2064 return CMD_WARNING_CONFIG_FAILED;
2065 }
d62a17ae 2066 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2067 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2068
d62a17ae 2069 return CMD_SUCCESS;
f188f2c4
DS
2070}
2071
2b791107 2072void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2073{
d70583f7
D
2074 /* If configured globally, no need to display per-instance value */
2075 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2076 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2077 if (bgp->v_update_delay != bgp->v_establish_wait)
2078 vty_out(vty, " %d", bgp->v_establish_wait);
2079 vty_out(vty, "\n");
2080 }
f188f2c4
DS
2081}
2082
d70583f7
D
2083/* Global update-delay configuration */
2084DEFPY (bgp_global_update_delay,
2085 bgp_global_update_delay_cmd,
2086 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2087 BGP_STR
2088 "Force initial delay for best-path and updates for all bgp instances\n"
2089 "Max delay in seconds\n"
2090 "Establish wait in seconds\n")
2091{
2092 return bgp_global_update_delay_config_vty(vty, delay, wait);
2093}
f188f2c4 2094
d70583f7
D
2095/* Global update-delay deconfiguration */
2096DEFPY (no_bgp_global_update_delay,
2097 no_bgp_global_update_delay_cmd,
2098 "no bgp update-delay [(0-3600) [(1-3600)]]",
2099 NO_STR
2100 BGP_STR
f188f2c4 2101 "Force initial delay for best-path and updates\n"
d70583f7
D
2102 "Max delay in seconds\n"
2103 "Establish wait in seconds\n")
f188f2c4 2104{
d70583f7 2105 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2106}
2107
d70583f7
D
2108/* Update-delay configuration */
2109
2110DEFPY (bgp_update_delay,
2111 bgp_update_delay_cmd,
2112 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2113 "Force initial delay for best-path and updates\n"
d70583f7
D
2114 "Max delay in seconds\n"
2115 "Establish wait in seconds\n")
f188f2c4 2116{
d70583f7 2117 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2118}
2119
2120/* Update-delay deconfiguration */
d70583f7 2121DEFPY (no_bgp_update_delay,
f188f2c4 2122 no_bgp_update_delay_cmd,
838758ac
DW
2123 "no update-delay [(0-3600) [(1-3600)]]",
2124 NO_STR
f188f2c4 2125 "Force initial delay for best-path and updates\n"
d70583f7
D
2126 "Max delay in seconds\n"
2127 "Establish wait in seconds\n")
f188f2c4 2128{
d62a17ae 2129 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2130}
2131
5e242b0d 2132
1ca2fd11
IR
2133static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2134 bool set)
cb1faec9 2135{
1ca2fd11
IR
2136 VTY_DECLVAR_CONTEXT(bgp, bgp);
2137
8fa7732f
QY
2138 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2139 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2140
2141 return CMD_SUCCESS;
2142}
2143
1ca2fd11
IR
2144static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2145 bool set)
555e09d4 2146{
1ca2fd11
IR
2147 VTY_DECLVAR_CONTEXT(bgp, bgp);
2148
8fa7732f
QY
2149 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2150 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2151
d62a17ae 2152 return CMD_SUCCESS;
cb1faec9
DS
2153}
2154
2b791107 2155void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2156{
555e09d4
QY
2157 uint32_t quanta =
2158 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2159 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2160 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2161}
2162
555e09d4
QY
2163void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2164{
2165 uint32_t quanta =
2166 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2167 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2168 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2169}
cb1faec9 2170
8fa7732f
QY
2171/* Packet quanta configuration
2172 *
2173 * XXX: The value set here controls the size of a stack buffer in the IO
2174 * thread. When changing these limits be careful to prevent stack overflow.
2175 *
2176 * Furthermore, the maximums used here should correspond to
2177 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2178 */
1ca2fd11
IR
2179DEFPY (bgp_wpkt_quanta,
2180 bgp_wpkt_quanta_cmd,
2181 "[no] write-quanta (1-64)$quanta",
2182 NO_STR
2183 "How many packets to write to peer socket per run\n"
2184 "Number of packets\n")
2185{
2186 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2187}
cb1faec9 2188
1ca2fd11
IR
2189DEFPY (bgp_rpkt_quanta,
2190 bgp_rpkt_quanta_cmd,
2191 "[no] read-quanta (1-10)$quanta",
2192 NO_STR
2193 "How many packets to read from peer socket per I/O cycle\n"
2194 "Number of packets\n")
2195{
2196 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
2197}
2198
2b791107 2199void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2200{
37a333fe 2201 if (!bgp->heuristic_coalesce)
d62a17ae 2202 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2203}
2204
4668a151 2205
1ca2fd11
IR
2206DEFUN (bgp_coalesce_time,
2207 bgp_coalesce_time_cmd,
2208 "coalesce-time (0-4294967295)",
2209 "Subgroup coalesce timer\n"
2210 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2211{
1ca2fd11 2212 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 2213
1ca2fd11 2214 int idx = 0;
d62a17ae 2215 argv_find(argv, argc, "(0-4294967295)", &idx);
1ca2fd11
IR
2216 bgp->heuristic_coalesce = false;
2217 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2218 return CMD_SUCCESS;
3f9c7369
DS
2219}
2220
1ca2fd11
IR
2221DEFUN (no_bgp_coalesce_time,
2222 no_bgp_coalesce_time_cmd,
2223 "no coalesce-time (0-4294967295)",
2224 NO_STR
2225 "Subgroup coalesce timer\n"
2226 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2227{
1ca2fd11 2228 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 2229
1ca2fd11
IR
2230 bgp->heuristic_coalesce = true;
2231 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2232 return CMD_SUCCESS;
3f9c7369
DS
2233}
2234
5e242b0d 2235/* Maximum-paths configuration */
585f1adc
IR
2236DEFUN (bgp_maxpaths,
2237 bgp_maxpaths_cmd,
2238 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2239 "Forward packets over multiple paths\n"
2240 "Number of paths\n")
5e242b0d 2241{
d62a17ae 2242 int idx_number = 1;
585f1adc
IR
2243 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2244 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
2245}
2246
d62a17ae 2247ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2248 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2249 "Forward packets over multiple paths\n"
2250 "Number of paths\n")
596c17ba 2251
585f1adc
IR
2252DEFUN (bgp_maxpaths_ibgp,
2253 bgp_maxpaths_ibgp_cmd,
2254 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2255 "Forward packets over multiple paths\n"
2256 "iBGP-multipath\n"
2257 "Number of paths\n")
165b5fff 2258{
d62a17ae 2259 int idx_number = 2;
585f1adc
IR
2260 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2261 argv[idx_number]->arg, 0, 1);
5e242b0d 2262}
165b5fff 2263
d62a17ae 2264ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2265 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2266 "Forward packets over multiple paths\n"
2267 "iBGP-multipath\n"
2268 "Number of paths\n")
596c17ba 2269
585f1adc
IR
2270DEFUN (bgp_maxpaths_ibgp_cluster,
2271 bgp_maxpaths_ibgp_cluster_cmd,
2272 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2273 "Forward packets over multiple paths\n"
2274 "iBGP-multipath\n"
2275 "Number of paths\n"
2276 "Match the cluster length\n")
5e242b0d 2277{
d62a17ae 2278 int idx_number = 2;
585f1adc
IR
2279 return bgp_maxpaths_config_vty(
2280 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
2281 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
2282}
2283
d62a17ae 2284ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2285 "maximum-paths ibgp " CMD_RANGE_STR(
2286 1, MULTIPATH_NUM) " equal-cluster-length",
2287 "Forward packets over multiple paths\n"
2288 "iBGP-multipath\n"
2289 "Number of paths\n"
2290 "Match the cluster length\n")
596c17ba 2291
585f1adc
IR
2292DEFUN (no_bgp_maxpaths,
2293 no_bgp_maxpaths_cmd,
2294 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2295 NO_STR
2296 "Forward packets over multiple paths\n"
2297 "Number of paths\n")
165b5fff 2298{
585f1adc 2299 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
2300}
2301
d62a17ae 2302ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2303 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2304 "Forward packets over multiple paths\n"
2305 "Number of paths\n")
596c17ba 2306
585f1adc
IR
2307DEFUN (no_bgp_maxpaths_ibgp,
2308 no_bgp_maxpaths_ibgp_cmd,
2309 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2310 NO_STR
2311 "Forward packets over multiple paths\n"
2312 "iBGP-multipath\n"
2313 "Number of paths\n"
2314 "Match the cluster length\n")
165b5fff 2315{
585f1adc 2316 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
2317}
2318
d62a17ae 2319ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2320 "no maximum-paths ibgp [" CMD_RANGE_STR(
2321 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2322 NO_STR
2323 "Forward packets over multiple paths\n"
2324 "iBGP-multipath\n"
2325 "Number of paths\n"
2326 "Match the cluster length\n")
596c17ba 2327
dd65f45e
DL
2328static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2329 afi_t afi, safi_t safi)
165b5fff 2330{
00908b7a 2331 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2332 vty_out(vty, " maximum-paths %d\n",
2333 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2334 }
165b5fff 2335
00908b7a 2336 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2337 vty_out(vty, " maximum-paths ibgp %d",
2338 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2339 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2340 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2341 vty_out(vty, " equal-cluster-length");
2342 vty_out(vty, "\n");
2343 }
165b5fff 2344}
6b0655a2 2345
718e3744 2346/* BGP timers. */
2347
1ca2fd11
IR
2348DEFUN (bgp_timers,
2349 bgp_timers_cmd,
2350 "timers bgp (0-65535) (0-65535)",
2351 "Adjust routing timers\n"
2352 "BGP timers\n"
2353 "Keepalive interval\n"
2354 "Holdtime\n")
718e3744 2355{
1ca2fd11 2356 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2357 int idx_number = 2;
2358 int idx_number_2 = 3;
1ca2fd11
IR
2359 unsigned long keepalive = 0;
2360 unsigned long holdtime = 0;
718e3744 2361
1ca2fd11
IR
2362 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2363 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 2364
1ca2fd11
IR
2365 /* Holdtime value check. */
2366 if (holdtime < 3 && holdtime != 0) {
2367 vty_out(vty,
2368 "%% hold time value must be either 0 or greater than 3\n");
2369 return CMD_WARNING_CONFIG_FAILED;
2370 }
718e3744 2371
1ca2fd11
IR
2372 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2373 BGP_DEFAULT_DELAYOPEN);
718e3744 2374
1ca2fd11 2375 return CMD_SUCCESS;
718e3744 2376}
2377
1ca2fd11
IR
2378DEFUN (no_bgp_timers,
2379 no_bgp_timers_cmd,
2380 "no timers bgp [(0-65535) (0-65535)]",
2381 NO_STR
2382 "Adjust routing timers\n"
2383 "BGP timers\n"
2384 "Keepalive interval\n"
2385 "Holdtime\n")
718e3744 2386{
1ca2fd11
IR
2387 VTY_DECLVAR_CONTEXT(bgp, bgp);
2388 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2389 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
ff8a8a7a 2390
1ca2fd11 2391 return CMD_SUCCESS;
718e3744 2392}
2393
b042667a
TI
2394/* BGP minimum holdtime. */
2395
2396DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2397 "bgp minimum-holdtime (1-65535)",
2398 "BGP specific commands\n"
2399 "BGP minimum holdtime\n"
2400 "Seconds\n")
2401{
2402 VTY_DECLVAR_CONTEXT(bgp, bgp);
2403 int idx_number = 2;
2404 unsigned long min_holdtime;
2405
2406 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2407
2408 bgp->default_min_holdtime = min_holdtime;
2409
2410 return CMD_SUCCESS;
2411}
2412
2413DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2414 "no bgp minimum-holdtime [(1-65535)]",
2415 NO_STR
2416 "BGP specific commands\n"
2417 "BGP minimum holdtime\n"
2418 "Seconds\n")
2419{
2420 VTY_DECLVAR_CONTEXT(bgp, bgp);
2421
2422 bgp->default_min_holdtime = 0;
2423
2424 return CMD_SUCCESS;
2425}
ff8a8a7a 2426
1ca2fd11
IR
2427DEFUN (bgp_client_to_client_reflection,
2428 bgp_client_to_client_reflection_cmd,
2429 "bgp client-to-client reflection",
e9273987 2430 BGP_STR
1ca2fd11
IR
2431 "Configure client to client route reflection\n"
2432 "reflection of routes allowed\n")
718e3744 2433{
1ca2fd11
IR
2434 VTY_DECLVAR_CONTEXT(bgp, bgp);
2435 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2436 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2437
1ca2fd11 2438 return CMD_SUCCESS;
718e3744 2439}
2440
1ca2fd11
IR
2441DEFUN (no_bgp_client_to_client_reflection,
2442 no_bgp_client_to_client_reflection_cmd,
2443 "no bgp client-to-client reflection",
2444 NO_STR
e9273987 2445 BGP_STR
1ca2fd11
IR
2446 "Configure client to client route reflection\n"
2447 "reflection of routes allowed\n")
718e3744 2448{
1ca2fd11
IR
2449 VTY_DECLVAR_CONTEXT(bgp, bgp);
2450 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2451 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2452
1ca2fd11 2453 return CMD_SUCCESS;
718e3744 2454}
2455
2456/* "bgp always-compare-med" configuration. */
1ca2fd11
IR
2457DEFUN (bgp_always_compare_med,
2458 bgp_always_compare_med_cmd,
2459 "bgp always-compare-med",
e9273987 2460 BGP_STR
1ca2fd11 2461 "Allow comparing MED from different neighbors\n")
718e3744 2462{
1ca2fd11
IR
2463 VTY_DECLVAR_CONTEXT(bgp, bgp);
2464 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2465 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2466
1ca2fd11 2467 return CMD_SUCCESS;
718e3744 2468}
2469
1ca2fd11
IR
2470DEFUN (no_bgp_always_compare_med,
2471 no_bgp_always_compare_med_cmd,
2472 "no bgp always-compare-med",
2473 NO_STR
e9273987 2474 BGP_STR
1ca2fd11 2475 "Allow comparing MED from different neighbors\n")
718e3744 2476{
1ca2fd11
IR
2477 VTY_DECLVAR_CONTEXT(bgp, bgp);
2478 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2479 bgp_recalculate_all_bestpaths(bgp);
6b0655a2 2480
1ca2fd11 2481 return CMD_SUCCESS;
2adac256
DA
2482}
2483
2adac256 2484
1ca2fd11
IR
2485DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2486 "bgp ebgp-requires-policy",
e9273987 2487 BGP_STR
1ca2fd11 2488 "Require in and out policy for eBGP peers (RFC8212)\n")
2adac256 2489{
1ca2fd11
IR
2490 VTY_DECLVAR_CONTEXT(bgp, bgp);
2491 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2492 return CMD_SUCCESS;
2adac256
DA
2493}
2494
1ca2fd11
IR
2495DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2496 "no bgp ebgp-requires-policy",
2497 NO_STR
e9273987 2498 BGP_STR
1ca2fd11 2499 "Require in and out policy for eBGP peers (RFC8212)\n")
ff8a8a7a 2500{
1ca2fd11
IR
2501 VTY_DECLVAR_CONTEXT(bgp, bgp);
2502 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2503 return CMD_SUCCESS;
ff8a8a7a 2504}
9dac9fc8 2505
1ca2fd11
IR
2506DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2507 "bgp suppress-duplicates",
e9273987 2508 BGP_STR
1ca2fd11 2509 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2510{
1ca2fd11
IR
2511 VTY_DECLVAR_CONTEXT(bgp, bgp);
2512 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2513 return CMD_SUCCESS;
9dac9fc8
DA
2514}
2515
1ca2fd11
IR
2516DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2517 "no bgp suppress-duplicates",
2518 NO_STR
e9273987 2519 BGP_STR
1ca2fd11 2520 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2521{
1ca2fd11
IR
2522 VTY_DECLVAR_CONTEXT(bgp, bgp);
2523 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2524 return CMD_SUCCESS;
9dac9fc8
DA
2525}
2526
fb29348a
DA
2527DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2528 "bgp reject-as-sets",
e9273987 2529 BGP_STR
fb29348a
DA
2530 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2531{
2532 VTY_DECLVAR_CONTEXT(bgp, bgp);
2533 struct listnode *node, *nnode;
2534 struct peer *peer;
2535
7f972cd8 2536 bgp->reject_as_sets = true;
fb29348a
DA
2537
2538 /* Reset existing BGP sessions to reject routes
2539 * with aspath containing AS_SET or AS_CONFED_SET.
2540 */
2541 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2542 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2543 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2544 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2545 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2546 }
2547 }
2548
2549 return CMD_SUCCESS;
2550}
2551
2552DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2553 "no bgp reject-as-sets",
2554 NO_STR
e9273987 2555 BGP_STR
fb29348a
DA
2556 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2557{
2558 VTY_DECLVAR_CONTEXT(bgp, bgp);
2559 struct listnode *node, *nnode;
2560 struct peer *peer;
2561
7f972cd8 2562 bgp->reject_as_sets = false;
fb29348a
DA
2563
2564 /* Reset existing BGP sessions to reject routes
2565 * with aspath containing AS_SET or AS_CONFED_SET.
2566 */
2567 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2568 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2569 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2570 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2571 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2572 }
2573 }
2574
2575 return CMD_SUCCESS;
2576}
9dac9fc8 2577
718e3744 2578/* "bgp deterministic-med" configuration. */
1ca2fd11 2579DEFUN (bgp_deterministic_med,
718e3744 2580 bgp_deterministic_med_cmd,
2581 "bgp deterministic-med",
e9273987 2582 BGP_STR
718e3744 2583 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2584{
1ca2fd11
IR
2585 VTY_DECLVAR_CONTEXT(bgp, bgp);
2586
2587 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2588 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2589 bgp_recalculate_all_bestpaths(bgp);
2590 }
7aafcaca 2591
1ca2fd11 2592 return CMD_SUCCESS;
718e3744 2593}
2594
1ca2fd11 2595DEFUN (no_bgp_deterministic_med,
718e3744 2596 no_bgp_deterministic_med_cmd,
2597 "no bgp deterministic-med",
2598 NO_STR
e9273987 2599 BGP_STR
718e3744 2600 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2601{
1ca2fd11
IR
2602 VTY_DECLVAR_CONTEXT(bgp, bgp);
2603 int bestpath_per_as_used;
2604 afi_t afi;
2605 safi_t safi;
2606 struct peer *peer;
2607 struct listnode *node, *nnode;
2608
2609 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2610 bestpath_per_as_used = 0;
2611
2612 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2613 FOREACH_AFI_SAFI (afi, safi)
2614 if (bgp_addpath_dmed_required(
2615 peer->addpath_type[afi][safi])) {
2616 bestpath_per_as_used = 1;
2617 break;
2618 }
2619
2620 if (bestpath_per_as_used)
2621 break;
2622 }
2623
2624 if (bestpath_per_as_used) {
2625 vty_out(vty,
2626 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2627 return CMD_WARNING_CONFIG_FAILED;
2628 } else {
2629 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2630 bgp_recalculate_all_bestpaths(bgp);
2631 }
2632 }
d62a17ae 2633
1ca2fd11 2634 return CMD_SUCCESS;
718e3744 2635}
538621f2 2636
055679e9 2637/* "bgp graceful-restart mode" configuration. */
538621f2 2638DEFUN (bgp_graceful_restart,
2ba1fe69 2639 bgp_graceful_restart_cmd,
2640 "bgp graceful-restart",
e9273987 2641 BGP_STR
2ba1fe69 2642 GR_CMD
055679e9 2643 )
538621f2 2644{
055679e9 2645 int ret = BGP_GR_FAILURE;
2646
2647 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2648 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2649
d62a17ae 2650 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2651
2652 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2653
36235319
QY
2654 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2655 ret);
5cce3f05 2656
055679e9 2657 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2658 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2659 vty_out(vty,
2660 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2661 return bgp_vty_return(vty, ret);
538621f2 2662}
2663
2664DEFUN (no_bgp_graceful_restart,
2ba1fe69 2665 no_bgp_graceful_restart_cmd,
2666 "no bgp graceful-restart",
2667 NO_STR
e9273987 2668 BGP_STR
2ba1fe69 2669 NO_GR_CMD
055679e9 2670 )
538621f2 2671{
d62a17ae 2672 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2673
2674 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2675 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2676
2677 int ret = BGP_GR_FAILURE;
2678
2679 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2680
36235319
QY
2681 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2682 ret);
5cce3f05 2683
055679e9 2684 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2685 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2686 vty_out(vty,
2687 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2688
2689 return bgp_vty_return(vty, ret);
538621f2 2690}
2691
93406d87 2692DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2693 bgp_graceful_restart_stalepath_time_cmd,
2694 "bgp graceful-restart stalepath-time (1-4095)",
e9273987 2695 BGP_STR
2ba1fe69 2696 "Graceful restart capability parameters\n"
2697 "Set the max time to hold onto restarting peer's stale paths\n"
2698 "Delay value (seconds)\n")
93406d87 2699{
d62a17ae 2700 VTY_DECLVAR_CONTEXT(bgp, bgp);
2701 int idx_number = 3;
d7c0a89a 2702 uint32_t stalepath;
93406d87 2703
d62a17ae 2704 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2705 bgp->stalepath_time = stalepath;
2706 return CMD_SUCCESS;
93406d87 2707}
2708
eb6f1b41 2709DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2710 bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2711 "bgp graceful-restart restart-time (0-4095)",
e9273987 2712 BGP_STR
2ba1fe69 2713 "Graceful restart capability parameters\n"
2714 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2715 "Delay value (seconds)\n")
eb6f1b41 2716{
d62a17ae 2717 VTY_DECLVAR_CONTEXT(bgp, bgp);
2718 int idx_number = 3;
d7c0a89a 2719 uint32_t restart;
eb6f1b41 2720
d62a17ae 2721 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2722 bgp->restart_time = restart;
2723 return CMD_SUCCESS;
eb6f1b41
PG
2724}
2725
cfd47646 2726DEFUN (bgp_graceful_restart_select_defer_time,
2727 bgp_graceful_restart_select_defer_time_cmd,
2728 "bgp graceful-restart select-defer-time (0-3600)",
e9273987 2729 BGP_STR
cfd47646 2730 "Graceful restart capability parameters\n"
2731 "Set the time to defer the BGP route selection after restart\n"
2732 "Delay value (seconds, 0 - disable)\n")
2733{
2734 VTY_DECLVAR_CONTEXT(bgp, bgp);
2735 int idx_number = 3;
2736 uint32_t defer_time;
2737
2738 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2739 bgp->select_defer_time = defer_time;
2740 if (defer_time == 0)
892fedb6 2741 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2742 else
892fedb6 2743 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2744
2745 return CMD_SUCCESS;
2746}
2747
93406d87 2748DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2749 no_bgp_graceful_restart_stalepath_time_cmd,
2750 "no bgp graceful-restart stalepath-time [(1-4095)]",
2751 NO_STR
e9273987 2752 BGP_STR
2ba1fe69 2753 "Graceful restart capability parameters\n"
2754 "Set the max time to hold onto restarting peer's stale paths\n"
2755 "Delay value (seconds)\n")
93406d87 2756{
d62a17ae 2757 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2758
d62a17ae 2759 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2760 return CMD_SUCCESS;
93406d87 2761}
2762
eb6f1b41 2763DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2764 no_bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2765 "no bgp graceful-restart restart-time [(0-4095)]",
2ba1fe69 2766 NO_STR
e9273987 2767 BGP_STR
2ba1fe69 2768 "Graceful restart capability parameters\n"
2769 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2770 "Delay value (seconds)\n")
eb6f1b41 2771{
d62a17ae 2772 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2773
d62a17ae 2774 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2775 return CMD_SUCCESS;
eb6f1b41
PG
2776}
2777
cfd47646 2778DEFUN (no_bgp_graceful_restart_select_defer_time,
2779 no_bgp_graceful_restart_select_defer_time_cmd,
2780 "no bgp graceful-restart select-defer-time [(0-3600)]",
2781 NO_STR
e9273987 2782 BGP_STR
cfd47646 2783 "Graceful restart capability parameters\n"
2784 "Set the time to defer the BGP route selection after restart\n"
2785 "Delay value (seconds)\n")
2786{
2787 VTY_DECLVAR_CONTEXT(bgp, bgp);
2788
2789 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2790 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2791
2792 return CMD_SUCCESS;
2793}
2794
43fc21b3 2795DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2796 bgp_graceful_restart_preserve_fw_cmd,
2797 "bgp graceful-restart preserve-fw-state",
e9273987 2798 BGP_STR
2ba1fe69 2799 "Graceful restart capability parameters\n"
2800 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2801{
d62a17ae 2802 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2803 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2804 return CMD_SUCCESS;
43fc21b3
JC
2805}
2806
2807DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2808 no_bgp_graceful_restart_preserve_fw_cmd,
2809 "no bgp graceful-restart preserve-fw-state",
2810 NO_STR
e9273987 2811 BGP_STR
2ba1fe69 2812 "Graceful restart capability parameters\n"
2813 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2814{
d62a17ae 2815 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2816 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2817 return CMD_SUCCESS;
43fc21b3
JC
2818}
2819
055679e9 2820DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2821 bgp_graceful_restart_disable_cmd,
2822 "bgp graceful-restart-disable",
e9273987 2823 BGP_STR
2ba1fe69 2824 GR_DISABLE)
055679e9 2825{
2826 int ret = BGP_GR_FAILURE;
2827
2828 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2829 zlog_debug(
2ba1fe69 2830 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2831
055679e9 2832 VTY_DECLVAR_CONTEXT(bgp, bgp);
2833
2834 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2835
dc95985f 2836 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2837 bgp->peer, ret);
5cce3f05 2838
055679e9 2839 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2840 zlog_debug(
2ba1fe69 2841 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2842 vty_out(vty,
2843 "Graceful restart configuration changed, reset all peers to take effect\n");
2844
055679e9 2845 return bgp_vty_return(vty, ret);
2846}
2847
2848DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2849 no_bgp_graceful_restart_disable_cmd,
2850 "no bgp graceful-restart-disable",
2851 NO_STR
e9273987 2852 BGP_STR
2ba1fe69 2853 NO_GR_DISABLE
055679e9 2854 )
2855{
2856 VTY_DECLVAR_CONTEXT(bgp, bgp);
2857
2858 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2859 zlog_debug(
2ba1fe69 2860 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2861
2862 int ret = BGP_GR_FAILURE;
2863
2864 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2865
36235319
QY
2866 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2867 ret);
5cce3f05 2868
055679e9 2869 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2870 zlog_debug(
2ba1fe69 2871 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2872 vty_out(vty,
2873 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2874
2875 return bgp_vty_return(vty, ret);
2876}
2877
2878DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2879 bgp_neighbor_graceful_restart_set_cmd,
2880 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2881 NEIGHBOR_STR
2882 NEIGHBOR_ADDR_STR2
2883 GR_NEIGHBOR_CMD
055679e9 2884 )
2885{
2886 int idx_peer = 1;
2887 struct peer *peer;
2888 int ret = BGP_GR_FAILURE;
2889
dc95985f 2890 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2891
055679e9 2892 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2893 zlog_debug(
2ba1fe69 2894 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2895
055679e9 2896 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2897 if (!peer)
2898 return CMD_WARNING_CONFIG_FAILED;
2899
2900 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2901
dc95985f 2902 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2903 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2904
2905 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2906 zlog_debug(
2ba1fe69 2907 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2908 vty_out(vty,
2909 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2910
2911 return bgp_vty_return(vty, ret);
2912}
2913
2914DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 2915 no_bgp_neighbor_graceful_restart_set_cmd,
2916 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2917 NO_STR
2918 NEIGHBOR_STR
2919 NEIGHBOR_ADDR_STR2
2920 NO_GR_NEIGHBOR_CMD
055679e9 2921 )
2922{
2923 int idx_peer = 2;
2924 int ret = BGP_GR_FAILURE;
2925 struct peer *peer;
2926
dc95985f 2927 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2928
055679e9 2929 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2930 if (!peer)
2931 return CMD_WARNING_CONFIG_FAILED;
2932
2933 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2934 zlog_debug(
2ba1fe69 2935 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 2936
2937 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2938
dc95985f 2939 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2940 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2941
2942 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2943 zlog_debug(
2ba1fe69 2944 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2945 vty_out(vty,
2946 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2947
2948 return bgp_vty_return(vty, ret);
2949}
2950
2951DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 2952 bgp_neighbor_graceful_restart_helper_set_cmd,
2953 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2954 NEIGHBOR_STR
2955 NEIGHBOR_ADDR_STR2
2956 GR_NEIGHBOR_HELPER_CMD
055679e9 2957 )
2958{
2959 int idx_peer = 1;
2960 struct peer *peer;
2961 int ret = BGP_GR_FAILURE;
2962
dc95985f 2963 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2964
055679e9 2965 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2966 zlog_debug(
2ba1fe69 2967 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 2968
055679e9 2969 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2970
055679e9 2971 if (!peer)
2972 return CMD_WARNING_CONFIG_FAILED;
2973
2974
2975 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 2976
dc95985f 2977 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2978 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 2979
055679e9 2980 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2981 zlog_debug(
2ba1fe69 2982 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2983 vty_out(vty,
2984 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2985
2986 return bgp_vty_return(vty, ret);
2987}
2988
2989DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 2990 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2991 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2992 NO_STR
2993 NEIGHBOR_STR
2994 NEIGHBOR_ADDR_STR2
2995 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 2996 )
2997{
2998 int idx_peer = 2;
2999 int ret = BGP_GR_FAILURE;
3000 struct peer *peer;
3001
dc95985f 3002 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3003
055679e9 3004 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3005 if (!peer)
3006 return CMD_WARNING_CONFIG_FAILED;
3007
3008 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3009 zlog_debug(
2ba1fe69 3010 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3011
36235319 3012 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3013
dc95985f 3014 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3015 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3016
3017 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3018 zlog_debug(
2ba1fe69 3019 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3020 vty_out(vty,
3021 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3022
3023 return bgp_vty_return(vty, ret);
3024}
3025
3026DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3027 bgp_neighbor_graceful_restart_disable_set_cmd,
3028 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3029 NEIGHBOR_STR
3030 NEIGHBOR_ADDR_STR2
3031 GR_NEIGHBOR_DISABLE_CMD
055679e9 3032 )
3033{
3034 int idx_peer = 1;
3035 struct peer *peer;
3036 int ret = BGP_GR_FAILURE;
3037
dc95985f 3038 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3039
055679e9 3040 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3041 zlog_debug(
2ba1fe69 3042 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3043
3044 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3045 if (!peer)
3046 return CMD_WARNING_CONFIG_FAILED;
3047
36235319 3048 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3049
3050 if (peer->bgp->t_startup)
3051 bgp_peer_gr_flags_update(peer);
3052
dc95985f 3053 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3054 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3055
055679e9 3056 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3057 zlog_debug(
2ba1fe69 3058 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3059 vty_out(vty,
3060 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3061
3062 return bgp_vty_return(vty, ret);
3063}
3064
3065DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3066 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3067 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3068 NO_STR
3069 NEIGHBOR_STR
3070 NEIGHBOR_ADDR_STR2
3071 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3072 )
3073{
3074 int idx_peer = 2;
3075 int ret = BGP_GR_FAILURE;
3076 struct peer *peer;
3077
dc95985f 3078 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3079
055679e9 3080 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3081 if (!peer)
3082 return CMD_WARNING_CONFIG_FAILED;
3083
3084 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3085 zlog_debug(
2ba1fe69 3086 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3087
3088 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3089
dc95985f 3090 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3091 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3092
3093 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3094 zlog_debug(
2ba1fe69 3095 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3096 vty_out(vty,
3097 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3098
3099 return bgp_vty_return(vty, ret);
3100}
3101
d6e3c15b 3102DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3103 bgp_graceful_restart_disable_eor_cmd,
3104 "bgp graceful-restart disable-eor",
e9273987 3105 BGP_STR
d6e3c15b 3106 "Graceful restart configuration parameters\n"
3107 "Disable EOR Check\n")
3108{
3109 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3110 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3111
d6e3c15b 3112 return CMD_SUCCESS;
3113}
3114
3115DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3116 no_bgp_graceful_restart_disable_eor_cmd,
3117 "no bgp graceful-restart disable-eor",
3118 NO_STR
e9273987 3119 BGP_STR
d6e3c15b 3120 "Graceful restart configuration parameters\n"
3121 "Disable EOR Check\n")
3122{
3123 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3124 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3125
3126 return CMD_SUCCESS;
3127}
3128
3129DEFUN (bgp_graceful_restart_rib_stale_time,
3130 bgp_graceful_restart_rib_stale_time_cmd,
3131 "bgp graceful-restart rib-stale-time (1-3600)",
e9273987 3132 BGP_STR
dc95985f 3133 "Graceful restart configuration parameters\n"
3134 "Specify the stale route removal timer in rib\n"
3135 "Delay value (seconds)\n")
3136{
3137 VTY_DECLVAR_CONTEXT(bgp, bgp);
3138 int idx_number = 3;
3139 uint32_t stale_time;
3140
3141 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3142 bgp->rib_stale_time = stale_time;
3143 /* Send the stale timer update message to RIB */
3144 if (bgp_zebra_stale_timer_update(bgp))
3145 return CMD_WARNING;
3146
3147 return CMD_SUCCESS;
3148}
3149
3150DEFUN (no_bgp_graceful_restart_rib_stale_time,
3151 no_bgp_graceful_restart_rib_stale_time_cmd,
3152 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3153 NO_STR
e9273987 3154 BGP_STR
dc95985f 3155 "Graceful restart configuration parameters\n"
3156 "Specify the stale route removal timer in rib\n"
3157 "Delay value (seconds)\n")
3158{
3159 VTY_DECLVAR_CONTEXT(bgp, bgp);
3160
3161 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3162 /* Send the stale timer update message to RIB */
3163 if (bgp_zebra_stale_timer_update(bgp))
3164 return CMD_WARNING;
3165
d6e3c15b 3166 return CMD_SUCCESS;
3167}
3168
8606be87 3169DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
7f8a9a24
DA
3170 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3171 BGP_STR
8606be87
DA
3172 "Enable Long-lived Graceful Restart\n"
3173 "Specifies maximum time to wait before purging long-lived stale routes\n"
3174 "Stale time value (seconds)\n")
3175{
3176 VTY_DECLVAR_CONTEXT(bgp, bgp);
3177
3178 uint32_t llgr_stale_time;
3179
3180 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3181 bgp->llgr_stale_time = llgr_stale_time;
3182
3183 return CMD_SUCCESS;
3184}
3185
3186DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
7f8a9a24 3187 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
8606be87
DA
3188 NO_STR BGP_STR
3189 "Enable Long-lived Graceful Restart\n"
3190 "Specifies maximum time to wait before purging long-lived stale routes\n"
3191 "Stale time value (seconds)\n")
3192{
3193 VTY_DECLVAR_CONTEXT(bgp, bgp);
3194
3195 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3196
3197 return CMD_SUCCESS;
3198}
3199
1ca2fd11
IR
3200static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3201 struct bgp *bgp)
05bd726c 3202{
3203 bgp_static_redo_import_check(bgp);
3204 bgp_redistribute_redo(bgp);
1ca2fd11
IR
3205 bgp_clear_star_soft_out(vty, bgp->name);
3206 bgp_clear_star_soft_in(vty, bgp->name);
05bd726c 3207}
3208
3209static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3210{
3211 struct listnode *node, *nnode;
3212 struct bgp *bgp;
3213 bool vrf_cfg = false;
3214
3215 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3216 return CMD_SUCCESS;
3217
3218 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3219 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3220 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3221 vty_out(vty,
3222 "%% graceful-shutdown configuration found in vrf %s\n",
3223 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3224 VRF_DEFAULT_NAME : bgp->name);
3225 vrf_cfg = true;
3226 }
3227 }
3228
3229 if (vrf_cfg) {
3230 vty_out(vty,
3231 "%%Failed: global graceful-shutdown not permitted\n");
3232 return CMD_WARNING;
3233 }
3234
3235 /* Set flag globally */
3236 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3237
3238 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3239 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3240 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3241
3242 return CMD_SUCCESS;
3243}
3244
3245static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3246{
3247 struct listnode *node, *nnode;
3248 struct bgp *bgp;
3249
3250 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3251 return CMD_SUCCESS;
3252
3253 /* Unset flag globally */
3254 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3255
3256 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3257 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3258 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3259
3260 return CMD_SUCCESS;
3261}
3262
7f323236
DW
3263/* "bgp graceful-shutdown" configuration */
3264DEFUN (bgp_graceful_shutdown,
3265 bgp_graceful_shutdown_cmd,
3266 "bgp graceful-shutdown",
3267 BGP_STR
3268 "Graceful shutdown parameters\n")
3269{
05bd726c 3270 if (vty->node == CONFIG_NODE)
3271 return bgp_global_graceful_shutdown_config_vty(vty);
3272
1ca2fd11 3273 VTY_DECLVAR_CONTEXT(bgp, bgp);
7f323236 3274
1ca2fd11
IR
3275 /* if configured globally, per-instance config is not allowed */
3276 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3277 vty_out(vty,
3278 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3279 return CMD_WARNING_CONFIG_FAILED;
3280 }
3281
3282 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3283 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3284 bgp_initiate_graceful_shut_unshut(vty, bgp);
3285 }
3286
3287 return CMD_SUCCESS;
7f323236
DW
3288}
3289
1ca2fd11 3290DEFUN (no_bgp_graceful_shutdown,
7f323236
DW
3291 no_bgp_graceful_shutdown_cmd,
3292 "no bgp graceful-shutdown",
3293 NO_STR
3294 BGP_STR
3295 "Graceful shutdown parameters\n")
3296{
05bd726c 3297 if (vty->node == CONFIG_NODE)
3298 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3299
1ca2fd11 3300 VTY_DECLVAR_CONTEXT(bgp, bgp);
05bd726c 3301
1ca2fd11
IR
3302 /* If configured globally, cannot remove from one bgp instance */
3303 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3304 vty_out(vty,
3305 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3306 return CMD_WARNING_CONFIG_FAILED;
3307 }
7f323236 3308
1ca2fd11
IR
3309 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3310 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3311 bgp_initiate_graceful_shut_unshut(vty, bgp);
3312 }
3313
3314 return CMD_SUCCESS;
7f323236
DW
3315}
3316
718e3744 3317/* "bgp fast-external-failover" configuration. */
1ca2fd11 3318DEFUN (bgp_fast_external_failover,
718e3744 3319 bgp_fast_external_failover_cmd,
3320 "bgp fast-external-failover",
3321 BGP_STR
3322 "Immediately reset session if a link to a directly connected external peer goes down\n")
3323{
1ca2fd11
IR
3324 VTY_DECLVAR_CONTEXT(bgp, bgp);
3325 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3326 return CMD_SUCCESS;
718e3744 3327}
3328
1ca2fd11 3329DEFUN (no_bgp_fast_external_failover,
718e3744 3330 no_bgp_fast_external_failover_cmd,
3331 "no bgp fast-external-failover",
3332 NO_STR
3333 BGP_STR
3334 "Immediately reset session if a link to a directly connected external peer goes down\n")
3335{
1ca2fd11
IR
3336 VTY_DECLVAR_CONTEXT(bgp, bgp);
3337 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3338 return CMD_SUCCESS;
718e3744 3339}
6b0655a2 3340
718e3744 3341/* "bgp bestpath compare-routerid" configuration. */
1ca2fd11
IR
3342DEFUN (bgp_bestpath_compare_router_id,
3343 bgp_bestpath_compare_router_id_cmd,
3344 "bgp bestpath compare-routerid",
e9273987 3345 BGP_STR
1ca2fd11
IR
3346 "Change the default bestpath selection\n"
3347 "Compare router-id for identical EBGP paths\n")
718e3744 3348{
1ca2fd11
IR
3349 VTY_DECLVAR_CONTEXT(bgp, bgp);
3350 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3351 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3352
1ca2fd11 3353 return CMD_SUCCESS;
718e3744 3354}
3355
1ca2fd11
IR
3356DEFUN (no_bgp_bestpath_compare_router_id,
3357 no_bgp_bestpath_compare_router_id_cmd,
3358 "no bgp bestpath compare-routerid",
3359 NO_STR
e9273987 3360 BGP_STR
1ca2fd11
IR
3361 "Change the default bestpath selection\n"
3362 "Compare router-id for identical EBGP paths\n")
718e3744 3363{
1ca2fd11
IR
3364 VTY_DECLVAR_CONTEXT(bgp, bgp);
3365 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3366 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3367
1ca2fd11 3368 return CMD_SUCCESS;
718e3744 3369}
6b0655a2 3370
718e3744 3371/* "bgp bestpath as-path ignore" configuration. */
1ca2fd11
IR
3372DEFUN (bgp_bestpath_aspath_ignore,
3373 bgp_bestpath_aspath_ignore_cmd,
3374 "bgp bestpath as-path ignore",
e9273987 3375 BGP_STR
1ca2fd11
IR
3376 "Change the default bestpath selection\n"
3377 "AS-path attribute\n"
3378 "Ignore as-path length in selecting a route\n")
718e3744 3379{
1ca2fd11
IR
3380 VTY_DECLVAR_CONTEXT(bgp, bgp);
3381 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3382 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3383
1ca2fd11 3384 return CMD_SUCCESS;
718e3744 3385}
3386
1ca2fd11
IR
3387DEFUN (no_bgp_bestpath_aspath_ignore,
3388 no_bgp_bestpath_aspath_ignore_cmd,
3389 "no bgp bestpath as-path ignore",
3390 NO_STR
e9273987 3391 BGP_STR
1ca2fd11
IR
3392 "Change the default bestpath selection\n"
3393 "AS-path attribute\n"
3394 "Ignore as-path length in selecting a route\n")
718e3744 3395{
1ca2fd11
IR
3396 VTY_DECLVAR_CONTEXT(bgp, bgp);
3397 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3398 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3399
1ca2fd11 3400 return CMD_SUCCESS;
718e3744 3401}
6b0655a2 3402
6811845b 3403/* "bgp bestpath as-path confed" configuration. */
1ca2fd11 3404DEFUN (bgp_bestpath_aspath_confed,
6811845b 3405 bgp_bestpath_aspath_confed_cmd,
3406 "bgp bestpath as-path confed",
e9273987 3407 BGP_STR
6811845b 3408 "Change the default bestpath selection\n"
3409 "AS-path attribute\n"
3410 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3411{
1ca2fd11
IR
3412 VTY_DECLVAR_CONTEXT(bgp, bgp);
3413 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3414 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3415
1ca2fd11 3416 return CMD_SUCCESS;
6811845b 3417}
3418
1ca2fd11 3419DEFUN (no_bgp_bestpath_aspath_confed,
6811845b 3420 no_bgp_bestpath_aspath_confed_cmd,
3421 "no bgp bestpath as-path confed",
3422 NO_STR
e9273987 3423 BGP_STR
6811845b 3424 "Change the default bestpath selection\n"
3425 "AS-path attribute\n"
3426 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3427{
1ca2fd11
IR
3428 VTY_DECLVAR_CONTEXT(bgp, bgp);
3429 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3430 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3431
1ca2fd11 3432 return CMD_SUCCESS;
6811845b 3433}
6b0655a2 3434
2fdd455c 3435/* "bgp bestpath as-path multipath-relax" configuration. */
1ca2fd11 3436DEFUN (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3437 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3438 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
e9273987 3439 BGP_STR
16fc1eec
DS
3440 "Change the default bestpath selection\n"
3441 "AS-path attribute\n"
3442 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3443 "Generate an AS_SET\n"
16fc1eec
DS
3444 "Do not generate an AS_SET\n")
3445{
1ca2fd11 3446 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3447 int idx = 0;
1ca2fd11 3448 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 3449
1ca2fd11
IR
3450 /* no-as-set is now the default behavior so we can silently
3451 * ignore it */
d62a17ae 3452 if (argv_find(argv, argc, "as-set", &idx))
1ca2fd11 3453 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 3454 else
1ca2fd11 3455 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
7aafcaca 3456
1ca2fd11
IR
3457 bgp_recalculate_all_bestpaths(bgp);
3458
3459 return CMD_SUCCESS;
16fc1eec
DS
3460}
3461
1ca2fd11 3462DEFUN (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3463 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3464 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec 3465 NO_STR
e9273987 3466 BGP_STR
16fc1eec
DS
3467 "Change the default bestpath selection\n"
3468 "AS-path attribute\n"
3469 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3470 "Generate an AS_SET\n"
16fc1eec
DS
3471 "Do not generate an AS_SET\n")
3472{
1ca2fd11
IR
3473 VTY_DECLVAR_CONTEXT(bgp, bgp);
3474 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3475 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3476 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3477
1ca2fd11 3478 return CMD_SUCCESS;
2fdd455c 3479}
6b0655a2 3480
ee88563a
JM
3481/* "bgp bestpath peer-type multipath-relax" configuration. */
3482DEFUN(bgp_bestpath_peer_type_multipath_relax,
3483 bgp_bestpath_peer_type_multipath_relax_cmd,
3484 "bgp bestpath peer-type multipath-relax",
3485 BGP_STR
3486 "Change the default bestpath selection\n"
3487 "Peer type\n"
3488 "Allow load sharing across routes learned from different peer types\n")
3489{
3490 VTY_DECLVAR_CONTEXT(bgp, bgp);
3491 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3492 bgp_recalculate_all_bestpaths(bgp);
3493
3494 return CMD_SUCCESS;
3495}
3496
3497DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3498 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3499 "no bgp bestpath peer-type multipath-relax",
3500 NO_STR BGP_STR
3501 "Change the default bestpath selection\n"
3502 "Peer type\n"
3503 "Allow load sharing across routes learned from different peer types\n")
3504{
3505 VTY_DECLVAR_CONTEXT(bgp, bgp);
3506 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3507 bgp_recalculate_all_bestpaths(bgp);
3508
3509 return CMD_SUCCESS;
3510}
3511
848973c7 3512/* "bgp log-neighbor-changes" configuration. */
1ca2fd11
IR
3513DEFUN (bgp_log_neighbor_changes,
3514 bgp_log_neighbor_changes_cmd,
3515 "bgp log-neighbor-changes",
e9273987 3516 BGP_STR
1ca2fd11 3517 "Log neighbor up/down and reset reason\n")
848973c7 3518{
1ca2fd11
IR
3519 VTY_DECLVAR_CONTEXT(bgp, bgp);
3520 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3521 return CMD_SUCCESS;
848973c7 3522}
3523
1ca2fd11
IR
3524DEFUN (no_bgp_log_neighbor_changes,
3525 no_bgp_log_neighbor_changes_cmd,
3526 "no bgp log-neighbor-changes",
3527 NO_STR
e9273987 3528 BGP_STR
1ca2fd11 3529 "Log neighbor up/down and reset reason\n")
848973c7 3530{
1ca2fd11
IR
3531 VTY_DECLVAR_CONTEXT(bgp, bgp);
3532 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3533 return CMD_SUCCESS;
848973c7 3534}
6b0655a2 3535
718e3744 3536/* "bgp bestpath med" configuration. */
1ca2fd11 3537DEFUN (bgp_bestpath_med,
718e3744 3538 bgp_bestpath_med_cmd,
2d8c1a4d 3539 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
e9273987 3540 BGP_STR
718e3744 3541 "Change the default bestpath selection\n"
3542 "MED attribute\n"
3543 "Compare MED among confederation paths\n"
838758ac
DW
3544 "Treat missing MED as the least preferred one\n"
3545 "Treat missing MED as the least preferred one\n"
3546 "Compare MED among confederation paths\n")
718e3744 3547{
1ca2fd11 3548 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3549
1ca2fd11 3550 int idx = 0;
d62a17ae 3551 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3552 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3553 idx = 0;
3554 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11 3555 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 3556
1ca2fd11 3557 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3558
1ca2fd11 3559 return CMD_SUCCESS;
718e3744 3560}
3561
1ca2fd11 3562DEFUN (no_bgp_bestpath_med,
718e3744 3563 no_bgp_bestpath_med_cmd,
2d8c1a4d 3564 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3565 NO_STR
e9273987 3566 BGP_STR
718e3744 3567 "Change the default bestpath selection\n"
3568 "MED attribute\n"
3569 "Compare MED among confederation paths\n"
3a2d747c
QY
3570 "Treat missing MED as the least preferred one\n"
3571 "Treat missing MED as the least preferred one\n"
3572 "Compare MED among confederation paths\n")
718e3744 3573{
1ca2fd11 3574 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3575
1ca2fd11 3576 int idx = 0;
d62a17ae 3577 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3578 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3579 idx = 0;
3580 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11
IR
3581 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3582
3583 bgp_recalculate_all_bestpaths(bgp);
718e3744 3584
1ca2fd11 3585 return CMD_SUCCESS;
718e3744 3586}
3587
f7e1c681 3588/* "bgp bestpath bandwidth" configuration. */
3589DEFPY (bgp_bestpath_bw,
3590 bgp_bestpath_bw_cmd,
ad36d216 3591 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
e9273987 3592 BGP_STR
f7e1c681 3593 "Change the default bestpath selection\n"
3594 "Link Bandwidth attribute\n"
3595 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3596 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3597 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3598{
3599 VTY_DECLVAR_CONTEXT(bgp, bgp);
3600 afi_t afi;
3601 safi_t safi;
3602
ad36d216
DS
3603 if (!bw_cfg) {
3604 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3605 return CMD_ERR_INCOMPLETE;
f7e1c681 3606 }
ad36d216
DS
3607 if (!strcmp(bw_cfg, "ignore"))
3608 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3609 else if (!strcmp(bw_cfg, "skip-missing"))
3610 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3611 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3612 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3613 else
3614 return CMD_ERR_NO_MATCH;
f7e1c681 3615
3616 /* This config is used in route install, so redo that. */
3617 FOREACH_AFI_SAFI (afi, safi) {
3618 if (!bgp_fibupd_safi(safi))
3619 continue;
3620 bgp_zebra_announce_table(bgp, afi, safi);
3621 }
3622
3623 return CMD_SUCCESS;
3624}
3625
ad36d216
DS
3626DEFPY (no_bgp_bestpath_bw,
3627 no_bgp_bestpath_bw_cmd,
3628 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3629 NO_STR
e9273987 3630 BGP_STR
ad36d216
DS
3631 "Change the default bestpath selection\n"
3632 "Link Bandwidth attribute\n"
3633 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3634 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3635 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3636{
3637 VTY_DECLVAR_CONTEXT(bgp, bgp);
3638 afi_t afi;
3639 safi_t safi;
3640
3641 bgp->lb_handling = BGP_LINK_BW_ECMP;
3642
3643 /* This config is used in route install, so redo that. */
3644 FOREACH_AFI_SAFI (afi, safi) {
3645 if (!bgp_fibupd_safi(safi))
3646 continue;
3647 bgp_zebra_announce_table(bgp, afi, safi);
3648 }
3649 return CMD_SUCCESS;
3650}
3651
b16bcbba 3652DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
38d11af5
TA
3653 "[no] bgp default <ipv4-unicast|"
3654 "ipv4-multicast|"
3655 "ipv4-vpn|"
3656 "ipv4-labeled-unicast|"
3657 "ipv4-flowspec|"
3658 "ipv6-unicast|"
3659 "ipv6-multicast|"
3660 "ipv6-vpn|"
3661 "ipv6-labeled-unicast|"
3662 "ipv6-flowspec|"
3663 "l2vpn-evpn>$afi_safi",
b16bcbba 3664 NO_STR
e9273987 3665 BGP_STR
e84c59af 3666 "Configure BGP defaults\n"
b16bcbba 3667 "Activate ipv4-unicast for a peer by default\n"
38d11af5
TA
3668 "Activate ipv4-multicast for a peer by default\n"
3669 "Activate ipv4-vpn for a peer by default\n"
3670 "Activate ipv4-labeled-unicast for a peer by default\n"
3671 "Activate ipv4-flowspec for a peer by default\n"
3672 "Activate ipv6-unicast for a peer by default\n"
3673 "Activate ipv6-multicast for a peer by default\n"
3674 "Activate ipv6-vpn for a peer by default\n"
3675 "Activate ipv6-labeled-unicast for a peer by default\n"
3676 "Activate ipv6-flowspec for a peer by default\n"
3677 "Activate l2vpn-evpn for a peer by default\n")
e84c59af
DA
3678{
3679 VTY_DECLVAR_CONTEXT(bgp, bgp);
b16bcbba
TA
3680 char afi_safi_str[strlen(afi_safi) + 1];
3681 char *afi_safi_str_tok;
e84c59af 3682
b16bcbba
TA
3683 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3684 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3685 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3686 afi_t afi = bgp_vty_afi_from_str(afi_str);
38d11af5 3687 safi_t safi;
e84c59af 3688
38d11af5
TA
3689 if (strmatch(safi_str, "labeled"))
3690 safi = bgp_vty_safi_from_str("labeled-unicast");
3691 else
3692 safi = bgp_vty_safi_from_str(safi_str);
b16bcbba
TA
3693
3694 if (no)
3695 bgp->default_af[afi][safi] = false;
38d11af5
TA
3696 else {
3697 if ((safi == SAFI_LABELED_UNICAST
3698 && bgp->default_af[afi][SAFI_UNICAST])
3699 || (safi == SAFI_UNICAST
3700 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3701 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3702 else
3703 bgp->default_af[afi][safi] = true;
3704 }
718e3744 3705
d62a17ae 3706 return CMD_SUCCESS;
718e3744 3707}
6b0655a2 3708
04b6bdc0 3709/* Display hostname in certain command outputs */
1ca2fd11 3710DEFUN (bgp_default_show_hostname,
04b6bdc0
DW
3711 bgp_default_show_hostname_cmd,
3712 "bgp default show-hostname",
e9273987 3713 BGP_STR
04b6bdc0 3714 "Configure BGP defaults\n"
0437e105 3715 "Show hostname in certain command outputs\n")
04b6bdc0 3716{
1ca2fd11
IR
3717 VTY_DECLVAR_CONTEXT(bgp, bgp);
3718 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3719 return CMD_SUCCESS;
ff8a8a7a
CS
3720}
3721
1ca2fd11
IR
3722DEFUN (no_bgp_default_show_hostname,
3723 no_bgp_default_show_hostname_cmd,
3724 "no bgp default show-hostname",
3725 NO_STR
e9273987 3726 BGP_STR
1ca2fd11
IR
3727 "Configure BGP defaults\n"
3728 "Show hostname in certain command outputs\n")
ff8a8a7a 3729{
1ca2fd11
IR
3730 VTY_DECLVAR_CONTEXT(bgp, bgp);
3731 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3732 return CMD_SUCCESS;
04b6bdc0
DW
3733}
3734
aef999a2 3735/* Display hostname in certain command outputs */
1d80f243
IR
3736DEFUN (bgp_default_show_nexthop_hostname,
3737 bgp_default_show_nexthop_hostname_cmd,
3738 "bgp default show-nexthop-hostname",
e9273987 3739 BGP_STR
1d80f243
IR
3740 "Configure BGP defaults\n"
3741 "Show hostname for nexthop in certain command outputs\n")
aef999a2 3742{
1ca2fd11
IR
3743 VTY_DECLVAR_CONTEXT(bgp, bgp);
3744 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3745 return CMD_SUCCESS;
aef999a2
DA
3746}
3747
3748DEFUN (no_bgp_default_show_nexthop_hostname,
3749 no_bgp_default_show_nexthop_hostname_cmd,
3750 "no bgp default show-nexthop-hostname",
3751 NO_STR
e9273987 3752 BGP_STR
aef999a2
DA
3753 "Configure BGP defaults\n"
3754 "Show hostname for nexthop in certain command outputs\n")
3755{
1ca2fd11
IR
3756 VTY_DECLVAR_CONTEXT(bgp, bgp);
3757 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3758 return CMD_SUCCESS;
aef999a2
DA
3759}
3760
8233ef81 3761/* "bgp network import-check" configuration. */
1ca2fd11
IR
3762DEFUN (bgp_network_import_check,
3763 bgp_network_import_check_cmd,
3764 "bgp network import-check",
e9273987 3765 BGP_STR
1ca2fd11
IR
3766 "BGP network command\n"
3767 "Check BGP network route exists in IGP\n")
718e3744 3768{
1ca2fd11
IR
3769 VTY_DECLVAR_CONTEXT(bgp, bgp);
3770 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3771 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3772 bgp_static_redo_import_check(bgp);
3773 }
078430f6 3774
1ca2fd11 3775 return CMD_SUCCESS;
718e3744 3776}
3777
d62a17ae 3778ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3779 "bgp network import-check exact",
e9273987 3780 BGP_STR
d62a17ae 3781 "BGP network command\n"
3782 "Check BGP network route exists in IGP\n"
3783 "Match route precisely\n")
8233ef81 3784
1ca2fd11
IR
3785DEFUN (no_bgp_network_import_check,
3786 no_bgp_network_import_check_cmd,
3787 "no bgp network import-check",
3788 NO_STR
e9273987 3789 BGP_STR
1ca2fd11
IR
3790 "BGP network command\n"
3791 "Check BGP network route exists in IGP\n")
718e3744 3792{
1ca2fd11
IR
3793 VTY_DECLVAR_CONTEXT(bgp, bgp);
3794 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3795 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3796 bgp_static_redo_import_check(bgp);
3797 }
6b0655a2 3798
1ca2fd11 3799 return CMD_SUCCESS;
ff8a8a7a 3800}
718e3744 3801
1ca2fd11
IR
3802DEFUN (bgp_default_local_preference,
3803 bgp_default_local_preference_cmd,
3804 "bgp default local-preference (0-4294967295)",
e9273987 3805 BGP_STR
1ca2fd11
IR
3806 "Configure BGP defaults\n"
3807 "local preference (higher=more preferred)\n"
3808 "Configure default local preference value\n")
ff8a8a7a 3809{
1ca2fd11 3810 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3811 int idx_number = 3;
1ca2fd11 3812 uint32_t local_pref;
718e3744 3813
1ca2fd11 3814 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 3815
1ca2fd11
IR
3816 bgp_default_local_preference_set(bgp, local_pref);
3817 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 3818
1ca2fd11 3819 return CMD_SUCCESS;
718e3744 3820}
3821
1ca2fd11
IR
3822DEFUN (no_bgp_default_local_preference,
3823 no_bgp_default_local_preference_cmd,
3824 "no bgp default local-preference [(0-4294967295)]",
3825 NO_STR
e9273987 3826 BGP_STR
1ca2fd11
IR
3827 "Configure BGP defaults\n"
3828 "local preference (higher=more preferred)\n"
3829 "Configure default local preference value\n")
ff8a8a7a 3830{
1ca2fd11
IR
3831 VTY_DECLVAR_CONTEXT(bgp, bgp);
3832 bgp_default_local_preference_unset(bgp);
3833 bgp_clear_star_soft_in(vty, bgp->name);
3834
3835 return CMD_SUCCESS;
ff8a8a7a 3836}
6b0655a2 3837
ff8a8a7a 3838
1ca2fd11
IR
3839DEFUN (bgp_default_subgroup_pkt_queue_max,
3840 bgp_default_subgroup_pkt_queue_max_cmd,
3841 "bgp default subgroup-pkt-queue-max (20-100)",
e9273987 3842 BGP_STR
1ca2fd11
IR
3843 "Configure BGP defaults\n"
3844 "subgroup-pkt-queue-max\n"
3845 "Configure subgroup packet queue max\n")
8bd9d948 3846{
1ca2fd11 3847 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3848 int idx_number = 3;
1ca2fd11 3849 uint32_t max_size;
3f9c7369 3850
1ca2fd11 3851 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 3852
1ca2fd11 3853 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
ff8a8a7a 3854
1ca2fd11 3855 return CMD_SUCCESS;
8bd9d948
DS
3856}
3857
1ca2fd11
IR
3858DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3859 no_bgp_default_subgroup_pkt_queue_max_cmd,
3860 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3861 NO_STR
e9273987 3862 BGP_STR
1ca2fd11
IR
3863 "Configure BGP defaults\n"
3864 "subgroup-pkt-queue-max\n"
3865 "Configure subgroup packet queue max\n")
ff8a8a7a 3866{
1ca2fd11
IR
3867 VTY_DECLVAR_CONTEXT(bgp, bgp);
3868 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3869 return CMD_SUCCESS;
ff8a8a7a 3870}
813d4307 3871
8bd9d948 3872
1ca2fd11
IR
3873DEFUN (bgp_rr_allow_outbound_policy,
3874 bgp_rr_allow_outbound_policy_cmd,
3875 "bgp route-reflector allow-outbound-policy",
e9273987 3876 BGP_STR
1ca2fd11
IR
3877 "Allow modifications made by out route-map\n"
3878 "on ibgp neighbors\n")
ff8a8a7a 3879{
1ca2fd11 3880 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3881
1ca2fd11
IR
3882 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3883 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3884 update_group_announce_rrclients(bgp);
3885 bgp_clear_star_soft_out(vty, bgp->name);
3886 }
8bd9d948 3887
1ca2fd11
IR
3888 return CMD_SUCCESS;
3889}
ff8a8a7a 3890
1ca2fd11
IR
3891DEFUN (no_bgp_rr_allow_outbound_policy,
3892 no_bgp_rr_allow_outbound_policy_cmd,
3893 "no bgp route-reflector allow-outbound-policy",
3894 NO_STR
e9273987 3895 BGP_STR
1ca2fd11
IR
3896 "Allow modifications made by out route-map\n"
3897 "on ibgp neighbors\n")
8bd9d948 3898{
1ca2fd11 3899 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 3900
1ca2fd11
IR
3901 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3902 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3903 update_group_announce_rrclients(bgp);
3904 bgp_clear_star_soft_out(vty, bgp->name);
d62a17ae 3905 }
8bd9d948 3906
1ca2fd11 3907 return CMD_SUCCESS;
8bd9d948
DS
3908}
3909
1ca2fd11
IR
3910DEFUN (bgp_listen_limit,
3911 bgp_listen_limit_cmd,
3912 "bgp listen limit (1-65535)",
e9273987 3913 BGP_STR
1ca2fd11
IR
3914 "BGP Dynamic Neighbors listen commands\n"
3915 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3916 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3917{
1ca2fd11 3918 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3919 int idx_number = 3;
1ca2fd11
IR
3920 int listen_limit;
3921
3922 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 3923
1ca2fd11 3924 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 3925
1ca2fd11 3926 return CMD_SUCCESS;
f14e6fdb
DS
3927}
3928
1ca2fd11
IR
3929DEFUN (no_bgp_listen_limit,
3930 no_bgp_listen_limit_cmd,
3931 "no bgp listen limit [(1-65535)]",
3932 NO_STR
e9273987 3933 BGP_STR
1ca2fd11
IR
3934 "BGP Dynamic Neighbors listen commands\n"
3935 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3936 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3937{
1ca2fd11
IR
3938 VTY_DECLVAR_CONTEXT(bgp, bgp);
3939 bgp_listen_limit_unset(bgp);
3940 return CMD_SUCCESS;
f14e6fdb
DS
3941}
3942
3943
20eb8864 3944/*
3945 * Check if this listen range is already configured. Check for exact
3946 * match or overlap based on input.
3947 */
d62a17ae 3948static struct peer_group *listen_range_exists(struct bgp *bgp,
3949 struct prefix *range, int exact)
3950{
3951 struct listnode *node, *nnode;
3952 struct listnode *node1, *nnode1;
3953 struct peer_group *group;
3954 struct prefix *lr;
3955 afi_t afi;
3956 int match;
3957
3958 afi = family2afi(range->family);
3959 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3960 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3961 lr)) {
3962 if (exact)
3963 match = prefix_same(range, lr);
3964 else
3965 match = (prefix_match(range, lr)
3966 || prefix_match(lr, range));
3967 if (match)
3968 return group;
3969 }
3970 }
3971
3972 return NULL;
20eb8864 3973}
3974
f14e6fdb
DS
3975DEFUN (bgp_listen_range,
3976 bgp_listen_range_cmd,
d7b9898c 3977 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
e9273987 3978 BGP_STR
d7fa34c1
QY
3979 "Configure BGP dynamic neighbors listen range\n"
3980 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
3981 NEIGHBOR_ADDR_STR
3982 "Member of the peer-group\n"
3983 "Peer-group name\n")
f14e6fdb 3984{
d62a17ae 3985 VTY_DECLVAR_CONTEXT(bgp, bgp);
3986 struct prefix range;
3987 struct peer_group *group, *existing_group;
3988 afi_t afi;
3989 int ret;
3990 int idx = 0;
3991
3992 argv_find(argv, argc, "A.B.C.D/M", &idx);
3993 argv_find(argv, argc, "X:X::X:X/M", &idx);
3994 char *prefix = argv[idx]->arg;
d7b9898c 3995 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3996 char *peergroup = argv[idx]->arg;
3997
3998 /* Convert IP prefix string to struct prefix. */
3999 ret = str2prefix(prefix, &range);
4000 if (!ret) {
4001 vty_out(vty, "%% Malformed listen range\n");
4002 return CMD_WARNING_CONFIG_FAILED;
4003 }
4004
4005 afi = family2afi(range.family);
4006
4007 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4008 vty_out(vty,
4009 "%% Malformed listen range (link-local address)\n");
4010 return CMD_WARNING_CONFIG_FAILED;
4011 }
4012
4013 apply_mask(&range);
4014
4015 /* Check if same listen range is already configured. */
4016 existing_group = listen_range_exists(bgp, &range, 1);
4017 if (existing_group) {
4018 if (strcmp(existing_group->name, peergroup) == 0)
4019 return CMD_SUCCESS;
4020 else {
4021 vty_out(vty,
4022 "%% Same listen range is attached to peer-group %s\n",
4023 existing_group->name);
4024 return CMD_WARNING_CONFIG_FAILED;
4025 }
4026 }
4027
4028 /* Check if an overlapping listen range exists. */
4029 if (listen_range_exists(bgp, &range, 0)) {
4030 vty_out(vty,
4031 "%% Listen range overlaps with existing listen range\n");
4032 return CMD_WARNING_CONFIG_FAILED;
4033 }
4034
4035 group = peer_group_lookup(bgp, peergroup);
4036 if (!group) {
4037 vty_out(vty, "%% Configure the peer-group first\n");
4038 return CMD_WARNING_CONFIG_FAILED;
4039 }
4040
4041 ret = peer_group_listen_range_add(group, &range);
4042 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4043}
4044
4045DEFUN (no_bgp_listen_range,
4046 no_bgp_listen_range_cmd,
d7b9898c 4047 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4048 NO_STR
e9273987 4049 BGP_STR
d7fa34c1
QY
4050 "Unconfigure BGP dynamic neighbors listen range\n"
4051 "Unconfigure BGP dynamic neighbors listen range\n"
4052 NEIGHBOR_ADDR_STR
4053 "Member of the peer-group\n"
4054 "Peer-group name\n")
f14e6fdb 4055{
d62a17ae 4056 VTY_DECLVAR_CONTEXT(bgp, bgp);
4057 struct prefix range;
4058 struct peer_group *group;
4059 afi_t afi;
4060 int ret;
4061 int idx = 0;
4062
4063 argv_find(argv, argc, "A.B.C.D/M", &idx);
4064 argv_find(argv, argc, "X:X::X:X/M", &idx);
4065 char *prefix = argv[idx]->arg;
21d88a71 4066 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4067 char *peergroup = argv[idx]->arg;
4068
4069 /* Convert IP prefix string to struct prefix. */
4070 ret = str2prefix(prefix, &range);
4071 if (!ret) {
4072 vty_out(vty, "%% Malformed listen range\n");
4073 return CMD_WARNING_CONFIG_FAILED;
4074 }
4075
4076 afi = family2afi(range.family);
4077
4078 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4079 vty_out(vty,
4080 "%% Malformed listen range (link-local address)\n");
4081 return CMD_WARNING_CONFIG_FAILED;
4082 }
4083
4084 apply_mask(&range);
4085
4086 group = peer_group_lookup(bgp, peergroup);
4087 if (!group) {
4088 vty_out(vty, "%% Peer-group does not exist\n");
4089 return CMD_WARNING_CONFIG_FAILED;
4090 }
4091
4092 ret = peer_group_listen_range_del(group, &range);
4093 return bgp_vty_return(vty, ret);
4094}
4095
2b791107 4096void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4097{
4098 struct peer_group *group;
4099 struct listnode *node, *nnode, *rnode, *nrnode;
4100 struct prefix *range;
4101 afi_t afi;
d62a17ae 4102
4103 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4104 vty_out(vty, " bgp listen limit %d\n",
4105 bgp->dynamic_neighbors_limit);
4106
4107 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4108 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4109 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4110 nrnode, range)) {
d62a17ae 4111 vty_out(vty,
2dbe669b
DA
4112 " bgp listen range %pFX peer-group %s\n",
4113 range, group->name);
d62a17ae 4114 }
4115 }
4116 }
f14e6fdb
DS
4117}
4118
4119
1ca2fd11
IR
4120DEFUN (bgp_disable_connected_route_check,
4121 bgp_disable_connected_route_check_cmd,
4122 "bgp disable-ebgp-connected-route-check",
e9273987 4123 BGP_STR
1ca2fd11 4124 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4125{
1ca2fd11
IR
4126 VTY_DECLVAR_CONTEXT(bgp, bgp);
4127 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4128 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 4129
1ca2fd11 4130 return CMD_SUCCESS;
907f92c8
DS
4131}
4132
1ca2fd11
IR
4133DEFUN (no_bgp_disable_connected_route_check,
4134 no_bgp_disable_connected_route_check_cmd,
4135 "no bgp disable-ebgp-connected-route-check",
4136 NO_STR
e9273987 4137 BGP_STR
1ca2fd11 4138 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4139{
1ca2fd11
IR
4140 VTY_DECLVAR_CONTEXT(bgp, bgp);
4141 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4142 bgp_clear_star_soft_in(vty, bgp->name);
d62a17ae 4143
1ca2fd11 4144 return CMD_SUCCESS;
d62a17ae 4145}
4146
4147
28c6e247
IR
4148static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4149 const char *as_str)
4150{
4151 VTY_DECLVAR_CONTEXT(bgp, bgp);
4152 int ret;
4153 as_t as;
4154 int as_type = AS_SPECIFIED;
4155 union sockunion su;
4156
4157 if (as_str[0] == 'i') {
4158 as = 0;
4159 as_type = AS_INTERNAL;
4160 } else if (as_str[0] == 'e') {
4161 as = 0;
4162 as_type = AS_EXTERNAL;
4163 } else {
4164 /* Get AS number. */
4165 as = strtoul(as_str, NULL, 10);
4166 }
4167
4168 /* If peer is peer group or interface peer, call proper function. */
4169 ret = str2sockunion(peer_str, &su);
4170 if (ret < 0) {
4171 struct peer *peer;
4172
4173 /* Check if existing interface peer */
4174 peer = peer_lookup_by_conf_if(bgp, peer_str);
4175
4176 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4177
4178 /* if not interface peer, check peer-group settings */
4179 if (ret < 0 && !peer) {
4180 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4181 if (ret < 0) {
4182 vty_out(vty,
4183 "%% Create the peer-group or interface first\n");
4184 return CMD_WARNING_CONFIG_FAILED;
4185 }
4186 return CMD_SUCCESS;
4187 }
4188 } else {
4189 if (peer_address_self_check(bgp, &su)) {
4190 vty_out(vty,
4191 "%% Can not configure the local system as neighbor\n");
4192 return CMD_WARNING_CONFIG_FAILED;
4193 }
4194 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4195 }
4196
4197 /* This peer belongs to peer group. */
4198 switch (ret) {
4199 case BGP_ERR_PEER_GROUP_MEMBER:
4200 vty_out(vty,
4201 "%% Peer-group member cannot override remote-as of peer-group\n");
4202 return CMD_WARNING_CONFIG_FAILED;
4203 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
4204 vty_out(vty,
4205 "%% Peer-group members must be all internal or all external\n");
4206 return CMD_WARNING_CONFIG_FAILED;
4207 }
4208 return bgp_vty_return(vty, ret);
4209}
4210
1ca2fd11
IR
4211DEFUN (bgp_default_shutdown,
4212 bgp_default_shutdown_cmd,
4213 "[no] bgp default shutdown",
4214 NO_STR
4215 BGP_STR
4216 "Configure BGP defaults\n"
4217 "Apply administrative shutdown to newly configured peers\n")
ff8a8a7a 4218{
1ca2fd11
IR
4219 VTY_DECLVAR_CONTEXT(bgp, bgp);
4220 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4221 return CMD_SUCCESS;
f26845f9
QY
4222}
4223
736b68f3
DS
4224DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4225 BGP_STR
9ddf4b81 4226 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4227 "Add a shutdown message (RFC 8203)\n"
4228 "Shutdown message\n")
9cf59432 4229{
736b68f3 4230 char *msgstr = NULL;
8389c83a 4231
9cf59432
DS
4232 VTY_DECLVAR_CONTEXT(bgp, bgp);
4233
8389c83a 4234 if (argc > 3)
f80e35b6 4235 msgstr = argv_concat(argv, argc, 3);
8389c83a 4236
b776f48c
DA
4237 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4238 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4239 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4240 return CMD_WARNING_CONFIG_FAILED;
4241 }
4242
8389c83a
DS
4243 bgp_shutdown_enable(bgp, msgstr);
4244 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4245
4246 return CMD_SUCCESS;
4247}
4248
736b68f3 4249DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4250 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4251{
4252 VTY_DECLVAR_CONTEXT(bgp, bgp);
4253
4254 bgp_shutdown_enable(bgp, NULL);
4255
4256 return CMD_SUCCESS;
4257}
8389c83a 4258
736b68f3 4259DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4260 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4261{
4262 VTY_DECLVAR_CONTEXT(bgp, bgp);
4263
4264 bgp_shutdown_disable(bgp);
4265
4266 return CMD_SUCCESS;
4267}
4268
9ddf4b81 4269ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4270 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4271 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4272 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4273
28c6e247
IR
4274DEFUN (neighbor_remote_as,
4275 neighbor_remote_as_cmd,
4276 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4277 NEIGHBOR_STR
4278 NEIGHBOR_ADDR_STR2
4279 "Specify a BGP neighbor\n"
4280 AS_STR
4281 "Internal BGP peer\n"
4282 "External BGP peer\n")
718e3744 4283{
d62a17ae 4284 int idx_peer = 1;
4285 int idx_remote_as = 3;
28c6e247
IR
4286 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4287 argv[idx_remote_as]->arg);
d62a17ae 4288}
f852eb98
PG
4289/* Enable fast convergence of bgp sessions. If this is enabled, bgp
4290 * sessions do not wait for hold timer expiry to bring down the sessions
4291 * when nexthop becomes unreachable
4292 */
4293DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4294 BGP_STR "Fast convergence for bgp sessions\n")
4295{
4296 VTY_DECLVAR_CONTEXT(bgp, bgp);
4297 bgp->fast_convergence = true;
4298
4299 return CMD_SUCCESS;
4300}
4301
4302DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4303 "no bgp fast-convergence",
4304 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4305{
4306 VTY_DECLVAR_CONTEXT(bgp, bgp);
4307 bgp->fast_convergence = false;
4308
4309 return CMD_SUCCESS;
4310}
d62a17ae 4311
28c6e247
IR
4312static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4313 int v6only,
4314 const char *peer_group_name,
4315 const char *as_str)
d62a17ae 4316{
28c6e247
IR
4317 VTY_DECLVAR_CONTEXT(bgp, bgp);
4318 as_t as = 0;
4319 int as_type = AS_UNSPECIFIED;
d62a17ae 4320 struct peer *peer;
4321 struct peer_group *group;
4322 int ret = 0;
d62a17ae 4323
4324 group = peer_group_lookup(bgp, conf_if);
4325
4326 if (group) {
28c6e247
IR
4327 vty_out(vty, "%% Name conflict with peer-group \n");
4328 return CMD_WARNING_CONFIG_FAILED;
4329 }
4330
4331 if (as_str) {
4332 if (as_str[0] == 'i') {
4333 as_type = AS_INTERNAL;
4334 } else if (as_str[0] == 'e') {
4335 as_type = AS_EXTERNAL;
4336 } else {
4337 /* Get AS number. */
4338 as = strtoul(as_str, NULL, 10);
4339 as_type = AS_SPECIFIED;
4340 }
d62a17ae 4341 }
4342
4343 peer = peer_lookup_by_conf_if(bgp, conf_if);
4344 if (peer) {
28c6e247 4345 if (as_str)
e84c59af 4346 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
d62a17ae 4347 } else {
e84c59af
DA
4348 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4349 NULL);
d62a17ae 4350
4351 if (!peer) {
28c6e247
IR
4352 vty_out(vty, "%% BGP failed to create peer\n");
4353 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4354 }
4355
4356 if (v6only)
527de3dc 4357 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4358
4359 /* Request zebra to initiate IPv6 RAs on this interface. We do
4360 * this
4361 * any unnumbered peer in order to not worry about run-time
4362 * transitions
4363 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4364 * address
4365 * gets deleted later etc.)
4366 */
4367 if (peer->ifp)
4368 bgp_zebra_initiate_radv(bgp, peer);
4369 }
4370
4371 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4372 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4373 if (v6only)
527de3dc 4374 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4375 else
527de3dc 4376 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4377
4378 /* v6only flag changed. Reset bgp seesion */
4379 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4380 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4381 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4382 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4383 } else
4384 bgp_session_reset(peer);
4385 }
4386
9fb964de
PM
4387 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4388 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4389 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4390 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4391 }
d62a17ae 4392
4393 if (peer_group_name) {
4394 group = peer_group_lookup(bgp, peer_group_name);
4395 if (!group) {
28c6e247
IR
4396 vty_out(vty, "%% Configure the peer-group first\n");
4397 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4398 }
4399
8395c1f8 4400 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4401 }
4402
28c6e247 4403 return bgp_vty_return(vty, ret);
a80beece
DS
4404}
4405
28c6e247
IR
4406DEFUN (neighbor_interface_config,
4407 neighbor_interface_config_cmd,
4408 "neighbor WORD interface [peer-group PGNAME]",
4409 NEIGHBOR_STR
4410 "Interface name or neighbor tag\n"
4411 "Enable BGP on interface\n"
4412 "Member of the peer-group\n"
4413 "Peer-group name\n")
4c48cf63 4414{
d62a17ae 4415 int idx_word = 1;
4416 int idx_peer_group_word = 4;
f4b8ec07 4417
d62a17ae 4418 if (argc > idx_peer_group_word)
28c6e247
IR
4419 return peer_conf_interface_get(
4420 vty, argv[idx_word]->arg, 0,
4421 argv[idx_peer_group_word]->arg, NULL);
4422 else
4423 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4424 NULL, NULL);
4c48cf63
DW
4425}
4426
28c6e247
IR
4427DEFUN (neighbor_interface_config_v6only,
4428 neighbor_interface_config_v6only_cmd,
4429 "neighbor WORD interface v6only [peer-group PGNAME]",
4430 NEIGHBOR_STR
4431 "Interface name or neighbor tag\n"
4432 "Enable BGP on interface\n"
4433 "Enable BGP with v6 link-local only\n"
4434 "Member of the peer-group\n"
4435 "Peer-group name\n")
4c48cf63 4436{
d62a17ae 4437 int idx_word = 1;
4438 int idx_peer_group_word = 5;
31500417 4439
d62a17ae 4440 if (argc > idx_peer_group_word)
28c6e247
IR
4441 return peer_conf_interface_get(
4442 vty, argv[idx_word]->arg, 1,
4443 argv[idx_peer_group_word]->arg, NULL);
31500417 4444
28c6e247 4445 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4c48cf63
DW
4446}
4447
a80beece 4448
28c6e247
IR
4449DEFUN (neighbor_interface_config_remote_as,
4450 neighbor_interface_config_remote_as_cmd,
4451 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4452 NEIGHBOR_STR
4453 "Interface name or neighbor tag\n"
4454 "Enable BGP on interface\n"
4455 "Specify a BGP neighbor\n"
4456 AS_STR
4457 "Internal BGP peer\n"
4458 "External BGP peer\n")
b3a39dc5 4459{
d62a17ae 4460 int idx_word = 1;
4461 int idx_remote_as = 4;
28c6e247
IR
4462 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4463 argv[idx_remote_as]->arg);
b3a39dc5
DD
4464}
4465
28c6e247
IR
4466DEFUN (neighbor_interface_v6only_config_remote_as,
4467 neighbor_interface_v6only_config_remote_as_cmd,
4468 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4469 NEIGHBOR_STR
4470 "Interface name or neighbor tag\n"
4471 "Enable BGP with v6 link-local only\n"
4472 "Enable BGP on interface\n"
4473 "Specify a BGP neighbor\n"
4474 AS_STR
4475 "Internal BGP peer\n"
4476 "External BGP peer\n")
b3a39dc5 4477{
d62a17ae 4478 int idx_word = 1;
4479 int idx_remote_as = 5;
28c6e247
IR
4480 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4481 argv[idx_remote_as]->arg);
b3a39dc5
DD
4482}
4483
28c6e247
IR
4484DEFUN (neighbor_peer_group,
4485 neighbor_peer_group_cmd,
4486 "neighbor WORD peer-group",
4487 NEIGHBOR_STR
4488 "Interface name or neighbor tag\n"
4489 "Configure peer-group\n")
718e3744 4490{
28c6e247 4491 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4492 int idx_word = 1;
28c6e247
IR
4493 struct peer *peer;
4494 struct peer_group *group;
718e3744 4495
28c6e247
IR
4496 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4497 if (peer) {
4498 vty_out(vty, "%% Name conflict with interface: \n");
4499 return CMD_WARNING_CONFIG_FAILED;
4500 }
718e3744 4501
28c6e247
IR
4502 group = peer_group_get(bgp, argv[idx_word]->arg);
4503 if (!group) {
4504 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4505 return CMD_WARNING_CONFIG_FAILED;
4506 }
718e3744 4507
28c6e247 4508 return CMD_SUCCESS;
718e3744 4509}
4510
1d80f243
IR
4511DEFUN (no_neighbor,
4512 no_neighbor_cmd,
4513 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4514 NO_STR
4515 NEIGHBOR_STR
4516 NEIGHBOR_ADDR_STR2
4517 "Specify a BGP neighbor\n"
4518 AS_STR
4519 "Internal BGP peer\n"
4520 "External BGP peer\n")
718e3744 4521{
28c6e247 4522 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4523 int idx_peer = 2;
28c6e247 4524 int ret;
d62a17ae 4525 union sockunion su;
28c6e247
IR
4526 struct peer_group *group;
4527 struct peer *peer;
4528 struct peer *other;
d62a17ae 4529
28c6e247
IR
4530 ret = str2sockunion(argv[idx_peer]->arg, &su);
4531 if (ret < 0) {
4532 /* look up for neighbor by interface name config. */
4533 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4534 if (peer) {
4535 /* Request zebra to terminate IPv6 RAs on this
4536 * interface. */
4537 if (peer->ifp)
4538 bgp_zebra_terminate_radv(peer->bgp, peer);
4539 peer_notify_unconfig(peer);
4540 peer_delete(peer);
4541 return CMD_SUCCESS;
d62a17ae 4542 }
28c6e247
IR
4543
4544 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4545 if (group) {
4546 peer_group_notify_unconfig(group);
4547 peer_group_delete(group);
4e2786df 4548 } else {
28c6e247 4549 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4550 return CMD_WARNING_CONFIG_FAILED;
4551 }
28c6e247
IR
4552 } else {
4553 peer = peer_lookup(bgp, &su);
4554 if (peer) {
4555 if (peer_dynamic_neighbor(peer)) {
4556 vty_out(vty,
4557 "%% Operation not allowed on a dynamic neighbor\n");
4558 return CMD_WARNING_CONFIG_FAILED;
4559 }
d62a17ae 4560
28c6e247 4561 other = peer->doppelganger;
f4b8ec07 4562
28c6e247
IR
4563 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4564 bgp_zebra_terminate_radv(peer->bgp, peer);
f4b8ec07 4565
28c6e247
IR
4566 peer_notify_unconfig(peer);
4567 peer_delete(peer);
4568 if (other && other->status != Deleted) {
4569 peer_notify_unconfig(other);
4570 peer_delete(other);
4571 }
4572 }
4573 }
4574
4575 return CMD_SUCCESS;
a80beece
DS
4576}
4577
28c6e247
IR
4578DEFUN (no_neighbor_interface_config,
4579 no_neighbor_interface_config_cmd,
4580 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4581 NO_STR
4582 NEIGHBOR_STR
4583 "Interface name\n"
4584 "Configure BGP on interface\n"
4585 "Enable BGP with v6 link-local only\n"
4586 "Member of the peer-group\n"
4587 "Peer-group name\n"
4588 "Specify a BGP neighbor\n"
4589 AS_STR
4590 "Internal BGP peer\n"
4591 "External BGP peer\n")
718e3744 4592{
28c6e247 4593 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4594 int idx_word = 2;
28c6e247 4595 struct peer *peer;
718e3744 4596
28c6e247
IR
4597 /* look up for neighbor by interface name config. */
4598 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4599 if (peer) {
4600 /* Request zebra to terminate IPv6 RAs on this interface. */
4601 if (peer->ifp)
4602 bgp_zebra_terminate_radv(peer->bgp, peer);
4603 peer_notify_unconfig(peer);
4604 peer_delete(peer);
4605 } else {
4606 vty_out(vty, "%% Create the bgp interface first\n");
4607 return CMD_WARNING_CONFIG_FAILED;
4608 }
4609 return CMD_SUCCESS;
718e3744 4610}
4611
28c6e247
IR
4612DEFUN (no_neighbor_peer_group,
4613 no_neighbor_peer_group_cmd,
4614 "no neighbor WORD peer-group",
4615 NO_STR
4616 NEIGHBOR_STR
4617 "Neighbor tag\n"
4618 "Configure peer-group\n")
718e3744 4619{
28c6e247
IR
4620 VTY_DECLVAR_CONTEXT(bgp, bgp);
4621 int idx_word = 2;
4622 struct peer_group *group;
f4b8ec07 4623
28c6e247
IR
4624 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4625 if (group) {
4626 peer_group_notify_unconfig(group);
4627 peer_group_delete(group);
f4b8ec07 4628 } else {
28c6e247 4629 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4630 return CMD_WARNING_CONFIG_FAILED;
4631 }
28c6e247
IR
4632 return CMD_SUCCESS;
4633}
f4b8ec07 4634
28c6e247
IR
4635DEFUN (no_neighbor_interface_peer_group_remote_as,
4636 no_neighbor_interface_peer_group_remote_as_cmd,
4637 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4638 NO_STR
4639 NEIGHBOR_STR
4640 "Interface name or neighbor tag\n"
4641 "Specify a BGP neighbor\n"
4642 AS_STR
4643 "Internal BGP peer\n"
4644 "External BGP peer\n")
4645{
4646 VTY_DECLVAR_CONTEXT(bgp, bgp);
4647 int idx_word = 2;
4648 struct peer_group *group;
4649 struct peer *peer;
f4b8ec07 4650
28c6e247
IR
4651 /* look up for neighbor by interface name config. */
4652 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4653 if (peer) {
4654 peer_as_change(peer, 0, AS_UNSPECIFIED);
4655 return CMD_SUCCESS;
4656 }
f4b8ec07 4657
28c6e247
IR
4658 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4659 if (group)
4660 peer_group_remote_as_delete(group);
4661 else {
4662 vty_out(vty, "%% Create the peer-group or interface first\n");
4663 return CMD_WARNING_CONFIG_FAILED;
4664 }
4665 return CMD_SUCCESS;
718e3744 4666}
6b0655a2 4667
28c6e247
IR
4668DEFUN (neighbor_local_as,
4669 neighbor_local_as_cmd,
4670 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4671 NEIGHBOR_STR
4672 NEIGHBOR_ADDR_STR2
4673 "Specify a local-as number\n"
4674 "AS number used as local AS\n")
718e3744 4675{
d62a17ae 4676 int idx_peer = 1;
4677 int idx_number = 3;
28c6e247
IR
4678 struct peer *peer;
4679 int ret;
4680 as_t as;
718e3744 4681
28c6e247
IR
4682 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4683 if (!peer)
d62a17ae 4684 return CMD_WARNING_CONFIG_FAILED;
718e3744 4685
28c6e247
IR
4686 as = strtoul(argv[idx_number]->arg, NULL, 10);
4687 ret = peer_local_as_set(peer, as, 0, 0);
4688 return bgp_vty_return(vty, ret);
718e3744 4689}
4690
28c6e247
IR
4691DEFUN (neighbor_local_as_no_prepend,
4692 neighbor_local_as_no_prepend_cmd,
4693 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4694 NEIGHBOR_STR
4695 NEIGHBOR_ADDR_STR2
4696 "Specify a local-as number\n"
4697 "AS number used as local AS\n"
4698 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4699{
d62a17ae 4700 int idx_peer = 1;
4701 int idx_number = 3;
28c6e247
IR
4702 struct peer *peer;
4703 int ret;
4704 as_t as;
718e3744 4705
28c6e247
IR
4706 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4707 if (!peer)
d62a17ae 4708 return CMD_WARNING_CONFIG_FAILED;
718e3744 4709
28c6e247
IR
4710 as = strtoul(argv[idx_number]->arg, NULL, 10);
4711 ret = peer_local_as_set(peer, as, 1, 0);
4712 return bgp_vty_return(vty, ret);
718e3744 4713}
4714
28c6e247
IR
4715DEFUN (neighbor_local_as_no_prepend_replace_as,
4716 neighbor_local_as_no_prepend_replace_as_cmd,
4717 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4718 NEIGHBOR_STR
4719 NEIGHBOR_ADDR_STR2
4720 "Specify a local-as number\n"
4721 "AS number used as local AS\n"
4722 "Do not prepend local-as to updates from ebgp peers\n"
4723 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4724{
d62a17ae 4725 int idx_peer = 1;
4726 int idx_number = 3;
28c6e247
IR
4727 struct peer *peer;
4728 int ret;
4729 as_t as;
9d3f9705 4730
28c6e247
IR
4731 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4732 if (!peer)
d62a17ae 4733 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4734
28c6e247
IR
4735 as = strtoul(argv[idx_number]->arg, NULL, 10);
4736 ret = peer_local_as_set(peer, as, 1, 1);
4737 return bgp_vty_return(vty, ret);
9d3f9705
AC
4738}
4739
28c6e247
IR
4740DEFUN (no_neighbor_local_as,
4741 no_neighbor_local_as_cmd,
4742 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4743 NO_STR
4744 NEIGHBOR_STR
4745 NEIGHBOR_ADDR_STR2
4746 "Specify a local-as number\n"
4747 "AS number used as local AS\n"
4748 "Do not prepend local-as to updates from ebgp peers\n"
4749 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4750{
d62a17ae 4751 int idx_peer = 2;
28c6e247
IR
4752 struct peer *peer;
4753 int ret;
718e3744 4754
28c6e247
IR
4755 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4756 if (!peer)
d62a17ae 4757 return CMD_WARNING_CONFIG_FAILED;
718e3744 4758
28c6e247
IR
4759 ret = peer_local_as_unset(peer);
4760 return bgp_vty_return(vty, ret);
718e3744 4761}
4762
718e3744 4763
3f9c7369
DS
4764DEFUN (neighbor_solo,
4765 neighbor_solo_cmd,
9ccf14f7 4766 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4767 NEIGHBOR_STR
4768 NEIGHBOR_ADDR_STR2
4769 "Solo peer - part of its own update group\n")
4770{
d62a17ae 4771 int idx_peer = 1;
4772 struct peer *peer;
4773 int ret;
3f9c7369 4774
d62a17ae 4775 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4776 if (!peer)
4777 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4778
d62a17ae 4779 ret = update_group_adjust_soloness(peer, 1);
4780 return bgp_vty_return(vty, ret);
3f9c7369
DS
4781}
4782
4783DEFUN (no_neighbor_solo,
4784 no_neighbor_solo_cmd,
9ccf14f7 4785 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4786 NO_STR
4787 NEIGHBOR_STR
4788 NEIGHBOR_ADDR_STR2
4789 "Solo peer - part of its own update group\n")
4790{
d62a17ae 4791 int idx_peer = 2;
4792 struct peer *peer;
4793 int ret;
3f9c7369 4794
d62a17ae 4795 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4796 if (!peer)
4797 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4798
d62a17ae 4799 ret = update_group_adjust_soloness(peer, 0);
4800 return bgp_vty_return(vty, ret);
3f9c7369
DS
4801}
4802
28c6e247
IR
4803DEFUN (neighbor_password,
4804 neighbor_password_cmd,
4805 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4806 NEIGHBOR_STR
4807 NEIGHBOR_ADDR_STR2
4808 "Set a password\n"
4809 "The password\n")
0df7c91f 4810{
d62a17ae 4811 int idx_peer = 1;
4812 int idx_line = 3;
28c6e247
IR
4813 struct peer *peer;
4814 int ret;
0df7c91f 4815
28c6e247
IR
4816 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4817 if (!peer)
d62a17ae 4818 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4819
28c6e247
IR
4820 ret = peer_password_set(peer, argv[idx_line]->arg);
4821 return bgp_vty_return(vty, ret);
0df7c91f
PJ
4822}
4823
28c6e247
IR
4824DEFUN (no_neighbor_password,
4825 no_neighbor_password_cmd,
4826 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4827 NO_STR
4828 NEIGHBOR_STR
4829 NEIGHBOR_ADDR_STR2
4830 "Set a password\n"
4831 "The password\n")
0df7c91f 4832{
d62a17ae 4833 int idx_peer = 2;
28c6e247
IR
4834 struct peer *peer;
4835 int ret;
0df7c91f 4836
28c6e247
IR
4837 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4838 if (!peer)
d62a17ae 4839 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4840
28c6e247
IR
4841 ret = peer_password_unset(peer);
4842 return bgp_vty_return(vty, ret);
0df7c91f 4843}
6b0655a2 4844
28c6e247
IR
4845DEFUN (neighbor_activate,
4846 neighbor_activate_cmd,
4847 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4848 NEIGHBOR_STR
4849 NEIGHBOR_ADDR_STR2
4850 "Enable the Address Family for this Neighbor\n")
718e3744 4851{
d62a17ae 4852 int idx_peer = 1;
28c6e247
IR
4853 int ret;
4854 struct peer *peer;
56ceae84 4855
28c6e247
IR
4856 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4857 if (!peer)
d62a17ae 4858 return CMD_WARNING_CONFIG_FAILED;
718e3744 4859
28c6e247
IR
4860 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4861 return bgp_vty_return(vty, ret);
718e3744 4862}
4863
d62a17ae 4864ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4865 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4866 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4867 "Enable the Address Family for this Neighbor\n")
596c17ba 4868
28c6e247
IR
4869DEFUN (no_neighbor_activate,
4870 no_neighbor_activate_cmd,
4871 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4872 NO_STR
4873 NEIGHBOR_STR
4874 NEIGHBOR_ADDR_STR2
4875 "Enable the Address Family for this Neighbor\n")
718e3744 4876{
d62a17ae 4877 int idx_peer = 2;
28c6e247
IR
4878 int ret;
4879 struct peer *peer;
f4b8ec07 4880
28c6e247
IR
4881 /* Lookup peer. */
4882 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4883 if (!peer)
d62a17ae 4884 return CMD_WARNING_CONFIG_FAILED;
718e3744 4885
28c6e247
IR
4886 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4887 return bgp_vty_return(vty, ret);
718e3744 4888}
6b0655a2 4889
d62a17ae 4890ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4891 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4892 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4893 "Enable the Address Family for this Neighbor\n")
596c17ba 4894
28c6e247
IR
4895DEFUN (neighbor_set_peer_group,
4896 neighbor_set_peer_group_cmd,
4897 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4898 NEIGHBOR_STR
4899 NEIGHBOR_ADDR_STR2
4900 "Member of the peer-group\n"
4901 "Peer-group name\n")
718e3744 4902{
28c6e247 4903 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4904 int idx_peer = 1;
4905 int idx_word = 3;
28c6e247
IR
4906 int ret;
4907 as_t as;
4908 union sockunion su;
4909 struct peer *peer;
4910 struct peer_group *group;
4911
4912 ret = str2sockunion(argv[idx_peer]->arg, &su);
4913 if (ret < 0) {
4914 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4915 if (!peer) {
4916 vty_out(vty, "%% Malformed address or name: %s\n",
4917 argv[idx_peer]->arg);
4918 return CMD_WARNING_CONFIG_FAILED;
4919 }
4920 } else {
4921 if (peer_address_self_check(bgp, &su)) {
4922 vty_out(vty,
4923 "%% Can not configure the local system as neighbor\n");
4924 return CMD_WARNING_CONFIG_FAILED;
4925 }
2a059a54 4926
28c6e247
IR
4927 /* Disallow for dynamic neighbor. */
4928 peer = peer_lookup(bgp, &su);
4929 if (peer && peer_dynamic_neighbor(peer)) {
4930 vty_out(vty,
4931 "%% Operation not allowed on a dynamic neighbor\n");
4932 return CMD_WARNING_CONFIG_FAILED;
4933 }
4934 }
4935
4936 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4937 if (!group) {
4938 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 4939 return CMD_WARNING_CONFIG_FAILED;
28c6e247 4940 }
d62a17ae 4941
28c6e247 4942 ret = peer_group_bind(bgp, &su, peer, group, &as);
2a059a54 4943
28c6e247
IR
4944 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4945 vty_out(vty,
4946 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4947 as);
4948 return CMD_WARNING_CONFIG_FAILED;
4949 }
4950
4951 return bgp_vty_return(vty, ret);
d62a17ae 4952}
4953
4954ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 4955 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4956 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4957 "Member of the peer-group\n"
4958 "Peer-group name\n")
596c17ba 4959
28c6e247
IR
4960DEFUN (no_neighbor_set_peer_group,
4961 no_neighbor_set_peer_group_cmd,
4962 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4963 NO_STR
4964 NEIGHBOR_STR
4965 NEIGHBOR_ADDR_STR2
4966 "Member of the peer-group\n"
4967 "Peer-group name\n")
718e3744 4968{
28c6e247 4969 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4970 int idx_peer = 2;
28c6e247
IR
4971 int idx_word = 4;
4972 int ret;
4973 struct peer *peer;
4974 struct peer_group *group;
d62a17ae 4975
28c6e247
IR
4976 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4977 if (!peer)
d62a17ae 4978 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 4979
28c6e247
IR
4980 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4981 if (!group) {
4982 vty_out(vty, "%% Configure the peer-group first\n");
4983 return CMD_WARNING_CONFIG_FAILED;
4984 }
718e3744 4985
28c6e247
IR
4986 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4987 bgp_zebra_terminate_radv(peer->bgp, peer);
4988
4989 peer_notify_unconfig(peer);
4990 ret = peer_delete(peer);
4991
4992 return bgp_vty_return(vty, ret);
718e3744 4993}
6b0655a2 4994
d62a17ae 4995ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
71cc0c88 4996 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4997 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4998 "Member of the peer-group\n"
4999 "Peer-group name\n")
596c17ba 5000
d62a17ae 5001static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 5002 uint32_t flag, int set)
718e3744 5003{
d62a17ae 5004 int ret;
5005 struct peer *peer;
718e3744 5006
d62a17ae 5007 peer = peer_and_group_lookup_vty(vty, ip_str);
5008 if (!peer)
5009 return CMD_WARNING_CONFIG_FAILED;
718e3744 5010
7ebe625c
QY
5011 /*
5012 * If 'neighbor <interface>', then this is for directly connected peers,
5013 * we should not accept disable-connected-check.
5014 */
5015 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5016 vty_out(vty,
3efd0893 5017 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
5018 ip_str);
5019 return CMD_WARNING_CONFIG_FAILED;
5020 }
5021
d62a17ae 5022 if (!set && flag == PEER_FLAG_SHUTDOWN)
5023 peer_tx_shutdown_message_unset(peer);
ae9b0e11 5024
d62a17ae 5025 if (set)
5026 ret = peer_flag_set(peer, flag);
5027 else
5028 ret = peer_flag_unset(peer, flag);
718e3744 5029
d62a17ae 5030 return bgp_vty_return(vty, ret);
718e3744 5031}
5032
47cbc09b 5033static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 5034{
d62a17ae 5035 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 5036}
5037
d62a17ae 5038static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 5039 uint32_t flag)
718e3744 5040{
d62a17ae 5041 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 5042}
5043
5044/* neighbor passive. */
28c6e247
IR
5045DEFUN (neighbor_passive,
5046 neighbor_passive_cmd,
5047 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5048 NEIGHBOR_STR
5049 NEIGHBOR_ADDR_STR2
5050 "Don't send open messages to this neighbor\n")
718e3744 5051{
d62a17ae 5052 int idx_peer = 1;
28c6e247 5053 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5054}
5055
28c6e247
IR
5056DEFUN (no_neighbor_passive,
5057 no_neighbor_passive_cmd,
5058 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5059 NO_STR
5060 NEIGHBOR_STR
5061 NEIGHBOR_ADDR_STR2
5062 "Don't send open messages to this neighbor\n")
718e3744 5063{
d62a17ae 5064 int idx_peer = 2;
28c6e247 5065 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5066}
6b0655a2 5067
718e3744 5068/* neighbor shutdown. */
28c6e247
IR
5069DEFUN (neighbor_shutdown_msg,
5070 neighbor_shutdown_msg_cmd,
5071 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5072 NEIGHBOR_STR
5073 NEIGHBOR_ADDR_STR2
5074 "Administratively shut down this neighbor\n"
5075 "Add a shutdown message (RFC 8203)\n"
5076 "Shutdown message\n")
718e3744 5077{
d62a17ae 5078 int idx_peer = 1;
73d70fa6 5079
d62a17ae 5080 if (argc >= 5) {
28c6e247
IR
5081 struct peer *peer =
5082 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
d62a17ae 5083 char *message;
73d70fa6 5084
28c6e247
IR
5085 if (!peer)
5086 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5087 message = argv_concat(argv, argc, 4);
28c6e247
IR
5088 peer_tx_shutdown_message_set(peer, message);
5089 XFREE(MTYPE_TMP, message);
d62a17ae 5090 }
73d70fa6 5091
28c6e247 5092 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 5093}
5094
1d80f243 5095ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5096 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5097 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5098 "Administratively shut down this neighbor\n")
73d70fa6 5099
28c6e247
IR
5100DEFUN (no_neighbor_shutdown_msg,
5101 no_neighbor_shutdown_msg_cmd,
5102 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5103 NO_STR
5104 NEIGHBOR_STR
5105 NEIGHBOR_ADDR_STR2
5106 "Administratively shut down this neighbor\n"
5107 "Remove a shutdown message (RFC 8203)\n"
5108 "Shutdown message\n")
718e3744 5109{
d62a17ae 5110 int idx_peer = 2;
73d70fa6 5111
28c6e247
IR
5112 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5113 PEER_FLAG_SHUTDOWN);
718e3744 5114}
6b0655a2 5115
1d80f243 5116ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5117 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5118 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5119 "Administratively shut down this neighbor\n")
73d70fa6 5120
8336c896
DA
5121DEFUN(neighbor_shutdown_rtt,
5122 neighbor_shutdown_rtt_cmd,
5123 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5124 NEIGHBOR_STR
5125 NEIGHBOR_ADDR_STR2
5126 "Administratively shut down this neighbor\n"
5127 "Shutdown if round-trip-time is higher than expected\n"
5128 "Round-trip-time in milliseconds\n"
5129 "Specify the number of keepalives before shutdown\n"
5130 "The number of keepalives with higher RTT to shutdown\n")
5131{
5132 int idx_peer = 1;
5133 int idx_rtt = 4;
5134 int idx_count = 0;
5135 struct peer *peer;
5136
5137 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5138
5139 if (!peer)
5140 return CMD_WARNING_CONFIG_FAILED;
5141
5142 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5143
5144 if (argv_find(argv, argc, "count", &idx_count))
5145 peer->rtt_keepalive_conf =
5146 strtol(argv[idx_count + 1]->arg, NULL, 10);
5147
5148 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5149 PEER_FLAG_RTT_SHUTDOWN);
5150}
5151
5152DEFUN(no_neighbor_shutdown_rtt,
5153 no_neighbor_shutdown_rtt_cmd,
5154 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5155 NO_STR
5156 NEIGHBOR_STR
5157 NEIGHBOR_ADDR_STR2
5158 "Administratively shut down this neighbor\n"
5159 "Shutdown if round-trip-time is higher than expected\n"
5160 "Round-trip-time in milliseconds\n"
5161 "Specify the number of keepalives before shutdown\n"
5162 "The number of keepalives with higher RTT to shutdown\n")
5163{
5164 int idx_peer = 2;
5165 struct peer *peer;
5166
5167 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5168
5169 if (!peer)
5170 return CMD_WARNING_CONFIG_FAILED;
5171
5172 peer->rtt_expected = 0;
5173 peer->rtt_keepalive_conf = 1;
5174
5175 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5176 PEER_FLAG_RTT_SHUTDOWN);
5177}
5178
718e3744 5179/* neighbor capability dynamic. */
28c6e247
IR
5180DEFUN (neighbor_capability_dynamic,
5181 neighbor_capability_dynamic_cmd,
5182 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5183 NEIGHBOR_STR
5184 NEIGHBOR_ADDR_STR2
5185 "Advertise capability to the peer\n"
5186 "Advertise dynamic capability to this neighbor\n")
718e3744 5187{
d62a17ae 5188 int idx_peer = 1;
28c6e247
IR
5189 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5190 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5191}
5192
28c6e247
IR
5193DEFUN (no_neighbor_capability_dynamic,
5194 no_neighbor_capability_dynamic_cmd,
5195 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5196 NO_STR
5197 NEIGHBOR_STR
5198 NEIGHBOR_ADDR_STR2
5199 "Advertise capability to the peer\n"
5200 "Advertise dynamic capability to this neighbor\n")
718e3744 5201{
d62a17ae 5202 int idx_peer = 2;
28c6e247
IR
5203 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5204 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5205}
6b0655a2 5206
718e3744 5207/* neighbor dont-capability-negotiate */
5208DEFUN (neighbor_dont_capability_negotiate,
5209 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5210 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5211 NEIGHBOR_STR
5212 NEIGHBOR_ADDR_STR2
5213 "Do not perform capability negotiation\n")
5214{
d62a17ae 5215 int idx_peer = 1;
5216 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5217 PEER_FLAG_DONT_CAPABILITY);
718e3744 5218}
5219
5220DEFUN (no_neighbor_dont_capability_negotiate,
5221 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5222 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5223 NO_STR
5224 NEIGHBOR_STR
5225 NEIGHBOR_ADDR_STR2
5226 "Do not perform capability negotiation\n")
5227{
28c6e247
IR
5228 int idx_peer = 2;
5229 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5230 PEER_FLAG_DONT_CAPABILITY);
f4b8ec07
CS
5231}
5232
28c6e247
IR
5233/* neighbor capability extended next hop encoding */
5234DEFUN (neighbor_capability_enhe,
5235 neighbor_capability_enhe_cmd,
5236 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5237 NEIGHBOR_STR
5238 NEIGHBOR_ADDR_STR2
5239 "Advertise capability to the peer\n"
5240 "Advertise extended next-hop capability to the peer\n")
f4b8ec07 5241{
28c6e247
IR
5242 int idx_peer = 1;
5243 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5244 PEER_FLAG_CAPABILITY_ENHE);
5245}
f4b8ec07 5246
28c6e247
IR
5247DEFUN (no_neighbor_capability_enhe,
5248 no_neighbor_capability_enhe_cmd,
5249 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5250 NO_STR
5251 NEIGHBOR_STR
5252 NEIGHBOR_ADDR_STR2
5253 "Advertise capability to the peer\n"
5254 "Advertise extended next-hop capability to the peer\n")
5255{
5256 int idx_peer = 2;
5257 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5258 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5259}
5260
d62a17ae 5261static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5262 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5263 int set)
718e3744 5264{
d62a17ae 5265 int ret;
5266 struct peer *peer;
718e3744 5267
d62a17ae 5268 peer = peer_and_group_lookup_vty(vty, peer_str);
5269 if (!peer)
5270 return CMD_WARNING_CONFIG_FAILED;
718e3744 5271
d62a17ae 5272 if (set)
5273 ret = peer_af_flag_set(peer, afi, safi, flag);
5274 else
5275 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5276
d62a17ae 5277 return bgp_vty_return(vty, ret);
718e3744 5278}
5279
d62a17ae 5280static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5281 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5282{
d62a17ae 5283 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5284}
5285
d62a17ae 5286static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5287 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5288{
d62a17ae 5289 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5290}
6b0655a2 5291
718e3744 5292/* neighbor capability orf prefix-list. */
5293DEFUN (neighbor_capability_orf_prefix,
5294 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5295 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5296 NEIGHBOR_STR
5297 NEIGHBOR_ADDR_STR2
5298 "Advertise capability to the peer\n"
5299 "Advertise ORF capability to the peer\n"
5300 "Advertise prefixlist ORF capability to this neighbor\n"
5301 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5302 "Capability to RECEIVE the ORF from this neighbor\n"
5303 "Capability to SEND the ORF to this neighbor\n")
5304{
d62a17ae 5305 int idx_send_recv = 5;
db45f64d
DS
5306 char *peer_str = argv[1]->arg;
5307 struct peer *peer;
5308 afi_t afi = bgp_node_afi(vty);
5309 safi_t safi = bgp_node_safi(vty);
d62a17ae 5310
db45f64d
DS
5311 peer = peer_and_group_lookup_vty(vty, peer_str);
5312 if (!peer)
d62a17ae 5313 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5314
db45f64d
DS
5315 if (strmatch(argv[idx_send_recv]->text, "send"))
5316 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5317 PEER_FLAG_ORF_PREFIX_SM);
5318
5319 if (strmatch(argv[idx_send_recv]->text, "receive"))
5320 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5321 PEER_FLAG_ORF_PREFIX_RM);
5322
5323 if (strmatch(argv[idx_send_recv]->text, "both"))
5324 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5325 PEER_FLAG_ORF_PREFIX_SM)
5326 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5327 PEER_FLAG_ORF_PREFIX_RM);
5328
5329 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5330}
5331
5332ALIAS_HIDDEN(
5333 neighbor_capability_orf_prefix,
5334 neighbor_capability_orf_prefix_hidden_cmd,
5335 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5336 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5337 "Advertise capability to the peer\n"
5338 "Advertise ORF capability to the peer\n"
5339 "Advertise prefixlist ORF capability to this neighbor\n"
5340 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5341 "Capability to RECEIVE the ORF from this neighbor\n"
5342 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5343
718e3744 5344DEFUN (no_neighbor_capability_orf_prefix,
5345 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5346 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5347 NO_STR
5348 NEIGHBOR_STR
5349 NEIGHBOR_ADDR_STR2
5350 "Advertise capability to the peer\n"
5351 "Advertise ORF capability to the peer\n"
5352 "Advertise prefixlist ORF capability to this neighbor\n"
5353 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5354 "Capability to RECEIVE the ORF from this neighbor\n"
5355 "Capability to SEND the ORF to this neighbor\n")
5356{
d62a17ae 5357 int idx_send_recv = 6;
db45f64d
DS
5358 char *peer_str = argv[2]->arg;
5359 struct peer *peer;
5360 afi_t afi = bgp_node_afi(vty);
5361 safi_t safi = bgp_node_safi(vty);
d62a17ae 5362
db45f64d
DS
5363 peer = peer_and_group_lookup_vty(vty, peer_str);
5364 if (!peer)
d62a17ae 5365 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5366
db45f64d
DS
5367 if (strmatch(argv[idx_send_recv]->text, "send"))
5368 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5369 PEER_FLAG_ORF_PREFIX_SM);
5370
5371 if (strmatch(argv[idx_send_recv]->text, "receive"))
5372 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5373 PEER_FLAG_ORF_PREFIX_RM);
5374
5375 if (strmatch(argv[idx_send_recv]->text, "both"))
5376 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5377 PEER_FLAG_ORF_PREFIX_SM)
5378 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5379 PEER_FLAG_ORF_PREFIX_RM);
5380
5381 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5382}
5383
5384ALIAS_HIDDEN(
5385 no_neighbor_capability_orf_prefix,
5386 no_neighbor_capability_orf_prefix_hidden_cmd,
5387 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5388 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5389 "Advertise capability to the peer\n"
5390 "Advertise ORF capability to the peer\n"
5391 "Advertise prefixlist ORF capability to this neighbor\n"
5392 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5393 "Capability to RECEIVE the ORF from this neighbor\n"
5394 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5395
718e3744 5396/* neighbor next-hop-self. */
28c6e247
IR
5397DEFUN (neighbor_nexthop_self,
5398 neighbor_nexthop_self_cmd,
5399 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5400 NEIGHBOR_STR
5401 NEIGHBOR_ADDR_STR2
5402 "Disable the next hop calculation for this neighbor\n")
718e3744 5403{
d62a17ae 5404 int idx_peer = 1;
28c6e247
IR
5405 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5406 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 5407}
9e7a53c1 5408
d62a17ae 5409ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5410 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5411 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5412 "Disable the next hop calculation for this neighbor\n")
596c17ba 5413
f4b8ec07 5414/* neighbor next-hop-self. */
28c6e247
IR
5415DEFUN (neighbor_nexthop_self_force,
5416 neighbor_nexthop_self_force_cmd,
5417 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5418 NEIGHBOR_STR
5419 NEIGHBOR_ADDR_STR2
5420 "Disable the next hop calculation for this neighbor\n"
5421 "Set the next hop to self for reflected routes\n")
f4b8ec07
CS
5422{
5423 int idx_peer = 1;
28c6e247
IR
5424 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5425 bgp_node_safi(vty),
5426 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 5427}
5428
d62a17ae 5429ALIAS_HIDDEN(neighbor_nexthop_self_force,
5430 neighbor_nexthop_self_force_hidden_cmd,
5431 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5432 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5433 "Disable the next hop calculation for this neighbor\n"
5434 "Set the next hop to self for reflected routes\n")
596c17ba 5435
1bc4e531
DA
5436ALIAS_HIDDEN(neighbor_nexthop_self_force,
5437 neighbor_nexthop_self_all_hidden_cmd,
5438 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5439 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5440 "Disable the next hop calculation for this neighbor\n"
5441 "Set the next hop to self for reflected routes\n")
5442
28c6e247
IR
5443DEFUN (no_neighbor_nexthop_self,
5444 no_neighbor_nexthop_self_cmd,
5445 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5446 NO_STR
5447 NEIGHBOR_STR
5448 NEIGHBOR_ADDR_STR2
5449 "Disable the next hop calculation for this neighbor\n")
718e3744 5450{
d62a17ae 5451 int idx_peer = 2;
28c6e247
IR
5452 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5453 bgp_node_afi(vty), bgp_node_safi(vty),
5454 PEER_FLAG_NEXTHOP_SELF);
718e3744 5455}
6b0655a2 5456
d62a17ae 5457ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5458 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5459 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5460 "Disable the next hop calculation for this neighbor\n")
596c17ba 5461
28c6e247
IR
5462DEFUN (no_neighbor_nexthop_self_force,
5463 no_neighbor_nexthop_self_force_cmd,
5464 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5465 NO_STR
5466 NEIGHBOR_STR
5467 NEIGHBOR_ADDR_STR2
5468 "Disable the next hop calculation for this neighbor\n"
5469 "Set the next hop to self for reflected routes\n")
88b8ed8d 5470{
d62a17ae 5471 int idx_peer = 2;
28c6e247
IR
5472 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5473 bgp_node_afi(vty), bgp_node_safi(vty),
5474 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5475}
a538debe 5476
d62a17ae 5477ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5478 no_neighbor_nexthop_self_force_hidden_cmd,
5479 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5480 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5481 "Disable the next hop calculation for this neighbor\n"
5482 "Set the next hop to self for reflected routes\n")
596c17ba 5483
1bc4e531
DA
5484ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5485 no_neighbor_nexthop_self_all_hidden_cmd,
5486 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5487 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5488 "Disable the next hop calculation for this neighbor\n"
5489 "Set the next hop to self for reflected routes\n")
5490
c7122e14 5491/* neighbor as-override */
28c6e247
IR
5492DEFUN (neighbor_as_override,
5493 neighbor_as_override_cmd,
5494 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5495 NEIGHBOR_STR
5496 NEIGHBOR_ADDR_STR2
5497 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5498{
d62a17ae 5499 int idx_peer = 1;
28c6e247
IR
5500 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5501 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5502}
5503
d62a17ae 5504ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5505 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5506 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5507 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5508
28c6e247
IR
5509DEFUN (no_neighbor_as_override,
5510 no_neighbor_as_override_cmd,
5511 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5512 NO_STR
5513 NEIGHBOR_STR
5514 NEIGHBOR_ADDR_STR2
5515 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5516{
d62a17ae 5517 int idx_peer = 2;
28c6e247
IR
5518 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5519 bgp_node_afi(vty), bgp_node_safi(vty),
5520 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5521}
5522
d62a17ae 5523ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5524 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5525 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5526 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5527
718e3744 5528/* neighbor remove-private-AS. */
28c6e247
IR
5529DEFUN (neighbor_remove_private_as,
5530 neighbor_remove_private_as_cmd,
5531 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5532 NEIGHBOR_STR
5533 NEIGHBOR_ADDR_STR2
5534 "Remove private ASNs in outbound updates\n")
718e3744 5535{
d62a17ae 5536 int idx_peer = 1;
28c6e247
IR
5537 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5538 bgp_node_safi(vty),
5539 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5540}
5541
d62a17ae 5542ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5543 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5544 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5545 "Remove private ASNs in outbound updates\n")
596c17ba 5546
28c6e247
IR
5547DEFUN (neighbor_remove_private_as_all,
5548 neighbor_remove_private_as_all_cmd,
5549 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5550 NEIGHBOR_STR
5551 NEIGHBOR_ADDR_STR2
5552 "Remove private ASNs in outbound updates\n"
5553 "Apply to all AS numbers\n")
5000f21c 5554{
d62a17ae 5555 int idx_peer = 1;
28c6e247
IR
5556 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5557 bgp_node_safi(vty),
5558 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
5559}
5560
d62a17ae 5561ALIAS_HIDDEN(neighbor_remove_private_as_all,
5562 neighbor_remove_private_as_all_hidden_cmd,
5563 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5564 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5565 "Remove private ASNs in outbound updates\n"
5566 "Apply to all AS numbers")
596c17ba 5567
28c6e247
IR
5568DEFUN (neighbor_remove_private_as_replace_as,
5569 neighbor_remove_private_as_replace_as_cmd,
5570 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5571 NEIGHBOR_STR
5572 NEIGHBOR_ADDR_STR2
5573 "Remove private ASNs in outbound updates\n"
5574 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5575{
d62a17ae 5576 int idx_peer = 1;
28c6e247
IR
5577 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5578 bgp_node_safi(vty),
5579 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
5580}
5581
d62a17ae 5582ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5583 neighbor_remove_private_as_replace_as_hidden_cmd,
5584 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5585 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5586 "Remove private ASNs in outbound updates\n"
5587 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5588
28c6e247
IR
5589DEFUN (neighbor_remove_private_as_all_replace_as,
5590 neighbor_remove_private_as_all_replace_as_cmd,
5591 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5592 NEIGHBOR_STR
5593 NEIGHBOR_ADDR_STR2
5594 "Remove private ASNs in outbound updates\n"
5595 "Apply to all AS numbers\n"
5596 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5597{
d62a17ae 5598 int idx_peer = 1;
28c6e247
IR
5599 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5600 bgp_node_safi(vty),
5601 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
5602}
5603
d62a17ae 5604ALIAS_HIDDEN(
5605 neighbor_remove_private_as_all_replace_as,
5606 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5607 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5608 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5609 "Remove private ASNs in outbound updates\n"
5610 "Apply to all AS numbers\n"
5611 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5612
28c6e247
IR
5613DEFUN (no_neighbor_remove_private_as,
5614 no_neighbor_remove_private_as_cmd,
5615 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5616 NO_STR
5617 NEIGHBOR_STR
5618 NEIGHBOR_ADDR_STR2
5619 "Remove private ASNs in outbound updates\n")
718e3744 5620{
d62a17ae 5621 int idx_peer = 2;
28c6e247
IR
5622 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5623 bgp_node_afi(vty), bgp_node_safi(vty),
5624 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5625}
6b0655a2 5626
d62a17ae 5627ALIAS_HIDDEN(no_neighbor_remove_private_as,
5628 no_neighbor_remove_private_as_hidden_cmd,
5629 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5630 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5631 "Remove private ASNs in outbound updates\n")
596c17ba 5632
28c6e247
IR
5633DEFUN (no_neighbor_remove_private_as_all,
5634 no_neighbor_remove_private_as_all_cmd,
5635 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5636 NO_STR
5637 NEIGHBOR_STR
5638 NEIGHBOR_ADDR_STR2
5639 "Remove private ASNs in outbound updates\n"
5640 "Apply to all AS numbers\n")
88b8ed8d 5641{
d62a17ae 5642 int idx_peer = 2;
28c6e247
IR
5643 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5644 bgp_node_afi(vty), bgp_node_safi(vty),
5645 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 5646}
5000f21c 5647
d62a17ae 5648ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5649 no_neighbor_remove_private_as_all_hidden_cmd,
5650 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5651 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5652 "Remove private ASNs in outbound updates\n"
5653 "Apply to all AS numbers\n")
596c17ba 5654
28c6e247
IR
5655DEFUN (no_neighbor_remove_private_as_replace_as,
5656 no_neighbor_remove_private_as_replace_as_cmd,
5657 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5658 NO_STR
5659 NEIGHBOR_STR
5660 NEIGHBOR_ADDR_STR2
5661 "Remove private ASNs in outbound updates\n"
5662 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5663{
d62a17ae 5664 int idx_peer = 2;
28c6e247
IR
5665 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5666 bgp_node_afi(vty), bgp_node_safi(vty),
5667 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 5668}
5000f21c 5669
d62a17ae 5670ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5671 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5672 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5673 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5674 "Remove private ASNs in outbound updates\n"
5675 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5676
28c6e247
IR
5677DEFUN (no_neighbor_remove_private_as_all_replace_as,
5678 no_neighbor_remove_private_as_all_replace_as_cmd,
5679 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5680 NO_STR
5681 NEIGHBOR_STR
5682 NEIGHBOR_ADDR_STR2
5683 "Remove private ASNs in outbound updates\n"
5684 "Apply to all AS numbers\n"
5685 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5686{
d62a17ae 5687 int idx_peer = 2;
28c6e247
IR
5688 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5689 bgp_node_afi(vty), bgp_node_safi(vty),
5690 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 5691}
5000f21c 5692
d62a17ae 5693ALIAS_HIDDEN(
5694 no_neighbor_remove_private_as_all_replace_as,
5695 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5696 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5697 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5698 "Remove private ASNs in outbound updates\n"
5699 "Apply to all AS numbers\n"
5700 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5701
5000f21c 5702
718e3744 5703/* neighbor send-community. */
28c6e247
IR
5704DEFUN (neighbor_send_community,
5705 neighbor_send_community_cmd,
5706 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5707 NEIGHBOR_STR
5708 NEIGHBOR_ADDR_STR2
5709 "Send Community attribute to this neighbor\n")
718e3744 5710{
d62a17ae 5711 int idx_peer = 1;
27c05d4d 5712
f63d4054
IR
5713 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5714 bgp_node_safi(vty),
5715 PEER_FLAG_SEND_COMMUNITY);
718e3744 5716}
5717
d62a17ae 5718ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5719 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5720 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5721 "Send Community attribute to this neighbor\n")
596c17ba 5722
28c6e247
IR
5723DEFUN (no_neighbor_send_community,
5724 no_neighbor_send_community_cmd,
5725 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5726 NO_STR
5727 NEIGHBOR_STR
5728 NEIGHBOR_ADDR_STR2
5729 "Send Community attribute to this neighbor\n")
718e3744 5730{
d62a17ae 5731 int idx_peer = 2;
27c05d4d 5732
f63d4054
IR
5733 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5734 bgp_node_afi(vty), bgp_node_safi(vty),
5735 PEER_FLAG_SEND_COMMUNITY);
718e3744 5736}
6b0655a2 5737
d62a17ae 5738ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5739 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5740 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5741 "Send Community attribute to this neighbor\n")
596c17ba 5742
718e3744 5743/* neighbor send-community extended. */
28c6e247
IR
5744DEFUN (neighbor_send_community_type,
5745 neighbor_send_community_type_cmd,
5746 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5747 NEIGHBOR_STR
5748 NEIGHBOR_ADDR_STR2
5749 "Send Community attribute to this neighbor\n"
5750 "Send Standard and Extended Community attributes\n"
5751 "Send Standard, Large and Extended Community attributes\n"
5752 "Send Extended Community attributes\n"
5753 "Send Standard Community attributes\n"
5754 "Send Large Community attributes\n")
718e3744 5755{
27c05d4d 5756 const char *type = argv[argc - 1]->text;
db45f64d 5757 char *peer_str = argv[1]->arg;
28c6e247 5758 struct peer *peer;
db45f64d 5759 afi_t afi = bgp_node_afi(vty);
28c6e247 5760 safi_t safi = bgp_node_safi(vty);
f4b8ec07 5761
28c6e247
IR
5762 peer = peer_and_group_lookup_vty(vty, peer_str);
5763 if (!peer)
5764 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07 5765
28c6e247
IR
5766 if (strmatch(type, "standard"))
5767 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5768 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 5769
28c6e247
IR
5770 if (strmatch(type, "extended"))
5771 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5772 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5773
28c6e247
IR
5774 if (strmatch(type, "large"))
5775 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5776 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07 5777
28c6e247
IR
5778 if (strmatch(type, "both")) {
5779 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5780 PEER_FLAG_SEND_COMMUNITY)
5781 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5782 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5783 }
28c6e247
IR
5784 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5785 PEER_FLAG_SEND_COMMUNITY)
5786 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5787 PEER_FLAG_SEND_EXT_COMMUNITY)
5788 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5789 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5790}
5791
5792ALIAS_HIDDEN(
5793 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5794 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5795 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5796 "Send Community attribute to this neighbor\n"
5797 "Send Standard and Extended Community attributes\n"
5798 "Send Standard, Large and Extended Community attributes\n"
5799 "Send Extended Community attributes\n"
5800 "Send Standard Community attributes\n"
5801 "Send Large Community attributes\n")
596c17ba 5802
28c6e247
IR
5803DEFUN (no_neighbor_send_community_type,
5804 no_neighbor_send_community_type_cmd,
5805 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5806 NO_STR
5807 NEIGHBOR_STR
5808 NEIGHBOR_ADDR_STR2
5809 "Send Community attribute to this neighbor\n"
5810 "Send Standard and Extended Community attributes\n"
5811 "Send Standard, Large and Extended Community attributes\n"
5812 "Send Extended Community attributes\n"
5813 "Send Standard Community attributes\n"
5814 "Send Large Community attributes\n")
718e3744 5815{
d62a17ae 5816 const char *type = argv[argc - 1]->text;
db45f64d 5817 char *peer_str = argv[2]->arg;
28c6e247 5818 struct peer *peer;
db45f64d
DS
5819 afi_t afi = bgp_node_afi(vty);
5820 safi_t safi = bgp_node_safi(vty);
5821
28c6e247
IR
5822 peer = peer_and_group_lookup_vty(vty, peer_str);
5823 if (!peer)
f4b8ec07
CS
5824 return CMD_WARNING_CONFIG_FAILED;
5825
28c6e247
IR
5826 if (strmatch(type, "standard"))
5827 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5828 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 5829
28c6e247
IR
5830 if (strmatch(type, "extended"))
5831 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5832 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5833
28c6e247
IR
5834 if (strmatch(type, "large"))
5835 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5836 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07
CS
5837
5838 if (strmatch(type, "both")) {
db45f64d 5839
28c6e247
IR
5840 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5841 PEER_FLAG_SEND_COMMUNITY)
5842 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5843 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
5844 }
5845
28c6e247
IR
5846 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5847 PEER_FLAG_SEND_COMMUNITY)
5848 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5849 PEER_FLAG_SEND_EXT_COMMUNITY)
5850 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5851 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5852}
5853
5854ALIAS_HIDDEN(
5855 no_neighbor_send_community_type,
5856 no_neighbor_send_community_type_hidden_cmd,
5857 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5858 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5859 "Send Community attribute to this neighbor\n"
5860 "Send Standard and Extended Community attributes\n"
5861 "Send Standard, Large and Extended Community attributes\n"
5862 "Send Extended Community attributes\n"
5863 "Send Standard Community attributes\n"
5864 "Send Large Community attributes\n")
596c17ba 5865
718e3744 5866/* neighbor soft-reconfig. */
28c6e247
IR
5867DEFUN (neighbor_soft_reconfiguration,
5868 neighbor_soft_reconfiguration_cmd,
5869 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5870 NEIGHBOR_STR
5871 NEIGHBOR_ADDR_STR2
5872 "Per neighbor soft reconfiguration\n"
5873 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 5874{
d62a17ae 5875 int idx_peer = 1;
28c6e247
IR
5876 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5877 bgp_node_safi(vty),
5878 PEER_FLAG_SOFT_RECONFIG);
718e3744 5879}
5880
d62a17ae 5881ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5882 neighbor_soft_reconfiguration_hidden_cmd,
5883 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5884 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5885 "Per neighbor soft reconfiguration\n"
5886 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5887
28c6e247
IR
5888DEFUN (no_neighbor_soft_reconfiguration,
5889 no_neighbor_soft_reconfiguration_cmd,
5890 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5891 NO_STR
5892 NEIGHBOR_STR
5893 NEIGHBOR_ADDR_STR2
5894 "Per neighbor soft reconfiguration\n"
5895 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 5896{
d62a17ae 5897 int idx_peer = 2;
28c6e247
IR
5898 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5899 bgp_node_afi(vty), bgp_node_safi(vty),
5900 PEER_FLAG_SOFT_RECONFIG);
718e3744 5901}
6b0655a2 5902
d62a17ae 5903ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5904 no_neighbor_soft_reconfiguration_hidden_cmd,
5905 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5906 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5907 "Per neighbor soft reconfiguration\n"
5908 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5909
28c6e247
IR
5910DEFUN (neighbor_route_reflector_client,
5911 neighbor_route_reflector_client_cmd,
5912 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5913 NEIGHBOR_STR
5914 NEIGHBOR_ADDR_STR2
5915 "Configure a neighbor as Route Reflector client\n")
718e3744 5916{
d62a17ae 5917 int idx_peer = 1;
28c6e247 5918 struct peer *peer;
718e3744 5919
5920
28c6e247
IR
5921 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5922 if (!peer)
d62a17ae 5923 return CMD_WARNING_CONFIG_FAILED;
718e3744 5924
28c6e247
IR
5925 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5926 bgp_node_safi(vty),
5927 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5928}
5929
d62a17ae 5930ALIAS_HIDDEN(neighbor_route_reflector_client,
5931 neighbor_route_reflector_client_hidden_cmd,
5932 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5933 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5934 "Configure a neighbor as Route Reflector client\n")
596c17ba 5935
28c6e247
IR
5936DEFUN (no_neighbor_route_reflector_client,
5937 no_neighbor_route_reflector_client_cmd,
5938 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5939 NO_STR
5940 NEIGHBOR_STR
5941 NEIGHBOR_ADDR_STR2
5942 "Configure a neighbor as Route Reflector client\n")
718e3744 5943{
d62a17ae 5944 int idx_peer = 2;
28c6e247
IR
5945 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5946 bgp_node_afi(vty), bgp_node_safi(vty),
5947 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5948}
6b0655a2 5949
d62a17ae 5950ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5951 no_neighbor_route_reflector_client_hidden_cmd,
5952 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5953 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5954 "Configure a neighbor as Route Reflector client\n")
596c17ba 5955
718e3744 5956/* neighbor route-server-client. */
28c6e247
IR
5957DEFUN (neighbor_route_server_client,
5958 neighbor_route_server_client_cmd,
5959 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5960 NEIGHBOR_STR
5961 NEIGHBOR_ADDR_STR2
5962 "Configure a neighbor as Route Server client\n")
718e3744 5963{
d62a17ae 5964 int idx_peer = 1;
28c6e247 5965 struct peer *peer;
f4b8ec07 5966
28c6e247
IR
5967 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5968 if (!peer)
d62a17ae 5969 return CMD_WARNING_CONFIG_FAILED;
28c6e247
IR
5970 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5971 bgp_node_safi(vty),
5972 PEER_FLAG_RSERVER_CLIENT);
718e3744 5973}
5974
d62a17ae 5975ALIAS_HIDDEN(neighbor_route_server_client,
5976 neighbor_route_server_client_hidden_cmd,
5977 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5978 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5979 "Configure a neighbor as Route Server client\n")
596c17ba 5980
28c6e247
IR
5981DEFUN (no_neighbor_route_server_client,
5982 no_neighbor_route_server_client_cmd,
5983 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5984 NO_STR
5985 NEIGHBOR_STR
5986 NEIGHBOR_ADDR_STR2
5987 "Configure a neighbor as Route Server client\n")
fee0f4c6 5988{
d62a17ae 5989 int idx_peer = 2;
28c6e247
IR
5990 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5991 bgp_node_afi(vty), bgp_node_safi(vty),
5992 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 5993}
6b0655a2 5994
d62a17ae 5995ALIAS_HIDDEN(no_neighbor_route_server_client,
5996 no_neighbor_route_server_client_hidden_cmd,
5997 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5998 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5999 "Configure a neighbor as Route Server client\n")
596c17ba 6000
fee0f4c6 6001DEFUN (neighbor_nexthop_local_unchanged,
6002 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6003 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6004 NEIGHBOR_STR
6005 NEIGHBOR_ADDR_STR2
6006 "Configure treatment of outgoing link-local nexthop attribute\n"
6007 "Leave link-local nexthop unchanged for this peer\n")
6008{
d62a17ae 6009 int idx_peer = 1;
6010 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6011 bgp_node_safi(vty),
6012 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6013}
6b0655a2 6014
fee0f4c6 6015DEFUN (no_neighbor_nexthop_local_unchanged,
6016 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6017 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6018 NO_STR
6019 NEIGHBOR_STR
6020 NEIGHBOR_ADDR_STR2
6021 "Configure treatment of outgoing link-local-nexthop attribute\n"
6022 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6023{
d62a17ae 6024 int idx_peer = 2;
6025 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6026 bgp_node_afi(vty), bgp_node_safi(vty),
6027 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6028}
6b0655a2 6029
28c6e247
IR
6030DEFUN (neighbor_attr_unchanged,
6031 neighbor_attr_unchanged_cmd,
6032 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6033 NEIGHBOR_STR
6034 NEIGHBOR_ADDR_STR2
6035 "BGP attribute is propagated unchanged to this neighbor\n"
6036 "As-path attribute\n"
6037 "Nexthop attribute\n"
6038 "Med attribute\n")
718e3744 6039{
d62a17ae 6040 int idx = 0;
8eeb0335 6041 char *peer_str = argv[1]->arg;
28c6e247 6042 struct peer *peer;
db45f64d
DS
6043 bool aspath = false;
6044 bool nexthop = false;
6045 bool med = false;
8eeb0335
DW
6046 afi_t afi = bgp_node_afi(vty);
6047 safi_t safi = bgp_node_safi(vty);
28c6e247 6048 int ret = 0;
f4b8ec07 6049
28c6e247
IR
6050 peer = peer_and_group_lookup_vty(vty, peer_str);
6051 if (!peer)
8eeb0335 6052 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6053
6054 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6055 aspath = true;
6056
d62a17ae 6057 idx = 0;
6058 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6059 nexthop = true;
6060
d62a17ae 6061 idx = 0;
6062 if (argv_find(argv, argc, "med", &idx))
db45f64d 6063 med = true;
d62a17ae 6064
8eeb0335 6065 /* no flags means all of them! */
db45f64d 6066 if (!aspath && !nexthop && !med) {
28c6e247
IR
6067 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6068 PEER_FLAG_AS_PATH_UNCHANGED);
6069 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6070 PEER_FLAG_NEXTHOP_UNCHANGED);
6071 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6072 PEER_FLAG_MED_UNCHANGED);
8eeb0335 6073 } else {
28c6e247
IR
6074 if (!aspath) {
6075 if (peer_af_flag_check(peer, afi, safi,
6076 PEER_FLAG_AS_PATH_UNCHANGED)) {
6077 ret |= peer_af_flag_unset_vty(
6078 vty, peer_str, afi, safi,
6079 PEER_FLAG_AS_PATH_UNCHANGED);
6080 }
6081 } else
6082 ret |= peer_af_flag_set_vty(
6083 vty, peer_str, afi, safi,
6084 PEER_FLAG_AS_PATH_UNCHANGED);
6085
6086 if (!nexthop) {
6087 if (peer_af_flag_check(peer, afi, safi,
6088 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6089 ret |= peer_af_flag_unset_vty(
6090 vty, peer_str, afi, safi,
6091 PEER_FLAG_NEXTHOP_UNCHANGED);
6092 }
6093 } else
6094 ret |= peer_af_flag_set_vty(
6095 vty, peer_str, afi, safi,
6096 PEER_FLAG_NEXTHOP_UNCHANGED);
6097
6098 if (!med) {
6099 if (peer_af_flag_check(peer, afi, safi,
6100 PEER_FLAG_MED_UNCHANGED)) {
6101 ret |= peer_af_flag_unset_vty(
6102 vty, peer_str, afi, safi,
6103 PEER_FLAG_MED_UNCHANGED);
6104 }
6105 } else
6106 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6107 PEER_FLAG_MED_UNCHANGED);
d62a17ae 6108 }
6109
28c6e247 6110 return ret;
d62a17ae 6111}
6112
6113ALIAS_HIDDEN(
6114 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6115 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6116 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6117 "BGP attribute is propagated unchanged to this neighbor\n"
6118 "As-path attribute\n"
6119 "Nexthop attribute\n"
6120 "Med attribute\n")
596c17ba 6121
28c6e247
IR
6122DEFUN (no_neighbor_attr_unchanged,
6123 no_neighbor_attr_unchanged_cmd,
6124 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6125 NO_STR
6126 NEIGHBOR_STR
6127 NEIGHBOR_ADDR_STR2
6128 "BGP attribute is propagated unchanged to this neighbor\n"
6129 "As-path attribute\n"
6130 "Nexthop attribute\n"
6131 "Med attribute\n")
718e3744 6132{
d62a17ae 6133 int idx = 0;
db45f64d 6134 char *peer_str = argv[2]->arg;
28c6e247 6135 struct peer *peer;
db45f64d
DS
6136 bool aspath = false;
6137 bool nexthop = false;
6138 bool med = false;
6139 afi_t afi = bgp_node_afi(vty);
6140 safi_t safi = bgp_node_safi(vty);
28c6e247 6141 int ret = 0;
f4b8ec07 6142
28c6e247
IR
6143 peer = peer_and_group_lookup_vty(vty, peer_str);
6144 if (!peer)
db45f64d 6145 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6146
6147 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6148 aspath = true;
6149
d62a17ae 6150 idx = 0;
6151 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6152 nexthop = true;
6153
d62a17ae 6154 idx = 0;
6155 if (argv_find(argv, argc, "med", &idx))
db45f64d 6156 med = true;
d62a17ae 6157
28c6e247
IR
6158 if (!aspath && !nexthop && !med) // no flags means all of them!
6159 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6160 PEER_FLAG_AS_PATH_UNCHANGED)
6161 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6162 PEER_FLAG_NEXTHOP_UNCHANGED)
6163 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6164 PEER_FLAG_MED_UNCHANGED);
db45f64d
DS
6165
6166 if (aspath)
28c6e247
IR
6167 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6168 PEER_FLAG_AS_PATH_UNCHANGED);
db45f64d
DS
6169
6170 if (nexthop)
28c6e247
IR
6171 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6172 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 6173
db45f64d 6174 if (med)
28c6e247
IR
6175 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6176 PEER_FLAG_MED_UNCHANGED);
db45f64d 6177
28c6e247 6178 return ret;
d62a17ae 6179}
6180
6181ALIAS_HIDDEN(
6182 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6183 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6184 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6185 "BGP attribute is propagated unchanged to this neighbor\n"
6186 "As-path attribute\n"
6187 "Nexthop attribute\n"
6188 "Med attribute\n")
718e3744 6189
28c6e247
IR
6190/* EBGP multihop configuration. */
6191static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6192 const char *ttl_str)
718e3744 6193{
28c6e247
IR
6194 struct peer *peer;
6195 unsigned int ttl;
718e3744 6196
28c6e247
IR
6197 peer = peer_and_group_lookup_vty(vty, ip_str);
6198 if (!peer)
d62a17ae 6199 return CMD_WARNING_CONFIG_FAILED;
718e3744 6200
28c6e247
IR
6201 if (peer->conf_if)
6202 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6203
6204 if (!ttl_str)
6205 ttl = MAXTTL;
6206 else
6207 ttl = strtoul(ttl_str, NULL, 10);
718e3744 6208
28c6e247 6209 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 6210}
6211
28c6e247 6212static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6213{
28c6e247 6214 struct peer *peer;
718e3744 6215
28c6e247
IR
6216 peer = peer_and_group_lookup_vty(vty, ip_str);
6217 if (!peer)
d62a17ae 6218 return CMD_WARNING_CONFIG_FAILED;
718e3744 6219
28c6e247 6220 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 6221}
6222
28c6e247
IR
6223/* neighbor ebgp-multihop. */
6224DEFUN (neighbor_ebgp_multihop,
6225 neighbor_ebgp_multihop_cmd,
6226 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6227 NEIGHBOR_STR
6228 NEIGHBOR_ADDR_STR2
6229 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6230{
28c6e247
IR
6231 int idx_peer = 1;
6232 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6233}
f4b8ec07 6234
28c6e247
IR
6235DEFUN (neighbor_ebgp_multihop_ttl,
6236 neighbor_ebgp_multihop_ttl_cmd,
6237 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6238 NEIGHBOR_STR
6239 NEIGHBOR_ADDR_STR2
6240 "Allow EBGP neighbors not on directly connected networks\n"
6241 "maximum hop count\n")
6242{
6243 int idx_peer = 1;
6244 int idx_number = 3;
6245 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6246 argv[idx_number]->arg);
6247}
f4b8ec07 6248
28c6e247
IR
6249DEFUN (no_neighbor_ebgp_multihop,
6250 no_neighbor_ebgp_multihop_cmd,
6251 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6252 NO_STR
6253 NEIGHBOR_STR
6254 NEIGHBOR_ADDR_STR2
6255 "Allow EBGP neighbors not on directly connected networks\n"
6256 "maximum hop count\n")
6257{
6258 int idx_peer = 2;
6259 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6260}
6261
6b0655a2 6262
6ffd2079 6263/* disable-connected-check */
28c6e247
IR
6264DEFUN (neighbor_disable_connected_check,
6265 neighbor_disable_connected_check_cmd,
6266 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6267 NEIGHBOR_STR
6268 NEIGHBOR_ADDR_STR2
6269 "one-hop away EBGP peer using loopback address\n"
6270 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6271{
d62a17ae 6272 int idx_peer = 1;
28c6e247
IR
6273 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6274 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6275}
6276
28c6e247
IR
6277DEFUN (no_neighbor_disable_connected_check,
6278 no_neighbor_disable_connected_check_cmd,
6279 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6280 NO_STR
6281 NEIGHBOR_STR
6282 NEIGHBOR_ADDR_STR2
6283 "one-hop away EBGP peer using loopback address\n"
6284 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6285{
d62a17ae 6286 int idx_peer = 2;
28c6e247
IR
6287 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6288 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6289}
6290
7ab294ea
DA
6291/* disable-link-bw-encoding-ieee */
6292DEFUN(neighbor_disable_link_bw_encoding_ieee,
6293 neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6294 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6295 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6296 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6297{
6298 int idx_peer = 1;
6299
6300 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6301 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6302}
6303
7ab294ea
DA
6304DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6305 no_neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6306 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6307 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6308 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6309{
6310 int idx_peer = 2;
6311
6312 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6313 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6314}
6315
d08c0c80
DA
6316/* extended-optional-parameters */
6317DEFUN(neighbor_extended_optional_parameters,
6318 neighbor_extended_optional_parameters_cmd,
6319 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6320 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6321 "Force the extended optional parameters format for OPEN messages\n")
6322{
6323 int idx_peer = 1;
6324
6325 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6326 PEER_FLAG_EXTENDED_OPT_PARAMS);
6327}
6328
6329DEFUN(no_neighbor_extended_optional_parameters,
6330 no_neighbor_extended_optional_parameters_cmd,
6331 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6332 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6333 "Force the extended optional parameters format for OPEN messages\n")
6334{
6335 int idx_peer = 2;
6336
6337 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6338 PEER_FLAG_EXTENDED_OPT_PARAMS);
6339}
47cbc09b
PM
6340
6341/* enforce-first-as */
28c6e247
IR
6342DEFUN (neighbor_enforce_first_as,
6343 neighbor_enforce_first_as_cmd,
6344 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6345 NEIGHBOR_STR
6346 NEIGHBOR_ADDR_STR2
6347 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6348{
6349 int idx_peer = 1;
f4b8ec07 6350
28c6e247
IR
6351 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6352 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6353}
6354
28c6e247
IR
6355DEFUN (no_neighbor_enforce_first_as,
6356 no_neighbor_enforce_first_as_cmd,
6357 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6358 NO_STR
6359 NEIGHBOR_STR
6360 NEIGHBOR_ADDR_STR2
6361 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6362{
6363 int idx_peer = 2;
f4b8ec07 6364
28c6e247
IR
6365 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6366 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6367}
6368
6369
28c6e247
IR
6370DEFUN (neighbor_description,
6371 neighbor_description_cmd,
6372 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6373 NEIGHBOR_STR
6374 NEIGHBOR_ADDR_STR2
6375 "Neighbor specific description\n"
6376 "Up to 80 characters describing this neighbor\n")
718e3744 6377{
d62a17ae 6378 int idx_peer = 1;
6379 int idx_line = 3;
28c6e247 6380 struct peer *peer;
d62a17ae 6381 char *str;
718e3744 6382
28c6e247
IR
6383 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6384 if (!peer)
d62a17ae 6385 return CMD_WARNING_CONFIG_FAILED;
718e3744 6386
d62a17ae 6387 str = argv_concat(argv, argc, idx_line);
718e3744 6388
28c6e247 6389 peer_description_set(peer, str);
718e3744 6390
d62a17ae 6391 XFREE(MTYPE_TMP, str);
718e3744 6392
28c6e247 6393 return CMD_SUCCESS;
718e3744 6394}
6395
28c6e247
IR
6396DEFUN (no_neighbor_description,
6397 no_neighbor_description_cmd,
6398 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6399 NO_STR
6400 NEIGHBOR_STR
6401 NEIGHBOR_ADDR_STR2
6402 "Neighbor specific description\n")
718e3744 6403{
d62a17ae 6404 int idx_peer = 2;
28c6e247 6405 struct peer *peer;
f4b8ec07 6406
28c6e247
IR
6407 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6408 if (!peer)
d62a17ae 6409 return CMD_WARNING_CONFIG_FAILED;
718e3744 6410
28c6e247 6411 peer_description_unset(peer);
718e3744 6412
28c6e247 6413 return CMD_SUCCESS;
718e3744 6414}
6415
1d80f243 6416ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
6417 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6418 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6419 "Neighbor specific description\n"
6420 "Up to 80 characters describing this neighbor\n")
6b0655a2 6421
28c6e247
IR
6422/* Neighbor update-source. */
6423static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6424 const char *source_str)
6425{
6426 struct peer *peer;
6427 struct prefix p;
6428 union sockunion su;
6429
6430 peer = peer_and_group_lookup_vty(vty, peer_str);
6431 if (!peer)
6432 return CMD_WARNING_CONFIG_FAILED;
6433
6434 if (peer->conf_if)
6435 return CMD_WARNING;
6436
6437 if (source_str) {
6438 if (str2sockunion(source_str, &su) == 0)
6439 peer_update_source_addr_set(peer, &su);
6440 else {
6441 if (str2prefix(source_str, &p)) {
6442 vty_out(vty,
6443 "%% Invalid update-source, remove prefix length \n");
6444 return CMD_WARNING_CONFIG_FAILED;
6445 } else
6446 peer_update_source_if_set(peer, source_str);
6447 }
6448 } else
6449 peer_update_source_unset(peer);
6450
6451 return CMD_SUCCESS;
6452}
6453
d62a17ae 6454#define BGP_UPDATE_SOURCE_HELP_STR \
6455 "IPv4 address\n" \
6456 "IPv6 address\n" \
6457 "Interface name (requires zebra to be running)\n"
369688c0 6458
28c6e247
IR
6459DEFUN (neighbor_update_source,
6460 neighbor_update_source_cmd,
6461 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6462 NEIGHBOR_STR
6463 NEIGHBOR_ADDR_STR2
6464 "Source of routing updates\n"
6465 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6466{
d62a17ae 6467 int idx_peer = 1;
6468 int idx_peer_2 = 3;
28c6e247 6469 return peer_update_source_vty(vty, argv[idx_peer]->arg,
d62a17ae 6470 argv[idx_peer_2]->arg);
718e3744 6471}
6472
28c6e247
IR
6473DEFUN (no_neighbor_update_source,
6474 no_neighbor_update_source_cmd,
6475 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6476 NO_STR
6477 NEIGHBOR_STR
6478 NEIGHBOR_ADDR_STR2
6479 "Source of routing updates\n"
6480 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6481{
d62a17ae 6482 int idx_peer = 2;
28c6e247 6483 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6484}
6b0655a2 6485
d62a17ae 6486static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6487 afi_t afi, safi_t safi,
6488 const char *rmap, int set)
718e3744 6489{
d62a17ae 6490 int ret;
6491 struct peer *peer;
80912664 6492 struct route_map *route_map = NULL;
718e3744 6493
d62a17ae 6494 peer = peer_and_group_lookup_vty(vty, peer_str);
6495 if (!peer)
6496 return CMD_WARNING_CONFIG_FAILED;
718e3744 6497
1de27621 6498 if (set) {
80912664
DS
6499 if (rmap)
6500 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
6501 ret = peer_default_originate_set(peer, afi, safi,
6502 rmap, route_map);
6503 } else
d62a17ae 6504 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 6505
d62a17ae 6506 return bgp_vty_return(vty, ret);
718e3744 6507}
6508
6509/* neighbor default-originate. */
6510DEFUN (neighbor_default_originate,
6511 neighbor_default_originate_cmd,
9ccf14f7 6512 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 6513 NEIGHBOR_STR
6514 NEIGHBOR_ADDR_STR2
6515 "Originate default route to this neighbor\n")
6516{
d62a17ae 6517 int idx_peer = 1;
6518 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6519 bgp_node_afi(vty),
6520 bgp_node_safi(vty), NULL, 1);
718e3744 6521}
6522
d62a17ae 6523ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6524 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6525 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6526 "Originate default route to this neighbor\n")
596c17ba 6527
718e3744 6528DEFUN (neighbor_default_originate_rmap,
6529 neighbor_default_originate_rmap_cmd,
9ccf14f7 6530 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 6531 NEIGHBOR_STR
6532 NEIGHBOR_ADDR_STR2
6533 "Originate default route to this neighbor\n"
6534 "Route-map to specify criteria to originate default\n"
6535 "route-map name\n")
6536{
d62a17ae 6537 int idx_peer = 1;
6538 int idx_word = 4;
6539 return peer_default_originate_set_vty(
6540 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6541 argv[idx_word]->arg, 1);
718e3744 6542}
6543
d62a17ae 6544ALIAS_HIDDEN(
6545 neighbor_default_originate_rmap,
6546 neighbor_default_originate_rmap_hidden_cmd,
6547 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6548 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6549 "Originate default route to this neighbor\n"
6550 "Route-map to specify criteria to originate default\n"
6551 "route-map name\n")
596c17ba 6552
718e3744 6553DEFUN (no_neighbor_default_originate,
6554 no_neighbor_default_originate_cmd,
a636c635 6555 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 6556 NO_STR
6557 NEIGHBOR_STR
6558 NEIGHBOR_ADDR_STR2
a636c635
DW
6559 "Originate default route to this neighbor\n"
6560 "Route-map to specify criteria to originate default\n"
6561 "route-map name\n")
718e3744 6562{
d62a17ae 6563 int idx_peer = 2;
6564 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6565 bgp_node_afi(vty),
6566 bgp_node_safi(vty), NULL, 0);
718e3744 6567}
6568
d62a17ae 6569ALIAS_HIDDEN(
6570 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6571 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6572 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6573 "Originate default route to this neighbor\n"
6574 "Route-map to specify criteria to originate default\n"
6575 "route-map name\n")
596c17ba 6576
6b0655a2 6577
28c6e247
IR
6578/* Set neighbor's BGP port. */
6579static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6580 const char *port_str)
718e3744 6581{
28c6e247
IR
6582 struct peer *peer;
6583 uint16_t port;
6584 struct servent *sp;
6585
6586 peer = peer_lookup_vty(vty, ip_str);
6587 if (!peer)
6588 return CMD_WARNING_CONFIG_FAILED;
6589
6590 if (!port_str) {
6591 sp = getservbyname("bgp", "tcp");
6592 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6593 } else {
6594 port = strtoul(port_str, NULL, 10);
6595 }
718e3744 6596
28c6e247 6597 peer_port_set(peer, port);
718e3744 6598
28c6e247
IR
6599 return CMD_SUCCESS;
6600}
f4b8ec07 6601
28c6e247
IR
6602/* Set specified peer's BGP port. */
6603DEFUN (neighbor_port,
6604 neighbor_port_cmd,
6605 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
6606 NEIGHBOR_STR
6607 NEIGHBOR_ADDR_STR
6608 "Neighbor's BGP port\n"
6609 "TCP port number\n")
6610{
6611 int idx_ip = 1;
6612 int idx_number = 3;
6613 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6614 argv[idx_number]->arg);
f4b8ec07 6615}
6b0655a2 6616
28c6e247
IR
6617DEFUN (no_neighbor_port,
6618 no_neighbor_port_cmd,
6619 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
6620 NO_STR
6621 NEIGHBOR_STR
6622 NEIGHBOR_ADDR_STR
6623 "Neighbor's BGP port\n"
6624 "TCP port number\n")
718e3744 6625{
f4b8ec07 6626 int idx_ip = 2;
28c6e247
IR
6627 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6628}
6629
6630
6631/* neighbor weight. */
6632static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6633 safi_t safi, const char *weight_str)
6634{
6635 int ret;
6636 struct peer *peer;
6637 unsigned long weight;
718e3744 6638
28c6e247
IR
6639 peer = peer_and_group_lookup_vty(vty, ip_str);
6640 if (!peer)
6641 return CMD_WARNING_CONFIG_FAILED;
718e3744 6642
28c6e247 6643 weight = strtoul(weight_str, NULL, 10);
718e3744 6644
28c6e247
IR
6645 ret = peer_weight_set(peer, afi, safi, weight);
6646 return bgp_vty_return(vty, ret);
718e3744 6647}
6648
28c6e247
IR
6649static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6650 safi_t safi)
718e3744 6651{
28c6e247
IR
6652 int ret;
6653 struct peer *peer;
f4b8ec07 6654
28c6e247
IR
6655 peer = peer_and_group_lookup_vty(vty, ip_str);
6656 if (!peer)
d62a17ae 6657 return CMD_WARNING_CONFIG_FAILED;
718e3744 6658
28c6e247
IR
6659 ret = peer_weight_unset(peer, afi, safi);
6660 return bgp_vty_return(vty, ret);
6661}
f4b8ec07 6662
28c6e247
IR
6663DEFUN (neighbor_weight,
6664 neighbor_weight_cmd,
6665 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6666 NEIGHBOR_STR
6667 NEIGHBOR_ADDR_STR2
6668 "Set default weight for routes from this neighbor\n"
6669 "default weight\n")
6670{
6671 int idx_peer = 1;
6672 int idx_number = 3;
6673 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6674 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 6675}
6676
d62a17ae 6677ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6678 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6679 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6680 "Set default weight for routes from this neighbor\n"
6681 "default weight\n")
596c17ba 6682
28c6e247
IR
6683DEFUN (no_neighbor_weight,
6684 no_neighbor_weight_cmd,
6685 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6686 NO_STR
6687 NEIGHBOR_STR
6688 NEIGHBOR_ADDR_STR2
6689 "Set default weight for routes from this neighbor\n"
6690 "default weight\n")
718e3744 6691{
d62a17ae 6692 int idx_peer = 2;
28c6e247
IR
6693 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6694 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 6695}
6696
d62a17ae 6697ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6698 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6699 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6700 "Set default weight for routes from this neighbor\n"
6701 "default weight\n")
596c17ba 6702
6b0655a2 6703
718e3744 6704/* Override capability negotiation. */
c36bc05f
IR
6705DEFUN (neighbor_override_capability,
6706 neighbor_override_capability_cmd,
6707 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6708 NEIGHBOR_STR
6709 NEIGHBOR_ADDR_STR2
6710 "Override capability negotiation result\n")
718e3744 6711{
d62a17ae 6712 int idx_peer = 1;
c36bc05f
IR
6713 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6714 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6715}
6716
c36bc05f
IR
6717DEFUN (no_neighbor_override_capability,
6718 no_neighbor_override_capability_cmd,
6719 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6720 NO_STR
6721 NEIGHBOR_STR
6722 NEIGHBOR_ADDR_STR2
6723 "Override capability negotiation result\n")
718e3744 6724{
d62a17ae 6725 int idx_peer = 2;
c36bc05f
IR
6726 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6727 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6728}
6b0655a2 6729
c36bc05f
IR
6730DEFUN (neighbor_strict_capability,
6731 neighbor_strict_capability_cmd,
6732 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6733 NEIGHBOR_STR
6734 NEIGHBOR_ADDR_STR2
6735 "Strict capability negotiation match\n")
718e3744 6736{
9fb964de
PM
6737 int idx_peer = 1;
6738
c36bc05f
IR
6739 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6740 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6741}
6742
c36bc05f
IR
6743DEFUN (no_neighbor_strict_capability,
6744 no_neighbor_strict_capability_cmd,
6745 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6746 NO_STR
6747 NEIGHBOR_STR
6748 NEIGHBOR_ADDR_STR2
6749 "Strict capability negotiation match\n")
718e3744 6750{
9fb964de 6751 int idx_peer = 2;
8611c7f3 6752
c36bc05f
IR
6753 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6754 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6755}
6b0655a2 6756
28c6e247
IR
6757static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6758 const char *keep_str, const char *hold_str)
718e3744 6759{
28c6e247
IR
6760 int ret;
6761 struct peer *peer;
6762 uint32_t keepalive;
6763 uint32_t holdtime;
718e3744 6764
28c6e247
IR
6765 peer = peer_and_group_lookup_vty(vty, ip_str);
6766 if (!peer)
d62a17ae 6767 return CMD_WARNING_CONFIG_FAILED;
718e3744 6768
28c6e247
IR
6769 keepalive = strtoul(keep_str, NULL, 10);
6770 holdtime = strtoul(hold_str, NULL, 10);
718e3744 6771
28c6e247 6772 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 6773
28c6e247 6774 return bgp_vty_return(vty, ret);
718e3744 6775}
6b0655a2 6776
28c6e247 6777static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6778{
28c6e247
IR
6779 int ret;
6780 struct peer *peer;
718e3744 6781
28c6e247
IR
6782 peer = peer_and_group_lookup_vty(vty, ip_str);
6783 if (!peer)
d62a17ae 6784 return CMD_WARNING_CONFIG_FAILED;
718e3744 6785
28c6e247 6786 ret = peer_timers_unset(peer);
718e3744 6787
28c6e247 6788 return bgp_vty_return(vty, ret);
718e3744 6789}
6b0655a2 6790
28c6e247
IR
6791DEFUN (neighbor_timers,
6792 neighbor_timers_cmd,
6793 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
6794 NEIGHBOR_STR
6795 NEIGHBOR_ADDR_STR2
6796 "BGP per neighbor timers\n"
6797 "Keepalive interval\n"
6798 "Holdtime\n")
718e3744 6799{
f4b8ec07 6800 int idx_peer = 1;
28c6e247
IR
6801 int idx_number = 3;
6802 int idx_number_2 = 4;
6803 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6804 argv[idx_number]->arg,
6805 argv[idx_number_2]->arg);
6806}
6807
6808DEFUN (no_neighbor_timers,
6809 no_neighbor_timers_cmd,
6810 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
6811 NO_STR
6812 NEIGHBOR_STR
6813 NEIGHBOR_ADDR_STR2
6814 "BGP per neighbor timers\n"
6815 "Keepalive interval\n"
6816 "Holdtime\n")
6817{
6818 int idx_peer = 2;
6819 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
6820}
6821
6822
6823static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6824 const char *time_str)
6825{
6826 int ret;
6827 struct peer *peer;
6828 uint32_t connect;
718e3744 6829
28c6e247
IR
6830 peer = peer_and_group_lookup_vty(vty, ip_str);
6831 if (!peer)
d62a17ae 6832 return CMD_WARNING_CONFIG_FAILED;
718e3744 6833
28c6e247
IR
6834 connect = strtoul(time_str, NULL, 10);
6835
6836 ret = peer_timers_connect_set(peer, connect);
718e3744 6837
28c6e247 6838 return bgp_vty_return(vty, ret);
718e3744 6839}
6840
28c6e247 6841static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6842{
28c6e247
IR
6843 int ret;
6844 struct peer *peer;
718e3744 6845
28c6e247
IR
6846 peer = peer_and_group_lookup_vty(vty, ip_str);
6847 if (!peer)
d62a17ae 6848 return CMD_WARNING_CONFIG_FAILED;
718e3744 6849
28c6e247
IR
6850 ret = peer_timers_connect_unset(peer);
6851
6852 return bgp_vty_return(vty, ret);
6853}
6854
6855DEFUN (neighbor_timers_connect,
6856 neighbor_timers_connect_cmd,
6857 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
6858 NEIGHBOR_STR
6859 NEIGHBOR_ADDR_STR2
6860 "BGP per neighbor timers\n"
6861 "BGP connect timer\n"
6862 "Connect timer\n")
6863{
6864 int idx_peer = 1;
6865 int idx_number = 4;
6866 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6867 argv[idx_number]->arg);
6868}
718e3744 6869
28c6e247
IR
6870DEFUN (no_neighbor_timers_connect,
6871 no_neighbor_timers_connect_cmd,
6872 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
6873 NO_STR
6874 NEIGHBOR_STR
6875 NEIGHBOR_ADDR_STR2
6876 "BGP per neighbor timers\n"
6877 "BGP connect timer\n"
6878 "Connect timer\n")
6879{
6880 int idx_peer = 2;
6881 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6882}
6883
d43114f3
DS
6884DEFPY (neighbor_timers_delayopen,
6885 neighbor_timers_delayopen_cmd,
6886 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
6887 NEIGHBOR_STR
6888 NEIGHBOR_ADDR_STR2
6889 "BGP per neighbor timers\n"
6890 "RFC 4271 DelayOpenTimer\n"
6891 "DelayOpenTime timer interval\n")
6892{
6893 struct peer *peer;
6894
6895 peer = peer_and_group_lookup_vty(vty, neighbor);
6896 if (!peer)
6897 return CMD_WARNING_CONFIG_FAILED;
6898
6899 if (!interval) {
6900 if (peer_timers_delayopen_unset(peer))
6901 return CMD_WARNING_CONFIG_FAILED;
6902 } else {
6903 if (peer_timers_delayopen_set(peer, interval))
6904 return CMD_WARNING_CONFIG_FAILED;
6905 }
6906
6907 return CMD_SUCCESS;
6908}
6909
6910DEFPY (no_neighbor_timers_delayopen,
6911 no_neighbor_timers_delayopen_cmd,
6912 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
6913 NO_STR
6914 NEIGHBOR_STR
6915 NEIGHBOR_ADDR_STR2
6916 "BGP per neighbor timers\n"
6917 "RFC 4271 DelayOpenTimer\n"
6918 "DelayOpenTime timer interval\n")
6919{
6920 struct peer *peer;
6921
6922 peer = peer_and_group_lookup_vty(vty, neighbor);
6923 if (!peer)
6924 return CMD_WARNING_CONFIG_FAILED;
6925
6926 if (peer_timers_delayopen_unset(peer))
6927 return CMD_WARNING_CONFIG_FAILED;
6928
6929 return CMD_SUCCESS;
6930}
6931
28c6e247
IR
6932static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
6933 const char *time_str, int set)
718e3744 6934{
28c6e247
IR
6935 int ret;
6936 struct peer *peer;
6937 uint32_t routeadv = 0;
718e3744 6938
28c6e247
IR
6939 peer = peer_and_group_lookup_vty(vty, ip_str);
6940 if (!peer)
d62a17ae 6941 return CMD_WARNING_CONFIG_FAILED;
718e3744 6942
28c6e247
IR
6943 if (time_str)
6944 routeadv = strtoul(time_str, NULL, 10);
6945
6946 if (set)
6947 ret = peer_advertise_interval_set(peer, routeadv);
6948 else
6949 ret = peer_advertise_interval_unset(peer);
718e3744 6950
28c6e247 6951 return bgp_vty_return(vty, ret);
718e3744 6952}
6953
28c6e247
IR
6954DEFUN (neighbor_advertise_interval,
6955 neighbor_advertise_interval_cmd,
6956 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
6957 NEIGHBOR_STR
6958 NEIGHBOR_ADDR_STR2
6959 "Minimum interval between sending BGP routing updates\n"
6960 "time in seconds\n")
718e3744 6961{
28c6e247
IR
6962 int idx_peer = 1;
6963 int idx_number = 3;
6964 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
6965 argv[idx_number]->arg, 1);
6966}
f4b8ec07 6967
28c6e247
IR
6968DEFUN (no_neighbor_advertise_interval,
6969 no_neighbor_advertise_interval_cmd,
6970 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
6971 NO_STR
6972 NEIGHBOR_STR
6973 NEIGHBOR_ADDR_STR2
6974 "Minimum interval between sending BGP routing updates\n"
6975 "time in seconds\n")
6976{
6977 int idx_peer = 2;
6978 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 6979}
6980
6b0655a2 6981
518f0eb1
DS
6982/* Time to wait before processing route-map updates */
6983DEFUN (bgp_set_route_map_delay_timer,
6984 bgp_set_route_map_delay_timer_cmd,
6147e2c6 6985 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
6986 SET_STR
6987 "BGP route-map delay timer\n"
6988 "Time in secs to wait before processing route-map changes\n"
f414725f 6989 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 6990{
d62a17ae 6991 int idx_number = 3;
d7c0a89a 6992 uint32_t rmap_delay_timer;
d62a17ae 6993
6994 if (argv[idx_number]->arg) {
6995 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
6996 bm->rmap_update_timer = rmap_delay_timer;
6997
6998 /* if the dynamic update handling is being disabled, and a timer
6999 * is
7000 * running, stop the timer and act as if the timer has already
7001 * fired.
7002 */
7003 if (!rmap_delay_timer && bm->t_rmap_update) {
7004 BGP_TIMER_OFF(bm->t_rmap_update);
7005 thread_execute(bm->master, bgp_route_map_update_timer,
7006 NULL, 0);
7007 }
7008 return CMD_SUCCESS;
7009 } else {
7010 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7011 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7012 }
518f0eb1
DS
7013}
7014
7015DEFUN (no_bgp_set_route_map_delay_timer,
7016 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7017 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7018 NO_STR
3a2d747c 7019 BGP_STR
518f0eb1 7020 "Default BGP route-map delay timer\n"
8334fd5a
DW
7021 "Reset to default time to wait for processing route-map changes\n"
7022 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7023{
518f0eb1 7024
d62a17ae 7025 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7026
d62a17ae 7027 return CMD_SUCCESS;
518f0eb1
DS
7028}
7029
28c6e247
IR
7030/* neighbor interface */
7031static int peer_interface_vty(struct vty *vty, const char *ip_str,
7032 const char *str)
718e3744 7033{
28c6e247 7034 struct peer *peer;
718e3744 7035
28c6e247
IR
7036 peer = peer_lookup_vty(vty, ip_str);
7037 if (!peer || peer->conf_if) {
7038 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7039 return CMD_WARNING_CONFIG_FAILED;
7040 }
718e3744 7041
28c6e247
IR
7042 if (str)
7043 peer_interface_set(peer, str);
7044 else
7045 peer_interface_unset(peer);
718e3744 7046
28c6e247 7047 return CMD_SUCCESS;
718e3744 7048}
7049
28c6e247
IR
7050DEFUN (neighbor_interface,
7051 neighbor_interface_cmd,
7052 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7053 NEIGHBOR_STR
7054 NEIGHBOR_ADDR_STR
7055 "Interface\n"
7056 "Interface name\n")
718e3744 7057{
28c6e247
IR
7058 int idx_ip = 1;
7059 int idx_word = 3;
294d8425 7060
28c6e247
IR
7061 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7062}
f4b8ec07 7063
28c6e247
IR
7064DEFUN (no_neighbor_interface,
7065 no_neighbor_interface_cmd,
294d8425 7066 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
28c6e247
IR
7067 NO_STR
7068 NEIGHBOR_STR
294d8425 7069 NEIGHBOR_ADDR_STR
28c6e247
IR
7070 "Interface\n"
7071 "Interface name\n")
7072{
7073 int idx_peer = 2;
294d8425 7074
28c6e247 7075 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 7076}
6b0655a2 7077
718e3744 7078DEFUN (neighbor_distribute_list,
7079 neighbor_distribute_list_cmd,
c60dec36 7080 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7081 NEIGHBOR_STR
7082 NEIGHBOR_ADDR_STR2
7083 "Filter updates to/from this neighbor\n"
718e3744 7084 "IP Access-list name\n"
7085 "Filter incoming updates\n"
7086 "Filter outgoing updates\n")
7087{
d62a17ae 7088 int idx_peer = 1;
7089 int idx_acl = 3;
7090 int direct, ret;
7091 struct peer *peer;
a8206004 7092
d62a17ae 7093 const char *pstr = argv[idx_peer]->arg;
7094 const char *acl = argv[idx_acl]->arg;
7095 const char *inout = argv[argc - 1]->text;
a8206004 7096
d62a17ae 7097 peer = peer_and_group_lookup_vty(vty, pstr);
7098 if (!peer)
7099 return CMD_WARNING_CONFIG_FAILED;
a8206004 7100
d62a17ae 7101 /* Check filter direction. */
7102 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7103 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7104 direct, acl);
a8206004 7105
d62a17ae 7106 return bgp_vty_return(vty, ret);
718e3744 7107}
7108
d62a17ae 7109ALIAS_HIDDEN(
7110 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
c60dec36 7111 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7112 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7113 "Filter updates to/from this neighbor\n"
d62a17ae 7114 "IP Access-list name\n"
7115 "Filter incoming updates\n"
7116 "Filter outgoing updates\n")
596c17ba 7117
718e3744 7118DEFUN (no_neighbor_distribute_list,
7119 no_neighbor_distribute_list_cmd,
c60dec36 7120 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7121 NO_STR
7122 NEIGHBOR_STR
7123 NEIGHBOR_ADDR_STR2
7124 "Filter updates to/from this neighbor\n"
718e3744 7125 "IP Access-list name\n"
7126 "Filter incoming updates\n"
7127 "Filter outgoing updates\n")
7128{
d62a17ae 7129 int idx_peer = 2;
7130 int direct, ret;
7131 struct peer *peer;
a8206004 7132
d62a17ae 7133 const char *pstr = argv[idx_peer]->arg;
7134 const char *inout = argv[argc - 1]->text;
a8206004 7135
d62a17ae 7136 peer = peer_and_group_lookup_vty(vty, pstr);
7137 if (!peer)
7138 return CMD_WARNING_CONFIG_FAILED;
a8206004 7139
d62a17ae 7140 /* Check filter direction. */
7141 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7142 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7143 direct);
a8206004 7144
d62a17ae 7145 return bgp_vty_return(vty, ret);
718e3744 7146}
6b0655a2 7147
d62a17ae 7148ALIAS_HIDDEN(
7149 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
c60dec36 7150 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7151 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7152 "Filter updates to/from this neighbor\n"
d62a17ae 7153 "IP Access-list name\n"
7154 "Filter incoming updates\n"
7155 "Filter outgoing updates\n")
596c17ba 7156
718e3744 7157/* Set prefix list to the peer. */
642ef664
IR
7158static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7159 afi_t afi, safi_t safi,
7160 const char *name_str,
7161 const char *direct_str)
718e3744 7162{
642ef664
IR
7163 int ret;
7164 int direct = FILTER_IN;
7165 struct peer *peer;
718e3744 7166
642ef664
IR
7167 peer = peer_and_group_lookup_vty(vty, ip_str);
7168 if (!peer)
d62a17ae 7169 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7170
642ef664
IR
7171 /* Check filter direction. */
7172 if (strncmp(direct_str, "i", 1) == 0)
7173 direct = FILTER_IN;
7174 else if (strncmp(direct_str, "o", 1) == 0)
7175 direct = FILTER_OUT;
718e3744 7176
642ef664 7177 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 7178
642ef664
IR
7179 return bgp_vty_return(vty, ret);
7180}
7181
7182static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7183 afi_t afi, safi_t safi,
7184 const char *direct_str)
7185{
7186 int ret;
7187 struct peer *peer;
7188 int direct = FILTER_IN;
7189
7190 peer = peer_and_group_lookup_vty(vty, ip_str);
7191 if (!peer)
7192 return CMD_WARNING_CONFIG_FAILED;
7193
7194 /* Check filter direction. */
7195 if (strncmp(direct_str, "i", 1) == 0)
7196 direct = FILTER_IN;
7197 else if (strncmp(direct_str, "o", 1) == 0)
7198 direct = FILTER_OUT;
7199
7200 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7201
7202 return bgp_vty_return(vty, ret);
7203}
7204
7205DEFUN (neighbor_prefix_list,
7206 neighbor_prefix_list_cmd,
7207 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7208 NEIGHBOR_STR
7209 NEIGHBOR_ADDR_STR2
7210 "Filter updates to/from this neighbor\n"
7211 "Name of a prefix list\n"
7212 "Filter incoming updates\n"
7213 "Filter outgoing updates\n")
7214{
7215 int idx_peer = 1;
7216 int idx_word = 3;
7217 int idx_in_out = 4;
7218 return peer_prefix_list_set_vty(
7219 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7220 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7221}
7222
d62a17ae 7223ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7224 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7225 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7226 "Filter updates to/from this neighbor\n"
7227 "Name of a prefix list\n"
7228 "Filter incoming updates\n"
7229 "Filter outgoing updates\n")
596c17ba 7230
642ef664
IR
7231DEFUN (no_neighbor_prefix_list,
7232 no_neighbor_prefix_list_cmd,
7233 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7234 NO_STR
7235 NEIGHBOR_STR
7236 NEIGHBOR_ADDR_STR2
7237 "Filter updates to/from this neighbor\n"
7238 "Name of a prefix list\n"
7239 "Filter incoming updates\n"
7240 "Filter outgoing updates\n")
7241{
7242 int idx_peer = 2;
7243 int idx_in_out = 5;
7244 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7245 bgp_node_afi(vty), bgp_node_safi(vty),
7246 argv[idx_in_out]->arg);
7247}
7248
7249ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7250 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7251 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7252 "Filter updates to/from this neighbor\n"
7253 "Name of a prefix list\n"
7254 "Filter incoming updates\n"
7255 "Filter outgoing updates\n")
7256
d62a17ae 7257static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7258 safi_t safi, const char *name_str,
7259 const char *direct_str)
718e3744 7260{
d62a17ae 7261 int ret;
7262 struct peer *peer;
7263 int direct = FILTER_IN;
718e3744 7264
d62a17ae 7265 peer = peer_and_group_lookup_vty(vty, ip_str);
7266 if (!peer)
7267 return CMD_WARNING_CONFIG_FAILED;
718e3744 7268
d62a17ae 7269 /* Check filter direction. */
7270 if (strncmp(direct_str, "i", 1) == 0)
7271 direct = FILTER_IN;
7272 else if (strncmp(direct_str, "o", 1) == 0)
7273 direct = FILTER_OUT;
718e3744 7274
d62a17ae 7275 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7276
d62a17ae 7277 return bgp_vty_return(vty, ret);
718e3744 7278}
7279
d62a17ae 7280static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7281 safi_t safi, const char *direct_str)
718e3744 7282{
d62a17ae 7283 int ret;
7284 struct peer *peer;
7285 int direct = FILTER_IN;
718e3744 7286
d62a17ae 7287 peer = peer_and_group_lookup_vty(vty, ip_str);
7288 if (!peer)
7289 return CMD_WARNING_CONFIG_FAILED;
718e3744 7290
d62a17ae 7291 /* Check filter direction. */
7292 if (strncmp(direct_str, "i", 1) == 0)
7293 direct = FILTER_IN;
7294 else if (strncmp(direct_str, "o", 1) == 0)
7295 direct = FILTER_OUT;
718e3744 7296
d62a17ae 7297 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7298
d62a17ae 7299 return bgp_vty_return(vty, ret);
718e3744 7300}
7301
7302DEFUN (neighbor_filter_list,
7303 neighbor_filter_list_cmd,
de71d43e 7304 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7305 NEIGHBOR_STR
7306 NEIGHBOR_ADDR_STR2
7307 "Establish BGP filters\n"
7308 "AS path access-list name\n"
7309 "Filter incoming routes\n"
7310 "Filter outgoing routes\n")
7311{
d62a17ae 7312 int idx_peer = 1;
7313 int idx_word = 3;
7314 int idx_in_out = 4;
7315 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7316 bgp_node_safi(vty), argv[idx_word]->arg,
7317 argv[idx_in_out]->arg);
718e3744 7318}
7319
d62a17ae 7320ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
de71d43e 7321 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7322 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7323 "Establish BGP filters\n"
7324 "AS path access-list name\n"
7325 "Filter incoming routes\n"
7326 "Filter outgoing routes\n")
596c17ba 7327
718e3744 7328DEFUN (no_neighbor_filter_list,
7329 no_neighbor_filter_list_cmd,
de71d43e 7330 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7331 NO_STR
7332 NEIGHBOR_STR
7333 NEIGHBOR_ADDR_STR2
7334 "Establish BGP filters\n"
7335 "AS path access-list name\n"
7336 "Filter incoming routes\n"
7337 "Filter outgoing routes\n")
7338{
d62a17ae 7339 int idx_peer = 2;
7340 int idx_in_out = 5;
7341 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7342 bgp_node_afi(vty), bgp_node_safi(vty),
7343 argv[idx_in_out]->arg);
718e3744 7344}
6b0655a2 7345
d62a17ae 7346ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
de71d43e 7347 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7348 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7349 "Establish BGP filters\n"
7350 "AS path access-list name\n"
7351 "Filter incoming routes\n"
7352 "Filter outgoing routes\n")
596c17ba 7353
7f7940e6
MK
7354/* Set advertise-map to the peer. */
7355static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7356 afi_t afi, safi_t safi,
cf2ad4d8
MK
7357 const char *advertise_str,
7358 const char *condition_str, bool condition,
7359 bool set)
7f7940e6
MK
7360{
7361 int ret = CMD_WARNING_CONFIG_FAILED;
7362 struct peer *peer;
7363 struct route_map *advertise_map;
7364 struct route_map *condition_map;
7365
7366 peer = peer_and_group_lookup_vty(vty, ip_str);
7367 if (!peer)
7368 return ret;
7369
7370 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7371 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7372
cf2ad4d8
MK
7373 if (set)
7374 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7375 advertise_map, condition_str,
7376 condition_map, condition);
7377 else
7378 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7379 advertise_map, condition_str,
7380 condition_map, condition);
7f7940e6
MK
7381
7382 return bgp_vty_return(vty, ret);
7383}
7384
389e4f92
QY
7385DEFPY (bgp_condadv_period,
7386 bgp_condadv_period_cmd,
7387 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7388 NO_STR
7389 BGP_STR
7390 "Conditional advertisement settings\n"
7391 "Set period to rescan BGP table to check if condition is met\n"
7392 "Period between BGP table scans, in seconds; default 60\n")
7393{
7394 VTY_DECLVAR_CONTEXT(bgp, bgp);
7395
7396 bgp->condition_check_period =
7397 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7398
7399 return CMD_SUCCESS;
7400}
7401
cf2ad4d8 7402DEFPY (neighbor_advertise_map,
7f7940e6 7403 neighbor_advertise_map_cmd,
52b84062 7404 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
cf2ad4d8 7405 NO_STR
7f7940e6
MK
7406 NEIGHBOR_STR
7407 NEIGHBOR_ADDR_STR2
7408 "Route-map to conditionally advertise routes\n"
7409 "Name of advertise map\n"
7410 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7411 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7412 "Name of the exist or non exist map\n")
7f7940e6 7413{
7f7940e6
MK
7414 bool condition = CONDITION_EXIST;
7415
52b84062 7416 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7417 condition = CONDITION_NON_EXIST;
7418
52b84062
MK
7419 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7420 bgp_node_safi(vty), advertise_str,
7421 condition_str, condition, !no);
7f7940e6
MK
7422}
7423
7424ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
52b84062 7425 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
7f7940e6
MK
7426 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7427 "Route-map to conditionally advertise routes\n"
7428 "Name of advertise map\n"
7429 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7430 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7431 "Name of the exist or non exist map\n")
7f7940e6 7432
718e3744 7433/* Set route-map to the peer. */
0ea8d871
IR
7434static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7435 afi_t afi, safi_t safi, const char *name_str,
7436 const char *direct_str)
718e3744 7437{
0ea8d871
IR
7438 int ret;
7439 struct peer *peer;
7440 int direct = RMAP_IN;
7441 struct route_map *route_map;
718e3744 7442
0ea8d871
IR
7443 peer = peer_and_group_lookup_vty(vty, ip_str);
7444 if (!peer)
d62a17ae 7445 return CMD_WARNING_CONFIG_FAILED;
718e3744 7446
0ea8d871
IR
7447 /* Check filter direction. */
7448 if (strncmp(direct_str, "in", 2) == 0)
7449 direct = RMAP_IN;
7450 else if (strncmp(direct_str, "o", 1) == 0)
7451 direct = RMAP_OUT;
718e3744 7452
0ea8d871
IR
7453 route_map = route_map_lookup_warn_noexist(vty, name_str);
7454 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7455
0ea8d871
IR
7456 return bgp_vty_return(vty, ret);
7457}
7458
7459static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7460 afi_t afi, safi_t safi,
7461 const char *direct_str)
7462{
7463 int ret;
7464 struct peer *peer;
7465 int direct = RMAP_IN;
7466
7467 peer = peer_and_group_lookup_vty(vty, ip_str);
7468 if (!peer)
7469 return CMD_WARNING_CONFIG_FAILED;
7470
7471 /* Check filter direction. */
7472 if (strncmp(direct_str, "in", 2) == 0)
7473 direct = RMAP_IN;
7474 else if (strncmp(direct_str, "o", 1) == 0)
7475 direct = RMAP_OUT;
7476
7477 ret = peer_route_map_unset(peer, afi, safi, direct);
7478
7479 return bgp_vty_return(vty, ret);
7480}
7481
7482DEFUN (neighbor_route_map,
7483 neighbor_route_map_cmd,
7484 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7485 NEIGHBOR_STR
7486 NEIGHBOR_ADDR_STR2
7487 "Apply route map to neighbor\n"
7488 "Name of route map\n"
7489 "Apply map to incoming routes\n"
7490 "Apply map to outbound routes\n")
7491{
7492 int idx_peer = 1;
7493 int idx_word = 3;
7494 int idx_in_out = 4;
7495 return peer_route_map_set_vty(
7496 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7497 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7498}
7499
d6d7ed37
IR
7500ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7501 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7502 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7503 "Apply route map to neighbor\n"
7504 "Name of route map\n"
7505 "Apply map to incoming routes\n"
7506 "Apply map to outbound routes\n")
7507
0ea8d871
IR
7508DEFUN (no_neighbor_route_map,
7509 no_neighbor_route_map_cmd,
7510 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7511 NO_STR
7512 NEIGHBOR_STR
7513 NEIGHBOR_ADDR_STR2
7514 "Apply route map to neighbor\n"
7515 "Name of route map\n"
7516 "Apply map to incoming routes\n"
7517 "Apply map to outbound routes\n")
7518{
7519 int idx_peer = 2;
7520 int idx_in_out = 5;
7521 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7522 bgp_node_afi(vty), bgp_node_safi(vty),
7523 argv[idx_in_out]->arg);
7524}
7525
7526ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
d6d7ed37
IR
7527 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7528 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7529 "Apply route map to neighbor\n"
7530 "Name of route map\n"
7531 "Apply map to incoming routes\n"
7532 "Apply map to outbound routes\n")
7533
718e3744 7534/* Set unsuppress-map to the peer. */
d62a17ae 7535static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7536 afi_t afi, safi_t safi,
7537 const char *name_str)
718e3744 7538{
d62a17ae 7539 int ret;
7540 struct peer *peer;
1de27621 7541 struct route_map *route_map;
718e3744 7542
d62a17ae 7543 peer = peer_and_group_lookup_vty(vty, ip_str);
7544 if (!peer)
7545 return CMD_WARNING_CONFIG_FAILED;
718e3744 7546
1de27621
DA
7547 route_map = route_map_lookup_warn_noexist(vty, name_str);
7548 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 7549
d62a17ae 7550 return bgp_vty_return(vty, ret);
718e3744 7551}
7552
7553/* Unset route-map from the peer. */
d62a17ae 7554static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7555 afi_t afi, safi_t safi)
718e3744 7556{
d62a17ae 7557 int ret;
7558 struct peer *peer;
718e3744 7559
d62a17ae 7560 peer = peer_and_group_lookup_vty(vty, ip_str);
7561 if (!peer)
7562 return CMD_WARNING_CONFIG_FAILED;
718e3744 7563
d62a17ae 7564 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 7565
d62a17ae 7566 return bgp_vty_return(vty, ret);
718e3744 7567}
7568
7569DEFUN (neighbor_unsuppress_map,
7570 neighbor_unsuppress_map_cmd,
9ccf14f7 7571 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7572 NEIGHBOR_STR
7573 NEIGHBOR_ADDR_STR2
7574 "Route-map to selectively unsuppress suppressed routes\n"
7575 "Name of route map\n")
7576{
d62a17ae 7577 int idx_peer = 1;
7578 int idx_word = 3;
7579 return peer_unsuppress_map_set_vty(
7580 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7581 argv[idx_word]->arg);
718e3744 7582}
7583
d62a17ae 7584ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7585 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7586 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7587 "Route-map to selectively unsuppress suppressed routes\n"
7588 "Name of route map\n")
596c17ba 7589
718e3744 7590DEFUN (no_neighbor_unsuppress_map,
7591 no_neighbor_unsuppress_map_cmd,
9ccf14f7 7592 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7593 NO_STR
7594 NEIGHBOR_STR
7595 NEIGHBOR_ADDR_STR2
7596 "Route-map to selectively unsuppress suppressed routes\n"
7597 "Name of route map\n")
7598{
d62a17ae 7599 int idx_peer = 2;
7600 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7601 bgp_node_afi(vty),
7602 bgp_node_safi(vty));
718e3744 7603}
6b0655a2 7604
d62a17ae 7605ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7606 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7607 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7608 "Route-map to selectively unsuppress suppressed routes\n"
7609 "Name of route map\n")
596c17ba 7610
7e62b792
IR
7611static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7612 afi_t afi, safi_t safi,
7613 const char *num_str,
7614 const char *threshold_str, int warning,
7615 const char *restart_str,
7616 const char *force_str)
7617{
7618 int ret;
7619 struct peer *peer;
7620 uint32_t max;
7621 uint8_t threshold;
7622 uint16_t restart;
7623
7624 peer = peer_and_group_lookup_vty(vty, ip_str);
7625 if (!peer)
7626 return CMD_WARNING_CONFIG_FAILED;
7627
7628 max = strtoul(num_str, NULL, 10);
7629 if (threshold_str)
7630 threshold = atoi(threshold_str);
7631 else
7632 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7633
7634 if (restart_str)
7635 restart = atoi(restart_str);
7636 else
7637 restart = 0;
7638
7639 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7640 restart, force_str ? true : false);
7641
7642 return bgp_vty_return(vty, ret);
7643}
7644
7645static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7646 afi_t afi, safi_t safi)
7647{
7648 int ret;
7649 struct peer *peer;
7650
7651 peer = peer_and_group_lookup_vty(vty, ip_str);
7652 if (!peer)
7653 return CMD_WARNING_CONFIG_FAILED;
7654
7655 ret = peer_maximum_prefix_unset(peer, afi, safi);
7656
7657 return bgp_vty_return(vty, ret);
7658}
7659
fde246e8 7660/* Maximum number of prefix to be sent to the neighbor. */
1d80f243
IR
7661DEFUN(neighbor_maximum_prefix_out,
7662 neighbor_maximum_prefix_out_cmd,
7663 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7664 NEIGHBOR_STR
7665 NEIGHBOR_ADDR_STR2
7666 "Maximum number of prefixes to be sent to this peer\n"
7667 "Maximum no. of prefix limit\n")
fde246e8
DA
7668{
7669 int idx_peer = 1;
7670 int idx_number = 3;
7e62b792
IR
7671 struct peer *peer;
7672 uint32_t max;
fde246e8
DA
7673 afi_t afi = bgp_node_afi(vty);
7674 safi_t safi = bgp_node_safi(vty);
7675
7e62b792
IR
7676 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7677 if (!peer)
fde246e8
DA
7678 return CMD_WARNING_CONFIG_FAILED;
7679
7e62b792 7680 max = strtoul(argv[idx_number]->arg, NULL, 10);
fde246e8 7681
7e62b792
IR
7682 SET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
7683 peer->pmax_out[afi][safi] = max;
fde246e8 7684
d0bf49ec 7685 peer_maximum_prefix_out_refresh_routes(peer, afi, safi);
7e62b792 7686 return CMD_SUCCESS;
fde246e8
DA
7687}
7688
1d80f243
IR
7689DEFUN(no_neighbor_maximum_prefix_out,
7690 no_neighbor_maximum_prefix_out_cmd,
7691 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
7692 NO_STR
7693 NEIGHBOR_STR
7694 NEIGHBOR_ADDR_STR2
7695 "Maximum number of prefixes to be sent to this peer\n")
fde246e8
DA
7696{
7697 int idx_peer = 2;
7e62b792 7698 struct peer *peer;
fde246e8
DA
7699 afi_t afi = bgp_node_afi(vty);
7700 safi_t safi = bgp_node_safi(vty);
7701
7e62b792
IR
7702 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7703 if (!peer)
fde246e8
DA
7704 return CMD_WARNING_CONFIG_FAILED;
7705
7e62b792
IR
7706 UNSET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
7707 peer->pmax_out[afi][safi] = 0;
fde246e8 7708
d0bf49ec 7709 peer_maximum_prefix_out_refresh_routes(peer, afi, safi);
7e62b792 7710 return CMD_SUCCESS;
fde246e8
DA
7711}
7712
9cbd06e0
DA
7713/* Maximum number of prefix configuration. Prefix count is different
7714 for each peer configuration. So this configuration can be set for
718e3744 7715 each peer configuration. */
1d80f243
IR
7716DEFUN (neighbor_maximum_prefix,
7717 neighbor_maximum_prefix_cmd,
7718 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7719 NEIGHBOR_STR
7720 NEIGHBOR_ADDR_STR2
7721 "Maximum number of prefix accept from this peer\n"
7722 "maximum no. of prefix limit\n"
7723 "Force checking all received routes not only accepted\n")
718e3744 7724{
d62a17ae 7725 int idx_peer = 1;
7726 int idx_number = 3;
9cbd06e0 7727 int idx_force = 0;
7e62b792 7728 char *force = NULL;
9cbd06e0
DA
7729
7730 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7731 force = argv[idx_force]->arg;
9cbd06e0 7732
7e62b792
IR
7733 return peer_maximum_prefix_set_vty(
7734 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7735 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 7736}
7737
d62a17ae 7738ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7739 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 7740 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7741 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
7742 "maximum no. of prefix limit\n"
7743 "Force checking all received routes not only accepted\n")
596c17ba 7744
1d80f243
IR
7745DEFUN (neighbor_maximum_prefix_threshold,
7746 neighbor_maximum_prefix_threshold_cmd,
7747 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7748 NEIGHBOR_STR
7749 NEIGHBOR_ADDR_STR2
7750 "Maximum number of prefix accept from this peer\n"
7751 "maximum no. of prefix limit\n"
7752 "Threshold value (%) at which to generate a warning msg\n"
7753 "Force checking all received routes not only accepted\n")
e0701b79 7754{
d62a17ae 7755 int idx_peer = 1;
7756 int idx_number = 3;
7757 int idx_number_2 = 4;
9cbd06e0 7758 int idx_force = 0;
7e62b792 7759 char *force = NULL;
9cbd06e0
DA
7760
7761 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7762 force = argv[idx_force]->arg;
9cbd06e0 7763
7e62b792
IR
7764 return peer_maximum_prefix_set_vty(
7765 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7766 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 7767}
e0701b79 7768
d62a17ae 7769ALIAS_HIDDEN(
7770 neighbor_maximum_prefix_threshold,
7771 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 7772 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 7773 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7774 "Maximum number of prefix accept from this peer\n"
7775 "maximum no. of prefix limit\n"
9cbd06e0
DA
7776 "Threshold value (%) at which to generate a warning msg\n"
7777 "Force checking all received routes not only accepted\n")
596c17ba 7778
1d80f243
IR
7779DEFUN (neighbor_maximum_prefix_warning,
7780 neighbor_maximum_prefix_warning_cmd,
7781 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7782 NEIGHBOR_STR
7783 NEIGHBOR_ADDR_STR2
7784 "Maximum number of prefix accept from this peer\n"
7785 "maximum no. of prefix limit\n"
7786 "Only give warning message when limit is exceeded\n"
7787 "Force checking all received routes not only accepted\n")
718e3744 7788{
d62a17ae 7789 int idx_peer = 1;
7790 int idx_number = 3;
9cbd06e0 7791 int idx_force = 0;
7e62b792 7792 char *force = NULL;
9cbd06e0
DA
7793
7794 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7795 force = argv[idx_force]->arg;
9cbd06e0 7796
7e62b792
IR
7797 return peer_maximum_prefix_set_vty(
7798 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7799 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 7800}
7801
d62a17ae 7802ALIAS_HIDDEN(
7803 neighbor_maximum_prefix_warning,
7804 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 7805 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 7806 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7807 "Maximum number of prefix accept from this peer\n"
7808 "maximum no. of prefix limit\n"
9cbd06e0
DA
7809 "Only give warning message when limit is exceeded\n"
7810 "Force checking all received routes not only accepted\n")
596c17ba 7811
1d80f243
IR
7812DEFUN (neighbor_maximum_prefix_threshold_warning,
7813 neighbor_maximum_prefix_threshold_warning_cmd,
7814 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7815 NEIGHBOR_STR
7816 NEIGHBOR_ADDR_STR2
7817 "Maximum number of prefix accept from this peer\n"
7818 "maximum no. of prefix limit\n"
7819 "Threshold value (%) at which to generate a warning msg\n"
7820 "Only give warning message when limit is exceeded\n"
7821 "Force checking all received routes not only accepted\n")
e0701b79 7822{
d62a17ae 7823 int idx_peer = 1;
7824 int idx_number = 3;
7825 int idx_number_2 = 4;
9cbd06e0 7826 int idx_force = 0;
7e62b792 7827 char *force = NULL;
9cbd06e0
DA
7828
7829 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7830 force = argv[idx_force]->arg;
9cbd06e0 7831
7e62b792
IR
7832 return peer_maximum_prefix_set_vty(
7833 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7834 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 7835}
7836
d62a17ae 7837ALIAS_HIDDEN(
7838 neighbor_maximum_prefix_threshold_warning,
7839 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 7840 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 7841 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7842 "Maximum number of prefix accept from this peer\n"
7843 "maximum no. of prefix limit\n"
7844 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
7845 "Only give warning message when limit is exceeded\n"
7846 "Force checking all received routes not only accepted\n")
596c17ba 7847
1d80f243
IR
7848DEFUN (neighbor_maximum_prefix_restart,
7849 neighbor_maximum_prefix_restart_cmd,
7850 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7851 NEIGHBOR_STR
7852 NEIGHBOR_ADDR_STR2
7853 "Maximum number of prefix accept from this peer\n"
7854 "maximum no. of prefix limit\n"
7855 "Restart bgp connection after limit is exceeded\n"
7856 "Restart interval in minutes\n"
7857 "Force checking all received routes not only accepted\n")
0a486e5f 7858{
d62a17ae 7859 int idx_peer = 1;
7860 int idx_number = 3;
7861 int idx_number_2 = 5;
9cbd06e0 7862 int idx_force = 0;
7e62b792 7863 char *force = NULL;
9cbd06e0
DA
7864
7865 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7866 force = argv[idx_force]->arg;
9cbd06e0 7867
7e62b792
IR
7868 return peer_maximum_prefix_set_vty(
7869 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7870 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 7871}
7872
d62a17ae 7873ALIAS_HIDDEN(
7874 neighbor_maximum_prefix_restart,
7875 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 7876 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 7877 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7878 "Maximum number of prefix accept from this peer\n"
7879 "maximum no. of prefix limit\n"
7880 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7881 "Restart interval in minutes\n"
7882 "Force checking all received routes not only accepted\n")
596c17ba 7883
1d80f243
IR
7884DEFUN (neighbor_maximum_prefix_threshold_restart,
7885 neighbor_maximum_prefix_threshold_restart_cmd,
7886 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7887 NEIGHBOR_STR
7888 NEIGHBOR_ADDR_STR2
7889 "Maximum number of prefixes to accept from this peer\n"
7890 "maximum no. of prefix limit\n"
7891 "Threshold value (%) at which to generate a warning msg\n"
7892 "Restart bgp connection after limit is exceeded\n"
7893 "Restart interval in minutes\n"
7894 "Force checking all received routes not only accepted\n")
0a486e5f 7895{
d62a17ae 7896 int idx_peer = 1;
7897 int idx_number = 3;
7898 int idx_number_2 = 4;
7899 int idx_number_3 = 6;
9cbd06e0 7900 int idx_force = 0;
7e62b792 7901 char *force = NULL;
9cbd06e0
DA
7902
7903 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7904 force = argv[idx_force]->arg;
9cbd06e0 7905
7e62b792
IR
7906 return peer_maximum_prefix_set_vty(
7907 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7908 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
7909 argv[idx_number_3]->arg, force);
d62a17ae 7910}
7911
7912ALIAS_HIDDEN(
7913 neighbor_maximum_prefix_threshold_restart,
7914 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 7915 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 7916 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7917 "Maximum number of prefixes to accept from this peer\n"
7918 "maximum no. of prefix limit\n"
7919 "Threshold value (%) at which to generate a warning msg\n"
7920 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7921 "Restart interval in minutes\n"
7922 "Force checking all received routes not only accepted\n")
596c17ba 7923
1d80f243
IR
7924DEFUN (no_neighbor_maximum_prefix,
7925 no_neighbor_maximum_prefix_cmd,
7926 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
7927 NO_STR
7928 NEIGHBOR_STR
7929 NEIGHBOR_ADDR_STR2
7930 "Maximum number of prefixes to accept from this peer\n"
7931 "maximum no. of prefix limit\n"
7932 "Threshold value (%) at which to generate a warning msg\n"
7933 "Restart bgp connection after limit is exceeded\n"
7934 "Restart interval in minutes\n"
7935 "Only give warning message when limit is exceeded\n"
7936 "Force checking all received routes not only accepted\n")
718e3744 7937{
d62a17ae 7938 int idx_peer = 2;
7e62b792
IR
7939 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
7940 bgp_node_afi(vty),
7941 bgp_node_safi(vty));
718e3744 7942}
e52702f2 7943
d62a17ae 7944ALIAS_HIDDEN(
7945 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7946 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 7947 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7948 "Maximum number of prefixes to accept from this peer\n"
7949 "maximum no. of prefix limit\n"
7950 "Threshold value (%) at which to generate a warning msg\n"
7951 "Restart bgp connection after limit is exceeded\n"
7952 "Restart interval in minutes\n"
9cbd06e0
DA
7953 "Only give warning message when limit is exceeded\n"
7954 "Force checking all received routes not only accepted\n")
596c17ba 7955
718e3744 7956
718e3744 7957/* "neighbor allowas-in" */
7958DEFUN (neighbor_allowas_in,
7959 neighbor_allowas_in_cmd,
fd8503f5 7960 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7961 NEIGHBOR_STR
7962 NEIGHBOR_ADDR_STR2
31500417 7963 "Accept as-path with my AS present in it\n"
f79f7a7b 7964 "Number of occurrences of AS number\n"
fd8503f5 7965 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7966{
d62a17ae 7967 int idx_peer = 1;
7968 int idx_number_origin = 3;
7969 int ret;
7970 int origin = 0;
7971 struct peer *peer;
7972 int allow_num = 0;
7973
7974 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7975 if (!peer)
7976 return CMD_WARNING_CONFIG_FAILED;
7977
7978 if (argc <= idx_number_origin)
7979 allow_num = 3;
7980 else {
7981 if (argv[idx_number_origin]->type == WORD_TKN)
7982 origin = 1;
7983 else
7984 allow_num = atoi(argv[idx_number_origin]->arg);
7985 }
7986
7987 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7988 allow_num, origin);
7989
7990 return bgp_vty_return(vty, ret);
7991}
7992
7993ALIAS_HIDDEN(
7994 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
7995 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7996 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7997 "Accept as-path with my AS present in it\n"
f79f7a7b 7998 "Number of occurrences of AS number\n"
d62a17ae 7999 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8000
718e3744 8001DEFUN (no_neighbor_allowas_in,
8002 no_neighbor_allowas_in_cmd,
fd8503f5 8003 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8004 NO_STR
8005 NEIGHBOR_STR
8006 NEIGHBOR_ADDR_STR2
8334fd5a 8007 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8008 "Number of occurrences of AS number\n"
fd8503f5 8009 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8010{
d62a17ae 8011 int idx_peer = 2;
8012 int ret;
8013 struct peer *peer;
718e3744 8014
d62a17ae 8015 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8016 if (!peer)
8017 return CMD_WARNING_CONFIG_FAILED;
718e3744 8018
d62a17ae 8019 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8020 bgp_node_safi(vty));
718e3744 8021
d62a17ae 8022 return bgp_vty_return(vty, ret);
718e3744 8023}
6b0655a2 8024
d62a17ae 8025ALIAS_HIDDEN(
8026 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8027 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8028 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8029 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8030 "Number of occurrences of AS number\n"
d62a17ae 8031 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8032
28c6e247
IR
8033DEFUN (neighbor_ttl_security,
8034 neighbor_ttl_security_cmd,
8035 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8036 NEIGHBOR_STR
8037 NEIGHBOR_ADDR_STR2
8038 "BGP ttl-security parameters\n"
8039 "Specify the maximum number of hops to the BGP peer\n"
8040 "Number of hops to BGP peer\n")
fa411a21 8041{
d62a17ae 8042 int idx_peer = 1;
8043 int idx_number = 4;
28c6e247
IR
8044 struct peer *peer;
8045 int gtsm_hops;
d62a17ae 8046
28c6e247
IR
8047 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8048 if (!peer)
d62a17ae 8049 return CMD_WARNING_CONFIG_FAILED;
8050
28c6e247
IR
8051 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8052
8053 /*
8054 * If 'neighbor swpX', then this is for directly connected peers,
8055 * we should not accept a ttl-security hops value greater than 1.
8056 */
8057 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8058 vty_out(vty,
8059 "%s is directly connected peer, hops cannot exceed 1\n",
8060 argv[idx_peer]->arg);
8061 return CMD_WARNING_CONFIG_FAILED;
8062 }
7ebe625c 8063
28c6e247 8064 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
8065}
8066
1d80f243
IR
8067DEFUN (no_neighbor_ttl_security,
8068 no_neighbor_ttl_security_cmd,
8069 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8070 NO_STR
8071 NEIGHBOR_STR
8072 NEIGHBOR_ADDR_STR2
8073 "BGP ttl-security parameters\n"
8074 "Specify the maximum number of hops to the BGP peer\n"
8075 "Number of hops to BGP peer\n")
fa411a21 8076{
d62a17ae 8077 int idx_peer = 2;
28c6e247 8078 struct peer *peer;
fa411a21 8079
28c6e247
IR
8080 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8081 if (!peer)
d62a17ae 8082 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8083
28c6e247 8084 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 8085}
6b0655a2 8086
7c0e4312
DA
8087/* disable-addpath-rx */
8088DEFUN(neighbor_disable_addpath_rx,
8089 neighbor_disable_addpath_rx_cmd,
8090 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8091 NEIGHBOR_STR
8092 NEIGHBOR_ADDR_STR2
8093 "Do not accept additional paths\n")
8094{
8095 char *peer_str = argv[1]->arg;
8096 struct peer *peer;
8097 afi_t afi = bgp_node_afi(vty);
8098 safi_t safi = bgp_node_safi(vty);
8099
8100 peer = peer_and_group_lookup_vty(vty, peer_str);
8101 if (!peer)
8102 return CMD_WARNING_CONFIG_FAILED;
8103
8104 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8105 PEER_FLAG_DISABLE_ADDPATH_RX);
8106}
8107
8108DEFUN(no_neighbor_disable_addpath_rx,
8109 no_neighbor_disable_addpath_rx_cmd,
8110 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8111 NO_STR
8112 NEIGHBOR_STR
8113 NEIGHBOR_ADDR_STR2
8114 "Do not accept additional paths\n")
8115{
8116 char *peer_str = argv[2]->arg;
8117 struct peer *peer;
8118 afi_t afi = bgp_node_afi(vty);
8119 safi_t safi = bgp_node_safi(vty);
8120
8121 peer = peer_and_group_lookup_vty(vty, peer_str);
8122 if (!peer)
8123 return CMD_WARNING_CONFIG_FAILED;
8124
8125 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8126 PEER_FLAG_DISABLE_ADDPATH_RX);
8127}
8128
adbac85e
DW
8129DEFUN (neighbor_addpath_tx_all_paths,
8130 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8131 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8132 NEIGHBOR_STR
8133 NEIGHBOR_ADDR_STR2
8134 "Use addpath to advertise all paths to a neighbor\n")
8135{
d62a17ae 8136 int idx_peer = 1;
8137 struct peer *peer;
adbac85e 8138
d62a17ae 8139 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8140 if (!peer)
8141 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8142
dcc68b5e
MS
8143 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8144 BGP_ADDPATH_ALL);
8145 return CMD_SUCCESS;
adbac85e
DW
8146}
8147
d62a17ae 8148ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8149 neighbor_addpath_tx_all_paths_hidden_cmd,
8150 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8151 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8152 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8153
adbac85e
DW
8154DEFUN (no_neighbor_addpath_tx_all_paths,
8155 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8156 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8157 NO_STR
8158 NEIGHBOR_STR
8159 NEIGHBOR_ADDR_STR2
8160 "Use addpath to advertise all paths to a neighbor\n")
8161{
d62a17ae 8162 int idx_peer = 2;
dcc68b5e
MS
8163 struct peer *peer;
8164
8165 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8166 if (!peer)
8167 return CMD_WARNING_CONFIG_FAILED;
8168
8169 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8170 != BGP_ADDPATH_ALL) {
8171 vty_out(vty,
8172 "%% Peer not currently configured to transmit all paths.");
8173 return CMD_WARNING_CONFIG_FAILED;
8174 }
8175
8176 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8177 BGP_ADDPATH_NONE);
8178
8179 return CMD_SUCCESS;
adbac85e
DW
8180}
8181
d62a17ae 8182ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8183 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8184 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8185 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8186 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8187
06370dac
DW
8188DEFUN (neighbor_addpath_tx_bestpath_per_as,
8189 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8190 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8191 NEIGHBOR_STR
8192 NEIGHBOR_ADDR_STR2
8193 "Use addpath to advertise the bestpath per each neighboring AS\n")
8194{
d62a17ae 8195 int idx_peer = 1;
8196 struct peer *peer;
06370dac 8197
d62a17ae 8198 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8199 if (!peer)
8200 return CMD_WARNING_CONFIG_FAILED;
06370dac 8201
dcc68b5e
MS
8202 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8203 BGP_ADDPATH_BEST_PER_AS);
8204
8205 return CMD_SUCCESS;
06370dac
DW
8206}
8207
d62a17ae 8208ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8209 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8210 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8211 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8212 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8213
06370dac
DW
8214DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8215 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8216 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8217 NO_STR
8218 NEIGHBOR_STR
8219 NEIGHBOR_ADDR_STR2
8220 "Use addpath to advertise the bestpath per each neighboring AS\n")
8221{
d62a17ae 8222 int idx_peer = 2;
dcc68b5e
MS
8223 struct peer *peer;
8224
8225 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8226 if (!peer)
8227 return CMD_WARNING_CONFIG_FAILED;
8228
8229 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8230 != BGP_ADDPATH_BEST_PER_AS) {
8231 vty_out(vty,
8232 "%% Peer not currently configured to transmit all best path per as.");
8233 return CMD_WARNING_CONFIG_FAILED;
8234 }
8235
8236 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8237 BGP_ADDPATH_NONE);
8238
8239 return CMD_SUCCESS;
06370dac
DW
8240}
8241
d62a17ae 8242ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8243 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8244 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8245 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8246 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8247
2b31007c
RZ
8248DEFPY(
8249 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8250 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8251 NEIGHBOR_STR
8252 NEIGHBOR_ADDR_STR2
8253 "Detect AS loops before sending to neighbor\n")
8254{
8255 struct peer *peer;
8256
8257 peer = peer_and_group_lookup_vty(vty, neighbor);
8258 if (!peer)
8259 return CMD_WARNING_CONFIG_FAILED;
8260
8261 peer->as_path_loop_detection = true;
8262
8263 return CMD_SUCCESS;
8264}
8265
8266DEFPY(
8267 no_neighbor_aspath_loop_detection,
8268 no_neighbor_aspath_loop_detection_cmd,
8269 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8270 NO_STR
8271 NEIGHBOR_STR
8272 NEIGHBOR_ADDR_STR2
8273 "Detect AS loops before sending to neighbor\n")
8274{
8275 struct peer *peer;
8276
8277 peer = peer_and_group_lookup_vty(vty, neighbor);
8278 if (!peer)
8279 return CMD_WARNING_CONFIG_FAILED;
8280
8281 peer->as_path_loop_detection = false;
8282
8283 return CMD_SUCCESS;
8284}
8285
b9c7bc5a 8286static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8287 struct ecommunity **list, bool is_rt6)
ddb5b488 8288{
b9c7bc5a
PZ
8289 struct ecommunity *ecom = NULL;
8290 struct ecommunity *ecomadd;
ddb5b488 8291
b9c7bc5a 8292 for (; argc; --argc, ++argv) {
9a659715
PG
8293 if (is_rt6)
8294 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8295 ECOMMUNITY_ROUTE_TARGET,
8296 0);
8297 else
8298 ecomadd = ecommunity_str2com(argv[0]->arg,
8299 ECOMMUNITY_ROUTE_TARGET,
8300 0);
b9c7bc5a
PZ
8301 if (!ecomadd) {
8302 vty_out(vty, "Malformed community-list value\n");
8303 if (ecom)
8304 ecommunity_free(&ecom);
8305 return CMD_WARNING_CONFIG_FAILED;
8306 }
ddb5b488 8307
b9c7bc5a
PZ
8308 if (ecom) {
8309 ecommunity_merge(ecom, ecomadd);
8310 ecommunity_free(&ecomadd);
8311 } else {
8312 ecom = ecomadd;
8313 }
8314 }
8315
8316 if (*list) {
8317 ecommunity_free(&*list);
ddb5b488 8318 }
b9c7bc5a
PZ
8319 *list = ecom;
8320
8321 return CMD_SUCCESS;
ddb5b488
PZ
8322}
8323
0ca70ba5
DS
8324/*
8325 * v2vimport is true if we are handling a `import vrf ...` command
8326 */
8327static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8328{
0ca70ba5
DS
8329 afi_t afi;
8330
ddb5b488 8331 switch (vty->node) {
b9c7bc5a 8332 case BGP_IPV4_NODE:
0ca70ba5
DS
8333 afi = AFI_IP;
8334 break;
b9c7bc5a 8335 case BGP_IPV6_NODE:
0ca70ba5
DS
8336 afi = AFI_IP6;
8337 break;
ddb5b488
PZ
8338 default:
8339 vty_out(vty,
b9c7bc5a 8340 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 8341 return AFI_MAX;
ddb5b488 8342 }
69b07479 8343
0ca70ba5
DS
8344 if (!v2vimport) {
8345 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8346 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8347 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8348 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8349 vty_out(vty,
8350 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8351 return AFI_MAX;
8352 }
8353 } else {
8354 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8355 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8356 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8357 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8358 vty_out(vty,
8359 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8360 return AFI_MAX;
8361 }
8362 }
8363 return afi;
ddb5b488
PZ
8364}
8365
585f1adc
IR
8366DEFPY (af_rd_vpn_export,
8367 af_rd_vpn_export_cmd,
8368 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8369 NO_STR
8370 "Specify route distinguisher\n"
8371 "Between current address-family and vpn\n"
8372 "For routes leaked from current address-family to vpn\n"
8373 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 8374{
585f1adc
IR
8375 VTY_DECLVAR_CONTEXT(bgp, bgp);
8376 struct prefix_rd prd;
8377 int ret;
ddb5b488 8378 afi_t afi;
b9c7bc5a 8379 int idx = 0;
585f1adc 8380 bool yes = true;
b9c7bc5a 8381
585f1adc
IR
8382 if (argv_find(argv, argc, "no", &idx))
8383 yes = false;
ddb5b488 8384
585f1adc
IR
8385 if (yes) {
8386 ret = str2prefix_rd(rd_str, &prd);
8387 if (!ret) {
8388 vty_out(vty, "%% Malformed rd\n");
8389 return CMD_WARNING_CONFIG_FAILED;
8390 }
8391 }
ddb5b488 8392
585f1adc
IR
8393 afi = vpn_policy_getafi(vty, bgp, false);
8394 if (afi == AFI_MAX)
8395 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8396
585f1adc
IR
8397 /*
8398 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8399 */
8400 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8401 bgp_get_default(), bgp);
ddb5b488 8402
585f1adc
IR
8403 if (yes) {
8404 bgp->vpn_policy[afi].tovpn_rd = prd;
8405 SET_FLAG(bgp->vpn_policy[afi].flags,
8406 BGP_VPN_POLICY_TOVPN_RD_SET);
8407 } else {
8408 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8409 BGP_VPN_POLICY_TOVPN_RD_SET);
8410 }
69b07479 8411
585f1adc
IR
8412 /* post-change: re-export vpn routes */
8413 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8414 bgp_get_default(), bgp);
8415
8416 return CMD_SUCCESS;
ddb5b488
PZ
8417}
8418
b9c7bc5a
PZ
8419ALIAS (af_rd_vpn_export,
8420 af_no_rd_vpn_export_cmd,
8421 "no rd vpn export",
ddb5b488 8422 NO_STR
b9c7bc5a
PZ
8423 "Specify route distinguisher\n"
8424 "Between current address-family and vpn\n"
8425 "For routes leaked from current address-family to vpn\n")
ddb5b488 8426
b9c7bc5a
PZ
8427DEFPY (af_label_vpn_export,
8428 af_label_vpn_export_cmd,
e70e9f8e 8429 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 8430 NO_STR
ddb5b488 8431 "label value for VRF\n"
b9c7bc5a
PZ
8432 "Between current address-family and vpn\n"
8433 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
8434 "Label Value <0-1048575>\n"
8435 "Automatically assign a label\n")
ddb5b488
PZ
8436{
8437 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8438 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 8439 afi_t afi;
b9c7bc5a 8440 int idx = 0;
c6423c31 8441 bool yes = true;
b9c7bc5a
PZ
8442
8443 if (argv_find(argv, argc, "no", &idx))
c6423c31 8444 yes = false;
ddb5b488 8445
21a16cc2
PZ
8446 /* If "no ...", squash trailing parameter */
8447 if (!yes)
8448 label_auto = NULL;
8449
e70e9f8e
PZ
8450 if (yes) {
8451 if (!label_auto)
8452 label = label_val; /* parser should force unsigned */
8453 }
ddb5b488 8454
0ca70ba5 8455 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8456 if (afi == AFI_MAX)
8457 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 8458
e70e9f8e 8459
69b07479
DS
8460 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8461 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8462 /* no change */
8463 return CMD_SUCCESS;
e70e9f8e 8464
69b07479
DS
8465 /*
8466 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8467 */
8468 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8469 bgp_get_default(), bgp);
8470
8471 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8472 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8473
8474 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8475
8476 /*
8477 * label has previously been automatically
8478 * assigned by labelpool: release it
8479 *
8480 * NB if tovpn_label == MPLS_LABEL_NONE it
8481 * means the automatic assignment is in flight
8482 * and therefore the labelpool callback must
8483 * detect that the auto label is not needed.
8484 */
8485
8486 bgp_lp_release(LP_TYPE_VRF,
8487 &bgp->vpn_policy[afi],
8488 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 8489 }
69b07479
DS
8490 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8491 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8492 }
ddb5b488 8493
69b07479
DS
8494 bgp->vpn_policy[afi].tovpn_label = label;
8495 if (label_auto) {
8496 SET_FLAG(bgp->vpn_policy[afi].flags,
8497 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8498 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8499 vpn_leak_label_callback);
ddb5b488
PZ
8500 }
8501
69b07479
DS
8502 /* post-change: re-export vpn routes */
8503 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8504 bgp_get_default(), bgp);
8505
0d020cd6 8506 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
8507 return CMD_SUCCESS;
8508}
8509
b72c9e14
HS
8510DEFPY (af_sid_vpn_export,
8511 af_sid_vpn_export_cmd,
8512 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8513 NO_STR
8514 "sid value for VRF\n"
8515 "Between current address-family and vpn\n"
8516 "For routes leaked from current address-family to vpn\n"
8517 "Sid allocation index\n"
8518 "Automatically assign a label\n")
8519{
8520 VTY_DECLVAR_CONTEXT(bgp, bgp);
8521 afi_t afi;
8522 int debug = 0;
8523 int idx = 0;
8524 bool yes = true;
8525
8526 if (argv_find(argv, argc, "no", &idx))
8527 yes = false;
8528 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8529 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8530
8531 afi = vpn_policy_getafi(vty, bgp, false);
8532 if (afi == AFI_MAX)
8533 return CMD_WARNING_CONFIG_FAILED;
8534
8535 if (!yes) {
8536 /* implement me */
8537 vty_out(vty, "It's not implemented");
8538 return CMD_WARNING_CONFIG_FAILED;
8539 }
8540
8541 /* skip when it's already configured */
8542 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8543 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8544 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8545 return CMD_SUCCESS;
8546
7de4c885
HS
8547 /*
8548 * mode change between sid_idx and sid_auto isn't supported.
8549 * user must negate sid vpn export when they want to change the mode
8550 */
b72c9e14
HS
8551 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8552 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8553 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8554 vty_out(vty, "it's already configured as %s.\n",
8555 sid_auto ? "auto-mode" : "idx-mode");
8556 return CMD_WARNING_CONFIG_FAILED;
8557 }
8558
8559 /* pre-change */
8560 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8561 bgp_get_default(), bgp);
8562
8563 if (sid_auto) {
8564 /* SID allocation auto-mode */
8565 if (debug)
8566 zlog_debug("%s: auto sid alloc.", __func__);
8567 SET_FLAG(bgp->vpn_policy[afi].flags,
8568 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8569 } else {
8570 /* SID allocation index-mode */
8571 if (debug)
8572 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8573 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8574 }
8575
8576 /* post-change */
8577 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8578 bgp_get_default(), bgp);
8579 return CMD_SUCCESS;
8580}
8581
b9c7bc5a
PZ
8582ALIAS (af_label_vpn_export,
8583 af_no_label_vpn_export_cmd,
8584 "no label vpn export",
8585 NO_STR
8586 "label value for VRF\n"
8587 "Between current address-family and vpn\n"
8588 "For routes leaked from current address-family to vpn\n")
ddb5b488 8589
585f1adc 8590DEFPY (af_nexthop_vpn_export,
b9c7bc5a 8591 af_nexthop_vpn_export_cmd,
8c85ca28 8592 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 8593 NO_STR
ddb5b488 8594 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
8595 "Between current address-family and vpn\n"
8596 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8597 "IPv4 prefix\n"
8598 "IPv6 prefix\n")
8599{
585f1adc 8600 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 8601 afi_t afi;
ddb5b488
PZ
8602 struct prefix p;
8603
8c85ca28
QY
8604 if (!no) {
8605 if (!nexthop_su) {
8606 vty_out(vty, "%% Nexthop required\n");
8607 return CMD_WARNING_CONFIG_FAILED;
8608 }
8c85ca28 8609 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
8610 return CMD_WARNING_CONFIG_FAILED;
8611 }
ddb5b488 8612
585f1adc
IR
8613 afi = vpn_policy_getafi(vty, bgp, false);
8614 if (afi == AFI_MAX)
8615 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8616
585f1adc
IR
8617 /*
8618 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8619 */
8620 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8621 bgp_get_default(), bgp);
ddb5b488 8622
585f1adc
IR
8623 if (!no) {
8624 bgp->vpn_policy[afi].tovpn_nexthop = p;
8625 SET_FLAG(bgp->vpn_policy[afi].flags,
8626 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8627 } else {
8628 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8629 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8630 }
69b07479 8631
585f1adc
IR
8632 /* post-change: re-export vpn routes */
8633 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8634 bgp_get_default(), bgp);
37a87b8f 8635
585f1adc 8636 return CMD_SUCCESS;
ddb5b488
PZ
8637}
8638
b9c7bc5a 8639static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 8640{
b9c7bc5a
PZ
8641 if (!strcmp(dstr, "import")) {
8642 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8643 } else if (!strcmp(dstr, "export")) {
8644 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8645 } else if (!strcmp(dstr, "both")) {
8646 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8647 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8648 } else {
8649 vty_out(vty, "%% direction parse error\n");
8650 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8651 }
ddb5b488
PZ
8652 return CMD_SUCCESS;
8653}
8654
b9c7bc5a
PZ
8655DEFPY (af_rt_vpn_imexport,
8656 af_rt_vpn_imexport_cmd,
8657 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8658 NO_STR
8659 "Specify route target list\n"
ddb5b488 8660 "Specify route target list\n"
b9c7bc5a
PZ
8661 "Between current address-family and vpn\n"
8662 "For routes leaked from vpn to current address-family: match any\n"
8663 "For routes leaked from current address-family to vpn: set\n"
8664 "both import: match any and export: set\n"
ddb5b488
PZ
8665 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8666{
8667 VTY_DECLVAR_CONTEXT(bgp, bgp);
8668 int ret;
8669 struct ecommunity *ecom = NULL;
8670 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
8671 vpn_policy_direction_t dir;
8672 afi_t afi;
8673 int idx = 0;
c6423c31 8674 bool yes = true;
ddb5b488 8675
b9c7bc5a 8676 if (argv_find(argv, argc, "no", &idx))
c6423c31 8677 yes = false;
b9c7bc5a 8678
0ca70ba5 8679 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8680 if (afi == AFI_MAX)
8681 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8682
b9c7bc5a 8683 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
8684 if (ret != CMD_SUCCESS)
8685 return ret;
8686
b9c7bc5a
PZ
8687 if (yes) {
8688 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8689 vty_out(vty, "%% Missing RTLIST\n");
8690 return CMD_WARNING_CONFIG_FAILED;
8691 }
c6423c31 8692 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
8693 if (ret != CMD_SUCCESS) {
8694 return ret;
8695 }
ddb5b488
PZ
8696 }
8697
69b07479
DS
8698 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8699 if (!dodir[dir])
ddb5b488 8700 continue;
ddb5b488 8701
69b07479 8702 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8703
69b07479
DS
8704 if (yes) {
8705 if (bgp->vpn_policy[afi].rtlist[dir])
8706 ecommunity_free(
8707 &bgp->vpn_policy[afi].rtlist[dir]);
8708 bgp->vpn_policy[afi].rtlist[dir] =
8709 ecommunity_dup(ecom);
8710 } else {
8711 if (bgp->vpn_policy[afi].rtlist[dir])
8712 ecommunity_free(
8713 &bgp->vpn_policy[afi].rtlist[dir]);
8714 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 8715 }
69b07479
DS
8716
8717 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8718 }
69b07479 8719
d555f3e9
PZ
8720 if (ecom)
8721 ecommunity_free(&ecom);
ddb5b488
PZ
8722
8723 return CMD_SUCCESS;
8724}
8725
b9c7bc5a
PZ
8726ALIAS (af_rt_vpn_imexport,
8727 af_no_rt_vpn_imexport_cmd,
8728 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
8729 NO_STR
8730 "Specify route target list\n"
b9c7bc5a
PZ
8731 "Specify route target list\n"
8732 "Between current address-family and vpn\n"
8733 "For routes leaked from vpn to current address-family\n"
8734 "For routes leaked from current address-family to vpn\n"
8735 "both import and export\n")
8736
585f1adc 8737DEFPY (af_route_map_vpn_imexport,
b9c7bc5a
PZ
8738 af_route_map_vpn_imexport_cmd,
8739/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8740 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8741 NO_STR
ddb5b488 8742 "Specify route map\n"
b9c7bc5a
PZ
8743 "Between current address-family and vpn\n"
8744 "For routes leaked from vpn to current address-family\n"
8745 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8746 "name of route-map\n")
8747{
585f1adc
IR
8748 VTY_DECLVAR_CONTEXT(bgp, bgp);
8749 int ret;
8750 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8751 vpn_policy_direction_t dir;
ddb5b488 8752 afi_t afi;
ddb5b488 8753 int idx = 0;
585f1adc 8754 bool yes = true;
ddb5b488 8755
585f1adc
IR
8756 if (argv_find(argv, argc, "no", &idx))
8757 yes = false;
ddb5b488 8758
585f1adc
IR
8759 afi = vpn_policy_getafi(vty, bgp, false);
8760 if (afi == AFI_MAX)
8761 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8762
585f1adc
IR
8763 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8764 if (ret != CMD_SUCCESS)
8765 return ret;
ddb5b488 8766
585f1adc
IR
8767 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8768 if (!dodir[dir])
8769 continue;
69b07479 8770
585f1adc
IR
8771 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8772
8773 if (yes) {
8774 if (bgp->vpn_policy[afi].rmap_name[dir])
8775 XFREE(MTYPE_ROUTE_MAP_NAME,
8776 bgp->vpn_policy[afi].rmap_name[dir]);
8777 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
8778 MTYPE_ROUTE_MAP_NAME, rmap_str);
8779 bgp->vpn_policy[afi].rmap[dir] =
8780 route_map_lookup_warn_noexist(vty, rmap_str);
8781 if (!bgp->vpn_policy[afi].rmap[dir])
8782 return CMD_SUCCESS;
8783 } else {
8784 if (bgp->vpn_policy[afi].rmap_name[dir])
8785 XFREE(MTYPE_ROUTE_MAP_NAME,
8786 bgp->vpn_policy[afi].rmap_name[dir]);
8787 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8788 bgp->vpn_policy[afi].rmap[dir] = NULL;
8789 }
8790
8791 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8792 }
ddb5b488 8793
585f1adc 8794 return CMD_SUCCESS;
ddb5b488
PZ
8795}
8796
b9c7bc5a
PZ
8797ALIAS (af_route_map_vpn_imexport,
8798 af_no_route_map_vpn_imexport_cmd,
8799 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
8800 NO_STR
8801 "Specify route map\n"
b9c7bc5a
PZ
8802 "Between current address-family and vpn\n"
8803 "For routes leaked from vpn to current address-family\n"
8804 "For routes leaked from current address-family to vpn\n")
8805
bb4f6190 8806DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 8807 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
8808 "Import routes from another VRF\n"
8809 "Vrf routes being filtered\n"
8810 "Specify route map\n"
8811 "name of route-map\n")
8812{
8813 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
8814 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8815 afi_t afi;
bb4f6190
DS
8816 struct bgp *bgp_default;
8817
0ca70ba5 8818 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
8819 if (afi == AFI_MAX)
8820 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
8821
8822 bgp_default = bgp_get_default();
8823 if (!bgp_default) {
8824 int32_t ret;
8825 as_t as = bgp->as;
8826
8827 /* Auto-create assuming the same AS */
5d5393b9
DL
8828 ret = bgp_get_vty(&bgp_default, &as, NULL,
8829 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
8830
8831 if (ret) {
8832 vty_out(vty,
8833 "VRF default is not configured as a bgp instance\n");
8834 return CMD_WARNING;
8835 }
8836 }
8837
69b07479 8838 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 8839
ae6a6fb4
DS
8840 if (bgp->vpn_policy[afi].rmap_name[dir])
8841 XFREE(MTYPE_ROUTE_MAP_NAME,
8842 bgp->vpn_policy[afi].rmap_name[dir]);
8843 bgp->vpn_policy[afi].rmap_name[dir] =
8844 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8845 bgp->vpn_policy[afi].rmap[dir] =
8846 route_map_lookup_warn_noexist(vty, rmap_str);
8847 if (!bgp->vpn_policy[afi].rmap[dir])
8848 return CMD_SUCCESS;
8849
8850 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8851 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 8852
69b07479
DS
8853 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8854
bb4f6190
DS
8855 return CMD_SUCCESS;
8856}
8857
ae6a6fb4
DS
8858DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
8859 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
8860 NO_STR
8861 "Import routes from another VRF\n"
8862 "Vrf routes being filtered\n"
ae6a6fb4
DS
8863 "Specify route map\n"
8864 "name of route-map\n")
8865{
8866 VTY_DECLVAR_CONTEXT(bgp, bgp);
8867 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8868 afi_t afi;
8869
8870 afi = vpn_policy_getafi(vty, bgp, true);
8871 if (afi == AFI_MAX)
8872 return CMD_WARNING_CONFIG_FAILED;
8873
8874 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8875
8876 if (bgp->vpn_policy[afi].rmap_name[dir])
8877 XFREE(MTYPE_ROUTE_MAP_NAME,
8878 bgp->vpn_policy[afi].rmap_name[dir]);
8879 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8880 bgp->vpn_policy[afi].rmap[dir] = NULL;
8881
8882 if (bgp->vpn_policy[afi].import_vrf->count == 0)
8883 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8884 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8885
8886 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8887
8888 return CMD_SUCCESS;
8889}
bb4f6190 8890
585f1adc
IR
8891DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
8892 "[no] import vrf VIEWVRFNAME$import_name",
8893 NO_STR
8894 "Import routes from another VRF\n"
8895 "VRF to import from\n"
8896 "The name of the VRF\n")
12a844a5 8897{
585f1adc
IR
8898 VTY_DECLVAR_CONTEXT(bgp, bgp);
8899 struct listnode *node;
8900 struct bgp *vrf_bgp, *bgp_default;
8901 int32_t ret = 0;
8902 as_t as = bgp->as;
8903 bool remove = false;
8904 int32_t idx = 0;
8905 char *vname;
8906 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
8907 safi_t safi;
8908 afi_t afi;
8909
867f0cca 8910 if (import_name == NULL) {
8911 vty_out(vty, "%% Missing import name\n");
8912 return CMD_WARNING;
8913 }
8914
ae6a6fb4
DS
8915 if (strcmp(import_name, "route-map") == 0) {
8916 vty_out(vty, "%% Must include route-map name\n");
8917 return CMD_WARNING;
8918 }
8919
585f1adc
IR
8920 if (argv_find(argv, argc, "no", &idx))
8921 remove = true;
8922
8923 afi = vpn_policy_getafi(vty, bgp, true);
8924 if (afi == AFI_MAX)
8925 return CMD_WARNING_CONFIG_FAILED;
8926
12a844a5
DS
8927 safi = bgp_node_safi(vty);
8928
585f1adc
IR
8929 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
8930 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
8931 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
8932 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
8933 remove ? "unimport" : "import", import_name);
8934 return CMD_WARNING;
8935 }
25679caa 8936
585f1adc
IR
8937 bgp_default = bgp_get_default();
8938 if (!bgp_default) {
8939 /* Auto-create assuming the same AS */
8940 ret = bgp_get_vty(&bgp_default, &as, NULL,
8941 BGP_INSTANCE_TYPE_DEFAULT);
12a844a5 8942
585f1adc
IR
8943 if (ret) {
8944 vty_out(vty,
8945 "VRF default is not configured as a bgp instance\n");
8946 return CMD_WARNING;
8947 }
8948 }
12a844a5 8949
585f1adc
IR
8950 vrf_bgp = bgp_lookup_by_name(import_name);
8951 if (!vrf_bgp) {
8952 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
8953 vrf_bgp = bgp_default;
8954 else
8955 /* Auto-create assuming the same AS */
8956 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
8957
8958 if (ret) {
8959 vty_out(vty,
8960 "VRF %s is not configured as a bgp instance\n",
8961 import_name);
8962 return CMD_WARNING;
8963 }
8964 }
8965
8966 if (remove) {
8967 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
8968 } else {
8969 /* Already importing from "import_vrf"? */
8970 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
8971 vname)) {
8972 if (strcmp(vname, import_name) == 0)
8973 return CMD_WARNING;
8974 }
8975
8976 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
8977 }
8978
8979 return CMD_SUCCESS;
12a844a5
DS
8980}
8981
b9c7bc5a 8982/* This command is valid only in a bgp vrf instance or the default instance */
585f1adc 8983DEFPY (bgp_imexport_vpn,
b9c7bc5a
PZ
8984 bgp_imexport_vpn_cmd,
8985 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
8986 NO_STR
8987 "Import routes to this address-family\n"
8988 "Export routes from this address-family\n"
8989 "to/from default instance VPN RIB\n")
ddb5b488 8990{
585f1adc
IR
8991 VTY_DECLVAR_CONTEXT(bgp, bgp);
8992 int previous_state;
37a87b8f 8993 afi_t afi;
585f1adc
IR
8994 safi_t safi;
8995 int idx = 0;
8996 bool yes = true;
8997 int flag;
8998 vpn_policy_direction_t dir;
8999
9000 if (argv_find(argv, argc, "no", &idx))
9001 yes = false;
9002
9003 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9004 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9005
9006 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9007 return CMD_WARNING_CONFIG_FAILED;
9008 }
ddb5b488 9009
b9c7bc5a
PZ
9010 afi = bgp_node_afi(vty);
9011 safi = bgp_node_safi(vty);
585f1adc
IR
9012 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9013 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9014 return CMD_WARNING_CONFIG_FAILED;
9015 }
ddb5b488 9016
b9c7bc5a 9017 if (!strcmp(direction_str, "import")) {
585f1adc
IR
9018 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9019 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b9c7bc5a 9020 } else if (!strcmp(direction_str, "export")) {
585f1adc
IR
9021 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9022 dir = BGP_VPN_POLICY_DIR_TOVPN;
b9c7bc5a
PZ
9023 } else {
9024 vty_out(vty, "%% unknown direction %s\n", direction_str);
9025 return CMD_WARNING_CONFIG_FAILED;
9026 }
9027
585f1adc 9028 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 9029
585f1adc
IR
9030 if (yes) {
9031 SET_FLAG(bgp->af_flags[afi][safi], flag);
9032 if (!previous_state) {
9033 /* trigger export current vrf */
9034 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9035 }
9036 } else {
9037 if (previous_state) {
9038 /* trigger un-export current vrf */
9039 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9040 }
9041 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9042 }
37a87b8f 9043
1ca2fd11
IR
9044 hook_call(bgp_snmp_init_stats, bgp);
9045
585f1adc 9046 return CMD_SUCCESS;
ddb5b488
PZ
9047}
9048
301ad80a
PG
9049DEFPY (af_routetarget_import,
9050 af_routetarget_import_cmd,
9a659715 9051 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9052 NO_STR
9053 "Specify route target list\n"
9054 "Specify route target list\n"
9a659715
PG
9055 "Specify route target list\n"
9056 "Specify route target list\n"
301ad80a
PG
9057 "Flow-spec redirect type route target\n"
9058 "Import routes to this address-family\n"
9a659715 9059 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9060{
9061 VTY_DECLVAR_CONTEXT(bgp, bgp);
9062 int ret;
9063 struct ecommunity *ecom = NULL;
301ad80a 9064 afi_t afi;
9a659715 9065 int idx = 0, idx_unused = 0;
c6423c31
PG
9066 bool yes = true;
9067 bool rt6 = false;
301ad80a
PG
9068
9069 if (argv_find(argv, argc, "no", &idx))
c6423c31 9070 yes = false;
301ad80a 9071
9a659715
PG
9072 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9073 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9074 rt6 = true;
301ad80a 9075
0ca70ba5 9076 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9077 if (afi == AFI_MAX)
9078 return CMD_WARNING_CONFIG_FAILED;
9079
9a659715
PG
9080 if (rt6 && afi != AFI_IP6)
9081 return CMD_WARNING_CONFIG_FAILED;
9082
301ad80a
PG
9083 if (yes) {
9084 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9085 vty_out(vty, "%% Missing RTLIST\n");
9086 return CMD_WARNING_CONFIG_FAILED;
9087 }
9a659715 9088 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9089 if (ret != CMD_SUCCESS)
9090 return ret;
9091 }
69b07479
DS
9092
9093 if (yes) {
9094 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9095 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9096 .import_redirect_rtlist);
69b07479
DS
9097 bgp->vpn_policy[afi].import_redirect_rtlist =
9098 ecommunity_dup(ecom);
9099 } else {
9100 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9101 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9102 .import_redirect_rtlist);
69b07479 9103 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9104 }
69b07479 9105
301ad80a
PG
9106 if (ecom)
9107 ecommunity_free(&ecom);
9108
9109 return CMD_SUCCESS;
9110}
9111
505e5056 9112DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9113 address_family_ipv4_safi_cmd,
9114 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9115 "Enter Address Family command mode\n"
9116 "Address Family\n"
9117 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9118{
f51bae9c 9119
d62a17ae 9120 if (argc == 3) {
585f1adc
IR
9121 VTY_DECLVAR_CONTEXT(bgp, bgp);
9122 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9123 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9124 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9125 && safi != SAFI_EVPN) {
31947174
MK
9126 vty_out(vty,
9127 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9128 return CMD_WARNING_CONFIG_FAILED;
9129 }
585f1adc
IR
9130 vty->node = bgp_node_type(AFI_IP, safi);
9131 } else
9132 vty->node = BGP_IPV4_NODE;
718e3744 9133
d62a17ae 9134 return CMD_SUCCESS;
718e3744 9135}
9136
505e5056 9137DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9138 address_family_ipv6_safi_cmd,
9139 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9140 "Enter Address Family command mode\n"
9141 "Address Family\n"
9142 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9143{
d62a17ae 9144 if (argc == 3) {
585f1adc
IR
9145 VTY_DECLVAR_CONTEXT(bgp, bgp);
9146 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9147 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9148 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9149 && safi != SAFI_EVPN) {
31947174
MK
9150 vty_out(vty,
9151 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9152 return CMD_WARNING_CONFIG_FAILED;
9153 }
585f1adc
IR
9154 vty->node = bgp_node_type(AFI_IP6, safi);
9155 } else
9156 vty->node = BGP_IPV6_NODE;
25ffbdc1 9157
d62a17ae 9158 return CMD_SUCCESS;
25ffbdc1 9159}
718e3744 9160
d6902373 9161#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9162DEFUN_NOSH (address_family_vpnv4,
718e3744 9163 address_family_vpnv4_cmd,
8334fd5a 9164 "address-family vpnv4 [unicast]",
718e3744 9165 "Enter Address Family command mode\n"
8c3deaae 9166 "Address Family\n"
3a2d747c 9167 "Address Family modifier\n")
718e3744 9168{
d62a17ae 9169 vty->node = BGP_VPNV4_NODE;
9170 return CMD_SUCCESS;
718e3744 9171}
9172
505e5056 9173DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9174 address_family_vpnv6_cmd,
8334fd5a 9175 "address-family vpnv6 [unicast]",
8ecd3266 9176 "Enter Address Family command mode\n"
8c3deaae 9177 "Address Family\n"
3a2d747c 9178 "Address Family modifier\n")
8ecd3266 9179{
d62a17ae 9180 vty->node = BGP_VPNV6_NODE;
9181 return CMD_SUCCESS;
8ecd3266 9182}
64e4a6c5 9183#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9184
505e5056 9185DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9186 address_family_evpn_cmd,
7111c1a0 9187 "address-family l2vpn evpn",
4e0b7b6d 9188 "Enter Address Family command mode\n"
7111c1a0
QY
9189 "Address Family\n"
9190 "Address Family modifier\n")
4e0b7b6d 9191{
2131d5cf 9192 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9193 vty->node = BGP_EVPN_NODE;
9194 return CMD_SUCCESS;
4e0b7b6d
PG
9195}
9196
bfaab44d
HS
9197DEFUN_NOSH (bgp_segment_routing_srv6,
9198 bgp_segment_routing_srv6_cmd,
9199 "segment-routing srv6",
9200 "Segment-Routing configuration\n"
9201 "Segment-Routing SRv6 configuration\n")
9202{
9203 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 9204 bgp->srv6_enabled = true;
bfaab44d
HS
9205 vty->node = BGP_SRV6_NODE;
9206 return CMD_SUCCESS;
9207}
9208
0249b8b6
HS
9209DEFUN (no_bgp_segment_routing_srv6,
9210 no_bgp_segment_routing_srv6_cmd,
9211 "no segment-routing srv6",
9212 NO_STR
9213 "Segment-Routing configuration\n"
9214 "Segment-Routing SRv6 configuration\n")
9215{
9216 VTY_DECLVAR_CONTEXT(bgp, bgp);
9217
9218 if (strlen(bgp->srv6_locator_name) > 0)
9219 if (bgp_srv6_locator_unset(bgp) < 0)
9220 return CMD_WARNING_CONFIG_FAILED;
9221
9222 bgp->srv6_enabled = false;
9223 return CMD_SUCCESS;
9224}
9225
a0281b2e
HS
9226DEFPY (bgp_srv6_locator,
9227 bgp_srv6_locator_cmd,
9228 "locator NAME$name",
9229 "Specify SRv6 locator\n"
9230 "Specify SRv6 locator\n")
9231{
9232 VTY_DECLVAR_CONTEXT(bgp, bgp);
7de4c885 9233 int ret;
a0281b2e
HS
9234
9235 if (strlen(bgp->srv6_locator_name) > 0
9236 && strcmp(name, bgp->srv6_locator_name) != 0) {
9237 vty_out(vty, "srv6 locator is already configured\n");
9238 return CMD_WARNING_CONFIG_FAILED;
7de4c885
HS
9239 }
9240
9241 snprintf(bgp->srv6_locator_name,
9242 sizeof(bgp->srv6_locator_name), "%s", name);
a0281b2e 9243
7de4c885 9244 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
a0281b2e
HS
9245 if (ret < 0)
9246 return CMD_WARNING_CONFIG_FAILED;
9247
9248 return CMD_SUCCESS;
9249}
9250
0249b8b6
HS
9251DEFPY (no_bgp_srv6_locator,
9252 no_bgp_srv6_locator_cmd,
9253 "no locator NAME$name",
9254 NO_STR
9255 "Specify SRv6 locator\n"
9256 "Specify SRv6 locator\n")
9257{
9258 VTY_DECLVAR_CONTEXT(bgp, bgp);
9259
9260 /* when locator isn't configured, do nothing */
9261 if (strlen(bgp->srv6_locator_name) < 1)
9262 return CMD_SUCCESS;
9263
9264 /* name validation */
9265 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9266 vty_out(vty, "%% No srv6 locator is configured\n");
9267 return CMD_WARNING_CONFIG_FAILED;
9268 }
9269
9270 /* unset locator */
9271 if (bgp_srv6_locator_unset(bgp) < 0)
9272 return CMD_WARNING_CONFIG_FAILED;
9273
9274 return CMD_SUCCESS;
9275}
9276
ea372e81
HS
9277DEFPY (show_bgp_srv6,
9278 show_bgp_srv6_cmd,
9279 "show bgp segment-routing srv6",
9280 SHOW_STR
9281 BGP_STR
9282 "BGP Segment Routing\n"
9283 "BGP Segment Routing SRv6\n")
9284{
9285 struct bgp *bgp;
9286 struct listnode *node;
9287 struct prefix_ipv6 *chunk;
9288 struct bgp_srv6_function *func;
9289 struct in6_addr *tovpn4_sid;
9290 struct in6_addr *tovpn6_sid;
9291 char buf[256];
9292 char buf_tovpn4_sid[256];
9293 char buf_tovpn6_sid[256];
9294
9295 bgp = bgp_get_default();
96db4340 9296 if (!bgp)
ea372e81
HS
9297 return CMD_SUCCESS;
9298
9299 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9300 vty_out(vty, "locator_chunks:\n");
9301 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9302 prefix2str(chunk, buf, sizeof(buf));
9303 vty_out(vty, "- %s\n", buf);
9304 }
9305
9306 vty_out(vty, "functions:\n");
9307 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9308 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9309 vty_out(vty, "- sid: %s\n", buf);
9310 vty_out(vty, " locator: %s\n", func->locator_name);
9311 }
9312
9313 vty_out(vty, "bgps:\n");
9314 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9315 vty_out(vty, "- name: %s\n",
9316 bgp->name ? bgp->name : "default");
9317
9318 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9319 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9320 if (tovpn4_sid)
9321 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9322 sizeof(buf_tovpn4_sid));
9323 if (tovpn6_sid)
9324 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9325 sizeof(buf_tovpn6_sid));
9326
9327 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9328 tovpn4_sid ? buf_tovpn4_sid : "none");
9329 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9330 tovpn6_sid ? buf_tovpn6_sid : "none");
9331 }
9332
9333 return CMD_SUCCESS;
9334}
9335
505e5056 9336DEFUN_NOSH (exit_address_family,
718e3744 9337 exit_address_family_cmd,
9338 "exit-address-family",
9339 "Exit from Address Family configuration mode\n")
9340{
d62a17ae 9341 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9342 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9343 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9344 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9345 || vty->node == BGP_EVPN_NODE
9346 || vty->node == BGP_FLOWSPECV4_NODE
9347 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9348 vty->node = BGP_NODE;
9349 return CMD_SUCCESS;
718e3744 9350}
6b0655a2 9351
8ad7271d 9352/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9353static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9354 const char *ip_str, afi_t afi, safi_t safi,
9355 struct prefix_rd *prd)
9356{
9357 int ret;
9358 struct prefix match;
9bcb3eef
DS
9359 struct bgp_dest *dest;
9360 struct bgp_dest *rm;
d62a17ae 9361 struct bgp *bgp;
9362 struct bgp_table *table;
9363 struct bgp_table *rib;
9364
9365 /* BGP structure lookup. */
9366 if (view_name) {
9367 bgp = bgp_lookup_by_name(view_name);
9368 if (bgp == NULL) {
9369 vty_out(vty, "%% Can't find BGP instance %s\n",
9370 view_name);
9371 return CMD_WARNING;
9372 }
9373 } else {
9374 bgp = bgp_get_default();
9375 if (bgp == NULL) {
9376 vty_out(vty, "%% No BGP process is configured\n");
9377 return CMD_WARNING;
9378 }
9379 }
9380
9381 /* Check IP address argument. */
9382 ret = str2prefix(ip_str, &match);
9383 if (!ret) {
9384 vty_out(vty, "%% address is malformed\n");
9385 return CMD_WARNING;
9386 }
9387
9388 match.family = afi2family(afi);
9389 rib = bgp->rib[afi][safi];
9390
9391 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9392 for (dest = bgp_table_top(rib); dest;
9393 dest = bgp_route_next(dest)) {
9394 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9395
9bcb3eef 9396 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9397 continue;
9398
9bcb3eef 9399 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9400 if (table == NULL)
9401 continue;
9402
4953391b
DA
9403 rm = bgp_node_match(table, &match);
9404 if (rm != NULL) {
b54892e0 9405 const struct prefix *rm_p =
9bcb3eef 9406 bgp_dest_get_prefix(rm);
b54892e0
DS
9407
9408 if (rm_p->prefixlen == match.prefixlen) {
9409 SET_FLAG(rm->flags,
9410 BGP_NODE_USER_CLEAR);
9411 bgp_process(bgp, rm, afi, safi);
d62a17ae 9412 }
9bcb3eef 9413 bgp_dest_unlock_node(rm);
d62a17ae 9414 }
9415 }
9416 } else {
4953391b
DA
9417 dest = bgp_node_match(rib, &match);
9418 if (dest != NULL) {
9bcb3eef 9419 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9420
9bcb3eef
DS
9421 if (dest_p->prefixlen == match.prefixlen) {
9422 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9423 bgp_process(bgp, dest, afi, safi);
d62a17ae 9424 }
9bcb3eef 9425 bgp_dest_unlock_node(dest);
d62a17ae 9426 }
9427 }
9428
9429 return CMD_SUCCESS;
8ad7271d
DS
9430}
9431
b09b5ae0 9432/* one clear bgp command to rule them all */
718e3744 9433DEFUN (clear_ip_bgp_all,
9434 clear_ip_bgp_all_cmd,
453c92f6 9435 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D$neighbor|X:X::X:X$neighbor|WORD$neighbor|(1-4294967295)|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out>]",
718e3744 9436 CLEAR_STR
9437 IP_STR
9438 BGP_STR
838758ac 9439 BGP_INSTANCE_HELP_STR
510afcd6 9440 BGP_AFI_HELP_STR
fd5e7b70 9441 "Address Family\n"
510afcd6 9442 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 9443 "Address Family modifier\n"
b09b5ae0 9444 "Clear all peers\n"
453c92f6 9445 "BGP IPv4 neighbor to clear\n"
a80beece 9446 "BGP IPv6 neighbor to clear\n"
838758ac 9447 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9448 "Clear peers with the AS number\n"
9449 "Clear all external peers\n"
718e3744 9450 "Clear all members of peer-group\n"
b09b5ae0 9451 "BGP peer-group name\n"
b09b5ae0
DW
9452 BGP_SOFT_STR
9453 BGP_SOFT_IN_STR
b09b5ae0
DW
9454 BGP_SOFT_OUT_STR
9455 BGP_SOFT_IN_STR
9456 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 9457 BGP_SOFT_OUT_STR)
718e3744 9458{
d62a17ae 9459 char *vrf = NULL;
9460
dc912615
DS
9461 afi_t afi = AFI_UNSPEC;
9462 safi_t safi = SAFI_UNSPEC;
d62a17ae 9463 enum clear_sort clr_sort = clear_peer;
9464 enum bgp_clear_type clr_type;
9465 char *clr_arg = NULL;
9466
9467 int idx = 0;
9468
9469 /* clear [ip] bgp */
9470 if (argv_find(argv, argc, "ip", &idx))
9471 afi = AFI_IP;
9472
9a8bdf1c
PG
9473 /* [<vrf> VIEWVRFNAME] */
9474 if (argv_find(argv, argc, "vrf", &idx)) {
9475 vrf = argv[idx + 1]->arg;
9476 idx += 2;
9477 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9478 vrf = NULL;
9479 } else if (argv_find(argv, argc, "view", &idx)) {
9480 /* [<view> VIEWVRFNAME] */
d62a17ae 9481 vrf = argv[idx + 1]->arg;
9482 idx += 2;
9483 }
d62a17ae 9484 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9485 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9486 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9487
d7b9898c 9488 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 9489 if (argv_find(argv, argc, "*", &idx)) {
9490 clr_sort = clear_all;
9491 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9492 clr_sort = clear_peer;
9493 clr_arg = argv[idx]->arg;
9494 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9495 clr_sort = clear_peer;
9496 clr_arg = argv[idx]->arg;
9497 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9498 clr_sort = clear_group;
9499 idx++;
9500 clr_arg = argv[idx]->arg;
d7b9898c 9501 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 9502 clr_sort = clear_peer;
9503 clr_arg = argv[idx]->arg;
8fa7d444
DS
9504 } else if (argv_find(argv, argc, "WORD", &idx)) {
9505 clr_sort = clear_peer;
9506 clr_arg = argv[idx]->arg;
d62a17ae 9507 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9508 clr_sort = clear_as;
9509 clr_arg = argv[idx]->arg;
9510 } else if (argv_find(argv, argc, "external", &idx)) {
9511 clr_sort = clear_external;
9512 }
9513
9514 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
9515 if (argv_find(argv, argc, "soft", &idx)) {
9516 if (argv_find(argv, argc, "in", &idx)
9517 || argv_find(argv, argc, "out", &idx))
9518 clr_type = strmatch(argv[idx]->text, "in")
9519 ? BGP_CLEAR_SOFT_IN
9520 : BGP_CLEAR_SOFT_OUT;
9521 else
9522 clr_type = BGP_CLEAR_SOFT_BOTH;
9523 } else if (argv_find(argv, argc, "in", &idx)) {
9524 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9525 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9526 : BGP_CLEAR_SOFT_IN;
9527 } else if (argv_find(argv, argc, "out", &idx)) {
9528 clr_type = BGP_CLEAR_SOFT_OUT;
9529 } else
9530 clr_type = BGP_CLEAR_SOFT_NONE;
9531
1ca2fd11 9532 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 9533}
01080f7c 9534
8ad7271d
DS
9535DEFUN (clear_ip_bgp_prefix,
9536 clear_ip_bgp_prefix_cmd,
18c57037 9537 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
9538 CLEAR_STR
9539 IP_STR
9540 BGP_STR
838758ac 9541 BGP_INSTANCE_HELP_STR
8ad7271d 9542 "Clear bestpath and re-advertise\n"
0c7b1b01 9543 "IPv4 prefix\n")
8ad7271d 9544{
d62a17ae 9545 char *vrf = NULL;
9546 char *prefix = NULL;
8ad7271d 9547
d62a17ae 9548 int idx = 0;
01080f7c 9549
d62a17ae 9550 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
9551 if (argv_find(argv, argc, "vrf", &idx)) {
9552 vrf = argv[idx + 1]->arg;
9553 idx += 2;
9554 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9555 vrf = NULL;
9556 } else if (argv_find(argv, argc, "view", &idx)) {
9557 /* [<view> VIEWVRFNAME] */
9558 vrf = argv[idx + 1]->arg;
9559 idx += 2;
9560 }
0c7b1b01 9561
d62a17ae 9562 prefix = argv[argc - 1]->arg;
8ad7271d 9563
d62a17ae 9564 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 9565}
8ad7271d 9566
b09b5ae0
DW
9567DEFUN (clear_bgp_ipv6_safi_prefix,
9568 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 9569 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9570 CLEAR_STR
3a2d747c 9571 IP_STR
718e3744 9572 BGP_STR
8c3deaae 9573 "Address Family\n"
46f296b4 9574 BGP_SAFI_HELP_STR
b09b5ae0 9575 "Clear bestpath and re-advertise\n"
0c7b1b01 9576 "IPv6 prefix\n")
718e3744 9577{
9b475e76
PG
9578 int idx_safi = 0;
9579 int idx_ipv6_prefix = 0;
9580 safi_t safi = SAFI_UNICAST;
9581 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9582 argv[idx_ipv6_prefix]->arg : NULL;
9583
9584 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 9585 return bgp_clear_prefix(
9b475e76
PG
9586 vty, NULL, prefix, AFI_IP6,
9587 safi, NULL);
838758ac 9588}
01080f7c 9589
b09b5ae0
DW
9590DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9591 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 9592 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9593 CLEAR_STR
3a2d747c 9594 IP_STR
718e3744 9595 BGP_STR
838758ac 9596 BGP_INSTANCE_HELP_STR
8c3deaae 9597 "Address Family\n"
46f296b4 9598 BGP_SAFI_HELP_STR
b09b5ae0 9599 "Clear bestpath and re-advertise\n"
0c7b1b01 9600 "IPv6 prefix\n")
718e3744 9601{
9b475e76 9602 int idx_safi = 0;
9a8bdf1c 9603 int idx_vrfview = 0;
9b475e76
PG
9604 int idx_ipv6_prefix = 0;
9605 safi_t safi = SAFI_UNICAST;
9606 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9607 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 9608 char *vrfview = NULL;
9b475e76 9609
9a8bdf1c
PG
9610 /* [<view|vrf> VIEWVRFNAME] */
9611 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9612 vrfview = argv[idx_vrfview + 1]->arg;
9613 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9614 vrfview = NULL;
9615 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9616 /* [<view> VIEWVRFNAME] */
9617 vrfview = argv[idx_vrfview + 1]->arg;
9618 }
9b475e76
PG
9619 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9620
d62a17ae 9621 return bgp_clear_prefix(
9b475e76
PG
9622 vty, vrfview, prefix,
9623 AFI_IP6, safi, NULL);
718e3744 9624}
9625
b09b5ae0
DW
9626DEFUN (show_bgp_views,
9627 show_bgp_views_cmd,
d6e3c605 9628 "show [ip] bgp views",
b09b5ae0 9629 SHOW_STR
d6e3c605 9630 IP_STR
01080f7c 9631 BGP_STR
b09b5ae0 9632 "Show the defined BGP views\n")
01080f7c 9633{
d62a17ae 9634 struct list *inst = bm->bgp;
9635 struct listnode *node;
9636 struct bgp *bgp;
01080f7c 9637
d62a17ae 9638 vty_out(vty, "Defined BGP views:\n");
9639 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9640 /* Skip VRFs. */
9641 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9642 continue;
9643 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9644 bgp->as);
9645 }
e52702f2 9646
d62a17ae 9647 return CMD_SUCCESS;
e0081f70
ML
9648}
9649
8386ac43 9650DEFUN (show_bgp_vrfs,
9651 show_bgp_vrfs_cmd,
d6e3c605 9652 "show [ip] bgp vrfs [json]",
8386ac43 9653 SHOW_STR
d6e3c605 9654 IP_STR
8386ac43 9655 BGP_STR
9656 "Show BGP VRFs\n"
9973d184 9657 JSON_STR)
8386ac43 9658{
fe1dc5a3 9659 char buf[ETHER_ADDR_STRLEN];
d62a17ae 9660 struct list *inst = bm->bgp;
9661 struct listnode *node;
9662 struct bgp *bgp;
9f049418 9663 bool uj = use_json(argc, argv);
d62a17ae 9664 json_object *json = NULL;
9665 json_object *json_vrfs = NULL;
9666 int count = 0;
d62a17ae 9667
d62a17ae 9668 if (uj) {
9669 json = json_object_new_object();
9670 json_vrfs = json_object_new_object();
9671 }
9672
9673 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9674 const char *name, *type;
9675 struct peer *peer;
7fe96307 9676 struct listnode *node2, *nnode2;
d62a17ae 9677 int peers_cfg, peers_estb;
9678 json_object *json_vrf = NULL;
d62a17ae 9679
9680 /* Skip Views. */
9681 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9682 continue;
9683
9684 count++;
efb4077a 9685 if (!uj && count == 1) {
fe1dc5a3 9686 vty_out(vty,
efb4077a 9687 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 9688 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
9689 "#PeersEstb", "Name");
9690 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9691 "L3-VNI", "RouterMAC", "Interface");
9692 }
d62a17ae 9693
9694 peers_cfg = peers_estb = 0;
9695 if (uj)
9696 json_vrf = json_object_new_object();
9697
9698
7fe96307 9699 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 9700 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9701 continue;
9702 peers_cfg++;
feb17238 9703 if (peer_established(peer))
d62a17ae 9704 peers_estb++;
9705 }
9706
9707 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 9708 name = VRF_DEFAULT_NAME;
d62a17ae 9709 type = "DFLT";
9710 } else {
9711 name = bgp->name;
9712 type = "VRF";
9713 }
9714
a8bf7d9c 9715
d62a17ae 9716 if (uj) {
a4d82a8a
PZ
9717 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9718 ? -1
9719 : (int64_t)bgp->vrf_id;
23d0a753
DA
9720 char buf[BUFSIZ] = {0};
9721
d62a17ae 9722 json_object_string_add(json_vrf, "type", type);
9723 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
c949c771
DA
9724 json_object_string_addf(json_vrf, "routerId", "%pI4",
9725 &bgp->router_id);
d62a17ae 9726 json_object_int_add(json_vrf, "numConfiguredPeers",
9727 peers_cfg);
9728 json_object_int_add(json_vrf, "numEstablishedPeers",
9729 peers_estb);
9730
fe1dc5a3 9731 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
9732 json_object_string_add(
9733 json_vrf, "rmac",
9734 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
9735 json_object_string_add(json_vrf, "interface",
9736 ifindex2ifname(bgp->l3vni_svi_ifindex,
9737 bgp->vrf_id));
d62a17ae 9738 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 9739 } else {
23d0a753 9740 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
9741 type,
9742 bgp->vrf_id == VRF_UNKNOWN ? -1
9743 : (int)bgp->vrf_id,
23d0a753 9744 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
9745 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
9746 bgp->l3vni,
9747 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
9748 ifindex2ifname(bgp->l3vni_svi_ifindex,
9749 bgp->vrf_id));
9750 }
d62a17ae 9751 }
9752
9753 if (uj) {
9754 json_object_object_add(json, "vrfs", json_vrfs);
9755
9756 json_object_int_add(json, "totalVrfs", count);
9757
75eeda93 9758 vty_json(vty, json);
d62a17ae 9759 } else {
9760 if (count)
9761 vty_out(vty,
9762 "\nTotal number of VRFs (including default): %d\n",
9763 count);
9764 }
9765
9766 return CMD_SUCCESS;
8386ac43 9767}
9768
48ecf8f5
DS
9769DEFUN (show_bgp_mac_hash,
9770 show_bgp_mac_hash_cmd,
9771 "show bgp mac hash",
9772 SHOW_STR
9773 BGP_STR
9774 "Mac Address\n"
9775 "Mac Address database\n")
9776{
9777 bgp_mac_dump_table(vty);
9778
9779 return CMD_SUCCESS;
9780}
acf71666 9781
e3b78da8 9782static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 9783{
0291c246 9784 struct vty *vty = (struct vty *)args;
e3b78da8 9785 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 9786
23d0a753 9787 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
9788}
9789
9790static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
9791{
9792 vty_out(vty, "self nexthop database:\n");
af97a18b 9793 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
9794
9795 vty_out(vty, "Tunnel-ip database:\n");
9796 hash_iterate(bgp->tip_hash,
e3b78da8 9797 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
9798 vty);
9799}
9800
15c81ca4
DS
9801DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
9802 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
9803 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
9804 "martian next-hops\n"
9805 "martian next-hop database\n")
acf71666 9806{
0291c246 9807 struct bgp *bgp = NULL;
15c81ca4 9808 int idx = 0;
9a8bdf1c
PG
9809 char *name = NULL;
9810
9811 /* [<vrf> VIEWVRFNAME] */
9812 if (argv_find(argv, argc, "vrf", &idx)) {
9813 name = argv[idx + 1]->arg;
9814 if (name && strmatch(name, VRF_DEFAULT_NAME))
9815 name = NULL;
9816 } else if (argv_find(argv, argc, "view", &idx))
9817 /* [<view> VIEWVRFNAME] */
9818 name = argv[idx + 1]->arg;
9819 if (name)
9820 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
9821 else
9822 bgp = bgp_get_default();
acf71666 9823
acf71666
MK
9824 if (!bgp) {
9825 vty_out(vty, "%% No BGP process is configured\n");
9826 return CMD_WARNING;
9827 }
9828 bgp_show_martian_nexthops(vty, bgp);
9829
9830 return CMD_SUCCESS;
9831}
9832
f412b39a 9833DEFUN (show_bgp_memory,
4bf6a362 9834 show_bgp_memory_cmd,
7fa12b13 9835 "show [ip] bgp memory",
4bf6a362 9836 SHOW_STR
3a2d747c 9837 IP_STR
4bf6a362
PJ
9838 BGP_STR
9839 "Global BGP memory statistics\n")
9840{
d62a17ae 9841 char memstrbuf[MTYPE_MEMSTR_LEN];
9842 unsigned long count;
9843
9844 /* RIB related usage stats */
9845 count = mtype_stats_alloc(MTYPE_BGP_NODE);
9846 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
9847 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 9848 count * sizeof(struct bgp_dest)));
d62a17ae 9849
9850 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
9851 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
9852 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 9853 count * sizeof(struct bgp_path_info)));
d62a17ae 9854 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
9855 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
9856 count,
4b7e6066
DS
9857 mtype_memstr(
9858 memstrbuf, sizeof(memstrbuf),
9859 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 9860
9861 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
9862 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
9863 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9864 count * sizeof(struct bgp_static)));
9865
9866 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
9867 vty_out(vty, "%ld Packets, using %s of memory\n", count,
9868 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9869 count * sizeof(struct bpacket)));
9870
9871 /* Adj-In/Out */
9872 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
9873 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
9874 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9875 count * sizeof(struct bgp_adj_in)));
9876 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
9877 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
9878 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9879 count * sizeof(struct bgp_adj_out)));
9880
9881 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
9882 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
9883 count,
9884 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9885 count * sizeof(struct bgp_nexthop_cache)));
9886
9887 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
9888 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
9889 count,
9890 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9891 count * sizeof(struct bgp_damp_info)));
9892
9893 /* Attributes */
9894 count = attr_count();
9895 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
9896 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9897 count * sizeof(struct attr)));
9898
9899 if ((count = attr_unknown_count()))
9900 vty_out(vty, "%ld unknown attributes\n", count);
9901
9902 /* AS_PATH attributes */
9903 count = aspath_count();
9904 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
9905 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9906 count * sizeof(struct aspath)));
9907
9908 count = mtype_stats_alloc(MTYPE_AS_SEG);
9909 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
9910 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9911 count * sizeof(struct assegment)));
9912
9913 /* Other attributes */
9914 if ((count = community_count()))
9915 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9916 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9917 count * sizeof(struct community)));
d62a17ae 9918 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
9919 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9920 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9921 count * sizeof(struct ecommunity)));
d62a17ae 9922 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
9923 vty_out(vty,
9924 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
9925 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9926 count * sizeof(struct lcommunity)));
d62a17ae 9927
9928 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
9929 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
9930 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9931 count * sizeof(struct cluster_list)));
9932
9933 /* Peer related usage */
9934 count = mtype_stats_alloc(MTYPE_BGP_PEER);
9935 vty_out(vty, "%ld peers, using %s of memory\n", count,
9936 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9937 count * sizeof(struct peer)));
9938
9939 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
9940 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
9941 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9942 count * sizeof(struct peer_group)));
9943
9944 /* Other */
d62a17ae 9945 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
9946 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
9947 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9948 count * sizeof(regex_t)));
d62a17ae 9949 return CMD_SUCCESS;
4bf6a362 9950}
fee0f4c6 9951
57a9c8a8
DS
9952static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
9953{
9954 json_object *bestpath = json_object_new_object();
9955
892fedb6 9956 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
9957 json_object_string_add(bestpath, "asPath", "ignore");
9958
892fedb6 9959 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
9960 json_object_string_add(bestpath, "asPath", "confed");
9961
892fedb6
DA
9962 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
9963 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 9964 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9965 "as-set");
9966 else
a4d82a8a 9967 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9968 "true");
9969 } else
a4d82a8a 9970 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 9971
ee88563a
JM
9972 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
9973 json_object_boolean_true_add(bestpath, "peerTypeRelax");
9974
892fedb6 9975 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 9976 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
9977 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
9978 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
9979 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 9980 json_object_string_add(bestpath, "med", "confed");
892fedb6 9981 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
9982 json_object_string_add(bestpath, "med",
9983 "missing-as-worst");
9984 else
9985 json_object_string_add(bestpath, "med", "true");
9986 }
9987
9988 json_object_object_add(json, "bestPath", bestpath);
9989}
9990
3577f1c5
DD
9991/* Print the error code/subcode for why the peer is down */
9992static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
9993 json_object *json_peer, bool use_json)
9994{
9995 const char *code_str;
9996 const char *subcode_str;
9997
9998 if (use_json) {
9999 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10000 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10001 char errorcodesubcode_hexstr[5];
10002 char errorcodesubcode_str[256];
10003
10004 code_str = bgp_notify_code_str(peer->notify.code);
10005 subcode_str = bgp_notify_subcode_str(
10006 peer->notify.code,
10007 peer->notify.subcode);
10008
772270f3
QY
10009 snprintf(errorcodesubcode_hexstr,
10010 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10011 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10012 json_object_string_add(json_peer,
10013 "lastErrorCodeSubcode",
10014 errorcodesubcode_hexstr);
10015 snprintf(errorcodesubcode_str, 255, "%s%s",
10016 code_str, subcode_str);
10017 json_object_string_add(json_peer,
10018 "lastNotificationReason",
10019 errorcodesubcode_str);
10020 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10021 && peer->notify.code == BGP_NOTIFY_CEASE
10022 && (peer->notify.subcode
10023 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10024 || peer->notify.subcode
10025 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10026 && peer->notify.length) {
10027 char msgbuf[1024];
10028 const char *msg_str;
10029
10030 msg_str = bgp_notify_admin_message(
10031 msgbuf, sizeof(msgbuf),
10032 (uint8_t *)peer->notify.data,
10033 peer->notify.length);
10034 if (msg_str)
10035 json_object_string_add(
10036 json_peer,
10037 "lastShutdownDescription",
10038 msg_str);
10039 }
10040
c258527b 10041 }
3577f1c5
DD
10042 json_object_string_add(json_peer, "lastResetDueTo",
10043 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10044 json_object_int_add(json_peer, "lastResetCode",
10045 peer->last_reset);
3577f1c5
DD
10046 } else {
10047 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10048 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10049 code_str = bgp_notify_code_str(peer->notify.code);
10050 subcode_str =
10051 bgp_notify_subcode_str(peer->notify.code,
10052 peer->notify.subcode);
10053 vty_out(vty, " Notification %s (%s%s)\n",
10054 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10055 ? "sent"
10056 : "received",
10057 code_str, subcode_str);
10058 } else {
e91c24c8 10059 vty_out(vty, " %s\n",
3577f1c5
DD
10060 peer_down_str[(int)peer->last_reset]);
10061 }
10062 }
10063}
10064
10065static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10066 safi_t safi)
10067{
feb17238 10068 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
3577f1c5
DD
10069}
10070
10071static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10072 struct peer *peer, json_object *json_peer,
10073 int max_neighbor_width, bool use_json)
10074{
10075 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10076 int len;
10077
10078 if (use_json) {
10079 if (peer_dynamic_neighbor(peer))
10080 json_object_boolean_true_add(json_peer,
10081 "dynamicPeer");
10082 if (peer->hostname)
10083 json_object_string_add(json_peer, "hostname",
10084 peer->hostname);
10085
10086 if (peer->domainname)
10087 json_object_string_add(json_peer, "domainname",
10088 peer->domainname);
10089 json_object_int_add(json_peer, "connectionsEstablished",
10090 peer->established);
10091 json_object_int_add(json_peer, "connectionsDropped",
10092 peer->dropped);
10093 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10094 use_json, json_peer);
feb17238 10095 if (peer_established(peer))
3577f1c5
DD
10096 json_object_string_add(json_peer, "lastResetDueTo",
10097 "AFI/SAFI Not Negotiated");
10098 else
10099 bgp_show_peer_reset(NULL, peer, json_peer, true);
10100 } else {
10101 dn_flag[1] = '\0';
10102 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10103 if (peer->hostname
892fedb6 10104 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10105 len = vty_out(vty, "%s%s(%s)", dn_flag,
10106 peer->hostname, peer->host);
10107 else
10108 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10109
10110 /* pad the neighbor column with spaces */
10111 if (len < max_neighbor_width)
10112 vty_out(vty, "%*s", max_neighbor_width - len,
10113 " ");
e91c24c8 10114 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10115 peer->dropped,
10116 peer_uptime(peer->uptime, timebuf,
10117 BGP_UPTIME_LEN, 0, NULL));
feb17238 10118 if (peer_established(peer))
3577f1c5
DD
10119 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10120 else
10121 bgp_show_peer_reset(vty, peer, NULL,
10122 false);
10123 }
10124}
c258527b 10125
565e9ddd 10126/* Strip peer's description to the given size. */
cb75bb31
DA
10127static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10128{
10129 static char stripped[BUFSIZ];
cb75bb31
DA
10130 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10131
cb75bb31
DA
10132 strlcpy(stripped, desc, len + 1);
10133
10134 return stripped;
10135}
3577f1c5 10136
8c1d4cd5
LS
10137/* Determine whether var peer should be filtered out of the summary. */
10138static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10139 struct peer *fpeer, int as_type,
10140 as_t as)
10141{
10142
10143 /* filter neighbor XXXX */
10144 if (fpeer && fpeer != peer)
10145 return true;
10146
10147 /* filter remote-as (internal|external) */
10148 if (as_type != AS_UNSPECIFIED) {
10149 if (peer->as_type == AS_SPECIFIED) {
10150 if (as_type == AS_INTERNAL) {
10151 if (peer->as != peer->local_as)
10152 return true;
10153 } else if (peer->as == peer->local_as)
10154 return true;
10155 } else if (as_type != peer->as_type)
10156 return true;
10157 } else if (as && as != peer->as) /* filter remote-as XXX */
10158 return true;
10159
10160 return false;
10161}
10162
565e9ddd
DA
10163/* Show BGP peer's summary information.
10164 *
10165 * Peer's description is stripped according to if `wide` option is given
10166 * or not.
10167 *
10168 * When adding new columns to `show bgp summary` output, please make
10169 * sure `Desc` is the lastest column to show because it can contain
10170 * whitespaces and the whole output will be tricky.
10171 */
d62a17ae 10172static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 10173 struct peer *fpeer, int as_type, as_t as,
96c81f66 10174 uint16_t show_flags)
d62a17ae 10175{
10176 struct peer *peer;
10177 struct listnode *node, *nnode;
10178 unsigned int count = 0, dn_count = 0;
10179 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10180 char neighbor_buf[VTY_BUFSIZ];
10181 int neighbor_col_default_width = 16;
3577f1c5 10182 int len, failed_count = 0;
ce1944f0 10183 unsigned int filtered_count = 0;
d62a17ae 10184 int max_neighbor_width = 0;
10185 int pfx_rcd_safi;
3c13337d 10186 json_object *json = NULL;
d62a17ae 10187 json_object *json_peer = NULL;
10188 json_object *json_peers = NULL;
50e05855 10189 struct peer_af *paf;
d3ada366 10190 struct bgp_filter *filter;
85eeb029
DA
10191 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10192 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10193 bool show_established =
10194 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10195 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
96c81f66 10196 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
d62a17ae 10197
10198 /* labeled-unicast routes are installed in the unicast table so in order
10199 * to
10200 * display the correct PfxRcd value we must look at SAFI_UNICAST
10201 */
3577f1c5 10202
d62a17ae 10203 if (safi == SAFI_LABELED_UNICAST)
10204 pfx_rcd_safi = SAFI_UNICAST;
10205 else
10206 pfx_rcd_safi = safi;
10207
10208 if (use_json) {
3c13337d 10209 json = json_object_new_object();
d62a17ae 10210 json_peers = json_object_new_object();
3577f1c5 10211 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10212 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10213 as_type, as)) {
ce1944f0 10214 filtered_count++;
8c1d4cd5
LS
10215 count++;
10216 continue;
10217 }
10218
3577f1c5
DD
10219 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10220 continue;
10221
10222 if (peer->afc[afi][safi]) {
10223 /* See if we have at least a single failed peer */
10224 if (bgp_has_peer_failed(peer, afi, safi))
10225 failed_count++;
10226 count++;
10227 }
10228 if (peer_dynamic_neighbor(peer))
10229 dn_count++;
10230 }
c258527b 10231
d62a17ae 10232 } else {
10233 /* Loop over all neighbors that will be displayed to determine
10234 * how many
10235 * characters are needed for the Neighbor column
10236 */
10237 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10238 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10239 as_type, as)) {
ce1944f0 10240 filtered_count++;
8c1d4cd5
LS
10241 count++;
10242 continue;
10243 }
10244
d62a17ae 10245 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10246 continue;
10247
10248 if (peer->afc[afi][safi]) {
10249 memset(dn_flag, '\0', sizeof(dn_flag));
10250 if (peer_dynamic_neighbor(peer))
10251 dn_flag[0] = '*';
10252
10253 if (peer->hostname
892fedb6
DA
10254 && CHECK_FLAG(bgp->flags,
10255 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10256 snprintf(neighbor_buf,
10257 sizeof(neighbor_buf),
10258 "%s%s(%s) ", dn_flag,
10259 peer->hostname, peer->host);
d62a17ae 10260 else
772270f3
QY
10261 snprintf(neighbor_buf,
10262 sizeof(neighbor_buf), "%s%s ",
10263 dn_flag, peer->host);
d62a17ae 10264
10265 len = strlen(neighbor_buf);
10266
10267 if (len > max_neighbor_width)
10268 max_neighbor_width = len;
c258527b 10269
3577f1c5
DD
10270 /* See if we have at least a single failed peer */
10271 if (bgp_has_peer_failed(peer, afi, safi))
10272 failed_count++;
10273 count++;
d62a17ae 10274 }
10275 }
f933309e 10276
d62a17ae 10277 /* Originally we displayed the Neighbor column as 16
10278 * characters wide so make that the default
10279 */
10280 if (max_neighbor_width < neighbor_col_default_width)
10281 max_neighbor_width = neighbor_col_default_width;
10282 }
f933309e 10283
3577f1c5
DD
10284 if (show_failed && !failed_count) {
10285 if (use_json) {
10286 json_object_int_add(json, "failedPeersCount", 0);
10287 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10288 json_object_int_add(json, "totalPeers", count);
3577f1c5 10289
75eeda93 10290 vty_json(vty, json);
3577f1c5
DD
10291 } else {
10292 vty_out(vty, "%% No failed BGP neighbors found\n");
3577f1c5
DD
10293 }
10294 return CMD_SUCCESS;
10295 }
c258527b 10296
3577f1c5 10297 count = 0; /* Reset the value as its used again */
ce1944f0 10298 filtered_count = 0;
800867d8 10299 dn_count = 0;
d62a17ae 10300 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10301 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10302 continue;
10303
ea47320b
DL
10304 if (!peer->afc[afi][safi])
10305 continue;
d62a17ae 10306
ea47320b
DL
10307 if (!count) {
10308 unsigned long ents;
10309 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10310 int64_t vrf_id_ui;
d62a17ae 10311
a4d82a8a
PZ
10312 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10313 ? -1
10314 : (int64_t)bgp->vrf_id;
ea47320b
DL
10315
10316 /* Usage summary and header */
10317 if (use_json) {
c949c771
DA
10318 json_object_string_addf(json, "routerId",
10319 "%pI4",
10320 &bgp->router_id);
60466a63
QY
10321 json_object_int_add(json, "as", bgp->as);
10322 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10323 json_object_string_add(
10324 json, "vrfName",
10325 (bgp->inst_type
10326 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10327 ? VRF_DEFAULT_NAME
ea47320b
DL
10328 : bgp->name);
10329 } else {
10330 vty_out(vty,
23d0a753
DA
10331 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10332 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10333 bgp->vrf_id == VRF_UNKNOWN
10334 ? -1
10335 : (int)bgp->vrf_id);
ea47320b
DL
10336 vty_out(vty, "\n");
10337 }
d62a17ae 10338
ea47320b 10339 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10340 if (use_json) {
ea47320b 10341 json_object_int_add(
60466a63 10342 json, "updateDelayLimit",
ea47320b 10343 bgp->v_update_delay);
d62a17ae 10344
ea47320b
DL
10345 if (bgp->v_update_delay
10346 != bgp->v_establish_wait)
d62a17ae 10347 json_object_int_add(
10348 json,
ea47320b
DL
10349 "updateDelayEstablishWait",
10350 bgp->v_establish_wait);
d62a17ae 10351
60466a63 10352 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10353 json_object_string_add(
10354 json,
10355 "updateDelayFirstNeighbor",
10356 bgp->update_delay_begin_time);
10357 json_object_boolean_true_add(
10358 json,
10359 "updateDelayInProgress");
10360 } else {
10361 if (bgp->update_delay_over) {
d62a17ae 10362 json_object_string_add(
10363 json,
10364 "updateDelayFirstNeighbor",
10365 bgp->update_delay_begin_time);
ea47320b 10366 json_object_string_add(
d62a17ae 10367 json,
ea47320b
DL
10368 "updateDelayBestpathResumed",
10369 bgp->update_delay_end_time);
10370 json_object_string_add(
d62a17ae 10371 json,
ea47320b
DL
10372 "updateDelayZebraUpdateResume",
10373 bgp->update_delay_zebra_resume_time);
10374 json_object_string_add(
10375 json,
10376 "updateDelayPeerUpdateResume",
10377 bgp->update_delay_peers_resume_time);
d62a17ae 10378 }
ea47320b
DL
10379 }
10380 } else {
10381 vty_out(vty,
10382 "Read-only mode update-delay limit: %d seconds\n",
10383 bgp->v_update_delay);
10384 if (bgp->v_update_delay
10385 != bgp->v_establish_wait)
d62a17ae 10386 vty_out(vty,
ea47320b
DL
10387 " Establish wait: %d seconds\n",
10388 bgp->v_establish_wait);
d62a17ae 10389
60466a63 10390 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10391 vty_out(vty,
10392 " First neighbor established: %s\n",
10393 bgp->update_delay_begin_time);
10394 vty_out(vty,
10395 " Delay in progress\n");
10396 } else {
10397 if (bgp->update_delay_over) {
d62a17ae 10398 vty_out(vty,
10399 " First neighbor established: %s\n",
10400 bgp->update_delay_begin_time);
10401 vty_out(vty,
ea47320b
DL
10402 " Best-paths resumed: %s\n",
10403 bgp->update_delay_end_time);
10404 vty_out(vty,
10405 " zebra update resumed: %s\n",
10406 bgp->update_delay_zebra_resume_time);
10407 vty_out(vty,
10408 " peers update resumed: %s\n",
10409 bgp->update_delay_peers_resume_time);
d62a17ae 10410 }
10411 }
10412 }
ea47320b 10413 }
d62a17ae 10414
ea47320b
DL
10415 if (use_json) {
10416 if (bgp_maxmed_onstartup_configured(bgp)
10417 && bgp->maxmed_active)
10418 json_object_boolean_true_add(
60466a63 10419 json, "maxMedOnStartup");
ea47320b
DL
10420 if (bgp->v_maxmed_admin)
10421 json_object_boolean_true_add(
60466a63 10422 json, "maxMedAdministrative");
d62a17ae 10423
ea47320b
DL
10424 json_object_int_add(
10425 json, "tableVersion",
60466a63 10426 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 10427
60466a63
QY
10428 ents = bgp_table_count(bgp->rib[afi][safi]);
10429 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
10430 json_object_int_add(
10431 json, "ribMemory",
9bcb3eef 10432 ents * sizeof(struct bgp_dest));
d62a17ae 10433
210ec2a0 10434 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
10435 json_object_int_add(json, "peerCount", ents);
10436 json_object_int_add(json, "peerMemory",
10437 ents * sizeof(struct peer));
d62a17ae 10438
ea47320b
DL
10439 if ((ents = listcount(bgp->group))) {
10440 json_object_int_add(
60466a63 10441 json, "peerGroupCount", ents);
ea47320b
DL
10442 json_object_int_add(
10443 json, "peerGroupMemory",
996c9314
LB
10444 ents * sizeof(struct
10445 peer_group));
ea47320b 10446 }
d62a17ae 10447
ea47320b
DL
10448 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10449 BGP_CONFIG_DAMPENING))
10450 json_object_boolean_true_add(
60466a63 10451 json, "dampeningEnabled");
ea47320b 10452 } else {
96c81f66
LS
10453 if (!show_terse) {
10454 if (bgp_maxmed_onstartup_configured(bgp)
10455 && bgp->maxmed_active)
10456 vty_out(vty,
10457 "Max-med on-startup active\n");
10458 if (bgp->v_maxmed_admin)
10459 vty_out(vty,
10460 "Max-med administrative active\n");
d62a17ae 10461
96c81f66
LS
10462 vty_out(vty,
10463 "BGP table version %" PRIu64
10464 "\n",
10465 bgp_table_version(
10466 bgp->rib[afi][safi]));
ea47320b 10467
96c81f66
LS
10468 ents = bgp_table_count(
10469 bgp->rib[afi][safi]);
d62a17ae 10470 vty_out(vty,
96c81f66 10471 "RIB entries %ld, using %s of memory\n",
d62a17ae 10472 ents,
10473 mtype_memstr(
10474 memstrbuf,
10475 sizeof(memstrbuf),
96c81f66
LS
10476 ents
10477 * sizeof(
10478 struct
10479 bgp_dest)));
d62a17ae 10480
96c81f66
LS
10481 /* Peer related usage */
10482 ents = bgp->af_peer_count[afi][safi];
10483 vty_out(vty,
10484 "Peers %ld, using %s of memory\n",
10485 ents,
10486 mtype_memstr(
10487 memstrbuf,
10488 sizeof(memstrbuf),
10489 ents
10490 * sizeof(
10491 struct
10492 peer)));
d62a17ae 10493
96c81f66
LS
10494 if ((ents = listcount(bgp->group)))
10495 vty_out(vty,
10496 "Peer groups %ld, using %s of memory\n",
10497 ents,
10498 mtype_memstr(
10499 memstrbuf,
10500 sizeof(memstrbuf),
10501 ents
10502 * sizeof(
10503 struct
10504 peer_group)));
10505
10506 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10507 BGP_CONFIG_DAMPENING))
10508 vty_out(vty,
10509 "Dampening enabled.\n");
10510 }
10511 if (show_failed) {
10512 vty_out(vty, "\n");
10513
10514 /* Subtract 8 here because 'Neighbor' is
10515 * 8 characters */
10516 vty_out(vty, "Neighbor");
10517 vty_out(vty, "%*s",
10518 max_neighbor_width - 8, " ");
85eeb029
DA
10519 vty_out(vty,
10520 BGP_SHOW_SUMMARY_HEADER_FAILED);
96c81f66 10521 }
d62a17ae 10522 }
ea47320b 10523 }
d62a17ae 10524
d55811cc 10525 paf = peer_af_find(peer, afi, safi);
d3ada366 10526 filter = &peer->filter[afi][safi];
db92d226 10527
ea47320b 10528 count++;
3577f1c5
DD
10529 /* Works for both failed & successful cases */
10530 if (peer_dynamic_neighbor(peer))
10531 dn_count++;
d62a17ae 10532
ea47320b 10533 if (use_json) {
3577f1c5 10534 json_peer = NULL;
8c1d4cd5 10535 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
10536 as_type, as)) {
10537 filtered_count++;
8c1d4cd5 10538 continue;
ce1944f0 10539 }
3577f1c5
DD
10540 if (show_failed &&
10541 bgp_has_peer_failed(peer, afi, safi)) {
10542 json_peer = json_object_new_object();
10543 bgp_show_failed_summary(vty, bgp, peer,
10544 json_peer, 0, use_json);
10545 } else if (!show_failed) {
10b49f14 10546 if (show_established
ce1944f0
LS
10547 && bgp_has_peer_failed(peer, afi, safi)) {
10548 filtered_count++;
10b49f14 10549 continue;
ce1944f0 10550 }
10b49f14 10551
3577f1c5
DD
10552 json_peer = json_object_new_object();
10553 if (peer_dynamic_neighbor(peer)) {
10554 json_object_boolean_true_add(json_peer,
10555 "dynamicPeer");
10556 }
d62a17ae 10557
3577f1c5
DD
10558 if (peer->hostname)
10559 json_object_string_add(json_peer, "hostname",
10560 peer->hostname);
10561
10562 if (peer->domainname)
10563 json_object_string_add(json_peer, "domainname",
10564 peer->domainname);
10565
10566 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
10567 json_object_int_add(
10568 json_peer, "localAs",
10569 peer->change_local_as
10570 ? peer->change_local_as
10571 : peer->local_as);
3577f1c5
DD
10572 json_object_int_add(json_peer, "version", 4);
10573 json_object_int_add(json_peer, "msgRcvd",
10574 PEER_TOTAL_RX(peer));
10575 json_object_int_add(json_peer, "msgSent",
10576 PEER_TOTAL_TX(peer));
10577
43aa5965
QY
10578 atomic_size_t outq_count, inq_count;
10579 outq_count = atomic_load_explicit(
10580 &peer->obuf->count,
10581 memory_order_relaxed);
10582 inq_count = atomic_load_explicit(
10583 &peer->ibuf->count,
10584 memory_order_relaxed);
10585
3577f1c5
DD
10586 json_object_int_add(json_peer, "tableVersion",
10587 peer->version[afi][safi]);
10588 json_object_int_add(json_peer, "outq",
43aa5965
QY
10589 outq_count);
10590 json_object_int_add(json_peer, "inq",
10591 inq_count);
3577f1c5
DD
10592 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10593 use_json, json_peer);
10594
3577f1c5
DD
10595 json_object_int_add(json_peer, "pfxRcd",
10596 peer->pcount[afi][pfx_rcd_safi]);
10597
3577f1c5 10598 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
10599 json_object_int_add(
10600 json_peer, "pfxSnt",
10601 (PAF_SUBGRP(paf))->scount);
10602 else
10603 json_object_int_add(json_peer, "pfxSnt",
10604 0);
0e1f8ab5
DA
10605
10606 /* BGP FSM state */
cb9196e7 10607 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
10608 || CHECK_FLAG(peer->bgp->flags,
10609 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
10610 json_object_string_add(json_peer,
10611 "state",
3577f1c5
DD
10612 "Idle (Admin)");
10613 else if (peer->afc_recv[afi][safi])
10614 json_object_string_add(
0e1f8ab5
DA
10615 json_peer, "state",
10616 lookup_msg(bgp_status_msg,
10617 peer->status, NULL));
10618 else if (CHECK_FLAG(
10619 peer->sflags,
10620 PEER_STATUS_PREFIX_OVERFLOW))
10621 json_object_string_add(json_peer,
10622 "state",
3577f1c5
DD
10623 "Idle (PfxCt)");
10624 else
10625 json_object_string_add(
0e1f8ab5
DA
10626 json_peer, "state",
10627 lookup_msg(bgp_status_msg,
10628 peer->status, NULL));
10629
10630 /* BGP peer state */
10631 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10632 || CHECK_FLAG(peer->bgp->flags,
10633 BGP_FLAG_SHUTDOWN))
10634 json_object_string_add(json_peer,
10635 "peerState",
10636 "Admin");
10637 else if (CHECK_FLAG(
10638 peer->sflags,
10639 PEER_STATUS_PREFIX_OVERFLOW))
10640 json_object_string_add(json_peer,
10641 "peerState",
10642 "PfxCt");
10643 else if (CHECK_FLAG(peer->flags,
10644 PEER_FLAG_PASSIVE))
10645 json_object_string_add(json_peer,
10646 "peerState",
10647 "Passive");
10648 else if (CHECK_FLAG(peer->sflags,
10649 PEER_STATUS_NSF_WAIT))
10650 json_object_string_add(json_peer,
10651 "peerState",
10652 "NSF passive");
10653 else if (CHECK_FLAG(
10654 peer->bgp->flags,
10655 BGP_FLAG_EBGP_REQUIRES_POLICY)
10656 && (!bgp_inbound_policy_exists(peer,
10657 filter)
10658 || !bgp_outbound_policy_exists(
10659 peer, filter)))
10660 json_object_string_add(json_peer,
10661 "peerState",
10662 "Policy");
10663 else
10664 json_object_string_add(
10665 json_peer, "peerState", "OK");
10666
200116db
DD
10667 json_object_int_add(json_peer, "connectionsEstablished",
10668 peer->established);
10669 json_object_int_add(json_peer, "connectionsDropped",
10670 peer->dropped);
aa72bd7e
PG
10671 if (peer->desc)
10672 json_object_string_add(
10673 json_peer, "desc", peer->desc);
b4e9dcba 10674 }
3577f1c5
DD
10675 /* Avoid creating empty peer dicts in JSON */
10676 if (json_peer == NULL)
10677 continue;
ea47320b
DL
10678
10679 if (peer->conf_if)
60466a63 10680 json_object_string_add(json_peer, "idType",
ea47320b
DL
10681 "interface");
10682 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
10683 json_object_string_add(json_peer, "idType",
10684 "ipv4");
ea47320b 10685 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
10686 json_object_string_add(json_peer, "idType",
10687 "ipv6");
ea47320b
DL
10688 json_object_object_add(json_peers, peer->host,
10689 json_peer);
10690 } else {
8c1d4cd5 10691 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
10692 as_type, as)) {
10693 filtered_count++;
8c1d4cd5 10694 continue;
ce1944f0 10695 }
3577f1c5
DD
10696 if (show_failed &&
10697 bgp_has_peer_failed(peer, afi, safi)) {
10698 bgp_show_failed_summary(vty, bgp, peer, NULL,
10699 max_neighbor_width,
10700 use_json);
10701 } else if (!show_failed) {
10b49f14 10702 if (show_established
ce1944f0
LS
10703 && bgp_has_peer_failed(peer, afi, safi)) {
10704 filtered_count++;
10b49f14 10705 continue;
ce1944f0 10706 }
96c81f66
LS
10707
10708 if ((count - filtered_count) == 1) {
10709 /* display headline before the first
10710 * neighbor line */
10711 vty_out(vty, "\n");
10712
10713 /* Subtract 8 here because 'Neighbor' is
10714 * 8 characters */
10715 vty_out(vty, "Neighbor");
10716 vty_out(vty, "%*s",
10717 max_neighbor_width - 8, " ");
10718 vty_out(vty,
10719 show_wide
10720 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10721 : BGP_SHOW_SUMMARY_HEADER_ALL);
10722 }
10723
3577f1c5
DD
10724 memset(dn_flag, '\0', sizeof(dn_flag));
10725 if (peer_dynamic_neighbor(peer)) {
10726 dn_flag[0] = '*';
10727 }
d62a17ae 10728
3577f1c5 10729 if (peer->hostname
892fedb6
DA
10730 && CHECK_FLAG(bgp->flags,
10731 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 10732 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
10733 peer->hostname,
10734 peer->host);
d62a17ae 10735 else
3577f1c5
DD
10736 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10737
10738 /* pad the neighbor column with spaces */
10739 if (len < max_neighbor_width)
10740 vty_out(vty, "%*s", max_neighbor_width - len,
10741 " ");
10742
43aa5965
QY
10743 atomic_size_t outq_count, inq_count;
10744 outq_count = atomic_load_explicit(
10745 &peer->obuf->count,
10746 memory_order_relaxed);
10747 inq_count = atomic_load_explicit(
10748 &peer->ibuf->count,
10749 memory_order_relaxed);
10750
85eeb029
DA
10751 if (show_wide)
10752 vty_out(vty,
10753 "4 %10u %10u %9u %9u %8" PRIu64
10754 " %4zu %4zu %8s",
10755 peer->as,
10756 peer->change_local_as
10757 ? peer->change_local_as
10758 : peer->local_as,
10759 PEER_TOTAL_RX(peer),
10760 PEER_TOTAL_TX(peer),
10761 peer->version[afi][safi],
10762 inq_count, outq_count,
10763 peer_uptime(peer->uptime,
10764 timebuf,
10765 BGP_UPTIME_LEN, 0,
10766 NULL));
10767 else
10768 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
10769 " %4zu %4zu %8s",
10770 peer->as, PEER_TOTAL_RX(peer),
10771 PEER_TOTAL_TX(peer),
10772 peer->version[afi][safi],
10773 inq_count, outq_count,
10774 peer_uptime(peer->uptime,
10775 timebuf,
10776 BGP_UPTIME_LEN, 0,
10777 NULL));
3577f1c5 10778
feb17238 10779 if (peer_established(peer)) {
d3ada366
DA
10780 if (peer->afc_recv[afi][safi]) {
10781 if (CHECK_FLAG(
10782 bgp->flags,
10783 BGP_FLAG_EBGP_REQUIRES_POLICY)
10784 && !bgp_inbound_policy_exists(
10785 peer, filter))
10786 vty_out(vty, " %12s",
10787 "(Policy)");
10788 else
10789 vty_out(vty,
6cde4b45 10790 " %12u",
d3ada366
DA
10791 peer->pcount
10792 [afi]
10793 [pfx_rcd_safi]);
10794 } else {
749d0f27 10795 vty_out(vty, " NoNeg");
d3ada366 10796 }
db92d226 10797
d3ada366
DA
10798 if (paf && PAF_SUBGRP(paf)) {
10799 if (CHECK_FLAG(
10800 bgp->flags,
10801 BGP_FLAG_EBGP_REQUIRES_POLICY)
10802 && !bgp_outbound_policy_exists(
10803 peer, filter))
10804 vty_out(vty, " %8s",
10805 "(Policy)");
10806 else
10807 vty_out(vty,
6cde4b45 10808 " %8u",
d3ada366
DA
10809 (PAF_SUBGRP(
10810 paf))
10811 ->scount);
749d0f27
DA
10812 } else {
10813 vty_out(vty, " NoNeg");
d3ada366 10814 }
db92d226 10815 } else {
736b68f3
DS
10816 if (CHECK_FLAG(peer->flags,
10817 PEER_FLAG_SHUTDOWN)
10818 || CHECK_FLAG(peer->bgp->flags,
10819 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
10820 vty_out(vty, " Idle (Admin)");
10821 else if (CHECK_FLAG(
10822 peer->sflags,
10823 PEER_STATUS_PREFIX_OVERFLOW))
10824 vty_out(vty, " Idle (PfxCt)");
10825 else
10826 vty_out(vty, " %12s",
10827 lookup_msg(bgp_status_msg,
10828 peer->status, NULL));
db92d226 10829
6cde4b45 10830 vty_out(vty, " %8u", 0);
3577f1c5 10831 }
565e9ddd
DA
10832 /* Make sure `Desc` column is the lastest in
10833 * the output.
10834 */
aa72bd7e 10835 if (peer->desc)
cb75bb31
DA
10836 vty_out(vty, " %s",
10837 bgp_peer_description_stripped(
85eeb029
DA
10838 peer->desc,
10839 show_wide ? 64 : 20));
aa72bd7e
PG
10840 else
10841 vty_out(vty, " N/A");
3577f1c5 10842 vty_out(vty, "\n");
d62a17ae 10843 }
3577f1c5 10844
d62a17ae 10845 }
10846 }
f933309e 10847
d62a17ae 10848 if (use_json) {
10849 json_object_object_add(json, "peers", json_peers);
3577f1c5 10850 json_object_int_add(json, "failedPeers", failed_count);
ce1944f0
LS
10851 json_object_int_add(json, "displayedPeers",
10852 count - filtered_count);
d62a17ae 10853 json_object_int_add(json, "totalPeers", count);
10854 json_object_int_add(json, "dynamicPeers", dn_count);
10855
3577f1c5
DD
10856 if (!show_failed)
10857 bgp_show_bestpath_json(bgp, json);
57a9c8a8 10858
75eeda93 10859 vty_json(vty, json);
d62a17ae 10860 } else {
ce1944f0 10861 if (count) {
96c81f66
LS
10862 if (filtered_count == count)
10863 vty_out(vty, "\n%% No matching neighbor\n");
10864 else {
10865 if (show_failed)
10866 vty_out(vty, "\nDisplayed neighbors %d",
10867 failed_count);
10868 else if (as_type != AS_UNSPECIFIED || as
10869 || fpeer || show_established)
ce1944f0
LS
10870 vty_out(vty, "\nDisplayed neighbors %d",
10871 count - filtered_count);
96c81f66
LS
10872
10873 vty_out(vty, "\nTotal number of neighbors %d\n",
10874 count);
ce1944f0 10875 }
ce1944f0 10876 } else {
d6ceaca3 10877 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 10878 get_afi_safi_str(afi, safi, false));
d62a17ae 10879 }
b05a1c8b 10880
d6ceaca3 10881 if (dn_count) {
d62a17ae 10882 vty_out(vty, "* - dynamic neighbor\n");
10883 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
10884 dn_count, bgp->dynamic_neighbors_limit);
10885 }
10886 }
1ff9a340 10887
d62a17ae 10888 return CMD_SUCCESS;
718e3744 10889}
10890
d62a17ae 10891static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5 10892 int safi, struct peer *fpeer, int as_type,
96c81f66 10893 as_t as, uint16_t show_flags)
d62a17ae 10894{
10895 int is_first = 1;
10896 int afi_wildcard = (afi == AFI_MAX);
10897 int safi_wildcard = (safi == SAFI_MAX);
10898 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 10899 bool nbr_output = false;
85eeb029 10900 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 10901
10902 if (use_json && is_wildcard)
10903 vty_out(vty, "{\n");
10904 if (afi_wildcard)
10905 afi = 1; /* AFI_IP */
10906 while (afi < AFI_MAX) {
10907 if (safi_wildcard)
10908 safi = 1; /* SAFI_UNICAST */
10909 while (safi < SAFI_MAX) {
318cac96 10910 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 10911 nbr_output = true;
f86897b9 10912
d62a17ae 10913 if (is_wildcard) {
10914 /*
10915 * So limit output to those afi/safi
10916 * pairs that
10917 * actualy have something interesting in
10918 * them
10919 */
10920 if (use_json) {
d62a17ae 10921 if (!is_first)
10922 vty_out(vty, ",\n");
10923 else
10924 is_first = 0;
10925
10926 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
10927 get_afi_safi_str(afi,
10928 safi,
10929 true));
d62a17ae 10930 } else {
6cac2fcc
LS
10931 vty_out(vty,
10932 "\n%s Summary (%s):\n",
5cb5f4d0
DD
10933 get_afi_safi_str(afi,
10934 safi,
6cac2fcc
LS
10935 false),
10936 bgp->name_pretty);
d62a17ae 10937 }
10938 }
8c1d4cd5
LS
10939 bgp_show_summary(vty, bgp, afi, safi, fpeer,
10940 as_type, as, show_flags);
d62a17ae 10941 }
10942 safi++;
d62a17ae 10943 if (!safi_wildcard)
10944 safi = SAFI_MAX;
10945 }
10946 afi++;
ee851c8c 10947 if (!afi_wildcard)
d62a17ae 10948 afi = AFI_MAX;
10949 }
10950
10951 if (use_json && is_wildcard)
10952 vty_out(vty, "}\n");
ca61fd25
DS
10953 else if (!nbr_output) {
10954 if (use_json)
10955 vty_out(vty, "{}\n");
10956 else
6cac2fcc
LS
10957 vty_out(vty, "%% No BGP neighbors found in %s\n",
10958 bgp->name_pretty);
ca61fd25 10959 }
d62a17ae 10960}
10961
10962static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
10963 safi_t safi,
10964 const char *neighbor,
10965 int as_type, as_t as,
96c81f66 10966 uint16_t show_flags)
d62a17ae 10967{
10968 struct listnode *node, *nnode;
10969 struct bgp *bgp;
8c1d4cd5 10970 struct peer *fpeer = NULL;
d62a17ae 10971 int is_first = 1;
9f049418 10972 bool nbr_output = false;
85eeb029 10973 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 10974
10975 if (use_json)
10976 vty_out(vty, "{\n");
10977
10978 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 10979 nbr_output = true;
d62a17ae 10980 if (use_json) {
d62a17ae 10981 if (!is_first)
10982 vty_out(vty, ",\n");
10983 else
10984 is_first = 0;
10985
10986 vty_out(vty, "\"%s\":",
10987 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10988 ? VRF_DEFAULT_NAME
d62a17ae 10989 : bgp->name);
d62a17ae 10990 }
8c1d4cd5
LS
10991 if (neighbor) {
10992 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
10993 use_json);
10994 if (!fpeer)
10995 continue;
10996 }
10997 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
10998 as, show_flags);
d62a17ae 10999 }
11000
11001 if (use_json)
11002 vty_out(vty, "}\n");
9f049418
DS
11003 else if (!nbr_output)
11004 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11005}
11006
11007int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5 11008 safi_t safi, const char *neighbor, int as_type,
96c81f66 11009 as_t as, uint16_t show_flags)
d62a17ae 11010{
11011 struct bgp *bgp;
85eeb029 11012 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 11013 struct peer *fpeer = NULL;
d62a17ae 11014
11015 if (name) {
11016 if (strmatch(name, "all")) {
85eeb029 11017 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
11018 neighbor, as_type,
11019 as, show_flags);
d62a17ae 11020 return CMD_SUCCESS;
11021 } else {
11022 bgp = bgp_lookup_by_name(name);
11023
11024 if (!bgp) {
11025 if (use_json)
11026 vty_out(vty, "{}\n");
11027 else
11028 vty_out(vty,
ca61fd25 11029 "%% BGP instance not found\n");
d62a17ae 11030 return CMD_WARNING;
11031 }
11032
8c1d4cd5
LS
11033 if (neighbor) {
11034 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11035 use_json);
11036 if (!fpeer)
11037 return CMD_WARNING;
11038 }
11039 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11040 as_type, as, show_flags);
d62a17ae 11041 return CMD_SUCCESS;
11042 }
11043 }
11044
11045 bgp = bgp_get_default();
11046
8c1d4cd5
LS
11047 if (bgp) {
11048 if (neighbor) {
11049 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11050 use_json);
11051 if (!fpeer)
11052 return CMD_WARNING;
11053 }
11054 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11055 as, show_flags);
11056 } else {
ca61fd25
DS
11057 if (use_json)
11058 vty_out(vty, "{}\n");
11059 else
11060 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11061 return CMD_WARNING;
11062 }
d62a17ae 11063
11064 return CMD_SUCCESS;
4fb25c53
DW
11065}
11066
716b2d8a 11067/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
11068DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11069 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11070 " [" BGP_SAFI_WITH_LABEL_CMD_STR
96c81f66 11071 "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <(1-4294967295)|internal|external>>] [terse] [wide] [json$uj]",
8c1d4cd5
LS
11072 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11073 BGP_SAFI_WITH_LABEL_HELP_STR
11074 "Display the entries for all address families\n"
11075 "Summary of BGP neighbor status\n"
11076 "Show only sessions in Established state\n"
11077 "Show only sessions not in Established state\n"
11078 "Show only the specified neighbor session\n"
11079 "Neighbor to display information about\n"
11080 "Neighbor to display information about\n"
11081 "Neighbor on BGP configured interface\n"
11082 "Show only the specified remote AS sessions\n"
11083 "AS number\n"
11084 "Internal (iBGP) AS sessions\n"
11085 "External (eBGP) AS sessions\n"
96c81f66 11086 "Shorten the information on BGP instances\n"
8c1d4cd5 11087 "Increase table width for longer output\n" JSON_STR)
718e3744 11088{
d62a17ae 11089 char *vrf = NULL;
11090 afi_t afi = AFI_MAX;
11091 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
11092 as_t as = 0; /* 0 means AS filter not set */
11093 int as_type = AS_UNSPECIFIED;
96c81f66 11094 uint16_t show_flags = 0;
d62a17ae 11095
11096 int idx = 0;
11097
11098 /* show [ip] bgp */
96f3485c 11099 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11100 afi = AFI_IP;
9a8bdf1c
PG
11101 /* [<vrf> VIEWVRFNAME] */
11102 if (argv_find(argv, argc, "vrf", &idx)) {
11103 vrf = argv[idx + 1]->arg;
11104 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11105 vrf = NULL;
11106 } else if (argv_find(argv, argc, "view", &idx))
11107 /* [<view> VIEWVRFNAME] */
11108 vrf = argv[idx + 1]->arg;
d62a17ae 11109 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11110 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11111 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11112 }
11113
3577f1c5 11114 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11115 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11116
10b49f14 11117 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11118 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11119
8c1d4cd5
LS
11120 if (argv_find(argv, argc, "remote-as", &idx)) {
11121 if (argv[idx + 1]->arg[0] == 'i')
11122 as_type = AS_INTERNAL;
11123 else if (argv[idx + 1]->arg[0] == 'e')
11124 as_type = AS_EXTERNAL;
11125 else
11126 as = (as_t)atoi(argv[idx + 1]->arg);
11127 }
11128
96c81f66
LS
11129 if (argv_find(argv, argc, "terse", &idx))
11130 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11131
85eeb029
DA
11132 if (argv_find(argv, argc, "wide", &idx))
11133 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11134
11135 if (argv_find(argv, argc, "json", &idx))
11136 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11137
8c1d4cd5
LS
11138 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11139 show_flags);
d62a17ae 11140}
11141
5cb5f4d0 11142const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11143{
5cb5f4d0
DD
11144 if (for_json)
11145 return get_afi_safi_json_str(afi, safi);
d62a17ae 11146 else
5cb5f4d0 11147 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11148}
11149
d62a17ae 11150
11151static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11152 afi_t afi, safi_t safi,
d7c0a89a
QY
11153 uint16_t adv_smcap, uint16_t adv_rmcap,
11154 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11155 bool use_json, json_object *json_pref)
d62a17ae 11156{
11157 /* Send-Mode */
11158 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11159 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11160 if (use_json) {
11161 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11162 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11163 json_object_string_add(json_pref, "sendMode",
11164 "advertisedAndReceived");
11165 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11166 json_object_string_add(json_pref, "sendMode",
11167 "advertised");
11168 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11169 json_object_string_add(json_pref, "sendMode",
11170 "received");
11171 } else {
11172 vty_out(vty, " Send-mode: ");
11173 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11174 vty_out(vty, "advertised");
11175 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11176 vty_out(vty, "%sreceived",
11177 CHECK_FLAG(p->af_cap[afi][safi],
11178 adv_smcap)
11179 ? ", "
11180 : "");
11181 vty_out(vty, "\n");
11182 }
11183 }
11184
11185 /* Receive-Mode */
11186 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11187 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11188 if (use_json) {
11189 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11190 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11191 json_object_string_add(json_pref, "recvMode",
11192 "advertisedAndReceived");
11193 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11194 json_object_string_add(json_pref, "recvMode",
11195 "advertised");
11196 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11197 json_object_string_add(json_pref, "recvMode",
11198 "received");
11199 } else {
11200 vty_out(vty, " Receive-mode: ");
11201 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11202 vty_out(vty, "advertised");
11203 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11204 vty_out(vty, "%sreceived",
11205 CHECK_FLAG(p->af_cap[afi][safi],
11206 adv_rmcap)
11207 ? ", "
11208 : "");
11209 vty_out(vty, "\n");
11210 }
11211 }
11212}
11213
13909c4f
DS
11214static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11215 struct peer *p,
11216 bool use_json,
11217 json_object *json)
2986cac2 11218{
08c2d52a 11219 bool rbit_status = false;
2986cac2 11220
11221 if (!use_json)
a53ca37b 11222 vty_out(vty, "\n R bit: ");
2986cac2 11223
13909c4f
DS
11224 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11225 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
feb17238 11226 && (peer_established(p))) {
2986cac2 11227
11228 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 11229 rbit_status = true;
2986cac2 11230 else
08c2d52a 11231 rbit_status = false;
2986cac2 11232 }
11233
11234 if (rbit_status) {
11235 if (use_json)
13909c4f 11236 json_object_boolean_true_add(json, "rBit");
2986cac2 11237 else
11238 vty_out(vty, "True\n");
11239 } else {
11240 if (use_json)
13909c4f 11241 json_object_boolean_false_add(json, "rBit");
2986cac2 11242 else
11243 vty_out(vty, "False\n");
11244 }
11245}
11246
13909c4f
DS
11247static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11248 struct peer *peer,
11249 bool use_json,
11250 json_object *json)
2986cac2 11251{
2bb5d39b 11252 const char *mode = "NotApplicable";
2986cac2 11253
11254 if (!use_json)
a53ca37b 11255 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11256
13909c4f 11257 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
feb17238 11258 && (peer_established(peer))) {
2986cac2 11259
13909c4f
DS
11260 if ((peer->nsf_af_count == 0)
11261 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11262
2986cac2 11263 mode = "Disable";
11264
13909c4f
DS
11265 } else if (peer->nsf_af_count == 0
11266 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11267
2986cac2 11268 mode = "Helper";
11269
13909c4f
DS
11270 } else if (peer->nsf_af_count != 0
11271 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11272
2986cac2 11273 mode = "Restart";
2986cac2 11274 }
11275 }
11276
11277 if (use_json) {
13909c4f 11278 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11279 } else
11280 vty_out(vty, mode, "\n");
11281}
11282
13909c4f
DS
11283static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11284 struct peer *p,
11285 bool use_json,
11286 json_object *json)
2986cac2 11287{
11288 const char *mode = "Invalid";
11289
11290 if (!use_json)
a53ca37b 11291 vty_out(vty, " Local GR Mode: ");
2986cac2 11292
11293 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11294 mode = "Helper";
11295 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11296 mode = "Restart";
11297 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11298 mode = "Disable";
2ba1fe69 11299 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11300 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11301 mode = "Helper*";
11302 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11303 mode = "Restart*";
11304 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11305 mode = "Disable*";
11306 else
11307 mode = "Invalid*";
2ba1fe69 11308 }
2986cac2 11309
11310 if (use_json) {
13909c4f 11311 json_object_string_add(json, "localGrMode", mode);
2986cac2 11312 } else {
11313 vty_out(vty, mode, "\n");
11314 }
11315}
11316
13909c4f
DS
11317static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11318 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11319{
2ba1fe69 11320 afi_t afi;
11321 safi_t safi;
2986cac2 11322 json_object *json_afi_safi = NULL;
11323 json_object *json_timer = NULL;
11324 json_object *json_endofrib_status = NULL;
9e3b51a7 11325 bool eor_flag = false;
2986cac2 11326
df8d723c
DA
11327 FOREACH_AFI_SAFI_NSF (afi, safi) {
11328 if (!peer->afc[afi][safi])
11329 continue;
2986cac2 11330
df8d723c
DA
11331 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11332 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11333 continue;
9e3b51a7 11334
df8d723c
DA
11335 if (use_json) {
11336 json_afi_safi = json_object_new_object();
11337 json_endofrib_status = json_object_new_object();
11338 json_timer = json_object_new_object();
11339 }
2986cac2 11340
df8d723c
DA
11341 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11342 eor_flag = true;
11343 else
11344 eor_flag = false;
2986cac2 11345
df8d723c
DA
11346 if (!use_json) {
11347 vty_out(vty, " %s:\n",
11348 get_afi_safi_str(afi, safi, false));
2986cac2 11349
df8d723c
DA
11350 vty_out(vty, " F bit: ");
11351 }
2986cac2 11352
df8d723c
DA
11353 if (peer->nsf[afi][safi] &&
11354 CHECK_FLAG(peer->af_cap[afi][safi],
11355 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11356
df8d723c
DA
11357 if (use_json) {
11358 json_object_boolean_true_add(json_afi_safi,
11359 "fBit");
11360 } else
11361 vty_out(vty, "True\n");
11362 } else {
11363 if (use_json)
11364 json_object_boolean_false_add(json_afi_safi,
11365 "fBit");
11366 else
11367 vty_out(vty, "False\n");
11368 }
2986cac2 11369
df8d723c
DA
11370 if (!use_json)
11371 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11372
df8d723c
DA
11373 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11374 PEER_STATUS_EOR_SEND)) {
11375 if (use_json) {
11376 json_object_boolean_true_add(
11377 json_endofrib_status, "endOfRibSend");
9e3b51a7 11378
df8d723c
DA
11379 PRINT_EOR_JSON(eor_flag);
11380 } else {
11381 vty_out(vty, "Yes\n");
11382 vty_out(vty,
11383 " End-of-RIB sent after update: ");
2986cac2 11384
df8d723c
DA
11385 PRINT_EOR(eor_flag);
11386 }
11387 } else {
11388 if (use_json) {
11389 json_object_boolean_false_add(
11390 json_endofrib_status, "endOfRibSend");
11391 json_object_boolean_false_add(
11392 json_endofrib_status,
11393 "endOfRibSentAfterUpdate");
13909c4f 11394 } else {
df8d723c
DA
11395 vty_out(vty, "No\n");
11396 vty_out(vty,
11397 " End-of-RIB sent after update: ");
11398 vty_out(vty, "No\n");
13909c4f 11399 }
df8d723c 11400 }
2986cac2 11401
df8d723c
DA
11402 if (!use_json)
11403 vty_out(vty, " End-of-RIB received: ");
a53ca37b 11404
df8d723c
DA
11405 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11406 PEER_STATUS_EOR_RECEIVED)) {
11407 if (use_json)
11408 json_object_boolean_true_add(
11409 json_endofrib_status, "endOfRibRecv");
11410 else
11411 vty_out(vty, "Yes\n");
11412 } else {
11413 if (use_json)
11414 json_object_boolean_false_add(
11415 json_endofrib_status, "endOfRibRecv");
11416 else
11417 vty_out(vty, "No\n");
11418 }
11419
11420 if (use_json) {
11421 json_object_int_add(json_timer, "stalePathTimer",
11422 peer->bgp->stalepath_time);
11423
11424 if (peer->t_gr_stale != NULL) {
11425 json_object_int_add(json_timer,
11426 "stalePathTimerRemaining",
11427 thread_timer_remain_second(
11428 peer->t_gr_stale));
a53ca37b
DA
11429 }
11430
df8d723c
DA
11431 /* Display Configured Selection
11432 * Deferral only when when
11433 * Gr mode is enabled.
11434 */
11435 if (CHECK_FLAG(peer->flags,
11436 PEER_FLAG_GRACEFUL_RESTART)) {
13909c4f 11437 json_object_int_add(json_timer,
df8d723c 11438 "selectionDeferralTimer",
13909c4f 11439 peer->bgp->stalepath_time);
df8d723c 11440 }
2986cac2 11441
df8d723c
DA
11442 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11443 NULL) {
2986cac2 11444
df8d723c
DA
11445 json_object_int_add(
11446 json_timer,
11447 "selectionDeferralTimerRemaining",
11448 thread_timer_remain_second(
11449 peer->bgp->gr_info[afi][safi]
11450 .t_select_deferral));
11451 }
11452 } else {
11453 vty_out(vty, " Timers:\n");
11454 vty_out(vty,
11455 " Configured Stale Path Time(sec): %u\n",
11456 peer->bgp->stalepath_time);
2986cac2 11457
df8d723c 11458 if (peer->t_gr_stale != NULL)
13909c4f 11459 vty_out(vty,
df8d723c
DA
11460 " Stale Path Remaining(sec): %ld\n",
11461 thread_timer_remain_second(
11462 peer->t_gr_stale));
11463 /* Display Configured Selection
11464 * Deferral only when when
11465 * Gr mode is enabled.
11466 */
11467 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11468 vty_out(vty,
11469 " Configured Selection Deferral Time(sec): %u\n",
11470 peer->bgp->select_defer_time);
2986cac2 11471
df8d723c
DA
11472 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11473 NULL)
11474 vty_out(vty,
11475 " Selection Deferral Time Remaining(sec): %ld\n",
11476 thread_timer_remain_second(
11477 peer->bgp->gr_info[afi][safi]
11478 .t_select_deferral));
11479 }
11480 if (use_json) {
11481 json_object_object_add(json_afi_safi, "endOfRibStatus",
11482 json_endofrib_status);
11483 json_object_object_add(json_afi_safi, "timers",
11484 json_timer);
11485 json_object_object_add(
11486 json, get_afi_safi_str(afi, safi, true),
11487 json_afi_safi);
2986cac2 11488 }
11489 }
11490}
11491
36235319
QY
11492static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11493 struct peer *p,
11494 bool use_json,
11495 json_object *json)
2986cac2 11496{
11497 if (use_json) {
11498 json_object *json_timer = NULL;
11499
11500 json_timer = json_object_new_object();
11501
13909c4f
DS
11502 json_object_int_add(json_timer, "configuredRestartTimer",
11503 p->bgp->restart_time);
2986cac2 11504
13909c4f
DS
11505 json_object_int_add(json_timer, "receivedRestartTimer",
11506 p->v_gr_restart);
2986cac2 11507
13909c4f
DS
11508 if (p->t_gr_restart != NULL)
11509 json_object_int_add(
11510 json_timer, "restartTimerRemaining",
11511 thread_timer_remain_second(p->t_gr_restart));
2986cac2 11512
11513 json_object_object_add(json, "timers", json_timer);
11514 } else {
11515
a53ca37b
DA
11516 vty_out(vty, " Timers:\n");
11517 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 11518 p->bgp->restart_time);
2986cac2 11519
a53ca37b 11520 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
11521 p->v_gr_restart);
11522 if (p->t_gr_restart != NULL)
a53ca37b 11523 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 11524 thread_timer_remain_second(p->t_gr_restart));
36235319 11525 if (p->t_gr_restart != NULL) {
a53ca37b 11526 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
11527 thread_timer_remain_second(p->t_gr_restart));
11528 }
2986cac2 11529 }
11530}
11531
11532static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 11533 bool use_json, json_object *json)
2986cac2 11534{
11535 char buf[SU_ADDRSTRLEN] = {0};
11536 char dn_flag[2] = {0};
2b7165e7
QY
11537 /* '*' + v6 address of neighbor */
11538 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 11539
2986cac2 11540 if (!p->conf_if && peer_dynamic_neighbor(p))
11541 dn_flag[0] = '*';
11542
11543 if (p->conf_if) {
11544 if (use_json)
13909c4f
DS
11545 json_object_string_add(
11546 json, "neighborAddr",
2986cac2 11547 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
11548 ? "none"
11549 : sockunion2str(&p->su, buf,
11550 SU_ADDRSTRLEN));
2986cac2 11551 else
13909c4f 11552 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 11553 BGP_PEER_SU_UNSPEC(p)
11554 ? "none"
11555 : sockunion2str(&p->su, buf,
11556 SU_ADDRSTRLEN));
11557 } else {
772270f3
QY
11558 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11559 p->host);
2986cac2 11560
11561 if (use_json)
36235319
QY
11562 json_object_string_add(json, "neighborAddr",
11563 neighborAddr);
2986cac2 11564 else
36235319 11565 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 11566 }
11567
11568 /* more gr info in new format */
11569 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11570}
11571
d62a17ae 11572static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 11573 safi_t safi, bool use_json,
d62a17ae 11574 json_object *json_neigh)
11575{
0291c246
MK
11576 struct bgp_filter *filter;
11577 struct peer_af *paf;
11578 char orf_pfx_name[BUFSIZ];
11579 int orf_pfx_count;
11580 json_object *json_af = NULL;
11581 json_object *json_prefA = NULL;
11582 json_object *json_prefB = NULL;
11583 json_object *json_addr = NULL;
fa36596c 11584 json_object *json_advmap = NULL;
d62a17ae 11585
11586 if (use_json) {
11587 json_addr = json_object_new_object();
11588 json_af = json_object_new_object();
11589 filter = &p->filter[afi][safi];
11590
11591 if (peer_group_active(p))
11592 json_object_string_add(json_addr, "peerGroupMember",
11593 p->group->name);
11594
11595 paf = peer_af_find(p, afi, safi);
11596 if (paf && PAF_SUBGRP(paf)) {
11597 json_object_int_add(json_addr, "updateGroupId",
11598 PAF_UPDGRP(paf)->id);
11599 json_object_int_add(json_addr, "subGroupId",
11600 PAF_SUBGRP(paf)->id);
11601 json_object_int_add(json_addr, "packetQueueLength",
11602 bpacket_queue_virtual_length(paf));
11603 }
11604
11605 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11606 || CHECK_FLAG(p->af_cap[afi][safi],
11607 PEER_CAP_ORF_PREFIX_SM_RCV)
11608 || CHECK_FLAG(p->af_cap[afi][safi],
11609 PEER_CAP_ORF_PREFIX_RM_ADV)
11610 || CHECK_FLAG(p->af_cap[afi][safi],
11611 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11612 json_object_int_add(json_af, "orfType",
11613 ORF_TYPE_PREFIX);
11614 json_prefA = json_object_new_object();
11615 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11616 PEER_CAP_ORF_PREFIX_SM_ADV,
11617 PEER_CAP_ORF_PREFIX_RM_ADV,
11618 PEER_CAP_ORF_PREFIX_SM_RCV,
11619 PEER_CAP_ORF_PREFIX_RM_RCV,
11620 use_json, json_prefA);
11621 json_object_object_add(json_af, "orfPrefixList",
11622 json_prefA);
11623 }
11624
11625 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11626 || CHECK_FLAG(p->af_cap[afi][safi],
11627 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11628 || CHECK_FLAG(p->af_cap[afi][safi],
11629 PEER_CAP_ORF_PREFIX_RM_ADV)
11630 || CHECK_FLAG(p->af_cap[afi][safi],
11631 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11632 json_object_int_add(json_af, "orfOldType",
11633 ORF_TYPE_PREFIX_OLD);
11634 json_prefB = json_object_new_object();
11635 bgp_show_peer_afi_orf_cap(
11636 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11637 PEER_CAP_ORF_PREFIX_RM_ADV,
11638 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11639 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11640 json_prefB);
11641 json_object_object_add(json_af, "orfOldPrefixList",
11642 json_prefB);
11643 }
11644
11645 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11646 || CHECK_FLAG(p->af_cap[afi][safi],
11647 PEER_CAP_ORF_PREFIX_SM_RCV)
11648 || CHECK_FLAG(p->af_cap[afi][safi],
11649 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11650 || CHECK_FLAG(p->af_cap[afi][safi],
11651 PEER_CAP_ORF_PREFIX_RM_ADV)
11652 || CHECK_FLAG(p->af_cap[afi][safi],
11653 PEER_CAP_ORF_PREFIX_RM_RCV)
11654 || CHECK_FLAG(p->af_cap[afi][safi],
11655 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11656 json_object_object_add(json_addr, "afDependentCap",
11657 json_af);
11658 else
11659 json_object_free(json_af);
11660
772270f3
QY
11661 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11662 p->host, afi, safi);
d62a17ae 11663 orf_pfx_count = prefix_bgp_show_prefix_list(
11664 NULL, afi, orf_pfx_name, use_json);
11665
11666 if (CHECK_FLAG(p->af_sflags[afi][safi],
11667 PEER_STATUS_ORF_PREFIX_SEND)
11668 || orf_pfx_count) {
11669 if (CHECK_FLAG(p->af_sflags[afi][safi],
11670 PEER_STATUS_ORF_PREFIX_SEND))
11671 json_object_boolean_true_add(json_neigh,
11672 "orfSent");
11673 if (orf_pfx_count)
11674 json_object_int_add(json_addr, "orfRecvCounter",
11675 orf_pfx_count);
11676 }
11677 if (CHECK_FLAG(p->af_sflags[afi][safi],
11678 PEER_STATUS_ORF_WAIT_REFRESH))
11679 json_object_string_add(
11680 json_addr, "orfFirstUpdate",
11681 "deferredUntilORFOrRouteRefreshRecvd");
11682
11683 if (CHECK_FLAG(p->af_flags[afi][safi],
11684 PEER_FLAG_REFLECTOR_CLIENT))
11685 json_object_boolean_true_add(json_addr,
11686 "routeReflectorClient");
11687 if (CHECK_FLAG(p->af_flags[afi][safi],
11688 PEER_FLAG_RSERVER_CLIENT))
11689 json_object_boolean_true_add(json_addr,
11690 "routeServerClient");
11691 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11692 json_object_boolean_true_add(json_addr,
11693 "inboundSoftConfigPermit");
11694
11695 if (CHECK_FLAG(p->af_flags[afi][safi],
11696 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11697 json_object_boolean_true_add(
11698 json_addr,
11699 "privateAsNumsAllReplacedInUpdatesToNbr");
11700 else if (CHECK_FLAG(p->af_flags[afi][safi],
11701 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11702 json_object_boolean_true_add(
11703 json_addr,
11704 "privateAsNumsReplacedInUpdatesToNbr");
11705 else if (CHECK_FLAG(p->af_flags[afi][safi],
11706 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11707 json_object_boolean_true_add(
11708 json_addr,
11709 "privateAsNumsAllRemovedInUpdatesToNbr");
11710 else if (CHECK_FLAG(p->af_flags[afi][safi],
11711 PEER_FLAG_REMOVE_PRIVATE_AS))
11712 json_object_boolean_true_add(
11713 json_addr,
11714 "privateAsNumsRemovedInUpdatesToNbr");
11715
dcc68b5e
MS
11716 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11717 json_object_boolean_true_add(
11718 json_addr,
11719 bgp_addpath_names(p->addpath_type[afi][safi])
11720 ->type_json_name);
d62a17ae 11721
11722 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11723 json_object_string_add(json_addr,
11724 "overrideASNsInOutboundUpdates",
11725 "ifAspathEqualRemoteAs");
11726
11727 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11728 || CHECK_FLAG(p->af_flags[afi][safi],
11729 PEER_FLAG_FORCE_NEXTHOP_SELF))
11730 json_object_boolean_true_add(json_addr,
11731 "routerAlwaysNextHop");
11732 if (CHECK_FLAG(p->af_flags[afi][safi],
11733 PEER_FLAG_AS_PATH_UNCHANGED))
11734 json_object_boolean_true_add(
11735 json_addr, "unchangedAsPathPropogatedToNbr");
11736 if (CHECK_FLAG(p->af_flags[afi][safi],
11737 PEER_FLAG_NEXTHOP_UNCHANGED))
11738 json_object_boolean_true_add(
11739 json_addr, "unchangedNextHopPropogatedToNbr");
11740 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11741 json_object_boolean_true_add(
11742 json_addr, "unchangedMedPropogatedToNbr");
11743 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11744 || CHECK_FLAG(p->af_flags[afi][safi],
11745 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11746 if (CHECK_FLAG(p->af_flags[afi][safi],
11747 PEER_FLAG_SEND_COMMUNITY)
11748 && CHECK_FLAG(p->af_flags[afi][safi],
11749 PEER_FLAG_SEND_EXT_COMMUNITY))
11750 json_object_string_add(json_addr,
11751 "commAttriSentToNbr",
11752 "extendedAndStandard");
11753 else if (CHECK_FLAG(p->af_flags[afi][safi],
11754 PEER_FLAG_SEND_EXT_COMMUNITY))
11755 json_object_string_add(json_addr,
11756 "commAttriSentToNbr",
11757 "extended");
11758 else
11759 json_object_string_add(json_addr,
11760 "commAttriSentToNbr",
11761 "standard");
11762 }
11763 if (CHECK_FLAG(p->af_flags[afi][safi],
11764 PEER_FLAG_DEFAULT_ORIGINATE)) {
11765 if (p->default_rmap[afi][safi].name)
11766 json_object_string_add(
11767 json_addr, "defaultRouteMap",
11768 p->default_rmap[afi][safi].name);
11769
11770 if (paf && PAF_SUBGRP(paf)
11771 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11772 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11773 json_object_boolean_true_add(json_addr,
11774 "defaultSent");
11775 else
11776 json_object_boolean_true_add(json_addr,
11777 "defaultNotSent");
11778 }
11779
dff8f48d 11780 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 11781 if (is_evpn_enabled())
60466a63
QY
11782 json_object_boolean_true_add(
11783 json_addr, "advertiseAllVnis");
dff8f48d
MK
11784 }
11785
d62a17ae 11786 if (filter->plist[FILTER_IN].name
11787 || filter->dlist[FILTER_IN].name
11788 || filter->aslist[FILTER_IN].name
11789 || filter->map[RMAP_IN].name)
11790 json_object_boolean_true_add(json_addr,
11791 "inboundPathPolicyConfig");
11792 if (filter->plist[FILTER_OUT].name
11793 || filter->dlist[FILTER_OUT].name
11794 || filter->aslist[FILTER_OUT].name
11795 || filter->map[RMAP_OUT].name || filter->usmap.name)
11796 json_object_boolean_true_add(
11797 json_addr, "outboundPathPolicyConfig");
11798
11799 /* prefix-list */
11800 if (filter->plist[FILTER_IN].name)
11801 json_object_string_add(json_addr,
11802 "incomingUpdatePrefixFilterList",
11803 filter->plist[FILTER_IN].name);
11804 if (filter->plist[FILTER_OUT].name)
11805 json_object_string_add(json_addr,
11806 "outgoingUpdatePrefixFilterList",
11807 filter->plist[FILTER_OUT].name);
11808
11809 /* distribute-list */
11810 if (filter->dlist[FILTER_IN].name)
11811 json_object_string_add(
11812 json_addr, "incomingUpdateNetworkFilterList",
11813 filter->dlist[FILTER_IN].name);
11814 if (filter->dlist[FILTER_OUT].name)
11815 json_object_string_add(
11816 json_addr, "outgoingUpdateNetworkFilterList",
11817 filter->dlist[FILTER_OUT].name);
11818
11819 /* filter-list. */
11820 if (filter->aslist[FILTER_IN].name)
11821 json_object_string_add(json_addr,
11822 "incomingUpdateAsPathFilterList",
11823 filter->aslist[FILTER_IN].name);
11824 if (filter->aslist[FILTER_OUT].name)
11825 json_object_string_add(json_addr,
11826 "outgoingUpdateAsPathFilterList",
11827 filter->aslist[FILTER_OUT].name);
11828
11829 /* route-map. */
11830 if (filter->map[RMAP_IN].name)
11831 json_object_string_add(
11832 json_addr, "routeMapForIncomingAdvertisements",
11833 filter->map[RMAP_IN].name);
11834 if (filter->map[RMAP_OUT].name)
11835 json_object_string_add(
11836 json_addr, "routeMapForOutgoingAdvertisements",
11837 filter->map[RMAP_OUT].name);
11838
9dac9fc8 11839 /* ebgp-requires-policy (inbound) */
1d3fdccf 11840 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11841 && !bgp_inbound_policy_exists(p, filter))
11842 json_object_string_add(
11843 json_addr, "inboundEbgpRequiresPolicy",
11844 "Inbound updates discarded due to missing policy");
11845
11846 /* ebgp-requires-policy (outbound) */
1d3fdccf 11847 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11848 && (!bgp_outbound_policy_exists(p, filter)))
11849 json_object_string_add(
11850 json_addr, "outboundEbgpRequiresPolicy",
11851 "Outbound updates discarded due to missing policy");
11852
d62a17ae 11853 /* unsuppress-map */
11854 if (filter->usmap.name)
11855 json_object_string_add(json_addr,
11856 "selectiveUnsuppressRouteMap",
11857 filter->usmap.name);
11858
fa36596c
MK
11859 /* advertise-map */
11860 if (filter->advmap.aname) {
11861 json_advmap = json_object_new_object();
11862 json_object_string_add(json_advmap, "condition",
11863 filter->advmap.condition
11864 ? "EXIST"
11865 : "NON_EXIST");
11866 json_object_string_add(json_advmap, "conditionMap",
11867 filter->advmap.cname);
11868 json_object_string_add(json_advmap, "advertiseMap",
11869 filter->advmap.aname);
11870 json_object_string_add(json_advmap, "advertiseStatus",
11871 filter->advmap.update_type
11872 == ADVERTISE
11873 ? "Advertise"
11874 : "Withdraw");
11875 json_object_object_add(json_addr, "advertiseMap",
11876 json_advmap);
11877 }
11878
d62a17ae 11879 /* Receive prefix count */
11880 json_object_int_add(json_addr, "acceptedPrefixCounter",
11881 p->pcount[afi][safi]);
50e05855
AD
11882 if (paf && PAF_SUBGRP(paf))
11883 json_object_int_add(json_addr, "sentPrefixCounter",
11884 (PAF_SUBGRP(paf))->scount);
d62a17ae 11885
fde246e8
DA
11886 /* Maximum prefix */
11887 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
11888 json_object_int_add(json_addr, "prefixOutAllowedMax",
11889 p->pmax_out[afi][safi]);
11890
d62a17ae 11891 /* Maximum prefix */
11892 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11893 json_object_int_add(json_addr, "prefixAllowedMax",
11894 p->pmax[afi][safi]);
11895 if (CHECK_FLAG(p->af_flags[afi][safi],
11896 PEER_FLAG_MAX_PREFIX_WARNING))
11897 json_object_boolean_true_add(
11898 json_addr, "prefixAllowedMaxWarning");
11899 json_object_int_add(json_addr,
11900 "prefixAllowedWarningThresh",
11901 p->pmax_threshold[afi][safi]);
11902 if (p->pmax_restart[afi][safi])
11903 json_object_int_add(
11904 json_addr,
11905 "prefixAllowedRestartIntervalMsecs",
11906 p->pmax_restart[afi][safi] * 60000);
11907 }
2986cac2 11908 json_object_object_add(json_neigh,
36235319 11909 get_afi_safi_str(afi, safi, true),
d62a17ae 11910 json_addr);
11911
11912 } else {
11913 filter = &p->filter[afi][safi];
11914
11915 vty_out(vty, " For address family: %s\n",
5cb5f4d0 11916 get_afi_safi_str(afi, safi, false));
d62a17ae 11917
11918 if (peer_group_active(p))
11919 vty_out(vty, " %s peer-group member\n",
11920 p->group->name);
11921
11922 paf = peer_af_find(p, afi, safi);
11923 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 11924 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 11925 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
11926 vty_out(vty, " Packet Queue length %d\n",
11927 bpacket_queue_virtual_length(paf));
11928 } else {
11929 vty_out(vty, " Not part of any update group\n");
11930 }
11931 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11932 || CHECK_FLAG(p->af_cap[afi][safi],
11933 PEER_CAP_ORF_PREFIX_SM_RCV)
11934 || CHECK_FLAG(p->af_cap[afi][safi],
11935 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11936 || CHECK_FLAG(p->af_cap[afi][safi],
11937 PEER_CAP_ORF_PREFIX_RM_ADV)
11938 || CHECK_FLAG(p->af_cap[afi][safi],
11939 PEER_CAP_ORF_PREFIX_RM_RCV)
11940 || CHECK_FLAG(p->af_cap[afi][safi],
11941 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11942 vty_out(vty, " AF-dependant capabilities:\n");
11943
11944 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11945 || CHECK_FLAG(p->af_cap[afi][safi],
11946 PEER_CAP_ORF_PREFIX_SM_RCV)
11947 || CHECK_FLAG(p->af_cap[afi][safi],
11948 PEER_CAP_ORF_PREFIX_RM_ADV)
11949 || CHECK_FLAG(p->af_cap[afi][safi],
11950 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11951 vty_out(vty,
11952 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11953 ORF_TYPE_PREFIX);
11954 bgp_show_peer_afi_orf_cap(
11955 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11956 PEER_CAP_ORF_PREFIX_RM_ADV,
11957 PEER_CAP_ORF_PREFIX_SM_RCV,
11958 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
11959 }
11960 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11961 || CHECK_FLAG(p->af_cap[afi][safi],
11962 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11963 || CHECK_FLAG(p->af_cap[afi][safi],
11964 PEER_CAP_ORF_PREFIX_RM_ADV)
11965 || CHECK_FLAG(p->af_cap[afi][safi],
11966 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11967 vty_out(vty,
11968 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11969 ORF_TYPE_PREFIX_OLD);
11970 bgp_show_peer_afi_orf_cap(
11971 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11972 PEER_CAP_ORF_PREFIX_RM_ADV,
11973 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11974 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
11975 }
11976
772270f3
QY
11977 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11978 p->host, afi, safi);
d62a17ae 11979 orf_pfx_count = prefix_bgp_show_prefix_list(
11980 NULL, afi, orf_pfx_name, use_json);
11981
11982 if (CHECK_FLAG(p->af_sflags[afi][safi],
11983 PEER_STATUS_ORF_PREFIX_SEND)
11984 || orf_pfx_count) {
11985 vty_out(vty, " Outbound Route Filter (ORF):");
11986 if (CHECK_FLAG(p->af_sflags[afi][safi],
11987 PEER_STATUS_ORF_PREFIX_SEND))
11988 vty_out(vty, " sent;");
11989 if (orf_pfx_count)
11990 vty_out(vty, " received (%d entries)",
11991 orf_pfx_count);
11992 vty_out(vty, "\n");
11993 }
11994 if (CHECK_FLAG(p->af_sflags[afi][safi],
11995 PEER_STATUS_ORF_WAIT_REFRESH))
11996 vty_out(vty,
11997 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
11998
11999 if (CHECK_FLAG(p->af_flags[afi][safi],
12000 PEER_FLAG_REFLECTOR_CLIENT))
12001 vty_out(vty, " Route-Reflector Client\n");
12002 if (CHECK_FLAG(p->af_flags[afi][safi],
12003 PEER_FLAG_RSERVER_CLIENT))
12004 vty_out(vty, " Route-Server Client\n");
12005 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12006 vty_out(vty,
12007 " Inbound soft reconfiguration allowed\n");
12008
12009 if (CHECK_FLAG(p->af_flags[afi][safi],
12010 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12011 vty_out(vty,
12012 " Private AS numbers (all) replaced in updates to this neighbor\n");
12013 else if (CHECK_FLAG(p->af_flags[afi][safi],
12014 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12015 vty_out(vty,
12016 " Private AS numbers replaced in updates to this neighbor\n");
12017 else if (CHECK_FLAG(p->af_flags[afi][safi],
12018 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12019 vty_out(vty,
12020 " Private AS numbers (all) removed in updates to this neighbor\n");
12021 else if (CHECK_FLAG(p->af_flags[afi][safi],
12022 PEER_FLAG_REMOVE_PRIVATE_AS))
12023 vty_out(vty,
12024 " Private AS numbers removed in updates to this neighbor\n");
12025
dcc68b5e
MS
12026 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12027 vty_out(vty, " %s\n",
12028 bgp_addpath_names(p->addpath_type[afi][safi])
12029 ->human_description);
d62a17ae 12030
12031 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12032 vty_out(vty,
12033 " Override ASNs in outbound updates if aspath equals remote-as\n");
12034
12035 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12036 || CHECK_FLAG(p->af_flags[afi][safi],
12037 PEER_FLAG_FORCE_NEXTHOP_SELF))
12038 vty_out(vty, " NEXT_HOP is always this router\n");
12039 if (CHECK_FLAG(p->af_flags[afi][safi],
12040 PEER_FLAG_AS_PATH_UNCHANGED))
12041 vty_out(vty,
12042 " AS_PATH is propagated unchanged to this neighbor\n");
12043 if (CHECK_FLAG(p->af_flags[afi][safi],
12044 PEER_FLAG_NEXTHOP_UNCHANGED))
12045 vty_out(vty,
12046 " NEXT_HOP is propagated unchanged to this neighbor\n");
12047 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12048 vty_out(vty,
12049 " MED is propagated unchanged to this neighbor\n");
12050 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12051 || CHECK_FLAG(p->af_flags[afi][safi],
12052 PEER_FLAG_SEND_EXT_COMMUNITY)
12053 || CHECK_FLAG(p->af_flags[afi][safi],
12054 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12055 vty_out(vty,
12056 " Community attribute sent to this neighbor");
12057 if (CHECK_FLAG(p->af_flags[afi][safi],
12058 PEER_FLAG_SEND_COMMUNITY)
12059 && CHECK_FLAG(p->af_flags[afi][safi],
12060 PEER_FLAG_SEND_EXT_COMMUNITY)
12061 && CHECK_FLAG(p->af_flags[afi][safi],
12062 PEER_FLAG_SEND_LARGE_COMMUNITY))
12063 vty_out(vty, "(all)\n");
12064 else if (CHECK_FLAG(p->af_flags[afi][safi],
12065 PEER_FLAG_SEND_LARGE_COMMUNITY))
12066 vty_out(vty, "(large)\n");
12067 else if (CHECK_FLAG(p->af_flags[afi][safi],
12068 PEER_FLAG_SEND_EXT_COMMUNITY))
12069 vty_out(vty, "(extended)\n");
12070 else
12071 vty_out(vty, "(standard)\n");
12072 }
12073 if (CHECK_FLAG(p->af_flags[afi][safi],
12074 PEER_FLAG_DEFAULT_ORIGINATE)) {
12075 vty_out(vty, " Default information originate,");
12076
12077 if (p->default_rmap[afi][safi].name)
12078 vty_out(vty, " default route-map %s%s,",
12079 p->default_rmap[afi][safi].map ? "*"
12080 : "",
12081 p->default_rmap[afi][safi].name);
12082 if (paf && PAF_SUBGRP(paf)
12083 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12084 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12085 vty_out(vty, " default sent\n");
12086 else
12087 vty_out(vty, " default not sent\n");
12088 }
12089
dff8f48d
MK
12090 /* advertise-vni-all */
12091 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12092 if (is_evpn_enabled())
dff8f48d
MK
12093 vty_out(vty, " advertise-all-vni\n");
12094 }
12095
d62a17ae 12096 if (filter->plist[FILTER_IN].name
12097 || filter->dlist[FILTER_IN].name
12098 || filter->aslist[FILTER_IN].name
12099 || filter->map[RMAP_IN].name)
12100 vty_out(vty, " Inbound path policy configured\n");
12101 if (filter->plist[FILTER_OUT].name
12102 || filter->dlist[FILTER_OUT].name
12103 || filter->aslist[FILTER_OUT].name
12104 || filter->map[RMAP_OUT].name || filter->usmap.name)
12105 vty_out(vty, " Outbound path policy configured\n");
12106
12107 /* prefix-list */
12108 if (filter->plist[FILTER_IN].name)
12109 vty_out(vty,
12110 " Incoming update prefix filter list is %s%s\n",
12111 filter->plist[FILTER_IN].plist ? "*" : "",
12112 filter->plist[FILTER_IN].name);
12113 if (filter->plist[FILTER_OUT].name)
12114 vty_out(vty,
12115 " Outgoing update prefix filter list is %s%s\n",
12116 filter->plist[FILTER_OUT].plist ? "*" : "",
12117 filter->plist[FILTER_OUT].name);
12118
12119 /* distribute-list */
12120 if (filter->dlist[FILTER_IN].name)
12121 vty_out(vty,
12122 " Incoming update network filter list is %s%s\n",
12123 filter->dlist[FILTER_IN].alist ? "*" : "",
12124 filter->dlist[FILTER_IN].name);
12125 if (filter->dlist[FILTER_OUT].name)
12126 vty_out(vty,
12127 " Outgoing update network filter list is %s%s\n",
12128 filter->dlist[FILTER_OUT].alist ? "*" : "",
12129 filter->dlist[FILTER_OUT].name);
12130
12131 /* filter-list. */
12132 if (filter->aslist[FILTER_IN].name)
12133 vty_out(vty,
12134 " Incoming update AS path filter list is %s%s\n",
12135 filter->aslist[FILTER_IN].aslist ? "*" : "",
12136 filter->aslist[FILTER_IN].name);
12137 if (filter->aslist[FILTER_OUT].name)
12138 vty_out(vty,
12139 " Outgoing update AS path filter list is %s%s\n",
12140 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12141 filter->aslist[FILTER_OUT].name);
12142
12143 /* route-map. */
12144 if (filter->map[RMAP_IN].name)
12145 vty_out(vty,
12146 " Route map for incoming advertisements is %s%s\n",
12147 filter->map[RMAP_IN].map ? "*" : "",
12148 filter->map[RMAP_IN].name);
12149 if (filter->map[RMAP_OUT].name)
12150 vty_out(vty,
12151 " Route map for outgoing advertisements is %s%s\n",
12152 filter->map[RMAP_OUT].map ? "*" : "",
12153 filter->map[RMAP_OUT].name);
12154
9dac9fc8 12155 /* ebgp-requires-policy (inbound) */
1d3fdccf 12156 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12157 && !bgp_inbound_policy_exists(p, filter))
12158 vty_out(vty,
12159 " Inbound updates discarded due to missing policy\n");
12160
12161 /* ebgp-requires-policy (outbound) */
1d3fdccf 12162 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12163 && !bgp_outbound_policy_exists(p, filter))
12164 vty_out(vty,
12165 " Outbound updates discarded due to missing policy\n");
12166
d62a17ae 12167 /* unsuppress-map */
12168 if (filter->usmap.name)
12169 vty_out(vty,
12170 " Route map for selective unsuppress is %s%s\n",
12171 filter->usmap.map ? "*" : "",
12172 filter->usmap.name);
12173
7f7940e6
MK
12174 /* advertise-map */
12175 if (filter->advmap.aname && filter->advmap.cname)
12176 vty_out(vty,
12177 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12178 filter->advmap.condition ? "EXIST"
12179 : "NON_EXIST",
12180 filter->advmap.cmap ? "*" : "",
12181 filter->advmap.cname,
12182 filter->advmap.amap ? "*" : "",
12183 filter->advmap.aname,
fa36596c 12184 filter->advmap.update_type == ADVERTISE
c385f82a
MK
12185 ? "Advertise"
12186 : "Withdraw");
7f7940e6 12187
d62a17ae 12188 /* Receive prefix count */
6cde4b45 12189 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12190 p->pcount[afi][safi]);
d62a17ae 12191
fde246e8
DA
12192 /* maximum-prefix-out */
12193 if (CHECK_FLAG(p->af_flags[afi][safi],
12194 PEER_FLAG_MAX_PREFIX_OUT))
12195 vty_out(vty,
6cde4b45 12196 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12197 p->pmax_out[afi][safi]);
12198
d62a17ae 12199 /* Maximum prefix */
12200 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12201 vty_out(vty,
6cde4b45 12202 " Maximum prefixes allowed %u%s\n",
d62a17ae 12203 p->pmax[afi][safi],
12204 CHECK_FLAG(p->af_flags[afi][safi],
12205 PEER_FLAG_MAX_PREFIX_WARNING)
12206 ? " (warning-only)"
12207 : "");
12208 vty_out(vty, " Threshold for warning message %d%%",
12209 p->pmax_threshold[afi][safi]);
12210 if (p->pmax_restart[afi][safi])
12211 vty_out(vty, ", restart interval %d min",
12212 p->pmax_restart[afi][safi]);
12213 vty_out(vty, "\n");
12214 }
12215
12216 vty_out(vty, "\n");
12217 }
12218}
12219
9f049418 12220static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12221 json_object *json)
718e3744 12222{
d62a17ae 12223 struct bgp *bgp;
12224 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12225 char timebuf[BGP_UPTIME_LEN];
12226 char dn_flag[2];
d62a17ae 12227 afi_t afi;
12228 safi_t safi;
d7c0a89a
QY
12229 uint16_t i;
12230 uint8_t *msg;
d62a17ae 12231 json_object *json_neigh = NULL;
12232 time_t epoch_tbuf;
4ab46701 12233 uint32_t sync_tcp_mss;
718e3744 12234
d62a17ae 12235 bgp = p->bgp;
12236
12237 if (use_json)
12238 json_neigh = json_object_new_object();
12239
12240 memset(dn_flag, '\0', sizeof(dn_flag));
12241 if (!p->conf_if && peer_dynamic_neighbor(p))
12242 dn_flag[0] = '*';
12243
12244 if (!use_json) {
12245 if (p->conf_if) /* Configured interface name. */
12246 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12247 BGP_PEER_SU_UNSPEC(p)
12248 ? "None"
12249 : sockunion2str(&p->su, buf,
12250 SU_ADDRSTRLEN));
12251 else /* Configured IP address. */
12252 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12253 p->host);
12254 }
12255
12256 if (use_json) {
12257 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12258 json_object_string_add(json_neigh, "bgpNeighborAddr",
12259 "none");
12260 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12261 json_object_string_add(
12262 json_neigh, "bgpNeighborAddr",
12263 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12264
12265 json_object_int_add(json_neigh, "remoteAs", p->as);
12266
12267 if (p->change_local_as)
12268 json_object_int_add(json_neigh, "localAs",
12269 p->change_local_as);
12270 else
12271 json_object_int_add(json_neigh, "localAs", p->local_as);
12272
12273 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12274 json_object_boolean_true_add(json_neigh,
12275 "localAsNoPrepend");
12276
12277 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12278 json_object_boolean_true_add(json_neigh,
12279 "localAsReplaceAs");
12280 } else {
12281 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12282 || (p->as_type == AS_INTERNAL))
12283 vty_out(vty, "remote AS %u, ", p->as);
12284 else
12285 vty_out(vty, "remote AS Unspecified, ");
12286 vty_out(vty, "local AS %u%s%s, ",
12287 p->change_local_as ? p->change_local_as : p->local_as,
12288 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12289 ? " no-prepend"
12290 : "",
12291 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12292 ? " replace-as"
12293 : "");
12294 }
faa16034
DS
12295 /* peer type internal or confed-internal */
12296 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12297 if (use_json) {
12298 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12299 json_object_boolean_true_add(
12300 json_neigh, "nbrConfedInternalLink");
12301 else
12302 json_object_boolean_true_add(json_neigh,
12303 "nbrInternalLink");
12304 } else {
12305 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12306 vty_out(vty, "confed-internal link\n");
12307 else
12308 vty_out(vty, "internal link\n");
12309 }
faa16034
DS
12310 /* peer type external or confed-external */
12311 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12312 if (use_json) {
12313 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12314 json_object_boolean_true_add(
12315 json_neigh, "nbrConfedExternalLink");
12316 else
12317 json_object_boolean_true_add(json_neigh,
12318 "nbrExternalLink");
12319 } else {
12320 if (bgp_confederation_peers_check(bgp, p->as))
12321 vty_out(vty, "confed-external link\n");
12322 else
12323 vty_out(vty, "external link\n");
12324 }
faa16034
DS
12325 } else {
12326 if (use_json)
12327 json_object_boolean_true_add(json_neigh,
12328 "nbrUnspecifiedLink");
12329 else
12330 vty_out(vty, "unspecified link\n");
d62a17ae 12331 }
12332
12333 /* Description. */
12334 if (p->desc) {
12335 if (use_json)
12336 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12337 else
12338 vty_out(vty, " Description: %s\n", p->desc);
12339 }
12340
12341 if (p->hostname) {
12342 if (use_json) {
12343 if (p->hostname)
12344 json_object_string_add(json_neigh, "hostname",
12345 p->hostname);
12346
12347 if (p->domainname)
12348 json_object_string_add(json_neigh, "domainname",
12349 p->domainname);
12350 } else {
12351 if (p->domainname && (p->domainname[0] != '\0'))
12352 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12353 p->domainname);
12354 else
12355 vty_out(vty, "Hostname: %s\n", p->hostname);
12356 }
12357 }
12358
12359 /* Peer-group */
12360 if (p->group) {
12361 if (use_json) {
12362 json_object_string_add(json_neigh, "peerGroup",
12363 p->group->name);
12364
12365 if (dn_flag[0]) {
12366 struct prefix prefix, *range = NULL;
12367
0154d8ce
DS
12368 if (sockunion2hostprefix(&(p->su), &prefix))
12369 range = peer_group_lookup_dynamic_neighbor_range(
12370 p->group, &prefix);
d62a17ae 12371
12372 if (range) {
67d7e256 12373 json_object_string_addf(
d62a17ae 12374 json_neigh,
67d7e256
DA
12375 "peerSubnetRangeGroup", "%pFX",
12376 range);
d62a17ae 12377 }
12378 }
12379 } else {
12380 vty_out(vty,
12381 " Member of peer-group %s for session parameters\n",
12382 p->group->name);
12383
12384 if (dn_flag[0]) {
12385 struct prefix prefix, *range = NULL;
12386
0154d8ce
DS
12387 if (sockunion2hostprefix(&(p->su), &prefix))
12388 range = peer_group_lookup_dynamic_neighbor_range(
12389 p->group, &prefix);
d62a17ae 12390
12391 if (range) {
d62a17ae 12392 vty_out(vty,
1b78780b
DL
12393 " Belongs to the subnet range group: %pFX\n",
12394 range);
d62a17ae 12395 }
12396 }
12397 }
12398 }
12399
12400 if (use_json) {
12401 /* Administrative shutdown. */
cb9196e7
DS
12402 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12403 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12404 json_object_boolean_true_add(json_neigh,
12405 "adminShutDown");
12406
12407 /* BGP Version. */
12408 json_object_int_add(json_neigh, "bgpVersion", 4);
c949c771
DA
12409 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12410 &p->remote_id);
12411 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12412 &bgp->router_id);
d62a17ae 12413
12414 /* Confederation */
12415 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12416 && bgp_confederation_peers_check(bgp, p->as))
12417 json_object_boolean_true_add(json_neigh,
12418 "nbrCommonAdmin");
12419
12420 /* Status. */
12421 json_object_string_add(
12422 json_neigh, "bgpState",
12423 lookup_msg(bgp_status_msg, p->status, NULL));
12424
feb17238 12425 if (peer_established(p)) {
d62a17ae 12426 time_t uptime;
d62a17ae 12427
12428 uptime = bgp_clock();
12429 uptime -= p->uptime;
d62a17ae 12430 epoch_tbuf = time(NULL) - uptime;
12431
d3c7efed
DS
12432 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12433 uptime * 1000);
d62a17ae 12434 json_object_string_add(json_neigh, "bgpTimerUpString",
12435 peer_uptime(p->uptime, timebuf,
12436 BGP_UPTIME_LEN, 0,
12437 NULL));
12438 json_object_int_add(json_neigh,
12439 "bgpTimerUpEstablishedEpoch",
12440 epoch_tbuf);
12441 }
12442
12443 else if (p->status == Active) {
12444 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12445 json_object_string_add(json_neigh, "bgpStateIs",
12446 "passive");
12447 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12448 json_object_string_add(json_neigh, "bgpStateIs",
12449 "passiveNSF");
12450 }
12451
12452 /* read timer */
12453 time_t uptime;
a2700b50 12454 struct tm tm;
d62a17ae 12455
12456 uptime = bgp_clock();
12457 uptime -= p->readtime;
a2700b50
MS
12458 gmtime_r(&uptime, &tm);
12459
d62a17ae 12460 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
12461 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12462 + (tm.tm_hour * 3600000));
d62a17ae 12463
12464 uptime = bgp_clock();
12465 uptime -= p->last_write;
a2700b50
MS
12466 gmtime_r(&uptime, &tm);
12467
d62a17ae 12468 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
12469 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12470 + (tm.tm_hour * 3600000));
d62a17ae 12471
12472 uptime = bgp_clock();
12473 uptime -= p->update_time;
a2700b50
MS
12474 gmtime_r(&uptime, &tm);
12475
d62a17ae 12476 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
12477 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12478 + (tm.tm_hour * 3600000));
d62a17ae 12479
12480 /* Configured timer values. */
12481 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12482 p->v_holdtime * 1000);
12483 json_object_int_add(json_neigh,
12484 "bgpTimerKeepAliveIntervalMsecs",
12485 p->v_keepalive * 1000);
d43114f3
DS
12486 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12487 json_object_int_add(json_neigh,
12488 "bgpTimerDelayOpenTimeMsecs",
12489 p->v_delayopen * 1000);
12490 }
12491
4ab46701
AR
12492 /* Configured and Synced tcp-mss value for peer */
12493 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12494 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12495 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12496 p->tcp_mss);
12497 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12498 sync_tcp_mss);
12499 }
12500
b90a8e13 12501 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12502 json_object_int_add(json_neigh,
12503 "bgpTimerConfiguredHoldTimeMsecs",
12504 p->holdtime * 1000);
12505 json_object_int_add(
12506 json_neigh,
12507 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12508 p->keepalive * 1000);
5d5393b9
DL
12509 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12510 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12511 json_object_int_add(json_neigh,
12512 "bgpTimerConfiguredHoldTimeMsecs",
12513 bgp->default_holdtime);
12514 json_object_int_add(
12515 json_neigh,
12516 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12517 bgp->default_keepalive);
d62a17ae 12518 }
d08c0c80
DA
12519
12520 /* Extended Optional Parameters Length for BGP OPEN Message */
12521 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12522 json_object_boolean_true_add(
12523 json_neigh, "extendedOptionalParametersLength");
12524 else
12525 json_object_boolean_false_add(
12526 json_neigh, "extendedOptionalParametersLength");
d62a17ae 12527 } else {
12528 /* Administrative shutdown. */
cb9196e7
DS
12529 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12530 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12531 vty_out(vty, " Administratively shut down\n");
12532
12533 /* BGP Version. */
12534 vty_out(vty, " BGP version 4");
0e38aeb4 12535 vty_out(vty, ", remote router ID %s",
d62a17ae 12536 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
12537 vty_out(vty, ", local router ID %s\n",
12538 inet_ntop(AF_INET, &bgp->router_id, buf1,
12539 sizeof(buf1)));
d62a17ae 12540
12541 /* Confederation */
12542 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12543 && bgp_confederation_peers_check(bgp, p->as))
12544 vty_out(vty,
12545 " Neighbor under common administration\n");
12546
12547 /* Status. */
12548 vty_out(vty, " BGP state = %s",
12549 lookup_msg(bgp_status_msg, p->status, NULL));
12550
feb17238 12551 if (peer_established(p))
d62a17ae 12552 vty_out(vty, ", up for %8s",
12553 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12554 0, NULL));
12555
12556 else if (p->status == Active) {
12557 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12558 vty_out(vty, " (passive)");
12559 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12560 vty_out(vty, " (NSF passive)");
12561 }
12562 vty_out(vty, "\n");
12563
12564 /* read timer */
12565 vty_out(vty, " Last read %s",
12566 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12567 NULL));
12568 vty_out(vty, ", Last write %s\n",
12569 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12570 NULL));
12571
12572 /* Configured timer values. */
12573 vty_out(vty,
12574 " Hold time is %d, keepalive interval is %d seconds\n",
12575 p->v_holdtime, p->v_keepalive);
b90a8e13 12576 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12577 vty_out(vty, " Configured hold time is %d",
12578 p->holdtime);
12579 vty_out(vty, ", keepalive interval is %d seconds\n",
12580 p->keepalive);
5d5393b9
DL
12581 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12582 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12583 vty_out(vty, " Configured hold time is %d",
12584 bgp->default_holdtime);
12585 vty_out(vty, ", keepalive interval is %d seconds\n",
12586 bgp->default_keepalive);
d62a17ae 12587 }
d43114f3
DS
12588 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12589 vty_out(vty,
12590 " Configured DelayOpenTime is %d seconds\n",
12591 p->delayopen);
4ab46701
AR
12592
12593 /* Configured and synced tcp-mss value for peer */
12594 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12595 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12596 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12597 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12598 }
d08c0c80
DA
12599
12600 /* Extended Optional Parameters Length for BGP OPEN Message */
12601 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12602 vty_out(vty,
12603 " Extended Optional Parameters Length is enabled\n");
d62a17ae 12604 }
12605 /* Capability. */
10711563
DA
12606 if (peer_established(p) &&
12607 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
12608 if (use_json) {
12609 json_object *json_cap = NULL;
d62a17ae 12610
10711563 12611 json_cap = json_object_new_object();
d62a17ae 12612
10711563
DA
12613 /* AS4 */
12614 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
12615 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12616 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
12617 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
ef56aee4 12618 json_object_string_add(
10711563 12619 json_cap, "4byteAs",
ef56aee4 12620 "advertisedAndReceived");
10711563
DA
12621 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
12622 json_object_string_add(json_cap,
12623 "4byteAs",
12624 "advertised");
12625 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12626 json_object_string_add(json_cap,
12627 "4byteAs",
12628 "received");
12629 }
ef56aee4 12630
10711563
DA
12631 /* Extended Message Support */
12632 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
12633 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
12634 json_object_string_add(json_cap,
12635 "extendedMessage",
12636 "advertisedAndReceived");
12637 else if (CHECK_FLAG(p->cap,
12638 PEER_CAP_EXTENDED_MESSAGE_ADV))
12639 json_object_string_add(json_cap,
12640 "extendedMessage",
12641 "advertised");
12642 else if (CHECK_FLAG(p->cap,
12643 PEER_CAP_EXTENDED_MESSAGE_RCV))
12644 json_object_string_add(json_cap,
12645 "extendedMessage",
12646 "received");
ef56aee4 12647
10711563
DA
12648 /* AddPath */
12649 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
12650 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
12651 json_object *json_add = NULL;
12652 const char *print_store;
d62a17ae 12653
10711563 12654 json_add = json_object_new_object();
d62a17ae 12655
10711563
DA
12656 FOREACH_AFI_SAFI (afi, safi) {
12657 json_object *json_sub = NULL;
12658 json_sub = json_object_new_object();
12659 print_store = get_afi_safi_str(
12660 afi, safi, true);
d62a17ae 12661
10711563
DA
12662 if (CHECK_FLAG(
12663 p->af_cap[afi][safi],
12664 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12665 CHECK_FLAG(
12666 p->af_cap[afi][safi],
12667 PEER_CAP_ADDPATH_AF_TX_RCV)) {
05c7a1cc
QY
12668 if (CHECK_FLAG(
12669 p->af_cap[afi]
12670 [safi],
10711563
DA
12671 PEER_CAP_ADDPATH_AF_TX_ADV) &&
12672 CHECK_FLAG(
05c7a1cc
QY
12673 p->af_cap[afi]
12674 [safi],
10711563
DA
12675 PEER_CAP_ADDPATH_AF_TX_RCV))
12676 json_object_boolean_true_add(
12677 json_sub,
12678 "txAdvertisedAndReceived");
12679 else if (
12680 CHECK_FLAG(
12681 p->af_cap[afi]
12682 [safi],
12683 PEER_CAP_ADDPATH_AF_TX_ADV))
12684 json_object_boolean_true_add(
12685 json_sub,
12686 "txAdvertised");
12687 else if (
12688 CHECK_FLAG(
12689 p->af_cap[afi]
12690 [safi],
12691 PEER_CAP_ADDPATH_AF_TX_RCV))
12692 json_object_boolean_true_add(
12693 json_sub,
12694 "txReceived");
12695 }
d62a17ae 12696
10711563
DA
12697 if (CHECK_FLAG(
12698 p->af_cap[afi][safi],
12699 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12700 CHECK_FLAG(
12701 p->af_cap[afi][safi],
12702 PEER_CAP_ADDPATH_AF_RX_RCV)) {
05c7a1cc
QY
12703 if (CHECK_FLAG(
12704 p->af_cap[afi]
12705 [safi],
10711563
DA
12706 PEER_CAP_ADDPATH_AF_RX_ADV) &&
12707 CHECK_FLAG(
12708 p->af_cap[afi]
12709 [safi],
12710 PEER_CAP_ADDPATH_AF_RX_RCV))
12711 json_object_boolean_true_add(
12712 json_sub,
12713 "rxAdvertisedAndReceived");
12714 else if (
12715 CHECK_FLAG(
12716 p->af_cap[afi]
12717 [safi],
12718 PEER_CAP_ADDPATH_AF_RX_ADV))
12719 json_object_boolean_true_add(
12720 json_sub,
12721 "rxAdvertised");
12722 else if (
12723 CHECK_FLAG(
12724 p->af_cap[afi]
12725 [safi],
12726 PEER_CAP_ADDPATH_AF_RX_RCV))
12727 json_object_boolean_true_add(
12728 json_sub,
12729 "rxReceived");
05c7a1cc
QY
12730 }
12731
10711563
DA
12732 if (CHECK_FLAG(
12733 p->af_cap[afi][safi],
12734 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12735 CHECK_FLAG(
12736 p->af_cap[afi][safi],
12737 PEER_CAP_ADDPATH_AF_TX_RCV) ||
12738 CHECK_FLAG(
12739 p->af_cap[afi][safi],
12740 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12741 CHECK_FLAG(
12742 p->af_cap[afi][safi],
12743 PEER_CAP_ADDPATH_AF_RX_RCV))
12744 json_object_object_add(
12745 json_add, print_store,
12746 json_sub);
12747 else
12748 json_object_free(json_sub);
d62a17ae 12749 }
12750
10711563
DA
12751 json_object_object_add(json_cap, "addPath",
12752 json_add);
12753 }
d62a17ae 12754
10711563
DA
12755 /* Dynamic */
12756 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
12757 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
12758 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
12759 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
12760 json_object_string_add(
12761 json_cap, "dynamic",
12762 "advertisedAndReceived");
12763 else if (CHECK_FLAG(p->cap,
12764 PEER_CAP_DYNAMIC_ADV))
12765 json_object_string_add(json_cap,
12766 "dynamic",
12767 "advertised");
12768 else if (CHECK_FLAG(p->cap,
12769 PEER_CAP_DYNAMIC_RCV))
12770 json_object_string_add(json_cap,
12771 "dynamic",
12772 "received");
12773 }
d62a17ae 12774
10711563
DA
12775 /* Extended nexthop */
12776 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
12777 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12778 json_object *json_nxt = NULL;
12779 const char *print_store;
d62a17ae 12780
d62a17ae 12781
10711563
DA
12782 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
12783 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12784 json_object_string_add(
12785 json_cap, "extendedNexthop",
12786 "advertisedAndReceived");
12787 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
12788 json_object_string_add(
12789 json_cap, "extendedNexthop",
12790 "advertised");
12791 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12792 json_object_string_add(
12793 json_cap, "extendedNexthop",
12794 "received");
d62a17ae 12795
10711563
DA
12796 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
12797 json_nxt = json_object_new_object();
d62a17ae 12798
10711563
DA
12799 for (safi = SAFI_UNICAST;
12800 safi < SAFI_MAX; safi++) {
12801 if (CHECK_FLAG(
12802 p->af_cap[AFI_IP]
12803 [safi],
12804 PEER_CAP_ENHE_AF_RCV)) {
12805 print_store =
12806 get_afi_safi_str(
d62a17ae 12807 AFI_IP,
10711563
DA
12808 safi,
12809 true);
12810 json_object_string_add(
12811 json_nxt,
12812 print_store,
12813 "recieved"); /* misspelled for compatibility */
d62a17ae 12814 }
d62a17ae 12815 }
10711563
DA
12816 json_object_object_add(
12817 json_cap,
12818 "extendedNexthopFamililesByPeer",
12819 json_nxt);
d62a17ae 12820 }
10711563 12821 }
d62a17ae 12822
10711563
DA
12823 /* Long-lived Graceful Restart */
12824 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
12825 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
12826 json_object *json_llgr = NULL;
12827 const char *afi_safi_str;
8606be87 12828
10711563
DA
12829 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
12830 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12831 json_object_string_add(
12832 json_cap,
12833 "longLivedGracefulRestart",
12834 "advertisedAndReceived");
12835 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
12836 json_object_string_add(
12837 json_cap,
12838 "longLivedGracefulRestart",
12839 "advertised");
12840 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12841 json_object_string_add(
12842 json_cap,
12843 "longLivedGracefulRestart",
12844 "received");
8606be87 12845
10711563
DA
12846 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
12847 json_llgr = json_object_new_object();
8606be87 12848
10711563
DA
12849 FOREACH_AFI_SAFI (afi, safi) {
12850 if (CHECK_FLAG(
12851 p->af_cap[afi]
12852 [safi],
12853 PEER_CAP_ENHE_AF_RCV)) {
12854 afi_safi_str =
12855 get_afi_safi_str(
8606be87
DA
12856 afi,
12857 safi,
12858 true);
10711563
DA
12859 json_object_string_add(
12860 json_llgr,
12861 afi_safi_str,
12862 "received");
8606be87 12863 }
8606be87 12864 }
10711563
DA
12865 json_object_object_add(
12866 json_cap,
12867 "longLivedGracefulRestartByPeer",
12868 json_llgr);
8606be87 12869 }
10711563 12870 }
8606be87 12871
10711563
DA
12872 /* Route Refresh */
12873 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
12874 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
12875 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
12876 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
12877 (CHECK_FLAG(p->cap,
12878 PEER_CAP_REFRESH_NEW_RCV) ||
12879 CHECK_FLAG(p->cap,
12880 PEER_CAP_REFRESH_OLD_RCV))) {
12881 if (CHECK_FLAG(
12882 p->cap,
12883 PEER_CAP_REFRESH_OLD_RCV) &&
12884 CHECK_FLAG(
12885 p->cap,
12886 PEER_CAP_REFRESH_NEW_RCV))
12887 json_object_string_add(
12888 json_cap,
12889 "routeRefresh",
12890 "advertisedAndReceivedOldNew");
12891 else {
d62a17ae 12892 if (CHECK_FLAG(
12893 p->cap,
10711563 12894 PEER_CAP_REFRESH_OLD_RCV))
d62a17ae 12895 json_object_string_add(
12896 json_cap,
12897 "routeRefresh",
10711563
DA
12898 "advertisedAndReceivedOld");
12899 else
12900 json_object_string_add(
12901 json_cap,
12902 "routeRefresh",
12903 "advertisedAndReceivedNew");
d62a17ae 12904 }
10711563
DA
12905 } else if (CHECK_FLAG(p->cap,
12906 PEER_CAP_REFRESH_ADV))
12907 json_object_string_add(json_cap,
12908 "routeRefresh",
12909 "advertised");
12910 else if (CHECK_FLAG(p->cap,
12911 PEER_CAP_REFRESH_NEW_RCV) ||
12912 CHECK_FLAG(p->cap,
12913 PEER_CAP_REFRESH_OLD_RCV))
12914 json_object_string_add(json_cap,
12915 "routeRefresh",
12916 "received");
12917 }
d62a17ae 12918
10711563
DA
12919 /* Enhanced Route Refresh */
12920 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
12921 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
12922 if (CHECK_FLAG(p->cap,
12923 PEER_CAP_ENHANCED_RR_ADV) &&
12924 CHECK_FLAG(p->cap,
12925 PEER_CAP_ENHANCED_RR_RCV))
d77114b7 12926 json_object_string_add(
10711563
DA
12927 json_cap,
12928 "enhancedRouteRefresh",
12929 "advertisedAndReceived");
12930 else if (CHECK_FLAG(p->cap,
12931 PEER_CAP_ENHANCED_RR_ADV))
d77114b7 12932 json_object_string_add(
10711563
DA
12933 json_cap,
12934 "enhancedRouteRefresh",
12935 "advertised");
12936 else if (CHECK_FLAG(p->cap,
9af52ccf 12937 PEER_CAP_ENHANCED_RR_RCV))
10711563
DA
12938 json_object_string_add(
12939 json_cap,
12940 "enhancedRouteRefresh",
12941 "received");
12942 }
d77114b7 12943
10711563
DA
12944 /* Multiprotocol Extensions */
12945 json_object *json_multi = NULL;
d77114b7 12946
10711563 12947 json_multi = json_object_new_object();
d77114b7 12948
10711563
DA
12949 FOREACH_AFI_SAFI (afi, safi) {
12950 if (p->afc_adv[afi][safi] ||
12951 p->afc_recv[afi][safi]) {
12952 json_object *json_exten = NULL;
12953 json_exten = json_object_new_object();
12954
12955 if (p->afc_adv[afi][safi] &&
12956 p->afc_recv[afi][safi])
12957 json_object_boolean_true_add(
12958 json_exten,
9af52ccf 12959 "advertisedAndReceived");
10711563
DA
12960 else if (p->afc_adv[afi][safi])
12961 json_object_boolean_true_add(
12962 json_exten,
9af52ccf 12963 "advertised");
10711563
DA
12964 else if (p->afc_recv[afi][safi])
12965 json_object_boolean_true_add(
12966 json_exten, "received");
9af52ccf 12967
10711563
DA
12968 json_object_object_add(
12969 json_multi,
12970 get_afi_safi_str(afi, safi,
12971 true),
12972 json_exten);
12973 }
12974 }
12975 json_object_object_add(json_cap,
12976 "multiprotocolExtensions",
12977 json_multi);
d62a17ae 12978
10711563
DA
12979 /* Hostname capabilities */
12980 json_object *json_hname = NULL;
d62a17ae 12981
10711563 12982 json_hname = json_object_new_object();
d62a17ae 12983
10711563
DA
12984 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
12985 json_object_string_add(
12986 json_hname, "advHostName",
12987 bgp->peer_self->hostname
12988 ? bgp->peer_self->hostname
12989 : "n/a");
12990 json_object_string_add(
12991 json_hname, "advDomainName",
12992 bgp->peer_self->domainname
12993 ? bgp->peer_self->domainname
12994 : "n/a");
12995 }
d77114b7 12996
d77114b7 12997
10711563
DA
12998 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
12999 json_object_string_add(
13000 json_hname, "rcvHostName",
13001 p->hostname ? p->hostname : "n/a");
13002 json_object_string_add(
13003 json_hname, "rcvDomainName",
13004 p->domainname ? p->domainname : "n/a");
13005 }
d77114b7 13006
10711563
DA
13007 json_object_object_add(json_cap, "hostName",
13008 json_hname);
d77114b7 13009
10711563
DA
13010 /* Gracefull Restart */
13011 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13012 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13013 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13014 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
d77114b7 13015 json_object_string_add(
10711563
DA
13016 json_cap, "gracefulRestart",
13017 "advertisedAndReceived");
13018 else if (CHECK_FLAG(p->cap,
13019 PEER_CAP_RESTART_ADV))
d77114b7 13020 json_object_string_add(
10711563
DA
13021 json_cap,
13022 "gracefulRestartCapability",
13023 "advertised");
13024 else if (CHECK_FLAG(p->cap,
13025 PEER_CAP_RESTART_RCV))
13026 json_object_string_add(
13027 json_cap,
13028 "gracefulRestartCapability",
13029 "received");
d77114b7 13030
10711563
DA
13031 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13032 int restart_af_count = 0;
13033 json_object *json_restart = NULL;
13034 json_restart = json_object_new_object();
d62a17ae 13035
10711563
DA
13036 json_object_int_add(
13037 json_cap,
13038 "gracefulRestartRemoteTimerMsecs",
13039 p->v_gr_restart * 1000);
d62a17ae 13040
10711563 13041 FOREACH_AFI_SAFI (afi, safi) {
05c7a1cc
QY
13042 if (CHECK_FLAG(
13043 p->af_cap[afi]
13044 [safi],
10711563
DA
13045 PEER_CAP_RESTART_AF_RCV)) {
13046 json_object *json_sub =
13047 NULL;
13048 json_sub =
13049 json_object_new_object();
d62a17ae 13050
05c7a1cc
QY
13051 if (CHECK_FLAG(
13052 p->af_cap
13053 [afi]
13054 [safi],
10711563
DA
13055 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13056 json_object_boolean_true_add(
13057 json_sub,
13058 "preserved");
13059 restart_af_count++;
d62a17ae 13060 json_object_object_add(
10711563
DA
13061 json_restart,
13062 get_afi_safi_str(
13063 afi,
13064 safi,
13065 true),
13066 json_sub);
d62a17ae 13067 }
d62a17ae 13068 }
10711563
DA
13069 if (!restart_af_count) {
13070 json_object_string_add(
13071 json_cap,
13072 "addressFamiliesByPeer",
13073 "none");
13074 json_object_free(json_restart);
13075 } else
13076 json_object_object_add(
13077 json_cap,
13078 "addressFamiliesByPeer",
13079 json_restart);
d62a17ae 13080 }
10711563
DA
13081 }
13082 json_object_object_add(
13083 json_neigh, "neighborCapabilities", json_cap);
13084 } else {
13085 vty_out(vty, " Neighbor capabilities:\n");
13086
13087 /* AS4 */
13088 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13089 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13090 vty_out(vty, " 4 Byte AS:");
13091 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13092 vty_out(vty, " advertised");
13093 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13094 vty_out(vty, " %sreceived",
13095 CHECK_FLAG(p->cap,
13096 PEER_CAP_AS4_ADV)
13097 ? "and "
13098 : "");
13099 vty_out(vty, "\n");
13100 }
d62a17ae 13101
10711563
DA
13102 /* Extended Message Support */
13103 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13104 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13105 vty_out(vty, " Extended Message:");
ef56aee4 13106 if (CHECK_FLAG(p->cap,
10711563
DA
13107 PEER_CAP_EXTENDED_MESSAGE_ADV))
13108 vty_out(vty, " advertised");
13109 if (CHECK_FLAG(p->cap,
13110 PEER_CAP_EXTENDED_MESSAGE_RCV))
13111 vty_out(vty, " %sreceived",
13112 CHECK_FLAG(
13113 p->cap,
13114 PEER_CAP_EXTENDED_MESSAGE_ADV)
13115 ? "and "
13116 : "");
13117 vty_out(vty, "\n");
13118 }
d62a17ae 13119
10711563
DA
13120 /* AddPath */
13121 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13122 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13123 vty_out(vty, " AddPath:\n");
d62a17ae 13124
10711563 13125 FOREACH_AFI_SAFI (afi, safi) {
ef56aee4 13126 if (CHECK_FLAG(
10711563
DA
13127 p->af_cap[afi][safi],
13128 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13129 CHECK_FLAG(
13130 p->af_cap[afi][safi],
13131 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13132 vty_out(vty, " %s: TX ",
13133 get_afi_safi_str(
13134 afi, safi,
13135 false));
ef56aee4 13136
10711563
DA
13137 if (CHECK_FLAG(
13138 p->af_cap[afi]
13139 [safi],
13140 PEER_CAP_ADDPATH_AF_TX_ADV))
13141 vty_out(vty,
13142 "advertised");
d62a17ae 13143
05c7a1cc
QY
13144 if (CHECK_FLAG(
13145 p->af_cap[afi]
13146 [safi],
10711563 13147 PEER_CAP_ADDPATH_AF_TX_RCV))
05c7a1cc 13148 vty_out(vty,
10711563
DA
13149 "%sreceived",
13150 CHECK_FLAG(
13151 p->af_cap
13152 [afi]
13153 [safi],
13154 PEER_CAP_ADDPATH_AF_TX_ADV)
13155 ? " and "
13156 : "");
05c7a1cc 13157
10711563
DA
13158 vty_out(vty, "\n");
13159 }
d62a17ae 13160
9af52ccf 13161 if (CHECK_FLAG(
10711563
DA
13162 p->af_cap[afi][safi],
13163 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13164 CHECK_FLAG(
13165 p->af_cap[afi][safi],
13166 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13167 vty_out(vty, " %s: RX ",
5cb5f4d0 13168 get_afi_safi_str(
10711563
DA
13169 afi, safi,
13170 false));
d62a17ae 13171
05c7a1cc
QY
13172 if (CHECK_FLAG(
13173 p->af_cap[afi]
13174 [safi],
10711563 13175 PEER_CAP_ADDPATH_AF_RX_ADV))
05c7a1cc 13176 vty_out(vty,
10711563 13177 "advertised");
d62a17ae 13178
10711563
DA
13179 if (CHECK_FLAG(
13180 p->af_cap[afi]
13181 [safi],
13182 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc 13183 vty_out(vty,
10711563
DA
13184 "%sreceived",
13185 CHECK_FLAG(
13186 p->af_cap
13187 [afi]
13188 [safi],
13189 PEER_CAP_ADDPATH_AF_RX_ADV)
13190 ? " and "
05c7a1cc 13191 : "");
d62a17ae 13192
05c7a1cc 13193 vty_out(vty, "\n");
05c7a1cc 13194 }
d62a17ae 13195 }
10711563 13196 }
d62a17ae 13197
10711563
DA
13198 /* Dynamic */
13199 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13200 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13201 vty_out(vty, " Dynamic:");
13202 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13203 vty_out(vty, " advertised");
13204 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13205 vty_out(vty, " %sreceived",
13206 CHECK_FLAG(p->cap,
13207 PEER_CAP_DYNAMIC_ADV)
13208 ? "and "
13209 : "");
13210 vty_out(vty, "\n");
13211 }
d62a17ae 13212
10711563
DA
13213 /* Extended nexthop */
13214 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13215 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13216 vty_out(vty, " Extended nexthop:");
13217 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13218 vty_out(vty, " advertised");
13219 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13220 vty_out(vty, " %sreceived",
13221 CHECK_FLAG(p->cap,
13222 PEER_CAP_ENHE_ADV)
13223 ? "and "
13224 : "");
13225 vty_out(vty, "\n");
d62a17ae 13226
10711563 13227 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
57f7feb6 13228 vty_out(vty,
10711563
DA
13229 " Address families by peer:\n ");
13230 for (safi = SAFI_UNICAST;
13231 safi < SAFI_MAX; safi++)
13232 if (CHECK_FLAG(
13233 p->af_cap[AFI_IP]
13234 [safi],
13235 PEER_CAP_ENHE_AF_RCV))
13236 vty_out(vty,
13237 " %s\n",
13238 get_afi_safi_str(
13239 AFI_IP,
13240 safi,
13241 false));
d62a17ae 13242 }
10711563 13243 }
d62a17ae 13244
10711563
DA
13245 /* Long-lived Graceful Restart */
13246 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13247 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13248 vty_out(vty,
13249 " Long-lived Graceful Restart:");
13250 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13251 vty_out(vty, " advertised");
13252 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13253 vty_out(vty, " %sreceived",
13254 CHECK_FLAG(p->cap,
13255 PEER_CAP_LLGR_ADV)
13256 ? "and "
13257 : "");
13258 vty_out(vty, "\n");
8606be87 13259
10711563 13260 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
57f7feb6 13261 vty_out(vty,
10711563
DA
13262 " Address families by peer:\n");
13263 FOREACH_AFI_SAFI (afi, safi)
13264 if (CHECK_FLAG(
13265 p->af_cap[afi]
13266 [safi],
13267 PEER_CAP_LLGR_AF_RCV))
13268 vty_out(vty,
13269 " %s\n",
13270 get_afi_safi_str(
13271 afi,
13272 safi,
13273 false));
8606be87 13274 }
10711563 13275 }
8606be87 13276
10711563
DA
13277 /* Route Refresh */
13278 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13279 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13280 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13281 vty_out(vty, " Route refresh:");
13282 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13283 vty_out(vty, " advertised");
13284 if (CHECK_FLAG(p->cap,
13285 PEER_CAP_REFRESH_NEW_RCV) ||
13286 CHECK_FLAG(p->cap,
13287 PEER_CAP_REFRESH_OLD_RCV))
13288 vty_out(vty, " %sreceived(%s)",
13289 CHECK_FLAG(p->cap,
13290 PEER_CAP_REFRESH_ADV)
13291 ? "and "
13292 : "",
13293 (CHECK_FLAG(
13294 p->cap,
13295 PEER_CAP_REFRESH_OLD_RCV) &&
13296 CHECK_FLAG(
13297 p->cap,
13298 PEER_CAP_REFRESH_NEW_RCV))
13299 ? "old & new"
13300 : CHECK_FLAG(
13301 p->cap,
13302 PEER_CAP_REFRESH_OLD_RCV)
13303 ? "old"
13304 : "new");
d62a17ae 13305
d77114b7 13306 vty_out(vty, "\n");
10711563 13307 }
d62a17ae 13308
10711563
DA
13309 /* Enhanced Route Refresh */
13310 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13311 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13312 vty_out(vty, " Enhanced Route Refresh:");
13313 if (CHECK_FLAG(p->cap,
13314 PEER_CAP_ENHANCED_RR_ADV))
13315 vty_out(vty, " advertised");
13316 if (CHECK_FLAG(p->cap,
13317 PEER_CAP_ENHANCED_RR_RCV))
13318 vty_out(vty, " %sreceived",
13319 CHECK_FLAG(p->cap,
13320 PEER_CAP_REFRESH_ADV)
13321 ? "and "
13322 : "");
13323 vty_out(vty, "\n");
13324 }
13325
13326 /* Multiprotocol Extensions */
13327 FOREACH_AFI_SAFI (afi, safi)
13328 if (p->afc_adv[afi][safi] ||
13329 p->afc_recv[afi][safi]) {
13330 vty_out(vty, " Address Family %s:",
13331 get_afi_safi_str(afi, safi,
13332 false));
13333 if (p->afc_adv[afi][safi])
9af52ccf 13334 vty_out(vty, " advertised");
10711563 13335 if (p->afc_recv[afi][safi])
9af52ccf 13336 vty_out(vty, " %sreceived",
10711563 13337 p->afc_adv[afi][safi]
9af52ccf
DA
13338 ? "and "
13339 : "");
13340 vty_out(vty, "\n");
13341 }
13342
10711563
DA
13343 /* Hostname capability */
13344 vty_out(vty, " Hostname Capability:");
d62a17ae 13345
10711563
DA
13346 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13347 vty_out(vty,
13348 " advertised (name: %s,domain name: %s)",
13349 bgp->peer_self->hostname
13350 ? bgp->peer_self->hostname
13351 : "n/a",
13352 bgp->peer_self->domainname
13353 ? bgp->peer_self->domainname
13354 : "n/a");
13355 } else {
13356 vty_out(vty, " not advertised");
13357 }
d77114b7 13358
10711563
DA
13359 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13360 vty_out(vty,
13361 " received (name: %s,domain name: %s)",
13362 p->hostname ? p->hostname : "n/a",
13363 p->domainname ? p->domainname : "n/a");
13364 } else {
13365 vty_out(vty, " not received");
d62a17ae 13366 }
d62a17ae 13367
10711563 13368 vty_out(vty, "\n");
d77114b7 13369
10711563
DA
13370 /* Graceful Restart */
13371 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13372 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13373 vty_out(vty,
13374 " Graceful Restart Capability:");
13375 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13376 vty_out(vty, " advertised");
13377 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13378 vty_out(vty, " %sreceived",
13379 CHECK_FLAG(p->cap,
13380 PEER_CAP_RESTART_ADV)
13381 ? "and "
13382 : "");
d77114b7
MK
13383 vty_out(vty, "\n");
13384
10711563
DA
13385 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13386 int restart_af_count = 0;
d62a17ae 13387
10711563
DA
13388 vty_out(vty,
13389 " Remote Restart timer is %d seconds\n",
13390 p->v_gr_restart);
13391 vty_out(vty,
13392 " Address families by peer:\n ");
d62a17ae 13393
10711563
DA
13394 FOREACH_AFI_SAFI (afi, safi)
13395 if (CHECK_FLAG(
13396 p->af_cap[afi]
13397 [safi],
13398 PEER_CAP_RESTART_AF_RCV)) {
13399 vty_out(vty, "%s%s(%s)",
13400 restart_af_count
13401 ? ", "
13402 : "",
13403 get_afi_safi_str(
13404 afi,
13405 safi,
13406 false),
13407 CHECK_FLAG(
13408 p->af_cap
13409 [afi]
13410 [safi],
13411 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13412 ? "preserved"
13413 : "not preserved");
13414 restart_af_count++;
13415 }
13416 if (!restart_af_count)
13417 vty_out(vty, "none");
13418 vty_out(vty, "\n");
13419 }
13420 } /* Gracefull Restart */
d62a17ae 13421 }
13422 }
13423
13424 /* graceful restart information */
10711563
DA
13425 json_object *json_grace = NULL;
13426 json_object *json_grace_send = NULL;
13427 json_object *json_grace_recv = NULL;
13428 int eor_send_af_count = 0;
13429 int eor_receive_af_count = 0;
d62a17ae 13430
10711563
DA
13431 if (use_json) {
13432 json_grace = json_object_new_object();
13433 json_grace_send = json_object_new_object();
13434 json_grace_recv = json_object_new_object();
13435
13436 if ((peer_established(p)) &&
13437 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13438 FOREACH_AFI_SAFI (afi, safi) {
13439 if (CHECK_FLAG(p->af_sflags[afi][safi],
13440 PEER_STATUS_EOR_SEND)) {
13441 json_object_boolean_true_add(
13442 json_grace_send,
13443 get_afi_safi_str(afi, safi,
13444 true));
13445 eor_send_af_count++;
d62a17ae 13446 }
10711563
DA
13447 }
13448 FOREACH_AFI_SAFI (afi, safi) {
13449 if (CHECK_FLAG(p->af_sflags[afi][safi],
13450 PEER_STATUS_EOR_RECEIVED)) {
13451 json_object_boolean_true_add(
13452 json_grace_recv,
13453 get_afi_safi_str(afi, safi,
13454 true));
13455 eor_receive_af_count++;
d62a17ae 13456 }
13457 }
10711563
DA
13458 }
13459 json_object_object_add(json_grace, "endOfRibSend",
13460 json_grace_send);
13461 json_object_object_add(json_grace, "endOfRibRecv",
13462 json_grace_recv);
d62a17ae 13463
d62a17ae 13464
10711563
DA
13465 if (p->t_gr_restart)
13466 json_object_int_add(
13467 json_grace, "gracefulRestartTimerMsecs",
13468 thread_timer_remain_second(p->t_gr_restart) *
13469 1000);
2986cac2 13470
10711563
DA
13471 if (p->t_gr_stale)
13472 json_object_int_add(
13473 json_grace, "gracefulStalepathTimerMsecs",
13474 thread_timer_remain_second(p->t_gr_stale) *
13475 1000);
13476 /* more gr info in new format */
13477 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13478 json_object_object_add(json_neigh, "gracefulRestartInfo",
13479 json_grace);
13480 } else {
13481 vty_out(vty, " Graceful restart information:\n");
13482 if ((peer_established(p)) &&
13483 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13484
13485 vty_out(vty, " End-of-RIB send: ");
13486 FOREACH_AFI_SAFI (afi, safi) {
13487 if (CHECK_FLAG(p->af_sflags[afi][safi],
13488 PEER_STATUS_EOR_SEND)) {
13489 vty_out(vty, "%s%s",
13490 eor_send_af_count ? ", " : "",
13491 get_afi_safi_str(afi, safi,
13492 false));
13493 eor_send_af_count++;
d62a17ae 13494 }
10711563
DA
13495 }
13496 vty_out(vty, "\n");
13497 vty_out(vty, " End-of-RIB received: ");
13498 FOREACH_AFI_SAFI (afi, safi) {
13499 if (CHECK_FLAG(p->af_sflags[afi][safi],
13500 PEER_STATUS_EOR_RECEIVED)) {
13501 vty_out(vty, "%s%s",
13502 eor_receive_af_count ? ", "
13503 : "",
13504 get_afi_safi_str(afi, safi,
13505 false));
13506 eor_receive_af_count++;
d62a17ae 13507 }
d62a17ae 13508 }
10711563
DA
13509 vty_out(vty, "\n");
13510 }
d62a17ae 13511
10711563
DA
13512 if (p->t_gr_restart)
13513 vty_out(vty,
13514 " The remaining time of restart timer is %ld\n",
13515 thread_timer_remain_second(p->t_gr_restart));
d62a17ae 13516
10711563
DA
13517 if (p->t_gr_stale)
13518 vty_out(vty,
13519 " The remaining time of stalepath timer is %ld\n",
13520 thread_timer_remain_second(p->t_gr_stale));
2986cac2 13521
10711563
DA
13522 /* more gr info in new format */
13523 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13524 }
2986cac2 13525
d62a17ae 13526 if (use_json) {
13527 json_object *json_stat = NULL;
13528 json_stat = json_object_new_object();
13529 /* Packet counts. */
43aa5965
QY
13530
13531 atomic_size_t outq_count, inq_count;
13532 outq_count = atomic_load_explicit(&p->obuf->count,
13533 memory_order_relaxed);
13534 inq_count = atomic_load_explicit(&p->ibuf->count,
13535 memory_order_relaxed);
13536
13537 json_object_int_add(json_stat, "depthInq",
13538 (unsigned long)inq_count);
d62a17ae 13539 json_object_int_add(json_stat, "depthOutq",
43aa5965 13540 (unsigned long)outq_count);
0112e9e0
QY
13541 json_object_int_add(json_stat, "opensSent",
13542 atomic_load_explicit(&p->open_out,
13543 memory_order_relaxed));
13544 json_object_int_add(json_stat, "opensRecv",
13545 atomic_load_explicit(&p->open_in,
13546 memory_order_relaxed));
d62a17ae 13547 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
13548 atomic_load_explicit(&p->notify_out,
13549 memory_order_relaxed));
d62a17ae 13550 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
13551 atomic_load_explicit(&p->notify_in,
13552 memory_order_relaxed));
13553 json_object_int_add(json_stat, "updatesSent",
13554 atomic_load_explicit(&p->update_out,
13555 memory_order_relaxed));
13556 json_object_int_add(json_stat, "updatesRecv",
13557 atomic_load_explicit(&p->update_in,
13558 memory_order_relaxed));
d62a17ae 13559 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
13560 atomic_load_explicit(&p->keepalive_out,
13561 memory_order_relaxed));
d62a17ae 13562 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
13563 atomic_load_explicit(&p->keepalive_in,
13564 memory_order_relaxed));
d62a17ae 13565 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
13566 atomic_load_explicit(&p->refresh_out,
13567 memory_order_relaxed));
d62a17ae 13568 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
13569 atomic_load_explicit(&p->refresh_in,
13570 memory_order_relaxed));
d62a17ae 13571 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
13572 atomic_load_explicit(&p->dynamic_cap_out,
13573 memory_order_relaxed));
d62a17ae 13574 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
13575 atomic_load_explicit(&p->dynamic_cap_in,
13576 memory_order_relaxed));
13577 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13578 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 13579 json_object_object_add(json_neigh, "messageStats", json_stat);
13580 } else {
43aa5965
QY
13581 atomic_size_t outq_count, inq_count;
13582 outq_count = atomic_load_explicit(&p->obuf->count,
13583 memory_order_relaxed);
13584 inq_count = atomic_load_explicit(&p->ibuf->count,
13585 memory_order_relaxed);
13586
d62a17ae 13587 /* Packet counts. */
13588 vty_out(vty, " Message statistics:\n");
43aa5965
QY
13589 vty_out(vty, " Inq depth is %zu\n", inq_count);
13590 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 13591 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
13592 vty_out(vty, " Opens: %10d %10d\n",
13593 atomic_load_explicit(&p->open_out,
13594 memory_order_relaxed),
13595 atomic_load_explicit(&p->open_in,
13596 memory_order_relaxed));
13597 vty_out(vty, " Notifications: %10d %10d\n",
13598 atomic_load_explicit(&p->notify_out,
13599 memory_order_relaxed),
13600 atomic_load_explicit(&p->notify_in,
13601 memory_order_relaxed));
13602 vty_out(vty, " Updates: %10d %10d\n",
13603 atomic_load_explicit(&p->update_out,
13604 memory_order_relaxed),
13605 atomic_load_explicit(&p->update_in,
13606 memory_order_relaxed));
13607 vty_out(vty, " Keepalives: %10d %10d\n",
13608 atomic_load_explicit(&p->keepalive_out,
13609 memory_order_relaxed),
13610 atomic_load_explicit(&p->keepalive_in,
13611 memory_order_relaxed));
13612 vty_out(vty, " Route Refresh: %10d %10d\n",
13613 atomic_load_explicit(&p->refresh_out,
13614 memory_order_relaxed),
13615 atomic_load_explicit(&p->refresh_in,
13616 memory_order_relaxed));
d62a17ae 13617 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
13618 atomic_load_explicit(&p->dynamic_cap_out,
13619 memory_order_relaxed),
13620 atomic_load_explicit(&p->dynamic_cap_in,
13621 memory_order_relaxed));
13622 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
13623 PEER_TOTAL_RX(p));
d62a17ae 13624 }
13625
13626 if (use_json) {
13627 /* advertisement-interval */
13628 json_object_int_add(json_neigh,
13629 "minBtwnAdvertisementRunsTimerMsecs",
13630 p->v_routeadv * 1000);
13631
13632 /* Update-source. */
13633 if (p->update_if || p->update_source) {
13634 if (p->update_if)
13635 json_object_string_add(json_neigh,
13636 "updateSource",
13637 p->update_if);
13638 else if (p->update_source)
13639 json_object_string_add(
13640 json_neigh, "updateSource",
13641 sockunion2str(p->update_source, buf1,
13642 SU_ADDRSTRLEN));
13643 }
13644 } else {
13645 /* advertisement-interval */
13646 vty_out(vty,
13647 " Minimum time between advertisement runs is %d seconds\n",
13648 p->v_routeadv);
13649
13650 /* Update-source. */
13651 if (p->update_if || p->update_source) {
13652 vty_out(vty, " Update source is ");
13653 if (p->update_if)
13654 vty_out(vty, "%s", p->update_if);
13655 else if (p->update_source)
13656 vty_out(vty, "%s",
13657 sockunion2str(p->update_source, buf1,
13658 SU_ADDRSTRLEN));
13659 vty_out(vty, "\n");
13660 }
13661
13662 vty_out(vty, "\n");
13663 }
13664
13665 /* Address Family Information */
13666 json_object *json_hold = NULL;
13667
13668 if (use_json)
13669 json_hold = json_object_new_object();
13670
05c7a1cc
QY
13671 FOREACH_AFI_SAFI (afi, safi)
13672 if (p->afc[afi][safi])
13673 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13674 json_hold);
d62a17ae 13675
13676 if (use_json) {
13677 json_object_object_add(json_neigh, "addressFamilyInfo",
13678 json_hold);
13679 json_object_int_add(json_neigh, "connectionsEstablished",
13680 p->established);
13681 json_object_int_add(json_neigh, "connectionsDropped",
13682 p->dropped);
13683 } else
13684 vty_out(vty, " Connections established %d; dropped %d\n",
13685 p->established, p->dropped);
13686
13687 if (!p->last_reset) {
13688 if (use_json)
13689 json_object_string_add(json_neigh, "lastReset",
13690 "never");
13691 else
13692 vty_out(vty, " Last reset never\n");
13693 } else {
13694 if (use_json) {
13695 time_t uptime;
a2700b50 13696 struct tm tm;
d62a17ae 13697
13698 uptime = bgp_clock();
13699 uptime -= p->resettime;
a2700b50
MS
13700 gmtime_r(&uptime, &tm);
13701
d62a17ae 13702 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
13703 (tm.tm_sec * 1000)
13704 + (tm.tm_min * 60000)
13705 + (tm.tm_hour * 3600000));
3577f1c5 13706 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 13707 } else {
13708 vty_out(vty, " Last reset %s, ",
13709 peer_uptime(p->resettime, timebuf,
13710 BGP_UPTIME_LEN, 0, NULL));
13711
3577f1c5 13712 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 13713 if (p->last_reset_cause_size) {
13714 msg = p->last_reset_cause;
13715 vty_out(vty,
13716 " Message received that caused BGP to send a NOTIFICATION:\n ");
13717 for (i = 1; i <= p->last_reset_cause_size;
13718 i++) {
13719 vty_out(vty, "%02X", *msg++);
13720
13721 if (i != p->last_reset_cause_size) {
13722 if (i % 16 == 0) {
13723 vty_out(vty, "\n ");
13724 } else if (i % 4 == 0) {
13725 vty_out(vty, " ");
13726 }
13727 }
13728 }
13729 vty_out(vty, "\n");
13730 }
13731 }
13732 }
13733
13734 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13735 if (use_json)
13736 json_object_boolean_true_add(json_neigh,
13737 "prefixesConfigExceedMax");
13738 else
13739 vty_out(vty,
13740 " Peer had exceeded the max. no. of prefixes configured.\n");
13741
13742 if (p->t_pmax_restart) {
13743 if (use_json) {
13744 json_object_boolean_true_add(
13745 json_neigh, "reducePrefixNumFrom");
13746 json_object_int_add(json_neigh,
13747 "restartInTimerMsec",
13748 thread_timer_remain_second(
13749 p->t_pmax_restart)
13750 * 1000);
13751 } else
13752 vty_out(vty,
13753 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
13754 p->host, thread_timer_remain_second(
13755 p->t_pmax_restart));
d62a17ae 13756 } else {
13757 if (use_json)
13758 json_object_boolean_true_add(
13759 json_neigh,
13760 "reducePrefixNumAndClearIpBgp");
13761 else
13762 vty_out(vty,
13763 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13764 p->host);
13765 }
13766 }
13767
13768 /* EBGP Multihop and GTSM */
13769 if (p->sort != BGP_PEER_IBGP) {
13770 if (use_json) {
e2521429 13771 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13772 json_object_int_add(json_neigh,
13773 "externalBgpNbrMaxHopsAway",
13774 p->gtsm_hops);
c8d6f0d6 13775 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13776 json_object_int_add(json_neigh,
13777 "externalBgpNbrMaxHopsAway",
13778 p->ttl);
13779 } else {
e2521429 13780 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13781 vty_out(vty,
13782 " External BGP neighbor may be up to %d hops away.\n",
13783 p->gtsm_hops);
c8d6f0d6 13784 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13785 vty_out(vty,
13786 " External BGP neighbor may be up to %d hops away.\n",
13787 p->ttl);
13788 }
13789 } else {
e2521429 13790 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 13791 if (use_json)
13792 json_object_int_add(json_neigh,
13793 "internalBgpNbrMaxHopsAway",
13794 p->gtsm_hops);
13795 else
13796 vty_out(vty,
13797 " Internal BGP neighbor may be up to %d hops away.\n",
13798 p->gtsm_hops);
13799 }
13800 }
13801
13802 /* Local address. */
13803 if (p->su_local) {
13804 if (use_json) {
13805 json_object_string_add(json_neigh, "hostLocal",
13806 sockunion2str(p->su_local, buf1,
13807 SU_ADDRSTRLEN));
13808 json_object_int_add(json_neigh, "portLocal",
13809 ntohs(p->su_local->sin.sin_port));
13810 } else
13811 vty_out(vty, "Local host: %s, Local port: %d\n",
13812 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
13813 ntohs(p->su_local->sin.sin_port));
13814 }
13815
13816 /* Remote address. */
13817 if (p->su_remote) {
13818 if (use_json) {
13819 json_object_string_add(json_neigh, "hostForeign",
13820 sockunion2str(p->su_remote, buf1,
13821 SU_ADDRSTRLEN));
13822 json_object_int_add(json_neigh, "portForeign",
13823 ntohs(p->su_remote->sin.sin_port));
13824 } else
13825 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
13826 sockunion2str(p->su_remote, buf1,
13827 SU_ADDRSTRLEN),
13828 ntohs(p->su_remote->sin.sin_port));
13829 }
13830
13831 /* Nexthop display. */
13832 if (p->su_local) {
13833 if (use_json) {
c949c771
DA
13834 json_object_string_addf(json_neigh, "nexthop", "%pI4",
13835 &p->nexthop.v4);
13836 json_object_string_addf(json_neigh, "nexthopGlobal",
13837 "%pI6", &p->nexthop.v6_global);
13838 json_object_string_addf(json_neigh, "nexthopLocal",
13839 "%pI6", &p->nexthop.v6_local);
d62a17ae 13840 if (p->shared_network)
13841 json_object_string_add(json_neigh,
13842 "bgpConnection",
13843 "sharedNetwork");
13844 else
13845 json_object_string_add(json_neigh,
13846 "bgpConnection",
13847 "nonSharedNetwork");
13848 } else {
13849 vty_out(vty, "Nexthop: %s\n",
13850 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
13851 sizeof(buf1)));
13852 vty_out(vty, "Nexthop global: %s\n",
13853 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
13854 sizeof(buf1)));
13855 vty_out(vty, "Nexthop local: %s\n",
13856 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
13857 sizeof(buf1)));
13858 vty_out(vty, "BGP connection: %s\n",
13859 p->shared_network ? "shared network"
13860 : "non shared network");
13861 }
13862 }
13863
13864 /* Timer information. */
13865 if (use_json) {
13866 json_object_int_add(json_neigh, "connectRetryTimer",
13867 p->v_connect);
feb17238 13868 if (peer_established(p) && p->rtt)
d62a17ae 13869 json_object_int_add(json_neigh, "estimatedRttInMsecs",
13870 p->rtt);
13871 if (p->t_start)
13872 json_object_int_add(
13873 json_neigh, "nextStartTimerDueInMsecs",
13874 thread_timer_remain_second(p->t_start) * 1000);
13875 if (p->t_connect)
13876 json_object_int_add(
13877 json_neigh, "nextConnectTimerDueInMsecs",
13878 thread_timer_remain_second(p->t_connect)
13879 * 1000);
13880 if (p->t_routeadv) {
13881 json_object_int_add(json_neigh, "mraiInterval",
13882 p->v_routeadv);
13883 json_object_int_add(
13884 json_neigh, "mraiTimerExpireInMsecs",
13885 thread_timer_remain_second(p->t_routeadv)
13886 * 1000);
13887 }
13888 if (p->password)
13889 json_object_int_add(json_neigh, "authenticationEnabled",
13890 1);
13891
13892 if (p->t_read)
13893 json_object_string_add(json_neigh, "readThread", "on");
13894 else
13895 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
13896
13897 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 13898 json_object_string_add(json_neigh, "writeThread", "on");
13899 else
13900 json_object_string_add(json_neigh, "writeThread",
13901 "off");
13902 } else {
13903 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
13904 p->v_connect);
feb17238 13905 if (peer_established(p) && p->rtt)
d62a17ae 13906 vty_out(vty, "Estimated round trip time: %d ms\n",
13907 p->rtt);
13908 if (p->t_start)
13909 vty_out(vty, "Next start timer due in %ld seconds\n",
13910 thread_timer_remain_second(p->t_start));
13911 if (p->t_connect)
13912 vty_out(vty, "Next connect timer due in %ld seconds\n",
13913 thread_timer_remain_second(p->t_connect));
13914 if (p->t_routeadv)
13915 vty_out(vty,
13916 "MRAI (interval %u) timer expires in %ld seconds\n",
13917 p->v_routeadv,
13918 thread_timer_remain_second(p->t_routeadv));
13919 if (p->password)
13920 vty_out(vty, "Peer Authentication Enabled\n");
13921
cac9e917 13922 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
13923 p->t_read ? "on" : "off",
13924 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
13925 ? "on"
cac9e917 13926 : "off", p->fd);
d62a17ae 13927 }
13928
13929 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
13930 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
13931 bgp_capability_vty_out(vty, p, use_json, json_neigh);
13932
13933 if (!use_json)
13934 vty_out(vty, "\n");
13935
13936 /* BFD information. */
21bfce98
RZ
13937 if (p->bfd_config)
13938 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 13939
13940 if (use_json) {
13941 if (p->conf_if) /* Configured interface name. */
13942 json_object_object_add(json, p->conf_if, json_neigh);
13943 else /* Configured IP address. */
13944 json_object_object_add(json, p->host, json_neigh);
13945 }
13946}
13947
36235319
QY
13948static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
13949 enum show_type type,
13950 union sockunion *su,
13951 const char *conf_if, afi_t afi,
74a630b6 13952 bool use_json)
2986cac2 13953{
13954 struct listnode *node, *nnode;
13955 struct peer *peer;
13956 int find = 0;
13957 safi_t safi = SAFI_UNICAST;
74a630b6 13958 json_object *json = NULL;
2986cac2 13959 json_object *json_neighbor = NULL;
13960
74a630b6
NT
13961 if (use_json) {
13962 json = json_object_new_object();
13963 json_neighbor = json_object_new_object();
13964 }
13965
2986cac2 13966 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13967
13968 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13969 continue;
13970
13971 if ((peer->afc[afi][safi]) == 0)
13972 continue;
13973
2ba1fe69 13974 if (type == show_all) {
2986cac2 13975 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 13976 json_neighbor);
2986cac2 13977
74a630b6 13978 if (use_json) {
13909c4f
DS
13979 json_object_object_add(json, peer->host,
13980 json_neighbor);
74a630b6
NT
13981 json_neighbor = NULL;
13982 }
2986cac2 13983
2ba1fe69 13984 } else if (type == show_peer) {
2986cac2 13985 if (conf_if) {
13986 if ((peer->conf_if
13909c4f
DS
13987 && !strcmp(peer->conf_if, conf_if))
13988 || (peer->hostname
2986cac2 13989 && !strcmp(peer->hostname, conf_if))) {
13990 find = 1;
13909c4f
DS
13991 bgp_show_peer_gr_status(vty, peer,
13992 use_json,
13993 json_neighbor);
2986cac2 13994 }
13995 } else {
13996 if (sockunion_same(&peer->su, su)) {
13997 find = 1;
13909c4f
DS
13998 bgp_show_peer_gr_status(vty, peer,
13999 use_json,
14000 json_neighbor);
2986cac2 14001 }
14002 }
13909c4f
DS
14003 if (use_json && find)
14004 json_object_object_add(json, peer->host,
14005 json_neighbor);
2986cac2 14006 }
14007
74a630b6
NT
14008 if (find) {
14009 json_neighbor = NULL;
2986cac2 14010 break;
74a630b6 14011 }
2986cac2 14012 }
14013
14014 if (type == show_peer && !find) {
14015 if (use_json)
13909c4f 14016 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14017 else
14018 vty_out(vty, "%% No such neighbor\n");
14019 }
14020 if (use_json) {
74a630b6
NT
14021 if (json_neighbor)
14022 json_object_free(json_neighbor);
75eeda93 14023 vty_json(vty, json);
2986cac2 14024 } else {
14025 vty_out(vty, "\n");
14026 }
14027
14028 return CMD_SUCCESS;
14029}
14030
d62a17ae 14031static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14032 enum show_type type, union sockunion *su,
9f049418 14033 const char *conf_if, bool use_json,
d62a17ae 14034 json_object *json)
14035{
14036 struct listnode *node, *nnode;
14037 struct peer *peer;
14038 int find = 0;
9f049418 14039 bool nbr_output = false;
d1927ebe
AS
14040 afi_t afi = AFI_MAX;
14041 safi_t safi = SAFI_MAX;
14042
14043 if (type == show_ipv4_peer || type == show_ipv4_all) {
14044 afi = AFI_IP;
14045 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14046 afi = AFI_IP6;
14047 }
d62a17ae 14048
14049 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14050 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14051 continue;
14052
14053 switch (type) {
14054 case show_all:
14055 bgp_show_peer(vty, peer, use_json, json);
9f049418 14056 nbr_output = true;
d62a17ae 14057 break;
14058 case show_peer:
14059 if (conf_if) {
14060 if ((peer->conf_if
14061 && !strcmp(peer->conf_if, conf_if))
14062 || (peer->hostname
14063 && !strcmp(peer->hostname, conf_if))) {
14064 find = 1;
14065 bgp_show_peer(vty, peer, use_json,
14066 json);
14067 }
14068 } else {
14069 if (sockunion_same(&peer->su, su)) {
14070 find = 1;
14071 bgp_show_peer(vty, peer, use_json,
14072 json);
14073 }
14074 }
14075 break;
d1927ebe
AS
14076 case show_ipv4_peer:
14077 case show_ipv6_peer:
14078 FOREACH_SAFI (safi) {
14079 if (peer->afc[afi][safi]) {
14080 if (conf_if) {
14081 if ((peer->conf_if
14082 && !strcmp(peer->conf_if, conf_if))
14083 || (peer->hostname
14084 && !strcmp(peer->hostname, conf_if))) {
14085 find = 1;
14086 bgp_show_peer(vty, peer, use_json,
14087 json);
14088 break;
14089 }
14090 } else {
14091 if (sockunion_same(&peer->su, su)) {
14092 find = 1;
14093 bgp_show_peer(vty, peer, use_json,
14094 json);
14095 break;
14096 }
14097 }
14098 }
14099 }
14100 break;
14101 case show_ipv4_all:
14102 case show_ipv6_all:
14103 FOREACH_SAFI (safi) {
14104 if (peer->afc[afi][safi]) {
14105 bgp_show_peer(vty, peer, use_json, json);
14106 nbr_output = true;
14107 break;
14108 }
14109 }
14110 break;
d62a17ae 14111 }
14112 }
14113
d1927ebe
AS
14114 if ((type == show_peer || type == show_ipv4_peer ||
14115 type == show_ipv6_peer) && !find) {
d62a17ae 14116 if (use_json)
14117 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14118 else
88b7d255 14119 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14120 }
14121
d1927ebe
AS
14122 if (type != show_peer && type != show_ipv4_peer &&
14123 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14124 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14125
d62a17ae 14126 if (use_json) {
996c9314
LB
14127 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14128 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14129 } else {
14130 vty_out(vty, "\n");
14131 }
14132
14133 return CMD_SUCCESS;
14134}
14135
36235319
QY
14136static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14137 enum show_type type,
14138 const char *ip_str,
14139 afi_t afi, bool use_json)
2986cac2 14140{
14141
14142 int ret;
14143 struct bgp *bgp;
14144 union sockunion su;
2986cac2 14145
14146 bgp = bgp_get_default();
14147
13909c4f
DS
14148 if (!bgp)
14149 return;
2986cac2 14150
13909c4f
DS
14151 if (!use_json)
14152 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14153 NULL);
2986cac2 14154
13909c4f
DS
14155 if (ip_str) {
14156 ret = str2sockunion(ip_str, &su);
14157 if (ret < 0)
13909c4f 14158 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14159 vty, bgp, type, NULL, ip_str, afi, use_json);
14160 else
14161 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14162 NULL, afi, use_json);
13909c4f
DS
14163 } else
14164 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14165 afi, use_json);
2986cac2 14166}
14167
d62a17ae 14168static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14169 enum show_type type,
14170 const char *ip_str,
9f049418 14171 bool use_json)
d62a17ae 14172{
0291c246
MK
14173 struct listnode *node, *nnode;
14174 struct bgp *bgp;
71aedaa3 14175 union sockunion su;
0291c246 14176 json_object *json = NULL;
71aedaa3 14177 int ret, is_first = 1;
9f049418 14178 bool nbr_output = false;
d62a17ae 14179
14180 if (use_json)
14181 vty_out(vty, "{\n");
14182
14183 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14184 nbr_output = true;
d62a17ae 14185 if (use_json) {
14186 if (!(json = json_object_new_object())) {
af4c2728 14187 flog_err(
e50f7cfd 14188 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14189 "Unable to allocate memory for JSON object");
14190 vty_out(vty,
14191 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14192 return;
14193 }
14194
14195 json_object_int_add(json, "vrfId",
14196 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14197 ? -1
14198 : (int64_t)bgp->vrf_id);
d62a17ae 14199 json_object_string_add(
14200 json, "vrfName",
14201 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14202 ? VRF_DEFAULT_NAME
d62a17ae 14203 : bgp->name);
14204
14205 if (!is_first)
14206 vty_out(vty, ",\n");
14207 else
14208 is_first = 0;
14209
14210 vty_out(vty, "\"%s\":",
14211 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14212 ? VRF_DEFAULT_NAME
d62a17ae 14213 : bgp->name);
14214 } else {
14215 vty_out(vty, "\nInstance %s:\n",
14216 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14217 ? VRF_DEFAULT_NAME
d62a17ae 14218 : bgp->name);
14219 }
71aedaa3 14220
d1927ebe
AS
14221 if (type == show_peer || type == show_ipv4_peer ||
14222 type == show_ipv6_peer) {
71aedaa3
DS
14223 ret = str2sockunion(ip_str, &su);
14224 if (ret < 0)
14225 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14226 use_json, json);
14227 else
14228 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14229 use_json, json);
14230 } else {
d1927ebe 14231 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14232 use_json, json);
14233 }
b77004d6 14234 json_object_free(json);
121067e9 14235 json = NULL;
d62a17ae 14236 }
14237
3e78a6ce 14238 if (use_json)
d62a17ae 14239 vty_out(vty, "}\n");
9f049418
DS
14240 else if (!nbr_output)
14241 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14242}
14243
14244static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14245 enum show_type type, const char *ip_str,
9f049418 14246 bool use_json)
d62a17ae 14247{
14248 int ret;
14249 struct bgp *bgp;
14250 union sockunion su;
14251 json_object *json = NULL;
14252
14253 if (name) {
14254 if (strmatch(name, "all")) {
71aedaa3
DS
14255 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14256 use_json);
d62a17ae 14257 return CMD_SUCCESS;
14258 } else {
14259 bgp = bgp_lookup_by_name(name);
14260 if (!bgp) {
14261 if (use_json) {
14262 json = json_object_new_object();
75eeda93 14263 vty_json(vty, json);
d62a17ae 14264 } else
14265 vty_out(vty,
9f049418 14266 "%% BGP instance not found\n");
d62a17ae 14267
14268 return CMD_WARNING;
14269 }
14270 }
14271 } else {
14272 bgp = bgp_get_default();
14273 }
14274
14275 if (bgp) {
14276 json = json_object_new_object();
14277 if (ip_str) {
14278 ret = str2sockunion(ip_str, &su);
14279 if (ret < 0)
14280 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14281 use_json, json);
14282 else
14283 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14284 use_json, json);
14285 } else {
14286 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14287 json);
14288 }
14289 json_object_free(json);
ca61fd25
DS
14290 } else {
14291 if (use_json)
14292 vty_out(vty, "{}\n");
14293 else
14294 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14295 }
14296
14297 return CMD_SUCCESS;
4fb25c53
DW
14298}
14299
2986cac2 14300
14301
14302/* "show [ip] bgp neighbors graceful-restart" commands. */
14303DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14304 show_ip_bgp_neighbors_graceful_restart_cmd,
14305 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14306 SHOW_STR
14307 BGP_STR
14308 IP_STR
14309 IPV6_STR
14310 NEIGHBOR_STR
14311 "Neighbor to display information about\n"
14312 "Neighbor to display information about\n"
14313 "Neighbor on BGP configured interface\n"
14314 GR_SHOW
14315 JSON_STR)
14316{
14317 char *sh_arg = NULL;
14318 enum show_type sh_type;
14319 int idx = 0;
14320 afi_t afi = AFI_MAX;
2986cac2 14321 bool uj = use_json(argc, argv);
14322
36235319 14323 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 14324 afi = AFI_MAX;
14325
14326 idx++;
14327
14328 if (argv_find(argv, argc, "A.B.C.D", &idx)
14329 || argv_find(argv, argc, "X:X::X:X", &idx)
14330 || argv_find(argv, argc, "WORD", &idx)) {
14331 sh_type = show_peer;
14332 sh_arg = argv[idx]->arg;
14333 } else
14334 sh_type = show_all;
14335
14336 if (!argv_find(argv, argc, "graceful-restart", &idx))
14337 return CMD_SUCCESS;
14338
14339
36235319
QY
14340 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14341 afi, uj);
2986cac2 14342}
14343
716b2d8a 14344/* "show [ip] bgp neighbors" commands. */
718e3744 14345DEFUN (show_ip_bgp_neighbors,
14346 show_ip_bgp_neighbors_cmd,
24345e82 14347 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 14348 SHOW_STR
14349 IP_STR
14350 BGP_STR
f2a8972b 14351 BGP_INSTANCE_HELP_STR
8c3deaae
QY
14352 "Address Family\n"
14353 "Address Family\n"
718e3744 14354 "Detailed information on TCP and BGP neighbor connections\n"
14355 "Neighbor to display information about\n"
a80beece 14356 "Neighbor to display information about\n"
91d37724 14357 "Neighbor on BGP configured interface\n"
9973d184 14358 JSON_STR)
718e3744 14359{
d62a17ae 14360 char *vrf = NULL;
14361 char *sh_arg = NULL;
14362 enum show_type sh_type;
d1927ebe 14363 afi_t afi = AFI_MAX;
718e3744 14364
9f049418 14365 bool uj = use_json(argc, argv);
718e3744 14366
d62a17ae 14367 int idx = 0;
718e3744 14368
9a8bdf1c
PG
14369 /* [<vrf> VIEWVRFNAME] */
14370 if (argv_find(argv, argc, "vrf", &idx)) {
14371 vrf = argv[idx + 1]->arg;
14372 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14373 vrf = NULL;
14374 } else if (argv_find(argv, argc, "view", &idx))
14375 /* [<view> VIEWVRFNAME] */
d62a17ae 14376 vrf = argv[idx + 1]->arg;
718e3744 14377
d62a17ae 14378 idx++;
d1927ebe
AS
14379
14380 if (argv_find(argv, argc, "ipv4", &idx)) {
14381 sh_type = show_ipv4_all;
14382 afi = AFI_IP;
14383 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14384 sh_type = show_ipv6_all;
14385 afi = AFI_IP6;
14386 } else {
14387 sh_type = show_all;
14388 }
14389
d62a17ae 14390 if (argv_find(argv, argc, "A.B.C.D", &idx)
14391 || argv_find(argv, argc, "X:X::X:X", &idx)
14392 || argv_find(argv, argc, "WORD", &idx)) {
14393 sh_type = show_peer;
14394 sh_arg = argv[idx]->arg;
d1927ebe
AS
14395 }
14396
14397 if (sh_type == show_peer && afi == AFI_IP) {
14398 sh_type = show_ipv4_peer;
14399 } else if (sh_type == show_peer && afi == AFI_IP6) {
14400 sh_type = show_ipv6_peer;
14401 }
856ca177 14402
d62a17ae 14403 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 14404}
14405
716b2d8a 14406/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 14407 paths' and `show ip mbgp paths'. Those functions results are the
14408 same.*/
f412b39a 14409DEFUN (show_ip_bgp_paths,
718e3744 14410 show_ip_bgp_paths_cmd,
46f296b4 14411 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 14412 SHOW_STR
14413 IP_STR
14414 BGP_STR
46f296b4 14415 BGP_SAFI_HELP_STR
718e3744 14416 "Path information\n")
14417{
d62a17ae 14418 vty_out(vty, "Address Refcnt Path\n");
14419 aspath_print_all_vty(vty);
14420 return CMD_SUCCESS;
718e3744 14421}
14422
718e3744 14423#include "hash.h"
14424
e3b78da8 14425static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14426 struct vty *vty)
718e3744 14427{
d62a17ae 14428 struct community *com;
718e3744 14429
e3b78da8 14430 com = (struct community *)bucket->data;
3f65c5b1 14431 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 14432 community_str(com, false));
718e3744 14433}
14434
14435/* Show BGP's community internal data. */
f412b39a 14436DEFUN (show_ip_bgp_community_info,
718e3744 14437 show_ip_bgp_community_info_cmd,
bec37ba5 14438 "show [ip] bgp community-info",
718e3744 14439 SHOW_STR
14440 IP_STR
14441 BGP_STR
14442 "List all bgp community information\n")
14443{
d62a17ae 14444 vty_out(vty, "Address Refcnt Community\n");
718e3744 14445
d62a17ae 14446 hash_iterate(community_hash(),
e3b78da8 14447 (void (*)(struct hash_bucket *,
d62a17ae 14448 void *))community_show_all_iterator,
14449 vty);
718e3744 14450
d62a17ae 14451 return CMD_SUCCESS;
718e3744 14452}
14453
e3b78da8 14454static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14455 struct vty *vty)
57d187bc 14456{
d62a17ae 14457 struct lcommunity *lcom;
57d187bc 14458
e3b78da8 14459 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 14460 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 14461 lcommunity_str(lcom, false));
57d187bc
JS
14462}
14463
14464/* Show BGP's community internal data. */
14465DEFUN (show_ip_bgp_lcommunity_info,
14466 show_ip_bgp_lcommunity_info_cmd,
14467 "show ip bgp large-community-info",
14468 SHOW_STR
14469 IP_STR
14470 BGP_STR
14471 "List all bgp large-community information\n")
14472{
d62a17ae 14473 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 14474
d62a17ae 14475 hash_iterate(lcommunity_hash(),
e3b78da8 14476 (void (*)(struct hash_bucket *,
d62a17ae 14477 void *))lcommunity_show_all_iterator,
14478 vty);
57d187bc 14479
d62a17ae 14480 return CMD_SUCCESS;
57d187bc 14481}
2986cac2 14482/* Graceful Restart */
14483
14484static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
14485 struct bgp *bgp,
14486 bool use_json,
14487 json_object *json)
2986cac2 14488{
57d187bc
JS
14489
14490
2986cac2 14491 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14492
7318ae88 14493 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 14494
14495 switch (bgp_global_gr_mode) {
14496
14497 case GLOBAL_HELPER:
13909c4f 14498 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 14499 break;
14500
14501 case GLOBAL_GR:
13909c4f 14502 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 14503 break;
14504
14505 case GLOBAL_DISABLE:
13909c4f 14506 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 14507 break;
14508
14509 case GLOBAL_INVALID:
2986cac2 14510 vty_out(vty,
2ba1fe69 14511 "Global BGP GR Mode Invalid\n");
2986cac2 14512 break;
14513 }
14514 vty_out(vty, "\n");
14515}
14516
36235319
QY
14517static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14518 enum show_type type,
14519 const char *ip_str,
14520 afi_t afi, bool use_json)
2986cac2 14521{
14522 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14523 afi = AFI_IP;
14524
14525 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14526
36235319
QY
14527 bgp_show_neighbor_graceful_restart_vty(
14528 vty, type, ip_str, afi, use_json);
2986cac2 14529 afi++;
14530 }
14531 } else if (afi != AFI_MAX) {
36235319
QY
14532 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14533 use_json);
2986cac2 14534 } else {
14535 return CMD_ERR_INCOMPLETE;
14536 }
14537
14538 return CMD_SUCCESS;
14539}
14540/* Graceful Restart */
14541
f412b39a 14542DEFUN (show_ip_bgp_attr_info,
718e3744 14543 show_ip_bgp_attr_info_cmd,
bec37ba5 14544 "show [ip] bgp attribute-info",
718e3744 14545 SHOW_STR
14546 IP_STR
14547 BGP_STR
14548 "List all bgp attribute information\n")
14549{
d62a17ae 14550 attr_show_all(vty);
14551 return CMD_SUCCESS;
718e3744 14552}
6b0655a2 14553
03915806
CS
14554static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14555 afi_t afi, safi_t safi,
14556 bool use_json, json_object *json)
53089bec 14557{
14558 struct bgp *bgp;
14559 struct listnode *node;
14560 char *vname;
14561 char buf1[INET6_ADDRSTRLEN];
14562 char *ecom_str;
14563 vpn_policy_direction_t dir;
14564
03915806 14565 if (json) {
b46dfd20
DS
14566 json_object *json_import_vrfs = NULL;
14567 json_object *json_export_vrfs = NULL;
14568
b46dfd20
DS
14569 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14570
53089bec 14571 if (!bgp) {
75eeda93 14572 vty_json(vty, json);
b46dfd20 14573
53089bec 14574 return CMD_WARNING;
14575 }
b46dfd20 14576
94d4c685
DS
14577 /* Provide context for the block */
14578 json_object_string_add(json, "vrf", name ? name : "default");
14579 json_object_string_add(json, "afiSafi",
5cb5f4d0 14580 get_afi_safi_str(afi, safi, true));
94d4c685 14581
b46dfd20
DS
14582 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14583 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14584 json_object_string_add(json, "importFromVrfs", "none");
14585 json_object_string_add(json, "importRts", "none");
14586 } else {
6ce24e52
DS
14587 json_import_vrfs = json_object_new_array();
14588
b46dfd20
DS
14589 for (ALL_LIST_ELEMENTS_RO(
14590 bgp->vpn_policy[afi].import_vrf,
14591 node, vname))
14592 json_object_array_add(json_import_vrfs,
14593 json_object_new_string(vname));
14594
b20875ea
CS
14595 json_object_object_add(json, "importFromVrfs",
14596 json_import_vrfs);
b46dfd20 14597 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14598 if (bgp->vpn_policy[afi].rtlist[dir]) {
14599 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14600 bgp->vpn_policy[afi].rtlist[dir],
14601 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14602 json_object_string_add(json, "importRts",
14603 ecom_str);
14604 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14605 } else
14606 json_object_string_add(json, "importRts",
14607 "none");
b46dfd20
DS
14608 }
14609
14610 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14611 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14612 json_object_string_add(json, "exportToVrfs", "none");
14613 json_object_string_add(json, "routeDistinguisher",
14614 "none");
14615 json_object_string_add(json, "exportRts", "none");
14616 } else {
6ce24e52
DS
14617 json_export_vrfs = json_object_new_array();
14618
b46dfd20
DS
14619 for (ALL_LIST_ELEMENTS_RO(
14620 bgp->vpn_policy[afi].export_vrf,
14621 node, vname))
14622 json_object_array_add(json_export_vrfs,
14623 json_object_new_string(vname));
14624 json_object_object_add(json, "exportToVrfs",
14625 json_export_vrfs);
14626 json_object_string_add(json, "routeDistinguisher",
14627 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14628 buf1, RD_ADDRSTRLEN));
14629
14630 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14631 if (bgp->vpn_policy[afi].rtlist[dir]) {
14632 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14633 bgp->vpn_policy[afi].rtlist[dir],
14634 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14635 json_object_string_add(json, "exportRts",
14636 ecom_str);
14637 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14638 } else
14639 json_object_string_add(json, "exportRts",
14640 "none");
b46dfd20
DS
14641 }
14642
03915806 14643 if (use_json) {
75eeda93 14644 vty_json(vty, json);
03915806 14645 }
53089bec 14646 } else {
b46dfd20
DS
14647 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14648
53089bec 14649 if (!bgp) {
b46dfd20 14650 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 14651 return CMD_WARNING;
14652 }
53089bec 14653
b46dfd20
DS
14654 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14655 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14656 vty_out(vty,
14657 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 14658 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14659 else {
14660 vty_out(vty,
14661 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 14662 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14663
14664 for (ALL_LIST_ELEMENTS_RO(
14665 bgp->vpn_policy[afi].import_vrf,
14666 node, vname))
14667 vty_out(vty, " %s\n", vname);
14668
14669 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14670 ecom_str = NULL;
14671 if (bgp->vpn_policy[afi].rtlist[dir]) {
14672 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14673 bgp->vpn_policy[afi].rtlist[dir],
14674 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 14675 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 14676
b20875ea
CS
14677 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14678 } else
14679 vty_out(vty, "Import RT(s):\n");
53089bec 14680 }
53089bec 14681
b46dfd20
DS
14682 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14683 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14684 vty_out(vty,
14685 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 14686 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14687 else {
14688 vty_out(vty,
04c9077f 14689 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 14690 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14691
14692 for (ALL_LIST_ELEMENTS_RO(
14693 bgp->vpn_policy[afi].export_vrf,
14694 node, vname))
14695 vty_out(vty, " %s\n", vname);
14696
14697 vty_out(vty, "RD: %s\n",
14698 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14699 buf1, RD_ADDRSTRLEN));
14700
14701 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14702 if (bgp->vpn_policy[afi].rtlist[dir]) {
14703 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14704 bgp->vpn_policy[afi].rtlist[dir],
14705 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14706 vty_out(vty, "Export RT: %s\n", ecom_str);
14707 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14708 } else
14709 vty_out(vty, "Import RT(s):\n");
53089bec 14710 }
53089bec 14711 }
14712
14713 return CMD_SUCCESS;
14714}
14715
03915806
CS
14716static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14717 safi_t safi, bool use_json)
14718{
14719 struct listnode *node, *nnode;
14720 struct bgp *bgp;
14721 char *vrf_name = NULL;
14722 json_object *json = NULL;
14723 json_object *json_vrf = NULL;
14724 json_object *json_vrfs = NULL;
14725
14726 if (use_json) {
14727 json = json_object_new_object();
14728 json_vrfs = json_object_new_object();
14729 }
14730
14731 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14732
14733 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14734 vrf_name = bgp->name;
14735
14736 if (use_json) {
14737 json_vrf = json_object_new_object();
14738 } else {
14739 vty_out(vty, "\nInstance %s:\n",
14740 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14741 ? VRF_DEFAULT_NAME : bgp->name);
14742 }
14743 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14744 if (use_json) {
14745 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14746 json_object_object_add(json_vrfs,
14747 VRF_DEFAULT_NAME, json_vrf);
14748 else
14749 json_object_object_add(json_vrfs, vrf_name,
14750 json_vrf);
14751 }
14752 }
14753
14754 if (use_json) {
14755 json_object_object_add(json, "vrfs", json_vrfs);
75eeda93 14756 vty_json(vty, json);
03915806
CS
14757 }
14758
14759 return CMD_SUCCESS;
14760}
14761
53089bec 14762/* "show [ip] bgp route-leak" command. */
14763DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
14764 show_ip_bgp_route_leak_cmd,
14765 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
14766 SHOW_STR
14767 IP_STR
14768 BGP_STR
14769 BGP_INSTANCE_HELP_STR
14770 BGP_AFI_HELP_STR
14771 BGP_SAFI_HELP_STR
14772 "Route leaking information\n"
14773 JSON_STR)
53089bec 14774{
14775 char *vrf = NULL;
14776 afi_t afi = AFI_MAX;
14777 safi_t safi = SAFI_MAX;
14778
9f049418 14779 bool uj = use_json(argc, argv);
53089bec 14780 int idx = 0;
03915806 14781 json_object *json = NULL;
53089bec 14782
14783 /* show [ip] bgp */
14784 if (argv_find(argv, argc, "ip", &idx)) {
14785 afi = AFI_IP;
14786 safi = SAFI_UNICAST;
14787 }
14788 /* [vrf VIEWVRFNAME] */
14789 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
14790 vty_out(vty,
14791 "%% This command is not applicable to BGP views\n");
53089bec 14792 return CMD_WARNING;
14793 }
14794
9a8bdf1c
PG
14795 if (argv_find(argv, argc, "vrf", &idx)) {
14796 vrf = argv[idx + 1]->arg;
14797 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14798 vrf = NULL;
14799 }
53089bec 14800 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
c48349e3 14801 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
53089bec 14802 argv_find_and_parse_safi(argv, argc, &idx, &safi);
53089bec 14803
14804 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
14805 vty_out(vty,
14806 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 14807 return CMD_WARNING;
14808 }
14809
03915806
CS
14810 if (vrf && strmatch(vrf, "all"))
14811 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
14812
14813 if (uj)
14814 json = json_object_new_object();
14815
14816 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 14817}
14818
d62a17ae 14819static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
14820 safi_t safi)
f186de26 14821{
d62a17ae 14822 struct listnode *node, *nnode;
14823 struct bgp *bgp;
f186de26 14824
d62a17ae 14825 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14826 vty_out(vty, "\nInstance %s:\n",
14827 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14828 ? VRF_DEFAULT_NAME
d62a17ae 14829 : bgp->name);
14830 update_group_show(bgp, afi, safi, vty, 0);
14831 }
f186de26 14832}
14833
d62a17ae 14834static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
14835 int safi, uint64_t subgrp_id)
4fb25c53 14836{
d62a17ae 14837 struct bgp *bgp;
4fb25c53 14838
d62a17ae 14839 if (name) {
14840 if (strmatch(name, "all")) {
14841 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
14842 return CMD_SUCCESS;
14843 } else {
14844 bgp = bgp_lookup_by_name(name);
14845 }
14846 } else {
14847 bgp = bgp_get_default();
14848 }
4fb25c53 14849
d62a17ae 14850 if (bgp)
14851 update_group_show(bgp, afi, safi, vty, subgrp_id);
14852 return CMD_SUCCESS;
4fb25c53
DW
14853}
14854
8fe8a7f6
DS
14855DEFUN (show_ip_bgp_updgrps,
14856 show_ip_bgp_updgrps_cmd,
c1a44e43 14857 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 14858 SHOW_STR
14859 IP_STR
14860 BGP_STR
14861 BGP_INSTANCE_HELP_STR
c9e571b4 14862 BGP_AFI_HELP_STR
9bedbb1e 14863 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
14864 "Detailed info about dynamic update groups\n"
14865 "Specific subgroup to display detailed info for\n")
8386ac43 14866{
d62a17ae 14867 char *vrf = NULL;
14868 afi_t afi = AFI_IP6;
14869 safi_t safi = SAFI_UNICAST;
14870 uint64_t subgrp_id = 0;
14871
14872 int idx = 0;
14873
14874 /* show [ip] bgp */
14875 if (argv_find(argv, argc, "ip", &idx))
14876 afi = AFI_IP;
9a8bdf1c
PG
14877 /* [<vrf> VIEWVRFNAME] */
14878 if (argv_find(argv, argc, "vrf", &idx)) {
14879 vrf = argv[idx + 1]->arg;
14880 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14881 vrf = NULL;
14882 } else if (argv_find(argv, argc, "view", &idx))
14883 /* [<view> VIEWVRFNAME] */
14884 vrf = argv[idx + 1]->arg;
d62a17ae 14885 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14886 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14887 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14888 }
5bf15956 14889
d62a17ae 14890 /* get subgroup id, if provided */
14891 idx = argc - 1;
14892 if (argv[idx]->type == VARIABLE_TKN)
14893 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 14894
d62a17ae 14895 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
14896}
14897
f186de26 14898DEFUN (show_bgp_instance_all_ipv6_updgrps,
14899 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 14900 "show [ip] bgp <view|vrf> all update-groups",
f186de26 14901 SHOW_STR
716b2d8a 14902 IP_STR
f186de26 14903 BGP_STR
14904 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 14905 "Detailed info about dynamic update groups\n")
f186de26 14906{
d62a17ae 14907 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
14908 return CMD_SUCCESS;
f186de26 14909}
14910
43d3f4fc
DS
14911DEFUN (show_bgp_l2vpn_evpn_updgrps,
14912 show_bgp_l2vpn_evpn_updgrps_cmd,
14913 "show [ip] bgp l2vpn evpn update-groups",
14914 SHOW_STR
14915 IP_STR
14916 BGP_STR
14917 "l2vpn address family\n"
14918 "evpn sub-address family\n"
14919 "Detailed info about dynamic update groups\n")
14920{
14921 char *vrf = NULL;
14922 uint64_t subgrp_id = 0;
14923
14924 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
14925 return CMD_SUCCESS;
14926}
14927
5bf15956
DW
14928DEFUN (show_bgp_updgrps_stats,
14929 show_bgp_updgrps_stats_cmd,
716b2d8a 14930 "show [ip] bgp update-groups statistics",
3f9c7369 14931 SHOW_STR
716b2d8a 14932 IP_STR
3f9c7369 14933 BGP_STR
0c7b1b01 14934 "Detailed info about dynamic update groups\n"
3f9c7369
DS
14935 "Statistics\n")
14936{
d62a17ae 14937 struct bgp *bgp;
3f9c7369 14938
d62a17ae 14939 bgp = bgp_get_default();
14940 if (bgp)
14941 update_group_show_stats(bgp, vty);
3f9c7369 14942
d62a17ae 14943 return CMD_SUCCESS;
3f9c7369
DS
14944}
14945
8386ac43 14946DEFUN (show_bgp_instance_updgrps_stats,
14947 show_bgp_instance_updgrps_stats_cmd,
18c57037 14948 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 14949 SHOW_STR
716b2d8a 14950 IP_STR
8386ac43 14951 BGP_STR
14952 BGP_INSTANCE_HELP_STR
0c7b1b01 14953 "Detailed info about dynamic update groups\n"
8386ac43 14954 "Statistics\n")
14955{
d62a17ae 14956 int idx_word = 3;
14957 struct bgp *bgp;
8386ac43 14958
d62a17ae 14959 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
14960 if (bgp)
14961 update_group_show_stats(bgp, vty);
8386ac43 14962
d62a17ae 14963 return CMD_SUCCESS;
8386ac43 14964}
14965
d62a17ae 14966static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
14967 afi_t afi, safi_t safi,
14968 const char *what, uint64_t subgrp_id)
3f9c7369 14969{
d62a17ae 14970 struct bgp *bgp;
8386ac43 14971
d62a17ae 14972 if (name)
14973 bgp = bgp_lookup_by_name(name);
14974 else
14975 bgp = bgp_get_default();
8386ac43 14976
d62a17ae 14977 if (bgp) {
14978 if (!strcmp(what, "advertise-queue"))
14979 update_group_show_adj_queue(bgp, afi, safi, vty,
14980 subgrp_id);
14981 else if (!strcmp(what, "advertised-routes"))
14982 update_group_show_advertised(bgp, afi, safi, vty,
14983 subgrp_id);
14984 else if (!strcmp(what, "packet-queue"))
14985 update_group_show_packet_queue(bgp, afi, safi, vty,
14986 subgrp_id);
14987 }
3f9c7369
DS
14988}
14989
dc64bdec
QY
14990DEFPY(show_ip_bgp_instance_updgrps_adj_s,
14991 show_ip_bgp_instance_updgrps_adj_s_cmd,
14992 "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",
14993 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
14994 BGP_SAFI_HELP_STR
14995 "Detailed info about dynamic update groups\n"
14996 "Specific subgroup to display info for\n"
14997 "Advertisement queue\n"
14998 "Announced routes\n"
14999 "Packet queue\n")
3f9c7369 15000{
dc64bdec
QY
15001 uint64_t subgrp_id = 0;
15002 afi_t afiz;
15003 safi_t safiz;
15004 if (sgid)
15005 subgrp_id = strtoull(sgid, NULL, 10);
15006
15007 if (!ip && !afi)
15008 afiz = AFI_IP6;
15009 if (!ip && afi)
15010 afiz = bgp_vty_afi_from_str(afi);
15011 if (ip && !afi)
15012 afiz = AFI_IP;
15013 if (ip && afi) {
15014 afiz = bgp_vty_afi_from_str(afi);
15015 if (afiz != AFI_IP)
15016 vty_out(vty,
15017 "%% Cannot specify both 'ip' and 'ipv6'\n");
15018 return CMD_WARNING;
15019 }
d62a17ae 15020
dc64bdec 15021 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15022
dc64bdec 15023 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15024 return CMD_SUCCESS;
15025}
15026
6f4eacf3
DA
15027static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15028 json_object *json)
d62a17ae 15029{
15030 struct listnode *node, *nnode;
15031 struct prefix *range;
15032 struct peer *conf;
15033 struct peer *peer;
d62a17ae 15034 afi_t afi;
15035 safi_t safi;
15036 const char *peer_status;
d62a17ae 15037 int lr_count;
15038 int dynamic;
6f4eacf3
DA
15039 bool af_cfgd;
15040 json_object *json_peer_group = NULL;
15041 json_object *json_peer_group_afc = NULL;
15042 json_object *json_peer_group_members = NULL;
15043 json_object *json_peer_group_dynamic = NULL;
15044 json_object *json_peer_group_dynamic_af = NULL;
15045 json_object *json_peer_group_ranges = NULL;
d62a17ae 15046
15047 conf = group->conf;
15048
6f4eacf3
DA
15049 if (json) {
15050 json_peer_group = json_object_new_object();
15051 json_peer_group_afc = json_object_new_array();
15052 }
15053
d62a17ae 15054 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3
DA
15055 if (json)
15056 json_object_int_add(json_peer_group, "remoteAs",
15057 conf->as);
15058 else
15059 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15060 group->name, conf->as);
d62a17ae 15061 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3
DA
15062 if (json)
15063 json_object_int_add(json_peer_group, "remoteAs",
15064 group->bgp->as);
15065 else
15066 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15067 group->name, group->bgp->as);
d62a17ae 15068 } else {
6f4eacf3
DA
15069 if (!json)
15070 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 15071 }
f14e6fdb 15072
6f4eacf3
DA
15073 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15074 if (json)
15075 json_object_string_add(json_peer_group, "type",
15076 "internal");
15077 else
15078 vty_out(vty, " Peer-group type is internal\n");
15079 } else {
15080 if (json)
15081 json_object_string_add(json_peer_group, "type",
15082 "external");
15083 else
15084 vty_out(vty, " Peer-group type is external\n");
15085 }
d62a17ae 15086
15087 /* Display AFs configured. */
6f4eacf3
DA
15088 if (!json)
15089 vty_out(vty, " Configured address-families:");
15090
05c7a1cc
QY
15091 FOREACH_AFI_SAFI (afi, safi) {
15092 if (conf->afc[afi][safi]) {
6f4eacf3
DA
15093 af_cfgd = true;
15094 if (json)
15095 json_object_array_add(
15096 json_peer_group_afc,
15097 json_object_new_string(get_afi_safi_str(
15098 afi, safi, false)));
15099 else
15100 vty_out(vty, " %s;",
15101 get_afi_safi_str(afi, safi, false));
d62a17ae 15102 }
05c7a1cc 15103 }
6f4eacf3
DA
15104
15105 if (json) {
15106 json_object_object_add(json_peer_group,
15107 "addressFamiliesConfigured",
15108 json_peer_group_afc);
15109 } else {
15110 if (!af_cfgd)
15111 vty_out(vty, " none\n");
15112 else
15113 vty_out(vty, "\n");
15114 }
d62a17ae 15115
15116 /* Display listen ranges (for dynamic neighbors), if any */
15117 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 15118 lr_count = listcount(group->listen_range[afi]);
15119 if (lr_count) {
6f4eacf3
DA
15120 if (json) {
15121 if (!json_peer_group_dynamic)
15122 json_peer_group_dynamic =
15123 json_object_new_object();
15124
15125 json_peer_group_dynamic_af =
15126 json_object_new_object();
15127 json_peer_group_ranges =
15128 json_object_new_array();
15129 json_object_int_add(json_peer_group_dynamic_af,
15130 "count", lr_count);
15131 } else {
15132 vty_out(vty, " %d %s listen range(s)\n",
15133 lr_count, afi2str(afi));
15134 }
d62a17ae 15135
15136 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
15137 nnode, range)) {
15138 if (json) {
15139 char buf[BUFSIZ];
15140
15141 snprintfrr(buf, sizeof(buf), "%pFX",
15142 range);
15143
15144 json_object_array_add(
15145 json_peer_group_ranges,
15146 json_object_new_string(buf));
15147 } else {
15148 vty_out(vty, " %pFX\n", range);
15149 }
15150 }
15151
15152 if (json) {
15153 json_object_object_add(
15154 json_peer_group_dynamic_af, "ranges",
15155 json_peer_group_ranges);
15156
15157 json_object_object_add(
15158 json_peer_group_dynamic, afi2str(afi),
15159 json_peer_group_dynamic_af);
15160 }
d62a17ae 15161 }
15162 }
f14e6fdb 15163
6f4eacf3
DA
15164 if (json_peer_group_dynamic)
15165 json_object_object_add(json_peer_group, "dynamicRanges",
15166 json_peer_group_dynamic);
15167
d62a17ae 15168 /* Display group members and their status */
15169 if (listcount(group->peer)) {
6f4eacf3
DA
15170 if (json)
15171 json_peer_group_members = json_object_new_object();
15172 else
15173 vty_out(vty, " Peer-group members:\n");
d62a17ae 15174 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15175 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15176 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15177 peer_status = "Idle (Admin)";
15178 else if (CHECK_FLAG(peer->sflags,
15179 PEER_STATUS_PREFIX_OVERFLOW))
15180 peer_status = "Idle (PfxCt)";
15181 else
15182 peer_status = lookup_msg(bgp_status_msg,
15183 peer->status, NULL);
15184
15185 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
15186
15187 if (json) {
15188 json_object *json_peer_group_member =
15189 json_object_new_object();
15190
15191 json_object_string_add(json_peer_group_member,
15192 "status", peer_status);
15193
15194 if (dynamic)
15195 json_object_boolean_true_add(
15196 json_peer_group_member,
15197 "dynamic");
15198
15199 json_object_object_add(json_peer_group_members,
15200 peer->host,
15201 json_peer_group_member);
15202 } else {
15203 vty_out(vty, " %s %s %s \n", peer->host,
15204 dynamic ? "(dynamic)" : "",
15205 peer_status);
15206 }
d62a17ae 15207 }
6f4eacf3
DA
15208 if (json)
15209 json_object_object_add(json_peer_group, "members",
15210 json_peer_group_members);
d62a17ae 15211 }
f14e6fdb 15212
6f4eacf3
DA
15213 if (json)
15214 json_object_object_add(json, group->name, json_peer_group);
15215
d62a17ae 15216 return CMD_SUCCESS;
15217}
15218
ff9959b0 15219static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 15220 const char *group_name, bool uj)
d62a17ae 15221{
ff9959b0 15222 struct bgp *bgp;
d62a17ae 15223 struct listnode *node, *nnode;
15224 struct peer_group *group;
ff9959b0 15225 bool found = false;
6f4eacf3
DA
15226 json_object *json = NULL;
15227
15228 if (uj)
15229 json = json_object_new_object();
ff9959b0
QY
15230
15231 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15232
15233 if (!bgp) {
c48349e3 15234 if (uj)
75eeda93 15235 vty_json(vty, json);
c48349e3 15236 else
6f4eacf3 15237 vty_out(vty, "%% BGP instance not found\n");
6f4eacf3 15238
ff9959b0
QY
15239 return CMD_WARNING;
15240 }
d62a17ae 15241
15242 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15243 if (group_name) {
15244 if (strmatch(group->name, group_name)) {
6f4eacf3 15245 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
15246 found = true;
15247 break;
d62a17ae 15248 }
ff9959b0 15249 } else {
6f4eacf3 15250 bgp_show_one_peer_group(vty, group, json);
d62a17ae 15251 }
f14e6fdb 15252 }
f14e6fdb 15253
6f4eacf3 15254 if (group_name && !found && !uj)
d62a17ae 15255 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15256
c48349e3 15257 if (uj)
75eeda93 15258 vty_json(vty, json);
6f4eacf3 15259
d62a17ae 15260 return CMD_SUCCESS;
f14e6fdb
DS
15261}
15262
6f4eacf3
DA
15263DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15264 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15265 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15266 "Detailed information on BGP peer groups\n"
15267 "Peer group name\n" JSON_STR)
f14e6fdb 15268{
d62a17ae 15269 char *vrf, *pg;
d62a17ae 15270 int idx = 0;
6f4eacf3 15271 bool uj = use_json(argc, argv);
f14e6fdb 15272
a4d82a8a
PZ
15273 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15274 : NULL;
d62a17ae 15275 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15276
6f4eacf3 15277 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 15278}
3f9c7369 15279
d6e3c605 15280
718e3744 15281/* Redistribute VTY commands. */
15282
585f1adc
IR
15283DEFUN (bgp_redistribute_ipv4,
15284 bgp_redistribute_ipv4_cmd,
15285 "redistribute " FRR_IP_REDIST_STR_BGPD,
15286 "Redistribute information from another routing protocol\n"
15287 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 15288{
585f1adc 15289 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15290 int idx_protocol = 1;
585f1adc 15291 int type;
37a87b8f 15292
585f1adc
IR
15293 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15294 if (type < 0) {
15295 vty_out(vty, "%% Invalid route type\n");
15296 return CMD_WARNING_CONFIG_FAILED;
15297 }
7f323236 15298
585f1adc
IR
15299 bgp_redist_add(bgp, AFI_IP, type, 0);
15300 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 15301}
15302
d62a17ae 15303ALIAS_HIDDEN(
15304 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15305 "redistribute " FRR_IP_REDIST_STR_BGPD,
15306 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 15307
585f1adc
IR
15308DEFUN (bgp_redistribute_ipv4_rmap,
15309 bgp_redistribute_ipv4_rmap_cmd,
15310 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15311 "Redistribute information from another routing protocol\n"
15312 FRR_IP_REDIST_HELP_STR_BGPD
15313 "Route map reference\n"
15314 "Pointer to route-map entries\n")
718e3744 15315{
585f1adc 15316 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15317 int idx_protocol = 1;
15318 int idx_word = 3;
585f1adc
IR
15319 int type;
15320 struct bgp_redist *red;
15321 bool changed;
15322 struct route_map *route_map = route_map_lookup_warn_noexist(
15323 vty, argv[idx_word]->arg);
15324
15325 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15326 if (type < 0) {
15327 vty_out(vty, "%% Invalid route type\n");
15328 return CMD_WARNING_CONFIG_FAILED;
15329 }
37a87b8f 15330
585f1adc
IR
15331 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15332 changed =
15333 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15334 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 15335}
15336
d62a17ae 15337ALIAS_HIDDEN(
15338 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15339 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15340 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15341 "Route map reference\n"
15342 "Pointer to route-map entries\n")
596c17ba 15343
585f1adc
IR
15344DEFUN (bgp_redistribute_ipv4_metric,
15345 bgp_redistribute_ipv4_metric_cmd,
15346 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15347 "Redistribute information from another routing protocol\n"
15348 FRR_IP_REDIST_HELP_STR_BGPD
15349 "Metric for redistributed routes\n"
15350 "Default metric\n")
718e3744 15351{
585f1adc 15352 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15353 int idx_protocol = 1;
15354 int idx_number = 3;
585f1adc
IR
15355 int type;
15356 uint32_t metric;
15357 struct bgp_redist *red;
15358 bool changed;
15359
15360 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15361 if (type < 0) {
15362 vty_out(vty, "%% Invalid route type\n");
15363 return CMD_WARNING_CONFIG_FAILED;
15364 }
15365 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15366
585f1adc
IR
15367 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15368 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15369 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15370}
15371
15372ALIAS_HIDDEN(
15373 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15374 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15375 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15376 "Metric for redistributed routes\n"
15377 "Default metric\n")
596c17ba 15378
585f1adc
IR
15379DEFUN (bgp_redistribute_ipv4_rmap_metric,
15380 bgp_redistribute_ipv4_rmap_metric_cmd,
15381 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15382 "Redistribute information from another routing protocol\n"
15383 FRR_IP_REDIST_HELP_STR_BGPD
15384 "Route map reference\n"
15385 "Pointer to route-map entries\n"
15386 "Metric for redistributed routes\n"
15387 "Default metric\n")
718e3744 15388{
585f1adc 15389 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15390 int idx_protocol = 1;
15391 int idx_word = 3;
15392 int idx_number = 5;
585f1adc
IR
15393 int type;
15394 uint32_t metric;
15395 struct bgp_redist *red;
15396 bool changed;
15397 struct route_map *route_map =
15398 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15399
15400 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15401 if (type < 0) {
15402 vty_out(vty, "%% Invalid route type\n");
15403 return CMD_WARNING_CONFIG_FAILED;
15404 }
15405 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15406
585f1adc
IR
15407 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15408 changed =
15409 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15410 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15411 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15412}
15413
15414ALIAS_HIDDEN(
15415 bgp_redistribute_ipv4_rmap_metric,
15416 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15417 "redistribute " FRR_IP_REDIST_STR_BGPD
15418 " route-map WORD metric (0-4294967295)",
15419 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15420 "Route map reference\n"
15421 "Pointer to route-map entries\n"
15422 "Metric for redistributed routes\n"
15423 "Default metric\n")
596c17ba 15424
585f1adc
IR
15425DEFUN (bgp_redistribute_ipv4_metric_rmap,
15426 bgp_redistribute_ipv4_metric_rmap_cmd,
15427 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15428 "Redistribute information from another routing protocol\n"
15429 FRR_IP_REDIST_HELP_STR_BGPD
15430 "Metric for redistributed routes\n"
15431 "Default metric\n"
15432 "Route map reference\n"
15433 "Pointer to route-map entries\n")
718e3744 15434{
585f1adc 15435 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15436 int idx_protocol = 1;
37a87b8f 15437 int idx_number = 3;
585f1adc
IR
15438 int idx_word = 5;
15439 int type;
15440 uint32_t metric;
15441 struct bgp_redist *red;
15442 bool changed;
15443 struct route_map *route_map =
15444 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15445
15446 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15447 if (type < 0) {
15448 vty_out(vty, "%% Invalid route type\n");
15449 return CMD_WARNING_CONFIG_FAILED;
15450 }
15451 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15452
585f1adc
IR
15453 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15454 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15455 changed |=
15456 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15457 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15458}
15459
15460ALIAS_HIDDEN(
15461 bgp_redistribute_ipv4_metric_rmap,
15462 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15463 "redistribute " FRR_IP_REDIST_STR_BGPD
15464 " metric (0-4294967295) route-map WORD",
15465 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15466 "Metric for redistributed routes\n"
15467 "Default metric\n"
15468 "Route map reference\n"
15469 "Pointer to route-map entries\n")
596c17ba 15470
585f1adc
IR
15471DEFUN (bgp_redistribute_ipv4_ospf,
15472 bgp_redistribute_ipv4_ospf_cmd,
15473 "redistribute <ospf|table> (1-65535)",
15474 "Redistribute information from another routing protocol\n"
15475 "Open Shortest Path First (OSPFv2)\n"
15476 "Non-main Kernel Routing Table\n"
15477 "Instance ID/Table ID\n")
7c8ff89e 15478{
585f1adc
IR
15479 VTY_DECLVAR_CONTEXT(bgp, bgp);
15480 int idx_ospf_table = 1;
d62a17ae 15481 int idx_number = 2;
585f1adc
IR
15482 unsigned short instance;
15483 unsigned short protocol;
7c8ff89e 15484
585f1adc 15485 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 15486
585f1adc
IR
15487 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15488 protocol = ZEBRA_ROUTE_OSPF;
15489 else
15490 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 15491
585f1adc
IR
15492 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15493 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
15494}
15495
d62a17ae 15496ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15497 "redistribute <ospf|table> (1-65535)",
15498 "Redistribute information from another routing protocol\n"
15499 "Open Shortest Path First (OSPFv2)\n"
15500 "Non-main Kernel Routing Table\n"
15501 "Instance ID/Table ID\n")
596c17ba 15502
585f1adc
IR
15503DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15504 bgp_redistribute_ipv4_ospf_rmap_cmd,
15505 "redistribute <ospf|table> (1-65535) route-map WORD",
15506 "Redistribute information from another routing protocol\n"
15507 "Open Shortest Path First (OSPFv2)\n"
15508 "Non-main Kernel Routing Table\n"
15509 "Instance ID/Table ID\n"
15510 "Route map reference\n"
15511 "Pointer to route-map entries\n")
7c8ff89e 15512{
585f1adc
IR
15513 VTY_DECLVAR_CONTEXT(bgp, bgp);
15514 int idx_ospf_table = 1;
d62a17ae 15515 int idx_number = 2;
15516 int idx_word = 4;
585f1adc
IR
15517 struct bgp_redist *red;
15518 unsigned short instance;
15519 int protocol;
15520 bool changed;
15521 struct route_map *route_map =
15522 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15523
15524 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15525 protocol = ZEBRA_ROUTE_OSPF;
15526 else
15527 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15528
585f1adc
IR
15529 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15530 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15531 changed =
15532 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15533 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15534}
15535
15536ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15537 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15538 "redistribute <ospf|table> (1-65535) route-map WORD",
15539 "Redistribute information from another routing protocol\n"
15540 "Open Shortest Path First (OSPFv2)\n"
15541 "Non-main Kernel Routing Table\n"
15542 "Instance ID/Table ID\n"
15543 "Route map reference\n"
15544 "Pointer to route-map entries\n")
596c17ba 15545
585f1adc
IR
15546DEFUN (bgp_redistribute_ipv4_ospf_metric,
15547 bgp_redistribute_ipv4_ospf_metric_cmd,
15548 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15549 "Redistribute information from another routing protocol\n"
15550 "Open Shortest Path First (OSPFv2)\n"
15551 "Non-main Kernel Routing Table\n"
15552 "Instance ID/Table ID\n"
15553 "Metric for redistributed routes\n"
15554 "Default metric\n")
7c8ff89e 15555{
585f1adc
IR
15556 VTY_DECLVAR_CONTEXT(bgp, bgp);
15557 int idx_ospf_table = 1;
d62a17ae 15558 int idx_number = 2;
15559 int idx_number_2 = 4;
585f1adc
IR
15560 uint32_t metric;
15561 struct bgp_redist *red;
15562 unsigned short instance;
15563 int protocol;
15564 bool changed;
15565
15566 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15567 protocol = ZEBRA_ROUTE_OSPF;
15568 else
15569 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15570
585f1adc
IR
15571 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15572 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15573
585f1adc
IR
15574 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15575 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15576 metric);
15577 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15578}
15579
15580ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15581 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15582 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15583 "Redistribute information from another routing protocol\n"
15584 "Open Shortest Path First (OSPFv2)\n"
15585 "Non-main Kernel Routing Table\n"
15586 "Instance ID/Table ID\n"
15587 "Metric for redistributed routes\n"
15588 "Default metric\n")
596c17ba 15589
585f1adc
IR
15590DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
15591 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15592 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15593 "Redistribute information from another routing protocol\n"
15594 "Open Shortest Path First (OSPFv2)\n"
15595 "Non-main Kernel Routing Table\n"
15596 "Instance ID/Table ID\n"
15597 "Route map reference\n"
15598 "Pointer to route-map entries\n"
15599 "Metric for redistributed routes\n"
15600 "Default metric\n")
7c8ff89e 15601{
585f1adc
IR
15602 VTY_DECLVAR_CONTEXT(bgp, bgp);
15603 int idx_ospf_table = 1;
d62a17ae 15604 int idx_number = 2;
15605 int idx_word = 4;
15606 int idx_number_2 = 6;
585f1adc
IR
15607 uint32_t metric;
15608 struct bgp_redist *red;
15609 unsigned short instance;
15610 int protocol;
15611 bool changed;
15612 struct route_map *route_map =
15613 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15614
15615 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15616 protocol = ZEBRA_ROUTE_OSPF;
15617 else
15618 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15619
585f1adc
IR
15620 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15621 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15622
585f1adc
IR
15623 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15624 changed =
15625 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15626 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15627 metric);
15628 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15629}
15630
15631ALIAS_HIDDEN(
15632 bgp_redistribute_ipv4_ospf_rmap_metric,
15633 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15634 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15635 "Redistribute information from another routing protocol\n"
15636 "Open Shortest Path First (OSPFv2)\n"
15637 "Non-main Kernel Routing Table\n"
15638 "Instance ID/Table ID\n"
15639 "Route map reference\n"
15640 "Pointer to route-map entries\n"
15641 "Metric for redistributed routes\n"
15642 "Default metric\n")
596c17ba 15643
585f1adc
IR
15644DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
15645 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15646 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15647 "Redistribute information from another routing protocol\n"
15648 "Open Shortest Path First (OSPFv2)\n"
15649 "Non-main Kernel Routing Table\n"
15650 "Instance ID/Table ID\n"
15651 "Metric for redistributed routes\n"
15652 "Default metric\n"
15653 "Route map reference\n"
15654 "Pointer to route-map entries\n")
7c8ff89e 15655{
585f1adc
IR
15656 VTY_DECLVAR_CONTEXT(bgp, bgp);
15657 int idx_ospf_table = 1;
d62a17ae 15658 int idx_number = 2;
15659 int idx_number_2 = 4;
15660 int idx_word = 6;
585f1adc
IR
15661 uint32_t metric;
15662 struct bgp_redist *red;
15663 unsigned short instance;
15664 int protocol;
15665 bool changed;
15666 struct route_map *route_map =
15667 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15668
15669 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15670 protocol = ZEBRA_ROUTE_OSPF;
15671 else
15672 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15673
585f1adc
IR
15674 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15675 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15676
585f1adc
IR
15677 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15678 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15679 metric);
15680 changed |=
15681 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15682 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15683}
15684
15685ALIAS_HIDDEN(
15686 bgp_redistribute_ipv4_ospf_metric_rmap,
15687 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15688 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15689 "Redistribute information from another routing protocol\n"
15690 "Open Shortest Path First (OSPFv2)\n"
15691 "Non-main Kernel Routing Table\n"
15692 "Instance ID/Table ID\n"
15693 "Metric for redistributed routes\n"
15694 "Default metric\n"
15695 "Route map reference\n"
15696 "Pointer to route-map entries\n")
596c17ba 15697
585f1adc
IR
15698DEFUN (no_bgp_redistribute_ipv4_ospf,
15699 no_bgp_redistribute_ipv4_ospf_cmd,
15700 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15701 NO_STR
15702 "Redistribute information from another routing protocol\n"
15703 "Open Shortest Path First (OSPFv2)\n"
15704 "Non-main Kernel Routing Table\n"
15705 "Instance ID/Table ID\n"
15706 "Metric for redistributed routes\n"
15707 "Default metric\n"
15708 "Route map reference\n"
15709 "Pointer to route-map entries\n")
7c8ff89e 15710{
585f1adc
IR
15711 VTY_DECLVAR_CONTEXT(bgp, bgp);
15712 int idx_ospf_table = 2;
d62a17ae 15713 int idx_number = 3;
585f1adc
IR
15714 unsigned short instance;
15715 int protocol;
37a87b8f 15716
585f1adc
IR
15717 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15718 protocol = ZEBRA_ROUTE_OSPF;
15719 else
15720 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15721
585f1adc
IR
15722 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15723 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
d62a17ae 15724}
15725
15726ALIAS_HIDDEN(
15727 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 15728 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15729 NO_STR
15730 "Redistribute information from another routing protocol\n"
15731 "Open Shortest Path First (OSPFv2)\n"
15732 "Non-main Kernel Routing Table\n"
15733 "Instance ID/Table ID\n"
15734 "Metric for redistributed routes\n"
15735 "Default metric\n"
15736 "Route map reference\n"
15737 "Pointer to route-map entries\n")
596c17ba 15738
585f1adc
IR
15739DEFUN (no_bgp_redistribute_ipv4,
15740 no_bgp_redistribute_ipv4_cmd,
15741 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15742 NO_STR
15743 "Redistribute information from another routing protocol\n"
15744 FRR_IP_REDIST_HELP_STR_BGPD
15745 "Metric for redistributed routes\n"
15746 "Default metric\n"
15747 "Route map reference\n"
15748 "Pointer to route-map entries\n")
718e3744 15749{
585f1adc 15750 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15751 int idx_protocol = 2;
585f1adc 15752 int type;
d62a17ae 15753
585f1adc
IR
15754 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15755 if (type < 0) {
15756 vty_out(vty, "%% Invalid route type\n");
15757 return CMD_WARNING_CONFIG_FAILED;
15758 }
15759 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
d62a17ae 15760}
15761
15762ALIAS_HIDDEN(
15763 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15764 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 15765 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15766 NO_STR
15767 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15768 "Metric for redistributed routes\n"
15769 "Default metric\n"
15770 "Route map reference\n"
15771 "Pointer to route-map entries\n")
596c17ba 15772
585f1adc
IR
15773DEFUN (bgp_redistribute_ipv6,
15774 bgp_redistribute_ipv6_cmd,
15775 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15776 "Redistribute information from another routing protocol\n"
15777 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 15778{
585f1adc 15779 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15780 int idx_protocol = 1;
585f1adc 15781 int type;
718e3744 15782
585f1adc
IR
15783 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15784 if (type < 0) {
15785 vty_out(vty, "%% Invalid route type\n");
15786 return CMD_WARNING_CONFIG_FAILED;
15787 }
718e3744 15788
585f1adc
IR
15789 bgp_redist_add(bgp, AFI_IP6, type, 0);
15790 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 15791}
15792
585f1adc
IR
15793DEFUN (bgp_redistribute_ipv6_rmap,
15794 bgp_redistribute_ipv6_rmap_cmd,
15795 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
15796 "Redistribute information from another routing protocol\n"
15797 FRR_IP6_REDIST_HELP_STR_BGPD
15798 "Route map reference\n"
15799 "Pointer to route-map entries\n")
718e3744 15800{
585f1adc 15801 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15802 int idx_protocol = 1;
15803 int idx_word = 3;
585f1adc
IR
15804 int type;
15805 struct bgp_redist *red;
15806 bool changed;
15807 struct route_map *route_map =
15808 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15809
15810 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15811 if (type < 0) {
15812 vty_out(vty, "%% Invalid route type\n");
15813 return CMD_WARNING_CONFIG_FAILED;
15814 }
37a87b8f 15815
585f1adc
IR
15816 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15817 changed =
15818 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15819 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15820}
15821
585f1adc 15822DEFUN (bgp_redistribute_ipv6_metric,
718e3744 15823 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 15824 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 15825 "Redistribute information from another routing protocol\n"
ab0181ee 15826 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 15827 "Metric for redistributed routes\n"
15828 "Default metric\n")
15829{
585f1adc 15830 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15831 int idx_protocol = 1;
15832 int idx_number = 3;
585f1adc
IR
15833 int type;
15834 uint32_t metric;
15835 struct bgp_redist *red;
15836 bool changed;
15837
15838 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15839 if (type < 0) {
15840 vty_out(vty, "%% Invalid route type\n");
15841 return CMD_WARNING_CONFIG_FAILED;
15842 }
15843 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15844
585f1adc
IR
15845 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15846 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
15847 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15848}
15849
585f1adc
IR
15850DEFUN (bgp_redistribute_ipv6_rmap_metric,
15851 bgp_redistribute_ipv6_rmap_metric_cmd,
15852 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15853 "Redistribute information from another routing protocol\n"
15854 FRR_IP6_REDIST_HELP_STR_BGPD
15855 "Route map reference\n"
15856 "Pointer to route-map entries\n"
15857 "Metric for redistributed routes\n"
15858 "Default metric\n")
718e3744 15859{
585f1adc 15860 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15861 int idx_protocol = 1;
15862 int idx_word = 3;
15863 int idx_number = 5;
585f1adc
IR
15864 int type;
15865 uint32_t metric;
15866 struct bgp_redist *red;
15867 bool changed;
15868 struct route_map *route_map =
15869 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15870
15871 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15872 if (type < 0) {
15873 vty_out(vty, "%% Invalid route type\n");
15874 return CMD_WARNING_CONFIG_FAILED;
15875 }
15876 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15877
585f1adc
IR
15878 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15879 changed =
15880 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15881 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
15882 metric);
15883 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15884}
15885
585f1adc
IR
15886DEFUN (bgp_redistribute_ipv6_metric_rmap,
15887 bgp_redistribute_ipv6_metric_rmap_cmd,
15888 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15889 "Redistribute information from another routing protocol\n"
15890 FRR_IP6_REDIST_HELP_STR_BGPD
15891 "Metric for redistributed routes\n"
15892 "Default metric\n"
15893 "Route map reference\n"
15894 "Pointer to route-map entries\n")
718e3744 15895{
585f1adc 15896 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15897 int idx_protocol = 1;
37a87b8f 15898 int idx_number = 3;
585f1adc
IR
15899 int idx_word = 5;
15900 int type;
15901 uint32_t metric;
15902 struct bgp_redist *red;
15903 bool changed;
15904 struct route_map *route_map =
15905 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15906
15907 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15908 if (type < 0) {
15909 vty_out(vty, "%% Invalid route type\n");
15910 return CMD_WARNING_CONFIG_FAILED;
15911 }
15912 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15913
585f1adc
IR
15914 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15915 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
15916 metric);
15917 changed |=
15918 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15919 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15920}
15921
585f1adc
IR
15922DEFUN (no_bgp_redistribute_ipv6,
15923 no_bgp_redistribute_ipv6_cmd,
15924 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15925 NO_STR
15926 "Redistribute information from another routing protocol\n"
15927 FRR_IP6_REDIST_HELP_STR_BGPD
15928 "Metric for redistributed routes\n"
15929 "Default metric\n"
15930 "Route map reference\n"
15931 "Pointer to route-map entries\n")
718e3744 15932{
585f1adc 15933 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15934 int idx_protocol = 2;
585f1adc 15935 int type;
37a87b8f 15936
585f1adc
IR
15937 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15938 if (type < 0) {
15939 vty_out(vty, "%% Invalid route type\n");
15940 return CMD_WARNING_CONFIG_FAILED;
15941 }
718e3744 15942
585f1adc 15943 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
d62a17ae 15944}
15945
4ab46701
AR
15946/* Neighbor update tcp-mss. */
15947static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
15948 const char *tcp_mss_str)
15949{
15950 struct peer *peer;
15951 uint32_t tcp_mss_val = 0;
15952
15953 peer = peer_and_group_lookup_vty(vty, peer_str);
15954 if (!peer)
15955 return CMD_WARNING_CONFIG_FAILED;
15956
15957 if (tcp_mss_str) {
15958 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
15959 peer_tcp_mss_set(peer, tcp_mss_val);
15960 } else {
15961 peer_tcp_mss_unset(peer);
15962 }
15963
15964 return CMD_SUCCESS;
15965}
15966
15967DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
15968 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
15969 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
15970 "TCP max segment size\n"
15971 "TCP MSS value\n")
15972{
15973 int peer_index = 1;
15974 int mss_index = 3;
15975
15976 vty_out(vty,
15977 " Warning: Reset BGP session for tcp-mss value to take effect\n");
15978 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
15979 argv[mss_index]->arg);
15980}
15981
15982DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
15983 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
15984 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
15985 "TCP max segment size\n"
15986 "TCP MSS value\n")
15987{
15988 int peer_index = 2;
15989
15990 vty_out(vty,
15991 " Warning: Reset BGP session for tcp-mss value to take effect\n");
15992 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
15993}
15994
dd65f45e
DL
15995static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
15996 afi_t afi, safi_t safi)
d62a17ae 15997{
15998 int i;
15999
16000 /* Unicast redistribution only. */
16001 if (safi != SAFI_UNICAST)
2b791107 16002 return;
d62a17ae 16003
16004 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16005 /* Redistribute BGP does not make sense. */
16006 if (i != ZEBRA_ROUTE_BGP) {
16007 struct list *red_list;
16008 struct listnode *node;
16009 struct bgp_redist *red;
16010
16011 red_list = bgp->redist[afi][i];
16012 if (!red_list)
16013 continue;
16014
16015 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16016 /* "redistribute" configuration. */
16017 vty_out(vty, " redistribute %s",
16018 zebra_route_string(i));
16019 if (red->instance)
16020 vty_out(vty, " %d", red->instance);
16021 if (red->redist_metric_flag)
16022 vty_out(vty, " metric %u",
16023 red->redist_metric);
16024 if (red->rmap.name)
16025 vty_out(vty, " route-map %s",
16026 red->rmap.name);
16027 vty_out(vty, "\n");
16028 }
16029 }
16030 }
718e3744 16031}
6b0655a2 16032
dd65f45e
DL
16033/* peer-group helpers for config-write */
16034
16035static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16036{
16037 if (!peer_group_active(peer)) {
16038 if (CHECK_FLAG(peer->flags_invert, flag))
16039 return !CHECK_FLAG(peer->flags, flag);
16040 else
16041 return !!CHECK_FLAG(peer->flags, flag);
16042 }
16043
16044 return !!CHECK_FLAG(peer->flags_override, flag);
16045}
16046
16047static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16048 uint32_t flag)
16049{
16050 if (!peer_group_active(peer)) {
16051 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16052 return !peer_af_flag_check(peer, afi, safi, flag);
16053 else
16054 return !!peer_af_flag_check(peer, afi, safi, flag);
16055 }
16056
16057 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16058}
16059
16060static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16061 uint8_t type, int direct)
16062{
16063 struct bgp_filter *filter;
16064
16065 if (peer_group_active(peer))
16066 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16067 type);
16068
16069 filter = &peer->filter[afi][safi];
16070 switch (type) {
16071 case PEER_FT_DISTRIBUTE_LIST:
16072 return !!(filter->dlist[direct].name);
16073 case PEER_FT_FILTER_LIST:
16074 return !!(filter->aslist[direct].name);
16075 case PEER_FT_PREFIX_LIST:
16076 return !!(filter->plist[direct].name);
16077 case PEER_FT_ROUTE_MAP:
16078 return !!(filter->map[direct].name);
16079 case PEER_FT_UNSUPPRESS_MAP:
16080 return !!(filter->usmap.name);
7f7940e6
MK
16081 case PEER_FT_ADVERTISE_MAP:
16082 return !!(filter->advmap.aname
16083 && ((filter->advmap.condition == direct)
16084 && filter->advmap.cname));
dd65f45e
DL
16085 default:
16086 return false;
16087 }
16088}
16089
16090/* Return true if the addpath type is set for peer and different from
16091 * peer-group.
16092 */
3dc339cd
DA
16093static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16094 safi_t safi)
dd65f45e
DL
16095{
16096 enum bgp_addpath_strat type, g_type;
16097
16098 type = peer->addpath_type[afi][safi];
16099
16100 if (type != BGP_ADDPATH_NONE) {
16101 if (peer_group_active(peer)) {
16102 g_type = peer->group->conf->addpath_type[afi][safi];
16103
16104 if (type != g_type)
3dc339cd 16105 return true;
dd65f45e 16106 else
3dc339cd 16107 return false;
dd65f45e
DL
16108 }
16109
3dc339cd 16110 return true;
dd65f45e
DL
16111 }
16112
3dc339cd 16113 return false;
dd65f45e
DL
16114}
16115
b9c7bc5a 16116/* This is part of the address-family block (unicast only) */
dd65f45e 16117static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16118 afi_t afi)
16119{
b9c7bc5a 16120 int indent = 2;
53970de3 16121 uint32_t tovpn_sid_index = 0;
ddb5b488 16122
8a066a70 16123 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16124 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16125 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16126 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16127 bgp->vpn_policy[afi]
bb4f6190 16128 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16129 else
16130 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16131 bgp->vpn_policy[afi]
16132 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16133 }
12a844a5
DS
16134 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16135 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16136 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16137 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16138 return;
16139
e70e9f8e
PZ
16140 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16141 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16142
16143 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16144
16145 } else {
16146 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16147 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16148 bgp->vpn_policy[afi].tovpn_label);
16149 }
ddb5b488 16150 }
53970de3
RS
16151
16152 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16153 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16154 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16155 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16156 } else if (tovpn_sid_index != 0) {
16157 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16158 tovpn_sid_index);
16159 }
16160
ddb5b488
PZ
16161 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16162 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16163 char buf[RD_ADDRSTRLEN];
b9c7bc5a 16164 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
16165 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16166 sizeof(buf)));
16167 }
16168 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16169 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16170
16171 char buf[PREFIX_STRLEN];
16172 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16173 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16174 sizeof(buf))) {
16175
b9c7bc5a
PZ
16176 vty_out(vty, "%*snexthop vpn export %s\n",
16177 indent, "", buf);
ddb5b488
PZ
16178 }
16179 }
16180 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16181 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16182 && ecommunity_cmp(
16183 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16184 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16185
16186 char *b = ecommunity_ecom2str(
16187 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16188 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16189 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16190 XFREE(MTYPE_ECOMMUNITY_STR, b);
16191 } else {
16192 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16193 char *b = ecommunity_ecom2str(
16194 bgp->vpn_policy[afi]
16195 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16196 ECOMMUNITY_FORMAT_ROUTE_MAP,
16197 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16198 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16199 XFREE(MTYPE_ECOMMUNITY_STR, b);
16200 }
16201 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16202 char *b = ecommunity_ecom2str(
16203 bgp->vpn_policy[afi]
16204 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16205 ECOMMUNITY_FORMAT_ROUTE_MAP,
16206 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16207 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16208 XFREE(MTYPE_ECOMMUNITY_STR, b);
16209 }
16210 }
bb4f6190
DS
16211
16212 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16213 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16214 bgp->vpn_policy[afi]
16215 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16216
301ad80a
PG
16217 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16218 char *b = ecommunity_ecom2str(
16219 bgp->vpn_policy[afi]
16220 .import_redirect_rtlist,
16221 ECOMMUNITY_FORMAT_ROUTE_MAP,
16222 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16223
9a659715
PG
16224 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16225 != ECOMMUNITY_SIZE)
c6423c31 16226 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16227 indent, "", b);
16228 else
16229 vty_out(vty, "%*srt redirect import %s\n",
16230 indent, "", b);
301ad80a
PG
16231 XFREE(MTYPE_ECOMMUNITY_STR, b);
16232 }
ddb5b488
PZ
16233}
16234
dd65f45e
DL
16235static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16236 afi_t afi, safi_t safi)
16237{
16238 struct bgp_filter *filter;
16239 char *addr;
16240
16241 addr = peer->host;
16242 filter = &peer->filter[afi][safi];
16243
16244 /* distribute-list. */
16245 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16246 FILTER_IN))
16247 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16248 filter->dlist[FILTER_IN].name);
16249
16250 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16251 FILTER_OUT))
16252 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16253 filter->dlist[FILTER_OUT].name);
16254
16255 /* prefix-list. */
16256 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16257 FILTER_IN))
16258 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16259 filter->plist[FILTER_IN].name);
16260
16261 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16262 FILTER_OUT))
16263 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16264 filter->plist[FILTER_OUT].name);
16265
16266 /* route-map. */
16267 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16268 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16269 filter->map[RMAP_IN].name);
16270
16271 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16272 RMAP_OUT))
16273 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16274 filter->map[RMAP_OUT].name);
16275
16276 /* unsuppress-map */
16277 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16278 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16279 filter->usmap.name);
16280
7f7940e6
MK
16281 /* advertise-map : always applied in OUT direction*/
16282 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16283 CONDITION_NON_EXIST))
16284 vty_out(vty,
16285 " neighbor %s advertise-map %s non-exist-map %s\n",
16286 addr, filter->advmap.aname, filter->advmap.cname);
16287
16288 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16289 CONDITION_EXIST))
16290 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16291 addr, filter->advmap.aname, filter->advmap.cname);
16292
dd65f45e
DL
16293 /* filter-list. */
16294 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16295 FILTER_IN))
16296 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16297 filter->aslist[FILTER_IN].name);
16298
16299 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16300 FILTER_OUT))
16301 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16302 filter->aslist[FILTER_OUT].name);
16303}
16304
16305/* BGP peer configuration display function. */
16306static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16307 struct peer *peer)
16308{
16309 struct peer *g_peer = NULL;
16310 char buf[SU_ADDRSTRLEN];
16311 char *addr;
16312 int if_pg_printed = false;
16313 int if_ras_printed = false;
16314
16315 /* Skip dynamic neighbors. */
16316 if (peer_dynamic_neighbor(peer))
16317 return;
16318
16319 if (peer->conf_if)
16320 addr = peer->conf_if;
16321 else
16322 addr = peer->host;
16323
16324 /************************************
16325 ****** Global to the neighbor ******
16326 ************************************/
16327 if (peer->conf_if) {
16328 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16329 vty_out(vty, " neighbor %s interface v6only", addr);
16330 else
16331 vty_out(vty, " neighbor %s interface", addr);
16332
16333 if (peer_group_active(peer)) {
16334 vty_out(vty, " peer-group %s", peer->group->name);
16335 if_pg_printed = true;
16336 } else if (peer->as_type == AS_SPECIFIED) {
16337 vty_out(vty, " remote-as %u", peer->as);
16338 if_ras_printed = true;
16339 } else if (peer->as_type == AS_INTERNAL) {
16340 vty_out(vty, " remote-as internal");
16341 if_ras_printed = true;
16342 } else if (peer->as_type == AS_EXTERNAL) {
16343 vty_out(vty, " remote-as external");
16344 if_ras_printed = true;
16345 }
16346
16347 vty_out(vty, "\n");
16348 }
16349
16350 /* remote-as and peer-group */
16351 /* peer is a member of a peer-group */
16352 if (peer_group_active(peer)) {
16353 g_peer = peer->group->conf;
16354
16355 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16356 if (peer->as_type == AS_SPECIFIED) {
16357 vty_out(vty, " neighbor %s remote-as %u\n",
16358 addr, peer->as);
16359 } else if (peer->as_type == AS_INTERNAL) {
16360 vty_out(vty,
16361 " neighbor %s remote-as internal\n",
16362 addr);
16363 } else if (peer->as_type == AS_EXTERNAL) {
16364 vty_out(vty,
16365 " neighbor %s remote-as external\n",
16366 addr);
16367 }
16368 }
16369
16370 /* For swpX peers we displayed the peer-group
16371 * via 'neighbor swpX interface peer-group PGNAME' */
16372 if (!if_pg_printed)
16373 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16374 peer->group->name);
16375 }
16376
16377 /* peer is NOT a member of a peer-group */
16378 else {
16379 /* peer is a peer-group, declare the peer-group */
16380 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16381 vty_out(vty, " neighbor %s peer-group\n", addr);
16382 }
16383
16384 if (!if_ras_printed) {
16385 if (peer->as_type == AS_SPECIFIED) {
16386 vty_out(vty, " neighbor %s remote-as %u\n",
16387 addr, peer->as);
16388 } else if (peer->as_type == AS_INTERNAL) {
16389 vty_out(vty,
16390 " neighbor %s remote-as internal\n",
16391 addr);
16392 } else if (peer->as_type == AS_EXTERNAL) {
16393 vty_out(vty,
16394 " neighbor %s remote-as external\n",
16395 addr);
16396 }
16397 }
16398 }
16399
16400 /* local-as */
16401 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16402 vty_out(vty, " neighbor %s local-as %u", addr,
16403 peer->change_local_as);
16404 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16405 vty_out(vty, " no-prepend");
16406 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16407 vty_out(vty, " replace-as");
16408 vty_out(vty, "\n");
16409 }
16410
16411 /* description */
16412 if (peer->desc) {
16413 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16414 }
16415
16416 /* shutdown */
16417 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16418 if (peer->tx_shutdown_message)
16419 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16420 peer->tx_shutdown_message);
16421 else
16422 vty_out(vty, " neighbor %s shutdown\n", addr);
16423 }
16424
8336c896
DA
16425 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16426 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16427 peer->rtt_expected, peer->rtt_keepalive_conf);
16428
dd65f45e 16429 /* bfd */
21bfce98
RZ
16430 if (peer->bfd_config)
16431 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
16432
16433 /* password */
16434 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16435 vty_out(vty, " neighbor %s password %s\n", addr,
16436 peer->password);
16437
16438 /* neighbor solo */
16439 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16440 if (!peer_group_active(peer)) {
16441 vty_out(vty, " neighbor %s solo\n", addr);
16442 }
16443 }
16444
16445 /* BGP port */
16446 if (peer->port != BGP_PORT_DEFAULT) {
16447 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16448 }
16449
16450 /* Local interface name */
16451 if (peer->ifname) {
16452 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16453 }
16454
4ab46701
AR
16455 /* TCP max segment size */
16456 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16457 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16458
dd65f45e
DL
16459 /* passive */
16460 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16461 vty_out(vty, " neighbor %s passive\n", addr);
16462
16463 /* ebgp-multihop */
16464 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
16465 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16466 && peer->ttl == MAXTTL)) {
dd65f45e
DL
16467 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16468 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16469 peer->ttl);
16470 }
16471 }
16472
16473 /* ttl-security hops */
e2521429 16474 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
16475 if (!peer_group_active(peer)
16476 || g_peer->gtsm_hops != peer->gtsm_hops) {
16477 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16478 addr, peer->gtsm_hops);
16479 }
16480 }
16481
16482 /* disable-connected-check */
16483 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16484 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16485
27aa23a4
DA
16486 /* link-bw-encoding-ieee */
16487 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16488 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16489 addr);
16490
d08c0c80
DA
16491 /* extended-optional-parameters */
16492 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16493 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16494 addr);
16495
dd65f45e
DL
16496 /* enforce-first-as */
16497 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16498 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16499
16500 /* update-source */
16501 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16502 if (peer->update_source)
16503 vty_out(vty, " neighbor %s update-source %s\n", addr,
16504 sockunion2str(peer->update_source, buf,
16505 SU_ADDRSTRLEN));
16506 else if (peer->update_if)
16507 vty_out(vty, " neighbor %s update-source %s\n", addr,
16508 peer->update_if);
16509 }
16510
16511 /* advertisement-interval */
16512 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16513 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16514 peer->routeadv);
16515
16516 /* timers */
16517 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16518 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16519 peer->keepalive, peer->holdtime);
16520
16521 /* timers connect */
16522 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16523 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16524 peer->connect);
5d5393b9
DL
16525 /* need special-case handling for changed default values due to
16526 * config profile / version (because there is no "timers bgp connect"
16527 * command, we need to save this per-peer :/)
16528 */
16529 else if (!peer_group_active(peer) && !peer->connect &&
16530 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16531 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16532 peer->bgp->default_connect_retry);
dd65f45e 16533
d43114f3
DS
16534 /* timers delayopen */
16535 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16536 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16537 peer->delayopen);
16538 /* Save config even though flag is not set if default values have been
16539 * changed
16540 */
16541 else if (!peer_group_active(peer) && !peer->delayopen
16542 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16543 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16544 peer->bgp->default_delayopen);
16545
dd65f45e
DL
16546 /* capability dynamic */
16547 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16548 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16549
16550 /* capability extended-nexthop */
16551 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16552 if (!peer->conf_if) {
16553 if (CHECK_FLAG(peer->flags_invert,
16554 PEER_FLAG_CAPABILITY_ENHE))
16555 vty_out(vty,
16556 " no neighbor %s capability extended-nexthop\n",
16557 addr);
16558 else
16559 vty_out(vty,
16560 " neighbor %s capability extended-nexthop\n",
16561 addr);
16562 }
16563 }
16564
16565 /* dont-capability-negotiation */
16566 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16567 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16568
16569 /* override-capability */
16570 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16571 vty_out(vty, " neighbor %s override-capability\n", addr);
16572
16573 /* strict-capability-match */
16574 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16575 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16576
16577 /* Sender side AS path loop detection. */
16578 if (peer->as_path_loop_detection)
16579 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16580 addr);
cfd47646 16581
16582 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16583 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 16584
16585 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16586 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 16587 vty_out(vty,
16588 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
16589 } else if (CHECK_FLAG(
16590 peer->peer_gr_new_status_flag,
16591 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 16592 vty_out(vty,
16593 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
16594 } else if (
16595 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16596 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16597 && !(CHECK_FLAG(
16598 peer->peer_gr_new_status_flag,
16599 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16600 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16601 addr);
cfd47646 16602 }
16603 }
dd65f45e
DL
16604}
16605
16606/* BGP peer configuration display function. */
16607static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16608 struct peer *peer, afi_t afi, safi_t safi)
16609{
16610 struct peer *g_peer = NULL;
16611 char *addr;
16612 bool flag_scomm, flag_secomm, flag_slcomm;
16613
16614 /* Skip dynamic neighbors. */
16615 if (peer_dynamic_neighbor(peer))
16616 return;
16617
16618 if (peer->conf_if)
16619 addr = peer->conf_if;
16620 else
16621 addr = peer->host;
16622
16623 /************************************
16624 ****** Per AF to the neighbor ******
16625 ************************************/
16626 if (peer_group_active(peer)) {
16627 g_peer = peer->group->conf;
16628
16629 /* If the peer-group is active but peer is not, print a 'no
16630 * activate' */
16631 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16632 vty_out(vty, " no neighbor %s activate\n", addr);
16633 }
16634
16635 /* If the peer-group is not active but peer is, print an
16636 'activate' */
16637 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16638 vty_out(vty, " neighbor %s activate\n", addr);
16639 }
16640 } else {
16641 if (peer->afc[afi][safi]) {
38d11af5
TA
16642 if (safi == SAFI_ENCAP)
16643 vty_out(vty, " neighbor %s activate\n", addr);
16644 else if (!bgp->default_af[afi][safi])
dd65f45e
DL
16645 vty_out(vty, " neighbor %s activate\n", addr);
16646 } else {
38d11af5
TA
16647 if (bgp->default_af[afi][safi])
16648 vty_out(vty, " no neighbor %s activate\n",
16649 addr);
dd65f45e
DL
16650 }
16651 }
16652
16653 /* addpath TX knobs */
16654 if (peergroup_af_addpath_check(peer, afi, safi)) {
16655 switch (peer->addpath_type[afi][safi]) {
16656 case BGP_ADDPATH_ALL:
16657 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16658 addr);
16659 break;
16660 case BGP_ADDPATH_BEST_PER_AS:
16661 vty_out(vty,
16662 " neighbor %s addpath-tx-bestpath-per-AS\n",
16663 addr);
16664 break;
16665 case BGP_ADDPATH_MAX:
16666 case BGP_ADDPATH_NONE:
16667 break;
16668 }
16669 }
16670
7c0e4312
DA
16671 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
16672 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
16673
dd65f45e
DL
16674 /* ORF capability. */
16675 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16676 || peergroup_af_flag_check(peer, afi, safi,
16677 PEER_FLAG_ORF_PREFIX_RM)) {
16678 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16679
16680 if (peergroup_af_flag_check(peer, afi, safi,
16681 PEER_FLAG_ORF_PREFIX_SM)
16682 && peergroup_af_flag_check(peer, afi, safi,
16683 PEER_FLAG_ORF_PREFIX_RM))
16684 vty_out(vty, " both");
16685 else if (peergroup_af_flag_check(peer, afi, safi,
16686 PEER_FLAG_ORF_PREFIX_SM))
16687 vty_out(vty, " send");
16688 else
16689 vty_out(vty, " receive");
16690 vty_out(vty, "\n");
16691 }
16692
dd65f45e
DL
16693 /* Route reflector client. */
16694 if (peergroup_af_flag_check(peer, afi, safi,
16695 PEER_FLAG_REFLECTOR_CLIENT)) {
16696 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16697 }
16698
16699 /* next-hop-self force */
16700 if (peergroup_af_flag_check(peer, afi, safi,
16701 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16702 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16703 }
16704
16705 /* next-hop-self */
16706 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16707 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16708 }
16709
16710 /* remove-private-AS */
16711 if (peergroup_af_flag_check(peer, afi, safi,
16712 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16713 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16714 addr);
16715 }
16716
16717 else if (peergroup_af_flag_check(peer, afi, safi,
16718 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16719 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16720 addr);
16721 }
16722
16723 else if (peergroup_af_flag_check(peer, afi, safi,
16724 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16725 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16726 }
16727
16728 else if (peergroup_af_flag_check(peer, afi, safi,
16729 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16730 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16731 }
16732
16733 /* as-override */
16734 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16735 vty_out(vty, " neighbor %s as-override\n", addr);
16736 }
16737
16738 /* send-community print. */
16739 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16740 PEER_FLAG_SEND_COMMUNITY);
16741 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16742 PEER_FLAG_SEND_EXT_COMMUNITY);
16743 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16744 PEER_FLAG_SEND_LARGE_COMMUNITY);
16745
16746 if (flag_scomm && flag_secomm && flag_slcomm) {
16747 vty_out(vty, " no neighbor %s send-community all\n", addr);
16748 } else {
16749 if (flag_scomm)
16750 vty_out(vty, " no neighbor %s send-community\n", addr);
16751 if (flag_secomm)
16752 vty_out(vty,
16753 " no neighbor %s send-community extended\n",
16754 addr);
16755
16756 if (flag_slcomm)
16757 vty_out(vty, " no neighbor %s send-community large\n",
16758 addr);
16759 }
16760
16761 /* Default information */
16762 if (peergroup_af_flag_check(peer, afi, safi,
16763 PEER_FLAG_DEFAULT_ORIGINATE)) {
16764 vty_out(vty, " neighbor %s default-originate", addr);
16765
16766 if (peer->default_rmap[afi][safi].name)
16767 vty_out(vty, " route-map %s",
16768 peer->default_rmap[afi][safi].name);
16769
16770 vty_out(vty, "\n");
16771 }
16772
16773 /* Soft reconfiguration inbound. */
16774 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16775 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16776 addr);
16777 }
16778
16779 /* maximum-prefix. */
16780 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 16781 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
16782 peer->pmax[afi][safi]);
16783
16784 if (peer->pmax_threshold[afi][safi]
16785 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16786 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16787 if (peer_af_flag_check(peer, afi, safi,
16788 PEER_FLAG_MAX_PREFIX_WARNING))
16789 vty_out(vty, " warning-only");
16790 if (peer->pmax_restart[afi][safi])
16791 vty_out(vty, " restart %u",
16792 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
16793 if (peer_af_flag_check(peer, afi, safi,
16794 PEER_FLAG_MAX_PREFIX_FORCE))
16795 vty_out(vty, " force");
dd65f45e
DL
16796
16797 vty_out(vty, "\n");
16798 }
16799
fde246e8
DA
16800 /* maximum-prefix-out */
16801 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 16802 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
16803 addr, peer->pmax_out[afi][safi]);
16804
dd65f45e
DL
16805 /* Route server client. */
16806 if (peergroup_af_flag_check(peer, afi, safi,
16807 PEER_FLAG_RSERVER_CLIENT)) {
16808 vty_out(vty, " neighbor %s route-server-client\n", addr);
16809 }
16810
16811 /* Nexthop-local unchanged. */
16812 if (peergroup_af_flag_check(peer, afi, safi,
16813 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16814 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16815 }
16816
16817 /* allowas-in <1-10> */
16818 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16819 if (peer_af_flag_check(peer, afi, safi,
16820 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16821 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16822 } else if (peer->allowas_in[afi][safi] == 3) {
16823 vty_out(vty, " neighbor %s allowas-in\n", addr);
16824 } else {
16825 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16826 peer->allowas_in[afi][safi]);
16827 }
16828 }
16829
16830 /* weight */
16831 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16832 vty_out(vty, " neighbor %s weight %lu\n", addr,
16833 peer->weight[afi][safi]);
16834
16835 /* Filter. */
16836 bgp_config_write_filter(vty, peer, afi, safi);
16837
16838 /* atribute-unchanged. */
16839 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16840 || (safi != SAFI_EVPN
16841 && peer_af_flag_check(peer, afi, safi,
16842 PEER_FLAG_NEXTHOP_UNCHANGED))
16843 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16844
16845 if (!peer_group_active(peer)
16846 || peergroup_af_flag_check(peer, afi, safi,
16847 PEER_FLAG_AS_PATH_UNCHANGED)
16848 || peergroup_af_flag_check(peer, afi, safi,
16849 PEER_FLAG_NEXTHOP_UNCHANGED)
16850 || peergroup_af_flag_check(peer, afi, safi,
16851 PEER_FLAG_MED_UNCHANGED)) {
16852
16853 vty_out(vty,
16854 " neighbor %s attribute-unchanged%s%s%s\n",
16855 addr,
16856 peer_af_flag_check(peer, afi, safi,
16857 PEER_FLAG_AS_PATH_UNCHANGED)
16858 ? " as-path"
16859 : "",
16860 peer_af_flag_check(peer, afi, safi,
16861 PEER_FLAG_NEXTHOP_UNCHANGED)
16862 ? " next-hop"
16863 : "",
16864 peer_af_flag_check(peer, afi, safi,
16865 PEER_FLAG_MED_UNCHANGED)
16866 ? " med"
16867 : "");
16868 }
16869 }
16870}
16871
16872/* Address family based peer configuration display. */
16873static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
16874 safi_t safi)
16875{
16876 struct peer *peer;
16877 struct peer_group *group;
16878 struct listnode *node, *nnode;
16879
16880
16881 vty_frame(vty, " !\n address-family ");
16882 if (afi == AFI_IP) {
16883 if (safi == SAFI_UNICAST)
16884 vty_frame(vty, "ipv4 unicast");
16885 else if (safi == SAFI_LABELED_UNICAST)
16886 vty_frame(vty, "ipv4 labeled-unicast");
16887 else if (safi == SAFI_MULTICAST)
16888 vty_frame(vty, "ipv4 multicast");
16889 else if (safi == SAFI_MPLS_VPN)
16890 vty_frame(vty, "ipv4 vpn");
16891 else if (safi == SAFI_ENCAP)
16892 vty_frame(vty, "ipv4 encap");
16893 else if (safi == SAFI_FLOWSPEC)
16894 vty_frame(vty, "ipv4 flowspec");
16895 } else if (afi == AFI_IP6) {
16896 if (safi == SAFI_UNICAST)
16897 vty_frame(vty, "ipv6 unicast");
16898 else if (safi == SAFI_LABELED_UNICAST)
16899 vty_frame(vty, "ipv6 labeled-unicast");
16900 else if (safi == SAFI_MULTICAST)
16901 vty_frame(vty, "ipv6 multicast");
16902 else if (safi == SAFI_MPLS_VPN)
16903 vty_frame(vty, "ipv6 vpn");
16904 else if (safi == SAFI_ENCAP)
16905 vty_frame(vty, "ipv6 encap");
16906 else if (safi == SAFI_FLOWSPEC)
16907 vty_frame(vty, "ipv6 flowspec");
16908 } else if (afi == AFI_L2VPN) {
16909 if (safi == SAFI_EVPN)
16910 vty_frame(vty, "l2vpn evpn");
16911 }
16912 vty_frame(vty, "\n");
16913
16914 bgp_config_write_distance(vty, bgp, afi, safi);
16915
16916 bgp_config_write_network(vty, bgp, afi, safi);
16917
16918 bgp_config_write_redistribute(vty, bgp, afi, safi);
16919
8a4e7fe6
DA
16920 /* BGP flag dampening. */
16921 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6c75f4b3 16922 bgp_config_write_damp(vty, afi, safi);
8a4e7fe6 16923
dd65f45e
DL
16924 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
16925 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
16926
16927 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
16928 /* Do not display doppelganger peers */
16929 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16930 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
16931 }
16932
16933 bgp_config_write_maxpaths(vty, bgp, afi, safi);
16934 bgp_config_write_table_map(vty, bgp, afi, safi);
16935
16936 if (safi == SAFI_EVPN)
16937 bgp_config_write_evpn_info(vty, bgp, afi, safi);
16938
16939 if (safi == SAFI_FLOWSPEC)
16940 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
16941
16942 if (safi == SAFI_UNICAST) {
16943 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
16944 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16945 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
16946
16947 vty_out(vty, " export vpn\n");
16948 }
16949 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16950 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
16951
16952 vty_out(vty, " import vpn\n");
16953 }
16954 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16955 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
16956 char *name;
16957
16958 for (ALL_LIST_ELEMENTS_RO(
16959 bgp->vpn_policy[afi].import_vrf, node,
16960 name))
16961 vty_out(vty, " import vrf %s\n", name);
16962 }
16963 }
16964
16965 vty_endframe(vty, " exit-address-family\n");
16966}
16967
16968int bgp_config_write(struct vty *vty)
16969{
16970 struct bgp *bgp;
16971 struct peer_group *group;
16972 struct peer *peer;
16973 struct listnode *node, *nnode;
16974 struct listnode *mnode, *mnnode;
b16bcbba
TA
16975 afi_t afi;
16976 safi_t safi;
dd65f45e
DL
16977
16978 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
16979 vty_out(vty, "bgp route-map delay-timer %u\n",
16980 bm->rmap_update_timer);
16981
d70583f7
D
16982 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
16983 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
16984 if (bm->v_update_delay != bm->v_establish_wait)
16985 vty_out(vty, " %d", bm->v_establish_wait);
16986 vty_out(vty, "\n");
16987 }
16988
9acb67cb
DS
16989 if (bm->wait_for_fib)
16990 vty_out(vty, "bgp suppress-fib-pending\n");
16991
05bd726c 16992 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
16993 vty_out(vty, "bgp graceful-shutdown\n");
16994
c163f297
DS
16995 /* No-RIB (Zebra) option flag configuration */
16996 if (bgp_option_check(BGP_OPT_NO_FIB))
16997 vty_out(vty, "bgp no-rib\n");
16998
ec0acb80 16999 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
e46723a5
DS
17000 vty_out(vty, "no bgp send-extra-data zebra\n");
17001
dd65f45e
DL
17002 /* BGP configuration. */
17003 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17004
17005 /* skip all auto created vrf as they dont have user config */
17006 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17007 continue;
17008
17009 /* Router bgp ASN */
17010 vty_out(vty, "router bgp %u", bgp->as);
17011
17012 if (bgp->name)
17013 vty_out(vty, " %s %s",
17014 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17015 ? "view" : "vrf", bgp->name);
17016 vty_out(vty, "\n");
17017
17018 /* BGP fast-external-failover. */
17019 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17020 vty_out(vty, " no bgp fast-external-failover\n");
17021
17022 /* BGP router ID. */
3a6290bd 17023 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17024 vty_out(vty, " bgp router-id %pI4\n",
17025 &bgp->router_id_static);
dd65f45e 17026
c208c586
S
17027 /* Suppress fib pending */
17028 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17029 vty_out(vty, " bgp suppress-fib-pending\n");
17030
dd65f45e 17031 /* BGP log-neighbor-changes. */
892fedb6 17032 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17033 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17034 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17035 CHECK_FLAG(bgp->flags,
17036 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17037 ? ""
17038 : "no ");
17039
17040 /* BGP configuration. */
892fedb6 17041 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17042 vty_out(vty, " bgp always-compare-med\n");
17043
17044 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17045 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17046 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17047 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17048 CHECK_FLAG(bgp->flags,
17049 BGP_FLAG_EBGP_REQUIRES_POLICY)
17050 ? ""
17051 : "no ");
dd65f45e
DL
17052
17053 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17054 if (bgp->reject_as_sets)
dd65f45e
DL
17055 vty_out(vty, " bgp reject-as-sets\n");
17056
2adac256
DA
17057 /* Suppress duplicate updates if the route actually not changed
17058 */
17059 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17060 != SAVE_BGP_SUPPRESS_DUPLICATES)
17061 vty_out(vty, " %sbgp suppress-duplicates\n",
17062 CHECK_FLAG(bgp->flags,
17063 BGP_FLAG_SUPPRESS_DUPLICATES)
17064 ? ""
17065 : "no ");
17066
b16bcbba
TA
17067 /* BGP default <afi>-<safi> */
17068 FOREACH_AFI_SAFI (afi, safi) {
17069 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17070 if (!bgp->default_af[afi][safi])
17071 vty_out(vty, " no bgp default %s\n",
17072 get_bgp_default_af_flag(afi,
17073 safi));
17074 } else if (bgp->default_af[afi][safi])
17075 vty_out(vty, " bgp default %s\n",
17076 get_bgp_default_af_flag(afi, safi));
17077 }
e84c59af 17078
dd65f45e
DL
17079 /* BGP default local-preference. */
17080 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17081 vty_out(vty, " bgp default local-preference %u\n",
17082 bgp->default_local_pref);
17083
17084 /* BGP default show-hostname */
892fedb6 17085 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17086 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17087 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17088 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17089 ? ""
17090 : "no ");
17091
aef999a2
DA
17092 /* BGP default show-nexthop-hostname */
17093 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17094 != SAVE_BGP_SHOW_HOSTNAME)
17095 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17096 CHECK_FLAG(bgp->flags,
17097 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17098 ? ""
17099 : "no ");
17100
dd65f45e
DL
17101 /* BGP default subgroup-pkt-queue-max. */
17102 if (bgp->default_subgroup_pkt_queue_max
17103 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17104 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17105 bgp->default_subgroup_pkt_queue_max);
17106
17107 /* BGP client-to-client reflection. */
892fedb6 17108 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17109 vty_out(vty, " no bgp client-to-client reflection\n");
17110
17111 /* BGP cluster ID. */
17112 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17113 vty_out(vty, " bgp cluster-id %pI4\n",
17114 &bgp->cluster_id);
dd65f45e
DL
17115
17116 /* Disable ebgp connected nexthop check */
892fedb6 17117 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17118 vty_out(vty,
17119 " bgp disable-ebgp-connected-route-check\n");
17120
17121 /* Confederation identifier*/
17122 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17123 vty_out(vty, " bgp confederation identifier %u\n",
17124 bgp->confed_id);
17125
17126 /* Confederation peer */
17127 if (bgp->confed_peers_cnt > 0) {
17128 int i;
17129
17130 vty_out(vty, " bgp confederation peers");
17131
17132 for (i = 0; i < bgp->confed_peers_cnt; i++)
17133 vty_out(vty, " %u", bgp->confed_peers[i]);
17134
17135 vty_out(vty, "\n");
17136 }
17137
17138 /* BGP deterministic-med. */
892fedb6 17139 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 17140 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 17141 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
17142 CHECK_FLAG(bgp->flags,
17143 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
17144 ? ""
17145 : "no ");
17146
17147 /* BGP update-delay. */
17148 bgp_config_write_update_delay(vty, bgp);
17149
17150 if (bgp->v_maxmed_onstartup
17151 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17152 vty_out(vty, " bgp max-med on-startup %u",
17153 bgp->v_maxmed_onstartup);
17154 if (bgp->maxmed_onstartup_value
17155 != BGP_MAXMED_VALUE_DEFAULT)
17156 vty_out(vty, " %u",
17157 bgp->maxmed_onstartup_value);
17158 vty_out(vty, "\n");
17159 }
17160 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17161 vty_out(vty, " bgp max-med administrative");
17162 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17163 vty_out(vty, " %u", bgp->maxmed_admin_value);
17164 vty_out(vty, "\n");
17165 }
17166
17167 /* write quanta */
17168 bgp_config_write_wpkt_quanta(vty, bgp);
17169 /* read quanta */
17170 bgp_config_write_rpkt_quanta(vty, bgp);
17171
17172 /* coalesce time */
17173 bgp_config_write_coalesce_time(vty, bgp);
17174
05bd726c 17175 /* BGP per-instance graceful-shutdown */
17176 /* BGP-wide settings and per-instance settings are mutually
17177 * exclusive.
17178 */
17179 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17180 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17181 vty_out(vty, " bgp graceful-shutdown\n");
17182
8606be87
DA
17183 /* Long-lived Graceful Restart */
17184 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17185 vty_out(vty,
17186 " bgp long-lived-graceful-restart stale-time %u\n",
17187 bgp->llgr_stale_time);
17188
dd65f45e
DL
17189 /* BGP graceful-restart. */
17190 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17191 vty_out(vty,
17192 " bgp graceful-restart stalepath-time %u\n",
17193 bgp->stalepath_time);
cfd47646 17194
dd65f45e
DL
17195 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17196 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17197 bgp->restart_time);
cfd47646 17198
17199 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17200 vty_out(vty,
17201 " bgp graceful-restart select-defer-time %u\n",
17202 bgp->select_defer_time);
17203
17204 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
17205 vty_out(vty, " bgp graceful-restart\n");
17206
cfd47646 17207 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17208 vty_out(vty, " bgp graceful-restart-disable\n");
17209
dd65f45e 17210 /* BGP graceful-restart Preserve State F bit. */
892fedb6 17211 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
17212 vty_out(vty,
17213 " bgp graceful-restart preserve-fw-state\n");
17214
dc95985f 17215 /* Stale timer for RIB */
17216 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17217 vty_out(vty,
17218 " bgp graceful-restart rib-stale-time %u\n",
17219 bgp->rib_stale_time);
17220
dd65f45e 17221 /* BGP bestpath method. */
892fedb6 17222 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 17223 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 17224 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
17225 vty_out(vty, " bgp bestpath as-path confed\n");
17226
892fedb6
DA
17227 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17228 if (CHECK_FLAG(bgp->flags,
17229 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
17230 vty_out(vty,
17231 " bgp bestpath as-path multipath-relax as-set\n");
17232 } else {
17233 vty_out(vty,
17234 " bgp bestpath as-path multipath-relax\n");
17235 }
17236 }
17237
892fedb6 17238 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17239 vty_out(vty,
17240 " bgp route-reflector allow-outbound-policy\n");
17241 }
892fedb6 17242 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17243 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17244 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17245 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17246 vty_out(vty, " bgp bestpath med");
892fedb6 17247 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17248 vty_out(vty, " confed");
892fedb6
DA
17249 if (CHECK_FLAG(bgp->flags,
17250 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17251 vty_out(vty, " missing-as-worst");
17252 vty_out(vty, "\n");
17253 }
17254
ee88563a
JM
17255 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17256 vty_out(vty,
17257 " bgp bestpath peer-type multipath-relax\n");
17258
f7e1c681 17259 /* Link bandwidth handling. */
17260 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17261 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17262 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17263 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17264 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17265 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17266
dd65f45e 17267 /* BGP network import check. */
892fedb6 17268 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17269 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17270 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17271 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17272 ? ""
17273 : "no ");
17274
17275 /* BGP timers configuration. */
5d5393b9 17276 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 17277 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17278 vty_out(vty, " timers bgp %u %u\n",
17279 bgp->default_keepalive, bgp->default_holdtime);
17280
b042667a
TI
17281 /* BGP minimum holdtime configuration. */
17282 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17283 && bgp->default_min_holdtime != 0)
17284 vty_out(vty, " bgp minimum-holdtime %u\n",
17285 bgp->default_min_holdtime);
17286
389e4f92
QY
17287 /* Conditional advertisement timer configuration */
17288 if (bgp->condition_check_period
17289 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17290 vty_out(vty,
17291 " bgp conditional-advertisement timer %u\n",
17292 bgp->condition_check_period);
17293
dd65f45e
DL
17294 /* peer-group */
17295 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17296 bgp_config_write_peer_global(vty, bgp, group->conf);
17297 }
17298
17299 /* Normal neighbor configuration. */
17300 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17301 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17302 bgp_config_write_peer_global(vty, bgp, peer);
17303 }
17304
17305 /* listen range and limit for dynamic BGP neighbors */
17306 bgp_config_write_listen(vty, bgp);
17307
17308 /*
17309 * BGP default autoshutdown neighbors
17310 *
17311 * This must be placed after any peer and peer-group
17312 * configuration, to avoid setting all peers to shutdown after
17313 * a daemon restart, which is undesired behavior. (see #2286)
17314 */
17315 if (bgp->autoshutdown)
17316 vty_out(vty, " bgp default shutdown\n");
17317
9cf59432
DS
17318 /* BGP instance administrative shutdown */
17319 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17320 vty_out(vty, " bgp shutdown\n");
17321
f852eb98
PG
17322 if (bgp->fast_convergence)
17323 vty_out(vty, " bgp fast-convergence\n");
17324
a0281b2e
HS
17325 if (bgp->srv6_enabled) {
17326 vty_frame(vty, " !\n segment-routing srv6\n");
96db4340 17327 if (strlen(bgp->srv6_locator_name))
a0281b2e
HS
17328 vty_out(vty, " locator %s\n",
17329 bgp->srv6_locator_name);
ff7c3ee1 17330 vty_endframe(vty, " exit\n");
a0281b2e
HS
17331 }
17332
17333
dd65f45e
DL
17334 /* IPv4 unicast configuration. */
17335 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17336
17337 /* IPv4 multicast configuration. */
17338 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17339
17340 /* IPv4 labeled-unicast configuration. */
17341 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17342
17343 /* IPv4 VPN configuration. */
17344 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17345
17346 /* ENCAPv4 configuration. */
17347 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17348
17349 /* FLOWSPEC v4 configuration. */
17350 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17351
17352 /* IPv6 unicast configuration. */
17353 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17354
17355 /* IPv6 multicast configuration. */
17356 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17357
17358 /* IPv6 labeled-unicast configuration. */
17359 bgp_config_write_family(vty, bgp, AFI_IP6,
17360 SAFI_LABELED_UNICAST);
17361
17362 /* IPv6 VPN configuration. */
17363 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17364
17365 /* ENCAPv6 configuration. */
17366 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17367
17368 /* FLOWSPEC v6 configuration. */
17369 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17370
17371 /* EVPN configuration. */
17372 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17373
17374 hook_call(bgp_inst_config_write, bgp, vty);
17375
49e5a4a0 17376#ifdef ENABLE_BGP_VNC
dd65f45e
DL
17377 bgp_rfapi_cfg_write(vty, bgp);
17378#endif
17379
07679ad9 17380 vty_out(vty, "exit\n");
dd65f45e
DL
17381 vty_out(vty, "!\n");
17382 }
17383 return 0;
17384}
17385
ddb5b488 17386
718e3744 17387/* BGP node structure. */
d62a17ae 17388static struct cmd_node bgp_node = {
f4b8291f 17389 .name = "bgp",
62b346ee 17390 .node = BGP_NODE,
24389580 17391 .parent_node = CONFIG_NODE,
62b346ee 17392 .prompt = "%s(config-router)# ",
612c2c15 17393 .config_write = bgp_config_write,
718e3744 17394};
17395
d62a17ae 17396static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 17397 .name = "bgp ipv4 unicast",
62b346ee 17398 .node = BGP_IPV4_NODE,
24389580 17399 .parent_node = BGP_NODE,
62b346ee 17400 .prompt = "%s(config-router-af)# ",
dd2c81b8 17401 .no_xpath = true,
718e3744 17402};
17403
d62a17ae 17404static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 17405 .name = "bgp ipv4 multicast",
62b346ee 17406 .node = BGP_IPV4M_NODE,
24389580 17407 .parent_node = BGP_NODE,
62b346ee 17408 .prompt = "%s(config-router-af)# ",
dd2c81b8 17409 .no_xpath = true,
718e3744 17410};
17411
d62a17ae 17412static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 17413 .name = "bgp ipv4 labeled unicast",
62b346ee 17414 .node = BGP_IPV4L_NODE,
24389580 17415 .parent_node = BGP_NODE,
62b346ee 17416 .prompt = "%s(config-router-af)# ",
dd2c81b8 17417 .no_xpath = true,
f51bae9c
DS
17418};
17419
d62a17ae 17420static struct cmd_node bgp_ipv6_unicast_node = {
a17cfb3f 17421 .name = "bgp ipv6 unicast",
62b346ee 17422 .node = BGP_IPV6_NODE,
24389580 17423 .parent_node = BGP_NODE,
62b346ee 17424 .prompt = "%s(config-router-af)# ",
dd2c81b8 17425 .no_xpath = true,
718e3744 17426};
17427
d62a17ae 17428static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 17429 .name = "bgp ipv6 multicast",
62b346ee 17430 .node = BGP_IPV6M_NODE,
24389580 17431 .parent_node = BGP_NODE,
62b346ee 17432 .prompt = "%s(config-router-af)# ",
dd2c81b8 17433 .no_xpath = true,
25ffbdc1 17434};
17435
d62a17ae 17436static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 17437 .name = "bgp ipv6 labeled unicast",
62b346ee 17438 .node = BGP_IPV6L_NODE,
24389580 17439 .parent_node = BGP_NODE,
62b346ee 17440 .prompt = "%s(config-router-af)# ",
dd2c81b8 17441 .no_xpath = true,
f51bae9c
DS
17442};
17443
62b346ee 17444static struct cmd_node bgp_vpnv4_node = {
f4b8291f 17445 .name = "bgp vpnv4",
62b346ee 17446 .node = BGP_VPNV4_NODE,
24389580 17447 .parent_node = BGP_NODE,
62b346ee 17448 .prompt = "%s(config-router-af)# ",
dd2c81b8 17449 .no_xpath = true,
62b346ee 17450};
6b0655a2 17451
62b346ee 17452static struct cmd_node bgp_vpnv6_node = {
f4b8291f 17453 .name = "bgp vpnv6",
62b346ee 17454 .node = BGP_VPNV6_NODE,
24389580 17455 .parent_node = BGP_NODE,
62b346ee 17456 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 17457 .no_xpath = true,
62b346ee 17458};
8ecd3266 17459
62b346ee 17460static struct cmd_node bgp_evpn_node = {
f4b8291f 17461 .name = "bgp evpn",
62b346ee 17462 .node = BGP_EVPN_NODE,
24389580 17463 .parent_node = BGP_NODE,
62b346ee 17464 .prompt = "%s(config-router-evpn)# ",
dd2c81b8 17465 .no_xpath = true,
62b346ee 17466};
4e0b7b6d 17467
62b346ee 17468static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 17469 .name = "bgp evpn vni",
62b346ee 17470 .node = BGP_EVPN_VNI_NODE,
24389580 17471 .parent_node = BGP_EVPN_NODE,
62b346ee 17472 .prompt = "%s(config-router-af-vni)# ",
62b346ee 17473};
90e60aa7 17474
62b346ee 17475static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 17476 .name = "bgp ipv4 flowspec",
62b346ee 17477 .node = BGP_FLOWSPECV4_NODE,
24389580 17478 .parent_node = BGP_NODE,
62b346ee 17479 .prompt = "%s(config-router-af)# ",
dd2c81b8 17480 .no_xpath = true,
62b346ee 17481};
7c40bf39 17482
62b346ee 17483static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 17484 .name = "bgp ipv6 flowspec",
62b346ee 17485 .node = BGP_FLOWSPECV6_NODE,
24389580 17486 .parent_node = BGP_NODE,
62b346ee 17487 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 17488 .no_xpath = true,
62b346ee 17489};
7c40bf39 17490
bfaab44d
HS
17491static struct cmd_node bgp_srv6_node = {
17492 .name = "bgp srv6",
17493 .node = BGP_SRV6_NODE,
17494 .parent_node = BGP_NODE,
17495 .prompt = "%s(config-router-srv6)# ",
17496};
17497
d62a17ae 17498static void community_list_vty(void);
1f8ae70b 17499
d62a17ae 17500static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 17501{
d62a17ae 17502 struct bgp *bgp;
17503 struct peer *peer;
d62a17ae 17504 struct listnode *lnbgp, *lnpeer;
b8a815e5 17505
d62a17ae 17506 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17507 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17508 /* only provide suggestions on the appropriate input
17509 * token type,
17510 * they'll otherwise show up multiple times */
17511 enum cmd_token_type match_type;
17512 char *name = peer->host;
d48ed3e0 17513
d62a17ae 17514 if (peer->conf_if) {
17515 match_type = VARIABLE_TKN;
17516 name = peer->conf_if;
17517 } else if (strchr(peer->host, ':'))
17518 match_type = IPV6_TKN;
17519 else
17520 match_type = IPV4_TKN;
d48ed3e0 17521
d62a17ae 17522 if (token->type != match_type)
17523 continue;
d48ed3e0 17524
d62a17ae 17525 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17526 }
d62a17ae 17527 }
b8a815e5
DL
17528}
17529
17530static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 17531 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17532 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 17533 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 17534 {.completions = NULL}};
17535
47a306a0
DS
17536static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17537{
17538 struct bgp *bgp;
17539 struct peer_group *group;
17540 struct listnode *lnbgp, *lnpeer;
17541
17542 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17543 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17544 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17545 group->name));
17546 }
17547}
17548
17549static const struct cmd_variable_handler bgp_var_peergroup[] = {
17550 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17551 {.completions = NULL} };
17552
d62a17ae 17553void bgp_vty_init(void)
17554{
17555 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 17556 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 17557
17558 /* Install bgp top node. */
612c2c15
DL
17559 install_node(&bgp_node);
17560 install_node(&bgp_ipv4_unicast_node);
17561 install_node(&bgp_ipv4_multicast_node);
17562 install_node(&bgp_ipv4_labeled_unicast_node);
17563 install_node(&bgp_ipv6_unicast_node);
17564 install_node(&bgp_ipv6_multicast_node);
17565 install_node(&bgp_ipv6_labeled_unicast_node);
17566 install_node(&bgp_vpnv4_node);
17567 install_node(&bgp_vpnv6_node);
17568 install_node(&bgp_evpn_node);
17569 install_node(&bgp_evpn_vni_node);
17570 install_node(&bgp_flowspecv4_node);
17571 install_node(&bgp_flowspecv6_node);
bfaab44d 17572 install_node(&bgp_srv6_node);
d62a17ae 17573
17574 /* Install default VTY commands to new nodes. */
17575 install_default(BGP_NODE);
17576 install_default(BGP_IPV4_NODE);
17577 install_default(BGP_IPV4M_NODE);
17578 install_default(BGP_IPV4L_NODE);
17579 install_default(BGP_IPV6_NODE);
17580 install_default(BGP_IPV6M_NODE);
17581 install_default(BGP_IPV6L_NODE);
17582 install_default(BGP_VPNV4_NODE);
17583 install_default(BGP_VPNV6_NODE);
7c40bf39 17584 install_default(BGP_FLOWSPECV4_NODE);
17585 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 17586 install_default(BGP_EVPN_NODE);
17587 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 17588 install_default(BGP_SRV6_NODE);
d62a17ae 17589
8029b216
AK
17590 /* "bgp local-mac" hidden commands. */
17591 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17592 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17593
9acb67cb
DS
17594 /* "bgp suppress-fib-pending" global */
17595 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17596
d62a17ae 17597 /* bgp route-map delay-timer commands. */
17598 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17599 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17600
f852eb98
PG
17601 /* bgp fast-convergence command */
17602 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
17603 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
17604
d70583f7
D
17605 /* global bgp update-delay command */
17606 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17607 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17608
05bd726c 17609 /* global bgp graceful-shutdown command */
17610 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17611 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17612
d62a17ae 17613 /* Dummy commands (Currently not supported) */
17614 install_element(BGP_NODE, &no_synchronization_cmd);
17615 install_element(BGP_NODE, &no_auto_summary_cmd);
17616
17617 /* "router bgp" commands. */
17618 install_element(CONFIG_NODE, &router_bgp_cmd);
17619
17620 /* "no router bgp" commands. */
17621 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17622
17623 /* "bgp router-id" commands. */
17624 install_element(BGP_NODE, &bgp_router_id_cmd);
17625 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17626
c208c586
S
17627 /* "bgp suppress-fib-pending" command */
17628 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17629
d62a17ae 17630 /* "bgp cluster-id" commands. */
17631 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17632 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17633
c163f297
DS
17634 /* "bgp no-rib" commands. */
17635 install_element(CONFIG_NODE, &bgp_norib_cmd);
17636 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17637
e46723a5
DS
17638 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17639
d62a17ae 17640 /* "bgp confederation" commands. */
17641 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17642 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17643
17644 /* "bgp confederation peers" commands. */
17645 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17646 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17647
17648 /* bgp max-med command */
17649 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17650 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17651 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17652 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17653 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17654
17655 /* bgp disable-ebgp-connected-nh-check */
17656 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17657 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17658
17659 /* bgp update-delay command */
17660 install_element(BGP_NODE, &bgp_update_delay_cmd);
17661 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 17662
17663 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 17664 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 17665
17666 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17667 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17668
17669 /* "maximum-paths" commands. */
17670 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17671 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17672 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17673 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17674 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17675 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17676 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17677 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17678 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17679 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17680 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17681 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17682 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17683 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17684 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17685
39edabac
PG
17686 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17687 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17688 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17689 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17690 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 17691 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17692 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17693 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17694 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17695 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17696
17697 /* "timers bgp" commands. */
17698 install_element(BGP_NODE, &bgp_timers_cmd);
17699 install_element(BGP_NODE, &no_bgp_timers_cmd);
17700
b042667a
TI
17701 /* "minimum-holdtime" commands. */
17702 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
17703 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
17704
d62a17ae 17705 /* route-map delay-timer commands - per instance for backwards compat.
17706 */
17707 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17708 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17709
17710 /* "bgp client-to-client reflection" commands */
17711 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17712 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17713
17714 /* "bgp always-compare-med" commands */
17715 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17716 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17717
9dac9fc8
DA
17718 /* bgp ebgp-requires-policy */
17719 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17720 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17721
2adac256
DA
17722 /* bgp suppress-duplicates */
17723 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17724 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17725
fb29348a
DA
17726 /* bgp reject-as-sets */
17727 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17728 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17729
d62a17ae 17730 /* "bgp deterministic-med" commands */
17731 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17732 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17733
055679e9 17734 /* "bgp graceful-restart" command */
36235319
QY
17735 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17736 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 17737
17738 /* "bgp graceful-restart-disable" command */
36235319
QY
17739 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17740 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 17741
17742 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
17743 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17744 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 17745
17746 /* "neighbor a:b:c:d graceful-restart-disable" command */
17747 install_element(BGP_NODE,
17748 &bgp_neighbor_graceful_restart_disable_set_cmd);
17749 install_element(BGP_NODE,
17750 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17751
17752 /* "neighbor a:b:c:d graceful-restart-helper" command */
17753 install_element(BGP_NODE,
17754 &bgp_neighbor_graceful_restart_helper_set_cmd);
17755 install_element(BGP_NODE,
17756 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17757
d62a17ae 17758 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17759 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17760 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17761 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 17762 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 17763 install_element(BGP_NODE,
17764 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 17765 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17766 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17767
d6e3c15b 17768 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17769 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 17770 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17771 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 17772
7f323236
DW
17773 /* "bgp graceful-shutdown" commands */
17774 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17775 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17776
8606be87
DA
17777 /* "bgp long-lived-graceful-restart" commands */
17778 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
17779 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
17780
d62a17ae 17781 /* "bgp fast-external-failover" commands */
17782 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17783 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17784
d62a17ae 17785 /* "bgp bestpath compare-routerid" commands */
17786 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17787 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17788
17789 /* "bgp bestpath as-path ignore" commands */
17790 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17791 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17792
17793 /* "bgp bestpath as-path confed" commands */
17794 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17795 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17796
17797 /* "bgp bestpath as-path multipath-relax" commands */
17798 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17799 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17800
ee88563a
JM
17801 /* "bgp bestpath peer-type multipath-relax" commands */
17802 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
17803 install_element(BGP_NODE,
17804 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
17805
d62a17ae 17806 /* "bgp log-neighbor-changes" commands */
17807 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17808 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17809
17810 /* "bgp bestpath med" commands */
17811 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17812 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17813
f7e1c681 17814 /* "bgp bestpath bandwidth" commands */
17815 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 17816 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 17817
b16bcbba
TA
17818 /* "no bgp default <afi>-<safi>" commands. */
17819 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
e84c59af 17820
d62a17ae 17821 /* "bgp network import-check" commands. */
17822 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17823 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17824 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17825
17826 /* "bgp default local-preference" commands. */
17827 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17828 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17829
17830 /* bgp default show-hostname */
17831 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17832 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17833
aef999a2
DA
17834 /* bgp default show-nexthop-hostname */
17835 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17836 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17837
d62a17ae 17838 /* "bgp default subgroup-pkt-queue-max" commands. */
17839 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17840 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17841
17842 /* bgp ibgp-allow-policy-mods command */
17843 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17844 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17845
17846 /* "bgp listen limit" commands. */
17847 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17848 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17849
17850 /* "bgp listen range" commands. */
17851 install_element(BGP_NODE, &bgp_listen_range_cmd);
17852 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17853
8175f54a 17854 /* "bgp default shutdown" command */
f26845f9 17855 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
17856
17857 /* "bgp shutdown" commands */
17858 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 17859 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 17860 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 17861 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 17862
d62a17ae 17863 /* "neighbor remote-as" commands. */
17864 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17865 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17866 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17867 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17868 install_element(BGP_NODE,
17869 &neighbor_interface_v6only_config_remote_as_cmd);
17870 install_element(BGP_NODE, &no_neighbor_cmd);
17871 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17872
17873 /* "neighbor peer-group" commands. */
17874 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17875 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17876 install_element(BGP_NODE,
17877 &no_neighbor_interface_peer_group_remote_as_cmd);
17878
17879 /* "neighbor local-as" commands. */
17880 install_element(BGP_NODE, &neighbor_local_as_cmd);
17881 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17882 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17883 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17884
17885 /* "neighbor solo" commands. */
17886 install_element(BGP_NODE, &neighbor_solo_cmd);
17887 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17888
17889 /* "neighbor password" commands. */
17890 install_element(BGP_NODE, &neighbor_password_cmd);
17891 install_element(BGP_NODE, &no_neighbor_password_cmd);
17892
17893 /* "neighbor activate" commands. */
17894 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17895 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17896 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17897 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17898 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17899 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17900 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17901 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
17902 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 17903 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
17904 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 17905 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
17906
17907 /* "no neighbor activate" commands. */
17908 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
17909 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
17910 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
17911 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
17912 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
17913 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
17914 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
17915 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
17916 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 17917 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
17918 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 17919 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
17920
17921 /* "neighbor peer-group" set commands. */
17922 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
17923 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17924 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
17925 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17926 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
17927 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
17928 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17929 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 17930 install_element(BGP_FLOWSPECV4_NODE,
17931 &neighbor_set_peer_group_hidden_cmd);
17932 install_element(BGP_FLOWSPECV6_NODE,
17933 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 17934
17935 /* "no neighbor peer-group unset" commands. */
17936 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
17937 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17938 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17939 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17940 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17941 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17942 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17943 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 17944 install_element(BGP_FLOWSPECV4_NODE,
17945 &no_neighbor_set_peer_group_hidden_cmd);
17946 install_element(BGP_FLOWSPECV6_NODE,
17947 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 17948
17949 /* "neighbor softreconfiguration inbound" commands.*/
17950 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
17951 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
17952 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
17953 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17954 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
17955 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17956 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
17957 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17958 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
17959 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17960 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
17961 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17962 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
17963 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17964 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
17965 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17966 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
17967 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 17968 install_element(BGP_FLOWSPECV4_NODE,
17969 &neighbor_soft_reconfiguration_cmd);
17970 install_element(BGP_FLOWSPECV4_NODE,
17971 &no_neighbor_soft_reconfiguration_cmd);
17972 install_element(BGP_FLOWSPECV6_NODE,
17973 &neighbor_soft_reconfiguration_cmd);
17974 install_element(BGP_FLOWSPECV6_NODE,
17975 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
17976 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
17977 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 17978
17979 /* "neighbor attribute-unchanged" commands. */
17980 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
17981 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
17982 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
17983 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
17984 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
17985 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
17986 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
17987 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
17988 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
17989 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
17990 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
17991 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
17992 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
17993 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
17994 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
17995 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
17996 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
17997 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
17998
17999 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18000 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18001
b8ad84d2
PG
18002 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18003 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18004 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18005 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18006
d62a17ae 18007 /* "nexthop-local unchanged" commands */
18008 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18009 install_element(BGP_IPV6_NODE,
18010 &no_neighbor_nexthop_local_unchanged_cmd);
18011
18012 /* "neighbor next-hop-self" commands. */
18013 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18014 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18015 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18016 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18017 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18018 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18019 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18020 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18021 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18022 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18023 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18024 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18025 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18026 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18027 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18028 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18029 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18030 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
18031 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18032 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 18033
18034 /* "neighbor next-hop-self force" commands. */
18035 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18036 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
18037 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18038 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18039 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18040 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18041 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18042 install_element(BGP_IPV4_NODE,
18043 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18044 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18045 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18046 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18047 install_element(BGP_IPV4M_NODE,
18048 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18049 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18050 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18051 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18052 install_element(BGP_IPV4L_NODE,
18053 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18054 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18055 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18056 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18057 install_element(BGP_IPV6_NODE,
18058 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18059 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18060 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18061 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18062 install_element(BGP_IPV6M_NODE,
18063 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18064 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18065 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18066 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18067 install_element(BGP_IPV6L_NODE,
18068 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18069 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18070 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18071 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18072 install_element(BGP_VPNV4_NODE,
18073 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18074 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18075 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18076 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18077 install_element(BGP_VPNV6_NODE,
18078 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
18079 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18080 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 18081
18082 /* "neighbor as-override" commands. */
18083 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18084 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18085 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18086 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18087 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18088 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18089 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18090 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18091 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18092 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18093 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18094 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18095 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18096 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18097 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18098 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18099 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18100 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18101
18102 /* "neighbor remove-private-AS" commands. */
18103 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18104 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18105 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18106 install_element(BGP_NODE,
18107 &no_neighbor_remove_private_as_all_hidden_cmd);
18108 install_element(BGP_NODE,
18109 &neighbor_remove_private_as_replace_as_hidden_cmd);
18110 install_element(BGP_NODE,
18111 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18112 install_element(BGP_NODE,
18113 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18114 install_element(
18115 BGP_NODE,
18116 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18117 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18118 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18119 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18120 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18121 install_element(BGP_IPV4_NODE,
18122 &neighbor_remove_private_as_replace_as_cmd);
18123 install_element(BGP_IPV4_NODE,
18124 &no_neighbor_remove_private_as_replace_as_cmd);
18125 install_element(BGP_IPV4_NODE,
18126 &neighbor_remove_private_as_all_replace_as_cmd);
18127 install_element(BGP_IPV4_NODE,
18128 &no_neighbor_remove_private_as_all_replace_as_cmd);
18129 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18130 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18131 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18132 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18133 install_element(BGP_IPV4M_NODE,
18134 &neighbor_remove_private_as_replace_as_cmd);
18135 install_element(BGP_IPV4M_NODE,
18136 &no_neighbor_remove_private_as_replace_as_cmd);
18137 install_element(BGP_IPV4M_NODE,
18138 &neighbor_remove_private_as_all_replace_as_cmd);
18139 install_element(BGP_IPV4M_NODE,
18140 &no_neighbor_remove_private_as_all_replace_as_cmd);
18141 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18142 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18143 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18144 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18145 install_element(BGP_IPV4L_NODE,
18146 &neighbor_remove_private_as_replace_as_cmd);
18147 install_element(BGP_IPV4L_NODE,
18148 &no_neighbor_remove_private_as_replace_as_cmd);
18149 install_element(BGP_IPV4L_NODE,
18150 &neighbor_remove_private_as_all_replace_as_cmd);
18151 install_element(BGP_IPV4L_NODE,
18152 &no_neighbor_remove_private_as_all_replace_as_cmd);
18153 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18154 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18155 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18156 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18157 install_element(BGP_IPV6_NODE,
18158 &neighbor_remove_private_as_replace_as_cmd);
18159 install_element(BGP_IPV6_NODE,
18160 &no_neighbor_remove_private_as_replace_as_cmd);
18161 install_element(BGP_IPV6_NODE,
18162 &neighbor_remove_private_as_all_replace_as_cmd);
18163 install_element(BGP_IPV6_NODE,
18164 &no_neighbor_remove_private_as_all_replace_as_cmd);
18165 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18166 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18167 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18168 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18169 install_element(BGP_IPV6M_NODE,
18170 &neighbor_remove_private_as_replace_as_cmd);
18171 install_element(BGP_IPV6M_NODE,
18172 &no_neighbor_remove_private_as_replace_as_cmd);
18173 install_element(BGP_IPV6M_NODE,
18174 &neighbor_remove_private_as_all_replace_as_cmd);
18175 install_element(BGP_IPV6M_NODE,
18176 &no_neighbor_remove_private_as_all_replace_as_cmd);
18177 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18178 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18179 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18180 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18181 install_element(BGP_IPV6L_NODE,
18182 &neighbor_remove_private_as_replace_as_cmd);
18183 install_element(BGP_IPV6L_NODE,
18184 &no_neighbor_remove_private_as_replace_as_cmd);
18185 install_element(BGP_IPV6L_NODE,
18186 &neighbor_remove_private_as_all_replace_as_cmd);
18187 install_element(BGP_IPV6L_NODE,
18188 &no_neighbor_remove_private_as_all_replace_as_cmd);
18189 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18190 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18191 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18192 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18193 install_element(BGP_VPNV4_NODE,
18194 &neighbor_remove_private_as_replace_as_cmd);
18195 install_element(BGP_VPNV4_NODE,
18196 &no_neighbor_remove_private_as_replace_as_cmd);
18197 install_element(BGP_VPNV4_NODE,
18198 &neighbor_remove_private_as_all_replace_as_cmd);
18199 install_element(BGP_VPNV4_NODE,
18200 &no_neighbor_remove_private_as_all_replace_as_cmd);
18201 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18202 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18203 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18204 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18205 install_element(BGP_VPNV6_NODE,
18206 &neighbor_remove_private_as_replace_as_cmd);
18207 install_element(BGP_VPNV6_NODE,
18208 &no_neighbor_remove_private_as_replace_as_cmd);
18209 install_element(BGP_VPNV6_NODE,
18210 &neighbor_remove_private_as_all_replace_as_cmd);
18211 install_element(BGP_VPNV6_NODE,
18212 &no_neighbor_remove_private_as_all_replace_as_cmd);
18213
18214 /* "neighbor send-community" commands.*/
18215 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18216 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18217 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18218 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18219 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18220 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18221 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18222 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18223 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18224 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18225 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18226 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18227 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18228 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18229 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18230 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18231 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18232 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18233 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18234 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18235 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18236 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18237 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18238 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18239 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18240 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18241 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18242 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18243 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18244 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18245 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18246 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18247 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18248 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18249 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18250 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18251
18252 /* "neighbor route-reflector" commands.*/
18253 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18254 install_element(BGP_NODE,
18255 &no_neighbor_route_reflector_client_hidden_cmd);
18256 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18257 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18258 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18259 install_element(BGP_IPV4M_NODE,
18260 &no_neighbor_route_reflector_client_cmd);
18261 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18262 install_element(BGP_IPV4L_NODE,
18263 &no_neighbor_route_reflector_client_cmd);
18264 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18265 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18266 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18267 install_element(BGP_IPV6M_NODE,
18268 &no_neighbor_route_reflector_client_cmd);
18269 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18270 install_element(BGP_IPV6L_NODE,
18271 &no_neighbor_route_reflector_client_cmd);
18272 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18273 install_element(BGP_VPNV4_NODE,
18274 &no_neighbor_route_reflector_client_cmd);
18275 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18276 install_element(BGP_VPNV6_NODE,
18277 &no_neighbor_route_reflector_client_cmd);
7c40bf39 18278 install_element(BGP_FLOWSPECV4_NODE,
18279 &neighbor_route_reflector_client_cmd);
18280 install_element(BGP_FLOWSPECV4_NODE,
18281 &no_neighbor_route_reflector_client_cmd);
18282 install_element(BGP_FLOWSPECV6_NODE,
18283 &neighbor_route_reflector_client_cmd);
18284 install_element(BGP_FLOWSPECV6_NODE,
18285 &no_neighbor_route_reflector_client_cmd);
d62a17ae 18286 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18287 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18288
18289 /* "neighbor route-server" commands.*/
18290 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18291 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18292 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18293 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18294 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18295 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18296 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18297 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18298 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18299 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18300 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18301 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18302 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18303 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18304 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18305 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18306 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18307 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
18308 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18309 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 18310 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18311 install_element(BGP_FLOWSPECV4_NODE,
18312 &no_neighbor_route_server_client_cmd);
18313 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18314 install_element(BGP_FLOWSPECV6_NODE,
18315 &no_neighbor_route_server_client_cmd);
d62a17ae 18316
7c0e4312
DA
18317 /* "neighbor disable-addpath-rx" commands. */
18318 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
18319 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18320 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
18321 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18322 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
18323 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18324 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
18325 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18326 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
18327 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18328 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
18329 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18330 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
18331 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18332 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
18333 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18334
d62a17ae 18335 /* "neighbor addpath-tx-all-paths" commands.*/
18336 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18337 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18338 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18339 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18340 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18341 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18342 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18343 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18344 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18345 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18346 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18347 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18348 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18349 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18350 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18351 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18352 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18353 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18354
18355 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18356 install_element(BGP_NODE,
18357 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18358 install_element(BGP_NODE,
18359 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18360 install_element(BGP_IPV4_NODE,
18361 &neighbor_addpath_tx_bestpath_per_as_cmd);
18362 install_element(BGP_IPV4_NODE,
18363 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18364 install_element(BGP_IPV4M_NODE,
18365 &neighbor_addpath_tx_bestpath_per_as_cmd);
18366 install_element(BGP_IPV4M_NODE,
18367 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18368 install_element(BGP_IPV4L_NODE,
18369 &neighbor_addpath_tx_bestpath_per_as_cmd);
18370 install_element(BGP_IPV4L_NODE,
18371 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18372 install_element(BGP_IPV6_NODE,
18373 &neighbor_addpath_tx_bestpath_per_as_cmd);
18374 install_element(BGP_IPV6_NODE,
18375 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18376 install_element(BGP_IPV6M_NODE,
18377 &neighbor_addpath_tx_bestpath_per_as_cmd);
18378 install_element(BGP_IPV6M_NODE,
18379 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18380 install_element(BGP_IPV6L_NODE,
18381 &neighbor_addpath_tx_bestpath_per_as_cmd);
18382 install_element(BGP_IPV6L_NODE,
18383 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18384 install_element(BGP_VPNV4_NODE,
18385 &neighbor_addpath_tx_bestpath_per_as_cmd);
18386 install_element(BGP_VPNV4_NODE,
18387 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18388 install_element(BGP_VPNV6_NODE,
18389 &neighbor_addpath_tx_bestpath_per_as_cmd);
18390 install_element(BGP_VPNV6_NODE,
18391 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18392
2b31007c
RZ
18393 /* "neighbor sender-as-path-loop-detection" commands. */
18394 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18395 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18396
d62a17ae 18397 /* "neighbor passive" commands. */
18398 install_element(BGP_NODE, &neighbor_passive_cmd);
18399 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18400
18401
18402 /* "neighbor shutdown" commands. */
18403 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18404 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18405 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18406 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
18407 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18408 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 18409
18410 /* "neighbor capability extended-nexthop" commands.*/
18411 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18412 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18413
18414 /* "neighbor capability orf prefix-list" commands.*/
18415 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18416 install_element(BGP_NODE,
18417 &no_neighbor_capability_orf_prefix_hidden_cmd);
18418 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18419 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18420 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18421 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18422 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18423 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18424 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18425 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18426 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18427 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18428 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18429 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18430
18431 /* "neighbor capability dynamic" commands.*/
18432 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18433 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18434
18435 /* "neighbor dont-capability-negotiate" commands. */
18436 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18437 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18438
18439 /* "neighbor ebgp-multihop" commands. */
18440 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18441 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18442 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18443
18444 /* "neighbor disable-connected-check" commands. */
18445 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18446 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18447
7ab294ea
DA
18448 /* "neighbor disable-link-bw-encoding-ieee" commands. */
18449 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
18450 install_element(BGP_NODE,
18451 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
27aa23a4 18452
d08c0c80
DA
18453 /* "neighbor extended-optional-parameters" commands. */
18454 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
18455 install_element(BGP_NODE,
18456 &no_neighbor_extended_optional_parameters_cmd);
18457
47cbc09b
PM
18458 /* "neighbor enforce-first-as" commands. */
18459 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18460 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18461
d62a17ae 18462 /* "neighbor description" commands. */
18463 install_element(BGP_NODE, &neighbor_description_cmd);
18464 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 18465 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 18466
18467 /* "neighbor update-source" commands. "*/
18468 install_element(BGP_NODE, &neighbor_update_source_cmd);
18469 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18470
18471 /* "neighbor default-originate" commands. */
18472 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18473 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18474 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18475 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18476 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18477 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18478 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18479 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18480 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18481 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18482 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18483 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18484 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18485 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18486 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18487 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18488 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18489 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18490 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18491 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18492 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18493
18494 /* "neighbor port" commands. */
18495 install_element(BGP_NODE, &neighbor_port_cmd);
18496 install_element(BGP_NODE, &no_neighbor_port_cmd);
18497
18498 /* "neighbor weight" commands. */
18499 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18500 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18501
18502 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18503 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18504 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18505 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18506 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18507 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18508 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18509 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18510 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18511 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18512 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18513 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18514 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18515 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18516 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18517 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18518
18519 /* "neighbor override-capability" commands. */
18520 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18521 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18522
18523 /* "neighbor strict-capability-match" commands. */
18524 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18525 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18526
18527 /* "neighbor timers" commands. */
18528 install_element(BGP_NODE, &neighbor_timers_cmd);
18529 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18530
18531 /* "neighbor timers connect" commands. */
18532 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18533 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18534
d43114f3
DS
18535 /* "neighbor timers delayopen" commands. */
18536 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18537 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18538
d62a17ae 18539 /* "neighbor advertisement-interval" commands. */
18540 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18541 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18542
18543 /* "neighbor interface" commands. */
18544 install_element(BGP_NODE, &neighbor_interface_cmd);
18545 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18546
18547 /* "neighbor distribute" commands. */
18548 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18549 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18550 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18551 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18552 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18553 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18554 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18555 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18556 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18557 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18558 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18559 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18560 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18561 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18562 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18563 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18564 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18565 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18566
18567 /* "neighbor prefix-list" commands. */
18568 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
642ef664 18569 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
d62a17ae 18570 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18571 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18572 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
642ef664 18573 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18574 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
642ef664 18575 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18576 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18577 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18578 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
642ef664 18579 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18580 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
642ef664 18581 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18582 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18583 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18584 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18585 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18586 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18587 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18588 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18589 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18590
18591 /* "neighbor filter-list" commands. */
18592 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18593 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18594 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18595 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18596 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18597 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18598 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18599 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18600 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18601 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18602 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18603 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18604 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18605 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18606 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18607 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18608 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18609 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 18610 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18611 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18612 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18613 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 18614
18615 /* "neighbor route-map" commands. */
d6d7ed37
IR
18616 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18617 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
d62a17ae 18618 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18619 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18620 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
0ea8d871 18621 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18622 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
0ea8d871 18623 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18624 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18625 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18626 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
0ea8d871 18627 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18628 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
0ea8d871 18629 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18630 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18631 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18632 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18633 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18634 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18635 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18636 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18637 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549 18638 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
0ea8d871 18639 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18640
18641 /* "neighbor unsuppress-map" commands. */
18642 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18643 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18644 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18645 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18646 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18647 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18648 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18649 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18650 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18651 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18652 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18653 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18654 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18655 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18656 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18657 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18658 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18659 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18660
7f7940e6 18661 /* "neighbor advertise-map" commands. */
389e4f92 18662 install_element(BGP_NODE, &bgp_condadv_period_cmd);
7f7940e6 18663 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 18664 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18665 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18666 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18667 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18668 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18669 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18670 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18671 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18672
fde246e8
DA
18673 /* neighbor maximum-prefix-out commands. */
18674 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18675 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18676 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18677 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18678 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18679 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18680 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18681 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18682 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18683 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18684 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18685 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18686 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18687 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18688 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18689 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18690 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18691 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18692
d62a17ae 18693 /* "neighbor maximum-prefix" commands. */
18694 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18695 install_element(BGP_NODE,
18696 &neighbor_maximum_prefix_threshold_hidden_cmd);
18697 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18698 install_element(BGP_NODE,
18699 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18700 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18701 install_element(BGP_NODE,
18702 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18703 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18704 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18705 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18706 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18707 install_element(BGP_IPV4_NODE,
18708 &neighbor_maximum_prefix_threshold_warning_cmd);
18709 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18710 install_element(BGP_IPV4_NODE,
18711 &neighbor_maximum_prefix_threshold_restart_cmd);
18712 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18713 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18714 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18715 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18716 install_element(BGP_IPV4M_NODE,
18717 &neighbor_maximum_prefix_threshold_warning_cmd);
18718 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18719 install_element(BGP_IPV4M_NODE,
18720 &neighbor_maximum_prefix_threshold_restart_cmd);
18721 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18722 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18723 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18724 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18725 install_element(BGP_IPV4L_NODE,
18726 &neighbor_maximum_prefix_threshold_warning_cmd);
18727 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18728 install_element(BGP_IPV4L_NODE,
18729 &neighbor_maximum_prefix_threshold_restart_cmd);
18730 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18731 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18732 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18733 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18734 install_element(BGP_IPV6_NODE,
18735 &neighbor_maximum_prefix_threshold_warning_cmd);
18736 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18737 install_element(BGP_IPV6_NODE,
18738 &neighbor_maximum_prefix_threshold_restart_cmd);
18739 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18740 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18741 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18742 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18743 install_element(BGP_IPV6M_NODE,
18744 &neighbor_maximum_prefix_threshold_warning_cmd);
18745 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18746 install_element(BGP_IPV6M_NODE,
18747 &neighbor_maximum_prefix_threshold_restart_cmd);
18748 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18749 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18750 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18751 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18752 install_element(BGP_IPV6L_NODE,
18753 &neighbor_maximum_prefix_threshold_warning_cmd);
18754 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18755 install_element(BGP_IPV6L_NODE,
18756 &neighbor_maximum_prefix_threshold_restart_cmd);
18757 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18758 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18759 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18760 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18761 install_element(BGP_VPNV4_NODE,
18762 &neighbor_maximum_prefix_threshold_warning_cmd);
18763 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18764 install_element(BGP_VPNV4_NODE,
18765 &neighbor_maximum_prefix_threshold_restart_cmd);
18766 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18767 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18768 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18769 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18770 install_element(BGP_VPNV6_NODE,
18771 &neighbor_maximum_prefix_threshold_warning_cmd);
18772 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18773 install_element(BGP_VPNV6_NODE,
18774 &neighbor_maximum_prefix_threshold_restart_cmd);
18775 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18776
18777 /* "neighbor allowas-in" */
18778 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18779 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18780 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18781 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18782 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18783 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18784 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18785 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18786 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18787 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18788 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18789 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18790 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18791 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18792 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18793 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18794 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18795 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18796 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18797 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18798
18799 /* address-family commands. */
18800 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18801 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 18802#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 18803 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18804 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 18805#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 18806
d62a17ae 18807 install_element(BGP_NODE, &address_family_evpn_cmd);
18808
18809 /* "exit-address-family" command. */
18810 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18811 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18812 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18813 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18814 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18815 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18816 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18817 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 18818 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18819 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 18820 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18821
18822 /* "clear ip bgp commands" */
18823 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18824
18825 /* clear ip bgp prefix */
18826 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18827 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18828 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18829
18830 /* "show [ip] bgp summary" commands. */
18831 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 18832 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 18833 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 18834 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 18835 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18836 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 18837 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18838
18839 /* "show [ip] bgp neighbors" commands. */
18840 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18841
36235319 18842 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 18843
d62a17ae 18844 /* "show [ip] bgp peer-group" commands. */
18845 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18846
18847 /* "show [ip] bgp paths" commands. */
18848 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18849
18850 /* "show [ip] bgp community" commands. */
18851 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18852
18853 /* "show ip bgp large-community" commands. */
18854 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18855 /* "show [ip] bgp attribute-info" commands. */
18856 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 18857 /* "show [ip] bgp route-leak" command */
18858 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 18859
18860 /* "redistribute" commands. */
18861 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18862 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18863 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18864 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18865 install_element(BGP_NODE,
18866 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18867 install_element(BGP_NODE,
18868 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18869 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18870 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18871 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18872 install_element(BGP_NODE,
18873 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18874 install_element(BGP_NODE,
18875 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18876 install_element(BGP_NODE,
18877 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18878 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18879 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18880 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18881 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18882 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18883 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18884 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18885 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18886 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18887 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18888 install_element(BGP_IPV4_NODE,
18889 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18890 install_element(BGP_IPV4_NODE,
18891 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18892 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18893 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18894 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18895 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18896 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18897 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18898
b9c7bc5a
PZ
18899 /* import|export vpn [route-map WORD] */
18900 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18901 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 18902
12a844a5
DS
18903 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18904 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18905
d62a17ae 18906 /* ttl_security commands */
18907 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18908 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18909
18910 /* "show [ip] bgp memory" commands. */
18911 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18912
acf71666
MK
18913 /* "show bgp martian next-hop" */
18914 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18915
48ecf8f5
DS
18916 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18917
d62a17ae 18918 /* "show [ip] bgp views" commands. */
18919 install_element(VIEW_NODE, &show_bgp_views_cmd);
18920
18921 /* "show [ip] bgp vrfs" commands. */
18922 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
18923
18924 /* Community-list. */
18925 community_list_vty();
ddb5b488 18926
ed0e57e3
DA
18927 community_alias_vty();
18928
ddb5b488 18929 /* vpn-policy commands */
b9c7bc5a
PZ
18930 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
18931 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
18932 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
18933 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
18934 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
18935 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
18936 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
18937 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
18938 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
18939 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
18940 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
18941 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 18942
301ad80a
PG
18943 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
18944 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
18945
b9c7bc5a
PZ
18946 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
18947 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
18948 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
18949 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
18950 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
18951 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
18952 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
18953 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
18954 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
18955 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
18956
18957 /* tcp-mss command */
18958 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
18959 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
18960
18961 /* srv6 commands */
ea372e81 18962 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
bfaab44d 18963 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
0249b8b6 18964 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
a0281b2e 18965 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
0249b8b6 18966 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
b72c9e14
HS
18967 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
18968 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
718e3744 18969}
6b0655a2 18970
718e3744 18971#include "memory.h"
18972#include "bgp_regex.h"
18973#include "bgp_clist.h"
18974#include "bgp_ecommunity.h"
18975
18976/* VTY functions. */
18977
18978/* Direction value to string conversion. */
d62a17ae 18979static const char *community_direct_str(int direct)
18980{
18981 switch (direct) {
18982 case COMMUNITY_DENY:
18983 return "deny";
18984 case COMMUNITY_PERMIT:
18985 return "permit";
18986 default:
18987 return "unknown";
18988 }
718e3744 18989}
18990
18991/* Display error string. */
d62a17ae 18992static void community_list_perror(struct vty *vty, int ret)
18993{
18994 switch (ret) {
18995 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
18996 vty_out(vty, "%% Can't find community-list\n");
18997 break;
18998 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
18999 vty_out(vty, "%% Malformed community-list value\n");
19000 break;
19001 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19002 vty_out(vty,
19003 "%% Community name conflict, previously defined as standard community\n");
19004 break;
19005 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19006 vty_out(vty,
19007 "%% Community name conflict, previously defined as expanded community\n");
19008 break;
19009 }
718e3744 19010}
19011
5bf15956
DW
19012/* "community-list" keyword help string. */
19013#define COMMUNITY_LIST_STR "Add a community list entry\n"
19014
7336e101
SP
19015/*community-list standard */
19016DEFUN (community_list_standard,
19017 bgp_community_list_standard_cmd,
a2099c1d 19018 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19019 BGP_STR
718e3744 19020 COMMUNITY_LIST_STR
19021 "Community list number (standard)\n"
5bf15956 19022 "Add an standard community-list entry\n"
718e3744 19023 "Community list name\n"
2f8cc0e5
DA
19024 "Sequence number of an entry\n"
19025 "Sequence number\n"
718e3744 19026 "Specify community to reject\n"
19027 "Specify community to accept\n"
19028 COMMUNITY_VAL_STR)
19029{
d62a17ae 19030 char *cl_name_or_number = NULL;
2f8cc0e5 19031 char *seq = NULL;
d62a17ae 19032 int direct = 0;
19033 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 19034 int idx = 0;
7336e101 19035
a08032fe 19036 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19037 if (idx)
19038 seq = argv[idx]->arg;
19039
19040 idx = 0;
d62a17ae 19041 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19042 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19043 cl_name_or_number = argv[idx]->arg;
19044 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19045 : COMMUNITY_DENY;
19046 argv_find(argv, argc, "AA:NN", &idx);
19047 char *str = argv_concat(argv, argc, idx);
42f914d4 19048
2f8cc0e5
DA
19049 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19050 direct, style);
42f914d4 19051
d62a17ae 19052 XFREE(MTYPE_TMP, str);
42f914d4 19053
d62a17ae 19054 if (ret < 0) {
19055 /* Display error string. */
19056 community_list_perror(vty, ret);
19057 return CMD_WARNING_CONFIG_FAILED;
19058 }
42f914d4 19059
d62a17ae 19060 return CMD_SUCCESS;
718e3744 19061}
19062
7336e101
SP
19063DEFUN (no_community_list_standard_all,
19064 no_bgp_community_list_standard_all_cmd,
a2099c1d 19065 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19066 NO_STR
19067 BGP_STR
19068 COMMUNITY_LIST_STR
19069 "Community list number (standard)\n"
19070 "Add an standard community-list entry\n"
19071 "Community list name\n"
2f8cc0e5
DA
19072 "Sequence number of an entry\n"
19073 "Sequence number\n"
7336e101
SP
19074 "Specify community to reject\n"
19075 "Specify community to accept\n"
19076 COMMUNITY_VAL_STR)
718e3744 19077{
d62a17ae 19078 char *cl_name_or_number = NULL;
174b5cb9 19079 char *str = NULL;
d62a17ae 19080 int direct = 0;
19081 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 19082 char *seq = NULL;
d62a17ae 19083 int idx = 0;
7336e101 19084
a08032fe 19085 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19086 if (idx)
19087 seq = argv[idx]->arg;
19088
19089 idx = 0;
174b5cb9
DA
19090 argv_find(argv, argc, "permit", &idx);
19091 argv_find(argv, argc, "deny", &idx);
19092
19093 if (idx) {
19094 direct = argv_find(argv, argc, "permit", &idx)
19095 ? COMMUNITY_PERMIT
19096 : COMMUNITY_DENY;
19097
19098 idx = 0;
19099 argv_find(argv, argc, "AA:NN", &idx);
19100 str = argv_concat(argv, argc, idx);
19101 }
19102
19103 idx = 0;
d62a17ae 19104 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19105 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19106 cl_name_or_number = argv[idx]->arg;
42f914d4 19107
2f8cc0e5 19108 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19109 direct, style);
42f914d4 19110
d62a17ae 19111 XFREE(MTYPE_TMP, str);
daf9ddbb 19112
d62a17ae 19113 if (ret < 0) {
19114 community_list_perror(vty, ret);
19115 return CMD_WARNING_CONFIG_FAILED;
19116 }
42f914d4 19117
d62a17ae 19118 return CMD_SUCCESS;
718e3744 19119}
7336e101 19120
174b5cb9 19121ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
a2099c1d 19122 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
174b5cb9
DA
19123 NO_STR BGP_STR COMMUNITY_LIST_STR
19124 "Community list number (standard)\n"
19125 "Add an standard community-list entry\n"
19126 "Community list name\n")
19127
7336e101
SP
19128/*community-list expanded */
19129DEFUN (community_list_expanded_all,
19130 bgp_community_list_expanded_all_cmd,
a2099c1d 19131 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19132 BGP_STR
19133 COMMUNITY_LIST_STR
718e3744 19134 "Community list number (expanded)\n"
5bf15956 19135 "Add an expanded community-list entry\n"
718e3744 19136 "Community list name\n"
2f8cc0e5
DA
19137 "Sequence number of an entry\n"
19138 "Sequence number\n"
718e3744 19139 "Specify community to reject\n"
19140 "Specify community to accept\n"
19141 COMMUNITY_VAL_STR)
19142{
d62a17ae 19143 char *cl_name_or_number = NULL;
2f8cc0e5 19144 char *seq = NULL;
d62a17ae 19145 int direct = 0;
19146 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19147 int idx = 0;
7b9a4750 19148
a08032fe 19149 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19150 if (idx)
19151 seq = argv[idx]->arg;
19152
19153 idx = 0;
19154
d62a17ae 19155 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19156 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19157 cl_name_or_number = argv[idx]->arg;
19158 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19159 : COMMUNITY_DENY;
19160 argv_find(argv, argc, "AA:NN", &idx);
19161 char *str = argv_concat(argv, argc, idx);
42f914d4 19162
2f8cc0e5
DA
19163 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19164 direct, style);
42f914d4 19165
d62a17ae 19166 XFREE(MTYPE_TMP, str);
42f914d4 19167
d62a17ae 19168 if (ret < 0) {
19169 /* Display error string. */
19170 community_list_perror(vty, ret);
19171 return CMD_WARNING_CONFIG_FAILED;
19172 }
42f914d4 19173
d62a17ae 19174 return CMD_SUCCESS;
718e3744 19175}
19176
7336e101
SP
19177DEFUN (no_community_list_expanded_all,
19178 no_bgp_community_list_expanded_all_cmd,
a2099c1d 19179 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19180 NO_STR
19181 BGP_STR
19182 COMMUNITY_LIST_STR
19183 "Community list number (expanded)\n"
19184 "Add an expanded community-list entry\n"
19185 "Community list name\n"
2f8cc0e5
DA
19186 "Sequence number of an entry\n"
19187 "Sequence number\n"
7336e101
SP
19188 "Specify community to reject\n"
19189 "Specify community to accept\n"
19190 COMMUNITY_VAL_STR)
718e3744 19191{
d62a17ae 19192 char *cl_name_or_number = NULL;
2f8cc0e5 19193 char *seq = NULL;
174b5cb9 19194 char *str = NULL;
d62a17ae 19195 int direct = 0;
19196 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19197 int idx = 0;
174b5cb9 19198
a08032fe 19199 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19200 if (idx)
19201 seq = argv[idx]->arg;
19202
19203 idx = 0;
174b5cb9
DA
19204 argv_find(argv, argc, "permit", &idx);
19205 argv_find(argv, argc, "deny", &idx);
19206
19207 if (idx) {
19208 direct = argv_find(argv, argc, "permit", &idx)
19209 ? COMMUNITY_PERMIT
19210 : COMMUNITY_DENY;
19211
19212 idx = 0;
19213 argv_find(argv, argc, "AA:NN", &idx);
19214 str = argv_concat(argv, argc, idx);
7336e101 19215 }
174b5cb9
DA
19216
19217 idx = 0;
d62a17ae 19218 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19219 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19220 cl_name_or_number = argv[idx]->arg;
42f914d4 19221
2f8cc0e5 19222 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19223 direct, style);
42f914d4 19224
d62a17ae 19225 XFREE(MTYPE_TMP, str);
daf9ddbb 19226
d62a17ae 19227 if (ret < 0) {
19228 community_list_perror(vty, ret);
19229 return CMD_WARNING_CONFIG_FAILED;
19230 }
42f914d4 19231
d62a17ae 19232 return CMD_SUCCESS;
718e3744 19233}
19234
36d4bb44
EB
19235ALIAS(no_community_list_expanded_all,
19236 no_bgp_community_list_expanded_all_list_cmd,
a2099c1d 19237 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
36d4bb44 19238 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
19239 "Community list number (expanded)\n"
19240 "Add an expanded community-list entry\n"
19241 "Community list name\n")
19242
8d9b8ed9
PM
19243/* Return configuration string of community-list entry. */
19244static const char *community_list_config_str(struct community_entry *entry)
19245{
19246 const char *str;
19247
19248 if (entry->any)
19249 str = "";
19250 else {
19251 if (entry->style == COMMUNITY_LIST_STANDARD)
19252 str = community_str(entry->u.com, false);
19253 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19254 str = lcommunity_str(entry->u.lcom, false);
19255 else
19256 str = entry->config;
19257 }
19258 return str;
19259}
19260
d62a17ae 19261static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 19262{
d62a17ae 19263 struct community_entry *entry;
718e3744 19264
d62a17ae 19265 for (entry = list->head; entry; entry = entry->next) {
19266 if (entry == list->head) {
19267 if (all_digit(list->name))
19268 vty_out(vty, "Community %s list %s\n",
19269 entry->style == COMMUNITY_LIST_STANDARD
19270 ? "standard"
19271 : "(expanded) access",
19272 list->name);
19273 else
19274 vty_out(vty, "Named Community %s list %s\n",
19275 entry->style == COMMUNITY_LIST_STANDARD
19276 ? "standard"
19277 : "expanded",
19278 list->name);
19279 }
19280 if (entry->any)
19281 vty_out(vty, " %s\n",
19282 community_direct_str(entry->direct));
19283 else
19284 vty_out(vty, " %s %s\n",
19285 community_direct_str(entry->direct),
8d9b8ed9 19286 community_list_config_str(entry));
d62a17ae 19287 }
718e3744 19288}
19289
7336e101
SP
19290DEFUN (show_community_list,
19291 show_bgp_community_list_cmd,
19292 "show bgp community-list",
718e3744 19293 SHOW_STR
7336e101 19294 BGP_STR
718e3744 19295 "List community-list\n")
19296{
d62a17ae 19297 struct community_list *list;
19298 struct community_list_master *cm;
718e3744 19299
d62a17ae 19300 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19301 if (!cm)
19302 return CMD_SUCCESS;
718e3744 19303
d62a17ae 19304 for (list = cm->num.head; list; list = list->next)
19305 community_list_show(vty, list);
718e3744 19306
d62a17ae 19307 for (list = cm->str.head; list; list = list->next)
19308 community_list_show(vty, list);
718e3744 19309
d62a17ae 19310 return CMD_SUCCESS;
718e3744 19311}
19312
7336e101
SP
19313DEFUN (show_community_list_arg,
19314 show_bgp_community_list_arg_cmd,
a2099c1d 19315 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
7336e101
SP
19316 SHOW_STR
19317 BGP_STR
718e3744 19318 "List community-list\n"
19319 "Community-list number\n"
960b69b9 19320 "Community-list name\n"
19321 "Detailed information on community-list\n")
718e3744 19322{
d62a17ae 19323 int idx_comm_list = 3;
19324 struct community_list *list;
718e3744 19325
e237b0d2 19326 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19327 COMMUNITY_LIST_MASTER);
19328 if (!list) {
19329 vty_out(vty, "%% Can't find community-list\n");
19330 return CMD_WARNING;
19331 }
718e3744 19332
d62a17ae 19333 community_list_show(vty, list);
718e3744 19334
d62a17ae 19335 return CMD_SUCCESS;
718e3744 19336}
6b0655a2 19337
57d187bc
JS
19338/*
19339 * Large Community code.
19340 */
d62a17ae 19341static int lcommunity_list_set_vty(struct vty *vty, int argc,
19342 struct cmd_token **argv, int style,
19343 int reject_all_digit_name)
19344{
19345 int ret;
19346 int direct;
19347 char *str;
19348 int idx = 0;
19349 char *cl_name;
2f8cc0e5
DA
19350 char *seq = NULL;
19351
a08032fe 19352 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19353 seq = argv[idx]->arg;
d62a17ae 19354
2f8cc0e5 19355 idx = 0;
d62a17ae 19356 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19357 : COMMUNITY_DENY;
19358
19359 /* All digit name check. */
19360 idx = 0;
a2099c1d 19361 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19362 argv_find(argv, argc, "(1-99)", &idx);
19363 argv_find(argv, argc, "(100-500)", &idx);
19364 cl_name = argv[idx]->arg;
19365 if (reject_all_digit_name && all_digit(cl_name)) {
19366 vty_out(vty, "%% Community name cannot have all digits\n");
19367 return CMD_WARNING_CONFIG_FAILED;
19368 }
19369
19370 idx = 0;
19371 argv_find(argv, argc, "AA:BB:CC", &idx);
19372 argv_find(argv, argc, "LINE", &idx);
19373 /* Concat community string argument. */
19374 if (idx)
19375 str = argv_concat(argv, argc, idx);
19376 else
19377 str = NULL;
19378
2f8cc0e5 19379 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 19380
19381 /* Free temporary community list string allocated by
19382 argv_concat(). */
0a22ddfb 19383 XFREE(MTYPE_TMP, str);
d62a17ae 19384
19385 if (ret < 0) {
19386 community_list_perror(vty, ret);
19387 return CMD_WARNING_CONFIG_FAILED;
19388 }
19389 return CMD_SUCCESS;
19390}
19391
19392static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19393 struct cmd_token **argv, int style)
19394{
19395 int ret;
19396 int direct = 0;
19397 char *str = NULL;
19398 int idx = 0;
2f8cc0e5 19399 char *seq = NULL;
d62a17ae 19400
a08032fe 19401 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19402 seq = argv[idx]->arg;
d62a17ae 19403
2f8cc0e5 19404 idx = 0;
d62a17ae 19405 argv_find(argv, argc, "permit", &idx);
19406 argv_find(argv, argc, "deny", &idx);
19407
19408 if (idx) {
19409 /* Check the list direct. */
19410 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19411 direct = COMMUNITY_PERMIT;
19412 else
19413 direct = COMMUNITY_DENY;
19414
19415 idx = 0;
19416 argv_find(argv, argc, "LINE", &idx);
19417 argv_find(argv, argc, "AA:AA:NN", &idx);
19418 /* Concat community string argument. */
19419 str = argv_concat(argv, argc, idx);
19420 }
19421
19422 idx = 0;
19423 argv_find(argv, argc, "(1-99)", &idx);
19424 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19425 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19426
19427 /* Unset community list. */
2f8cc0e5 19428 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 19429 style);
19430
19431 /* Free temporary community list string allocated by
19432 argv_concat(). */
0a22ddfb 19433 XFREE(MTYPE_TMP, str);
d62a17ae 19434
19435 if (ret < 0) {
19436 community_list_perror(vty, ret);
19437 return CMD_WARNING_CONFIG_FAILED;
19438 }
19439
19440 return CMD_SUCCESS;
57d187bc
JS
19441}
19442
19443/* "large-community-list" keyword help string. */
19444#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19445#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19446
7336e101
SP
19447DEFUN (lcommunity_list_standard,
19448 bgp_lcommunity_list_standard_cmd,
a08032fe 19449 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19450 BGP_STR
19451 LCOMMUNITY_LIST_STR
19452 "Large Community list number (standard)\n"
2f8cc0e5
DA
19453 "Sequence number of an entry\n"
19454 "Sequence number\n"
7336e101
SP
19455 "Specify large community to reject\n"
19456 "Specify large community to accept\n"
19457 LCOMMUNITY_VAL_STR)
52951b63 19458{
d62a17ae 19459 return lcommunity_list_set_vty(vty, argc, argv,
19460 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
19461}
19462
7336e101
SP
19463DEFUN (lcommunity_list_expanded,
19464 bgp_lcommunity_list_expanded_cmd,
a08032fe 19465 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19466 BGP_STR
19467 LCOMMUNITY_LIST_STR
19468 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19469 "Sequence number of an entry\n"
19470 "Sequence number\n"
7336e101
SP
19471 "Specify large community to reject\n"
19472 "Specify large community to accept\n"
19473 "An ordered list as a regular-expression\n")
57d187bc 19474{
d62a17ae 19475 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19476 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
19477}
19478
7336e101
SP
19479DEFUN (lcommunity_list_name_standard,
19480 bgp_lcommunity_list_name_standard_cmd,
a2099c1d 19481 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19482 BGP_STR
19483 LCOMMUNITY_LIST_STR
19484 "Specify standard large-community-list\n"
19485 "Large Community list name\n"
2f8cc0e5
DA
19486 "Sequence number of an entry\n"
19487 "Sequence number\n"
7336e101
SP
19488 "Specify large community to reject\n"
19489 "Specify large community to accept\n"
19490 LCOMMUNITY_VAL_STR)
52951b63 19491{
d62a17ae 19492 return lcommunity_list_set_vty(vty, argc, argv,
19493 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
19494}
19495
7336e101
SP
19496DEFUN (lcommunity_list_name_expanded,
19497 bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 19498 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19499 BGP_STR
19500 LCOMMUNITY_LIST_STR
19501 "Specify expanded large-community-list\n"
19502 "Large Community list name\n"
2f8cc0e5
DA
19503 "Sequence number of an entry\n"
19504 "Sequence number\n"
7336e101
SP
19505 "Specify large community to reject\n"
19506 "Specify large community to accept\n"
19507 "An ordered list as a regular-expression\n")
57d187bc 19508{
d62a17ae 19509 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19510 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
19511}
19512
4378f57c
DA
19513DEFUN (no_lcommunity_list_all,
19514 no_bgp_lcommunity_list_all_cmd,
a2099c1d 19515 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
7336e101
SP
19516 NO_STR
19517 BGP_STR
19518 LCOMMUNITY_LIST_STR
19519 "Large Community list number (standard)\n"
19520 "Large Community list number (expanded)\n"
19521 "Large Community list name\n")
57d187bc 19522{
7336e101
SP
19523 return lcommunity_list_unset_vty(vty, argc, argv,
19524 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19525}
19526
4378f57c
DA
19527DEFUN (no_lcommunity_list_name_standard_all,
19528 no_bgp_lcommunity_list_name_standard_all_cmd,
a2099c1d 19529 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
4378f57c
DA
19530 NO_STR
19531 BGP_STR
19532 LCOMMUNITY_LIST_STR
19533 "Specify standard large-community-list\n"
19534 "Large Community list name\n")
19535{
19536 return lcommunity_list_unset_vty(vty, argc, argv,
19537 LARGE_COMMUNITY_LIST_STANDARD);
19538}
19539
7336e101
SP
19540DEFUN (no_lcommunity_list_name_expanded_all,
19541 no_bgp_lcommunity_list_name_expanded_all_cmd,
a2099c1d 19542 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
7336e101
SP
19543 NO_STR
19544 BGP_STR
19545 LCOMMUNITY_LIST_STR
19546 "Specify expanded large-community-list\n"
19547 "Large Community list name\n")
57d187bc 19548{
d62a17ae 19549 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19550 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19551}
19552
7336e101
SP
19553DEFUN (no_lcommunity_list_standard,
19554 no_bgp_lcommunity_list_standard_cmd,
a08032fe 19555 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19556 NO_STR
19557 BGP_STR
19558 LCOMMUNITY_LIST_STR
19559 "Large Community list number (standard)\n"
2f8cc0e5
DA
19560 "Sequence number of an entry\n"
19561 "Sequence number\n"
7336e101
SP
19562 "Specify large community to reject\n"
19563 "Specify large community to accept\n"
19564 LCOMMUNITY_VAL_STR)
57d187bc 19565{
d62a17ae 19566 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19567 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19568}
19569
7336e101
SP
19570DEFUN (no_lcommunity_list_expanded,
19571 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 19572 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19573 NO_STR
19574 BGP_STR
19575 LCOMMUNITY_LIST_STR
19576 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19577 "Sequence number of an entry\n"
19578 "Sequence number\n"
7336e101
SP
19579 "Specify large community to reject\n"
19580 "Specify large community to accept\n"
19581 "An ordered list as a regular-expression\n")
57d187bc 19582{
d62a17ae 19583 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19584 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19585}
19586
7336e101
SP
19587DEFUN (no_lcommunity_list_name_standard,
19588 no_bgp_lcommunity_list_name_standard_cmd,
a2099c1d 19589 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19590 NO_STR
19591 BGP_STR
19592 LCOMMUNITY_LIST_STR
19593 "Specify standard large-community-list\n"
19594 "Large Community list name\n"
2f8cc0e5
DA
19595 "Sequence number of an entry\n"
19596 "Sequence number\n"
7336e101
SP
19597 "Specify large community to reject\n"
19598 "Specify large community to accept\n"
19599 LCOMMUNITY_VAL_STR)
57d187bc 19600{
d62a17ae 19601 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19602 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19603}
19604
7336e101
SP
19605DEFUN (no_lcommunity_list_name_expanded,
19606 no_bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 19607 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19608 NO_STR
19609 BGP_STR
19610 LCOMMUNITY_LIST_STR
19611 "Specify expanded large-community-list\n"
19612 "Large community list name\n"
2f8cc0e5
DA
19613 "Sequence number of an entry\n"
19614 "Sequence number\n"
7336e101
SP
19615 "Specify large community to reject\n"
19616 "Specify large community to accept\n"
19617 "An ordered list as a regular-expression\n")
57d187bc 19618{
d62a17ae 19619 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19620 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19621}
19622
d62a17ae 19623static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19624{
19625 struct community_entry *entry;
19626
19627 for (entry = list->head; entry; entry = entry->next) {
19628 if (entry == list->head) {
19629 if (all_digit(list->name))
19630 vty_out(vty, "Large community %s list %s\n",
169b72c8 19631 entry->style ==
19632 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19633 ? "standard"
19634 : "(expanded) access",
19635 list->name);
19636 else
19637 vty_out(vty,
19638 "Named large community %s list %s\n",
169b72c8 19639 entry->style ==
19640 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19641 ? "standard"
19642 : "expanded",
19643 list->name);
19644 }
19645 if (entry->any)
19646 vty_out(vty, " %s\n",
19647 community_direct_str(entry->direct));
19648 else
19649 vty_out(vty, " %s %s\n",
19650 community_direct_str(entry->direct),
8d9b8ed9 19651 community_list_config_str(entry));
d62a17ae 19652 }
57d187bc
JS
19653}
19654
7336e101
SP
19655DEFUN (show_lcommunity_list,
19656 show_bgp_lcommunity_list_cmd,
19657 "show bgp large-community-list",
57d187bc 19658 SHOW_STR
7336e101 19659 BGP_STR
57d187bc
JS
19660 "List large-community list\n")
19661{
d62a17ae 19662 struct community_list *list;
19663 struct community_list_master *cm;
57d187bc 19664
d62a17ae 19665 cm = community_list_master_lookup(bgp_clist,
19666 LARGE_COMMUNITY_LIST_MASTER);
19667 if (!cm)
19668 return CMD_SUCCESS;
57d187bc 19669
d62a17ae 19670 for (list = cm->num.head; list; list = list->next)
19671 lcommunity_list_show(vty, list);
57d187bc 19672
d62a17ae 19673 for (list = cm->str.head; list; list = list->next)
19674 lcommunity_list_show(vty, list);
57d187bc 19675
d62a17ae 19676 return CMD_SUCCESS;
57d187bc
JS
19677}
19678
7336e101
SP
19679DEFUN (show_lcommunity_list_arg,
19680 show_bgp_lcommunity_list_arg_cmd,
a2099c1d 19681 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
7336e101
SP
19682 SHOW_STR
19683 BGP_STR
57d187bc 19684 "List large-community list\n"
960b69b9 19685 "Large-community-list number\n"
19686 "Large-community-list name\n"
19687 "Detailed information on large-community-list\n")
57d187bc 19688{
d62a17ae 19689 struct community_list *list;
57d187bc 19690
e237b0d2 19691 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 19692 LARGE_COMMUNITY_LIST_MASTER);
19693 if (!list) {
960b69b9 19694 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 19695 return CMD_WARNING;
19696 }
57d187bc 19697
d62a17ae 19698 lcommunity_list_show(vty, list);
57d187bc 19699
d62a17ae 19700 return CMD_SUCCESS;
57d187bc
JS
19701}
19702
718e3744 19703/* "extcommunity-list" keyword help string. */
19704#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19705#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19706
7336e101
SP
19707DEFUN (extcommunity_list_standard,
19708 bgp_extcommunity_list_standard_cmd,
a2099c1d 19709 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19710 BGP_STR
718e3744 19711 EXTCOMMUNITY_LIST_STR
19712 "Extended Community list number (standard)\n"
718e3744 19713 "Specify standard extcommunity-list\n"
5bf15956 19714 "Community list name\n"
2f8cc0e5
DA
19715 "Sequence number of an entry\n"
19716 "Sequence number\n"
718e3744 19717 "Specify community to reject\n"
19718 "Specify community to accept\n"
19719 EXTCOMMUNITY_VAL_STR)
19720{
d62a17ae 19721 int style = EXTCOMMUNITY_LIST_STANDARD;
19722 int direct = 0;
19723 char *cl_number_or_name = NULL;
2f8cc0e5 19724 char *seq = NULL;
42f914d4 19725
d62a17ae 19726 int idx = 0;
7b9a4750 19727
d62a17ae 19728 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19729 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19730 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19731
a08032fe 19732 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19733 seq = argv[idx]->arg;
19734
d62a17ae 19735 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19736 : COMMUNITY_DENY;
19737 argv_find(argv, argc, "AA:NN", &idx);
19738 char *str = argv_concat(argv, argc, idx);
42f914d4 19739
2f8cc0e5 19740 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19741 direct, style);
42f914d4 19742
d62a17ae 19743 XFREE(MTYPE_TMP, str);
42f914d4 19744
d62a17ae 19745 if (ret < 0) {
19746 community_list_perror(vty, ret);
19747 return CMD_WARNING_CONFIG_FAILED;
19748 }
42f914d4 19749
d62a17ae 19750 return CMD_SUCCESS;
718e3744 19751}
19752
7336e101
SP
19753DEFUN (extcommunity_list_name_expanded,
19754 bgp_extcommunity_list_name_expanded_cmd,
a2099c1d 19755 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19756 BGP_STR
19757 EXTCOMMUNITY_LIST_STR
5bf15956 19758 "Extended Community list number (expanded)\n"
718e3744 19759 "Specify expanded extcommunity-list\n"
19760 "Extended Community list name\n"
2f8cc0e5
DA
19761 "Sequence number of an entry\n"
19762 "Sequence number\n"
718e3744 19763 "Specify community to reject\n"
19764 "Specify community to accept\n"
19765 "An ordered list as a regular-expression\n")
19766{
d62a17ae 19767 int style = EXTCOMMUNITY_LIST_EXPANDED;
19768 int direct = 0;
19769 char *cl_number_or_name = NULL;
2f8cc0e5 19770 char *seq = NULL;
d62a17ae 19771 int idx = 0;
7336e101 19772
d62a17ae 19773 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19774 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19775 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19776
a08032fe 19777 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19778 seq = argv[idx]->arg;
19779
d62a17ae 19780 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19781 : COMMUNITY_DENY;
19782 argv_find(argv, argc, "LINE", &idx);
19783 char *str = argv_concat(argv, argc, idx);
42f914d4 19784
2f8cc0e5 19785 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19786 direct, style);
42f914d4 19787
d62a17ae 19788 XFREE(MTYPE_TMP, str);
42f914d4 19789
d62a17ae 19790 if (ret < 0) {
19791 community_list_perror(vty, ret);
19792 return CMD_WARNING_CONFIG_FAILED;
19793 }
42f914d4 19794
d62a17ae 19795 return CMD_SUCCESS;
718e3744 19796}
19797
7336e101
SP
19798DEFUN (no_extcommunity_list_standard_all,
19799 no_bgp_extcommunity_list_standard_all_cmd,
a2099c1d 19800 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19801 NO_STR
19802 BGP_STR
19803 EXTCOMMUNITY_LIST_STR
813d4307 19804 "Extended Community list number (standard)\n"
718e3744 19805 "Specify standard extcommunity-list\n"
5bf15956 19806 "Community list name\n"
2f8cc0e5
DA
19807 "Sequence number of an entry\n"
19808 "Sequence number\n"
718e3744 19809 "Specify community to reject\n"
19810 "Specify community to accept\n"
19811 EXTCOMMUNITY_VAL_STR)
19812{
d62a17ae 19813 int style = EXTCOMMUNITY_LIST_STANDARD;
19814 int direct = 0;
19815 char *cl_number_or_name = NULL;
d4455c89 19816 char *str = NULL;
2f8cc0e5 19817 char *seq = NULL;
d62a17ae 19818 int idx = 0;
d4455c89 19819
a08032fe 19820 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19821 seq = argv[idx]->arg;
19822
19823 idx = 0;
d4455c89
DA
19824 argv_find(argv, argc, "permit", &idx);
19825 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
19826 if (idx) {
19827 direct = argv_find(argv, argc, "permit", &idx)
19828 ? COMMUNITY_PERMIT
19829 : COMMUNITY_DENY;
19830
19831 idx = 0;
19832 argv_find(argv, argc, "AA:NN", &idx);
19833 str = argv_concat(argv, argc, idx);
19834 }
19835
19836 idx = 0;
d62a17ae 19837 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19838 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19839 cl_number_or_name = argv[idx]->arg;
42f914d4 19840
d62a17ae 19841 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19842 seq, direct, style);
42f914d4 19843
d62a17ae 19844 XFREE(MTYPE_TMP, str);
42f914d4 19845
d62a17ae 19846 if (ret < 0) {
19847 community_list_perror(vty, ret);
19848 return CMD_WARNING_CONFIG_FAILED;
19849 }
42f914d4 19850
d62a17ae 19851 return CMD_SUCCESS;
718e3744 19852}
19853
d4455c89
DA
19854ALIAS(no_extcommunity_list_standard_all,
19855 no_bgp_extcommunity_list_standard_all_list_cmd,
a2099c1d 19856 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
36d4bb44 19857 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19858 "Extended Community list number (standard)\n"
19859 "Specify standard extcommunity-list\n"
19860 "Community list name\n")
19861
7336e101
SP
19862DEFUN (no_extcommunity_list_expanded_all,
19863 no_bgp_extcommunity_list_expanded_all_cmd,
a2099c1d 19864 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19865 NO_STR
19866 BGP_STR
19867 EXTCOMMUNITY_LIST_STR
718e3744 19868 "Extended Community list number (expanded)\n"
718e3744 19869 "Specify expanded extcommunity-list\n"
5bf15956 19870 "Extended Community list name\n"
2f8cc0e5
DA
19871 "Sequence number of an entry\n"
19872 "Sequence number\n"
718e3744 19873 "Specify community to reject\n"
19874 "Specify community to accept\n"
19875 "An ordered list as a regular-expression\n")
19876{
d62a17ae 19877 int style = EXTCOMMUNITY_LIST_EXPANDED;
19878 int direct = 0;
19879 char *cl_number_or_name = NULL;
d4455c89 19880 char *str = NULL;
2f8cc0e5 19881 char *seq = NULL;
d62a17ae 19882 int idx = 0;
d4455c89 19883
a08032fe 19884 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19885 seq = argv[idx]->arg;
19886
19887 idx = 0;
d4455c89
DA
19888 argv_find(argv, argc, "permit", &idx);
19889 argv_find(argv, argc, "deny", &idx);
19890
19891 if (idx) {
19892 direct = argv_find(argv, argc, "permit", &idx)
19893 ? COMMUNITY_PERMIT
19894 : COMMUNITY_DENY;
19895
19896 idx = 0;
19897 argv_find(argv, argc, "LINE", &idx);
19898 str = argv_concat(argv, argc, idx);
19899 }
19900
19901 idx = 0;
d62a17ae 19902 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19903 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19904 cl_number_or_name = argv[idx]->arg;
42f914d4 19905
d62a17ae 19906 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19907 seq, direct, style);
42f914d4 19908
d62a17ae 19909 XFREE(MTYPE_TMP, str);
42f914d4 19910
d62a17ae 19911 if (ret < 0) {
19912 community_list_perror(vty, ret);
19913 return CMD_WARNING_CONFIG_FAILED;
19914 }
42f914d4 19915
d62a17ae 19916 return CMD_SUCCESS;
718e3744 19917}
19918
d4455c89
DA
19919ALIAS(no_extcommunity_list_expanded_all,
19920 no_bgp_extcommunity_list_expanded_all_list_cmd,
a2099c1d 19921 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
36d4bb44 19922 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19923 "Extended Community list number (expanded)\n"
19924 "Specify expanded extcommunity-list\n"
19925 "Extended Community list name\n")
19926
d62a17ae 19927static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 19928{
d62a17ae 19929 struct community_entry *entry;
718e3744 19930
d62a17ae 19931 for (entry = list->head; entry; entry = entry->next) {
19932 if (entry == list->head) {
19933 if (all_digit(list->name))
19934 vty_out(vty, "Extended community %s list %s\n",
19935 entry->style == EXTCOMMUNITY_LIST_STANDARD
19936 ? "standard"
19937 : "(expanded) access",
19938 list->name);
19939 else
19940 vty_out(vty,
19941 "Named extended community %s list %s\n",
19942 entry->style == EXTCOMMUNITY_LIST_STANDARD
19943 ? "standard"
19944 : "expanded",
19945 list->name);
19946 }
19947 if (entry->any)
19948 vty_out(vty, " %s\n",
19949 community_direct_str(entry->direct));
19950 else
19951 vty_out(vty, " %s %s\n",
19952 community_direct_str(entry->direct),
8d9b8ed9 19953 community_list_config_str(entry));
d62a17ae 19954 }
718e3744 19955}
19956
7336e101
SP
19957DEFUN (show_extcommunity_list,
19958 show_bgp_extcommunity_list_cmd,
19959 "show bgp extcommunity-list",
718e3744 19960 SHOW_STR
7336e101 19961 BGP_STR
718e3744 19962 "List extended-community list\n")
19963{
d62a17ae 19964 struct community_list *list;
19965 struct community_list_master *cm;
718e3744 19966
d62a17ae 19967 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19968 if (!cm)
19969 return CMD_SUCCESS;
718e3744 19970
d62a17ae 19971 for (list = cm->num.head; list; list = list->next)
19972 extcommunity_list_show(vty, list);
718e3744 19973
d62a17ae 19974 for (list = cm->str.head; list; list = list->next)
19975 extcommunity_list_show(vty, list);
718e3744 19976
d62a17ae 19977 return CMD_SUCCESS;
718e3744 19978}
19979
7336e101
SP
19980DEFUN (show_extcommunity_list_arg,
19981 show_bgp_extcommunity_list_arg_cmd,
a2099c1d 19982 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
7336e101
SP
19983 SHOW_STR
19984 BGP_STR
718e3744 19985 "List extended-community list\n"
19986 "Extcommunity-list number\n"
960b69b9 19987 "Extcommunity-list name\n"
19988 "Detailed information on extcommunity-list\n")
718e3744 19989{
d62a17ae 19990 int idx_comm_list = 3;
19991 struct community_list *list;
718e3744 19992
e237b0d2 19993 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19994 EXTCOMMUNITY_LIST_MASTER);
19995 if (!list) {
19996 vty_out(vty, "%% Can't find extcommunity-list\n");
19997 return CMD_WARNING;
19998 }
718e3744 19999
d62a17ae 20000 extcommunity_list_show(vty, list);
718e3744 20001
d62a17ae 20002 return CMD_SUCCESS;
718e3744 20003}
6b0655a2 20004
718e3744 20005/* Display community-list and extcommunity-list configuration. */
d62a17ae 20006static int community_list_config_write(struct vty *vty)
20007{
20008 struct community_list *list;
20009 struct community_entry *entry;
20010 struct community_list_master *cm;
20011 int write = 0;
20012
20013 /* Community-list. */
20014 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20015
20016 for (list = cm->num.head; list; list = list->next)
20017 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20018 vty_out(vty,
20019 "bgp community-list %s seq %" PRId64 " %s %s\n",
20020 list->name, entry->seq,
d62a17ae 20021 community_direct_str(entry->direct),
20022 community_list_config_str(entry));
20023 write++;
20024 }
20025 for (list = cm->str.head; list; list = list->next)
20026 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20027 vty_out(vty,
20028 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 20029 entry->style == COMMUNITY_LIST_STANDARD
20030 ? "standard"
20031 : "expanded",
2f8cc0e5
DA
20032 list->name, entry->seq,
20033 community_direct_str(entry->direct),
d62a17ae 20034 community_list_config_str(entry));
20035 write++;
20036 }
20037
20038 /* Extcommunity-list. */
20039 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20040
20041 for (list = cm->num.head; list; list = list->next)
20042 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20043 vty_out(vty,
20044 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20045 list->name, entry->seq,
20046 community_direct_str(entry->direct),
d62a17ae 20047 community_list_config_str(entry));
20048 write++;
20049 }
20050 for (list = cm->str.head; list; list = list->next)
20051 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20052 vty_out(vty,
6cde4b45 20053 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 20054 entry->style == EXTCOMMUNITY_LIST_STANDARD
20055 ? "standard"
20056 : "expanded",
2f8cc0e5
DA
20057 list->name, entry->seq,
20058 community_direct_str(entry->direct),
d62a17ae 20059 community_list_config_str(entry));
20060 write++;
20061 }
20062
20063
20064 /* lcommunity-list. */
20065 cm = community_list_master_lookup(bgp_clist,
20066 LARGE_COMMUNITY_LIST_MASTER);
20067
20068 for (list = cm->num.head; list; list = list->next)
20069 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20070 vty_out(vty,
6cde4b45 20071 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
20072 list->name, entry->seq,
20073 community_direct_str(entry->direct),
d62a17ae 20074 community_list_config_str(entry));
20075 write++;
20076 }
20077 for (list = cm->str.head; list; list = list->next)
20078 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20079 vty_out(vty,
6cde4b45 20080 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 20081
d62a17ae 20082 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20083 ? "standard"
20084 : "expanded",
2f8cc0e5 20085 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 20086 community_list_config_str(entry));
20087 write++;
20088 }
20089
20090 return write;
20091}
20092
612c2c15 20093static int community_list_config_write(struct vty *vty);
d62a17ae 20094static struct cmd_node community_list_node = {
f4b8291f 20095 .name = "community list",
62b346ee
DL
20096 .node = COMMUNITY_LIST_NODE,
20097 .prompt = "",
612c2c15 20098 .config_write = community_list_config_write,
718e3744 20099};
20100
d62a17ae 20101static void community_list_vty(void)
20102{
612c2c15 20103 install_node(&community_list_node);
d62a17ae 20104
20105 /* Community-list. */
7336e101
SP
20106 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20107 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20108 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 20109 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 20110 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 20111 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
20112 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20113 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 20114
20115 /* Extcommunity-list. */
7336e101
SP
20116 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20117 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20118 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
20119 install_element(CONFIG_NODE,
20120 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 20121 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
20122 install_element(CONFIG_NODE,
20123 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
20124 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20125 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 20126
20127 /* Large Community List */
7336e101 20128 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
20129 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20130 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 20131 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
20132 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20133 install_element(CONFIG_NODE,
20134 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
20135 install_element(CONFIG_NODE,
20136 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20137 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20138 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20139 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20140 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20141 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20142 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
225096bc
DA
20143
20144 bgp_community_list_command_completion_setup();
5bf15956 20145}
ed0e57e3
DA
20146
20147static struct cmd_node community_alias_node = {
20148 .name = "community alias",
20149 .node = COMMUNITY_ALIAS_NODE,
20150 .prompt = "",
20151 .config_write = bgp_community_alias_write,
20152};
20153
20154void community_alias_vty(void)
20155{
20156 install_node(&community_alias_node);
20157
20158 /* Community-list. */
20159 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
b4ad2fae
DS
20160
20161 bgp_community_alias_command_completion_setup();
ed0e57e3 20162}