]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #10360 from opensourcerouting/clippy-rel-endian
[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
7e62b792 7685 return CMD_SUCCESS;
fde246e8
DA
7686}
7687
1d80f243
IR
7688DEFUN(no_neighbor_maximum_prefix_out,
7689 no_neighbor_maximum_prefix_out_cmd,
7690 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
7691 NO_STR
7692 NEIGHBOR_STR
7693 NEIGHBOR_ADDR_STR2
7694 "Maximum number of prefixes to be sent to this peer\n")
fde246e8
DA
7695{
7696 int idx_peer = 2;
7e62b792 7697 struct peer *peer;
fde246e8
DA
7698 afi_t afi = bgp_node_afi(vty);
7699 safi_t safi = bgp_node_safi(vty);
7700
7e62b792
IR
7701 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7702 if (!peer)
fde246e8
DA
7703 return CMD_WARNING_CONFIG_FAILED;
7704
7e62b792
IR
7705 UNSET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
7706 peer->pmax_out[afi][safi] = 0;
fde246e8 7707
7e62b792 7708 return CMD_SUCCESS;
fde246e8
DA
7709}
7710
9cbd06e0
DA
7711/* Maximum number of prefix configuration. Prefix count is different
7712 for each peer configuration. So this configuration can be set for
718e3744 7713 each peer configuration. */
1d80f243
IR
7714DEFUN (neighbor_maximum_prefix,
7715 neighbor_maximum_prefix_cmd,
7716 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7717 NEIGHBOR_STR
7718 NEIGHBOR_ADDR_STR2
7719 "Maximum number of prefix accept from this peer\n"
7720 "maximum no. of prefix limit\n"
7721 "Force checking all received routes not only accepted\n")
718e3744 7722{
d62a17ae 7723 int idx_peer = 1;
7724 int idx_number = 3;
9cbd06e0 7725 int idx_force = 0;
7e62b792 7726 char *force = NULL;
9cbd06e0
DA
7727
7728 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7729 force = argv[idx_force]->arg;
9cbd06e0 7730
7e62b792
IR
7731 return peer_maximum_prefix_set_vty(
7732 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7733 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 7734}
7735
d62a17ae 7736ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7737 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 7738 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7739 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
7740 "maximum no. of prefix limit\n"
7741 "Force checking all received routes not only accepted\n")
596c17ba 7742
1d80f243
IR
7743DEFUN (neighbor_maximum_prefix_threshold,
7744 neighbor_maximum_prefix_threshold_cmd,
7745 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7746 NEIGHBOR_STR
7747 NEIGHBOR_ADDR_STR2
7748 "Maximum number of prefix accept from this peer\n"
7749 "maximum no. of prefix limit\n"
7750 "Threshold value (%) at which to generate a warning msg\n"
7751 "Force checking all received routes not only accepted\n")
e0701b79 7752{
d62a17ae 7753 int idx_peer = 1;
7754 int idx_number = 3;
7755 int idx_number_2 = 4;
9cbd06e0 7756 int idx_force = 0;
7e62b792 7757 char *force = NULL;
9cbd06e0
DA
7758
7759 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7760 force = argv[idx_force]->arg;
9cbd06e0 7761
7e62b792
IR
7762 return peer_maximum_prefix_set_vty(
7763 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7764 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 7765}
e0701b79 7766
d62a17ae 7767ALIAS_HIDDEN(
7768 neighbor_maximum_prefix_threshold,
7769 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 7770 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 7771 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7772 "Maximum number of prefix accept from this peer\n"
7773 "maximum no. of prefix limit\n"
9cbd06e0
DA
7774 "Threshold value (%) at which to generate a warning msg\n"
7775 "Force checking all received routes not only accepted\n")
596c17ba 7776
1d80f243
IR
7777DEFUN (neighbor_maximum_prefix_warning,
7778 neighbor_maximum_prefix_warning_cmd,
7779 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7780 NEIGHBOR_STR
7781 NEIGHBOR_ADDR_STR2
7782 "Maximum number of prefix accept from this peer\n"
7783 "maximum no. of prefix limit\n"
7784 "Only give warning message when limit is exceeded\n"
7785 "Force checking all received routes not only accepted\n")
718e3744 7786{
d62a17ae 7787 int idx_peer = 1;
7788 int idx_number = 3;
9cbd06e0 7789 int idx_force = 0;
7e62b792 7790 char *force = NULL;
9cbd06e0
DA
7791
7792 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7793 force = argv[idx_force]->arg;
9cbd06e0 7794
7e62b792
IR
7795 return peer_maximum_prefix_set_vty(
7796 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7797 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 7798}
7799
d62a17ae 7800ALIAS_HIDDEN(
7801 neighbor_maximum_prefix_warning,
7802 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 7803 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 7804 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7805 "Maximum number of prefix accept from this peer\n"
7806 "maximum no. of prefix limit\n"
9cbd06e0
DA
7807 "Only give warning message when limit is exceeded\n"
7808 "Force checking all received routes not only accepted\n")
596c17ba 7809
1d80f243
IR
7810DEFUN (neighbor_maximum_prefix_threshold_warning,
7811 neighbor_maximum_prefix_threshold_warning_cmd,
7812 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7813 NEIGHBOR_STR
7814 NEIGHBOR_ADDR_STR2
7815 "Maximum number of prefix accept from this peer\n"
7816 "maximum no. of prefix limit\n"
7817 "Threshold value (%) at which to generate a warning msg\n"
7818 "Only give warning message when limit is exceeded\n"
7819 "Force checking all received routes not only accepted\n")
e0701b79 7820{
d62a17ae 7821 int idx_peer = 1;
7822 int idx_number = 3;
7823 int idx_number_2 = 4;
9cbd06e0 7824 int idx_force = 0;
7e62b792 7825 char *force = NULL;
9cbd06e0
DA
7826
7827 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7828 force = argv[idx_force]->arg;
9cbd06e0 7829
7e62b792
IR
7830 return peer_maximum_prefix_set_vty(
7831 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7832 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 7833}
7834
d62a17ae 7835ALIAS_HIDDEN(
7836 neighbor_maximum_prefix_threshold_warning,
7837 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 7838 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 7839 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7840 "Maximum number of prefix accept from this peer\n"
7841 "maximum no. of prefix limit\n"
7842 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
7843 "Only give warning message when limit is exceeded\n"
7844 "Force checking all received routes not only accepted\n")
596c17ba 7845
1d80f243
IR
7846DEFUN (neighbor_maximum_prefix_restart,
7847 neighbor_maximum_prefix_restart_cmd,
7848 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7849 NEIGHBOR_STR
7850 NEIGHBOR_ADDR_STR2
7851 "Maximum number of prefix accept from this peer\n"
7852 "maximum no. of prefix limit\n"
7853 "Restart bgp connection after limit is exceeded\n"
7854 "Restart interval in minutes\n"
7855 "Force checking all received routes not only accepted\n")
0a486e5f 7856{
d62a17ae 7857 int idx_peer = 1;
7858 int idx_number = 3;
7859 int idx_number_2 = 5;
9cbd06e0 7860 int idx_force = 0;
7e62b792 7861 char *force = NULL;
9cbd06e0
DA
7862
7863 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7864 force = argv[idx_force]->arg;
9cbd06e0 7865
7e62b792
IR
7866 return peer_maximum_prefix_set_vty(
7867 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7868 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 7869}
7870
d62a17ae 7871ALIAS_HIDDEN(
7872 neighbor_maximum_prefix_restart,
7873 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 7874 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 7875 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7876 "Maximum number of prefix accept from this peer\n"
7877 "maximum no. of prefix limit\n"
7878 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7879 "Restart interval in minutes\n"
7880 "Force checking all received routes not only accepted\n")
596c17ba 7881
1d80f243
IR
7882DEFUN (neighbor_maximum_prefix_threshold_restart,
7883 neighbor_maximum_prefix_threshold_restart_cmd,
7884 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7885 NEIGHBOR_STR
7886 NEIGHBOR_ADDR_STR2
7887 "Maximum number of prefixes to accept from this peer\n"
7888 "maximum no. of prefix limit\n"
7889 "Threshold value (%) at which to generate a warning msg\n"
7890 "Restart bgp connection after limit is exceeded\n"
7891 "Restart interval in minutes\n"
7892 "Force checking all received routes not only accepted\n")
0a486e5f 7893{
d62a17ae 7894 int idx_peer = 1;
7895 int idx_number = 3;
7896 int idx_number_2 = 4;
7897 int idx_number_3 = 6;
9cbd06e0 7898 int idx_force = 0;
7e62b792 7899 char *force = NULL;
9cbd06e0
DA
7900
7901 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7902 force = argv[idx_force]->arg;
9cbd06e0 7903
7e62b792
IR
7904 return peer_maximum_prefix_set_vty(
7905 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7906 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
7907 argv[idx_number_3]->arg, force);
d62a17ae 7908}
7909
7910ALIAS_HIDDEN(
7911 neighbor_maximum_prefix_threshold_restart,
7912 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 7913 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 7914 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7915 "Maximum number of prefixes to accept from this peer\n"
7916 "maximum no. of prefix limit\n"
7917 "Threshold value (%) at which to generate a warning msg\n"
7918 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7919 "Restart interval in minutes\n"
7920 "Force checking all received routes not only accepted\n")
596c17ba 7921
1d80f243
IR
7922DEFUN (no_neighbor_maximum_prefix,
7923 no_neighbor_maximum_prefix_cmd,
7924 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
7925 NO_STR
7926 NEIGHBOR_STR
7927 NEIGHBOR_ADDR_STR2
7928 "Maximum number of prefixes to accept from this peer\n"
7929 "maximum no. of prefix limit\n"
7930 "Threshold value (%) at which to generate a warning msg\n"
7931 "Restart bgp connection after limit is exceeded\n"
7932 "Restart interval in minutes\n"
7933 "Only give warning message when limit is exceeded\n"
7934 "Force checking all received routes not only accepted\n")
718e3744 7935{
d62a17ae 7936 int idx_peer = 2;
7e62b792
IR
7937 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
7938 bgp_node_afi(vty),
7939 bgp_node_safi(vty));
718e3744 7940}
e52702f2 7941
d62a17ae 7942ALIAS_HIDDEN(
7943 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7944 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 7945 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7946 "Maximum number of prefixes to accept from this peer\n"
7947 "maximum no. of prefix limit\n"
7948 "Threshold value (%) at which to generate a warning msg\n"
7949 "Restart bgp connection after limit is exceeded\n"
7950 "Restart interval in minutes\n"
9cbd06e0
DA
7951 "Only give warning message when limit is exceeded\n"
7952 "Force checking all received routes not only accepted\n")
596c17ba 7953
718e3744 7954
718e3744 7955/* "neighbor allowas-in" */
7956DEFUN (neighbor_allowas_in,
7957 neighbor_allowas_in_cmd,
fd8503f5 7958 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7959 NEIGHBOR_STR
7960 NEIGHBOR_ADDR_STR2
31500417 7961 "Accept as-path with my AS present in it\n"
f79f7a7b 7962 "Number of occurrences of AS number\n"
fd8503f5 7963 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7964{
d62a17ae 7965 int idx_peer = 1;
7966 int idx_number_origin = 3;
7967 int ret;
7968 int origin = 0;
7969 struct peer *peer;
7970 int allow_num = 0;
7971
7972 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7973 if (!peer)
7974 return CMD_WARNING_CONFIG_FAILED;
7975
7976 if (argc <= idx_number_origin)
7977 allow_num = 3;
7978 else {
7979 if (argv[idx_number_origin]->type == WORD_TKN)
7980 origin = 1;
7981 else
7982 allow_num = atoi(argv[idx_number_origin]->arg);
7983 }
7984
7985 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7986 allow_num, origin);
7987
7988 return bgp_vty_return(vty, ret);
7989}
7990
7991ALIAS_HIDDEN(
7992 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
7993 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7994 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7995 "Accept as-path with my AS present in it\n"
f79f7a7b 7996 "Number of occurrences of AS number\n"
d62a17ae 7997 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 7998
718e3744 7999DEFUN (no_neighbor_allowas_in,
8000 no_neighbor_allowas_in_cmd,
fd8503f5 8001 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8002 NO_STR
8003 NEIGHBOR_STR
8004 NEIGHBOR_ADDR_STR2
8334fd5a 8005 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8006 "Number of occurrences of AS number\n"
fd8503f5 8007 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8008{
d62a17ae 8009 int idx_peer = 2;
8010 int ret;
8011 struct peer *peer;
718e3744 8012
d62a17ae 8013 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8014 if (!peer)
8015 return CMD_WARNING_CONFIG_FAILED;
718e3744 8016
d62a17ae 8017 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8018 bgp_node_safi(vty));
718e3744 8019
d62a17ae 8020 return bgp_vty_return(vty, ret);
718e3744 8021}
6b0655a2 8022
d62a17ae 8023ALIAS_HIDDEN(
8024 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8025 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8026 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8027 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8028 "Number of occurrences of AS number\n"
d62a17ae 8029 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8030
28c6e247
IR
8031DEFUN (neighbor_ttl_security,
8032 neighbor_ttl_security_cmd,
8033 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8034 NEIGHBOR_STR
8035 NEIGHBOR_ADDR_STR2
8036 "BGP ttl-security parameters\n"
8037 "Specify the maximum number of hops to the BGP peer\n"
8038 "Number of hops to BGP peer\n")
fa411a21 8039{
d62a17ae 8040 int idx_peer = 1;
8041 int idx_number = 4;
28c6e247
IR
8042 struct peer *peer;
8043 int gtsm_hops;
d62a17ae 8044
28c6e247
IR
8045 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8046 if (!peer)
d62a17ae 8047 return CMD_WARNING_CONFIG_FAILED;
8048
28c6e247
IR
8049 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8050
8051 /*
8052 * If 'neighbor swpX', then this is for directly connected peers,
8053 * we should not accept a ttl-security hops value greater than 1.
8054 */
8055 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8056 vty_out(vty,
8057 "%s is directly connected peer, hops cannot exceed 1\n",
8058 argv[idx_peer]->arg);
8059 return CMD_WARNING_CONFIG_FAILED;
8060 }
7ebe625c 8061
28c6e247 8062 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
8063}
8064
1d80f243
IR
8065DEFUN (no_neighbor_ttl_security,
8066 no_neighbor_ttl_security_cmd,
8067 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8068 NO_STR
8069 NEIGHBOR_STR
8070 NEIGHBOR_ADDR_STR2
8071 "BGP ttl-security parameters\n"
8072 "Specify the maximum number of hops to the BGP peer\n"
8073 "Number of hops to BGP peer\n")
fa411a21 8074{
d62a17ae 8075 int idx_peer = 2;
28c6e247 8076 struct peer *peer;
fa411a21 8077
28c6e247
IR
8078 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8079 if (!peer)
d62a17ae 8080 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8081
28c6e247 8082 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 8083}
6b0655a2 8084
7c0e4312
DA
8085/* disable-addpath-rx */
8086DEFUN(neighbor_disable_addpath_rx,
8087 neighbor_disable_addpath_rx_cmd,
8088 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8089 NEIGHBOR_STR
8090 NEIGHBOR_ADDR_STR2
8091 "Do not accept additional paths\n")
8092{
8093 char *peer_str = argv[1]->arg;
8094 struct peer *peer;
8095 afi_t afi = bgp_node_afi(vty);
8096 safi_t safi = bgp_node_safi(vty);
8097
8098 peer = peer_and_group_lookup_vty(vty, peer_str);
8099 if (!peer)
8100 return CMD_WARNING_CONFIG_FAILED;
8101
8102 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8103 PEER_FLAG_DISABLE_ADDPATH_RX);
8104}
8105
8106DEFUN(no_neighbor_disable_addpath_rx,
8107 no_neighbor_disable_addpath_rx_cmd,
8108 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8109 NO_STR
8110 NEIGHBOR_STR
8111 NEIGHBOR_ADDR_STR2
8112 "Do not accept additional paths\n")
8113{
8114 char *peer_str = argv[2]->arg;
8115 struct peer *peer;
8116 afi_t afi = bgp_node_afi(vty);
8117 safi_t safi = bgp_node_safi(vty);
8118
8119 peer = peer_and_group_lookup_vty(vty, peer_str);
8120 if (!peer)
8121 return CMD_WARNING_CONFIG_FAILED;
8122
8123 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8124 PEER_FLAG_DISABLE_ADDPATH_RX);
8125}
8126
adbac85e
DW
8127DEFUN (neighbor_addpath_tx_all_paths,
8128 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8129 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8130 NEIGHBOR_STR
8131 NEIGHBOR_ADDR_STR2
8132 "Use addpath to advertise all paths to a neighbor\n")
8133{
d62a17ae 8134 int idx_peer = 1;
8135 struct peer *peer;
adbac85e 8136
d62a17ae 8137 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8138 if (!peer)
8139 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8140
dcc68b5e
MS
8141 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8142 BGP_ADDPATH_ALL);
8143 return CMD_SUCCESS;
adbac85e
DW
8144}
8145
d62a17ae 8146ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8147 neighbor_addpath_tx_all_paths_hidden_cmd,
8148 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8149 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8150 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8151
adbac85e
DW
8152DEFUN (no_neighbor_addpath_tx_all_paths,
8153 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8154 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8155 NO_STR
8156 NEIGHBOR_STR
8157 NEIGHBOR_ADDR_STR2
8158 "Use addpath to advertise all paths to a neighbor\n")
8159{
d62a17ae 8160 int idx_peer = 2;
dcc68b5e
MS
8161 struct peer *peer;
8162
8163 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8164 if (!peer)
8165 return CMD_WARNING_CONFIG_FAILED;
8166
8167 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8168 != BGP_ADDPATH_ALL) {
8169 vty_out(vty,
8170 "%% Peer not currently configured to transmit all paths.");
8171 return CMD_WARNING_CONFIG_FAILED;
8172 }
8173
8174 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8175 BGP_ADDPATH_NONE);
8176
8177 return CMD_SUCCESS;
adbac85e
DW
8178}
8179
d62a17ae 8180ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8181 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8182 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8183 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8184 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8185
06370dac
DW
8186DEFUN (neighbor_addpath_tx_bestpath_per_as,
8187 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8188 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8189 NEIGHBOR_STR
8190 NEIGHBOR_ADDR_STR2
8191 "Use addpath to advertise the bestpath per each neighboring AS\n")
8192{
d62a17ae 8193 int idx_peer = 1;
8194 struct peer *peer;
06370dac 8195
d62a17ae 8196 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8197 if (!peer)
8198 return CMD_WARNING_CONFIG_FAILED;
06370dac 8199
dcc68b5e
MS
8200 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8201 BGP_ADDPATH_BEST_PER_AS);
8202
8203 return CMD_SUCCESS;
06370dac
DW
8204}
8205
d62a17ae 8206ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8207 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8208 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8209 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8210 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8211
06370dac
DW
8212DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8213 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8214 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8215 NO_STR
8216 NEIGHBOR_STR
8217 NEIGHBOR_ADDR_STR2
8218 "Use addpath to advertise the bestpath per each neighboring AS\n")
8219{
d62a17ae 8220 int idx_peer = 2;
dcc68b5e
MS
8221 struct peer *peer;
8222
8223 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8224 if (!peer)
8225 return CMD_WARNING_CONFIG_FAILED;
8226
8227 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8228 != BGP_ADDPATH_BEST_PER_AS) {
8229 vty_out(vty,
8230 "%% Peer not currently configured to transmit all best path per as.");
8231 return CMD_WARNING_CONFIG_FAILED;
8232 }
8233
8234 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8235 BGP_ADDPATH_NONE);
8236
8237 return CMD_SUCCESS;
06370dac
DW
8238}
8239
d62a17ae 8240ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8241 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8242 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8243 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8244 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8245
2b31007c
RZ
8246DEFPY(
8247 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8248 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8249 NEIGHBOR_STR
8250 NEIGHBOR_ADDR_STR2
8251 "Detect AS loops before sending to neighbor\n")
8252{
8253 struct peer *peer;
8254
8255 peer = peer_and_group_lookup_vty(vty, neighbor);
8256 if (!peer)
8257 return CMD_WARNING_CONFIG_FAILED;
8258
8259 peer->as_path_loop_detection = true;
8260
8261 return CMD_SUCCESS;
8262}
8263
8264DEFPY(
8265 no_neighbor_aspath_loop_detection,
8266 no_neighbor_aspath_loop_detection_cmd,
8267 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8268 NO_STR
8269 NEIGHBOR_STR
8270 NEIGHBOR_ADDR_STR2
8271 "Detect AS loops before sending to neighbor\n")
8272{
8273 struct peer *peer;
8274
8275 peer = peer_and_group_lookup_vty(vty, neighbor);
8276 if (!peer)
8277 return CMD_WARNING_CONFIG_FAILED;
8278
8279 peer->as_path_loop_detection = false;
8280
8281 return CMD_SUCCESS;
8282}
8283
b9c7bc5a 8284static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8285 struct ecommunity **list, bool is_rt6)
ddb5b488 8286{
b9c7bc5a
PZ
8287 struct ecommunity *ecom = NULL;
8288 struct ecommunity *ecomadd;
ddb5b488 8289
b9c7bc5a 8290 for (; argc; --argc, ++argv) {
9a659715
PG
8291 if (is_rt6)
8292 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8293 ECOMMUNITY_ROUTE_TARGET,
8294 0);
8295 else
8296 ecomadd = ecommunity_str2com(argv[0]->arg,
8297 ECOMMUNITY_ROUTE_TARGET,
8298 0);
b9c7bc5a
PZ
8299 if (!ecomadd) {
8300 vty_out(vty, "Malformed community-list value\n");
8301 if (ecom)
8302 ecommunity_free(&ecom);
8303 return CMD_WARNING_CONFIG_FAILED;
8304 }
ddb5b488 8305
b9c7bc5a
PZ
8306 if (ecom) {
8307 ecommunity_merge(ecom, ecomadd);
8308 ecommunity_free(&ecomadd);
8309 } else {
8310 ecom = ecomadd;
8311 }
8312 }
8313
8314 if (*list) {
8315 ecommunity_free(&*list);
ddb5b488 8316 }
b9c7bc5a
PZ
8317 *list = ecom;
8318
8319 return CMD_SUCCESS;
ddb5b488
PZ
8320}
8321
0ca70ba5
DS
8322/*
8323 * v2vimport is true if we are handling a `import vrf ...` command
8324 */
8325static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8326{
0ca70ba5
DS
8327 afi_t afi;
8328
ddb5b488 8329 switch (vty->node) {
b9c7bc5a 8330 case BGP_IPV4_NODE:
0ca70ba5
DS
8331 afi = AFI_IP;
8332 break;
b9c7bc5a 8333 case BGP_IPV6_NODE:
0ca70ba5
DS
8334 afi = AFI_IP6;
8335 break;
ddb5b488
PZ
8336 default:
8337 vty_out(vty,
b9c7bc5a 8338 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 8339 return AFI_MAX;
ddb5b488 8340 }
69b07479 8341
0ca70ba5
DS
8342 if (!v2vimport) {
8343 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8344 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8345 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8346 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8347 vty_out(vty,
8348 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8349 return AFI_MAX;
8350 }
8351 } else {
8352 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8353 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8354 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8355 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8356 vty_out(vty,
8357 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8358 return AFI_MAX;
8359 }
8360 }
8361 return afi;
ddb5b488
PZ
8362}
8363
585f1adc
IR
8364DEFPY (af_rd_vpn_export,
8365 af_rd_vpn_export_cmd,
8366 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8367 NO_STR
8368 "Specify route distinguisher\n"
8369 "Between current address-family and vpn\n"
8370 "For routes leaked from current address-family to vpn\n"
8371 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 8372{
585f1adc
IR
8373 VTY_DECLVAR_CONTEXT(bgp, bgp);
8374 struct prefix_rd prd;
8375 int ret;
ddb5b488 8376 afi_t afi;
b9c7bc5a 8377 int idx = 0;
585f1adc 8378 bool yes = true;
b9c7bc5a 8379
585f1adc
IR
8380 if (argv_find(argv, argc, "no", &idx))
8381 yes = false;
ddb5b488 8382
585f1adc
IR
8383 if (yes) {
8384 ret = str2prefix_rd(rd_str, &prd);
8385 if (!ret) {
8386 vty_out(vty, "%% Malformed rd\n");
8387 return CMD_WARNING_CONFIG_FAILED;
8388 }
8389 }
ddb5b488 8390
585f1adc
IR
8391 afi = vpn_policy_getafi(vty, bgp, false);
8392 if (afi == AFI_MAX)
8393 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8394
585f1adc
IR
8395 /*
8396 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8397 */
8398 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8399 bgp_get_default(), bgp);
ddb5b488 8400
585f1adc
IR
8401 if (yes) {
8402 bgp->vpn_policy[afi].tovpn_rd = prd;
8403 SET_FLAG(bgp->vpn_policy[afi].flags,
8404 BGP_VPN_POLICY_TOVPN_RD_SET);
8405 } else {
8406 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8407 BGP_VPN_POLICY_TOVPN_RD_SET);
8408 }
69b07479 8409
585f1adc
IR
8410 /* post-change: re-export vpn routes */
8411 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8412 bgp_get_default(), bgp);
8413
8414 return CMD_SUCCESS;
ddb5b488
PZ
8415}
8416
b9c7bc5a
PZ
8417ALIAS (af_rd_vpn_export,
8418 af_no_rd_vpn_export_cmd,
8419 "no rd vpn export",
ddb5b488 8420 NO_STR
b9c7bc5a
PZ
8421 "Specify route distinguisher\n"
8422 "Between current address-family and vpn\n"
8423 "For routes leaked from current address-family to vpn\n")
ddb5b488 8424
b9c7bc5a
PZ
8425DEFPY (af_label_vpn_export,
8426 af_label_vpn_export_cmd,
e70e9f8e 8427 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 8428 NO_STR
ddb5b488 8429 "label value for VRF\n"
b9c7bc5a
PZ
8430 "Between current address-family and vpn\n"
8431 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
8432 "Label Value <0-1048575>\n"
8433 "Automatically assign a label\n")
ddb5b488
PZ
8434{
8435 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8436 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 8437 afi_t afi;
b9c7bc5a 8438 int idx = 0;
c6423c31 8439 bool yes = true;
b9c7bc5a
PZ
8440
8441 if (argv_find(argv, argc, "no", &idx))
c6423c31 8442 yes = false;
ddb5b488 8443
21a16cc2
PZ
8444 /* If "no ...", squash trailing parameter */
8445 if (!yes)
8446 label_auto = NULL;
8447
e70e9f8e
PZ
8448 if (yes) {
8449 if (!label_auto)
8450 label = label_val; /* parser should force unsigned */
8451 }
ddb5b488 8452
0ca70ba5 8453 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8454 if (afi == AFI_MAX)
8455 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 8456
e70e9f8e 8457
69b07479
DS
8458 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8459 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8460 /* no change */
8461 return CMD_SUCCESS;
e70e9f8e 8462
69b07479
DS
8463 /*
8464 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8465 */
8466 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8467 bgp_get_default(), bgp);
8468
8469 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8470 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8471
8472 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8473
8474 /*
8475 * label has previously been automatically
8476 * assigned by labelpool: release it
8477 *
8478 * NB if tovpn_label == MPLS_LABEL_NONE it
8479 * means the automatic assignment is in flight
8480 * and therefore the labelpool callback must
8481 * detect that the auto label is not needed.
8482 */
8483
8484 bgp_lp_release(LP_TYPE_VRF,
8485 &bgp->vpn_policy[afi],
8486 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 8487 }
69b07479
DS
8488 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8489 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8490 }
ddb5b488 8491
69b07479
DS
8492 bgp->vpn_policy[afi].tovpn_label = label;
8493 if (label_auto) {
8494 SET_FLAG(bgp->vpn_policy[afi].flags,
8495 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8496 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8497 vpn_leak_label_callback);
ddb5b488
PZ
8498 }
8499
69b07479
DS
8500 /* post-change: re-export vpn routes */
8501 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8502 bgp_get_default(), bgp);
8503
0d020cd6 8504 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
8505 return CMD_SUCCESS;
8506}
8507
b72c9e14
HS
8508DEFPY (af_sid_vpn_export,
8509 af_sid_vpn_export_cmd,
8510 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8511 NO_STR
8512 "sid value for VRF\n"
8513 "Between current address-family and vpn\n"
8514 "For routes leaked from current address-family to vpn\n"
8515 "Sid allocation index\n"
8516 "Automatically assign a label\n")
8517{
8518 VTY_DECLVAR_CONTEXT(bgp, bgp);
8519 afi_t afi;
8520 int debug = 0;
8521 int idx = 0;
8522 bool yes = true;
8523
8524 if (argv_find(argv, argc, "no", &idx))
8525 yes = false;
8526 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8527 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8528
8529 afi = vpn_policy_getafi(vty, bgp, false);
8530 if (afi == AFI_MAX)
8531 return CMD_WARNING_CONFIG_FAILED;
8532
8533 if (!yes) {
8534 /* implement me */
8535 vty_out(vty, "It's not implemented");
8536 return CMD_WARNING_CONFIG_FAILED;
8537 }
8538
8539 /* skip when it's already configured */
8540 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8541 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8542 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8543 return CMD_SUCCESS;
8544
7de4c885
HS
8545 /*
8546 * mode change between sid_idx and sid_auto isn't supported.
8547 * user must negate sid vpn export when they want to change the mode
8548 */
b72c9e14
HS
8549 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8550 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8551 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8552 vty_out(vty, "it's already configured as %s.\n",
8553 sid_auto ? "auto-mode" : "idx-mode");
8554 return CMD_WARNING_CONFIG_FAILED;
8555 }
8556
8557 /* pre-change */
8558 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8559 bgp_get_default(), bgp);
8560
8561 if (sid_auto) {
8562 /* SID allocation auto-mode */
8563 if (debug)
8564 zlog_debug("%s: auto sid alloc.", __func__);
8565 SET_FLAG(bgp->vpn_policy[afi].flags,
8566 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8567 } else {
8568 /* SID allocation index-mode */
8569 if (debug)
8570 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8571 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8572 }
8573
8574 /* post-change */
8575 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8576 bgp_get_default(), bgp);
8577 return CMD_SUCCESS;
8578}
8579
b9c7bc5a
PZ
8580ALIAS (af_label_vpn_export,
8581 af_no_label_vpn_export_cmd,
8582 "no label vpn export",
8583 NO_STR
8584 "label value for VRF\n"
8585 "Between current address-family and vpn\n"
8586 "For routes leaked from current address-family to vpn\n")
ddb5b488 8587
585f1adc 8588DEFPY (af_nexthop_vpn_export,
b9c7bc5a 8589 af_nexthop_vpn_export_cmd,
8c85ca28 8590 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 8591 NO_STR
ddb5b488 8592 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
8593 "Between current address-family and vpn\n"
8594 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8595 "IPv4 prefix\n"
8596 "IPv6 prefix\n")
8597{
585f1adc 8598 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 8599 afi_t afi;
ddb5b488
PZ
8600 struct prefix p;
8601
8c85ca28
QY
8602 if (!no) {
8603 if (!nexthop_su) {
8604 vty_out(vty, "%% Nexthop required\n");
8605 return CMD_WARNING_CONFIG_FAILED;
8606 }
8c85ca28 8607 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
8608 return CMD_WARNING_CONFIG_FAILED;
8609 }
ddb5b488 8610
585f1adc
IR
8611 afi = vpn_policy_getafi(vty, bgp, false);
8612 if (afi == AFI_MAX)
8613 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8614
585f1adc
IR
8615 /*
8616 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8617 */
8618 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8619 bgp_get_default(), bgp);
ddb5b488 8620
585f1adc
IR
8621 if (!no) {
8622 bgp->vpn_policy[afi].tovpn_nexthop = p;
8623 SET_FLAG(bgp->vpn_policy[afi].flags,
8624 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8625 } else {
8626 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8627 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8628 }
69b07479 8629
585f1adc
IR
8630 /* post-change: re-export vpn routes */
8631 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8632 bgp_get_default(), bgp);
37a87b8f 8633
585f1adc 8634 return CMD_SUCCESS;
ddb5b488
PZ
8635}
8636
b9c7bc5a 8637static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 8638{
b9c7bc5a
PZ
8639 if (!strcmp(dstr, "import")) {
8640 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8641 } else if (!strcmp(dstr, "export")) {
8642 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8643 } else if (!strcmp(dstr, "both")) {
8644 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8645 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8646 } else {
8647 vty_out(vty, "%% direction parse error\n");
8648 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8649 }
ddb5b488
PZ
8650 return CMD_SUCCESS;
8651}
8652
b9c7bc5a
PZ
8653DEFPY (af_rt_vpn_imexport,
8654 af_rt_vpn_imexport_cmd,
8655 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8656 NO_STR
8657 "Specify route target list\n"
ddb5b488 8658 "Specify route target list\n"
b9c7bc5a
PZ
8659 "Between current address-family and vpn\n"
8660 "For routes leaked from vpn to current address-family: match any\n"
8661 "For routes leaked from current address-family to vpn: set\n"
8662 "both import: match any and export: set\n"
ddb5b488
PZ
8663 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8664{
8665 VTY_DECLVAR_CONTEXT(bgp, bgp);
8666 int ret;
8667 struct ecommunity *ecom = NULL;
8668 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
8669 vpn_policy_direction_t dir;
8670 afi_t afi;
8671 int idx = 0;
c6423c31 8672 bool yes = true;
ddb5b488 8673
b9c7bc5a 8674 if (argv_find(argv, argc, "no", &idx))
c6423c31 8675 yes = false;
b9c7bc5a 8676
0ca70ba5 8677 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8678 if (afi == AFI_MAX)
8679 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8680
b9c7bc5a 8681 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
8682 if (ret != CMD_SUCCESS)
8683 return ret;
8684
b9c7bc5a
PZ
8685 if (yes) {
8686 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8687 vty_out(vty, "%% Missing RTLIST\n");
8688 return CMD_WARNING_CONFIG_FAILED;
8689 }
c6423c31 8690 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
8691 if (ret != CMD_SUCCESS) {
8692 return ret;
8693 }
ddb5b488
PZ
8694 }
8695
69b07479
DS
8696 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8697 if (!dodir[dir])
ddb5b488 8698 continue;
ddb5b488 8699
69b07479 8700 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8701
69b07479
DS
8702 if (yes) {
8703 if (bgp->vpn_policy[afi].rtlist[dir])
8704 ecommunity_free(
8705 &bgp->vpn_policy[afi].rtlist[dir]);
8706 bgp->vpn_policy[afi].rtlist[dir] =
8707 ecommunity_dup(ecom);
8708 } else {
8709 if (bgp->vpn_policy[afi].rtlist[dir])
8710 ecommunity_free(
8711 &bgp->vpn_policy[afi].rtlist[dir]);
8712 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 8713 }
69b07479
DS
8714
8715 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8716 }
69b07479 8717
d555f3e9
PZ
8718 if (ecom)
8719 ecommunity_free(&ecom);
ddb5b488
PZ
8720
8721 return CMD_SUCCESS;
8722}
8723
b9c7bc5a
PZ
8724ALIAS (af_rt_vpn_imexport,
8725 af_no_rt_vpn_imexport_cmd,
8726 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
8727 NO_STR
8728 "Specify route target list\n"
b9c7bc5a
PZ
8729 "Specify route target list\n"
8730 "Between current address-family and vpn\n"
8731 "For routes leaked from vpn to current address-family\n"
8732 "For routes leaked from current address-family to vpn\n"
8733 "both import and export\n")
8734
585f1adc 8735DEFPY (af_route_map_vpn_imexport,
b9c7bc5a
PZ
8736 af_route_map_vpn_imexport_cmd,
8737/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8738 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8739 NO_STR
ddb5b488 8740 "Specify route map\n"
b9c7bc5a
PZ
8741 "Between current address-family and vpn\n"
8742 "For routes leaked from vpn to current address-family\n"
8743 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8744 "name of route-map\n")
8745{
585f1adc
IR
8746 VTY_DECLVAR_CONTEXT(bgp, bgp);
8747 int ret;
8748 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8749 vpn_policy_direction_t dir;
ddb5b488 8750 afi_t afi;
ddb5b488 8751 int idx = 0;
585f1adc 8752 bool yes = true;
ddb5b488 8753
585f1adc
IR
8754 if (argv_find(argv, argc, "no", &idx))
8755 yes = false;
ddb5b488 8756
585f1adc
IR
8757 afi = vpn_policy_getafi(vty, bgp, false);
8758 if (afi == AFI_MAX)
8759 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8760
585f1adc
IR
8761 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8762 if (ret != CMD_SUCCESS)
8763 return ret;
ddb5b488 8764
585f1adc
IR
8765 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8766 if (!dodir[dir])
8767 continue;
69b07479 8768
585f1adc
IR
8769 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8770
8771 if (yes) {
8772 if (bgp->vpn_policy[afi].rmap_name[dir])
8773 XFREE(MTYPE_ROUTE_MAP_NAME,
8774 bgp->vpn_policy[afi].rmap_name[dir]);
8775 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
8776 MTYPE_ROUTE_MAP_NAME, rmap_str);
8777 bgp->vpn_policy[afi].rmap[dir] =
8778 route_map_lookup_warn_noexist(vty, rmap_str);
8779 if (!bgp->vpn_policy[afi].rmap[dir])
8780 return CMD_SUCCESS;
8781 } else {
8782 if (bgp->vpn_policy[afi].rmap_name[dir])
8783 XFREE(MTYPE_ROUTE_MAP_NAME,
8784 bgp->vpn_policy[afi].rmap_name[dir]);
8785 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8786 bgp->vpn_policy[afi].rmap[dir] = NULL;
8787 }
8788
8789 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8790 }
ddb5b488 8791
585f1adc 8792 return CMD_SUCCESS;
ddb5b488
PZ
8793}
8794
b9c7bc5a
PZ
8795ALIAS (af_route_map_vpn_imexport,
8796 af_no_route_map_vpn_imexport_cmd,
8797 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
8798 NO_STR
8799 "Specify route map\n"
b9c7bc5a
PZ
8800 "Between current address-family and vpn\n"
8801 "For routes leaked from vpn to current address-family\n"
8802 "For routes leaked from current address-family to vpn\n")
8803
bb4f6190 8804DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 8805 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
8806 "Import routes from another VRF\n"
8807 "Vrf routes being filtered\n"
8808 "Specify route map\n"
8809 "name of route-map\n")
8810{
8811 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
8812 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8813 afi_t afi;
bb4f6190
DS
8814 struct bgp *bgp_default;
8815
0ca70ba5 8816 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
8817 if (afi == AFI_MAX)
8818 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
8819
8820 bgp_default = bgp_get_default();
8821 if (!bgp_default) {
8822 int32_t ret;
8823 as_t as = bgp->as;
8824
8825 /* Auto-create assuming the same AS */
5d5393b9
DL
8826 ret = bgp_get_vty(&bgp_default, &as, NULL,
8827 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
8828
8829 if (ret) {
8830 vty_out(vty,
8831 "VRF default is not configured as a bgp instance\n");
8832 return CMD_WARNING;
8833 }
8834 }
8835
69b07479 8836 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 8837
ae6a6fb4
DS
8838 if (bgp->vpn_policy[afi].rmap_name[dir])
8839 XFREE(MTYPE_ROUTE_MAP_NAME,
8840 bgp->vpn_policy[afi].rmap_name[dir]);
8841 bgp->vpn_policy[afi].rmap_name[dir] =
8842 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8843 bgp->vpn_policy[afi].rmap[dir] =
8844 route_map_lookup_warn_noexist(vty, rmap_str);
8845 if (!bgp->vpn_policy[afi].rmap[dir])
8846 return CMD_SUCCESS;
8847
8848 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8849 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 8850
69b07479
DS
8851 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8852
bb4f6190
DS
8853 return CMD_SUCCESS;
8854}
8855
ae6a6fb4
DS
8856DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
8857 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
8858 NO_STR
8859 "Import routes from another VRF\n"
8860 "Vrf routes being filtered\n"
ae6a6fb4
DS
8861 "Specify route map\n"
8862 "name of route-map\n")
8863{
8864 VTY_DECLVAR_CONTEXT(bgp, bgp);
8865 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8866 afi_t afi;
8867
8868 afi = vpn_policy_getafi(vty, bgp, true);
8869 if (afi == AFI_MAX)
8870 return CMD_WARNING_CONFIG_FAILED;
8871
8872 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8873
8874 if (bgp->vpn_policy[afi].rmap_name[dir])
8875 XFREE(MTYPE_ROUTE_MAP_NAME,
8876 bgp->vpn_policy[afi].rmap_name[dir]);
8877 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8878 bgp->vpn_policy[afi].rmap[dir] = NULL;
8879
8880 if (bgp->vpn_policy[afi].import_vrf->count == 0)
8881 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8882 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8883
8884 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8885
8886 return CMD_SUCCESS;
8887}
bb4f6190 8888
585f1adc
IR
8889DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
8890 "[no] import vrf VIEWVRFNAME$import_name",
8891 NO_STR
8892 "Import routes from another VRF\n"
8893 "VRF to import from\n"
8894 "The name of the VRF\n")
12a844a5 8895{
585f1adc
IR
8896 VTY_DECLVAR_CONTEXT(bgp, bgp);
8897 struct listnode *node;
8898 struct bgp *vrf_bgp, *bgp_default;
8899 int32_t ret = 0;
8900 as_t as = bgp->as;
8901 bool remove = false;
8902 int32_t idx = 0;
8903 char *vname;
8904 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
8905 safi_t safi;
8906 afi_t afi;
8907
867f0cca 8908 if (import_name == NULL) {
8909 vty_out(vty, "%% Missing import name\n");
8910 return CMD_WARNING;
8911 }
8912
ae6a6fb4
DS
8913 if (strcmp(import_name, "route-map") == 0) {
8914 vty_out(vty, "%% Must include route-map name\n");
8915 return CMD_WARNING;
8916 }
8917
585f1adc
IR
8918 if (argv_find(argv, argc, "no", &idx))
8919 remove = true;
8920
8921 afi = vpn_policy_getafi(vty, bgp, true);
8922 if (afi == AFI_MAX)
8923 return CMD_WARNING_CONFIG_FAILED;
8924
12a844a5
DS
8925 safi = bgp_node_safi(vty);
8926
585f1adc
IR
8927 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
8928 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
8929 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
8930 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
8931 remove ? "unimport" : "import", import_name);
8932 return CMD_WARNING;
8933 }
25679caa 8934
585f1adc
IR
8935 bgp_default = bgp_get_default();
8936 if (!bgp_default) {
8937 /* Auto-create assuming the same AS */
8938 ret = bgp_get_vty(&bgp_default, &as, NULL,
8939 BGP_INSTANCE_TYPE_DEFAULT);
12a844a5 8940
585f1adc
IR
8941 if (ret) {
8942 vty_out(vty,
8943 "VRF default is not configured as a bgp instance\n");
8944 return CMD_WARNING;
8945 }
8946 }
12a844a5 8947
585f1adc
IR
8948 vrf_bgp = bgp_lookup_by_name(import_name);
8949 if (!vrf_bgp) {
8950 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
8951 vrf_bgp = bgp_default;
8952 else
8953 /* Auto-create assuming the same AS */
8954 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
8955
8956 if (ret) {
8957 vty_out(vty,
8958 "VRF %s is not configured as a bgp instance\n",
8959 import_name);
8960 return CMD_WARNING;
8961 }
8962 }
8963
8964 if (remove) {
8965 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
8966 } else {
8967 /* Already importing from "import_vrf"? */
8968 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
8969 vname)) {
8970 if (strcmp(vname, import_name) == 0)
8971 return CMD_WARNING;
8972 }
8973
8974 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
8975 }
8976
8977 return CMD_SUCCESS;
12a844a5
DS
8978}
8979
b9c7bc5a 8980/* This command is valid only in a bgp vrf instance or the default instance */
585f1adc 8981DEFPY (bgp_imexport_vpn,
b9c7bc5a
PZ
8982 bgp_imexport_vpn_cmd,
8983 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
8984 NO_STR
8985 "Import routes to this address-family\n"
8986 "Export routes from this address-family\n"
8987 "to/from default instance VPN RIB\n")
ddb5b488 8988{
585f1adc
IR
8989 VTY_DECLVAR_CONTEXT(bgp, bgp);
8990 int previous_state;
37a87b8f 8991 afi_t afi;
585f1adc
IR
8992 safi_t safi;
8993 int idx = 0;
8994 bool yes = true;
8995 int flag;
8996 vpn_policy_direction_t dir;
8997
8998 if (argv_find(argv, argc, "no", &idx))
8999 yes = false;
9000
9001 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9002 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9003
9004 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9005 return CMD_WARNING_CONFIG_FAILED;
9006 }
ddb5b488 9007
b9c7bc5a
PZ
9008 afi = bgp_node_afi(vty);
9009 safi = bgp_node_safi(vty);
585f1adc
IR
9010 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9011 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9012 return CMD_WARNING_CONFIG_FAILED;
9013 }
ddb5b488 9014
b9c7bc5a 9015 if (!strcmp(direction_str, "import")) {
585f1adc
IR
9016 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9017 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b9c7bc5a 9018 } else if (!strcmp(direction_str, "export")) {
585f1adc
IR
9019 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9020 dir = BGP_VPN_POLICY_DIR_TOVPN;
b9c7bc5a
PZ
9021 } else {
9022 vty_out(vty, "%% unknown direction %s\n", direction_str);
9023 return CMD_WARNING_CONFIG_FAILED;
9024 }
9025
585f1adc 9026 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 9027
585f1adc
IR
9028 if (yes) {
9029 SET_FLAG(bgp->af_flags[afi][safi], flag);
9030 if (!previous_state) {
9031 /* trigger export current vrf */
9032 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9033 }
9034 } else {
9035 if (previous_state) {
9036 /* trigger un-export current vrf */
9037 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9038 }
9039 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9040 }
37a87b8f 9041
1ca2fd11
IR
9042 hook_call(bgp_snmp_init_stats, bgp);
9043
585f1adc 9044 return CMD_SUCCESS;
ddb5b488
PZ
9045}
9046
301ad80a
PG
9047DEFPY (af_routetarget_import,
9048 af_routetarget_import_cmd,
9a659715 9049 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9050 NO_STR
9051 "Specify route target list\n"
9052 "Specify route target list\n"
9a659715
PG
9053 "Specify route target list\n"
9054 "Specify route target list\n"
301ad80a
PG
9055 "Flow-spec redirect type route target\n"
9056 "Import routes to this address-family\n"
9a659715 9057 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9058{
9059 VTY_DECLVAR_CONTEXT(bgp, bgp);
9060 int ret;
9061 struct ecommunity *ecom = NULL;
301ad80a 9062 afi_t afi;
9a659715 9063 int idx = 0, idx_unused = 0;
c6423c31
PG
9064 bool yes = true;
9065 bool rt6 = false;
301ad80a
PG
9066
9067 if (argv_find(argv, argc, "no", &idx))
c6423c31 9068 yes = false;
301ad80a 9069
9a659715
PG
9070 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9071 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9072 rt6 = true;
301ad80a 9073
0ca70ba5 9074 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9075 if (afi == AFI_MAX)
9076 return CMD_WARNING_CONFIG_FAILED;
9077
9a659715
PG
9078 if (rt6 && afi != AFI_IP6)
9079 return CMD_WARNING_CONFIG_FAILED;
9080
301ad80a
PG
9081 if (yes) {
9082 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9083 vty_out(vty, "%% Missing RTLIST\n");
9084 return CMD_WARNING_CONFIG_FAILED;
9085 }
9a659715 9086 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9087 if (ret != CMD_SUCCESS)
9088 return ret;
9089 }
69b07479
DS
9090
9091 if (yes) {
9092 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9093 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9094 .import_redirect_rtlist);
69b07479
DS
9095 bgp->vpn_policy[afi].import_redirect_rtlist =
9096 ecommunity_dup(ecom);
9097 } else {
9098 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9099 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9100 .import_redirect_rtlist);
69b07479 9101 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9102 }
69b07479 9103
301ad80a
PG
9104 if (ecom)
9105 ecommunity_free(&ecom);
9106
9107 return CMD_SUCCESS;
9108}
9109
505e5056 9110DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9111 address_family_ipv4_safi_cmd,
9112 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9113 "Enter Address Family command mode\n"
9114 "Address Family\n"
9115 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9116{
f51bae9c 9117
d62a17ae 9118 if (argc == 3) {
585f1adc
IR
9119 VTY_DECLVAR_CONTEXT(bgp, bgp);
9120 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9121 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9122 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9123 && safi != SAFI_EVPN) {
31947174
MK
9124 vty_out(vty,
9125 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9126 return CMD_WARNING_CONFIG_FAILED;
9127 }
585f1adc
IR
9128 vty->node = bgp_node_type(AFI_IP, safi);
9129 } else
9130 vty->node = BGP_IPV4_NODE;
718e3744 9131
d62a17ae 9132 return CMD_SUCCESS;
718e3744 9133}
9134
505e5056 9135DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9136 address_family_ipv6_safi_cmd,
9137 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9138 "Enter Address Family command mode\n"
9139 "Address Family\n"
9140 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9141{
d62a17ae 9142 if (argc == 3) {
585f1adc
IR
9143 VTY_DECLVAR_CONTEXT(bgp, bgp);
9144 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9145 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9146 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9147 && safi != SAFI_EVPN) {
31947174
MK
9148 vty_out(vty,
9149 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9150 return CMD_WARNING_CONFIG_FAILED;
9151 }
585f1adc
IR
9152 vty->node = bgp_node_type(AFI_IP6, safi);
9153 } else
9154 vty->node = BGP_IPV6_NODE;
25ffbdc1 9155
d62a17ae 9156 return CMD_SUCCESS;
25ffbdc1 9157}
718e3744 9158
d6902373 9159#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9160DEFUN_NOSH (address_family_vpnv4,
718e3744 9161 address_family_vpnv4_cmd,
8334fd5a 9162 "address-family vpnv4 [unicast]",
718e3744 9163 "Enter Address Family command mode\n"
8c3deaae 9164 "Address Family\n"
3a2d747c 9165 "Address Family modifier\n")
718e3744 9166{
d62a17ae 9167 vty->node = BGP_VPNV4_NODE;
9168 return CMD_SUCCESS;
718e3744 9169}
9170
505e5056 9171DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9172 address_family_vpnv6_cmd,
8334fd5a 9173 "address-family vpnv6 [unicast]",
8ecd3266 9174 "Enter Address Family command mode\n"
8c3deaae 9175 "Address Family\n"
3a2d747c 9176 "Address Family modifier\n")
8ecd3266 9177{
d62a17ae 9178 vty->node = BGP_VPNV6_NODE;
9179 return CMD_SUCCESS;
8ecd3266 9180}
64e4a6c5 9181#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9182
505e5056 9183DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9184 address_family_evpn_cmd,
7111c1a0 9185 "address-family l2vpn evpn",
4e0b7b6d 9186 "Enter Address Family command mode\n"
7111c1a0
QY
9187 "Address Family\n"
9188 "Address Family modifier\n")
4e0b7b6d 9189{
2131d5cf 9190 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9191 vty->node = BGP_EVPN_NODE;
9192 return CMD_SUCCESS;
4e0b7b6d
PG
9193}
9194
bfaab44d
HS
9195DEFUN_NOSH (bgp_segment_routing_srv6,
9196 bgp_segment_routing_srv6_cmd,
9197 "segment-routing srv6",
9198 "Segment-Routing configuration\n"
9199 "Segment-Routing SRv6 configuration\n")
9200{
9201 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 9202 bgp->srv6_enabled = true;
bfaab44d
HS
9203 vty->node = BGP_SRV6_NODE;
9204 return CMD_SUCCESS;
9205}
9206
0249b8b6
HS
9207DEFUN (no_bgp_segment_routing_srv6,
9208 no_bgp_segment_routing_srv6_cmd,
9209 "no segment-routing srv6",
9210 NO_STR
9211 "Segment-Routing configuration\n"
9212 "Segment-Routing SRv6 configuration\n")
9213{
9214 VTY_DECLVAR_CONTEXT(bgp, bgp);
9215
9216 if (strlen(bgp->srv6_locator_name) > 0)
9217 if (bgp_srv6_locator_unset(bgp) < 0)
9218 return CMD_WARNING_CONFIG_FAILED;
9219
9220 bgp->srv6_enabled = false;
9221 return CMD_SUCCESS;
9222}
9223
a0281b2e
HS
9224DEFPY (bgp_srv6_locator,
9225 bgp_srv6_locator_cmd,
9226 "locator NAME$name",
9227 "Specify SRv6 locator\n"
9228 "Specify SRv6 locator\n")
9229{
9230 VTY_DECLVAR_CONTEXT(bgp, bgp);
7de4c885 9231 int ret;
a0281b2e
HS
9232
9233 if (strlen(bgp->srv6_locator_name) > 0
9234 && strcmp(name, bgp->srv6_locator_name) != 0) {
9235 vty_out(vty, "srv6 locator is already configured\n");
9236 return CMD_WARNING_CONFIG_FAILED;
7de4c885
HS
9237 }
9238
9239 snprintf(bgp->srv6_locator_name,
9240 sizeof(bgp->srv6_locator_name), "%s", name);
a0281b2e 9241
7de4c885 9242 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
a0281b2e
HS
9243 if (ret < 0)
9244 return CMD_WARNING_CONFIG_FAILED;
9245
9246 return CMD_SUCCESS;
9247}
9248
0249b8b6
HS
9249DEFPY (no_bgp_srv6_locator,
9250 no_bgp_srv6_locator_cmd,
9251 "no locator NAME$name",
9252 NO_STR
9253 "Specify SRv6 locator\n"
9254 "Specify SRv6 locator\n")
9255{
9256 VTY_DECLVAR_CONTEXT(bgp, bgp);
9257
9258 /* when locator isn't configured, do nothing */
9259 if (strlen(bgp->srv6_locator_name) < 1)
9260 return CMD_SUCCESS;
9261
9262 /* name validation */
9263 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9264 vty_out(vty, "%% No srv6 locator is configured\n");
9265 return CMD_WARNING_CONFIG_FAILED;
9266 }
9267
9268 /* unset locator */
9269 if (bgp_srv6_locator_unset(bgp) < 0)
9270 return CMD_WARNING_CONFIG_FAILED;
9271
9272 return CMD_SUCCESS;
9273}
9274
ea372e81
HS
9275DEFPY (show_bgp_srv6,
9276 show_bgp_srv6_cmd,
9277 "show bgp segment-routing srv6",
9278 SHOW_STR
9279 BGP_STR
9280 "BGP Segment Routing\n"
9281 "BGP Segment Routing SRv6\n")
9282{
9283 struct bgp *bgp;
9284 struct listnode *node;
9285 struct prefix_ipv6 *chunk;
9286 struct bgp_srv6_function *func;
9287 struct in6_addr *tovpn4_sid;
9288 struct in6_addr *tovpn6_sid;
9289 char buf[256];
9290 char buf_tovpn4_sid[256];
9291 char buf_tovpn6_sid[256];
9292
9293 bgp = bgp_get_default();
96db4340 9294 if (!bgp)
ea372e81
HS
9295 return CMD_SUCCESS;
9296
9297 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9298 vty_out(vty, "locator_chunks:\n");
9299 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9300 prefix2str(chunk, buf, sizeof(buf));
9301 vty_out(vty, "- %s\n", buf);
9302 }
9303
9304 vty_out(vty, "functions:\n");
9305 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9306 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9307 vty_out(vty, "- sid: %s\n", buf);
9308 vty_out(vty, " locator: %s\n", func->locator_name);
9309 }
9310
9311 vty_out(vty, "bgps:\n");
9312 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9313 vty_out(vty, "- name: %s\n",
9314 bgp->name ? bgp->name : "default");
9315
9316 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9317 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9318 if (tovpn4_sid)
9319 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9320 sizeof(buf_tovpn4_sid));
9321 if (tovpn6_sid)
9322 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9323 sizeof(buf_tovpn6_sid));
9324
9325 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9326 tovpn4_sid ? buf_tovpn4_sid : "none");
9327 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9328 tovpn6_sid ? buf_tovpn6_sid : "none");
9329 }
9330
9331 return CMD_SUCCESS;
9332}
9333
505e5056 9334DEFUN_NOSH (exit_address_family,
718e3744 9335 exit_address_family_cmd,
9336 "exit-address-family",
9337 "Exit from Address Family configuration mode\n")
9338{
d62a17ae 9339 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9340 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9341 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9342 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9343 || vty->node == BGP_EVPN_NODE
9344 || vty->node == BGP_FLOWSPECV4_NODE
9345 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9346 vty->node = BGP_NODE;
9347 return CMD_SUCCESS;
718e3744 9348}
6b0655a2 9349
8ad7271d 9350/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9351static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9352 const char *ip_str, afi_t afi, safi_t safi,
9353 struct prefix_rd *prd)
9354{
9355 int ret;
9356 struct prefix match;
9bcb3eef
DS
9357 struct bgp_dest *dest;
9358 struct bgp_dest *rm;
d62a17ae 9359 struct bgp *bgp;
9360 struct bgp_table *table;
9361 struct bgp_table *rib;
9362
9363 /* BGP structure lookup. */
9364 if (view_name) {
9365 bgp = bgp_lookup_by_name(view_name);
9366 if (bgp == NULL) {
9367 vty_out(vty, "%% Can't find BGP instance %s\n",
9368 view_name);
9369 return CMD_WARNING;
9370 }
9371 } else {
9372 bgp = bgp_get_default();
9373 if (bgp == NULL) {
9374 vty_out(vty, "%% No BGP process is configured\n");
9375 return CMD_WARNING;
9376 }
9377 }
9378
9379 /* Check IP address argument. */
9380 ret = str2prefix(ip_str, &match);
9381 if (!ret) {
9382 vty_out(vty, "%% address is malformed\n");
9383 return CMD_WARNING;
9384 }
9385
9386 match.family = afi2family(afi);
9387 rib = bgp->rib[afi][safi];
9388
9389 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9390 for (dest = bgp_table_top(rib); dest;
9391 dest = bgp_route_next(dest)) {
9392 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9393
9bcb3eef 9394 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9395 continue;
9396
9bcb3eef 9397 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9398 if (table == NULL)
9399 continue;
9400
4953391b
DA
9401 rm = bgp_node_match(table, &match);
9402 if (rm != NULL) {
b54892e0 9403 const struct prefix *rm_p =
9bcb3eef 9404 bgp_dest_get_prefix(rm);
b54892e0
DS
9405
9406 if (rm_p->prefixlen == match.prefixlen) {
9407 SET_FLAG(rm->flags,
9408 BGP_NODE_USER_CLEAR);
9409 bgp_process(bgp, rm, afi, safi);
d62a17ae 9410 }
9bcb3eef 9411 bgp_dest_unlock_node(rm);
d62a17ae 9412 }
9413 }
9414 } else {
4953391b
DA
9415 dest = bgp_node_match(rib, &match);
9416 if (dest != NULL) {
9bcb3eef 9417 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9418
9bcb3eef
DS
9419 if (dest_p->prefixlen == match.prefixlen) {
9420 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9421 bgp_process(bgp, dest, afi, safi);
d62a17ae 9422 }
9bcb3eef 9423 bgp_dest_unlock_node(dest);
d62a17ae 9424 }
9425 }
9426
9427 return CMD_SUCCESS;
8ad7271d
DS
9428}
9429
b09b5ae0 9430/* one clear bgp command to rule them all */
718e3744 9431DEFUN (clear_ip_bgp_all,
9432 clear_ip_bgp_all_cmd,
453c92f6 9433 "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 9434 CLEAR_STR
9435 IP_STR
9436 BGP_STR
838758ac 9437 BGP_INSTANCE_HELP_STR
510afcd6 9438 BGP_AFI_HELP_STR
fd5e7b70 9439 "Address Family\n"
510afcd6 9440 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 9441 "Address Family modifier\n"
b09b5ae0 9442 "Clear all peers\n"
453c92f6 9443 "BGP IPv4 neighbor to clear\n"
a80beece 9444 "BGP IPv6 neighbor to clear\n"
838758ac 9445 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9446 "Clear peers with the AS number\n"
9447 "Clear all external peers\n"
718e3744 9448 "Clear all members of peer-group\n"
b09b5ae0 9449 "BGP peer-group name\n"
b09b5ae0
DW
9450 BGP_SOFT_STR
9451 BGP_SOFT_IN_STR
b09b5ae0
DW
9452 BGP_SOFT_OUT_STR
9453 BGP_SOFT_IN_STR
9454 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 9455 BGP_SOFT_OUT_STR)
718e3744 9456{
d62a17ae 9457 char *vrf = NULL;
9458
dc912615
DS
9459 afi_t afi = AFI_UNSPEC;
9460 safi_t safi = SAFI_UNSPEC;
d62a17ae 9461 enum clear_sort clr_sort = clear_peer;
9462 enum bgp_clear_type clr_type;
9463 char *clr_arg = NULL;
9464
9465 int idx = 0;
9466
9467 /* clear [ip] bgp */
9468 if (argv_find(argv, argc, "ip", &idx))
9469 afi = AFI_IP;
9470
9a8bdf1c
PG
9471 /* [<vrf> VIEWVRFNAME] */
9472 if (argv_find(argv, argc, "vrf", &idx)) {
9473 vrf = argv[idx + 1]->arg;
9474 idx += 2;
9475 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9476 vrf = NULL;
9477 } else if (argv_find(argv, argc, "view", &idx)) {
9478 /* [<view> VIEWVRFNAME] */
d62a17ae 9479 vrf = argv[idx + 1]->arg;
9480 idx += 2;
9481 }
d62a17ae 9482 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9483 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9484 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9485
d7b9898c 9486 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 9487 if (argv_find(argv, argc, "*", &idx)) {
9488 clr_sort = clear_all;
9489 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9490 clr_sort = clear_peer;
9491 clr_arg = argv[idx]->arg;
9492 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9493 clr_sort = clear_peer;
9494 clr_arg = argv[idx]->arg;
9495 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9496 clr_sort = clear_group;
9497 idx++;
9498 clr_arg = argv[idx]->arg;
d7b9898c 9499 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 9500 clr_sort = clear_peer;
9501 clr_arg = argv[idx]->arg;
8fa7d444
DS
9502 } else if (argv_find(argv, argc, "WORD", &idx)) {
9503 clr_sort = clear_peer;
9504 clr_arg = argv[idx]->arg;
d62a17ae 9505 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9506 clr_sort = clear_as;
9507 clr_arg = argv[idx]->arg;
9508 } else if (argv_find(argv, argc, "external", &idx)) {
9509 clr_sort = clear_external;
9510 }
9511
9512 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
9513 if (argv_find(argv, argc, "soft", &idx)) {
9514 if (argv_find(argv, argc, "in", &idx)
9515 || argv_find(argv, argc, "out", &idx))
9516 clr_type = strmatch(argv[idx]->text, "in")
9517 ? BGP_CLEAR_SOFT_IN
9518 : BGP_CLEAR_SOFT_OUT;
9519 else
9520 clr_type = BGP_CLEAR_SOFT_BOTH;
9521 } else if (argv_find(argv, argc, "in", &idx)) {
9522 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9523 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9524 : BGP_CLEAR_SOFT_IN;
9525 } else if (argv_find(argv, argc, "out", &idx)) {
9526 clr_type = BGP_CLEAR_SOFT_OUT;
9527 } else
9528 clr_type = BGP_CLEAR_SOFT_NONE;
9529
1ca2fd11 9530 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 9531}
01080f7c 9532
8ad7271d
DS
9533DEFUN (clear_ip_bgp_prefix,
9534 clear_ip_bgp_prefix_cmd,
18c57037 9535 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
9536 CLEAR_STR
9537 IP_STR
9538 BGP_STR
838758ac 9539 BGP_INSTANCE_HELP_STR
8ad7271d 9540 "Clear bestpath and re-advertise\n"
0c7b1b01 9541 "IPv4 prefix\n")
8ad7271d 9542{
d62a17ae 9543 char *vrf = NULL;
9544 char *prefix = NULL;
8ad7271d 9545
d62a17ae 9546 int idx = 0;
01080f7c 9547
d62a17ae 9548 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
9549 if (argv_find(argv, argc, "vrf", &idx)) {
9550 vrf = argv[idx + 1]->arg;
9551 idx += 2;
9552 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9553 vrf = NULL;
9554 } else if (argv_find(argv, argc, "view", &idx)) {
9555 /* [<view> VIEWVRFNAME] */
9556 vrf = argv[idx + 1]->arg;
9557 idx += 2;
9558 }
0c7b1b01 9559
d62a17ae 9560 prefix = argv[argc - 1]->arg;
8ad7271d 9561
d62a17ae 9562 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 9563}
8ad7271d 9564
b09b5ae0
DW
9565DEFUN (clear_bgp_ipv6_safi_prefix,
9566 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 9567 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9568 CLEAR_STR
3a2d747c 9569 IP_STR
718e3744 9570 BGP_STR
8c3deaae 9571 "Address Family\n"
46f296b4 9572 BGP_SAFI_HELP_STR
b09b5ae0 9573 "Clear bestpath and re-advertise\n"
0c7b1b01 9574 "IPv6 prefix\n")
718e3744 9575{
9b475e76
PG
9576 int idx_safi = 0;
9577 int idx_ipv6_prefix = 0;
9578 safi_t safi = SAFI_UNICAST;
9579 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9580 argv[idx_ipv6_prefix]->arg : NULL;
9581
9582 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 9583 return bgp_clear_prefix(
9b475e76
PG
9584 vty, NULL, prefix, AFI_IP6,
9585 safi, NULL);
838758ac 9586}
01080f7c 9587
b09b5ae0
DW
9588DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9589 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 9590 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9591 CLEAR_STR
3a2d747c 9592 IP_STR
718e3744 9593 BGP_STR
838758ac 9594 BGP_INSTANCE_HELP_STR
8c3deaae 9595 "Address Family\n"
46f296b4 9596 BGP_SAFI_HELP_STR
b09b5ae0 9597 "Clear bestpath and re-advertise\n"
0c7b1b01 9598 "IPv6 prefix\n")
718e3744 9599{
9b475e76 9600 int idx_safi = 0;
9a8bdf1c 9601 int idx_vrfview = 0;
9b475e76
PG
9602 int idx_ipv6_prefix = 0;
9603 safi_t safi = SAFI_UNICAST;
9604 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9605 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 9606 char *vrfview = NULL;
9b475e76 9607
9a8bdf1c
PG
9608 /* [<view|vrf> VIEWVRFNAME] */
9609 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9610 vrfview = argv[idx_vrfview + 1]->arg;
9611 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9612 vrfview = NULL;
9613 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9614 /* [<view> VIEWVRFNAME] */
9615 vrfview = argv[idx_vrfview + 1]->arg;
9616 }
9b475e76
PG
9617 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9618
d62a17ae 9619 return bgp_clear_prefix(
9b475e76
PG
9620 vty, vrfview, prefix,
9621 AFI_IP6, safi, NULL);
718e3744 9622}
9623
b09b5ae0
DW
9624DEFUN (show_bgp_views,
9625 show_bgp_views_cmd,
d6e3c605 9626 "show [ip] bgp views",
b09b5ae0 9627 SHOW_STR
d6e3c605 9628 IP_STR
01080f7c 9629 BGP_STR
b09b5ae0 9630 "Show the defined BGP views\n")
01080f7c 9631{
d62a17ae 9632 struct list *inst = bm->bgp;
9633 struct listnode *node;
9634 struct bgp *bgp;
01080f7c 9635
d62a17ae 9636 vty_out(vty, "Defined BGP views:\n");
9637 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9638 /* Skip VRFs. */
9639 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9640 continue;
9641 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9642 bgp->as);
9643 }
e52702f2 9644
d62a17ae 9645 return CMD_SUCCESS;
e0081f70
ML
9646}
9647
8386ac43 9648DEFUN (show_bgp_vrfs,
9649 show_bgp_vrfs_cmd,
d6e3c605 9650 "show [ip] bgp vrfs [json]",
8386ac43 9651 SHOW_STR
d6e3c605 9652 IP_STR
8386ac43 9653 BGP_STR
9654 "Show BGP VRFs\n"
9973d184 9655 JSON_STR)
8386ac43 9656{
fe1dc5a3 9657 char buf[ETHER_ADDR_STRLEN];
d62a17ae 9658 struct list *inst = bm->bgp;
9659 struct listnode *node;
9660 struct bgp *bgp;
9f049418 9661 bool uj = use_json(argc, argv);
d62a17ae 9662 json_object *json = NULL;
9663 json_object *json_vrfs = NULL;
9664 int count = 0;
d62a17ae 9665
d62a17ae 9666 if (uj) {
9667 json = json_object_new_object();
9668 json_vrfs = json_object_new_object();
9669 }
9670
9671 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9672 const char *name, *type;
9673 struct peer *peer;
7fe96307 9674 struct listnode *node2, *nnode2;
d62a17ae 9675 int peers_cfg, peers_estb;
9676 json_object *json_vrf = NULL;
d62a17ae 9677
9678 /* Skip Views. */
9679 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9680 continue;
9681
9682 count++;
efb4077a 9683 if (!uj && count == 1) {
fe1dc5a3 9684 vty_out(vty,
efb4077a 9685 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 9686 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
9687 "#PeersEstb", "Name");
9688 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9689 "L3-VNI", "RouterMAC", "Interface");
9690 }
d62a17ae 9691
9692 peers_cfg = peers_estb = 0;
9693 if (uj)
9694 json_vrf = json_object_new_object();
9695
9696
7fe96307 9697 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 9698 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9699 continue;
9700 peers_cfg++;
feb17238 9701 if (peer_established(peer))
d62a17ae 9702 peers_estb++;
9703 }
9704
9705 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 9706 name = VRF_DEFAULT_NAME;
d62a17ae 9707 type = "DFLT";
9708 } else {
9709 name = bgp->name;
9710 type = "VRF";
9711 }
9712
a8bf7d9c 9713
d62a17ae 9714 if (uj) {
a4d82a8a
PZ
9715 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9716 ? -1
9717 : (int64_t)bgp->vrf_id;
23d0a753
DA
9718 char buf[BUFSIZ] = {0};
9719
d62a17ae 9720 json_object_string_add(json_vrf, "type", type);
9721 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
c949c771
DA
9722 json_object_string_addf(json_vrf, "routerId", "%pI4",
9723 &bgp->router_id);
d62a17ae 9724 json_object_int_add(json_vrf, "numConfiguredPeers",
9725 peers_cfg);
9726 json_object_int_add(json_vrf, "numEstablishedPeers",
9727 peers_estb);
9728
fe1dc5a3 9729 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
9730 json_object_string_add(
9731 json_vrf, "rmac",
9732 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
9733 json_object_string_add(json_vrf, "interface",
9734 ifindex2ifname(bgp->l3vni_svi_ifindex,
9735 bgp->vrf_id));
d62a17ae 9736 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 9737 } else {
23d0a753 9738 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
9739 type,
9740 bgp->vrf_id == VRF_UNKNOWN ? -1
9741 : (int)bgp->vrf_id,
23d0a753 9742 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
9743 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
9744 bgp->l3vni,
9745 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
9746 ifindex2ifname(bgp->l3vni_svi_ifindex,
9747 bgp->vrf_id));
9748 }
d62a17ae 9749 }
9750
9751 if (uj) {
9752 json_object_object_add(json, "vrfs", json_vrfs);
9753
9754 json_object_int_add(json, "totalVrfs", count);
9755
75eeda93 9756 vty_json(vty, json);
d62a17ae 9757 } else {
9758 if (count)
9759 vty_out(vty,
9760 "\nTotal number of VRFs (including default): %d\n",
9761 count);
9762 }
9763
9764 return CMD_SUCCESS;
8386ac43 9765}
9766
48ecf8f5
DS
9767DEFUN (show_bgp_mac_hash,
9768 show_bgp_mac_hash_cmd,
9769 "show bgp mac hash",
9770 SHOW_STR
9771 BGP_STR
9772 "Mac Address\n"
9773 "Mac Address database\n")
9774{
9775 bgp_mac_dump_table(vty);
9776
9777 return CMD_SUCCESS;
9778}
acf71666 9779
e3b78da8 9780static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 9781{
0291c246 9782 struct vty *vty = (struct vty *)args;
e3b78da8 9783 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 9784
23d0a753 9785 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
9786}
9787
9788static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
9789{
9790 vty_out(vty, "self nexthop database:\n");
af97a18b 9791 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
9792
9793 vty_out(vty, "Tunnel-ip database:\n");
9794 hash_iterate(bgp->tip_hash,
e3b78da8 9795 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
9796 vty);
9797}
9798
15c81ca4
DS
9799DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
9800 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
9801 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
9802 "martian next-hops\n"
9803 "martian next-hop database\n")
acf71666 9804{
0291c246 9805 struct bgp *bgp = NULL;
15c81ca4 9806 int idx = 0;
9a8bdf1c
PG
9807 char *name = NULL;
9808
9809 /* [<vrf> VIEWVRFNAME] */
9810 if (argv_find(argv, argc, "vrf", &idx)) {
9811 name = argv[idx + 1]->arg;
9812 if (name && strmatch(name, VRF_DEFAULT_NAME))
9813 name = NULL;
9814 } else if (argv_find(argv, argc, "view", &idx))
9815 /* [<view> VIEWVRFNAME] */
9816 name = argv[idx + 1]->arg;
9817 if (name)
9818 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
9819 else
9820 bgp = bgp_get_default();
acf71666 9821
acf71666
MK
9822 if (!bgp) {
9823 vty_out(vty, "%% No BGP process is configured\n");
9824 return CMD_WARNING;
9825 }
9826 bgp_show_martian_nexthops(vty, bgp);
9827
9828 return CMD_SUCCESS;
9829}
9830
f412b39a 9831DEFUN (show_bgp_memory,
4bf6a362 9832 show_bgp_memory_cmd,
7fa12b13 9833 "show [ip] bgp memory",
4bf6a362 9834 SHOW_STR
3a2d747c 9835 IP_STR
4bf6a362
PJ
9836 BGP_STR
9837 "Global BGP memory statistics\n")
9838{
d62a17ae 9839 char memstrbuf[MTYPE_MEMSTR_LEN];
9840 unsigned long count;
9841
9842 /* RIB related usage stats */
9843 count = mtype_stats_alloc(MTYPE_BGP_NODE);
9844 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
9845 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 9846 count * sizeof(struct bgp_dest)));
d62a17ae 9847
9848 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
9849 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
9850 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 9851 count * sizeof(struct bgp_path_info)));
d62a17ae 9852 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
9853 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
9854 count,
4b7e6066
DS
9855 mtype_memstr(
9856 memstrbuf, sizeof(memstrbuf),
9857 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 9858
9859 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
9860 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
9861 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9862 count * sizeof(struct bgp_static)));
9863
9864 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
9865 vty_out(vty, "%ld Packets, using %s of memory\n", count,
9866 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9867 count * sizeof(struct bpacket)));
9868
9869 /* Adj-In/Out */
9870 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
9871 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
9872 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9873 count * sizeof(struct bgp_adj_in)));
9874 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
9875 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
9876 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9877 count * sizeof(struct bgp_adj_out)));
9878
9879 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
9880 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
9881 count,
9882 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9883 count * sizeof(struct bgp_nexthop_cache)));
9884
9885 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
9886 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
9887 count,
9888 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9889 count * sizeof(struct bgp_damp_info)));
9890
9891 /* Attributes */
9892 count = attr_count();
9893 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
9894 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9895 count * sizeof(struct attr)));
9896
9897 if ((count = attr_unknown_count()))
9898 vty_out(vty, "%ld unknown attributes\n", count);
9899
9900 /* AS_PATH attributes */
9901 count = aspath_count();
9902 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
9903 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9904 count * sizeof(struct aspath)));
9905
9906 count = mtype_stats_alloc(MTYPE_AS_SEG);
9907 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
9908 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9909 count * sizeof(struct assegment)));
9910
9911 /* Other attributes */
9912 if ((count = community_count()))
9913 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9914 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9915 count * sizeof(struct community)));
d62a17ae 9916 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
9917 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9918 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9919 count * sizeof(struct ecommunity)));
d62a17ae 9920 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
9921 vty_out(vty,
9922 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
9923 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9924 count * sizeof(struct lcommunity)));
d62a17ae 9925
9926 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
9927 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
9928 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9929 count * sizeof(struct cluster_list)));
9930
9931 /* Peer related usage */
9932 count = mtype_stats_alloc(MTYPE_BGP_PEER);
9933 vty_out(vty, "%ld peers, using %s of memory\n", count,
9934 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9935 count * sizeof(struct peer)));
9936
9937 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
9938 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
9939 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9940 count * sizeof(struct peer_group)));
9941
9942 /* Other */
d62a17ae 9943 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
9944 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
9945 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9946 count * sizeof(regex_t)));
d62a17ae 9947 return CMD_SUCCESS;
4bf6a362 9948}
fee0f4c6 9949
57a9c8a8
DS
9950static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
9951{
9952 json_object *bestpath = json_object_new_object();
9953
892fedb6 9954 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
9955 json_object_string_add(bestpath, "asPath", "ignore");
9956
892fedb6 9957 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
9958 json_object_string_add(bestpath, "asPath", "confed");
9959
892fedb6
DA
9960 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
9961 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 9962 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9963 "as-set");
9964 else
a4d82a8a 9965 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9966 "true");
9967 } else
a4d82a8a 9968 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 9969
ee88563a
JM
9970 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
9971 json_object_boolean_true_add(bestpath, "peerTypeRelax");
9972
892fedb6 9973 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 9974 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
9975 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
9976 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
9977 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 9978 json_object_string_add(bestpath, "med", "confed");
892fedb6 9979 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
9980 json_object_string_add(bestpath, "med",
9981 "missing-as-worst");
9982 else
9983 json_object_string_add(bestpath, "med", "true");
9984 }
9985
9986 json_object_object_add(json, "bestPath", bestpath);
9987}
9988
3577f1c5
DD
9989/* Print the error code/subcode for why the peer is down */
9990static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
9991 json_object *json_peer, bool use_json)
9992{
9993 const char *code_str;
9994 const char *subcode_str;
9995
9996 if (use_json) {
9997 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
9998 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9999 char errorcodesubcode_hexstr[5];
10000 char errorcodesubcode_str[256];
10001
10002 code_str = bgp_notify_code_str(peer->notify.code);
10003 subcode_str = bgp_notify_subcode_str(
10004 peer->notify.code,
10005 peer->notify.subcode);
10006
772270f3
QY
10007 snprintf(errorcodesubcode_hexstr,
10008 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10009 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10010 json_object_string_add(json_peer,
10011 "lastErrorCodeSubcode",
10012 errorcodesubcode_hexstr);
10013 snprintf(errorcodesubcode_str, 255, "%s%s",
10014 code_str, subcode_str);
10015 json_object_string_add(json_peer,
10016 "lastNotificationReason",
10017 errorcodesubcode_str);
10018 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10019 && peer->notify.code == BGP_NOTIFY_CEASE
10020 && (peer->notify.subcode
10021 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10022 || peer->notify.subcode
10023 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10024 && peer->notify.length) {
10025 char msgbuf[1024];
10026 const char *msg_str;
10027
10028 msg_str = bgp_notify_admin_message(
10029 msgbuf, sizeof(msgbuf),
10030 (uint8_t *)peer->notify.data,
10031 peer->notify.length);
10032 if (msg_str)
10033 json_object_string_add(
10034 json_peer,
10035 "lastShutdownDescription",
10036 msg_str);
10037 }
10038
c258527b 10039 }
3577f1c5
DD
10040 json_object_string_add(json_peer, "lastResetDueTo",
10041 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10042 json_object_int_add(json_peer, "lastResetCode",
10043 peer->last_reset);
3577f1c5
DD
10044 } else {
10045 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10046 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10047 code_str = bgp_notify_code_str(peer->notify.code);
10048 subcode_str =
10049 bgp_notify_subcode_str(peer->notify.code,
10050 peer->notify.subcode);
10051 vty_out(vty, " Notification %s (%s%s)\n",
10052 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10053 ? "sent"
10054 : "received",
10055 code_str, subcode_str);
10056 } else {
e91c24c8 10057 vty_out(vty, " %s\n",
3577f1c5
DD
10058 peer_down_str[(int)peer->last_reset]);
10059 }
10060 }
10061}
10062
10063static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10064 safi_t safi)
10065{
feb17238 10066 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
3577f1c5
DD
10067}
10068
10069static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10070 struct peer *peer, json_object *json_peer,
10071 int max_neighbor_width, bool use_json)
10072{
10073 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10074 int len;
10075
10076 if (use_json) {
10077 if (peer_dynamic_neighbor(peer))
10078 json_object_boolean_true_add(json_peer,
10079 "dynamicPeer");
10080 if (peer->hostname)
10081 json_object_string_add(json_peer, "hostname",
10082 peer->hostname);
10083
10084 if (peer->domainname)
10085 json_object_string_add(json_peer, "domainname",
10086 peer->domainname);
10087 json_object_int_add(json_peer, "connectionsEstablished",
10088 peer->established);
10089 json_object_int_add(json_peer, "connectionsDropped",
10090 peer->dropped);
10091 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10092 use_json, json_peer);
feb17238 10093 if (peer_established(peer))
3577f1c5
DD
10094 json_object_string_add(json_peer, "lastResetDueTo",
10095 "AFI/SAFI Not Negotiated");
10096 else
10097 bgp_show_peer_reset(NULL, peer, json_peer, true);
10098 } else {
10099 dn_flag[1] = '\0';
10100 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10101 if (peer->hostname
892fedb6 10102 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10103 len = vty_out(vty, "%s%s(%s)", dn_flag,
10104 peer->hostname, peer->host);
10105 else
10106 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10107
10108 /* pad the neighbor column with spaces */
10109 if (len < max_neighbor_width)
10110 vty_out(vty, "%*s", max_neighbor_width - len,
10111 " ");
e91c24c8 10112 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10113 peer->dropped,
10114 peer_uptime(peer->uptime, timebuf,
10115 BGP_UPTIME_LEN, 0, NULL));
feb17238 10116 if (peer_established(peer))
3577f1c5
DD
10117 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10118 else
10119 bgp_show_peer_reset(vty, peer, NULL,
10120 false);
10121 }
10122}
c258527b 10123
565e9ddd 10124/* Strip peer's description to the given size. */
cb75bb31
DA
10125static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10126{
10127 static char stripped[BUFSIZ];
cb75bb31
DA
10128 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10129
cb75bb31
DA
10130 strlcpy(stripped, desc, len + 1);
10131
10132 return stripped;
10133}
3577f1c5 10134
8c1d4cd5
LS
10135/* Determine whether var peer should be filtered out of the summary. */
10136static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10137 struct peer *fpeer, int as_type,
10138 as_t as)
10139{
10140
10141 /* filter neighbor XXXX */
10142 if (fpeer && fpeer != peer)
10143 return true;
10144
10145 /* filter remote-as (internal|external) */
10146 if (as_type != AS_UNSPECIFIED) {
10147 if (peer->as_type == AS_SPECIFIED) {
10148 if (as_type == AS_INTERNAL) {
10149 if (peer->as != peer->local_as)
10150 return true;
10151 } else if (peer->as == peer->local_as)
10152 return true;
10153 } else if (as_type != peer->as_type)
10154 return true;
10155 } else if (as && as != peer->as) /* filter remote-as XXX */
10156 return true;
10157
10158 return false;
10159}
10160
565e9ddd
DA
10161/* Show BGP peer's summary information.
10162 *
10163 * Peer's description is stripped according to if `wide` option is given
10164 * or not.
10165 *
10166 * When adding new columns to `show bgp summary` output, please make
10167 * sure `Desc` is the lastest column to show because it can contain
10168 * whitespaces and the whole output will be tricky.
10169 */
d62a17ae 10170static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 10171 struct peer *fpeer, int as_type, as_t as,
96c81f66 10172 uint16_t show_flags)
d62a17ae 10173{
10174 struct peer *peer;
10175 struct listnode *node, *nnode;
10176 unsigned int count = 0, dn_count = 0;
10177 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10178 char neighbor_buf[VTY_BUFSIZ];
10179 int neighbor_col_default_width = 16;
3577f1c5 10180 int len, failed_count = 0;
ce1944f0 10181 unsigned int filtered_count = 0;
d62a17ae 10182 int max_neighbor_width = 0;
10183 int pfx_rcd_safi;
3c13337d 10184 json_object *json = NULL;
d62a17ae 10185 json_object *json_peer = NULL;
10186 json_object *json_peers = NULL;
50e05855 10187 struct peer_af *paf;
d3ada366 10188 struct bgp_filter *filter;
85eeb029
DA
10189 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10190 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10191 bool show_established =
10192 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10193 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
96c81f66 10194 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
d62a17ae 10195
10196 /* labeled-unicast routes are installed in the unicast table so in order
10197 * to
10198 * display the correct PfxRcd value we must look at SAFI_UNICAST
10199 */
3577f1c5 10200
d62a17ae 10201 if (safi == SAFI_LABELED_UNICAST)
10202 pfx_rcd_safi = SAFI_UNICAST;
10203 else
10204 pfx_rcd_safi = safi;
10205
10206 if (use_json) {
3c13337d 10207 json = json_object_new_object();
d62a17ae 10208 json_peers = json_object_new_object();
3577f1c5 10209 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10210 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10211 as_type, as)) {
ce1944f0 10212 filtered_count++;
8c1d4cd5
LS
10213 count++;
10214 continue;
10215 }
10216
3577f1c5
DD
10217 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10218 continue;
10219
10220 if (peer->afc[afi][safi]) {
10221 /* See if we have at least a single failed peer */
10222 if (bgp_has_peer_failed(peer, afi, safi))
10223 failed_count++;
10224 count++;
10225 }
10226 if (peer_dynamic_neighbor(peer))
10227 dn_count++;
10228 }
c258527b 10229
d62a17ae 10230 } else {
10231 /* Loop over all neighbors that will be displayed to determine
10232 * how many
10233 * characters are needed for the Neighbor column
10234 */
10235 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10236 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10237 as_type, as)) {
ce1944f0 10238 filtered_count++;
8c1d4cd5
LS
10239 count++;
10240 continue;
10241 }
10242
d62a17ae 10243 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10244 continue;
10245
10246 if (peer->afc[afi][safi]) {
10247 memset(dn_flag, '\0', sizeof(dn_flag));
10248 if (peer_dynamic_neighbor(peer))
10249 dn_flag[0] = '*';
10250
10251 if (peer->hostname
892fedb6
DA
10252 && CHECK_FLAG(bgp->flags,
10253 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10254 snprintf(neighbor_buf,
10255 sizeof(neighbor_buf),
10256 "%s%s(%s) ", dn_flag,
10257 peer->hostname, peer->host);
d62a17ae 10258 else
772270f3
QY
10259 snprintf(neighbor_buf,
10260 sizeof(neighbor_buf), "%s%s ",
10261 dn_flag, peer->host);
d62a17ae 10262
10263 len = strlen(neighbor_buf);
10264
10265 if (len > max_neighbor_width)
10266 max_neighbor_width = len;
c258527b 10267
3577f1c5
DD
10268 /* See if we have at least a single failed peer */
10269 if (bgp_has_peer_failed(peer, afi, safi))
10270 failed_count++;
10271 count++;
d62a17ae 10272 }
10273 }
f933309e 10274
d62a17ae 10275 /* Originally we displayed the Neighbor column as 16
10276 * characters wide so make that the default
10277 */
10278 if (max_neighbor_width < neighbor_col_default_width)
10279 max_neighbor_width = neighbor_col_default_width;
10280 }
f933309e 10281
3577f1c5
DD
10282 if (show_failed && !failed_count) {
10283 if (use_json) {
10284 json_object_int_add(json, "failedPeersCount", 0);
10285 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10286 json_object_int_add(json, "totalPeers", count);
3577f1c5 10287
75eeda93 10288 vty_json(vty, json);
3577f1c5
DD
10289 } else {
10290 vty_out(vty, "%% No failed BGP neighbors found\n");
3577f1c5
DD
10291 }
10292 return CMD_SUCCESS;
10293 }
c258527b 10294
3577f1c5 10295 count = 0; /* Reset the value as its used again */
ce1944f0 10296 filtered_count = 0;
800867d8 10297 dn_count = 0;
d62a17ae 10298 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10299 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10300 continue;
10301
ea47320b
DL
10302 if (!peer->afc[afi][safi])
10303 continue;
d62a17ae 10304
ea47320b
DL
10305 if (!count) {
10306 unsigned long ents;
10307 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10308 int64_t vrf_id_ui;
d62a17ae 10309
a4d82a8a
PZ
10310 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10311 ? -1
10312 : (int64_t)bgp->vrf_id;
ea47320b
DL
10313
10314 /* Usage summary and header */
10315 if (use_json) {
c949c771
DA
10316 json_object_string_addf(json, "routerId",
10317 "%pI4",
10318 &bgp->router_id);
60466a63
QY
10319 json_object_int_add(json, "as", bgp->as);
10320 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10321 json_object_string_add(
10322 json, "vrfName",
10323 (bgp->inst_type
10324 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10325 ? VRF_DEFAULT_NAME
ea47320b
DL
10326 : bgp->name);
10327 } else {
10328 vty_out(vty,
23d0a753
DA
10329 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10330 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10331 bgp->vrf_id == VRF_UNKNOWN
10332 ? -1
10333 : (int)bgp->vrf_id);
ea47320b
DL
10334 vty_out(vty, "\n");
10335 }
d62a17ae 10336
ea47320b 10337 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10338 if (use_json) {
ea47320b 10339 json_object_int_add(
60466a63 10340 json, "updateDelayLimit",
ea47320b 10341 bgp->v_update_delay);
d62a17ae 10342
ea47320b
DL
10343 if (bgp->v_update_delay
10344 != bgp->v_establish_wait)
d62a17ae 10345 json_object_int_add(
10346 json,
ea47320b
DL
10347 "updateDelayEstablishWait",
10348 bgp->v_establish_wait);
d62a17ae 10349
60466a63 10350 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10351 json_object_string_add(
10352 json,
10353 "updateDelayFirstNeighbor",
10354 bgp->update_delay_begin_time);
10355 json_object_boolean_true_add(
10356 json,
10357 "updateDelayInProgress");
10358 } else {
10359 if (bgp->update_delay_over) {
d62a17ae 10360 json_object_string_add(
10361 json,
10362 "updateDelayFirstNeighbor",
10363 bgp->update_delay_begin_time);
ea47320b 10364 json_object_string_add(
d62a17ae 10365 json,
ea47320b
DL
10366 "updateDelayBestpathResumed",
10367 bgp->update_delay_end_time);
10368 json_object_string_add(
d62a17ae 10369 json,
ea47320b
DL
10370 "updateDelayZebraUpdateResume",
10371 bgp->update_delay_zebra_resume_time);
10372 json_object_string_add(
10373 json,
10374 "updateDelayPeerUpdateResume",
10375 bgp->update_delay_peers_resume_time);
d62a17ae 10376 }
ea47320b
DL
10377 }
10378 } else {
10379 vty_out(vty,
10380 "Read-only mode update-delay limit: %d seconds\n",
10381 bgp->v_update_delay);
10382 if (bgp->v_update_delay
10383 != bgp->v_establish_wait)
d62a17ae 10384 vty_out(vty,
ea47320b
DL
10385 " Establish wait: %d seconds\n",
10386 bgp->v_establish_wait);
d62a17ae 10387
60466a63 10388 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10389 vty_out(vty,
10390 " First neighbor established: %s\n",
10391 bgp->update_delay_begin_time);
10392 vty_out(vty,
10393 " Delay in progress\n");
10394 } else {
10395 if (bgp->update_delay_over) {
d62a17ae 10396 vty_out(vty,
10397 " First neighbor established: %s\n",
10398 bgp->update_delay_begin_time);
10399 vty_out(vty,
ea47320b
DL
10400 " Best-paths resumed: %s\n",
10401 bgp->update_delay_end_time);
10402 vty_out(vty,
10403 " zebra update resumed: %s\n",
10404 bgp->update_delay_zebra_resume_time);
10405 vty_out(vty,
10406 " peers update resumed: %s\n",
10407 bgp->update_delay_peers_resume_time);
d62a17ae 10408 }
10409 }
10410 }
ea47320b 10411 }
d62a17ae 10412
ea47320b
DL
10413 if (use_json) {
10414 if (bgp_maxmed_onstartup_configured(bgp)
10415 && bgp->maxmed_active)
10416 json_object_boolean_true_add(
60466a63 10417 json, "maxMedOnStartup");
ea47320b
DL
10418 if (bgp->v_maxmed_admin)
10419 json_object_boolean_true_add(
60466a63 10420 json, "maxMedAdministrative");
d62a17ae 10421
ea47320b
DL
10422 json_object_int_add(
10423 json, "tableVersion",
60466a63 10424 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 10425
60466a63
QY
10426 ents = bgp_table_count(bgp->rib[afi][safi]);
10427 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
10428 json_object_int_add(
10429 json, "ribMemory",
9bcb3eef 10430 ents * sizeof(struct bgp_dest));
d62a17ae 10431
210ec2a0 10432 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
10433 json_object_int_add(json, "peerCount", ents);
10434 json_object_int_add(json, "peerMemory",
10435 ents * sizeof(struct peer));
d62a17ae 10436
ea47320b
DL
10437 if ((ents = listcount(bgp->group))) {
10438 json_object_int_add(
60466a63 10439 json, "peerGroupCount", ents);
ea47320b
DL
10440 json_object_int_add(
10441 json, "peerGroupMemory",
996c9314
LB
10442 ents * sizeof(struct
10443 peer_group));
ea47320b 10444 }
d62a17ae 10445
ea47320b
DL
10446 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10447 BGP_CONFIG_DAMPENING))
10448 json_object_boolean_true_add(
60466a63 10449 json, "dampeningEnabled");
ea47320b 10450 } else {
96c81f66
LS
10451 if (!show_terse) {
10452 if (bgp_maxmed_onstartup_configured(bgp)
10453 && bgp->maxmed_active)
10454 vty_out(vty,
10455 "Max-med on-startup active\n");
10456 if (bgp->v_maxmed_admin)
10457 vty_out(vty,
10458 "Max-med administrative active\n");
d62a17ae 10459
96c81f66
LS
10460 vty_out(vty,
10461 "BGP table version %" PRIu64
10462 "\n",
10463 bgp_table_version(
10464 bgp->rib[afi][safi]));
ea47320b 10465
96c81f66
LS
10466 ents = bgp_table_count(
10467 bgp->rib[afi][safi]);
d62a17ae 10468 vty_out(vty,
96c81f66 10469 "RIB entries %ld, using %s of memory\n",
d62a17ae 10470 ents,
10471 mtype_memstr(
10472 memstrbuf,
10473 sizeof(memstrbuf),
96c81f66
LS
10474 ents
10475 * sizeof(
10476 struct
10477 bgp_dest)));
d62a17ae 10478
96c81f66
LS
10479 /* Peer related usage */
10480 ents = bgp->af_peer_count[afi][safi];
10481 vty_out(vty,
10482 "Peers %ld, using %s of memory\n",
10483 ents,
10484 mtype_memstr(
10485 memstrbuf,
10486 sizeof(memstrbuf),
10487 ents
10488 * sizeof(
10489 struct
10490 peer)));
d62a17ae 10491
96c81f66
LS
10492 if ((ents = listcount(bgp->group)))
10493 vty_out(vty,
10494 "Peer groups %ld, using %s of memory\n",
10495 ents,
10496 mtype_memstr(
10497 memstrbuf,
10498 sizeof(memstrbuf),
10499 ents
10500 * sizeof(
10501 struct
10502 peer_group)));
10503
10504 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10505 BGP_CONFIG_DAMPENING))
10506 vty_out(vty,
10507 "Dampening enabled.\n");
10508 }
10509 if (show_failed) {
10510 vty_out(vty, "\n");
10511
10512 /* Subtract 8 here because 'Neighbor' is
10513 * 8 characters */
10514 vty_out(vty, "Neighbor");
10515 vty_out(vty, "%*s",
10516 max_neighbor_width - 8, " ");
85eeb029
DA
10517 vty_out(vty,
10518 BGP_SHOW_SUMMARY_HEADER_FAILED);
96c81f66 10519 }
d62a17ae 10520 }
ea47320b 10521 }
d62a17ae 10522
d55811cc 10523 paf = peer_af_find(peer, afi, safi);
d3ada366 10524 filter = &peer->filter[afi][safi];
db92d226 10525
ea47320b 10526 count++;
3577f1c5
DD
10527 /* Works for both failed & successful cases */
10528 if (peer_dynamic_neighbor(peer))
10529 dn_count++;
d62a17ae 10530
ea47320b 10531 if (use_json) {
3577f1c5 10532 json_peer = NULL;
8c1d4cd5 10533 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
10534 as_type, as)) {
10535 filtered_count++;
8c1d4cd5 10536 continue;
ce1944f0 10537 }
3577f1c5
DD
10538 if (show_failed &&
10539 bgp_has_peer_failed(peer, afi, safi)) {
10540 json_peer = json_object_new_object();
10541 bgp_show_failed_summary(vty, bgp, peer,
10542 json_peer, 0, use_json);
10543 } else if (!show_failed) {
10b49f14 10544 if (show_established
ce1944f0
LS
10545 && bgp_has_peer_failed(peer, afi, safi)) {
10546 filtered_count++;
10b49f14 10547 continue;
ce1944f0 10548 }
10b49f14 10549
3577f1c5
DD
10550 json_peer = json_object_new_object();
10551 if (peer_dynamic_neighbor(peer)) {
10552 json_object_boolean_true_add(json_peer,
10553 "dynamicPeer");
10554 }
d62a17ae 10555
3577f1c5
DD
10556 if (peer->hostname)
10557 json_object_string_add(json_peer, "hostname",
10558 peer->hostname);
10559
10560 if (peer->domainname)
10561 json_object_string_add(json_peer, "domainname",
10562 peer->domainname);
10563
10564 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
10565 json_object_int_add(
10566 json_peer, "localAs",
10567 peer->change_local_as
10568 ? peer->change_local_as
10569 : peer->local_as);
3577f1c5
DD
10570 json_object_int_add(json_peer, "version", 4);
10571 json_object_int_add(json_peer, "msgRcvd",
10572 PEER_TOTAL_RX(peer));
10573 json_object_int_add(json_peer, "msgSent",
10574 PEER_TOTAL_TX(peer));
10575
43aa5965
QY
10576 atomic_size_t outq_count, inq_count;
10577 outq_count = atomic_load_explicit(
10578 &peer->obuf->count,
10579 memory_order_relaxed);
10580 inq_count = atomic_load_explicit(
10581 &peer->ibuf->count,
10582 memory_order_relaxed);
10583
3577f1c5
DD
10584 json_object_int_add(json_peer, "tableVersion",
10585 peer->version[afi][safi]);
10586 json_object_int_add(json_peer, "outq",
43aa5965
QY
10587 outq_count);
10588 json_object_int_add(json_peer, "inq",
10589 inq_count);
3577f1c5
DD
10590 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10591 use_json, json_peer);
10592
3577f1c5
DD
10593 json_object_int_add(json_peer, "pfxRcd",
10594 peer->pcount[afi][pfx_rcd_safi]);
10595
3577f1c5 10596 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
10597 json_object_int_add(
10598 json_peer, "pfxSnt",
10599 (PAF_SUBGRP(paf))->scount);
10600 else
10601 json_object_int_add(json_peer, "pfxSnt",
10602 0);
0e1f8ab5
DA
10603
10604 /* BGP FSM state */
cb9196e7 10605 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
10606 || CHECK_FLAG(peer->bgp->flags,
10607 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
10608 json_object_string_add(json_peer,
10609 "state",
3577f1c5
DD
10610 "Idle (Admin)");
10611 else if (peer->afc_recv[afi][safi])
10612 json_object_string_add(
0e1f8ab5
DA
10613 json_peer, "state",
10614 lookup_msg(bgp_status_msg,
10615 peer->status, NULL));
10616 else if (CHECK_FLAG(
10617 peer->sflags,
10618 PEER_STATUS_PREFIX_OVERFLOW))
10619 json_object_string_add(json_peer,
10620 "state",
3577f1c5
DD
10621 "Idle (PfxCt)");
10622 else
10623 json_object_string_add(
0e1f8ab5
DA
10624 json_peer, "state",
10625 lookup_msg(bgp_status_msg,
10626 peer->status, NULL));
10627
10628 /* BGP peer state */
10629 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10630 || CHECK_FLAG(peer->bgp->flags,
10631 BGP_FLAG_SHUTDOWN))
10632 json_object_string_add(json_peer,
10633 "peerState",
10634 "Admin");
10635 else if (CHECK_FLAG(
10636 peer->sflags,
10637 PEER_STATUS_PREFIX_OVERFLOW))
10638 json_object_string_add(json_peer,
10639 "peerState",
10640 "PfxCt");
10641 else if (CHECK_FLAG(peer->flags,
10642 PEER_FLAG_PASSIVE))
10643 json_object_string_add(json_peer,
10644 "peerState",
10645 "Passive");
10646 else if (CHECK_FLAG(peer->sflags,
10647 PEER_STATUS_NSF_WAIT))
10648 json_object_string_add(json_peer,
10649 "peerState",
10650 "NSF passive");
10651 else if (CHECK_FLAG(
10652 peer->bgp->flags,
10653 BGP_FLAG_EBGP_REQUIRES_POLICY)
10654 && (!bgp_inbound_policy_exists(peer,
10655 filter)
10656 || !bgp_outbound_policy_exists(
10657 peer, filter)))
10658 json_object_string_add(json_peer,
10659 "peerState",
10660 "Policy");
10661 else
10662 json_object_string_add(
10663 json_peer, "peerState", "OK");
10664
200116db
DD
10665 json_object_int_add(json_peer, "connectionsEstablished",
10666 peer->established);
10667 json_object_int_add(json_peer, "connectionsDropped",
10668 peer->dropped);
aa72bd7e
PG
10669 if (peer->desc)
10670 json_object_string_add(
10671 json_peer, "desc", peer->desc);
b4e9dcba 10672 }
3577f1c5
DD
10673 /* Avoid creating empty peer dicts in JSON */
10674 if (json_peer == NULL)
10675 continue;
ea47320b
DL
10676
10677 if (peer->conf_if)
60466a63 10678 json_object_string_add(json_peer, "idType",
ea47320b
DL
10679 "interface");
10680 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
10681 json_object_string_add(json_peer, "idType",
10682 "ipv4");
ea47320b 10683 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
10684 json_object_string_add(json_peer, "idType",
10685 "ipv6");
ea47320b
DL
10686 json_object_object_add(json_peers, peer->host,
10687 json_peer);
10688 } else {
8c1d4cd5 10689 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
10690 as_type, as)) {
10691 filtered_count++;
8c1d4cd5 10692 continue;
ce1944f0 10693 }
3577f1c5
DD
10694 if (show_failed &&
10695 bgp_has_peer_failed(peer, afi, safi)) {
10696 bgp_show_failed_summary(vty, bgp, peer, NULL,
10697 max_neighbor_width,
10698 use_json);
10699 } else if (!show_failed) {
10b49f14 10700 if (show_established
ce1944f0
LS
10701 && bgp_has_peer_failed(peer, afi, safi)) {
10702 filtered_count++;
10b49f14 10703 continue;
ce1944f0 10704 }
96c81f66
LS
10705
10706 if ((count - filtered_count) == 1) {
10707 /* display headline before the first
10708 * neighbor line */
10709 vty_out(vty, "\n");
10710
10711 /* Subtract 8 here because 'Neighbor' is
10712 * 8 characters */
10713 vty_out(vty, "Neighbor");
10714 vty_out(vty, "%*s",
10715 max_neighbor_width - 8, " ");
10716 vty_out(vty,
10717 show_wide
10718 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10719 : BGP_SHOW_SUMMARY_HEADER_ALL);
10720 }
10721
3577f1c5
DD
10722 memset(dn_flag, '\0', sizeof(dn_flag));
10723 if (peer_dynamic_neighbor(peer)) {
10724 dn_flag[0] = '*';
10725 }
d62a17ae 10726
3577f1c5 10727 if (peer->hostname
892fedb6
DA
10728 && CHECK_FLAG(bgp->flags,
10729 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 10730 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
10731 peer->hostname,
10732 peer->host);
d62a17ae 10733 else
3577f1c5
DD
10734 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10735
10736 /* pad the neighbor column with spaces */
10737 if (len < max_neighbor_width)
10738 vty_out(vty, "%*s", max_neighbor_width - len,
10739 " ");
10740
43aa5965
QY
10741 atomic_size_t outq_count, inq_count;
10742 outq_count = atomic_load_explicit(
10743 &peer->obuf->count,
10744 memory_order_relaxed);
10745 inq_count = atomic_load_explicit(
10746 &peer->ibuf->count,
10747 memory_order_relaxed);
10748
85eeb029
DA
10749 if (show_wide)
10750 vty_out(vty,
10751 "4 %10u %10u %9u %9u %8" PRIu64
10752 " %4zu %4zu %8s",
10753 peer->as,
10754 peer->change_local_as
10755 ? peer->change_local_as
10756 : peer->local_as,
10757 PEER_TOTAL_RX(peer),
10758 PEER_TOTAL_TX(peer),
10759 peer->version[afi][safi],
10760 inq_count, outq_count,
10761 peer_uptime(peer->uptime,
10762 timebuf,
10763 BGP_UPTIME_LEN, 0,
10764 NULL));
10765 else
10766 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
10767 " %4zu %4zu %8s",
10768 peer->as, PEER_TOTAL_RX(peer),
10769 PEER_TOTAL_TX(peer),
10770 peer->version[afi][safi],
10771 inq_count, outq_count,
10772 peer_uptime(peer->uptime,
10773 timebuf,
10774 BGP_UPTIME_LEN, 0,
10775 NULL));
3577f1c5 10776
feb17238 10777 if (peer_established(peer)) {
d3ada366
DA
10778 if (peer->afc_recv[afi][safi]) {
10779 if (CHECK_FLAG(
10780 bgp->flags,
10781 BGP_FLAG_EBGP_REQUIRES_POLICY)
10782 && !bgp_inbound_policy_exists(
10783 peer, filter))
10784 vty_out(vty, " %12s",
10785 "(Policy)");
10786 else
10787 vty_out(vty,
6cde4b45 10788 " %12u",
d3ada366
DA
10789 peer->pcount
10790 [afi]
10791 [pfx_rcd_safi]);
10792 } else {
749d0f27 10793 vty_out(vty, " NoNeg");
d3ada366 10794 }
db92d226 10795
d3ada366
DA
10796 if (paf && PAF_SUBGRP(paf)) {
10797 if (CHECK_FLAG(
10798 bgp->flags,
10799 BGP_FLAG_EBGP_REQUIRES_POLICY)
10800 && !bgp_outbound_policy_exists(
10801 peer, filter))
10802 vty_out(vty, " %8s",
10803 "(Policy)");
10804 else
10805 vty_out(vty,
6cde4b45 10806 " %8u",
d3ada366
DA
10807 (PAF_SUBGRP(
10808 paf))
10809 ->scount);
749d0f27
DA
10810 } else {
10811 vty_out(vty, " NoNeg");
d3ada366 10812 }
db92d226 10813 } else {
736b68f3
DS
10814 if (CHECK_FLAG(peer->flags,
10815 PEER_FLAG_SHUTDOWN)
10816 || CHECK_FLAG(peer->bgp->flags,
10817 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
10818 vty_out(vty, " Idle (Admin)");
10819 else if (CHECK_FLAG(
10820 peer->sflags,
10821 PEER_STATUS_PREFIX_OVERFLOW))
10822 vty_out(vty, " Idle (PfxCt)");
10823 else
10824 vty_out(vty, " %12s",
10825 lookup_msg(bgp_status_msg,
10826 peer->status, NULL));
db92d226 10827
6cde4b45 10828 vty_out(vty, " %8u", 0);
3577f1c5 10829 }
565e9ddd
DA
10830 /* Make sure `Desc` column is the lastest in
10831 * the output.
10832 */
aa72bd7e 10833 if (peer->desc)
cb75bb31
DA
10834 vty_out(vty, " %s",
10835 bgp_peer_description_stripped(
85eeb029
DA
10836 peer->desc,
10837 show_wide ? 64 : 20));
aa72bd7e
PG
10838 else
10839 vty_out(vty, " N/A");
3577f1c5 10840 vty_out(vty, "\n");
d62a17ae 10841 }
3577f1c5 10842
d62a17ae 10843 }
10844 }
f933309e 10845
d62a17ae 10846 if (use_json) {
10847 json_object_object_add(json, "peers", json_peers);
3577f1c5 10848 json_object_int_add(json, "failedPeers", failed_count);
ce1944f0
LS
10849 json_object_int_add(json, "displayedPeers",
10850 count - filtered_count);
d62a17ae 10851 json_object_int_add(json, "totalPeers", count);
10852 json_object_int_add(json, "dynamicPeers", dn_count);
10853
3577f1c5
DD
10854 if (!show_failed)
10855 bgp_show_bestpath_json(bgp, json);
57a9c8a8 10856
75eeda93 10857 vty_json(vty, json);
d62a17ae 10858 } else {
ce1944f0 10859 if (count) {
96c81f66
LS
10860 if (filtered_count == count)
10861 vty_out(vty, "\n%% No matching neighbor\n");
10862 else {
10863 if (show_failed)
10864 vty_out(vty, "\nDisplayed neighbors %d",
10865 failed_count);
10866 else if (as_type != AS_UNSPECIFIED || as
10867 || fpeer || show_established)
ce1944f0
LS
10868 vty_out(vty, "\nDisplayed neighbors %d",
10869 count - filtered_count);
96c81f66
LS
10870
10871 vty_out(vty, "\nTotal number of neighbors %d\n",
10872 count);
ce1944f0 10873 }
ce1944f0 10874 } else {
d6ceaca3 10875 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 10876 get_afi_safi_str(afi, safi, false));
d62a17ae 10877 }
b05a1c8b 10878
d6ceaca3 10879 if (dn_count) {
d62a17ae 10880 vty_out(vty, "* - dynamic neighbor\n");
10881 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
10882 dn_count, bgp->dynamic_neighbors_limit);
10883 }
10884 }
1ff9a340 10885
d62a17ae 10886 return CMD_SUCCESS;
718e3744 10887}
10888
d62a17ae 10889static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5 10890 int safi, struct peer *fpeer, int as_type,
96c81f66 10891 as_t as, uint16_t show_flags)
d62a17ae 10892{
10893 int is_first = 1;
10894 int afi_wildcard = (afi == AFI_MAX);
10895 int safi_wildcard = (safi == SAFI_MAX);
10896 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 10897 bool nbr_output = false;
85eeb029 10898 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 10899
10900 if (use_json && is_wildcard)
10901 vty_out(vty, "{\n");
10902 if (afi_wildcard)
10903 afi = 1; /* AFI_IP */
10904 while (afi < AFI_MAX) {
10905 if (safi_wildcard)
10906 safi = 1; /* SAFI_UNICAST */
10907 while (safi < SAFI_MAX) {
318cac96 10908 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 10909 nbr_output = true;
f86897b9 10910
d62a17ae 10911 if (is_wildcard) {
10912 /*
10913 * So limit output to those afi/safi
10914 * pairs that
10915 * actualy have something interesting in
10916 * them
10917 */
10918 if (use_json) {
d62a17ae 10919 if (!is_first)
10920 vty_out(vty, ",\n");
10921 else
10922 is_first = 0;
10923
10924 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
10925 get_afi_safi_str(afi,
10926 safi,
10927 true));
d62a17ae 10928 } else {
6cac2fcc
LS
10929 vty_out(vty,
10930 "\n%s Summary (%s):\n",
5cb5f4d0
DD
10931 get_afi_safi_str(afi,
10932 safi,
6cac2fcc
LS
10933 false),
10934 bgp->name_pretty);
d62a17ae 10935 }
10936 }
8c1d4cd5
LS
10937 bgp_show_summary(vty, bgp, afi, safi, fpeer,
10938 as_type, as, show_flags);
d62a17ae 10939 }
10940 safi++;
d62a17ae 10941 if (!safi_wildcard)
10942 safi = SAFI_MAX;
10943 }
10944 afi++;
ee851c8c 10945 if (!afi_wildcard)
d62a17ae 10946 afi = AFI_MAX;
10947 }
10948
10949 if (use_json && is_wildcard)
10950 vty_out(vty, "}\n");
ca61fd25
DS
10951 else if (!nbr_output) {
10952 if (use_json)
10953 vty_out(vty, "{}\n");
10954 else
6cac2fcc
LS
10955 vty_out(vty, "%% No BGP neighbors found in %s\n",
10956 bgp->name_pretty);
ca61fd25 10957 }
d62a17ae 10958}
10959
10960static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
10961 safi_t safi,
10962 const char *neighbor,
10963 int as_type, as_t as,
96c81f66 10964 uint16_t show_flags)
d62a17ae 10965{
10966 struct listnode *node, *nnode;
10967 struct bgp *bgp;
8c1d4cd5 10968 struct peer *fpeer = NULL;
d62a17ae 10969 int is_first = 1;
9f049418 10970 bool nbr_output = false;
85eeb029 10971 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 10972
10973 if (use_json)
10974 vty_out(vty, "{\n");
10975
10976 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 10977 nbr_output = true;
d62a17ae 10978 if (use_json) {
d62a17ae 10979 if (!is_first)
10980 vty_out(vty, ",\n");
10981 else
10982 is_first = 0;
10983
10984 vty_out(vty, "\"%s\":",
10985 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10986 ? VRF_DEFAULT_NAME
d62a17ae 10987 : bgp->name);
d62a17ae 10988 }
8c1d4cd5
LS
10989 if (neighbor) {
10990 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
10991 use_json);
10992 if (!fpeer)
10993 continue;
10994 }
10995 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
10996 as, show_flags);
d62a17ae 10997 }
10998
10999 if (use_json)
11000 vty_out(vty, "}\n");
9f049418
DS
11001 else if (!nbr_output)
11002 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11003}
11004
11005int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5 11006 safi_t safi, const char *neighbor, int as_type,
96c81f66 11007 as_t as, uint16_t show_flags)
d62a17ae 11008{
11009 struct bgp *bgp;
85eeb029 11010 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 11011 struct peer *fpeer = NULL;
d62a17ae 11012
11013 if (name) {
11014 if (strmatch(name, "all")) {
85eeb029 11015 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
11016 neighbor, as_type,
11017 as, show_flags);
d62a17ae 11018 return CMD_SUCCESS;
11019 } else {
11020 bgp = bgp_lookup_by_name(name);
11021
11022 if (!bgp) {
11023 if (use_json)
11024 vty_out(vty, "{}\n");
11025 else
11026 vty_out(vty,
ca61fd25 11027 "%% BGP instance not found\n");
d62a17ae 11028 return CMD_WARNING;
11029 }
11030
8c1d4cd5
LS
11031 if (neighbor) {
11032 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11033 use_json);
11034 if (!fpeer)
11035 return CMD_WARNING;
11036 }
11037 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11038 as_type, as, show_flags);
d62a17ae 11039 return CMD_SUCCESS;
11040 }
11041 }
11042
11043 bgp = bgp_get_default();
11044
8c1d4cd5
LS
11045 if (bgp) {
11046 if (neighbor) {
11047 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11048 use_json);
11049 if (!fpeer)
11050 return CMD_WARNING;
11051 }
11052 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11053 as, show_flags);
11054 } else {
ca61fd25
DS
11055 if (use_json)
11056 vty_out(vty, "{}\n");
11057 else
11058 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11059 return CMD_WARNING;
11060 }
d62a17ae 11061
11062 return CMD_SUCCESS;
4fb25c53
DW
11063}
11064
716b2d8a 11065/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
11066DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11067 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11068 " [" BGP_SAFI_WITH_LABEL_CMD_STR
96c81f66 11069 "]] [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
11070 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11071 BGP_SAFI_WITH_LABEL_HELP_STR
11072 "Display the entries for all address families\n"
11073 "Summary of BGP neighbor status\n"
11074 "Show only sessions in Established state\n"
11075 "Show only sessions not in Established state\n"
11076 "Show only the specified neighbor session\n"
11077 "Neighbor to display information about\n"
11078 "Neighbor to display information about\n"
11079 "Neighbor on BGP configured interface\n"
11080 "Show only the specified remote AS sessions\n"
11081 "AS number\n"
11082 "Internal (iBGP) AS sessions\n"
11083 "External (eBGP) AS sessions\n"
96c81f66 11084 "Shorten the information on BGP instances\n"
8c1d4cd5 11085 "Increase table width for longer output\n" JSON_STR)
718e3744 11086{
d62a17ae 11087 char *vrf = NULL;
11088 afi_t afi = AFI_MAX;
11089 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
11090 as_t as = 0; /* 0 means AS filter not set */
11091 int as_type = AS_UNSPECIFIED;
96c81f66 11092 uint16_t show_flags = 0;
d62a17ae 11093
11094 int idx = 0;
11095
11096 /* show [ip] bgp */
96f3485c 11097 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11098 afi = AFI_IP;
9a8bdf1c
PG
11099 /* [<vrf> VIEWVRFNAME] */
11100 if (argv_find(argv, argc, "vrf", &idx)) {
11101 vrf = argv[idx + 1]->arg;
11102 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11103 vrf = NULL;
11104 } else if (argv_find(argv, argc, "view", &idx))
11105 /* [<view> VIEWVRFNAME] */
11106 vrf = argv[idx + 1]->arg;
d62a17ae 11107 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11108 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11109 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11110 }
11111
3577f1c5 11112 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11113 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11114
10b49f14 11115 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11116 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11117
8c1d4cd5
LS
11118 if (argv_find(argv, argc, "remote-as", &idx)) {
11119 if (argv[idx + 1]->arg[0] == 'i')
11120 as_type = AS_INTERNAL;
11121 else if (argv[idx + 1]->arg[0] == 'e')
11122 as_type = AS_EXTERNAL;
11123 else
11124 as = (as_t)atoi(argv[idx + 1]->arg);
11125 }
11126
96c81f66
LS
11127 if (argv_find(argv, argc, "terse", &idx))
11128 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11129
85eeb029
DA
11130 if (argv_find(argv, argc, "wide", &idx))
11131 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11132
11133 if (argv_find(argv, argc, "json", &idx))
11134 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11135
8c1d4cd5
LS
11136 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11137 show_flags);
d62a17ae 11138}
11139
5cb5f4d0 11140const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11141{
5cb5f4d0
DD
11142 if (for_json)
11143 return get_afi_safi_json_str(afi, safi);
d62a17ae 11144 else
5cb5f4d0 11145 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11146}
11147
d62a17ae 11148
11149static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11150 afi_t afi, safi_t safi,
d7c0a89a
QY
11151 uint16_t adv_smcap, uint16_t adv_rmcap,
11152 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11153 bool use_json, json_object *json_pref)
d62a17ae 11154{
11155 /* Send-Mode */
11156 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11157 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11158 if (use_json) {
11159 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11160 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11161 json_object_string_add(json_pref, "sendMode",
11162 "advertisedAndReceived");
11163 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11164 json_object_string_add(json_pref, "sendMode",
11165 "advertised");
11166 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11167 json_object_string_add(json_pref, "sendMode",
11168 "received");
11169 } else {
11170 vty_out(vty, " Send-mode: ");
11171 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11172 vty_out(vty, "advertised");
11173 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11174 vty_out(vty, "%sreceived",
11175 CHECK_FLAG(p->af_cap[afi][safi],
11176 adv_smcap)
11177 ? ", "
11178 : "");
11179 vty_out(vty, "\n");
11180 }
11181 }
11182
11183 /* Receive-Mode */
11184 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11185 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11186 if (use_json) {
11187 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11188 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11189 json_object_string_add(json_pref, "recvMode",
11190 "advertisedAndReceived");
11191 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11192 json_object_string_add(json_pref, "recvMode",
11193 "advertised");
11194 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11195 json_object_string_add(json_pref, "recvMode",
11196 "received");
11197 } else {
11198 vty_out(vty, " Receive-mode: ");
11199 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11200 vty_out(vty, "advertised");
11201 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11202 vty_out(vty, "%sreceived",
11203 CHECK_FLAG(p->af_cap[afi][safi],
11204 adv_rmcap)
11205 ? ", "
11206 : "");
11207 vty_out(vty, "\n");
11208 }
11209 }
11210}
11211
13909c4f
DS
11212static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11213 struct peer *p,
11214 bool use_json,
11215 json_object *json)
2986cac2 11216{
08c2d52a 11217 bool rbit_status = false;
2986cac2 11218
11219 if (!use_json)
a53ca37b 11220 vty_out(vty, "\n R bit: ");
2986cac2 11221
13909c4f
DS
11222 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11223 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
feb17238 11224 && (peer_established(p))) {
2986cac2 11225
11226 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 11227 rbit_status = true;
2986cac2 11228 else
08c2d52a 11229 rbit_status = false;
2986cac2 11230 }
11231
11232 if (rbit_status) {
11233 if (use_json)
13909c4f 11234 json_object_boolean_true_add(json, "rBit");
2986cac2 11235 else
11236 vty_out(vty, "True\n");
11237 } else {
11238 if (use_json)
13909c4f 11239 json_object_boolean_false_add(json, "rBit");
2986cac2 11240 else
11241 vty_out(vty, "False\n");
11242 }
11243}
11244
13909c4f
DS
11245static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11246 struct peer *peer,
11247 bool use_json,
11248 json_object *json)
2986cac2 11249{
2bb5d39b 11250 const char *mode = "NotApplicable";
2986cac2 11251
11252 if (!use_json)
a53ca37b 11253 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11254
13909c4f 11255 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
feb17238 11256 && (peer_established(peer))) {
2986cac2 11257
13909c4f
DS
11258 if ((peer->nsf_af_count == 0)
11259 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11260
2986cac2 11261 mode = "Disable";
11262
13909c4f
DS
11263 } else if (peer->nsf_af_count == 0
11264 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11265
2986cac2 11266 mode = "Helper";
11267
13909c4f
DS
11268 } else if (peer->nsf_af_count != 0
11269 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11270
2986cac2 11271 mode = "Restart";
2986cac2 11272 }
11273 }
11274
11275 if (use_json) {
13909c4f 11276 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11277 } else
11278 vty_out(vty, mode, "\n");
11279}
11280
13909c4f
DS
11281static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11282 struct peer *p,
11283 bool use_json,
11284 json_object *json)
2986cac2 11285{
11286 const char *mode = "Invalid";
11287
11288 if (!use_json)
a53ca37b 11289 vty_out(vty, " Local GR Mode: ");
2986cac2 11290
11291 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11292 mode = "Helper";
11293 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11294 mode = "Restart";
11295 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11296 mode = "Disable";
2ba1fe69 11297 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11298 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11299 mode = "Helper*";
11300 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11301 mode = "Restart*";
11302 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11303 mode = "Disable*";
11304 else
11305 mode = "Invalid*";
2ba1fe69 11306 }
2986cac2 11307
11308 if (use_json) {
13909c4f 11309 json_object_string_add(json, "localGrMode", mode);
2986cac2 11310 } else {
11311 vty_out(vty, mode, "\n");
11312 }
11313}
11314
13909c4f
DS
11315static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11316 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11317{
2ba1fe69 11318 afi_t afi;
11319 safi_t safi;
2986cac2 11320 json_object *json_afi_safi = NULL;
11321 json_object *json_timer = NULL;
11322 json_object *json_endofrib_status = NULL;
9e3b51a7 11323 bool eor_flag = false;
2986cac2 11324
df8d723c
DA
11325 FOREACH_AFI_SAFI_NSF (afi, safi) {
11326 if (!peer->afc[afi][safi])
11327 continue;
2986cac2 11328
df8d723c
DA
11329 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11330 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11331 continue;
9e3b51a7 11332
df8d723c
DA
11333 if (use_json) {
11334 json_afi_safi = json_object_new_object();
11335 json_endofrib_status = json_object_new_object();
11336 json_timer = json_object_new_object();
11337 }
2986cac2 11338
df8d723c
DA
11339 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11340 eor_flag = true;
11341 else
11342 eor_flag = false;
2986cac2 11343
df8d723c
DA
11344 if (!use_json) {
11345 vty_out(vty, " %s:\n",
11346 get_afi_safi_str(afi, safi, false));
2986cac2 11347
df8d723c
DA
11348 vty_out(vty, " F bit: ");
11349 }
2986cac2 11350
df8d723c
DA
11351 if (peer->nsf[afi][safi] &&
11352 CHECK_FLAG(peer->af_cap[afi][safi],
11353 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11354
df8d723c
DA
11355 if (use_json) {
11356 json_object_boolean_true_add(json_afi_safi,
11357 "fBit");
11358 } else
11359 vty_out(vty, "True\n");
11360 } else {
11361 if (use_json)
11362 json_object_boolean_false_add(json_afi_safi,
11363 "fBit");
11364 else
11365 vty_out(vty, "False\n");
11366 }
2986cac2 11367
df8d723c
DA
11368 if (!use_json)
11369 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11370
df8d723c
DA
11371 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11372 PEER_STATUS_EOR_SEND)) {
11373 if (use_json) {
11374 json_object_boolean_true_add(
11375 json_endofrib_status, "endOfRibSend");
9e3b51a7 11376
df8d723c
DA
11377 PRINT_EOR_JSON(eor_flag);
11378 } else {
11379 vty_out(vty, "Yes\n");
11380 vty_out(vty,
11381 " End-of-RIB sent after update: ");
2986cac2 11382
df8d723c
DA
11383 PRINT_EOR(eor_flag);
11384 }
11385 } else {
11386 if (use_json) {
11387 json_object_boolean_false_add(
11388 json_endofrib_status, "endOfRibSend");
11389 json_object_boolean_false_add(
11390 json_endofrib_status,
11391 "endOfRibSentAfterUpdate");
13909c4f 11392 } else {
df8d723c
DA
11393 vty_out(vty, "No\n");
11394 vty_out(vty,
11395 " End-of-RIB sent after update: ");
11396 vty_out(vty, "No\n");
13909c4f 11397 }
df8d723c 11398 }
2986cac2 11399
df8d723c
DA
11400 if (!use_json)
11401 vty_out(vty, " End-of-RIB received: ");
a53ca37b 11402
df8d723c
DA
11403 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11404 PEER_STATUS_EOR_RECEIVED)) {
11405 if (use_json)
11406 json_object_boolean_true_add(
11407 json_endofrib_status, "endOfRibRecv");
11408 else
11409 vty_out(vty, "Yes\n");
11410 } else {
11411 if (use_json)
11412 json_object_boolean_false_add(
11413 json_endofrib_status, "endOfRibRecv");
11414 else
11415 vty_out(vty, "No\n");
11416 }
11417
11418 if (use_json) {
11419 json_object_int_add(json_timer, "stalePathTimer",
11420 peer->bgp->stalepath_time);
11421
11422 if (peer->t_gr_stale != NULL) {
11423 json_object_int_add(json_timer,
11424 "stalePathTimerRemaining",
11425 thread_timer_remain_second(
11426 peer->t_gr_stale));
a53ca37b
DA
11427 }
11428
df8d723c
DA
11429 /* Display Configured Selection
11430 * Deferral only when when
11431 * Gr mode is enabled.
11432 */
11433 if (CHECK_FLAG(peer->flags,
11434 PEER_FLAG_GRACEFUL_RESTART)) {
13909c4f 11435 json_object_int_add(json_timer,
df8d723c 11436 "selectionDeferralTimer",
13909c4f 11437 peer->bgp->stalepath_time);
df8d723c 11438 }
2986cac2 11439
df8d723c
DA
11440 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11441 NULL) {
2986cac2 11442
df8d723c
DA
11443 json_object_int_add(
11444 json_timer,
11445 "selectionDeferralTimerRemaining",
11446 thread_timer_remain_second(
11447 peer->bgp->gr_info[afi][safi]
11448 .t_select_deferral));
11449 }
11450 } else {
11451 vty_out(vty, " Timers:\n");
11452 vty_out(vty,
11453 " Configured Stale Path Time(sec): %u\n",
11454 peer->bgp->stalepath_time);
2986cac2 11455
df8d723c 11456 if (peer->t_gr_stale != NULL)
13909c4f 11457 vty_out(vty,
df8d723c
DA
11458 " Stale Path Remaining(sec): %ld\n",
11459 thread_timer_remain_second(
11460 peer->t_gr_stale));
11461 /* Display Configured Selection
11462 * Deferral only when when
11463 * Gr mode is enabled.
11464 */
11465 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11466 vty_out(vty,
11467 " Configured Selection Deferral Time(sec): %u\n",
11468 peer->bgp->select_defer_time);
2986cac2 11469
df8d723c
DA
11470 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11471 NULL)
11472 vty_out(vty,
11473 " Selection Deferral Time Remaining(sec): %ld\n",
11474 thread_timer_remain_second(
11475 peer->bgp->gr_info[afi][safi]
11476 .t_select_deferral));
11477 }
11478 if (use_json) {
11479 json_object_object_add(json_afi_safi, "endOfRibStatus",
11480 json_endofrib_status);
11481 json_object_object_add(json_afi_safi, "timers",
11482 json_timer);
11483 json_object_object_add(
11484 json, get_afi_safi_str(afi, safi, true),
11485 json_afi_safi);
2986cac2 11486 }
11487 }
11488}
11489
36235319
QY
11490static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11491 struct peer *p,
11492 bool use_json,
11493 json_object *json)
2986cac2 11494{
11495 if (use_json) {
11496 json_object *json_timer = NULL;
11497
11498 json_timer = json_object_new_object();
11499
13909c4f
DS
11500 json_object_int_add(json_timer, "configuredRestartTimer",
11501 p->bgp->restart_time);
2986cac2 11502
13909c4f
DS
11503 json_object_int_add(json_timer, "receivedRestartTimer",
11504 p->v_gr_restart);
2986cac2 11505
13909c4f
DS
11506 if (p->t_gr_restart != NULL)
11507 json_object_int_add(
11508 json_timer, "restartTimerRemaining",
11509 thread_timer_remain_second(p->t_gr_restart));
2986cac2 11510
11511 json_object_object_add(json, "timers", json_timer);
11512 } else {
11513
a53ca37b
DA
11514 vty_out(vty, " Timers:\n");
11515 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 11516 p->bgp->restart_time);
2986cac2 11517
a53ca37b 11518 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
11519 p->v_gr_restart);
11520 if (p->t_gr_restart != NULL)
a53ca37b 11521 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 11522 thread_timer_remain_second(p->t_gr_restart));
36235319 11523 if (p->t_gr_restart != NULL) {
a53ca37b 11524 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
11525 thread_timer_remain_second(p->t_gr_restart));
11526 }
2986cac2 11527 }
11528}
11529
11530static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 11531 bool use_json, json_object *json)
2986cac2 11532{
11533 char buf[SU_ADDRSTRLEN] = {0};
11534 char dn_flag[2] = {0};
2b7165e7
QY
11535 /* '*' + v6 address of neighbor */
11536 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 11537
2986cac2 11538 if (!p->conf_if && peer_dynamic_neighbor(p))
11539 dn_flag[0] = '*';
11540
11541 if (p->conf_if) {
11542 if (use_json)
13909c4f
DS
11543 json_object_string_add(
11544 json, "neighborAddr",
2986cac2 11545 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
11546 ? "none"
11547 : sockunion2str(&p->su, buf,
11548 SU_ADDRSTRLEN));
2986cac2 11549 else
13909c4f 11550 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 11551 BGP_PEER_SU_UNSPEC(p)
11552 ? "none"
11553 : sockunion2str(&p->su, buf,
11554 SU_ADDRSTRLEN));
11555 } else {
772270f3
QY
11556 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11557 p->host);
2986cac2 11558
11559 if (use_json)
36235319
QY
11560 json_object_string_add(json, "neighborAddr",
11561 neighborAddr);
2986cac2 11562 else
36235319 11563 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 11564 }
11565
11566 /* more gr info in new format */
11567 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11568}
11569
d62a17ae 11570static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 11571 safi_t safi, bool use_json,
d62a17ae 11572 json_object *json_neigh)
11573{
0291c246
MK
11574 struct bgp_filter *filter;
11575 struct peer_af *paf;
11576 char orf_pfx_name[BUFSIZ];
11577 int orf_pfx_count;
11578 json_object *json_af = NULL;
11579 json_object *json_prefA = NULL;
11580 json_object *json_prefB = NULL;
11581 json_object *json_addr = NULL;
fa36596c 11582 json_object *json_advmap = NULL;
d62a17ae 11583
11584 if (use_json) {
11585 json_addr = json_object_new_object();
11586 json_af = json_object_new_object();
11587 filter = &p->filter[afi][safi];
11588
11589 if (peer_group_active(p))
11590 json_object_string_add(json_addr, "peerGroupMember",
11591 p->group->name);
11592
11593 paf = peer_af_find(p, afi, safi);
11594 if (paf && PAF_SUBGRP(paf)) {
11595 json_object_int_add(json_addr, "updateGroupId",
11596 PAF_UPDGRP(paf)->id);
11597 json_object_int_add(json_addr, "subGroupId",
11598 PAF_SUBGRP(paf)->id);
11599 json_object_int_add(json_addr, "packetQueueLength",
11600 bpacket_queue_virtual_length(paf));
11601 }
11602
11603 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11604 || CHECK_FLAG(p->af_cap[afi][safi],
11605 PEER_CAP_ORF_PREFIX_SM_RCV)
11606 || CHECK_FLAG(p->af_cap[afi][safi],
11607 PEER_CAP_ORF_PREFIX_RM_ADV)
11608 || CHECK_FLAG(p->af_cap[afi][safi],
11609 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11610 json_object_int_add(json_af, "orfType",
11611 ORF_TYPE_PREFIX);
11612 json_prefA = json_object_new_object();
11613 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11614 PEER_CAP_ORF_PREFIX_SM_ADV,
11615 PEER_CAP_ORF_PREFIX_RM_ADV,
11616 PEER_CAP_ORF_PREFIX_SM_RCV,
11617 PEER_CAP_ORF_PREFIX_RM_RCV,
11618 use_json, json_prefA);
11619 json_object_object_add(json_af, "orfPrefixList",
11620 json_prefA);
11621 }
11622
11623 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11624 || CHECK_FLAG(p->af_cap[afi][safi],
11625 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11626 || CHECK_FLAG(p->af_cap[afi][safi],
11627 PEER_CAP_ORF_PREFIX_RM_ADV)
11628 || CHECK_FLAG(p->af_cap[afi][safi],
11629 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11630 json_object_int_add(json_af, "orfOldType",
11631 ORF_TYPE_PREFIX_OLD);
11632 json_prefB = json_object_new_object();
11633 bgp_show_peer_afi_orf_cap(
11634 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11635 PEER_CAP_ORF_PREFIX_RM_ADV,
11636 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11637 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11638 json_prefB);
11639 json_object_object_add(json_af, "orfOldPrefixList",
11640 json_prefB);
11641 }
11642
11643 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11644 || CHECK_FLAG(p->af_cap[afi][safi],
11645 PEER_CAP_ORF_PREFIX_SM_RCV)
11646 || CHECK_FLAG(p->af_cap[afi][safi],
11647 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11648 || CHECK_FLAG(p->af_cap[afi][safi],
11649 PEER_CAP_ORF_PREFIX_RM_ADV)
11650 || CHECK_FLAG(p->af_cap[afi][safi],
11651 PEER_CAP_ORF_PREFIX_RM_RCV)
11652 || CHECK_FLAG(p->af_cap[afi][safi],
11653 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11654 json_object_object_add(json_addr, "afDependentCap",
11655 json_af);
11656 else
11657 json_object_free(json_af);
11658
772270f3
QY
11659 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11660 p->host, afi, safi);
d62a17ae 11661 orf_pfx_count = prefix_bgp_show_prefix_list(
11662 NULL, afi, orf_pfx_name, use_json);
11663
11664 if (CHECK_FLAG(p->af_sflags[afi][safi],
11665 PEER_STATUS_ORF_PREFIX_SEND)
11666 || orf_pfx_count) {
11667 if (CHECK_FLAG(p->af_sflags[afi][safi],
11668 PEER_STATUS_ORF_PREFIX_SEND))
11669 json_object_boolean_true_add(json_neigh,
11670 "orfSent");
11671 if (orf_pfx_count)
11672 json_object_int_add(json_addr, "orfRecvCounter",
11673 orf_pfx_count);
11674 }
11675 if (CHECK_FLAG(p->af_sflags[afi][safi],
11676 PEER_STATUS_ORF_WAIT_REFRESH))
11677 json_object_string_add(
11678 json_addr, "orfFirstUpdate",
11679 "deferredUntilORFOrRouteRefreshRecvd");
11680
11681 if (CHECK_FLAG(p->af_flags[afi][safi],
11682 PEER_FLAG_REFLECTOR_CLIENT))
11683 json_object_boolean_true_add(json_addr,
11684 "routeReflectorClient");
11685 if (CHECK_FLAG(p->af_flags[afi][safi],
11686 PEER_FLAG_RSERVER_CLIENT))
11687 json_object_boolean_true_add(json_addr,
11688 "routeServerClient");
11689 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11690 json_object_boolean_true_add(json_addr,
11691 "inboundSoftConfigPermit");
11692
11693 if (CHECK_FLAG(p->af_flags[afi][safi],
11694 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11695 json_object_boolean_true_add(
11696 json_addr,
11697 "privateAsNumsAllReplacedInUpdatesToNbr");
11698 else if (CHECK_FLAG(p->af_flags[afi][safi],
11699 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11700 json_object_boolean_true_add(
11701 json_addr,
11702 "privateAsNumsReplacedInUpdatesToNbr");
11703 else if (CHECK_FLAG(p->af_flags[afi][safi],
11704 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11705 json_object_boolean_true_add(
11706 json_addr,
11707 "privateAsNumsAllRemovedInUpdatesToNbr");
11708 else if (CHECK_FLAG(p->af_flags[afi][safi],
11709 PEER_FLAG_REMOVE_PRIVATE_AS))
11710 json_object_boolean_true_add(
11711 json_addr,
11712 "privateAsNumsRemovedInUpdatesToNbr");
11713
dcc68b5e
MS
11714 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11715 json_object_boolean_true_add(
11716 json_addr,
11717 bgp_addpath_names(p->addpath_type[afi][safi])
11718 ->type_json_name);
d62a17ae 11719
11720 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11721 json_object_string_add(json_addr,
11722 "overrideASNsInOutboundUpdates",
11723 "ifAspathEqualRemoteAs");
11724
11725 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11726 || CHECK_FLAG(p->af_flags[afi][safi],
11727 PEER_FLAG_FORCE_NEXTHOP_SELF))
11728 json_object_boolean_true_add(json_addr,
11729 "routerAlwaysNextHop");
11730 if (CHECK_FLAG(p->af_flags[afi][safi],
11731 PEER_FLAG_AS_PATH_UNCHANGED))
11732 json_object_boolean_true_add(
11733 json_addr, "unchangedAsPathPropogatedToNbr");
11734 if (CHECK_FLAG(p->af_flags[afi][safi],
11735 PEER_FLAG_NEXTHOP_UNCHANGED))
11736 json_object_boolean_true_add(
11737 json_addr, "unchangedNextHopPropogatedToNbr");
11738 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11739 json_object_boolean_true_add(
11740 json_addr, "unchangedMedPropogatedToNbr");
11741 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11742 || CHECK_FLAG(p->af_flags[afi][safi],
11743 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11744 if (CHECK_FLAG(p->af_flags[afi][safi],
11745 PEER_FLAG_SEND_COMMUNITY)
11746 && CHECK_FLAG(p->af_flags[afi][safi],
11747 PEER_FLAG_SEND_EXT_COMMUNITY))
11748 json_object_string_add(json_addr,
11749 "commAttriSentToNbr",
11750 "extendedAndStandard");
11751 else if (CHECK_FLAG(p->af_flags[afi][safi],
11752 PEER_FLAG_SEND_EXT_COMMUNITY))
11753 json_object_string_add(json_addr,
11754 "commAttriSentToNbr",
11755 "extended");
11756 else
11757 json_object_string_add(json_addr,
11758 "commAttriSentToNbr",
11759 "standard");
11760 }
11761 if (CHECK_FLAG(p->af_flags[afi][safi],
11762 PEER_FLAG_DEFAULT_ORIGINATE)) {
11763 if (p->default_rmap[afi][safi].name)
11764 json_object_string_add(
11765 json_addr, "defaultRouteMap",
11766 p->default_rmap[afi][safi].name);
11767
11768 if (paf && PAF_SUBGRP(paf)
11769 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11770 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11771 json_object_boolean_true_add(json_addr,
11772 "defaultSent");
11773 else
11774 json_object_boolean_true_add(json_addr,
11775 "defaultNotSent");
11776 }
11777
dff8f48d 11778 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 11779 if (is_evpn_enabled())
60466a63
QY
11780 json_object_boolean_true_add(
11781 json_addr, "advertiseAllVnis");
dff8f48d
MK
11782 }
11783
d62a17ae 11784 if (filter->plist[FILTER_IN].name
11785 || filter->dlist[FILTER_IN].name
11786 || filter->aslist[FILTER_IN].name
11787 || filter->map[RMAP_IN].name)
11788 json_object_boolean_true_add(json_addr,
11789 "inboundPathPolicyConfig");
11790 if (filter->plist[FILTER_OUT].name
11791 || filter->dlist[FILTER_OUT].name
11792 || filter->aslist[FILTER_OUT].name
11793 || filter->map[RMAP_OUT].name || filter->usmap.name)
11794 json_object_boolean_true_add(
11795 json_addr, "outboundPathPolicyConfig");
11796
11797 /* prefix-list */
11798 if (filter->plist[FILTER_IN].name)
11799 json_object_string_add(json_addr,
11800 "incomingUpdatePrefixFilterList",
11801 filter->plist[FILTER_IN].name);
11802 if (filter->plist[FILTER_OUT].name)
11803 json_object_string_add(json_addr,
11804 "outgoingUpdatePrefixFilterList",
11805 filter->plist[FILTER_OUT].name);
11806
11807 /* distribute-list */
11808 if (filter->dlist[FILTER_IN].name)
11809 json_object_string_add(
11810 json_addr, "incomingUpdateNetworkFilterList",
11811 filter->dlist[FILTER_IN].name);
11812 if (filter->dlist[FILTER_OUT].name)
11813 json_object_string_add(
11814 json_addr, "outgoingUpdateNetworkFilterList",
11815 filter->dlist[FILTER_OUT].name);
11816
11817 /* filter-list. */
11818 if (filter->aslist[FILTER_IN].name)
11819 json_object_string_add(json_addr,
11820 "incomingUpdateAsPathFilterList",
11821 filter->aslist[FILTER_IN].name);
11822 if (filter->aslist[FILTER_OUT].name)
11823 json_object_string_add(json_addr,
11824 "outgoingUpdateAsPathFilterList",
11825 filter->aslist[FILTER_OUT].name);
11826
11827 /* route-map. */
11828 if (filter->map[RMAP_IN].name)
11829 json_object_string_add(
11830 json_addr, "routeMapForIncomingAdvertisements",
11831 filter->map[RMAP_IN].name);
11832 if (filter->map[RMAP_OUT].name)
11833 json_object_string_add(
11834 json_addr, "routeMapForOutgoingAdvertisements",
11835 filter->map[RMAP_OUT].name);
11836
9dac9fc8 11837 /* ebgp-requires-policy (inbound) */
1d3fdccf 11838 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11839 && !bgp_inbound_policy_exists(p, filter))
11840 json_object_string_add(
11841 json_addr, "inboundEbgpRequiresPolicy",
11842 "Inbound updates discarded due to missing policy");
11843
11844 /* ebgp-requires-policy (outbound) */
1d3fdccf 11845 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11846 && (!bgp_outbound_policy_exists(p, filter)))
11847 json_object_string_add(
11848 json_addr, "outboundEbgpRequiresPolicy",
11849 "Outbound updates discarded due to missing policy");
11850
d62a17ae 11851 /* unsuppress-map */
11852 if (filter->usmap.name)
11853 json_object_string_add(json_addr,
11854 "selectiveUnsuppressRouteMap",
11855 filter->usmap.name);
11856
fa36596c
MK
11857 /* advertise-map */
11858 if (filter->advmap.aname) {
11859 json_advmap = json_object_new_object();
11860 json_object_string_add(json_advmap, "condition",
11861 filter->advmap.condition
11862 ? "EXIST"
11863 : "NON_EXIST");
11864 json_object_string_add(json_advmap, "conditionMap",
11865 filter->advmap.cname);
11866 json_object_string_add(json_advmap, "advertiseMap",
11867 filter->advmap.aname);
11868 json_object_string_add(json_advmap, "advertiseStatus",
11869 filter->advmap.update_type
11870 == ADVERTISE
11871 ? "Advertise"
11872 : "Withdraw");
11873 json_object_object_add(json_addr, "advertiseMap",
11874 json_advmap);
11875 }
11876
d62a17ae 11877 /* Receive prefix count */
11878 json_object_int_add(json_addr, "acceptedPrefixCounter",
11879 p->pcount[afi][safi]);
50e05855
AD
11880 if (paf && PAF_SUBGRP(paf))
11881 json_object_int_add(json_addr, "sentPrefixCounter",
11882 (PAF_SUBGRP(paf))->scount);
d62a17ae 11883
fde246e8
DA
11884 /* Maximum prefix */
11885 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
11886 json_object_int_add(json_addr, "prefixOutAllowedMax",
11887 p->pmax_out[afi][safi]);
11888
d62a17ae 11889 /* Maximum prefix */
11890 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11891 json_object_int_add(json_addr, "prefixAllowedMax",
11892 p->pmax[afi][safi]);
11893 if (CHECK_FLAG(p->af_flags[afi][safi],
11894 PEER_FLAG_MAX_PREFIX_WARNING))
11895 json_object_boolean_true_add(
11896 json_addr, "prefixAllowedMaxWarning");
11897 json_object_int_add(json_addr,
11898 "prefixAllowedWarningThresh",
11899 p->pmax_threshold[afi][safi]);
11900 if (p->pmax_restart[afi][safi])
11901 json_object_int_add(
11902 json_addr,
11903 "prefixAllowedRestartIntervalMsecs",
11904 p->pmax_restart[afi][safi] * 60000);
11905 }
2986cac2 11906 json_object_object_add(json_neigh,
36235319 11907 get_afi_safi_str(afi, safi, true),
d62a17ae 11908 json_addr);
11909
11910 } else {
11911 filter = &p->filter[afi][safi];
11912
11913 vty_out(vty, " For address family: %s\n",
5cb5f4d0 11914 get_afi_safi_str(afi, safi, false));
d62a17ae 11915
11916 if (peer_group_active(p))
11917 vty_out(vty, " %s peer-group member\n",
11918 p->group->name);
11919
11920 paf = peer_af_find(p, afi, safi);
11921 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 11922 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 11923 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
11924 vty_out(vty, " Packet Queue length %d\n",
11925 bpacket_queue_virtual_length(paf));
11926 } else {
11927 vty_out(vty, " Not part of any update group\n");
11928 }
11929 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11930 || CHECK_FLAG(p->af_cap[afi][safi],
11931 PEER_CAP_ORF_PREFIX_SM_RCV)
11932 || CHECK_FLAG(p->af_cap[afi][safi],
11933 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11934 || CHECK_FLAG(p->af_cap[afi][safi],
11935 PEER_CAP_ORF_PREFIX_RM_ADV)
11936 || CHECK_FLAG(p->af_cap[afi][safi],
11937 PEER_CAP_ORF_PREFIX_RM_RCV)
11938 || CHECK_FLAG(p->af_cap[afi][safi],
11939 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11940 vty_out(vty, " AF-dependant capabilities:\n");
11941
11942 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11943 || CHECK_FLAG(p->af_cap[afi][safi],
11944 PEER_CAP_ORF_PREFIX_SM_RCV)
11945 || CHECK_FLAG(p->af_cap[afi][safi],
11946 PEER_CAP_ORF_PREFIX_RM_ADV)
11947 || CHECK_FLAG(p->af_cap[afi][safi],
11948 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11949 vty_out(vty,
11950 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11951 ORF_TYPE_PREFIX);
11952 bgp_show_peer_afi_orf_cap(
11953 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11954 PEER_CAP_ORF_PREFIX_RM_ADV,
11955 PEER_CAP_ORF_PREFIX_SM_RCV,
11956 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
11957 }
11958 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11959 || CHECK_FLAG(p->af_cap[afi][safi],
11960 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11961 || CHECK_FLAG(p->af_cap[afi][safi],
11962 PEER_CAP_ORF_PREFIX_RM_ADV)
11963 || CHECK_FLAG(p->af_cap[afi][safi],
11964 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11965 vty_out(vty,
11966 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11967 ORF_TYPE_PREFIX_OLD);
11968 bgp_show_peer_afi_orf_cap(
11969 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11970 PEER_CAP_ORF_PREFIX_RM_ADV,
11971 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11972 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
11973 }
11974
772270f3
QY
11975 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11976 p->host, afi, safi);
d62a17ae 11977 orf_pfx_count = prefix_bgp_show_prefix_list(
11978 NULL, afi, orf_pfx_name, use_json);
11979
11980 if (CHECK_FLAG(p->af_sflags[afi][safi],
11981 PEER_STATUS_ORF_PREFIX_SEND)
11982 || orf_pfx_count) {
11983 vty_out(vty, " Outbound Route Filter (ORF):");
11984 if (CHECK_FLAG(p->af_sflags[afi][safi],
11985 PEER_STATUS_ORF_PREFIX_SEND))
11986 vty_out(vty, " sent;");
11987 if (orf_pfx_count)
11988 vty_out(vty, " received (%d entries)",
11989 orf_pfx_count);
11990 vty_out(vty, "\n");
11991 }
11992 if (CHECK_FLAG(p->af_sflags[afi][safi],
11993 PEER_STATUS_ORF_WAIT_REFRESH))
11994 vty_out(vty,
11995 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
11996
11997 if (CHECK_FLAG(p->af_flags[afi][safi],
11998 PEER_FLAG_REFLECTOR_CLIENT))
11999 vty_out(vty, " Route-Reflector Client\n");
12000 if (CHECK_FLAG(p->af_flags[afi][safi],
12001 PEER_FLAG_RSERVER_CLIENT))
12002 vty_out(vty, " Route-Server Client\n");
12003 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12004 vty_out(vty,
12005 " Inbound soft reconfiguration allowed\n");
12006
12007 if (CHECK_FLAG(p->af_flags[afi][safi],
12008 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12009 vty_out(vty,
12010 " Private AS numbers (all) replaced in updates to this neighbor\n");
12011 else if (CHECK_FLAG(p->af_flags[afi][safi],
12012 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12013 vty_out(vty,
12014 " Private AS numbers replaced in updates to this neighbor\n");
12015 else if (CHECK_FLAG(p->af_flags[afi][safi],
12016 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12017 vty_out(vty,
12018 " Private AS numbers (all) removed in updates to this neighbor\n");
12019 else if (CHECK_FLAG(p->af_flags[afi][safi],
12020 PEER_FLAG_REMOVE_PRIVATE_AS))
12021 vty_out(vty,
12022 " Private AS numbers removed in updates to this neighbor\n");
12023
dcc68b5e
MS
12024 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12025 vty_out(vty, " %s\n",
12026 bgp_addpath_names(p->addpath_type[afi][safi])
12027 ->human_description);
d62a17ae 12028
12029 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12030 vty_out(vty,
12031 " Override ASNs in outbound updates if aspath equals remote-as\n");
12032
12033 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12034 || CHECK_FLAG(p->af_flags[afi][safi],
12035 PEER_FLAG_FORCE_NEXTHOP_SELF))
12036 vty_out(vty, " NEXT_HOP is always this router\n");
12037 if (CHECK_FLAG(p->af_flags[afi][safi],
12038 PEER_FLAG_AS_PATH_UNCHANGED))
12039 vty_out(vty,
12040 " AS_PATH is propagated unchanged to this neighbor\n");
12041 if (CHECK_FLAG(p->af_flags[afi][safi],
12042 PEER_FLAG_NEXTHOP_UNCHANGED))
12043 vty_out(vty,
12044 " NEXT_HOP is propagated unchanged to this neighbor\n");
12045 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12046 vty_out(vty,
12047 " MED is propagated unchanged to this neighbor\n");
12048 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12049 || CHECK_FLAG(p->af_flags[afi][safi],
12050 PEER_FLAG_SEND_EXT_COMMUNITY)
12051 || CHECK_FLAG(p->af_flags[afi][safi],
12052 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12053 vty_out(vty,
12054 " Community attribute sent to this neighbor");
12055 if (CHECK_FLAG(p->af_flags[afi][safi],
12056 PEER_FLAG_SEND_COMMUNITY)
12057 && CHECK_FLAG(p->af_flags[afi][safi],
12058 PEER_FLAG_SEND_EXT_COMMUNITY)
12059 && CHECK_FLAG(p->af_flags[afi][safi],
12060 PEER_FLAG_SEND_LARGE_COMMUNITY))
12061 vty_out(vty, "(all)\n");
12062 else if (CHECK_FLAG(p->af_flags[afi][safi],
12063 PEER_FLAG_SEND_LARGE_COMMUNITY))
12064 vty_out(vty, "(large)\n");
12065 else if (CHECK_FLAG(p->af_flags[afi][safi],
12066 PEER_FLAG_SEND_EXT_COMMUNITY))
12067 vty_out(vty, "(extended)\n");
12068 else
12069 vty_out(vty, "(standard)\n");
12070 }
12071 if (CHECK_FLAG(p->af_flags[afi][safi],
12072 PEER_FLAG_DEFAULT_ORIGINATE)) {
12073 vty_out(vty, " Default information originate,");
12074
12075 if (p->default_rmap[afi][safi].name)
12076 vty_out(vty, " default route-map %s%s,",
12077 p->default_rmap[afi][safi].map ? "*"
12078 : "",
12079 p->default_rmap[afi][safi].name);
12080 if (paf && PAF_SUBGRP(paf)
12081 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12082 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12083 vty_out(vty, " default sent\n");
12084 else
12085 vty_out(vty, " default not sent\n");
12086 }
12087
dff8f48d
MK
12088 /* advertise-vni-all */
12089 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12090 if (is_evpn_enabled())
dff8f48d
MK
12091 vty_out(vty, " advertise-all-vni\n");
12092 }
12093
d62a17ae 12094 if (filter->plist[FILTER_IN].name
12095 || filter->dlist[FILTER_IN].name
12096 || filter->aslist[FILTER_IN].name
12097 || filter->map[RMAP_IN].name)
12098 vty_out(vty, " Inbound path policy configured\n");
12099 if (filter->plist[FILTER_OUT].name
12100 || filter->dlist[FILTER_OUT].name
12101 || filter->aslist[FILTER_OUT].name
12102 || filter->map[RMAP_OUT].name || filter->usmap.name)
12103 vty_out(vty, " Outbound path policy configured\n");
12104
12105 /* prefix-list */
12106 if (filter->plist[FILTER_IN].name)
12107 vty_out(vty,
12108 " Incoming update prefix filter list is %s%s\n",
12109 filter->plist[FILTER_IN].plist ? "*" : "",
12110 filter->plist[FILTER_IN].name);
12111 if (filter->plist[FILTER_OUT].name)
12112 vty_out(vty,
12113 " Outgoing update prefix filter list is %s%s\n",
12114 filter->plist[FILTER_OUT].plist ? "*" : "",
12115 filter->plist[FILTER_OUT].name);
12116
12117 /* distribute-list */
12118 if (filter->dlist[FILTER_IN].name)
12119 vty_out(vty,
12120 " Incoming update network filter list is %s%s\n",
12121 filter->dlist[FILTER_IN].alist ? "*" : "",
12122 filter->dlist[FILTER_IN].name);
12123 if (filter->dlist[FILTER_OUT].name)
12124 vty_out(vty,
12125 " Outgoing update network filter list is %s%s\n",
12126 filter->dlist[FILTER_OUT].alist ? "*" : "",
12127 filter->dlist[FILTER_OUT].name);
12128
12129 /* filter-list. */
12130 if (filter->aslist[FILTER_IN].name)
12131 vty_out(vty,
12132 " Incoming update AS path filter list is %s%s\n",
12133 filter->aslist[FILTER_IN].aslist ? "*" : "",
12134 filter->aslist[FILTER_IN].name);
12135 if (filter->aslist[FILTER_OUT].name)
12136 vty_out(vty,
12137 " Outgoing update AS path filter list is %s%s\n",
12138 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12139 filter->aslist[FILTER_OUT].name);
12140
12141 /* route-map. */
12142 if (filter->map[RMAP_IN].name)
12143 vty_out(vty,
12144 " Route map for incoming advertisements is %s%s\n",
12145 filter->map[RMAP_IN].map ? "*" : "",
12146 filter->map[RMAP_IN].name);
12147 if (filter->map[RMAP_OUT].name)
12148 vty_out(vty,
12149 " Route map for outgoing advertisements is %s%s\n",
12150 filter->map[RMAP_OUT].map ? "*" : "",
12151 filter->map[RMAP_OUT].name);
12152
9dac9fc8 12153 /* ebgp-requires-policy (inbound) */
1d3fdccf 12154 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12155 && !bgp_inbound_policy_exists(p, filter))
12156 vty_out(vty,
12157 " Inbound updates discarded due to missing policy\n");
12158
12159 /* ebgp-requires-policy (outbound) */
1d3fdccf 12160 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12161 && !bgp_outbound_policy_exists(p, filter))
12162 vty_out(vty,
12163 " Outbound updates discarded due to missing policy\n");
12164
d62a17ae 12165 /* unsuppress-map */
12166 if (filter->usmap.name)
12167 vty_out(vty,
12168 " Route map for selective unsuppress is %s%s\n",
12169 filter->usmap.map ? "*" : "",
12170 filter->usmap.name);
12171
7f7940e6
MK
12172 /* advertise-map */
12173 if (filter->advmap.aname && filter->advmap.cname)
12174 vty_out(vty,
12175 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12176 filter->advmap.condition ? "EXIST"
12177 : "NON_EXIST",
12178 filter->advmap.cmap ? "*" : "",
12179 filter->advmap.cname,
12180 filter->advmap.amap ? "*" : "",
12181 filter->advmap.aname,
fa36596c 12182 filter->advmap.update_type == ADVERTISE
c385f82a
MK
12183 ? "Advertise"
12184 : "Withdraw");
7f7940e6 12185
d62a17ae 12186 /* Receive prefix count */
6cde4b45 12187 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12188 p->pcount[afi][safi]);
d62a17ae 12189
fde246e8
DA
12190 /* maximum-prefix-out */
12191 if (CHECK_FLAG(p->af_flags[afi][safi],
12192 PEER_FLAG_MAX_PREFIX_OUT))
12193 vty_out(vty,
6cde4b45 12194 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12195 p->pmax_out[afi][safi]);
12196
d62a17ae 12197 /* Maximum prefix */
12198 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12199 vty_out(vty,
6cde4b45 12200 " Maximum prefixes allowed %u%s\n",
d62a17ae 12201 p->pmax[afi][safi],
12202 CHECK_FLAG(p->af_flags[afi][safi],
12203 PEER_FLAG_MAX_PREFIX_WARNING)
12204 ? " (warning-only)"
12205 : "");
12206 vty_out(vty, " Threshold for warning message %d%%",
12207 p->pmax_threshold[afi][safi]);
12208 if (p->pmax_restart[afi][safi])
12209 vty_out(vty, ", restart interval %d min",
12210 p->pmax_restart[afi][safi]);
12211 vty_out(vty, "\n");
12212 }
12213
12214 vty_out(vty, "\n");
12215 }
12216}
12217
9f049418 12218static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12219 json_object *json)
718e3744 12220{
d62a17ae 12221 struct bgp *bgp;
12222 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12223 char timebuf[BGP_UPTIME_LEN];
12224 char dn_flag[2];
d62a17ae 12225 afi_t afi;
12226 safi_t safi;
d7c0a89a
QY
12227 uint16_t i;
12228 uint8_t *msg;
d62a17ae 12229 json_object *json_neigh = NULL;
12230 time_t epoch_tbuf;
4ab46701 12231 uint32_t sync_tcp_mss;
718e3744 12232
d62a17ae 12233 bgp = p->bgp;
12234
12235 if (use_json)
12236 json_neigh = json_object_new_object();
12237
12238 memset(dn_flag, '\0', sizeof(dn_flag));
12239 if (!p->conf_if && peer_dynamic_neighbor(p))
12240 dn_flag[0] = '*';
12241
12242 if (!use_json) {
12243 if (p->conf_if) /* Configured interface name. */
12244 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12245 BGP_PEER_SU_UNSPEC(p)
12246 ? "None"
12247 : sockunion2str(&p->su, buf,
12248 SU_ADDRSTRLEN));
12249 else /* Configured IP address. */
12250 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12251 p->host);
12252 }
12253
12254 if (use_json) {
12255 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12256 json_object_string_add(json_neigh, "bgpNeighborAddr",
12257 "none");
12258 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12259 json_object_string_add(
12260 json_neigh, "bgpNeighborAddr",
12261 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12262
12263 json_object_int_add(json_neigh, "remoteAs", p->as);
12264
12265 if (p->change_local_as)
12266 json_object_int_add(json_neigh, "localAs",
12267 p->change_local_as);
12268 else
12269 json_object_int_add(json_neigh, "localAs", p->local_as);
12270
12271 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12272 json_object_boolean_true_add(json_neigh,
12273 "localAsNoPrepend");
12274
12275 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12276 json_object_boolean_true_add(json_neigh,
12277 "localAsReplaceAs");
12278 } else {
12279 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12280 || (p->as_type == AS_INTERNAL))
12281 vty_out(vty, "remote AS %u, ", p->as);
12282 else
12283 vty_out(vty, "remote AS Unspecified, ");
12284 vty_out(vty, "local AS %u%s%s, ",
12285 p->change_local_as ? p->change_local_as : p->local_as,
12286 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12287 ? " no-prepend"
12288 : "",
12289 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12290 ? " replace-as"
12291 : "");
12292 }
faa16034
DS
12293 /* peer type internal or confed-internal */
12294 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12295 if (use_json) {
12296 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12297 json_object_boolean_true_add(
12298 json_neigh, "nbrConfedInternalLink");
12299 else
12300 json_object_boolean_true_add(json_neigh,
12301 "nbrInternalLink");
12302 } else {
12303 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12304 vty_out(vty, "confed-internal link\n");
12305 else
12306 vty_out(vty, "internal link\n");
12307 }
faa16034
DS
12308 /* peer type external or confed-external */
12309 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12310 if (use_json) {
12311 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12312 json_object_boolean_true_add(
12313 json_neigh, "nbrConfedExternalLink");
12314 else
12315 json_object_boolean_true_add(json_neigh,
12316 "nbrExternalLink");
12317 } else {
12318 if (bgp_confederation_peers_check(bgp, p->as))
12319 vty_out(vty, "confed-external link\n");
12320 else
12321 vty_out(vty, "external link\n");
12322 }
faa16034
DS
12323 } else {
12324 if (use_json)
12325 json_object_boolean_true_add(json_neigh,
12326 "nbrUnspecifiedLink");
12327 else
12328 vty_out(vty, "unspecified link\n");
d62a17ae 12329 }
12330
12331 /* Description. */
12332 if (p->desc) {
12333 if (use_json)
12334 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12335 else
12336 vty_out(vty, " Description: %s\n", p->desc);
12337 }
12338
12339 if (p->hostname) {
12340 if (use_json) {
12341 if (p->hostname)
12342 json_object_string_add(json_neigh, "hostname",
12343 p->hostname);
12344
12345 if (p->domainname)
12346 json_object_string_add(json_neigh, "domainname",
12347 p->domainname);
12348 } else {
12349 if (p->domainname && (p->domainname[0] != '\0'))
12350 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12351 p->domainname);
12352 else
12353 vty_out(vty, "Hostname: %s\n", p->hostname);
12354 }
12355 }
12356
12357 /* Peer-group */
12358 if (p->group) {
12359 if (use_json) {
12360 json_object_string_add(json_neigh, "peerGroup",
12361 p->group->name);
12362
12363 if (dn_flag[0]) {
12364 struct prefix prefix, *range = NULL;
12365
0154d8ce
DS
12366 if (sockunion2hostprefix(&(p->su), &prefix))
12367 range = peer_group_lookup_dynamic_neighbor_range(
12368 p->group, &prefix);
d62a17ae 12369
12370 if (range) {
67d7e256 12371 json_object_string_addf(
d62a17ae 12372 json_neigh,
67d7e256
DA
12373 "peerSubnetRangeGroup", "%pFX",
12374 range);
d62a17ae 12375 }
12376 }
12377 } else {
12378 vty_out(vty,
12379 " Member of peer-group %s for session parameters\n",
12380 p->group->name);
12381
12382 if (dn_flag[0]) {
12383 struct prefix prefix, *range = NULL;
12384
0154d8ce
DS
12385 if (sockunion2hostprefix(&(p->su), &prefix))
12386 range = peer_group_lookup_dynamic_neighbor_range(
12387 p->group, &prefix);
d62a17ae 12388
12389 if (range) {
d62a17ae 12390 vty_out(vty,
1b78780b
DL
12391 " Belongs to the subnet range group: %pFX\n",
12392 range);
d62a17ae 12393 }
12394 }
12395 }
12396 }
12397
12398 if (use_json) {
12399 /* Administrative shutdown. */
cb9196e7
DS
12400 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12401 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12402 json_object_boolean_true_add(json_neigh,
12403 "adminShutDown");
12404
12405 /* BGP Version. */
12406 json_object_int_add(json_neigh, "bgpVersion", 4);
c949c771
DA
12407 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12408 &p->remote_id);
12409 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12410 &bgp->router_id);
d62a17ae 12411
12412 /* Confederation */
12413 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12414 && bgp_confederation_peers_check(bgp, p->as))
12415 json_object_boolean_true_add(json_neigh,
12416 "nbrCommonAdmin");
12417
12418 /* Status. */
12419 json_object_string_add(
12420 json_neigh, "bgpState",
12421 lookup_msg(bgp_status_msg, p->status, NULL));
12422
feb17238 12423 if (peer_established(p)) {
d62a17ae 12424 time_t uptime;
d62a17ae 12425
12426 uptime = bgp_clock();
12427 uptime -= p->uptime;
d62a17ae 12428 epoch_tbuf = time(NULL) - uptime;
12429
d3c7efed
DS
12430 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12431 uptime * 1000);
d62a17ae 12432 json_object_string_add(json_neigh, "bgpTimerUpString",
12433 peer_uptime(p->uptime, timebuf,
12434 BGP_UPTIME_LEN, 0,
12435 NULL));
12436 json_object_int_add(json_neigh,
12437 "bgpTimerUpEstablishedEpoch",
12438 epoch_tbuf);
12439 }
12440
12441 else if (p->status == Active) {
12442 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12443 json_object_string_add(json_neigh, "bgpStateIs",
12444 "passive");
12445 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12446 json_object_string_add(json_neigh, "bgpStateIs",
12447 "passiveNSF");
12448 }
12449
12450 /* read timer */
12451 time_t uptime;
a2700b50 12452 struct tm tm;
d62a17ae 12453
12454 uptime = bgp_clock();
12455 uptime -= p->readtime;
a2700b50
MS
12456 gmtime_r(&uptime, &tm);
12457
d62a17ae 12458 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
12459 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12460 + (tm.tm_hour * 3600000));
d62a17ae 12461
12462 uptime = bgp_clock();
12463 uptime -= p->last_write;
a2700b50
MS
12464 gmtime_r(&uptime, &tm);
12465
d62a17ae 12466 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
12467 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12468 + (tm.tm_hour * 3600000));
d62a17ae 12469
12470 uptime = bgp_clock();
12471 uptime -= p->update_time;
a2700b50
MS
12472 gmtime_r(&uptime, &tm);
12473
d62a17ae 12474 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
12475 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12476 + (tm.tm_hour * 3600000));
d62a17ae 12477
12478 /* Configured timer values. */
12479 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12480 p->v_holdtime * 1000);
12481 json_object_int_add(json_neigh,
12482 "bgpTimerKeepAliveIntervalMsecs",
12483 p->v_keepalive * 1000);
d43114f3
DS
12484 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12485 json_object_int_add(json_neigh,
12486 "bgpTimerDelayOpenTimeMsecs",
12487 p->v_delayopen * 1000);
12488 }
12489
4ab46701
AR
12490 /* Configured and Synced tcp-mss value for peer */
12491 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12492 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12493 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12494 p->tcp_mss);
12495 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12496 sync_tcp_mss);
12497 }
12498
b90a8e13 12499 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12500 json_object_int_add(json_neigh,
12501 "bgpTimerConfiguredHoldTimeMsecs",
12502 p->holdtime * 1000);
12503 json_object_int_add(
12504 json_neigh,
12505 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12506 p->keepalive * 1000);
5d5393b9
DL
12507 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12508 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12509 json_object_int_add(json_neigh,
12510 "bgpTimerConfiguredHoldTimeMsecs",
12511 bgp->default_holdtime);
12512 json_object_int_add(
12513 json_neigh,
12514 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12515 bgp->default_keepalive);
d62a17ae 12516 }
d08c0c80
DA
12517
12518 /* Extended Optional Parameters Length for BGP OPEN Message */
12519 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12520 json_object_boolean_true_add(
12521 json_neigh, "extendedOptionalParametersLength");
12522 else
12523 json_object_boolean_false_add(
12524 json_neigh, "extendedOptionalParametersLength");
d62a17ae 12525 } else {
12526 /* Administrative shutdown. */
cb9196e7
DS
12527 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12528 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12529 vty_out(vty, " Administratively shut down\n");
12530
12531 /* BGP Version. */
12532 vty_out(vty, " BGP version 4");
0e38aeb4 12533 vty_out(vty, ", remote router ID %s",
d62a17ae 12534 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
12535 vty_out(vty, ", local router ID %s\n",
12536 inet_ntop(AF_INET, &bgp->router_id, buf1,
12537 sizeof(buf1)));
d62a17ae 12538
12539 /* Confederation */
12540 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12541 && bgp_confederation_peers_check(bgp, p->as))
12542 vty_out(vty,
12543 " Neighbor under common administration\n");
12544
12545 /* Status. */
12546 vty_out(vty, " BGP state = %s",
12547 lookup_msg(bgp_status_msg, p->status, NULL));
12548
feb17238 12549 if (peer_established(p))
d62a17ae 12550 vty_out(vty, ", up for %8s",
12551 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12552 0, NULL));
12553
12554 else if (p->status == Active) {
12555 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12556 vty_out(vty, " (passive)");
12557 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12558 vty_out(vty, " (NSF passive)");
12559 }
12560 vty_out(vty, "\n");
12561
12562 /* read timer */
12563 vty_out(vty, " Last read %s",
12564 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12565 NULL));
12566 vty_out(vty, ", Last write %s\n",
12567 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12568 NULL));
12569
12570 /* Configured timer values. */
12571 vty_out(vty,
12572 " Hold time is %d, keepalive interval is %d seconds\n",
12573 p->v_holdtime, p->v_keepalive);
b90a8e13 12574 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12575 vty_out(vty, " Configured hold time is %d",
12576 p->holdtime);
12577 vty_out(vty, ", keepalive interval is %d seconds\n",
12578 p->keepalive);
5d5393b9
DL
12579 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12580 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12581 vty_out(vty, " Configured hold time is %d",
12582 bgp->default_holdtime);
12583 vty_out(vty, ", keepalive interval is %d seconds\n",
12584 bgp->default_keepalive);
d62a17ae 12585 }
d43114f3
DS
12586 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12587 vty_out(vty,
12588 " Configured DelayOpenTime is %d seconds\n",
12589 p->delayopen);
4ab46701
AR
12590
12591 /* Configured and synced tcp-mss value for peer */
12592 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12593 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12594 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12595 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12596 }
d08c0c80
DA
12597
12598 /* Extended Optional Parameters Length for BGP OPEN Message */
12599 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12600 vty_out(vty,
12601 " Extended Optional Parameters Length is enabled\n");
d62a17ae 12602 }
12603 /* Capability. */
10711563
DA
12604 if (peer_established(p) &&
12605 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
12606 if (use_json) {
12607 json_object *json_cap = NULL;
d62a17ae 12608
10711563 12609 json_cap = json_object_new_object();
d62a17ae 12610
10711563
DA
12611 /* AS4 */
12612 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
12613 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12614 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
12615 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
ef56aee4 12616 json_object_string_add(
10711563 12617 json_cap, "4byteAs",
ef56aee4 12618 "advertisedAndReceived");
10711563
DA
12619 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
12620 json_object_string_add(json_cap,
12621 "4byteAs",
12622 "advertised");
12623 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12624 json_object_string_add(json_cap,
12625 "4byteAs",
12626 "received");
12627 }
ef56aee4 12628
10711563
DA
12629 /* Extended Message Support */
12630 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
12631 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
12632 json_object_string_add(json_cap,
12633 "extendedMessage",
12634 "advertisedAndReceived");
12635 else if (CHECK_FLAG(p->cap,
12636 PEER_CAP_EXTENDED_MESSAGE_ADV))
12637 json_object_string_add(json_cap,
12638 "extendedMessage",
12639 "advertised");
12640 else if (CHECK_FLAG(p->cap,
12641 PEER_CAP_EXTENDED_MESSAGE_RCV))
12642 json_object_string_add(json_cap,
12643 "extendedMessage",
12644 "received");
ef56aee4 12645
10711563
DA
12646 /* AddPath */
12647 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
12648 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
12649 json_object *json_add = NULL;
12650 const char *print_store;
d62a17ae 12651
10711563 12652 json_add = json_object_new_object();
d62a17ae 12653
10711563
DA
12654 FOREACH_AFI_SAFI (afi, safi) {
12655 json_object *json_sub = NULL;
12656 json_sub = json_object_new_object();
12657 print_store = get_afi_safi_str(
12658 afi, safi, true);
d62a17ae 12659
10711563
DA
12660 if (CHECK_FLAG(
12661 p->af_cap[afi][safi],
12662 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12663 CHECK_FLAG(
12664 p->af_cap[afi][safi],
12665 PEER_CAP_ADDPATH_AF_TX_RCV)) {
05c7a1cc
QY
12666 if (CHECK_FLAG(
12667 p->af_cap[afi]
12668 [safi],
10711563
DA
12669 PEER_CAP_ADDPATH_AF_TX_ADV) &&
12670 CHECK_FLAG(
05c7a1cc
QY
12671 p->af_cap[afi]
12672 [safi],
10711563
DA
12673 PEER_CAP_ADDPATH_AF_TX_RCV))
12674 json_object_boolean_true_add(
12675 json_sub,
12676 "txAdvertisedAndReceived");
12677 else if (
12678 CHECK_FLAG(
12679 p->af_cap[afi]
12680 [safi],
12681 PEER_CAP_ADDPATH_AF_TX_ADV))
12682 json_object_boolean_true_add(
12683 json_sub,
12684 "txAdvertised");
12685 else if (
12686 CHECK_FLAG(
12687 p->af_cap[afi]
12688 [safi],
12689 PEER_CAP_ADDPATH_AF_TX_RCV))
12690 json_object_boolean_true_add(
12691 json_sub,
12692 "txReceived");
12693 }
d62a17ae 12694
10711563
DA
12695 if (CHECK_FLAG(
12696 p->af_cap[afi][safi],
12697 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12698 CHECK_FLAG(
12699 p->af_cap[afi][safi],
12700 PEER_CAP_ADDPATH_AF_RX_RCV)) {
05c7a1cc
QY
12701 if (CHECK_FLAG(
12702 p->af_cap[afi]
12703 [safi],
10711563
DA
12704 PEER_CAP_ADDPATH_AF_RX_ADV) &&
12705 CHECK_FLAG(
12706 p->af_cap[afi]
12707 [safi],
12708 PEER_CAP_ADDPATH_AF_RX_RCV))
12709 json_object_boolean_true_add(
12710 json_sub,
12711 "rxAdvertisedAndReceived");
12712 else if (
12713 CHECK_FLAG(
12714 p->af_cap[afi]
12715 [safi],
12716 PEER_CAP_ADDPATH_AF_RX_ADV))
12717 json_object_boolean_true_add(
12718 json_sub,
12719 "rxAdvertised");
12720 else if (
12721 CHECK_FLAG(
12722 p->af_cap[afi]
12723 [safi],
12724 PEER_CAP_ADDPATH_AF_RX_RCV))
12725 json_object_boolean_true_add(
12726 json_sub,
12727 "rxReceived");
05c7a1cc
QY
12728 }
12729
10711563
DA
12730 if (CHECK_FLAG(
12731 p->af_cap[afi][safi],
12732 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12733 CHECK_FLAG(
12734 p->af_cap[afi][safi],
12735 PEER_CAP_ADDPATH_AF_TX_RCV) ||
12736 CHECK_FLAG(
12737 p->af_cap[afi][safi],
12738 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12739 CHECK_FLAG(
12740 p->af_cap[afi][safi],
12741 PEER_CAP_ADDPATH_AF_RX_RCV))
12742 json_object_object_add(
12743 json_add, print_store,
12744 json_sub);
12745 else
12746 json_object_free(json_sub);
d62a17ae 12747 }
12748
10711563
DA
12749 json_object_object_add(json_cap, "addPath",
12750 json_add);
12751 }
d62a17ae 12752
10711563
DA
12753 /* Dynamic */
12754 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
12755 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
12756 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
12757 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
12758 json_object_string_add(
12759 json_cap, "dynamic",
12760 "advertisedAndReceived");
12761 else if (CHECK_FLAG(p->cap,
12762 PEER_CAP_DYNAMIC_ADV))
12763 json_object_string_add(json_cap,
12764 "dynamic",
12765 "advertised");
12766 else if (CHECK_FLAG(p->cap,
12767 PEER_CAP_DYNAMIC_RCV))
12768 json_object_string_add(json_cap,
12769 "dynamic",
12770 "received");
12771 }
d62a17ae 12772
10711563
DA
12773 /* Extended nexthop */
12774 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
12775 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12776 json_object *json_nxt = NULL;
12777 const char *print_store;
d62a17ae 12778
d62a17ae 12779
10711563
DA
12780 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
12781 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12782 json_object_string_add(
12783 json_cap, "extendedNexthop",
12784 "advertisedAndReceived");
12785 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
12786 json_object_string_add(
12787 json_cap, "extendedNexthop",
12788 "advertised");
12789 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12790 json_object_string_add(
12791 json_cap, "extendedNexthop",
12792 "received");
d62a17ae 12793
10711563
DA
12794 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
12795 json_nxt = json_object_new_object();
d62a17ae 12796
10711563
DA
12797 for (safi = SAFI_UNICAST;
12798 safi < SAFI_MAX; safi++) {
12799 if (CHECK_FLAG(
12800 p->af_cap[AFI_IP]
12801 [safi],
12802 PEER_CAP_ENHE_AF_RCV)) {
12803 print_store =
12804 get_afi_safi_str(
d62a17ae 12805 AFI_IP,
10711563
DA
12806 safi,
12807 true);
12808 json_object_string_add(
12809 json_nxt,
12810 print_store,
12811 "recieved"); /* misspelled for compatibility */
d62a17ae 12812 }
d62a17ae 12813 }
10711563
DA
12814 json_object_object_add(
12815 json_cap,
12816 "extendedNexthopFamililesByPeer",
12817 json_nxt);
d62a17ae 12818 }
10711563 12819 }
d62a17ae 12820
10711563
DA
12821 /* Long-lived Graceful Restart */
12822 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
12823 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
12824 json_object *json_llgr = NULL;
12825 const char *afi_safi_str;
8606be87 12826
10711563
DA
12827 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
12828 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12829 json_object_string_add(
12830 json_cap,
12831 "longLivedGracefulRestart",
12832 "advertisedAndReceived");
12833 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
12834 json_object_string_add(
12835 json_cap,
12836 "longLivedGracefulRestart",
12837 "advertised");
12838 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12839 json_object_string_add(
12840 json_cap,
12841 "longLivedGracefulRestart",
12842 "received");
8606be87 12843
10711563
DA
12844 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
12845 json_llgr = json_object_new_object();
8606be87 12846
10711563
DA
12847 FOREACH_AFI_SAFI (afi, safi) {
12848 if (CHECK_FLAG(
12849 p->af_cap[afi]
12850 [safi],
12851 PEER_CAP_ENHE_AF_RCV)) {
12852 afi_safi_str =
12853 get_afi_safi_str(
8606be87
DA
12854 afi,
12855 safi,
12856 true);
10711563
DA
12857 json_object_string_add(
12858 json_llgr,
12859 afi_safi_str,
12860 "received");
8606be87 12861 }
8606be87 12862 }
10711563
DA
12863 json_object_object_add(
12864 json_cap,
12865 "longLivedGracefulRestartByPeer",
12866 json_llgr);
8606be87 12867 }
10711563 12868 }
8606be87 12869
10711563
DA
12870 /* Route Refresh */
12871 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
12872 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
12873 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
12874 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
12875 (CHECK_FLAG(p->cap,
12876 PEER_CAP_REFRESH_NEW_RCV) ||
12877 CHECK_FLAG(p->cap,
12878 PEER_CAP_REFRESH_OLD_RCV))) {
12879 if (CHECK_FLAG(
12880 p->cap,
12881 PEER_CAP_REFRESH_OLD_RCV) &&
12882 CHECK_FLAG(
12883 p->cap,
12884 PEER_CAP_REFRESH_NEW_RCV))
12885 json_object_string_add(
12886 json_cap,
12887 "routeRefresh",
12888 "advertisedAndReceivedOldNew");
12889 else {
d62a17ae 12890 if (CHECK_FLAG(
12891 p->cap,
10711563 12892 PEER_CAP_REFRESH_OLD_RCV))
d62a17ae 12893 json_object_string_add(
12894 json_cap,
12895 "routeRefresh",
10711563
DA
12896 "advertisedAndReceivedOld");
12897 else
12898 json_object_string_add(
12899 json_cap,
12900 "routeRefresh",
12901 "advertisedAndReceivedNew");
d62a17ae 12902 }
10711563
DA
12903 } else if (CHECK_FLAG(p->cap,
12904 PEER_CAP_REFRESH_ADV))
12905 json_object_string_add(json_cap,
12906 "routeRefresh",
12907 "advertised");
12908 else if (CHECK_FLAG(p->cap,
12909 PEER_CAP_REFRESH_NEW_RCV) ||
12910 CHECK_FLAG(p->cap,
12911 PEER_CAP_REFRESH_OLD_RCV))
12912 json_object_string_add(json_cap,
12913 "routeRefresh",
12914 "received");
12915 }
d62a17ae 12916
10711563
DA
12917 /* Enhanced Route Refresh */
12918 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
12919 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
12920 if (CHECK_FLAG(p->cap,
12921 PEER_CAP_ENHANCED_RR_ADV) &&
12922 CHECK_FLAG(p->cap,
12923 PEER_CAP_ENHANCED_RR_RCV))
d77114b7 12924 json_object_string_add(
10711563
DA
12925 json_cap,
12926 "enhancedRouteRefresh",
12927 "advertisedAndReceived");
12928 else if (CHECK_FLAG(p->cap,
12929 PEER_CAP_ENHANCED_RR_ADV))
d77114b7 12930 json_object_string_add(
10711563
DA
12931 json_cap,
12932 "enhancedRouteRefresh",
12933 "advertised");
12934 else if (CHECK_FLAG(p->cap,
9af52ccf 12935 PEER_CAP_ENHANCED_RR_RCV))
10711563
DA
12936 json_object_string_add(
12937 json_cap,
12938 "enhancedRouteRefresh",
12939 "received");
12940 }
d77114b7 12941
10711563
DA
12942 /* Multiprotocol Extensions */
12943 json_object *json_multi = NULL;
d77114b7 12944
10711563 12945 json_multi = json_object_new_object();
d77114b7 12946
10711563
DA
12947 FOREACH_AFI_SAFI (afi, safi) {
12948 if (p->afc_adv[afi][safi] ||
12949 p->afc_recv[afi][safi]) {
12950 json_object *json_exten = NULL;
12951 json_exten = json_object_new_object();
12952
12953 if (p->afc_adv[afi][safi] &&
12954 p->afc_recv[afi][safi])
12955 json_object_boolean_true_add(
12956 json_exten,
9af52ccf 12957 "advertisedAndReceived");
10711563
DA
12958 else if (p->afc_adv[afi][safi])
12959 json_object_boolean_true_add(
12960 json_exten,
9af52ccf 12961 "advertised");
10711563
DA
12962 else if (p->afc_recv[afi][safi])
12963 json_object_boolean_true_add(
12964 json_exten, "received");
9af52ccf 12965
10711563
DA
12966 json_object_object_add(
12967 json_multi,
12968 get_afi_safi_str(afi, safi,
12969 true),
12970 json_exten);
12971 }
12972 }
12973 json_object_object_add(json_cap,
12974 "multiprotocolExtensions",
12975 json_multi);
d62a17ae 12976
10711563
DA
12977 /* Hostname capabilities */
12978 json_object *json_hname = NULL;
d62a17ae 12979
10711563 12980 json_hname = json_object_new_object();
d62a17ae 12981
10711563
DA
12982 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
12983 json_object_string_add(
12984 json_hname, "advHostName",
12985 bgp->peer_self->hostname
12986 ? bgp->peer_self->hostname
12987 : "n/a");
12988 json_object_string_add(
12989 json_hname, "advDomainName",
12990 bgp->peer_self->domainname
12991 ? bgp->peer_self->domainname
12992 : "n/a");
12993 }
d77114b7 12994
d77114b7 12995
10711563
DA
12996 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
12997 json_object_string_add(
12998 json_hname, "rcvHostName",
12999 p->hostname ? p->hostname : "n/a");
13000 json_object_string_add(
13001 json_hname, "rcvDomainName",
13002 p->domainname ? p->domainname : "n/a");
13003 }
d77114b7 13004
10711563
DA
13005 json_object_object_add(json_cap, "hostName",
13006 json_hname);
d77114b7 13007
10711563
DA
13008 /* Gracefull Restart */
13009 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13010 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13011 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13012 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
d77114b7 13013 json_object_string_add(
10711563
DA
13014 json_cap, "gracefulRestart",
13015 "advertisedAndReceived");
13016 else if (CHECK_FLAG(p->cap,
13017 PEER_CAP_RESTART_ADV))
d77114b7 13018 json_object_string_add(
10711563
DA
13019 json_cap,
13020 "gracefulRestartCapability",
13021 "advertised");
13022 else if (CHECK_FLAG(p->cap,
13023 PEER_CAP_RESTART_RCV))
13024 json_object_string_add(
13025 json_cap,
13026 "gracefulRestartCapability",
13027 "received");
d77114b7 13028
10711563
DA
13029 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13030 int restart_af_count = 0;
13031 json_object *json_restart = NULL;
13032 json_restart = json_object_new_object();
d62a17ae 13033
10711563
DA
13034 json_object_int_add(
13035 json_cap,
13036 "gracefulRestartRemoteTimerMsecs",
13037 p->v_gr_restart * 1000);
d62a17ae 13038
10711563 13039 FOREACH_AFI_SAFI (afi, safi) {
05c7a1cc
QY
13040 if (CHECK_FLAG(
13041 p->af_cap[afi]
13042 [safi],
10711563
DA
13043 PEER_CAP_RESTART_AF_RCV)) {
13044 json_object *json_sub =
13045 NULL;
13046 json_sub =
13047 json_object_new_object();
d62a17ae 13048
05c7a1cc
QY
13049 if (CHECK_FLAG(
13050 p->af_cap
13051 [afi]
13052 [safi],
10711563
DA
13053 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13054 json_object_boolean_true_add(
13055 json_sub,
13056 "preserved");
13057 restart_af_count++;
d62a17ae 13058 json_object_object_add(
10711563
DA
13059 json_restart,
13060 get_afi_safi_str(
13061 afi,
13062 safi,
13063 true),
13064 json_sub);
d62a17ae 13065 }
d62a17ae 13066 }
10711563
DA
13067 if (!restart_af_count) {
13068 json_object_string_add(
13069 json_cap,
13070 "addressFamiliesByPeer",
13071 "none");
13072 json_object_free(json_restart);
13073 } else
13074 json_object_object_add(
13075 json_cap,
13076 "addressFamiliesByPeer",
13077 json_restart);
d62a17ae 13078 }
10711563
DA
13079 }
13080 json_object_object_add(
13081 json_neigh, "neighborCapabilities", json_cap);
13082 } else {
13083 vty_out(vty, " Neighbor capabilities:\n");
13084
13085 /* AS4 */
13086 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13087 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13088 vty_out(vty, " 4 Byte AS:");
13089 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13090 vty_out(vty, " advertised");
13091 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13092 vty_out(vty, " %sreceived",
13093 CHECK_FLAG(p->cap,
13094 PEER_CAP_AS4_ADV)
13095 ? "and "
13096 : "");
13097 vty_out(vty, "\n");
13098 }
d62a17ae 13099
10711563
DA
13100 /* Extended Message Support */
13101 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13102 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13103 vty_out(vty, " Extended Message:");
ef56aee4 13104 if (CHECK_FLAG(p->cap,
10711563
DA
13105 PEER_CAP_EXTENDED_MESSAGE_ADV))
13106 vty_out(vty, " advertised");
13107 if (CHECK_FLAG(p->cap,
13108 PEER_CAP_EXTENDED_MESSAGE_RCV))
13109 vty_out(vty, " %sreceived",
13110 CHECK_FLAG(
13111 p->cap,
13112 PEER_CAP_EXTENDED_MESSAGE_ADV)
13113 ? "and "
13114 : "");
13115 vty_out(vty, "\n");
13116 }
d62a17ae 13117
10711563
DA
13118 /* AddPath */
13119 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13120 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13121 vty_out(vty, " AddPath:\n");
d62a17ae 13122
10711563 13123 FOREACH_AFI_SAFI (afi, safi) {
ef56aee4 13124 if (CHECK_FLAG(
10711563
DA
13125 p->af_cap[afi][safi],
13126 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13127 CHECK_FLAG(
13128 p->af_cap[afi][safi],
13129 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13130 vty_out(vty, " %s: TX ",
13131 get_afi_safi_str(
13132 afi, safi,
13133 false));
ef56aee4 13134
10711563
DA
13135 if (CHECK_FLAG(
13136 p->af_cap[afi]
13137 [safi],
13138 PEER_CAP_ADDPATH_AF_TX_ADV))
13139 vty_out(vty,
13140 "advertised");
d62a17ae 13141
05c7a1cc
QY
13142 if (CHECK_FLAG(
13143 p->af_cap[afi]
13144 [safi],
10711563 13145 PEER_CAP_ADDPATH_AF_TX_RCV))
05c7a1cc 13146 vty_out(vty,
10711563
DA
13147 "%sreceived",
13148 CHECK_FLAG(
13149 p->af_cap
13150 [afi]
13151 [safi],
13152 PEER_CAP_ADDPATH_AF_TX_ADV)
13153 ? " and "
13154 : "");
05c7a1cc 13155
10711563
DA
13156 vty_out(vty, "\n");
13157 }
d62a17ae 13158
9af52ccf 13159 if (CHECK_FLAG(
10711563
DA
13160 p->af_cap[afi][safi],
13161 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13162 CHECK_FLAG(
13163 p->af_cap[afi][safi],
13164 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13165 vty_out(vty, " %s: RX ",
5cb5f4d0 13166 get_afi_safi_str(
10711563
DA
13167 afi, safi,
13168 false));
d62a17ae 13169
05c7a1cc
QY
13170 if (CHECK_FLAG(
13171 p->af_cap[afi]
13172 [safi],
10711563 13173 PEER_CAP_ADDPATH_AF_RX_ADV))
05c7a1cc 13174 vty_out(vty,
10711563 13175 "advertised");
d62a17ae 13176
10711563
DA
13177 if (CHECK_FLAG(
13178 p->af_cap[afi]
13179 [safi],
13180 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc 13181 vty_out(vty,
10711563
DA
13182 "%sreceived",
13183 CHECK_FLAG(
13184 p->af_cap
13185 [afi]
13186 [safi],
13187 PEER_CAP_ADDPATH_AF_RX_ADV)
13188 ? " and "
05c7a1cc 13189 : "");
d62a17ae 13190
05c7a1cc 13191 vty_out(vty, "\n");
05c7a1cc 13192 }
d62a17ae 13193 }
10711563 13194 }
d62a17ae 13195
10711563
DA
13196 /* Dynamic */
13197 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13198 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13199 vty_out(vty, " Dynamic:");
13200 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13201 vty_out(vty, " advertised");
13202 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13203 vty_out(vty, " %sreceived",
13204 CHECK_FLAG(p->cap,
13205 PEER_CAP_DYNAMIC_ADV)
13206 ? "and "
13207 : "");
13208 vty_out(vty, "\n");
13209 }
d62a17ae 13210
10711563
DA
13211 /* Extended nexthop */
13212 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13213 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13214 vty_out(vty, " Extended nexthop:");
13215 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13216 vty_out(vty, " advertised");
13217 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13218 vty_out(vty, " %sreceived",
13219 CHECK_FLAG(p->cap,
13220 PEER_CAP_ENHE_ADV)
13221 ? "and "
13222 : "");
13223 vty_out(vty, "\n");
d62a17ae 13224
10711563 13225 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
57f7feb6 13226 vty_out(vty,
10711563
DA
13227 " Address families by peer:\n ");
13228 for (safi = SAFI_UNICAST;
13229 safi < SAFI_MAX; safi++)
13230 if (CHECK_FLAG(
13231 p->af_cap[AFI_IP]
13232 [safi],
13233 PEER_CAP_ENHE_AF_RCV))
13234 vty_out(vty,
13235 " %s\n",
13236 get_afi_safi_str(
13237 AFI_IP,
13238 safi,
13239 false));
d62a17ae 13240 }
10711563 13241 }
d62a17ae 13242
10711563
DA
13243 /* Long-lived Graceful Restart */
13244 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13245 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13246 vty_out(vty,
13247 " Long-lived Graceful Restart:");
13248 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13249 vty_out(vty, " advertised");
13250 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13251 vty_out(vty, " %sreceived",
13252 CHECK_FLAG(p->cap,
13253 PEER_CAP_LLGR_ADV)
13254 ? "and "
13255 : "");
13256 vty_out(vty, "\n");
8606be87 13257
10711563 13258 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
57f7feb6 13259 vty_out(vty,
10711563
DA
13260 " Address families by peer:\n");
13261 FOREACH_AFI_SAFI (afi, safi)
13262 if (CHECK_FLAG(
13263 p->af_cap[afi]
13264 [safi],
13265 PEER_CAP_LLGR_AF_RCV))
13266 vty_out(vty,
13267 " %s\n",
13268 get_afi_safi_str(
13269 afi,
13270 safi,
13271 false));
8606be87 13272 }
10711563 13273 }
8606be87 13274
10711563
DA
13275 /* Route Refresh */
13276 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13277 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13278 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13279 vty_out(vty, " Route refresh:");
13280 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13281 vty_out(vty, " advertised");
13282 if (CHECK_FLAG(p->cap,
13283 PEER_CAP_REFRESH_NEW_RCV) ||
13284 CHECK_FLAG(p->cap,
13285 PEER_CAP_REFRESH_OLD_RCV))
13286 vty_out(vty, " %sreceived(%s)",
13287 CHECK_FLAG(p->cap,
13288 PEER_CAP_REFRESH_ADV)
13289 ? "and "
13290 : "",
13291 (CHECK_FLAG(
13292 p->cap,
13293 PEER_CAP_REFRESH_OLD_RCV) &&
13294 CHECK_FLAG(
13295 p->cap,
13296 PEER_CAP_REFRESH_NEW_RCV))
13297 ? "old & new"
13298 : CHECK_FLAG(
13299 p->cap,
13300 PEER_CAP_REFRESH_OLD_RCV)
13301 ? "old"
13302 : "new");
d62a17ae 13303
d77114b7 13304 vty_out(vty, "\n");
10711563 13305 }
d62a17ae 13306
10711563
DA
13307 /* Enhanced Route Refresh */
13308 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13309 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13310 vty_out(vty, " Enhanced Route Refresh:");
13311 if (CHECK_FLAG(p->cap,
13312 PEER_CAP_ENHANCED_RR_ADV))
13313 vty_out(vty, " advertised");
13314 if (CHECK_FLAG(p->cap,
13315 PEER_CAP_ENHANCED_RR_RCV))
13316 vty_out(vty, " %sreceived",
13317 CHECK_FLAG(p->cap,
13318 PEER_CAP_REFRESH_ADV)
13319 ? "and "
13320 : "");
13321 vty_out(vty, "\n");
13322 }
13323
13324 /* Multiprotocol Extensions */
13325 FOREACH_AFI_SAFI (afi, safi)
13326 if (p->afc_adv[afi][safi] ||
13327 p->afc_recv[afi][safi]) {
13328 vty_out(vty, " Address Family %s:",
13329 get_afi_safi_str(afi, safi,
13330 false));
13331 if (p->afc_adv[afi][safi])
9af52ccf 13332 vty_out(vty, " advertised");
10711563 13333 if (p->afc_recv[afi][safi])
9af52ccf 13334 vty_out(vty, " %sreceived",
10711563 13335 p->afc_adv[afi][safi]
9af52ccf
DA
13336 ? "and "
13337 : "");
13338 vty_out(vty, "\n");
13339 }
13340
10711563
DA
13341 /* Hostname capability */
13342 vty_out(vty, " Hostname Capability:");
d62a17ae 13343
10711563
DA
13344 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13345 vty_out(vty,
13346 " advertised (name: %s,domain name: %s)",
13347 bgp->peer_self->hostname
13348 ? bgp->peer_self->hostname
13349 : "n/a",
13350 bgp->peer_self->domainname
13351 ? bgp->peer_self->domainname
13352 : "n/a");
13353 } else {
13354 vty_out(vty, " not advertised");
13355 }
d77114b7 13356
10711563
DA
13357 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13358 vty_out(vty,
13359 " received (name: %s,domain name: %s)",
13360 p->hostname ? p->hostname : "n/a",
13361 p->domainname ? p->domainname : "n/a");
13362 } else {
13363 vty_out(vty, " not received");
d62a17ae 13364 }
d62a17ae 13365
10711563 13366 vty_out(vty, "\n");
d77114b7 13367
10711563
DA
13368 /* Graceful Restart */
13369 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13370 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13371 vty_out(vty,
13372 " Graceful Restart Capability:");
13373 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13374 vty_out(vty, " advertised");
13375 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13376 vty_out(vty, " %sreceived",
13377 CHECK_FLAG(p->cap,
13378 PEER_CAP_RESTART_ADV)
13379 ? "and "
13380 : "");
d77114b7
MK
13381 vty_out(vty, "\n");
13382
10711563
DA
13383 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13384 int restart_af_count = 0;
d62a17ae 13385
10711563
DA
13386 vty_out(vty,
13387 " Remote Restart timer is %d seconds\n",
13388 p->v_gr_restart);
13389 vty_out(vty,
13390 " Address families by peer:\n ");
d62a17ae 13391
10711563
DA
13392 FOREACH_AFI_SAFI (afi, safi)
13393 if (CHECK_FLAG(
13394 p->af_cap[afi]
13395 [safi],
13396 PEER_CAP_RESTART_AF_RCV)) {
13397 vty_out(vty, "%s%s(%s)",
13398 restart_af_count
13399 ? ", "
13400 : "",
13401 get_afi_safi_str(
13402 afi,
13403 safi,
13404 false),
13405 CHECK_FLAG(
13406 p->af_cap
13407 [afi]
13408 [safi],
13409 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13410 ? "preserved"
13411 : "not preserved");
13412 restart_af_count++;
13413 }
13414 if (!restart_af_count)
13415 vty_out(vty, "none");
13416 vty_out(vty, "\n");
13417 }
13418 } /* Gracefull Restart */
d62a17ae 13419 }
13420 }
13421
13422 /* graceful restart information */
10711563
DA
13423 json_object *json_grace = NULL;
13424 json_object *json_grace_send = NULL;
13425 json_object *json_grace_recv = NULL;
13426 int eor_send_af_count = 0;
13427 int eor_receive_af_count = 0;
d62a17ae 13428
10711563
DA
13429 if (use_json) {
13430 json_grace = json_object_new_object();
13431 json_grace_send = json_object_new_object();
13432 json_grace_recv = json_object_new_object();
13433
13434 if ((peer_established(p)) &&
13435 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13436 FOREACH_AFI_SAFI (afi, safi) {
13437 if (CHECK_FLAG(p->af_sflags[afi][safi],
13438 PEER_STATUS_EOR_SEND)) {
13439 json_object_boolean_true_add(
13440 json_grace_send,
13441 get_afi_safi_str(afi, safi,
13442 true));
13443 eor_send_af_count++;
d62a17ae 13444 }
10711563
DA
13445 }
13446 FOREACH_AFI_SAFI (afi, safi) {
13447 if (CHECK_FLAG(p->af_sflags[afi][safi],
13448 PEER_STATUS_EOR_RECEIVED)) {
13449 json_object_boolean_true_add(
13450 json_grace_recv,
13451 get_afi_safi_str(afi, safi,
13452 true));
13453 eor_receive_af_count++;
d62a17ae 13454 }
13455 }
10711563
DA
13456 }
13457 json_object_object_add(json_grace, "endOfRibSend",
13458 json_grace_send);
13459 json_object_object_add(json_grace, "endOfRibRecv",
13460 json_grace_recv);
d62a17ae 13461
d62a17ae 13462
10711563
DA
13463 if (p->t_gr_restart)
13464 json_object_int_add(
13465 json_grace, "gracefulRestartTimerMsecs",
13466 thread_timer_remain_second(p->t_gr_restart) *
13467 1000);
2986cac2 13468
10711563
DA
13469 if (p->t_gr_stale)
13470 json_object_int_add(
13471 json_grace, "gracefulStalepathTimerMsecs",
13472 thread_timer_remain_second(p->t_gr_stale) *
13473 1000);
13474 /* more gr info in new format */
13475 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13476 json_object_object_add(json_neigh, "gracefulRestartInfo",
13477 json_grace);
13478 } else {
13479 vty_out(vty, " Graceful restart information:\n");
13480 if ((peer_established(p)) &&
13481 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13482
13483 vty_out(vty, " End-of-RIB send: ");
13484 FOREACH_AFI_SAFI (afi, safi) {
13485 if (CHECK_FLAG(p->af_sflags[afi][safi],
13486 PEER_STATUS_EOR_SEND)) {
13487 vty_out(vty, "%s%s",
13488 eor_send_af_count ? ", " : "",
13489 get_afi_safi_str(afi, safi,
13490 false));
13491 eor_send_af_count++;
d62a17ae 13492 }
10711563
DA
13493 }
13494 vty_out(vty, "\n");
13495 vty_out(vty, " End-of-RIB received: ");
13496 FOREACH_AFI_SAFI (afi, safi) {
13497 if (CHECK_FLAG(p->af_sflags[afi][safi],
13498 PEER_STATUS_EOR_RECEIVED)) {
13499 vty_out(vty, "%s%s",
13500 eor_receive_af_count ? ", "
13501 : "",
13502 get_afi_safi_str(afi, safi,
13503 false));
13504 eor_receive_af_count++;
d62a17ae 13505 }
d62a17ae 13506 }
10711563
DA
13507 vty_out(vty, "\n");
13508 }
d62a17ae 13509
10711563
DA
13510 if (p->t_gr_restart)
13511 vty_out(vty,
13512 " The remaining time of restart timer is %ld\n",
13513 thread_timer_remain_second(p->t_gr_restart));
d62a17ae 13514
10711563
DA
13515 if (p->t_gr_stale)
13516 vty_out(vty,
13517 " The remaining time of stalepath timer is %ld\n",
13518 thread_timer_remain_second(p->t_gr_stale));
2986cac2 13519
10711563
DA
13520 /* more gr info in new format */
13521 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13522 }
2986cac2 13523
d62a17ae 13524 if (use_json) {
13525 json_object *json_stat = NULL;
13526 json_stat = json_object_new_object();
13527 /* Packet counts. */
43aa5965
QY
13528
13529 atomic_size_t outq_count, inq_count;
13530 outq_count = atomic_load_explicit(&p->obuf->count,
13531 memory_order_relaxed);
13532 inq_count = atomic_load_explicit(&p->ibuf->count,
13533 memory_order_relaxed);
13534
13535 json_object_int_add(json_stat, "depthInq",
13536 (unsigned long)inq_count);
d62a17ae 13537 json_object_int_add(json_stat, "depthOutq",
43aa5965 13538 (unsigned long)outq_count);
0112e9e0
QY
13539 json_object_int_add(json_stat, "opensSent",
13540 atomic_load_explicit(&p->open_out,
13541 memory_order_relaxed));
13542 json_object_int_add(json_stat, "opensRecv",
13543 atomic_load_explicit(&p->open_in,
13544 memory_order_relaxed));
d62a17ae 13545 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
13546 atomic_load_explicit(&p->notify_out,
13547 memory_order_relaxed));
d62a17ae 13548 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
13549 atomic_load_explicit(&p->notify_in,
13550 memory_order_relaxed));
13551 json_object_int_add(json_stat, "updatesSent",
13552 atomic_load_explicit(&p->update_out,
13553 memory_order_relaxed));
13554 json_object_int_add(json_stat, "updatesRecv",
13555 atomic_load_explicit(&p->update_in,
13556 memory_order_relaxed));
d62a17ae 13557 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
13558 atomic_load_explicit(&p->keepalive_out,
13559 memory_order_relaxed));
d62a17ae 13560 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
13561 atomic_load_explicit(&p->keepalive_in,
13562 memory_order_relaxed));
d62a17ae 13563 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
13564 atomic_load_explicit(&p->refresh_out,
13565 memory_order_relaxed));
d62a17ae 13566 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
13567 atomic_load_explicit(&p->refresh_in,
13568 memory_order_relaxed));
d62a17ae 13569 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
13570 atomic_load_explicit(&p->dynamic_cap_out,
13571 memory_order_relaxed));
d62a17ae 13572 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
13573 atomic_load_explicit(&p->dynamic_cap_in,
13574 memory_order_relaxed));
13575 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13576 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 13577 json_object_object_add(json_neigh, "messageStats", json_stat);
13578 } else {
43aa5965
QY
13579 atomic_size_t outq_count, inq_count;
13580 outq_count = atomic_load_explicit(&p->obuf->count,
13581 memory_order_relaxed);
13582 inq_count = atomic_load_explicit(&p->ibuf->count,
13583 memory_order_relaxed);
13584
d62a17ae 13585 /* Packet counts. */
13586 vty_out(vty, " Message statistics:\n");
43aa5965
QY
13587 vty_out(vty, " Inq depth is %zu\n", inq_count);
13588 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 13589 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
13590 vty_out(vty, " Opens: %10d %10d\n",
13591 atomic_load_explicit(&p->open_out,
13592 memory_order_relaxed),
13593 atomic_load_explicit(&p->open_in,
13594 memory_order_relaxed));
13595 vty_out(vty, " Notifications: %10d %10d\n",
13596 atomic_load_explicit(&p->notify_out,
13597 memory_order_relaxed),
13598 atomic_load_explicit(&p->notify_in,
13599 memory_order_relaxed));
13600 vty_out(vty, " Updates: %10d %10d\n",
13601 atomic_load_explicit(&p->update_out,
13602 memory_order_relaxed),
13603 atomic_load_explicit(&p->update_in,
13604 memory_order_relaxed));
13605 vty_out(vty, " Keepalives: %10d %10d\n",
13606 atomic_load_explicit(&p->keepalive_out,
13607 memory_order_relaxed),
13608 atomic_load_explicit(&p->keepalive_in,
13609 memory_order_relaxed));
13610 vty_out(vty, " Route Refresh: %10d %10d\n",
13611 atomic_load_explicit(&p->refresh_out,
13612 memory_order_relaxed),
13613 atomic_load_explicit(&p->refresh_in,
13614 memory_order_relaxed));
d62a17ae 13615 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
13616 atomic_load_explicit(&p->dynamic_cap_out,
13617 memory_order_relaxed),
13618 atomic_load_explicit(&p->dynamic_cap_in,
13619 memory_order_relaxed));
13620 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
13621 PEER_TOTAL_RX(p));
d62a17ae 13622 }
13623
13624 if (use_json) {
13625 /* advertisement-interval */
13626 json_object_int_add(json_neigh,
13627 "minBtwnAdvertisementRunsTimerMsecs",
13628 p->v_routeadv * 1000);
13629
13630 /* Update-source. */
13631 if (p->update_if || p->update_source) {
13632 if (p->update_if)
13633 json_object_string_add(json_neigh,
13634 "updateSource",
13635 p->update_if);
13636 else if (p->update_source)
13637 json_object_string_add(
13638 json_neigh, "updateSource",
13639 sockunion2str(p->update_source, buf1,
13640 SU_ADDRSTRLEN));
13641 }
13642 } else {
13643 /* advertisement-interval */
13644 vty_out(vty,
13645 " Minimum time between advertisement runs is %d seconds\n",
13646 p->v_routeadv);
13647
13648 /* Update-source. */
13649 if (p->update_if || p->update_source) {
13650 vty_out(vty, " Update source is ");
13651 if (p->update_if)
13652 vty_out(vty, "%s", p->update_if);
13653 else if (p->update_source)
13654 vty_out(vty, "%s",
13655 sockunion2str(p->update_source, buf1,
13656 SU_ADDRSTRLEN));
13657 vty_out(vty, "\n");
13658 }
13659
13660 vty_out(vty, "\n");
13661 }
13662
13663 /* Address Family Information */
13664 json_object *json_hold = NULL;
13665
13666 if (use_json)
13667 json_hold = json_object_new_object();
13668
05c7a1cc
QY
13669 FOREACH_AFI_SAFI (afi, safi)
13670 if (p->afc[afi][safi])
13671 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13672 json_hold);
d62a17ae 13673
13674 if (use_json) {
13675 json_object_object_add(json_neigh, "addressFamilyInfo",
13676 json_hold);
13677 json_object_int_add(json_neigh, "connectionsEstablished",
13678 p->established);
13679 json_object_int_add(json_neigh, "connectionsDropped",
13680 p->dropped);
13681 } else
13682 vty_out(vty, " Connections established %d; dropped %d\n",
13683 p->established, p->dropped);
13684
13685 if (!p->last_reset) {
13686 if (use_json)
13687 json_object_string_add(json_neigh, "lastReset",
13688 "never");
13689 else
13690 vty_out(vty, " Last reset never\n");
13691 } else {
13692 if (use_json) {
13693 time_t uptime;
a2700b50 13694 struct tm tm;
d62a17ae 13695
13696 uptime = bgp_clock();
13697 uptime -= p->resettime;
a2700b50
MS
13698 gmtime_r(&uptime, &tm);
13699
d62a17ae 13700 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
13701 (tm.tm_sec * 1000)
13702 + (tm.tm_min * 60000)
13703 + (tm.tm_hour * 3600000));
3577f1c5 13704 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 13705 } else {
13706 vty_out(vty, " Last reset %s, ",
13707 peer_uptime(p->resettime, timebuf,
13708 BGP_UPTIME_LEN, 0, NULL));
13709
3577f1c5 13710 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 13711 if (p->last_reset_cause_size) {
13712 msg = p->last_reset_cause;
13713 vty_out(vty,
13714 " Message received that caused BGP to send a NOTIFICATION:\n ");
13715 for (i = 1; i <= p->last_reset_cause_size;
13716 i++) {
13717 vty_out(vty, "%02X", *msg++);
13718
13719 if (i != p->last_reset_cause_size) {
13720 if (i % 16 == 0) {
13721 vty_out(vty, "\n ");
13722 } else if (i % 4 == 0) {
13723 vty_out(vty, " ");
13724 }
13725 }
13726 }
13727 vty_out(vty, "\n");
13728 }
13729 }
13730 }
13731
13732 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13733 if (use_json)
13734 json_object_boolean_true_add(json_neigh,
13735 "prefixesConfigExceedMax");
13736 else
13737 vty_out(vty,
13738 " Peer had exceeded the max. no. of prefixes configured.\n");
13739
13740 if (p->t_pmax_restart) {
13741 if (use_json) {
13742 json_object_boolean_true_add(
13743 json_neigh, "reducePrefixNumFrom");
13744 json_object_int_add(json_neigh,
13745 "restartInTimerMsec",
13746 thread_timer_remain_second(
13747 p->t_pmax_restart)
13748 * 1000);
13749 } else
13750 vty_out(vty,
13751 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
13752 p->host, thread_timer_remain_second(
13753 p->t_pmax_restart));
d62a17ae 13754 } else {
13755 if (use_json)
13756 json_object_boolean_true_add(
13757 json_neigh,
13758 "reducePrefixNumAndClearIpBgp");
13759 else
13760 vty_out(vty,
13761 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13762 p->host);
13763 }
13764 }
13765
13766 /* EBGP Multihop and GTSM */
13767 if (p->sort != BGP_PEER_IBGP) {
13768 if (use_json) {
e2521429 13769 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13770 json_object_int_add(json_neigh,
13771 "externalBgpNbrMaxHopsAway",
13772 p->gtsm_hops);
c8d6f0d6 13773 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13774 json_object_int_add(json_neigh,
13775 "externalBgpNbrMaxHopsAway",
13776 p->ttl);
13777 } else {
e2521429 13778 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13779 vty_out(vty,
13780 " External BGP neighbor may be up to %d hops away.\n",
13781 p->gtsm_hops);
c8d6f0d6 13782 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13783 vty_out(vty,
13784 " External BGP neighbor may be up to %d hops away.\n",
13785 p->ttl);
13786 }
13787 } else {
e2521429 13788 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 13789 if (use_json)
13790 json_object_int_add(json_neigh,
13791 "internalBgpNbrMaxHopsAway",
13792 p->gtsm_hops);
13793 else
13794 vty_out(vty,
13795 " Internal BGP neighbor may be up to %d hops away.\n",
13796 p->gtsm_hops);
13797 }
13798 }
13799
13800 /* Local address. */
13801 if (p->su_local) {
13802 if (use_json) {
13803 json_object_string_add(json_neigh, "hostLocal",
13804 sockunion2str(p->su_local, buf1,
13805 SU_ADDRSTRLEN));
13806 json_object_int_add(json_neigh, "portLocal",
13807 ntohs(p->su_local->sin.sin_port));
13808 } else
13809 vty_out(vty, "Local host: %s, Local port: %d\n",
13810 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
13811 ntohs(p->su_local->sin.sin_port));
13812 }
13813
13814 /* Remote address. */
13815 if (p->su_remote) {
13816 if (use_json) {
13817 json_object_string_add(json_neigh, "hostForeign",
13818 sockunion2str(p->su_remote, buf1,
13819 SU_ADDRSTRLEN));
13820 json_object_int_add(json_neigh, "portForeign",
13821 ntohs(p->su_remote->sin.sin_port));
13822 } else
13823 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
13824 sockunion2str(p->su_remote, buf1,
13825 SU_ADDRSTRLEN),
13826 ntohs(p->su_remote->sin.sin_port));
13827 }
13828
13829 /* Nexthop display. */
13830 if (p->su_local) {
13831 if (use_json) {
c949c771
DA
13832 json_object_string_addf(json_neigh, "nexthop", "%pI4",
13833 &p->nexthop.v4);
13834 json_object_string_addf(json_neigh, "nexthopGlobal",
13835 "%pI6", &p->nexthop.v6_global);
13836 json_object_string_addf(json_neigh, "nexthopLocal",
13837 "%pI6", &p->nexthop.v6_local);
d62a17ae 13838 if (p->shared_network)
13839 json_object_string_add(json_neigh,
13840 "bgpConnection",
13841 "sharedNetwork");
13842 else
13843 json_object_string_add(json_neigh,
13844 "bgpConnection",
13845 "nonSharedNetwork");
13846 } else {
13847 vty_out(vty, "Nexthop: %s\n",
13848 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
13849 sizeof(buf1)));
13850 vty_out(vty, "Nexthop global: %s\n",
13851 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
13852 sizeof(buf1)));
13853 vty_out(vty, "Nexthop local: %s\n",
13854 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
13855 sizeof(buf1)));
13856 vty_out(vty, "BGP connection: %s\n",
13857 p->shared_network ? "shared network"
13858 : "non shared network");
13859 }
13860 }
13861
13862 /* Timer information. */
13863 if (use_json) {
13864 json_object_int_add(json_neigh, "connectRetryTimer",
13865 p->v_connect);
feb17238 13866 if (peer_established(p) && p->rtt)
d62a17ae 13867 json_object_int_add(json_neigh, "estimatedRttInMsecs",
13868 p->rtt);
13869 if (p->t_start)
13870 json_object_int_add(
13871 json_neigh, "nextStartTimerDueInMsecs",
13872 thread_timer_remain_second(p->t_start) * 1000);
13873 if (p->t_connect)
13874 json_object_int_add(
13875 json_neigh, "nextConnectTimerDueInMsecs",
13876 thread_timer_remain_second(p->t_connect)
13877 * 1000);
13878 if (p->t_routeadv) {
13879 json_object_int_add(json_neigh, "mraiInterval",
13880 p->v_routeadv);
13881 json_object_int_add(
13882 json_neigh, "mraiTimerExpireInMsecs",
13883 thread_timer_remain_second(p->t_routeadv)
13884 * 1000);
13885 }
13886 if (p->password)
13887 json_object_int_add(json_neigh, "authenticationEnabled",
13888 1);
13889
13890 if (p->t_read)
13891 json_object_string_add(json_neigh, "readThread", "on");
13892 else
13893 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
13894
13895 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 13896 json_object_string_add(json_neigh, "writeThread", "on");
13897 else
13898 json_object_string_add(json_neigh, "writeThread",
13899 "off");
13900 } else {
13901 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
13902 p->v_connect);
feb17238 13903 if (peer_established(p) && p->rtt)
d62a17ae 13904 vty_out(vty, "Estimated round trip time: %d ms\n",
13905 p->rtt);
13906 if (p->t_start)
13907 vty_out(vty, "Next start timer due in %ld seconds\n",
13908 thread_timer_remain_second(p->t_start));
13909 if (p->t_connect)
13910 vty_out(vty, "Next connect timer due in %ld seconds\n",
13911 thread_timer_remain_second(p->t_connect));
13912 if (p->t_routeadv)
13913 vty_out(vty,
13914 "MRAI (interval %u) timer expires in %ld seconds\n",
13915 p->v_routeadv,
13916 thread_timer_remain_second(p->t_routeadv));
13917 if (p->password)
13918 vty_out(vty, "Peer Authentication Enabled\n");
13919
cac9e917 13920 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
13921 p->t_read ? "on" : "off",
13922 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
13923 ? "on"
cac9e917 13924 : "off", p->fd);
d62a17ae 13925 }
13926
13927 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
13928 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
13929 bgp_capability_vty_out(vty, p, use_json, json_neigh);
13930
13931 if (!use_json)
13932 vty_out(vty, "\n");
13933
13934 /* BFD information. */
21bfce98
RZ
13935 if (p->bfd_config)
13936 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 13937
13938 if (use_json) {
13939 if (p->conf_if) /* Configured interface name. */
13940 json_object_object_add(json, p->conf_if, json_neigh);
13941 else /* Configured IP address. */
13942 json_object_object_add(json, p->host, json_neigh);
13943 }
13944}
13945
36235319
QY
13946static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
13947 enum show_type type,
13948 union sockunion *su,
13949 const char *conf_if, afi_t afi,
74a630b6 13950 bool use_json)
2986cac2 13951{
13952 struct listnode *node, *nnode;
13953 struct peer *peer;
13954 int find = 0;
13955 safi_t safi = SAFI_UNICAST;
74a630b6 13956 json_object *json = NULL;
2986cac2 13957 json_object *json_neighbor = NULL;
13958
74a630b6
NT
13959 if (use_json) {
13960 json = json_object_new_object();
13961 json_neighbor = json_object_new_object();
13962 }
13963
2986cac2 13964 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13965
13966 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13967 continue;
13968
13969 if ((peer->afc[afi][safi]) == 0)
13970 continue;
13971
2ba1fe69 13972 if (type == show_all) {
2986cac2 13973 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 13974 json_neighbor);
2986cac2 13975
74a630b6 13976 if (use_json) {
13909c4f
DS
13977 json_object_object_add(json, peer->host,
13978 json_neighbor);
74a630b6
NT
13979 json_neighbor = NULL;
13980 }
2986cac2 13981
2ba1fe69 13982 } else if (type == show_peer) {
2986cac2 13983 if (conf_if) {
13984 if ((peer->conf_if
13909c4f
DS
13985 && !strcmp(peer->conf_if, conf_if))
13986 || (peer->hostname
2986cac2 13987 && !strcmp(peer->hostname, conf_if))) {
13988 find = 1;
13909c4f
DS
13989 bgp_show_peer_gr_status(vty, peer,
13990 use_json,
13991 json_neighbor);
2986cac2 13992 }
13993 } else {
13994 if (sockunion_same(&peer->su, su)) {
13995 find = 1;
13909c4f
DS
13996 bgp_show_peer_gr_status(vty, peer,
13997 use_json,
13998 json_neighbor);
2986cac2 13999 }
14000 }
13909c4f
DS
14001 if (use_json && find)
14002 json_object_object_add(json, peer->host,
14003 json_neighbor);
2986cac2 14004 }
14005
74a630b6
NT
14006 if (find) {
14007 json_neighbor = NULL;
2986cac2 14008 break;
74a630b6 14009 }
2986cac2 14010 }
14011
14012 if (type == show_peer && !find) {
14013 if (use_json)
13909c4f 14014 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14015 else
14016 vty_out(vty, "%% No such neighbor\n");
14017 }
14018 if (use_json) {
74a630b6
NT
14019 if (json_neighbor)
14020 json_object_free(json_neighbor);
75eeda93 14021 vty_json(vty, json);
2986cac2 14022 } else {
14023 vty_out(vty, "\n");
14024 }
14025
14026 return CMD_SUCCESS;
14027}
14028
d62a17ae 14029static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14030 enum show_type type, union sockunion *su,
9f049418 14031 const char *conf_if, bool use_json,
d62a17ae 14032 json_object *json)
14033{
14034 struct listnode *node, *nnode;
14035 struct peer *peer;
14036 int find = 0;
9f049418 14037 bool nbr_output = false;
d1927ebe
AS
14038 afi_t afi = AFI_MAX;
14039 safi_t safi = SAFI_MAX;
14040
14041 if (type == show_ipv4_peer || type == show_ipv4_all) {
14042 afi = AFI_IP;
14043 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14044 afi = AFI_IP6;
14045 }
d62a17ae 14046
14047 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14048 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14049 continue;
14050
14051 switch (type) {
14052 case show_all:
14053 bgp_show_peer(vty, peer, use_json, json);
9f049418 14054 nbr_output = true;
d62a17ae 14055 break;
14056 case show_peer:
14057 if (conf_if) {
14058 if ((peer->conf_if
14059 && !strcmp(peer->conf_if, conf_if))
14060 || (peer->hostname
14061 && !strcmp(peer->hostname, conf_if))) {
14062 find = 1;
14063 bgp_show_peer(vty, peer, use_json,
14064 json);
14065 }
14066 } else {
14067 if (sockunion_same(&peer->su, su)) {
14068 find = 1;
14069 bgp_show_peer(vty, peer, use_json,
14070 json);
14071 }
14072 }
14073 break;
d1927ebe
AS
14074 case show_ipv4_peer:
14075 case show_ipv6_peer:
14076 FOREACH_SAFI (safi) {
14077 if (peer->afc[afi][safi]) {
14078 if (conf_if) {
14079 if ((peer->conf_if
14080 && !strcmp(peer->conf_if, conf_if))
14081 || (peer->hostname
14082 && !strcmp(peer->hostname, conf_if))) {
14083 find = 1;
14084 bgp_show_peer(vty, peer, use_json,
14085 json);
14086 break;
14087 }
14088 } else {
14089 if (sockunion_same(&peer->su, su)) {
14090 find = 1;
14091 bgp_show_peer(vty, peer, use_json,
14092 json);
14093 break;
14094 }
14095 }
14096 }
14097 }
14098 break;
14099 case show_ipv4_all:
14100 case show_ipv6_all:
14101 FOREACH_SAFI (safi) {
14102 if (peer->afc[afi][safi]) {
14103 bgp_show_peer(vty, peer, use_json, json);
14104 nbr_output = true;
14105 break;
14106 }
14107 }
14108 break;
d62a17ae 14109 }
14110 }
14111
d1927ebe
AS
14112 if ((type == show_peer || type == show_ipv4_peer ||
14113 type == show_ipv6_peer) && !find) {
d62a17ae 14114 if (use_json)
14115 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14116 else
88b7d255 14117 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14118 }
14119
d1927ebe
AS
14120 if (type != show_peer && type != show_ipv4_peer &&
14121 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14122 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14123
d62a17ae 14124 if (use_json) {
996c9314
LB
14125 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14126 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14127 } else {
14128 vty_out(vty, "\n");
14129 }
14130
14131 return CMD_SUCCESS;
14132}
14133
36235319
QY
14134static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14135 enum show_type type,
14136 const char *ip_str,
14137 afi_t afi, bool use_json)
2986cac2 14138{
14139
14140 int ret;
14141 struct bgp *bgp;
14142 union sockunion su;
2986cac2 14143
14144 bgp = bgp_get_default();
14145
13909c4f
DS
14146 if (!bgp)
14147 return;
2986cac2 14148
13909c4f
DS
14149 if (!use_json)
14150 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14151 NULL);
2986cac2 14152
13909c4f
DS
14153 if (ip_str) {
14154 ret = str2sockunion(ip_str, &su);
14155 if (ret < 0)
13909c4f 14156 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14157 vty, bgp, type, NULL, ip_str, afi, use_json);
14158 else
14159 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14160 NULL, afi, use_json);
13909c4f
DS
14161 } else
14162 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14163 afi, use_json);
2986cac2 14164}
14165
d62a17ae 14166static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14167 enum show_type type,
14168 const char *ip_str,
9f049418 14169 bool use_json)
d62a17ae 14170{
0291c246
MK
14171 struct listnode *node, *nnode;
14172 struct bgp *bgp;
71aedaa3 14173 union sockunion su;
0291c246 14174 json_object *json = NULL;
71aedaa3 14175 int ret, is_first = 1;
9f049418 14176 bool nbr_output = false;
d62a17ae 14177
14178 if (use_json)
14179 vty_out(vty, "{\n");
14180
14181 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14182 nbr_output = true;
d62a17ae 14183 if (use_json) {
14184 if (!(json = json_object_new_object())) {
af4c2728 14185 flog_err(
e50f7cfd 14186 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14187 "Unable to allocate memory for JSON object");
14188 vty_out(vty,
14189 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14190 return;
14191 }
14192
14193 json_object_int_add(json, "vrfId",
14194 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14195 ? -1
14196 : (int64_t)bgp->vrf_id);
d62a17ae 14197 json_object_string_add(
14198 json, "vrfName",
14199 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14200 ? VRF_DEFAULT_NAME
d62a17ae 14201 : bgp->name);
14202
14203 if (!is_first)
14204 vty_out(vty, ",\n");
14205 else
14206 is_first = 0;
14207
14208 vty_out(vty, "\"%s\":",
14209 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14210 ? VRF_DEFAULT_NAME
d62a17ae 14211 : bgp->name);
14212 } else {
14213 vty_out(vty, "\nInstance %s:\n",
14214 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14215 ? VRF_DEFAULT_NAME
d62a17ae 14216 : bgp->name);
14217 }
71aedaa3 14218
d1927ebe
AS
14219 if (type == show_peer || type == show_ipv4_peer ||
14220 type == show_ipv6_peer) {
71aedaa3
DS
14221 ret = str2sockunion(ip_str, &su);
14222 if (ret < 0)
14223 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14224 use_json, json);
14225 else
14226 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14227 use_json, json);
14228 } else {
d1927ebe 14229 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14230 use_json, json);
14231 }
b77004d6 14232 json_object_free(json);
121067e9 14233 json = NULL;
d62a17ae 14234 }
14235
3e78a6ce 14236 if (use_json)
d62a17ae 14237 vty_out(vty, "}\n");
9f049418
DS
14238 else if (!nbr_output)
14239 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14240}
14241
14242static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14243 enum show_type type, const char *ip_str,
9f049418 14244 bool use_json)
d62a17ae 14245{
14246 int ret;
14247 struct bgp *bgp;
14248 union sockunion su;
14249 json_object *json = NULL;
14250
14251 if (name) {
14252 if (strmatch(name, "all")) {
71aedaa3
DS
14253 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14254 use_json);
d62a17ae 14255 return CMD_SUCCESS;
14256 } else {
14257 bgp = bgp_lookup_by_name(name);
14258 if (!bgp) {
14259 if (use_json) {
14260 json = json_object_new_object();
75eeda93 14261 vty_json(vty, json);
d62a17ae 14262 } else
14263 vty_out(vty,
9f049418 14264 "%% BGP instance not found\n");
d62a17ae 14265
14266 return CMD_WARNING;
14267 }
14268 }
14269 } else {
14270 bgp = bgp_get_default();
14271 }
14272
14273 if (bgp) {
14274 json = json_object_new_object();
14275 if (ip_str) {
14276 ret = str2sockunion(ip_str, &su);
14277 if (ret < 0)
14278 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14279 use_json, json);
14280 else
14281 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14282 use_json, json);
14283 } else {
14284 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14285 json);
14286 }
14287 json_object_free(json);
ca61fd25
DS
14288 } else {
14289 if (use_json)
14290 vty_out(vty, "{}\n");
14291 else
14292 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14293 }
14294
14295 return CMD_SUCCESS;
4fb25c53
DW
14296}
14297
2986cac2 14298
14299
14300/* "show [ip] bgp neighbors graceful-restart" commands. */
14301DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14302 show_ip_bgp_neighbors_graceful_restart_cmd,
14303 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14304 SHOW_STR
14305 BGP_STR
14306 IP_STR
14307 IPV6_STR
14308 NEIGHBOR_STR
14309 "Neighbor to display information about\n"
14310 "Neighbor to display information about\n"
14311 "Neighbor on BGP configured interface\n"
14312 GR_SHOW
14313 JSON_STR)
14314{
14315 char *sh_arg = NULL;
14316 enum show_type sh_type;
14317 int idx = 0;
14318 afi_t afi = AFI_MAX;
2986cac2 14319 bool uj = use_json(argc, argv);
14320
36235319 14321 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 14322 afi = AFI_MAX;
14323
14324 idx++;
14325
14326 if (argv_find(argv, argc, "A.B.C.D", &idx)
14327 || argv_find(argv, argc, "X:X::X:X", &idx)
14328 || argv_find(argv, argc, "WORD", &idx)) {
14329 sh_type = show_peer;
14330 sh_arg = argv[idx]->arg;
14331 } else
14332 sh_type = show_all;
14333
14334 if (!argv_find(argv, argc, "graceful-restart", &idx))
14335 return CMD_SUCCESS;
14336
14337
36235319
QY
14338 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14339 afi, uj);
2986cac2 14340}
14341
716b2d8a 14342/* "show [ip] bgp neighbors" commands. */
718e3744 14343DEFUN (show_ip_bgp_neighbors,
14344 show_ip_bgp_neighbors_cmd,
24345e82 14345 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 14346 SHOW_STR
14347 IP_STR
14348 BGP_STR
f2a8972b 14349 BGP_INSTANCE_HELP_STR
8c3deaae
QY
14350 "Address Family\n"
14351 "Address Family\n"
718e3744 14352 "Detailed information on TCP and BGP neighbor connections\n"
14353 "Neighbor to display information about\n"
a80beece 14354 "Neighbor to display information about\n"
91d37724 14355 "Neighbor on BGP configured interface\n"
9973d184 14356 JSON_STR)
718e3744 14357{
d62a17ae 14358 char *vrf = NULL;
14359 char *sh_arg = NULL;
14360 enum show_type sh_type;
d1927ebe 14361 afi_t afi = AFI_MAX;
718e3744 14362
9f049418 14363 bool uj = use_json(argc, argv);
718e3744 14364
d62a17ae 14365 int idx = 0;
718e3744 14366
9a8bdf1c
PG
14367 /* [<vrf> VIEWVRFNAME] */
14368 if (argv_find(argv, argc, "vrf", &idx)) {
14369 vrf = argv[idx + 1]->arg;
14370 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14371 vrf = NULL;
14372 } else if (argv_find(argv, argc, "view", &idx))
14373 /* [<view> VIEWVRFNAME] */
d62a17ae 14374 vrf = argv[idx + 1]->arg;
718e3744 14375
d62a17ae 14376 idx++;
d1927ebe
AS
14377
14378 if (argv_find(argv, argc, "ipv4", &idx)) {
14379 sh_type = show_ipv4_all;
14380 afi = AFI_IP;
14381 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14382 sh_type = show_ipv6_all;
14383 afi = AFI_IP6;
14384 } else {
14385 sh_type = show_all;
14386 }
14387
d62a17ae 14388 if (argv_find(argv, argc, "A.B.C.D", &idx)
14389 || argv_find(argv, argc, "X:X::X:X", &idx)
14390 || argv_find(argv, argc, "WORD", &idx)) {
14391 sh_type = show_peer;
14392 sh_arg = argv[idx]->arg;
d1927ebe
AS
14393 }
14394
14395 if (sh_type == show_peer && afi == AFI_IP) {
14396 sh_type = show_ipv4_peer;
14397 } else if (sh_type == show_peer && afi == AFI_IP6) {
14398 sh_type = show_ipv6_peer;
14399 }
856ca177 14400
d62a17ae 14401 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 14402}
14403
716b2d8a 14404/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 14405 paths' and `show ip mbgp paths'. Those functions results are the
14406 same.*/
f412b39a 14407DEFUN (show_ip_bgp_paths,
718e3744 14408 show_ip_bgp_paths_cmd,
46f296b4 14409 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 14410 SHOW_STR
14411 IP_STR
14412 BGP_STR
46f296b4 14413 BGP_SAFI_HELP_STR
718e3744 14414 "Path information\n")
14415{
d62a17ae 14416 vty_out(vty, "Address Refcnt Path\n");
14417 aspath_print_all_vty(vty);
14418 return CMD_SUCCESS;
718e3744 14419}
14420
718e3744 14421#include "hash.h"
14422
e3b78da8 14423static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14424 struct vty *vty)
718e3744 14425{
d62a17ae 14426 struct community *com;
718e3744 14427
e3b78da8 14428 com = (struct community *)bucket->data;
3f65c5b1 14429 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 14430 community_str(com, false));
718e3744 14431}
14432
14433/* Show BGP's community internal data. */
f412b39a 14434DEFUN (show_ip_bgp_community_info,
718e3744 14435 show_ip_bgp_community_info_cmd,
bec37ba5 14436 "show [ip] bgp community-info",
718e3744 14437 SHOW_STR
14438 IP_STR
14439 BGP_STR
14440 "List all bgp community information\n")
14441{
d62a17ae 14442 vty_out(vty, "Address Refcnt Community\n");
718e3744 14443
d62a17ae 14444 hash_iterate(community_hash(),
e3b78da8 14445 (void (*)(struct hash_bucket *,
d62a17ae 14446 void *))community_show_all_iterator,
14447 vty);
718e3744 14448
d62a17ae 14449 return CMD_SUCCESS;
718e3744 14450}
14451
e3b78da8 14452static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14453 struct vty *vty)
57d187bc 14454{
d62a17ae 14455 struct lcommunity *lcom;
57d187bc 14456
e3b78da8 14457 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 14458 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 14459 lcommunity_str(lcom, false));
57d187bc
JS
14460}
14461
14462/* Show BGP's community internal data. */
14463DEFUN (show_ip_bgp_lcommunity_info,
14464 show_ip_bgp_lcommunity_info_cmd,
14465 "show ip bgp large-community-info",
14466 SHOW_STR
14467 IP_STR
14468 BGP_STR
14469 "List all bgp large-community information\n")
14470{
d62a17ae 14471 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 14472
d62a17ae 14473 hash_iterate(lcommunity_hash(),
e3b78da8 14474 (void (*)(struct hash_bucket *,
d62a17ae 14475 void *))lcommunity_show_all_iterator,
14476 vty);
57d187bc 14477
d62a17ae 14478 return CMD_SUCCESS;
57d187bc 14479}
2986cac2 14480/* Graceful Restart */
14481
14482static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
14483 struct bgp *bgp,
14484 bool use_json,
14485 json_object *json)
2986cac2 14486{
57d187bc
JS
14487
14488
2986cac2 14489 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14490
7318ae88 14491 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 14492
14493 switch (bgp_global_gr_mode) {
14494
14495 case GLOBAL_HELPER:
13909c4f 14496 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 14497 break;
14498
14499 case GLOBAL_GR:
13909c4f 14500 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 14501 break;
14502
14503 case GLOBAL_DISABLE:
13909c4f 14504 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 14505 break;
14506
14507 case GLOBAL_INVALID:
2986cac2 14508 vty_out(vty,
2ba1fe69 14509 "Global BGP GR Mode Invalid\n");
2986cac2 14510 break;
14511 }
14512 vty_out(vty, "\n");
14513}
14514
36235319
QY
14515static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14516 enum show_type type,
14517 const char *ip_str,
14518 afi_t afi, bool use_json)
2986cac2 14519{
14520 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14521 afi = AFI_IP;
14522
14523 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14524
36235319
QY
14525 bgp_show_neighbor_graceful_restart_vty(
14526 vty, type, ip_str, afi, use_json);
2986cac2 14527 afi++;
14528 }
14529 } else if (afi != AFI_MAX) {
36235319
QY
14530 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14531 use_json);
2986cac2 14532 } else {
14533 return CMD_ERR_INCOMPLETE;
14534 }
14535
14536 return CMD_SUCCESS;
14537}
14538/* Graceful Restart */
14539
f412b39a 14540DEFUN (show_ip_bgp_attr_info,
718e3744 14541 show_ip_bgp_attr_info_cmd,
bec37ba5 14542 "show [ip] bgp attribute-info",
718e3744 14543 SHOW_STR
14544 IP_STR
14545 BGP_STR
14546 "List all bgp attribute information\n")
14547{
d62a17ae 14548 attr_show_all(vty);
14549 return CMD_SUCCESS;
718e3744 14550}
6b0655a2 14551
03915806
CS
14552static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14553 afi_t afi, safi_t safi,
14554 bool use_json, json_object *json)
53089bec 14555{
14556 struct bgp *bgp;
14557 struct listnode *node;
14558 char *vname;
14559 char buf1[INET6_ADDRSTRLEN];
14560 char *ecom_str;
14561 vpn_policy_direction_t dir;
14562
03915806 14563 if (json) {
b46dfd20
DS
14564 json_object *json_import_vrfs = NULL;
14565 json_object *json_export_vrfs = NULL;
14566
b46dfd20
DS
14567 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14568
53089bec 14569 if (!bgp) {
75eeda93 14570 vty_json(vty, json);
b46dfd20 14571
53089bec 14572 return CMD_WARNING;
14573 }
b46dfd20 14574
94d4c685
DS
14575 /* Provide context for the block */
14576 json_object_string_add(json, "vrf", name ? name : "default");
14577 json_object_string_add(json, "afiSafi",
5cb5f4d0 14578 get_afi_safi_str(afi, safi, true));
94d4c685 14579
b46dfd20
DS
14580 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14581 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14582 json_object_string_add(json, "importFromVrfs", "none");
14583 json_object_string_add(json, "importRts", "none");
14584 } else {
6ce24e52
DS
14585 json_import_vrfs = json_object_new_array();
14586
b46dfd20
DS
14587 for (ALL_LIST_ELEMENTS_RO(
14588 bgp->vpn_policy[afi].import_vrf,
14589 node, vname))
14590 json_object_array_add(json_import_vrfs,
14591 json_object_new_string(vname));
14592
b20875ea
CS
14593 json_object_object_add(json, "importFromVrfs",
14594 json_import_vrfs);
b46dfd20 14595 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14596 if (bgp->vpn_policy[afi].rtlist[dir]) {
14597 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14598 bgp->vpn_policy[afi].rtlist[dir],
14599 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14600 json_object_string_add(json, "importRts",
14601 ecom_str);
14602 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14603 } else
14604 json_object_string_add(json, "importRts",
14605 "none");
b46dfd20
DS
14606 }
14607
14608 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14609 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14610 json_object_string_add(json, "exportToVrfs", "none");
14611 json_object_string_add(json, "routeDistinguisher",
14612 "none");
14613 json_object_string_add(json, "exportRts", "none");
14614 } else {
6ce24e52
DS
14615 json_export_vrfs = json_object_new_array();
14616
b46dfd20
DS
14617 for (ALL_LIST_ELEMENTS_RO(
14618 bgp->vpn_policy[afi].export_vrf,
14619 node, vname))
14620 json_object_array_add(json_export_vrfs,
14621 json_object_new_string(vname));
14622 json_object_object_add(json, "exportToVrfs",
14623 json_export_vrfs);
14624 json_object_string_add(json, "routeDistinguisher",
14625 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14626 buf1, RD_ADDRSTRLEN));
14627
14628 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14629 if (bgp->vpn_policy[afi].rtlist[dir]) {
14630 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14631 bgp->vpn_policy[afi].rtlist[dir],
14632 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14633 json_object_string_add(json, "exportRts",
14634 ecom_str);
14635 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14636 } else
14637 json_object_string_add(json, "exportRts",
14638 "none");
b46dfd20
DS
14639 }
14640
03915806 14641 if (use_json) {
75eeda93 14642 vty_json(vty, json);
03915806 14643 }
53089bec 14644 } else {
b46dfd20
DS
14645 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14646
53089bec 14647 if (!bgp) {
b46dfd20 14648 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 14649 return CMD_WARNING;
14650 }
53089bec 14651
b46dfd20
DS
14652 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14653 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14654 vty_out(vty,
14655 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 14656 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14657 else {
14658 vty_out(vty,
14659 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 14660 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14661
14662 for (ALL_LIST_ELEMENTS_RO(
14663 bgp->vpn_policy[afi].import_vrf,
14664 node, vname))
14665 vty_out(vty, " %s\n", vname);
14666
14667 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14668 ecom_str = NULL;
14669 if (bgp->vpn_policy[afi].rtlist[dir]) {
14670 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14671 bgp->vpn_policy[afi].rtlist[dir],
14672 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 14673 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 14674
b20875ea
CS
14675 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14676 } else
14677 vty_out(vty, "Import RT(s):\n");
53089bec 14678 }
53089bec 14679
b46dfd20
DS
14680 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14681 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14682 vty_out(vty,
14683 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 14684 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14685 else {
14686 vty_out(vty,
04c9077f 14687 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 14688 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14689
14690 for (ALL_LIST_ELEMENTS_RO(
14691 bgp->vpn_policy[afi].export_vrf,
14692 node, vname))
14693 vty_out(vty, " %s\n", vname);
14694
14695 vty_out(vty, "RD: %s\n",
14696 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14697 buf1, RD_ADDRSTRLEN));
14698
14699 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14700 if (bgp->vpn_policy[afi].rtlist[dir]) {
14701 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14702 bgp->vpn_policy[afi].rtlist[dir],
14703 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14704 vty_out(vty, "Export RT: %s\n", ecom_str);
14705 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14706 } else
14707 vty_out(vty, "Import RT(s):\n");
53089bec 14708 }
53089bec 14709 }
14710
14711 return CMD_SUCCESS;
14712}
14713
03915806
CS
14714static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14715 safi_t safi, bool use_json)
14716{
14717 struct listnode *node, *nnode;
14718 struct bgp *bgp;
14719 char *vrf_name = NULL;
14720 json_object *json = NULL;
14721 json_object *json_vrf = NULL;
14722 json_object *json_vrfs = NULL;
14723
14724 if (use_json) {
14725 json = json_object_new_object();
14726 json_vrfs = json_object_new_object();
14727 }
14728
14729 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14730
14731 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14732 vrf_name = bgp->name;
14733
14734 if (use_json) {
14735 json_vrf = json_object_new_object();
14736 } else {
14737 vty_out(vty, "\nInstance %s:\n",
14738 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14739 ? VRF_DEFAULT_NAME : bgp->name);
14740 }
14741 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14742 if (use_json) {
14743 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14744 json_object_object_add(json_vrfs,
14745 VRF_DEFAULT_NAME, json_vrf);
14746 else
14747 json_object_object_add(json_vrfs, vrf_name,
14748 json_vrf);
14749 }
14750 }
14751
14752 if (use_json) {
14753 json_object_object_add(json, "vrfs", json_vrfs);
75eeda93 14754 vty_json(vty, json);
03915806
CS
14755 }
14756
14757 return CMD_SUCCESS;
14758}
14759
53089bec 14760/* "show [ip] bgp route-leak" command. */
14761DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
14762 show_ip_bgp_route_leak_cmd,
14763 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
14764 SHOW_STR
14765 IP_STR
14766 BGP_STR
14767 BGP_INSTANCE_HELP_STR
14768 BGP_AFI_HELP_STR
14769 BGP_SAFI_HELP_STR
14770 "Route leaking information\n"
14771 JSON_STR)
53089bec 14772{
14773 char *vrf = NULL;
14774 afi_t afi = AFI_MAX;
14775 safi_t safi = SAFI_MAX;
14776
9f049418 14777 bool uj = use_json(argc, argv);
53089bec 14778 int idx = 0;
03915806 14779 json_object *json = NULL;
53089bec 14780
14781 /* show [ip] bgp */
14782 if (argv_find(argv, argc, "ip", &idx)) {
14783 afi = AFI_IP;
14784 safi = SAFI_UNICAST;
14785 }
14786 /* [vrf VIEWVRFNAME] */
14787 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
14788 vty_out(vty,
14789 "%% This command is not applicable to BGP views\n");
53089bec 14790 return CMD_WARNING;
14791 }
14792
9a8bdf1c
PG
14793 if (argv_find(argv, argc, "vrf", &idx)) {
14794 vrf = argv[idx + 1]->arg;
14795 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14796 vrf = NULL;
14797 }
53089bec 14798 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
c48349e3 14799 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
53089bec 14800 argv_find_and_parse_safi(argv, argc, &idx, &safi);
53089bec 14801
14802 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
14803 vty_out(vty,
14804 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 14805 return CMD_WARNING;
14806 }
14807
03915806
CS
14808 if (vrf && strmatch(vrf, "all"))
14809 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
14810
14811 if (uj)
14812 json = json_object_new_object();
14813
14814 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 14815}
14816
d62a17ae 14817static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
14818 safi_t safi)
f186de26 14819{
d62a17ae 14820 struct listnode *node, *nnode;
14821 struct bgp *bgp;
f186de26 14822
d62a17ae 14823 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14824 vty_out(vty, "\nInstance %s:\n",
14825 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14826 ? VRF_DEFAULT_NAME
d62a17ae 14827 : bgp->name);
14828 update_group_show(bgp, afi, safi, vty, 0);
14829 }
f186de26 14830}
14831
d62a17ae 14832static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
14833 int safi, uint64_t subgrp_id)
4fb25c53 14834{
d62a17ae 14835 struct bgp *bgp;
4fb25c53 14836
d62a17ae 14837 if (name) {
14838 if (strmatch(name, "all")) {
14839 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
14840 return CMD_SUCCESS;
14841 } else {
14842 bgp = bgp_lookup_by_name(name);
14843 }
14844 } else {
14845 bgp = bgp_get_default();
14846 }
4fb25c53 14847
d62a17ae 14848 if (bgp)
14849 update_group_show(bgp, afi, safi, vty, subgrp_id);
14850 return CMD_SUCCESS;
4fb25c53
DW
14851}
14852
8fe8a7f6
DS
14853DEFUN (show_ip_bgp_updgrps,
14854 show_ip_bgp_updgrps_cmd,
c1a44e43 14855 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 14856 SHOW_STR
14857 IP_STR
14858 BGP_STR
14859 BGP_INSTANCE_HELP_STR
c9e571b4 14860 BGP_AFI_HELP_STR
9bedbb1e 14861 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
14862 "Detailed info about dynamic update groups\n"
14863 "Specific subgroup to display detailed info for\n")
8386ac43 14864{
d62a17ae 14865 char *vrf = NULL;
14866 afi_t afi = AFI_IP6;
14867 safi_t safi = SAFI_UNICAST;
14868 uint64_t subgrp_id = 0;
14869
14870 int idx = 0;
14871
14872 /* show [ip] bgp */
14873 if (argv_find(argv, argc, "ip", &idx))
14874 afi = AFI_IP;
9a8bdf1c
PG
14875 /* [<vrf> VIEWVRFNAME] */
14876 if (argv_find(argv, argc, "vrf", &idx)) {
14877 vrf = argv[idx + 1]->arg;
14878 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14879 vrf = NULL;
14880 } else if (argv_find(argv, argc, "view", &idx))
14881 /* [<view> VIEWVRFNAME] */
14882 vrf = argv[idx + 1]->arg;
d62a17ae 14883 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14884 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14885 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14886 }
5bf15956 14887
d62a17ae 14888 /* get subgroup id, if provided */
14889 idx = argc - 1;
14890 if (argv[idx]->type == VARIABLE_TKN)
14891 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 14892
d62a17ae 14893 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
14894}
14895
f186de26 14896DEFUN (show_bgp_instance_all_ipv6_updgrps,
14897 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 14898 "show [ip] bgp <view|vrf> all update-groups",
f186de26 14899 SHOW_STR
716b2d8a 14900 IP_STR
f186de26 14901 BGP_STR
14902 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 14903 "Detailed info about dynamic update groups\n")
f186de26 14904{
d62a17ae 14905 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
14906 return CMD_SUCCESS;
f186de26 14907}
14908
43d3f4fc
DS
14909DEFUN (show_bgp_l2vpn_evpn_updgrps,
14910 show_bgp_l2vpn_evpn_updgrps_cmd,
14911 "show [ip] bgp l2vpn evpn update-groups",
14912 SHOW_STR
14913 IP_STR
14914 BGP_STR
14915 "l2vpn address family\n"
14916 "evpn sub-address family\n"
14917 "Detailed info about dynamic update groups\n")
14918{
14919 char *vrf = NULL;
14920 uint64_t subgrp_id = 0;
14921
14922 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
14923 return CMD_SUCCESS;
14924}
14925
5bf15956
DW
14926DEFUN (show_bgp_updgrps_stats,
14927 show_bgp_updgrps_stats_cmd,
716b2d8a 14928 "show [ip] bgp update-groups statistics",
3f9c7369 14929 SHOW_STR
716b2d8a 14930 IP_STR
3f9c7369 14931 BGP_STR
0c7b1b01 14932 "Detailed info about dynamic update groups\n"
3f9c7369
DS
14933 "Statistics\n")
14934{
d62a17ae 14935 struct bgp *bgp;
3f9c7369 14936
d62a17ae 14937 bgp = bgp_get_default();
14938 if (bgp)
14939 update_group_show_stats(bgp, vty);
3f9c7369 14940
d62a17ae 14941 return CMD_SUCCESS;
3f9c7369
DS
14942}
14943
8386ac43 14944DEFUN (show_bgp_instance_updgrps_stats,
14945 show_bgp_instance_updgrps_stats_cmd,
18c57037 14946 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 14947 SHOW_STR
716b2d8a 14948 IP_STR
8386ac43 14949 BGP_STR
14950 BGP_INSTANCE_HELP_STR
0c7b1b01 14951 "Detailed info about dynamic update groups\n"
8386ac43 14952 "Statistics\n")
14953{
d62a17ae 14954 int idx_word = 3;
14955 struct bgp *bgp;
8386ac43 14956
d62a17ae 14957 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
14958 if (bgp)
14959 update_group_show_stats(bgp, vty);
8386ac43 14960
d62a17ae 14961 return CMD_SUCCESS;
8386ac43 14962}
14963
d62a17ae 14964static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
14965 afi_t afi, safi_t safi,
14966 const char *what, uint64_t subgrp_id)
3f9c7369 14967{
d62a17ae 14968 struct bgp *bgp;
8386ac43 14969
d62a17ae 14970 if (name)
14971 bgp = bgp_lookup_by_name(name);
14972 else
14973 bgp = bgp_get_default();
8386ac43 14974
d62a17ae 14975 if (bgp) {
14976 if (!strcmp(what, "advertise-queue"))
14977 update_group_show_adj_queue(bgp, afi, safi, vty,
14978 subgrp_id);
14979 else if (!strcmp(what, "advertised-routes"))
14980 update_group_show_advertised(bgp, afi, safi, vty,
14981 subgrp_id);
14982 else if (!strcmp(what, "packet-queue"))
14983 update_group_show_packet_queue(bgp, afi, safi, vty,
14984 subgrp_id);
14985 }
3f9c7369
DS
14986}
14987
dc64bdec
QY
14988DEFPY(show_ip_bgp_instance_updgrps_adj_s,
14989 show_ip_bgp_instance_updgrps_adj_s_cmd,
14990 "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",
14991 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
14992 BGP_SAFI_HELP_STR
14993 "Detailed info about dynamic update groups\n"
14994 "Specific subgroup to display info for\n"
14995 "Advertisement queue\n"
14996 "Announced routes\n"
14997 "Packet queue\n")
3f9c7369 14998{
dc64bdec
QY
14999 uint64_t subgrp_id = 0;
15000 afi_t afiz;
15001 safi_t safiz;
15002 if (sgid)
15003 subgrp_id = strtoull(sgid, NULL, 10);
15004
15005 if (!ip && !afi)
15006 afiz = AFI_IP6;
15007 if (!ip && afi)
15008 afiz = bgp_vty_afi_from_str(afi);
15009 if (ip && !afi)
15010 afiz = AFI_IP;
15011 if (ip && afi) {
15012 afiz = bgp_vty_afi_from_str(afi);
15013 if (afiz != AFI_IP)
15014 vty_out(vty,
15015 "%% Cannot specify both 'ip' and 'ipv6'\n");
15016 return CMD_WARNING;
15017 }
d62a17ae 15018
dc64bdec 15019 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15020
dc64bdec 15021 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15022 return CMD_SUCCESS;
15023}
15024
6f4eacf3
DA
15025static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15026 json_object *json)
d62a17ae 15027{
15028 struct listnode *node, *nnode;
15029 struct prefix *range;
15030 struct peer *conf;
15031 struct peer *peer;
d62a17ae 15032 afi_t afi;
15033 safi_t safi;
15034 const char *peer_status;
d62a17ae 15035 int lr_count;
15036 int dynamic;
6f4eacf3
DA
15037 bool af_cfgd;
15038 json_object *json_peer_group = NULL;
15039 json_object *json_peer_group_afc = NULL;
15040 json_object *json_peer_group_members = NULL;
15041 json_object *json_peer_group_dynamic = NULL;
15042 json_object *json_peer_group_dynamic_af = NULL;
15043 json_object *json_peer_group_ranges = NULL;
d62a17ae 15044
15045 conf = group->conf;
15046
6f4eacf3
DA
15047 if (json) {
15048 json_peer_group = json_object_new_object();
15049 json_peer_group_afc = json_object_new_array();
15050 }
15051
d62a17ae 15052 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3
DA
15053 if (json)
15054 json_object_int_add(json_peer_group, "remoteAs",
15055 conf->as);
15056 else
15057 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15058 group->name, conf->as);
d62a17ae 15059 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3
DA
15060 if (json)
15061 json_object_int_add(json_peer_group, "remoteAs",
15062 group->bgp->as);
15063 else
15064 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15065 group->name, group->bgp->as);
d62a17ae 15066 } else {
6f4eacf3
DA
15067 if (!json)
15068 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 15069 }
f14e6fdb 15070
6f4eacf3
DA
15071 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15072 if (json)
15073 json_object_string_add(json_peer_group, "type",
15074 "internal");
15075 else
15076 vty_out(vty, " Peer-group type is internal\n");
15077 } else {
15078 if (json)
15079 json_object_string_add(json_peer_group, "type",
15080 "external");
15081 else
15082 vty_out(vty, " Peer-group type is external\n");
15083 }
d62a17ae 15084
15085 /* Display AFs configured. */
6f4eacf3
DA
15086 if (!json)
15087 vty_out(vty, " Configured address-families:");
15088
05c7a1cc
QY
15089 FOREACH_AFI_SAFI (afi, safi) {
15090 if (conf->afc[afi][safi]) {
6f4eacf3
DA
15091 af_cfgd = true;
15092 if (json)
15093 json_object_array_add(
15094 json_peer_group_afc,
15095 json_object_new_string(get_afi_safi_str(
15096 afi, safi, false)));
15097 else
15098 vty_out(vty, " %s;",
15099 get_afi_safi_str(afi, safi, false));
d62a17ae 15100 }
05c7a1cc 15101 }
6f4eacf3
DA
15102
15103 if (json) {
15104 json_object_object_add(json_peer_group,
15105 "addressFamiliesConfigured",
15106 json_peer_group_afc);
15107 } else {
15108 if (!af_cfgd)
15109 vty_out(vty, " none\n");
15110 else
15111 vty_out(vty, "\n");
15112 }
d62a17ae 15113
15114 /* Display listen ranges (for dynamic neighbors), if any */
15115 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 15116 lr_count = listcount(group->listen_range[afi]);
15117 if (lr_count) {
6f4eacf3
DA
15118 if (json) {
15119 if (!json_peer_group_dynamic)
15120 json_peer_group_dynamic =
15121 json_object_new_object();
15122
15123 json_peer_group_dynamic_af =
15124 json_object_new_object();
15125 json_peer_group_ranges =
15126 json_object_new_array();
15127 json_object_int_add(json_peer_group_dynamic_af,
15128 "count", lr_count);
15129 } else {
15130 vty_out(vty, " %d %s listen range(s)\n",
15131 lr_count, afi2str(afi));
15132 }
d62a17ae 15133
15134 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
15135 nnode, range)) {
15136 if (json) {
15137 char buf[BUFSIZ];
15138
15139 snprintfrr(buf, sizeof(buf), "%pFX",
15140 range);
15141
15142 json_object_array_add(
15143 json_peer_group_ranges,
15144 json_object_new_string(buf));
15145 } else {
15146 vty_out(vty, " %pFX\n", range);
15147 }
15148 }
15149
15150 if (json) {
15151 json_object_object_add(
15152 json_peer_group_dynamic_af, "ranges",
15153 json_peer_group_ranges);
15154
15155 json_object_object_add(
15156 json_peer_group_dynamic, afi2str(afi),
15157 json_peer_group_dynamic_af);
15158 }
d62a17ae 15159 }
15160 }
f14e6fdb 15161
6f4eacf3
DA
15162 if (json_peer_group_dynamic)
15163 json_object_object_add(json_peer_group, "dynamicRanges",
15164 json_peer_group_dynamic);
15165
d62a17ae 15166 /* Display group members and their status */
15167 if (listcount(group->peer)) {
6f4eacf3
DA
15168 if (json)
15169 json_peer_group_members = json_object_new_object();
15170 else
15171 vty_out(vty, " Peer-group members:\n");
d62a17ae 15172 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15173 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15174 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15175 peer_status = "Idle (Admin)";
15176 else if (CHECK_FLAG(peer->sflags,
15177 PEER_STATUS_PREFIX_OVERFLOW))
15178 peer_status = "Idle (PfxCt)";
15179 else
15180 peer_status = lookup_msg(bgp_status_msg,
15181 peer->status, NULL);
15182
15183 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
15184
15185 if (json) {
15186 json_object *json_peer_group_member =
15187 json_object_new_object();
15188
15189 json_object_string_add(json_peer_group_member,
15190 "status", peer_status);
15191
15192 if (dynamic)
15193 json_object_boolean_true_add(
15194 json_peer_group_member,
15195 "dynamic");
15196
15197 json_object_object_add(json_peer_group_members,
15198 peer->host,
15199 json_peer_group_member);
15200 } else {
15201 vty_out(vty, " %s %s %s \n", peer->host,
15202 dynamic ? "(dynamic)" : "",
15203 peer_status);
15204 }
d62a17ae 15205 }
6f4eacf3
DA
15206 if (json)
15207 json_object_object_add(json_peer_group, "members",
15208 json_peer_group_members);
d62a17ae 15209 }
f14e6fdb 15210
6f4eacf3
DA
15211 if (json)
15212 json_object_object_add(json, group->name, json_peer_group);
15213
d62a17ae 15214 return CMD_SUCCESS;
15215}
15216
ff9959b0 15217static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 15218 const char *group_name, bool uj)
d62a17ae 15219{
ff9959b0 15220 struct bgp *bgp;
d62a17ae 15221 struct listnode *node, *nnode;
15222 struct peer_group *group;
ff9959b0 15223 bool found = false;
6f4eacf3
DA
15224 json_object *json = NULL;
15225
15226 if (uj)
15227 json = json_object_new_object();
ff9959b0
QY
15228
15229 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15230
15231 if (!bgp) {
c48349e3 15232 if (uj)
75eeda93 15233 vty_json(vty, json);
c48349e3 15234 else
6f4eacf3 15235 vty_out(vty, "%% BGP instance not found\n");
6f4eacf3 15236
ff9959b0
QY
15237 return CMD_WARNING;
15238 }
d62a17ae 15239
15240 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15241 if (group_name) {
15242 if (strmatch(group->name, group_name)) {
6f4eacf3 15243 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
15244 found = true;
15245 break;
d62a17ae 15246 }
ff9959b0 15247 } else {
6f4eacf3 15248 bgp_show_one_peer_group(vty, group, json);
d62a17ae 15249 }
f14e6fdb 15250 }
f14e6fdb 15251
6f4eacf3 15252 if (group_name && !found && !uj)
d62a17ae 15253 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15254
c48349e3 15255 if (uj)
75eeda93 15256 vty_json(vty, json);
6f4eacf3 15257
d62a17ae 15258 return CMD_SUCCESS;
f14e6fdb
DS
15259}
15260
6f4eacf3
DA
15261DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15262 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15263 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15264 "Detailed information on BGP peer groups\n"
15265 "Peer group name\n" JSON_STR)
f14e6fdb 15266{
d62a17ae 15267 char *vrf, *pg;
d62a17ae 15268 int idx = 0;
6f4eacf3 15269 bool uj = use_json(argc, argv);
f14e6fdb 15270
a4d82a8a
PZ
15271 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15272 : NULL;
d62a17ae 15273 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15274
6f4eacf3 15275 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 15276}
3f9c7369 15277
d6e3c605 15278
718e3744 15279/* Redistribute VTY commands. */
15280
585f1adc
IR
15281DEFUN (bgp_redistribute_ipv4,
15282 bgp_redistribute_ipv4_cmd,
15283 "redistribute " FRR_IP_REDIST_STR_BGPD,
15284 "Redistribute information from another routing protocol\n"
15285 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 15286{
585f1adc 15287 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15288 int idx_protocol = 1;
585f1adc 15289 int type;
37a87b8f 15290
585f1adc
IR
15291 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15292 if (type < 0) {
15293 vty_out(vty, "%% Invalid route type\n");
15294 return CMD_WARNING_CONFIG_FAILED;
15295 }
7f323236 15296
585f1adc
IR
15297 bgp_redist_add(bgp, AFI_IP, type, 0);
15298 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 15299}
15300
d62a17ae 15301ALIAS_HIDDEN(
15302 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15303 "redistribute " FRR_IP_REDIST_STR_BGPD,
15304 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 15305
585f1adc
IR
15306DEFUN (bgp_redistribute_ipv4_rmap,
15307 bgp_redistribute_ipv4_rmap_cmd,
15308 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15309 "Redistribute information from another routing protocol\n"
15310 FRR_IP_REDIST_HELP_STR_BGPD
15311 "Route map reference\n"
15312 "Pointer to route-map entries\n")
718e3744 15313{
585f1adc 15314 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15315 int idx_protocol = 1;
15316 int idx_word = 3;
585f1adc
IR
15317 int type;
15318 struct bgp_redist *red;
15319 bool changed;
15320 struct route_map *route_map = route_map_lookup_warn_noexist(
15321 vty, argv[idx_word]->arg);
15322
15323 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15324 if (type < 0) {
15325 vty_out(vty, "%% Invalid route type\n");
15326 return CMD_WARNING_CONFIG_FAILED;
15327 }
37a87b8f 15328
585f1adc
IR
15329 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15330 changed =
15331 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15332 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 15333}
15334
d62a17ae 15335ALIAS_HIDDEN(
15336 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15337 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15338 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15339 "Route map reference\n"
15340 "Pointer to route-map entries\n")
596c17ba 15341
585f1adc
IR
15342DEFUN (bgp_redistribute_ipv4_metric,
15343 bgp_redistribute_ipv4_metric_cmd,
15344 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15345 "Redistribute information from another routing protocol\n"
15346 FRR_IP_REDIST_HELP_STR_BGPD
15347 "Metric for redistributed routes\n"
15348 "Default metric\n")
718e3744 15349{
585f1adc 15350 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15351 int idx_protocol = 1;
15352 int idx_number = 3;
585f1adc
IR
15353 int type;
15354 uint32_t metric;
15355 struct bgp_redist *red;
15356 bool changed;
15357
15358 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15359 if (type < 0) {
15360 vty_out(vty, "%% Invalid route type\n");
15361 return CMD_WARNING_CONFIG_FAILED;
15362 }
15363 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15364
585f1adc
IR
15365 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15366 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15367 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15368}
15369
15370ALIAS_HIDDEN(
15371 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15372 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15373 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15374 "Metric for redistributed routes\n"
15375 "Default metric\n")
596c17ba 15376
585f1adc
IR
15377DEFUN (bgp_redistribute_ipv4_rmap_metric,
15378 bgp_redistribute_ipv4_rmap_metric_cmd,
15379 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15380 "Redistribute information from another routing protocol\n"
15381 FRR_IP_REDIST_HELP_STR_BGPD
15382 "Route map reference\n"
15383 "Pointer to route-map entries\n"
15384 "Metric for redistributed routes\n"
15385 "Default metric\n")
718e3744 15386{
585f1adc 15387 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15388 int idx_protocol = 1;
15389 int idx_word = 3;
15390 int idx_number = 5;
585f1adc
IR
15391 int type;
15392 uint32_t metric;
15393 struct bgp_redist *red;
15394 bool changed;
15395 struct route_map *route_map =
15396 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15397
15398 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15399 if (type < 0) {
15400 vty_out(vty, "%% Invalid route type\n");
15401 return CMD_WARNING_CONFIG_FAILED;
15402 }
15403 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15404
585f1adc
IR
15405 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15406 changed =
15407 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15408 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15409 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15410}
15411
15412ALIAS_HIDDEN(
15413 bgp_redistribute_ipv4_rmap_metric,
15414 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15415 "redistribute " FRR_IP_REDIST_STR_BGPD
15416 " route-map WORD metric (0-4294967295)",
15417 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15418 "Route map reference\n"
15419 "Pointer to route-map entries\n"
15420 "Metric for redistributed routes\n"
15421 "Default metric\n")
596c17ba 15422
585f1adc
IR
15423DEFUN (bgp_redistribute_ipv4_metric_rmap,
15424 bgp_redistribute_ipv4_metric_rmap_cmd,
15425 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15426 "Redistribute information from another routing protocol\n"
15427 FRR_IP_REDIST_HELP_STR_BGPD
15428 "Metric for redistributed routes\n"
15429 "Default metric\n"
15430 "Route map reference\n"
15431 "Pointer to route-map entries\n")
718e3744 15432{
585f1adc 15433 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15434 int idx_protocol = 1;
37a87b8f 15435 int idx_number = 3;
585f1adc
IR
15436 int idx_word = 5;
15437 int type;
15438 uint32_t metric;
15439 struct bgp_redist *red;
15440 bool changed;
15441 struct route_map *route_map =
15442 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15443
15444 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15445 if (type < 0) {
15446 vty_out(vty, "%% Invalid route type\n");
15447 return CMD_WARNING_CONFIG_FAILED;
15448 }
15449 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15450
585f1adc
IR
15451 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15452 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15453 changed |=
15454 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15455 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15456}
15457
15458ALIAS_HIDDEN(
15459 bgp_redistribute_ipv4_metric_rmap,
15460 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15461 "redistribute " FRR_IP_REDIST_STR_BGPD
15462 " metric (0-4294967295) route-map WORD",
15463 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15464 "Metric for redistributed routes\n"
15465 "Default metric\n"
15466 "Route map reference\n"
15467 "Pointer to route-map entries\n")
596c17ba 15468
585f1adc
IR
15469DEFUN (bgp_redistribute_ipv4_ospf,
15470 bgp_redistribute_ipv4_ospf_cmd,
15471 "redistribute <ospf|table> (1-65535)",
15472 "Redistribute information from another routing protocol\n"
15473 "Open Shortest Path First (OSPFv2)\n"
15474 "Non-main Kernel Routing Table\n"
15475 "Instance ID/Table ID\n")
7c8ff89e 15476{
585f1adc
IR
15477 VTY_DECLVAR_CONTEXT(bgp, bgp);
15478 int idx_ospf_table = 1;
d62a17ae 15479 int idx_number = 2;
585f1adc
IR
15480 unsigned short instance;
15481 unsigned short protocol;
7c8ff89e 15482
585f1adc 15483 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 15484
585f1adc
IR
15485 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15486 protocol = ZEBRA_ROUTE_OSPF;
15487 else
15488 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 15489
585f1adc
IR
15490 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15491 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
15492}
15493
d62a17ae 15494ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15495 "redistribute <ospf|table> (1-65535)",
15496 "Redistribute information from another routing protocol\n"
15497 "Open Shortest Path First (OSPFv2)\n"
15498 "Non-main Kernel Routing Table\n"
15499 "Instance ID/Table ID\n")
596c17ba 15500
585f1adc
IR
15501DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15502 bgp_redistribute_ipv4_ospf_rmap_cmd,
15503 "redistribute <ospf|table> (1-65535) route-map WORD",
15504 "Redistribute information from another routing protocol\n"
15505 "Open Shortest Path First (OSPFv2)\n"
15506 "Non-main Kernel Routing Table\n"
15507 "Instance ID/Table ID\n"
15508 "Route map reference\n"
15509 "Pointer to route-map entries\n")
7c8ff89e 15510{
585f1adc
IR
15511 VTY_DECLVAR_CONTEXT(bgp, bgp);
15512 int idx_ospf_table = 1;
d62a17ae 15513 int idx_number = 2;
15514 int idx_word = 4;
585f1adc
IR
15515 struct bgp_redist *red;
15516 unsigned short instance;
15517 int protocol;
15518 bool changed;
15519 struct route_map *route_map =
15520 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15521
15522 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15523 protocol = ZEBRA_ROUTE_OSPF;
15524 else
15525 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15526
585f1adc
IR
15527 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15528 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15529 changed =
15530 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15531 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15532}
15533
15534ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15535 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15536 "redistribute <ospf|table> (1-65535) route-map WORD",
15537 "Redistribute information from another routing protocol\n"
15538 "Open Shortest Path First (OSPFv2)\n"
15539 "Non-main Kernel Routing Table\n"
15540 "Instance ID/Table ID\n"
15541 "Route map reference\n"
15542 "Pointer to route-map entries\n")
596c17ba 15543
585f1adc
IR
15544DEFUN (bgp_redistribute_ipv4_ospf_metric,
15545 bgp_redistribute_ipv4_ospf_metric_cmd,
15546 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15547 "Redistribute information from another routing protocol\n"
15548 "Open Shortest Path First (OSPFv2)\n"
15549 "Non-main Kernel Routing Table\n"
15550 "Instance ID/Table ID\n"
15551 "Metric for redistributed routes\n"
15552 "Default metric\n")
7c8ff89e 15553{
585f1adc
IR
15554 VTY_DECLVAR_CONTEXT(bgp, bgp);
15555 int idx_ospf_table = 1;
d62a17ae 15556 int idx_number = 2;
15557 int idx_number_2 = 4;
585f1adc
IR
15558 uint32_t metric;
15559 struct bgp_redist *red;
15560 unsigned short instance;
15561 int protocol;
15562 bool changed;
15563
15564 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15565 protocol = ZEBRA_ROUTE_OSPF;
15566 else
15567 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15568
585f1adc
IR
15569 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15570 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15571
585f1adc
IR
15572 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15573 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15574 metric);
15575 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15576}
15577
15578ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15579 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15580 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15581 "Redistribute information from another routing protocol\n"
15582 "Open Shortest Path First (OSPFv2)\n"
15583 "Non-main Kernel Routing Table\n"
15584 "Instance ID/Table ID\n"
15585 "Metric for redistributed routes\n"
15586 "Default metric\n")
596c17ba 15587
585f1adc
IR
15588DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
15589 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15590 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15591 "Redistribute information from another routing protocol\n"
15592 "Open Shortest Path First (OSPFv2)\n"
15593 "Non-main Kernel Routing Table\n"
15594 "Instance ID/Table ID\n"
15595 "Route map reference\n"
15596 "Pointer to route-map entries\n"
15597 "Metric for redistributed routes\n"
15598 "Default metric\n")
7c8ff89e 15599{
585f1adc
IR
15600 VTY_DECLVAR_CONTEXT(bgp, bgp);
15601 int idx_ospf_table = 1;
d62a17ae 15602 int idx_number = 2;
15603 int idx_word = 4;
15604 int idx_number_2 = 6;
585f1adc
IR
15605 uint32_t metric;
15606 struct bgp_redist *red;
15607 unsigned short instance;
15608 int protocol;
15609 bool changed;
15610 struct route_map *route_map =
15611 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15612
15613 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15614 protocol = ZEBRA_ROUTE_OSPF;
15615 else
15616 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15617
585f1adc
IR
15618 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15619 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15620
585f1adc
IR
15621 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15622 changed =
15623 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15624 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15625 metric);
15626 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15627}
15628
15629ALIAS_HIDDEN(
15630 bgp_redistribute_ipv4_ospf_rmap_metric,
15631 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15632 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15633 "Redistribute information from another routing protocol\n"
15634 "Open Shortest Path First (OSPFv2)\n"
15635 "Non-main Kernel Routing Table\n"
15636 "Instance ID/Table ID\n"
15637 "Route map reference\n"
15638 "Pointer to route-map entries\n"
15639 "Metric for redistributed routes\n"
15640 "Default metric\n")
596c17ba 15641
585f1adc
IR
15642DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
15643 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15644 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15645 "Redistribute information from another routing protocol\n"
15646 "Open Shortest Path First (OSPFv2)\n"
15647 "Non-main Kernel Routing Table\n"
15648 "Instance ID/Table ID\n"
15649 "Metric for redistributed routes\n"
15650 "Default metric\n"
15651 "Route map reference\n"
15652 "Pointer to route-map entries\n")
7c8ff89e 15653{
585f1adc
IR
15654 VTY_DECLVAR_CONTEXT(bgp, bgp);
15655 int idx_ospf_table = 1;
d62a17ae 15656 int idx_number = 2;
15657 int idx_number_2 = 4;
15658 int idx_word = 6;
585f1adc
IR
15659 uint32_t metric;
15660 struct bgp_redist *red;
15661 unsigned short instance;
15662 int protocol;
15663 bool changed;
15664 struct route_map *route_map =
15665 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15666
15667 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15668 protocol = ZEBRA_ROUTE_OSPF;
15669 else
15670 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15671
585f1adc
IR
15672 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15673 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15674
585f1adc
IR
15675 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15676 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15677 metric);
15678 changed |=
15679 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15680 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15681}
15682
15683ALIAS_HIDDEN(
15684 bgp_redistribute_ipv4_ospf_metric_rmap,
15685 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15686 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15687 "Redistribute information from another routing protocol\n"
15688 "Open Shortest Path First (OSPFv2)\n"
15689 "Non-main Kernel Routing Table\n"
15690 "Instance ID/Table ID\n"
15691 "Metric for redistributed routes\n"
15692 "Default metric\n"
15693 "Route map reference\n"
15694 "Pointer to route-map entries\n")
596c17ba 15695
585f1adc
IR
15696DEFUN (no_bgp_redistribute_ipv4_ospf,
15697 no_bgp_redistribute_ipv4_ospf_cmd,
15698 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15699 NO_STR
15700 "Redistribute information from another routing protocol\n"
15701 "Open Shortest Path First (OSPFv2)\n"
15702 "Non-main Kernel Routing Table\n"
15703 "Instance ID/Table ID\n"
15704 "Metric for redistributed routes\n"
15705 "Default metric\n"
15706 "Route map reference\n"
15707 "Pointer to route-map entries\n")
7c8ff89e 15708{
585f1adc
IR
15709 VTY_DECLVAR_CONTEXT(bgp, bgp);
15710 int idx_ospf_table = 2;
d62a17ae 15711 int idx_number = 3;
585f1adc
IR
15712 unsigned short instance;
15713 int protocol;
37a87b8f 15714
585f1adc
IR
15715 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15716 protocol = ZEBRA_ROUTE_OSPF;
15717 else
15718 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15719
585f1adc
IR
15720 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15721 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
d62a17ae 15722}
15723
15724ALIAS_HIDDEN(
15725 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 15726 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15727 NO_STR
15728 "Redistribute information from another routing protocol\n"
15729 "Open Shortest Path First (OSPFv2)\n"
15730 "Non-main Kernel Routing Table\n"
15731 "Instance ID/Table ID\n"
15732 "Metric for redistributed routes\n"
15733 "Default metric\n"
15734 "Route map reference\n"
15735 "Pointer to route-map entries\n")
596c17ba 15736
585f1adc
IR
15737DEFUN (no_bgp_redistribute_ipv4,
15738 no_bgp_redistribute_ipv4_cmd,
15739 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15740 NO_STR
15741 "Redistribute information from another routing protocol\n"
15742 FRR_IP_REDIST_HELP_STR_BGPD
15743 "Metric for redistributed routes\n"
15744 "Default metric\n"
15745 "Route map reference\n"
15746 "Pointer to route-map entries\n")
718e3744 15747{
585f1adc 15748 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15749 int idx_protocol = 2;
585f1adc 15750 int type;
d62a17ae 15751
585f1adc
IR
15752 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15753 if (type < 0) {
15754 vty_out(vty, "%% Invalid route type\n");
15755 return CMD_WARNING_CONFIG_FAILED;
15756 }
15757 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
d62a17ae 15758}
15759
15760ALIAS_HIDDEN(
15761 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15762 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 15763 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15764 NO_STR
15765 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15766 "Metric for redistributed routes\n"
15767 "Default metric\n"
15768 "Route map reference\n"
15769 "Pointer to route-map entries\n")
596c17ba 15770
585f1adc
IR
15771DEFUN (bgp_redistribute_ipv6,
15772 bgp_redistribute_ipv6_cmd,
15773 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15774 "Redistribute information from another routing protocol\n"
15775 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 15776{
585f1adc 15777 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15778 int idx_protocol = 1;
585f1adc 15779 int type;
718e3744 15780
585f1adc
IR
15781 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15782 if (type < 0) {
15783 vty_out(vty, "%% Invalid route type\n");
15784 return CMD_WARNING_CONFIG_FAILED;
15785 }
718e3744 15786
585f1adc
IR
15787 bgp_redist_add(bgp, AFI_IP6, type, 0);
15788 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 15789}
15790
585f1adc
IR
15791DEFUN (bgp_redistribute_ipv6_rmap,
15792 bgp_redistribute_ipv6_rmap_cmd,
15793 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
15794 "Redistribute information from another routing protocol\n"
15795 FRR_IP6_REDIST_HELP_STR_BGPD
15796 "Route map reference\n"
15797 "Pointer to route-map entries\n")
718e3744 15798{
585f1adc 15799 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15800 int idx_protocol = 1;
15801 int idx_word = 3;
585f1adc
IR
15802 int type;
15803 struct bgp_redist *red;
15804 bool changed;
15805 struct route_map *route_map =
15806 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15807
15808 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15809 if (type < 0) {
15810 vty_out(vty, "%% Invalid route type\n");
15811 return CMD_WARNING_CONFIG_FAILED;
15812 }
37a87b8f 15813
585f1adc
IR
15814 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15815 changed =
15816 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15817 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15818}
15819
585f1adc 15820DEFUN (bgp_redistribute_ipv6_metric,
718e3744 15821 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 15822 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 15823 "Redistribute information from another routing protocol\n"
ab0181ee 15824 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 15825 "Metric for redistributed routes\n"
15826 "Default metric\n")
15827{
585f1adc 15828 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15829 int idx_protocol = 1;
15830 int idx_number = 3;
585f1adc
IR
15831 int type;
15832 uint32_t metric;
15833 struct bgp_redist *red;
15834 bool changed;
15835
15836 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15837 if (type < 0) {
15838 vty_out(vty, "%% Invalid route type\n");
15839 return CMD_WARNING_CONFIG_FAILED;
15840 }
15841 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15842
585f1adc
IR
15843 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15844 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
15845 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15846}
15847
585f1adc
IR
15848DEFUN (bgp_redistribute_ipv6_rmap_metric,
15849 bgp_redistribute_ipv6_rmap_metric_cmd,
15850 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15851 "Redistribute information from another routing protocol\n"
15852 FRR_IP6_REDIST_HELP_STR_BGPD
15853 "Route map reference\n"
15854 "Pointer to route-map entries\n"
15855 "Metric for redistributed routes\n"
15856 "Default metric\n")
718e3744 15857{
585f1adc 15858 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15859 int idx_protocol = 1;
15860 int idx_word = 3;
15861 int idx_number = 5;
585f1adc
IR
15862 int type;
15863 uint32_t metric;
15864 struct bgp_redist *red;
15865 bool changed;
15866 struct route_map *route_map =
15867 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15868
15869 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15870 if (type < 0) {
15871 vty_out(vty, "%% Invalid route type\n");
15872 return CMD_WARNING_CONFIG_FAILED;
15873 }
15874 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15875
585f1adc
IR
15876 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15877 changed =
15878 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15879 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
15880 metric);
15881 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15882}
15883
585f1adc
IR
15884DEFUN (bgp_redistribute_ipv6_metric_rmap,
15885 bgp_redistribute_ipv6_metric_rmap_cmd,
15886 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15887 "Redistribute information from another routing protocol\n"
15888 FRR_IP6_REDIST_HELP_STR_BGPD
15889 "Metric for redistributed routes\n"
15890 "Default metric\n"
15891 "Route map reference\n"
15892 "Pointer to route-map entries\n")
718e3744 15893{
585f1adc 15894 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15895 int idx_protocol = 1;
37a87b8f 15896 int idx_number = 3;
585f1adc
IR
15897 int idx_word = 5;
15898 int type;
15899 uint32_t metric;
15900 struct bgp_redist *red;
15901 bool changed;
15902 struct route_map *route_map =
15903 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15904
15905 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15906 if (type < 0) {
15907 vty_out(vty, "%% Invalid route type\n");
15908 return CMD_WARNING_CONFIG_FAILED;
15909 }
15910 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15911
585f1adc
IR
15912 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15913 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
15914 metric);
15915 changed |=
15916 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15917 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15918}
15919
585f1adc
IR
15920DEFUN (no_bgp_redistribute_ipv6,
15921 no_bgp_redistribute_ipv6_cmd,
15922 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15923 NO_STR
15924 "Redistribute information from another routing protocol\n"
15925 FRR_IP6_REDIST_HELP_STR_BGPD
15926 "Metric for redistributed routes\n"
15927 "Default metric\n"
15928 "Route map reference\n"
15929 "Pointer to route-map entries\n")
718e3744 15930{
585f1adc 15931 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15932 int idx_protocol = 2;
585f1adc 15933 int type;
37a87b8f 15934
585f1adc
IR
15935 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15936 if (type < 0) {
15937 vty_out(vty, "%% Invalid route type\n");
15938 return CMD_WARNING_CONFIG_FAILED;
15939 }
718e3744 15940
585f1adc 15941 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
d62a17ae 15942}
15943
4ab46701
AR
15944/* Neighbor update tcp-mss. */
15945static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
15946 const char *tcp_mss_str)
15947{
15948 struct peer *peer;
15949 uint32_t tcp_mss_val = 0;
15950
15951 peer = peer_and_group_lookup_vty(vty, peer_str);
15952 if (!peer)
15953 return CMD_WARNING_CONFIG_FAILED;
15954
15955 if (tcp_mss_str) {
15956 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
15957 peer_tcp_mss_set(peer, tcp_mss_val);
15958 } else {
15959 peer_tcp_mss_unset(peer);
15960 }
15961
15962 return CMD_SUCCESS;
15963}
15964
15965DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
15966 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
15967 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
15968 "TCP max segment size\n"
15969 "TCP MSS value\n")
15970{
15971 int peer_index = 1;
15972 int mss_index = 3;
15973
15974 vty_out(vty,
15975 " Warning: Reset BGP session for tcp-mss value to take effect\n");
15976 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
15977 argv[mss_index]->arg);
15978}
15979
15980DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
15981 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
15982 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
15983 "TCP max segment size\n"
15984 "TCP MSS value\n")
15985{
15986 int peer_index = 2;
15987
15988 vty_out(vty,
15989 " Warning: Reset BGP session for tcp-mss value to take effect\n");
15990 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
15991}
15992
dd65f45e
DL
15993static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
15994 afi_t afi, safi_t safi)
d62a17ae 15995{
15996 int i;
15997
15998 /* Unicast redistribution only. */
15999 if (safi != SAFI_UNICAST)
2b791107 16000 return;
d62a17ae 16001
16002 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16003 /* Redistribute BGP does not make sense. */
16004 if (i != ZEBRA_ROUTE_BGP) {
16005 struct list *red_list;
16006 struct listnode *node;
16007 struct bgp_redist *red;
16008
16009 red_list = bgp->redist[afi][i];
16010 if (!red_list)
16011 continue;
16012
16013 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16014 /* "redistribute" configuration. */
16015 vty_out(vty, " redistribute %s",
16016 zebra_route_string(i));
16017 if (red->instance)
16018 vty_out(vty, " %d", red->instance);
16019 if (red->redist_metric_flag)
16020 vty_out(vty, " metric %u",
16021 red->redist_metric);
16022 if (red->rmap.name)
16023 vty_out(vty, " route-map %s",
16024 red->rmap.name);
16025 vty_out(vty, "\n");
16026 }
16027 }
16028 }
718e3744 16029}
6b0655a2 16030
dd65f45e
DL
16031/* peer-group helpers for config-write */
16032
16033static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16034{
16035 if (!peer_group_active(peer)) {
16036 if (CHECK_FLAG(peer->flags_invert, flag))
16037 return !CHECK_FLAG(peer->flags, flag);
16038 else
16039 return !!CHECK_FLAG(peer->flags, flag);
16040 }
16041
16042 return !!CHECK_FLAG(peer->flags_override, flag);
16043}
16044
16045static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16046 uint32_t flag)
16047{
16048 if (!peer_group_active(peer)) {
16049 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16050 return !peer_af_flag_check(peer, afi, safi, flag);
16051 else
16052 return !!peer_af_flag_check(peer, afi, safi, flag);
16053 }
16054
16055 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16056}
16057
16058static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16059 uint8_t type, int direct)
16060{
16061 struct bgp_filter *filter;
16062
16063 if (peer_group_active(peer))
16064 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16065 type);
16066
16067 filter = &peer->filter[afi][safi];
16068 switch (type) {
16069 case PEER_FT_DISTRIBUTE_LIST:
16070 return !!(filter->dlist[direct].name);
16071 case PEER_FT_FILTER_LIST:
16072 return !!(filter->aslist[direct].name);
16073 case PEER_FT_PREFIX_LIST:
16074 return !!(filter->plist[direct].name);
16075 case PEER_FT_ROUTE_MAP:
16076 return !!(filter->map[direct].name);
16077 case PEER_FT_UNSUPPRESS_MAP:
16078 return !!(filter->usmap.name);
7f7940e6
MK
16079 case PEER_FT_ADVERTISE_MAP:
16080 return !!(filter->advmap.aname
16081 && ((filter->advmap.condition == direct)
16082 && filter->advmap.cname));
dd65f45e
DL
16083 default:
16084 return false;
16085 }
16086}
16087
16088/* Return true if the addpath type is set for peer and different from
16089 * peer-group.
16090 */
3dc339cd
DA
16091static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16092 safi_t safi)
dd65f45e
DL
16093{
16094 enum bgp_addpath_strat type, g_type;
16095
16096 type = peer->addpath_type[afi][safi];
16097
16098 if (type != BGP_ADDPATH_NONE) {
16099 if (peer_group_active(peer)) {
16100 g_type = peer->group->conf->addpath_type[afi][safi];
16101
16102 if (type != g_type)
3dc339cd 16103 return true;
dd65f45e 16104 else
3dc339cd 16105 return false;
dd65f45e
DL
16106 }
16107
3dc339cd 16108 return true;
dd65f45e
DL
16109 }
16110
3dc339cd 16111 return false;
dd65f45e
DL
16112}
16113
b9c7bc5a 16114/* This is part of the address-family block (unicast only) */
dd65f45e 16115static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16116 afi_t afi)
16117{
b9c7bc5a 16118 int indent = 2;
53970de3 16119 uint32_t tovpn_sid_index = 0;
ddb5b488 16120
8a066a70 16121 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16122 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16123 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16124 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16125 bgp->vpn_policy[afi]
bb4f6190 16126 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16127 else
16128 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16129 bgp->vpn_policy[afi]
16130 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16131 }
12a844a5
DS
16132 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16133 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16134 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16135 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16136 return;
16137
e70e9f8e
PZ
16138 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16139 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16140
16141 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16142
16143 } else {
16144 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16145 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16146 bgp->vpn_policy[afi].tovpn_label);
16147 }
ddb5b488 16148 }
53970de3
RS
16149
16150 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16151 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16152 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16153 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16154 } else if (tovpn_sid_index != 0) {
16155 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16156 tovpn_sid_index);
16157 }
16158
ddb5b488
PZ
16159 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16160 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16161 char buf[RD_ADDRSTRLEN];
b9c7bc5a 16162 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
16163 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16164 sizeof(buf)));
16165 }
16166 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16167 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16168
16169 char buf[PREFIX_STRLEN];
16170 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16171 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16172 sizeof(buf))) {
16173
b9c7bc5a
PZ
16174 vty_out(vty, "%*snexthop vpn export %s\n",
16175 indent, "", buf);
ddb5b488
PZ
16176 }
16177 }
16178 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16179 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16180 && ecommunity_cmp(
16181 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16182 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16183
16184 char *b = ecommunity_ecom2str(
16185 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16186 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16187 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16188 XFREE(MTYPE_ECOMMUNITY_STR, b);
16189 } else {
16190 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16191 char *b = ecommunity_ecom2str(
16192 bgp->vpn_policy[afi]
16193 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16194 ECOMMUNITY_FORMAT_ROUTE_MAP,
16195 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16196 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16197 XFREE(MTYPE_ECOMMUNITY_STR, b);
16198 }
16199 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16200 char *b = ecommunity_ecom2str(
16201 bgp->vpn_policy[afi]
16202 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16203 ECOMMUNITY_FORMAT_ROUTE_MAP,
16204 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16205 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16206 XFREE(MTYPE_ECOMMUNITY_STR, b);
16207 }
16208 }
bb4f6190
DS
16209
16210 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16211 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16212 bgp->vpn_policy[afi]
16213 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16214
301ad80a
PG
16215 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16216 char *b = ecommunity_ecom2str(
16217 bgp->vpn_policy[afi]
16218 .import_redirect_rtlist,
16219 ECOMMUNITY_FORMAT_ROUTE_MAP,
16220 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16221
9a659715
PG
16222 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16223 != ECOMMUNITY_SIZE)
c6423c31 16224 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16225 indent, "", b);
16226 else
16227 vty_out(vty, "%*srt redirect import %s\n",
16228 indent, "", b);
301ad80a
PG
16229 XFREE(MTYPE_ECOMMUNITY_STR, b);
16230 }
ddb5b488
PZ
16231}
16232
dd65f45e
DL
16233static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16234 afi_t afi, safi_t safi)
16235{
16236 struct bgp_filter *filter;
16237 char *addr;
16238
16239 addr = peer->host;
16240 filter = &peer->filter[afi][safi];
16241
16242 /* distribute-list. */
16243 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16244 FILTER_IN))
16245 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16246 filter->dlist[FILTER_IN].name);
16247
16248 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16249 FILTER_OUT))
16250 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16251 filter->dlist[FILTER_OUT].name);
16252
16253 /* prefix-list. */
16254 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16255 FILTER_IN))
16256 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16257 filter->plist[FILTER_IN].name);
16258
16259 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16260 FILTER_OUT))
16261 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16262 filter->plist[FILTER_OUT].name);
16263
16264 /* route-map. */
16265 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16266 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16267 filter->map[RMAP_IN].name);
16268
16269 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16270 RMAP_OUT))
16271 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16272 filter->map[RMAP_OUT].name);
16273
16274 /* unsuppress-map */
16275 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16276 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16277 filter->usmap.name);
16278
7f7940e6
MK
16279 /* advertise-map : always applied in OUT direction*/
16280 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16281 CONDITION_NON_EXIST))
16282 vty_out(vty,
16283 " neighbor %s advertise-map %s non-exist-map %s\n",
16284 addr, filter->advmap.aname, filter->advmap.cname);
16285
16286 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16287 CONDITION_EXIST))
16288 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16289 addr, filter->advmap.aname, filter->advmap.cname);
16290
dd65f45e
DL
16291 /* filter-list. */
16292 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16293 FILTER_IN))
16294 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16295 filter->aslist[FILTER_IN].name);
16296
16297 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16298 FILTER_OUT))
16299 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16300 filter->aslist[FILTER_OUT].name);
16301}
16302
16303/* BGP peer configuration display function. */
16304static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16305 struct peer *peer)
16306{
16307 struct peer *g_peer = NULL;
16308 char buf[SU_ADDRSTRLEN];
16309 char *addr;
16310 int if_pg_printed = false;
16311 int if_ras_printed = false;
16312
16313 /* Skip dynamic neighbors. */
16314 if (peer_dynamic_neighbor(peer))
16315 return;
16316
16317 if (peer->conf_if)
16318 addr = peer->conf_if;
16319 else
16320 addr = peer->host;
16321
16322 /************************************
16323 ****** Global to the neighbor ******
16324 ************************************/
16325 if (peer->conf_if) {
16326 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16327 vty_out(vty, " neighbor %s interface v6only", addr);
16328 else
16329 vty_out(vty, " neighbor %s interface", addr);
16330
16331 if (peer_group_active(peer)) {
16332 vty_out(vty, " peer-group %s", peer->group->name);
16333 if_pg_printed = true;
16334 } else if (peer->as_type == AS_SPECIFIED) {
16335 vty_out(vty, " remote-as %u", peer->as);
16336 if_ras_printed = true;
16337 } else if (peer->as_type == AS_INTERNAL) {
16338 vty_out(vty, " remote-as internal");
16339 if_ras_printed = true;
16340 } else if (peer->as_type == AS_EXTERNAL) {
16341 vty_out(vty, " remote-as external");
16342 if_ras_printed = true;
16343 }
16344
16345 vty_out(vty, "\n");
16346 }
16347
16348 /* remote-as and peer-group */
16349 /* peer is a member of a peer-group */
16350 if (peer_group_active(peer)) {
16351 g_peer = peer->group->conf;
16352
16353 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16354 if (peer->as_type == AS_SPECIFIED) {
16355 vty_out(vty, " neighbor %s remote-as %u\n",
16356 addr, peer->as);
16357 } else if (peer->as_type == AS_INTERNAL) {
16358 vty_out(vty,
16359 " neighbor %s remote-as internal\n",
16360 addr);
16361 } else if (peer->as_type == AS_EXTERNAL) {
16362 vty_out(vty,
16363 " neighbor %s remote-as external\n",
16364 addr);
16365 }
16366 }
16367
16368 /* For swpX peers we displayed the peer-group
16369 * via 'neighbor swpX interface peer-group PGNAME' */
16370 if (!if_pg_printed)
16371 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16372 peer->group->name);
16373 }
16374
16375 /* peer is NOT a member of a peer-group */
16376 else {
16377 /* peer is a peer-group, declare the peer-group */
16378 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16379 vty_out(vty, " neighbor %s peer-group\n", addr);
16380 }
16381
16382 if (!if_ras_printed) {
16383 if (peer->as_type == AS_SPECIFIED) {
16384 vty_out(vty, " neighbor %s remote-as %u\n",
16385 addr, peer->as);
16386 } else if (peer->as_type == AS_INTERNAL) {
16387 vty_out(vty,
16388 " neighbor %s remote-as internal\n",
16389 addr);
16390 } else if (peer->as_type == AS_EXTERNAL) {
16391 vty_out(vty,
16392 " neighbor %s remote-as external\n",
16393 addr);
16394 }
16395 }
16396 }
16397
16398 /* local-as */
16399 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16400 vty_out(vty, " neighbor %s local-as %u", addr,
16401 peer->change_local_as);
16402 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16403 vty_out(vty, " no-prepend");
16404 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16405 vty_out(vty, " replace-as");
16406 vty_out(vty, "\n");
16407 }
16408
16409 /* description */
16410 if (peer->desc) {
16411 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16412 }
16413
16414 /* shutdown */
16415 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16416 if (peer->tx_shutdown_message)
16417 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16418 peer->tx_shutdown_message);
16419 else
16420 vty_out(vty, " neighbor %s shutdown\n", addr);
16421 }
16422
8336c896
DA
16423 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16424 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16425 peer->rtt_expected, peer->rtt_keepalive_conf);
16426
dd65f45e 16427 /* bfd */
21bfce98
RZ
16428 if (peer->bfd_config)
16429 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
16430
16431 /* password */
16432 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16433 vty_out(vty, " neighbor %s password %s\n", addr,
16434 peer->password);
16435
16436 /* neighbor solo */
16437 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16438 if (!peer_group_active(peer)) {
16439 vty_out(vty, " neighbor %s solo\n", addr);
16440 }
16441 }
16442
16443 /* BGP port */
16444 if (peer->port != BGP_PORT_DEFAULT) {
16445 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16446 }
16447
16448 /* Local interface name */
16449 if (peer->ifname) {
16450 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16451 }
16452
4ab46701
AR
16453 /* TCP max segment size */
16454 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16455 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16456
dd65f45e
DL
16457 /* passive */
16458 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16459 vty_out(vty, " neighbor %s passive\n", addr);
16460
16461 /* ebgp-multihop */
16462 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
16463 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16464 && peer->ttl == MAXTTL)) {
dd65f45e
DL
16465 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16466 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16467 peer->ttl);
16468 }
16469 }
16470
16471 /* ttl-security hops */
e2521429 16472 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
16473 if (!peer_group_active(peer)
16474 || g_peer->gtsm_hops != peer->gtsm_hops) {
16475 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16476 addr, peer->gtsm_hops);
16477 }
16478 }
16479
16480 /* disable-connected-check */
16481 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16482 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16483
27aa23a4
DA
16484 /* link-bw-encoding-ieee */
16485 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16486 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16487 addr);
16488
d08c0c80
DA
16489 /* extended-optional-parameters */
16490 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16491 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16492 addr);
16493
dd65f45e
DL
16494 /* enforce-first-as */
16495 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16496 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16497
16498 /* update-source */
16499 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16500 if (peer->update_source)
16501 vty_out(vty, " neighbor %s update-source %s\n", addr,
16502 sockunion2str(peer->update_source, buf,
16503 SU_ADDRSTRLEN));
16504 else if (peer->update_if)
16505 vty_out(vty, " neighbor %s update-source %s\n", addr,
16506 peer->update_if);
16507 }
16508
16509 /* advertisement-interval */
16510 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16511 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16512 peer->routeadv);
16513
16514 /* timers */
16515 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16516 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16517 peer->keepalive, peer->holdtime);
16518
16519 /* timers connect */
16520 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16521 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16522 peer->connect);
5d5393b9
DL
16523 /* need special-case handling for changed default values due to
16524 * config profile / version (because there is no "timers bgp connect"
16525 * command, we need to save this per-peer :/)
16526 */
16527 else if (!peer_group_active(peer) && !peer->connect &&
16528 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16529 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16530 peer->bgp->default_connect_retry);
dd65f45e 16531
d43114f3
DS
16532 /* timers delayopen */
16533 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16534 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16535 peer->delayopen);
16536 /* Save config even though flag is not set if default values have been
16537 * changed
16538 */
16539 else if (!peer_group_active(peer) && !peer->delayopen
16540 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16541 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16542 peer->bgp->default_delayopen);
16543
dd65f45e
DL
16544 /* capability dynamic */
16545 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16546 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16547
16548 /* capability extended-nexthop */
16549 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16550 if (!peer->conf_if) {
16551 if (CHECK_FLAG(peer->flags_invert,
16552 PEER_FLAG_CAPABILITY_ENHE))
16553 vty_out(vty,
16554 " no neighbor %s capability extended-nexthop\n",
16555 addr);
16556 else
16557 vty_out(vty,
16558 " neighbor %s capability extended-nexthop\n",
16559 addr);
16560 }
16561 }
16562
16563 /* dont-capability-negotiation */
16564 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16565 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16566
16567 /* override-capability */
16568 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16569 vty_out(vty, " neighbor %s override-capability\n", addr);
16570
16571 /* strict-capability-match */
16572 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16573 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16574
16575 /* Sender side AS path loop detection. */
16576 if (peer->as_path_loop_detection)
16577 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16578 addr);
cfd47646 16579
16580 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16581 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 16582
16583 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16584 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 16585 vty_out(vty,
16586 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
16587 } else if (CHECK_FLAG(
16588 peer->peer_gr_new_status_flag,
16589 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 16590 vty_out(vty,
16591 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
16592 } else if (
16593 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16594 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16595 && !(CHECK_FLAG(
16596 peer->peer_gr_new_status_flag,
16597 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16598 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16599 addr);
cfd47646 16600 }
16601 }
dd65f45e
DL
16602}
16603
16604/* BGP peer configuration display function. */
16605static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16606 struct peer *peer, afi_t afi, safi_t safi)
16607{
16608 struct peer *g_peer = NULL;
16609 char *addr;
16610 bool flag_scomm, flag_secomm, flag_slcomm;
16611
16612 /* Skip dynamic neighbors. */
16613 if (peer_dynamic_neighbor(peer))
16614 return;
16615
16616 if (peer->conf_if)
16617 addr = peer->conf_if;
16618 else
16619 addr = peer->host;
16620
16621 /************************************
16622 ****** Per AF to the neighbor ******
16623 ************************************/
16624 if (peer_group_active(peer)) {
16625 g_peer = peer->group->conf;
16626
16627 /* If the peer-group is active but peer is not, print a 'no
16628 * activate' */
16629 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16630 vty_out(vty, " no neighbor %s activate\n", addr);
16631 }
16632
16633 /* If the peer-group is not active but peer is, print an
16634 'activate' */
16635 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16636 vty_out(vty, " neighbor %s activate\n", addr);
16637 }
16638 } else {
16639 if (peer->afc[afi][safi]) {
38d11af5
TA
16640 if (safi == SAFI_ENCAP)
16641 vty_out(vty, " neighbor %s activate\n", addr);
16642 else if (!bgp->default_af[afi][safi])
dd65f45e
DL
16643 vty_out(vty, " neighbor %s activate\n", addr);
16644 } else {
38d11af5
TA
16645 if (bgp->default_af[afi][safi])
16646 vty_out(vty, " no neighbor %s activate\n",
16647 addr);
dd65f45e
DL
16648 }
16649 }
16650
16651 /* addpath TX knobs */
16652 if (peergroup_af_addpath_check(peer, afi, safi)) {
16653 switch (peer->addpath_type[afi][safi]) {
16654 case BGP_ADDPATH_ALL:
16655 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16656 addr);
16657 break;
16658 case BGP_ADDPATH_BEST_PER_AS:
16659 vty_out(vty,
16660 " neighbor %s addpath-tx-bestpath-per-AS\n",
16661 addr);
16662 break;
16663 case BGP_ADDPATH_MAX:
16664 case BGP_ADDPATH_NONE:
16665 break;
16666 }
16667 }
16668
7c0e4312
DA
16669 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
16670 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
16671
dd65f45e
DL
16672 /* ORF capability. */
16673 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16674 || peergroup_af_flag_check(peer, afi, safi,
16675 PEER_FLAG_ORF_PREFIX_RM)) {
16676 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16677
16678 if (peergroup_af_flag_check(peer, afi, safi,
16679 PEER_FLAG_ORF_PREFIX_SM)
16680 && peergroup_af_flag_check(peer, afi, safi,
16681 PEER_FLAG_ORF_PREFIX_RM))
16682 vty_out(vty, " both");
16683 else if (peergroup_af_flag_check(peer, afi, safi,
16684 PEER_FLAG_ORF_PREFIX_SM))
16685 vty_out(vty, " send");
16686 else
16687 vty_out(vty, " receive");
16688 vty_out(vty, "\n");
16689 }
16690
dd65f45e
DL
16691 /* Route reflector client. */
16692 if (peergroup_af_flag_check(peer, afi, safi,
16693 PEER_FLAG_REFLECTOR_CLIENT)) {
16694 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16695 }
16696
16697 /* next-hop-self force */
16698 if (peergroup_af_flag_check(peer, afi, safi,
16699 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16700 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16701 }
16702
16703 /* next-hop-self */
16704 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16705 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16706 }
16707
16708 /* remove-private-AS */
16709 if (peergroup_af_flag_check(peer, afi, safi,
16710 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16711 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16712 addr);
16713 }
16714
16715 else if (peergroup_af_flag_check(peer, afi, safi,
16716 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16717 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16718 addr);
16719 }
16720
16721 else if (peergroup_af_flag_check(peer, afi, safi,
16722 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16723 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16724 }
16725
16726 else if (peergroup_af_flag_check(peer, afi, safi,
16727 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16728 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16729 }
16730
16731 /* as-override */
16732 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16733 vty_out(vty, " neighbor %s as-override\n", addr);
16734 }
16735
16736 /* send-community print. */
16737 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16738 PEER_FLAG_SEND_COMMUNITY);
16739 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16740 PEER_FLAG_SEND_EXT_COMMUNITY);
16741 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16742 PEER_FLAG_SEND_LARGE_COMMUNITY);
16743
16744 if (flag_scomm && flag_secomm && flag_slcomm) {
16745 vty_out(vty, " no neighbor %s send-community all\n", addr);
16746 } else {
16747 if (flag_scomm)
16748 vty_out(vty, " no neighbor %s send-community\n", addr);
16749 if (flag_secomm)
16750 vty_out(vty,
16751 " no neighbor %s send-community extended\n",
16752 addr);
16753
16754 if (flag_slcomm)
16755 vty_out(vty, " no neighbor %s send-community large\n",
16756 addr);
16757 }
16758
16759 /* Default information */
16760 if (peergroup_af_flag_check(peer, afi, safi,
16761 PEER_FLAG_DEFAULT_ORIGINATE)) {
16762 vty_out(vty, " neighbor %s default-originate", addr);
16763
16764 if (peer->default_rmap[afi][safi].name)
16765 vty_out(vty, " route-map %s",
16766 peer->default_rmap[afi][safi].name);
16767
16768 vty_out(vty, "\n");
16769 }
16770
16771 /* Soft reconfiguration inbound. */
16772 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16773 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16774 addr);
16775 }
16776
16777 /* maximum-prefix. */
16778 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 16779 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
16780 peer->pmax[afi][safi]);
16781
16782 if (peer->pmax_threshold[afi][safi]
16783 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16784 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16785 if (peer_af_flag_check(peer, afi, safi,
16786 PEER_FLAG_MAX_PREFIX_WARNING))
16787 vty_out(vty, " warning-only");
16788 if (peer->pmax_restart[afi][safi])
16789 vty_out(vty, " restart %u",
16790 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
16791 if (peer_af_flag_check(peer, afi, safi,
16792 PEER_FLAG_MAX_PREFIX_FORCE))
16793 vty_out(vty, " force");
dd65f45e
DL
16794
16795 vty_out(vty, "\n");
16796 }
16797
fde246e8
DA
16798 /* maximum-prefix-out */
16799 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 16800 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
16801 addr, peer->pmax_out[afi][safi]);
16802
dd65f45e
DL
16803 /* Route server client. */
16804 if (peergroup_af_flag_check(peer, afi, safi,
16805 PEER_FLAG_RSERVER_CLIENT)) {
16806 vty_out(vty, " neighbor %s route-server-client\n", addr);
16807 }
16808
16809 /* Nexthop-local unchanged. */
16810 if (peergroup_af_flag_check(peer, afi, safi,
16811 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16812 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16813 }
16814
16815 /* allowas-in <1-10> */
16816 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16817 if (peer_af_flag_check(peer, afi, safi,
16818 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16819 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16820 } else if (peer->allowas_in[afi][safi] == 3) {
16821 vty_out(vty, " neighbor %s allowas-in\n", addr);
16822 } else {
16823 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16824 peer->allowas_in[afi][safi]);
16825 }
16826 }
16827
16828 /* weight */
16829 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16830 vty_out(vty, " neighbor %s weight %lu\n", addr,
16831 peer->weight[afi][safi]);
16832
16833 /* Filter. */
16834 bgp_config_write_filter(vty, peer, afi, safi);
16835
16836 /* atribute-unchanged. */
16837 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16838 || (safi != SAFI_EVPN
16839 && peer_af_flag_check(peer, afi, safi,
16840 PEER_FLAG_NEXTHOP_UNCHANGED))
16841 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16842
16843 if (!peer_group_active(peer)
16844 || peergroup_af_flag_check(peer, afi, safi,
16845 PEER_FLAG_AS_PATH_UNCHANGED)
16846 || peergroup_af_flag_check(peer, afi, safi,
16847 PEER_FLAG_NEXTHOP_UNCHANGED)
16848 || peergroup_af_flag_check(peer, afi, safi,
16849 PEER_FLAG_MED_UNCHANGED)) {
16850
16851 vty_out(vty,
16852 " neighbor %s attribute-unchanged%s%s%s\n",
16853 addr,
16854 peer_af_flag_check(peer, afi, safi,
16855 PEER_FLAG_AS_PATH_UNCHANGED)
16856 ? " as-path"
16857 : "",
16858 peer_af_flag_check(peer, afi, safi,
16859 PEER_FLAG_NEXTHOP_UNCHANGED)
16860 ? " next-hop"
16861 : "",
16862 peer_af_flag_check(peer, afi, safi,
16863 PEER_FLAG_MED_UNCHANGED)
16864 ? " med"
16865 : "");
16866 }
16867 }
16868}
16869
16870/* Address family based peer configuration display. */
16871static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
16872 safi_t safi)
16873{
16874 struct peer *peer;
16875 struct peer_group *group;
16876 struct listnode *node, *nnode;
16877
16878
16879 vty_frame(vty, " !\n address-family ");
16880 if (afi == AFI_IP) {
16881 if (safi == SAFI_UNICAST)
16882 vty_frame(vty, "ipv4 unicast");
16883 else if (safi == SAFI_LABELED_UNICAST)
16884 vty_frame(vty, "ipv4 labeled-unicast");
16885 else if (safi == SAFI_MULTICAST)
16886 vty_frame(vty, "ipv4 multicast");
16887 else if (safi == SAFI_MPLS_VPN)
16888 vty_frame(vty, "ipv4 vpn");
16889 else if (safi == SAFI_ENCAP)
16890 vty_frame(vty, "ipv4 encap");
16891 else if (safi == SAFI_FLOWSPEC)
16892 vty_frame(vty, "ipv4 flowspec");
16893 } else if (afi == AFI_IP6) {
16894 if (safi == SAFI_UNICAST)
16895 vty_frame(vty, "ipv6 unicast");
16896 else if (safi == SAFI_LABELED_UNICAST)
16897 vty_frame(vty, "ipv6 labeled-unicast");
16898 else if (safi == SAFI_MULTICAST)
16899 vty_frame(vty, "ipv6 multicast");
16900 else if (safi == SAFI_MPLS_VPN)
16901 vty_frame(vty, "ipv6 vpn");
16902 else if (safi == SAFI_ENCAP)
16903 vty_frame(vty, "ipv6 encap");
16904 else if (safi == SAFI_FLOWSPEC)
16905 vty_frame(vty, "ipv6 flowspec");
16906 } else if (afi == AFI_L2VPN) {
16907 if (safi == SAFI_EVPN)
16908 vty_frame(vty, "l2vpn evpn");
16909 }
16910 vty_frame(vty, "\n");
16911
16912 bgp_config_write_distance(vty, bgp, afi, safi);
16913
16914 bgp_config_write_network(vty, bgp, afi, safi);
16915
16916 bgp_config_write_redistribute(vty, bgp, afi, safi);
16917
8a4e7fe6
DA
16918 /* BGP flag dampening. */
16919 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6c75f4b3 16920 bgp_config_write_damp(vty, afi, safi);
8a4e7fe6 16921
dd65f45e
DL
16922 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
16923 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
16924
16925 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
16926 /* Do not display doppelganger peers */
16927 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16928 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
16929 }
16930
16931 bgp_config_write_maxpaths(vty, bgp, afi, safi);
16932 bgp_config_write_table_map(vty, bgp, afi, safi);
16933
16934 if (safi == SAFI_EVPN)
16935 bgp_config_write_evpn_info(vty, bgp, afi, safi);
16936
16937 if (safi == SAFI_FLOWSPEC)
16938 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
16939
16940 if (safi == SAFI_UNICAST) {
16941 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
16942 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16943 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
16944
16945 vty_out(vty, " export vpn\n");
16946 }
16947 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16948 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
16949
16950 vty_out(vty, " import vpn\n");
16951 }
16952 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16953 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
16954 char *name;
16955
16956 for (ALL_LIST_ELEMENTS_RO(
16957 bgp->vpn_policy[afi].import_vrf, node,
16958 name))
16959 vty_out(vty, " import vrf %s\n", name);
16960 }
16961 }
16962
16963 vty_endframe(vty, " exit-address-family\n");
16964}
16965
16966int bgp_config_write(struct vty *vty)
16967{
16968 struct bgp *bgp;
16969 struct peer_group *group;
16970 struct peer *peer;
16971 struct listnode *node, *nnode;
16972 struct listnode *mnode, *mnnode;
b16bcbba
TA
16973 afi_t afi;
16974 safi_t safi;
dd65f45e
DL
16975
16976 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
16977 vty_out(vty, "bgp route-map delay-timer %u\n",
16978 bm->rmap_update_timer);
16979
d70583f7
D
16980 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
16981 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
16982 if (bm->v_update_delay != bm->v_establish_wait)
16983 vty_out(vty, " %d", bm->v_establish_wait);
16984 vty_out(vty, "\n");
16985 }
16986
9acb67cb
DS
16987 if (bm->wait_for_fib)
16988 vty_out(vty, "bgp suppress-fib-pending\n");
16989
05bd726c 16990 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
16991 vty_out(vty, "bgp graceful-shutdown\n");
16992
c163f297
DS
16993 /* No-RIB (Zebra) option flag configuration */
16994 if (bgp_option_check(BGP_OPT_NO_FIB))
16995 vty_out(vty, "bgp no-rib\n");
16996
ec0acb80 16997 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
e46723a5
DS
16998 vty_out(vty, "no bgp send-extra-data zebra\n");
16999
dd65f45e
DL
17000 /* BGP configuration. */
17001 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17002
17003 /* skip all auto created vrf as they dont have user config */
17004 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17005 continue;
17006
17007 /* Router bgp ASN */
17008 vty_out(vty, "router bgp %u", bgp->as);
17009
17010 if (bgp->name)
17011 vty_out(vty, " %s %s",
17012 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17013 ? "view" : "vrf", bgp->name);
17014 vty_out(vty, "\n");
17015
17016 /* BGP fast-external-failover. */
17017 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17018 vty_out(vty, " no bgp fast-external-failover\n");
17019
17020 /* BGP router ID. */
3a6290bd 17021 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17022 vty_out(vty, " bgp router-id %pI4\n",
17023 &bgp->router_id_static);
dd65f45e 17024
c208c586
S
17025 /* Suppress fib pending */
17026 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17027 vty_out(vty, " bgp suppress-fib-pending\n");
17028
dd65f45e 17029 /* BGP log-neighbor-changes. */
892fedb6 17030 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17031 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17032 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17033 CHECK_FLAG(bgp->flags,
17034 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17035 ? ""
17036 : "no ");
17037
17038 /* BGP configuration. */
892fedb6 17039 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17040 vty_out(vty, " bgp always-compare-med\n");
17041
17042 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17043 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17044 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17045 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17046 CHECK_FLAG(bgp->flags,
17047 BGP_FLAG_EBGP_REQUIRES_POLICY)
17048 ? ""
17049 : "no ");
dd65f45e
DL
17050
17051 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17052 if (bgp->reject_as_sets)
dd65f45e
DL
17053 vty_out(vty, " bgp reject-as-sets\n");
17054
2adac256
DA
17055 /* Suppress duplicate updates if the route actually not changed
17056 */
17057 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17058 != SAVE_BGP_SUPPRESS_DUPLICATES)
17059 vty_out(vty, " %sbgp suppress-duplicates\n",
17060 CHECK_FLAG(bgp->flags,
17061 BGP_FLAG_SUPPRESS_DUPLICATES)
17062 ? ""
17063 : "no ");
17064
b16bcbba
TA
17065 /* BGP default <afi>-<safi> */
17066 FOREACH_AFI_SAFI (afi, safi) {
17067 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17068 if (!bgp->default_af[afi][safi])
17069 vty_out(vty, " no bgp default %s\n",
17070 get_bgp_default_af_flag(afi,
17071 safi));
17072 } else if (bgp->default_af[afi][safi])
17073 vty_out(vty, " bgp default %s\n",
17074 get_bgp_default_af_flag(afi, safi));
17075 }
e84c59af 17076
dd65f45e
DL
17077 /* BGP default local-preference. */
17078 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17079 vty_out(vty, " bgp default local-preference %u\n",
17080 bgp->default_local_pref);
17081
17082 /* BGP default show-hostname */
892fedb6 17083 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17084 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17085 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17086 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17087 ? ""
17088 : "no ");
17089
aef999a2
DA
17090 /* BGP default show-nexthop-hostname */
17091 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17092 != SAVE_BGP_SHOW_HOSTNAME)
17093 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17094 CHECK_FLAG(bgp->flags,
17095 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17096 ? ""
17097 : "no ");
17098
dd65f45e
DL
17099 /* BGP default subgroup-pkt-queue-max. */
17100 if (bgp->default_subgroup_pkt_queue_max
17101 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17102 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17103 bgp->default_subgroup_pkt_queue_max);
17104
17105 /* BGP client-to-client reflection. */
892fedb6 17106 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17107 vty_out(vty, " no bgp client-to-client reflection\n");
17108
17109 /* BGP cluster ID. */
17110 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17111 vty_out(vty, " bgp cluster-id %pI4\n",
17112 &bgp->cluster_id);
dd65f45e
DL
17113
17114 /* Disable ebgp connected nexthop check */
892fedb6 17115 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17116 vty_out(vty,
17117 " bgp disable-ebgp-connected-route-check\n");
17118
17119 /* Confederation identifier*/
17120 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17121 vty_out(vty, " bgp confederation identifier %u\n",
17122 bgp->confed_id);
17123
17124 /* Confederation peer */
17125 if (bgp->confed_peers_cnt > 0) {
17126 int i;
17127
17128 vty_out(vty, " bgp confederation peers");
17129
17130 for (i = 0; i < bgp->confed_peers_cnt; i++)
17131 vty_out(vty, " %u", bgp->confed_peers[i]);
17132
17133 vty_out(vty, "\n");
17134 }
17135
17136 /* BGP deterministic-med. */
892fedb6 17137 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 17138 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 17139 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
17140 CHECK_FLAG(bgp->flags,
17141 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
17142 ? ""
17143 : "no ");
17144
17145 /* BGP update-delay. */
17146 bgp_config_write_update_delay(vty, bgp);
17147
17148 if (bgp->v_maxmed_onstartup
17149 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17150 vty_out(vty, " bgp max-med on-startup %u",
17151 bgp->v_maxmed_onstartup);
17152 if (bgp->maxmed_onstartup_value
17153 != BGP_MAXMED_VALUE_DEFAULT)
17154 vty_out(vty, " %u",
17155 bgp->maxmed_onstartup_value);
17156 vty_out(vty, "\n");
17157 }
17158 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17159 vty_out(vty, " bgp max-med administrative");
17160 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17161 vty_out(vty, " %u", bgp->maxmed_admin_value);
17162 vty_out(vty, "\n");
17163 }
17164
17165 /* write quanta */
17166 bgp_config_write_wpkt_quanta(vty, bgp);
17167 /* read quanta */
17168 bgp_config_write_rpkt_quanta(vty, bgp);
17169
17170 /* coalesce time */
17171 bgp_config_write_coalesce_time(vty, bgp);
17172
05bd726c 17173 /* BGP per-instance graceful-shutdown */
17174 /* BGP-wide settings and per-instance settings are mutually
17175 * exclusive.
17176 */
17177 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17178 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17179 vty_out(vty, " bgp graceful-shutdown\n");
17180
8606be87
DA
17181 /* Long-lived Graceful Restart */
17182 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17183 vty_out(vty,
17184 " bgp long-lived-graceful-restart stale-time %u\n",
17185 bgp->llgr_stale_time);
17186
dd65f45e
DL
17187 /* BGP graceful-restart. */
17188 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17189 vty_out(vty,
17190 " bgp graceful-restart stalepath-time %u\n",
17191 bgp->stalepath_time);
cfd47646 17192
dd65f45e
DL
17193 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17194 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17195 bgp->restart_time);
cfd47646 17196
17197 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17198 vty_out(vty,
17199 " bgp graceful-restart select-defer-time %u\n",
17200 bgp->select_defer_time);
17201
17202 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
17203 vty_out(vty, " bgp graceful-restart\n");
17204
cfd47646 17205 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17206 vty_out(vty, " bgp graceful-restart-disable\n");
17207
dd65f45e 17208 /* BGP graceful-restart Preserve State F bit. */
892fedb6 17209 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
17210 vty_out(vty,
17211 " bgp graceful-restart preserve-fw-state\n");
17212
dc95985f 17213 /* Stale timer for RIB */
17214 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17215 vty_out(vty,
17216 " bgp graceful-restart rib-stale-time %u\n",
17217 bgp->rib_stale_time);
17218
dd65f45e 17219 /* BGP bestpath method. */
892fedb6 17220 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 17221 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 17222 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
17223 vty_out(vty, " bgp bestpath as-path confed\n");
17224
892fedb6
DA
17225 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17226 if (CHECK_FLAG(bgp->flags,
17227 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
17228 vty_out(vty,
17229 " bgp bestpath as-path multipath-relax as-set\n");
17230 } else {
17231 vty_out(vty,
17232 " bgp bestpath as-path multipath-relax\n");
17233 }
17234 }
17235
892fedb6 17236 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17237 vty_out(vty,
17238 " bgp route-reflector allow-outbound-policy\n");
17239 }
892fedb6 17240 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17241 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17242 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17243 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17244 vty_out(vty, " bgp bestpath med");
892fedb6 17245 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17246 vty_out(vty, " confed");
892fedb6
DA
17247 if (CHECK_FLAG(bgp->flags,
17248 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17249 vty_out(vty, " missing-as-worst");
17250 vty_out(vty, "\n");
17251 }
17252
ee88563a
JM
17253 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17254 vty_out(vty,
17255 " bgp bestpath peer-type multipath-relax\n");
17256
f7e1c681 17257 /* Link bandwidth handling. */
17258 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17259 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17260 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17261 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17262 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17263 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17264
dd65f45e 17265 /* BGP network import check. */
892fedb6 17266 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17267 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17268 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17269 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17270 ? ""
17271 : "no ");
17272
17273 /* BGP timers configuration. */
5d5393b9 17274 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 17275 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17276 vty_out(vty, " timers bgp %u %u\n",
17277 bgp->default_keepalive, bgp->default_holdtime);
17278
b042667a
TI
17279 /* BGP minimum holdtime configuration. */
17280 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17281 && bgp->default_min_holdtime != 0)
17282 vty_out(vty, " bgp minimum-holdtime %u\n",
17283 bgp->default_min_holdtime);
17284
389e4f92
QY
17285 /* Conditional advertisement timer configuration */
17286 if (bgp->condition_check_period
17287 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17288 vty_out(vty,
17289 " bgp conditional-advertisement timer %u\n",
17290 bgp->condition_check_period);
17291
dd65f45e
DL
17292 /* peer-group */
17293 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17294 bgp_config_write_peer_global(vty, bgp, group->conf);
17295 }
17296
17297 /* Normal neighbor configuration. */
17298 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17299 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17300 bgp_config_write_peer_global(vty, bgp, peer);
17301 }
17302
17303 /* listen range and limit for dynamic BGP neighbors */
17304 bgp_config_write_listen(vty, bgp);
17305
17306 /*
17307 * BGP default autoshutdown neighbors
17308 *
17309 * This must be placed after any peer and peer-group
17310 * configuration, to avoid setting all peers to shutdown after
17311 * a daemon restart, which is undesired behavior. (see #2286)
17312 */
17313 if (bgp->autoshutdown)
17314 vty_out(vty, " bgp default shutdown\n");
17315
9cf59432
DS
17316 /* BGP instance administrative shutdown */
17317 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17318 vty_out(vty, " bgp shutdown\n");
17319
f852eb98
PG
17320 if (bgp->fast_convergence)
17321 vty_out(vty, " bgp fast-convergence\n");
17322
a0281b2e
HS
17323 if (bgp->srv6_enabled) {
17324 vty_frame(vty, " !\n segment-routing srv6\n");
96db4340 17325 if (strlen(bgp->srv6_locator_name))
a0281b2e
HS
17326 vty_out(vty, " locator %s\n",
17327 bgp->srv6_locator_name);
ff7c3ee1 17328 vty_endframe(vty, " exit\n");
a0281b2e
HS
17329 }
17330
17331
dd65f45e
DL
17332 /* IPv4 unicast configuration. */
17333 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17334
17335 /* IPv4 multicast configuration. */
17336 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17337
17338 /* IPv4 labeled-unicast configuration. */
17339 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17340
17341 /* IPv4 VPN configuration. */
17342 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17343
17344 /* ENCAPv4 configuration. */
17345 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17346
17347 /* FLOWSPEC v4 configuration. */
17348 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17349
17350 /* IPv6 unicast configuration. */
17351 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17352
17353 /* IPv6 multicast configuration. */
17354 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17355
17356 /* IPv6 labeled-unicast configuration. */
17357 bgp_config_write_family(vty, bgp, AFI_IP6,
17358 SAFI_LABELED_UNICAST);
17359
17360 /* IPv6 VPN configuration. */
17361 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17362
17363 /* ENCAPv6 configuration. */
17364 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17365
17366 /* FLOWSPEC v6 configuration. */
17367 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17368
17369 /* EVPN configuration. */
17370 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17371
17372 hook_call(bgp_inst_config_write, bgp, vty);
17373
49e5a4a0 17374#ifdef ENABLE_BGP_VNC
dd65f45e
DL
17375 bgp_rfapi_cfg_write(vty, bgp);
17376#endif
17377
07679ad9 17378 vty_out(vty, "exit\n");
dd65f45e
DL
17379 vty_out(vty, "!\n");
17380 }
17381 return 0;
17382}
17383
ddb5b488 17384
718e3744 17385/* BGP node structure. */
d62a17ae 17386static struct cmd_node bgp_node = {
f4b8291f 17387 .name = "bgp",
62b346ee 17388 .node = BGP_NODE,
24389580 17389 .parent_node = CONFIG_NODE,
62b346ee 17390 .prompt = "%s(config-router)# ",
612c2c15 17391 .config_write = bgp_config_write,
718e3744 17392};
17393
d62a17ae 17394static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 17395 .name = "bgp ipv4 unicast",
62b346ee 17396 .node = BGP_IPV4_NODE,
24389580 17397 .parent_node = BGP_NODE,
62b346ee 17398 .prompt = "%s(config-router-af)# ",
dd2c81b8 17399 .no_xpath = true,
718e3744 17400};
17401
d62a17ae 17402static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 17403 .name = "bgp ipv4 multicast",
62b346ee 17404 .node = BGP_IPV4M_NODE,
24389580 17405 .parent_node = BGP_NODE,
62b346ee 17406 .prompt = "%s(config-router-af)# ",
dd2c81b8 17407 .no_xpath = true,
718e3744 17408};
17409
d62a17ae 17410static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 17411 .name = "bgp ipv4 labeled unicast",
62b346ee 17412 .node = BGP_IPV4L_NODE,
24389580 17413 .parent_node = BGP_NODE,
62b346ee 17414 .prompt = "%s(config-router-af)# ",
dd2c81b8 17415 .no_xpath = true,
f51bae9c
DS
17416};
17417
d62a17ae 17418static struct cmd_node bgp_ipv6_unicast_node = {
a17cfb3f 17419 .name = "bgp ipv6 unicast",
62b346ee 17420 .node = BGP_IPV6_NODE,
24389580 17421 .parent_node = BGP_NODE,
62b346ee 17422 .prompt = "%s(config-router-af)# ",
dd2c81b8 17423 .no_xpath = true,
718e3744 17424};
17425
d62a17ae 17426static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 17427 .name = "bgp ipv6 multicast",
62b346ee 17428 .node = BGP_IPV6M_NODE,
24389580 17429 .parent_node = BGP_NODE,
62b346ee 17430 .prompt = "%s(config-router-af)# ",
dd2c81b8 17431 .no_xpath = true,
25ffbdc1 17432};
17433
d62a17ae 17434static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 17435 .name = "bgp ipv6 labeled unicast",
62b346ee 17436 .node = BGP_IPV6L_NODE,
24389580 17437 .parent_node = BGP_NODE,
62b346ee 17438 .prompt = "%s(config-router-af)# ",
dd2c81b8 17439 .no_xpath = true,
f51bae9c
DS
17440};
17441
62b346ee 17442static struct cmd_node bgp_vpnv4_node = {
f4b8291f 17443 .name = "bgp vpnv4",
62b346ee 17444 .node = BGP_VPNV4_NODE,
24389580 17445 .parent_node = BGP_NODE,
62b346ee 17446 .prompt = "%s(config-router-af)# ",
dd2c81b8 17447 .no_xpath = true,
62b346ee 17448};
6b0655a2 17449
62b346ee 17450static struct cmd_node bgp_vpnv6_node = {
f4b8291f 17451 .name = "bgp vpnv6",
62b346ee 17452 .node = BGP_VPNV6_NODE,
24389580 17453 .parent_node = BGP_NODE,
62b346ee 17454 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 17455 .no_xpath = true,
62b346ee 17456};
8ecd3266 17457
62b346ee 17458static struct cmd_node bgp_evpn_node = {
f4b8291f 17459 .name = "bgp evpn",
62b346ee 17460 .node = BGP_EVPN_NODE,
24389580 17461 .parent_node = BGP_NODE,
62b346ee 17462 .prompt = "%s(config-router-evpn)# ",
dd2c81b8 17463 .no_xpath = true,
62b346ee 17464};
4e0b7b6d 17465
62b346ee 17466static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 17467 .name = "bgp evpn vni",
62b346ee 17468 .node = BGP_EVPN_VNI_NODE,
24389580 17469 .parent_node = BGP_EVPN_NODE,
62b346ee 17470 .prompt = "%s(config-router-af-vni)# ",
62b346ee 17471};
90e60aa7 17472
62b346ee 17473static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 17474 .name = "bgp ipv4 flowspec",
62b346ee 17475 .node = BGP_FLOWSPECV4_NODE,
24389580 17476 .parent_node = BGP_NODE,
62b346ee 17477 .prompt = "%s(config-router-af)# ",
dd2c81b8 17478 .no_xpath = true,
62b346ee 17479};
7c40bf39 17480
62b346ee 17481static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 17482 .name = "bgp ipv6 flowspec",
62b346ee 17483 .node = BGP_FLOWSPECV6_NODE,
24389580 17484 .parent_node = BGP_NODE,
62b346ee 17485 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 17486 .no_xpath = true,
62b346ee 17487};
7c40bf39 17488
bfaab44d
HS
17489static struct cmd_node bgp_srv6_node = {
17490 .name = "bgp srv6",
17491 .node = BGP_SRV6_NODE,
17492 .parent_node = BGP_NODE,
17493 .prompt = "%s(config-router-srv6)# ",
17494};
17495
d62a17ae 17496static void community_list_vty(void);
1f8ae70b 17497
d62a17ae 17498static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 17499{
d62a17ae 17500 struct bgp *bgp;
17501 struct peer *peer;
d62a17ae 17502 struct listnode *lnbgp, *lnpeer;
b8a815e5 17503
d62a17ae 17504 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17505 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17506 /* only provide suggestions on the appropriate input
17507 * token type,
17508 * they'll otherwise show up multiple times */
17509 enum cmd_token_type match_type;
17510 char *name = peer->host;
d48ed3e0 17511
d62a17ae 17512 if (peer->conf_if) {
17513 match_type = VARIABLE_TKN;
17514 name = peer->conf_if;
17515 } else if (strchr(peer->host, ':'))
17516 match_type = IPV6_TKN;
17517 else
17518 match_type = IPV4_TKN;
d48ed3e0 17519
d62a17ae 17520 if (token->type != match_type)
17521 continue;
d48ed3e0 17522
d62a17ae 17523 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17524 }
d62a17ae 17525 }
b8a815e5
DL
17526}
17527
17528static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 17529 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17530 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 17531 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 17532 {.completions = NULL}};
17533
47a306a0
DS
17534static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17535{
17536 struct bgp *bgp;
17537 struct peer_group *group;
17538 struct listnode *lnbgp, *lnpeer;
17539
17540 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17541 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17542 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17543 group->name));
17544 }
17545}
17546
17547static const struct cmd_variable_handler bgp_var_peergroup[] = {
17548 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17549 {.completions = NULL} };
17550
d62a17ae 17551void bgp_vty_init(void)
17552{
17553 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 17554 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 17555
17556 /* Install bgp top node. */
612c2c15
DL
17557 install_node(&bgp_node);
17558 install_node(&bgp_ipv4_unicast_node);
17559 install_node(&bgp_ipv4_multicast_node);
17560 install_node(&bgp_ipv4_labeled_unicast_node);
17561 install_node(&bgp_ipv6_unicast_node);
17562 install_node(&bgp_ipv6_multicast_node);
17563 install_node(&bgp_ipv6_labeled_unicast_node);
17564 install_node(&bgp_vpnv4_node);
17565 install_node(&bgp_vpnv6_node);
17566 install_node(&bgp_evpn_node);
17567 install_node(&bgp_evpn_vni_node);
17568 install_node(&bgp_flowspecv4_node);
17569 install_node(&bgp_flowspecv6_node);
bfaab44d 17570 install_node(&bgp_srv6_node);
d62a17ae 17571
17572 /* Install default VTY commands to new nodes. */
17573 install_default(BGP_NODE);
17574 install_default(BGP_IPV4_NODE);
17575 install_default(BGP_IPV4M_NODE);
17576 install_default(BGP_IPV4L_NODE);
17577 install_default(BGP_IPV6_NODE);
17578 install_default(BGP_IPV6M_NODE);
17579 install_default(BGP_IPV6L_NODE);
17580 install_default(BGP_VPNV4_NODE);
17581 install_default(BGP_VPNV6_NODE);
7c40bf39 17582 install_default(BGP_FLOWSPECV4_NODE);
17583 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 17584 install_default(BGP_EVPN_NODE);
17585 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 17586 install_default(BGP_SRV6_NODE);
d62a17ae 17587
8029b216
AK
17588 /* "bgp local-mac" hidden commands. */
17589 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17590 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17591
9acb67cb
DS
17592 /* "bgp suppress-fib-pending" global */
17593 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17594
d62a17ae 17595 /* bgp route-map delay-timer commands. */
17596 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17597 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17598
f852eb98
PG
17599 /* bgp fast-convergence command */
17600 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
17601 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
17602
d70583f7
D
17603 /* global bgp update-delay command */
17604 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17605 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17606
05bd726c 17607 /* global bgp graceful-shutdown command */
17608 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17609 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17610
d62a17ae 17611 /* Dummy commands (Currently not supported) */
17612 install_element(BGP_NODE, &no_synchronization_cmd);
17613 install_element(BGP_NODE, &no_auto_summary_cmd);
17614
17615 /* "router bgp" commands. */
17616 install_element(CONFIG_NODE, &router_bgp_cmd);
17617
17618 /* "no router bgp" commands. */
17619 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17620
17621 /* "bgp router-id" commands. */
17622 install_element(BGP_NODE, &bgp_router_id_cmd);
17623 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17624
c208c586
S
17625 /* "bgp suppress-fib-pending" command */
17626 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17627
d62a17ae 17628 /* "bgp cluster-id" commands. */
17629 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17630 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17631
c163f297
DS
17632 /* "bgp no-rib" commands. */
17633 install_element(CONFIG_NODE, &bgp_norib_cmd);
17634 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17635
e46723a5
DS
17636 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17637
d62a17ae 17638 /* "bgp confederation" commands. */
17639 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17640 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17641
17642 /* "bgp confederation peers" commands. */
17643 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17644 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17645
17646 /* bgp max-med command */
17647 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17648 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17649 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17650 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17651 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17652
17653 /* bgp disable-ebgp-connected-nh-check */
17654 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17655 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17656
17657 /* bgp update-delay command */
17658 install_element(BGP_NODE, &bgp_update_delay_cmd);
17659 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 17660
17661 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 17662 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 17663
17664 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17665 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17666
17667 /* "maximum-paths" commands. */
17668 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17669 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17670 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17671 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17672 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17673 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17674 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17675 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17676 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17677 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17678 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17679 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17680 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17681 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17682 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17683
39edabac
PG
17684 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17685 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17686 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17687 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17688 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 17689 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17690 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17691 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17692 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17693 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17694
17695 /* "timers bgp" commands. */
17696 install_element(BGP_NODE, &bgp_timers_cmd);
17697 install_element(BGP_NODE, &no_bgp_timers_cmd);
17698
b042667a
TI
17699 /* "minimum-holdtime" commands. */
17700 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
17701 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
17702
d62a17ae 17703 /* route-map delay-timer commands - per instance for backwards compat.
17704 */
17705 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17706 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17707
17708 /* "bgp client-to-client reflection" commands */
17709 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17710 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17711
17712 /* "bgp always-compare-med" commands */
17713 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17714 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17715
9dac9fc8
DA
17716 /* bgp ebgp-requires-policy */
17717 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17718 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17719
2adac256
DA
17720 /* bgp suppress-duplicates */
17721 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17722 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17723
fb29348a
DA
17724 /* bgp reject-as-sets */
17725 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17726 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17727
d62a17ae 17728 /* "bgp deterministic-med" commands */
17729 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17730 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17731
055679e9 17732 /* "bgp graceful-restart" command */
36235319
QY
17733 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17734 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 17735
17736 /* "bgp graceful-restart-disable" command */
36235319
QY
17737 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17738 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 17739
17740 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
17741 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17742 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 17743
17744 /* "neighbor a:b:c:d graceful-restart-disable" command */
17745 install_element(BGP_NODE,
17746 &bgp_neighbor_graceful_restart_disable_set_cmd);
17747 install_element(BGP_NODE,
17748 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17749
17750 /* "neighbor a:b:c:d graceful-restart-helper" command */
17751 install_element(BGP_NODE,
17752 &bgp_neighbor_graceful_restart_helper_set_cmd);
17753 install_element(BGP_NODE,
17754 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17755
d62a17ae 17756 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17757 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17758 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17759 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 17760 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 17761 install_element(BGP_NODE,
17762 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 17763 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17764 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17765
d6e3c15b 17766 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17767 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 17768 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17769 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 17770
7f323236
DW
17771 /* "bgp graceful-shutdown" commands */
17772 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17773 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17774
8606be87
DA
17775 /* "bgp long-lived-graceful-restart" commands */
17776 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
17777 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
17778
d62a17ae 17779 /* "bgp fast-external-failover" commands */
17780 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17781 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17782
d62a17ae 17783 /* "bgp bestpath compare-routerid" commands */
17784 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17785 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17786
17787 /* "bgp bestpath as-path ignore" commands */
17788 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17789 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17790
17791 /* "bgp bestpath as-path confed" commands */
17792 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17793 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17794
17795 /* "bgp bestpath as-path multipath-relax" commands */
17796 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17797 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17798
ee88563a
JM
17799 /* "bgp bestpath peer-type multipath-relax" commands */
17800 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
17801 install_element(BGP_NODE,
17802 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
17803
d62a17ae 17804 /* "bgp log-neighbor-changes" commands */
17805 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17806 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17807
17808 /* "bgp bestpath med" commands */
17809 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17810 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17811
f7e1c681 17812 /* "bgp bestpath bandwidth" commands */
17813 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 17814 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 17815
b16bcbba
TA
17816 /* "no bgp default <afi>-<safi>" commands. */
17817 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
e84c59af 17818
d62a17ae 17819 /* "bgp network import-check" commands. */
17820 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17821 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17822 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17823
17824 /* "bgp default local-preference" commands. */
17825 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17826 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17827
17828 /* bgp default show-hostname */
17829 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17830 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17831
aef999a2
DA
17832 /* bgp default show-nexthop-hostname */
17833 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17834 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17835
d62a17ae 17836 /* "bgp default subgroup-pkt-queue-max" commands. */
17837 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17838 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17839
17840 /* bgp ibgp-allow-policy-mods command */
17841 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17842 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17843
17844 /* "bgp listen limit" commands. */
17845 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17846 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17847
17848 /* "bgp listen range" commands. */
17849 install_element(BGP_NODE, &bgp_listen_range_cmd);
17850 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17851
8175f54a 17852 /* "bgp default shutdown" command */
f26845f9 17853 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
17854
17855 /* "bgp shutdown" commands */
17856 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 17857 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 17858 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 17859 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 17860
d62a17ae 17861 /* "neighbor remote-as" commands. */
17862 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17863 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17864 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17865 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17866 install_element(BGP_NODE,
17867 &neighbor_interface_v6only_config_remote_as_cmd);
17868 install_element(BGP_NODE, &no_neighbor_cmd);
17869 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17870
17871 /* "neighbor peer-group" commands. */
17872 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17873 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17874 install_element(BGP_NODE,
17875 &no_neighbor_interface_peer_group_remote_as_cmd);
17876
17877 /* "neighbor local-as" commands. */
17878 install_element(BGP_NODE, &neighbor_local_as_cmd);
17879 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17880 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17881 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17882
17883 /* "neighbor solo" commands. */
17884 install_element(BGP_NODE, &neighbor_solo_cmd);
17885 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17886
17887 /* "neighbor password" commands. */
17888 install_element(BGP_NODE, &neighbor_password_cmd);
17889 install_element(BGP_NODE, &no_neighbor_password_cmd);
17890
17891 /* "neighbor activate" commands. */
17892 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17893 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17894 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17895 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17896 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17897 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17898 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17899 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
17900 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 17901 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
17902 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 17903 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
17904
17905 /* "no neighbor activate" commands. */
17906 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
17907 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
17908 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
17909 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
17910 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
17911 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
17912 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
17913 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
17914 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 17915 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
17916 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 17917 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
17918
17919 /* "neighbor peer-group" set commands. */
17920 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
17921 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17922 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
17923 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17924 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
17925 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
17926 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17927 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 17928 install_element(BGP_FLOWSPECV4_NODE,
17929 &neighbor_set_peer_group_hidden_cmd);
17930 install_element(BGP_FLOWSPECV6_NODE,
17931 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 17932
17933 /* "no neighbor peer-group unset" commands. */
17934 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
17935 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17936 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17937 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17938 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17939 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17940 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17941 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 17942 install_element(BGP_FLOWSPECV4_NODE,
17943 &no_neighbor_set_peer_group_hidden_cmd);
17944 install_element(BGP_FLOWSPECV6_NODE,
17945 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 17946
17947 /* "neighbor softreconfiguration inbound" commands.*/
17948 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
17949 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
17950 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
17951 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17952 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
17953 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17954 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
17955 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17956 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
17957 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17958 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
17959 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17960 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
17961 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17962 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
17963 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17964 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
17965 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 17966 install_element(BGP_FLOWSPECV4_NODE,
17967 &neighbor_soft_reconfiguration_cmd);
17968 install_element(BGP_FLOWSPECV4_NODE,
17969 &no_neighbor_soft_reconfiguration_cmd);
17970 install_element(BGP_FLOWSPECV6_NODE,
17971 &neighbor_soft_reconfiguration_cmd);
17972 install_element(BGP_FLOWSPECV6_NODE,
17973 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
17974 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
17975 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 17976
17977 /* "neighbor attribute-unchanged" commands. */
17978 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
17979 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
17980 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
17981 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
17982 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
17983 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
17984 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
17985 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
17986 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
17987 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
17988 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
17989 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
17990 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
17991 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
17992 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
17993 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
17994 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
17995 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
17996
17997 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
17998 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
17999
b8ad84d2
PG
18000 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18001 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18002 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18003 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18004
d62a17ae 18005 /* "nexthop-local unchanged" commands */
18006 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18007 install_element(BGP_IPV6_NODE,
18008 &no_neighbor_nexthop_local_unchanged_cmd);
18009
18010 /* "neighbor next-hop-self" commands. */
18011 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18012 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18013 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18014 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18015 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18016 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18017 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18018 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18019 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18020 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18021 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18022 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18023 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18024 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18025 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18026 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18027 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18028 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
18029 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18030 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 18031
18032 /* "neighbor next-hop-self force" commands. */
18033 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18034 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
18035 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18036 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18037 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18038 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18039 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18040 install_element(BGP_IPV4_NODE,
18041 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18042 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18043 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18044 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18045 install_element(BGP_IPV4M_NODE,
18046 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18047 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18048 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18049 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18050 install_element(BGP_IPV4L_NODE,
18051 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18052 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18053 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18054 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18055 install_element(BGP_IPV6_NODE,
18056 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18057 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18058 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18059 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18060 install_element(BGP_IPV6M_NODE,
18061 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18062 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18063 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18064 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18065 install_element(BGP_IPV6L_NODE,
18066 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18067 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18068 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18069 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18070 install_element(BGP_VPNV4_NODE,
18071 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18072 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18073 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18074 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18075 install_element(BGP_VPNV6_NODE,
18076 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
18077 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18078 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 18079
18080 /* "neighbor as-override" commands. */
18081 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18082 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18083 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18084 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18085 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18086 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18087 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18088 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18089 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18090 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18091 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18092 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18093 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18094 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18095 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18096 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18097 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18098 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18099
18100 /* "neighbor remove-private-AS" commands. */
18101 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18102 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18103 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18104 install_element(BGP_NODE,
18105 &no_neighbor_remove_private_as_all_hidden_cmd);
18106 install_element(BGP_NODE,
18107 &neighbor_remove_private_as_replace_as_hidden_cmd);
18108 install_element(BGP_NODE,
18109 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18110 install_element(BGP_NODE,
18111 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18112 install_element(
18113 BGP_NODE,
18114 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18115 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18116 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18117 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18118 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18119 install_element(BGP_IPV4_NODE,
18120 &neighbor_remove_private_as_replace_as_cmd);
18121 install_element(BGP_IPV4_NODE,
18122 &no_neighbor_remove_private_as_replace_as_cmd);
18123 install_element(BGP_IPV4_NODE,
18124 &neighbor_remove_private_as_all_replace_as_cmd);
18125 install_element(BGP_IPV4_NODE,
18126 &no_neighbor_remove_private_as_all_replace_as_cmd);
18127 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18128 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18129 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18130 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18131 install_element(BGP_IPV4M_NODE,
18132 &neighbor_remove_private_as_replace_as_cmd);
18133 install_element(BGP_IPV4M_NODE,
18134 &no_neighbor_remove_private_as_replace_as_cmd);
18135 install_element(BGP_IPV4M_NODE,
18136 &neighbor_remove_private_as_all_replace_as_cmd);
18137 install_element(BGP_IPV4M_NODE,
18138 &no_neighbor_remove_private_as_all_replace_as_cmd);
18139 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18140 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18141 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18142 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18143 install_element(BGP_IPV4L_NODE,
18144 &neighbor_remove_private_as_replace_as_cmd);
18145 install_element(BGP_IPV4L_NODE,
18146 &no_neighbor_remove_private_as_replace_as_cmd);
18147 install_element(BGP_IPV4L_NODE,
18148 &neighbor_remove_private_as_all_replace_as_cmd);
18149 install_element(BGP_IPV4L_NODE,
18150 &no_neighbor_remove_private_as_all_replace_as_cmd);
18151 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18152 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18153 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18154 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18155 install_element(BGP_IPV6_NODE,
18156 &neighbor_remove_private_as_replace_as_cmd);
18157 install_element(BGP_IPV6_NODE,
18158 &no_neighbor_remove_private_as_replace_as_cmd);
18159 install_element(BGP_IPV6_NODE,
18160 &neighbor_remove_private_as_all_replace_as_cmd);
18161 install_element(BGP_IPV6_NODE,
18162 &no_neighbor_remove_private_as_all_replace_as_cmd);
18163 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18164 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18165 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18166 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18167 install_element(BGP_IPV6M_NODE,
18168 &neighbor_remove_private_as_replace_as_cmd);
18169 install_element(BGP_IPV6M_NODE,
18170 &no_neighbor_remove_private_as_replace_as_cmd);
18171 install_element(BGP_IPV6M_NODE,
18172 &neighbor_remove_private_as_all_replace_as_cmd);
18173 install_element(BGP_IPV6M_NODE,
18174 &no_neighbor_remove_private_as_all_replace_as_cmd);
18175 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18176 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18177 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18178 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18179 install_element(BGP_IPV6L_NODE,
18180 &neighbor_remove_private_as_replace_as_cmd);
18181 install_element(BGP_IPV6L_NODE,
18182 &no_neighbor_remove_private_as_replace_as_cmd);
18183 install_element(BGP_IPV6L_NODE,
18184 &neighbor_remove_private_as_all_replace_as_cmd);
18185 install_element(BGP_IPV6L_NODE,
18186 &no_neighbor_remove_private_as_all_replace_as_cmd);
18187 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18188 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18189 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18190 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18191 install_element(BGP_VPNV4_NODE,
18192 &neighbor_remove_private_as_replace_as_cmd);
18193 install_element(BGP_VPNV4_NODE,
18194 &no_neighbor_remove_private_as_replace_as_cmd);
18195 install_element(BGP_VPNV4_NODE,
18196 &neighbor_remove_private_as_all_replace_as_cmd);
18197 install_element(BGP_VPNV4_NODE,
18198 &no_neighbor_remove_private_as_all_replace_as_cmd);
18199 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18200 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18201 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18202 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18203 install_element(BGP_VPNV6_NODE,
18204 &neighbor_remove_private_as_replace_as_cmd);
18205 install_element(BGP_VPNV6_NODE,
18206 &no_neighbor_remove_private_as_replace_as_cmd);
18207 install_element(BGP_VPNV6_NODE,
18208 &neighbor_remove_private_as_all_replace_as_cmd);
18209 install_element(BGP_VPNV6_NODE,
18210 &no_neighbor_remove_private_as_all_replace_as_cmd);
18211
18212 /* "neighbor send-community" commands.*/
18213 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18214 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18215 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18216 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18217 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18218 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18219 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18220 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18221 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18222 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18223 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18224 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18225 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18226 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18227 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18228 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18229 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18230 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18231 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18232 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18233 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18234 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18235 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18236 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18237 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18238 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18239 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18240 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18241 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18242 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18243 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18244 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18245 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18246 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18247 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18248 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18249
18250 /* "neighbor route-reflector" commands.*/
18251 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18252 install_element(BGP_NODE,
18253 &no_neighbor_route_reflector_client_hidden_cmd);
18254 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18255 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18256 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18257 install_element(BGP_IPV4M_NODE,
18258 &no_neighbor_route_reflector_client_cmd);
18259 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18260 install_element(BGP_IPV4L_NODE,
18261 &no_neighbor_route_reflector_client_cmd);
18262 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18263 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18264 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18265 install_element(BGP_IPV6M_NODE,
18266 &no_neighbor_route_reflector_client_cmd);
18267 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18268 install_element(BGP_IPV6L_NODE,
18269 &no_neighbor_route_reflector_client_cmd);
18270 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18271 install_element(BGP_VPNV4_NODE,
18272 &no_neighbor_route_reflector_client_cmd);
18273 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18274 install_element(BGP_VPNV6_NODE,
18275 &no_neighbor_route_reflector_client_cmd);
7c40bf39 18276 install_element(BGP_FLOWSPECV4_NODE,
18277 &neighbor_route_reflector_client_cmd);
18278 install_element(BGP_FLOWSPECV4_NODE,
18279 &no_neighbor_route_reflector_client_cmd);
18280 install_element(BGP_FLOWSPECV6_NODE,
18281 &neighbor_route_reflector_client_cmd);
18282 install_element(BGP_FLOWSPECV6_NODE,
18283 &no_neighbor_route_reflector_client_cmd);
d62a17ae 18284 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18285 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18286
18287 /* "neighbor route-server" commands.*/
18288 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18289 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18290 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18291 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18292 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18293 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18294 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18295 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18296 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18297 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18298 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18299 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18300 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18301 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18302 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18303 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18304 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18305 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
18306 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18307 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 18308 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18309 install_element(BGP_FLOWSPECV4_NODE,
18310 &no_neighbor_route_server_client_cmd);
18311 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18312 install_element(BGP_FLOWSPECV6_NODE,
18313 &no_neighbor_route_server_client_cmd);
d62a17ae 18314
7c0e4312
DA
18315 /* "neighbor disable-addpath-rx" commands. */
18316 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
18317 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18318 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
18319 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18320 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
18321 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18322 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
18323 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18324 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
18325 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18326 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
18327 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18328 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
18329 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18330 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
18331 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18332
d62a17ae 18333 /* "neighbor addpath-tx-all-paths" commands.*/
18334 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18335 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18336 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18337 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18338 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18339 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18340 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18341 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18342 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18343 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18344 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18345 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18346 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18347 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18348 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18349 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18350 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18351 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18352
18353 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18354 install_element(BGP_NODE,
18355 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18356 install_element(BGP_NODE,
18357 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18358 install_element(BGP_IPV4_NODE,
18359 &neighbor_addpath_tx_bestpath_per_as_cmd);
18360 install_element(BGP_IPV4_NODE,
18361 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18362 install_element(BGP_IPV4M_NODE,
18363 &neighbor_addpath_tx_bestpath_per_as_cmd);
18364 install_element(BGP_IPV4M_NODE,
18365 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18366 install_element(BGP_IPV4L_NODE,
18367 &neighbor_addpath_tx_bestpath_per_as_cmd);
18368 install_element(BGP_IPV4L_NODE,
18369 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18370 install_element(BGP_IPV6_NODE,
18371 &neighbor_addpath_tx_bestpath_per_as_cmd);
18372 install_element(BGP_IPV6_NODE,
18373 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18374 install_element(BGP_IPV6M_NODE,
18375 &neighbor_addpath_tx_bestpath_per_as_cmd);
18376 install_element(BGP_IPV6M_NODE,
18377 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18378 install_element(BGP_IPV6L_NODE,
18379 &neighbor_addpath_tx_bestpath_per_as_cmd);
18380 install_element(BGP_IPV6L_NODE,
18381 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18382 install_element(BGP_VPNV4_NODE,
18383 &neighbor_addpath_tx_bestpath_per_as_cmd);
18384 install_element(BGP_VPNV4_NODE,
18385 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18386 install_element(BGP_VPNV6_NODE,
18387 &neighbor_addpath_tx_bestpath_per_as_cmd);
18388 install_element(BGP_VPNV6_NODE,
18389 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18390
2b31007c
RZ
18391 /* "neighbor sender-as-path-loop-detection" commands. */
18392 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18393 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18394
d62a17ae 18395 /* "neighbor passive" commands. */
18396 install_element(BGP_NODE, &neighbor_passive_cmd);
18397 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18398
18399
18400 /* "neighbor shutdown" commands. */
18401 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18402 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18403 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18404 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
18405 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18406 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 18407
18408 /* "neighbor capability extended-nexthop" commands.*/
18409 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18410 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18411
18412 /* "neighbor capability orf prefix-list" commands.*/
18413 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18414 install_element(BGP_NODE,
18415 &no_neighbor_capability_orf_prefix_hidden_cmd);
18416 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18417 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18418 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18419 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18420 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18421 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18422 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18423 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18424 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18425 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18426 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18427 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18428
18429 /* "neighbor capability dynamic" commands.*/
18430 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18431 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18432
18433 /* "neighbor dont-capability-negotiate" commands. */
18434 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18435 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18436
18437 /* "neighbor ebgp-multihop" commands. */
18438 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18439 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18440 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18441
18442 /* "neighbor disable-connected-check" commands. */
18443 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18444 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18445
7ab294ea
DA
18446 /* "neighbor disable-link-bw-encoding-ieee" commands. */
18447 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
18448 install_element(BGP_NODE,
18449 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
27aa23a4 18450
d08c0c80
DA
18451 /* "neighbor extended-optional-parameters" commands. */
18452 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
18453 install_element(BGP_NODE,
18454 &no_neighbor_extended_optional_parameters_cmd);
18455
47cbc09b
PM
18456 /* "neighbor enforce-first-as" commands. */
18457 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18458 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18459
d62a17ae 18460 /* "neighbor description" commands. */
18461 install_element(BGP_NODE, &neighbor_description_cmd);
18462 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 18463 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 18464
18465 /* "neighbor update-source" commands. "*/
18466 install_element(BGP_NODE, &neighbor_update_source_cmd);
18467 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18468
18469 /* "neighbor default-originate" commands. */
18470 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18471 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18472 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18473 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18474 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18475 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18476 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18477 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18478 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18479 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18480 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18481 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18482 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18483 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18484 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18485 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18486 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18487 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18488 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18489 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18490 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18491
18492 /* "neighbor port" commands. */
18493 install_element(BGP_NODE, &neighbor_port_cmd);
18494 install_element(BGP_NODE, &no_neighbor_port_cmd);
18495
18496 /* "neighbor weight" commands. */
18497 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18498 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18499
18500 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18501 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18502 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18503 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18504 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18505 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18506 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18507 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18508 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18509 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18510 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18511 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18512 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18513 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18514 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18515 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18516
18517 /* "neighbor override-capability" commands. */
18518 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18519 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18520
18521 /* "neighbor strict-capability-match" commands. */
18522 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18523 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18524
18525 /* "neighbor timers" commands. */
18526 install_element(BGP_NODE, &neighbor_timers_cmd);
18527 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18528
18529 /* "neighbor timers connect" commands. */
18530 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18531 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18532
d43114f3
DS
18533 /* "neighbor timers delayopen" commands. */
18534 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18535 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18536
d62a17ae 18537 /* "neighbor advertisement-interval" commands. */
18538 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18539 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18540
18541 /* "neighbor interface" commands. */
18542 install_element(BGP_NODE, &neighbor_interface_cmd);
18543 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18544
18545 /* "neighbor distribute" commands. */
18546 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18547 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18548 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18549 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18550 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18551 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18552 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18553 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18554 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18555 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18556 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18557 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18558 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18559 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18560 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18561 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18562 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18563 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18564
18565 /* "neighbor prefix-list" commands. */
18566 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
642ef664 18567 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
d62a17ae 18568 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18569 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18570 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
642ef664 18571 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18572 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
642ef664 18573 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18574 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18575 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18576 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
642ef664 18577 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18578 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
642ef664 18579 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18580 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18581 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18582 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18583 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18584 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18585 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18586 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18587 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18588
18589 /* "neighbor filter-list" commands. */
18590 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18591 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18592 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18593 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18594 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18595 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18596 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18597 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18598 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18599 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18600 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18601 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18602 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18603 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18604 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18605 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18606 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18607 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 18608 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18609 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18610 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18611 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 18612
18613 /* "neighbor route-map" commands. */
d6d7ed37
IR
18614 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18615 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
d62a17ae 18616 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18617 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18618 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
0ea8d871 18619 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18620 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
0ea8d871 18621 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18622 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18623 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18624 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
0ea8d871 18625 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18626 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
0ea8d871 18627 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18628 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18629 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18630 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18631 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18632 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18633 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18634 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18635 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549 18636 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
0ea8d871 18637 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18638
18639 /* "neighbor unsuppress-map" commands. */
18640 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18641 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18642 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18643 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18644 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18645 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18646 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18647 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18648 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18649 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18650 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18651 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18652 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18653 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18654 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18655 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18656 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18657 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18658
7f7940e6 18659 /* "neighbor advertise-map" commands. */
389e4f92 18660 install_element(BGP_NODE, &bgp_condadv_period_cmd);
7f7940e6 18661 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 18662 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18663 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18664 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18665 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18666 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18667 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18668 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18669 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18670
fde246e8
DA
18671 /* neighbor maximum-prefix-out commands. */
18672 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18673 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18674 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18675 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18676 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18677 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18678 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18679 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18680 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18681 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18682 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18683 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18684 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18685 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18686 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18687 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18688 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18689 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18690
d62a17ae 18691 /* "neighbor maximum-prefix" commands. */
18692 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18693 install_element(BGP_NODE,
18694 &neighbor_maximum_prefix_threshold_hidden_cmd);
18695 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18696 install_element(BGP_NODE,
18697 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18698 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18699 install_element(BGP_NODE,
18700 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18701 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18702 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18703 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18704 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18705 install_element(BGP_IPV4_NODE,
18706 &neighbor_maximum_prefix_threshold_warning_cmd);
18707 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18708 install_element(BGP_IPV4_NODE,
18709 &neighbor_maximum_prefix_threshold_restart_cmd);
18710 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18711 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18712 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18713 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18714 install_element(BGP_IPV4M_NODE,
18715 &neighbor_maximum_prefix_threshold_warning_cmd);
18716 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18717 install_element(BGP_IPV4M_NODE,
18718 &neighbor_maximum_prefix_threshold_restart_cmd);
18719 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18720 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18721 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18722 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18723 install_element(BGP_IPV4L_NODE,
18724 &neighbor_maximum_prefix_threshold_warning_cmd);
18725 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18726 install_element(BGP_IPV4L_NODE,
18727 &neighbor_maximum_prefix_threshold_restart_cmd);
18728 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18729 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18730 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18731 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18732 install_element(BGP_IPV6_NODE,
18733 &neighbor_maximum_prefix_threshold_warning_cmd);
18734 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18735 install_element(BGP_IPV6_NODE,
18736 &neighbor_maximum_prefix_threshold_restart_cmd);
18737 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18738 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18739 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18740 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18741 install_element(BGP_IPV6M_NODE,
18742 &neighbor_maximum_prefix_threshold_warning_cmd);
18743 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18744 install_element(BGP_IPV6M_NODE,
18745 &neighbor_maximum_prefix_threshold_restart_cmd);
18746 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18747 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18748 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18749 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18750 install_element(BGP_IPV6L_NODE,
18751 &neighbor_maximum_prefix_threshold_warning_cmd);
18752 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18753 install_element(BGP_IPV6L_NODE,
18754 &neighbor_maximum_prefix_threshold_restart_cmd);
18755 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18756 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18757 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18758 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18759 install_element(BGP_VPNV4_NODE,
18760 &neighbor_maximum_prefix_threshold_warning_cmd);
18761 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18762 install_element(BGP_VPNV4_NODE,
18763 &neighbor_maximum_prefix_threshold_restart_cmd);
18764 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18765 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18766 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18767 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18768 install_element(BGP_VPNV6_NODE,
18769 &neighbor_maximum_prefix_threshold_warning_cmd);
18770 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18771 install_element(BGP_VPNV6_NODE,
18772 &neighbor_maximum_prefix_threshold_restart_cmd);
18773 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18774
18775 /* "neighbor allowas-in" */
18776 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18777 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18778 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18779 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18780 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18781 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18782 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18783 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18784 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18785 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18786 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18787 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18788 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18789 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18790 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18791 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18792 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18793 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18794 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18795 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18796
18797 /* address-family commands. */
18798 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18799 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 18800#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 18801 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18802 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 18803#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 18804
d62a17ae 18805 install_element(BGP_NODE, &address_family_evpn_cmd);
18806
18807 /* "exit-address-family" command. */
18808 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18809 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18810 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18811 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18812 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18813 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18814 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18815 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 18816 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18817 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 18818 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18819
18820 /* "clear ip bgp commands" */
18821 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18822
18823 /* clear ip bgp prefix */
18824 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18825 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18826 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18827
18828 /* "show [ip] bgp summary" commands. */
18829 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 18830 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 18831 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 18832 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 18833 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18834 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 18835 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18836
18837 /* "show [ip] bgp neighbors" commands. */
18838 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18839
36235319 18840 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 18841
d62a17ae 18842 /* "show [ip] bgp peer-group" commands. */
18843 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18844
18845 /* "show [ip] bgp paths" commands. */
18846 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18847
18848 /* "show [ip] bgp community" commands. */
18849 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18850
18851 /* "show ip bgp large-community" commands. */
18852 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18853 /* "show [ip] bgp attribute-info" commands. */
18854 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 18855 /* "show [ip] bgp route-leak" command */
18856 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 18857
18858 /* "redistribute" commands. */
18859 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18860 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18861 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18862 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18863 install_element(BGP_NODE,
18864 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18865 install_element(BGP_NODE,
18866 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18867 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18868 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18869 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18870 install_element(BGP_NODE,
18871 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18872 install_element(BGP_NODE,
18873 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18874 install_element(BGP_NODE,
18875 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18876 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18877 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18878 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18879 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18880 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18881 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18882 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18883 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18884 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18885 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18886 install_element(BGP_IPV4_NODE,
18887 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18888 install_element(BGP_IPV4_NODE,
18889 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18890 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18891 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18892 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18893 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18894 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18895 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18896
b9c7bc5a
PZ
18897 /* import|export vpn [route-map WORD] */
18898 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18899 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 18900
12a844a5
DS
18901 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18902 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18903
d62a17ae 18904 /* ttl_security commands */
18905 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18906 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18907
18908 /* "show [ip] bgp memory" commands. */
18909 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18910
acf71666
MK
18911 /* "show bgp martian next-hop" */
18912 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18913
48ecf8f5
DS
18914 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18915
d62a17ae 18916 /* "show [ip] bgp views" commands. */
18917 install_element(VIEW_NODE, &show_bgp_views_cmd);
18918
18919 /* "show [ip] bgp vrfs" commands. */
18920 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
18921
18922 /* Community-list. */
18923 community_list_vty();
ddb5b488 18924
ed0e57e3
DA
18925 community_alias_vty();
18926
ddb5b488 18927 /* vpn-policy commands */
b9c7bc5a
PZ
18928 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
18929 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
18930 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
18931 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
18932 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
18933 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
18934 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
18935 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
18936 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
18937 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
18938 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
18939 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 18940
301ad80a
PG
18941 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
18942 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
18943
b9c7bc5a
PZ
18944 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
18945 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
18946 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
18947 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
18948 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
18949 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
18950 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
18951 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
18952 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
18953 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
18954
18955 /* tcp-mss command */
18956 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
18957 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
18958
18959 /* srv6 commands */
ea372e81 18960 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
bfaab44d 18961 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
0249b8b6 18962 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
a0281b2e 18963 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
0249b8b6 18964 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
b72c9e14
HS
18965 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
18966 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
718e3744 18967}
6b0655a2 18968
718e3744 18969#include "memory.h"
18970#include "bgp_regex.h"
18971#include "bgp_clist.h"
18972#include "bgp_ecommunity.h"
18973
18974/* VTY functions. */
18975
18976/* Direction value to string conversion. */
d62a17ae 18977static const char *community_direct_str(int direct)
18978{
18979 switch (direct) {
18980 case COMMUNITY_DENY:
18981 return "deny";
18982 case COMMUNITY_PERMIT:
18983 return "permit";
18984 default:
18985 return "unknown";
18986 }
718e3744 18987}
18988
18989/* Display error string. */
d62a17ae 18990static void community_list_perror(struct vty *vty, int ret)
18991{
18992 switch (ret) {
18993 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
18994 vty_out(vty, "%% Can't find community-list\n");
18995 break;
18996 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
18997 vty_out(vty, "%% Malformed community-list value\n");
18998 break;
18999 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19000 vty_out(vty,
19001 "%% Community name conflict, previously defined as standard community\n");
19002 break;
19003 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19004 vty_out(vty,
19005 "%% Community name conflict, previously defined as expanded community\n");
19006 break;
19007 }
718e3744 19008}
19009
5bf15956
DW
19010/* "community-list" keyword help string. */
19011#define COMMUNITY_LIST_STR "Add a community list entry\n"
19012
7336e101
SP
19013/*community-list standard */
19014DEFUN (community_list_standard,
19015 bgp_community_list_standard_cmd,
a2099c1d 19016 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19017 BGP_STR
718e3744 19018 COMMUNITY_LIST_STR
19019 "Community list number (standard)\n"
5bf15956 19020 "Add an standard community-list entry\n"
718e3744 19021 "Community list name\n"
2f8cc0e5
DA
19022 "Sequence number of an entry\n"
19023 "Sequence number\n"
718e3744 19024 "Specify community to reject\n"
19025 "Specify community to accept\n"
19026 COMMUNITY_VAL_STR)
19027{
d62a17ae 19028 char *cl_name_or_number = NULL;
2f8cc0e5 19029 char *seq = NULL;
d62a17ae 19030 int direct = 0;
19031 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 19032 int idx = 0;
7336e101 19033
a08032fe 19034 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19035 if (idx)
19036 seq = argv[idx]->arg;
19037
19038 idx = 0;
d62a17ae 19039 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19040 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19041 cl_name_or_number = argv[idx]->arg;
19042 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19043 : COMMUNITY_DENY;
19044 argv_find(argv, argc, "AA:NN", &idx);
19045 char *str = argv_concat(argv, argc, idx);
42f914d4 19046
2f8cc0e5
DA
19047 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19048 direct, style);
42f914d4 19049
d62a17ae 19050 XFREE(MTYPE_TMP, str);
42f914d4 19051
d62a17ae 19052 if (ret < 0) {
19053 /* Display error string. */
19054 community_list_perror(vty, ret);
19055 return CMD_WARNING_CONFIG_FAILED;
19056 }
42f914d4 19057
d62a17ae 19058 return CMD_SUCCESS;
718e3744 19059}
19060
7336e101
SP
19061DEFUN (no_community_list_standard_all,
19062 no_bgp_community_list_standard_all_cmd,
a2099c1d 19063 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19064 NO_STR
19065 BGP_STR
19066 COMMUNITY_LIST_STR
19067 "Community list number (standard)\n"
19068 "Add an standard community-list entry\n"
19069 "Community list name\n"
2f8cc0e5
DA
19070 "Sequence number of an entry\n"
19071 "Sequence number\n"
7336e101
SP
19072 "Specify community to reject\n"
19073 "Specify community to accept\n"
19074 COMMUNITY_VAL_STR)
718e3744 19075{
d62a17ae 19076 char *cl_name_or_number = NULL;
174b5cb9 19077 char *str = NULL;
d62a17ae 19078 int direct = 0;
19079 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 19080 char *seq = NULL;
d62a17ae 19081 int idx = 0;
7336e101 19082
a08032fe 19083 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19084 if (idx)
19085 seq = argv[idx]->arg;
19086
19087 idx = 0;
174b5cb9
DA
19088 argv_find(argv, argc, "permit", &idx);
19089 argv_find(argv, argc, "deny", &idx);
19090
19091 if (idx) {
19092 direct = argv_find(argv, argc, "permit", &idx)
19093 ? COMMUNITY_PERMIT
19094 : COMMUNITY_DENY;
19095
19096 idx = 0;
19097 argv_find(argv, argc, "AA:NN", &idx);
19098 str = argv_concat(argv, argc, idx);
19099 }
19100
19101 idx = 0;
d62a17ae 19102 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19103 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19104 cl_name_or_number = argv[idx]->arg;
42f914d4 19105
2f8cc0e5 19106 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19107 direct, style);
42f914d4 19108
d62a17ae 19109 XFREE(MTYPE_TMP, str);
daf9ddbb 19110
d62a17ae 19111 if (ret < 0) {
19112 community_list_perror(vty, ret);
19113 return CMD_WARNING_CONFIG_FAILED;
19114 }
42f914d4 19115
d62a17ae 19116 return CMD_SUCCESS;
718e3744 19117}
7336e101 19118
174b5cb9 19119ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
a2099c1d 19120 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
174b5cb9
DA
19121 NO_STR BGP_STR COMMUNITY_LIST_STR
19122 "Community list number (standard)\n"
19123 "Add an standard community-list entry\n"
19124 "Community list name\n")
19125
7336e101
SP
19126/*community-list expanded */
19127DEFUN (community_list_expanded_all,
19128 bgp_community_list_expanded_all_cmd,
a2099c1d 19129 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19130 BGP_STR
19131 COMMUNITY_LIST_STR
718e3744 19132 "Community list number (expanded)\n"
5bf15956 19133 "Add an expanded community-list entry\n"
718e3744 19134 "Community list name\n"
2f8cc0e5
DA
19135 "Sequence number of an entry\n"
19136 "Sequence number\n"
718e3744 19137 "Specify community to reject\n"
19138 "Specify community to accept\n"
19139 COMMUNITY_VAL_STR)
19140{
d62a17ae 19141 char *cl_name_or_number = NULL;
2f8cc0e5 19142 char *seq = NULL;
d62a17ae 19143 int direct = 0;
19144 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19145 int idx = 0;
7b9a4750 19146
a08032fe 19147 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19148 if (idx)
19149 seq = argv[idx]->arg;
19150
19151 idx = 0;
19152
d62a17ae 19153 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19154 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19155 cl_name_or_number = argv[idx]->arg;
19156 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19157 : COMMUNITY_DENY;
19158 argv_find(argv, argc, "AA:NN", &idx);
19159 char *str = argv_concat(argv, argc, idx);
42f914d4 19160
2f8cc0e5
DA
19161 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19162 direct, style);
42f914d4 19163
d62a17ae 19164 XFREE(MTYPE_TMP, str);
42f914d4 19165
d62a17ae 19166 if (ret < 0) {
19167 /* Display error string. */
19168 community_list_perror(vty, ret);
19169 return CMD_WARNING_CONFIG_FAILED;
19170 }
42f914d4 19171
d62a17ae 19172 return CMD_SUCCESS;
718e3744 19173}
19174
7336e101
SP
19175DEFUN (no_community_list_expanded_all,
19176 no_bgp_community_list_expanded_all_cmd,
a2099c1d 19177 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19178 NO_STR
19179 BGP_STR
19180 COMMUNITY_LIST_STR
19181 "Community list number (expanded)\n"
19182 "Add an expanded community-list entry\n"
19183 "Community list name\n"
2f8cc0e5
DA
19184 "Sequence number of an entry\n"
19185 "Sequence number\n"
7336e101
SP
19186 "Specify community to reject\n"
19187 "Specify community to accept\n"
19188 COMMUNITY_VAL_STR)
718e3744 19189{
d62a17ae 19190 char *cl_name_or_number = NULL;
2f8cc0e5 19191 char *seq = NULL;
174b5cb9 19192 char *str = NULL;
d62a17ae 19193 int direct = 0;
19194 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19195 int idx = 0;
174b5cb9 19196
a08032fe 19197 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19198 if (idx)
19199 seq = argv[idx]->arg;
19200
19201 idx = 0;
174b5cb9
DA
19202 argv_find(argv, argc, "permit", &idx);
19203 argv_find(argv, argc, "deny", &idx);
19204
19205 if (idx) {
19206 direct = argv_find(argv, argc, "permit", &idx)
19207 ? COMMUNITY_PERMIT
19208 : COMMUNITY_DENY;
19209
19210 idx = 0;
19211 argv_find(argv, argc, "AA:NN", &idx);
19212 str = argv_concat(argv, argc, idx);
7336e101 19213 }
174b5cb9
DA
19214
19215 idx = 0;
d62a17ae 19216 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19217 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19218 cl_name_or_number = argv[idx]->arg;
42f914d4 19219
2f8cc0e5 19220 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19221 direct, style);
42f914d4 19222
d62a17ae 19223 XFREE(MTYPE_TMP, str);
daf9ddbb 19224
d62a17ae 19225 if (ret < 0) {
19226 community_list_perror(vty, ret);
19227 return CMD_WARNING_CONFIG_FAILED;
19228 }
42f914d4 19229
d62a17ae 19230 return CMD_SUCCESS;
718e3744 19231}
19232
36d4bb44
EB
19233ALIAS(no_community_list_expanded_all,
19234 no_bgp_community_list_expanded_all_list_cmd,
a2099c1d 19235 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
36d4bb44 19236 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
19237 "Community list number (expanded)\n"
19238 "Add an expanded community-list entry\n"
19239 "Community list name\n")
19240
8d9b8ed9
PM
19241/* Return configuration string of community-list entry. */
19242static const char *community_list_config_str(struct community_entry *entry)
19243{
19244 const char *str;
19245
19246 if (entry->any)
19247 str = "";
19248 else {
19249 if (entry->style == COMMUNITY_LIST_STANDARD)
19250 str = community_str(entry->u.com, false);
19251 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19252 str = lcommunity_str(entry->u.lcom, false);
19253 else
19254 str = entry->config;
19255 }
19256 return str;
19257}
19258
d62a17ae 19259static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 19260{
d62a17ae 19261 struct community_entry *entry;
718e3744 19262
d62a17ae 19263 for (entry = list->head; entry; entry = entry->next) {
19264 if (entry == list->head) {
19265 if (all_digit(list->name))
19266 vty_out(vty, "Community %s list %s\n",
19267 entry->style == COMMUNITY_LIST_STANDARD
19268 ? "standard"
19269 : "(expanded) access",
19270 list->name);
19271 else
19272 vty_out(vty, "Named Community %s list %s\n",
19273 entry->style == COMMUNITY_LIST_STANDARD
19274 ? "standard"
19275 : "expanded",
19276 list->name);
19277 }
19278 if (entry->any)
19279 vty_out(vty, " %s\n",
19280 community_direct_str(entry->direct));
19281 else
19282 vty_out(vty, " %s %s\n",
19283 community_direct_str(entry->direct),
8d9b8ed9 19284 community_list_config_str(entry));
d62a17ae 19285 }
718e3744 19286}
19287
7336e101
SP
19288DEFUN (show_community_list,
19289 show_bgp_community_list_cmd,
19290 "show bgp community-list",
718e3744 19291 SHOW_STR
7336e101 19292 BGP_STR
718e3744 19293 "List community-list\n")
19294{
d62a17ae 19295 struct community_list *list;
19296 struct community_list_master *cm;
718e3744 19297
d62a17ae 19298 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19299 if (!cm)
19300 return CMD_SUCCESS;
718e3744 19301
d62a17ae 19302 for (list = cm->num.head; list; list = list->next)
19303 community_list_show(vty, list);
718e3744 19304
d62a17ae 19305 for (list = cm->str.head; list; list = list->next)
19306 community_list_show(vty, list);
718e3744 19307
d62a17ae 19308 return CMD_SUCCESS;
718e3744 19309}
19310
7336e101
SP
19311DEFUN (show_community_list_arg,
19312 show_bgp_community_list_arg_cmd,
a2099c1d 19313 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
7336e101
SP
19314 SHOW_STR
19315 BGP_STR
718e3744 19316 "List community-list\n"
19317 "Community-list number\n"
960b69b9 19318 "Community-list name\n"
19319 "Detailed information on community-list\n")
718e3744 19320{
d62a17ae 19321 int idx_comm_list = 3;
19322 struct community_list *list;
718e3744 19323
e237b0d2 19324 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19325 COMMUNITY_LIST_MASTER);
19326 if (!list) {
19327 vty_out(vty, "%% Can't find community-list\n");
19328 return CMD_WARNING;
19329 }
718e3744 19330
d62a17ae 19331 community_list_show(vty, list);
718e3744 19332
d62a17ae 19333 return CMD_SUCCESS;
718e3744 19334}
6b0655a2 19335
57d187bc
JS
19336/*
19337 * Large Community code.
19338 */
d62a17ae 19339static int lcommunity_list_set_vty(struct vty *vty, int argc,
19340 struct cmd_token **argv, int style,
19341 int reject_all_digit_name)
19342{
19343 int ret;
19344 int direct;
19345 char *str;
19346 int idx = 0;
19347 char *cl_name;
2f8cc0e5
DA
19348 char *seq = NULL;
19349
a08032fe 19350 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19351 seq = argv[idx]->arg;
d62a17ae 19352
2f8cc0e5 19353 idx = 0;
d62a17ae 19354 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19355 : COMMUNITY_DENY;
19356
19357 /* All digit name check. */
19358 idx = 0;
a2099c1d 19359 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19360 argv_find(argv, argc, "(1-99)", &idx);
19361 argv_find(argv, argc, "(100-500)", &idx);
19362 cl_name = argv[idx]->arg;
19363 if (reject_all_digit_name && all_digit(cl_name)) {
19364 vty_out(vty, "%% Community name cannot have all digits\n");
19365 return CMD_WARNING_CONFIG_FAILED;
19366 }
19367
19368 idx = 0;
19369 argv_find(argv, argc, "AA:BB:CC", &idx);
19370 argv_find(argv, argc, "LINE", &idx);
19371 /* Concat community string argument. */
19372 if (idx)
19373 str = argv_concat(argv, argc, idx);
19374 else
19375 str = NULL;
19376
2f8cc0e5 19377 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 19378
19379 /* Free temporary community list string allocated by
19380 argv_concat(). */
0a22ddfb 19381 XFREE(MTYPE_TMP, str);
d62a17ae 19382
19383 if (ret < 0) {
19384 community_list_perror(vty, ret);
19385 return CMD_WARNING_CONFIG_FAILED;
19386 }
19387 return CMD_SUCCESS;
19388}
19389
19390static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19391 struct cmd_token **argv, int style)
19392{
19393 int ret;
19394 int direct = 0;
19395 char *str = NULL;
19396 int idx = 0;
2f8cc0e5 19397 char *seq = NULL;
d62a17ae 19398
a08032fe 19399 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19400 seq = argv[idx]->arg;
d62a17ae 19401
2f8cc0e5 19402 idx = 0;
d62a17ae 19403 argv_find(argv, argc, "permit", &idx);
19404 argv_find(argv, argc, "deny", &idx);
19405
19406 if (idx) {
19407 /* Check the list direct. */
19408 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19409 direct = COMMUNITY_PERMIT;
19410 else
19411 direct = COMMUNITY_DENY;
19412
19413 idx = 0;
19414 argv_find(argv, argc, "LINE", &idx);
19415 argv_find(argv, argc, "AA:AA:NN", &idx);
19416 /* Concat community string argument. */
19417 str = argv_concat(argv, argc, idx);
19418 }
19419
19420 idx = 0;
19421 argv_find(argv, argc, "(1-99)", &idx);
19422 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19423 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19424
19425 /* Unset community list. */
2f8cc0e5 19426 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 19427 style);
19428
19429 /* Free temporary community list string allocated by
19430 argv_concat(). */
0a22ddfb 19431 XFREE(MTYPE_TMP, str);
d62a17ae 19432
19433 if (ret < 0) {
19434 community_list_perror(vty, ret);
19435 return CMD_WARNING_CONFIG_FAILED;
19436 }
19437
19438 return CMD_SUCCESS;
57d187bc
JS
19439}
19440
19441/* "large-community-list" keyword help string. */
19442#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19443#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19444
7336e101
SP
19445DEFUN (lcommunity_list_standard,
19446 bgp_lcommunity_list_standard_cmd,
a08032fe 19447 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19448 BGP_STR
19449 LCOMMUNITY_LIST_STR
19450 "Large Community list number (standard)\n"
2f8cc0e5
DA
19451 "Sequence number of an entry\n"
19452 "Sequence number\n"
7336e101
SP
19453 "Specify large community to reject\n"
19454 "Specify large community to accept\n"
19455 LCOMMUNITY_VAL_STR)
52951b63 19456{
d62a17ae 19457 return lcommunity_list_set_vty(vty, argc, argv,
19458 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
19459}
19460
7336e101
SP
19461DEFUN (lcommunity_list_expanded,
19462 bgp_lcommunity_list_expanded_cmd,
a08032fe 19463 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19464 BGP_STR
19465 LCOMMUNITY_LIST_STR
19466 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19467 "Sequence number of an entry\n"
19468 "Sequence number\n"
7336e101
SP
19469 "Specify large community to reject\n"
19470 "Specify large community to accept\n"
19471 "An ordered list as a regular-expression\n")
57d187bc 19472{
d62a17ae 19473 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19474 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
19475}
19476
7336e101
SP
19477DEFUN (lcommunity_list_name_standard,
19478 bgp_lcommunity_list_name_standard_cmd,
a2099c1d 19479 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19480 BGP_STR
19481 LCOMMUNITY_LIST_STR
19482 "Specify standard large-community-list\n"
19483 "Large Community list name\n"
2f8cc0e5
DA
19484 "Sequence number of an entry\n"
19485 "Sequence number\n"
7336e101
SP
19486 "Specify large community to reject\n"
19487 "Specify large community to accept\n"
19488 LCOMMUNITY_VAL_STR)
52951b63 19489{
d62a17ae 19490 return lcommunity_list_set_vty(vty, argc, argv,
19491 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
19492}
19493
7336e101
SP
19494DEFUN (lcommunity_list_name_expanded,
19495 bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 19496 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19497 BGP_STR
19498 LCOMMUNITY_LIST_STR
19499 "Specify expanded large-community-list\n"
19500 "Large Community list name\n"
2f8cc0e5
DA
19501 "Sequence number of an entry\n"
19502 "Sequence number\n"
7336e101
SP
19503 "Specify large community to reject\n"
19504 "Specify large community to accept\n"
19505 "An ordered list as a regular-expression\n")
57d187bc 19506{
d62a17ae 19507 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19508 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
19509}
19510
4378f57c
DA
19511DEFUN (no_lcommunity_list_all,
19512 no_bgp_lcommunity_list_all_cmd,
a2099c1d 19513 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
7336e101
SP
19514 NO_STR
19515 BGP_STR
19516 LCOMMUNITY_LIST_STR
19517 "Large Community list number (standard)\n"
19518 "Large Community list number (expanded)\n"
19519 "Large Community list name\n")
57d187bc 19520{
7336e101
SP
19521 return lcommunity_list_unset_vty(vty, argc, argv,
19522 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19523}
19524
4378f57c
DA
19525DEFUN (no_lcommunity_list_name_standard_all,
19526 no_bgp_lcommunity_list_name_standard_all_cmd,
a2099c1d 19527 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
4378f57c
DA
19528 NO_STR
19529 BGP_STR
19530 LCOMMUNITY_LIST_STR
19531 "Specify standard large-community-list\n"
19532 "Large Community list name\n")
19533{
19534 return lcommunity_list_unset_vty(vty, argc, argv,
19535 LARGE_COMMUNITY_LIST_STANDARD);
19536}
19537
7336e101
SP
19538DEFUN (no_lcommunity_list_name_expanded_all,
19539 no_bgp_lcommunity_list_name_expanded_all_cmd,
a2099c1d 19540 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
7336e101
SP
19541 NO_STR
19542 BGP_STR
19543 LCOMMUNITY_LIST_STR
19544 "Specify expanded large-community-list\n"
19545 "Large Community list name\n")
57d187bc 19546{
d62a17ae 19547 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19548 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19549}
19550
7336e101
SP
19551DEFUN (no_lcommunity_list_standard,
19552 no_bgp_lcommunity_list_standard_cmd,
a08032fe 19553 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19554 NO_STR
19555 BGP_STR
19556 LCOMMUNITY_LIST_STR
19557 "Large Community list number (standard)\n"
2f8cc0e5
DA
19558 "Sequence number of an entry\n"
19559 "Sequence number\n"
7336e101
SP
19560 "Specify large community to reject\n"
19561 "Specify large community to accept\n"
19562 LCOMMUNITY_VAL_STR)
57d187bc 19563{
d62a17ae 19564 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19565 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19566}
19567
7336e101
SP
19568DEFUN (no_lcommunity_list_expanded,
19569 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 19570 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19571 NO_STR
19572 BGP_STR
19573 LCOMMUNITY_LIST_STR
19574 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19575 "Sequence number of an entry\n"
19576 "Sequence number\n"
7336e101
SP
19577 "Specify large community to reject\n"
19578 "Specify large community to accept\n"
19579 "An ordered list as a regular-expression\n")
57d187bc 19580{
d62a17ae 19581 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19582 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19583}
19584
7336e101
SP
19585DEFUN (no_lcommunity_list_name_standard,
19586 no_bgp_lcommunity_list_name_standard_cmd,
a2099c1d 19587 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19588 NO_STR
19589 BGP_STR
19590 LCOMMUNITY_LIST_STR
19591 "Specify standard large-community-list\n"
19592 "Large Community list name\n"
2f8cc0e5
DA
19593 "Sequence number of an entry\n"
19594 "Sequence number\n"
7336e101
SP
19595 "Specify large community to reject\n"
19596 "Specify large community to accept\n"
19597 LCOMMUNITY_VAL_STR)
57d187bc 19598{
d62a17ae 19599 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19600 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19601}
19602
7336e101
SP
19603DEFUN (no_lcommunity_list_name_expanded,
19604 no_bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 19605 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19606 NO_STR
19607 BGP_STR
19608 LCOMMUNITY_LIST_STR
19609 "Specify expanded large-community-list\n"
19610 "Large community list name\n"
2f8cc0e5
DA
19611 "Sequence number of an entry\n"
19612 "Sequence number\n"
7336e101
SP
19613 "Specify large community to reject\n"
19614 "Specify large community to accept\n"
19615 "An ordered list as a regular-expression\n")
57d187bc 19616{
d62a17ae 19617 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19618 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19619}
19620
d62a17ae 19621static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19622{
19623 struct community_entry *entry;
19624
19625 for (entry = list->head; entry; entry = entry->next) {
19626 if (entry == list->head) {
19627 if (all_digit(list->name))
19628 vty_out(vty, "Large community %s list %s\n",
169b72c8 19629 entry->style ==
19630 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19631 ? "standard"
19632 : "(expanded) access",
19633 list->name);
19634 else
19635 vty_out(vty,
19636 "Named large community %s list %s\n",
169b72c8 19637 entry->style ==
19638 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19639 ? "standard"
19640 : "expanded",
19641 list->name);
19642 }
19643 if (entry->any)
19644 vty_out(vty, " %s\n",
19645 community_direct_str(entry->direct));
19646 else
19647 vty_out(vty, " %s %s\n",
19648 community_direct_str(entry->direct),
8d9b8ed9 19649 community_list_config_str(entry));
d62a17ae 19650 }
57d187bc
JS
19651}
19652
7336e101
SP
19653DEFUN (show_lcommunity_list,
19654 show_bgp_lcommunity_list_cmd,
19655 "show bgp large-community-list",
57d187bc 19656 SHOW_STR
7336e101 19657 BGP_STR
57d187bc
JS
19658 "List large-community list\n")
19659{
d62a17ae 19660 struct community_list *list;
19661 struct community_list_master *cm;
57d187bc 19662
d62a17ae 19663 cm = community_list_master_lookup(bgp_clist,
19664 LARGE_COMMUNITY_LIST_MASTER);
19665 if (!cm)
19666 return CMD_SUCCESS;
57d187bc 19667
d62a17ae 19668 for (list = cm->num.head; list; list = list->next)
19669 lcommunity_list_show(vty, list);
57d187bc 19670
d62a17ae 19671 for (list = cm->str.head; list; list = list->next)
19672 lcommunity_list_show(vty, list);
57d187bc 19673
d62a17ae 19674 return CMD_SUCCESS;
57d187bc
JS
19675}
19676
7336e101
SP
19677DEFUN (show_lcommunity_list_arg,
19678 show_bgp_lcommunity_list_arg_cmd,
a2099c1d 19679 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
7336e101
SP
19680 SHOW_STR
19681 BGP_STR
57d187bc 19682 "List large-community list\n"
960b69b9 19683 "Large-community-list number\n"
19684 "Large-community-list name\n"
19685 "Detailed information on large-community-list\n")
57d187bc 19686{
d62a17ae 19687 struct community_list *list;
57d187bc 19688
e237b0d2 19689 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 19690 LARGE_COMMUNITY_LIST_MASTER);
19691 if (!list) {
960b69b9 19692 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 19693 return CMD_WARNING;
19694 }
57d187bc 19695
d62a17ae 19696 lcommunity_list_show(vty, list);
57d187bc 19697
d62a17ae 19698 return CMD_SUCCESS;
57d187bc
JS
19699}
19700
718e3744 19701/* "extcommunity-list" keyword help string. */
19702#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19703#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19704
7336e101
SP
19705DEFUN (extcommunity_list_standard,
19706 bgp_extcommunity_list_standard_cmd,
a2099c1d 19707 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19708 BGP_STR
718e3744 19709 EXTCOMMUNITY_LIST_STR
19710 "Extended Community list number (standard)\n"
718e3744 19711 "Specify standard extcommunity-list\n"
5bf15956 19712 "Community list name\n"
2f8cc0e5
DA
19713 "Sequence number of an entry\n"
19714 "Sequence number\n"
718e3744 19715 "Specify community to reject\n"
19716 "Specify community to accept\n"
19717 EXTCOMMUNITY_VAL_STR)
19718{
d62a17ae 19719 int style = EXTCOMMUNITY_LIST_STANDARD;
19720 int direct = 0;
19721 char *cl_number_or_name = NULL;
2f8cc0e5 19722 char *seq = NULL;
42f914d4 19723
d62a17ae 19724 int idx = 0;
7b9a4750 19725
d62a17ae 19726 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19727 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19728 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19729
a08032fe 19730 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19731 seq = argv[idx]->arg;
19732
d62a17ae 19733 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19734 : COMMUNITY_DENY;
19735 argv_find(argv, argc, "AA:NN", &idx);
19736 char *str = argv_concat(argv, argc, idx);
42f914d4 19737
2f8cc0e5 19738 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19739 direct, style);
42f914d4 19740
d62a17ae 19741 XFREE(MTYPE_TMP, str);
42f914d4 19742
d62a17ae 19743 if (ret < 0) {
19744 community_list_perror(vty, ret);
19745 return CMD_WARNING_CONFIG_FAILED;
19746 }
42f914d4 19747
d62a17ae 19748 return CMD_SUCCESS;
718e3744 19749}
19750
7336e101
SP
19751DEFUN (extcommunity_list_name_expanded,
19752 bgp_extcommunity_list_name_expanded_cmd,
a2099c1d 19753 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19754 BGP_STR
19755 EXTCOMMUNITY_LIST_STR
5bf15956 19756 "Extended Community list number (expanded)\n"
718e3744 19757 "Specify expanded extcommunity-list\n"
19758 "Extended Community list name\n"
2f8cc0e5
DA
19759 "Sequence number of an entry\n"
19760 "Sequence number\n"
718e3744 19761 "Specify community to reject\n"
19762 "Specify community to accept\n"
19763 "An ordered list as a regular-expression\n")
19764{
d62a17ae 19765 int style = EXTCOMMUNITY_LIST_EXPANDED;
19766 int direct = 0;
19767 char *cl_number_or_name = NULL;
2f8cc0e5 19768 char *seq = NULL;
d62a17ae 19769 int idx = 0;
7336e101 19770
d62a17ae 19771 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19772 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19773 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19774
a08032fe 19775 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19776 seq = argv[idx]->arg;
19777
d62a17ae 19778 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19779 : COMMUNITY_DENY;
19780 argv_find(argv, argc, "LINE", &idx);
19781 char *str = argv_concat(argv, argc, idx);
42f914d4 19782
2f8cc0e5 19783 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19784 direct, style);
42f914d4 19785
d62a17ae 19786 XFREE(MTYPE_TMP, str);
42f914d4 19787
d62a17ae 19788 if (ret < 0) {
19789 community_list_perror(vty, ret);
19790 return CMD_WARNING_CONFIG_FAILED;
19791 }
42f914d4 19792
d62a17ae 19793 return CMD_SUCCESS;
718e3744 19794}
19795
7336e101
SP
19796DEFUN (no_extcommunity_list_standard_all,
19797 no_bgp_extcommunity_list_standard_all_cmd,
a2099c1d 19798 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19799 NO_STR
19800 BGP_STR
19801 EXTCOMMUNITY_LIST_STR
813d4307 19802 "Extended Community list number (standard)\n"
718e3744 19803 "Specify standard extcommunity-list\n"
5bf15956 19804 "Community list name\n"
2f8cc0e5
DA
19805 "Sequence number of an entry\n"
19806 "Sequence number\n"
718e3744 19807 "Specify community to reject\n"
19808 "Specify community to accept\n"
19809 EXTCOMMUNITY_VAL_STR)
19810{
d62a17ae 19811 int style = EXTCOMMUNITY_LIST_STANDARD;
19812 int direct = 0;
19813 char *cl_number_or_name = NULL;
d4455c89 19814 char *str = NULL;
2f8cc0e5 19815 char *seq = NULL;
d62a17ae 19816 int idx = 0;
d4455c89 19817
a08032fe 19818 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19819 seq = argv[idx]->arg;
19820
19821 idx = 0;
d4455c89
DA
19822 argv_find(argv, argc, "permit", &idx);
19823 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
19824 if (idx) {
19825 direct = argv_find(argv, argc, "permit", &idx)
19826 ? COMMUNITY_PERMIT
19827 : COMMUNITY_DENY;
19828
19829 idx = 0;
19830 argv_find(argv, argc, "AA:NN", &idx);
19831 str = argv_concat(argv, argc, idx);
19832 }
19833
19834 idx = 0;
d62a17ae 19835 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19836 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19837 cl_number_or_name = argv[idx]->arg;
42f914d4 19838
d62a17ae 19839 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19840 seq, direct, style);
42f914d4 19841
d62a17ae 19842 XFREE(MTYPE_TMP, str);
42f914d4 19843
d62a17ae 19844 if (ret < 0) {
19845 community_list_perror(vty, ret);
19846 return CMD_WARNING_CONFIG_FAILED;
19847 }
42f914d4 19848
d62a17ae 19849 return CMD_SUCCESS;
718e3744 19850}
19851
d4455c89
DA
19852ALIAS(no_extcommunity_list_standard_all,
19853 no_bgp_extcommunity_list_standard_all_list_cmd,
a2099c1d 19854 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
36d4bb44 19855 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19856 "Extended Community list number (standard)\n"
19857 "Specify standard extcommunity-list\n"
19858 "Community list name\n")
19859
7336e101
SP
19860DEFUN (no_extcommunity_list_expanded_all,
19861 no_bgp_extcommunity_list_expanded_all_cmd,
a2099c1d 19862 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19863 NO_STR
19864 BGP_STR
19865 EXTCOMMUNITY_LIST_STR
718e3744 19866 "Extended Community list number (expanded)\n"
718e3744 19867 "Specify expanded extcommunity-list\n"
5bf15956 19868 "Extended Community list name\n"
2f8cc0e5
DA
19869 "Sequence number of an entry\n"
19870 "Sequence number\n"
718e3744 19871 "Specify community to reject\n"
19872 "Specify community to accept\n"
19873 "An ordered list as a regular-expression\n")
19874{
d62a17ae 19875 int style = EXTCOMMUNITY_LIST_EXPANDED;
19876 int direct = 0;
19877 char *cl_number_or_name = NULL;
d4455c89 19878 char *str = NULL;
2f8cc0e5 19879 char *seq = NULL;
d62a17ae 19880 int idx = 0;
d4455c89 19881
a08032fe 19882 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19883 seq = argv[idx]->arg;
19884
19885 idx = 0;
d4455c89
DA
19886 argv_find(argv, argc, "permit", &idx);
19887 argv_find(argv, argc, "deny", &idx);
19888
19889 if (idx) {
19890 direct = argv_find(argv, argc, "permit", &idx)
19891 ? COMMUNITY_PERMIT
19892 : COMMUNITY_DENY;
19893
19894 idx = 0;
19895 argv_find(argv, argc, "LINE", &idx);
19896 str = argv_concat(argv, argc, idx);
19897 }
19898
19899 idx = 0;
d62a17ae 19900 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19901 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19902 cl_number_or_name = argv[idx]->arg;
42f914d4 19903
d62a17ae 19904 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19905 seq, direct, style);
42f914d4 19906
d62a17ae 19907 XFREE(MTYPE_TMP, str);
42f914d4 19908
d62a17ae 19909 if (ret < 0) {
19910 community_list_perror(vty, ret);
19911 return CMD_WARNING_CONFIG_FAILED;
19912 }
42f914d4 19913
d62a17ae 19914 return CMD_SUCCESS;
718e3744 19915}
19916
d4455c89
DA
19917ALIAS(no_extcommunity_list_expanded_all,
19918 no_bgp_extcommunity_list_expanded_all_list_cmd,
a2099c1d 19919 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
36d4bb44 19920 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19921 "Extended Community list number (expanded)\n"
19922 "Specify expanded extcommunity-list\n"
19923 "Extended Community list name\n")
19924
d62a17ae 19925static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 19926{
d62a17ae 19927 struct community_entry *entry;
718e3744 19928
d62a17ae 19929 for (entry = list->head; entry; entry = entry->next) {
19930 if (entry == list->head) {
19931 if (all_digit(list->name))
19932 vty_out(vty, "Extended community %s list %s\n",
19933 entry->style == EXTCOMMUNITY_LIST_STANDARD
19934 ? "standard"
19935 : "(expanded) access",
19936 list->name);
19937 else
19938 vty_out(vty,
19939 "Named extended community %s list %s\n",
19940 entry->style == EXTCOMMUNITY_LIST_STANDARD
19941 ? "standard"
19942 : "expanded",
19943 list->name);
19944 }
19945 if (entry->any)
19946 vty_out(vty, " %s\n",
19947 community_direct_str(entry->direct));
19948 else
19949 vty_out(vty, " %s %s\n",
19950 community_direct_str(entry->direct),
8d9b8ed9 19951 community_list_config_str(entry));
d62a17ae 19952 }
718e3744 19953}
19954
7336e101
SP
19955DEFUN (show_extcommunity_list,
19956 show_bgp_extcommunity_list_cmd,
19957 "show bgp extcommunity-list",
718e3744 19958 SHOW_STR
7336e101 19959 BGP_STR
718e3744 19960 "List extended-community list\n")
19961{
d62a17ae 19962 struct community_list *list;
19963 struct community_list_master *cm;
718e3744 19964
d62a17ae 19965 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19966 if (!cm)
19967 return CMD_SUCCESS;
718e3744 19968
d62a17ae 19969 for (list = cm->num.head; list; list = list->next)
19970 extcommunity_list_show(vty, list);
718e3744 19971
d62a17ae 19972 for (list = cm->str.head; list; list = list->next)
19973 extcommunity_list_show(vty, list);
718e3744 19974
d62a17ae 19975 return CMD_SUCCESS;
718e3744 19976}
19977
7336e101
SP
19978DEFUN (show_extcommunity_list_arg,
19979 show_bgp_extcommunity_list_arg_cmd,
a2099c1d 19980 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
7336e101
SP
19981 SHOW_STR
19982 BGP_STR
718e3744 19983 "List extended-community list\n"
19984 "Extcommunity-list number\n"
960b69b9 19985 "Extcommunity-list name\n"
19986 "Detailed information on extcommunity-list\n")
718e3744 19987{
d62a17ae 19988 int idx_comm_list = 3;
19989 struct community_list *list;
718e3744 19990
e237b0d2 19991 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19992 EXTCOMMUNITY_LIST_MASTER);
19993 if (!list) {
19994 vty_out(vty, "%% Can't find extcommunity-list\n");
19995 return CMD_WARNING;
19996 }
718e3744 19997
d62a17ae 19998 extcommunity_list_show(vty, list);
718e3744 19999
d62a17ae 20000 return CMD_SUCCESS;
718e3744 20001}
6b0655a2 20002
718e3744 20003/* Display community-list and extcommunity-list configuration. */
d62a17ae 20004static int community_list_config_write(struct vty *vty)
20005{
20006 struct community_list *list;
20007 struct community_entry *entry;
20008 struct community_list_master *cm;
20009 int write = 0;
20010
20011 /* Community-list. */
20012 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20013
20014 for (list = cm->num.head; list; list = list->next)
20015 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20016 vty_out(vty,
20017 "bgp community-list %s seq %" PRId64 " %s %s\n",
20018 list->name, entry->seq,
d62a17ae 20019 community_direct_str(entry->direct),
20020 community_list_config_str(entry));
20021 write++;
20022 }
20023 for (list = cm->str.head; list; list = list->next)
20024 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20025 vty_out(vty,
20026 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 20027 entry->style == COMMUNITY_LIST_STANDARD
20028 ? "standard"
20029 : "expanded",
2f8cc0e5
DA
20030 list->name, entry->seq,
20031 community_direct_str(entry->direct),
d62a17ae 20032 community_list_config_str(entry));
20033 write++;
20034 }
20035
20036 /* Extcommunity-list. */
20037 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20038
20039 for (list = cm->num.head; list; list = list->next)
20040 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20041 vty_out(vty,
20042 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20043 list->name, entry->seq,
20044 community_direct_str(entry->direct),
d62a17ae 20045 community_list_config_str(entry));
20046 write++;
20047 }
20048 for (list = cm->str.head; list; list = list->next)
20049 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20050 vty_out(vty,
6cde4b45 20051 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 20052 entry->style == EXTCOMMUNITY_LIST_STANDARD
20053 ? "standard"
20054 : "expanded",
2f8cc0e5
DA
20055 list->name, entry->seq,
20056 community_direct_str(entry->direct),
d62a17ae 20057 community_list_config_str(entry));
20058 write++;
20059 }
20060
20061
20062 /* lcommunity-list. */
20063 cm = community_list_master_lookup(bgp_clist,
20064 LARGE_COMMUNITY_LIST_MASTER);
20065
20066 for (list = cm->num.head; list; list = list->next)
20067 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20068 vty_out(vty,
6cde4b45 20069 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
20070 list->name, entry->seq,
20071 community_direct_str(entry->direct),
d62a17ae 20072 community_list_config_str(entry));
20073 write++;
20074 }
20075 for (list = cm->str.head; list; list = list->next)
20076 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20077 vty_out(vty,
6cde4b45 20078 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 20079
d62a17ae 20080 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20081 ? "standard"
20082 : "expanded",
2f8cc0e5 20083 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 20084 community_list_config_str(entry));
20085 write++;
20086 }
20087
20088 return write;
20089}
20090
612c2c15 20091static int community_list_config_write(struct vty *vty);
d62a17ae 20092static struct cmd_node community_list_node = {
f4b8291f 20093 .name = "community list",
62b346ee
DL
20094 .node = COMMUNITY_LIST_NODE,
20095 .prompt = "",
612c2c15 20096 .config_write = community_list_config_write,
718e3744 20097};
20098
d62a17ae 20099static void community_list_vty(void)
20100{
612c2c15 20101 install_node(&community_list_node);
d62a17ae 20102
20103 /* Community-list. */
7336e101
SP
20104 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20105 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20106 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 20107 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 20108 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 20109 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
20110 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20111 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 20112
20113 /* Extcommunity-list. */
7336e101
SP
20114 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20115 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20116 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
20117 install_element(CONFIG_NODE,
20118 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 20119 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
20120 install_element(CONFIG_NODE,
20121 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
20122 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20123 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 20124
20125 /* Large Community List */
7336e101 20126 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
20127 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20128 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 20129 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
20130 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20131 install_element(CONFIG_NODE,
20132 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
20133 install_element(CONFIG_NODE,
20134 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20135 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20136 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20137 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20138 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20139 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20140 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
225096bc
DA
20141
20142 bgp_community_list_command_completion_setup();
5bf15956 20143}
ed0e57e3
DA
20144
20145static struct cmd_node community_alias_node = {
20146 .name = "community alias",
20147 .node = COMMUNITY_ALIAS_NODE,
20148 .prompt = "",
20149 .config_write = bgp_community_alias_write,
20150};
20151
20152void community_alias_vty(void)
20153{
20154 install_node(&community_alias_node);
20155
20156 /* Community-list. */
20157 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
b4ad2fae
DS
20158
20159 bgp_community_alias_command_completion_setup();
ed0e57e3 20160}