]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #10356 from opensourcerouting/pim6-adjust-20220117
[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"
4122b697 57#include "bgpd/bgp_network.h"
718e3744 58#include "bgpd/bgp_open.h"
4bf6a362 59#include "bgpd/bgp_regex.h"
718e3744 60#include "bgpd/bgp_route.h"
c016b6c7 61#include "bgpd/bgp_mplsvpn.h"
718e3744 62#include "bgpd/bgp_zebra.h"
fee0f4c6 63#include "bgpd/bgp_table.h"
94f2b392 64#include "bgpd/bgp_vty.h"
165b5fff 65#include "bgpd/bgp_mpath.h"
cb1faec9 66#include "bgpd/bgp_packet.h"
3f9c7369 67#include "bgpd/bgp_updgrp.h"
c43ed2e4 68#include "bgpd/bgp_bfd.h"
555e09d4 69#include "bgpd/bgp_io.h"
94c2f693 70#include "bgpd/bgp_evpn.h"
dd65f45e 71#include "bgpd/bgp_evpn_vty.h"
b5e140c8 72#include "bgpd/bgp_evpn_mh.h"
dcc68b5e 73#include "bgpd/bgp_addpath.h"
48ecf8f5 74#include "bgpd/bgp_mac.h"
dd65f45e 75#include "bgpd/bgp_flowspec.h"
389e4f92 76#include "bgpd/bgp_conditional_adv.h"
49e5a4a0 77#ifdef ENABLE_BGP_VNC
dd65f45e
DL
78#include "bgpd/rfapi/bgp_rfapi_cfg.h"
79#endif
80
5d5393b9 81FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
62282e83
DS
82 {
83 .val_bool = false,
84 .match_profile = "traditional",
85 .match_version = "< 7.4",
86 },
87 { .val_bool = true },
67b0f40c 88);
5d5393b9 89FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
4c1458b5
DL
90 { .val_bool = true, .match_profile = "datacenter", },
91 { .val_bool = false },
67b0f40c 92);
aef999a2
DA
93FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
94 { .val_bool = true, .match_profile = "datacenter", },
95 { .val_bool = false },
67b0f40c 96);
5d5393b9 97FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
4c1458b5
DL
98 { .val_bool = true, .match_profile = "datacenter", },
99 { .val_bool = false },
67b0f40c 100);
5d5393b9 101FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
4c1458b5
DL
102 { .val_bool = true, .match_profile = "datacenter", },
103 { .val_bool = false },
67b0f40c 104);
5d5393b9
DL
105FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
106 { .val_ulong = 10, .match_profile = "datacenter", },
107 { .val_ulong = 120 },
67b0f40c 108);
5d5393b9
DL
109FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
110 { .val_ulong = 9, .match_profile = "datacenter", },
111 { .val_ulong = 180 },
67b0f40c 112);
5d5393b9
DL
113FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
114 { .val_ulong = 3, .match_profile = "datacenter", },
115 { .val_ulong = 60 },
67b0f40c 116);
1d3fdccf
DA
117FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
118 { .val_bool = false, .match_profile = "datacenter", },
119 { .val_bool = false, .match_version = "< 7.4", },
120 { .val_bool = true },
67b0f40c 121);
2adac256
DA
122FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
123 { .val_bool = false, .match_version = "< 7.6", },
124 { .val_bool = true },
67b0f40c 125);
5d5393b9 126
dd65f45e
DL
127DEFINE_HOOK(bgp_inst_config_write,
128 (struct bgp *bgp, struct vty *vty),
8451921b
DL
129 (bgp, vty));
130DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
1ca2fd11 131DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
718e3744 132
d62a17ae 133static struct peer_group *listen_range_exists(struct bgp *bgp,
134 struct prefix *range, int exact);
135
055679e9 136/* Show BGP peer's information. */
137enum show_type {
138 show_all,
139 show_peer,
140 show_ipv4_all,
141 show_ipv6_all,
142 show_ipv4_peer,
143 show_ipv6_peer
144};
145
36235319
QY
146static struct peer_group *listen_range_exists(struct bgp *bgp,
147 struct prefix *range, int exact);
2986cac2 148
36235319
QY
149static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
150 struct bgp *bgp,
151 bool use_json,
152 json_object *json);
2986cac2 153
36235319
QY
154static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
155 enum show_type type,
156 const char *ip_str,
157 afi_t afi, bool use_json);
2986cac2 158
d62a17ae 159static enum node_type bgp_node_type(afi_t afi, safi_t safi)
160{
161 switch (afi) {
162 case AFI_IP:
163 switch (safi) {
164 case SAFI_UNICAST:
165 return BGP_IPV4_NODE;
d62a17ae 166 case SAFI_MULTICAST:
167 return BGP_IPV4M_NODE;
d62a17ae 168 case SAFI_LABELED_UNICAST:
169 return BGP_IPV4L_NODE;
d62a17ae 170 case SAFI_MPLS_VPN:
171 return BGP_VPNV4_NODE;
7c40bf39 172 case SAFI_FLOWSPEC:
173 return BGP_FLOWSPECV4_NODE;
5c525538
RW
174 default:
175 /* not expected */
176 return BGP_IPV4_NODE;
d62a17ae 177 }
d62a17ae 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 }
d62a17ae 194 case AFI_L2VPN:
195 return BGP_EVPN_NODE;
b26f891d 196 case AFI_UNSPEC:
d62a17ae 197 case AFI_MAX:
198 // We should never be here but to clarify the switch statement..
199 return BGP_IPV4_NODE;
d62a17ae 200 }
201
202 // Impossible to happen
203 return BGP_IPV4_NODE;
f51bae9c 204}
20eb8864 205
5cb5f4d0
DD
206static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
207{
7d0d37de
DS
208 if (afi == AFI_IP) {
209 if (safi == SAFI_UNICAST)
210 return "IPv4 Unicast";
211 if (safi == SAFI_MULTICAST)
212 return "IPv4 Multicast";
213 if (safi == SAFI_LABELED_UNICAST)
214 return "IPv4 Labeled Unicast";
215 if (safi == SAFI_MPLS_VPN)
216 return "IPv4 VPN";
217 if (safi == SAFI_ENCAP)
218 return "IPv4 Encap";
219 if (safi == SAFI_FLOWSPEC)
220 return "IPv4 Flowspec";
221 } else if (afi == AFI_IP6) {
222 if (safi == SAFI_UNICAST)
223 return "IPv6 Unicast";
224 if (safi == SAFI_MULTICAST)
225 return "IPv6 Multicast";
226 if (safi == SAFI_LABELED_UNICAST)
227 return "IPv6 Labeled Unicast";
228 if (safi == SAFI_MPLS_VPN)
229 return "IPv6 VPN";
230 if (safi == SAFI_ENCAP)
231 return "IPv6 Encap";
232 if (safi == SAFI_FLOWSPEC)
233 return "IPv6 Flowspec";
234 } else if (afi == AFI_L2VPN) {
235 if (safi == SAFI_EVPN)
236 return "L2VPN EVPN";
237 }
238
239 return "Unknown";
5cb5f4d0
DD
240}
241
242/*
243 * Please note that we have intentionally camelCased
244 * the return strings here. So if you want
245 * to use this function, please ensure you
246 * are doing this within json output
247 */
248static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
249{
7d0d37de
DS
250 if (afi == AFI_IP) {
251 if (safi == SAFI_UNICAST)
252 return "ipv4Unicast";
253 if (safi == SAFI_MULTICAST)
254 return "ipv4Multicast";
255 if (safi == SAFI_LABELED_UNICAST)
256 return "ipv4LabeledUnicast";
257 if (safi == SAFI_MPLS_VPN)
258 return "ipv4Vpn";
259 if (safi == SAFI_ENCAP)
260 return "ipv4Encap";
261 if (safi == SAFI_FLOWSPEC)
262 return "ipv4Flowspec";
263 } else if (afi == AFI_IP6) {
264 if (safi == SAFI_UNICAST)
265 return "ipv6Unicast";
266 if (safi == SAFI_MULTICAST)
267 return "ipv6Multicast";
268 if (safi == SAFI_LABELED_UNICAST)
269 return "ipv6LabeledUnicast";
270 if (safi == SAFI_MPLS_VPN)
271 return "ipv6Vpn";
272 if (safi == SAFI_ENCAP)
273 return "ipv6Encap";
274 if (safi == SAFI_FLOWSPEC)
275 return "ipv6Flowspec";
276 } else if (afi == AFI_L2VPN) {
277 if (safi == SAFI_EVPN)
278 return "l2VpnEvpn";
279 }
280
281 return "Unknown";
5cb5f4d0
DD
282}
283
0249b8b6
HS
284/* unset srv6 locator */
285static int bgp_srv6_locator_unset(struct bgp *bgp)
286{
287 int ret;
288 struct listnode *node, *nnode;
289 struct prefix_ipv6 *chunk;
290 struct bgp_srv6_function *func;
291 struct bgp *bgp_vrf;
292 struct in6_addr *tovpn_sid;
293
294 /* release chunk notification via ZAPI */
295 ret = bgp_zebra_srv6_manager_release_locator_chunk(
296 bgp->srv6_locator_name);
297 if (ret < 0)
298 return -1;
299
300 /* refresh chunks */
301 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk))
302 listnode_delete(bgp->srv6_locator_chunks, chunk);
303
304 /* refresh functions */
305 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func))
306 listnode_delete(bgp->srv6_functions, func);
307
308 /* refresh tovpn_sid */
309 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
310 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
311 continue;
312
313 /* refresh vpnv4 tovpn_sid */
314 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP].tovpn_sid;
315 if (tovpn_sid)
316 XFREE(MTYPE_BGP_SRV6_SID,
317 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
318
319 /* refresh vpnv6 tovpn_sid */
320 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid;
321 if (tovpn_sid)
322 XFREE(MTYPE_BGP_SRV6_SID,
323 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
324 }
325
326 /* update vpn bgp processes */
327 vpn_leak_postchange_all();
328
329 /* clear locator name */
330 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
331
332 return 0;
333}
334
718e3744 335/* Utility function to get address family from current node. */
d62a17ae 336afi_t bgp_node_afi(struct vty *vty)
337{
338 afi_t afi;
339 switch (vty->node) {
340 case BGP_IPV6_NODE:
341 case BGP_IPV6M_NODE:
342 case BGP_IPV6L_NODE:
343 case BGP_VPNV6_NODE:
7c40bf39 344 case BGP_FLOWSPECV6_NODE:
d62a17ae 345 afi = AFI_IP6;
346 break;
347 case BGP_EVPN_NODE:
348 afi = AFI_L2VPN;
349 break;
350 default:
351 afi = AFI_IP;
352 break;
353 }
354 return afi;
718e3744 355}
356
357/* Utility function to get subsequent address family from current
358 node. */
d62a17ae 359safi_t bgp_node_safi(struct vty *vty)
360{
361 safi_t safi;
362 switch (vty->node) {
363 case BGP_VPNV4_NODE:
364 case BGP_VPNV6_NODE:
365 safi = SAFI_MPLS_VPN;
366 break;
367 case BGP_IPV4M_NODE:
368 case BGP_IPV6M_NODE:
369 safi = SAFI_MULTICAST;
370 break;
371 case BGP_EVPN_NODE:
372 safi = SAFI_EVPN;
373 break;
374 case BGP_IPV4L_NODE:
375 case BGP_IPV6L_NODE:
376 safi = SAFI_LABELED_UNICAST;
377 break;
7c40bf39 378 case BGP_FLOWSPECV4_NODE:
379 case BGP_FLOWSPECV6_NODE:
380 safi = SAFI_FLOWSPEC;
381 break;
d62a17ae 382 default:
383 safi = SAFI_UNICAST;
384 break;
385 }
386 return safi;
718e3744 387}
388
55f91488
QY
389/**
390 * Converts an AFI in string form to afi_t
391 *
392 * @param afi string, one of
393 * - "ipv4"
394 * - "ipv6"
81cf0de5 395 * - "l2vpn"
55f91488
QY
396 * @return the corresponding afi_t
397 */
d62a17ae 398afi_t bgp_vty_afi_from_str(const char *afi_str)
399{
400 afi_t afi = AFI_MAX; /* unknown */
401 if (strmatch(afi_str, "ipv4"))
402 afi = AFI_IP;
403 else if (strmatch(afi_str, "ipv6"))
404 afi = AFI_IP6;
81cf0de5
CS
405 else if (strmatch(afi_str, "l2vpn"))
406 afi = AFI_L2VPN;
d62a17ae 407 return afi;
408}
409
410int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
411 afi_t *afi)
412{
413 int ret = 0;
414 if (argv_find(argv, argc, "ipv4", index)) {
415 ret = 1;
416 if (afi)
417 *afi = AFI_IP;
418 } else if (argv_find(argv, argc, "ipv6", index)) {
419 ret = 1;
420 if (afi)
421 *afi = AFI_IP6;
8688b3e7
DS
422 } else if (argv_find(argv, argc, "l2vpn", index)) {
423 ret = 1;
424 if (afi)
425 *afi = AFI_L2VPN;
d62a17ae 426 }
427 return ret;
46f296b4
LB
428}
429
375a2e67 430/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 431safi_t bgp_vty_safi_from_str(const char *safi_str)
432{
433 safi_t safi = SAFI_MAX; /* unknown */
434 if (strmatch(safi_str, "multicast"))
435 safi = SAFI_MULTICAST;
436 else if (strmatch(safi_str, "unicast"))
437 safi = SAFI_UNICAST;
438 else if (strmatch(safi_str, "vpn"))
439 safi = SAFI_MPLS_VPN;
81cf0de5
CS
440 else if (strmatch(safi_str, "evpn"))
441 safi = SAFI_EVPN;
d62a17ae 442 else if (strmatch(safi_str, "labeled-unicast"))
443 safi = SAFI_LABELED_UNICAST;
7c40bf39 444 else if (strmatch(safi_str, "flowspec"))
445 safi = SAFI_FLOWSPEC;
d62a17ae 446 return safi;
447}
448
449int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
450 safi_t *safi)
451{
452 int ret = 0;
453 if (argv_find(argv, argc, "unicast", index)) {
454 ret = 1;
455 if (safi)
456 *safi = SAFI_UNICAST;
457 } else if (argv_find(argv, argc, "multicast", index)) {
458 ret = 1;
459 if (safi)
460 *safi = SAFI_MULTICAST;
461 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
462 ret = 1;
463 if (safi)
464 *safi = SAFI_LABELED_UNICAST;
465 } else if (argv_find(argv, argc, "vpn", index)) {
466 ret = 1;
467 if (safi)
468 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
469 } else if (argv_find(argv, argc, "evpn", index)) {
470 ret = 1;
471 if (safi)
472 *safi = SAFI_EVPN;
7c40bf39 473 } else if (argv_find(argv, argc, "flowspec", index)) {
474 ret = 1;
475 if (safi)
476 *safi = SAFI_FLOWSPEC;
d62a17ae 477 }
478 return ret;
46f296b4
LB
479}
480
b16bcbba
TA
481/*
482 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
483 *
484 * afi
485 * address-family identifier
486 *
487 * safi
488 * subsequent address-family identifier
489 *
490 * Returns:
491 * default_af string corresponding to the supplied afi/safi pair.
492 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
493 * return -1.
494 */
495static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
496{
497 switch (afi) {
498 case AFI_IP:
499 switch (safi) {
500 case SAFI_UNICAST:
501 return "ipv4-unicast";
502 case SAFI_MULTICAST:
503 return "ipv4-multicast";
504 case SAFI_MPLS_VPN:
505 return "ipv4-vpn";
506 case SAFI_ENCAP:
507 return "ipv4-encap";
508 case SAFI_LABELED_UNICAST:
509 return "ipv4-labeled-unicast";
510 case SAFI_FLOWSPEC:
511 return "ipv4-flowspec";
512 default:
513 return "unknown-afi/safi";
514 }
515 break;
516 case AFI_IP6:
517 switch (safi) {
518 case SAFI_UNICAST:
519 return "ipv6-unicast";
520 case SAFI_MULTICAST:
521 return "ipv6-multicast";
522 case SAFI_MPLS_VPN:
523 return "ipv6-vpn";
524 case SAFI_ENCAP:
525 return "ipv6-encap";
526 case SAFI_LABELED_UNICAST:
527 return "ipv6-labeled-unicast";
528 case SAFI_FLOWSPEC:
529 return "ipv6-flowspec";
530 default:
531 return "unknown-afi/safi";
532 }
533 break;
534 case AFI_L2VPN:
535 switch (safi) {
536 case SAFI_EVPN:
537 return "l2vpn-evpn";
538 default:
539 return "unknown-afi/safi";
540 }
541 case AFI_UNSPEC:
542 case AFI_MAX:
543 return "unknown-afi/safi";
544 }
545 /* all AFIs are accounted for above, so this shouldn't happen */
546 return "unknown-afi/safi";
547}
548
5d5393b9
DL
549int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
550 enum bgp_instance_type inst_type)
551{
552 int ret = bgp_get(bgp, as, name, inst_type);
553
554 if (ret == BGP_CREATED) {
555 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
d43114f3 556 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
5d5393b9
DL
557
558 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 559 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 560 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 561 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
562 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
563 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 564 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 565 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 566 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 567 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
568 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
569 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2adac256
DA
570 if (DFLT_BGP_SUPPRESS_DUPLICATES)
571 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
5d5393b9
DL
572
573 ret = BGP_SUCCESS;
574 }
575 return ret;
576}
577
7eeee51e 578/*
f212a857 579 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 580 *
f212a857
DS
581 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
582 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
583 * to appropriate values for the calling function. This is to allow the
584 * calling function to make decisions appropriate for the show command
585 * that is being parsed.
586 *
587 * The show commands are generally of the form:
d62a17ae 588 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
589 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
590 *
591 * Since we use argv_find if the show command in particular doesn't have:
592 * [ip]
18c57037 593 * [<view|vrf> VIEWVRFNAME]
375a2e67 594 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
595 * The command parsing should still be ok.
596 *
597 * vty -> The vty for the command so we can output some useful data in
598 * the event of a parse error in the vrf.
599 * argv -> The command tokens
600 * argc -> How many command tokens we have
d62a17ae 601 * idx -> The current place in the command, generally should be 0 for this
602 * function
7eeee51e
DS
603 * afi -> The parsed afi if it was included in the show command, returned here
604 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 605 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 606 * use_json -> json is configured or not
7eeee51e
DS
607 *
608 * The function returns the correct location in the parse tree for the
609 * last token found.
0e37c258
DS
610 *
611 * Returns 0 for failure to parse correctly, else the idx position of where
612 * it found the last token.
7eeee51e 613 */
d62a17ae 614int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
615 struct cmd_token **argv, int argc,
616 int *idx, afi_t *afi, safi_t *safi,
9f049418 617 struct bgp **bgp, bool use_json)
d62a17ae 618{
619 char *vrf_name = NULL;
620
621 assert(afi);
622 assert(safi);
623 assert(bgp);
624
625 if (argv_find(argv, argc, "ip", idx))
626 *afi = AFI_IP;
627
9a8bdf1c 628 if (argv_find(argv, argc, "view", idx))
d62a17ae 629 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
630 else if (argv_find(argv, argc, "vrf", idx)) {
631 vrf_name = argv[*idx + 1]->arg;
632 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
633 vrf_name = NULL;
634 }
635 if (vrf_name) {
d62a17ae 636 if (strmatch(vrf_name, "all"))
637 *bgp = NULL;
638 else {
639 *bgp = bgp_lookup_by_name(vrf_name);
640 if (!*bgp) {
52e5b8c4
SP
641 if (use_json) {
642 json_object *json = NULL;
643 json = json_object_new_object();
644 json_object_string_add(
645 json, "warning",
646 "View/Vrf is unknown");
75eeda93 647 vty_json(vty, json);
52e5b8c4 648 }
ca61fd25
DS
649 else
650 vty_out(vty, "View/Vrf %s is unknown\n",
651 vrf_name);
d62a17ae 652 *idx = 0;
653 return 0;
654 }
655 }
656 } else {
657 *bgp = bgp_get_default();
658 if (!*bgp) {
52e5b8c4
SP
659 if (use_json) {
660 json_object *json = NULL;
661 json = json_object_new_object();
662 json_object_string_add(
663 json, "warning",
664 "Default BGP instance not found");
75eeda93 665 vty_json(vty, json);
52e5b8c4 666 }
ca61fd25
DS
667 else
668 vty_out(vty,
669 "Default BGP instance not found\n");
d62a17ae 670 *idx = 0;
671 return 0;
672 }
673 }
674
675 if (argv_find_and_parse_afi(argv, argc, idx, afi))
676 argv_find_and_parse_safi(argv, argc, idx, safi);
677
678 *idx += 1;
679 return *idx;
680}
681
28c6e247 682static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 683{
684 struct interface *ifp = NULL;
4122b697
DA
685 struct listnode *node;
686 struct bgp_listener *listener;
687 union sockunion all_su;
d62a17ae 688
4122b697 689 if (su->sa.sa_family == AF_INET) {
3d2a2725 690 (void)str2sockunion("0.0.0.0", &all_su);
d62a17ae 691 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
4122b697 692 } else if (su->sa.sa_family == AF_INET6) {
3d2a2725 693 (void)str2sockunion("::", &all_su);
d62a17ae 694 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
695 su->sin6.sin6_scope_id,
696 bgp->vrf_id);
4122b697 697 }
d62a17ae 698
4122b697
DA
699 if (ifp) {
700 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
701 if (sockunion_family(su) !=
702 sockunion_family(&listener->su))
703 continue;
704
705 /* If 0.0.0.0/:: is a listener, then treat as self and
706 * reject.
707 */
708 if (!sockunion_cmp(&listener->su, su) ||
709 !sockunion_cmp(&listener->su, &all_su))
710 return true;
711 }
712 }
d62a17ae 713
3dc339cd 714 return false;
718e3744 715}
716
28c6e247
IR
717/* Utility function for looking up peer from VTY. */
718/* This is used only for configuration, so disallow if attempted on
719 * a dynamic neighbor.
720 */
721static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
722{
723 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
724 int ret;
725 union sockunion su;
726 struct peer *peer;
727
728 if (!bgp) {
729 return NULL;
730 }
731
732 ret = str2sockunion(ip_str, &su);
733 if (ret < 0) {
734 peer = peer_lookup_by_conf_if(bgp, ip_str);
735 if (!peer) {
736 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
737 == NULL) {
738 vty_out(vty,
739 "%% Malformed address or name: %s\n",
740 ip_str);
741 return NULL;
742 }
743 }
744 } else {
745 peer = peer_lookup(bgp, &su);
746 if (!peer) {
747 vty_out(vty,
748 "%% Specify remote-as or peer-group commands first\n");
749 return NULL;
750 }
751 if (peer_dynamic_neighbor(peer)) {
752 vty_out(vty,
753 "%% Operation not allowed on a dynamic neighbor\n");
754 return NULL;
755 }
756 }
757 return peer;
758}
759
718e3744 760/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
761/* This is used only for configuration, so disallow if attempted on
762 * a dynamic neighbor.
763 */
d62a17ae 764struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
765{
766 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
767 int ret;
768 union sockunion su;
769 struct peer *peer = NULL;
770 struct peer_group *group = NULL;
771
772 if (!bgp) {
773 return NULL;
774 }
775
776 ret = str2sockunion(peer_str, &su);
777 if (ret == 0) {
778 /* IP address, locate peer. */
779 peer = peer_lookup(bgp, &su);
780 } else {
781 /* Not IP, could match either peer configured on interface or a
782 * group. */
783 peer = peer_lookup_by_conf_if(bgp, peer_str);
784 if (!peer)
785 group = peer_group_lookup(bgp, peer_str);
786 }
787
788 if (peer) {
789 if (peer_dynamic_neighbor(peer)) {
790 vty_out(vty,
791 "%% Operation not allowed on a dynamic neighbor\n");
792 return NULL;
793 }
794
795 return peer;
796 }
797
798 if (group)
799 return group->conf;
800
801 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
802
803 return NULL;
804}
805
806int bgp_vty_return(struct vty *vty, int ret)
807{
808 const char *str = NULL;
809
810 switch (ret) {
811 case BGP_ERR_INVALID_VALUE:
812 str = "Invalid value";
813 break;
814 case BGP_ERR_INVALID_FLAG:
815 str = "Invalid flag";
816 break;
817 case BGP_ERR_PEER_GROUP_SHUTDOWN:
818 str = "Peer-group has been shutdown. Activate the peer-group first";
819 break;
820 case BGP_ERR_PEER_FLAG_CONFLICT:
821 str = "Can't set override-capability and strict-capability-match at the same time";
822 break;
823 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
824 str = "Specify remote-as or peer-group remote AS first";
825 break;
826 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
827 str = "Cannot change the peer-group. Deconfigure first";
828 break;
829 case BGP_ERR_PEER_GROUP_MISMATCH:
830 str = "Peer is not a member of this peer-group";
831 break;
832 case BGP_ERR_PEER_FILTER_CONFLICT:
833 str = "Prefix/distribute list can not co-exist";
834 break;
835 case BGP_ERR_NOT_INTERNAL_PEER:
836 str = "Invalid command. Not an internal neighbor";
837 break;
838 case BGP_ERR_REMOVE_PRIVATE_AS:
839 str = "remove-private-AS cannot be configured for IBGP peers";
840 break;
841 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
842 str = "Local-AS allowed only for EBGP peers";
843 break;
844 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
845 str = "Cannot have local-as same as BGP AS number";
846 break;
847 case BGP_ERR_TCPSIG_FAILED:
848 str = "Error while applying TCP-Sig to session(s)";
849 break;
850 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
851 str = "ebgp-multihop and ttl-security cannot be configured together";
852 break;
853 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
854 str = "ttl-security only allowed for EBGP peers";
855 break;
856 case BGP_ERR_AS_OVERRIDE:
857 str = "as-override cannot be configured for IBGP peers";
858 break;
859 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
860 str = "Invalid limit for number of dynamic neighbors";
861 break;
862 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
863 str = "Dynamic neighbor listen range already exists";
864 break;
865 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
866 str = "Operation not allowed on a dynamic neighbor";
867 break;
868 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
869 str = "Operation not allowed on a directly connected neighbor";
870 break;
871 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 872 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
055679e9 873 break;
874 case BGP_ERR_GR_INVALID_CMD:
875 str = "The Graceful Restart command used is not valid at this moment.";
876 break;
877 case BGP_ERR_GR_OPERATION_FAILED:
878 str = "The Graceful Restart Operation failed due to an err.";
879 break;
d62a17ae 880 }
881 if (str) {
882 vty_out(vty, "%% %s\n", str);
883 return CMD_WARNING_CONFIG_FAILED;
884 }
885 return CMD_SUCCESS;
718e3744 886}
887
7aafcaca 888/* BGP clear sort. */
d62a17ae 889enum clear_sort {
890 clear_all,
891 clear_peer,
892 clear_group,
893 clear_external,
894 clear_as
7aafcaca
DS
895};
896
1ca2fd11
IR
897static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
898 safi_t safi, int error)
d62a17ae 899{
900 switch (error) {
901 case BGP_ERR_AF_UNCONFIGURED:
1ca2fd11
IR
902 vty_out(vty,
903 "%%BGP: Enable %s address family for the neighbor %s\n",
904 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 905 break;
906 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
1ca2fd11
IR
907 vty_out(vty,
908 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
d62a17ae 909 peer->host);
910 break;
911 default:
912 break;
913 }
7aafcaca
DS
914}
915
dc912615 916static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 917 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
918{
919 int ret = 0;
2adac256 920 struct peer_af *paf;
dc912615
DS
921
922 /* if afi/.safi not specified, spin thru all of them */
923 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
924 afi_t tmp_afi;
925 safi_t tmp_safi;
0e5cdd59
DS
926 enum bgp_af_index index;
927
928 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
929 paf = peer->peer_af_array[index];
930 if (!paf)
931 continue;
dc912615 932
2adac256
DA
933 if (paf && paf->subgroup)
934 SET_FLAG(paf->subgroup->sflags,
935 SUBGRP_STATUS_FORCE_UPDATES);
936
0e5cdd59
DS
937 tmp_afi = paf->afi;
938 tmp_safi = paf->safi;
dc912615
DS
939 if (!peer->afc[tmp_afi][tmp_safi])
940 continue;
941
942 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 943 ret = peer_clear(peer, nnode);
dc912615
DS
944 else
945 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
946 stype);
947 }
948 /* if afi specified and safi not, spin thru safis on this afi */
949 } else if (safi == SAFI_UNSPEC) {
950 safi_t tmp_safi;
951
952 for (tmp_safi = SAFI_UNICAST;
953 tmp_safi < SAFI_MAX; tmp_safi++) {
954 if (!peer->afc[afi][tmp_safi])
955 continue;
956
2adac256
DA
957 paf = peer_af_find(peer, afi, tmp_safi);
958 if (paf && paf->subgroup)
959 SET_FLAG(paf->subgroup->sflags,
960 SUBGRP_STATUS_FORCE_UPDATES);
961
dc912615 962 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 963 ret = peer_clear(peer, nnode);
dc912615
DS
964 else
965 ret = peer_clear_soft(peer, afi,
966 tmp_safi, stype);
967 }
968 /* both afi/safi specified, let the caller know if not defined */
969 } else {
970 if (!peer->afc[afi][safi])
971 return 1;
972
2adac256
DA
973 paf = peer_af_find(peer, afi, safi);
974 if (paf && paf->subgroup)
975 SET_FLAG(paf->subgroup->sflags,
976 SUBGRP_STATUS_FORCE_UPDATES);
977
dc912615 978 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 979 ret = peer_clear(peer, nnode);
dc912615
DS
980 else
981 ret = peer_clear_soft(peer, afi, safi, stype);
982 }
983
984 return ret;
985}
986
7aafcaca 987/* `clear ip bgp' functions. */
1ca2fd11 988static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 989 enum clear_sort sort, enum bgp_clear_type stype,
1ca2fd11 990 const char *arg)
d62a17ae 991{
dc912615 992 int ret = 0;
3ae8bfa5 993 bool found = false;
d62a17ae 994 struct peer *peer;
dc95985f 995
996 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 997
998 /* Clear all neighbors. */
999 /*
1000 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
1001 * nodes on the BGP instance as that may get freed if it is a
1002 * doppelganger
d62a17ae 1003 */
1004 if (sort == clear_all) {
1005 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 1006
1007 bgp_peer_gr_flags_update(peer);
1008
36235319 1009 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 1010 gr_router_detected = true;
1011
c368171c 1012 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 1013 stype);
d62a17ae 1014
1015 if (ret < 0)
1ca2fd11 1016 bgp_clear_vty_error(vty, peer, afi, safi, ret);
dc95985f 1017 }
1018
36235319
QY
1019 if (gr_router_detected
1020 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1021 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1022 } else if (!gr_router_detected
1023 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1024 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 1025 }
d62a17ae 1026
1027 /* This is to apply read-only mode on this clear. */
1028 if (stype == BGP_CLEAR_SOFT_NONE)
1029 bgp->update_delay_over = 0;
1030
1031 return CMD_SUCCESS;
7aafcaca
DS
1032 }
1033
3ae8bfa5 1034 /* Clear specified neighbor. */
d62a17ae 1035 if (sort == clear_peer) {
1036 union sockunion su;
d62a17ae 1037
1038 /* Make sockunion for lookup. */
1039 ret = str2sockunion(arg, &su);
1040 if (ret < 0) {
1041 peer = peer_lookup_by_conf_if(bgp, arg);
1042 if (!peer) {
1043 peer = peer_lookup_by_hostname(bgp, arg);
1044 if (!peer) {
1ca2fd11
IR
1045 vty_out(vty,
1046 "Malformed address or name: %s\n",
d62a17ae 1047 arg);
1048 return CMD_WARNING;
1049 }
1050 }
1051 } else {
1052 peer = peer_lookup(bgp, &su);
1053 if (!peer) {
1ca2fd11
IR
1054 vty_out(vty,
1055 "%%BGP: Unknown neighbor - \"%s\"\n",
1056 arg);
d62a17ae 1057 return CMD_WARNING;
1058 }
1059 }
7aafcaca 1060
dc95985f 1061 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1062 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1063
dc912615
DS
1064 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1065
1066 /* if afi/safi not defined for this peer, let caller know */
1067 if (ret == 1)
3ae8bfa5 1068 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1069
d62a17ae 1070 if (ret < 0)
1ca2fd11 1071 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 1072
d62a17ae 1073 return CMD_SUCCESS;
7aafcaca 1074 }
7aafcaca 1075
3ae8bfa5 1076 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1077 if (sort == clear_group) {
1078 struct peer_group *group;
7aafcaca 1079
d62a17ae 1080 group = peer_group_lookup(bgp, arg);
1081 if (!group) {
1ca2fd11 1082 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
d62a17ae 1083 return CMD_WARNING;
1084 }
1085
1086 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1087 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1088
d62a17ae 1089 if (ret < 0)
1ca2fd11 1090 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1091 else
1092 found = true;
d62a17ae 1093 }
3ae8bfa5
PM
1094
1095 if (!found)
1ca2fd11
IR
1096 vty_out(vty,
1097 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 1098 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1099
d62a17ae 1100 return CMD_SUCCESS;
7aafcaca 1101 }
7aafcaca 1102
3ae8bfa5 1103 /* Clear all external (eBGP) neighbors. */
d62a17ae 1104 if (sort == clear_external) {
1105 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1106 if (peer->sort == BGP_PEER_IBGP)
1107 continue;
7aafcaca 1108
dc95985f 1109 bgp_peer_gr_flags_update(peer);
1110
36235319 1111 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1112 gr_router_detected = true;
dc95985f 1113
c368171c 1114 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1115
d62a17ae 1116 if (ret < 0)
1ca2fd11 1117 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1118 else
1119 found = true;
d62a17ae 1120 }
3ae8bfa5 1121
36235319
QY
1122 if (gr_router_detected
1123 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1124 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1125 } else if (!gr_router_detected
1126 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1127 bgp_zebra_send_capabilities(bgp, true);
1128 }
1129
3ae8bfa5 1130 if (!found)
1ca2fd11
IR
1131 vty_out(vty,
1132 "%%BGP: No external %s peer is configured\n",
1133 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1134
d62a17ae 1135 return CMD_SUCCESS;
1136 }
1137
3ae8bfa5 1138 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1139 if (sort == clear_as) {
3ae8bfa5 1140 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1141
1142 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1143 if (peer->as != as)
1144 continue;
1145
dc95985f 1146 bgp_peer_gr_flags_update(peer);
1147
36235319 1148 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1149 gr_router_detected = true;
dc95985f 1150
c368171c 1151 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1152
1153 if (ret < 0)
1ca2fd11 1154 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1155 else
1156 found = true;
d62a17ae 1157 }
3ae8bfa5 1158
36235319
QY
1159 if (gr_router_detected
1160 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1161 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1162 } else if (!gr_router_detected
1163 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1164 bgp_zebra_send_capabilities(bgp, true);
1165 }
1166
3ae8bfa5 1167 if (!found)
1ca2fd11
IR
1168 vty_out(vty,
1169 "%%BGP: No %s peer is configured with AS %s\n",
1170 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1171
d62a17ae 1172 return CMD_SUCCESS;
1173 }
1174
1175 return CMD_SUCCESS;
1176}
1177
1ca2fd11
IR
1178static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1179 safi_t safi, enum clear_sort sort,
1180 enum bgp_clear_type stype, const char *arg)
d62a17ae 1181{
1182 struct bgp *bgp;
1183
1184 /* BGP structure lookup. */
1185 if (name) {
1186 bgp = bgp_lookup_by_name(name);
1187 if (bgp == NULL) {
1ca2fd11 1188 vty_out(vty, "Can't find BGP instance %s\n", name);
d62a17ae 1189 return CMD_WARNING;
1190 }
1191 } else {
1192 bgp = bgp_get_default();
1193 if (bgp == NULL) {
1ca2fd11 1194 vty_out(vty, "No BGP process is configured\n");
d62a17ae 1195 return CMD_WARNING;
1196 }
1197 }
1198
1ca2fd11 1199 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
1200}
1201
1202/* clear soft inbound */
1ca2fd11 1203static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 1204{
99b3ebd3
NS
1205 afi_t afi;
1206 safi_t safi;
1207
1ca2fd11
IR
1208 FOREACH_AFI_SAFI (afi, safi)
1209 bgp_clear_vty(vty, name, afi, safi, clear_all,
1210 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
1211}
1212
1213/* clear soft outbound */
1ca2fd11 1214static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 1215{
99b3ebd3
NS
1216 afi_t afi;
1217 safi_t safi;
1218
1ca2fd11
IR
1219 FOREACH_AFI_SAFI (afi, safi)
1220 bgp_clear_vty(vty, name, afi, safi, clear_all,
1221 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
1222}
1223
1224
f787d7a0 1225#ifndef VTYSH_EXTRACT_PL
2e4c2296 1226#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1227#endif
1228
8029b216
AK
1229DEFUN_HIDDEN (bgp_local_mac,
1230 bgp_local_mac_cmd,
093e3f23 1231 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1232 BGP_STR
1233 "Local MAC config\n"
1234 "VxLAN Network Identifier\n"
1235 "VNI number\n"
1236 "local mac\n"
1237 "mac address\n"
1238 "mac-mobility sequence\n"
1239 "seq number\n")
1240{
1241 int rv;
1242 vni_t vni;
1243 struct ethaddr mac;
1244 struct ipaddr ip;
1245 uint32_t seq;
1246 struct bgp *bgp;
1247
1248 vni = strtoul(argv[3]->arg, NULL, 10);
1249 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1250 vty_out(vty, "%% Malformed MAC address\n");
1251 return CMD_WARNING;
1252 }
1253 memset(&ip, 0, sizeof(ip));
1254 seq = strtoul(argv[7]->arg, NULL, 10);
1255
1256 bgp = bgp_get_default();
1257 if (!bgp) {
1258 vty_out(vty, "Default BGP instance is not there\n");
1259 return CMD_WARNING;
1260 }
1261
b5e140c8
AK
1262 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1263 zero_esi);
8029b216
AK
1264 if (rv < 0) {
1265 vty_out(vty, "Internal error\n");
1266 return CMD_WARNING;
1267 }
1268
1269 return CMD_SUCCESS;
1270}
1271
1272DEFUN_HIDDEN (no_bgp_local_mac,
1273 no_bgp_local_mac_cmd,
093e3f23 1274 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1275 NO_STR
1276 BGP_STR
1277 "Local MAC config\n"
1278 "VxLAN Network Identifier\n"
1279 "VNI number\n"
1280 "local mac\n"
1281 "mac address\n")
1282{
1283 int rv;
1284 vni_t vni;
1285 struct ethaddr mac;
1286 struct ipaddr ip;
1287 struct bgp *bgp;
1288
1289 vni = strtoul(argv[4]->arg, NULL, 10);
1290 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1291 vty_out(vty, "%% Malformed MAC address\n");
1292 return CMD_WARNING;
1293 }
1294 memset(&ip, 0, sizeof(ip));
1295
1296 bgp = bgp_get_default();
1297 if (!bgp) {
1298 vty_out(vty, "Default BGP instance is not there\n");
1299 return CMD_WARNING;
1300 }
1301
ec0ab544 1302 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1303 if (rv < 0) {
1304 vty_out(vty, "Internal error\n");
1305 return CMD_WARNING;
1306 }
1307
1308 return CMD_SUCCESS;
1309}
1310
718e3744 1311DEFUN (no_synchronization,
1312 no_synchronization_cmd,
1313 "no synchronization",
1314 NO_STR
1315 "Perform IGP synchronization\n")
1316{
d62a17ae 1317 return CMD_SUCCESS;
718e3744 1318}
1319
1320DEFUN (no_auto_summary,
1321 no_auto_summary_cmd,
1322 "no auto-summary",
1323 NO_STR
1324 "Enable automatic network number summarization\n")
1325{
d62a17ae 1326 return CMD_SUCCESS;
718e3744 1327}
3d515fd9 1328
718e3744 1329/* "router bgp" commands. */
1ca2fd11
IR
1330DEFUN_NOSH (router_bgp,
1331 router_bgp_cmd,
1332 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1333 ROUTER_STR
1334 BGP_STR
1335 AS_STR
1336 BGP_INSTANCE_HELP_STR)
718e3744 1337{
d62a17ae 1338 int idx_asn = 2;
1339 int idx_view_vrf = 3;
1340 int idx_vrf = 4;
1ca2fd11
IR
1341 int is_new_bgp = 0;
1342 int ret;
d62a17ae 1343 as_t as;
1344 struct bgp *bgp;
1345 const char *name = NULL;
1346 enum bgp_instance_type inst_type;
1347
1348 // "router bgp" without an ASN
1349 if (argc == 2) {
1350 // Pending: Make VRF option available for ASN less config
1abef40f 1351 bgp = bgp_get_default();
d62a17ae 1352
1abef40f 1353 if (bgp == NULL) {
d62a17ae 1354 vty_out(vty, "%% No BGP process is configured\n");
1355 return CMD_WARNING_CONFIG_FAILED;
1356 }
1357
1358 if (listcount(bm->bgp) > 1) {
996c9314 1359 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1360 return CMD_WARNING_CONFIG_FAILED;
1361 }
1362 }
1363
1364 // "router bgp X"
1365 else {
ff8a8a7a 1366 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1ca2fd11 1367
cc413e2a
DA
1368 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1369 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1370 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1371
d62a17ae 1372 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1373 if (argc > 3) {
1374 name = argv[idx_vrf]->arg;
1375
9a8bdf1c
PG
1376 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1377 if (strmatch(name, VRF_DEFAULT_NAME))
1378 name = NULL;
1379 else
1380 inst_type = BGP_INSTANCE_TYPE_VRF;
1ca2fd11 1381 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1382 inst_type = BGP_INSTANCE_TYPE_VIEW;
d62a17ae 1383 }
1384
1ca2fd11
IR
1385 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1386 is_new_bgp = (bgp_lookup(as, name) == NULL);
3bd70bf8 1387
1ca2fd11
IR
1388 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1389 switch (ret) {
1390 case BGP_ERR_AS_MISMATCH:
1391 vty_out(vty, "BGP is already running; AS is %u\n", as);
1392 return CMD_WARNING_CONFIG_FAILED;
1393 case BGP_ERR_INSTANCE_MISMATCH:
1394 vty_out(vty,
1395 "BGP instance name and AS number mismatch\n");
1396 vty_out(vty,
1397 "BGP instance is already running; AS is %u\n",
1398 as);
1399 return CMD_WARNING_CONFIG_FAILED;
ff8a8a7a 1400 }
1ca2fd11
IR
1401
1402 /*
1403 * If we just instantiated the default instance, complete
1404 * any pending VRF-VPN leaking that was configured via
1405 * earlier "router bgp X vrf FOO" blocks.
1406 */
1407 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1408 vpn_leak_postchange_all();
1409
1410 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1411 bgp_vpn_leak_export(bgp);
1412 /* Pending: handle when user tries to change a view to vrf n vv.
1413 */
d62a17ae 1414 }
1415
1ca2fd11
IR
1416 /* unset the auto created flag as the user config is now present */
1417 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1418 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1419
1420 return CMD_SUCCESS;
718e3744 1421}
1422
718e3744 1423/* "no router bgp" commands. */
1ca2fd11
IR
1424DEFUN (no_router_bgp,
1425 no_router_bgp_cmd,
1426 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1427 NO_STR
1428 ROUTER_STR
1429 BGP_STR
1430 AS_STR
1431 BGP_INSTANCE_HELP_STR)
718e3744 1432{
4fd9919e 1433 int idx_asn = 3;
d62a17ae 1434 int idx_vrf = 5;
1ca2fd11 1435 as_t as;
4fd9919e 1436 struct bgp *bgp;
d62a17ae 1437 const char *name = NULL;
718e3744 1438
d62a17ae 1439 // "no router bgp" without an ASN
1440 if (argc == 3) {
1441 // Pending: Make VRF option available for ASN less config
8382083a 1442 bgp = bgp_get_default();
718e3744 1443
8382083a 1444 if (bgp == NULL) {
d62a17ae 1445 vty_out(vty, "%% No BGP process is configured\n");
1446 return CMD_WARNING_CONFIG_FAILED;
1447 }
7fb21a9f 1448
d62a17ae 1449 if (listcount(bm->bgp) > 1) {
996c9314 1450 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1451 return CMD_WARNING_CONFIG_FAILED;
1452 }
4fd9919e 1453
4fd9919e
IR
1454 if (bgp->l3vni) {
1455 vty_out(vty, "%% Please unconfigure l3vni %u",
1456 bgp->l3vni);
1457 return CMD_WARNING_CONFIG_FAILED;
1458 }
d62a17ae 1459 } else {
4fd9919e
IR
1460 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1461
1ca42c8d 1462 if (argc > 4) {
d62a17ae 1463 name = argv[idx_vrf]->arg;
1ca42c8d
IR
1464 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1465 && strmatch(name, VRF_DEFAULT_NAME))
1466 name = NULL;
1467 }
7fb21a9f 1468
4fd9919e
IR
1469 /* Lookup bgp structure. */
1470 bgp = bgp_lookup(as, name);
1471 if (!bgp) {
1472 vty_out(vty, "%% Can't find BGP instance\n");
1473 return CMD_WARNING_CONFIG_FAILED;
1474 }
1475
1476 if (bgp->l3vni) {
1477 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1478 bgp->l3vni);
1479 return CMD_WARNING_CONFIG_FAILED;
1480 }
1481
1482 /* Cannot delete default instance if vrf instances exist */
1483 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1484 struct listnode *node;
1485 struct bgp *tmp_bgp;
1486
1487 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1488 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1489 continue;
1490 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1491 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1492 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1493 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1494 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1495 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1496 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1497 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1498 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1499 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1500 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1501 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1502 (bgp == bgp_get_evpn() &&
1503 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1504 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1505 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1506 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1507 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1508 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1509 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1510 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1511 (tmp_bgp->vnihash && hashcount(tmp_bgp->vnihash))) {
1512 vty_out(vty,
1513 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1514 return CMD_WARNING_CONFIG_FAILED;
1515 }
1516 }
1517 }
d62a17ae 1518 }
718e3744 1519
1ca2fd11 1520 bgp_delete(bgp);
718e3744 1521
1ca2fd11 1522 return CMD_SUCCESS;
718e3744 1523}
1524
718e3744 1525
ff8a8a7a
CS
1526/* BGP router-id. */
1527
1ca2fd11
IR
1528DEFPY (bgp_router_id,
1529 bgp_router_id_cmd,
1530 "bgp router-id A.B.C.D",
1531 BGP_STR
1532 "Override configured router identifier\n"
1533 "Manually configured router identifier\n")
718e3744 1534{
1ca2fd11
IR
1535 VTY_DECLVAR_CONTEXT(bgp, bgp);
1536 bgp_router_id_static_set(bgp, router_id);
1537 return CMD_SUCCESS;
ff8a8a7a 1538}
718e3744 1539
1ca2fd11
IR
1540DEFPY (no_bgp_router_id,
1541 no_bgp_router_id_cmd,
1542 "no bgp router-id [A.B.C.D]",
1543 NO_STR
1544 BGP_STR
1545 "Override configured router identifier\n"
1546 "Manually configured router identifier\n")
ff8a8a7a 1547{
1ca2fd11 1548 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1549
1ca2fd11
IR
1550 if (router_id_str) {
1551 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1552 vty_out(vty, "%% BGP router-id doesn't match\n");
1553 return CMD_WARNING_CONFIG_FAILED;
1554 }
1555 }
718e3744 1556
1ca2fd11
IR
1557 router_id.s_addr = 0;
1558 bgp_router_id_static_set(bgp, router_id);
1559
1560 return CMD_SUCCESS;
ff8a8a7a 1561}
6b0655a2 1562
ed0e57e3 1563DEFPY(bgp_community_alias, bgp_community_alias_cmd,
b4ad2fae 1564 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
ed0e57e3
DA
1565 NO_STR BGP_STR
1566 "Add community specific parameters\n"
1567 "Create an alias for a community\n"
1568 "Community (AA:BB or AA:BB:CC)\n"
1569 "Alias name\n")
1570{
1571 struct community_alias ca1;
1572 struct community_alias ca2;
1573 struct community_alias *lookup_community;
1574 struct community_alias *lookup_alias;
1575
1576 if (!community_str2com(community) && !lcommunity_str2com(community)) {
1577 vty_out(vty, "Invalid community format\n");
1578 return CMD_WARNING;
1579 }
1580
1581 memset(&ca1, 0, sizeof(ca1));
1582 memset(&ca2, 0, sizeof(ca2));
1583 strlcpy(ca1.community, community, sizeof(ca1.community));
b4ad2fae 1584 strlcpy(ca1.alias, alias_name, sizeof(ca1.alias));
ed0e57e3
DA
1585
1586 lookup_community = bgp_ca_community_lookup(&ca1);
1587 lookup_alias = bgp_ca_alias_lookup(&ca1);
1588
1589 if (no) {
1590 bgp_ca_alias_delete(&ca1);
1591 bgp_ca_community_delete(&ca1);
1592 } else {
1593 if (lookup_alias) {
1594 /* Lookup if community hash table has an item
1595 * with the same alias name.
1596 */
1597 strlcpy(ca2.community, lookup_alias->community,
1598 sizeof(ca2.community));
1599 if (bgp_ca_community_lookup(&ca2)) {
1600 vty_out(vty,
1601 "community (%s) already has this alias (%s)\n",
1602 lookup_alias->community,
1603 lookup_alias->alias);
1604 return CMD_WARNING;
1605 }
1606 bgp_ca_alias_delete(&ca1);
1607 }
1608
1609 if (lookup_community)
1610 bgp_ca_community_delete(&ca1);
1611
1612 bgp_ca_alias_insert(&ca1);
1613 bgp_ca_community_insert(&ca1);
1614 }
1615
1616 return CMD_SUCCESS;
1617}
1618
9acb67cb
DS
1619DEFPY (bgp_global_suppress_fib_pending,
1620 bgp_global_suppress_fib_pending_cmd,
1621 "[no] bgp suppress-fib-pending",
1622 NO_STR
1623 BGP_STR
1624 "Advertise only routes that are programmed in kernel to peers globally\n")
1625{
1626 bm_wait_for_fib_set(!no);
1627
1628 return CMD_SUCCESS;
1629}
1630
c208c586
S
1631DEFPY (bgp_suppress_fib_pending,
1632 bgp_suppress_fib_pending_cmd,
1633 "[no] bgp suppress-fib-pending",
1634 NO_STR
1635 BGP_STR
1636 "Advertise only routes that are programmed in kernel to peers\n")
1637{
1638 VTY_DECLVAR_CONTEXT(bgp, bgp);
1639
1640 bgp_suppress_fib_pending_set(bgp, !no);
1641 return CMD_SUCCESS;
1642}
1643
1644
718e3744 1645/* BGP Cluster ID. */
1ca2fd11
IR
1646DEFUN (bgp_cluster_id,
1647 bgp_cluster_id_cmd,
1648 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1649 BGP_STR
1650 "Configure Route-Reflector Cluster-id\n"
1651 "Route-Reflector Cluster-id in IP address format\n"
1652 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1653{
1ca2fd11 1654 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1655 int idx_ipv4 = 2;
1ca2fd11
IR
1656 int ret;
1657 struct in_addr cluster;
1658
1659 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1660 if (!ret) {
1661 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1662 return CMD_WARNING_CONFIG_FAILED;
1663 }
718e3744 1664
1ca2fd11
IR
1665 bgp_cluster_id_set(bgp, &cluster);
1666 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1667
1ca2fd11 1668 return CMD_SUCCESS;
718e3744 1669}
1670
1ca2fd11
IR
1671DEFUN (no_bgp_cluster_id,
1672 no_bgp_cluster_id_cmd,
1673 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1674 NO_STR
1675 BGP_STR
1676 "Configure Route-Reflector Cluster-id\n"
1677 "Route-Reflector Cluster-id in IP address format\n"
1678 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1679{
1ca2fd11
IR
1680 VTY_DECLVAR_CONTEXT(bgp, bgp);
1681 bgp_cluster_id_unset(bgp);
1682 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1683
1ca2fd11 1684 return CMD_SUCCESS;
718e3744 1685}
1686
c163f297
DS
1687DEFPY (bgp_norib,
1688 bgp_norib_cmd,
1689 "bgp no-rib",
1690 BGP_STR
1691 "Disable BGP route installation to RIB (Zebra)\n")
1692{
1693 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1694 vty_out(vty,
1695 "%% No-RIB option is already set, nothing to do here.\n");
1696 return CMD_SUCCESS;
1697 }
1698
1699 bgp_option_norib_set_runtime();
1700
1701 return CMD_SUCCESS;
1702}
1703
1704DEFPY (no_bgp_norib,
1705 no_bgp_norib_cmd,
1706 "no bgp no-rib",
1707 NO_STR
1708 BGP_STR
1709 "Disable BGP route installation to RIB (Zebra)\n")
1710{
1711 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1712 vty_out(vty,
1713 "%% No-RIB option is not set, nothing to do here.\n");
1714 return CMD_SUCCESS;
1715 }
1716
1717 bgp_option_norib_unset_runtime();
1718
1719 return CMD_SUCCESS;
1720}
1721
e46723a5
DS
1722DEFPY (no_bgp_send_extra_data,
1723 no_bgp_send_extra_data_cmd,
1724 "[no] bgp send-extra-data zebra",
1725 NO_STR
1726 BGP_STR
1727 "Extra data to Zebra for display/use\n"
1728 "To zebra\n")
1729{
ec0acb80
DA
1730 if (no)
1731 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1732 else
1733 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1734
1735 return CMD_SUCCESS;
1736}
1737
1ca2fd11
IR
1738DEFUN (bgp_confederation_identifier,
1739 bgp_confederation_identifier_cmd,
1740 "bgp confederation identifier (1-4294967295)",
e9273987 1741 BGP_STR
1ca2fd11
IR
1742 "AS confederation parameters\n"
1743 "AS number\n"
1744 "Set routing domain confederation AS\n")
718e3744 1745{
1ca2fd11 1746 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1747 int idx_number = 3;
1ca2fd11 1748 as_t as;
718e3744 1749
1ca2fd11 1750 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1751
1ca2fd11 1752 bgp_confederation_id_set(bgp, as);
718e3744 1753
1ca2fd11 1754 return CMD_SUCCESS;
718e3744 1755}
1756
1ca2fd11
IR
1757DEFUN (no_bgp_confederation_identifier,
1758 no_bgp_confederation_identifier_cmd,
1759 "no bgp confederation identifier [(1-4294967295)]",
1760 NO_STR
e9273987 1761 BGP_STR
1ca2fd11
IR
1762 "AS confederation parameters\n"
1763 "AS number\n"
1764 "Set routing domain confederation AS\n")
ff8a8a7a 1765{
1ca2fd11
IR
1766 VTY_DECLVAR_CONTEXT(bgp, bgp);
1767 bgp_confederation_id_unset(bgp);
1768
1769 return CMD_SUCCESS;
ff8a8a7a
CS
1770}
1771
1ca2fd11
IR
1772DEFUN (bgp_confederation_peers,
1773 bgp_confederation_peers_cmd,
1774 "bgp confederation peers (1-4294967295)...",
e9273987 1775 BGP_STR
1ca2fd11
IR
1776 "AS confederation parameters\n"
1777 "Peer ASs in BGP confederation\n"
1778 AS_STR)
718e3744 1779{
1ca2fd11 1780 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1781 int idx_asn = 3;
1ca2fd11 1782 as_t as;
d62a17ae 1783 int i;
718e3744 1784
1ca2fd11
IR
1785 for (i = idx_asn; i < argc; i++) {
1786 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1787
1ca2fd11
IR
1788 if (bgp->as == as) {
1789 vty_out(vty,
1790 "%% Local member-AS not allowed in confed peer list\n");
1791 continue;
1792 }
1793
1794 bgp_confederation_peers_add(bgp, as);
1795 }
1796 return CMD_SUCCESS;
718e3744 1797}
1798
1ca2fd11
IR
1799DEFUN (no_bgp_confederation_peers,
1800 no_bgp_confederation_peers_cmd,
1801 "no bgp confederation peers (1-4294967295)...",
1802 NO_STR
e9273987 1803 BGP_STR
1ca2fd11
IR
1804 "AS confederation parameters\n"
1805 "Peer ASs in BGP confederation\n"
1806 AS_STR)
718e3744 1807{
1ca2fd11 1808 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1809 int idx_asn = 4;
1ca2fd11 1810 as_t as;
d62a17ae 1811 int i;
718e3744 1812
1ca2fd11
IR
1813 for (i = idx_asn; i < argc; i++) {
1814 as = strtoul(argv[i]->arg, NULL, 10);
ff8a8a7a 1815
1ca2fd11
IR
1816 bgp_confederation_peers_remove(bgp, as);
1817 }
1818 return CMD_SUCCESS;
718e3744 1819}
6b0655a2 1820
5e242b0d
DS
1821/**
1822 * Central routine for maximum-paths configuration.
1823 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1824 * @set: 1 for setting values, 0 for removing the max-paths config.
1825 */
585f1adc
IR
1826static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1827 const char *mpaths, uint16_t options,
1828 int set)
d62a17ae 1829{
585f1adc
IR
1830 VTY_DECLVAR_CONTEXT(bgp, bgp);
1831 uint16_t maxpaths = 0;
d62a17ae 1832 int ret;
585f1adc
IR
1833 afi_t afi;
1834 safi_t safi;
1835
1836 afi = bgp_node_afi(vty);
1837 safi = bgp_node_safi(vty);
d62a17ae 1838
1839 if (set) {
585f1adc 1840 maxpaths = strtol(mpaths, NULL, 10);
d62a17ae 1841 if (maxpaths > multipath_num) {
585f1adc 1842 vty_out(vty,
d62a17ae 1843 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1844 maxpaths, multipath_num);
1845 return CMD_WARNING_CONFIG_FAILED;
1846 }
1847 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1848 options);
1849 } else
1850 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1851
1852 if (ret < 0) {
585f1adc 1853 vty_out(vty,
d62a17ae 1854 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1855 (set == 1) ? "" : "un",
1856 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1857 maxpaths, afi, safi);
1858 return CMD_WARNING_CONFIG_FAILED;
1859 }
1860
1861 bgp_recalculate_all_bestpaths(bgp);
1862
1863 return CMD_SUCCESS;
165b5fff
JB
1864}
1865
1ca2fd11
IR
1866DEFUN (bgp_maxmed_admin,
1867 bgp_maxmed_admin_cmd,
1868 "bgp max-med administrative ",
1869 BGP_STR
1870 "Advertise routes with max-med\n"
1871 "Administratively applied, for an indefinite period\n")
abc920f8 1872{
1ca2fd11 1873 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1874
1ca2fd11
IR
1875 bgp->v_maxmed_admin = 1;
1876 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
ff8a8a7a 1877
1ca2fd11 1878 bgp_maxmed_update(bgp);
abc920f8 1879
1ca2fd11 1880 return CMD_SUCCESS;
ff8a8a7a
CS
1881}
1882
1ca2fd11
IR
1883DEFUN (bgp_maxmed_admin_medv,
1884 bgp_maxmed_admin_medv_cmd,
1885 "bgp max-med administrative (0-4294967295)",
1886 BGP_STR
1887 "Advertise routes with max-med\n"
1888 "Administratively applied, for an indefinite period\n"
1889 "Max MED value to be used\n")
abc920f8 1890{
1ca2fd11 1891 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1892 int idx_number = 3;
abc920f8 1893
1ca2fd11
IR
1894 bgp->v_maxmed_admin = 1;
1895 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1896
1ca2fd11 1897 bgp_maxmed_update(bgp);
abc920f8 1898
1ca2fd11 1899 return CMD_SUCCESS;
abc920f8
DS
1900}
1901
1ca2fd11
IR
1902DEFUN (no_bgp_maxmed_admin,
1903 no_bgp_maxmed_admin_cmd,
1904 "no bgp max-med administrative [(0-4294967295)]",
1905 NO_STR
1906 BGP_STR
1907 "Advertise routes with max-med\n"
1908 "Administratively applied, for an indefinite period\n"
1909 "Max MED value to be used\n")
abc920f8 1910{
1ca2fd11
IR
1911 VTY_DECLVAR_CONTEXT(bgp, bgp);
1912 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1913 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1914 bgp_maxmed_update(bgp);
ff8a8a7a 1915
1ca2fd11 1916 return CMD_SUCCESS;
abc920f8
DS
1917}
1918
1ca2fd11
IR
1919DEFUN (bgp_maxmed_onstartup,
1920 bgp_maxmed_onstartup_cmd,
1921 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1922 BGP_STR
1923 "Advertise routes with max-med\n"
1924 "Effective on a startup\n"
1925 "Time (seconds) period for max-med\n"
1926 "Max MED value to be used\n")
abc920f8 1927{
1ca2fd11 1928 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1929 int idx = 0;
4668a151 1930
d62a17ae 1931 argv_find(argv, argc, "(5-86400)", &idx);
1ca2fd11 1932 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 1933 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1ca2fd11 1934 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 1935 else
1ca2fd11 1936 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1937
1ca2fd11
IR
1938 bgp_maxmed_update(bgp);
1939
1940 return CMD_SUCCESS;
abc920f8
DS
1941}
1942
1ca2fd11
IR
1943DEFUN (no_bgp_maxmed_onstartup,
1944 no_bgp_maxmed_onstartup_cmd,
1945 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1946 NO_STR
1947 BGP_STR
1948 "Advertise routes with max-med\n"
1949 "Effective on a startup\n"
1950 "Time (seconds) period for max-med\n"
1951 "Max MED value to be used\n")
abc920f8 1952{
1ca2fd11
IR
1953 VTY_DECLVAR_CONTEXT(bgp, bgp);
1954
1955 /* Cancel max-med onstartup if its on */
1956 if (bgp->t_maxmed_onstartup) {
1957 thread_cancel(&bgp->t_maxmed_onstartup);
1958 bgp->maxmed_onstartup_over = 1;
1959 }
abc920f8 1960
1ca2fd11
IR
1961 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1962 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1963
1ca2fd11
IR
1964 bgp_maxmed_update(bgp);
1965
1966 return CMD_SUCCESS;
abc920f8
DS
1967}
1968
d70583f7
D
1969static int bgp_global_update_delay_config_vty(struct vty *vty,
1970 uint16_t update_delay,
1971 uint16_t establish_wait)
1972{
1973 struct listnode *node, *nnode;
1974 struct bgp *bgp;
1975 bool vrf_cfg = false;
1976
1977 /*
1978 * See if update-delay is set per-vrf and warn user to delete it
1979 * Note that we only need to check this if this is the first time
1980 * setting the global config.
1981 */
1982 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1983 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1984 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1985 vty_out(vty,
1986 "%% update-delay configuration found in vrf %s\n",
1987 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1988 ? VRF_DEFAULT_NAME
1989 : bgp->name);
1990 vrf_cfg = true;
1991 }
1992 }
1993 }
1994
1995 if (vrf_cfg) {
1996 vty_out(vty,
1997 "%%Failed: global update-delay config not permitted\n");
1998 return CMD_WARNING;
1999 }
2000
2001 if (!establish_wait) { /* update-delay <delay> */
2002 bm->v_update_delay = update_delay;
2003 bm->v_establish_wait = bm->v_update_delay;
2004 } else {
2005 /* update-delay <delay> <establish-wait> */
2006 if (update_delay < establish_wait) {
2007 vty_out(vty,
2008 "%%Failed: update-delay less than the establish-wait!\n");
2009 return CMD_WARNING_CONFIG_FAILED;
2010 }
2011
2012 bm->v_update_delay = update_delay;
2013 bm->v_establish_wait = establish_wait;
2014 }
2015
2016 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2017 bgp->v_update_delay = bm->v_update_delay;
2018 bgp->v_establish_wait = bm->v_establish_wait;
2019 }
2020
2021 return CMD_SUCCESS;
2022}
2023
2024static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2025{
2026 struct listnode *node, *nnode;
2027 struct bgp *bgp;
2028
2029 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2030 bm->v_establish_wait = bm->v_update_delay;
2031
2032 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2033 bgp->v_update_delay = bm->v_update_delay;
2034 bgp->v_establish_wait = bm->v_establish_wait;
2035 }
2036
2037 return CMD_SUCCESS;
2038}
2039
2040static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2041 uint16_t establish_wait)
f188f2c4 2042{
d62a17ae 2043 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2044
d70583f7
D
2045 /* if configured globally, per-instance config is not allowed */
2046 if (bm->v_update_delay) {
2047 vty_out(vty,
2048 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2049 return CMD_WARNING_CONFIG_FAILED;
2050 }
2051
f188f2c4 2052
d70583f7 2053 if (!establish_wait) /* update-delay <delay> */
d62a17ae 2054 {
2055 bgp->v_update_delay = update_delay;
2056 bgp->v_establish_wait = bgp->v_update_delay;
2057 return CMD_SUCCESS;
2058 }
f188f2c4 2059
d62a17ae 2060 /* update-delay <delay> <establish-wait> */
d62a17ae 2061 if (update_delay < establish_wait) {
2062 vty_out(vty,
2063 "%%Failed: update-delay less than the establish-wait!\n");
2064 return CMD_WARNING_CONFIG_FAILED;
2065 }
f188f2c4 2066
d62a17ae 2067 bgp->v_update_delay = update_delay;
2068 bgp->v_establish_wait = establish_wait;
f188f2c4 2069
d62a17ae 2070 return CMD_SUCCESS;
f188f2c4
DS
2071}
2072
d62a17ae 2073static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2074{
d62a17ae 2075 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2076
d70583f7
D
2077 /* If configured globally, cannot remove from one bgp instance */
2078 if (bm->v_update_delay) {
2079 vty_out(vty,
2080 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2081 return CMD_WARNING_CONFIG_FAILED;
2082 }
d62a17ae 2083 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2084 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2085
d62a17ae 2086 return CMD_SUCCESS;
f188f2c4
DS
2087}
2088
2b791107 2089void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2090{
d70583f7
D
2091 /* If configured globally, no need to display per-instance value */
2092 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2093 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2094 if (bgp->v_update_delay != bgp->v_establish_wait)
2095 vty_out(vty, " %d", bgp->v_establish_wait);
2096 vty_out(vty, "\n");
2097 }
f188f2c4
DS
2098}
2099
d70583f7
D
2100/* Global update-delay configuration */
2101DEFPY (bgp_global_update_delay,
2102 bgp_global_update_delay_cmd,
2103 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2104 BGP_STR
2105 "Force initial delay for best-path and updates for all bgp instances\n"
2106 "Max delay in seconds\n"
2107 "Establish wait in seconds\n")
2108{
2109 return bgp_global_update_delay_config_vty(vty, delay, wait);
2110}
f188f2c4 2111
d70583f7
D
2112/* Global update-delay deconfiguration */
2113DEFPY (no_bgp_global_update_delay,
2114 no_bgp_global_update_delay_cmd,
2115 "no bgp update-delay [(0-3600) [(1-3600)]]",
2116 NO_STR
2117 BGP_STR
f188f2c4 2118 "Force initial delay for best-path and updates\n"
d70583f7
D
2119 "Max delay in seconds\n"
2120 "Establish wait in seconds\n")
f188f2c4 2121{
d70583f7 2122 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2123}
2124
d70583f7
D
2125/* Update-delay configuration */
2126
2127DEFPY (bgp_update_delay,
2128 bgp_update_delay_cmd,
2129 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2130 "Force initial delay for best-path and updates\n"
d70583f7
D
2131 "Max delay in seconds\n"
2132 "Establish wait in seconds\n")
f188f2c4 2133{
d70583f7 2134 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2135}
2136
2137/* Update-delay deconfiguration */
d70583f7 2138DEFPY (no_bgp_update_delay,
f188f2c4 2139 no_bgp_update_delay_cmd,
838758ac
DW
2140 "no update-delay [(0-3600) [(1-3600)]]",
2141 NO_STR
f188f2c4 2142 "Force initial delay for best-path and updates\n"
d70583f7
D
2143 "Max delay in seconds\n"
2144 "Establish wait in seconds\n")
f188f2c4 2145{
d62a17ae 2146 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2147}
2148
5e242b0d 2149
1ca2fd11
IR
2150static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2151 bool set)
cb1faec9 2152{
1ca2fd11
IR
2153 VTY_DECLVAR_CONTEXT(bgp, bgp);
2154
8fa7732f
QY
2155 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2156 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2157
2158 return CMD_SUCCESS;
2159}
2160
1ca2fd11
IR
2161static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2162 bool set)
555e09d4 2163{
1ca2fd11
IR
2164 VTY_DECLVAR_CONTEXT(bgp, bgp);
2165
8fa7732f
QY
2166 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2167 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2168
d62a17ae 2169 return CMD_SUCCESS;
cb1faec9
DS
2170}
2171
2b791107 2172void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2173{
555e09d4
QY
2174 uint32_t quanta =
2175 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2176 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2177 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2178}
2179
555e09d4
QY
2180void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2181{
2182 uint32_t quanta =
2183 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2184 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2185 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2186}
cb1faec9 2187
8fa7732f
QY
2188/* Packet quanta configuration
2189 *
2190 * XXX: The value set here controls the size of a stack buffer in the IO
2191 * thread. When changing these limits be careful to prevent stack overflow.
2192 *
2193 * Furthermore, the maximums used here should correspond to
2194 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2195 */
1ca2fd11
IR
2196DEFPY (bgp_wpkt_quanta,
2197 bgp_wpkt_quanta_cmd,
2198 "[no] write-quanta (1-64)$quanta",
2199 NO_STR
2200 "How many packets to write to peer socket per run\n"
2201 "Number of packets\n")
2202{
2203 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2204}
cb1faec9 2205
1ca2fd11
IR
2206DEFPY (bgp_rpkt_quanta,
2207 bgp_rpkt_quanta_cmd,
2208 "[no] read-quanta (1-10)$quanta",
2209 NO_STR
2210 "How many packets to read from peer socket per I/O cycle\n"
2211 "Number of packets\n")
2212{
2213 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
2214}
2215
2b791107 2216void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2217{
37a333fe 2218 if (!bgp->heuristic_coalesce)
d62a17ae 2219 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2220}
2221
4668a151 2222
1ca2fd11
IR
2223DEFUN (bgp_coalesce_time,
2224 bgp_coalesce_time_cmd,
2225 "coalesce-time (0-4294967295)",
2226 "Subgroup coalesce timer\n"
2227 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2228{
1ca2fd11 2229 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 2230
1ca2fd11 2231 int idx = 0;
d62a17ae 2232 argv_find(argv, argc, "(0-4294967295)", &idx);
1ca2fd11
IR
2233 bgp->heuristic_coalesce = false;
2234 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2235 return CMD_SUCCESS;
3f9c7369
DS
2236}
2237
1ca2fd11
IR
2238DEFUN (no_bgp_coalesce_time,
2239 no_bgp_coalesce_time_cmd,
2240 "no coalesce-time (0-4294967295)",
2241 NO_STR
2242 "Subgroup coalesce timer\n"
2243 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2244{
1ca2fd11 2245 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 2246
1ca2fd11
IR
2247 bgp->heuristic_coalesce = true;
2248 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2249 return CMD_SUCCESS;
3f9c7369
DS
2250}
2251
5e242b0d 2252/* Maximum-paths configuration */
585f1adc
IR
2253DEFUN (bgp_maxpaths,
2254 bgp_maxpaths_cmd,
2255 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2256 "Forward packets over multiple paths\n"
2257 "Number of paths\n")
5e242b0d 2258{
d62a17ae 2259 int idx_number = 1;
585f1adc
IR
2260 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2261 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
2262}
2263
d62a17ae 2264ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2265 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2266 "Forward packets over multiple paths\n"
2267 "Number of paths\n")
596c17ba 2268
585f1adc
IR
2269DEFUN (bgp_maxpaths_ibgp,
2270 bgp_maxpaths_ibgp_cmd,
2271 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2272 "Forward packets over multiple paths\n"
2273 "iBGP-multipath\n"
2274 "Number of paths\n")
165b5fff 2275{
d62a17ae 2276 int idx_number = 2;
585f1adc
IR
2277 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2278 argv[idx_number]->arg, 0, 1);
5e242b0d 2279}
165b5fff 2280
d62a17ae 2281ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2282 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2283 "Forward packets over multiple paths\n"
2284 "iBGP-multipath\n"
2285 "Number of paths\n")
596c17ba 2286
585f1adc
IR
2287DEFUN (bgp_maxpaths_ibgp_cluster,
2288 bgp_maxpaths_ibgp_cluster_cmd,
2289 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2290 "Forward packets over multiple paths\n"
2291 "iBGP-multipath\n"
2292 "Number of paths\n"
2293 "Match the cluster length\n")
5e242b0d 2294{
d62a17ae 2295 int idx_number = 2;
585f1adc
IR
2296 return bgp_maxpaths_config_vty(
2297 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
2298 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
2299}
2300
d62a17ae 2301ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2302 "maximum-paths ibgp " CMD_RANGE_STR(
2303 1, MULTIPATH_NUM) " equal-cluster-length",
2304 "Forward packets over multiple paths\n"
2305 "iBGP-multipath\n"
2306 "Number of paths\n"
2307 "Match the cluster length\n")
596c17ba 2308
585f1adc
IR
2309DEFUN (no_bgp_maxpaths,
2310 no_bgp_maxpaths_cmd,
2311 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2312 NO_STR
2313 "Forward packets over multiple paths\n"
2314 "Number of paths\n")
165b5fff 2315{
585f1adc 2316 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
2317}
2318
d62a17ae 2319ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2320 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2321 "Forward packets over multiple paths\n"
2322 "Number of paths\n")
596c17ba 2323
585f1adc
IR
2324DEFUN (no_bgp_maxpaths_ibgp,
2325 no_bgp_maxpaths_ibgp_cmd,
2326 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2327 NO_STR
2328 "Forward packets over multiple paths\n"
2329 "iBGP-multipath\n"
2330 "Number of paths\n"
2331 "Match the cluster length\n")
165b5fff 2332{
585f1adc 2333 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
2334}
2335
d62a17ae 2336ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2337 "no maximum-paths ibgp [" CMD_RANGE_STR(
2338 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2339 NO_STR
2340 "Forward packets over multiple paths\n"
2341 "iBGP-multipath\n"
2342 "Number of paths\n"
2343 "Match the cluster length\n")
596c17ba 2344
dd65f45e
DL
2345static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2346 afi_t afi, safi_t safi)
165b5fff 2347{
00908b7a 2348 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2349 vty_out(vty, " maximum-paths %d\n",
2350 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2351 }
165b5fff 2352
00908b7a 2353 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2354 vty_out(vty, " maximum-paths ibgp %d",
2355 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2356 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2357 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2358 vty_out(vty, " equal-cluster-length");
2359 vty_out(vty, "\n");
2360 }
165b5fff 2361}
6b0655a2 2362
718e3744 2363/* BGP timers. */
2364
1ca2fd11
IR
2365DEFUN (bgp_timers,
2366 bgp_timers_cmd,
2367 "timers bgp (0-65535) (0-65535)",
2368 "Adjust routing timers\n"
2369 "BGP timers\n"
2370 "Keepalive interval\n"
2371 "Holdtime\n")
718e3744 2372{
1ca2fd11 2373 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2374 int idx_number = 2;
2375 int idx_number_2 = 3;
1ca2fd11
IR
2376 unsigned long keepalive = 0;
2377 unsigned long holdtime = 0;
718e3744 2378
1ca2fd11
IR
2379 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2380 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 2381
1ca2fd11
IR
2382 /* Holdtime value check. */
2383 if (holdtime < 3 && holdtime != 0) {
2384 vty_out(vty,
2385 "%% hold time value must be either 0 or greater than 3\n");
2386 return CMD_WARNING_CONFIG_FAILED;
2387 }
718e3744 2388
1ca2fd11
IR
2389 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2390 BGP_DEFAULT_DELAYOPEN);
718e3744 2391
1ca2fd11 2392 return CMD_SUCCESS;
718e3744 2393}
2394
1ca2fd11
IR
2395DEFUN (no_bgp_timers,
2396 no_bgp_timers_cmd,
2397 "no timers bgp [(0-65535) (0-65535)]",
2398 NO_STR
2399 "Adjust routing timers\n"
2400 "BGP timers\n"
2401 "Keepalive interval\n"
2402 "Holdtime\n")
718e3744 2403{
1ca2fd11
IR
2404 VTY_DECLVAR_CONTEXT(bgp, bgp);
2405 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2406 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
ff8a8a7a 2407
1ca2fd11 2408 return CMD_SUCCESS;
718e3744 2409}
2410
b042667a
TI
2411/* BGP minimum holdtime. */
2412
2413DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2414 "bgp minimum-holdtime (1-65535)",
2415 "BGP specific commands\n"
2416 "BGP minimum holdtime\n"
2417 "Seconds\n")
2418{
2419 VTY_DECLVAR_CONTEXT(bgp, bgp);
2420 int idx_number = 2;
2421 unsigned long min_holdtime;
2422
2423 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2424
2425 bgp->default_min_holdtime = min_holdtime;
2426
2427 return CMD_SUCCESS;
2428}
2429
2430DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2431 "no bgp minimum-holdtime [(1-65535)]",
2432 NO_STR
2433 "BGP specific commands\n"
2434 "BGP minimum holdtime\n"
2435 "Seconds\n")
2436{
2437 VTY_DECLVAR_CONTEXT(bgp, bgp);
2438
2439 bgp->default_min_holdtime = 0;
2440
2441 return CMD_SUCCESS;
2442}
ff8a8a7a 2443
1ca2fd11
IR
2444DEFUN (bgp_client_to_client_reflection,
2445 bgp_client_to_client_reflection_cmd,
2446 "bgp client-to-client reflection",
e9273987 2447 BGP_STR
1ca2fd11
IR
2448 "Configure client to client route reflection\n"
2449 "reflection of routes allowed\n")
718e3744 2450{
1ca2fd11
IR
2451 VTY_DECLVAR_CONTEXT(bgp, bgp);
2452 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2453 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2454
1ca2fd11 2455 return CMD_SUCCESS;
718e3744 2456}
2457
1ca2fd11
IR
2458DEFUN (no_bgp_client_to_client_reflection,
2459 no_bgp_client_to_client_reflection_cmd,
2460 "no bgp client-to-client reflection",
2461 NO_STR
e9273987 2462 BGP_STR
1ca2fd11
IR
2463 "Configure client to client route reflection\n"
2464 "reflection of routes allowed\n")
718e3744 2465{
1ca2fd11
IR
2466 VTY_DECLVAR_CONTEXT(bgp, bgp);
2467 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2468 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2469
1ca2fd11 2470 return CMD_SUCCESS;
718e3744 2471}
2472
2473/* "bgp always-compare-med" configuration. */
1ca2fd11
IR
2474DEFUN (bgp_always_compare_med,
2475 bgp_always_compare_med_cmd,
2476 "bgp always-compare-med",
e9273987 2477 BGP_STR
1ca2fd11 2478 "Allow comparing MED from different neighbors\n")
718e3744 2479{
1ca2fd11
IR
2480 VTY_DECLVAR_CONTEXT(bgp, bgp);
2481 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2482 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2483
1ca2fd11 2484 return CMD_SUCCESS;
718e3744 2485}
2486
1ca2fd11
IR
2487DEFUN (no_bgp_always_compare_med,
2488 no_bgp_always_compare_med_cmd,
2489 "no bgp always-compare-med",
2490 NO_STR
e9273987 2491 BGP_STR
1ca2fd11 2492 "Allow comparing MED from different neighbors\n")
718e3744 2493{
1ca2fd11
IR
2494 VTY_DECLVAR_CONTEXT(bgp, bgp);
2495 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2496 bgp_recalculate_all_bestpaths(bgp);
6b0655a2 2497
1ca2fd11 2498 return CMD_SUCCESS;
2adac256
DA
2499}
2500
2adac256 2501
1ca2fd11
IR
2502DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2503 "bgp ebgp-requires-policy",
e9273987 2504 BGP_STR
1ca2fd11 2505 "Require in and out policy for eBGP peers (RFC8212)\n")
2adac256 2506{
1ca2fd11
IR
2507 VTY_DECLVAR_CONTEXT(bgp, bgp);
2508 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2509 return CMD_SUCCESS;
2adac256
DA
2510}
2511
1ca2fd11
IR
2512DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2513 "no bgp ebgp-requires-policy",
2514 NO_STR
e9273987 2515 BGP_STR
1ca2fd11 2516 "Require in and out policy for eBGP peers (RFC8212)\n")
ff8a8a7a 2517{
1ca2fd11
IR
2518 VTY_DECLVAR_CONTEXT(bgp, bgp);
2519 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2520 return CMD_SUCCESS;
ff8a8a7a 2521}
9dac9fc8 2522
1ca2fd11
IR
2523DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2524 "bgp suppress-duplicates",
e9273987 2525 BGP_STR
1ca2fd11 2526 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2527{
1ca2fd11
IR
2528 VTY_DECLVAR_CONTEXT(bgp, bgp);
2529 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2530 return CMD_SUCCESS;
9dac9fc8
DA
2531}
2532
1ca2fd11
IR
2533DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2534 "no bgp suppress-duplicates",
2535 NO_STR
e9273987 2536 BGP_STR
1ca2fd11 2537 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2538{
1ca2fd11
IR
2539 VTY_DECLVAR_CONTEXT(bgp, bgp);
2540 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2541 return CMD_SUCCESS;
9dac9fc8
DA
2542}
2543
fb29348a
DA
2544DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2545 "bgp reject-as-sets",
e9273987 2546 BGP_STR
fb29348a
DA
2547 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2548{
2549 VTY_DECLVAR_CONTEXT(bgp, bgp);
2550 struct listnode *node, *nnode;
2551 struct peer *peer;
2552
7f972cd8 2553 bgp->reject_as_sets = true;
fb29348a
DA
2554
2555 /* Reset existing BGP sessions to reject routes
2556 * with aspath containing AS_SET or AS_CONFED_SET.
2557 */
2558 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2559 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2560 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2561 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2562 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2563 }
2564 }
2565
2566 return CMD_SUCCESS;
2567}
2568
2569DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2570 "no bgp reject-as-sets",
2571 NO_STR
e9273987 2572 BGP_STR
fb29348a
DA
2573 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2574{
2575 VTY_DECLVAR_CONTEXT(bgp, bgp);
2576 struct listnode *node, *nnode;
2577 struct peer *peer;
2578
7f972cd8 2579 bgp->reject_as_sets = false;
fb29348a
DA
2580
2581 /* Reset existing BGP sessions to reject routes
2582 * with aspath containing AS_SET or AS_CONFED_SET.
2583 */
2584 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2585 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2586 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2587 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2588 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2589 }
2590 }
2591
2592 return CMD_SUCCESS;
2593}
9dac9fc8 2594
718e3744 2595/* "bgp deterministic-med" configuration. */
1ca2fd11 2596DEFUN (bgp_deterministic_med,
718e3744 2597 bgp_deterministic_med_cmd,
2598 "bgp deterministic-med",
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
2604 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2605 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2606 bgp_recalculate_all_bestpaths(bgp);
2607 }
7aafcaca 2608
1ca2fd11 2609 return CMD_SUCCESS;
718e3744 2610}
2611
1ca2fd11 2612DEFUN (no_bgp_deterministic_med,
718e3744 2613 no_bgp_deterministic_med_cmd,
2614 "no bgp deterministic-med",
2615 NO_STR
e9273987 2616 BGP_STR
718e3744 2617 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2618{
1ca2fd11
IR
2619 VTY_DECLVAR_CONTEXT(bgp, bgp);
2620 int bestpath_per_as_used;
2621 afi_t afi;
2622 safi_t safi;
2623 struct peer *peer;
2624 struct listnode *node, *nnode;
2625
2626 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2627 bestpath_per_as_used = 0;
2628
2629 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2630 FOREACH_AFI_SAFI (afi, safi)
2631 if (bgp_addpath_dmed_required(
2632 peer->addpath_type[afi][safi])) {
2633 bestpath_per_as_used = 1;
2634 break;
2635 }
2636
2637 if (bestpath_per_as_used)
2638 break;
2639 }
2640
2641 if (bestpath_per_as_used) {
2642 vty_out(vty,
2643 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2644 return CMD_WARNING_CONFIG_FAILED;
2645 } else {
2646 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2647 bgp_recalculate_all_bestpaths(bgp);
2648 }
2649 }
d62a17ae 2650
1ca2fd11 2651 return CMD_SUCCESS;
718e3744 2652}
538621f2 2653
055679e9 2654/* "bgp graceful-restart mode" configuration. */
538621f2 2655DEFUN (bgp_graceful_restart,
2ba1fe69 2656 bgp_graceful_restart_cmd,
2657 "bgp graceful-restart",
e9273987 2658 BGP_STR
2ba1fe69 2659 GR_CMD
055679e9 2660 )
538621f2 2661{
055679e9 2662 int ret = BGP_GR_FAILURE;
2663
2664 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2665 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2666
d62a17ae 2667 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2668
2669 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2670
36235319
QY
2671 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2672 ret);
5cce3f05 2673
055679e9 2674 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2675 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2676 vty_out(vty,
2677 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2678 return bgp_vty_return(vty, ret);
538621f2 2679}
2680
2681DEFUN (no_bgp_graceful_restart,
2ba1fe69 2682 no_bgp_graceful_restart_cmd,
2683 "no bgp graceful-restart",
2684 NO_STR
e9273987 2685 BGP_STR
2ba1fe69 2686 NO_GR_CMD
055679e9 2687 )
538621f2 2688{
d62a17ae 2689 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2690
2691 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2692 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2693
2694 int ret = BGP_GR_FAILURE;
2695
2696 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2697
36235319
QY
2698 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2699 ret);
5cce3f05 2700
055679e9 2701 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2702 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2703 vty_out(vty,
2704 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2705
2706 return bgp_vty_return(vty, ret);
538621f2 2707}
2708
93406d87 2709DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2710 bgp_graceful_restart_stalepath_time_cmd,
2711 "bgp graceful-restart stalepath-time (1-4095)",
e9273987 2712 BGP_STR
2ba1fe69 2713 "Graceful restart capability parameters\n"
2714 "Set the max time to hold onto restarting peer's stale paths\n"
2715 "Delay value (seconds)\n")
93406d87 2716{
d62a17ae 2717 VTY_DECLVAR_CONTEXT(bgp, bgp);
2718 int idx_number = 3;
d7c0a89a 2719 uint32_t stalepath;
93406d87 2720
d62a17ae 2721 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2722 bgp->stalepath_time = stalepath;
2723 return CMD_SUCCESS;
93406d87 2724}
2725
eb6f1b41 2726DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2727 bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2728 "bgp graceful-restart restart-time (0-4095)",
e9273987 2729 BGP_STR
2ba1fe69 2730 "Graceful restart capability parameters\n"
2731 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2732 "Delay value (seconds)\n")
eb6f1b41 2733{
d62a17ae 2734 VTY_DECLVAR_CONTEXT(bgp, bgp);
2735 int idx_number = 3;
d7c0a89a 2736 uint32_t restart;
eb6f1b41 2737
d62a17ae 2738 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2739 bgp->restart_time = restart;
2740 return CMD_SUCCESS;
eb6f1b41
PG
2741}
2742
cfd47646 2743DEFUN (bgp_graceful_restart_select_defer_time,
2744 bgp_graceful_restart_select_defer_time_cmd,
2745 "bgp graceful-restart select-defer-time (0-3600)",
e9273987 2746 BGP_STR
cfd47646 2747 "Graceful restart capability parameters\n"
2748 "Set the time to defer the BGP route selection after restart\n"
2749 "Delay value (seconds, 0 - disable)\n")
2750{
2751 VTY_DECLVAR_CONTEXT(bgp, bgp);
2752 int idx_number = 3;
2753 uint32_t defer_time;
2754
2755 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2756 bgp->select_defer_time = defer_time;
2757 if (defer_time == 0)
892fedb6 2758 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2759 else
892fedb6 2760 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2761
2762 return CMD_SUCCESS;
2763}
2764
93406d87 2765DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2766 no_bgp_graceful_restart_stalepath_time_cmd,
2767 "no bgp graceful-restart stalepath-time [(1-4095)]",
2768 NO_STR
e9273987 2769 BGP_STR
2ba1fe69 2770 "Graceful restart capability parameters\n"
2771 "Set the max time to hold onto restarting peer's stale paths\n"
2772 "Delay value (seconds)\n")
93406d87 2773{
d62a17ae 2774 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2775
d62a17ae 2776 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2777 return CMD_SUCCESS;
93406d87 2778}
2779
eb6f1b41 2780DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2781 no_bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2782 "no bgp graceful-restart restart-time [(0-4095)]",
2ba1fe69 2783 NO_STR
e9273987 2784 BGP_STR
2ba1fe69 2785 "Graceful restart capability parameters\n"
2786 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2787 "Delay value (seconds)\n")
eb6f1b41 2788{
d62a17ae 2789 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2790
d62a17ae 2791 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2792 return CMD_SUCCESS;
eb6f1b41
PG
2793}
2794
cfd47646 2795DEFUN (no_bgp_graceful_restart_select_defer_time,
2796 no_bgp_graceful_restart_select_defer_time_cmd,
2797 "no bgp graceful-restart select-defer-time [(0-3600)]",
2798 NO_STR
e9273987 2799 BGP_STR
cfd47646 2800 "Graceful restart capability parameters\n"
2801 "Set the time to defer the BGP route selection after restart\n"
2802 "Delay value (seconds)\n")
2803{
2804 VTY_DECLVAR_CONTEXT(bgp, bgp);
2805
2806 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2807 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2808
2809 return CMD_SUCCESS;
2810}
2811
43fc21b3 2812DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2813 bgp_graceful_restart_preserve_fw_cmd,
2814 "bgp graceful-restart preserve-fw-state",
e9273987 2815 BGP_STR
2ba1fe69 2816 "Graceful restart capability parameters\n"
2817 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2818{
d62a17ae 2819 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2820 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2821 return CMD_SUCCESS;
43fc21b3
JC
2822}
2823
2824DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2825 no_bgp_graceful_restart_preserve_fw_cmd,
2826 "no bgp graceful-restart preserve-fw-state",
2827 NO_STR
e9273987 2828 BGP_STR
2ba1fe69 2829 "Graceful restart capability parameters\n"
2830 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2831{
d62a17ae 2832 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2833 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2834 return CMD_SUCCESS;
43fc21b3
JC
2835}
2836
055679e9 2837DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2838 bgp_graceful_restart_disable_cmd,
2839 "bgp graceful-restart-disable",
e9273987 2840 BGP_STR
2ba1fe69 2841 GR_DISABLE)
055679e9 2842{
2843 int ret = BGP_GR_FAILURE;
2844
2845 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2846 zlog_debug(
2ba1fe69 2847 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2848
055679e9 2849 VTY_DECLVAR_CONTEXT(bgp, bgp);
2850
2851 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2852
dc95985f 2853 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2854 bgp->peer, ret);
5cce3f05 2855
055679e9 2856 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2857 zlog_debug(
2ba1fe69 2858 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2859 vty_out(vty,
2860 "Graceful restart configuration changed, reset all peers to take effect\n");
2861
055679e9 2862 return bgp_vty_return(vty, ret);
2863}
2864
2865DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2866 no_bgp_graceful_restart_disable_cmd,
2867 "no bgp graceful-restart-disable",
2868 NO_STR
e9273987 2869 BGP_STR
2ba1fe69 2870 NO_GR_DISABLE
055679e9 2871 )
2872{
2873 VTY_DECLVAR_CONTEXT(bgp, bgp);
2874
2875 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2876 zlog_debug(
2ba1fe69 2877 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2878
2879 int ret = BGP_GR_FAILURE;
2880
2881 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2882
36235319
QY
2883 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2884 ret);
5cce3f05 2885
055679e9 2886 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2887 zlog_debug(
2ba1fe69 2888 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2889 vty_out(vty,
2890 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2891
2892 return bgp_vty_return(vty, ret);
2893}
2894
2895DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2896 bgp_neighbor_graceful_restart_set_cmd,
2897 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2898 NEIGHBOR_STR
2899 NEIGHBOR_ADDR_STR2
2900 GR_NEIGHBOR_CMD
055679e9 2901 )
2902{
2903 int idx_peer = 1;
2904 struct peer *peer;
2905 int ret = BGP_GR_FAILURE;
2906
dc95985f 2907 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2908
055679e9 2909 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2910 zlog_debug(
2ba1fe69 2911 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2912
055679e9 2913 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2914 if (!peer)
2915 return CMD_WARNING_CONFIG_FAILED;
2916
2917 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2918
dc95985f 2919 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2920 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2921
2922 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2923 zlog_debug(
2ba1fe69 2924 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2925 vty_out(vty,
2926 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2927
2928 return bgp_vty_return(vty, ret);
2929}
2930
2931DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 2932 no_bgp_neighbor_graceful_restart_set_cmd,
2933 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2934 NO_STR
2935 NEIGHBOR_STR
2936 NEIGHBOR_ADDR_STR2
2937 NO_GR_NEIGHBOR_CMD
055679e9 2938 )
2939{
2940 int idx_peer = 2;
2941 int ret = BGP_GR_FAILURE;
2942 struct peer *peer;
2943
dc95985f 2944 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2945
055679e9 2946 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2947 if (!peer)
2948 return CMD_WARNING_CONFIG_FAILED;
2949
2950 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2951 zlog_debug(
2ba1fe69 2952 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 2953
2954 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2955
dc95985f 2956 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2957 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2958
2959 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2960 zlog_debug(
2ba1fe69 2961 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2962 vty_out(vty,
2963 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2964
2965 return bgp_vty_return(vty, ret);
2966}
2967
2968DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 2969 bgp_neighbor_graceful_restart_helper_set_cmd,
2970 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2971 NEIGHBOR_STR
2972 NEIGHBOR_ADDR_STR2
2973 GR_NEIGHBOR_HELPER_CMD
055679e9 2974 )
2975{
2976 int idx_peer = 1;
2977 struct peer *peer;
2978 int ret = BGP_GR_FAILURE;
2979
dc95985f 2980 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2981
055679e9 2982 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2983 zlog_debug(
2ba1fe69 2984 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 2985
055679e9 2986 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2987
055679e9 2988 if (!peer)
2989 return CMD_WARNING_CONFIG_FAILED;
2990
2991
2992 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 2993
dc95985f 2994 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2995 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 2996
055679e9 2997 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2998 zlog_debug(
2ba1fe69 2999 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3000 vty_out(vty,
3001 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3002
3003 return bgp_vty_return(vty, ret);
3004}
3005
3006DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3007 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3008 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3009 NO_STR
3010 NEIGHBOR_STR
3011 NEIGHBOR_ADDR_STR2
3012 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3013 )
3014{
3015 int idx_peer = 2;
3016 int ret = BGP_GR_FAILURE;
3017 struct peer *peer;
3018
dc95985f 3019 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3020
055679e9 3021 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3022 if (!peer)
3023 return CMD_WARNING_CONFIG_FAILED;
3024
3025 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3026 zlog_debug(
2ba1fe69 3027 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3028
36235319 3029 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3030
dc95985f 3031 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3032 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3033
3034 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3035 zlog_debug(
2ba1fe69 3036 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3037 vty_out(vty,
3038 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3039
3040 return bgp_vty_return(vty, ret);
3041}
3042
3043DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3044 bgp_neighbor_graceful_restart_disable_set_cmd,
3045 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3046 NEIGHBOR_STR
3047 NEIGHBOR_ADDR_STR2
3048 GR_NEIGHBOR_DISABLE_CMD
055679e9 3049 )
3050{
3051 int idx_peer = 1;
3052 struct peer *peer;
3053 int ret = BGP_GR_FAILURE;
3054
dc95985f 3055 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3056
055679e9 3057 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3058 zlog_debug(
2ba1fe69 3059 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3060
3061 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3062 if (!peer)
3063 return CMD_WARNING_CONFIG_FAILED;
3064
36235319 3065 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3066
3067 if (peer->bgp->t_startup)
3068 bgp_peer_gr_flags_update(peer);
3069
dc95985f 3070 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3071 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3072
055679e9 3073 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3074 zlog_debug(
2ba1fe69 3075 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3076 vty_out(vty,
3077 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3078
3079 return bgp_vty_return(vty, ret);
3080}
3081
3082DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3083 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3084 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3085 NO_STR
3086 NEIGHBOR_STR
3087 NEIGHBOR_ADDR_STR2
3088 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3089 )
3090{
3091 int idx_peer = 2;
3092 int ret = BGP_GR_FAILURE;
3093 struct peer *peer;
3094
dc95985f 3095 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3096
055679e9 3097 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3098 if (!peer)
3099 return CMD_WARNING_CONFIG_FAILED;
3100
3101 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3102 zlog_debug(
2ba1fe69 3103 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3104
3105 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3106
dc95985f 3107 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3108 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3109
3110 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3111 zlog_debug(
2ba1fe69 3112 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3113 vty_out(vty,
3114 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3115
3116 return bgp_vty_return(vty, ret);
3117}
3118
d6e3c15b 3119DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3120 bgp_graceful_restart_disable_eor_cmd,
3121 "bgp graceful-restart disable-eor",
e9273987 3122 BGP_STR
d6e3c15b 3123 "Graceful restart configuration parameters\n"
3124 "Disable EOR Check\n")
3125{
3126 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3127 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3128
d6e3c15b 3129 return CMD_SUCCESS;
3130}
3131
3132DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3133 no_bgp_graceful_restart_disable_eor_cmd,
3134 "no bgp graceful-restart disable-eor",
3135 NO_STR
e9273987 3136 BGP_STR
d6e3c15b 3137 "Graceful restart configuration parameters\n"
3138 "Disable EOR Check\n")
3139{
3140 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3141 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3142
3143 return CMD_SUCCESS;
3144}
3145
3146DEFUN (bgp_graceful_restart_rib_stale_time,
3147 bgp_graceful_restart_rib_stale_time_cmd,
3148 "bgp graceful-restart rib-stale-time (1-3600)",
e9273987 3149 BGP_STR
dc95985f 3150 "Graceful restart configuration parameters\n"
3151 "Specify the stale route removal timer in rib\n"
3152 "Delay value (seconds)\n")
3153{
3154 VTY_DECLVAR_CONTEXT(bgp, bgp);
3155 int idx_number = 3;
3156 uint32_t stale_time;
3157
3158 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3159 bgp->rib_stale_time = stale_time;
3160 /* Send the stale timer update message to RIB */
3161 if (bgp_zebra_stale_timer_update(bgp))
3162 return CMD_WARNING;
3163
3164 return CMD_SUCCESS;
3165}
3166
3167DEFUN (no_bgp_graceful_restart_rib_stale_time,
3168 no_bgp_graceful_restart_rib_stale_time_cmd,
3169 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3170 NO_STR
e9273987 3171 BGP_STR
dc95985f 3172 "Graceful restart configuration parameters\n"
3173 "Specify the stale route removal timer in rib\n"
3174 "Delay value (seconds)\n")
3175{
3176 VTY_DECLVAR_CONTEXT(bgp, bgp);
3177
3178 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3179 /* Send the stale timer update message to RIB */
3180 if (bgp_zebra_stale_timer_update(bgp))
3181 return CMD_WARNING;
3182
d6e3c15b 3183 return CMD_SUCCESS;
3184}
3185
8606be87 3186DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
7f8a9a24
DA
3187 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3188 BGP_STR
8606be87
DA
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 uint32_t llgr_stale_time;
3196
3197 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3198 bgp->llgr_stale_time = llgr_stale_time;
3199
3200 return CMD_SUCCESS;
3201}
3202
3203DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
7f8a9a24 3204 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
8606be87
DA
3205 NO_STR BGP_STR
3206 "Enable Long-lived Graceful Restart\n"
3207 "Specifies maximum time to wait before purging long-lived stale routes\n"
3208 "Stale time value (seconds)\n")
3209{
3210 VTY_DECLVAR_CONTEXT(bgp, bgp);
3211
3212 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3213
3214 return CMD_SUCCESS;
3215}
3216
1ca2fd11
IR
3217static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3218 struct bgp *bgp)
05bd726c 3219{
3220 bgp_static_redo_import_check(bgp);
3221 bgp_redistribute_redo(bgp);
1ca2fd11
IR
3222 bgp_clear_star_soft_out(vty, bgp->name);
3223 bgp_clear_star_soft_in(vty, bgp->name);
05bd726c 3224}
3225
3226static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3227{
3228 struct listnode *node, *nnode;
3229 struct bgp *bgp;
3230 bool vrf_cfg = false;
3231
3232 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3233 return CMD_SUCCESS;
3234
3235 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3236 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3237 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3238 vty_out(vty,
3239 "%% graceful-shutdown configuration found in vrf %s\n",
3240 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3241 VRF_DEFAULT_NAME : bgp->name);
3242 vrf_cfg = true;
3243 }
3244 }
3245
3246 if (vrf_cfg) {
3247 vty_out(vty,
3248 "%%Failed: global graceful-shutdown not permitted\n");
3249 return CMD_WARNING;
3250 }
3251
3252 /* Set flag globally */
3253 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3254
3255 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3256 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3257 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3258
3259 return CMD_SUCCESS;
3260}
3261
3262static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3263{
3264 struct listnode *node, *nnode;
3265 struct bgp *bgp;
3266
3267 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3268 return CMD_SUCCESS;
3269
3270 /* Unset flag globally */
3271 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3272
3273 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3274 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3275 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3276
3277 return CMD_SUCCESS;
3278}
3279
7f323236
DW
3280/* "bgp graceful-shutdown" configuration */
3281DEFUN (bgp_graceful_shutdown,
3282 bgp_graceful_shutdown_cmd,
3283 "bgp graceful-shutdown",
3284 BGP_STR
3285 "Graceful shutdown parameters\n")
3286{
05bd726c 3287 if (vty->node == CONFIG_NODE)
3288 return bgp_global_graceful_shutdown_config_vty(vty);
3289
1ca2fd11 3290 VTY_DECLVAR_CONTEXT(bgp, bgp);
7f323236 3291
1ca2fd11
IR
3292 /* if configured globally, per-instance config is not allowed */
3293 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3294 vty_out(vty,
3295 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3296 return CMD_WARNING_CONFIG_FAILED;
3297 }
3298
3299 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3300 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3301 bgp_initiate_graceful_shut_unshut(vty, bgp);
3302 }
3303
3304 return CMD_SUCCESS;
7f323236
DW
3305}
3306
1ca2fd11 3307DEFUN (no_bgp_graceful_shutdown,
7f323236
DW
3308 no_bgp_graceful_shutdown_cmd,
3309 "no bgp graceful-shutdown",
3310 NO_STR
3311 BGP_STR
3312 "Graceful shutdown parameters\n")
3313{
05bd726c 3314 if (vty->node == CONFIG_NODE)
3315 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3316
1ca2fd11 3317 VTY_DECLVAR_CONTEXT(bgp, bgp);
05bd726c 3318
1ca2fd11
IR
3319 /* If configured globally, cannot remove from one bgp instance */
3320 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3321 vty_out(vty,
3322 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3323 return CMD_WARNING_CONFIG_FAILED;
3324 }
7f323236 3325
1ca2fd11
IR
3326 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3327 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3328 bgp_initiate_graceful_shut_unshut(vty, bgp);
3329 }
3330
3331 return CMD_SUCCESS;
7f323236
DW
3332}
3333
718e3744 3334/* "bgp fast-external-failover" configuration. */
1ca2fd11 3335DEFUN (bgp_fast_external_failover,
718e3744 3336 bgp_fast_external_failover_cmd,
3337 "bgp fast-external-failover",
3338 BGP_STR
3339 "Immediately reset session if a link to a directly connected external peer goes down\n")
3340{
1ca2fd11
IR
3341 VTY_DECLVAR_CONTEXT(bgp, bgp);
3342 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3343 return CMD_SUCCESS;
718e3744 3344}
3345
1ca2fd11 3346DEFUN (no_bgp_fast_external_failover,
718e3744 3347 no_bgp_fast_external_failover_cmd,
3348 "no bgp fast-external-failover",
3349 NO_STR
3350 BGP_STR
3351 "Immediately reset session if a link to a directly connected external peer goes down\n")
3352{
1ca2fd11
IR
3353 VTY_DECLVAR_CONTEXT(bgp, bgp);
3354 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3355 return CMD_SUCCESS;
718e3744 3356}
6b0655a2 3357
718e3744 3358/* "bgp bestpath compare-routerid" configuration. */
1ca2fd11
IR
3359DEFUN (bgp_bestpath_compare_router_id,
3360 bgp_bestpath_compare_router_id_cmd,
3361 "bgp bestpath compare-routerid",
e9273987 3362 BGP_STR
1ca2fd11
IR
3363 "Change the default bestpath selection\n"
3364 "Compare router-id for identical EBGP paths\n")
718e3744 3365{
1ca2fd11
IR
3366 VTY_DECLVAR_CONTEXT(bgp, bgp);
3367 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3368 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3369
1ca2fd11 3370 return CMD_SUCCESS;
718e3744 3371}
3372
1ca2fd11
IR
3373DEFUN (no_bgp_bestpath_compare_router_id,
3374 no_bgp_bestpath_compare_router_id_cmd,
3375 "no bgp bestpath compare-routerid",
3376 NO_STR
e9273987 3377 BGP_STR
1ca2fd11
IR
3378 "Change the default bestpath selection\n"
3379 "Compare router-id for identical EBGP paths\n")
718e3744 3380{
1ca2fd11
IR
3381 VTY_DECLVAR_CONTEXT(bgp, bgp);
3382 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3383 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3384
1ca2fd11 3385 return CMD_SUCCESS;
718e3744 3386}
6b0655a2 3387
718e3744 3388/* "bgp bestpath as-path ignore" configuration. */
1ca2fd11
IR
3389DEFUN (bgp_bestpath_aspath_ignore,
3390 bgp_bestpath_aspath_ignore_cmd,
3391 "bgp bestpath as-path ignore",
e9273987 3392 BGP_STR
1ca2fd11
IR
3393 "Change the default bestpath selection\n"
3394 "AS-path attribute\n"
3395 "Ignore as-path length in selecting a route\n")
718e3744 3396{
1ca2fd11
IR
3397 VTY_DECLVAR_CONTEXT(bgp, bgp);
3398 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3399 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3400
1ca2fd11 3401 return CMD_SUCCESS;
718e3744 3402}
3403
1ca2fd11
IR
3404DEFUN (no_bgp_bestpath_aspath_ignore,
3405 no_bgp_bestpath_aspath_ignore_cmd,
3406 "no bgp bestpath as-path ignore",
3407 NO_STR
e9273987 3408 BGP_STR
1ca2fd11
IR
3409 "Change the default bestpath selection\n"
3410 "AS-path attribute\n"
3411 "Ignore as-path length in selecting a route\n")
718e3744 3412{
1ca2fd11
IR
3413 VTY_DECLVAR_CONTEXT(bgp, bgp);
3414 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3415 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3416
1ca2fd11 3417 return CMD_SUCCESS;
718e3744 3418}
6b0655a2 3419
6811845b 3420/* "bgp bestpath as-path confed" configuration. */
1ca2fd11 3421DEFUN (bgp_bestpath_aspath_confed,
6811845b 3422 bgp_bestpath_aspath_confed_cmd,
3423 "bgp bestpath as-path confed",
e9273987 3424 BGP_STR
6811845b 3425 "Change the default bestpath selection\n"
3426 "AS-path attribute\n"
3427 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3428{
1ca2fd11
IR
3429 VTY_DECLVAR_CONTEXT(bgp, bgp);
3430 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3431 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3432
1ca2fd11 3433 return CMD_SUCCESS;
6811845b 3434}
3435
1ca2fd11 3436DEFUN (no_bgp_bestpath_aspath_confed,
6811845b 3437 no_bgp_bestpath_aspath_confed_cmd,
3438 "no bgp bestpath as-path confed",
3439 NO_STR
e9273987 3440 BGP_STR
6811845b 3441 "Change the default bestpath selection\n"
3442 "AS-path attribute\n"
3443 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3444{
1ca2fd11
IR
3445 VTY_DECLVAR_CONTEXT(bgp, bgp);
3446 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3447 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3448
1ca2fd11 3449 return CMD_SUCCESS;
6811845b 3450}
6b0655a2 3451
2fdd455c 3452/* "bgp bestpath as-path multipath-relax" configuration. */
1ca2fd11 3453DEFUN (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3454 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3455 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
e9273987 3456 BGP_STR
16fc1eec
DS
3457 "Change the default bestpath selection\n"
3458 "AS-path attribute\n"
3459 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3460 "Generate an AS_SET\n"
16fc1eec
DS
3461 "Do not generate an AS_SET\n")
3462{
1ca2fd11 3463 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3464 int idx = 0;
1ca2fd11 3465 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 3466
1ca2fd11
IR
3467 /* no-as-set is now the default behavior so we can silently
3468 * ignore it */
d62a17ae 3469 if (argv_find(argv, argc, "as-set", &idx))
1ca2fd11 3470 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 3471 else
1ca2fd11 3472 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
7aafcaca 3473
1ca2fd11
IR
3474 bgp_recalculate_all_bestpaths(bgp);
3475
3476 return CMD_SUCCESS;
16fc1eec
DS
3477}
3478
1ca2fd11 3479DEFUN (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3480 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3481 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec 3482 NO_STR
e9273987 3483 BGP_STR
16fc1eec
DS
3484 "Change the default bestpath selection\n"
3485 "AS-path attribute\n"
3486 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3487 "Generate an AS_SET\n"
16fc1eec
DS
3488 "Do not generate an AS_SET\n")
3489{
1ca2fd11
IR
3490 VTY_DECLVAR_CONTEXT(bgp, bgp);
3491 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3492 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3493 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3494
1ca2fd11 3495 return CMD_SUCCESS;
2fdd455c 3496}
6b0655a2 3497
ee88563a
JM
3498/* "bgp bestpath peer-type multipath-relax" configuration. */
3499DEFUN(bgp_bestpath_peer_type_multipath_relax,
3500 bgp_bestpath_peer_type_multipath_relax_cmd,
3501 "bgp bestpath peer-type multipath-relax",
3502 BGP_STR
3503 "Change the default bestpath selection\n"
3504 "Peer type\n"
3505 "Allow load sharing across routes learned from different peer types\n")
3506{
3507 VTY_DECLVAR_CONTEXT(bgp, bgp);
3508 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3509 bgp_recalculate_all_bestpaths(bgp);
3510
3511 return CMD_SUCCESS;
3512}
3513
3514DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3515 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3516 "no bgp bestpath peer-type multipath-relax",
3517 NO_STR BGP_STR
3518 "Change the default bestpath selection\n"
3519 "Peer type\n"
3520 "Allow load sharing across routes learned from different peer types\n")
3521{
3522 VTY_DECLVAR_CONTEXT(bgp, bgp);
3523 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3524 bgp_recalculate_all_bestpaths(bgp);
3525
3526 return CMD_SUCCESS;
3527}
3528
848973c7 3529/* "bgp log-neighbor-changes" configuration. */
1ca2fd11
IR
3530DEFUN (bgp_log_neighbor_changes,
3531 bgp_log_neighbor_changes_cmd,
3532 "bgp log-neighbor-changes",
e9273987 3533 BGP_STR
1ca2fd11 3534 "Log neighbor up/down and reset reason\n")
848973c7 3535{
1ca2fd11
IR
3536 VTY_DECLVAR_CONTEXT(bgp, bgp);
3537 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3538 return CMD_SUCCESS;
848973c7 3539}
3540
1ca2fd11
IR
3541DEFUN (no_bgp_log_neighbor_changes,
3542 no_bgp_log_neighbor_changes_cmd,
3543 "no bgp log-neighbor-changes",
3544 NO_STR
e9273987 3545 BGP_STR
1ca2fd11 3546 "Log neighbor up/down and reset reason\n")
848973c7 3547{
1ca2fd11
IR
3548 VTY_DECLVAR_CONTEXT(bgp, bgp);
3549 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3550 return CMD_SUCCESS;
848973c7 3551}
6b0655a2 3552
718e3744 3553/* "bgp bestpath med" configuration. */
1ca2fd11 3554DEFUN (bgp_bestpath_med,
718e3744 3555 bgp_bestpath_med_cmd,
2d8c1a4d 3556 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
e9273987 3557 BGP_STR
718e3744 3558 "Change the default bestpath selection\n"
3559 "MED attribute\n"
3560 "Compare MED among confederation paths\n"
838758ac
DW
3561 "Treat missing MED as the least preferred one\n"
3562 "Treat missing MED as the least preferred one\n"
3563 "Compare MED among confederation paths\n")
718e3744 3564{
1ca2fd11 3565 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3566
1ca2fd11 3567 int idx = 0;
d62a17ae 3568 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3569 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3570 idx = 0;
3571 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11 3572 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 3573
1ca2fd11 3574 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3575
1ca2fd11 3576 return CMD_SUCCESS;
718e3744 3577}
3578
1ca2fd11 3579DEFUN (no_bgp_bestpath_med,
718e3744 3580 no_bgp_bestpath_med_cmd,
2d8c1a4d 3581 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3582 NO_STR
e9273987 3583 BGP_STR
718e3744 3584 "Change the default bestpath selection\n"
3585 "MED attribute\n"
3586 "Compare MED among confederation paths\n"
3a2d747c
QY
3587 "Treat missing MED as the least preferred one\n"
3588 "Treat missing MED as the least preferred one\n"
3589 "Compare MED among confederation paths\n")
718e3744 3590{
1ca2fd11 3591 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3592
1ca2fd11 3593 int idx = 0;
d62a17ae 3594 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3595 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3596 idx = 0;
3597 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11
IR
3598 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3599
3600 bgp_recalculate_all_bestpaths(bgp);
718e3744 3601
1ca2fd11 3602 return CMD_SUCCESS;
718e3744 3603}
3604
f7e1c681 3605/* "bgp bestpath bandwidth" configuration. */
3606DEFPY (bgp_bestpath_bw,
3607 bgp_bestpath_bw_cmd,
ad36d216 3608 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
e9273987 3609 BGP_STR
f7e1c681 3610 "Change the default bestpath selection\n"
3611 "Link Bandwidth attribute\n"
3612 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3613 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3614 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3615{
3616 VTY_DECLVAR_CONTEXT(bgp, bgp);
3617 afi_t afi;
3618 safi_t safi;
3619
ad36d216
DS
3620 if (!bw_cfg) {
3621 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3622 return CMD_ERR_INCOMPLETE;
f7e1c681 3623 }
ad36d216
DS
3624 if (!strcmp(bw_cfg, "ignore"))
3625 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3626 else if (!strcmp(bw_cfg, "skip-missing"))
3627 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3628 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3629 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3630 else
3631 return CMD_ERR_NO_MATCH;
f7e1c681 3632
3633 /* This config is used in route install, so redo that. */
3634 FOREACH_AFI_SAFI (afi, safi) {
3635 if (!bgp_fibupd_safi(safi))
3636 continue;
3637 bgp_zebra_announce_table(bgp, afi, safi);
3638 }
3639
3640 return CMD_SUCCESS;
3641}
3642
ad36d216
DS
3643DEFPY (no_bgp_bestpath_bw,
3644 no_bgp_bestpath_bw_cmd,
3645 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3646 NO_STR
e9273987 3647 BGP_STR
ad36d216
DS
3648 "Change the default bestpath selection\n"
3649 "Link Bandwidth attribute\n"
3650 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3651 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3652 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3653{
3654 VTY_DECLVAR_CONTEXT(bgp, bgp);
3655 afi_t afi;
3656 safi_t safi;
3657
3658 bgp->lb_handling = BGP_LINK_BW_ECMP;
3659
3660 /* This config is used in route install, so redo that. */
3661 FOREACH_AFI_SAFI (afi, safi) {
3662 if (!bgp_fibupd_safi(safi))
3663 continue;
3664 bgp_zebra_announce_table(bgp, afi, safi);
3665 }
3666 return CMD_SUCCESS;
3667}
3668
b16bcbba 3669DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
38d11af5
TA
3670 "[no] bgp default <ipv4-unicast|"
3671 "ipv4-multicast|"
3672 "ipv4-vpn|"
3673 "ipv4-labeled-unicast|"
3674 "ipv4-flowspec|"
3675 "ipv6-unicast|"
3676 "ipv6-multicast|"
3677 "ipv6-vpn|"
3678 "ipv6-labeled-unicast|"
3679 "ipv6-flowspec|"
3680 "l2vpn-evpn>$afi_safi",
b16bcbba 3681 NO_STR
e9273987 3682 BGP_STR
e84c59af 3683 "Configure BGP defaults\n"
b16bcbba 3684 "Activate ipv4-unicast for a peer by default\n"
38d11af5
TA
3685 "Activate ipv4-multicast for a peer by default\n"
3686 "Activate ipv4-vpn for a peer by default\n"
3687 "Activate ipv4-labeled-unicast for a peer by default\n"
3688 "Activate ipv4-flowspec for a peer by default\n"
3689 "Activate ipv6-unicast for a peer by default\n"
3690 "Activate ipv6-multicast for a peer by default\n"
3691 "Activate ipv6-vpn for a peer by default\n"
3692 "Activate ipv6-labeled-unicast for a peer by default\n"
3693 "Activate ipv6-flowspec for a peer by default\n"
3694 "Activate l2vpn-evpn for a peer by default\n")
e84c59af
DA
3695{
3696 VTY_DECLVAR_CONTEXT(bgp, bgp);
b16bcbba
TA
3697 char afi_safi_str[strlen(afi_safi) + 1];
3698 char *afi_safi_str_tok;
e84c59af 3699
b16bcbba
TA
3700 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3701 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3702 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3703 afi_t afi = bgp_vty_afi_from_str(afi_str);
38d11af5 3704 safi_t safi;
e84c59af 3705
38d11af5
TA
3706 if (strmatch(safi_str, "labeled"))
3707 safi = bgp_vty_safi_from_str("labeled-unicast");
3708 else
3709 safi = bgp_vty_safi_from_str(safi_str);
b16bcbba
TA
3710
3711 if (no)
3712 bgp->default_af[afi][safi] = false;
38d11af5
TA
3713 else {
3714 if ((safi == SAFI_LABELED_UNICAST
3715 && bgp->default_af[afi][SAFI_UNICAST])
3716 || (safi == SAFI_UNICAST
3717 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3718 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3719 else
3720 bgp->default_af[afi][safi] = true;
3721 }
718e3744 3722
d62a17ae 3723 return CMD_SUCCESS;
718e3744 3724}
6b0655a2 3725
04b6bdc0 3726/* Display hostname in certain command outputs */
1ca2fd11 3727DEFUN (bgp_default_show_hostname,
04b6bdc0
DW
3728 bgp_default_show_hostname_cmd,
3729 "bgp default show-hostname",
e9273987 3730 BGP_STR
04b6bdc0 3731 "Configure BGP defaults\n"
0437e105 3732 "Show hostname in certain command outputs\n")
04b6bdc0 3733{
1ca2fd11
IR
3734 VTY_DECLVAR_CONTEXT(bgp, bgp);
3735 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3736 return CMD_SUCCESS;
ff8a8a7a
CS
3737}
3738
1ca2fd11
IR
3739DEFUN (no_bgp_default_show_hostname,
3740 no_bgp_default_show_hostname_cmd,
3741 "no bgp default show-hostname",
3742 NO_STR
e9273987 3743 BGP_STR
1ca2fd11
IR
3744 "Configure BGP defaults\n"
3745 "Show hostname in certain command outputs\n")
ff8a8a7a 3746{
1ca2fd11
IR
3747 VTY_DECLVAR_CONTEXT(bgp, bgp);
3748 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3749 return CMD_SUCCESS;
04b6bdc0
DW
3750}
3751
aef999a2 3752/* Display hostname in certain command outputs */
1d80f243
IR
3753DEFUN (bgp_default_show_nexthop_hostname,
3754 bgp_default_show_nexthop_hostname_cmd,
3755 "bgp default show-nexthop-hostname",
e9273987 3756 BGP_STR
1d80f243
IR
3757 "Configure BGP defaults\n"
3758 "Show hostname for nexthop in certain command outputs\n")
aef999a2 3759{
1ca2fd11
IR
3760 VTY_DECLVAR_CONTEXT(bgp, bgp);
3761 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3762 return CMD_SUCCESS;
aef999a2
DA
3763}
3764
3765DEFUN (no_bgp_default_show_nexthop_hostname,
3766 no_bgp_default_show_nexthop_hostname_cmd,
3767 "no bgp default show-nexthop-hostname",
3768 NO_STR
e9273987 3769 BGP_STR
aef999a2
DA
3770 "Configure BGP defaults\n"
3771 "Show hostname for nexthop in certain command outputs\n")
3772{
1ca2fd11
IR
3773 VTY_DECLVAR_CONTEXT(bgp, bgp);
3774 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3775 return CMD_SUCCESS;
aef999a2
DA
3776}
3777
8233ef81 3778/* "bgp network import-check" configuration. */
1ca2fd11
IR
3779DEFUN (bgp_network_import_check,
3780 bgp_network_import_check_cmd,
3781 "bgp network import-check",
e9273987 3782 BGP_STR
1ca2fd11
IR
3783 "BGP network command\n"
3784 "Check BGP network route exists in IGP\n")
718e3744 3785{
1ca2fd11
IR
3786 VTY_DECLVAR_CONTEXT(bgp, bgp);
3787 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3788 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3789 bgp_static_redo_import_check(bgp);
3790 }
078430f6 3791
1ca2fd11 3792 return CMD_SUCCESS;
718e3744 3793}
3794
d62a17ae 3795ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3796 "bgp network import-check exact",
e9273987 3797 BGP_STR
d62a17ae 3798 "BGP network command\n"
3799 "Check BGP network route exists in IGP\n"
3800 "Match route precisely\n")
8233ef81 3801
1ca2fd11
IR
3802DEFUN (no_bgp_network_import_check,
3803 no_bgp_network_import_check_cmd,
3804 "no bgp network import-check",
3805 NO_STR
e9273987 3806 BGP_STR
1ca2fd11
IR
3807 "BGP network command\n"
3808 "Check BGP network route exists in IGP\n")
718e3744 3809{
1ca2fd11
IR
3810 VTY_DECLVAR_CONTEXT(bgp, bgp);
3811 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3812 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3813 bgp_static_redo_import_check(bgp);
3814 }
6b0655a2 3815
1ca2fd11 3816 return CMD_SUCCESS;
ff8a8a7a 3817}
718e3744 3818
1ca2fd11
IR
3819DEFUN (bgp_default_local_preference,
3820 bgp_default_local_preference_cmd,
3821 "bgp default local-preference (0-4294967295)",
e9273987 3822 BGP_STR
1ca2fd11
IR
3823 "Configure BGP defaults\n"
3824 "local preference (higher=more preferred)\n"
3825 "Configure default local preference value\n")
ff8a8a7a 3826{
1ca2fd11 3827 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3828 int idx_number = 3;
1ca2fd11 3829 uint32_t local_pref;
718e3744 3830
1ca2fd11 3831 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 3832
1ca2fd11
IR
3833 bgp_default_local_preference_set(bgp, local_pref);
3834 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 3835
1ca2fd11 3836 return CMD_SUCCESS;
718e3744 3837}
3838
1ca2fd11
IR
3839DEFUN (no_bgp_default_local_preference,
3840 no_bgp_default_local_preference_cmd,
3841 "no bgp default local-preference [(0-4294967295)]",
3842 NO_STR
e9273987 3843 BGP_STR
1ca2fd11
IR
3844 "Configure BGP defaults\n"
3845 "local preference (higher=more preferred)\n"
3846 "Configure default local preference value\n")
ff8a8a7a 3847{
1ca2fd11
IR
3848 VTY_DECLVAR_CONTEXT(bgp, bgp);
3849 bgp_default_local_preference_unset(bgp);
3850 bgp_clear_star_soft_in(vty, bgp->name);
3851
3852 return CMD_SUCCESS;
ff8a8a7a 3853}
6b0655a2 3854
ff8a8a7a 3855
1ca2fd11
IR
3856DEFUN (bgp_default_subgroup_pkt_queue_max,
3857 bgp_default_subgroup_pkt_queue_max_cmd,
3858 "bgp default subgroup-pkt-queue-max (20-100)",
e9273987 3859 BGP_STR
1ca2fd11
IR
3860 "Configure BGP defaults\n"
3861 "subgroup-pkt-queue-max\n"
3862 "Configure subgroup packet queue max\n")
8bd9d948 3863{
1ca2fd11 3864 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3865 int idx_number = 3;
1ca2fd11 3866 uint32_t max_size;
3f9c7369 3867
1ca2fd11 3868 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 3869
1ca2fd11 3870 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
ff8a8a7a 3871
1ca2fd11 3872 return CMD_SUCCESS;
8bd9d948
DS
3873}
3874
1ca2fd11
IR
3875DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3876 no_bgp_default_subgroup_pkt_queue_max_cmd,
3877 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3878 NO_STR
e9273987 3879 BGP_STR
1ca2fd11
IR
3880 "Configure BGP defaults\n"
3881 "subgroup-pkt-queue-max\n"
3882 "Configure subgroup packet queue max\n")
ff8a8a7a 3883{
1ca2fd11
IR
3884 VTY_DECLVAR_CONTEXT(bgp, bgp);
3885 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3886 return CMD_SUCCESS;
ff8a8a7a 3887}
813d4307 3888
8bd9d948 3889
1ca2fd11
IR
3890DEFUN (bgp_rr_allow_outbound_policy,
3891 bgp_rr_allow_outbound_policy_cmd,
3892 "bgp route-reflector allow-outbound-policy",
e9273987 3893 BGP_STR
1ca2fd11
IR
3894 "Allow modifications made by out route-map\n"
3895 "on ibgp neighbors\n")
ff8a8a7a 3896{
1ca2fd11 3897 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3898
1ca2fd11
IR
3899 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3900 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3901 update_group_announce_rrclients(bgp);
3902 bgp_clear_star_soft_out(vty, bgp->name);
3903 }
8bd9d948 3904
1ca2fd11
IR
3905 return CMD_SUCCESS;
3906}
ff8a8a7a 3907
1ca2fd11
IR
3908DEFUN (no_bgp_rr_allow_outbound_policy,
3909 no_bgp_rr_allow_outbound_policy_cmd,
3910 "no bgp route-reflector allow-outbound-policy",
3911 NO_STR
e9273987 3912 BGP_STR
1ca2fd11
IR
3913 "Allow modifications made by out route-map\n"
3914 "on ibgp neighbors\n")
8bd9d948 3915{
1ca2fd11 3916 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 3917
1ca2fd11
IR
3918 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3919 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3920 update_group_announce_rrclients(bgp);
3921 bgp_clear_star_soft_out(vty, bgp->name);
d62a17ae 3922 }
8bd9d948 3923
1ca2fd11 3924 return CMD_SUCCESS;
8bd9d948
DS
3925}
3926
1ca2fd11
IR
3927DEFUN (bgp_listen_limit,
3928 bgp_listen_limit_cmd,
3929 "bgp listen limit (1-65535)",
e9273987 3930 BGP_STR
1ca2fd11
IR
3931 "BGP Dynamic Neighbors listen commands\n"
3932 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3933 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3934{
1ca2fd11 3935 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3936 int idx_number = 3;
1ca2fd11
IR
3937 int listen_limit;
3938
3939 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 3940
1ca2fd11 3941 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 3942
1ca2fd11 3943 return CMD_SUCCESS;
f14e6fdb
DS
3944}
3945
1ca2fd11
IR
3946DEFUN (no_bgp_listen_limit,
3947 no_bgp_listen_limit_cmd,
3948 "no bgp listen limit [(1-65535)]",
3949 NO_STR
e9273987 3950 BGP_STR
1ca2fd11
IR
3951 "BGP Dynamic Neighbors listen commands\n"
3952 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3953 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3954{
1ca2fd11
IR
3955 VTY_DECLVAR_CONTEXT(bgp, bgp);
3956 bgp_listen_limit_unset(bgp);
3957 return CMD_SUCCESS;
f14e6fdb
DS
3958}
3959
3960
20eb8864 3961/*
3962 * Check if this listen range is already configured. Check for exact
3963 * match or overlap based on input.
3964 */
d62a17ae 3965static struct peer_group *listen_range_exists(struct bgp *bgp,
3966 struct prefix *range, int exact)
3967{
3968 struct listnode *node, *nnode;
3969 struct listnode *node1, *nnode1;
3970 struct peer_group *group;
3971 struct prefix *lr;
3972 afi_t afi;
3973 int match;
3974
3975 afi = family2afi(range->family);
3976 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3977 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3978 lr)) {
3979 if (exact)
3980 match = prefix_same(range, lr);
3981 else
3982 match = (prefix_match(range, lr)
3983 || prefix_match(lr, range));
3984 if (match)
3985 return group;
3986 }
3987 }
3988
3989 return NULL;
20eb8864 3990}
3991
f14e6fdb
DS
3992DEFUN (bgp_listen_range,
3993 bgp_listen_range_cmd,
d7b9898c 3994 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
e9273987 3995 BGP_STR
d7fa34c1
QY
3996 "Configure BGP dynamic neighbors listen range\n"
3997 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
3998 NEIGHBOR_ADDR_STR
3999 "Member of the peer-group\n"
4000 "Peer-group name\n")
f14e6fdb 4001{
d62a17ae 4002 VTY_DECLVAR_CONTEXT(bgp, bgp);
4003 struct prefix range;
4004 struct peer_group *group, *existing_group;
4005 afi_t afi;
4006 int ret;
4007 int idx = 0;
4008
4009 argv_find(argv, argc, "A.B.C.D/M", &idx);
4010 argv_find(argv, argc, "X:X::X:X/M", &idx);
4011 char *prefix = argv[idx]->arg;
d7b9898c 4012 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4013 char *peergroup = argv[idx]->arg;
4014
4015 /* Convert IP prefix string to struct prefix. */
4016 ret = str2prefix(prefix, &range);
4017 if (!ret) {
4018 vty_out(vty, "%% Malformed listen range\n");
4019 return CMD_WARNING_CONFIG_FAILED;
4020 }
4021
4022 afi = family2afi(range.family);
4023
4024 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4025 vty_out(vty,
4026 "%% Malformed listen range (link-local address)\n");
4027 return CMD_WARNING_CONFIG_FAILED;
4028 }
4029
4030 apply_mask(&range);
4031
4032 /* Check if same listen range is already configured. */
4033 existing_group = listen_range_exists(bgp, &range, 1);
4034 if (existing_group) {
4035 if (strcmp(existing_group->name, peergroup) == 0)
4036 return CMD_SUCCESS;
4037 else {
4038 vty_out(vty,
4039 "%% Same listen range is attached to peer-group %s\n",
4040 existing_group->name);
4041 return CMD_WARNING_CONFIG_FAILED;
4042 }
4043 }
4044
4045 /* Check if an overlapping listen range exists. */
4046 if (listen_range_exists(bgp, &range, 0)) {
4047 vty_out(vty,
4048 "%% Listen range overlaps with existing listen range\n");
4049 return CMD_WARNING_CONFIG_FAILED;
4050 }
4051
4052 group = peer_group_lookup(bgp, peergroup);
4053 if (!group) {
4054 vty_out(vty, "%% Configure the peer-group first\n");
4055 return CMD_WARNING_CONFIG_FAILED;
4056 }
4057
4058 ret = peer_group_listen_range_add(group, &range);
4059 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4060}
4061
4062DEFUN (no_bgp_listen_range,
4063 no_bgp_listen_range_cmd,
d7b9898c 4064 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4065 NO_STR
e9273987 4066 BGP_STR
d7fa34c1
QY
4067 "Unconfigure BGP dynamic neighbors listen range\n"
4068 "Unconfigure BGP dynamic neighbors listen range\n"
4069 NEIGHBOR_ADDR_STR
4070 "Member of the peer-group\n"
4071 "Peer-group name\n")
f14e6fdb 4072{
d62a17ae 4073 VTY_DECLVAR_CONTEXT(bgp, bgp);
4074 struct prefix range;
4075 struct peer_group *group;
4076 afi_t afi;
4077 int ret;
4078 int idx = 0;
4079
4080 argv_find(argv, argc, "A.B.C.D/M", &idx);
4081 argv_find(argv, argc, "X:X::X:X/M", &idx);
4082 char *prefix = argv[idx]->arg;
21d88a71 4083 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4084 char *peergroup = argv[idx]->arg;
4085
4086 /* Convert IP prefix string to struct prefix. */
4087 ret = str2prefix(prefix, &range);
4088 if (!ret) {
4089 vty_out(vty, "%% Malformed listen range\n");
4090 return CMD_WARNING_CONFIG_FAILED;
4091 }
4092
4093 afi = family2afi(range.family);
4094
4095 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4096 vty_out(vty,
4097 "%% Malformed listen range (link-local address)\n");
4098 return CMD_WARNING_CONFIG_FAILED;
4099 }
4100
4101 apply_mask(&range);
4102
4103 group = peer_group_lookup(bgp, peergroup);
4104 if (!group) {
4105 vty_out(vty, "%% Peer-group does not exist\n");
4106 return CMD_WARNING_CONFIG_FAILED;
4107 }
4108
4109 ret = peer_group_listen_range_del(group, &range);
4110 return bgp_vty_return(vty, ret);
4111}
4112
2b791107 4113void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4114{
4115 struct peer_group *group;
4116 struct listnode *node, *nnode, *rnode, *nrnode;
4117 struct prefix *range;
4118 afi_t afi;
d62a17ae 4119
4120 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4121 vty_out(vty, " bgp listen limit %d\n",
4122 bgp->dynamic_neighbors_limit);
4123
4124 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4125 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4126 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4127 nrnode, range)) {
d62a17ae 4128 vty_out(vty,
2dbe669b
DA
4129 " bgp listen range %pFX peer-group %s\n",
4130 range, group->name);
d62a17ae 4131 }
4132 }
4133 }
f14e6fdb
DS
4134}
4135
4136
1ca2fd11
IR
4137DEFUN (bgp_disable_connected_route_check,
4138 bgp_disable_connected_route_check_cmd,
4139 "bgp disable-ebgp-connected-route-check",
e9273987 4140 BGP_STR
1ca2fd11 4141 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4142{
1ca2fd11
IR
4143 VTY_DECLVAR_CONTEXT(bgp, bgp);
4144 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4145 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 4146
1ca2fd11 4147 return CMD_SUCCESS;
907f92c8
DS
4148}
4149
1ca2fd11
IR
4150DEFUN (no_bgp_disable_connected_route_check,
4151 no_bgp_disable_connected_route_check_cmd,
4152 "no bgp disable-ebgp-connected-route-check",
4153 NO_STR
e9273987 4154 BGP_STR
1ca2fd11 4155 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4156{
1ca2fd11
IR
4157 VTY_DECLVAR_CONTEXT(bgp, bgp);
4158 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4159 bgp_clear_star_soft_in(vty, bgp->name);
d62a17ae 4160
1ca2fd11 4161 return CMD_SUCCESS;
d62a17ae 4162}
4163
4164
28c6e247
IR
4165static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4166 const char *as_str)
4167{
4168 VTY_DECLVAR_CONTEXT(bgp, bgp);
4169 int ret;
4170 as_t as;
4171 int as_type = AS_SPECIFIED;
4172 union sockunion su;
4173
4174 if (as_str[0] == 'i') {
4175 as = 0;
4176 as_type = AS_INTERNAL;
4177 } else if (as_str[0] == 'e') {
4178 as = 0;
4179 as_type = AS_EXTERNAL;
4180 } else {
4181 /* Get AS number. */
4182 as = strtoul(as_str, NULL, 10);
4183 }
4184
4185 /* If peer is peer group or interface peer, call proper function. */
4186 ret = str2sockunion(peer_str, &su);
4187 if (ret < 0) {
4188 struct peer *peer;
4189
4190 /* Check if existing interface peer */
4191 peer = peer_lookup_by_conf_if(bgp, peer_str);
4192
4193 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4194
4195 /* if not interface peer, check peer-group settings */
4196 if (ret < 0 && !peer) {
4197 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4198 if (ret < 0) {
4199 vty_out(vty,
4200 "%% Create the peer-group or interface first\n");
4201 return CMD_WARNING_CONFIG_FAILED;
4202 }
4203 return CMD_SUCCESS;
4204 }
4205 } else {
4206 if (peer_address_self_check(bgp, &su)) {
4207 vty_out(vty,
4208 "%% Can not configure the local system as neighbor\n");
4209 return CMD_WARNING_CONFIG_FAILED;
4210 }
4211 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4212 }
4213
4214 /* This peer belongs to peer group. */
4215 switch (ret) {
4216 case BGP_ERR_PEER_GROUP_MEMBER:
4217 vty_out(vty,
4218 "%% Peer-group member cannot override remote-as of peer-group\n");
4219 return CMD_WARNING_CONFIG_FAILED;
4220 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
4221 vty_out(vty,
4222 "%% Peer-group members must be all internal or all external\n");
4223 return CMD_WARNING_CONFIG_FAILED;
4224 }
4225 return bgp_vty_return(vty, ret);
4226}
4227
1ca2fd11
IR
4228DEFUN (bgp_default_shutdown,
4229 bgp_default_shutdown_cmd,
4230 "[no] bgp default shutdown",
4231 NO_STR
4232 BGP_STR
4233 "Configure BGP defaults\n"
4234 "Apply administrative shutdown to newly configured peers\n")
ff8a8a7a 4235{
1ca2fd11
IR
4236 VTY_DECLVAR_CONTEXT(bgp, bgp);
4237 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4238 return CMD_SUCCESS;
f26845f9
QY
4239}
4240
736b68f3
DS
4241DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4242 BGP_STR
9ddf4b81 4243 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4244 "Add a shutdown message (RFC 8203)\n"
4245 "Shutdown message\n")
9cf59432 4246{
736b68f3 4247 char *msgstr = NULL;
8389c83a 4248
9cf59432
DS
4249 VTY_DECLVAR_CONTEXT(bgp, bgp);
4250
8389c83a 4251 if (argc > 3)
f80e35b6 4252 msgstr = argv_concat(argv, argc, 3);
8389c83a 4253
b776f48c
DA
4254 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4255 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4256 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4257 return CMD_WARNING_CONFIG_FAILED;
4258 }
4259
8389c83a
DS
4260 bgp_shutdown_enable(bgp, msgstr);
4261 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4262
4263 return CMD_SUCCESS;
4264}
4265
736b68f3 4266DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4267 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4268{
4269 VTY_DECLVAR_CONTEXT(bgp, bgp);
4270
4271 bgp_shutdown_enable(bgp, NULL);
4272
4273 return CMD_SUCCESS;
4274}
8389c83a 4275
736b68f3 4276DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4277 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4278{
4279 VTY_DECLVAR_CONTEXT(bgp, bgp);
4280
4281 bgp_shutdown_disable(bgp);
4282
4283 return CMD_SUCCESS;
4284}
4285
9ddf4b81 4286ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4287 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4288 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4289 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4290
28c6e247
IR
4291DEFUN (neighbor_remote_as,
4292 neighbor_remote_as_cmd,
4293 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4294 NEIGHBOR_STR
4295 NEIGHBOR_ADDR_STR2
4296 "Specify a BGP neighbor\n"
4297 AS_STR
4298 "Internal BGP peer\n"
4299 "External BGP peer\n")
718e3744 4300{
d62a17ae 4301 int idx_peer = 1;
4302 int idx_remote_as = 3;
28c6e247
IR
4303 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4304 argv[idx_remote_as]->arg);
d62a17ae 4305}
f852eb98
PG
4306/* Enable fast convergence of bgp sessions. If this is enabled, bgp
4307 * sessions do not wait for hold timer expiry to bring down the sessions
4308 * when nexthop becomes unreachable
4309 */
4310DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4311 BGP_STR "Fast convergence for bgp sessions\n")
4312{
4313 VTY_DECLVAR_CONTEXT(bgp, bgp);
4314 bgp->fast_convergence = true;
4315
4316 return CMD_SUCCESS;
4317}
4318
4319DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4320 "no bgp fast-convergence",
4321 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4322{
4323 VTY_DECLVAR_CONTEXT(bgp, bgp);
4324 bgp->fast_convergence = false;
4325
4326 return CMD_SUCCESS;
4327}
d62a17ae 4328
28c6e247
IR
4329static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4330 int v6only,
4331 const char *peer_group_name,
4332 const char *as_str)
d62a17ae 4333{
28c6e247
IR
4334 VTY_DECLVAR_CONTEXT(bgp, bgp);
4335 as_t as = 0;
4336 int as_type = AS_UNSPECIFIED;
d62a17ae 4337 struct peer *peer;
4338 struct peer_group *group;
4339 int ret = 0;
d62a17ae 4340
4341 group = peer_group_lookup(bgp, conf_if);
4342
4343 if (group) {
28c6e247
IR
4344 vty_out(vty, "%% Name conflict with peer-group \n");
4345 return CMD_WARNING_CONFIG_FAILED;
4346 }
4347
4348 if (as_str) {
4349 if (as_str[0] == 'i') {
4350 as_type = AS_INTERNAL;
4351 } else if (as_str[0] == 'e') {
4352 as_type = AS_EXTERNAL;
4353 } else {
4354 /* Get AS number. */
4355 as = strtoul(as_str, NULL, 10);
4356 as_type = AS_SPECIFIED;
4357 }
d62a17ae 4358 }
4359
4360 peer = peer_lookup_by_conf_if(bgp, conf_if);
4361 if (peer) {
28c6e247 4362 if (as_str)
e84c59af 4363 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
d62a17ae 4364 } else {
e84c59af
DA
4365 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4366 NULL);
d62a17ae 4367
4368 if (!peer) {
28c6e247
IR
4369 vty_out(vty, "%% BGP failed to create peer\n");
4370 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4371 }
4372
4373 if (v6only)
527de3dc 4374 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4375
4376 /* Request zebra to initiate IPv6 RAs on this interface. We do
4377 * this
4378 * any unnumbered peer in order to not worry about run-time
4379 * transitions
4380 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4381 * address
4382 * gets deleted later etc.)
4383 */
4384 if (peer->ifp)
4385 bgp_zebra_initiate_radv(bgp, peer);
4386 }
4387
4388 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4389 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4390 if (v6only)
527de3dc 4391 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4392 else
527de3dc 4393 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4394
4395 /* v6only flag changed. Reset bgp seesion */
4396 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4397 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4398 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4399 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4400 } else
4401 bgp_session_reset(peer);
4402 }
4403
9fb964de
PM
4404 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4405 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4406 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4407 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4408 }
d62a17ae 4409
4410 if (peer_group_name) {
4411 group = peer_group_lookup(bgp, peer_group_name);
4412 if (!group) {
28c6e247
IR
4413 vty_out(vty, "%% Configure the peer-group first\n");
4414 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4415 }
4416
8395c1f8 4417 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4418 }
4419
28c6e247 4420 return bgp_vty_return(vty, ret);
a80beece
DS
4421}
4422
28c6e247
IR
4423DEFUN (neighbor_interface_config,
4424 neighbor_interface_config_cmd,
4425 "neighbor WORD interface [peer-group PGNAME]",
4426 NEIGHBOR_STR
4427 "Interface name or neighbor tag\n"
4428 "Enable BGP on interface\n"
4429 "Member of the peer-group\n"
4430 "Peer-group name\n")
4c48cf63 4431{
d62a17ae 4432 int idx_word = 1;
4433 int idx_peer_group_word = 4;
f4b8ec07 4434
d62a17ae 4435 if (argc > idx_peer_group_word)
28c6e247
IR
4436 return peer_conf_interface_get(
4437 vty, argv[idx_word]->arg, 0,
4438 argv[idx_peer_group_word]->arg, NULL);
4439 else
4440 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4441 NULL, NULL);
4c48cf63
DW
4442}
4443
28c6e247
IR
4444DEFUN (neighbor_interface_config_v6only,
4445 neighbor_interface_config_v6only_cmd,
4446 "neighbor WORD interface v6only [peer-group PGNAME]",
4447 NEIGHBOR_STR
4448 "Interface name or neighbor tag\n"
4449 "Enable BGP on interface\n"
4450 "Enable BGP with v6 link-local only\n"
4451 "Member of the peer-group\n"
4452 "Peer-group name\n")
4c48cf63 4453{
d62a17ae 4454 int idx_word = 1;
4455 int idx_peer_group_word = 5;
31500417 4456
d62a17ae 4457 if (argc > idx_peer_group_word)
28c6e247
IR
4458 return peer_conf_interface_get(
4459 vty, argv[idx_word]->arg, 1,
4460 argv[idx_peer_group_word]->arg, NULL);
31500417 4461
28c6e247 4462 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4c48cf63
DW
4463}
4464
a80beece 4465
28c6e247
IR
4466DEFUN (neighbor_interface_config_remote_as,
4467 neighbor_interface_config_remote_as_cmd,
4468 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4469 NEIGHBOR_STR
4470 "Interface name or neighbor tag\n"
4471 "Enable BGP on interface\n"
4472 "Specify a BGP neighbor\n"
4473 AS_STR
4474 "Internal BGP peer\n"
4475 "External BGP peer\n")
b3a39dc5 4476{
d62a17ae 4477 int idx_word = 1;
4478 int idx_remote_as = 4;
28c6e247
IR
4479 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4480 argv[idx_remote_as]->arg);
b3a39dc5
DD
4481}
4482
28c6e247
IR
4483DEFUN (neighbor_interface_v6only_config_remote_as,
4484 neighbor_interface_v6only_config_remote_as_cmd,
4485 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4486 NEIGHBOR_STR
4487 "Interface name or neighbor tag\n"
4488 "Enable BGP with v6 link-local only\n"
4489 "Enable BGP on interface\n"
4490 "Specify a BGP neighbor\n"
4491 AS_STR
4492 "Internal BGP peer\n"
4493 "External BGP peer\n")
b3a39dc5 4494{
d62a17ae 4495 int idx_word = 1;
4496 int idx_remote_as = 5;
28c6e247
IR
4497 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4498 argv[idx_remote_as]->arg);
b3a39dc5
DD
4499}
4500
28c6e247
IR
4501DEFUN (neighbor_peer_group,
4502 neighbor_peer_group_cmd,
4503 "neighbor WORD peer-group",
4504 NEIGHBOR_STR
4505 "Interface name or neighbor tag\n"
4506 "Configure peer-group\n")
718e3744 4507{
28c6e247 4508 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4509 int idx_word = 1;
28c6e247
IR
4510 struct peer *peer;
4511 struct peer_group *group;
718e3744 4512
28c6e247
IR
4513 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4514 if (peer) {
4515 vty_out(vty, "%% Name conflict with interface: \n");
4516 return CMD_WARNING_CONFIG_FAILED;
4517 }
718e3744 4518
28c6e247
IR
4519 group = peer_group_get(bgp, argv[idx_word]->arg);
4520 if (!group) {
4521 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4522 return CMD_WARNING_CONFIG_FAILED;
4523 }
718e3744 4524
28c6e247 4525 return CMD_SUCCESS;
718e3744 4526}
4527
1d80f243
IR
4528DEFUN (no_neighbor,
4529 no_neighbor_cmd,
4530 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4531 NO_STR
4532 NEIGHBOR_STR
4533 NEIGHBOR_ADDR_STR2
4534 "Specify a BGP neighbor\n"
4535 AS_STR
4536 "Internal BGP peer\n"
4537 "External BGP peer\n")
718e3744 4538{
28c6e247 4539 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4540 int idx_peer = 2;
28c6e247 4541 int ret;
d62a17ae 4542 union sockunion su;
28c6e247
IR
4543 struct peer_group *group;
4544 struct peer *peer;
4545 struct peer *other;
d62a17ae 4546
28c6e247
IR
4547 ret = str2sockunion(argv[idx_peer]->arg, &su);
4548 if (ret < 0) {
4549 /* look up for neighbor by interface name config. */
4550 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4551 if (peer) {
4552 /* Request zebra to terminate IPv6 RAs on this
4553 * interface. */
4554 if (peer->ifp)
4555 bgp_zebra_terminate_radv(peer->bgp, peer);
4556 peer_notify_unconfig(peer);
4557 peer_delete(peer);
4558 return CMD_SUCCESS;
d62a17ae 4559 }
28c6e247
IR
4560
4561 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4562 if (group) {
4563 peer_group_notify_unconfig(group);
4564 peer_group_delete(group);
4e2786df 4565 } else {
28c6e247 4566 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4567 return CMD_WARNING_CONFIG_FAILED;
4568 }
28c6e247
IR
4569 } else {
4570 peer = peer_lookup(bgp, &su);
4571 if (peer) {
4572 if (peer_dynamic_neighbor(peer)) {
4573 vty_out(vty,
4574 "%% Operation not allowed on a dynamic neighbor\n");
4575 return CMD_WARNING_CONFIG_FAILED;
4576 }
d62a17ae 4577
28c6e247 4578 other = peer->doppelganger;
f4b8ec07 4579
28c6e247
IR
4580 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4581 bgp_zebra_terminate_radv(peer->bgp, peer);
f4b8ec07 4582
28c6e247
IR
4583 peer_notify_unconfig(peer);
4584 peer_delete(peer);
4585 if (other && other->status != Deleted) {
4586 peer_notify_unconfig(other);
4587 peer_delete(other);
4588 }
4589 }
4590 }
4591
4592 return CMD_SUCCESS;
a80beece
DS
4593}
4594
28c6e247
IR
4595DEFUN (no_neighbor_interface_config,
4596 no_neighbor_interface_config_cmd,
4597 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4598 NO_STR
4599 NEIGHBOR_STR
4600 "Interface name\n"
4601 "Configure BGP on interface\n"
4602 "Enable BGP with v6 link-local only\n"
4603 "Member of the peer-group\n"
4604 "Peer-group name\n"
4605 "Specify a BGP neighbor\n"
4606 AS_STR
4607 "Internal BGP peer\n"
4608 "External BGP peer\n")
718e3744 4609{
28c6e247 4610 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4611 int idx_word = 2;
28c6e247 4612 struct peer *peer;
718e3744 4613
28c6e247
IR
4614 /* look up for neighbor by interface name config. */
4615 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4616 if (peer) {
4617 /* Request zebra to terminate IPv6 RAs on this interface. */
4618 if (peer->ifp)
4619 bgp_zebra_terminate_radv(peer->bgp, peer);
4620 peer_notify_unconfig(peer);
4621 peer_delete(peer);
4622 } else {
4623 vty_out(vty, "%% Create the bgp interface first\n");
4624 return CMD_WARNING_CONFIG_FAILED;
4625 }
4626 return CMD_SUCCESS;
718e3744 4627}
4628
28c6e247
IR
4629DEFUN (no_neighbor_peer_group,
4630 no_neighbor_peer_group_cmd,
4631 "no neighbor WORD peer-group",
4632 NO_STR
4633 NEIGHBOR_STR
4634 "Neighbor tag\n"
4635 "Configure peer-group\n")
718e3744 4636{
28c6e247
IR
4637 VTY_DECLVAR_CONTEXT(bgp, bgp);
4638 int idx_word = 2;
4639 struct peer_group *group;
f4b8ec07 4640
28c6e247
IR
4641 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4642 if (group) {
4643 peer_group_notify_unconfig(group);
4644 peer_group_delete(group);
f4b8ec07 4645 } else {
28c6e247 4646 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4647 return CMD_WARNING_CONFIG_FAILED;
4648 }
28c6e247
IR
4649 return CMD_SUCCESS;
4650}
f4b8ec07 4651
28c6e247
IR
4652DEFUN (no_neighbor_interface_peer_group_remote_as,
4653 no_neighbor_interface_peer_group_remote_as_cmd,
4654 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4655 NO_STR
4656 NEIGHBOR_STR
4657 "Interface name or neighbor tag\n"
4658 "Specify a BGP neighbor\n"
4659 AS_STR
4660 "Internal BGP peer\n"
4661 "External BGP peer\n")
4662{
4663 VTY_DECLVAR_CONTEXT(bgp, bgp);
4664 int idx_word = 2;
4665 struct peer_group *group;
4666 struct peer *peer;
f4b8ec07 4667
28c6e247
IR
4668 /* look up for neighbor by interface name config. */
4669 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4670 if (peer) {
4671 peer_as_change(peer, 0, AS_UNSPECIFIED);
4672 return CMD_SUCCESS;
4673 }
f4b8ec07 4674
28c6e247
IR
4675 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4676 if (group)
4677 peer_group_remote_as_delete(group);
4678 else {
4679 vty_out(vty, "%% Create the peer-group or interface first\n");
4680 return CMD_WARNING_CONFIG_FAILED;
4681 }
4682 return CMD_SUCCESS;
718e3744 4683}
6b0655a2 4684
28c6e247
IR
4685DEFUN (neighbor_local_as,
4686 neighbor_local_as_cmd,
4687 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4688 NEIGHBOR_STR
4689 NEIGHBOR_ADDR_STR2
4690 "Specify a local-as number\n"
4691 "AS number used as local AS\n")
718e3744 4692{
d62a17ae 4693 int idx_peer = 1;
4694 int idx_number = 3;
28c6e247
IR
4695 struct peer *peer;
4696 int ret;
4697 as_t as;
718e3744 4698
28c6e247
IR
4699 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4700 if (!peer)
d62a17ae 4701 return CMD_WARNING_CONFIG_FAILED;
718e3744 4702
28c6e247
IR
4703 as = strtoul(argv[idx_number]->arg, NULL, 10);
4704 ret = peer_local_as_set(peer, as, 0, 0);
4705 return bgp_vty_return(vty, ret);
718e3744 4706}
4707
28c6e247
IR
4708DEFUN (neighbor_local_as_no_prepend,
4709 neighbor_local_as_no_prepend_cmd,
4710 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4711 NEIGHBOR_STR
4712 NEIGHBOR_ADDR_STR2
4713 "Specify a local-as number\n"
4714 "AS number used as local AS\n"
4715 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4716{
d62a17ae 4717 int idx_peer = 1;
4718 int idx_number = 3;
28c6e247
IR
4719 struct peer *peer;
4720 int ret;
4721 as_t as;
718e3744 4722
28c6e247
IR
4723 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4724 if (!peer)
d62a17ae 4725 return CMD_WARNING_CONFIG_FAILED;
718e3744 4726
28c6e247
IR
4727 as = strtoul(argv[idx_number]->arg, NULL, 10);
4728 ret = peer_local_as_set(peer, as, 1, 0);
4729 return bgp_vty_return(vty, ret);
718e3744 4730}
4731
28c6e247
IR
4732DEFUN (neighbor_local_as_no_prepend_replace_as,
4733 neighbor_local_as_no_prepend_replace_as_cmd,
4734 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4735 NEIGHBOR_STR
4736 NEIGHBOR_ADDR_STR2
4737 "Specify a local-as number\n"
4738 "AS number used as local AS\n"
4739 "Do not prepend local-as to updates from ebgp peers\n"
4740 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4741{
d62a17ae 4742 int idx_peer = 1;
4743 int idx_number = 3;
28c6e247
IR
4744 struct peer *peer;
4745 int ret;
4746 as_t as;
9d3f9705 4747
28c6e247
IR
4748 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4749 if (!peer)
d62a17ae 4750 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4751
28c6e247
IR
4752 as = strtoul(argv[idx_number]->arg, NULL, 10);
4753 ret = peer_local_as_set(peer, as, 1, 1);
4754 return bgp_vty_return(vty, ret);
9d3f9705
AC
4755}
4756
28c6e247
IR
4757DEFUN (no_neighbor_local_as,
4758 no_neighbor_local_as_cmd,
4759 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4760 NO_STR
4761 NEIGHBOR_STR
4762 NEIGHBOR_ADDR_STR2
4763 "Specify a local-as number\n"
4764 "AS number used as local AS\n"
4765 "Do not prepend local-as to updates from ebgp peers\n"
4766 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4767{
d62a17ae 4768 int idx_peer = 2;
28c6e247
IR
4769 struct peer *peer;
4770 int ret;
718e3744 4771
28c6e247
IR
4772 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4773 if (!peer)
d62a17ae 4774 return CMD_WARNING_CONFIG_FAILED;
718e3744 4775
28c6e247
IR
4776 ret = peer_local_as_unset(peer);
4777 return bgp_vty_return(vty, ret);
718e3744 4778}
4779
718e3744 4780
3f9c7369
DS
4781DEFUN (neighbor_solo,
4782 neighbor_solo_cmd,
9ccf14f7 4783 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4784 NEIGHBOR_STR
4785 NEIGHBOR_ADDR_STR2
4786 "Solo peer - part of its own update group\n")
4787{
d62a17ae 4788 int idx_peer = 1;
4789 struct peer *peer;
4790 int ret;
3f9c7369 4791
d62a17ae 4792 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4793 if (!peer)
4794 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4795
d62a17ae 4796 ret = update_group_adjust_soloness(peer, 1);
4797 return bgp_vty_return(vty, ret);
3f9c7369
DS
4798}
4799
4800DEFUN (no_neighbor_solo,
4801 no_neighbor_solo_cmd,
9ccf14f7 4802 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4803 NO_STR
4804 NEIGHBOR_STR
4805 NEIGHBOR_ADDR_STR2
4806 "Solo peer - part of its own update group\n")
4807{
d62a17ae 4808 int idx_peer = 2;
4809 struct peer *peer;
4810 int ret;
3f9c7369 4811
d62a17ae 4812 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4813 if (!peer)
4814 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4815
d62a17ae 4816 ret = update_group_adjust_soloness(peer, 0);
4817 return bgp_vty_return(vty, ret);
3f9c7369
DS
4818}
4819
28c6e247
IR
4820DEFUN (neighbor_password,
4821 neighbor_password_cmd,
4822 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4823 NEIGHBOR_STR
4824 NEIGHBOR_ADDR_STR2
4825 "Set a password\n"
4826 "The password\n")
0df7c91f 4827{
d62a17ae 4828 int idx_peer = 1;
4829 int idx_line = 3;
28c6e247
IR
4830 struct peer *peer;
4831 int ret;
0df7c91f 4832
28c6e247
IR
4833 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4834 if (!peer)
d62a17ae 4835 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4836
28c6e247
IR
4837 ret = peer_password_set(peer, argv[idx_line]->arg);
4838 return bgp_vty_return(vty, ret);
0df7c91f
PJ
4839}
4840
28c6e247
IR
4841DEFUN (no_neighbor_password,
4842 no_neighbor_password_cmd,
4843 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4844 NO_STR
4845 NEIGHBOR_STR
4846 NEIGHBOR_ADDR_STR2
4847 "Set a password\n"
4848 "The password\n")
0df7c91f 4849{
d62a17ae 4850 int idx_peer = 2;
28c6e247
IR
4851 struct peer *peer;
4852 int ret;
0df7c91f 4853
28c6e247
IR
4854 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4855 if (!peer)
d62a17ae 4856 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4857
28c6e247
IR
4858 ret = peer_password_unset(peer);
4859 return bgp_vty_return(vty, ret);
0df7c91f 4860}
6b0655a2 4861
28c6e247
IR
4862DEFUN (neighbor_activate,
4863 neighbor_activate_cmd,
4864 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4865 NEIGHBOR_STR
4866 NEIGHBOR_ADDR_STR2
4867 "Enable the Address Family for this Neighbor\n")
718e3744 4868{
d62a17ae 4869 int idx_peer = 1;
28c6e247
IR
4870 int ret;
4871 struct peer *peer;
56ceae84 4872
28c6e247
IR
4873 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4874 if (!peer)
d62a17ae 4875 return CMD_WARNING_CONFIG_FAILED;
718e3744 4876
28c6e247
IR
4877 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4878 return bgp_vty_return(vty, ret);
718e3744 4879}
4880
d62a17ae 4881ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4882 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4883 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4884 "Enable the Address Family for this Neighbor\n")
596c17ba 4885
28c6e247
IR
4886DEFUN (no_neighbor_activate,
4887 no_neighbor_activate_cmd,
4888 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4889 NO_STR
4890 NEIGHBOR_STR
4891 NEIGHBOR_ADDR_STR2
4892 "Enable the Address Family for this Neighbor\n")
718e3744 4893{
d62a17ae 4894 int idx_peer = 2;
28c6e247
IR
4895 int ret;
4896 struct peer *peer;
f4b8ec07 4897
28c6e247
IR
4898 /* Lookup peer. */
4899 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4900 if (!peer)
d62a17ae 4901 return CMD_WARNING_CONFIG_FAILED;
718e3744 4902
28c6e247
IR
4903 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4904 return bgp_vty_return(vty, ret);
718e3744 4905}
6b0655a2 4906
d62a17ae 4907ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4908 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4909 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4910 "Enable the Address Family for this Neighbor\n")
596c17ba 4911
28c6e247
IR
4912DEFUN (neighbor_set_peer_group,
4913 neighbor_set_peer_group_cmd,
4914 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4915 NEIGHBOR_STR
4916 NEIGHBOR_ADDR_STR2
4917 "Member of the peer-group\n"
4918 "Peer-group name\n")
718e3744 4919{
28c6e247 4920 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4921 int idx_peer = 1;
4922 int idx_word = 3;
28c6e247
IR
4923 int ret;
4924 as_t as;
4925 union sockunion su;
4926 struct peer *peer;
4927 struct peer_group *group;
4928
4929 ret = str2sockunion(argv[idx_peer]->arg, &su);
4930 if (ret < 0) {
4931 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4932 if (!peer) {
4933 vty_out(vty, "%% Malformed address or name: %s\n",
4934 argv[idx_peer]->arg);
4935 return CMD_WARNING_CONFIG_FAILED;
4936 }
4937 } else {
4938 if (peer_address_self_check(bgp, &su)) {
4939 vty_out(vty,
4940 "%% Can not configure the local system as neighbor\n");
4941 return CMD_WARNING_CONFIG_FAILED;
4942 }
2a059a54 4943
28c6e247
IR
4944 /* Disallow for dynamic neighbor. */
4945 peer = peer_lookup(bgp, &su);
4946 if (peer && peer_dynamic_neighbor(peer)) {
4947 vty_out(vty,
4948 "%% Operation not allowed on a dynamic neighbor\n");
4949 return CMD_WARNING_CONFIG_FAILED;
4950 }
4951 }
4952
4953 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4954 if (!group) {
4955 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 4956 return CMD_WARNING_CONFIG_FAILED;
28c6e247 4957 }
d62a17ae 4958
28c6e247 4959 ret = peer_group_bind(bgp, &su, peer, group, &as);
2a059a54 4960
28c6e247
IR
4961 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4962 vty_out(vty,
4963 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4964 as);
4965 return CMD_WARNING_CONFIG_FAILED;
4966 }
4967
4968 return bgp_vty_return(vty, ret);
d62a17ae 4969}
4970
4971ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 4972 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4973 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4974 "Member of the peer-group\n"
4975 "Peer-group name\n")
596c17ba 4976
28c6e247
IR
4977DEFUN (no_neighbor_set_peer_group,
4978 no_neighbor_set_peer_group_cmd,
4979 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4980 NO_STR
4981 NEIGHBOR_STR
4982 NEIGHBOR_ADDR_STR2
4983 "Member of the peer-group\n"
4984 "Peer-group name\n")
718e3744 4985{
28c6e247 4986 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4987 int idx_peer = 2;
28c6e247
IR
4988 int idx_word = 4;
4989 int ret;
4990 struct peer *peer;
4991 struct peer_group *group;
d62a17ae 4992
28c6e247
IR
4993 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4994 if (!peer)
d62a17ae 4995 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 4996
28c6e247
IR
4997 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4998 if (!group) {
4999 vty_out(vty, "%% Configure the peer-group first\n");
5000 return CMD_WARNING_CONFIG_FAILED;
5001 }
718e3744 5002
28c6e247
IR
5003 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5004 bgp_zebra_terminate_radv(peer->bgp, peer);
5005
5006 peer_notify_unconfig(peer);
5007 ret = peer_delete(peer);
5008
5009 return bgp_vty_return(vty, ret);
718e3744 5010}
6b0655a2 5011
d62a17ae 5012ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
71cc0c88 5013 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5014 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5015 "Member of the peer-group\n"
5016 "Peer-group name\n")
596c17ba 5017
d62a17ae 5018static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 5019 uint32_t flag, int set)
718e3744 5020{
d62a17ae 5021 int ret;
5022 struct peer *peer;
718e3744 5023
d62a17ae 5024 peer = peer_and_group_lookup_vty(vty, ip_str);
5025 if (!peer)
5026 return CMD_WARNING_CONFIG_FAILED;
718e3744 5027
7ebe625c
QY
5028 /*
5029 * If 'neighbor <interface>', then this is for directly connected peers,
5030 * we should not accept disable-connected-check.
5031 */
5032 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5033 vty_out(vty,
3efd0893 5034 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
5035 ip_str);
5036 return CMD_WARNING_CONFIG_FAILED;
5037 }
5038
d62a17ae 5039 if (!set && flag == PEER_FLAG_SHUTDOWN)
5040 peer_tx_shutdown_message_unset(peer);
ae9b0e11 5041
d62a17ae 5042 if (set)
5043 ret = peer_flag_set(peer, flag);
5044 else
5045 ret = peer_flag_unset(peer, flag);
718e3744 5046
d62a17ae 5047 return bgp_vty_return(vty, ret);
718e3744 5048}
5049
47cbc09b 5050static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 5051{
d62a17ae 5052 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 5053}
5054
d62a17ae 5055static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 5056 uint32_t flag)
718e3744 5057{
d62a17ae 5058 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 5059}
5060
5061/* neighbor passive. */
28c6e247
IR
5062DEFUN (neighbor_passive,
5063 neighbor_passive_cmd,
5064 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5065 NEIGHBOR_STR
5066 NEIGHBOR_ADDR_STR2
5067 "Don't send open messages to this neighbor\n")
718e3744 5068{
d62a17ae 5069 int idx_peer = 1;
28c6e247 5070 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5071}
5072
28c6e247
IR
5073DEFUN (no_neighbor_passive,
5074 no_neighbor_passive_cmd,
5075 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5076 NO_STR
5077 NEIGHBOR_STR
5078 NEIGHBOR_ADDR_STR2
5079 "Don't send open messages to this neighbor\n")
718e3744 5080{
d62a17ae 5081 int idx_peer = 2;
28c6e247 5082 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5083}
6b0655a2 5084
718e3744 5085/* neighbor shutdown. */
28c6e247
IR
5086DEFUN (neighbor_shutdown_msg,
5087 neighbor_shutdown_msg_cmd,
5088 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5089 NEIGHBOR_STR
5090 NEIGHBOR_ADDR_STR2
5091 "Administratively shut down this neighbor\n"
5092 "Add a shutdown message (RFC 8203)\n"
5093 "Shutdown message\n")
718e3744 5094{
d62a17ae 5095 int idx_peer = 1;
73d70fa6 5096
d62a17ae 5097 if (argc >= 5) {
28c6e247
IR
5098 struct peer *peer =
5099 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
d62a17ae 5100 char *message;
73d70fa6 5101
28c6e247
IR
5102 if (!peer)
5103 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5104 message = argv_concat(argv, argc, 4);
28c6e247
IR
5105 peer_tx_shutdown_message_set(peer, message);
5106 XFREE(MTYPE_TMP, message);
d62a17ae 5107 }
73d70fa6 5108
28c6e247 5109 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 5110}
5111
1d80f243 5112ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5113 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5114 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5115 "Administratively shut down this neighbor\n")
73d70fa6 5116
28c6e247
IR
5117DEFUN (no_neighbor_shutdown_msg,
5118 no_neighbor_shutdown_msg_cmd,
5119 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5120 NO_STR
5121 NEIGHBOR_STR
5122 NEIGHBOR_ADDR_STR2
5123 "Administratively shut down this neighbor\n"
5124 "Remove a shutdown message (RFC 8203)\n"
5125 "Shutdown message\n")
718e3744 5126{
d62a17ae 5127 int idx_peer = 2;
73d70fa6 5128
28c6e247
IR
5129 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5130 PEER_FLAG_SHUTDOWN);
718e3744 5131}
6b0655a2 5132
1d80f243 5133ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5134 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5135 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5136 "Administratively shut down this neighbor\n")
73d70fa6 5137
8336c896
DA
5138DEFUN(neighbor_shutdown_rtt,
5139 neighbor_shutdown_rtt_cmd,
5140 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5141 NEIGHBOR_STR
5142 NEIGHBOR_ADDR_STR2
5143 "Administratively shut down this neighbor\n"
5144 "Shutdown if round-trip-time is higher than expected\n"
5145 "Round-trip-time in milliseconds\n"
5146 "Specify the number of keepalives before shutdown\n"
5147 "The number of keepalives with higher RTT to shutdown\n")
5148{
5149 int idx_peer = 1;
5150 int idx_rtt = 4;
5151 int idx_count = 0;
5152 struct peer *peer;
5153
5154 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5155
5156 if (!peer)
5157 return CMD_WARNING_CONFIG_FAILED;
5158
5159 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5160
5161 if (argv_find(argv, argc, "count", &idx_count))
5162 peer->rtt_keepalive_conf =
5163 strtol(argv[idx_count + 1]->arg, NULL, 10);
5164
5165 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5166 PEER_FLAG_RTT_SHUTDOWN);
5167}
5168
5169DEFUN(no_neighbor_shutdown_rtt,
5170 no_neighbor_shutdown_rtt_cmd,
5171 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5172 NO_STR
5173 NEIGHBOR_STR
5174 NEIGHBOR_ADDR_STR2
5175 "Administratively shut down this neighbor\n"
5176 "Shutdown if round-trip-time is higher than expected\n"
5177 "Round-trip-time in milliseconds\n"
5178 "Specify the number of keepalives before shutdown\n"
5179 "The number of keepalives with higher RTT to shutdown\n")
5180{
5181 int idx_peer = 2;
5182 struct peer *peer;
5183
5184 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5185
5186 if (!peer)
5187 return CMD_WARNING_CONFIG_FAILED;
5188
5189 peer->rtt_expected = 0;
5190 peer->rtt_keepalive_conf = 1;
5191
5192 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5193 PEER_FLAG_RTT_SHUTDOWN);
5194}
5195
718e3744 5196/* neighbor capability dynamic. */
28c6e247
IR
5197DEFUN (neighbor_capability_dynamic,
5198 neighbor_capability_dynamic_cmd,
5199 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5200 NEIGHBOR_STR
5201 NEIGHBOR_ADDR_STR2
5202 "Advertise capability to the peer\n"
5203 "Advertise dynamic capability to this neighbor\n")
718e3744 5204{
d62a17ae 5205 int idx_peer = 1;
28c6e247
IR
5206 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5207 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5208}
5209
28c6e247
IR
5210DEFUN (no_neighbor_capability_dynamic,
5211 no_neighbor_capability_dynamic_cmd,
5212 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5213 NO_STR
5214 NEIGHBOR_STR
5215 NEIGHBOR_ADDR_STR2
5216 "Advertise capability to the peer\n"
5217 "Advertise dynamic capability to this neighbor\n")
718e3744 5218{
d62a17ae 5219 int idx_peer = 2;
28c6e247
IR
5220 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5221 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5222}
6b0655a2 5223
718e3744 5224/* neighbor dont-capability-negotiate */
5225DEFUN (neighbor_dont_capability_negotiate,
5226 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5227 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5228 NEIGHBOR_STR
5229 NEIGHBOR_ADDR_STR2
5230 "Do not perform capability negotiation\n")
5231{
d62a17ae 5232 int idx_peer = 1;
5233 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5234 PEER_FLAG_DONT_CAPABILITY);
718e3744 5235}
5236
5237DEFUN (no_neighbor_dont_capability_negotiate,
5238 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5239 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5240 NO_STR
5241 NEIGHBOR_STR
5242 NEIGHBOR_ADDR_STR2
5243 "Do not perform capability negotiation\n")
5244{
28c6e247
IR
5245 int idx_peer = 2;
5246 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5247 PEER_FLAG_DONT_CAPABILITY);
f4b8ec07
CS
5248}
5249
28c6e247
IR
5250/* neighbor capability extended next hop encoding */
5251DEFUN (neighbor_capability_enhe,
5252 neighbor_capability_enhe_cmd,
5253 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5254 NEIGHBOR_STR
5255 NEIGHBOR_ADDR_STR2
5256 "Advertise capability to the peer\n"
5257 "Advertise extended next-hop capability to the peer\n")
f4b8ec07 5258{
28c6e247
IR
5259 int idx_peer = 1;
5260 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5261 PEER_FLAG_CAPABILITY_ENHE);
5262}
f4b8ec07 5263
28c6e247
IR
5264DEFUN (no_neighbor_capability_enhe,
5265 no_neighbor_capability_enhe_cmd,
5266 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5267 NO_STR
5268 NEIGHBOR_STR
5269 NEIGHBOR_ADDR_STR2
5270 "Advertise capability to the peer\n"
5271 "Advertise extended next-hop capability to the peer\n")
5272{
5273 int idx_peer = 2;
5274 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5275 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5276}
5277
d62a17ae 5278static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5279 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5280 int set)
718e3744 5281{
d62a17ae 5282 int ret;
5283 struct peer *peer;
718e3744 5284
d62a17ae 5285 peer = peer_and_group_lookup_vty(vty, peer_str);
5286 if (!peer)
5287 return CMD_WARNING_CONFIG_FAILED;
718e3744 5288
d62a17ae 5289 if (set)
5290 ret = peer_af_flag_set(peer, afi, safi, flag);
5291 else
5292 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5293
d62a17ae 5294 return bgp_vty_return(vty, ret);
718e3744 5295}
5296
d62a17ae 5297static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5298 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5299{
d62a17ae 5300 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5301}
5302
d62a17ae 5303static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5304 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5305{
d62a17ae 5306 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5307}
6b0655a2 5308
718e3744 5309/* neighbor capability orf prefix-list. */
5310DEFUN (neighbor_capability_orf_prefix,
5311 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5312 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5313 NEIGHBOR_STR
5314 NEIGHBOR_ADDR_STR2
5315 "Advertise capability to the peer\n"
5316 "Advertise ORF capability to the peer\n"
5317 "Advertise prefixlist ORF capability to this neighbor\n"
5318 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5319 "Capability to RECEIVE the ORF from this neighbor\n"
5320 "Capability to SEND the ORF to this neighbor\n")
5321{
d62a17ae 5322 int idx_send_recv = 5;
db45f64d
DS
5323 char *peer_str = argv[1]->arg;
5324 struct peer *peer;
5325 afi_t afi = bgp_node_afi(vty);
5326 safi_t safi = bgp_node_safi(vty);
d62a17ae 5327
db45f64d
DS
5328 peer = peer_and_group_lookup_vty(vty, peer_str);
5329 if (!peer)
d62a17ae 5330 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5331
db45f64d
DS
5332 if (strmatch(argv[idx_send_recv]->text, "send"))
5333 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5334 PEER_FLAG_ORF_PREFIX_SM);
5335
5336 if (strmatch(argv[idx_send_recv]->text, "receive"))
5337 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5338 PEER_FLAG_ORF_PREFIX_RM);
5339
5340 if (strmatch(argv[idx_send_recv]->text, "both"))
5341 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5342 PEER_FLAG_ORF_PREFIX_SM)
5343 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5344 PEER_FLAG_ORF_PREFIX_RM);
5345
5346 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5347}
5348
5349ALIAS_HIDDEN(
5350 neighbor_capability_orf_prefix,
5351 neighbor_capability_orf_prefix_hidden_cmd,
5352 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5353 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5354 "Advertise capability to the peer\n"
5355 "Advertise ORF capability to the peer\n"
5356 "Advertise prefixlist ORF capability to this neighbor\n"
5357 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5358 "Capability to RECEIVE the ORF from this neighbor\n"
5359 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5360
718e3744 5361DEFUN (no_neighbor_capability_orf_prefix,
5362 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5363 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5364 NO_STR
5365 NEIGHBOR_STR
5366 NEIGHBOR_ADDR_STR2
5367 "Advertise capability to the peer\n"
5368 "Advertise ORF capability to the peer\n"
5369 "Advertise prefixlist ORF capability to this neighbor\n"
5370 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5371 "Capability to RECEIVE the ORF from this neighbor\n"
5372 "Capability to SEND the ORF to this neighbor\n")
5373{
d62a17ae 5374 int idx_send_recv = 6;
db45f64d
DS
5375 char *peer_str = argv[2]->arg;
5376 struct peer *peer;
5377 afi_t afi = bgp_node_afi(vty);
5378 safi_t safi = bgp_node_safi(vty);
d62a17ae 5379
db45f64d
DS
5380 peer = peer_and_group_lookup_vty(vty, peer_str);
5381 if (!peer)
d62a17ae 5382 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5383
db45f64d
DS
5384 if (strmatch(argv[idx_send_recv]->text, "send"))
5385 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5386 PEER_FLAG_ORF_PREFIX_SM);
5387
5388 if (strmatch(argv[idx_send_recv]->text, "receive"))
5389 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5390 PEER_FLAG_ORF_PREFIX_RM);
5391
5392 if (strmatch(argv[idx_send_recv]->text, "both"))
5393 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5394 PEER_FLAG_ORF_PREFIX_SM)
5395 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5396 PEER_FLAG_ORF_PREFIX_RM);
5397
5398 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5399}
5400
5401ALIAS_HIDDEN(
5402 no_neighbor_capability_orf_prefix,
5403 no_neighbor_capability_orf_prefix_hidden_cmd,
5404 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5405 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5406 "Advertise capability to the peer\n"
5407 "Advertise ORF capability to the peer\n"
5408 "Advertise prefixlist ORF capability to this neighbor\n"
5409 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5410 "Capability to RECEIVE the ORF from this neighbor\n"
5411 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5412
718e3744 5413/* neighbor next-hop-self. */
28c6e247
IR
5414DEFUN (neighbor_nexthop_self,
5415 neighbor_nexthop_self_cmd,
5416 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5417 NEIGHBOR_STR
5418 NEIGHBOR_ADDR_STR2
5419 "Disable the next hop calculation for this neighbor\n")
718e3744 5420{
d62a17ae 5421 int idx_peer = 1;
28c6e247
IR
5422 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5423 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 5424}
9e7a53c1 5425
d62a17ae 5426ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5427 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5428 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5429 "Disable the next hop calculation for this neighbor\n")
596c17ba 5430
f4b8ec07 5431/* neighbor next-hop-self. */
28c6e247
IR
5432DEFUN (neighbor_nexthop_self_force,
5433 neighbor_nexthop_self_force_cmd,
5434 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5435 NEIGHBOR_STR
5436 NEIGHBOR_ADDR_STR2
5437 "Disable the next hop calculation for this neighbor\n"
5438 "Set the next hop to self for reflected routes\n")
f4b8ec07
CS
5439{
5440 int idx_peer = 1;
28c6e247
IR
5441 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5442 bgp_node_safi(vty),
5443 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 5444}
5445
d62a17ae 5446ALIAS_HIDDEN(neighbor_nexthop_self_force,
5447 neighbor_nexthop_self_force_hidden_cmd,
5448 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5449 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5450 "Disable the next hop calculation for this neighbor\n"
5451 "Set the next hop to self for reflected routes\n")
596c17ba 5452
1bc4e531
DA
5453ALIAS_HIDDEN(neighbor_nexthop_self_force,
5454 neighbor_nexthop_self_all_hidden_cmd,
5455 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5456 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5457 "Disable the next hop calculation for this neighbor\n"
5458 "Set the next hop to self for reflected routes\n")
5459
28c6e247
IR
5460DEFUN (no_neighbor_nexthop_self,
5461 no_neighbor_nexthop_self_cmd,
5462 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5463 NO_STR
5464 NEIGHBOR_STR
5465 NEIGHBOR_ADDR_STR2
5466 "Disable the next hop calculation for this neighbor\n")
718e3744 5467{
d62a17ae 5468 int idx_peer = 2;
28c6e247
IR
5469 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5470 bgp_node_afi(vty), bgp_node_safi(vty),
5471 PEER_FLAG_NEXTHOP_SELF);
718e3744 5472}
6b0655a2 5473
d62a17ae 5474ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5475 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5476 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5477 "Disable the next hop calculation for this neighbor\n")
596c17ba 5478
28c6e247
IR
5479DEFUN (no_neighbor_nexthop_self_force,
5480 no_neighbor_nexthop_self_force_cmd,
5481 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5482 NO_STR
5483 NEIGHBOR_STR
5484 NEIGHBOR_ADDR_STR2
5485 "Disable the next hop calculation for this neighbor\n"
5486 "Set the next hop to self for reflected routes\n")
88b8ed8d 5487{
d62a17ae 5488 int idx_peer = 2;
28c6e247
IR
5489 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5490 bgp_node_afi(vty), bgp_node_safi(vty),
5491 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5492}
a538debe 5493
d62a17ae 5494ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5495 no_neighbor_nexthop_self_force_hidden_cmd,
5496 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5497 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5498 "Disable the next hop calculation for this neighbor\n"
5499 "Set the next hop to self for reflected routes\n")
596c17ba 5500
1bc4e531
DA
5501ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5502 no_neighbor_nexthop_self_all_hidden_cmd,
5503 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5504 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5505 "Disable the next hop calculation for this neighbor\n"
5506 "Set the next hop to self for reflected routes\n")
5507
c7122e14 5508/* neighbor as-override */
28c6e247
IR
5509DEFUN (neighbor_as_override,
5510 neighbor_as_override_cmd,
5511 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5512 NEIGHBOR_STR
5513 NEIGHBOR_ADDR_STR2
5514 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5515{
d62a17ae 5516 int idx_peer = 1;
28c6e247
IR
5517 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5518 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5519}
5520
d62a17ae 5521ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5522 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5523 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5524 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5525
28c6e247
IR
5526DEFUN (no_neighbor_as_override,
5527 no_neighbor_as_override_cmd,
5528 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5529 NO_STR
5530 NEIGHBOR_STR
5531 NEIGHBOR_ADDR_STR2
5532 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5533{
d62a17ae 5534 int idx_peer = 2;
28c6e247
IR
5535 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5536 bgp_node_afi(vty), bgp_node_safi(vty),
5537 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5538}
5539
d62a17ae 5540ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5541 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5542 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5543 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5544
718e3744 5545/* neighbor remove-private-AS. */
28c6e247
IR
5546DEFUN (neighbor_remove_private_as,
5547 neighbor_remove_private_as_cmd,
5548 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5549 NEIGHBOR_STR
5550 NEIGHBOR_ADDR_STR2
5551 "Remove private ASNs in outbound updates\n")
718e3744 5552{
d62a17ae 5553 int idx_peer = 1;
28c6e247
IR
5554 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5555 bgp_node_safi(vty),
5556 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5557}
5558
d62a17ae 5559ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5560 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5561 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5562 "Remove private ASNs in outbound updates\n")
596c17ba 5563
28c6e247
IR
5564DEFUN (neighbor_remove_private_as_all,
5565 neighbor_remove_private_as_all_cmd,
5566 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5567 NEIGHBOR_STR
5568 NEIGHBOR_ADDR_STR2
5569 "Remove private ASNs in outbound updates\n"
5570 "Apply to all AS numbers\n")
5000f21c 5571{
d62a17ae 5572 int idx_peer = 1;
28c6e247
IR
5573 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5574 bgp_node_safi(vty),
5575 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
5576}
5577
d62a17ae 5578ALIAS_HIDDEN(neighbor_remove_private_as_all,
5579 neighbor_remove_private_as_all_hidden_cmd,
5580 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5581 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5582 "Remove private ASNs in outbound updates\n"
5583 "Apply to all AS numbers")
596c17ba 5584
28c6e247
IR
5585DEFUN (neighbor_remove_private_as_replace_as,
5586 neighbor_remove_private_as_replace_as_cmd,
5587 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5588 NEIGHBOR_STR
5589 NEIGHBOR_ADDR_STR2
5590 "Remove private ASNs in outbound updates\n"
5591 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5592{
d62a17ae 5593 int idx_peer = 1;
28c6e247
IR
5594 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5595 bgp_node_safi(vty),
5596 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
5597}
5598
d62a17ae 5599ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5600 neighbor_remove_private_as_replace_as_hidden_cmd,
5601 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5602 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5603 "Remove private ASNs in outbound updates\n"
5604 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5605
28c6e247
IR
5606DEFUN (neighbor_remove_private_as_all_replace_as,
5607 neighbor_remove_private_as_all_replace_as_cmd,
5608 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5609 NEIGHBOR_STR
5610 NEIGHBOR_ADDR_STR2
5611 "Remove private ASNs in outbound updates\n"
5612 "Apply to all AS numbers\n"
5613 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5614{
d62a17ae 5615 int idx_peer = 1;
28c6e247
IR
5616 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5617 bgp_node_safi(vty),
5618 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
5619}
5620
d62a17ae 5621ALIAS_HIDDEN(
5622 neighbor_remove_private_as_all_replace_as,
5623 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5624 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5625 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5626 "Remove private ASNs in outbound updates\n"
5627 "Apply to all AS numbers\n"
5628 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5629
28c6e247
IR
5630DEFUN (no_neighbor_remove_private_as,
5631 no_neighbor_remove_private_as_cmd,
5632 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5633 NO_STR
5634 NEIGHBOR_STR
5635 NEIGHBOR_ADDR_STR2
5636 "Remove private ASNs in outbound updates\n")
718e3744 5637{
d62a17ae 5638 int idx_peer = 2;
28c6e247
IR
5639 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5640 bgp_node_afi(vty), bgp_node_safi(vty),
5641 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5642}
6b0655a2 5643
d62a17ae 5644ALIAS_HIDDEN(no_neighbor_remove_private_as,
5645 no_neighbor_remove_private_as_hidden_cmd,
5646 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5647 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5648 "Remove private ASNs in outbound updates\n")
596c17ba 5649
28c6e247
IR
5650DEFUN (no_neighbor_remove_private_as_all,
5651 no_neighbor_remove_private_as_all_cmd,
5652 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5653 NO_STR
5654 NEIGHBOR_STR
5655 NEIGHBOR_ADDR_STR2
5656 "Remove private ASNs in outbound updates\n"
5657 "Apply to all AS numbers\n")
88b8ed8d 5658{
d62a17ae 5659 int idx_peer = 2;
28c6e247
IR
5660 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5661 bgp_node_afi(vty), bgp_node_safi(vty),
5662 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 5663}
5000f21c 5664
d62a17ae 5665ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5666 no_neighbor_remove_private_as_all_hidden_cmd,
5667 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5668 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5669 "Remove private ASNs in outbound updates\n"
5670 "Apply to all AS numbers\n")
596c17ba 5671
28c6e247
IR
5672DEFUN (no_neighbor_remove_private_as_replace_as,
5673 no_neighbor_remove_private_as_replace_as_cmd,
5674 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5675 NO_STR
5676 NEIGHBOR_STR
5677 NEIGHBOR_ADDR_STR2
5678 "Remove private ASNs in outbound updates\n"
5679 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5680{
d62a17ae 5681 int idx_peer = 2;
28c6e247
IR
5682 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5683 bgp_node_afi(vty), bgp_node_safi(vty),
5684 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 5685}
5000f21c 5686
d62a17ae 5687ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5688 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5689 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5690 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5691 "Remove private ASNs in outbound updates\n"
5692 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5693
28c6e247
IR
5694DEFUN (no_neighbor_remove_private_as_all_replace_as,
5695 no_neighbor_remove_private_as_all_replace_as_cmd,
5696 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5697 NO_STR
5698 NEIGHBOR_STR
5699 NEIGHBOR_ADDR_STR2
5700 "Remove private ASNs in outbound updates\n"
5701 "Apply to all AS numbers\n"
5702 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5703{
d62a17ae 5704 int idx_peer = 2;
28c6e247
IR
5705 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5706 bgp_node_afi(vty), bgp_node_safi(vty),
5707 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 5708}
5000f21c 5709
d62a17ae 5710ALIAS_HIDDEN(
5711 no_neighbor_remove_private_as_all_replace_as,
5712 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5713 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5714 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5715 "Remove private ASNs in outbound updates\n"
5716 "Apply to all AS numbers\n"
5717 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5718
5000f21c 5719
718e3744 5720/* neighbor send-community. */
28c6e247
IR
5721DEFUN (neighbor_send_community,
5722 neighbor_send_community_cmd,
5723 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5724 NEIGHBOR_STR
5725 NEIGHBOR_ADDR_STR2
5726 "Send Community attribute to this neighbor\n")
718e3744 5727{
d62a17ae 5728 int idx_peer = 1;
27c05d4d 5729
f63d4054
IR
5730 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5731 bgp_node_safi(vty),
5732 PEER_FLAG_SEND_COMMUNITY);
718e3744 5733}
5734
d62a17ae 5735ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5736 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5737 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5738 "Send Community attribute to this neighbor\n")
596c17ba 5739
28c6e247
IR
5740DEFUN (no_neighbor_send_community,
5741 no_neighbor_send_community_cmd,
5742 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5743 NO_STR
5744 NEIGHBOR_STR
5745 NEIGHBOR_ADDR_STR2
5746 "Send Community attribute to this neighbor\n")
718e3744 5747{
d62a17ae 5748 int idx_peer = 2;
27c05d4d 5749
f63d4054
IR
5750 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5751 bgp_node_afi(vty), bgp_node_safi(vty),
5752 PEER_FLAG_SEND_COMMUNITY);
718e3744 5753}
6b0655a2 5754
d62a17ae 5755ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5756 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5757 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5758 "Send Community attribute to this neighbor\n")
596c17ba 5759
718e3744 5760/* neighbor send-community extended. */
28c6e247
IR
5761DEFUN (neighbor_send_community_type,
5762 neighbor_send_community_type_cmd,
5763 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5764 NEIGHBOR_STR
5765 NEIGHBOR_ADDR_STR2
5766 "Send Community attribute to this neighbor\n"
5767 "Send Standard and Extended Community attributes\n"
5768 "Send Standard, Large and Extended Community attributes\n"
5769 "Send Extended Community attributes\n"
5770 "Send Standard Community attributes\n"
5771 "Send Large Community attributes\n")
718e3744 5772{
27c05d4d 5773 const char *type = argv[argc - 1]->text;
db45f64d 5774 char *peer_str = argv[1]->arg;
28c6e247 5775 struct peer *peer;
db45f64d 5776 afi_t afi = bgp_node_afi(vty);
28c6e247 5777 safi_t safi = bgp_node_safi(vty);
f4b8ec07 5778
28c6e247
IR
5779 peer = peer_and_group_lookup_vty(vty, peer_str);
5780 if (!peer)
5781 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07 5782
28c6e247
IR
5783 if (strmatch(type, "standard"))
5784 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5785 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 5786
28c6e247
IR
5787 if (strmatch(type, "extended"))
5788 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5789 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5790
28c6e247
IR
5791 if (strmatch(type, "large"))
5792 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5793 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07 5794
28c6e247
IR
5795 if (strmatch(type, "both")) {
5796 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5797 PEER_FLAG_SEND_COMMUNITY)
5798 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5799 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5800 }
28c6e247
IR
5801 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5802 PEER_FLAG_SEND_COMMUNITY)
5803 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5804 PEER_FLAG_SEND_EXT_COMMUNITY)
5805 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5806 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5807}
5808
5809ALIAS_HIDDEN(
5810 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5811 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5812 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5813 "Send Community attribute to this neighbor\n"
5814 "Send Standard and Extended Community attributes\n"
5815 "Send Standard, Large and Extended Community attributes\n"
5816 "Send Extended Community attributes\n"
5817 "Send Standard Community attributes\n"
5818 "Send Large Community attributes\n")
596c17ba 5819
28c6e247
IR
5820DEFUN (no_neighbor_send_community_type,
5821 no_neighbor_send_community_type_cmd,
5822 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5823 NO_STR
5824 NEIGHBOR_STR
5825 NEIGHBOR_ADDR_STR2
5826 "Send Community attribute to this neighbor\n"
5827 "Send Standard and Extended Community attributes\n"
5828 "Send Standard, Large and Extended Community attributes\n"
5829 "Send Extended Community attributes\n"
5830 "Send Standard Community attributes\n"
5831 "Send Large Community attributes\n")
718e3744 5832{
d62a17ae 5833 const char *type = argv[argc - 1]->text;
db45f64d 5834 char *peer_str = argv[2]->arg;
28c6e247 5835 struct peer *peer;
db45f64d
DS
5836 afi_t afi = bgp_node_afi(vty);
5837 safi_t safi = bgp_node_safi(vty);
5838
28c6e247
IR
5839 peer = peer_and_group_lookup_vty(vty, peer_str);
5840 if (!peer)
f4b8ec07
CS
5841 return CMD_WARNING_CONFIG_FAILED;
5842
28c6e247
IR
5843 if (strmatch(type, "standard"))
5844 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5845 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 5846
28c6e247
IR
5847 if (strmatch(type, "extended"))
5848 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5849 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5850
28c6e247
IR
5851 if (strmatch(type, "large"))
5852 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5853 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07
CS
5854
5855 if (strmatch(type, "both")) {
db45f64d 5856
28c6e247
IR
5857 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5858 PEER_FLAG_SEND_COMMUNITY)
5859 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5860 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
5861 }
5862
28c6e247
IR
5863 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5864 PEER_FLAG_SEND_COMMUNITY)
5865 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5866 PEER_FLAG_SEND_EXT_COMMUNITY)
5867 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5868 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5869}
5870
5871ALIAS_HIDDEN(
5872 no_neighbor_send_community_type,
5873 no_neighbor_send_community_type_hidden_cmd,
5874 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5875 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5876 "Send Community attribute to this neighbor\n"
5877 "Send Standard and Extended Community attributes\n"
5878 "Send Standard, Large and Extended Community attributes\n"
5879 "Send Extended Community attributes\n"
5880 "Send Standard Community attributes\n"
5881 "Send Large Community attributes\n")
596c17ba 5882
718e3744 5883/* neighbor soft-reconfig. */
28c6e247
IR
5884DEFUN (neighbor_soft_reconfiguration,
5885 neighbor_soft_reconfiguration_cmd,
5886 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5887 NEIGHBOR_STR
5888 NEIGHBOR_ADDR_STR2
5889 "Per neighbor soft reconfiguration\n"
5890 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 5891{
d62a17ae 5892 int idx_peer = 1;
28c6e247
IR
5893 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5894 bgp_node_safi(vty),
5895 PEER_FLAG_SOFT_RECONFIG);
718e3744 5896}
5897
d62a17ae 5898ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5899 neighbor_soft_reconfiguration_hidden_cmd,
5900 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5901 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5902 "Per neighbor soft reconfiguration\n"
5903 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5904
28c6e247
IR
5905DEFUN (no_neighbor_soft_reconfiguration,
5906 no_neighbor_soft_reconfiguration_cmd,
5907 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5908 NO_STR
5909 NEIGHBOR_STR
5910 NEIGHBOR_ADDR_STR2
5911 "Per neighbor soft reconfiguration\n"
5912 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 5913{
d62a17ae 5914 int idx_peer = 2;
28c6e247
IR
5915 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5916 bgp_node_afi(vty), bgp_node_safi(vty),
5917 PEER_FLAG_SOFT_RECONFIG);
718e3744 5918}
6b0655a2 5919
d62a17ae 5920ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5921 no_neighbor_soft_reconfiguration_hidden_cmd,
5922 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5923 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5924 "Per neighbor soft reconfiguration\n"
5925 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5926
28c6e247
IR
5927DEFUN (neighbor_route_reflector_client,
5928 neighbor_route_reflector_client_cmd,
5929 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5930 NEIGHBOR_STR
5931 NEIGHBOR_ADDR_STR2
5932 "Configure a neighbor as Route Reflector client\n")
718e3744 5933{
d62a17ae 5934 int idx_peer = 1;
28c6e247 5935 struct peer *peer;
718e3744 5936
5937
28c6e247
IR
5938 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5939 if (!peer)
d62a17ae 5940 return CMD_WARNING_CONFIG_FAILED;
718e3744 5941
28c6e247
IR
5942 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5943 bgp_node_safi(vty),
5944 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5945}
5946
d62a17ae 5947ALIAS_HIDDEN(neighbor_route_reflector_client,
5948 neighbor_route_reflector_client_hidden_cmd,
5949 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5950 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5951 "Configure a neighbor as Route Reflector client\n")
596c17ba 5952
28c6e247
IR
5953DEFUN (no_neighbor_route_reflector_client,
5954 no_neighbor_route_reflector_client_cmd,
5955 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5956 NO_STR
5957 NEIGHBOR_STR
5958 NEIGHBOR_ADDR_STR2
5959 "Configure a neighbor as Route Reflector client\n")
718e3744 5960{
d62a17ae 5961 int idx_peer = 2;
28c6e247
IR
5962 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5963 bgp_node_afi(vty), bgp_node_safi(vty),
5964 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5965}
6b0655a2 5966
d62a17ae 5967ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5968 no_neighbor_route_reflector_client_hidden_cmd,
5969 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5970 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5971 "Configure a neighbor as Route Reflector client\n")
596c17ba 5972
718e3744 5973/* neighbor route-server-client. */
28c6e247
IR
5974DEFUN (neighbor_route_server_client,
5975 neighbor_route_server_client_cmd,
5976 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5977 NEIGHBOR_STR
5978 NEIGHBOR_ADDR_STR2
5979 "Configure a neighbor as Route Server client\n")
718e3744 5980{
d62a17ae 5981 int idx_peer = 1;
28c6e247 5982 struct peer *peer;
f4b8ec07 5983
28c6e247
IR
5984 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5985 if (!peer)
d62a17ae 5986 return CMD_WARNING_CONFIG_FAILED;
28c6e247
IR
5987 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5988 bgp_node_safi(vty),
5989 PEER_FLAG_RSERVER_CLIENT);
718e3744 5990}
5991
d62a17ae 5992ALIAS_HIDDEN(neighbor_route_server_client,
5993 neighbor_route_server_client_hidden_cmd,
5994 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5995 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5996 "Configure a neighbor as Route Server client\n")
596c17ba 5997
28c6e247
IR
5998DEFUN (no_neighbor_route_server_client,
5999 no_neighbor_route_server_client_cmd,
6000 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6001 NO_STR
6002 NEIGHBOR_STR
6003 NEIGHBOR_ADDR_STR2
6004 "Configure a neighbor as Route Server client\n")
fee0f4c6 6005{
d62a17ae 6006 int idx_peer = 2;
28c6e247
IR
6007 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6008 bgp_node_afi(vty), bgp_node_safi(vty),
6009 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 6010}
6b0655a2 6011
d62a17ae 6012ALIAS_HIDDEN(no_neighbor_route_server_client,
6013 no_neighbor_route_server_client_hidden_cmd,
6014 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6015 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6016 "Configure a neighbor as Route Server client\n")
596c17ba 6017
fee0f4c6 6018DEFUN (neighbor_nexthop_local_unchanged,
6019 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6020 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6021 NEIGHBOR_STR
6022 NEIGHBOR_ADDR_STR2
6023 "Configure treatment of outgoing link-local nexthop attribute\n"
6024 "Leave link-local nexthop unchanged for this peer\n")
6025{
d62a17ae 6026 int idx_peer = 1;
6027 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6028 bgp_node_safi(vty),
6029 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6030}
6b0655a2 6031
fee0f4c6 6032DEFUN (no_neighbor_nexthop_local_unchanged,
6033 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6034 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6035 NO_STR
6036 NEIGHBOR_STR
6037 NEIGHBOR_ADDR_STR2
6038 "Configure treatment of outgoing link-local-nexthop attribute\n"
6039 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6040{
d62a17ae 6041 int idx_peer = 2;
6042 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6043 bgp_node_afi(vty), bgp_node_safi(vty),
6044 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6045}
6b0655a2 6046
28c6e247
IR
6047DEFUN (neighbor_attr_unchanged,
6048 neighbor_attr_unchanged_cmd,
6049 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6050 NEIGHBOR_STR
6051 NEIGHBOR_ADDR_STR2
6052 "BGP attribute is propagated unchanged to this neighbor\n"
6053 "As-path attribute\n"
6054 "Nexthop attribute\n"
6055 "Med attribute\n")
718e3744 6056{
d62a17ae 6057 int idx = 0;
8eeb0335 6058 char *peer_str = argv[1]->arg;
28c6e247 6059 struct peer *peer;
db45f64d
DS
6060 bool aspath = false;
6061 bool nexthop = false;
6062 bool med = false;
8eeb0335
DW
6063 afi_t afi = bgp_node_afi(vty);
6064 safi_t safi = bgp_node_safi(vty);
28c6e247 6065 int ret = 0;
f4b8ec07 6066
28c6e247
IR
6067 peer = peer_and_group_lookup_vty(vty, peer_str);
6068 if (!peer)
8eeb0335 6069 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6070
6071 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6072 aspath = true;
6073
d62a17ae 6074 idx = 0;
6075 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6076 nexthop = true;
6077
d62a17ae 6078 idx = 0;
6079 if (argv_find(argv, argc, "med", &idx))
db45f64d 6080 med = true;
d62a17ae 6081
8eeb0335 6082 /* no flags means all of them! */
db45f64d 6083 if (!aspath && !nexthop && !med) {
28c6e247
IR
6084 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6085 PEER_FLAG_AS_PATH_UNCHANGED);
6086 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6087 PEER_FLAG_NEXTHOP_UNCHANGED);
6088 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6089 PEER_FLAG_MED_UNCHANGED);
8eeb0335 6090 } else {
28c6e247
IR
6091 if (!aspath) {
6092 if (peer_af_flag_check(peer, afi, safi,
6093 PEER_FLAG_AS_PATH_UNCHANGED)) {
6094 ret |= peer_af_flag_unset_vty(
6095 vty, peer_str, afi, safi,
6096 PEER_FLAG_AS_PATH_UNCHANGED);
6097 }
6098 } else
6099 ret |= peer_af_flag_set_vty(
6100 vty, peer_str, afi, safi,
6101 PEER_FLAG_AS_PATH_UNCHANGED);
6102
6103 if (!nexthop) {
6104 if (peer_af_flag_check(peer, afi, safi,
6105 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6106 ret |= peer_af_flag_unset_vty(
6107 vty, peer_str, afi, safi,
6108 PEER_FLAG_NEXTHOP_UNCHANGED);
6109 }
6110 } else
6111 ret |= peer_af_flag_set_vty(
6112 vty, peer_str, afi, safi,
6113 PEER_FLAG_NEXTHOP_UNCHANGED);
6114
6115 if (!med) {
6116 if (peer_af_flag_check(peer, afi, safi,
6117 PEER_FLAG_MED_UNCHANGED)) {
6118 ret |= peer_af_flag_unset_vty(
6119 vty, peer_str, afi, safi,
6120 PEER_FLAG_MED_UNCHANGED);
6121 }
6122 } else
6123 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6124 PEER_FLAG_MED_UNCHANGED);
d62a17ae 6125 }
6126
28c6e247 6127 return ret;
d62a17ae 6128}
6129
6130ALIAS_HIDDEN(
6131 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6132 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6133 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6134 "BGP attribute is propagated unchanged to this neighbor\n"
6135 "As-path attribute\n"
6136 "Nexthop attribute\n"
6137 "Med attribute\n")
596c17ba 6138
28c6e247
IR
6139DEFUN (no_neighbor_attr_unchanged,
6140 no_neighbor_attr_unchanged_cmd,
6141 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6142 NO_STR
6143 NEIGHBOR_STR
6144 NEIGHBOR_ADDR_STR2
6145 "BGP attribute is propagated unchanged to this neighbor\n"
6146 "As-path attribute\n"
6147 "Nexthop attribute\n"
6148 "Med attribute\n")
718e3744 6149{
d62a17ae 6150 int idx = 0;
db45f64d 6151 char *peer_str = argv[2]->arg;
28c6e247 6152 struct peer *peer;
db45f64d
DS
6153 bool aspath = false;
6154 bool nexthop = false;
6155 bool med = false;
6156 afi_t afi = bgp_node_afi(vty);
6157 safi_t safi = bgp_node_safi(vty);
28c6e247 6158 int ret = 0;
f4b8ec07 6159
28c6e247
IR
6160 peer = peer_and_group_lookup_vty(vty, peer_str);
6161 if (!peer)
db45f64d 6162 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6163
6164 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6165 aspath = true;
6166
d62a17ae 6167 idx = 0;
6168 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6169 nexthop = true;
6170
d62a17ae 6171 idx = 0;
6172 if (argv_find(argv, argc, "med", &idx))
db45f64d 6173 med = true;
d62a17ae 6174
28c6e247
IR
6175 if (!aspath && !nexthop && !med) // no flags means all of them!
6176 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6177 PEER_FLAG_AS_PATH_UNCHANGED)
6178 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6179 PEER_FLAG_NEXTHOP_UNCHANGED)
6180 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6181 PEER_FLAG_MED_UNCHANGED);
db45f64d
DS
6182
6183 if (aspath)
28c6e247
IR
6184 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6185 PEER_FLAG_AS_PATH_UNCHANGED);
db45f64d
DS
6186
6187 if (nexthop)
28c6e247
IR
6188 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6189 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 6190
db45f64d 6191 if (med)
28c6e247
IR
6192 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6193 PEER_FLAG_MED_UNCHANGED);
db45f64d 6194
28c6e247 6195 return ret;
d62a17ae 6196}
6197
6198ALIAS_HIDDEN(
6199 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6200 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6201 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6202 "BGP attribute is propagated unchanged to this neighbor\n"
6203 "As-path attribute\n"
6204 "Nexthop attribute\n"
6205 "Med attribute\n")
718e3744 6206
28c6e247
IR
6207/* EBGP multihop configuration. */
6208static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6209 const char *ttl_str)
718e3744 6210{
28c6e247
IR
6211 struct peer *peer;
6212 unsigned int ttl;
718e3744 6213
28c6e247
IR
6214 peer = peer_and_group_lookup_vty(vty, ip_str);
6215 if (!peer)
d62a17ae 6216 return CMD_WARNING_CONFIG_FAILED;
718e3744 6217
28c6e247
IR
6218 if (peer->conf_if)
6219 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6220
6221 if (!ttl_str)
6222 ttl = MAXTTL;
6223 else
6224 ttl = strtoul(ttl_str, NULL, 10);
718e3744 6225
28c6e247 6226 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 6227}
6228
28c6e247 6229static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6230{
28c6e247 6231 struct peer *peer;
718e3744 6232
28c6e247
IR
6233 peer = peer_and_group_lookup_vty(vty, ip_str);
6234 if (!peer)
d62a17ae 6235 return CMD_WARNING_CONFIG_FAILED;
718e3744 6236
28c6e247 6237 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 6238}
6239
28c6e247
IR
6240/* neighbor ebgp-multihop. */
6241DEFUN (neighbor_ebgp_multihop,
6242 neighbor_ebgp_multihop_cmd,
6243 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6244 NEIGHBOR_STR
6245 NEIGHBOR_ADDR_STR2
6246 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6247{
28c6e247
IR
6248 int idx_peer = 1;
6249 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6250}
f4b8ec07 6251
28c6e247
IR
6252DEFUN (neighbor_ebgp_multihop_ttl,
6253 neighbor_ebgp_multihop_ttl_cmd,
6254 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6255 NEIGHBOR_STR
6256 NEIGHBOR_ADDR_STR2
6257 "Allow EBGP neighbors not on directly connected networks\n"
6258 "maximum hop count\n")
6259{
6260 int idx_peer = 1;
6261 int idx_number = 3;
6262 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6263 argv[idx_number]->arg);
6264}
f4b8ec07 6265
28c6e247
IR
6266DEFUN (no_neighbor_ebgp_multihop,
6267 no_neighbor_ebgp_multihop_cmd,
6268 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6269 NO_STR
6270 NEIGHBOR_STR
6271 NEIGHBOR_ADDR_STR2
6272 "Allow EBGP neighbors not on directly connected networks\n"
6273 "maximum hop count\n")
6274{
6275 int idx_peer = 2;
6276 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6277}
6278
6b0655a2 6279
6ffd2079 6280/* disable-connected-check */
28c6e247
IR
6281DEFUN (neighbor_disable_connected_check,
6282 neighbor_disable_connected_check_cmd,
6283 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6284 NEIGHBOR_STR
6285 NEIGHBOR_ADDR_STR2
6286 "one-hop away EBGP peer using loopback address\n"
6287 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6288{
d62a17ae 6289 int idx_peer = 1;
28c6e247
IR
6290 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6291 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6292}
6293
28c6e247
IR
6294DEFUN (no_neighbor_disable_connected_check,
6295 no_neighbor_disable_connected_check_cmd,
6296 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6297 NO_STR
6298 NEIGHBOR_STR
6299 NEIGHBOR_ADDR_STR2
6300 "one-hop away EBGP peer using loopback address\n"
6301 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6302{
d62a17ae 6303 int idx_peer = 2;
28c6e247
IR
6304 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6305 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6306}
6307
7ab294ea
DA
6308/* disable-link-bw-encoding-ieee */
6309DEFUN(neighbor_disable_link_bw_encoding_ieee,
6310 neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6311 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6312 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6313 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6314{
6315 int idx_peer = 1;
6316
6317 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6318 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6319}
6320
7ab294ea
DA
6321DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6322 no_neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6323 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6324 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6325 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6326{
6327 int idx_peer = 2;
6328
6329 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6330 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6331}
6332
d08c0c80
DA
6333/* extended-optional-parameters */
6334DEFUN(neighbor_extended_optional_parameters,
6335 neighbor_extended_optional_parameters_cmd,
6336 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6337 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6338 "Force the extended optional parameters format for OPEN messages\n")
6339{
6340 int idx_peer = 1;
6341
6342 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6343 PEER_FLAG_EXTENDED_OPT_PARAMS);
6344}
6345
6346DEFUN(no_neighbor_extended_optional_parameters,
6347 no_neighbor_extended_optional_parameters_cmd,
6348 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6349 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6350 "Force the extended optional parameters format for OPEN messages\n")
6351{
6352 int idx_peer = 2;
6353
6354 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6355 PEER_FLAG_EXTENDED_OPT_PARAMS);
6356}
47cbc09b
PM
6357
6358/* enforce-first-as */
28c6e247
IR
6359DEFUN (neighbor_enforce_first_as,
6360 neighbor_enforce_first_as_cmd,
6361 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6362 NEIGHBOR_STR
6363 NEIGHBOR_ADDR_STR2
6364 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6365{
6366 int idx_peer = 1;
f4b8ec07 6367
28c6e247
IR
6368 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6369 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6370}
6371
28c6e247
IR
6372DEFUN (no_neighbor_enforce_first_as,
6373 no_neighbor_enforce_first_as_cmd,
6374 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6375 NO_STR
6376 NEIGHBOR_STR
6377 NEIGHBOR_ADDR_STR2
6378 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6379{
6380 int idx_peer = 2;
f4b8ec07 6381
28c6e247
IR
6382 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6383 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6384}
6385
6386
28c6e247
IR
6387DEFUN (neighbor_description,
6388 neighbor_description_cmd,
6389 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6390 NEIGHBOR_STR
6391 NEIGHBOR_ADDR_STR2
6392 "Neighbor specific description\n"
6393 "Up to 80 characters describing this neighbor\n")
718e3744 6394{
d62a17ae 6395 int idx_peer = 1;
6396 int idx_line = 3;
28c6e247 6397 struct peer *peer;
d62a17ae 6398 char *str;
718e3744 6399
28c6e247
IR
6400 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6401 if (!peer)
d62a17ae 6402 return CMD_WARNING_CONFIG_FAILED;
718e3744 6403
d62a17ae 6404 str = argv_concat(argv, argc, idx_line);
718e3744 6405
28c6e247 6406 peer_description_set(peer, str);
718e3744 6407
d62a17ae 6408 XFREE(MTYPE_TMP, str);
718e3744 6409
28c6e247 6410 return CMD_SUCCESS;
718e3744 6411}
6412
28c6e247
IR
6413DEFUN (no_neighbor_description,
6414 no_neighbor_description_cmd,
6415 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6416 NO_STR
6417 NEIGHBOR_STR
6418 NEIGHBOR_ADDR_STR2
6419 "Neighbor specific description\n")
718e3744 6420{
d62a17ae 6421 int idx_peer = 2;
28c6e247 6422 struct peer *peer;
f4b8ec07 6423
28c6e247
IR
6424 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6425 if (!peer)
d62a17ae 6426 return CMD_WARNING_CONFIG_FAILED;
718e3744 6427
28c6e247 6428 peer_description_unset(peer);
718e3744 6429
28c6e247 6430 return CMD_SUCCESS;
718e3744 6431}
6432
1d80f243 6433ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
6434 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6435 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6436 "Neighbor specific description\n"
6437 "Up to 80 characters describing this neighbor\n")
6b0655a2 6438
28c6e247
IR
6439/* Neighbor update-source. */
6440static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6441 const char *source_str)
6442{
6443 struct peer *peer;
6444 struct prefix p;
6445 union sockunion su;
6446
6447 peer = peer_and_group_lookup_vty(vty, peer_str);
6448 if (!peer)
6449 return CMD_WARNING_CONFIG_FAILED;
6450
6451 if (peer->conf_if)
6452 return CMD_WARNING;
6453
6454 if (source_str) {
6455 if (str2sockunion(source_str, &su) == 0)
6456 peer_update_source_addr_set(peer, &su);
6457 else {
6458 if (str2prefix(source_str, &p)) {
6459 vty_out(vty,
6460 "%% Invalid update-source, remove prefix length \n");
6461 return CMD_WARNING_CONFIG_FAILED;
6462 } else
6463 peer_update_source_if_set(peer, source_str);
6464 }
6465 } else
6466 peer_update_source_unset(peer);
6467
6468 return CMD_SUCCESS;
6469}
6470
d62a17ae 6471#define BGP_UPDATE_SOURCE_HELP_STR \
6472 "IPv4 address\n" \
6473 "IPv6 address\n" \
6474 "Interface name (requires zebra to be running)\n"
369688c0 6475
28c6e247
IR
6476DEFUN (neighbor_update_source,
6477 neighbor_update_source_cmd,
6478 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6479 NEIGHBOR_STR
6480 NEIGHBOR_ADDR_STR2
6481 "Source of routing updates\n"
6482 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6483{
d62a17ae 6484 int idx_peer = 1;
6485 int idx_peer_2 = 3;
28c6e247 6486 return peer_update_source_vty(vty, argv[idx_peer]->arg,
d62a17ae 6487 argv[idx_peer_2]->arg);
718e3744 6488}
6489
28c6e247
IR
6490DEFUN (no_neighbor_update_source,
6491 no_neighbor_update_source_cmd,
6492 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6493 NO_STR
6494 NEIGHBOR_STR
6495 NEIGHBOR_ADDR_STR2
6496 "Source of routing updates\n"
6497 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6498{
d62a17ae 6499 int idx_peer = 2;
28c6e247 6500 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6501}
6b0655a2 6502
d62a17ae 6503static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6504 afi_t afi, safi_t safi,
6505 const char *rmap, int set)
718e3744 6506{
d62a17ae 6507 int ret;
6508 struct peer *peer;
80912664 6509 struct route_map *route_map = NULL;
718e3744 6510
d62a17ae 6511 peer = peer_and_group_lookup_vty(vty, peer_str);
6512 if (!peer)
6513 return CMD_WARNING_CONFIG_FAILED;
718e3744 6514
1de27621 6515 if (set) {
80912664
DS
6516 if (rmap)
6517 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
6518 ret = peer_default_originate_set(peer, afi, safi,
6519 rmap, route_map);
6520 } else
d62a17ae 6521 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 6522
d62a17ae 6523 return bgp_vty_return(vty, ret);
718e3744 6524}
6525
6526/* neighbor default-originate. */
6527DEFUN (neighbor_default_originate,
6528 neighbor_default_originate_cmd,
9ccf14f7 6529 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 6530 NEIGHBOR_STR
6531 NEIGHBOR_ADDR_STR2
6532 "Originate default route to this neighbor\n")
6533{
d62a17ae 6534 int idx_peer = 1;
6535 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6536 bgp_node_afi(vty),
6537 bgp_node_safi(vty), NULL, 1);
718e3744 6538}
6539
d62a17ae 6540ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6541 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6542 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6543 "Originate default route to this neighbor\n")
596c17ba 6544
718e3744 6545DEFUN (neighbor_default_originate_rmap,
6546 neighbor_default_originate_rmap_cmd,
9ccf14f7 6547 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 6548 NEIGHBOR_STR
6549 NEIGHBOR_ADDR_STR2
6550 "Originate default route to this neighbor\n"
6551 "Route-map to specify criteria to originate default\n"
6552 "route-map name\n")
6553{
d62a17ae 6554 int idx_peer = 1;
6555 int idx_word = 4;
6556 return peer_default_originate_set_vty(
6557 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6558 argv[idx_word]->arg, 1);
718e3744 6559}
6560
d62a17ae 6561ALIAS_HIDDEN(
6562 neighbor_default_originate_rmap,
6563 neighbor_default_originate_rmap_hidden_cmd,
6564 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6565 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6566 "Originate default route to this neighbor\n"
6567 "Route-map to specify criteria to originate default\n"
6568 "route-map name\n")
596c17ba 6569
718e3744 6570DEFUN (no_neighbor_default_originate,
6571 no_neighbor_default_originate_cmd,
a636c635 6572 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 6573 NO_STR
6574 NEIGHBOR_STR
6575 NEIGHBOR_ADDR_STR2
a636c635
DW
6576 "Originate default route to this neighbor\n"
6577 "Route-map to specify criteria to originate default\n"
6578 "route-map name\n")
718e3744 6579{
d62a17ae 6580 int idx_peer = 2;
6581 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6582 bgp_node_afi(vty),
6583 bgp_node_safi(vty), NULL, 0);
718e3744 6584}
6585
d62a17ae 6586ALIAS_HIDDEN(
6587 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6588 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6589 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6590 "Originate default route to this neighbor\n"
6591 "Route-map to specify criteria to originate default\n"
6592 "route-map name\n")
596c17ba 6593
6b0655a2 6594
28c6e247
IR
6595/* Set neighbor's BGP port. */
6596static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6597 const char *port_str)
718e3744 6598{
28c6e247
IR
6599 struct peer *peer;
6600 uint16_t port;
6601 struct servent *sp;
6602
6603 peer = peer_lookup_vty(vty, ip_str);
6604 if (!peer)
6605 return CMD_WARNING_CONFIG_FAILED;
6606
6607 if (!port_str) {
6608 sp = getservbyname("bgp", "tcp");
6609 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6610 } else {
6611 port = strtoul(port_str, NULL, 10);
6612 }
718e3744 6613
28c6e247 6614 peer_port_set(peer, port);
718e3744 6615
28c6e247
IR
6616 return CMD_SUCCESS;
6617}
f4b8ec07 6618
28c6e247
IR
6619/* Set specified peer's BGP port. */
6620DEFUN (neighbor_port,
6621 neighbor_port_cmd,
6622 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
6623 NEIGHBOR_STR
6624 NEIGHBOR_ADDR_STR
6625 "Neighbor's BGP port\n"
6626 "TCP port number\n")
6627{
6628 int idx_ip = 1;
6629 int idx_number = 3;
6630 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6631 argv[idx_number]->arg);
f4b8ec07 6632}
6b0655a2 6633
28c6e247
IR
6634DEFUN (no_neighbor_port,
6635 no_neighbor_port_cmd,
6636 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
6637 NO_STR
6638 NEIGHBOR_STR
6639 NEIGHBOR_ADDR_STR
6640 "Neighbor's BGP port\n"
6641 "TCP port number\n")
718e3744 6642{
f4b8ec07 6643 int idx_ip = 2;
28c6e247
IR
6644 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6645}
6646
6647
6648/* neighbor weight. */
6649static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6650 safi_t safi, const char *weight_str)
6651{
6652 int ret;
6653 struct peer *peer;
6654 unsigned long weight;
718e3744 6655
28c6e247
IR
6656 peer = peer_and_group_lookup_vty(vty, ip_str);
6657 if (!peer)
6658 return CMD_WARNING_CONFIG_FAILED;
718e3744 6659
28c6e247 6660 weight = strtoul(weight_str, NULL, 10);
718e3744 6661
28c6e247
IR
6662 ret = peer_weight_set(peer, afi, safi, weight);
6663 return bgp_vty_return(vty, ret);
718e3744 6664}
6665
28c6e247
IR
6666static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6667 safi_t safi)
718e3744 6668{
28c6e247
IR
6669 int ret;
6670 struct peer *peer;
f4b8ec07 6671
28c6e247
IR
6672 peer = peer_and_group_lookup_vty(vty, ip_str);
6673 if (!peer)
d62a17ae 6674 return CMD_WARNING_CONFIG_FAILED;
718e3744 6675
28c6e247
IR
6676 ret = peer_weight_unset(peer, afi, safi);
6677 return bgp_vty_return(vty, ret);
6678}
f4b8ec07 6679
28c6e247
IR
6680DEFUN (neighbor_weight,
6681 neighbor_weight_cmd,
6682 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6683 NEIGHBOR_STR
6684 NEIGHBOR_ADDR_STR2
6685 "Set default weight for routes from this neighbor\n"
6686 "default weight\n")
6687{
6688 int idx_peer = 1;
6689 int idx_number = 3;
6690 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6691 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 6692}
6693
d62a17ae 6694ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6695 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6696 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6697 "Set default weight for routes from this neighbor\n"
6698 "default weight\n")
596c17ba 6699
28c6e247
IR
6700DEFUN (no_neighbor_weight,
6701 no_neighbor_weight_cmd,
6702 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6703 NO_STR
6704 NEIGHBOR_STR
6705 NEIGHBOR_ADDR_STR2
6706 "Set default weight for routes from this neighbor\n"
6707 "default weight\n")
718e3744 6708{
d62a17ae 6709 int idx_peer = 2;
28c6e247
IR
6710 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6711 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 6712}
6713
d62a17ae 6714ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6715 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6716 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6717 "Set default weight for routes from this neighbor\n"
6718 "default weight\n")
596c17ba 6719
6b0655a2 6720
718e3744 6721/* Override capability negotiation. */
c36bc05f
IR
6722DEFUN (neighbor_override_capability,
6723 neighbor_override_capability_cmd,
6724 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6725 NEIGHBOR_STR
6726 NEIGHBOR_ADDR_STR2
6727 "Override capability negotiation result\n")
718e3744 6728{
d62a17ae 6729 int idx_peer = 1;
c36bc05f
IR
6730 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6731 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6732}
6733
c36bc05f
IR
6734DEFUN (no_neighbor_override_capability,
6735 no_neighbor_override_capability_cmd,
6736 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6737 NO_STR
6738 NEIGHBOR_STR
6739 NEIGHBOR_ADDR_STR2
6740 "Override capability negotiation result\n")
718e3744 6741{
d62a17ae 6742 int idx_peer = 2;
c36bc05f
IR
6743 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6744 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6745}
6b0655a2 6746
c36bc05f
IR
6747DEFUN (neighbor_strict_capability,
6748 neighbor_strict_capability_cmd,
6749 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6750 NEIGHBOR_STR
6751 NEIGHBOR_ADDR_STR2
6752 "Strict capability negotiation match\n")
718e3744 6753{
9fb964de
PM
6754 int idx_peer = 1;
6755
c36bc05f
IR
6756 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6757 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6758}
6759
c36bc05f
IR
6760DEFUN (no_neighbor_strict_capability,
6761 no_neighbor_strict_capability_cmd,
6762 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6763 NO_STR
6764 NEIGHBOR_STR
6765 NEIGHBOR_ADDR_STR2
6766 "Strict capability negotiation match\n")
718e3744 6767{
9fb964de 6768 int idx_peer = 2;
8611c7f3 6769
c36bc05f
IR
6770 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6771 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6772}
6b0655a2 6773
28c6e247
IR
6774static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6775 const char *keep_str, const char *hold_str)
718e3744 6776{
28c6e247
IR
6777 int ret;
6778 struct peer *peer;
6779 uint32_t keepalive;
6780 uint32_t holdtime;
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
IR
6786 keepalive = strtoul(keep_str, NULL, 10);
6787 holdtime = strtoul(hold_str, NULL, 10);
718e3744 6788
28c6e247 6789 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 6790
28c6e247 6791 return bgp_vty_return(vty, ret);
718e3744 6792}
6b0655a2 6793
28c6e247 6794static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6795{
28c6e247
IR
6796 int ret;
6797 struct peer *peer;
718e3744 6798
28c6e247
IR
6799 peer = peer_and_group_lookup_vty(vty, ip_str);
6800 if (!peer)
d62a17ae 6801 return CMD_WARNING_CONFIG_FAILED;
718e3744 6802
28c6e247 6803 ret = peer_timers_unset(peer);
718e3744 6804
28c6e247 6805 return bgp_vty_return(vty, ret);
718e3744 6806}
6b0655a2 6807
28c6e247
IR
6808DEFUN (neighbor_timers,
6809 neighbor_timers_cmd,
6810 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
6811 NEIGHBOR_STR
6812 NEIGHBOR_ADDR_STR2
6813 "BGP per neighbor timers\n"
6814 "Keepalive interval\n"
6815 "Holdtime\n")
718e3744 6816{
f4b8ec07 6817 int idx_peer = 1;
28c6e247
IR
6818 int idx_number = 3;
6819 int idx_number_2 = 4;
6820 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6821 argv[idx_number]->arg,
6822 argv[idx_number_2]->arg);
6823}
6824
6825DEFUN (no_neighbor_timers,
6826 no_neighbor_timers_cmd,
6827 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
6828 NO_STR
6829 NEIGHBOR_STR
6830 NEIGHBOR_ADDR_STR2
6831 "BGP per neighbor timers\n"
6832 "Keepalive interval\n"
6833 "Holdtime\n")
6834{
6835 int idx_peer = 2;
6836 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
6837}
6838
6839
6840static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6841 const char *time_str)
6842{
6843 int ret;
6844 struct peer *peer;
6845 uint32_t connect;
718e3744 6846
28c6e247
IR
6847 peer = peer_and_group_lookup_vty(vty, ip_str);
6848 if (!peer)
d62a17ae 6849 return CMD_WARNING_CONFIG_FAILED;
718e3744 6850
28c6e247
IR
6851 connect = strtoul(time_str, NULL, 10);
6852
6853 ret = peer_timers_connect_set(peer, connect);
718e3744 6854
28c6e247 6855 return bgp_vty_return(vty, ret);
718e3744 6856}
6857
28c6e247 6858static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6859{
28c6e247
IR
6860 int ret;
6861 struct peer *peer;
718e3744 6862
28c6e247
IR
6863 peer = peer_and_group_lookup_vty(vty, ip_str);
6864 if (!peer)
d62a17ae 6865 return CMD_WARNING_CONFIG_FAILED;
718e3744 6866
28c6e247
IR
6867 ret = peer_timers_connect_unset(peer);
6868
6869 return bgp_vty_return(vty, ret);
6870}
6871
6872DEFUN (neighbor_timers_connect,
6873 neighbor_timers_connect_cmd,
6874 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
6875 NEIGHBOR_STR
6876 NEIGHBOR_ADDR_STR2
6877 "BGP per neighbor timers\n"
6878 "BGP connect timer\n"
6879 "Connect timer\n")
6880{
6881 int idx_peer = 1;
6882 int idx_number = 4;
6883 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6884 argv[idx_number]->arg);
6885}
718e3744 6886
28c6e247
IR
6887DEFUN (no_neighbor_timers_connect,
6888 no_neighbor_timers_connect_cmd,
6889 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
6890 NO_STR
6891 NEIGHBOR_STR
6892 NEIGHBOR_ADDR_STR2
6893 "BGP per neighbor timers\n"
6894 "BGP connect timer\n"
6895 "Connect timer\n")
6896{
6897 int idx_peer = 2;
6898 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6899}
6900
d43114f3
DS
6901DEFPY (neighbor_timers_delayopen,
6902 neighbor_timers_delayopen_cmd,
6903 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
6904 NEIGHBOR_STR
6905 NEIGHBOR_ADDR_STR2
6906 "BGP per neighbor timers\n"
6907 "RFC 4271 DelayOpenTimer\n"
6908 "DelayOpenTime timer interval\n")
6909{
6910 struct peer *peer;
6911
6912 peer = peer_and_group_lookup_vty(vty, neighbor);
6913 if (!peer)
6914 return CMD_WARNING_CONFIG_FAILED;
6915
6916 if (!interval) {
6917 if (peer_timers_delayopen_unset(peer))
6918 return CMD_WARNING_CONFIG_FAILED;
6919 } else {
6920 if (peer_timers_delayopen_set(peer, interval))
6921 return CMD_WARNING_CONFIG_FAILED;
6922 }
6923
6924 return CMD_SUCCESS;
6925}
6926
6927DEFPY (no_neighbor_timers_delayopen,
6928 no_neighbor_timers_delayopen_cmd,
6929 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
6930 NO_STR
6931 NEIGHBOR_STR
6932 NEIGHBOR_ADDR_STR2
6933 "BGP per neighbor timers\n"
6934 "RFC 4271 DelayOpenTimer\n"
6935 "DelayOpenTime timer interval\n")
6936{
6937 struct peer *peer;
6938
6939 peer = peer_and_group_lookup_vty(vty, neighbor);
6940 if (!peer)
6941 return CMD_WARNING_CONFIG_FAILED;
6942
6943 if (peer_timers_delayopen_unset(peer))
6944 return CMD_WARNING_CONFIG_FAILED;
6945
6946 return CMD_SUCCESS;
6947}
6948
28c6e247
IR
6949static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
6950 const char *time_str, int set)
718e3744 6951{
28c6e247
IR
6952 int ret;
6953 struct peer *peer;
6954 uint32_t routeadv = 0;
718e3744 6955
28c6e247
IR
6956 peer = peer_and_group_lookup_vty(vty, ip_str);
6957 if (!peer)
d62a17ae 6958 return CMD_WARNING_CONFIG_FAILED;
718e3744 6959
28c6e247
IR
6960 if (time_str)
6961 routeadv = strtoul(time_str, NULL, 10);
6962
6963 if (set)
6964 ret = peer_advertise_interval_set(peer, routeadv);
6965 else
6966 ret = peer_advertise_interval_unset(peer);
718e3744 6967
28c6e247 6968 return bgp_vty_return(vty, ret);
718e3744 6969}
6970
28c6e247
IR
6971DEFUN (neighbor_advertise_interval,
6972 neighbor_advertise_interval_cmd,
6973 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
6974 NEIGHBOR_STR
6975 NEIGHBOR_ADDR_STR2
6976 "Minimum interval between sending BGP routing updates\n"
6977 "time in seconds\n")
718e3744 6978{
28c6e247
IR
6979 int idx_peer = 1;
6980 int idx_number = 3;
6981 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
6982 argv[idx_number]->arg, 1);
6983}
f4b8ec07 6984
28c6e247
IR
6985DEFUN (no_neighbor_advertise_interval,
6986 no_neighbor_advertise_interval_cmd,
6987 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
6988 NO_STR
6989 NEIGHBOR_STR
6990 NEIGHBOR_ADDR_STR2
6991 "Minimum interval between sending BGP routing updates\n"
6992 "time in seconds\n")
6993{
6994 int idx_peer = 2;
6995 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 6996}
6997
6b0655a2 6998
518f0eb1
DS
6999/* Time to wait before processing route-map updates */
7000DEFUN (bgp_set_route_map_delay_timer,
7001 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7002 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7003 SET_STR
7004 "BGP route-map delay timer\n"
7005 "Time in secs to wait before processing route-map changes\n"
f414725f 7006 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7007{
d62a17ae 7008 int idx_number = 3;
d7c0a89a 7009 uint32_t rmap_delay_timer;
d62a17ae 7010
7011 if (argv[idx_number]->arg) {
7012 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7013 bm->rmap_update_timer = rmap_delay_timer;
7014
7015 /* if the dynamic update handling is being disabled, and a timer
7016 * is
7017 * running, stop the timer and act as if the timer has already
7018 * fired.
7019 */
7020 if (!rmap_delay_timer && bm->t_rmap_update) {
7021 BGP_TIMER_OFF(bm->t_rmap_update);
7022 thread_execute(bm->master, bgp_route_map_update_timer,
7023 NULL, 0);
7024 }
7025 return CMD_SUCCESS;
7026 } else {
7027 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7028 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7029 }
518f0eb1
DS
7030}
7031
7032DEFUN (no_bgp_set_route_map_delay_timer,
7033 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7034 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7035 NO_STR
3a2d747c 7036 BGP_STR
518f0eb1 7037 "Default BGP route-map delay timer\n"
8334fd5a
DW
7038 "Reset to default time to wait for processing route-map changes\n"
7039 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7040{
518f0eb1 7041
d62a17ae 7042 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7043
d62a17ae 7044 return CMD_SUCCESS;
518f0eb1
DS
7045}
7046
28c6e247
IR
7047/* neighbor interface */
7048static int peer_interface_vty(struct vty *vty, const char *ip_str,
7049 const char *str)
718e3744 7050{
28c6e247 7051 struct peer *peer;
718e3744 7052
28c6e247
IR
7053 peer = peer_lookup_vty(vty, ip_str);
7054 if (!peer || peer->conf_if) {
7055 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7056 return CMD_WARNING_CONFIG_FAILED;
7057 }
718e3744 7058
28c6e247
IR
7059 if (str)
7060 peer_interface_set(peer, str);
7061 else
7062 peer_interface_unset(peer);
718e3744 7063
28c6e247 7064 return CMD_SUCCESS;
718e3744 7065}
7066
28c6e247
IR
7067DEFUN (neighbor_interface,
7068 neighbor_interface_cmd,
7069 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7070 NEIGHBOR_STR
7071 NEIGHBOR_ADDR_STR
7072 "Interface\n"
7073 "Interface name\n")
718e3744 7074{
28c6e247
IR
7075 int idx_ip = 1;
7076 int idx_word = 3;
294d8425 7077
28c6e247
IR
7078 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7079}
f4b8ec07 7080
28c6e247
IR
7081DEFUN (no_neighbor_interface,
7082 no_neighbor_interface_cmd,
294d8425 7083 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
28c6e247
IR
7084 NO_STR
7085 NEIGHBOR_STR
294d8425 7086 NEIGHBOR_ADDR_STR
28c6e247
IR
7087 "Interface\n"
7088 "Interface name\n")
7089{
7090 int idx_peer = 2;
294d8425 7091
28c6e247 7092 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 7093}
6b0655a2 7094
718e3744 7095DEFUN (neighbor_distribute_list,
7096 neighbor_distribute_list_cmd,
c60dec36 7097 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7098 NEIGHBOR_STR
7099 NEIGHBOR_ADDR_STR2
7100 "Filter updates to/from this neighbor\n"
718e3744 7101 "IP Access-list name\n"
7102 "Filter incoming updates\n"
7103 "Filter outgoing updates\n")
7104{
d62a17ae 7105 int idx_peer = 1;
7106 int idx_acl = 3;
7107 int direct, ret;
7108 struct peer *peer;
a8206004 7109
d62a17ae 7110 const char *pstr = argv[idx_peer]->arg;
7111 const char *acl = argv[idx_acl]->arg;
7112 const char *inout = argv[argc - 1]->text;
a8206004 7113
d62a17ae 7114 peer = peer_and_group_lookup_vty(vty, pstr);
7115 if (!peer)
7116 return CMD_WARNING_CONFIG_FAILED;
a8206004 7117
d62a17ae 7118 /* Check filter direction. */
7119 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7120 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7121 direct, acl);
a8206004 7122
d62a17ae 7123 return bgp_vty_return(vty, ret);
718e3744 7124}
7125
d62a17ae 7126ALIAS_HIDDEN(
7127 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
c60dec36 7128 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7129 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7130 "Filter updates to/from this neighbor\n"
d62a17ae 7131 "IP Access-list name\n"
7132 "Filter incoming updates\n"
7133 "Filter outgoing updates\n")
596c17ba 7134
718e3744 7135DEFUN (no_neighbor_distribute_list,
7136 no_neighbor_distribute_list_cmd,
c60dec36 7137 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7138 NO_STR
7139 NEIGHBOR_STR
7140 NEIGHBOR_ADDR_STR2
7141 "Filter updates to/from this neighbor\n"
718e3744 7142 "IP Access-list name\n"
7143 "Filter incoming updates\n"
7144 "Filter outgoing updates\n")
7145{
d62a17ae 7146 int idx_peer = 2;
7147 int direct, ret;
7148 struct peer *peer;
a8206004 7149
d62a17ae 7150 const char *pstr = argv[idx_peer]->arg;
7151 const char *inout = argv[argc - 1]->text;
a8206004 7152
d62a17ae 7153 peer = peer_and_group_lookup_vty(vty, pstr);
7154 if (!peer)
7155 return CMD_WARNING_CONFIG_FAILED;
a8206004 7156
d62a17ae 7157 /* Check filter direction. */
7158 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7159 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7160 direct);
a8206004 7161
d62a17ae 7162 return bgp_vty_return(vty, ret);
718e3744 7163}
6b0655a2 7164
d62a17ae 7165ALIAS_HIDDEN(
7166 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
c60dec36 7167 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7168 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7169 "Filter updates to/from this neighbor\n"
d62a17ae 7170 "IP Access-list name\n"
7171 "Filter incoming updates\n"
7172 "Filter outgoing updates\n")
596c17ba 7173
718e3744 7174/* Set prefix list to the peer. */
642ef664
IR
7175static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7176 afi_t afi, safi_t safi,
7177 const char *name_str,
7178 const char *direct_str)
718e3744 7179{
642ef664
IR
7180 int ret;
7181 int direct = FILTER_IN;
7182 struct peer *peer;
718e3744 7183
642ef664
IR
7184 peer = peer_and_group_lookup_vty(vty, ip_str);
7185 if (!peer)
d62a17ae 7186 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7187
642ef664
IR
7188 /* Check filter direction. */
7189 if (strncmp(direct_str, "i", 1) == 0)
7190 direct = FILTER_IN;
7191 else if (strncmp(direct_str, "o", 1) == 0)
7192 direct = FILTER_OUT;
718e3744 7193
642ef664 7194 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 7195
642ef664
IR
7196 return bgp_vty_return(vty, ret);
7197}
7198
7199static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7200 afi_t afi, safi_t safi,
7201 const char *direct_str)
7202{
7203 int ret;
7204 struct peer *peer;
7205 int direct = FILTER_IN;
7206
7207 peer = peer_and_group_lookup_vty(vty, ip_str);
7208 if (!peer)
7209 return CMD_WARNING_CONFIG_FAILED;
7210
7211 /* Check filter direction. */
7212 if (strncmp(direct_str, "i", 1) == 0)
7213 direct = FILTER_IN;
7214 else if (strncmp(direct_str, "o", 1) == 0)
7215 direct = FILTER_OUT;
7216
7217 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7218
7219 return bgp_vty_return(vty, ret);
7220}
7221
7222DEFUN (neighbor_prefix_list,
7223 neighbor_prefix_list_cmd,
7224 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7225 NEIGHBOR_STR
7226 NEIGHBOR_ADDR_STR2
7227 "Filter updates to/from this neighbor\n"
7228 "Name of a prefix list\n"
7229 "Filter incoming updates\n"
7230 "Filter outgoing updates\n")
7231{
7232 int idx_peer = 1;
7233 int idx_word = 3;
7234 int idx_in_out = 4;
7235 return peer_prefix_list_set_vty(
7236 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7237 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7238}
7239
d62a17ae 7240ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7241 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7242 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7243 "Filter updates to/from this neighbor\n"
7244 "Name of a prefix list\n"
7245 "Filter incoming updates\n"
7246 "Filter outgoing updates\n")
596c17ba 7247
642ef664
IR
7248DEFUN (no_neighbor_prefix_list,
7249 no_neighbor_prefix_list_cmd,
7250 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7251 NO_STR
7252 NEIGHBOR_STR
7253 NEIGHBOR_ADDR_STR2
7254 "Filter updates to/from this neighbor\n"
7255 "Name of a prefix list\n"
7256 "Filter incoming updates\n"
7257 "Filter outgoing updates\n")
7258{
7259 int idx_peer = 2;
7260 int idx_in_out = 5;
7261 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7262 bgp_node_afi(vty), bgp_node_safi(vty),
7263 argv[idx_in_out]->arg);
7264}
7265
7266ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7267 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7268 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7269 "Filter updates to/from this neighbor\n"
7270 "Name of a prefix list\n"
7271 "Filter incoming updates\n"
7272 "Filter outgoing updates\n")
7273
d62a17ae 7274static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7275 safi_t safi, const char *name_str,
7276 const char *direct_str)
718e3744 7277{
d62a17ae 7278 int ret;
7279 struct peer *peer;
7280 int direct = FILTER_IN;
718e3744 7281
d62a17ae 7282 peer = peer_and_group_lookup_vty(vty, ip_str);
7283 if (!peer)
7284 return CMD_WARNING_CONFIG_FAILED;
718e3744 7285
d62a17ae 7286 /* Check filter direction. */
7287 if (strncmp(direct_str, "i", 1) == 0)
7288 direct = FILTER_IN;
7289 else if (strncmp(direct_str, "o", 1) == 0)
7290 direct = FILTER_OUT;
718e3744 7291
d62a17ae 7292 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7293
d62a17ae 7294 return bgp_vty_return(vty, ret);
718e3744 7295}
7296
d62a17ae 7297static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7298 safi_t safi, const char *direct_str)
718e3744 7299{
d62a17ae 7300 int ret;
7301 struct peer *peer;
7302 int direct = FILTER_IN;
718e3744 7303
d62a17ae 7304 peer = peer_and_group_lookup_vty(vty, ip_str);
7305 if (!peer)
7306 return CMD_WARNING_CONFIG_FAILED;
718e3744 7307
d62a17ae 7308 /* Check filter direction. */
7309 if (strncmp(direct_str, "i", 1) == 0)
7310 direct = FILTER_IN;
7311 else if (strncmp(direct_str, "o", 1) == 0)
7312 direct = FILTER_OUT;
718e3744 7313
d62a17ae 7314 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7315
d62a17ae 7316 return bgp_vty_return(vty, ret);
718e3744 7317}
7318
7319DEFUN (neighbor_filter_list,
7320 neighbor_filter_list_cmd,
de71d43e 7321 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7322 NEIGHBOR_STR
7323 NEIGHBOR_ADDR_STR2
7324 "Establish BGP filters\n"
7325 "AS path access-list name\n"
7326 "Filter incoming routes\n"
7327 "Filter outgoing routes\n")
7328{
d62a17ae 7329 int idx_peer = 1;
7330 int idx_word = 3;
7331 int idx_in_out = 4;
7332 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7333 bgp_node_safi(vty), argv[idx_word]->arg,
7334 argv[idx_in_out]->arg);
718e3744 7335}
7336
d62a17ae 7337ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
de71d43e 7338 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7339 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7340 "Establish BGP filters\n"
7341 "AS path access-list name\n"
7342 "Filter incoming routes\n"
7343 "Filter outgoing routes\n")
596c17ba 7344
718e3744 7345DEFUN (no_neighbor_filter_list,
7346 no_neighbor_filter_list_cmd,
de71d43e 7347 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7348 NO_STR
7349 NEIGHBOR_STR
7350 NEIGHBOR_ADDR_STR2
7351 "Establish BGP filters\n"
7352 "AS path access-list name\n"
7353 "Filter incoming routes\n"
7354 "Filter outgoing routes\n")
7355{
d62a17ae 7356 int idx_peer = 2;
7357 int idx_in_out = 5;
7358 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7359 bgp_node_afi(vty), bgp_node_safi(vty),
7360 argv[idx_in_out]->arg);
718e3744 7361}
6b0655a2 7362
d62a17ae 7363ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
de71d43e 7364 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7365 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7366 "Establish BGP filters\n"
7367 "AS path access-list name\n"
7368 "Filter incoming routes\n"
7369 "Filter outgoing routes\n")
596c17ba 7370
7f7940e6
MK
7371/* Set advertise-map to the peer. */
7372static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7373 afi_t afi, safi_t safi,
cf2ad4d8
MK
7374 const char *advertise_str,
7375 const char *condition_str, bool condition,
7376 bool set)
7f7940e6
MK
7377{
7378 int ret = CMD_WARNING_CONFIG_FAILED;
7379 struct peer *peer;
7380 struct route_map *advertise_map;
7381 struct route_map *condition_map;
7382
7383 peer = peer_and_group_lookup_vty(vty, ip_str);
7384 if (!peer)
7385 return ret;
7386
7387 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7388 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7389
cf2ad4d8
MK
7390 if (set)
7391 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7392 advertise_map, condition_str,
7393 condition_map, condition);
7394 else
7395 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7396 advertise_map, condition_str,
7397 condition_map, condition);
7f7940e6
MK
7398
7399 return bgp_vty_return(vty, ret);
7400}
7401
389e4f92
QY
7402DEFPY (bgp_condadv_period,
7403 bgp_condadv_period_cmd,
7404 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7405 NO_STR
7406 BGP_STR
7407 "Conditional advertisement settings\n"
7408 "Set period to rescan BGP table to check if condition is met\n"
7409 "Period between BGP table scans, in seconds; default 60\n")
7410{
7411 VTY_DECLVAR_CONTEXT(bgp, bgp);
7412
7413 bgp->condition_check_period =
7414 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7415
7416 return CMD_SUCCESS;
7417}
7418
cf2ad4d8 7419DEFPY (neighbor_advertise_map,
7f7940e6 7420 neighbor_advertise_map_cmd,
52b84062 7421 "[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 7422 NO_STR
7f7940e6
MK
7423 NEIGHBOR_STR
7424 NEIGHBOR_ADDR_STR2
7425 "Route-map to conditionally advertise routes\n"
7426 "Name of advertise map\n"
7427 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7428 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7429 "Name of the exist or non exist map\n")
7f7940e6 7430{
7f7940e6
MK
7431 bool condition = CONDITION_EXIST;
7432
52b84062 7433 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7434 condition = CONDITION_NON_EXIST;
7435
52b84062
MK
7436 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7437 bgp_node_safi(vty), advertise_str,
7438 condition_str, condition, !no);
7f7940e6
MK
7439}
7440
7441ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
52b84062 7442 "[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
7443 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7444 "Route-map to conditionally advertise routes\n"
7445 "Name of advertise map\n"
7446 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7447 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7448 "Name of the exist or non exist map\n")
7f7940e6 7449
718e3744 7450/* Set route-map to the peer. */
0ea8d871
IR
7451static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7452 afi_t afi, safi_t safi, const char *name_str,
7453 const char *direct_str)
718e3744 7454{
0ea8d871
IR
7455 int ret;
7456 struct peer *peer;
7457 int direct = RMAP_IN;
7458 struct route_map *route_map;
718e3744 7459
0ea8d871
IR
7460 peer = peer_and_group_lookup_vty(vty, ip_str);
7461 if (!peer)
d62a17ae 7462 return CMD_WARNING_CONFIG_FAILED;
718e3744 7463
0ea8d871
IR
7464 /* Check filter direction. */
7465 if (strncmp(direct_str, "in", 2) == 0)
7466 direct = RMAP_IN;
7467 else if (strncmp(direct_str, "o", 1) == 0)
7468 direct = RMAP_OUT;
718e3744 7469
0ea8d871
IR
7470 route_map = route_map_lookup_warn_noexist(vty, name_str);
7471 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7472
0ea8d871
IR
7473 return bgp_vty_return(vty, ret);
7474}
7475
7476static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7477 afi_t afi, safi_t safi,
7478 const char *direct_str)
7479{
7480 int ret;
7481 struct peer *peer;
7482 int direct = RMAP_IN;
7483
7484 peer = peer_and_group_lookup_vty(vty, ip_str);
7485 if (!peer)
7486 return CMD_WARNING_CONFIG_FAILED;
7487
7488 /* Check filter direction. */
7489 if (strncmp(direct_str, "in", 2) == 0)
7490 direct = RMAP_IN;
7491 else if (strncmp(direct_str, "o", 1) == 0)
7492 direct = RMAP_OUT;
7493
7494 ret = peer_route_map_unset(peer, afi, safi, direct);
7495
7496 return bgp_vty_return(vty, ret);
7497}
7498
7499DEFUN (neighbor_route_map,
7500 neighbor_route_map_cmd,
7501 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7502 NEIGHBOR_STR
7503 NEIGHBOR_ADDR_STR2
7504 "Apply route map to neighbor\n"
7505 "Name of route map\n"
7506 "Apply map to incoming routes\n"
7507 "Apply map to outbound routes\n")
7508{
7509 int idx_peer = 1;
7510 int idx_word = 3;
7511 int idx_in_out = 4;
7512 return peer_route_map_set_vty(
7513 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7514 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7515}
7516
d6d7ed37
IR
7517ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7518 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7519 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7520 "Apply route map to neighbor\n"
7521 "Name of route map\n"
7522 "Apply map to incoming routes\n"
7523 "Apply map to outbound routes\n")
7524
0ea8d871
IR
7525DEFUN (no_neighbor_route_map,
7526 no_neighbor_route_map_cmd,
7527 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7528 NO_STR
7529 NEIGHBOR_STR
7530 NEIGHBOR_ADDR_STR2
7531 "Apply route map to neighbor\n"
7532 "Name of route map\n"
7533 "Apply map to incoming routes\n"
7534 "Apply map to outbound routes\n")
7535{
7536 int idx_peer = 2;
7537 int idx_in_out = 5;
7538 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7539 bgp_node_afi(vty), bgp_node_safi(vty),
7540 argv[idx_in_out]->arg);
7541}
7542
7543ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
d6d7ed37
IR
7544 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7545 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7546 "Apply route map to neighbor\n"
7547 "Name of route map\n"
7548 "Apply map to incoming routes\n"
7549 "Apply map to outbound routes\n")
7550
718e3744 7551/* Set unsuppress-map to the peer. */
d62a17ae 7552static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7553 afi_t afi, safi_t safi,
7554 const char *name_str)
718e3744 7555{
d62a17ae 7556 int ret;
7557 struct peer *peer;
1de27621 7558 struct route_map *route_map;
718e3744 7559
d62a17ae 7560 peer = peer_and_group_lookup_vty(vty, ip_str);
7561 if (!peer)
7562 return CMD_WARNING_CONFIG_FAILED;
718e3744 7563
1de27621
DA
7564 route_map = route_map_lookup_warn_noexist(vty, name_str);
7565 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 7566
d62a17ae 7567 return bgp_vty_return(vty, ret);
718e3744 7568}
7569
7570/* Unset route-map from the peer. */
d62a17ae 7571static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7572 afi_t afi, safi_t safi)
718e3744 7573{
d62a17ae 7574 int ret;
7575 struct peer *peer;
718e3744 7576
d62a17ae 7577 peer = peer_and_group_lookup_vty(vty, ip_str);
7578 if (!peer)
7579 return CMD_WARNING_CONFIG_FAILED;
718e3744 7580
d62a17ae 7581 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 7582
d62a17ae 7583 return bgp_vty_return(vty, ret);
718e3744 7584}
7585
7586DEFUN (neighbor_unsuppress_map,
7587 neighbor_unsuppress_map_cmd,
9ccf14f7 7588 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7589 NEIGHBOR_STR
7590 NEIGHBOR_ADDR_STR2
7591 "Route-map to selectively unsuppress suppressed routes\n"
7592 "Name of route map\n")
7593{
d62a17ae 7594 int idx_peer = 1;
7595 int idx_word = 3;
7596 return peer_unsuppress_map_set_vty(
7597 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7598 argv[idx_word]->arg);
718e3744 7599}
7600
d62a17ae 7601ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7602 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7603 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7604 "Route-map to selectively unsuppress suppressed routes\n"
7605 "Name of route map\n")
596c17ba 7606
718e3744 7607DEFUN (no_neighbor_unsuppress_map,
7608 no_neighbor_unsuppress_map_cmd,
9ccf14f7 7609 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7610 NO_STR
7611 NEIGHBOR_STR
7612 NEIGHBOR_ADDR_STR2
7613 "Route-map to selectively unsuppress suppressed routes\n"
7614 "Name of route map\n")
7615{
d62a17ae 7616 int idx_peer = 2;
7617 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7618 bgp_node_afi(vty),
7619 bgp_node_safi(vty));
718e3744 7620}
6b0655a2 7621
d62a17ae 7622ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7623 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7624 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7625 "Route-map to selectively unsuppress suppressed routes\n"
7626 "Name of route map\n")
596c17ba 7627
7e62b792
IR
7628static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7629 afi_t afi, safi_t safi,
7630 const char *num_str,
7631 const char *threshold_str, int warning,
7632 const char *restart_str,
7633 const char *force_str)
7634{
7635 int ret;
7636 struct peer *peer;
7637 uint32_t max;
7638 uint8_t threshold;
7639 uint16_t restart;
7640
7641 peer = peer_and_group_lookup_vty(vty, ip_str);
7642 if (!peer)
7643 return CMD_WARNING_CONFIG_FAILED;
7644
7645 max = strtoul(num_str, NULL, 10);
7646 if (threshold_str)
7647 threshold = atoi(threshold_str);
7648 else
7649 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7650
7651 if (restart_str)
7652 restart = atoi(restart_str);
7653 else
7654 restart = 0;
7655
7656 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7657 restart, force_str ? true : false);
7658
7659 return bgp_vty_return(vty, ret);
7660}
7661
7662static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7663 afi_t afi, safi_t safi)
7664{
7665 int ret;
7666 struct peer *peer;
7667
7668 peer = peer_and_group_lookup_vty(vty, ip_str);
7669 if (!peer)
7670 return CMD_WARNING_CONFIG_FAILED;
7671
7672 ret = peer_maximum_prefix_unset(peer, afi, safi);
7673
7674 return bgp_vty_return(vty, ret);
7675}
7676
fde246e8 7677/* Maximum number of prefix to be sent to the neighbor. */
1d80f243
IR
7678DEFUN(neighbor_maximum_prefix_out,
7679 neighbor_maximum_prefix_out_cmd,
7680 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7681 NEIGHBOR_STR
7682 NEIGHBOR_ADDR_STR2
7683 "Maximum number of prefixes to be sent to this peer\n"
7684 "Maximum no. of prefix limit\n")
fde246e8 7685{
80444d30 7686 int ret;
fde246e8
DA
7687 int idx_peer = 1;
7688 int idx_number = 3;
7e62b792
IR
7689 struct peer *peer;
7690 uint32_t max;
fde246e8
DA
7691 afi_t afi = bgp_node_afi(vty);
7692 safi_t safi = bgp_node_safi(vty);
7693
7e62b792
IR
7694 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7695 if (!peer)
fde246e8
DA
7696 return CMD_WARNING_CONFIG_FAILED;
7697
7e62b792 7698 max = strtoul(argv[idx_number]->arg, NULL, 10);
fde246e8 7699
80444d30 7700 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
fde246e8 7701
80444d30 7702 return bgp_vty_return(vty, ret);
fde246e8
DA
7703}
7704
1d80f243
IR
7705DEFUN(no_neighbor_maximum_prefix_out,
7706 no_neighbor_maximum_prefix_out_cmd,
bc03c622 7707 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
1d80f243
IR
7708 NO_STR
7709 NEIGHBOR_STR
7710 NEIGHBOR_ADDR_STR2
bc03c622
LS
7711 "Maximum number of prefixes to be sent to this peer\n"
7712 "Maximum no. of prefix limit\n")
fde246e8 7713{
80444d30 7714 int ret;
fde246e8 7715 int idx_peer = 2;
7e62b792 7716 struct peer *peer;
fde246e8
DA
7717 afi_t afi = bgp_node_afi(vty);
7718 safi_t safi = bgp_node_safi(vty);
7719
7e62b792
IR
7720 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7721 if (!peer)
fde246e8
DA
7722 return CMD_WARNING_CONFIG_FAILED;
7723
80444d30 7724 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
fde246e8 7725
80444d30 7726 return bgp_vty_return(vty, ret);
fde246e8
DA
7727}
7728
9cbd06e0
DA
7729/* Maximum number of prefix configuration. Prefix count is different
7730 for each peer configuration. So this configuration can be set for
718e3744 7731 each peer configuration. */
1d80f243
IR
7732DEFUN (neighbor_maximum_prefix,
7733 neighbor_maximum_prefix_cmd,
7734 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7735 NEIGHBOR_STR
7736 NEIGHBOR_ADDR_STR2
7737 "Maximum number of prefix accept from this peer\n"
7738 "maximum no. of prefix limit\n"
7739 "Force checking all received routes not only accepted\n")
718e3744 7740{
d62a17ae 7741 int idx_peer = 1;
7742 int idx_number = 3;
9cbd06e0 7743 int idx_force = 0;
7e62b792 7744 char *force = NULL;
9cbd06e0
DA
7745
7746 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7747 force = argv[idx_force]->arg;
9cbd06e0 7748
7e62b792
IR
7749 return peer_maximum_prefix_set_vty(
7750 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7751 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 7752}
7753
d62a17ae 7754ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7755 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 7756 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7757 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
7758 "maximum no. of prefix limit\n"
7759 "Force checking all received routes not only accepted\n")
596c17ba 7760
1d80f243
IR
7761DEFUN (neighbor_maximum_prefix_threshold,
7762 neighbor_maximum_prefix_threshold_cmd,
7763 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7764 NEIGHBOR_STR
7765 NEIGHBOR_ADDR_STR2
7766 "Maximum number of prefix accept from this peer\n"
7767 "maximum no. of prefix limit\n"
7768 "Threshold value (%) at which to generate a warning msg\n"
7769 "Force checking all received routes not only accepted\n")
e0701b79 7770{
d62a17ae 7771 int idx_peer = 1;
7772 int idx_number = 3;
7773 int idx_number_2 = 4;
9cbd06e0 7774 int idx_force = 0;
7e62b792 7775 char *force = NULL;
9cbd06e0
DA
7776
7777 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7778 force = argv[idx_force]->arg;
9cbd06e0 7779
7e62b792
IR
7780 return peer_maximum_prefix_set_vty(
7781 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7782 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 7783}
e0701b79 7784
d62a17ae 7785ALIAS_HIDDEN(
7786 neighbor_maximum_prefix_threshold,
7787 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 7788 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 7789 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7790 "Maximum number of prefix accept from this peer\n"
7791 "maximum no. of prefix limit\n"
9cbd06e0
DA
7792 "Threshold value (%) at which to generate a warning msg\n"
7793 "Force checking all received routes not only accepted\n")
596c17ba 7794
1d80f243
IR
7795DEFUN (neighbor_maximum_prefix_warning,
7796 neighbor_maximum_prefix_warning_cmd,
7797 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7798 NEIGHBOR_STR
7799 NEIGHBOR_ADDR_STR2
7800 "Maximum number of prefix accept from this peer\n"
7801 "maximum no. of prefix limit\n"
7802 "Only give warning message when limit is exceeded\n"
7803 "Force checking all received routes not only accepted\n")
718e3744 7804{
d62a17ae 7805 int idx_peer = 1;
7806 int idx_number = 3;
9cbd06e0 7807 int idx_force = 0;
7e62b792 7808 char *force = NULL;
9cbd06e0
DA
7809
7810 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7811 force = argv[idx_force]->arg;
9cbd06e0 7812
7e62b792
IR
7813 return peer_maximum_prefix_set_vty(
7814 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7815 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 7816}
7817
d62a17ae 7818ALIAS_HIDDEN(
7819 neighbor_maximum_prefix_warning,
7820 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 7821 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 7822 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7823 "Maximum number of prefix accept from this peer\n"
7824 "maximum no. of prefix limit\n"
9cbd06e0
DA
7825 "Only give warning message when limit is exceeded\n"
7826 "Force checking all received routes not only accepted\n")
596c17ba 7827
1d80f243
IR
7828DEFUN (neighbor_maximum_prefix_threshold_warning,
7829 neighbor_maximum_prefix_threshold_warning_cmd,
7830 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7831 NEIGHBOR_STR
7832 NEIGHBOR_ADDR_STR2
7833 "Maximum number of prefix accept from this peer\n"
7834 "maximum no. of prefix limit\n"
7835 "Threshold value (%) at which to generate a warning msg\n"
7836 "Only give warning message when limit is exceeded\n"
7837 "Force checking all received routes not only accepted\n")
e0701b79 7838{
d62a17ae 7839 int idx_peer = 1;
7840 int idx_number = 3;
7841 int idx_number_2 = 4;
9cbd06e0 7842 int idx_force = 0;
7e62b792 7843 char *force = NULL;
9cbd06e0
DA
7844
7845 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7846 force = argv[idx_force]->arg;
9cbd06e0 7847
7e62b792
IR
7848 return peer_maximum_prefix_set_vty(
7849 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7850 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 7851}
7852
d62a17ae 7853ALIAS_HIDDEN(
7854 neighbor_maximum_prefix_threshold_warning,
7855 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 7856 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 7857 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7858 "Maximum number of prefix accept from this peer\n"
7859 "maximum no. of prefix limit\n"
7860 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
7861 "Only give warning message when limit is exceeded\n"
7862 "Force checking all received routes not only accepted\n")
596c17ba 7863
1d80f243
IR
7864DEFUN (neighbor_maximum_prefix_restart,
7865 neighbor_maximum_prefix_restart_cmd,
7866 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7867 NEIGHBOR_STR
7868 NEIGHBOR_ADDR_STR2
7869 "Maximum number of prefix accept from this peer\n"
7870 "maximum no. of prefix limit\n"
7871 "Restart bgp connection after limit is exceeded\n"
7872 "Restart interval in minutes\n"
7873 "Force checking all received routes not only accepted\n")
0a486e5f 7874{
d62a17ae 7875 int idx_peer = 1;
7876 int idx_number = 3;
7877 int idx_number_2 = 5;
9cbd06e0 7878 int idx_force = 0;
7e62b792 7879 char *force = NULL;
9cbd06e0
DA
7880
7881 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7882 force = argv[idx_force]->arg;
9cbd06e0 7883
7e62b792
IR
7884 return peer_maximum_prefix_set_vty(
7885 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7886 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 7887}
7888
d62a17ae 7889ALIAS_HIDDEN(
7890 neighbor_maximum_prefix_restart,
7891 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 7892 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 7893 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7894 "Maximum number of prefix accept from this peer\n"
7895 "maximum no. of prefix limit\n"
7896 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7897 "Restart interval in minutes\n"
7898 "Force checking all received routes not only accepted\n")
596c17ba 7899
1d80f243
IR
7900DEFUN (neighbor_maximum_prefix_threshold_restart,
7901 neighbor_maximum_prefix_threshold_restart_cmd,
7902 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7903 NEIGHBOR_STR
7904 NEIGHBOR_ADDR_STR2
7905 "Maximum number of prefixes to accept from this peer\n"
7906 "maximum no. of prefix limit\n"
7907 "Threshold value (%) at which to generate a warning msg\n"
7908 "Restart bgp connection after limit is exceeded\n"
7909 "Restart interval in minutes\n"
7910 "Force checking all received routes not only accepted\n")
0a486e5f 7911{
d62a17ae 7912 int idx_peer = 1;
7913 int idx_number = 3;
7914 int idx_number_2 = 4;
7915 int idx_number_3 = 6;
9cbd06e0 7916 int idx_force = 0;
7e62b792 7917 char *force = NULL;
9cbd06e0
DA
7918
7919 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7920 force = argv[idx_force]->arg;
9cbd06e0 7921
7e62b792
IR
7922 return peer_maximum_prefix_set_vty(
7923 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7924 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
7925 argv[idx_number_3]->arg, force);
d62a17ae 7926}
7927
7928ALIAS_HIDDEN(
7929 neighbor_maximum_prefix_threshold_restart,
7930 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 7931 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 7932 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7933 "Maximum number of prefixes to accept from this peer\n"
7934 "maximum no. of prefix limit\n"
7935 "Threshold value (%) at which to generate a warning msg\n"
7936 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7937 "Restart interval in minutes\n"
7938 "Force checking all received routes not only accepted\n")
596c17ba 7939
1d80f243
IR
7940DEFUN (no_neighbor_maximum_prefix,
7941 no_neighbor_maximum_prefix_cmd,
7942 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
7943 NO_STR
7944 NEIGHBOR_STR
7945 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"
7951 "Only give warning message when limit is exceeded\n"
7952 "Force checking all received routes not only accepted\n")
718e3744 7953{
d62a17ae 7954 int idx_peer = 2;
7e62b792
IR
7955 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
7956 bgp_node_afi(vty),
7957 bgp_node_safi(vty));
718e3744 7958}
e52702f2 7959
d62a17ae 7960ALIAS_HIDDEN(
7961 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7962 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 7963 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7964 "Maximum number of prefixes to accept from this peer\n"
7965 "maximum no. of prefix limit\n"
7966 "Threshold value (%) at which to generate a warning msg\n"
7967 "Restart bgp connection after limit is exceeded\n"
7968 "Restart interval in minutes\n"
9cbd06e0
DA
7969 "Only give warning message when limit is exceeded\n"
7970 "Force checking all received routes not only accepted\n")
596c17ba 7971
718e3744 7972
718e3744 7973/* "neighbor allowas-in" */
7974DEFUN (neighbor_allowas_in,
7975 neighbor_allowas_in_cmd,
fd8503f5 7976 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7977 NEIGHBOR_STR
7978 NEIGHBOR_ADDR_STR2
31500417 7979 "Accept as-path with my AS present in it\n"
f79f7a7b 7980 "Number of occurrences of AS number\n"
fd8503f5 7981 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7982{
d62a17ae 7983 int idx_peer = 1;
7984 int idx_number_origin = 3;
7985 int ret;
7986 int origin = 0;
7987 struct peer *peer;
7988 int allow_num = 0;
7989
7990 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7991 if (!peer)
7992 return CMD_WARNING_CONFIG_FAILED;
7993
7994 if (argc <= idx_number_origin)
7995 allow_num = 3;
7996 else {
7997 if (argv[idx_number_origin]->type == WORD_TKN)
7998 origin = 1;
7999 else
8000 allow_num = atoi(argv[idx_number_origin]->arg);
8001 }
8002
8003 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8004 allow_num, origin);
8005
8006 return bgp_vty_return(vty, ret);
8007}
8008
8009ALIAS_HIDDEN(
8010 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8011 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8012 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8013 "Accept as-path with my AS present in it\n"
f79f7a7b 8014 "Number of occurrences of AS number\n"
d62a17ae 8015 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8016
718e3744 8017DEFUN (no_neighbor_allowas_in,
8018 no_neighbor_allowas_in_cmd,
fd8503f5 8019 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8020 NO_STR
8021 NEIGHBOR_STR
8022 NEIGHBOR_ADDR_STR2
8334fd5a 8023 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8024 "Number of occurrences of AS number\n"
fd8503f5 8025 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8026{
d62a17ae 8027 int idx_peer = 2;
8028 int ret;
8029 struct peer *peer;
718e3744 8030
d62a17ae 8031 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8032 if (!peer)
8033 return CMD_WARNING_CONFIG_FAILED;
718e3744 8034
d62a17ae 8035 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8036 bgp_node_safi(vty));
718e3744 8037
d62a17ae 8038 return bgp_vty_return(vty, ret);
718e3744 8039}
6b0655a2 8040
d62a17ae 8041ALIAS_HIDDEN(
8042 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8043 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8044 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8045 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8046 "Number of occurrences of AS number\n"
d62a17ae 8047 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8048
28c6e247
IR
8049DEFUN (neighbor_ttl_security,
8050 neighbor_ttl_security_cmd,
8051 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8052 NEIGHBOR_STR
8053 NEIGHBOR_ADDR_STR2
8054 "BGP ttl-security parameters\n"
8055 "Specify the maximum number of hops to the BGP peer\n"
8056 "Number of hops to BGP peer\n")
fa411a21 8057{
d62a17ae 8058 int idx_peer = 1;
8059 int idx_number = 4;
28c6e247
IR
8060 struct peer *peer;
8061 int gtsm_hops;
d62a17ae 8062
28c6e247
IR
8063 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8064 if (!peer)
d62a17ae 8065 return CMD_WARNING_CONFIG_FAILED;
8066
28c6e247
IR
8067 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8068
8069 /*
8070 * If 'neighbor swpX', then this is for directly connected peers,
8071 * we should not accept a ttl-security hops value greater than 1.
8072 */
8073 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8074 vty_out(vty,
8075 "%s is directly connected peer, hops cannot exceed 1\n",
8076 argv[idx_peer]->arg);
8077 return CMD_WARNING_CONFIG_FAILED;
8078 }
7ebe625c 8079
28c6e247 8080 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
8081}
8082
1d80f243
IR
8083DEFUN (no_neighbor_ttl_security,
8084 no_neighbor_ttl_security_cmd,
8085 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8086 NO_STR
8087 NEIGHBOR_STR
8088 NEIGHBOR_ADDR_STR2
8089 "BGP ttl-security parameters\n"
8090 "Specify the maximum number of hops to the BGP peer\n"
8091 "Number of hops to BGP peer\n")
fa411a21 8092{
d62a17ae 8093 int idx_peer = 2;
28c6e247 8094 struct peer *peer;
fa411a21 8095
28c6e247
IR
8096 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8097 if (!peer)
d62a17ae 8098 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8099
28c6e247 8100 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 8101}
6b0655a2 8102
7c0e4312
DA
8103/* disable-addpath-rx */
8104DEFUN(neighbor_disable_addpath_rx,
8105 neighbor_disable_addpath_rx_cmd,
8106 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8107 NEIGHBOR_STR
8108 NEIGHBOR_ADDR_STR2
8109 "Do not accept additional paths\n")
8110{
8111 char *peer_str = argv[1]->arg;
8112 struct peer *peer;
8113 afi_t afi = bgp_node_afi(vty);
8114 safi_t safi = bgp_node_safi(vty);
8115
8116 peer = peer_and_group_lookup_vty(vty, peer_str);
8117 if (!peer)
8118 return CMD_WARNING_CONFIG_FAILED;
8119
8120 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8121 PEER_FLAG_DISABLE_ADDPATH_RX);
8122}
8123
8124DEFUN(no_neighbor_disable_addpath_rx,
8125 no_neighbor_disable_addpath_rx_cmd,
8126 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8127 NO_STR
8128 NEIGHBOR_STR
8129 NEIGHBOR_ADDR_STR2
8130 "Do not accept additional paths\n")
8131{
8132 char *peer_str = argv[2]->arg;
8133 struct peer *peer;
8134 afi_t afi = bgp_node_afi(vty);
8135 safi_t safi = bgp_node_safi(vty);
8136
8137 peer = peer_and_group_lookup_vty(vty, peer_str);
8138 if (!peer)
8139 return CMD_WARNING_CONFIG_FAILED;
8140
8141 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8142 PEER_FLAG_DISABLE_ADDPATH_RX);
8143}
8144
adbac85e
DW
8145DEFUN (neighbor_addpath_tx_all_paths,
8146 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8147 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8148 NEIGHBOR_STR
8149 NEIGHBOR_ADDR_STR2
8150 "Use addpath to advertise all paths to a neighbor\n")
8151{
d62a17ae 8152 int idx_peer = 1;
8153 struct peer *peer;
adbac85e 8154
d62a17ae 8155 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8156 if (!peer)
8157 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8158
dcc68b5e
MS
8159 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8160 BGP_ADDPATH_ALL);
8161 return CMD_SUCCESS;
adbac85e
DW
8162}
8163
d62a17ae 8164ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8165 neighbor_addpath_tx_all_paths_hidden_cmd,
8166 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8167 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8168 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8169
adbac85e
DW
8170DEFUN (no_neighbor_addpath_tx_all_paths,
8171 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8172 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8173 NO_STR
8174 NEIGHBOR_STR
8175 NEIGHBOR_ADDR_STR2
8176 "Use addpath to advertise all paths to a neighbor\n")
8177{
d62a17ae 8178 int idx_peer = 2;
dcc68b5e
MS
8179 struct peer *peer;
8180
8181 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8182 if (!peer)
8183 return CMD_WARNING_CONFIG_FAILED;
8184
8185 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8186 != BGP_ADDPATH_ALL) {
8187 vty_out(vty,
8188 "%% Peer not currently configured to transmit all paths.");
8189 return CMD_WARNING_CONFIG_FAILED;
8190 }
8191
8192 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8193 BGP_ADDPATH_NONE);
8194
8195 return CMD_SUCCESS;
adbac85e
DW
8196}
8197
d62a17ae 8198ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8199 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8200 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8201 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8202 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8203
06370dac
DW
8204DEFUN (neighbor_addpath_tx_bestpath_per_as,
8205 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8206 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8207 NEIGHBOR_STR
8208 NEIGHBOR_ADDR_STR2
8209 "Use addpath to advertise the bestpath per each neighboring AS\n")
8210{
d62a17ae 8211 int idx_peer = 1;
8212 struct peer *peer;
06370dac 8213
d62a17ae 8214 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8215 if (!peer)
8216 return CMD_WARNING_CONFIG_FAILED;
06370dac 8217
dcc68b5e
MS
8218 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8219 BGP_ADDPATH_BEST_PER_AS);
8220
8221 return CMD_SUCCESS;
06370dac
DW
8222}
8223
d62a17ae 8224ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8225 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8226 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8227 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8228 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8229
06370dac
DW
8230DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8231 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8232 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8233 NO_STR
8234 NEIGHBOR_STR
8235 NEIGHBOR_ADDR_STR2
8236 "Use addpath to advertise the bestpath per each neighboring AS\n")
8237{
d62a17ae 8238 int idx_peer = 2;
dcc68b5e
MS
8239 struct peer *peer;
8240
8241 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8242 if (!peer)
8243 return CMD_WARNING_CONFIG_FAILED;
8244
8245 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8246 != BGP_ADDPATH_BEST_PER_AS) {
8247 vty_out(vty,
8248 "%% Peer not currently configured to transmit all best path per as.");
8249 return CMD_WARNING_CONFIG_FAILED;
8250 }
8251
8252 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8253 BGP_ADDPATH_NONE);
8254
8255 return CMD_SUCCESS;
06370dac
DW
8256}
8257
d62a17ae 8258ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8259 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8260 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8261 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8262 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8263
2b31007c
RZ
8264DEFPY(
8265 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8266 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8267 NEIGHBOR_STR
8268 NEIGHBOR_ADDR_STR2
8269 "Detect AS loops before sending to neighbor\n")
8270{
8271 struct peer *peer;
8272
8273 peer = peer_and_group_lookup_vty(vty, neighbor);
8274 if (!peer)
8275 return CMD_WARNING_CONFIG_FAILED;
8276
8277 peer->as_path_loop_detection = true;
8278
8279 return CMD_SUCCESS;
8280}
8281
8282DEFPY(
8283 no_neighbor_aspath_loop_detection,
8284 no_neighbor_aspath_loop_detection_cmd,
8285 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8286 NO_STR
8287 NEIGHBOR_STR
8288 NEIGHBOR_ADDR_STR2
8289 "Detect AS loops before sending to neighbor\n")
8290{
8291 struct peer *peer;
8292
8293 peer = peer_and_group_lookup_vty(vty, neighbor);
8294 if (!peer)
8295 return CMD_WARNING_CONFIG_FAILED;
8296
8297 peer->as_path_loop_detection = false;
8298
8299 return CMD_SUCCESS;
8300}
8301
b9c7bc5a 8302static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8303 struct ecommunity **list, bool is_rt6)
ddb5b488 8304{
b9c7bc5a
PZ
8305 struct ecommunity *ecom = NULL;
8306 struct ecommunity *ecomadd;
ddb5b488 8307
b9c7bc5a 8308 for (; argc; --argc, ++argv) {
9a659715
PG
8309 if (is_rt6)
8310 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8311 ECOMMUNITY_ROUTE_TARGET,
8312 0);
8313 else
8314 ecomadd = ecommunity_str2com(argv[0]->arg,
8315 ECOMMUNITY_ROUTE_TARGET,
8316 0);
b9c7bc5a
PZ
8317 if (!ecomadd) {
8318 vty_out(vty, "Malformed community-list value\n");
8319 if (ecom)
8320 ecommunity_free(&ecom);
8321 return CMD_WARNING_CONFIG_FAILED;
8322 }
ddb5b488 8323
b9c7bc5a
PZ
8324 if (ecom) {
8325 ecommunity_merge(ecom, ecomadd);
8326 ecommunity_free(&ecomadd);
8327 } else {
8328 ecom = ecomadd;
8329 }
8330 }
8331
8332 if (*list) {
8333 ecommunity_free(&*list);
ddb5b488 8334 }
b9c7bc5a
PZ
8335 *list = ecom;
8336
8337 return CMD_SUCCESS;
ddb5b488
PZ
8338}
8339
0ca70ba5
DS
8340/*
8341 * v2vimport is true if we are handling a `import vrf ...` command
8342 */
8343static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8344{
0ca70ba5
DS
8345 afi_t afi;
8346
ddb5b488 8347 switch (vty->node) {
b9c7bc5a 8348 case BGP_IPV4_NODE:
0ca70ba5
DS
8349 afi = AFI_IP;
8350 break;
b9c7bc5a 8351 case BGP_IPV6_NODE:
0ca70ba5
DS
8352 afi = AFI_IP6;
8353 break;
ddb5b488
PZ
8354 default:
8355 vty_out(vty,
b9c7bc5a 8356 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 8357 return AFI_MAX;
ddb5b488 8358 }
69b07479 8359
0ca70ba5
DS
8360 if (!v2vimport) {
8361 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8362 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8363 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8364 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8365 vty_out(vty,
8366 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8367 return AFI_MAX;
8368 }
8369 } else {
8370 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8371 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8372 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8373 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8374 vty_out(vty,
8375 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8376 return AFI_MAX;
8377 }
8378 }
8379 return afi;
ddb5b488
PZ
8380}
8381
585f1adc
IR
8382DEFPY (af_rd_vpn_export,
8383 af_rd_vpn_export_cmd,
8384 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8385 NO_STR
8386 "Specify route distinguisher\n"
8387 "Between current address-family and vpn\n"
8388 "For routes leaked from current address-family to vpn\n"
8389 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 8390{
585f1adc
IR
8391 VTY_DECLVAR_CONTEXT(bgp, bgp);
8392 struct prefix_rd prd;
8393 int ret;
ddb5b488 8394 afi_t afi;
b9c7bc5a 8395 int idx = 0;
585f1adc 8396 bool yes = true;
b9c7bc5a 8397
585f1adc
IR
8398 if (argv_find(argv, argc, "no", &idx))
8399 yes = false;
ddb5b488 8400
585f1adc
IR
8401 if (yes) {
8402 ret = str2prefix_rd(rd_str, &prd);
8403 if (!ret) {
8404 vty_out(vty, "%% Malformed rd\n");
8405 return CMD_WARNING_CONFIG_FAILED;
8406 }
8407 }
ddb5b488 8408
585f1adc
IR
8409 afi = vpn_policy_getafi(vty, bgp, false);
8410 if (afi == AFI_MAX)
8411 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8412
585f1adc
IR
8413 /*
8414 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8415 */
8416 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8417 bgp_get_default(), bgp);
ddb5b488 8418
585f1adc
IR
8419 if (yes) {
8420 bgp->vpn_policy[afi].tovpn_rd = prd;
8421 SET_FLAG(bgp->vpn_policy[afi].flags,
8422 BGP_VPN_POLICY_TOVPN_RD_SET);
8423 } else {
8424 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8425 BGP_VPN_POLICY_TOVPN_RD_SET);
8426 }
69b07479 8427
585f1adc
IR
8428 /* post-change: re-export vpn routes */
8429 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8430 bgp_get_default(), bgp);
8431
8432 return CMD_SUCCESS;
ddb5b488
PZ
8433}
8434
b9c7bc5a
PZ
8435ALIAS (af_rd_vpn_export,
8436 af_no_rd_vpn_export_cmd,
8437 "no rd vpn export",
ddb5b488 8438 NO_STR
b9c7bc5a
PZ
8439 "Specify route distinguisher\n"
8440 "Between current address-family and vpn\n"
8441 "For routes leaked from current address-family to vpn\n")
ddb5b488 8442
b9c7bc5a
PZ
8443DEFPY (af_label_vpn_export,
8444 af_label_vpn_export_cmd,
e70e9f8e 8445 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 8446 NO_STR
ddb5b488 8447 "label value for VRF\n"
b9c7bc5a
PZ
8448 "Between current address-family and vpn\n"
8449 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
8450 "Label Value <0-1048575>\n"
8451 "Automatically assign a label\n")
ddb5b488
PZ
8452{
8453 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8454 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 8455 afi_t afi;
b9c7bc5a 8456 int idx = 0;
c6423c31 8457 bool yes = true;
b9c7bc5a
PZ
8458
8459 if (argv_find(argv, argc, "no", &idx))
c6423c31 8460 yes = false;
ddb5b488 8461
21a16cc2
PZ
8462 /* If "no ...", squash trailing parameter */
8463 if (!yes)
8464 label_auto = NULL;
8465
e70e9f8e
PZ
8466 if (yes) {
8467 if (!label_auto)
8468 label = label_val; /* parser should force unsigned */
8469 }
ddb5b488 8470
0ca70ba5 8471 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8472 if (afi == AFI_MAX)
8473 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 8474
e70e9f8e 8475
69b07479
DS
8476 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8477 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8478 /* no change */
8479 return CMD_SUCCESS;
e70e9f8e 8480
69b07479
DS
8481 /*
8482 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8483 */
8484 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8485 bgp_get_default(), bgp);
8486
8487 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8488 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8489
8490 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8491
8492 /*
8493 * label has previously been automatically
8494 * assigned by labelpool: release it
8495 *
8496 * NB if tovpn_label == MPLS_LABEL_NONE it
8497 * means the automatic assignment is in flight
8498 * and therefore the labelpool callback must
8499 * detect that the auto label is not needed.
8500 */
8501
8502 bgp_lp_release(LP_TYPE_VRF,
8503 &bgp->vpn_policy[afi],
8504 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 8505 }
69b07479
DS
8506 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8507 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8508 }
ddb5b488 8509
69b07479
DS
8510 bgp->vpn_policy[afi].tovpn_label = label;
8511 if (label_auto) {
8512 SET_FLAG(bgp->vpn_policy[afi].flags,
8513 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8514 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8515 vpn_leak_label_callback);
ddb5b488
PZ
8516 }
8517
69b07479
DS
8518 /* post-change: re-export vpn routes */
8519 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8520 bgp_get_default(), bgp);
8521
0d020cd6 8522 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
8523 return CMD_SUCCESS;
8524}
8525
b72c9e14
HS
8526DEFPY (af_sid_vpn_export,
8527 af_sid_vpn_export_cmd,
8528 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8529 NO_STR
8530 "sid value for VRF\n"
8531 "Between current address-family and vpn\n"
8532 "For routes leaked from current address-family to vpn\n"
8533 "Sid allocation index\n"
8534 "Automatically assign a label\n")
8535{
8536 VTY_DECLVAR_CONTEXT(bgp, bgp);
8537 afi_t afi;
8538 int debug = 0;
8539 int idx = 0;
8540 bool yes = true;
8541
8542 if (argv_find(argv, argc, "no", &idx))
8543 yes = false;
8544 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8545 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8546
8547 afi = vpn_policy_getafi(vty, bgp, false);
8548 if (afi == AFI_MAX)
8549 return CMD_WARNING_CONFIG_FAILED;
8550
8551 if (!yes) {
8552 /* implement me */
8553 vty_out(vty, "It's not implemented");
8554 return CMD_WARNING_CONFIG_FAILED;
8555 }
8556
8557 /* skip when it's already configured */
8558 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8559 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8560 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8561 return CMD_SUCCESS;
8562
7de4c885
HS
8563 /*
8564 * mode change between sid_idx and sid_auto isn't supported.
8565 * user must negate sid vpn export when they want to change the mode
8566 */
b72c9e14
HS
8567 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8568 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8569 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8570 vty_out(vty, "it's already configured as %s.\n",
8571 sid_auto ? "auto-mode" : "idx-mode");
8572 return CMD_WARNING_CONFIG_FAILED;
8573 }
8574
8575 /* pre-change */
8576 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8577 bgp_get_default(), bgp);
8578
8579 if (sid_auto) {
8580 /* SID allocation auto-mode */
8581 if (debug)
8582 zlog_debug("%s: auto sid alloc.", __func__);
8583 SET_FLAG(bgp->vpn_policy[afi].flags,
8584 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8585 } else {
8586 /* SID allocation index-mode */
8587 if (debug)
8588 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8589 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8590 }
8591
8592 /* post-change */
8593 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8594 bgp_get_default(), bgp);
8595 return CMD_SUCCESS;
8596}
8597
b9c7bc5a
PZ
8598ALIAS (af_label_vpn_export,
8599 af_no_label_vpn_export_cmd,
8600 "no label vpn export",
8601 NO_STR
8602 "label value for VRF\n"
8603 "Between current address-family and vpn\n"
8604 "For routes leaked from current address-family to vpn\n")
ddb5b488 8605
585f1adc 8606DEFPY (af_nexthop_vpn_export,
b9c7bc5a 8607 af_nexthop_vpn_export_cmd,
8c85ca28 8608 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 8609 NO_STR
ddb5b488 8610 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
8611 "Between current address-family and vpn\n"
8612 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8613 "IPv4 prefix\n"
8614 "IPv6 prefix\n")
8615{
585f1adc 8616 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 8617 afi_t afi;
ddb5b488
PZ
8618 struct prefix p;
8619
8c85ca28
QY
8620 if (!no) {
8621 if (!nexthop_su) {
8622 vty_out(vty, "%% Nexthop required\n");
8623 return CMD_WARNING_CONFIG_FAILED;
8624 }
8c85ca28 8625 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
8626 return CMD_WARNING_CONFIG_FAILED;
8627 }
ddb5b488 8628
585f1adc
IR
8629 afi = vpn_policy_getafi(vty, bgp, false);
8630 if (afi == AFI_MAX)
8631 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8632
585f1adc
IR
8633 /*
8634 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8635 */
8636 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8637 bgp_get_default(), bgp);
ddb5b488 8638
585f1adc
IR
8639 if (!no) {
8640 bgp->vpn_policy[afi].tovpn_nexthop = p;
8641 SET_FLAG(bgp->vpn_policy[afi].flags,
8642 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8643 } else {
8644 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8645 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8646 }
69b07479 8647
585f1adc
IR
8648 /* post-change: re-export vpn routes */
8649 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8650 bgp_get_default(), bgp);
37a87b8f 8651
585f1adc 8652 return CMD_SUCCESS;
ddb5b488
PZ
8653}
8654
b9c7bc5a 8655static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 8656{
b9c7bc5a
PZ
8657 if (!strcmp(dstr, "import")) {
8658 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8659 } else if (!strcmp(dstr, "export")) {
8660 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8661 } else if (!strcmp(dstr, "both")) {
8662 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8663 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8664 } else {
8665 vty_out(vty, "%% direction parse error\n");
8666 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8667 }
ddb5b488
PZ
8668 return CMD_SUCCESS;
8669}
8670
b9c7bc5a
PZ
8671DEFPY (af_rt_vpn_imexport,
8672 af_rt_vpn_imexport_cmd,
8673 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8674 NO_STR
8675 "Specify route target list\n"
ddb5b488 8676 "Specify route target list\n"
b9c7bc5a
PZ
8677 "Between current address-family and vpn\n"
8678 "For routes leaked from vpn to current address-family: match any\n"
8679 "For routes leaked from current address-family to vpn: set\n"
8680 "both import: match any and export: set\n"
ddb5b488
PZ
8681 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8682{
8683 VTY_DECLVAR_CONTEXT(bgp, bgp);
8684 int ret;
8685 struct ecommunity *ecom = NULL;
8686 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
8687 vpn_policy_direction_t dir;
8688 afi_t afi;
8689 int idx = 0;
c6423c31 8690 bool yes = true;
ddb5b488 8691
b9c7bc5a 8692 if (argv_find(argv, argc, "no", &idx))
c6423c31 8693 yes = false;
b9c7bc5a 8694
0ca70ba5 8695 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8696 if (afi == AFI_MAX)
8697 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8698
b9c7bc5a 8699 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
8700 if (ret != CMD_SUCCESS)
8701 return ret;
8702
b9c7bc5a
PZ
8703 if (yes) {
8704 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8705 vty_out(vty, "%% Missing RTLIST\n");
8706 return CMD_WARNING_CONFIG_FAILED;
8707 }
c6423c31 8708 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
8709 if (ret != CMD_SUCCESS) {
8710 return ret;
8711 }
ddb5b488
PZ
8712 }
8713
69b07479
DS
8714 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8715 if (!dodir[dir])
ddb5b488 8716 continue;
ddb5b488 8717
69b07479 8718 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8719
69b07479
DS
8720 if (yes) {
8721 if (bgp->vpn_policy[afi].rtlist[dir])
8722 ecommunity_free(
8723 &bgp->vpn_policy[afi].rtlist[dir]);
8724 bgp->vpn_policy[afi].rtlist[dir] =
8725 ecommunity_dup(ecom);
8726 } else {
8727 if (bgp->vpn_policy[afi].rtlist[dir])
8728 ecommunity_free(
8729 &bgp->vpn_policy[afi].rtlist[dir]);
8730 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 8731 }
69b07479
DS
8732
8733 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8734 }
69b07479 8735
d555f3e9
PZ
8736 if (ecom)
8737 ecommunity_free(&ecom);
ddb5b488
PZ
8738
8739 return CMD_SUCCESS;
8740}
8741
b9c7bc5a
PZ
8742ALIAS (af_rt_vpn_imexport,
8743 af_no_rt_vpn_imexport_cmd,
8744 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
8745 NO_STR
8746 "Specify route target list\n"
b9c7bc5a
PZ
8747 "Specify route target list\n"
8748 "Between current address-family and vpn\n"
8749 "For routes leaked from vpn to current address-family\n"
8750 "For routes leaked from current address-family to vpn\n"
8751 "both import and export\n")
8752
585f1adc 8753DEFPY (af_route_map_vpn_imexport,
b9c7bc5a
PZ
8754 af_route_map_vpn_imexport_cmd,
8755/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8756 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8757 NO_STR
ddb5b488 8758 "Specify route map\n"
b9c7bc5a
PZ
8759 "Between current address-family and vpn\n"
8760 "For routes leaked from vpn to current address-family\n"
8761 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8762 "name of route-map\n")
8763{
585f1adc
IR
8764 VTY_DECLVAR_CONTEXT(bgp, bgp);
8765 int ret;
8766 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8767 vpn_policy_direction_t dir;
ddb5b488 8768 afi_t afi;
ddb5b488 8769 int idx = 0;
585f1adc 8770 bool yes = true;
ddb5b488 8771
585f1adc
IR
8772 if (argv_find(argv, argc, "no", &idx))
8773 yes = false;
ddb5b488 8774
585f1adc
IR
8775 afi = vpn_policy_getafi(vty, bgp, false);
8776 if (afi == AFI_MAX)
8777 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8778
585f1adc
IR
8779 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8780 if (ret != CMD_SUCCESS)
8781 return ret;
ddb5b488 8782
585f1adc
IR
8783 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8784 if (!dodir[dir])
8785 continue;
69b07479 8786
585f1adc
IR
8787 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8788
8789 if (yes) {
8790 if (bgp->vpn_policy[afi].rmap_name[dir])
8791 XFREE(MTYPE_ROUTE_MAP_NAME,
8792 bgp->vpn_policy[afi].rmap_name[dir]);
8793 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
8794 MTYPE_ROUTE_MAP_NAME, rmap_str);
8795 bgp->vpn_policy[afi].rmap[dir] =
8796 route_map_lookup_warn_noexist(vty, rmap_str);
8797 if (!bgp->vpn_policy[afi].rmap[dir])
8798 return CMD_SUCCESS;
8799 } else {
8800 if (bgp->vpn_policy[afi].rmap_name[dir])
8801 XFREE(MTYPE_ROUTE_MAP_NAME,
8802 bgp->vpn_policy[afi].rmap_name[dir]);
8803 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8804 bgp->vpn_policy[afi].rmap[dir] = NULL;
8805 }
8806
8807 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8808 }
ddb5b488 8809
585f1adc 8810 return CMD_SUCCESS;
ddb5b488
PZ
8811}
8812
b9c7bc5a
PZ
8813ALIAS (af_route_map_vpn_imexport,
8814 af_no_route_map_vpn_imexport_cmd,
8815 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
8816 NO_STR
8817 "Specify route map\n"
b9c7bc5a
PZ
8818 "Between current address-family and vpn\n"
8819 "For routes leaked from vpn to current address-family\n"
8820 "For routes leaked from current address-family to vpn\n")
8821
bb4f6190 8822DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 8823 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
8824 "Import routes from another VRF\n"
8825 "Vrf routes being filtered\n"
8826 "Specify route map\n"
8827 "name of route-map\n")
8828{
8829 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
8830 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8831 afi_t afi;
bb4f6190
DS
8832 struct bgp *bgp_default;
8833
0ca70ba5 8834 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
8835 if (afi == AFI_MAX)
8836 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
8837
8838 bgp_default = bgp_get_default();
8839 if (!bgp_default) {
8840 int32_t ret;
8841 as_t as = bgp->as;
8842
8843 /* Auto-create assuming the same AS */
5d5393b9
DL
8844 ret = bgp_get_vty(&bgp_default, &as, NULL,
8845 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
8846
8847 if (ret) {
8848 vty_out(vty,
8849 "VRF default is not configured as a bgp instance\n");
8850 return CMD_WARNING;
8851 }
8852 }
8853
69b07479 8854 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 8855
ae6a6fb4
DS
8856 if (bgp->vpn_policy[afi].rmap_name[dir])
8857 XFREE(MTYPE_ROUTE_MAP_NAME,
8858 bgp->vpn_policy[afi].rmap_name[dir]);
8859 bgp->vpn_policy[afi].rmap_name[dir] =
8860 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8861 bgp->vpn_policy[afi].rmap[dir] =
8862 route_map_lookup_warn_noexist(vty, rmap_str);
8863 if (!bgp->vpn_policy[afi].rmap[dir])
8864 return CMD_SUCCESS;
8865
8866 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8867 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 8868
69b07479
DS
8869 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8870
bb4f6190
DS
8871 return CMD_SUCCESS;
8872}
8873
ae6a6fb4
DS
8874DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
8875 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
8876 NO_STR
8877 "Import routes from another VRF\n"
8878 "Vrf routes being filtered\n"
ae6a6fb4
DS
8879 "Specify route map\n"
8880 "name of route-map\n")
8881{
8882 VTY_DECLVAR_CONTEXT(bgp, bgp);
8883 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8884 afi_t afi;
8885
8886 afi = vpn_policy_getafi(vty, bgp, true);
8887 if (afi == AFI_MAX)
8888 return CMD_WARNING_CONFIG_FAILED;
8889
8890 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8891
8892 if (bgp->vpn_policy[afi].rmap_name[dir])
8893 XFREE(MTYPE_ROUTE_MAP_NAME,
8894 bgp->vpn_policy[afi].rmap_name[dir]);
8895 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8896 bgp->vpn_policy[afi].rmap[dir] = NULL;
8897
8898 if (bgp->vpn_policy[afi].import_vrf->count == 0)
8899 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8900 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8901
8902 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8903
8904 return CMD_SUCCESS;
8905}
bb4f6190 8906
585f1adc
IR
8907DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
8908 "[no] import vrf VIEWVRFNAME$import_name",
8909 NO_STR
8910 "Import routes from another VRF\n"
8911 "VRF to import from\n"
8912 "The name of the VRF\n")
12a844a5 8913{
585f1adc
IR
8914 VTY_DECLVAR_CONTEXT(bgp, bgp);
8915 struct listnode *node;
8916 struct bgp *vrf_bgp, *bgp_default;
8917 int32_t ret = 0;
8918 as_t as = bgp->as;
8919 bool remove = false;
8920 int32_t idx = 0;
8921 char *vname;
8922 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
8923 safi_t safi;
8924 afi_t afi;
8925
867f0cca 8926 if (import_name == NULL) {
8927 vty_out(vty, "%% Missing import name\n");
8928 return CMD_WARNING;
8929 }
8930
ae6a6fb4
DS
8931 if (strcmp(import_name, "route-map") == 0) {
8932 vty_out(vty, "%% Must include route-map name\n");
8933 return CMD_WARNING;
8934 }
8935
585f1adc
IR
8936 if (argv_find(argv, argc, "no", &idx))
8937 remove = true;
8938
8939 afi = vpn_policy_getafi(vty, bgp, true);
8940 if (afi == AFI_MAX)
8941 return CMD_WARNING_CONFIG_FAILED;
8942
12a844a5
DS
8943 safi = bgp_node_safi(vty);
8944
585f1adc
IR
8945 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
8946 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
8947 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
8948 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
8949 remove ? "unimport" : "import", import_name);
8950 return CMD_WARNING;
8951 }
25679caa 8952
585f1adc
IR
8953 bgp_default = bgp_get_default();
8954 if (!bgp_default) {
8955 /* Auto-create assuming the same AS */
8956 ret = bgp_get_vty(&bgp_default, &as, NULL,
8957 BGP_INSTANCE_TYPE_DEFAULT);
12a844a5 8958
585f1adc
IR
8959 if (ret) {
8960 vty_out(vty,
8961 "VRF default is not configured as a bgp instance\n");
8962 return CMD_WARNING;
8963 }
8964 }
12a844a5 8965
585f1adc
IR
8966 vrf_bgp = bgp_lookup_by_name(import_name);
8967 if (!vrf_bgp) {
8968 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
8969 vrf_bgp = bgp_default;
8970 else
8971 /* Auto-create assuming the same AS */
8972 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
8973
8974 if (ret) {
8975 vty_out(vty,
8976 "VRF %s is not configured as a bgp instance\n",
8977 import_name);
8978 return CMD_WARNING;
8979 }
8980 }
8981
8982 if (remove) {
8983 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
8984 } else {
8985 /* Already importing from "import_vrf"? */
8986 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
8987 vname)) {
8988 if (strcmp(vname, import_name) == 0)
8989 return CMD_WARNING;
8990 }
8991
8992 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
8993 }
8994
8995 return CMD_SUCCESS;
12a844a5
DS
8996}
8997
b9c7bc5a 8998/* This command is valid only in a bgp vrf instance or the default instance */
585f1adc 8999DEFPY (bgp_imexport_vpn,
b9c7bc5a
PZ
9000 bgp_imexport_vpn_cmd,
9001 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9002 NO_STR
9003 "Import routes to this address-family\n"
9004 "Export routes from this address-family\n"
9005 "to/from default instance VPN RIB\n")
ddb5b488 9006{
585f1adc
IR
9007 VTY_DECLVAR_CONTEXT(bgp, bgp);
9008 int previous_state;
37a87b8f 9009 afi_t afi;
585f1adc
IR
9010 safi_t safi;
9011 int idx = 0;
9012 bool yes = true;
9013 int flag;
9014 vpn_policy_direction_t dir;
9015
9016 if (argv_find(argv, argc, "no", &idx))
9017 yes = false;
9018
9019 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9020 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9021
9022 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9023 return CMD_WARNING_CONFIG_FAILED;
9024 }
ddb5b488 9025
b9c7bc5a
PZ
9026 afi = bgp_node_afi(vty);
9027 safi = bgp_node_safi(vty);
585f1adc
IR
9028 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9029 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9030 return CMD_WARNING_CONFIG_FAILED;
9031 }
ddb5b488 9032
b9c7bc5a 9033 if (!strcmp(direction_str, "import")) {
585f1adc
IR
9034 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9035 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b9c7bc5a 9036 } else if (!strcmp(direction_str, "export")) {
585f1adc
IR
9037 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9038 dir = BGP_VPN_POLICY_DIR_TOVPN;
b9c7bc5a
PZ
9039 } else {
9040 vty_out(vty, "%% unknown direction %s\n", direction_str);
9041 return CMD_WARNING_CONFIG_FAILED;
9042 }
9043
585f1adc 9044 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 9045
585f1adc
IR
9046 if (yes) {
9047 SET_FLAG(bgp->af_flags[afi][safi], flag);
9048 if (!previous_state) {
9049 /* trigger export current vrf */
9050 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9051 }
9052 } else {
9053 if (previous_state) {
9054 /* trigger un-export current vrf */
9055 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9056 }
9057 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9058 }
37a87b8f 9059
1ca2fd11
IR
9060 hook_call(bgp_snmp_init_stats, bgp);
9061
585f1adc 9062 return CMD_SUCCESS;
ddb5b488
PZ
9063}
9064
301ad80a
PG
9065DEFPY (af_routetarget_import,
9066 af_routetarget_import_cmd,
9a659715 9067 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9068 NO_STR
9069 "Specify route target list\n"
9070 "Specify route target list\n"
9a659715
PG
9071 "Specify route target list\n"
9072 "Specify route target list\n"
301ad80a
PG
9073 "Flow-spec redirect type route target\n"
9074 "Import routes to this address-family\n"
9a659715 9075 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9076{
9077 VTY_DECLVAR_CONTEXT(bgp, bgp);
9078 int ret;
9079 struct ecommunity *ecom = NULL;
301ad80a 9080 afi_t afi;
9a659715 9081 int idx = 0, idx_unused = 0;
c6423c31
PG
9082 bool yes = true;
9083 bool rt6 = false;
301ad80a
PG
9084
9085 if (argv_find(argv, argc, "no", &idx))
c6423c31 9086 yes = false;
301ad80a 9087
9a659715
PG
9088 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9089 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9090 rt6 = true;
301ad80a 9091
0ca70ba5 9092 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9093 if (afi == AFI_MAX)
9094 return CMD_WARNING_CONFIG_FAILED;
9095
9a659715
PG
9096 if (rt6 && afi != AFI_IP6)
9097 return CMD_WARNING_CONFIG_FAILED;
9098
301ad80a
PG
9099 if (yes) {
9100 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9101 vty_out(vty, "%% Missing RTLIST\n");
9102 return CMD_WARNING_CONFIG_FAILED;
9103 }
9a659715 9104 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9105 if (ret != CMD_SUCCESS)
9106 return ret;
9107 }
69b07479
DS
9108
9109 if (yes) {
9110 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9111 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9112 .import_redirect_rtlist);
69b07479
DS
9113 bgp->vpn_policy[afi].import_redirect_rtlist =
9114 ecommunity_dup(ecom);
9115 } else {
9116 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9117 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9118 .import_redirect_rtlist);
69b07479 9119 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9120 }
69b07479 9121
301ad80a
PG
9122 if (ecom)
9123 ecommunity_free(&ecom);
9124
9125 return CMD_SUCCESS;
9126}
9127
505e5056 9128DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9129 address_family_ipv4_safi_cmd,
9130 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9131 "Enter Address Family command mode\n"
9132 "Address Family\n"
9133 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9134{
f51bae9c 9135
d62a17ae 9136 if (argc == 3) {
585f1adc
IR
9137 VTY_DECLVAR_CONTEXT(bgp, bgp);
9138 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9139 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9140 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9141 && safi != SAFI_EVPN) {
31947174
MK
9142 vty_out(vty,
9143 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9144 return CMD_WARNING_CONFIG_FAILED;
9145 }
585f1adc
IR
9146 vty->node = bgp_node_type(AFI_IP, safi);
9147 } else
9148 vty->node = BGP_IPV4_NODE;
718e3744 9149
d62a17ae 9150 return CMD_SUCCESS;
718e3744 9151}
9152
505e5056 9153DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9154 address_family_ipv6_safi_cmd,
9155 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9156 "Enter Address Family command mode\n"
9157 "Address Family\n"
9158 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9159{
d62a17ae 9160 if (argc == 3) {
585f1adc
IR
9161 VTY_DECLVAR_CONTEXT(bgp, bgp);
9162 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9163 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9164 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9165 && safi != SAFI_EVPN) {
31947174
MK
9166 vty_out(vty,
9167 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9168 return CMD_WARNING_CONFIG_FAILED;
9169 }
585f1adc
IR
9170 vty->node = bgp_node_type(AFI_IP6, safi);
9171 } else
9172 vty->node = BGP_IPV6_NODE;
25ffbdc1 9173
d62a17ae 9174 return CMD_SUCCESS;
25ffbdc1 9175}
718e3744 9176
d6902373 9177#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9178DEFUN_NOSH (address_family_vpnv4,
718e3744 9179 address_family_vpnv4_cmd,
8334fd5a 9180 "address-family vpnv4 [unicast]",
718e3744 9181 "Enter Address Family command mode\n"
8c3deaae 9182 "Address Family\n"
3a2d747c 9183 "Address Family modifier\n")
718e3744 9184{
d62a17ae 9185 vty->node = BGP_VPNV4_NODE;
9186 return CMD_SUCCESS;
718e3744 9187}
9188
505e5056 9189DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9190 address_family_vpnv6_cmd,
8334fd5a 9191 "address-family vpnv6 [unicast]",
8ecd3266 9192 "Enter Address Family command mode\n"
8c3deaae 9193 "Address Family\n"
3a2d747c 9194 "Address Family modifier\n")
8ecd3266 9195{
d62a17ae 9196 vty->node = BGP_VPNV6_NODE;
9197 return CMD_SUCCESS;
8ecd3266 9198}
64e4a6c5 9199#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9200
505e5056 9201DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9202 address_family_evpn_cmd,
7111c1a0 9203 "address-family l2vpn evpn",
4e0b7b6d 9204 "Enter Address Family command mode\n"
7111c1a0
QY
9205 "Address Family\n"
9206 "Address Family modifier\n")
4e0b7b6d 9207{
2131d5cf 9208 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9209 vty->node = BGP_EVPN_NODE;
9210 return CMD_SUCCESS;
4e0b7b6d
PG
9211}
9212
bfaab44d
HS
9213DEFUN_NOSH (bgp_segment_routing_srv6,
9214 bgp_segment_routing_srv6_cmd,
9215 "segment-routing srv6",
9216 "Segment-Routing configuration\n"
9217 "Segment-Routing SRv6 configuration\n")
9218{
9219 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 9220 bgp->srv6_enabled = true;
bfaab44d
HS
9221 vty->node = BGP_SRV6_NODE;
9222 return CMD_SUCCESS;
9223}
9224
0249b8b6
HS
9225DEFUN (no_bgp_segment_routing_srv6,
9226 no_bgp_segment_routing_srv6_cmd,
9227 "no segment-routing srv6",
9228 NO_STR
9229 "Segment-Routing configuration\n"
9230 "Segment-Routing SRv6 configuration\n")
9231{
9232 VTY_DECLVAR_CONTEXT(bgp, bgp);
9233
9234 if (strlen(bgp->srv6_locator_name) > 0)
9235 if (bgp_srv6_locator_unset(bgp) < 0)
9236 return CMD_WARNING_CONFIG_FAILED;
9237
9238 bgp->srv6_enabled = false;
9239 return CMD_SUCCESS;
9240}
9241
a0281b2e
HS
9242DEFPY (bgp_srv6_locator,
9243 bgp_srv6_locator_cmd,
9244 "locator NAME$name",
9245 "Specify SRv6 locator\n"
9246 "Specify SRv6 locator\n")
9247{
9248 VTY_DECLVAR_CONTEXT(bgp, bgp);
7de4c885 9249 int ret;
a0281b2e
HS
9250
9251 if (strlen(bgp->srv6_locator_name) > 0
9252 && strcmp(name, bgp->srv6_locator_name) != 0) {
9253 vty_out(vty, "srv6 locator is already configured\n");
9254 return CMD_WARNING_CONFIG_FAILED;
7de4c885
HS
9255 }
9256
9257 snprintf(bgp->srv6_locator_name,
9258 sizeof(bgp->srv6_locator_name), "%s", name);
a0281b2e 9259
7de4c885 9260 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
a0281b2e
HS
9261 if (ret < 0)
9262 return CMD_WARNING_CONFIG_FAILED;
9263
9264 return CMD_SUCCESS;
9265}
9266
0249b8b6
HS
9267DEFPY (no_bgp_srv6_locator,
9268 no_bgp_srv6_locator_cmd,
9269 "no locator NAME$name",
9270 NO_STR
9271 "Specify SRv6 locator\n"
9272 "Specify SRv6 locator\n")
9273{
9274 VTY_DECLVAR_CONTEXT(bgp, bgp);
9275
9276 /* when locator isn't configured, do nothing */
9277 if (strlen(bgp->srv6_locator_name) < 1)
9278 return CMD_SUCCESS;
9279
9280 /* name validation */
9281 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9282 vty_out(vty, "%% No srv6 locator is configured\n");
9283 return CMD_WARNING_CONFIG_FAILED;
9284 }
9285
9286 /* unset locator */
9287 if (bgp_srv6_locator_unset(bgp) < 0)
9288 return CMD_WARNING_CONFIG_FAILED;
9289
9290 return CMD_SUCCESS;
9291}
9292
ea372e81
HS
9293DEFPY (show_bgp_srv6,
9294 show_bgp_srv6_cmd,
9295 "show bgp segment-routing srv6",
9296 SHOW_STR
9297 BGP_STR
9298 "BGP Segment Routing\n"
9299 "BGP Segment Routing SRv6\n")
9300{
9301 struct bgp *bgp;
9302 struct listnode *node;
9303 struct prefix_ipv6 *chunk;
9304 struct bgp_srv6_function *func;
9305 struct in6_addr *tovpn4_sid;
9306 struct in6_addr *tovpn6_sid;
9307 char buf[256];
9308 char buf_tovpn4_sid[256];
9309 char buf_tovpn6_sid[256];
9310
9311 bgp = bgp_get_default();
96db4340 9312 if (!bgp)
ea372e81
HS
9313 return CMD_SUCCESS;
9314
9315 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9316 vty_out(vty, "locator_chunks:\n");
9317 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9318 prefix2str(chunk, buf, sizeof(buf));
9319 vty_out(vty, "- %s\n", buf);
9320 }
9321
9322 vty_out(vty, "functions:\n");
9323 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9324 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9325 vty_out(vty, "- sid: %s\n", buf);
9326 vty_out(vty, " locator: %s\n", func->locator_name);
9327 }
9328
9329 vty_out(vty, "bgps:\n");
9330 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9331 vty_out(vty, "- name: %s\n",
9332 bgp->name ? bgp->name : "default");
9333
9334 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9335 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9336 if (tovpn4_sid)
9337 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9338 sizeof(buf_tovpn4_sid));
9339 if (tovpn6_sid)
9340 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9341 sizeof(buf_tovpn6_sid));
9342
9343 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9344 tovpn4_sid ? buf_tovpn4_sid : "none");
9345 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9346 tovpn6_sid ? buf_tovpn6_sid : "none");
9347 }
9348
9349 return CMD_SUCCESS;
9350}
9351
505e5056 9352DEFUN_NOSH (exit_address_family,
718e3744 9353 exit_address_family_cmd,
9354 "exit-address-family",
9355 "Exit from Address Family configuration mode\n")
9356{
d62a17ae 9357 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9358 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9359 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9360 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9361 || vty->node == BGP_EVPN_NODE
9362 || vty->node == BGP_FLOWSPECV4_NODE
9363 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9364 vty->node = BGP_NODE;
9365 return CMD_SUCCESS;
718e3744 9366}
6b0655a2 9367
8ad7271d 9368/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9369static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9370 const char *ip_str, afi_t afi, safi_t safi,
9371 struct prefix_rd *prd)
9372{
9373 int ret;
9374 struct prefix match;
9bcb3eef
DS
9375 struct bgp_dest *dest;
9376 struct bgp_dest *rm;
d62a17ae 9377 struct bgp *bgp;
9378 struct bgp_table *table;
9379 struct bgp_table *rib;
9380
9381 /* BGP structure lookup. */
9382 if (view_name) {
9383 bgp = bgp_lookup_by_name(view_name);
9384 if (bgp == NULL) {
9385 vty_out(vty, "%% Can't find BGP instance %s\n",
9386 view_name);
9387 return CMD_WARNING;
9388 }
9389 } else {
9390 bgp = bgp_get_default();
9391 if (bgp == NULL) {
9392 vty_out(vty, "%% No BGP process is configured\n");
9393 return CMD_WARNING;
9394 }
9395 }
9396
9397 /* Check IP address argument. */
9398 ret = str2prefix(ip_str, &match);
9399 if (!ret) {
9400 vty_out(vty, "%% address is malformed\n");
9401 return CMD_WARNING;
9402 }
9403
9404 match.family = afi2family(afi);
9405 rib = bgp->rib[afi][safi];
9406
9407 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9408 for (dest = bgp_table_top(rib); dest;
9409 dest = bgp_route_next(dest)) {
9410 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9411
9bcb3eef 9412 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9413 continue;
9414
9bcb3eef 9415 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9416 if (table == NULL)
9417 continue;
9418
4953391b
DA
9419 rm = bgp_node_match(table, &match);
9420 if (rm != NULL) {
b54892e0 9421 const struct prefix *rm_p =
9bcb3eef 9422 bgp_dest_get_prefix(rm);
b54892e0
DS
9423
9424 if (rm_p->prefixlen == match.prefixlen) {
9425 SET_FLAG(rm->flags,
9426 BGP_NODE_USER_CLEAR);
9427 bgp_process(bgp, rm, afi, safi);
d62a17ae 9428 }
9bcb3eef 9429 bgp_dest_unlock_node(rm);
d62a17ae 9430 }
9431 }
9432 } else {
4953391b
DA
9433 dest = bgp_node_match(rib, &match);
9434 if (dest != NULL) {
9bcb3eef 9435 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9436
9bcb3eef
DS
9437 if (dest_p->prefixlen == match.prefixlen) {
9438 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9439 bgp_process(bgp, dest, afi, safi);
d62a17ae 9440 }
9bcb3eef 9441 bgp_dest_unlock_node(dest);
d62a17ae 9442 }
9443 }
9444
9445 return CMD_SUCCESS;
8ad7271d
DS
9446}
9447
b09b5ae0 9448/* one clear bgp command to rule them all */
718e3744 9449DEFUN (clear_ip_bgp_all,
9450 clear_ip_bgp_all_cmd,
3cb14f26 9451 "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|message-stats>]",
718e3744 9452 CLEAR_STR
9453 IP_STR
9454 BGP_STR
838758ac 9455 BGP_INSTANCE_HELP_STR
510afcd6 9456 BGP_AFI_HELP_STR
fd5e7b70 9457 "Address Family\n"
510afcd6 9458 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 9459 "Address Family modifier\n"
b09b5ae0 9460 "Clear all peers\n"
453c92f6 9461 "BGP IPv4 neighbor to clear\n"
a80beece 9462 "BGP IPv6 neighbor to clear\n"
838758ac 9463 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9464 "Clear peers with the AS number\n"
9465 "Clear all external peers\n"
718e3744 9466 "Clear all members of peer-group\n"
b09b5ae0 9467 "BGP peer-group name\n"
b09b5ae0
DW
9468 BGP_SOFT_STR
9469 BGP_SOFT_IN_STR
b09b5ae0
DW
9470 BGP_SOFT_OUT_STR
9471 BGP_SOFT_IN_STR
9472 "Push out prefix-list ORF and do inbound soft reconfig\n"
3cb14f26
DS
9473 BGP_SOFT_OUT_STR
9474 "Reset message statistics\n")
718e3744 9475{
d62a17ae 9476 char *vrf = NULL;
9477
dc912615
DS
9478 afi_t afi = AFI_UNSPEC;
9479 safi_t safi = SAFI_UNSPEC;
d62a17ae 9480 enum clear_sort clr_sort = clear_peer;
9481 enum bgp_clear_type clr_type;
9482 char *clr_arg = NULL;
9483
9484 int idx = 0;
9485
9486 /* clear [ip] bgp */
9487 if (argv_find(argv, argc, "ip", &idx))
9488 afi = AFI_IP;
9489
9a8bdf1c
PG
9490 /* [<vrf> VIEWVRFNAME] */
9491 if (argv_find(argv, argc, "vrf", &idx)) {
9492 vrf = argv[idx + 1]->arg;
9493 idx += 2;
9494 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9495 vrf = NULL;
9496 } else if (argv_find(argv, argc, "view", &idx)) {
9497 /* [<view> VIEWVRFNAME] */
d62a17ae 9498 vrf = argv[idx + 1]->arg;
9499 idx += 2;
9500 }
d62a17ae 9501 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9502 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9503 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9504
d7b9898c 9505 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 9506 if (argv_find(argv, argc, "*", &idx)) {
9507 clr_sort = clear_all;
9508 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9509 clr_sort = clear_peer;
9510 clr_arg = argv[idx]->arg;
9511 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9512 clr_sort = clear_peer;
9513 clr_arg = argv[idx]->arg;
9514 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9515 clr_sort = clear_group;
9516 idx++;
9517 clr_arg = argv[idx]->arg;
d7b9898c 9518 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 9519 clr_sort = clear_peer;
9520 clr_arg = argv[idx]->arg;
8fa7d444
DS
9521 } else if (argv_find(argv, argc, "WORD", &idx)) {
9522 clr_sort = clear_peer;
9523 clr_arg = argv[idx]->arg;
d62a17ae 9524 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9525 clr_sort = clear_as;
9526 clr_arg = argv[idx]->arg;
9527 } else if (argv_find(argv, argc, "external", &idx)) {
9528 clr_sort = clear_external;
9529 }
9530
3cb14f26 9531 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
d62a17ae 9532 if (argv_find(argv, argc, "soft", &idx)) {
9533 if (argv_find(argv, argc, "in", &idx)
9534 || argv_find(argv, argc, "out", &idx))
9535 clr_type = strmatch(argv[idx]->text, "in")
9536 ? BGP_CLEAR_SOFT_IN
9537 : BGP_CLEAR_SOFT_OUT;
9538 else
9539 clr_type = BGP_CLEAR_SOFT_BOTH;
9540 } else if (argv_find(argv, argc, "in", &idx)) {
9541 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9542 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9543 : BGP_CLEAR_SOFT_IN;
9544 } else if (argv_find(argv, argc, "out", &idx)) {
9545 clr_type = BGP_CLEAR_SOFT_OUT;
3cb14f26
DS
9546 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9547 clr_type = BGP_CLEAR_MESSAGE_STATS;
d62a17ae 9548 } else
9549 clr_type = BGP_CLEAR_SOFT_NONE;
9550
1ca2fd11 9551 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 9552}
01080f7c 9553
8ad7271d
DS
9554DEFUN (clear_ip_bgp_prefix,
9555 clear_ip_bgp_prefix_cmd,
18c57037 9556 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
9557 CLEAR_STR
9558 IP_STR
9559 BGP_STR
838758ac 9560 BGP_INSTANCE_HELP_STR
8ad7271d 9561 "Clear bestpath and re-advertise\n"
0c7b1b01 9562 "IPv4 prefix\n")
8ad7271d 9563{
d62a17ae 9564 char *vrf = NULL;
9565 char *prefix = NULL;
8ad7271d 9566
d62a17ae 9567 int idx = 0;
01080f7c 9568
d62a17ae 9569 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
9570 if (argv_find(argv, argc, "vrf", &idx)) {
9571 vrf = argv[idx + 1]->arg;
9572 idx += 2;
9573 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9574 vrf = NULL;
9575 } else if (argv_find(argv, argc, "view", &idx)) {
9576 /* [<view> VIEWVRFNAME] */
9577 vrf = argv[idx + 1]->arg;
9578 idx += 2;
9579 }
0c7b1b01 9580
d62a17ae 9581 prefix = argv[argc - 1]->arg;
8ad7271d 9582
d62a17ae 9583 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 9584}
8ad7271d 9585
b09b5ae0
DW
9586DEFUN (clear_bgp_ipv6_safi_prefix,
9587 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 9588 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9589 CLEAR_STR
3a2d747c 9590 IP_STR
718e3744 9591 BGP_STR
8c3deaae 9592 "Address Family\n"
46f296b4 9593 BGP_SAFI_HELP_STR
b09b5ae0 9594 "Clear bestpath and re-advertise\n"
0c7b1b01 9595 "IPv6 prefix\n")
718e3744 9596{
9b475e76
PG
9597 int idx_safi = 0;
9598 int idx_ipv6_prefix = 0;
9599 safi_t safi = SAFI_UNICAST;
9600 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9601 argv[idx_ipv6_prefix]->arg : NULL;
9602
9603 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 9604 return bgp_clear_prefix(
9b475e76
PG
9605 vty, NULL, prefix, AFI_IP6,
9606 safi, NULL);
838758ac 9607}
01080f7c 9608
b09b5ae0
DW
9609DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9610 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 9611 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9612 CLEAR_STR
3a2d747c 9613 IP_STR
718e3744 9614 BGP_STR
838758ac 9615 BGP_INSTANCE_HELP_STR
8c3deaae 9616 "Address Family\n"
46f296b4 9617 BGP_SAFI_HELP_STR
b09b5ae0 9618 "Clear bestpath and re-advertise\n"
0c7b1b01 9619 "IPv6 prefix\n")
718e3744 9620{
9b475e76 9621 int idx_safi = 0;
9a8bdf1c 9622 int idx_vrfview = 0;
9b475e76
PG
9623 int idx_ipv6_prefix = 0;
9624 safi_t safi = SAFI_UNICAST;
9625 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9626 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 9627 char *vrfview = NULL;
9b475e76 9628
9a8bdf1c
PG
9629 /* [<view|vrf> VIEWVRFNAME] */
9630 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9631 vrfview = argv[idx_vrfview + 1]->arg;
9632 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9633 vrfview = NULL;
9634 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9635 /* [<view> VIEWVRFNAME] */
9636 vrfview = argv[idx_vrfview + 1]->arg;
9637 }
9b475e76
PG
9638 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9639
d62a17ae 9640 return bgp_clear_prefix(
9b475e76
PG
9641 vty, vrfview, prefix,
9642 AFI_IP6, safi, NULL);
718e3744 9643}
9644
b09b5ae0
DW
9645DEFUN (show_bgp_views,
9646 show_bgp_views_cmd,
d6e3c605 9647 "show [ip] bgp views",
b09b5ae0 9648 SHOW_STR
d6e3c605 9649 IP_STR
01080f7c 9650 BGP_STR
b09b5ae0 9651 "Show the defined BGP views\n")
01080f7c 9652{
d62a17ae 9653 struct list *inst = bm->bgp;
9654 struct listnode *node;
9655 struct bgp *bgp;
01080f7c 9656
d62a17ae 9657 vty_out(vty, "Defined BGP views:\n");
9658 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9659 /* Skip VRFs. */
9660 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9661 continue;
9662 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9663 bgp->as);
9664 }
e52702f2 9665
d62a17ae 9666 return CMD_SUCCESS;
e0081f70
ML
9667}
9668
8386ac43 9669DEFUN (show_bgp_vrfs,
9670 show_bgp_vrfs_cmd,
d6e3c605 9671 "show [ip] bgp vrfs [json]",
8386ac43 9672 SHOW_STR
d6e3c605 9673 IP_STR
8386ac43 9674 BGP_STR
9675 "Show BGP VRFs\n"
9973d184 9676 JSON_STR)
8386ac43 9677{
fe1dc5a3 9678 char buf[ETHER_ADDR_STRLEN];
d62a17ae 9679 struct list *inst = bm->bgp;
9680 struct listnode *node;
9681 struct bgp *bgp;
9f049418 9682 bool uj = use_json(argc, argv);
d62a17ae 9683 json_object *json = NULL;
9684 json_object *json_vrfs = NULL;
9685 int count = 0;
d62a17ae 9686
d62a17ae 9687 if (uj) {
9688 json = json_object_new_object();
9689 json_vrfs = json_object_new_object();
9690 }
9691
9692 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9693 const char *name, *type;
9694 struct peer *peer;
7fe96307 9695 struct listnode *node2, *nnode2;
d62a17ae 9696 int peers_cfg, peers_estb;
9697 json_object *json_vrf = NULL;
d62a17ae 9698
9699 /* Skip Views. */
9700 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9701 continue;
9702
9703 count++;
efb4077a 9704 if (!uj && count == 1) {
fe1dc5a3 9705 vty_out(vty,
efb4077a 9706 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 9707 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
9708 "#PeersEstb", "Name");
9709 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9710 "L3-VNI", "RouterMAC", "Interface");
9711 }
d62a17ae 9712
9713 peers_cfg = peers_estb = 0;
9714 if (uj)
9715 json_vrf = json_object_new_object();
9716
9717
7fe96307 9718 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 9719 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9720 continue;
9721 peers_cfg++;
feb17238 9722 if (peer_established(peer))
d62a17ae 9723 peers_estb++;
9724 }
9725
9726 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 9727 name = VRF_DEFAULT_NAME;
d62a17ae 9728 type = "DFLT";
9729 } else {
9730 name = bgp->name;
9731 type = "VRF";
9732 }
9733
a8bf7d9c 9734
d62a17ae 9735 if (uj) {
a4d82a8a
PZ
9736 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9737 ? -1
9738 : (int64_t)bgp->vrf_id;
23d0a753
DA
9739 char buf[BUFSIZ] = {0};
9740
d62a17ae 9741 json_object_string_add(json_vrf, "type", type);
9742 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
c949c771
DA
9743 json_object_string_addf(json_vrf, "routerId", "%pI4",
9744 &bgp->router_id);
d62a17ae 9745 json_object_int_add(json_vrf, "numConfiguredPeers",
9746 peers_cfg);
9747 json_object_int_add(json_vrf, "numEstablishedPeers",
9748 peers_estb);
9749
fe1dc5a3 9750 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
9751 json_object_string_add(
9752 json_vrf, "rmac",
9753 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
9754 json_object_string_add(json_vrf, "interface",
9755 ifindex2ifname(bgp->l3vni_svi_ifindex,
9756 bgp->vrf_id));
d62a17ae 9757 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 9758 } else {
23d0a753 9759 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
9760 type,
9761 bgp->vrf_id == VRF_UNKNOWN ? -1
9762 : (int)bgp->vrf_id,
23d0a753 9763 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
9764 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
9765 bgp->l3vni,
9766 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
9767 ifindex2ifname(bgp->l3vni_svi_ifindex,
9768 bgp->vrf_id));
9769 }
d62a17ae 9770 }
9771
9772 if (uj) {
9773 json_object_object_add(json, "vrfs", json_vrfs);
9774
9775 json_object_int_add(json, "totalVrfs", count);
9776
75eeda93 9777 vty_json(vty, json);
d62a17ae 9778 } else {
9779 if (count)
9780 vty_out(vty,
9781 "\nTotal number of VRFs (including default): %d\n",
9782 count);
9783 }
9784
9785 return CMD_SUCCESS;
8386ac43 9786}
9787
48ecf8f5
DS
9788DEFUN (show_bgp_mac_hash,
9789 show_bgp_mac_hash_cmd,
9790 "show bgp mac hash",
9791 SHOW_STR
9792 BGP_STR
9793 "Mac Address\n"
9794 "Mac Address database\n")
9795{
9796 bgp_mac_dump_table(vty);
9797
9798 return CMD_SUCCESS;
9799}
acf71666 9800
e3b78da8 9801static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 9802{
0291c246 9803 struct vty *vty = (struct vty *)args;
e3b78da8 9804 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 9805
23d0a753 9806 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
9807}
9808
9809static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
9810{
9811 vty_out(vty, "self nexthop database:\n");
af97a18b 9812 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
9813
9814 vty_out(vty, "Tunnel-ip database:\n");
9815 hash_iterate(bgp->tip_hash,
e3b78da8 9816 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
9817 vty);
9818}
9819
15c81ca4
DS
9820DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
9821 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
9822 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
9823 "martian next-hops\n"
9824 "martian next-hop database\n")
acf71666 9825{
0291c246 9826 struct bgp *bgp = NULL;
15c81ca4 9827 int idx = 0;
9a8bdf1c
PG
9828 char *name = NULL;
9829
9830 /* [<vrf> VIEWVRFNAME] */
9831 if (argv_find(argv, argc, "vrf", &idx)) {
9832 name = argv[idx + 1]->arg;
9833 if (name && strmatch(name, VRF_DEFAULT_NAME))
9834 name = NULL;
9835 } else if (argv_find(argv, argc, "view", &idx))
9836 /* [<view> VIEWVRFNAME] */
9837 name = argv[idx + 1]->arg;
9838 if (name)
9839 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
9840 else
9841 bgp = bgp_get_default();
acf71666 9842
acf71666
MK
9843 if (!bgp) {
9844 vty_out(vty, "%% No BGP process is configured\n");
9845 return CMD_WARNING;
9846 }
9847 bgp_show_martian_nexthops(vty, bgp);
9848
9849 return CMD_SUCCESS;
9850}
9851
f412b39a 9852DEFUN (show_bgp_memory,
4bf6a362 9853 show_bgp_memory_cmd,
7fa12b13 9854 "show [ip] bgp memory",
4bf6a362 9855 SHOW_STR
3a2d747c 9856 IP_STR
4bf6a362
PJ
9857 BGP_STR
9858 "Global BGP memory statistics\n")
9859{
d62a17ae 9860 char memstrbuf[MTYPE_MEMSTR_LEN];
9861 unsigned long count;
9862
9863 /* RIB related usage stats */
9864 count = mtype_stats_alloc(MTYPE_BGP_NODE);
9865 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
9866 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 9867 count * sizeof(struct bgp_dest)));
d62a17ae 9868
9869 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
9870 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
9871 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 9872 count * sizeof(struct bgp_path_info)));
d62a17ae 9873 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
9874 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
9875 count,
4b7e6066
DS
9876 mtype_memstr(
9877 memstrbuf, sizeof(memstrbuf),
9878 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 9879
9880 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
9881 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
9882 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9883 count * sizeof(struct bgp_static)));
9884
9885 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
9886 vty_out(vty, "%ld Packets, using %s of memory\n", count,
9887 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9888 count * sizeof(struct bpacket)));
9889
9890 /* Adj-In/Out */
9891 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
9892 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
9893 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9894 count * sizeof(struct bgp_adj_in)));
9895 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
9896 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
9897 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9898 count * sizeof(struct bgp_adj_out)));
9899
9900 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
9901 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
9902 count,
9903 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9904 count * sizeof(struct bgp_nexthop_cache)));
9905
9906 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
9907 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
9908 count,
9909 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9910 count * sizeof(struct bgp_damp_info)));
9911
9912 /* Attributes */
9913 count = attr_count();
9914 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
9915 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9916 count * sizeof(struct attr)));
9917
9918 if ((count = attr_unknown_count()))
9919 vty_out(vty, "%ld unknown attributes\n", count);
9920
9921 /* AS_PATH attributes */
9922 count = aspath_count();
9923 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
9924 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9925 count * sizeof(struct aspath)));
9926
9927 count = mtype_stats_alloc(MTYPE_AS_SEG);
9928 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
9929 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9930 count * sizeof(struct assegment)));
9931
9932 /* Other attributes */
9933 if ((count = community_count()))
9934 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9935 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9936 count * sizeof(struct community)));
d62a17ae 9937 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
9938 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9939 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9940 count * sizeof(struct ecommunity)));
d62a17ae 9941 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
9942 vty_out(vty,
9943 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
9944 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9945 count * sizeof(struct lcommunity)));
d62a17ae 9946
9947 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
9948 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
9949 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9950 count * sizeof(struct cluster_list)));
9951
9952 /* Peer related usage */
9953 count = mtype_stats_alloc(MTYPE_BGP_PEER);
9954 vty_out(vty, "%ld peers, using %s of memory\n", count,
9955 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9956 count * sizeof(struct peer)));
9957
9958 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
9959 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
9960 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9961 count * sizeof(struct peer_group)));
9962
9963 /* Other */
d62a17ae 9964 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
9965 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
9966 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9967 count * sizeof(regex_t)));
d62a17ae 9968 return CMD_SUCCESS;
4bf6a362 9969}
fee0f4c6 9970
57a9c8a8
DS
9971static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
9972{
9973 json_object *bestpath = json_object_new_object();
9974
892fedb6 9975 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
9976 json_object_string_add(bestpath, "asPath", "ignore");
9977
892fedb6 9978 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
9979 json_object_string_add(bestpath, "asPath", "confed");
9980
892fedb6
DA
9981 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
9982 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 9983 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9984 "as-set");
9985 else
a4d82a8a 9986 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9987 "true");
9988 } else
a4d82a8a 9989 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 9990
ee88563a
JM
9991 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
9992 json_object_boolean_true_add(bestpath, "peerTypeRelax");
9993
892fedb6 9994 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 9995 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
9996 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
9997 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
9998 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 9999 json_object_string_add(bestpath, "med", "confed");
892fedb6 10000 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10001 json_object_string_add(bestpath, "med",
10002 "missing-as-worst");
10003 else
10004 json_object_string_add(bestpath, "med", "true");
10005 }
10006
10007 json_object_object_add(json, "bestPath", bestpath);
10008}
10009
3577f1c5
DD
10010/* Print the error code/subcode for why the peer is down */
10011static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10012 json_object *json_peer, bool use_json)
10013{
10014 const char *code_str;
10015 const char *subcode_str;
10016
10017 if (use_json) {
10018 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10019 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10020 char errorcodesubcode_hexstr[5];
10021 char errorcodesubcode_str[256];
10022
10023 code_str = bgp_notify_code_str(peer->notify.code);
10024 subcode_str = bgp_notify_subcode_str(
10025 peer->notify.code,
10026 peer->notify.subcode);
10027
772270f3
QY
10028 snprintf(errorcodesubcode_hexstr,
10029 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10030 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10031 json_object_string_add(json_peer,
10032 "lastErrorCodeSubcode",
10033 errorcodesubcode_hexstr);
10034 snprintf(errorcodesubcode_str, 255, "%s%s",
10035 code_str, subcode_str);
10036 json_object_string_add(json_peer,
10037 "lastNotificationReason",
10038 errorcodesubcode_str);
10039 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10040 && peer->notify.code == BGP_NOTIFY_CEASE
10041 && (peer->notify.subcode
10042 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10043 || peer->notify.subcode
10044 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10045 && peer->notify.length) {
10046 char msgbuf[1024];
10047 const char *msg_str;
10048
10049 msg_str = bgp_notify_admin_message(
10050 msgbuf, sizeof(msgbuf),
10051 (uint8_t *)peer->notify.data,
10052 peer->notify.length);
10053 if (msg_str)
10054 json_object_string_add(
10055 json_peer,
10056 "lastShutdownDescription",
10057 msg_str);
10058 }
10059
c258527b 10060 }
3577f1c5
DD
10061 json_object_string_add(json_peer, "lastResetDueTo",
10062 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10063 json_object_int_add(json_peer, "lastResetCode",
10064 peer->last_reset);
3577f1c5
DD
10065 } else {
10066 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10067 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10068 code_str = bgp_notify_code_str(peer->notify.code);
10069 subcode_str =
10070 bgp_notify_subcode_str(peer->notify.code,
10071 peer->notify.subcode);
10072 vty_out(vty, " Notification %s (%s%s)\n",
10073 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10074 ? "sent"
10075 : "received",
10076 code_str, subcode_str);
10077 } else {
e91c24c8 10078 vty_out(vty, " %s\n",
3577f1c5
DD
10079 peer_down_str[(int)peer->last_reset]);
10080 }
10081 }
10082}
10083
10084static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10085 safi_t safi)
10086{
feb17238 10087 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
3577f1c5
DD
10088}
10089
10090static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10091 struct peer *peer, json_object *json_peer,
10092 int max_neighbor_width, bool use_json)
10093{
10094 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10095 int len;
10096
10097 if (use_json) {
10098 if (peer_dynamic_neighbor(peer))
10099 json_object_boolean_true_add(json_peer,
10100 "dynamicPeer");
10101 if (peer->hostname)
10102 json_object_string_add(json_peer, "hostname",
10103 peer->hostname);
10104
10105 if (peer->domainname)
10106 json_object_string_add(json_peer, "domainname",
10107 peer->domainname);
10108 json_object_int_add(json_peer, "connectionsEstablished",
10109 peer->established);
10110 json_object_int_add(json_peer, "connectionsDropped",
10111 peer->dropped);
10112 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10113 use_json, json_peer);
feb17238 10114 if (peer_established(peer))
3577f1c5
DD
10115 json_object_string_add(json_peer, "lastResetDueTo",
10116 "AFI/SAFI Not Negotiated");
10117 else
10118 bgp_show_peer_reset(NULL, peer, json_peer, true);
10119 } else {
10120 dn_flag[1] = '\0';
10121 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10122 if (peer->hostname
892fedb6 10123 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10124 len = vty_out(vty, "%s%s(%s)", dn_flag,
10125 peer->hostname, peer->host);
10126 else
10127 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10128
10129 /* pad the neighbor column with spaces */
10130 if (len < max_neighbor_width)
10131 vty_out(vty, "%*s", max_neighbor_width - len,
10132 " ");
e91c24c8 10133 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10134 peer->dropped,
10135 peer_uptime(peer->uptime, timebuf,
10136 BGP_UPTIME_LEN, 0, NULL));
feb17238 10137 if (peer_established(peer))
3577f1c5
DD
10138 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10139 else
10140 bgp_show_peer_reset(vty, peer, NULL,
10141 false);
10142 }
10143}
c258527b 10144
565e9ddd 10145/* Strip peer's description to the given size. */
cb75bb31
DA
10146static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10147{
10148 static char stripped[BUFSIZ];
cb75bb31
DA
10149 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10150
cb75bb31
DA
10151 strlcpy(stripped, desc, len + 1);
10152
10153 return stripped;
10154}
3577f1c5 10155
8c1d4cd5
LS
10156/* Determine whether var peer should be filtered out of the summary. */
10157static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10158 struct peer *fpeer, int as_type,
10159 as_t as)
10160{
10161
10162 /* filter neighbor XXXX */
10163 if (fpeer && fpeer != peer)
10164 return true;
10165
10166 /* filter remote-as (internal|external) */
10167 if (as_type != AS_UNSPECIFIED) {
10168 if (peer->as_type == AS_SPECIFIED) {
10169 if (as_type == AS_INTERNAL) {
10170 if (peer->as != peer->local_as)
10171 return true;
10172 } else if (peer->as == peer->local_as)
10173 return true;
10174 } else if (as_type != peer->as_type)
10175 return true;
10176 } else if (as && as != peer->as) /* filter remote-as XXX */
10177 return true;
10178
10179 return false;
10180}
10181
565e9ddd
DA
10182/* Show BGP peer's summary information.
10183 *
10184 * Peer's description is stripped according to if `wide` option is given
10185 * or not.
10186 *
10187 * When adding new columns to `show bgp summary` output, please make
10188 * sure `Desc` is the lastest column to show because it can contain
10189 * whitespaces and the whole output will be tricky.
10190 */
d62a17ae 10191static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 10192 struct peer *fpeer, int as_type, as_t as,
96c81f66 10193 uint16_t show_flags)
d62a17ae 10194{
10195 struct peer *peer;
10196 struct listnode *node, *nnode;
10197 unsigned int count = 0, dn_count = 0;
10198 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10199 char neighbor_buf[VTY_BUFSIZ];
10200 int neighbor_col_default_width = 16;
3577f1c5 10201 int len, failed_count = 0;
ce1944f0 10202 unsigned int filtered_count = 0;
d62a17ae 10203 int max_neighbor_width = 0;
10204 int pfx_rcd_safi;
3c13337d 10205 json_object *json = NULL;
d62a17ae 10206 json_object *json_peer = NULL;
10207 json_object *json_peers = NULL;
50e05855 10208 struct peer_af *paf;
d3ada366 10209 struct bgp_filter *filter;
85eeb029
DA
10210 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10211 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10212 bool show_established =
10213 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10214 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
96c81f66 10215 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
d62a17ae 10216
10217 /* labeled-unicast routes are installed in the unicast table so in order
10218 * to
10219 * display the correct PfxRcd value we must look at SAFI_UNICAST
10220 */
3577f1c5 10221
d62a17ae 10222 if (safi == SAFI_LABELED_UNICAST)
10223 pfx_rcd_safi = SAFI_UNICAST;
10224 else
10225 pfx_rcd_safi = safi;
10226
10227 if (use_json) {
3c13337d 10228 json = json_object_new_object();
d62a17ae 10229 json_peers = json_object_new_object();
3577f1c5 10230 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10231 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10232 as_type, as)) {
ce1944f0 10233 filtered_count++;
8c1d4cd5
LS
10234 count++;
10235 continue;
10236 }
10237
3577f1c5
DD
10238 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10239 continue;
10240
10241 if (peer->afc[afi][safi]) {
10242 /* See if we have at least a single failed peer */
10243 if (bgp_has_peer_failed(peer, afi, safi))
10244 failed_count++;
10245 count++;
10246 }
10247 if (peer_dynamic_neighbor(peer))
10248 dn_count++;
10249 }
c258527b 10250
d62a17ae 10251 } else {
10252 /* Loop over all neighbors that will be displayed to determine
10253 * how many
10254 * characters are needed for the Neighbor column
10255 */
10256 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10257 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10258 as_type, as)) {
ce1944f0 10259 filtered_count++;
8c1d4cd5
LS
10260 count++;
10261 continue;
10262 }
10263
d62a17ae 10264 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10265 continue;
10266
10267 if (peer->afc[afi][safi]) {
10268 memset(dn_flag, '\0', sizeof(dn_flag));
10269 if (peer_dynamic_neighbor(peer))
10270 dn_flag[0] = '*';
10271
10272 if (peer->hostname
892fedb6
DA
10273 && CHECK_FLAG(bgp->flags,
10274 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10275 snprintf(neighbor_buf,
10276 sizeof(neighbor_buf),
10277 "%s%s(%s) ", dn_flag,
10278 peer->hostname, peer->host);
d62a17ae 10279 else
772270f3
QY
10280 snprintf(neighbor_buf,
10281 sizeof(neighbor_buf), "%s%s ",
10282 dn_flag, peer->host);
d62a17ae 10283
10284 len = strlen(neighbor_buf);
10285
10286 if (len > max_neighbor_width)
10287 max_neighbor_width = len;
c258527b 10288
3577f1c5
DD
10289 /* See if we have at least a single failed peer */
10290 if (bgp_has_peer_failed(peer, afi, safi))
10291 failed_count++;
10292 count++;
d62a17ae 10293 }
10294 }
f933309e 10295
d62a17ae 10296 /* Originally we displayed the Neighbor column as 16
10297 * characters wide so make that the default
10298 */
10299 if (max_neighbor_width < neighbor_col_default_width)
10300 max_neighbor_width = neighbor_col_default_width;
10301 }
f933309e 10302
3577f1c5
DD
10303 if (show_failed && !failed_count) {
10304 if (use_json) {
10305 json_object_int_add(json, "failedPeersCount", 0);
10306 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10307 json_object_int_add(json, "totalPeers", count);
3577f1c5 10308
75eeda93 10309 vty_json(vty, json);
3577f1c5
DD
10310 } else {
10311 vty_out(vty, "%% No failed BGP neighbors found\n");
3577f1c5
DD
10312 }
10313 return CMD_SUCCESS;
10314 }
c258527b 10315
3577f1c5 10316 count = 0; /* Reset the value as its used again */
ce1944f0 10317 filtered_count = 0;
800867d8 10318 dn_count = 0;
d62a17ae 10319 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10320 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10321 continue;
10322
ea47320b
DL
10323 if (!peer->afc[afi][safi])
10324 continue;
d62a17ae 10325
ea47320b
DL
10326 if (!count) {
10327 unsigned long ents;
10328 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10329 int64_t vrf_id_ui;
d62a17ae 10330
a4d82a8a
PZ
10331 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10332 ? -1
10333 : (int64_t)bgp->vrf_id;
ea47320b
DL
10334
10335 /* Usage summary and header */
10336 if (use_json) {
c949c771
DA
10337 json_object_string_addf(json, "routerId",
10338 "%pI4",
10339 &bgp->router_id);
60466a63
QY
10340 json_object_int_add(json, "as", bgp->as);
10341 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10342 json_object_string_add(
10343 json, "vrfName",
10344 (bgp->inst_type
10345 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10346 ? VRF_DEFAULT_NAME
ea47320b
DL
10347 : bgp->name);
10348 } else {
10349 vty_out(vty,
23d0a753
DA
10350 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10351 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10352 bgp->vrf_id == VRF_UNKNOWN
10353 ? -1
10354 : (int)bgp->vrf_id);
ea47320b
DL
10355 vty_out(vty, "\n");
10356 }
d62a17ae 10357
ea47320b 10358 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10359 if (use_json) {
ea47320b 10360 json_object_int_add(
60466a63 10361 json, "updateDelayLimit",
ea47320b 10362 bgp->v_update_delay);
d62a17ae 10363
ea47320b
DL
10364 if (bgp->v_update_delay
10365 != bgp->v_establish_wait)
d62a17ae 10366 json_object_int_add(
10367 json,
ea47320b
DL
10368 "updateDelayEstablishWait",
10369 bgp->v_establish_wait);
d62a17ae 10370
60466a63 10371 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10372 json_object_string_add(
10373 json,
10374 "updateDelayFirstNeighbor",
10375 bgp->update_delay_begin_time);
10376 json_object_boolean_true_add(
10377 json,
10378 "updateDelayInProgress");
10379 } else {
10380 if (bgp->update_delay_over) {
d62a17ae 10381 json_object_string_add(
10382 json,
10383 "updateDelayFirstNeighbor",
10384 bgp->update_delay_begin_time);
ea47320b 10385 json_object_string_add(
d62a17ae 10386 json,
ea47320b
DL
10387 "updateDelayBestpathResumed",
10388 bgp->update_delay_end_time);
10389 json_object_string_add(
d62a17ae 10390 json,
ea47320b
DL
10391 "updateDelayZebraUpdateResume",
10392 bgp->update_delay_zebra_resume_time);
10393 json_object_string_add(
10394 json,
10395 "updateDelayPeerUpdateResume",
10396 bgp->update_delay_peers_resume_time);
d62a17ae 10397 }
ea47320b
DL
10398 }
10399 } else {
10400 vty_out(vty,
10401 "Read-only mode update-delay limit: %d seconds\n",
10402 bgp->v_update_delay);
10403 if (bgp->v_update_delay
10404 != bgp->v_establish_wait)
d62a17ae 10405 vty_out(vty,
ea47320b
DL
10406 " Establish wait: %d seconds\n",
10407 bgp->v_establish_wait);
d62a17ae 10408
60466a63 10409 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10410 vty_out(vty,
10411 " First neighbor established: %s\n",
10412 bgp->update_delay_begin_time);
10413 vty_out(vty,
10414 " Delay in progress\n");
10415 } else {
10416 if (bgp->update_delay_over) {
d62a17ae 10417 vty_out(vty,
10418 " First neighbor established: %s\n",
10419 bgp->update_delay_begin_time);
10420 vty_out(vty,
ea47320b
DL
10421 " Best-paths resumed: %s\n",
10422 bgp->update_delay_end_time);
10423 vty_out(vty,
10424 " zebra update resumed: %s\n",
10425 bgp->update_delay_zebra_resume_time);
10426 vty_out(vty,
10427 " peers update resumed: %s\n",
10428 bgp->update_delay_peers_resume_time);
d62a17ae 10429 }
10430 }
10431 }
ea47320b 10432 }
d62a17ae 10433
ea47320b
DL
10434 if (use_json) {
10435 if (bgp_maxmed_onstartup_configured(bgp)
10436 && bgp->maxmed_active)
10437 json_object_boolean_true_add(
60466a63 10438 json, "maxMedOnStartup");
ea47320b
DL
10439 if (bgp->v_maxmed_admin)
10440 json_object_boolean_true_add(
60466a63 10441 json, "maxMedAdministrative");
d62a17ae 10442
ea47320b
DL
10443 json_object_int_add(
10444 json, "tableVersion",
60466a63 10445 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 10446
60466a63
QY
10447 ents = bgp_table_count(bgp->rib[afi][safi]);
10448 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
10449 json_object_int_add(
10450 json, "ribMemory",
9bcb3eef 10451 ents * sizeof(struct bgp_dest));
d62a17ae 10452
210ec2a0 10453 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
10454 json_object_int_add(json, "peerCount", ents);
10455 json_object_int_add(json, "peerMemory",
10456 ents * sizeof(struct peer));
d62a17ae 10457
ea47320b
DL
10458 if ((ents = listcount(bgp->group))) {
10459 json_object_int_add(
60466a63 10460 json, "peerGroupCount", ents);
ea47320b
DL
10461 json_object_int_add(
10462 json, "peerGroupMemory",
996c9314
LB
10463 ents * sizeof(struct
10464 peer_group));
ea47320b 10465 }
d62a17ae 10466
ea47320b
DL
10467 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10468 BGP_CONFIG_DAMPENING))
10469 json_object_boolean_true_add(
60466a63 10470 json, "dampeningEnabled");
ea47320b 10471 } else {
96c81f66
LS
10472 if (!show_terse) {
10473 if (bgp_maxmed_onstartup_configured(bgp)
10474 && bgp->maxmed_active)
10475 vty_out(vty,
10476 "Max-med on-startup active\n");
10477 if (bgp->v_maxmed_admin)
10478 vty_out(vty,
10479 "Max-med administrative active\n");
d62a17ae 10480
96c81f66
LS
10481 vty_out(vty,
10482 "BGP table version %" PRIu64
10483 "\n",
10484 bgp_table_version(
10485 bgp->rib[afi][safi]));
ea47320b 10486
96c81f66
LS
10487 ents = bgp_table_count(
10488 bgp->rib[afi][safi]);
d62a17ae 10489 vty_out(vty,
96c81f66 10490 "RIB entries %ld, using %s of memory\n",
d62a17ae 10491 ents,
10492 mtype_memstr(
10493 memstrbuf,
10494 sizeof(memstrbuf),
96c81f66
LS
10495 ents
10496 * sizeof(
10497 struct
10498 bgp_dest)));
d62a17ae 10499
96c81f66
LS
10500 /* Peer related usage */
10501 ents = bgp->af_peer_count[afi][safi];
10502 vty_out(vty,
10503 "Peers %ld, using %s of memory\n",
10504 ents,
10505 mtype_memstr(
10506 memstrbuf,
10507 sizeof(memstrbuf),
10508 ents
10509 * sizeof(
10510 struct
10511 peer)));
d62a17ae 10512
96c81f66
LS
10513 if ((ents = listcount(bgp->group)))
10514 vty_out(vty,
10515 "Peer groups %ld, using %s of memory\n",
10516 ents,
10517 mtype_memstr(
10518 memstrbuf,
10519 sizeof(memstrbuf),
10520 ents
10521 * sizeof(
10522 struct
10523 peer_group)));
10524
10525 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10526 BGP_CONFIG_DAMPENING))
10527 vty_out(vty,
10528 "Dampening enabled.\n");
10529 }
10530 if (show_failed) {
10531 vty_out(vty, "\n");
10532
10533 /* Subtract 8 here because 'Neighbor' is
10534 * 8 characters */
10535 vty_out(vty, "Neighbor");
10536 vty_out(vty, "%*s",
10537 max_neighbor_width - 8, " ");
85eeb029
DA
10538 vty_out(vty,
10539 BGP_SHOW_SUMMARY_HEADER_FAILED);
96c81f66 10540 }
d62a17ae 10541 }
ea47320b 10542 }
d62a17ae 10543
d55811cc 10544 paf = peer_af_find(peer, afi, safi);
d3ada366 10545 filter = &peer->filter[afi][safi];
db92d226 10546
ea47320b 10547 count++;
3577f1c5
DD
10548 /* Works for both failed & successful cases */
10549 if (peer_dynamic_neighbor(peer))
10550 dn_count++;
d62a17ae 10551
ea47320b 10552 if (use_json) {
3577f1c5 10553 json_peer = NULL;
8c1d4cd5 10554 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
10555 as_type, as)) {
10556 filtered_count++;
8c1d4cd5 10557 continue;
ce1944f0 10558 }
3577f1c5
DD
10559 if (show_failed &&
10560 bgp_has_peer_failed(peer, afi, safi)) {
10561 json_peer = json_object_new_object();
10562 bgp_show_failed_summary(vty, bgp, peer,
10563 json_peer, 0, use_json);
10564 } else if (!show_failed) {
10b49f14 10565 if (show_established
ce1944f0
LS
10566 && bgp_has_peer_failed(peer, afi, safi)) {
10567 filtered_count++;
10b49f14 10568 continue;
ce1944f0 10569 }
10b49f14 10570
3577f1c5
DD
10571 json_peer = json_object_new_object();
10572 if (peer_dynamic_neighbor(peer)) {
10573 json_object_boolean_true_add(json_peer,
10574 "dynamicPeer");
10575 }
d62a17ae 10576
3577f1c5
DD
10577 if (peer->hostname)
10578 json_object_string_add(json_peer, "hostname",
10579 peer->hostname);
10580
10581 if (peer->domainname)
10582 json_object_string_add(json_peer, "domainname",
10583 peer->domainname);
10584
10585 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
10586 json_object_int_add(
10587 json_peer, "localAs",
10588 peer->change_local_as
10589 ? peer->change_local_as
10590 : peer->local_as);
3577f1c5
DD
10591 json_object_int_add(json_peer, "version", 4);
10592 json_object_int_add(json_peer, "msgRcvd",
10593 PEER_TOTAL_RX(peer));
10594 json_object_int_add(json_peer, "msgSent",
10595 PEER_TOTAL_TX(peer));
10596
43aa5965
QY
10597 atomic_size_t outq_count, inq_count;
10598 outq_count = atomic_load_explicit(
10599 &peer->obuf->count,
10600 memory_order_relaxed);
10601 inq_count = atomic_load_explicit(
10602 &peer->ibuf->count,
10603 memory_order_relaxed);
10604
3577f1c5
DD
10605 json_object_int_add(json_peer, "tableVersion",
10606 peer->version[afi][safi]);
10607 json_object_int_add(json_peer, "outq",
43aa5965
QY
10608 outq_count);
10609 json_object_int_add(json_peer, "inq",
10610 inq_count);
3577f1c5
DD
10611 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10612 use_json, json_peer);
10613
3577f1c5
DD
10614 json_object_int_add(json_peer, "pfxRcd",
10615 peer->pcount[afi][pfx_rcd_safi]);
10616
3577f1c5 10617 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
10618 json_object_int_add(
10619 json_peer, "pfxSnt",
10620 (PAF_SUBGRP(paf))->scount);
10621 else
10622 json_object_int_add(json_peer, "pfxSnt",
10623 0);
0e1f8ab5
DA
10624
10625 /* BGP FSM state */
cb9196e7 10626 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
10627 || CHECK_FLAG(peer->bgp->flags,
10628 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
10629 json_object_string_add(json_peer,
10630 "state",
3577f1c5
DD
10631 "Idle (Admin)");
10632 else if (peer->afc_recv[afi][safi])
10633 json_object_string_add(
0e1f8ab5
DA
10634 json_peer, "state",
10635 lookup_msg(bgp_status_msg,
10636 peer->status, NULL));
10637 else if (CHECK_FLAG(
10638 peer->sflags,
10639 PEER_STATUS_PREFIX_OVERFLOW))
10640 json_object_string_add(json_peer,
10641 "state",
3577f1c5
DD
10642 "Idle (PfxCt)");
10643 else
10644 json_object_string_add(
0e1f8ab5
DA
10645 json_peer, "state",
10646 lookup_msg(bgp_status_msg,
10647 peer->status, NULL));
10648
10649 /* BGP peer state */
10650 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10651 || CHECK_FLAG(peer->bgp->flags,
10652 BGP_FLAG_SHUTDOWN))
10653 json_object_string_add(json_peer,
10654 "peerState",
10655 "Admin");
10656 else if (CHECK_FLAG(
10657 peer->sflags,
10658 PEER_STATUS_PREFIX_OVERFLOW))
10659 json_object_string_add(json_peer,
10660 "peerState",
10661 "PfxCt");
10662 else if (CHECK_FLAG(peer->flags,
10663 PEER_FLAG_PASSIVE))
10664 json_object_string_add(json_peer,
10665 "peerState",
10666 "Passive");
10667 else if (CHECK_FLAG(peer->sflags,
10668 PEER_STATUS_NSF_WAIT))
10669 json_object_string_add(json_peer,
10670 "peerState",
10671 "NSF passive");
10672 else if (CHECK_FLAG(
10673 peer->bgp->flags,
10674 BGP_FLAG_EBGP_REQUIRES_POLICY)
10675 && (!bgp_inbound_policy_exists(peer,
10676 filter)
10677 || !bgp_outbound_policy_exists(
10678 peer, filter)))
10679 json_object_string_add(json_peer,
10680 "peerState",
10681 "Policy");
10682 else
10683 json_object_string_add(
10684 json_peer, "peerState", "OK");
10685
200116db
DD
10686 json_object_int_add(json_peer, "connectionsEstablished",
10687 peer->established);
10688 json_object_int_add(json_peer, "connectionsDropped",
10689 peer->dropped);
aa72bd7e
PG
10690 if (peer->desc)
10691 json_object_string_add(
10692 json_peer, "desc", peer->desc);
b4e9dcba 10693 }
3577f1c5
DD
10694 /* Avoid creating empty peer dicts in JSON */
10695 if (json_peer == NULL)
10696 continue;
ea47320b
DL
10697
10698 if (peer->conf_if)
60466a63 10699 json_object_string_add(json_peer, "idType",
ea47320b
DL
10700 "interface");
10701 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
10702 json_object_string_add(json_peer, "idType",
10703 "ipv4");
ea47320b 10704 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
10705 json_object_string_add(json_peer, "idType",
10706 "ipv6");
ea47320b
DL
10707 json_object_object_add(json_peers, peer->host,
10708 json_peer);
10709 } else {
8c1d4cd5 10710 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
10711 as_type, as)) {
10712 filtered_count++;
8c1d4cd5 10713 continue;
ce1944f0 10714 }
3577f1c5
DD
10715 if (show_failed &&
10716 bgp_has_peer_failed(peer, afi, safi)) {
10717 bgp_show_failed_summary(vty, bgp, peer, NULL,
10718 max_neighbor_width,
10719 use_json);
10720 } else if (!show_failed) {
10b49f14 10721 if (show_established
ce1944f0
LS
10722 && bgp_has_peer_failed(peer, afi, safi)) {
10723 filtered_count++;
10b49f14 10724 continue;
ce1944f0 10725 }
96c81f66
LS
10726
10727 if ((count - filtered_count) == 1) {
10728 /* display headline before the first
10729 * neighbor line */
10730 vty_out(vty, "\n");
10731
10732 /* Subtract 8 here because 'Neighbor' is
10733 * 8 characters */
10734 vty_out(vty, "Neighbor");
10735 vty_out(vty, "%*s",
10736 max_neighbor_width - 8, " ");
10737 vty_out(vty,
10738 show_wide
10739 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10740 : BGP_SHOW_SUMMARY_HEADER_ALL);
10741 }
10742
3577f1c5
DD
10743 memset(dn_flag, '\0', sizeof(dn_flag));
10744 if (peer_dynamic_neighbor(peer)) {
10745 dn_flag[0] = '*';
10746 }
d62a17ae 10747
3577f1c5 10748 if (peer->hostname
892fedb6
DA
10749 && CHECK_FLAG(bgp->flags,
10750 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 10751 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
10752 peer->hostname,
10753 peer->host);
d62a17ae 10754 else
3577f1c5
DD
10755 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10756
10757 /* pad the neighbor column with spaces */
10758 if (len < max_neighbor_width)
10759 vty_out(vty, "%*s", max_neighbor_width - len,
10760 " ");
10761
43aa5965
QY
10762 atomic_size_t outq_count, inq_count;
10763 outq_count = atomic_load_explicit(
10764 &peer->obuf->count,
10765 memory_order_relaxed);
10766 inq_count = atomic_load_explicit(
10767 &peer->ibuf->count,
10768 memory_order_relaxed);
10769
85eeb029
DA
10770 if (show_wide)
10771 vty_out(vty,
10772 "4 %10u %10u %9u %9u %8" PRIu64
10773 " %4zu %4zu %8s",
10774 peer->as,
10775 peer->change_local_as
10776 ? peer->change_local_as
10777 : peer->local_as,
10778 PEER_TOTAL_RX(peer),
10779 PEER_TOTAL_TX(peer),
10780 peer->version[afi][safi],
10781 inq_count, outq_count,
10782 peer_uptime(peer->uptime,
10783 timebuf,
10784 BGP_UPTIME_LEN, 0,
10785 NULL));
10786 else
10787 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
10788 " %4zu %4zu %8s",
10789 peer->as, PEER_TOTAL_RX(peer),
10790 PEER_TOTAL_TX(peer),
10791 peer->version[afi][safi],
10792 inq_count, outq_count,
10793 peer_uptime(peer->uptime,
10794 timebuf,
10795 BGP_UPTIME_LEN, 0,
10796 NULL));
3577f1c5 10797
feb17238 10798 if (peer_established(peer)) {
d3ada366
DA
10799 if (peer->afc_recv[afi][safi]) {
10800 if (CHECK_FLAG(
10801 bgp->flags,
10802 BGP_FLAG_EBGP_REQUIRES_POLICY)
10803 && !bgp_inbound_policy_exists(
10804 peer, filter))
10805 vty_out(vty, " %12s",
10806 "(Policy)");
10807 else
10808 vty_out(vty,
6cde4b45 10809 " %12u",
d3ada366
DA
10810 peer->pcount
10811 [afi]
10812 [pfx_rcd_safi]);
10813 } else {
749d0f27 10814 vty_out(vty, " NoNeg");
d3ada366 10815 }
db92d226 10816
d3ada366
DA
10817 if (paf && PAF_SUBGRP(paf)) {
10818 if (CHECK_FLAG(
10819 bgp->flags,
10820 BGP_FLAG_EBGP_REQUIRES_POLICY)
10821 && !bgp_outbound_policy_exists(
10822 peer, filter))
10823 vty_out(vty, " %8s",
10824 "(Policy)");
10825 else
10826 vty_out(vty,
6cde4b45 10827 " %8u",
d3ada366
DA
10828 (PAF_SUBGRP(
10829 paf))
10830 ->scount);
749d0f27
DA
10831 } else {
10832 vty_out(vty, " NoNeg");
d3ada366 10833 }
db92d226 10834 } else {
736b68f3
DS
10835 if (CHECK_FLAG(peer->flags,
10836 PEER_FLAG_SHUTDOWN)
10837 || CHECK_FLAG(peer->bgp->flags,
10838 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
10839 vty_out(vty, " Idle (Admin)");
10840 else if (CHECK_FLAG(
10841 peer->sflags,
10842 PEER_STATUS_PREFIX_OVERFLOW))
10843 vty_out(vty, " Idle (PfxCt)");
10844 else
10845 vty_out(vty, " %12s",
10846 lookup_msg(bgp_status_msg,
10847 peer->status, NULL));
db92d226 10848
6cde4b45 10849 vty_out(vty, " %8u", 0);
3577f1c5 10850 }
565e9ddd
DA
10851 /* Make sure `Desc` column is the lastest in
10852 * the output.
10853 */
aa72bd7e 10854 if (peer->desc)
cb75bb31
DA
10855 vty_out(vty, " %s",
10856 bgp_peer_description_stripped(
85eeb029
DA
10857 peer->desc,
10858 show_wide ? 64 : 20));
aa72bd7e
PG
10859 else
10860 vty_out(vty, " N/A");
3577f1c5 10861 vty_out(vty, "\n");
d62a17ae 10862 }
3577f1c5 10863
d62a17ae 10864 }
10865 }
f933309e 10866
d62a17ae 10867 if (use_json) {
10868 json_object_object_add(json, "peers", json_peers);
3577f1c5 10869 json_object_int_add(json, "failedPeers", failed_count);
ce1944f0
LS
10870 json_object_int_add(json, "displayedPeers",
10871 count - filtered_count);
d62a17ae 10872 json_object_int_add(json, "totalPeers", count);
10873 json_object_int_add(json, "dynamicPeers", dn_count);
10874
3577f1c5
DD
10875 if (!show_failed)
10876 bgp_show_bestpath_json(bgp, json);
57a9c8a8 10877
75eeda93 10878 vty_json(vty, json);
d62a17ae 10879 } else {
ce1944f0 10880 if (count) {
96c81f66
LS
10881 if (filtered_count == count)
10882 vty_out(vty, "\n%% No matching neighbor\n");
10883 else {
10884 if (show_failed)
10885 vty_out(vty, "\nDisplayed neighbors %d",
10886 failed_count);
10887 else if (as_type != AS_UNSPECIFIED || as
10888 || fpeer || show_established)
ce1944f0
LS
10889 vty_out(vty, "\nDisplayed neighbors %d",
10890 count - filtered_count);
96c81f66
LS
10891
10892 vty_out(vty, "\nTotal number of neighbors %d\n",
10893 count);
ce1944f0 10894 }
ce1944f0 10895 } else {
d6ceaca3 10896 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 10897 get_afi_safi_str(afi, safi, false));
d62a17ae 10898 }
b05a1c8b 10899
d6ceaca3 10900 if (dn_count) {
d62a17ae 10901 vty_out(vty, "* - dynamic neighbor\n");
10902 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
10903 dn_count, bgp->dynamic_neighbors_limit);
10904 }
10905 }
1ff9a340 10906
d62a17ae 10907 return CMD_SUCCESS;
718e3744 10908}
10909
d62a17ae 10910static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5 10911 int safi, struct peer *fpeer, int as_type,
96c81f66 10912 as_t as, uint16_t show_flags)
d62a17ae 10913{
10914 int is_first = 1;
10915 int afi_wildcard = (afi == AFI_MAX);
10916 int safi_wildcard = (safi == SAFI_MAX);
10917 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 10918 bool nbr_output = false;
85eeb029 10919 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 10920
10921 if (use_json && is_wildcard)
10922 vty_out(vty, "{\n");
10923 if (afi_wildcard)
10924 afi = 1; /* AFI_IP */
10925 while (afi < AFI_MAX) {
10926 if (safi_wildcard)
10927 safi = 1; /* SAFI_UNICAST */
10928 while (safi < SAFI_MAX) {
318cac96 10929 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 10930 nbr_output = true;
f86897b9 10931
d62a17ae 10932 if (is_wildcard) {
10933 /*
10934 * So limit output to those afi/safi
10935 * pairs that
10936 * actualy have something interesting in
10937 * them
10938 */
10939 if (use_json) {
d62a17ae 10940 if (!is_first)
10941 vty_out(vty, ",\n");
10942 else
10943 is_first = 0;
10944
10945 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
10946 get_afi_safi_str(afi,
10947 safi,
10948 true));
d62a17ae 10949 } else {
6cac2fcc
LS
10950 vty_out(vty,
10951 "\n%s Summary (%s):\n",
5cb5f4d0
DD
10952 get_afi_safi_str(afi,
10953 safi,
6cac2fcc
LS
10954 false),
10955 bgp->name_pretty);
d62a17ae 10956 }
10957 }
8c1d4cd5
LS
10958 bgp_show_summary(vty, bgp, afi, safi, fpeer,
10959 as_type, as, show_flags);
d62a17ae 10960 }
10961 safi++;
d62a17ae 10962 if (!safi_wildcard)
10963 safi = SAFI_MAX;
10964 }
10965 afi++;
ee851c8c 10966 if (!afi_wildcard)
d62a17ae 10967 afi = AFI_MAX;
10968 }
10969
10970 if (use_json && is_wildcard)
10971 vty_out(vty, "}\n");
ca61fd25
DS
10972 else if (!nbr_output) {
10973 if (use_json)
10974 vty_out(vty, "{}\n");
10975 else
6cac2fcc
LS
10976 vty_out(vty, "%% No BGP neighbors found in %s\n",
10977 bgp->name_pretty);
ca61fd25 10978 }
d62a17ae 10979}
10980
10981static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
10982 safi_t safi,
10983 const char *neighbor,
10984 int as_type, as_t as,
96c81f66 10985 uint16_t show_flags)
d62a17ae 10986{
10987 struct listnode *node, *nnode;
10988 struct bgp *bgp;
8c1d4cd5 10989 struct peer *fpeer = NULL;
d62a17ae 10990 int is_first = 1;
9f049418 10991 bool nbr_output = false;
85eeb029 10992 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 10993
10994 if (use_json)
10995 vty_out(vty, "{\n");
10996
10997 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 10998 nbr_output = true;
d62a17ae 10999 if (use_json) {
d62a17ae 11000 if (!is_first)
11001 vty_out(vty, ",\n");
11002 else
11003 is_first = 0;
11004
11005 vty_out(vty, "\"%s\":",
11006 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11007 ? VRF_DEFAULT_NAME
d62a17ae 11008 : bgp->name);
d62a17ae 11009 }
8c1d4cd5
LS
11010 if (neighbor) {
11011 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11012 use_json);
11013 if (!fpeer)
11014 continue;
11015 }
11016 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11017 as, show_flags);
d62a17ae 11018 }
11019
11020 if (use_json)
11021 vty_out(vty, "}\n");
9f049418
DS
11022 else if (!nbr_output)
11023 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11024}
11025
11026int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5 11027 safi_t safi, const char *neighbor, int as_type,
96c81f66 11028 as_t as, uint16_t show_flags)
d62a17ae 11029{
11030 struct bgp *bgp;
85eeb029 11031 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 11032 struct peer *fpeer = NULL;
d62a17ae 11033
11034 if (name) {
11035 if (strmatch(name, "all")) {
85eeb029 11036 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
11037 neighbor, as_type,
11038 as, show_flags);
d62a17ae 11039 return CMD_SUCCESS;
11040 } else {
11041 bgp = bgp_lookup_by_name(name);
11042
11043 if (!bgp) {
11044 if (use_json)
11045 vty_out(vty, "{}\n");
11046 else
11047 vty_out(vty,
ca61fd25 11048 "%% BGP instance not found\n");
d62a17ae 11049 return CMD_WARNING;
11050 }
11051
8c1d4cd5
LS
11052 if (neighbor) {
11053 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11054 use_json);
11055 if (!fpeer)
11056 return CMD_WARNING;
11057 }
11058 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11059 as_type, as, show_flags);
d62a17ae 11060 return CMD_SUCCESS;
11061 }
11062 }
11063
11064 bgp = bgp_get_default();
11065
8c1d4cd5
LS
11066 if (bgp) {
11067 if (neighbor) {
11068 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11069 use_json);
11070 if (!fpeer)
11071 return CMD_WARNING;
11072 }
11073 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11074 as, show_flags);
11075 } else {
ca61fd25
DS
11076 if (use_json)
11077 vty_out(vty, "{}\n");
11078 else
11079 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11080 return CMD_WARNING;
11081 }
d62a17ae 11082
11083 return CMD_SUCCESS;
4fb25c53
DW
11084}
11085
716b2d8a 11086/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
11087DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11088 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11089 " [" BGP_SAFI_WITH_LABEL_CMD_STR
96c81f66 11090 "]] [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
11091 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11092 BGP_SAFI_WITH_LABEL_HELP_STR
11093 "Display the entries for all address families\n"
11094 "Summary of BGP neighbor status\n"
11095 "Show only sessions in Established state\n"
11096 "Show only sessions not in Established state\n"
11097 "Show only the specified neighbor session\n"
11098 "Neighbor to display information about\n"
11099 "Neighbor to display information about\n"
11100 "Neighbor on BGP configured interface\n"
11101 "Show only the specified remote AS sessions\n"
11102 "AS number\n"
11103 "Internal (iBGP) AS sessions\n"
11104 "External (eBGP) AS sessions\n"
96c81f66 11105 "Shorten the information on BGP instances\n"
8c1d4cd5 11106 "Increase table width for longer output\n" JSON_STR)
718e3744 11107{
d62a17ae 11108 char *vrf = NULL;
11109 afi_t afi = AFI_MAX;
11110 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
11111 as_t as = 0; /* 0 means AS filter not set */
11112 int as_type = AS_UNSPECIFIED;
96c81f66 11113 uint16_t show_flags = 0;
d62a17ae 11114
11115 int idx = 0;
11116
11117 /* show [ip] bgp */
96f3485c 11118 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11119 afi = AFI_IP;
9a8bdf1c
PG
11120 /* [<vrf> VIEWVRFNAME] */
11121 if (argv_find(argv, argc, "vrf", &idx)) {
11122 vrf = argv[idx + 1]->arg;
11123 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11124 vrf = NULL;
11125 } else if (argv_find(argv, argc, "view", &idx))
11126 /* [<view> VIEWVRFNAME] */
11127 vrf = argv[idx + 1]->arg;
d62a17ae 11128 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11129 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11130 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11131 }
11132
3577f1c5 11133 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11134 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11135
10b49f14 11136 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11137 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11138
8c1d4cd5
LS
11139 if (argv_find(argv, argc, "remote-as", &idx)) {
11140 if (argv[idx + 1]->arg[0] == 'i')
11141 as_type = AS_INTERNAL;
11142 else if (argv[idx + 1]->arg[0] == 'e')
11143 as_type = AS_EXTERNAL;
11144 else
11145 as = (as_t)atoi(argv[idx + 1]->arg);
11146 }
11147
96c81f66
LS
11148 if (argv_find(argv, argc, "terse", &idx))
11149 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11150
85eeb029
DA
11151 if (argv_find(argv, argc, "wide", &idx))
11152 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11153
11154 if (argv_find(argv, argc, "json", &idx))
11155 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11156
8c1d4cd5
LS
11157 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11158 show_flags);
d62a17ae 11159}
11160
5cb5f4d0 11161const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11162{
5cb5f4d0
DD
11163 if (for_json)
11164 return get_afi_safi_json_str(afi, safi);
d62a17ae 11165 else
5cb5f4d0 11166 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11167}
11168
d62a17ae 11169
11170static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11171 afi_t afi, safi_t safi,
d7c0a89a
QY
11172 uint16_t adv_smcap, uint16_t adv_rmcap,
11173 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11174 bool use_json, json_object *json_pref)
d62a17ae 11175{
11176 /* Send-Mode */
11177 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11178 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11179 if (use_json) {
11180 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11181 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11182 json_object_string_add(json_pref, "sendMode",
11183 "advertisedAndReceived");
11184 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11185 json_object_string_add(json_pref, "sendMode",
11186 "advertised");
11187 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11188 json_object_string_add(json_pref, "sendMode",
11189 "received");
11190 } else {
11191 vty_out(vty, " Send-mode: ");
11192 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11193 vty_out(vty, "advertised");
11194 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11195 vty_out(vty, "%sreceived",
11196 CHECK_FLAG(p->af_cap[afi][safi],
11197 adv_smcap)
11198 ? ", "
11199 : "");
11200 vty_out(vty, "\n");
11201 }
11202 }
11203
11204 /* Receive-Mode */
11205 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11206 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11207 if (use_json) {
11208 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11209 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11210 json_object_string_add(json_pref, "recvMode",
11211 "advertisedAndReceived");
11212 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11213 json_object_string_add(json_pref, "recvMode",
11214 "advertised");
11215 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11216 json_object_string_add(json_pref, "recvMode",
11217 "received");
11218 } else {
11219 vty_out(vty, " Receive-mode: ");
11220 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11221 vty_out(vty, "advertised");
11222 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11223 vty_out(vty, "%sreceived",
11224 CHECK_FLAG(p->af_cap[afi][safi],
11225 adv_rmcap)
11226 ? ", "
11227 : "");
11228 vty_out(vty, "\n");
11229 }
11230 }
11231}
11232
13909c4f
DS
11233static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11234 struct peer *p,
11235 bool use_json,
11236 json_object *json)
2986cac2 11237{
08c2d52a 11238 bool rbit_status = false;
2986cac2 11239
11240 if (!use_json)
a53ca37b 11241 vty_out(vty, "\n R bit: ");
2986cac2 11242
13909c4f
DS
11243 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11244 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
feb17238 11245 && (peer_established(p))) {
2986cac2 11246
11247 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 11248 rbit_status = true;
2986cac2 11249 else
08c2d52a 11250 rbit_status = false;
2986cac2 11251 }
11252
11253 if (rbit_status) {
11254 if (use_json)
13909c4f 11255 json_object_boolean_true_add(json, "rBit");
2986cac2 11256 else
11257 vty_out(vty, "True\n");
11258 } else {
11259 if (use_json)
13909c4f 11260 json_object_boolean_false_add(json, "rBit");
2986cac2 11261 else
11262 vty_out(vty, "False\n");
11263 }
11264}
11265
13909c4f
DS
11266static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11267 struct peer *peer,
11268 bool use_json,
11269 json_object *json)
2986cac2 11270{
2bb5d39b 11271 const char *mode = "NotApplicable";
2986cac2 11272
11273 if (!use_json)
a53ca37b 11274 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11275
13909c4f 11276 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
feb17238 11277 && (peer_established(peer))) {
2986cac2 11278
13909c4f
DS
11279 if ((peer->nsf_af_count == 0)
11280 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11281
2986cac2 11282 mode = "Disable";
11283
13909c4f
DS
11284 } else if (peer->nsf_af_count == 0
11285 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11286
2986cac2 11287 mode = "Helper";
11288
13909c4f
DS
11289 } else if (peer->nsf_af_count != 0
11290 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11291
2986cac2 11292 mode = "Restart";
2986cac2 11293 }
11294 }
11295
11296 if (use_json) {
13909c4f 11297 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11298 } else
11299 vty_out(vty, mode, "\n");
11300}
11301
13909c4f
DS
11302static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11303 struct peer *p,
11304 bool use_json,
11305 json_object *json)
2986cac2 11306{
11307 const char *mode = "Invalid";
11308
11309 if (!use_json)
a53ca37b 11310 vty_out(vty, " Local GR Mode: ");
2986cac2 11311
11312 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11313 mode = "Helper";
11314 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11315 mode = "Restart";
11316 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11317 mode = "Disable";
2ba1fe69 11318 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11319 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11320 mode = "Helper*";
11321 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11322 mode = "Restart*";
11323 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11324 mode = "Disable*";
11325 else
11326 mode = "Invalid*";
2ba1fe69 11327 }
2986cac2 11328
11329 if (use_json) {
13909c4f 11330 json_object_string_add(json, "localGrMode", mode);
2986cac2 11331 } else {
11332 vty_out(vty, mode, "\n");
11333 }
11334}
11335
13909c4f
DS
11336static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11337 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11338{
2ba1fe69 11339 afi_t afi;
11340 safi_t safi;
2986cac2 11341 json_object *json_afi_safi = NULL;
11342 json_object *json_timer = NULL;
11343 json_object *json_endofrib_status = NULL;
9e3b51a7 11344 bool eor_flag = false;
2986cac2 11345
df8d723c
DA
11346 FOREACH_AFI_SAFI_NSF (afi, safi) {
11347 if (!peer->afc[afi][safi])
11348 continue;
2986cac2 11349
df8d723c
DA
11350 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11351 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11352 continue;
9e3b51a7 11353
df8d723c
DA
11354 if (use_json) {
11355 json_afi_safi = json_object_new_object();
11356 json_endofrib_status = json_object_new_object();
11357 json_timer = json_object_new_object();
11358 }
2986cac2 11359
df8d723c
DA
11360 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11361 eor_flag = true;
11362 else
11363 eor_flag = false;
2986cac2 11364
df8d723c
DA
11365 if (!use_json) {
11366 vty_out(vty, " %s:\n",
11367 get_afi_safi_str(afi, safi, false));
2986cac2 11368
df8d723c
DA
11369 vty_out(vty, " F bit: ");
11370 }
2986cac2 11371
df8d723c
DA
11372 if (peer->nsf[afi][safi] &&
11373 CHECK_FLAG(peer->af_cap[afi][safi],
11374 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11375
df8d723c
DA
11376 if (use_json) {
11377 json_object_boolean_true_add(json_afi_safi,
11378 "fBit");
11379 } else
11380 vty_out(vty, "True\n");
11381 } else {
11382 if (use_json)
11383 json_object_boolean_false_add(json_afi_safi,
11384 "fBit");
11385 else
11386 vty_out(vty, "False\n");
11387 }
2986cac2 11388
df8d723c
DA
11389 if (!use_json)
11390 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11391
df8d723c
DA
11392 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11393 PEER_STATUS_EOR_SEND)) {
11394 if (use_json) {
11395 json_object_boolean_true_add(
11396 json_endofrib_status, "endOfRibSend");
9e3b51a7 11397
df8d723c
DA
11398 PRINT_EOR_JSON(eor_flag);
11399 } else {
11400 vty_out(vty, "Yes\n");
11401 vty_out(vty,
11402 " End-of-RIB sent after update: ");
2986cac2 11403
df8d723c
DA
11404 PRINT_EOR(eor_flag);
11405 }
11406 } else {
11407 if (use_json) {
11408 json_object_boolean_false_add(
11409 json_endofrib_status, "endOfRibSend");
11410 json_object_boolean_false_add(
11411 json_endofrib_status,
11412 "endOfRibSentAfterUpdate");
13909c4f 11413 } else {
df8d723c
DA
11414 vty_out(vty, "No\n");
11415 vty_out(vty,
11416 " End-of-RIB sent after update: ");
11417 vty_out(vty, "No\n");
13909c4f 11418 }
df8d723c 11419 }
2986cac2 11420
df8d723c
DA
11421 if (!use_json)
11422 vty_out(vty, " End-of-RIB received: ");
a53ca37b 11423
df8d723c
DA
11424 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11425 PEER_STATUS_EOR_RECEIVED)) {
11426 if (use_json)
11427 json_object_boolean_true_add(
11428 json_endofrib_status, "endOfRibRecv");
11429 else
11430 vty_out(vty, "Yes\n");
11431 } else {
11432 if (use_json)
11433 json_object_boolean_false_add(
11434 json_endofrib_status, "endOfRibRecv");
11435 else
11436 vty_out(vty, "No\n");
11437 }
11438
11439 if (use_json) {
11440 json_object_int_add(json_timer, "stalePathTimer",
11441 peer->bgp->stalepath_time);
11442
11443 if (peer->t_gr_stale != NULL) {
11444 json_object_int_add(json_timer,
11445 "stalePathTimerRemaining",
11446 thread_timer_remain_second(
11447 peer->t_gr_stale));
a53ca37b
DA
11448 }
11449
df8d723c
DA
11450 /* Display Configured Selection
11451 * Deferral only when when
11452 * Gr mode is enabled.
11453 */
11454 if (CHECK_FLAG(peer->flags,
11455 PEER_FLAG_GRACEFUL_RESTART)) {
13909c4f 11456 json_object_int_add(json_timer,
df8d723c 11457 "selectionDeferralTimer",
13909c4f 11458 peer->bgp->stalepath_time);
df8d723c 11459 }
2986cac2 11460
df8d723c
DA
11461 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11462 NULL) {
2986cac2 11463
df8d723c
DA
11464 json_object_int_add(
11465 json_timer,
11466 "selectionDeferralTimerRemaining",
11467 thread_timer_remain_second(
11468 peer->bgp->gr_info[afi][safi]
11469 .t_select_deferral));
11470 }
11471 } else {
11472 vty_out(vty, " Timers:\n");
11473 vty_out(vty,
11474 " Configured Stale Path Time(sec): %u\n",
11475 peer->bgp->stalepath_time);
2986cac2 11476
df8d723c 11477 if (peer->t_gr_stale != NULL)
13909c4f 11478 vty_out(vty,
df8d723c
DA
11479 " Stale Path Remaining(sec): %ld\n",
11480 thread_timer_remain_second(
11481 peer->t_gr_stale));
11482 /* Display Configured Selection
11483 * Deferral only when when
11484 * Gr mode is enabled.
11485 */
11486 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11487 vty_out(vty,
11488 " Configured Selection Deferral Time(sec): %u\n",
11489 peer->bgp->select_defer_time);
2986cac2 11490
df8d723c
DA
11491 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11492 NULL)
11493 vty_out(vty,
11494 " Selection Deferral Time Remaining(sec): %ld\n",
11495 thread_timer_remain_second(
11496 peer->bgp->gr_info[afi][safi]
11497 .t_select_deferral));
11498 }
11499 if (use_json) {
11500 json_object_object_add(json_afi_safi, "endOfRibStatus",
11501 json_endofrib_status);
11502 json_object_object_add(json_afi_safi, "timers",
11503 json_timer);
11504 json_object_object_add(
11505 json, get_afi_safi_str(afi, safi, true),
11506 json_afi_safi);
2986cac2 11507 }
11508 }
11509}
11510
36235319
QY
11511static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11512 struct peer *p,
11513 bool use_json,
11514 json_object *json)
2986cac2 11515{
11516 if (use_json) {
11517 json_object *json_timer = NULL;
11518
11519 json_timer = json_object_new_object();
11520
13909c4f
DS
11521 json_object_int_add(json_timer, "configuredRestartTimer",
11522 p->bgp->restart_time);
2986cac2 11523
13909c4f
DS
11524 json_object_int_add(json_timer, "receivedRestartTimer",
11525 p->v_gr_restart);
2986cac2 11526
13909c4f
DS
11527 if (p->t_gr_restart != NULL)
11528 json_object_int_add(
11529 json_timer, "restartTimerRemaining",
11530 thread_timer_remain_second(p->t_gr_restart));
2986cac2 11531
11532 json_object_object_add(json, "timers", json_timer);
11533 } else {
11534
a53ca37b
DA
11535 vty_out(vty, " Timers:\n");
11536 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 11537 p->bgp->restart_time);
2986cac2 11538
a53ca37b 11539 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
11540 p->v_gr_restart);
11541 if (p->t_gr_restart != NULL)
a53ca37b 11542 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 11543 thread_timer_remain_second(p->t_gr_restart));
36235319 11544 if (p->t_gr_restart != NULL) {
a53ca37b 11545 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
11546 thread_timer_remain_second(p->t_gr_restart));
11547 }
2986cac2 11548 }
11549}
11550
11551static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 11552 bool use_json, json_object *json)
2986cac2 11553{
11554 char buf[SU_ADDRSTRLEN] = {0};
11555 char dn_flag[2] = {0};
2b7165e7
QY
11556 /* '*' + v6 address of neighbor */
11557 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 11558
2986cac2 11559 if (!p->conf_if && peer_dynamic_neighbor(p))
11560 dn_flag[0] = '*';
11561
11562 if (p->conf_if) {
11563 if (use_json)
13909c4f
DS
11564 json_object_string_add(
11565 json, "neighborAddr",
2986cac2 11566 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
11567 ? "none"
11568 : sockunion2str(&p->su, buf,
11569 SU_ADDRSTRLEN));
2986cac2 11570 else
13909c4f 11571 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 11572 BGP_PEER_SU_UNSPEC(p)
11573 ? "none"
11574 : sockunion2str(&p->su, buf,
11575 SU_ADDRSTRLEN));
11576 } else {
772270f3
QY
11577 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11578 p->host);
2986cac2 11579
11580 if (use_json)
36235319
QY
11581 json_object_string_add(json, "neighborAddr",
11582 neighborAddr);
2986cac2 11583 else
36235319 11584 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 11585 }
11586
11587 /* more gr info in new format */
11588 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11589}
11590
d62a17ae 11591static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 11592 safi_t safi, bool use_json,
d62a17ae 11593 json_object *json_neigh)
11594{
0291c246
MK
11595 struct bgp_filter *filter;
11596 struct peer_af *paf;
11597 char orf_pfx_name[BUFSIZ];
11598 int orf_pfx_count;
11599 json_object *json_af = NULL;
11600 json_object *json_prefA = NULL;
11601 json_object *json_prefB = NULL;
11602 json_object *json_addr = NULL;
fa36596c 11603 json_object *json_advmap = NULL;
d62a17ae 11604
11605 if (use_json) {
11606 json_addr = json_object_new_object();
11607 json_af = json_object_new_object();
11608 filter = &p->filter[afi][safi];
11609
11610 if (peer_group_active(p))
11611 json_object_string_add(json_addr, "peerGroupMember",
11612 p->group->name);
11613
11614 paf = peer_af_find(p, afi, safi);
11615 if (paf && PAF_SUBGRP(paf)) {
11616 json_object_int_add(json_addr, "updateGroupId",
11617 PAF_UPDGRP(paf)->id);
11618 json_object_int_add(json_addr, "subGroupId",
11619 PAF_SUBGRP(paf)->id);
11620 json_object_int_add(json_addr, "packetQueueLength",
11621 bpacket_queue_virtual_length(paf));
11622 }
11623
11624 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11625 || CHECK_FLAG(p->af_cap[afi][safi],
11626 PEER_CAP_ORF_PREFIX_SM_RCV)
11627 || CHECK_FLAG(p->af_cap[afi][safi],
11628 PEER_CAP_ORF_PREFIX_RM_ADV)
11629 || CHECK_FLAG(p->af_cap[afi][safi],
11630 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11631 json_object_int_add(json_af, "orfType",
11632 ORF_TYPE_PREFIX);
11633 json_prefA = json_object_new_object();
11634 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11635 PEER_CAP_ORF_PREFIX_SM_ADV,
11636 PEER_CAP_ORF_PREFIX_RM_ADV,
11637 PEER_CAP_ORF_PREFIX_SM_RCV,
11638 PEER_CAP_ORF_PREFIX_RM_RCV,
11639 use_json, json_prefA);
11640 json_object_object_add(json_af, "orfPrefixList",
11641 json_prefA);
11642 }
11643
11644 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11645 || CHECK_FLAG(p->af_cap[afi][safi],
11646 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11647 || CHECK_FLAG(p->af_cap[afi][safi],
11648 PEER_CAP_ORF_PREFIX_RM_ADV)
11649 || CHECK_FLAG(p->af_cap[afi][safi],
11650 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11651 json_object_int_add(json_af, "orfOldType",
11652 ORF_TYPE_PREFIX_OLD);
11653 json_prefB = json_object_new_object();
11654 bgp_show_peer_afi_orf_cap(
11655 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11656 PEER_CAP_ORF_PREFIX_RM_ADV,
11657 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11658 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11659 json_prefB);
11660 json_object_object_add(json_af, "orfOldPrefixList",
11661 json_prefB);
11662 }
11663
11664 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11665 || CHECK_FLAG(p->af_cap[afi][safi],
11666 PEER_CAP_ORF_PREFIX_SM_RCV)
11667 || CHECK_FLAG(p->af_cap[afi][safi],
11668 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11669 || CHECK_FLAG(p->af_cap[afi][safi],
11670 PEER_CAP_ORF_PREFIX_RM_ADV)
11671 || CHECK_FLAG(p->af_cap[afi][safi],
11672 PEER_CAP_ORF_PREFIX_RM_RCV)
11673 || CHECK_FLAG(p->af_cap[afi][safi],
11674 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11675 json_object_object_add(json_addr, "afDependentCap",
11676 json_af);
11677 else
11678 json_object_free(json_af);
11679
772270f3
QY
11680 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11681 p->host, afi, safi);
d62a17ae 11682 orf_pfx_count = prefix_bgp_show_prefix_list(
11683 NULL, afi, orf_pfx_name, use_json);
11684
11685 if (CHECK_FLAG(p->af_sflags[afi][safi],
11686 PEER_STATUS_ORF_PREFIX_SEND)
11687 || orf_pfx_count) {
11688 if (CHECK_FLAG(p->af_sflags[afi][safi],
11689 PEER_STATUS_ORF_PREFIX_SEND))
11690 json_object_boolean_true_add(json_neigh,
11691 "orfSent");
11692 if (orf_pfx_count)
11693 json_object_int_add(json_addr, "orfRecvCounter",
11694 orf_pfx_count);
11695 }
11696 if (CHECK_FLAG(p->af_sflags[afi][safi],
11697 PEER_STATUS_ORF_WAIT_REFRESH))
11698 json_object_string_add(
11699 json_addr, "orfFirstUpdate",
11700 "deferredUntilORFOrRouteRefreshRecvd");
11701
11702 if (CHECK_FLAG(p->af_flags[afi][safi],
11703 PEER_FLAG_REFLECTOR_CLIENT))
11704 json_object_boolean_true_add(json_addr,
11705 "routeReflectorClient");
11706 if (CHECK_FLAG(p->af_flags[afi][safi],
11707 PEER_FLAG_RSERVER_CLIENT))
11708 json_object_boolean_true_add(json_addr,
11709 "routeServerClient");
11710 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11711 json_object_boolean_true_add(json_addr,
11712 "inboundSoftConfigPermit");
11713
11714 if (CHECK_FLAG(p->af_flags[afi][safi],
11715 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11716 json_object_boolean_true_add(
11717 json_addr,
11718 "privateAsNumsAllReplacedInUpdatesToNbr");
11719 else if (CHECK_FLAG(p->af_flags[afi][safi],
11720 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11721 json_object_boolean_true_add(
11722 json_addr,
11723 "privateAsNumsReplacedInUpdatesToNbr");
11724 else if (CHECK_FLAG(p->af_flags[afi][safi],
11725 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11726 json_object_boolean_true_add(
11727 json_addr,
11728 "privateAsNumsAllRemovedInUpdatesToNbr");
11729 else if (CHECK_FLAG(p->af_flags[afi][safi],
11730 PEER_FLAG_REMOVE_PRIVATE_AS))
11731 json_object_boolean_true_add(
11732 json_addr,
11733 "privateAsNumsRemovedInUpdatesToNbr");
11734
dcc68b5e
MS
11735 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11736 json_object_boolean_true_add(
11737 json_addr,
11738 bgp_addpath_names(p->addpath_type[afi][safi])
11739 ->type_json_name);
d62a17ae 11740
11741 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11742 json_object_string_add(json_addr,
11743 "overrideASNsInOutboundUpdates",
11744 "ifAspathEqualRemoteAs");
11745
11746 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11747 || CHECK_FLAG(p->af_flags[afi][safi],
11748 PEER_FLAG_FORCE_NEXTHOP_SELF))
11749 json_object_boolean_true_add(json_addr,
11750 "routerAlwaysNextHop");
11751 if (CHECK_FLAG(p->af_flags[afi][safi],
11752 PEER_FLAG_AS_PATH_UNCHANGED))
11753 json_object_boolean_true_add(
11754 json_addr, "unchangedAsPathPropogatedToNbr");
11755 if (CHECK_FLAG(p->af_flags[afi][safi],
11756 PEER_FLAG_NEXTHOP_UNCHANGED))
11757 json_object_boolean_true_add(
11758 json_addr, "unchangedNextHopPropogatedToNbr");
11759 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11760 json_object_boolean_true_add(
11761 json_addr, "unchangedMedPropogatedToNbr");
11762 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11763 || CHECK_FLAG(p->af_flags[afi][safi],
11764 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11765 if (CHECK_FLAG(p->af_flags[afi][safi],
11766 PEER_FLAG_SEND_COMMUNITY)
11767 && CHECK_FLAG(p->af_flags[afi][safi],
11768 PEER_FLAG_SEND_EXT_COMMUNITY))
11769 json_object_string_add(json_addr,
11770 "commAttriSentToNbr",
11771 "extendedAndStandard");
11772 else if (CHECK_FLAG(p->af_flags[afi][safi],
11773 PEER_FLAG_SEND_EXT_COMMUNITY))
11774 json_object_string_add(json_addr,
11775 "commAttriSentToNbr",
11776 "extended");
11777 else
11778 json_object_string_add(json_addr,
11779 "commAttriSentToNbr",
11780 "standard");
11781 }
11782 if (CHECK_FLAG(p->af_flags[afi][safi],
11783 PEER_FLAG_DEFAULT_ORIGINATE)) {
11784 if (p->default_rmap[afi][safi].name)
11785 json_object_string_add(
11786 json_addr, "defaultRouteMap",
11787 p->default_rmap[afi][safi].name);
11788
11789 if (paf && PAF_SUBGRP(paf)
11790 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11791 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11792 json_object_boolean_true_add(json_addr,
11793 "defaultSent");
11794 else
11795 json_object_boolean_true_add(json_addr,
11796 "defaultNotSent");
11797 }
11798
dff8f48d 11799 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 11800 if (is_evpn_enabled())
60466a63
QY
11801 json_object_boolean_true_add(
11802 json_addr, "advertiseAllVnis");
dff8f48d
MK
11803 }
11804
d62a17ae 11805 if (filter->plist[FILTER_IN].name
11806 || filter->dlist[FILTER_IN].name
11807 || filter->aslist[FILTER_IN].name
11808 || filter->map[RMAP_IN].name)
11809 json_object_boolean_true_add(json_addr,
11810 "inboundPathPolicyConfig");
11811 if (filter->plist[FILTER_OUT].name
11812 || filter->dlist[FILTER_OUT].name
11813 || filter->aslist[FILTER_OUT].name
11814 || filter->map[RMAP_OUT].name || filter->usmap.name)
11815 json_object_boolean_true_add(
11816 json_addr, "outboundPathPolicyConfig");
11817
11818 /* prefix-list */
11819 if (filter->plist[FILTER_IN].name)
11820 json_object_string_add(json_addr,
11821 "incomingUpdatePrefixFilterList",
11822 filter->plist[FILTER_IN].name);
11823 if (filter->plist[FILTER_OUT].name)
11824 json_object_string_add(json_addr,
11825 "outgoingUpdatePrefixFilterList",
11826 filter->plist[FILTER_OUT].name);
11827
11828 /* distribute-list */
11829 if (filter->dlist[FILTER_IN].name)
11830 json_object_string_add(
11831 json_addr, "incomingUpdateNetworkFilterList",
11832 filter->dlist[FILTER_IN].name);
11833 if (filter->dlist[FILTER_OUT].name)
11834 json_object_string_add(
11835 json_addr, "outgoingUpdateNetworkFilterList",
11836 filter->dlist[FILTER_OUT].name);
11837
11838 /* filter-list. */
11839 if (filter->aslist[FILTER_IN].name)
11840 json_object_string_add(json_addr,
11841 "incomingUpdateAsPathFilterList",
11842 filter->aslist[FILTER_IN].name);
11843 if (filter->aslist[FILTER_OUT].name)
11844 json_object_string_add(json_addr,
11845 "outgoingUpdateAsPathFilterList",
11846 filter->aslist[FILTER_OUT].name);
11847
11848 /* route-map. */
11849 if (filter->map[RMAP_IN].name)
11850 json_object_string_add(
11851 json_addr, "routeMapForIncomingAdvertisements",
11852 filter->map[RMAP_IN].name);
11853 if (filter->map[RMAP_OUT].name)
11854 json_object_string_add(
11855 json_addr, "routeMapForOutgoingAdvertisements",
11856 filter->map[RMAP_OUT].name);
11857
9dac9fc8 11858 /* ebgp-requires-policy (inbound) */
1d3fdccf 11859 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11860 && !bgp_inbound_policy_exists(p, filter))
11861 json_object_string_add(
11862 json_addr, "inboundEbgpRequiresPolicy",
11863 "Inbound updates discarded due to missing policy");
11864
11865 /* ebgp-requires-policy (outbound) */
1d3fdccf 11866 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11867 && (!bgp_outbound_policy_exists(p, filter)))
11868 json_object_string_add(
11869 json_addr, "outboundEbgpRequiresPolicy",
11870 "Outbound updates discarded due to missing policy");
11871
d62a17ae 11872 /* unsuppress-map */
11873 if (filter->usmap.name)
11874 json_object_string_add(json_addr,
11875 "selectiveUnsuppressRouteMap",
11876 filter->usmap.name);
11877
fa36596c
MK
11878 /* advertise-map */
11879 if (filter->advmap.aname) {
11880 json_advmap = json_object_new_object();
11881 json_object_string_add(json_advmap, "condition",
11882 filter->advmap.condition
11883 ? "EXIST"
11884 : "NON_EXIST");
11885 json_object_string_add(json_advmap, "conditionMap",
11886 filter->advmap.cname);
11887 json_object_string_add(json_advmap, "advertiseMap",
11888 filter->advmap.aname);
11889 json_object_string_add(json_advmap, "advertiseStatus",
11890 filter->advmap.update_type
11891 == ADVERTISE
11892 ? "Advertise"
11893 : "Withdraw");
11894 json_object_object_add(json_addr, "advertiseMap",
11895 json_advmap);
11896 }
11897
d62a17ae 11898 /* Receive prefix count */
11899 json_object_int_add(json_addr, "acceptedPrefixCounter",
11900 p->pcount[afi][safi]);
50e05855
AD
11901 if (paf && PAF_SUBGRP(paf))
11902 json_object_int_add(json_addr, "sentPrefixCounter",
11903 (PAF_SUBGRP(paf))->scount);
d62a17ae 11904
fde246e8
DA
11905 /* Maximum prefix */
11906 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
11907 json_object_int_add(json_addr, "prefixOutAllowedMax",
11908 p->pmax_out[afi][safi]);
11909
d62a17ae 11910 /* Maximum prefix */
11911 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11912 json_object_int_add(json_addr, "prefixAllowedMax",
11913 p->pmax[afi][safi]);
11914 if (CHECK_FLAG(p->af_flags[afi][safi],
11915 PEER_FLAG_MAX_PREFIX_WARNING))
11916 json_object_boolean_true_add(
11917 json_addr, "prefixAllowedMaxWarning");
11918 json_object_int_add(json_addr,
11919 "prefixAllowedWarningThresh",
11920 p->pmax_threshold[afi][safi]);
11921 if (p->pmax_restart[afi][safi])
11922 json_object_int_add(
11923 json_addr,
11924 "prefixAllowedRestartIntervalMsecs",
11925 p->pmax_restart[afi][safi] * 60000);
11926 }
2986cac2 11927 json_object_object_add(json_neigh,
36235319 11928 get_afi_safi_str(afi, safi, true),
d62a17ae 11929 json_addr);
11930
11931 } else {
11932 filter = &p->filter[afi][safi];
11933
11934 vty_out(vty, " For address family: %s\n",
5cb5f4d0 11935 get_afi_safi_str(afi, safi, false));
d62a17ae 11936
11937 if (peer_group_active(p))
11938 vty_out(vty, " %s peer-group member\n",
11939 p->group->name);
11940
11941 paf = peer_af_find(p, afi, safi);
11942 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 11943 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 11944 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
11945 vty_out(vty, " Packet Queue length %d\n",
11946 bpacket_queue_virtual_length(paf));
11947 } else {
11948 vty_out(vty, " Not part of any update group\n");
11949 }
11950 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11951 || CHECK_FLAG(p->af_cap[afi][safi],
11952 PEER_CAP_ORF_PREFIX_SM_RCV)
11953 || CHECK_FLAG(p->af_cap[afi][safi],
11954 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11955 || CHECK_FLAG(p->af_cap[afi][safi],
11956 PEER_CAP_ORF_PREFIX_RM_ADV)
11957 || CHECK_FLAG(p->af_cap[afi][safi],
11958 PEER_CAP_ORF_PREFIX_RM_RCV)
11959 || CHECK_FLAG(p->af_cap[afi][safi],
11960 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11961 vty_out(vty, " AF-dependant capabilities:\n");
11962
11963 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11964 || CHECK_FLAG(p->af_cap[afi][safi],
11965 PEER_CAP_ORF_PREFIX_SM_RCV)
11966 || CHECK_FLAG(p->af_cap[afi][safi],
11967 PEER_CAP_ORF_PREFIX_RM_ADV)
11968 || CHECK_FLAG(p->af_cap[afi][safi],
11969 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11970 vty_out(vty,
11971 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11972 ORF_TYPE_PREFIX);
11973 bgp_show_peer_afi_orf_cap(
11974 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11975 PEER_CAP_ORF_PREFIX_RM_ADV,
11976 PEER_CAP_ORF_PREFIX_SM_RCV,
11977 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
11978 }
11979 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11980 || CHECK_FLAG(p->af_cap[afi][safi],
11981 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11982 || CHECK_FLAG(p->af_cap[afi][safi],
11983 PEER_CAP_ORF_PREFIX_RM_ADV)
11984 || CHECK_FLAG(p->af_cap[afi][safi],
11985 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11986 vty_out(vty,
11987 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11988 ORF_TYPE_PREFIX_OLD);
11989 bgp_show_peer_afi_orf_cap(
11990 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11991 PEER_CAP_ORF_PREFIX_RM_ADV,
11992 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11993 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
11994 }
11995
772270f3
QY
11996 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11997 p->host, afi, safi);
d62a17ae 11998 orf_pfx_count = prefix_bgp_show_prefix_list(
11999 NULL, afi, orf_pfx_name, use_json);
12000
12001 if (CHECK_FLAG(p->af_sflags[afi][safi],
12002 PEER_STATUS_ORF_PREFIX_SEND)
12003 || orf_pfx_count) {
12004 vty_out(vty, " Outbound Route Filter (ORF):");
12005 if (CHECK_FLAG(p->af_sflags[afi][safi],
12006 PEER_STATUS_ORF_PREFIX_SEND))
12007 vty_out(vty, " sent;");
12008 if (orf_pfx_count)
12009 vty_out(vty, " received (%d entries)",
12010 orf_pfx_count);
12011 vty_out(vty, "\n");
12012 }
12013 if (CHECK_FLAG(p->af_sflags[afi][safi],
12014 PEER_STATUS_ORF_WAIT_REFRESH))
12015 vty_out(vty,
12016 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12017
12018 if (CHECK_FLAG(p->af_flags[afi][safi],
12019 PEER_FLAG_REFLECTOR_CLIENT))
12020 vty_out(vty, " Route-Reflector Client\n");
12021 if (CHECK_FLAG(p->af_flags[afi][safi],
12022 PEER_FLAG_RSERVER_CLIENT))
12023 vty_out(vty, " Route-Server Client\n");
12024 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12025 vty_out(vty,
12026 " Inbound soft reconfiguration allowed\n");
12027
12028 if (CHECK_FLAG(p->af_flags[afi][safi],
12029 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12030 vty_out(vty,
12031 " Private AS numbers (all) replaced in updates to this neighbor\n");
12032 else if (CHECK_FLAG(p->af_flags[afi][safi],
12033 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12034 vty_out(vty,
12035 " Private AS numbers replaced in updates to this neighbor\n");
12036 else if (CHECK_FLAG(p->af_flags[afi][safi],
12037 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12038 vty_out(vty,
12039 " Private AS numbers (all) removed in updates to this neighbor\n");
12040 else if (CHECK_FLAG(p->af_flags[afi][safi],
12041 PEER_FLAG_REMOVE_PRIVATE_AS))
12042 vty_out(vty,
12043 " Private AS numbers removed in updates to this neighbor\n");
12044
dcc68b5e
MS
12045 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12046 vty_out(vty, " %s\n",
12047 bgp_addpath_names(p->addpath_type[afi][safi])
12048 ->human_description);
d62a17ae 12049
12050 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12051 vty_out(vty,
12052 " Override ASNs in outbound updates if aspath equals remote-as\n");
12053
12054 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12055 || CHECK_FLAG(p->af_flags[afi][safi],
12056 PEER_FLAG_FORCE_NEXTHOP_SELF))
12057 vty_out(vty, " NEXT_HOP is always this router\n");
12058 if (CHECK_FLAG(p->af_flags[afi][safi],
12059 PEER_FLAG_AS_PATH_UNCHANGED))
12060 vty_out(vty,
12061 " AS_PATH is propagated unchanged to this neighbor\n");
12062 if (CHECK_FLAG(p->af_flags[afi][safi],
12063 PEER_FLAG_NEXTHOP_UNCHANGED))
12064 vty_out(vty,
12065 " NEXT_HOP is propagated unchanged to this neighbor\n");
12066 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12067 vty_out(vty,
12068 " MED is propagated unchanged to this neighbor\n");
12069 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12070 || CHECK_FLAG(p->af_flags[afi][safi],
12071 PEER_FLAG_SEND_EXT_COMMUNITY)
12072 || CHECK_FLAG(p->af_flags[afi][safi],
12073 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12074 vty_out(vty,
12075 " Community attribute sent to this neighbor");
12076 if (CHECK_FLAG(p->af_flags[afi][safi],
12077 PEER_FLAG_SEND_COMMUNITY)
12078 && CHECK_FLAG(p->af_flags[afi][safi],
12079 PEER_FLAG_SEND_EXT_COMMUNITY)
12080 && CHECK_FLAG(p->af_flags[afi][safi],
12081 PEER_FLAG_SEND_LARGE_COMMUNITY))
12082 vty_out(vty, "(all)\n");
12083 else if (CHECK_FLAG(p->af_flags[afi][safi],
12084 PEER_FLAG_SEND_LARGE_COMMUNITY))
12085 vty_out(vty, "(large)\n");
12086 else if (CHECK_FLAG(p->af_flags[afi][safi],
12087 PEER_FLAG_SEND_EXT_COMMUNITY))
12088 vty_out(vty, "(extended)\n");
12089 else
12090 vty_out(vty, "(standard)\n");
12091 }
12092 if (CHECK_FLAG(p->af_flags[afi][safi],
12093 PEER_FLAG_DEFAULT_ORIGINATE)) {
12094 vty_out(vty, " Default information originate,");
12095
12096 if (p->default_rmap[afi][safi].name)
12097 vty_out(vty, " default route-map %s%s,",
12098 p->default_rmap[afi][safi].map ? "*"
12099 : "",
12100 p->default_rmap[afi][safi].name);
12101 if (paf && PAF_SUBGRP(paf)
12102 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12103 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12104 vty_out(vty, " default sent\n");
12105 else
12106 vty_out(vty, " default not sent\n");
12107 }
12108
dff8f48d
MK
12109 /* advertise-vni-all */
12110 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12111 if (is_evpn_enabled())
dff8f48d
MK
12112 vty_out(vty, " advertise-all-vni\n");
12113 }
12114
d62a17ae 12115 if (filter->plist[FILTER_IN].name
12116 || filter->dlist[FILTER_IN].name
12117 || filter->aslist[FILTER_IN].name
12118 || filter->map[RMAP_IN].name)
12119 vty_out(vty, " Inbound path policy configured\n");
12120 if (filter->plist[FILTER_OUT].name
12121 || filter->dlist[FILTER_OUT].name
12122 || filter->aslist[FILTER_OUT].name
12123 || filter->map[RMAP_OUT].name || filter->usmap.name)
12124 vty_out(vty, " Outbound path policy configured\n");
12125
12126 /* prefix-list */
12127 if (filter->plist[FILTER_IN].name)
12128 vty_out(vty,
12129 " Incoming update prefix filter list is %s%s\n",
12130 filter->plist[FILTER_IN].plist ? "*" : "",
12131 filter->plist[FILTER_IN].name);
12132 if (filter->plist[FILTER_OUT].name)
12133 vty_out(vty,
12134 " Outgoing update prefix filter list is %s%s\n",
12135 filter->plist[FILTER_OUT].plist ? "*" : "",
12136 filter->plist[FILTER_OUT].name);
12137
12138 /* distribute-list */
12139 if (filter->dlist[FILTER_IN].name)
12140 vty_out(vty,
12141 " Incoming update network filter list is %s%s\n",
12142 filter->dlist[FILTER_IN].alist ? "*" : "",
12143 filter->dlist[FILTER_IN].name);
12144 if (filter->dlist[FILTER_OUT].name)
12145 vty_out(vty,
12146 " Outgoing update network filter list is %s%s\n",
12147 filter->dlist[FILTER_OUT].alist ? "*" : "",
12148 filter->dlist[FILTER_OUT].name);
12149
12150 /* filter-list. */
12151 if (filter->aslist[FILTER_IN].name)
12152 vty_out(vty,
12153 " Incoming update AS path filter list is %s%s\n",
12154 filter->aslist[FILTER_IN].aslist ? "*" : "",
12155 filter->aslist[FILTER_IN].name);
12156 if (filter->aslist[FILTER_OUT].name)
12157 vty_out(vty,
12158 " Outgoing update AS path filter list is %s%s\n",
12159 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12160 filter->aslist[FILTER_OUT].name);
12161
12162 /* route-map. */
12163 if (filter->map[RMAP_IN].name)
12164 vty_out(vty,
12165 " Route map for incoming advertisements is %s%s\n",
12166 filter->map[RMAP_IN].map ? "*" : "",
12167 filter->map[RMAP_IN].name);
12168 if (filter->map[RMAP_OUT].name)
12169 vty_out(vty,
12170 " Route map for outgoing advertisements is %s%s\n",
12171 filter->map[RMAP_OUT].map ? "*" : "",
12172 filter->map[RMAP_OUT].name);
12173
9dac9fc8 12174 /* ebgp-requires-policy (inbound) */
1d3fdccf 12175 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12176 && !bgp_inbound_policy_exists(p, filter))
12177 vty_out(vty,
12178 " Inbound updates discarded due to missing policy\n");
12179
12180 /* ebgp-requires-policy (outbound) */
1d3fdccf 12181 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12182 && !bgp_outbound_policy_exists(p, filter))
12183 vty_out(vty,
12184 " Outbound updates discarded due to missing policy\n");
12185
d62a17ae 12186 /* unsuppress-map */
12187 if (filter->usmap.name)
12188 vty_out(vty,
12189 " Route map for selective unsuppress is %s%s\n",
12190 filter->usmap.map ? "*" : "",
12191 filter->usmap.name);
12192
7f7940e6
MK
12193 /* advertise-map */
12194 if (filter->advmap.aname && filter->advmap.cname)
12195 vty_out(vty,
12196 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12197 filter->advmap.condition ? "EXIST"
12198 : "NON_EXIST",
12199 filter->advmap.cmap ? "*" : "",
12200 filter->advmap.cname,
12201 filter->advmap.amap ? "*" : "",
12202 filter->advmap.aname,
fa36596c 12203 filter->advmap.update_type == ADVERTISE
c385f82a
MK
12204 ? "Advertise"
12205 : "Withdraw");
7f7940e6 12206
d62a17ae 12207 /* Receive prefix count */
6cde4b45 12208 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12209 p->pcount[afi][safi]);
d62a17ae 12210
fde246e8
DA
12211 /* maximum-prefix-out */
12212 if (CHECK_FLAG(p->af_flags[afi][safi],
12213 PEER_FLAG_MAX_PREFIX_OUT))
12214 vty_out(vty,
6cde4b45 12215 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12216 p->pmax_out[afi][safi]);
12217
d62a17ae 12218 /* Maximum prefix */
12219 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12220 vty_out(vty,
6cde4b45 12221 " Maximum prefixes allowed %u%s\n",
d62a17ae 12222 p->pmax[afi][safi],
12223 CHECK_FLAG(p->af_flags[afi][safi],
12224 PEER_FLAG_MAX_PREFIX_WARNING)
12225 ? " (warning-only)"
12226 : "");
12227 vty_out(vty, " Threshold for warning message %d%%",
12228 p->pmax_threshold[afi][safi]);
12229 if (p->pmax_restart[afi][safi])
12230 vty_out(vty, ", restart interval %d min",
12231 p->pmax_restart[afi][safi]);
12232 vty_out(vty, "\n");
12233 }
12234
12235 vty_out(vty, "\n");
12236 }
12237}
12238
9f049418 12239static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12240 json_object *json)
718e3744 12241{
d62a17ae 12242 struct bgp *bgp;
12243 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12244 char timebuf[BGP_UPTIME_LEN];
12245 char dn_flag[2];
d62a17ae 12246 afi_t afi;
12247 safi_t safi;
d7c0a89a
QY
12248 uint16_t i;
12249 uint8_t *msg;
d62a17ae 12250 json_object *json_neigh = NULL;
12251 time_t epoch_tbuf;
4ab46701 12252 uint32_t sync_tcp_mss;
718e3744 12253
d62a17ae 12254 bgp = p->bgp;
12255
12256 if (use_json)
12257 json_neigh = json_object_new_object();
12258
12259 memset(dn_flag, '\0', sizeof(dn_flag));
12260 if (!p->conf_if && peer_dynamic_neighbor(p))
12261 dn_flag[0] = '*';
12262
12263 if (!use_json) {
12264 if (p->conf_if) /* Configured interface name. */
12265 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12266 BGP_PEER_SU_UNSPEC(p)
12267 ? "None"
12268 : sockunion2str(&p->su, buf,
12269 SU_ADDRSTRLEN));
12270 else /* Configured IP address. */
12271 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12272 p->host);
12273 }
12274
12275 if (use_json) {
12276 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12277 json_object_string_add(json_neigh, "bgpNeighborAddr",
12278 "none");
12279 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12280 json_object_string_add(
12281 json_neigh, "bgpNeighborAddr",
12282 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12283
12284 json_object_int_add(json_neigh, "remoteAs", p->as);
12285
12286 if (p->change_local_as)
12287 json_object_int_add(json_neigh, "localAs",
12288 p->change_local_as);
12289 else
12290 json_object_int_add(json_neigh, "localAs", p->local_as);
12291
12292 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12293 json_object_boolean_true_add(json_neigh,
12294 "localAsNoPrepend");
12295
12296 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12297 json_object_boolean_true_add(json_neigh,
12298 "localAsReplaceAs");
12299 } else {
12300 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12301 || (p->as_type == AS_INTERNAL))
12302 vty_out(vty, "remote AS %u, ", p->as);
12303 else
12304 vty_out(vty, "remote AS Unspecified, ");
12305 vty_out(vty, "local AS %u%s%s, ",
12306 p->change_local_as ? p->change_local_as : p->local_as,
12307 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12308 ? " no-prepend"
12309 : "",
12310 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12311 ? " replace-as"
12312 : "");
12313 }
faa16034
DS
12314 /* peer type internal or confed-internal */
12315 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12316 if (use_json) {
12317 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12318 json_object_boolean_true_add(
12319 json_neigh, "nbrConfedInternalLink");
12320 else
12321 json_object_boolean_true_add(json_neigh,
12322 "nbrInternalLink");
12323 } else {
12324 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12325 vty_out(vty, "confed-internal link\n");
12326 else
12327 vty_out(vty, "internal link\n");
12328 }
faa16034
DS
12329 /* peer type external or confed-external */
12330 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12331 if (use_json) {
12332 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12333 json_object_boolean_true_add(
12334 json_neigh, "nbrConfedExternalLink");
12335 else
12336 json_object_boolean_true_add(json_neigh,
12337 "nbrExternalLink");
12338 } else {
12339 if (bgp_confederation_peers_check(bgp, p->as))
12340 vty_out(vty, "confed-external link\n");
12341 else
12342 vty_out(vty, "external link\n");
12343 }
faa16034
DS
12344 } else {
12345 if (use_json)
12346 json_object_boolean_true_add(json_neigh,
12347 "nbrUnspecifiedLink");
12348 else
12349 vty_out(vty, "unspecified link\n");
d62a17ae 12350 }
12351
12352 /* Description. */
12353 if (p->desc) {
12354 if (use_json)
12355 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12356 else
12357 vty_out(vty, " Description: %s\n", p->desc);
12358 }
12359
12360 if (p->hostname) {
12361 if (use_json) {
12362 if (p->hostname)
12363 json_object_string_add(json_neigh, "hostname",
12364 p->hostname);
12365
12366 if (p->domainname)
12367 json_object_string_add(json_neigh, "domainname",
12368 p->domainname);
12369 } else {
12370 if (p->domainname && (p->domainname[0] != '\0'))
12371 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12372 p->domainname);
12373 else
12374 vty_out(vty, "Hostname: %s\n", p->hostname);
12375 }
12376 }
12377
12378 /* Peer-group */
12379 if (p->group) {
12380 if (use_json) {
12381 json_object_string_add(json_neigh, "peerGroup",
12382 p->group->name);
12383
12384 if (dn_flag[0]) {
12385 struct prefix prefix, *range = NULL;
12386
0154d8ce
DS
12387 if (sockunion2hostprefix(&(p->su), &prefix))
12388 range = peer_group_lookup_dynamic_neighbor_range(
12389 p->group, &prefix);
d62a17ae 12390
12391 if (range) {
67d7e256 12392 json_object_string_addf(
d62a17ae 12393 json_neigh,
67d7e256
DA
12394 "peerSubnetRangeGroup", "%pFX",
12395 range);
d62a17ae 12396 }
12397 }
12398 } else {
12399 vty_out(vty,
12400 " Member of peer-group %s for session parameters\n",
12401 p->group->name);
12402
12403 if (dn_flag[0]) {
12404 struct prefix prefix, *range = NULL;
12405
0154d8ce
DS
12406 if (sockunion2hostprefix(&(p->su), &prefix))
12407 range = peer_group_lookup_dynamic_neighbor_range(
12408 p->group, &prefix);
d62a17ae 12409
12410 if (range) {
d62a17ae 12411 vty_out(vty,
1b78780b
DL
12412 " Belongs to the subnet range group: %pFX\n",
12413 range);
d62a17ae 12414 }
12415 }
12416 }
12417 }
12418
12419 if (use_json) {
12420 /* Administrative shutdown. */
cb9196e7
DS
12421 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12422 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12423 json_object_boolean_true_add(json_neigh,
12424 "adminShutDown");
12425
12426 /* BGP Version. */
12427 json_object_int_add(json_neigh, "bgpVersion", 4);
c949c771
DA
12428 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12429 &p->remote_id);
12430 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12431 &bgp->router_id);
d62a17ae 12432
12433 /* Confederation */
12434 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12435 && bgp_confederation_peers_check(bgp, p->as))
12436 json_object_boolean_true_add(json_neigh,
12437 "nbrCommonAdmin");
12438
12439 /* Status. */
12440 json_object_string_add(
12441 json_neigh, "bgpState",
12442 lookup_msg(bgp_status_msg, p->status, NULL));
12443
feb17238 12444 if (peer_established(p)) {
d62a17ae 12445 time_t uptime;
d62a17ae 12446
12447 uptime = bgp_clock();
12448 uptime -= p->uptime;
d62a17ae 12449 epoch_tbuf = time(NULL) - uptime;
12450
d3c7efed
DS
12451 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12452 uptime * 1000);
d62a17ae 12453 json_object_string_add(json_neigh, "bgpTimerUpString",
12454 peer_uptime(p->uptime, timebuf,
12455 BGP_UPTIME_LEN, 0,
12456 NULL));
12457 json_object_int_add(json_neigh,
12458 "bgpTimerUpEstablishedEpoch",
12459 epoch_tbuf);
12460 }
12461
12462 else if (p->status == Active) {
12463 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12464 json_object_string_add(json_neigh, "bgpStateIs",
12465 "passive");
12466 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12467 json_object_string_add(json_neigh, "bgpStateIs",
12468 "passiveNSF");
12469 }
12470
12471 /* read timer */
12472 time_t uptime;
a2700b50 12473 struct tm tm;
d62a17ae 12474
12475 uptime = bgp_clock();
12476 uptime -= p->readtime;
a2700b50
MS
12477 gmtime_r(&uptime, &tm);
12478
d62a17ae 12479 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
12480 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12481 + (tm.tm_hour * 3600000));
d62a17ae 12482
12483 uptime = bgp_clock();
12484 uptime -= p->last_write;
a2700b50
MS
12485 gmtime_r(&uptime, &tm);
12486
d62a17ae 12487 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
12488 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12489 + (tm.tm_hour * 3600000));
d62a17ae 12490
12491 uptime = bgp_clock();
12492 uptime -= p->update_time;
a2700b50
MS
12493 gmtime_r(&uptime, &tm);
12494
d62a17ae 12495 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
12496 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12497 + (tm.tm_hour * 3600000));
d62a17ae 12498
12499 /* Configured timer values. */
12500 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12501 p->v_holdtime * 1000);
12502 json_object_int_add(json_neigh,
12503 "bgpTimerKeepAliveIntervalMsecs",
12504 p->v_keepalive * 1000);
d43114f3
DS
12505 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12506 json_object_int_add(json_neigh,
12507 "bgpTimerDelayOpenTimeMsecs",
12508 p->v_delayopen * 1000);
12509 }
12510
4ab46701
AR
12511 /* Configured and Synced tcp-mss value for peer */
12512 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12513 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12514 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12515 p->tcp_mss);
12516 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12517 sync_tcp_mss);
12518 }
12519
b90a8e13 12520 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12521 json_object_int_add(json_neigh,
12522 "bgpTimerConfiguredHoldTimeMsecs",
12523 p->holdtime * 1000);
12524 json_object_int_add(
12525 json_neigh,
12526 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12527 p->keepalive * 1000);
5d5393b9
DL
12528 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12529 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12530 json_object_int_add(json_neigh,
12531 "bgpTimerConfiguredHoldTimeMsecs",
12532 bgp->default_holdtime);
12533 json_object_int_add(
12534 json_neigh,
12535 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12536 bgp->default_keepalive);
d62a17ae 12537 }
d08c0c80
DA
12538
12539 /* Extended Optional Parameters Length for BGP OPEN Message */
12540 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12541 json_object_boolean_true_add(
12542 json_neigh, "extendedOptionalParametersLength");
12543 else
12544 json_object_boolean_false_add(
12545 json_neigh, "extendedOptionalParametersLength");
d62a17ae 12546 } else {
12547 /* Administrative shutdown. */
cb9196e7
DS
12548 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12549 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12550 vty_out(vty, " Administratively shut down\n");
12551
12552 /* BGP Version. */
12553 vty_out(vty, " BGP version 4");
0e38aeb4 12554 vty_out(vty, ", remote router ID %s",
d62a17ae 12555 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
12556 vty_out(vty, ", local router ID %s\n",
12557 inet_ntop(AF_INET, &bgp->router_id, buf1,
12558 sizeof(buf1)));
d62a17ae 12559
12560 /* Confederation */
12561 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12562 && bgp_confederation_peers_check(bgp, p->as))
12563 vty_out(vty,
12564 " Neighbor under common administration\n");
12565
12566 /* Status. */
12567 vty_out(vty, " BGP state = %s",
12568 lookup_msg(bgp_status_msg, p->status, NULL));
12569
feb17238 12570 if (peer_established(p))
d62a17ae 12571 vty_out(vty, ", up for %8s",
12572 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12573 0, NULL));
12574
12575 else if (p->status == Active) {
12576 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12577 vty_out(vty, " (passive)");
12578 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12579 vty_out(vty, " (NSF passive)");
12580 }
12581 vty_out(vty, "\n");
12582
12583 /* read timer */
12584 vty_out(vty, " Last read %s",
12585 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12586 NULL));
12587 vty_out(vty, ", Last write %s\n",
12588 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12589 NULL));
12590
12591 /* Configured timer values. */
12592 vty_out(vty,
12593 " Hold time is %d, keepalive interval is %d seconds\n",
12594 p->v_holdtime, p->v_keepalive);
b90a8e13 12595 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12596 vty_out(vty, " Configured hold time is %d",
12597 p->holdtime);
12598 vty_out(vty, ", keepalive interval is %d seconds\n",
12599 p->keepalive);
5d5393b9
DL
12600 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12601 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12602 vty_out(vty, " Configured hold time is %d",
12603 bgp->default_holdtime);
12604 vty_out(vty, ", keepalive interval is %d seconds\n",
12605 bgp->default_keepalive);
d62a17ae 12606 }
d43114f3
DS
12607 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12608 vty_out(vty,
12609 " Configured DelayOpenTime is %d seconds\n",
12610 p->delayopen);
4ab46701
AR
12611
12612 /* Configured and synced tcp-mss value for peer */
12613 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12614 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12615 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12616 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12617 }
d08c0c80
DA
12618
12619 /* Extended Optional Parameters Length for BGP OPEN Message */
12620 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12621 vty_out(vty,
12622 " Extended Optional Parameters Length is enabled\n");
d62a17ae 12623 }
12624 /* Capability. */
10711563
DA
12625 if (peer_established(p) &&
12626 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
12627 if (use_json) {
12628 json_object *json_cap = NULL;
d62a17ae 12629
10711563 12630 json_cap = json_object_new_object();
d62a17ae 12631
10711563
DA
12632 /* AS4 */
12633 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
12634 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12635 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
12636 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
ef56aee4 12637 json_object_string_add(
10711563 12638 json_cap, "4byteAs",
ef56aee4 12639 "advertisedAndReceived");
10711563
DA
12640 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
12641 json_object_string_add(json_cap,
12642 "4byteAs",
12643 "advertised");
12644 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12645 json_object_string_add(json_cap,
12646 "4byteAs",
12647 "received");
12648 }
ef56aee4 12649
10711563
DA
12650 /* Extended Message Support */
12651 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
12652 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
12653 json_object_string_add(json_cap,
12654 "extendedMessage",
12655 "advertisedAndReceived");
12656 else if (CHECK_FLAG(p->cap,
12657 PEER_CAP_EXTENDED_MESSAGE_ADV))
12658 json_object_string_add(json_cap,
12659 "extendedMessage",
12660 "advertised");
12661 else if (CHECK_FLAG(p->cap,
12662 PEER_CAP_EXTENDED_MESSAGE_RCV))
12663 json_object_string_add(json_cap,
12664 "extendedMessage",
12665 "received");
ef56aee4 12666
10711563
DA
12667 /* AddPath */
12668 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
12669 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
12670 json_object *json_add = NULL;
12671 const char *print_store;
d62a17ae 12672
10711563 12673 json_add = json_object_new_object();
d62a17ae 12674
10711563
DA
12675 FOREACH_AFI_SAFI (afi, safi) {
12676 json_object *json_sub = NULL;
12677 json_sub = json_object_new_object();
12678 print_store = get_afi_safi_str(
12679 afi, safi, true);
d62a17ae 12680
10711563
DA
12681 if (CHECK_FLAG(
12682 p->af_cap[afi][safi],
12683 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12684 CHECK_FLAG(
12685 p->af_cap[afi][safi],
12686 PEER_CAP_ADDPATH_AF_TX_RCV)) {
05c7a1cc
QY
12687 if (CHECK_FLAG(
12688 p->af_cap[afi]
12689 [safi],
10711563
DA
12690 PEER_CAP_ADDPATH_AF_TX_ADV) &&
12691 CHECK_FLAG(
05c7a1cc
QY
12692 p->af_cap[afi]
12693 [safi],
10711563
DA
12694 PEER_CAP_ADDPATH_AF_TX_RCV))
12695 json_object_boolean_true_add(
12696 json_sub,
12697 "txAdvertisedAndReceived");
12698 else if (
12699 CHECK_FLAG(
12700 p->af_cap[afi]
12701 [safi],
12702 PEER_CAP_ADDPATH_AF_TX_ADV))
12703 json_object_boolean_true_add(
12704 json_sub,
12705 "txAdvertised");
12706 else if (
12707 CHECK_FLAG(
12708 p->af_cap[afi]
12709 [safi],
12710 PEER_CAP_ADDPATH_AF_TX_RCV))
12711 json_object_boolean_true_add(
12712 json_sub,
12713 "txReceived");
12714 }
d62a17ae 12715
10711563
DA
12716 if (CHECK_FLAG(
12717 p->af_cap[afi][safi],
12718 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12719 CHECK_FLAG(
12720 p->af_cap[afi][safi],
12721 PEER_CAP_ADDPATH_AF_RX_RCV)) {
05c7a1cc
QY
12722 if (CHECK_FLAG(
12723 p->af_cap[afi]
12724 [safi],
10711563
DA
12725 PEER_CAP_ADDPATH_AF_RX_ADV) &&
12726 CHECK_FLAG(
12727 p->af_cap[afi]
12728 [safi],
12729 PEER_CAP_ADDPATH_AF_RX_RCV))
12730 json_object_boolean_true_add(
12731 json_sub,
12732 "rxAdvertisedAndReceived");
12733 else if (
12734 CHECK_FLAG(
12735 p->af_cap[afi]
12736 [safi],
12737 PEER_CAP_ADDPATH_AF_RX_ADV))
12738 json_object_boolean_true_add(
12739 json_sub,
12740 "rxAdvertised");
12741 else if (
12742 CHECK_FLAG(
12743 p->af_cap[afi]
12744 [safi],
12745 PEER_CAP_ADDPATH_AF_RX_RCV))
12746 json_object_boolean_true_add(
12747 json_sub,
12748 "rxReceived");
05c7a1cc
QY
12749 }
12750
10711563
DA
12751 if (CHECK_FLAG(
12752 p->af_cap[afi][safi],
12753 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12754 CHECK_FLAG(
12755 p->af_cap[afi][safi],
12756 PEER_CAP_ADDPATH_AF_TX_RCV) ||
12757 CHECK_FLAG(
12758 p->af_cap[afi][safi],
12759 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12760 CHECK_FLAG(
12761 p->af_cap[afi][safi],
12762 PEER_CAP_ADDPATH_AF_RX_RCV))
12763 json_object_object_add(
12764 json_add, print_store,
12765 json_sub);
12766 else
12767 json_object_free(json_sub);
d62a17ae 12768 }
12769
10711563
DA
12770 json_object_object_add(json_cap, "addPath",
12771 json_add);
12772 }
d62a17ae 12773
10711563
DA
12774 /* Dynamic */
12775 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
12776 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
12777 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
12778 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
12779 json_object_string_add(
12780 json_cap, "dynamic",
12781 "advertisedAndReceived");
12782 else if (CHECK_FLAG(p->cap,
12783 PEER_CAP_DYNAMIC_ADV))
12784 json_object_string_add(json_cap,
12785 "dynamic",
12786 "advertised");
12787 else if (CHECK_FLAG(p->cap,
12788 PEER_CAP_DYNAMIC_RCV))
12789 json_object_string_add(json_cap,
12790 "dynamic",
12791 "received");
12792 }
d62a17ae 12793
10711563
DA
12794 /* Extended nexthop */
12795 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
12796 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12797 json_object *json_nxt = NULL;
12798 const char *print_store;
d62a17ae 12799
d62a17ae 12800
10711563
DA
12801 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
12802 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12803 json_object_string_add(
12804 json_cap, "extendedNexthop",
12805 "advertisedAndReceived");
12806 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
12807 json_object_string_add(
12808 json_cap, "extendedNexthop",
12809 "advertised");
12810 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12811 json_object_string_add(
12812 json_cap, "extendedNexthop",
12813 "received");
d62a17ae 12814
10711563
DA
12815 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
12816 json_nxt = json_object_new_object();
d62a17ae 12817
10711563
DA
12818 for (safi = SAFI_UNICAST;
12819 safi < SAFI_MAX; safi++) {
12820 if (CHECK_FLAG(
12821 p->af_cap[AFI_IP]
12822 [safi],
12823 PEER_CAP_ENHE_AF_RCV)) {
12824 print_store =
12825 get_afi_safi_str(
d62a17ae 12826 AFI_IP,
10711563
DA
12827 safi,
12828 true);
12829 json_object_string_add(
12830 json_nxt,
12831 print_store,
12832 "recieved"); /* misspelled for compatibility */
d62a17ae 12833 }
d62a17ae 12834 }
10711563
DA
12835 json_object_object_add(
12836 json_cap,
12837 "extendedNexthopFamililesByPeer",
12838 json_nxt);
d62a17ae 12839 }
10711563 12840 }
d62a17ae 12841
10711563
DA
12842 /* Long-lived Graceful Restart */
12843 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
12844 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
12845 json_object *json_llgr = NULL;
12846 const char *afi_safi_str;
8606be87 12847
10711563
DA
12848 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
12849 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12850 json_object_string_add(
12851 json_cap,
12852 "longLivedGracefulRestart",
12853 "advertisedAndReceived");
12854 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
12855 json_object_string_add(
12856 json_cap,
12857 "longLivedGracefulRestart",
12858 "advertised");
12859 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12860 json_object_string_add(
12861 json_cap,
12862 "longLivedGracefulRestart",
12863 "received");
8606be87 12864
10711563
DA
12865 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
12866 json_llgr = json_object_new_object();
8606be87 12867
10711563
DA
12868 FOREACH_AFI_SAFI (afi, safi) {
12869 if (CHECK_FLAG(
12870 p->af_cap[afi]
12871 [safi],
12872 PEER_CAP_ENHE_AF_RCV)) {
12873 afi_safi_str =
12874 get_afi_safi_str(
8606be87
DA
12875 afi,
12876 safi,
12877 true);
10711563
DA
12878 json_object_string_add(
12879 json_llgr,
12880 afi_safi_str,
12881 "received");
8606be87 12882 }
8606be87 12883 }
10711563
DA
12884 json_object_object_add(
12885 json_cap,
12886 "longLivedGracefulRestartByPeer",
12887 json_llgr);
8606be87 12888 }
10711563 12889 }
8606be87 12890
10711563
DA
12891 /* Route Refresh */
12892 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
12893 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
12894 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
12895 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
12896 (CHECK_FLAG(p->cap,
12897 PEER_CAP_REFRESH_NEW_RCV) ||
12898 CHECK_FLAG(p->cap,
12899 PEER_CAP_REFRESH_OLD_RCV))) {
12900 if (CHECK_FLAG(
12901 p->cap,
12902 PEER_CAP_REFRESH_OLD_RCV) &&
12903 CHECK_FLAG(
12904 p->cap,
12905 PEER_CAP_REFRESH_NEW_RCV))
12906 json_object_string_add(
12907 json_cap,
12908 "routeRefresh",
12909 "advertisedAndReceivedOldNew");
12910 else {
d62a17ae 12911 if (CHECK_FLAG(
12912 p->cap,
10711563 12913 PEER_CAP_REFRESH_OLD_RCV))
d62a17ae 12914 json_object_string_add(
12915 json_cap,
12916 "routeRefresh",
10711563
DA
12917 "advertisedAndReceivedOld");
12918 else
12919 json_object_string_add(
12920 json_cap,
12921 "routeRefresh",
12922 "advertisedAndReceivedNew");
d62a17ae 12923 }
10711563
DA
12924 } else if (CHECK_FLAG(p->cap,
12925 PEER_CAP_REFRESH_ADV))
12926 json_object_string_add(json_cap,
12927 "routeRefresh",
12928 "advertised");
12929 else if (CHECK_FLAG(p->cap,
12930 PEER_CAP_REFRESH_NEW_RCV) ||
12931 CHECK_FLAG(p->cap,
12932 PEER_CAP_REFRESH_OLD_RCV))
12933 json_object_string_add(json_cap,
12934 "routeRefresh",
12935 "received");
12936 }
d62a17ae 12937
10711563
DA
12938 /* Enhanced Route Refresh */
12939 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
12940 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
12941 if (CHECK_FLAG(p->cap,
12942 PEER_CAP_ENHANCED_RR_ADV) &&
12943 CHECK_FLAG(p->cap,
12944 PEER_CAP_ENHANCED_RR_RCV))
d77114b7 12945 json_object_string_add(
10711563
DA
12946 json_cap,
12947 "enhancedRouteRefresh",
12948 "advertisedAndReceived");
12949 else if (CHECK_FLAG(p->cap,
12950 PEER_CAP_ENHANCED_RR_ADV))
d77114b7 12951 json_object_string_add(
10711563
DA
12952 json_cap,
12953 "enhancedRouteRefresh",
12954 "advertised");
12955 else if (CHECK_FLAG(p->cap,
9af52ccf 12956 PEER_CAP_ENHANCED_RR_RCV))
10711563
DA
12957 json_object_string_add(
12958 json_cap,
12959 "enhancedRouteRefresh",
12960 "received");
12961 }
d77114b7 12962
10711563
DA
12963 /* Multiprotocol Extensions */
12964 json_object *json_multi = NULL;
d77114b7 12965
10711563 12966 json_multi = json_object_new_object();
d77114b7 12967
10711563
DA
12968 FOREACH_AFI_SAFI (afi, safi) {
12969 if (p->afc_adv[afi][safi] ||
12970 p->afc_recv[afi][safi]) {
12971 json_object *json_exten = NULL;
12972 json_exten = json_object_new_object();
12973
12974 if (p->afc_adv[afi][safi] &&
12975 p->afc_recv[afi][safi])
12976 json_object_boolean_true_add(
12977 json_exten,
9af52ccf 12978 "advertisedAndReceived");
10711563
DA
12979 else if (p->afc_adv[afi][safi])
12980 json_object_boolean_true_add(
12981 json_exten,
9af52ccf 12982 "advertised");
10711563
DA
12983 else if (p->afc_recv[afi][safi])
12984 json_object_boolean_true_add(
12985 json_exten, "received");
9af52ccf 12986
10711563
DA
12987 json_object_object_add(
12988 json_multi,
12989 get_afi_safi_str(afi, safi,
12990 true),
12991 json_exten);
12992 }
12993 }
12994 json_object_object_add(json_cap,
12995 "multiprotocolExtensions",
12996 json_multi);
d62a17ae 12997
10711563
DA
12998 /* Hostname capabilities */
12999 json_object *json_hname = NULL;
d62a17ae 13000
10711563 13001 json_hname = json_object_new_object();
d62a17ae 13002
10711563
DA
13003 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13004 json_object_string_add(
13005 json_hname, "advHostName",
13006 bgp->peer_self->hostname
13007 ? bgp->peer_self->hostname
13008 : "n/a");
13009 json_object_string_add(
13010 json_hname, "advDomainName",
13011 bgp->peer_self->domainname
13012 ? bgp->peer_self->domainname
13013 : "n/a");
13014 }
d77114b7 13015
d77114b7 13016
10711563
DA
13017 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13018 json_object_string_add(
13019 json_hname, "rcvHostName",
13020 p->hostname ? p->hostname : "n/a");
13021 json_object_string_add(
13022 json_hname, "rcvDomainName",
13023 p->domainname ? p->domainname : "n/a");
13024 }
d77114b7 13025
10711563
DA
13026 json_object_object_add(json_cap, "hostName",
13027 json_hname);
d77114b7 13028
10711563
DA
13029 /* Gracefull Restart */
13030 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13031 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13032 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13033 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
d77114b7 13034 json_object_string_add(
10711563
DA
13035 json_cap, "gracefulRestart",
13036 "advertisedAndReceived");
13037 else if (CHECK_FLAG(p->cap,
13038 PEER_CAP_RESTART_ADV))
d77114b7 13039 json_object_string_add(
10711563
DA
13040 json_cap,
13041 "gracefulRestartCapability",
13042 "advertised");
13043 else if (CHECK_FLAG(p->cap,
13044 PEER_CAP_RESTART_RCV))
13045 json_object_string_add(
13046 json_cap,
13047 "gracefulRestartCapability",
13048 "received");
d77114b7 13049
10711563
DA
13050 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13051 int restart_af_count = 0;
13052 json_object *json_restart = NULL;
13053 json_restart = json_object_new_object();
d62a17ae 13054
10711563
DA
13055 json_object_int_add(
13056 json_cap,
13057 "gracefulRestartRemoteTimerMsecs",
13058 p->v_gr_restart * 1000);
d62a17ae 13059
10711563 13060 FOREACH_AFI_SAFI (afi, safi) {
05c7a1cc
QY
13061 if (CHECK_FLAG(
13062 p->af_cap[afi]
13063 [safi],
10711563
DA
13064 PEER_CAP_RESTART_AF_RCV)) {
13065 json_object *json_sub =
13066 NULL;
13067 json_sub =
13068 json_object_new_object();
d62a17ae 13069
05c7a1cc
QY
13070 if (CHECK_FLAG(
13071 p->af_cap
13072 [afi]
13073 [safi],
10711563
DA
13074 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13075 json_object_boolean_true_add(
13076 json_sub,
13077 "preserved");
13078 restart_af_count++;
d62a17ae 13079 json_object_object_add(
10711563
DA
13080 json_restart,
13081 get_afi_safi_str(
13082 afi,
13083 safi,
13084 true),
13085 json_sub);
d62a17ae 13086 }
d62a17ae 13087 }
10711563
DA
13088 if (!restart_af_count) {
13089 json_object_string_add(
13090 json_cap,
13091 "addressFamiliesByPeer",
13092 "none");
13093 json_object_free(json_restart);
13094 } else
13095 json_object_object_add(
13096 json_cap,
13097 "addressFamiliesByPeer",
13098 json_restart);
d62a17ae 13099 }
10711563
DA
13100 }
13101 json_object_object_add(
13102 json_neigh, "neighborCapabilities", json_cap);
13103 } else {
13104 vty_out(vty, " Neighbor capabilities:\n");
13105
13106 /* AS4 */
13107 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13108 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13109 vty_out(vty, " 4 Byte AS:");
13110 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13111 vty_out(vty, " advertised");
13112 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13113 vty_out(vty, " %sreceived",
13114 CHECK_FLAG(p->cap,
13115 PEER_CAP_AS4_ADV)
13116 ? "and "
13117 : "");
13118 vty_out(vty, "\n");
13119 }
d62a17ae 13120
10711563
DA
13121 /* Extended Message Support */
13122 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13123 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13124 vty_out(vty, " Extended Message:");
ef56aee4 13125 if (CHECK_FLAG(p->cap,
10711563
DA
13126 PEER_CAP_EXTENDED_MESSAGE_ADV))
13127 vty_out(vty, " advertised");
13128 if (CHECK_FLAG(p->cap,
13129 PEER_CAP_EXTENDED_MESSAGE_RCV))
13130 vty_out(vty, " %sreceived",
13131 CHECK_FLAG(
13132 p->cap,
13133 PEER_CAP_EXTENDED_MESSAGE_ADV)
13134 ? "and "
13135 : "");
13136 vty_out(vty, "\n");
13137 }
d62a17ae 13138
10711563
DA
13139 /* AddPath */
13140 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13141 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13142 vty_out(vty, " AddPath:\n");
d62a17ae 13143
10711563 13144 FOREACH_AFI_SAFI (afi, safi) {
ef56aee4 13145 if (CHECK_FLAG(
10711563
DA
13146 p->af_cap[afi][safi],
13147 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13148 CHECK_FLAG(
13149 p->af_cap[afi][safi],
13150 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13151 vty_out(vty, " %s: TX ",
13152 get_afi_safi_str(
13153 afi, safi,
13154 false));
ef56aee4 13155
10711563
DA
13156 if (CHECK_FLAG(
13157 p->af_cap[afi]
13158 [safi],
13159 PEER_CAP_ADDPATH_AF_TX_ADV))
13160 vty_out(vty,
13161 "advertised");
d62a17ae 13162
05c7a1cc
QY
13163 if (CHECK_FLAG(
13164 p->af_cap[afi]
13165 [safi],
10711563 13166 PEER_CAP_ADDPATH_AF_TX_RCV))
05c7a1cc 13167 vty_out(vty,
10711563
DA
13168 "%sreceived",
13169 CHECK_FLAG(
13170 p->af_cap
13171 [afi]
13172 [safi],
13173 PEER_CAP_ADDPATH_AF_TX_ADV)
13174 ? " and "
13175 : "");
05c7a1cc 13176
10711563
DA
13177 vty_out(vty, "\n");
13178 }
d62a17ae 13179
9af52ccf 13180 if (CHECK_FLAG(
10711563
DA
13181 p->af_cap[afi][safi],
13182 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13183 CHECK_FLAG(
13184 p->af_cap[afi][safi],
13185 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13186 vty_out(vty, " %s: RX ",
5cb5f4d0 13187 get_afi_safi_str(
10711563
DA
13188 afi, safi,
13189 false));
d62a17ae 13190
05c7a1cc
QY
13191 if (CHECK_FLAG(
13192 p->af_cap[afi]
13193 [safi],
10711563 13194 PEER_CAP_ADDPATH_AF_RX_ADV))
05c7a1cc 13195 vty_out(vty,
10711563 13196 "advertised");
d62a17ae 13197
10711563
DA
13198 if (CHECK_FLAG(
13199 p->af_cap[afi]
13200 [safi],
13201 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc 13202 vty_out(vty,
10711563
DA
13203 "%sreceived",
13204 CHECK_FLAG(
13205 p->af_cap
13206 [afi]
13207 [safi],
13208 PEER_CAP_ADDPATH_AF_RX_ADV)
13209 ? " and "
05c7a1cc 13210 : "");
d62a17ae 13211
05c7a1cc 13212 vty_out(vty, "\n");
05c7a1cc 13213 }
d62a17ae 13214 }
10711563 13215 }
d62a17ae 13216
10711563
DA
13217 /* Dynamic */
13218 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13219 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13220 vty_out(vty, " Dynamic:");
13221 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13222 vty_out(vty, " advertised");
13223 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13224 vty_out(vty, " %sreceived",
13225 CHECK_FLAG(p->cap,
13226 PEER_CAP_DYNAMIC_ADV)
13227 ? "and "
13228 : "");
13229 vty_out(vty, "\n");
13230 }
d62a17ae 13231
10711563
DA
13232 /* Extended nexthop */
13233 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13234 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13235 vty_out(vty, " Extended nexthop:");
13236 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13237 vty_out(vty, " advertised");
13238 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13239 vty_out(vty, " %sreceived",
13240 CHECK_FLAG(p->cap,
13241 PEER_CAP_ENHE_ADV)
13242 ? "and "
13243 : "");
13244 vty_out(vty, "\n");
d62a17ae 13245
10711563 13246 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
57f7feb6 13247 vty_out(vty,
10711563
DA
13248 " Address families by peer:\n ");
13249 for (safi = SAFI_UNICAST;
13250 safi < SAFI_MAX; safi++)
13251 if (CHECK_FLAG(
13252 p->af_cap[AFI_IP]
13253 [safi],
13254 PEER_CAP_ENHE_AF_RCV))
13255 vty_out(vty,
13256 " %s\n",
13257 get_afi_safi_str(
13258 AFI_IP,
13259 safi,
13260 false));
d62a17ae 13261 }
10711563 13262 }
d62a17ae 13263
10711563
DA
13264 /* Long-lived Graceful Restart */
13265 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13266 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13267 vty_out(vty,
13268 " Long-lived Graceful Restart:");
13269 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13270 vty_out(vty, " advertised");
13271 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13272 vty_out(vty, " %sreceived",
13273 CHECK_FLAG(p->cap,
13274 PEER_CAP_LLGR_ADV)
13275 ? "and "
13276 : "");
13277 vty_out(vty, "\n");
8606be87 13278
10711563 13279 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
57f7feb6 13280 vty_out(vty,
10711563
DA
13281 " Address families by peer:\n");
13282 FOREACH_AFI_SAFI (afi, safi)
13283 if (CHECK_FLAG(
13284 p->af_cap[afi]
13285 [safi],
13286 PEER_CAP_LLGR_AF_RCV))
13287 vty_out(vty,
13288 " %s\n",
13289 get_afi_safi_str(
13290 afi,
13291 safi,
13292 false));
8606be87 13293 }
10711563 13294 }
8606be87 13295
10711563
DA
13296 /* Route Refresh */
13297 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13298 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13299 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13300 vty_out(vty, " Route refresh:");
13301 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13302 vty_out(vty, " advertised");
13303 if (CHECK_FLAG(p->cap,
13304 PEER_CAP_REFRESH_NEW_RCV) ||
13305 CHECK_FLAG(p->cap,
13306 PEER_CAP_REFRESH_OLD_RCV))
13307 vty_out(vty, " %sreceived(%s)",
13308 CHECK_FLAG(p->cap,
13309 PEER_CAP_REFRESH_ADV)
13310 ? "and "
13311 : "",
13312 (CHECK_FLAG(
13313 p->cap,
13314 PEER_CAP_REFRESH_OLD_RCV) &&
13315 CHECK_FLAG(
13316 p->cap,
13317 PEER_CAP_REFRESH_NEW_RCV))
13318 ? "old & new"
13319 : CHECK_FLAG(
13320 p->cap,
13321 PEER_CAP_REFRESH_OLD_RCV)
13322 ? "old"
13323 : "new");
d62a17ae 13324
d77114b7 13325 vty_out(vty, "\n");
10711563 13326 }
d62a17ae 13327
10711563
DA
13328 /* Enhanced Route Refresh */
13329 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13330 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13331 vty_out(vty, " Enhanced Route Refresh:");
13332 if (CHECK_FLAG(p->cap,
13333 PEER_CAP_ENHANCED_RR_ADV))
13334 vty_out(vty, " advertised");
13335 if (CHECK_FLAG(p->cap,
13336 PEER_CAP_ENHANCED_RR_RCV))
13337 vty_out(vty, " %sreceived",
13338 CHECK_FLAG(p->cap,
13339 PEER_CAP_REFRESH_ADV)
13340 ? "and "
13341 : "");
13342 vty_out(vty, "\n");
13343 }
13344
13345 /* Multiprotocol Extensions */
13346 FOREACH_AFI_SAFI (afi, safi)
13347 if (p->afc_adv[afi][safi] ||
13348 p->afc_recv[afi][safi]) {
13349 vty_out(vty, " Address Family %s:",
13350 get_afi_safi_str(afi, safi,
13351 false));
13352 if (p->afc_adv[afi][safi])
9af52ccf 13353 vty_out(vty, " advertised");
10711563 13354 if (p->afc_recv[afi][safi])
9af52ccf 13355 vty_out(vty, " %sreceived",
10711563 13356 p->afc_adv[afi][safi]
9af52ccf
DA
13357 ? "and "
13358 : "");
13359 vty_out(vty, "\n");
13360 }
13361
10711563
DA
13362 /* Hostname capability */
13363 vty_out(vty, " Hostname Capability:");
d62a17ae 13364
10711563
DA
13365 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13366 vty_out(vty,
13367 " advertised (name: %s,domain name: %s)",
13368 bgp->peer_self->hostname
13369 ? bgp->peer_self->hostname
13370 : "n/a",
13371 bgp->peer_self->domainname
13372 ? bgp->peer_self->domainname
13373 : "n/a");
13374 } else {
13375 vty_out(vty, " not advertised");
13376 }
d77114b7 13377
10711563
DA
13378 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13379 vty_out(vty,
13380 " received (name: %s,domain name: %s)",
13381 p->hostname ? p->hostname : "n/a",
13382 p->domainname ? p->domainname : "n/a");
13383 } else {
13384 vty_out(vty, " not received");
d62a17ae 13385 }
d62a17ae 13386
10711563 13387 vty_out(vty, "\n");
d77114b7 13388
10711563
DA
13389 /* Graceful Restart */
13390 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13391 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13392 vty_out(vty,
13393 " Graceful Restart Capability:");
13394 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13395 vty_out(vty, " advertised");
13396 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13397 vty_out(vty, " %sreceived",
13398 CHECK_FLAG(p->cap,
13399 PEER_CAP_RESTART_ADV)
13400 ? "and "
13401 : "");
d77114b7
MK
13402 vty_out(vty, "\n");
13403
10711563
DA
13404 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13405 int restart_af_count = 0;
d62a17ae 13406
10711563
DA
13407 vty_out(vty,
13408 " Remote Restart timer is %d seconds\n",
13409 p->v_gr_restart);
13410 vty_out(vty,
13411 " Address families by peer:\n ");
d62a17ae 13412
10711563
DA
13413 FOREACH_AFI_SAFI (afi, safi)
13414 if (CHECK_FLAG(
13415 p->af_cap[afi]
13416 [safi],
13417 PEER_CAP_RESTART_AF_RCV)) {
13418 vty_out(vty, "%s%s(%s)",
13419 restart_af_count
13420 ? ", "
13421 : "",
13422 get_afi_safi_str(
13423 afi,
13424 safi,
13425 false),
13426 CHECK_FLAG(
13427 p->af_cap
13428 [afi]
13429 [safi],
13430 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13431 ? "preserved"
13432 : "not preserved");
13433 restart_af_count++;
13434 }
13435 if (!restart_af_count)
13436 vty_out(vty, "none");
13437 vty_out(vty, "\n");
13438 }
13439 } /* Gracefull Restart */
d62a17ae 13440 }
13441 }
13442
13443 /* graceful restart information */
10711563
DA
13444 json_object *json_grace = NULL;
13445 json_object *json_grace_send = NULL;
13446 json_object *json_grace_recv = NULL;
13447 int eor_send_af_count = 0;
13448 int eor_receive_af_count = 0;
d62a17ae 13449
10711563
DA
13450 if (use_json) {
13451 json_grace = json_object_new_object();
13452 json_grace_send = json_object_new_object();
13453 json_grace_recv = json_object_new_object();
13454
13455 if ((peer_established(p)) &&
13456 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13457 FOREACH_AFI_SAFI (afi, safi) {
13458 if (CHECK_FLAG(p->af_sflags[afi][safi],
13459 PEER_STATUS_EOR_SEND)) {
13460 json_object_boolean_true_add(
13461 json_grace_send,
13462 get_afi_safi_str(afi, safi,
13463 true));
13464 eor_send_af_count++;
d62a17ae 13465 }
10711563
DA
13466 }
13467 FOREACH_AFI_SAFI (afi, safi) {
13468 if (CHECK_FLAG(p->af_sflags[afi][safi],
13469 PEER_STATUS_EOR_RECEIVED)) {
13470 json_object_boolean_true_add(
13471 json_grace_recv,
13472 get_afi_safi_str(afi, safi,
13473 true));
13474 eor_receive_af_count++;
d62a17ae 13475 }
13476 }
10711563
DA
13477 }
13478 json_object_object_add(json_grace, "endOfRibSend",
13479 json_grace_send);
13480 json_object_object_add(json_grace, "endOfRibRecv",
13481 json_grace_recv);
d62a17ae 13482
d62a17ae 13483
10711563
DA
13484 if (p->t_gr_restart)
13485 json_object_int_add(
13486 json_grace, "gracefulRestartTimerMsecs",
13487 thread_timer_remain_second(p->t_gr_restart) *
13488 1000);
2986cac2 13489
10711563
DA
13490 if (p->t_gr_stale)
13491 json_object_int_add(
13492 json_grace, "gracefulStalepathTimerMsecs",
13493 thread_timer_remain_second(p->t_gr_stale) *
13494 1000);
13495 /* more gr info in new format */
13496 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13497 json_object_object_add(json_neigh, "gracefulRestartInfo",
13498 json_grace);
13499 } else {
13500 vty_out(vty, " Graceful restart information:\n");
13501 if ((peer_established(p)) &&
13502 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13503
13504 vty_out(vty, " End-of-RIB send: ");
13505 FOREACH_AFI_SAFI (afi, safi) {
13506 if (CHECK_FLAG(p->af_sflags[afi][safi],
13507 PEER_STATUS_EOR_SEND)) {
13508 vty_out(vty, "%s%s",
13509 eor_send_af_count ? ", " : "",
13510 get_afi_safi_str(afi, safi,
13511 false));
13512 eor_send_af_count++;
d62a17ae 13513 }
10711563
DA
13514 }
13515 vty_out(vty, "\n");
13516 vty_out(vty, " End-of-RIB received: ");
13517 FOREACH_AFI_SAFI (afi, safi) {
13518 if (CHECK_FLAG(p->af_sflags[afi][safi],
13519 PEER_STATUS_EOR_RECEIVED)) {
13520 vty_out(vty, "%s%s",
13521 eor_receive_af_count ? ", "
13522 : "",
13523 get_afi_safi_str(afi, safi,
13524 false));
13525 eor_receive_af_count++;
d62a17ae 13526 }
d62a17ae 13527 }
10711563
DA
13528 vty_out(vty, "\n");
13529 }
d62a17ae 13530
10711563
DA
13531 if (p->t_gr_restart)
13532 vty_out(vty,
13533 " The remaining time of restart timer is %ld\n",
13534 thread_timer_remain_second(p->t_gr_restart));
d62a17ae 13535
10711563
DA
13536 if (p->t_gr_stale)
13537 vty_out(vty,
13538 " The remaining time of stalepath timer is %ld\n",
13539 thread_timer_remain_second(p->t_gr_stale));
2986cac2 13540
10711563
DA
13541 /* more gr info in new format */
13542 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13543 }
2986cac2 13544
d62a17ae 13545 if (use_json) {
13546 json_object *json_stat = NULL;
13547 json_stat = json_object_new_object();
13548 /* Packet counts. */
43aa5965
QY
13549
13550 atomic_size_t outq_count, inq_count;
13551 outq_count = atomic_load_explicit(&p->obuf->count,
13552 memory_order_relaxed);
13553 inq_count = atomic_load_explicit(&p->ibuf->count,
13554 memory_order_relaxed);
13555
13556 json_object_int_add(json_stat, "depthInq",
13557 (unsigned long)inq_count);
d62a17ae 13558 json_object_int_add(json_stat, "depthOutq",
43aa5965 13559 (unsigned long)outq_count);
0112e9e0
QY
13560 json_object_int_add(json_stat, "opensSent",
13561 atomic_load_explicit(&p->open_out,
13562 memory_order_relaxed));
13563 json_object_int_add(json_stat, "opensRecv",
13564 atomic_load_explicit(&p->open_in,
13565 memory_order_relaxed));
d62a17ae 13566 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
13567 atomic_load_explicit(&p->notify_out,
13568 memory_order_relaxed));
d62a17ae 13569 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
13570 atomic_load_explicit(&p->notify_in,
13571 memory_order_relaxed));
13572 json_object_int_add(json_stat, "updatesSent",
13573 atomic_load_explicit(&p->update_out,
13574 memory_order_relaxed));
13575 json_object_int_add(json_stat, "updatesRecv",
13576 atomic_load_explicit(&p->update_in,
13577 memory_order_relaxed));
d62a17ae 13578 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
13579 atomic_load_explicit(&p->keepalive_out,
13580 memory_order_relaxed));
d62a17ae 13581 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
13582 atomic_load_explicit(&p->keepalive_in,
13583 memory_order_relaxed));
d62a17ae 13584 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
13585 atomic_load_explicit(&p->refresh_out,
13586 memory_order_relaxed));
d62a17ae 13587 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
13588 atomic_load_explicit(&p->refresh_in,
13589 memory_order_relaxed));
d62a17ae 13590 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
13591 atomic_load_explicit(&p->dynamic_cap_out,
13592 memory_order_relaxed));
d62a17ae 13593 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
13594 atomic_load_explicit(&p->dynamic_cap_in,
13595 memory_order_relaxed));
13596 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13597 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 13598 json_object_object_add(json_neigh, "messageStats", json_stat);
13599 } else {
cb93e0a2
IS
13600 atomic_size_t outq_count, inq_count, open_out, open_in,
13601 notify_out, notify_in, update_out, update_in,
13602 keepalive_out, keepalive_in, refresh_out, refresh_in,
13603 dynamic_cap_out, dynamic_cap_in;
43aa5965
QY
13604 outq_count = atomic_load_explicit(&p->obuf->count,
13605 memory_order_relaxed);
13606 inq_count = atomic_load_explicit(&p->ibuf->count,
13607 memory_order_relaxed);
cb93e0a2
IS
13608 open_out = atomic_load_explicit(&p->open_out,
13609 memory_order_relaxed);
13610 open_in =
13611 atomic_load_explicit(&p->open_in, memory_order_relaxed);
13612 notify_out = atomic_load_explicit(&p->notify_out,
13613 memory_order_relaxed);
13614 notify_in = atomic_load_explicit(&p->notify_in,
13615 memory_order_relaxed);
13616 update_out = atomic_load_explicit(&p->update_out,
13617 memory_order_relaxed);
13618 update_in = atomic_load_explicit(&p->update_in,
13619 memory_order_relaxed);
13620 keepalive_out = atomic_load_explicit(&p->keepalive_out,
13621 memory_order_relaxed);
13622 keepalive_in = atomic_load_explicit(&p->keepalive_in,
13623 memory_order_relaxed);
13624 refresh_out = atomic_load_explicit(&p->refresh_out,
13625 memory_order_relaxed);
13626 refresh_in = atomic_load_explicit(&p->refresh_in,
13627 memory_order_relaxed);
13628 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
13629 memory_order_relaxed);
13630 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
13631 memory_order_relaxed);
43aa5965 13632
d62a17ae 13633 /* Packet counts. */
13634 vty_out(vty, " Message statistics:\n");
43aa5965
QY
13635 vty_out(vty, " Inq depth is %zu\n", inq_count);
13636 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 13637 vty_out(vty, " Sent Rcvd\n");
cb93e0a2
IS
13638 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
13639 open_in);
13640 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
13641 notify_in);
13642 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
13643 update_in);
13644 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
13645 keepalive_in);
13646 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
13647 refresh_in);
13648 vty_out(vty, " Capability: %10zu %10zu\n",
13649 dynamic_cap_out, dynamic_cap_in);
13650 vty_out(vty, " Total: %10u %10u\n",
13651 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
d62a17ae 13652 }
13653
13654 if (use_json) {
13655 /* advertisement-interval */
13656 json_object_int_add(json_neigh,
13657 "minBtwnAdvertisementRunsTimerMsecs",
13658 p->v_routeadv * 1000);
13659
13660 /* Update-source. */
13661 if (p->update_if || p->update_source) {
13662 if (p->update_if)
13663 json_object_string_add(json_neigh,
13664 "updateSource",
13665 p->update_if);
13666 else if (p->update_source)
13667 json_object_string_add(
13668 json_neigh, "updateSource",
13669 sockunion2str(p->update_source, buf1,
13670 SU_ADDRSTRLEN));
13671 }
13672 } else {
13673 /* advertisement-interval */
13674 vty_out(vty,
13675 " Minimum time between advertisement runs is %d seconds\n",
13676 p->v_routeadv);
13677
13678 /* Update-source. */
13679 if (p->update_if || p->update_source) {
13680 vty_out(vty, " Update source is ");
13681 if (p->update_if)
13682 vty_out(vty, "%s", p->update_if);
13683 else if (p->update_source)
13684 vty_out(vty, "%s",
13685 sockunion2str(p->update_source, buf1,
13686 SU_ADDRSTRLEN));
13687 vty_out(vty, "\n");
13688 }
13689
13690 vty_out(vty, "\n");
13691 }
13692
13693 /* Address Family Information */
13694 json_object *json_hold = NULL;
13695
13696 if (use_json)
13697 json_hold = json_object_new_object();
13698
05c7a1cc
QY
13699 FOREACH_AFI_SAFI (afi, safi)
13700 if (p->afc[afi][safi])
13701 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13702 json_hold);
d62a17ae 13703
13704 if (use_json) {
13705 json_object_object_add(json_neigh, "addressFamilyInfo",
13706 json_hold);
13707 json_object_int_add(json_neigh, "connectionsEstablished",
13708 p->established);
13709 json_object_int_add(json_neigh, "connectionsDropped",
13710 p->dropped);
13711 } else
13712 vty_out(vty, " Connections established %d; dropped %d\n",
13713 p->established, p->dropped);
13714
13715 if (!p->last_reset) {
13716 if (use_json)
13717 json_object_string_add(json_neigh, "lastReset",
13718 "never");
13719 else
13720 vty_out(vty, " Last reset never\n");
13721 } else {
13722 if (use_json) {
13723 time_t uptime;
a2700b50 13724 struct tm tm;
d62a17ae 13725
13726 uptime = bgp_clock();
13727 uptime -= p->resettime;
a2700b50
MS
13728 gmtime_r(&uptime, &tm);
13729
d62a17ae 13730 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
13731 (tm.tm_sec * 1000)
13732 + (tm.tm_min * 60000)
13733 + (tm.tm_hour * 3600000));
3577f1c5 13734 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 13735 } else {
13736 vty_out(vty, " Last reset %s, ",
13737 peer_uptime(p->resettime, timebuf,
13738 BGP_UPTIME_LEN, 0, NULL));
13739
3577f1c5 13740 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 13741 if (p->last_reset_cause_size) {
13742 msg = p->last_reset_cause;
13743 vty_out(vty,
13744 " Message received that caused BGP to send a NOTIFICATION:\n ");
13745 for (i = 1; i <= p->last_reset_cause_size;
13746 i++) {
13747 vty_out(vty, "%02X", *msg++);
13748
13749 if (i != p->last_reset_cause_size) {
13750 if (i % 16 == 0) {
13751 vty_out(vty, "\n ");
13752 } else if (i % 4 == 0) {
13753 vty_out(vty, " ");
13754 }
13755 }
13756 }
13757 vty_out(vty, "\n");
13758 }
13759 }
13760 }
13761
13762 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13763 if (use_json)
13764 json_object_boolean_true_add(json_neigh,
13765 "prefixesConfigExceedMax");
13766 else
13767 vty_out(vty,
13768 " Peer had exceeded the max. no. of prefixes configured.\n");
13769
13770 if (p->t_pmax_restart) {
13771 if (use_json) {
13772 json_object_boolean_true_add(
13773 json_neigh, "reducePrefixNumFrom");
13774 json_object_int_add(json_neigh,
13775 "restartInTimerMsec",
13776 thread_timer_remain_second(
13777 p->t_pmax_restart)
13778 * 1000);
13779 } else
13780 vty_out(vty,
13781 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
13782 p->host, thread_timer_remain_second(
13783 p->t_pmax_restart));
d62a17ae 13784 } else {
13785 if (use_json)
13786 json_object_boolean_true_add(
13787 json_neigh,
13788 "reducePrefixNumAndClearIpBgp");
13789 else
13790 vty_out(vty,
13791 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13792 p->host);
13793 }
13794 }
13795
13796 /* EBGP Multihop and GTSM */
13797 if (p->sort != BGP_PEER_IBGP) {
13798 if (use_json) {
e2521429 13799 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13800 json_object_int_add(json_neigh,
13801 "externalBgpNbrMaxHopsAway",
13802 p->gtsm_hops);
c8d6f0d6 13803 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13804 json_object_int_add(json_neigh,
13805 "externalBgpNbrMaxHopsAway",
13806 p->ttl);
13807 } else {
e2521429 13808 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13809 vty_out(vty,
13810 " External BGP neighbor may be up to %d hops away.\n",
13811 p->gtsm_hops);
c8d6f0d6 13812 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13813 vty_out(vty,
13814 " External BGP neighbor may be up to %d hops away.\n",
13815 p->ttl);
13816 }
13817 } else {
e2521429 13818 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 13819 if (use_json)
13820 json_object_int_add(json_neigh,
13821 "internalBgpNbrMaxHopsAway",
13822 p->gtsm_hops);
13823 else
13824 vty_out(vty,
13825 " Internal BGP neighbor may be up to %d hops away.\n",
13826 p->gtsm_hops);
13827 }
13828 }
13829
13830 /* Local address. */
13831 if (p->su_local) {
13832 if (use_json) {
13833 json_object_string_add(json_neigh, "hostLocal",
13834 sockunion2str(p->su_local, buf1,
13835 SU_ADDRSTRLEN));
13836 json_object_int_add(json_neigh, "portLocal",
13837 ntohs(p->su_local->sin.sin_port));
13838 } else
13839 vty_out(vty, "Local host: %s, Local port: %d\n",
13840 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
13841 ntohs(p->su_local->sin.sin_port));
13842 }
13843
13844 /* Remote address. */
13845 if (p->su_remote) {
13846 if (use_json) {
13847 json_object_string_add(json_neigh, "hostForeign",
13848 sockunion2str(p->su_remote, buf1,
13849 SU_ADDRSTRLEN));
13850 json_object_int_add(json_neigh, "portForeign",
13851 ntohs(p->su_remote->sin.sin_port));
13852 } else
13853 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
13854 sockunion2str(p->su_remote, buf1,
13855 SU_ADDRSTRLEN),
13856 ntohs(p->su_remote->sin.sin_port));
13857 }
13858
13859 /* Nexthop display. */
13860 if (p->su_local) {
13861 if (use_json) {
c949c771
DA
13862 json_object_string_addf(json_neigh, "nexthop", "%pI4",
13863 &p->nexthop.v4);
13864 json_object_string_addf(json_neigh, "nexthopGlobal",
13865 "%pI6", &p->nexthop.v6_global);
13866 json_object_string_addf(json_neigh, "nexthopLocal",
13867 "%pI6", &p->nexthop.v6_local);
d62a17ae 13868 if (p->shared_network)
13869 json_object_string_add(json_neigh,
13870 "bgpConnection",
13871 "sharedNetwork");
13872 else
13873 json_object_string_add(json_neigh,
13874 "bgpConnection",
13875 "nonSharedNetwork");
13876 } else {
13877 vty_out(vty, "Nexthop: %s\n",
13878 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
13879 sizeof(buf1)));
13880 vty_out(vty, "Nexthop global: %s\n",
13881 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
13882 sizeof(buf1)));
13883 vty_out(vty, "Nexthop local: %s\n",
13884 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
13885 sizeof(buf1)));
13886 vty_out(vty, "BGP connection: %s\n",
13887 p->shared_network ? "shared network"
13888 : "non shared network");
13889 }
13890 }
13891
13892 /* Timer information. */
13893 if (use_json) {
13894 json_object_int_add(json_neigh, "connectRetryTimer",
13895 p->v_connect);
feb17238 13896 if (peer_established(p) && p->rtt)
d62a17ae 13897 json_object_int_add(json_neigh, "estimatedRttInMsecs",
13898 p->rtt);
13899 if (p->t_start)
13900 json_object_int_add(
13901 json_neigh, "nextStartTimerDueInMsecs",
13902 thread_timer_remain_second(p->t_start) * 1000);
13903 if (p->t_connect)
13904 json_object_int_add(
13905 json_neigh, "nextConnectTimerDueInMsecs",
13906 thread_timer_remain_second(p->t_connect)
13907 * 1000);
13908 if (p->t_routeadv) {
13909 json_object_int_add(json_neigh, "mraiInterval",
13910 p->v_routeadv);
13911 json_object_int_add(
13912 json_neigh, "mraiTimerExpireInMsecs",
13913 thread_timer_remain_second(p->t_routeadv)
13914 * 1000);
13915 }
13916 if (p->password)
13917 json_object_int_add(json_neigh, "authenticationEnabled",
13918 1);
13919
13920 if (p->t_read)
13921 json_object_string_add(json_neigh, "readThread", "on");
13922 else
13923 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
13924
13925 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 13926 json_object_string_add(json_neigh, "writeThread", "on");
13927 else
13928 json_object_string_add(json_neigh, "writeThread",
13929 "off");
13930 } else {
13931 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
13932 p->v_connect);
feb17238 13933 if (peer_established(p) && p->rtt)
d62a17ae 13934 vty_out(vty, "Estimated round trip time: %d ms\n",
13935 p->rtt);
13936 if (p->t_start)
13937 vty_out(vty, "Next start timer due in %ld seconds\n",
13938 thread_timer_remain_second(p->t_start));
13939 if (p->t_connect)
13940 vty_out(vty, "Next connect timer due in %ld seconds\n",
13941 thread_timer_remain_second(p->t_connect));
13942 if (p->t_routeadv)
13943 vty_out(vty,
13944 "MRAI (interval %u) timer expires in %ld seconds\n",
13945 p->v_routeadv,
13946 thread_timer_remain_second(p->t_routeadv));
13947 if (p->password)
13948 vty_out(vty, "Peer Authentication Enabled\n");
13949
cac9e917 13950 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
13951 p->t_read ? "on" : "off",
13952 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
13953 ? "on"
cac9e917 13954 : "off", p->fd);
d62a17ae 13955 }
13956
13957 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
13958 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
13959 bgp_capability_vty_out(vty, p, use_json, json_neigh);
13960
13961 if (!use_json)
13962 vty_out(vty, "\n");
13963
13964 /* BFD information. */
21bfce98
RZ
13965 if (p->bfd_config)
13966 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 13967
13968 if (use_json) {
13969 if (p->conf_if) /* Configured interface name. */
13970 json_object_object_add(json, p->conf_if, json_neigh);
13971 else /* Configured IP address. */
13972 json_object_object_add(json, p->host, json_neigh);
13973 }
13974}
13975
36235319
QY
13976static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
13977 enum show_type type,
13978 union sockunion *su,
13979 const char *conf_if, afi_t afi,
74a630b6 13980 bool use_json)
2986cac2 13981{
13982 struct listnode *node, *nnode;
13983 struct peer *peer;
13984 int find = 0;
13985 safi_t safi = SAFI_UNICAST;
74a630b6 13986 json_object *json = NULL;
2986cac2 13987 json_object *json_neighbor = NULL;
13988
74a630b6
NT
13989 if (use_json) {
13990 json = json_object_new_object();
13991 json_neighbor = json_object_new_object();
13992 }
13993
2986cac2 13994 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13995
13996 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13997 continue;
13998
13999 if ((peer->afc[afi][safi]) == 0)
14000 continue;
14001
2ba1fe69 14002 if (type == show_all) {
2986cac2 14003 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 14004 json_neighbor);
2986cac2 14005
74a630b6 14006 if (use_json) {
13909c4f
DS
14007 json_object_object_add(json, peer->host,
14008 json_neighbor);
74a630b6
NT
14009 json_neighbor = NULL;
14010 }
2986cac2 14011
2ba1fe69 14012 } else if (type == show_peer) {
2986cac2 14013 if (conf_if) {
14014 if ((peer->conf_if
13909c4f
DS
14015 && !strcmp(peer->conf_if, conf_if))
14016 || (peer->hostname
2986cac2 14017 && !strcmp(peer->hostname, conf_if))) {
14018 find = 1;
13909c4f
DS
14019 bgp_show_peer_gr_status(vty, peer,
14020 use_json,
14021 json_neighbor);
2986cac2 14022 }
14023 } else {
14024 if (sockunion_same(&peer->su, su)) {
14025 find = 1;
13909c4f
DS
14026 bgp_show_peer_gr_status(vty, peer,
14027 use_json,
14028 json_neighbor);
2986cac2 14029 }
14030 }
13909c4f
DS
14031 if (use_json && find)
14032 json_object_object_add(json, peer->host,
14033 json_neighbor);
2986cac2 14034 }
14035
74a630b6
NT
14036 if (find) {
14037 json_neighbor = NULL;
2986cac2 14038 break;
74a630b6 14039 }
2986cac2 14040 }
14041
14042 if (type == show_peer && !find) {
14043 if (use_json)
13909c4f 14044 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14045 else
14046 vty_out(vty, "%% No such neighbor\n");
14047 }
14048 if (use_json) {
74a630b6
NT
14049 if (json_neighbor)
14050 json_object_free(json_neighbor);
75eeda93 14051 vty_json(vty, json);
2986cac2 14052 } else {
14053 vty_out(vty, "\n");
14054 }
14055
14056 return CMD_SUCCESS;
14057}
14058
d62a17ae 14059static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14060 enum show_type type, union sockunion *su,
9f049418 14061 const char *conf_if, bool use_json,
d62a17ae 14062 json_object *json)
14063{
14064 struct listnode *node, *nnode;
14065 struct peer *peer;
14066 int find = 0;
9f049418 14067 bool nbr_output = false;
d1927ebe
AS
14068 afi_t afi = AFI_MAX;
14069 safi_t safi = SAFI_MAX;
14070
14071 if (type == show_ipv4_peer || type == show_ipv4_all) {
14072 afi = AFI_IP;
14073 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14074 afi = AFI_IP6;
14075 }
d62a17ae 14076
14077 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14078 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14079 continue;
14080
14081 switch (type) {
14082 case show_all:
14083 bgp_show_peer(vty, peer, use_json, json);
9f049418 14084 nbr_output = true;
d62a17ae 14085 break;
14086 case show_peer:
14087 if (conf_if) {
14088 if ((peer->conf_if
14089 && !strcmp(peer->conf_if, conf_if))
14090 || (peer->hostname
14091 && !strcmp(peer->hostname, conf_if))) {
14092 find = 1;
14093 bgp_show_peer(vty, peer, use_json,
14094 json);
14095 }
14096 } else {
14097 if (sockunion_same(&peer->su, su)) {
14098 find = 1;
14099 bgp_show_peer(vty, peer, use_json,
14100 json);
14101 }
14102 }
14103 break;
d1927ebe
AS
14104 case show_ipv4_peer:
14105 case show_ipv6_peer:
14106 FOREACH_SAFI (safi) {
14107 if (peer->afc[afi][safi]) {
14108 if (conf_if) {
14109 if ((peer->conf_if
14110 && !strcmp(peer->conf_if, conf_if))
14111 || (peer->hostname
14112 && !strcmp(peer->hostname, conf_if))) {
14113 find = 1;
14114 bgp_show_peer(vty, peer, use_json,
14115 json);
14116 break;
14117 }
14118 } else {
14119 if (sockunion_same(&peer->su, su)) {
14120 find = 1;
14121 bgp_show_peer(vty, peer, use_json,
14122 json);
14123 break;
14124 }
14125 }
14126 }
14127 }
14128 break;
14129 case show_ipv4_all:
14130 case show_ipv6_all:
14131 FOREACH_SAFI (safi) {
14132 if (peer->afc[afi][safi]) {
14133 bgp_show_peer(vty, peer, use_json, json);
14134 nbr_output = true;
14135 break;
14136 }
14137 }
14138 break;
d62a17ae 14139 }
14140 }
14141
d1927ebe
AS
14142 if ((type == show_peer || type == show_ipv4_peer ||
14143 type == show_ipv6_peer) && !find) {
d62a17ae 14144 if (use_json)
14145 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14146 else
88b7d255 14147 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14148 }
14149
d1927ebe
AS
14150 if (type != show_peer && type != show_ipv4_peer &&
14151 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14152 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14153
d62a17ae 14154 if (use_json) {
996c9314
LB
14155 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14156 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14157 } else {
14158 vty_out(vty, "\n");
14159 }
14160
14161 return CMD_SUCCESS;
14162}
14163
36235319
QY
14164static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14165 enum show_type type,
14166 const char *ip_str,
14167 afi_t afi, bool use_json)
2986cac2 14168{
14169
14170 int ret;
14171 struct bgp *bgp;
14172 union sockunion su;
2986cac2 14173
14174 bgp = bgp_get_default();
14175
13909c4f
DS
14176 if (!bgp)
14177 return;
2986cac2 14178
13909c4f
DS
14179 if (!use_json)
14180 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14181 NULL);
2986cac2 14182
13909c4f
DS
14183 if (ip_str) {
14184 ret = str2sockunion(ip_str, &su);
14185 if (ret < 0)
13909c4f 14186 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14187 vty, bgp, type, NULL, ip_str, afi, use_json);
14188 else
14189 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14190 NULL, afi, use_json);
13909c4f
DS
14191 } else
14192 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14193 afi, use_json);
2986cac2 14194}
14195
d62a17ae 14196static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14197 enum show_type type,
14198 const char *ip_str,
9f049418 14199 bool use_json)
d62a17ae 14200{
0291c246
MK
14201 struct listnode *node, *nnode;
14202 struct bgp *bgp;
71aedaa3 14203 union sockunion su;
0291c246 14204 json_object *json = NULL;
71aedaa3 14205 int ret, is_first = 1;
9f049418 14206 bool nbr_output = false;
d62a17ae 14207
14208 if (use_json)
14209 vty_out(vty, "{\n");
14210
14211 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14212 nbr_output = true;
d62a17ae 14213 if (use_json) {
14214 if (!(json = json_object_new_object())) {
af4c2728 14215 flog_err(
e50f7cfd 14216 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14217 "Unable to allocate memory for JSON object");
14218 vty_out(vty,
14219 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14220 return;
14221 }
14222
14223 json_object_int_add(json, "vrfId",
14224 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14225 ? -1
14226 : (int64_t)bgp->vrf_id);
d62a17ae 14227 json_object_string_add(
14228 json, "vrfName",
14229 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14230 ? VRF_DEFAULT_NAME
d62a17ae 14231 : bgp->name);
14232
14233 if (!is_first)
14234 vty_out(vty, ",\n");
14235 else
14236 is_first = 0;
14237
14238 vty_out(vty, "\"%s\":",
14239 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14240 ? VRF_DEFAULT_NAME
d62a17ae 14241 : bgp->name);
14242 } else {
14243 vty_out(vty, "\nInstance %s:\n",
14244 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14245 ? VRF_DEFAULT_NAME
d62a17ae 14246 : bgp->name);
14247 }
71aedaa3 14248
d1927ebe
AS
14249 if (type == show_peer || type == show_ipv4_peer ||
14250 type == show_ipv6_peer) {
71aedaa3
DS
14251 ret = str2sockunion(ip_str, &su);
14252 if (ret < 0)
14253 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14254 use_json, json);
14255 else
14256 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14257 use_json, json);
14258 } else {
d1927ebe 14259 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14260 use_json, json);
14261 }
b77004d6 14262 json_object_free(json);
121067e9 14263 json = NULL;
d62a17ae 14264 }
14265
3e78a6ce 14266 if (use_json)
d62a17ae 14267 vty_out(vty, "}\n");
9f049418
DS
14268 else if (!nbr_output)
14269 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14270}
14271
14272static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14273 enum show_type type, const char *ip_str,
9f049418 14274 bool use_json)
d62a17ae 14275{
14276 int ret;
14277 struct bgp *bgp;
14278 union sockunion su;
14279 json_object *json = NULL;
14280
14281 if (name) {
14282 if (strmatch(name, "all")) {
71aedaa3
DS
14283 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14284 use_json);
d62a17ae 14285 return CMD_SUCCESS;
14286 } else {
14287 bgp = bgp_lookup_by_name(name);
14288 if (!bgp) {
14289 if (use_json) {
14290 json = json_object_new_object();
75eeda93 14291 vty_json(vty, json);
d62a17ae 14292 } else
14293 vty_out(vty,
9f049418 14294 "%% BGP instance not found\n");
d62a17ae 14295
14296 return CMD_WARNING;
14297 }
14298 }
14299 } else {
14300 bgp = bgp_get_default();
14301 }
14302
14303 if (bgp) {
14304 json = json_object_new_object();
14305 if (ip_str) {
14306 ret = str2sockunion(ip_str, &su);
14307 if (ret < 0)
14308 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14309 use_json, json);
14310 else
14311 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14312 use_json, json);
14313 } else {
14314 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14315 json);
14316 }
14317 json_object_free(json);
ca61fd25
DS
14318 } else {
14319 if (use_json)
14320 vty_out(vty, "{}\n");
14321 else
14322 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14323 }
14324
14325 return CMD_SUCCESS;
4fb25c53
DW
14326}
14327
2986cac2 14328
14329
14330/* "show [ip] bgp neighbors graceful-restart" commands. */
14331DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14332 show_ip_bgp_neighbors_graceful_restart_cmd,
14333 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14334 SHOW_STR
14335 BGP_STR
14336 IP_STR
14337 IPV6_STR
14338 NEIGHBOR_STR
14339 "Neighbor to display information about\n"
14340 "Neighbor to display information about\n"
14341 "Neighbor on BGP configured interface\n"
14342 GR_SHOW
14343 JSON_STR)
14344{
14345 char *sh_arg = NULL;
14346 enum show_type sh_type;
14347 int idx = 0;
14348 afi_t afi = AFI_MAX;
2986cac2 14349 bool uj = use_json(argc, argv);
14350
36235319 14351 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 14352 afi = AFI_MAX;
14353
14354 idx++;
14355
14356 if (argv_find(argv, argc, "A.B.C.D", &idx)
14357 || argv_find(argv, argc, "X:X::X:X", &idx)
14358 || argv_find(argv, argc, "WORD", &idx)) {
14359 sh_type = show_peer;
14360 sh_arg = argv[idx]->arg;
14361 } else
14362 sh_type = show_all;
14363
14364 if (!argv_find(argv, argc, "graceful-restart", &idx))
14365 return CMD_SUCCESS;
14366
14367
36235319
QY
14368 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14369 afi, uj);
2986cac2 14370}
14371
716b2d8a 14372/* "show [ip] bgp neighbors" commands. */
718e3744 14373DEFUN (show_ip_bgp_neighbors,
14374 show_ip_bgp_neighbors_cmd,
24345e82 14375 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 14376 SHOW_STR
14377 IP_STR
14378 BGP_STR
f2a8972b 14379 BGP_INSTANCE_HELP_STR
8c3deaae
QY
14380 "Address Family\n"
14381 "Address Family\n"
718e3744 14382 "Detailed information on TCP and BGP neighbor connections\n"
14383 "Neighbor to display information about\n"
a80beece 14384 "Neighbor to display information about\n"
91d37724 14385 "Neighbor on BGP configured interface\n"
9973d184 14386 JSON_STR)
718e3744 14387{
d62a17ae 14388 char *vrf = NULL;
14389 char *sh_arg = NULL;
14390 enum show_type sh_type;
d1927ebe 14391 afi_t afi = AFI_MAX;
718e3744 14392
9f049418 14393 bool uj = use_json(argc, argv);
718e3744 14394
d62a17ae 14395 int idx = 0;
718e3744 14396
9a8bdf1c
PG
14397 /* [<vrf> VIEWVRFNAME] */
14398 if (argv_find(argv, argc, "vrf", &idx)) {
14399 vrf = argv[idx + 1]->arg;
14400 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14401 vrf = NULL;
14402 } else if (argv_find(argv, argc, "view", &idx))
14403 /* [<view> VIEWVRFNAME] */
d62a17ae 14404 vrf = argv[idx + 1]->arg;
718e3744 14405
d62a17ae 14406 idx++;
d1927ebe
AS
14407
14408 if (argv_find(argv, argc, "ipv4", &idx)) {
14409 sh_type = show_ipv4_all;
14410 afi = AFI_IP;
14411 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14412 sh_type = show_ipv6_all;
14413 afi = AFI_IP6;
14414 } else {
14415 sh_type = show_all;
14416 }
14417
d62a17ae 14418 if (argv_find(argv, argc, "A.B.C.D", &idx)
14419 || argv_find(argv, argc, "X:X::X:X", &idx)
14420 || argv_find(argv, argc, "WORD", &idx)) {
14421 sh_type = show_peer;
14422 sh_arg = argv[idx]->arg;
d1927ebe
AS
14423 }
14424
14425 if (sh_type == show_peer && afi == AFI_IP) {
14426 sh_type = show_ipv4_peer;
14427 } else if (sh_type == show_peer && afi == AFI_IP6) {
14428 sh_type = show_ipv6_peer;
14429 }
856ca177 14430
d62a17ae 14431 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 14432}
14433
716b2d8a 14434/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 14435 paths' and `show ip mbgp paths'. Those functions results are the
14436 same.*/
f412b39a 14437DEFUN (show_ip_bgp_paths,
718e3744 14438 show_ip_bgp_paths_cmd,
46f296b4 14439 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 14440 SHOW_STR
14441 IP_STR
14442 BGP_STR
46f296b4 14443 BGP_SAFI_HELP_STR
718e3744 14444 "Path information\n")
14445{
d62a17ae 14446 vty_out(vty, "Address Refcnt Path\n");
14447 aspath_print_all_vty(vty);
14448 return CMD_SUCCESS;
718e3744 14449}
14450
718e3744 14451#include "hash.h"
14452
e3b78da8 14453static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14454 struct vty *vty)
718e3744 14455{
d62a17ae 14456 struct community *com;
718e3744 14457
e3b78da8 14458 com = (struct community *)bucket->data;
3f65c5b1 14459 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 14460 community_str(com, false));
718e3744 14461}
14462
14463/* Show BGP's community internal data. */
f412b39a 14464DEFUN (show_ip_bgp_community_info,
718e3744 14465 show_ip_bgp_community_info_cmd,
bec37ba5 14466 "show [ip] bgp community-info",
718e3744 14467 SHOW_STR
14468 IP_STR
14469 BGP_STR
14470 "List all bgp community information\n")
14471{
d62a17ae 14472 vty_out(vty, "Address Refcnt Community\n");
718e3744 14473
d62a17ae 14474 hash_iterate(community_hash(),
e3b78da8 14475 (void (*)(struct hash_bucket *,
d62a17ae 14476 void *))community_show_all_iterator,
14477 vty);
718e3744 14478
d62a17ae 14479 return CMD_SUCCESS;
718e3744 14480}
14481
e3b78da8 14482static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14483 struct vty *vty)
57d187bc 14484{
d62a17ae 14485 struct lcommunity *lcom;
57d187bc 14486
e3b78da8 14487 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 14488 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 14489 lcommunity_str(lcom, false));
57d187bc
JS
14490}
14491
14492/* Show BGP's community internal data. */
14493DEFUN (show_ip_bgp_lcommunity_info,
14494 show_ip_bgp_lcommunity_info_cmd,
14495 "show ip bgp large-community-info",
14496 SHOW_STR
14497 IP_STR
14498 BGP_STR
14499 "List all bgp large-community information\n")
14500{
d62a17ae 14501 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 14502
d62a17ae 14503 hash_iterate(lcommunity_hash(),
e3b78da8 14504 (void (*)(struct hash_bucket *,
d62a17ae 14505 void *))lcommunity_show_all_iterator,
14506 vty);
57d187bc 14507
d62a17ae 14508 return CMD_SUCCESS;
57d187bc 14509}
2986cac2 14510/* Graceful Restart */
14511
14512static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
14513 struct bgp *bgp,
14514 bool use_json,
14515 json_object *json)
2986cac2 14516{
57d187bc
JS
14517
14518
2986cac2 14519 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14520
7318ae88 14521 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 14522
14523 switch (bgp_global_gr_mode) {
14524
14525 case GLOBAL_HELPER:
13909c4f 14526 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 14527 break;
14528
14529 case GLOBAL_GR:
13909c4f 14530 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 14531 break;
14532
14533 case GLOBAL_DISABLE:
13909c4f 14534 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 14535 break;
14536
14537 case GLOBAL_INVALID:
2986cac2 14538 vty_out(vty,
2ba1fe69 14539 "Global BGP GR Mode Invalid\n");
2986cac2 14540 break;
14541 }
14542 vty_out(vty, "\n");
14543}
14544
36235319
QY
14545static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14546 enum show_type type,
14547 const char *ip_str,
14548 afi_t afi, bool use_json)
2986cac2 14549{
14550 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14551 afi = AFI_IP;
14552
14553 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14554
36235319
QY
14555 bgp_show_neighbor_graceful_restart_vty(
14556 vty, type, ip_str, afi, use_json);
2986cac2 14557 afi++;
14558 }
14559 } else if (afi != AFI_MAX) {
36235319
QY
14560 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14561 use_json);
2986cac2 14562 } else {
14563 return CMD_ERR_INCOMPLETE;
14564 }
14565
14566 return CMD_SUCCESS;
14567}
14568/* Graceful Restart */
14569
f412b39a 14570DEFUN (show_ip_bgp_attr_info,
718e3744 14571 show_ip_bgp_attr_info_cmd,
bec37ba5 14572 "show [ip] bgp attribute-info",
718e3744 14573 SHOW_STR
14574 IP_STR
14575 BGP_STR
14576 "List all bgp attribute information\n")
14577{
d62a17ae 14578 attr_show_all(vty);
14579 return CMD_SUCCESS;
718e3744 14580}
6b0655a2 14581
03915806
CS
14582static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14583 afi_t afi, safi_t safi,
14584 bool use_json, json_object *json)
53089bec 14585{
14586 struct bgp *bgp;
14587 struct listnode *node;
14588 char *vname;
14589 char buf1[INET6_ADDRSTRLEN];
14590 char *ecom_str;
14591 vpn_policy_direction_t dir;
14592
03915806 14593 if (json) {
b46dfd20
DS
14594 json_object *json_import_vrfs = NULL;
14595 json_object *json_export_vrfs = NULL;
14596
b46dfd20
DS
14597 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14598
53089bec 14599 if (!bgp) {
75eeda93 14600 vty_json(vty, json);
b46dfd20 14601
53089bec 14602 return CMD_WARNING;
14603 }
b46dfd20 14604
94d4c685
DS
14605 /* Provide context for the block */
14606 json_object_string_add(json, "vrf", name ? name : "default");
14607 json_object_string_add(json, "afiSafi",
5cb5f4d0 14608 get_afi_safi_str(afi, safi, true));
94d4c685 14609
b46dfd20
DS
14610 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14611 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14612 json_object_string_add(json, "importFromVrfs", "none");
14613 json_object_string_add(json, "importRts", "none");
14614 } else {
6ce24e52
DS
14615 json_import_vrfs = json_object_new_array();
14616
b46dfd20
DS
14617 for (ALL_LIST_ELEMENTS_RO(
14618 bgp->vpn_policy[afi].import_vrf,
14619 node, vname))
14620 json_object_array_add(json_import_vrfs,
14621 json_object_new_string(vname));
14622
b20875ea
CS
14623 json_object_object_add(json, "importFromVrfs",
14624 json_import_vrfs);
b46dfd20 14625 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14626 if (bgp->vpn_policy[afi].rtlist[dir]) {
14627 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14628 bgp->vpn_policy[afi].rtlist[dir],
14629 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14630 json_object_string_add(json, "importRts",
14631 ecom_str);
14632 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14633 } else
14634 json_object_string_add(json, "importRts",
14635 "none");
b46dfd20
DS
14636 }
14637
14638 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14639 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14640 json_object_string_add(json, "exportToVrfs", "none");
14641 json_object_string_add(json, "routeDistinguisher",
14642 "none");
14643 json_object_string_add(json, "exportRts", "none");
14644 } else {
6ce24e52
DS
14645 json_export_vrfs = json_object_new_array();
14646
b46dfd20
DS
14647 for (ALL_LIST_ELEMENTS_RO(
14648 bgp->vpn_policy[afi].export_vrf,
14649 node, vname))
14650 json_object_array_add(json_export_vrfs,
14651 json_object_new_string(vname));
14652 json_object_object_add(json, "exportToVrfs",
14653 json_export_vrfs);
14654 json_object_string_add(json, "routeDistinguisher",
14655 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14656 buf1, RD_ADDRSTRLEN));
14657
14658 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14659 if (bgp->vpn_policy[afi].rtlist[dir]) {
14660 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14661 bgp->vpn_policy[afi].rtlist[dir],
14662 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14663 json_object_string_add(json, "exportRts",
14664 ecom_str);
14665 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14666 } else
14667 json_object_string_add(json, "exportRts",
14668 "none");
b46dfd20
DS
14669 }
14670
03915806 14671 if (use_json) {
75eeda93 14672 vty_json(vty, json);
03915806 14673 }
53089bec 14674 } else {
b46dfd20
DS
14675 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14676
53089bec 14677 if (!bgp) {
b46dfd20 14678 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 14679 return CMD_WARNING;
14680 }
53089bec 14681
b46dfd20
DS
14682 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14683 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14684 vty_out(vty,
14685 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 14686 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14687 else {
14688 vty_out(vty,
14689 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 14690 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14691
14692 for (ALL_LIST_ELEMENTS_RO(
14693 bgp->vpn_policy[afi].import_vrf,
14694 node, vname))
14695 vty_out(vty, " %s\n", vname);
14696
14697 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14698 ecom_str = NULL;
14699 if (bgp->vpn_policy[afi].rtlist[dir]) {
14700 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14701 bgp->vpn_policy[afi].rtlist[dir],
14702 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 14703 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 14704
b20875ea
CS
14705 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14706 } else
14707 vty_out(vty, "Import RT(s):\n");
53089bec 14708 }
53089bec 14709
b46dfd20
DS
14710 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14711 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14712 vty_out(vty,
14713 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 14714 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14715 else {
14716 vty_out(vty,
04c9077f 14717 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 14718 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14719
14720 for (ALL_LIST_ELEMENTS_RO(
14721 bgp->vpn_policy[afi].export_vrf,
14722 node, vname))
14723 vty_out(vty, " %s\n", vname);
14724
14725 vty_out(vty, "RD: %s\n",
14726 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14727 buf1, RD_ADDRSTRLEN));
14728
14729 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14730 if (bgp->vpn_policy[afi].rtlist[dir]) {
14731 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14732 bgp->vpn_policy[afi].rtlist[dir],
14733 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14734 vty_out(vty, "Export RT: %s\n", ecom_str);
14735 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14736 } else
14737 vty_out(vty, "Import RT(s):\n");
53089bec 14738 }
53089bec 14739 }
14740
14741 return CMD_SUCCESS;
14742}
14743
03915806
CS
14744static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14745 safi_t safi, bool use_json)
14746{
14747 struct listnode *node, *nnode;
14748 struct bgp *bgp;
14749 char *vrf_name = NULL;
14750 json_object *json = NULL;
14751 json_object *json_vrf = NULL;
14752 json_object *json_vrfs = NULL;
14753
14754 if (use_json) {
14755 json = json_object_new_object();
14756 json_vrfs = json_object_new_object();
14757 }
14758
14759 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14760
14761 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14762 vrf_name = bgp->name;
14763
14764 if (use_json) {
14765 json_vrf = json_object_new_object();
14766 } else {
14767 vty_out(vty, "\nInstance %s:\n",
14768 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14769 ? VRF_DEFAULT_NAME : bgp->name);
14770 }
14771 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14772 if (use_json) {
14773 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14774 json_object_object_add(json_vrfs,
14775 VRF_DEFAULT_NAME, json_vrf);
14776 else
14777 json_object_object_add(json_vrfs, vrf_name,
14778 json_vrf);
14779 }
14780 }
14781
14782 if (use_json) {
14783 json_object_object_add(json, "vrfs", json_vrfs);
75eeda93 14784 vty_json(vty, json);
03915806
CS
14785 }
14786
14787 return CMD_SUCCESS;
14788}
14789
53089bec 14790/* "show [ip] bgp route-leak" command. */
14791DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
14792 show_ip_bgp_route_leak_cmd,
14793 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
14794 SHOW_STR
14795 IP_STR
14796 BGP_STR
14797 BGP_INSTANCE_HELP_STR
14798 BGP_AFI_HELP_STR
14799 BGP_SAFI_HELP_STR
14800 "Route leaking information\n"
14801 JSON_STR)
53089bec 14802{
14803 char *vrf = NULL;
14804 afi_t afi = AFI_MAX;
14805 safi_t safi = SAFI_MAX;
14806
9f049418 14807 bool uj = use_json(argc, argv);
53089bec 14808 int idx = 0;
03915806 14809 json_object *json = NULL;
53089bec 14810
14811 /* show [ip] bgp */
14812 if (argv_find(argv, argc, "ip", &idx)) {
14813 afi = AFI_IP;
14814 safi = SAFI_UNICAST;
14815 }
14816 /* [vrf VIEWVRFNAME] */
14817 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
14818 vty_out(vty,
14819 "%% This command is not applicable to BGP views\n");
53089bec 14820 return CMD_WARNING;
14821 }
14822
9a8bdf1c
PG
14823 if (argv_find(argv, argc, "vrf", &idx)) {
14824 vrf = argv[idx + 1]->arg;
14825 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14826 vrf = NULL;
14827 }
53089bec 14828 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
c48349e3 14829 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
53089bec 14830 argv_find_and_parse_safi(argv, argc, &idx, &safi);
53089bec 14831
14832 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
14833 vty_out(vty,
14834 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 14835 return CMD_WARNING;
14836 }
14837
03915806
CS
14838 if (vrf && strmatch(vrf, "all"))
14839 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
14840
14841 if (uj)
14842 json = json_object_new_object();
14843
14844 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 14845}
14846
d62a17ae 14847static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
14848 safi_t safi)
f186de26 14849{
d62a17ae 14850 struct listnode *node, *nnode;
14851 struct bgp *bgp;
f186de26 14852
d62a17ae 14853 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14854 vty_out(vty, "\nInstance %s:\n",
14855 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14856 ? VRF_DEFAULT_NAME
d62a17ae 14857 : bgp->name);
14858 update_group_show(bgp, afi, safi, vty, 0);
14859 }
f186de26 14860}
14861
d62a17ae 14862static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
14863 int safi, uint64_t subgrp_id)
4fb25c53 14864{
d62a17ae 14865 struct bgp *bgp;
4fb25c53 14866
d62a17ae 14867 if (name) {
14868 if (strmatch(name, "all")) {
14869 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
14870 return CMD_SUCCESS;
14871 } else {
14872 bgp = bgp_lookup_by_name(name);
14873 }
14874 } else {
14875 bgp = bgp_get_default();
14876 }
4fb25c53 14877
d62a17ae 14878 if (bgp)
14879 update_group_show(bgp, afi, safi, vty, subgrp_id);
14880 return CMD_SUCCESS;
4fb25c53
DW
14881}
14882
8fe8a7f6
DS
14883DEFUN (show_ip_bgp_updgrps,
14884 show_ip_bgp_updgrps_cmd,
c1a44e43 14885 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 14886 SHOW_STR
14887 IP_STR
14888 BGP_STR
14889 BGP_INSTANCE_HELP_STR
c9e571b4 14890 BGP_AFI_HELP_STR
9bedbb1e 14891 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
14892 "Detailed info about dynamic update groups\n"
14893 "Specific subgroup to display detailed info for\n")
8386ac43 14894{
d62a17ae 14895 char *vrf = NULL;
14896 afi_t afi = AFI_IP6;
14897 safi_t safi = SAFI_UNICAST;
14898 uint64_t subgrp_id = 0;
14899
14900 int idx = 0;
14901
14902 /* show [ip] bgp */
14903 if (argv_find(argv, argc, "ip", &idx))
14904 afi = AFI_IP;
9a8bdf1c
PG
14905 /* [<vrf> VIEWVRFNAME] */
14906 if (argv_find(argv, argc, "vrf", &idx)) {
14907 vrf = argv[idx + 1]->arg;
14908 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14909 vrf = NULL;
14910 } else if (argv_find(argv, argc, "view", &idx))
14911 /* [<view> VIEWVRFNAME] */
14912 vrf = argv[idx + 1]->arg;
d62a17ae 14913 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14914 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14915 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14916 }
5bf15956 14917
d62a17ae 14918 /* get subgroup id, if provided */
14919 idx = argc - 1;
14920 if (argv[idx]->type == VARIABLE_TKN)
14921 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 14922
d62a17ae 14923 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
14924}
14925
f186de26 14926DEFUN (show_bgp_instance_all_ipv6_updgrps,
14927 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 14928 "show [ip] bgp <view|vrf> all update-groups",
f186de26 14929 SHOW_STR
716b2d8a 14930 IP_STR
f186de26 14931 BGP_STR
14932 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 14933 "Detailed info about dynamic update groups\n")
f186de26 14934{
d62a17ae 14935 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
14936 return CMD_SUCCESS;
f186de26 14937}
14938
43d3f4fc
DS
14939DEFUN (show_bgp_l2vpn_evpn_updgrps,
14940 show_bgp_l2vpn_evpn_updgrps_cmd,
14941 "show [ip] bgp l2vpn evpn update-groups",
14942 SHOW_STR
14943 IP_STR
14944 BGP_STR
14945 "l2vpn address family\n"
14946 "evpn sub-address family\n"
14947 "Detailed info about dynamic update groups\n")
14948{
14949 char *vrf = NULL;
14950 uint64_t subgrp_id = 0;
14951
14952 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
14953 return CMD_SUCCESS;
14954}
14955
5bf15956
DW
14956DEFUN (show_bgp_updgrps_stats,
14957 show_bgp_updgrps_stats_cmd,
716b2d8a 14958 "show [ip] bgp update-groups statistics",
3f9c7369 14959 SHOW_STR
716b2d8a 14960 IP_STR
3f9c7369 14961 BGP_STR
0c7b1b01 14962 "Detailed info about dynamic update groups\n"
3f9c7369
DS
14963 "Statistics\n")
14964{
d62a17ae 14965 struct bgp *bgp;
3f9c7369 14966
d62a17ae 14967 bgp = bgp_get_default();
14968 if (bgp)
14969 update_group_show_stats(bgp, vty);
3f9c7369 14970
d62a17ae 14971 return CMD_SUCCESS;
3f9c7369
DS
14972}
14973
8386ac43 14974DEFUN (show_bgp_instance_updgrps_stats,
14975 show_bgp_instance_updgrps_stats_cmd,
18c57037 14976 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 14977 SHOW_STR
716b2d8a 14978 IP_STR
8386ac43 14979 BGP_STR
14980 BGP_INSTANCE_HELP_STR
0c7b1b01 14981 "Detailed info about dynamic update groups\n"
8386ac43 14982 "Statistics\n")
14983{
d62a17ae 14984 int idx_word = 3;
14985 struct bgp *bgp;
8386ac43 14986
d62a17ae 14987 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
14988 if (bgp)
14989 update_group_show_stats(bgp, vty);
8386ac43 14990
d62a17ae 14991 return CMD_SUCCESS;
8386ac43 14992}
14993
d62a17ae 14994static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
14995 afi_t afi, safi_t safi,
14996 const char *what, uint64_t subgrp_id)
3f9c7369 14997{
d62a17ae 14998 struct bgp *bgp;
8386ac43 14999
d62a17ae 15000 if (name)
15001 bgp = bgp_lookup_by_name(name);
15002 else
15003 bgp = bgp_get_default();
8386ac43 15004
d62a17ae 15005 if (bgp) {
15006 if (!strcmp(what, "advertise-queue"))
15007 update_group_show_adj_queue(bgp, afi, safi, vty,
15008 subgrp_id);
15009 else if (!strcmp(what, "advertised-routes"))
15010 update_group_show_advertised(bgp, afi, safi, vty,
15011 subgrp_id);
15012 else if (!strcmp(what, "packet-queue"))
15013 update_group_show_packet_queue(bgp, afi, safi, vty,
15014 subgrp_id);
15015 }
3f9c7369
DS
15016}
15017
dc64bdec
QY
15018DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15019 show_ip_bgp_instance_updgrps_adj_s_cmd,
15020 "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",
15021 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15022 BGP_SAFI_HELP_STR
15023 "Detailed info about dynamic update groups\n"
15024 "Specific subgroup to display info for\n"
15025 "Advertisement queue\n"
15026 "Announced routes\n"
15027 "Packet queue\n")
3f9c7369 15028{
dc64bdec
QY
15029 uint64_t subgrp_id = 0;
15030 afi_t afiz;
15031 safi_t safiz;
15032 if (sgid)
15033 subgrp_id = strtoull(sgid, NULL, 10);
15034
15035 if (!ip && !afi)
15036 afiz = AFI_IP6;
15037 if (!ip && afi)
15038 afiz = bgp_vty_afi_from_str(afi);
15039 if (ip && !afi)
15040 afiz = AFI_IP;
15041 if (ip && afi) {
15042 afiz = bgp_vty_afi_from_str(afi);
15043 if (afiz != AFI_IP)
15044 vty_out(vty,
15045 "%% Cannot specify both 'ip' and 'ipv6'\n");
15046 return CMD_WARNING;
15047 }
d62a17ae 15048
dc64bdec 15049 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15050
dc64bdec 15051 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15052 return CMD_SUCCESS;
15053}
15054
6f4eacf3
DA
15055static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15056 json_object *json)
d62a17ae 15057{
15058 struct listnode *node, *nnode;
15059 struct prefix *range;
15060 struct peer *conf;
15061 struct peer *peer;
d62a17ae 15062 afi_t afi;
15063 safi_t safi;
15064 const char *peer_status;
d62a17ae 15065 int lr_count;
15066 int dynamic;
6f4eacf3
DA
15067 bool af_cfgd;
15068 json_object *json_peer_group = NULL;
15069 json_object *json_peer_group_afc = NULL;
15070 json_object *json_peer_group_members = NULL;
15071 json_object *json_peer_group_dynamic = NULL;
15072 json_object *json_peer_group_dynamic_af = NULL;
15073 json_object *json_peer_group_ranges = NULL;
d62a17ae 15074
15075 conf = group->conf;
15076
6f4eacf3
DA
15077 if (json) {
15078 json_peer_group = json_object_new_object();
15079 json_peer_group_afc = json_object_new_array();
15080 }
15081
d62a17ae 15082 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3
DA
15083 if (json)
15084 json_object_int_add(json_peer_group, "remoteAs",
15085 conf->as);
15086 else
15087 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15088 group->name, conf->as);
d62a17ae 15089 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3
DA
15090 if (json)
15091 json_object_int_add(json_peer_group, "remoteAs",
15092 group->bgp->as);
15093 else
15094 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15095 group->name, group->bgp->as);
d62a17ae 15096 } else {
6f4eacf3
DA
15097 if (!json)
15098 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 15099 }
f14e6fdb 15100
6f4eacf3
DA
15101 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15102 if (json)
15103 json_object_string_add(json_peer_group, "type",
15104 "internal");
15105 else
15106 vty_out(vty, " Peer-group type is internal\n");
15107 } else {
15108 if (json)
15109 json_object_string_add(json_peer_group, "type",
15110 "external");
15111 else
15112 vty_out(vty, " Peer-group type is external\n");
15113 }
d62a17ae 15114
15115 /* Display AFs configured. */
6f4eacf3
DA
15116 if (!json)
15117 vty_out(vty, " Configured address-families:");
15118
05c7a1cc
QY
15119 FOREACH_AFI_SAFI (afi, safi) {
15120 if (conf->afc[afi][safi]) {
6f4eacf3
DA
15121 af_cfgd = true;
15122 if (json)
15123 json_object_array_add(
15124 json_peer_group_afc,
15125 json_object_new_string(get_afi_safi_str(
15126 afi, safi, false)));
15127 else
15128 vty_out(vty, " %s;",
15129 get_afi_safi_str(afi, safi, false));
d62a17ae 15130 }
05c7a1cc 15131 }
6f4eacf3
DA
15132
15133 if (json) {
15134 json_object_object_add(json_peer_group,
15135 "addressFamiliesConfigured",
15136 json_peer_group_afc);
15137 } else {
15138 if (!af_cfgd)
15139 vty_out(vty, " none\n");
15140 else
15141 vty_out(vty, "\n");
15142 }
d62a17ae 15143
15144 /* Display listen ranges (for dynamic neighbors), if any */
15145 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 15146 lr_count = listcount(group->listen_range[afi]);
15147 if (lr_count) {
6f4eacf3
DA
15148 if (json) {
15149 if (!json_peer_group_dynamic)
15150 json_peer_group_dynamic =
15151 json_object_new_object();
15152
15153 json_peer_group_dynamic_af =
15154 json_object_new_object();
15155 json_peer_group_ranges =
15156 json_object_new_array();
15157 json_object_int_add(json_peer_group_dynamic_af,
15158 "count", lr_count);
15159 } else {
15160 vty_out(vty, " %d %s listen range(s)\n",
15161 lr_count, afi2str(afi));
15162 }
d62a17ae 15163
15164 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
15165 nnode, range)) {
15166 if (json) {
15167 char buf[BUFSIZ];
15168
15169 snprintfrr(buf, sizeof(buf), "%pFX",
15170 range);
15171
15172 json_object_array_add(
15173 json_peer_group_ranges,
15174 json_object_new_string(buf));
15175 } else {
15176 vty_out(vty, " %pFX\n", range);
15177 }
15178 }
15179
15180 if (json) {
15181 json_object_object_add(
15182 json_peer_group_dynamic_af, "ranges",
15183 json_peer_group_ranges);
15184
15185 json_object_object_add(
15186 json_peer_group_dynamic, afi2str(afi),
15187 json_peer_group_dynamic_af);
15188 }
d62a17ae 15189 }
15190 }
f14e6fdb 15191
6f4eacf3
DA
15192 if (json_peer_group_dynamic)
15193 json_object_object_add(json_peer_group, "dynamicRanges",
15194 json_peer_group_dynamic);
15195
d62a17ae 15196 /* Display group members and their status */
15197 if (listcount(group->peer)) {
6f4eacf3
DA
15198 if (json)
15199 json_peer_group_members = json_object_new_object();
15200 else
15201 vty_out(vty, " Peer-group members:\n");
d62a17ae 15202 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15203 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15204 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15205 peer_status = "Idle (Admin)";
15206 else if (CHECK_FLAG(peer->sflags,
15207 PEER_STATUS_PREFIX_OVERFLOW))
15208 peer_status = "Idle (PfxCt)";
15209 else
15210 peer_status = lookup_msg(bgp_status_msg,
15211 peer->status, NULL);
15212
15213 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
15214
15215 if (json) {
15216 json_object *json_peer_group_member =
15217 json_object_new_object();
15218
15219 json_object_string_add(json_peer_group_member,
15220 "status", peer_status);
15221
15222 if (dynamic)
15223 json_object_boolean_true_add(
15224 json_peer_group_member,
15225 "dynamic");
15226
15227 json_object_object_add(json_peer_group_members,
15228 peer->host,
15229 json_peer_group_member);
15230 } else {
15231 vty_out(vty, " %s %s %s \n", peer->host,
15232 dynamic ? "(dynamic)" : "",
15233 peer_status);
15234 }
d62a17ae 15235 }
6f4eacf3
DA
15236 if (json)
15237 json_object_object_add(json_peer_group, "members",
15238 json_peer_group_members);
d62a17ae 15239 }
f14e6fdb 15240
6f4eacf3
DA
15241 if (json)
15242 json_object_object_add(json, group->name, json_peer_group);
15243
d62a17ae 15244 return CMD_SUCCESS;
15245}
15246
ff9959b0 15247static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 15248 const char *group_name, bool uj)
d62a17ae 15249{
ff9959b0 15250 struct bgp *bgp;
d62a17ae 15251 struct listnode *node, *nnode;
15252 struct peer_group *group;
ff9959b0 15253 bool found = false;
6f4eacf3
DA
15254 json_object *json = NULL;
15255
15256 if (uj)
15257 json = json_object_new_object();
ff9959b0
QY
15258
15259 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15260
15261 if (!bgp) {
c48349e3 15262 if (uj)
75eeda93 15263 vty_json(vty, json);
c48349e3 15264 else
6f4eacf3 15265 vty_out(vty, "%% BGP instance not found\n");
6f4eacf3 15266
ff9959b0
QY
15267 return CMD_WARNING;
15268 }
d62a17ae 15269
15270 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15271 if (group_name) {
15272 if (strmatch(group->name, group_name)) {
6f4eacf3 15273 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
15274 found = true;
15275 break;
d62a17ae 15276 }
ff9959b0 15277 } else {
6f4eacf3 15278 bgp_show_one_peer_group(vty, group, json);
d62a17ae 15279 }
f14e6fdb 15280 }
f14e6fdb 15281
6f4eacf3 15282 if (group_name && !found && !uj)
d62a17ae 15283 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15284
c48349e3 15285 if (uj)
75eeda93 15286 vty_json(vty, json);
6f4eacf3 15287
d62a17ae 15288 return CMD_SUCCESS;
f14e6fdb
DS
15289}
15290
6f4eacf3
DA
15291DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15292 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15293 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15294 "Detailed information on BGP peer groups\n"
15295 "Peer group name\n" JSON_STR)
f14e6fdb 15296{
d62a17ae 15297 char *vrf, *pg;
d62a17ae 15298 int idx = 0;
6f4eacf3 15299 bool uj = use_json(argc, argv);
f14e6fdb 15300
a4d82a8a
PZ
15301 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15302 : NULL;
d62a17ae 15303 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15304
6f4eacf3 15305 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 15306}
3f9c7369 15307
d6e3c605 15308
718e3744 15309/* Redistribute VTY commands. */
15310
585f1adc
IR
15311DEFUN (bgp_redistribute_ipv4,
15312 bgp_redistribute_ipv4_cmd,
15313 "redistribute " FRR_IP_REDIST_STR_BGPD,
15314 "Redistribute information from another routing protocol\n"
15315 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 15316{
585f1adc 15317 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15318 int idx_protocol = 1;
585f1adc 15319 int type;
37a87b8f 15320
585f1adc
IR
15321 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15322 if (type < 0) {
15323 vty_out(vty, "%% Invalid route type\n");
15324 return CMD_WARNING_CONFIG_FAILED;
15325 }
7f323236 15326
585f1adc
IR
15327 bgp_redist_add(bgp, AFI_IP, type, 0);
15328 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 15329}
15330
d62a17ae 15331ALIAS_HIDDEN(
15332 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15333 "redistribute " FRR_IP_REDIST_STR_BGPD,
15334 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 15335
585f1adc
IR
15336DEFUN (bgp_redistribute_ipv4_rmap,
15337 bgp_redistribute_ipv4_rmap_cmd,
15338 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15339 "Redistribute information from another routing protocol\n"
15340 FRR_IP_REDIST_HELP_STR_BGPD
15341 "Route map reference\n"
15342 "Pointer to route-map entries\n")
718e3744 15343{
585f1adc 15344 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15345 int idx_protocol = 1;
15346 int idx_word = 3;
585f1adc
IR
15347 int type;
15348 struct bgp_redist *red;
15349 bool changed;
15350 struct route_map *route_map = route_map_lookup_warn_noexist(
15351 vty, argv[idx_word]->arg);
15352
15353 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15354 if (type < 0) {
15355 vty_out(vty, "%% Invalid route type\n");
15356 return CMD_WARNING_CONFIG_FAILED;
15357 }
37a87b8f 15358
585f1adc
IR
15359 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15360 changed =
15361 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15362 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 15363}
15364
d62a17ae 15365ALIAS_HIDDEN(
15366 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15367 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15368 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15369 "Route map reference\n"
15370 "Pointer to route-map entries\n")
596c17ba 15371
585f1adc
IR
15372DEFUN (bgp_redistribute_ipv4_metric,
15373 bgp_redistribute_ipv4_metric_cmd,
15374 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15375 "Redistribute information from another routing protocol\n"
15376 FRR_IP_REDIST_HELP_STR_BGPD
15377 "Metric for redistributed routes\n"
15378 "Default metric\n")
718e3744 15379{
585f1adc 15380 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15381 int idx_protocol = 1;
15382 int idx_number = 3;
585f1adc
IR
15383 int type;
15384 uint32_t metric;
15385 struct bgp_redist *red;
15386 bool changed;
15387
15388 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15389 if (type < 0) {
15390 vty_out(vty, "%% Invalid route type\n");
15391 return CMD_WARNING_CONFIG_FAILED;
15392 }
15393 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15394
585f1adc
IR
15395 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15396 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15397 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15398}
15399
15400ALIAS_HIDDEN(
15401 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15402 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15403 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15404 "Metric for redistributed routes\n"
15405 "Default metric\n")
596c17ba 15406
585f1adc
IR
15407DEFUN (bgp_redistribute_ipv4_rmap_metric,
15408 bgp_redistribute_ipv4_rmap_metric_cmd,
15409 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15410 "Redistribute information from another routing protocol\n"
15411 FRR_IP_REDIST_HELP_STR_BGPD
15412 "Route map reference\n"
15413 "Pointer to route-map entries\n"
15414 "Metric for redistributed routes\n"
15415 "Default metric\n")
718e3744 15416{
585f1adc 15417 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15418 int idx_protocol = 1;
15419 int idx_word = 3;
15420 int idx_number = 5;
585f1adc
IR
15421 int type;
15422 uint32_t metric;
15423 struct bgp_redist *red;
15424 bool changed;
15425 struct route_map *route_map =
15426 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15427
15428 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15429 if (type < 0) {
15430 vty_out(vty, "%% Invalid route type\n");
15431 return CMD_WARNING_CONFIG_FAILED;
15432 }
15433 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15434
585f1adc
IR
15435 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15436 changed =
15437 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15438 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15439 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15440}
15441
15442ALIAS_HIDDEN(
15443 bgp_redistribute_ipv4_rmap_metric,
15444 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15445 "redistribute " FRR_IP_REDIST_STR_BGPD
15446 " route-map WORD metric (0-4294967295)",
15447 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15448 "Route map reference\n"
15449 "Pointer to route-map entries\n"
15450 "Metric for redistributed routes\n"
15451 "Default metric\n")
596c17ba 15452
585f1adc
IR
15453DEFUN (bgp_redistribute_ipv4_metric_rmap,
15454 bgp_redistribute_ipv4_metric_rmap_cmd,
15455 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15456 "Redistribute information from another routing protocol\n"
15457 FRR_IP_REDIST_HELP_STR_BGPD
15458 "Metric for redistributed routes\n"
15459 "Default metric\n"
15460 "Route map reference\n"
15461 "Pointer to route-map entries\n")
718e3744 15462{
585f1adc 15463 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15464 int idx_protocol = 1;
37a87b8f 15465 int idx_number = 3;
585f1adc
IR
15466 int idx_word = 5;
15467 int type;
15468 uint32_t metric;
15469 struct bgp_redist *red;
15470 bool changed;
15471 struct route_map *route_map =
15472 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15473
15474 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15475 if (type < 0) {
15476 vty_out(vty, "%% Invalid route type\n");
15477 return CMD_WARNING_CONFIG_FAILED;
15478 }
15479 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15480
585f1adc
IR
15481 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15482 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15483 changed |=
15484 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15485 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15486}
15487
15488ALIAS_HIDDEN(
15489 bgp_redistribute_ipv4_metric_rmap,
15490 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15491 "redistribute " FRR_IP_REDIST_STR_BGPD
15492 " metric (0-4294967295) route-map WORD",
15493 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15494 "Metric for redistributed routes\n"
15495 "Default metric\n"
15496 "Route map reference\n"
15497 "Pointer to route-map entries\n")
596c17ba 15498
585f1adc
IR
15499DEFUN (bgp_redistribute_ipv4_ospf,
15500 bgp_redistribute_ipv4_ospf_cmd,
15501 "redistribute <ospf|table> (1-65535)",
15502 "Redistribute information from another routing protocol\n"
15503 "Open Shortest Path First (OSPFv2)\n"
15504 "Non-main Kernel Routing Table\n"
15505 "Instance ID/Table ID\n")
7c8ff89e 15506{
585f1adc
IR
15507 VTY_DECLVAR_CONTEXT(bgp, bgp);
15508 int idx_ospf_table = 1;
d62a17ae 15509 int idx_number = 2;
585f1adc
IR
15510 unsigned short instance;
15511 unsigned short protocol;
7c8ff89e 15512
585f1adc 15513 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 15514
585f1adc
IR
15515 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15516 protocol = ZEBRA_ROUTE_OSPF;
15517 else
15518 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 15519
585f1adc
IR
15520 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15521 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
15522}
15523
d62a17ae 15524ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15525 "redistribute <ospf|table> (1-65535)",
15526 "Redistribute information from another routing protocol\n"
15527 "Open Shortest Path First (OSPFv2)\n"
15528 "Non-main Kernel Routing Table\n"
15529 "Instance ID/Table ID\n")
596c17ba 15530
585f1adc
IR
15531DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15532 bgp_redistribute_ipv4_ospf_rmap_cmd,
15533 "redistribute <ospf|table> (1-65535) route-map WORD",
15534 "Redistribute information from another routing protocol\n"
15535 "Open Shortest Path First (OSPFv2)\n"
15536 "Non-main Kernel Routing Table\n"
15537 "Instance ID/Table ID\n"
15538 "Route map reference\n"
15539 "Pointer to route-map entries\n")
7c8ff89e 15540{
585f1adc
IR
15541 VTY_DECLVAR_CONTEXT(bgp, bgp);
15542 int idx_ospf_table = 1;
d62a17ae 15543 int idx_number = 2;
15544 int idx_word = 4;
585f1adc
IR
15545 struct bgp_redist *red;
15546 unsigned short instance;
15547 int protocol;
15548 bool changed;
15549 struct route_map *route_map =
15550 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15551
15552 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15553 protocol = ZEBRA_ROUTE_OSPF;
15554 else
15555 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15556
585f1adc
IR
15557 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15558 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15559 changed =
15560 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15561 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15562}
15563
15564ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15565 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15566 "redistribute <ospf|table> (1-65535) route-map WORD",
15567 "Redistribute information from another routing protocol\n"
15568 "Open Shortest Path First (OSPFv2)\n"
15569 "Non-main Kernel Routing Table\n"
15570 "Instance ID/Table ID\n"
15571 "Route map reference\n"
15572 "Pointer to route-map entries\n")
596c17ba 15573
585f1adc
IR
15574DEFUN (bgp_redistribute_ipv4_ospf_metric,
15575 bgp_redistribute_ipv4_ospf_metric_cmd,
15576 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15577 "Redistribute information from another routing protocol\n"
15578 "Open Shortest Path First (OSPFv2)\n"
15579 "Non-main Kernel Routing Table\n"
15580 "Instance ID/Table ID\n"
15581 "Metric for redistributed routes\n"
15582 "Default metric\n")
7c8ff89e 15583{
585f1adc
IR
15584 VTY_DECLVAR_CONTEXT(bgp, bgp);
15585 int idx_ospf_table = 1;
d62a17ae 15586 int idx_number = 2;
15587 int idx_number_2 = 4;
585f1adc
IR
15588 uint32_t metric;
15589 struct bgp_redist *red;
15590 unsigned short instance;
15591 int protocol;
15592 bool changed;
15593
15594 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15595 protocol = ZEBRA_ROUTE_OSPF;
15596 else
15597 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15598
585f1adc
IR
15599 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15600 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15601
585f1adc
IR
15602 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15603 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15604 metric);
15605 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15606}
15607
15608ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15609 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15610 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15611 "Redistribute information from another routing protocol\n"
15612 "Open Shortest Path First (OSPFv2)\n"
15613 "Non-main Kernel Routing Table\n"
15614 "Instance ID/Table ID\n"
15615 "Metric for redistributed routes\n"
15616 "Default metric\n")
596c17ba 15617
585f1adc
IR
15618DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
15619 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15620 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15621 "Redistribute information from another routing protocol\n"
15622 "Open Shortest Path First (OSPFv2)\n"
15623 "Non-main Kernel Routing Table\n"
15624 "Instance ID/Table ID\n"
15625 "Route map reference\n"
15626 "Pointer to route-map entries\n"
15627 "Metric for redistributed routes\n"
15628 "Default metric\n")
7c8ff89e 15629{
585f1adc
IR
15630 VTY_DECLVAR_CONTEXT(bgp, bgp);
15631 int idx_ospf_table = 1;
d62a17ae 15632 int idx_number = 2;
15633 int idx_word = 4;
15634 int idx_number_2 = 6;
585f1adc
IR
15635 uint32_t metric;
15636 struct bgp_redist *red;
15637 unsigned short instance;
15638 int protocol;
15639 bool changed;
15640 struct route_map *route_map =
15641 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15642
15643 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15644 protocol = ZEBRA_ROUTE_OSPF;
15645 else
15646 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15647
585f1adc
IR
15648 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15649 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15650
585f1adc
IR
15651 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15652 changed =
15653 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15654 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15655 metric);
15656 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15657}
15658
15659ALIAS_HIDDEN(
15660 bgp_redistribute_ipv4_ospf_rmap_metric,
15661 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15662 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15663 "Redistribute information from another routing protocol\n"
15664 "Open Shortest Path First (OSPFv2)\n"
15665 "Non-main Kernel Routing Table\n"
15666 "Instance ID/Table ID\n"
15667 "Route map reference\n"
15668 "Pointer to route-map entries\n"
15669 "Metric for redistributed routes\n"
15670 "Default metric\n")
596c17ba 15671
585f1adc
IR
15672DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
15673 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15674 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15675 "Redistribute information from another routing protocol\n"
15676 "Open Shortest Path First (OSPFv2)\n"
15677 "Non-main Kernel Routing Table\n"
15678 "Instance ID/Table ID\n"
15679 "Metric for redistributed routes\n"
15680 "Default metric\n"
15681 "Route map reference\n"
15682 "Pointer to route-map entries\n")
7c8ff89e 15683{
585f1adc
IR
15684 VTY_DECLVAR_CONTEXT(bgp, bgp);
15685 int idx_ospf_table = 1;
d62a17ae 15686 int idx_number = 2;
15687 int idx_number_2 = 4;
15688 int idx_word = 6;
585f1adc
IR
15689 uint32_t metric;
15690 struct bgp_redist *red;
15691 unsigned short instance;
15692 int protocol;
15693 bool changed;
15694 struct route_map *route_map =
15695 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15696
15697 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15698 protocol = ZEBRA_ROUTE_OSPF;
15699 else
15700 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15701
585f1adc
IR
15702 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15703 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15704
585f1adc
IR
15705 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15706 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15707 metric);
15708 changed |=
15709 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15710 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15711}
15712
15713ALIAS_HIDDEN(
15714 bgp_redistribute_ipv4_ospf_metric_rmap,
15715 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15716 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15717 "Redistribute information from another routing protocol\n"
15718 "Open Shortest Path First (OSPFv2)\n"
15719 "Non-main Kernel Routing Table\n"
15720 "Instance ID/Table ID\n"
15721 "Metric for redistributed routes\n"
15722 "Default metric\n"
15723 "Route map reference\n"
15724 "Pointer to route-map entries\n")
596c17ba 15725
585f1adc
IR
15726DEFUN (no_bgp_redistribute_ipv4_ospf,
15727 no_bgp_redistribute_ipv4_ospf_cmd,
15728 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15729 NO_STR
15730 "Redistribute information from another routing protocol\n"
15731 "Open Shortest Path First (OSPFv2)\n"
15732 "Non-main Kernel Routing Table\n"
15733 "Instance ID/Table ID\n"
15734 "Metric for redistributed routes\n"
15735 "Default metric\n"
15736 "Route map reference\n"
15737 "Pointer to route-map entries\n")
7c8ff89e 15738{
585f1adc
IR
15739 VTY_DECLVAR_CONTEXT(bgp, bgp);
15740 int idx_ospf_table = 2;
d62a17ae 15741 int idx_number = 3;
585f1adc
IR
15742 unsigned short instance;
15743 int protocol;
37a87b8f 15744
585f1adc
IR
15745 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15746 protocol = ZEBRA_ROUTE_OSPF;
15747 else
15748 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15749
585f1adc
IR
15750 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15751 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
d62a17ae 15752}
15753
15754ALIAS_HIDDEN(
15755 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 15756 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15757 NO_STR
15758 "Redistribute information from another routing protocol\n"
15759 "Open Shortest Path First (OSPFv2)\n"
15760 "Non-main Kernel Routing Table\n"
15761 "Instance ID/Table ID\n"
15762 "Metric for redistributed routes\n"
15763 "Default metric\n"
15764 "Route map reference\n"
15765 "Pointer to route-map entries\n")
596c17ba 15766
585f1adc
IR
15767DEFUN (no_bgp_redistribute_ipv4,
15768 no_bgp_redistribute_ipv4_cmd,
15769 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15770 NO_STR
15771 "Redistribute information from another routing protocol\n"
15772 FRR_IP_REDIST_HELP_STR_BGPD
15773 "Metric for redistributed routes\n"
15774 "Default metric\n"
15775 "Route map reference\n"
15776 "Pointer to route-map entries\n")
718e3744 15777{
585f1adc 15778 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15779 int idx_protocol = 2;
585f1adc 15780 int type;
d62a17ae 15781
585f1adc
IR
15782 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15783 if (type < 0) {
15784 vty_out(vty, "%% Invalid route type\n");
15785 return CMD_WARNING_CONFIG_FAILED;
15786 }
15787 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
d62a17ae 15788}
15789
15790ALIAS_HIDDEN(
15791 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15792 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 15793 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15794 NO_STR
15795 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15796 "Metric for redistributed routes\n"
15797 "Default metric\n"
15798 "Route map reference\n"
15799 "Pointer to route-map entries\n")
596c17ba 15800
585f1adc
IR
15801DEFUN (bgp_redistribute_ipv6,
15802 bgp_redistribute_ipv6_cmd,
15803 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15804 "Redistribute information from another routing protocol\n"
15805 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 15806{
585f1adc 15807 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15808 int idx_protocol = 1;
585f1adc 15809 int type;
718e3744 15810
585f1adc
IR
15811 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15812 if (type < 0) {
15813 vty_out(vty, "%% Invalid route type\n");
15814 return CMD_WARNING_CONFIG_FAILED;
15815 }
718e3744 15816
585f1adc
IR
15817 bgp_redist_add(bgp, AFI_IP6, type, 0);
15818 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 15819}
15820
585f1adc
IR
15821DEFUN (bgp_redistribute_ipv6_rmap,
15822 bgp_redistribute_ipv6_rmap_cmd,
15823 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
15824 "Redistribute information from another routing protocol\n"
15825 FRR_IP6_REDIST_HELP_STR_BGPD
15826 "Route map reference\n"
15827 "Pointer to route-map entries\n")
718e3744 15828{
585f1adc 15829 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15830 int idx_protocol = 1;
15831 int idx_word = 3;
585f1adc
IR
15832 int type;
15833 struct bgp_redist *red;
15834 bool changed;
15835 struct route_map *route_map =
15836 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15837
15838 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15839 if (type < 0) {
15840 vty_out(vty, "%% Invalid route type\n");
15841 return CMD_WARNING_CONFIG_FAILED;
15842 }
37a87b8f 15843
585f1adc
IR
15844 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15845 changed =
15846 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15847 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15848}
15849
585f1adc 15850DEFUN (bgp_redistribute_ipv6_metric,
718e3744 15851 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 15852 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 15853 "Redistribute information from another routing protocol\n"
ab0181ee 15854 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 15855 "Metric for redistributed routes\n"
15856 "Default metric\n")
15857{
585f1adc 15858 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15859 int idx_protocol = 1;
15860 int idx_number = 3;
585f1adc
IR
15861 int type;
15862 uint32_t metric;
15863 struct bgp_redist *red;
15864 bool changed;
15865
15866 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15867 if (type < 0) {
15868 vty_out(vty, "%% Invalid route type\n");
15869 return CMD_WARNING_CONFIG_FAILED;
15870 }
15871 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15872
585f1adc
IR
15873 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15874 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
15875 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15876}
15877
585f1adc
IR
15878DEFUN (bgp_redistribute_ipv6_rmap_metric,
15879 bgp_redistribute_ipv6_rmap_metric_cmd,
15880 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15881 "Redistribute information from another routing protocol\n"
15882 FRR_IP6_REDIST_HELP_STR_BGPD
15883 "Route map reference\n"
15884 "Pointer to route-map entries\n"
15885 "Metric for redistributed routes\n"
15886 "Default metric\n")
718e3744 15887{
585f1adc 15888 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15889 int idx_protocol = 1;
15890 int idx_word = 3;
15891 int idx_number = 5;
585f1adc
IR
15892 int type;
15893 uint32_t metric;
15894 struct bgp_redist *red;
15895 bool changed;
15896 struct route_map *route_map =
15897 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15898
15899 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15900 if (type < 0) {
15901 vty_out(vty, "%% Invalid route type\n");
15902 return CMD_WARNING_CONFIG_FAILED;
15903 }
15904 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15905
585f1adc
IR
15906 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15907 changed =
15908 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15909 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
15910 metric);
15911 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15912}
15913
585f1adc
IR
15914DEFUN (bgp_redistribute_ipv6_metric_rmap,
15915 bgp_redistribute_ipv6_metric_rmap_cmd,
15916 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15917 "Redistribute information from another routing protocol\n"
15918 FRR_IP6_REDIST_HELP_STR_BGPD
15919 "Metric for redistributed routes\n"
15920 "Default metric\n"
15921 "Route map reference\n"
15922 "Pointer to route-map entries\n")
718e3744 15923{
585f1adc 15924 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15925 int idx_protocol = 1;
37a87b8f 15926 int idx_number = 3;
585f1adc
IR
15927 int idx_word = 5;
15928 int type;
15929 uint32_t metric;
15930 struct bgp_redist *red;
15931 bool changed;
15932 struct route_map *route_map =
15933 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15934
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 }
15940 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15941
585f1adc
IR
15942 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15943 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
15944 metric);
15945 changed |=
15946 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15947 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15948}
15949
585f1adc
IR
15950DEFUN (no_bgp_redistribute_ipv6,
15951 no_bgp_redistribute_ipv6_cmd,
15952 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15953 NO_STR
15954 "Redistribute information from another routing protocol\n"
15955 FRR_IP6_REDIST_HELP_STR_BGPD
15956 "Metric for redistributed routes\n"
15957 "Default metric\n"
15958 "Route map reference\n"
15959 "Pointer to route-map entries\n")
718e3744 15960{
585f1adc 15961 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15962 int idx_protocol = 2;
585f1adc 15963 int type;
37a87b8f 15964
585f1adc
IR
15965 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15966 if (type < 0) {
15967 vty_out(vty, "%% Invalid route type\n");
15968 return CMD_WARNING_CONFIG_FAILED;
15969 }
718e3744 15970
585f1adc 15971 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
d62a17ae 15972}
15973
4ab46701
AR
15974/* Neighbor update tcp-mss. */
15975static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
15976 const char *tcp_mss_str)
15977{
15978 struct peer *peer;
15979 uint32_t tcp_mss_val = 0;
15980
15981 peer = peer_and_group_lookup_vty(vty, peer_str);
15982 if (!peer)
15983 return CMD_WARNING_CONFIG_FAILED;
15984
15985 if (tcp_mss_str) {
15986 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
15987 peer_tcp_mss_set(peer, tcp_mss_val);
15988 } else {
15989 peer_tcp_mss_unset(peer);
15990 }
15991
15992 return CMD_SUCCESS;
15993}
15994
15995DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
15996 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
15997 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
15998 "TCP max segment size\n"
15999 "TCP MSS value\n")
16000{
16001 int peer_index = 1;
16002 int mss_index = 3;
16003
16004 vty_out(vty,
16005 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16006 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16007 argv[mss_index]->arg);
16008}
16009
16010DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16011 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16012 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16013 "TCP max segment size\n"
16014 "TCP MSS value\n")
16015{
16016 int peer_index = 2;
16017
16018 vty_out(vty,
16019 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16020 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16021}
16022
dd65f45e
DL
16023static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16024 afi_t afi, safi_t safi)
d62a17ae 16025{
16026 int i;
16027
16028 /* Unicast redistribution only. */
16029 if (safi != SAFI_UNICAST)
2b791107 16030 return;
d62a17ae 16031
16032 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16033 /* Redistribute BGP does not make sense. */
16034 if (i != ZEBRA_ROUTE_BGP) {
16035 struct list *red_list;
16036 struct listnode *node;
16037 struct bgp_redist *red;
16038
16039 red_list = bgp->redist[afi][i];
16040 if (!red_list)
16041 continue;
16042
16043 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16044 /* "redistribute" configuration. */
16045 vty_out(vty, " redistribute %s",
16046 zebra_route_string(i));
16047 if (red->instance)
16048 vty_out(vty, " %d", red->instance);
16049 if (red->redist_metric_flag)
16050 vty_out(vty, " metric %u",
16051 red->redist_metric);
16052 if (red->rmap.name)
16053 vty_out(vty, " route-map %s",
16054 red->rmap.name);
16055 vty_out(vty, "\n");
16056 }
16057 }
16058 }
718e3744 16059}
6b0655a2 16060
dd65f45e
DL
16061/* peer-group helpers for config-write */
16062
16063static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16064{
16065 if (!peer_group_active(peer)) {
16066 if (CHECK_FLAG(peer->flags_invert, flag))
16067 return !CHECK_FLAG(peer->flags, flag);
16068 else
16069 return !!CHECK_FLAG(peer->flags, flag);
16070 }
16071
16072 return !!CHECK_FLAG(peer->flags_override, flag);
16073}
16074
16075static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16076 uint32_t flag)
16077{
16078 if (!peer_group_active(peer)) {
16079 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16080 return !peer_af_flag_check(peer, afi, safi, flag);
16081 else
16082 return !!peer_af_flag_check(peer, afi, safi, flag);
16083 }
16084
16085 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16086}
16087
16088static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16089 uint8_t type, int direct)
16090{
16091 struct bgp_filter *filter;
16092
16093 if (peer_group_active(peer))
16094 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16095 type);
16096
16097 filter = &peer->filter[afi][safi];
16098 switch (type) {
16099 case PEER_FT_DISTRIBUTE_LIST:
16100 return !!(filter->dlist[direct].name);
16101 case PEER_FT_FILTER_LIST:
16102 return !!(filter->aslist[direct].name);
16103 case PEER_FT_PREFIX_LIST:
16104 return !!(filter->plist[direct].name);
16105 case PEER_FT_ROUTE_MAP:
16106 return !!(filter->map[direct].name);
16107 case PEER_FT_UNSUPPRESS_MAP:
16108 return !!(filter->usmap.name);
7f7940e6
MK
16109 case PEER_FT_ADVERTISE_MAP:
16110 return !!(filter->advmap.aname
16111 && ((filter->advmap.condition == direct)
16112 && filter->advmap.cname));
dd65f45e
DL
16113 default:
16114 return false;
16115 }
16116}
16117
16118/* Return true if the addpath type is set for peer and different from
16119 * peer-group.
16120 */
3dc339cd
DA
16121static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16122 safi_t safi)
dd65f45e
DL
16123{
16124 enum bgp_addpath_strat type, g_type;
16125
16126 type = peer->addpath_type[afi][safi];
16127
16128 if (type != BGP_ADDPATH_NONE) {
16129 if (peer_group_active(peer)) {
16130 g_type = peer->group->conf->addpath_type[afi][safi];
16131
16132 if (type != g_type)
3dc339cd 16133 return true;
dd65f45e 16134 else
3dc339cd 16135 return false;
dd65f45e
DL
16136 }
16137
3dc339cd 16138 return true;
dd65f45e
DL
16139 }
16140
3dc339cd 16141 return false;
dd65f45e
DL
16142}
16143
b9c7bc5a 16144/* This is part of the address-family block (unicast only) */
dd65f45e 16145static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16146 afi_t afi)
16147{
b9c7bc5a 16148 int indent = 2;
53970de3 16149 uint32_t tovpn_sid_index = 0;
ddb5b488 16150
8a066a70 16151 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16152 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16153 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16154 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16155 bgp->vpn_policy[afi]
bb4f6190 16156 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16157 else
16158 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16159 bgp->vpn_policy[afi]
16160 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16161 }
12a844a5
DS
16162 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16163 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16164 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16165 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16166 return;
16167
e70e9f8e
PZ
16168 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16169 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16170
16171 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16172
16173 } else {
16174 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16175 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16176 bgp->vpn_policy[afi].tovpn_label);
16177 }
ddb5b488 16178 }
53970de3
RS
16179
16180 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16181 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16182 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16183 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16184 } else if (tovpn_sid_index != 0) {
16185 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16186 tovpn_sid_index);
16187 }
16188
ddb5b488
PZ
16189 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16190 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16191 char buf[RD_ADDRSTRLEN];
b9c7bc5a 16192 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
16193 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16194 sizeof(buf)));
16195 }
16196 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16197 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16198
16199 char buf[PREFIX_STRLEN];
16200 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16201 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16202 sizeof(buf))) {
16203
b9c7bc5a
PZ
16204 vty_out(vty, "%*snexthop vpn export %s\n",
16205 indent, "", buf);
ddb5b488
PZ
16206 }
16207 }
16208 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16209 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16210 && ecommunity_cmp(
16211 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16212 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16213
16214 char *b = ecommunity_ecom2str(
16215 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16216 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16217 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16218 XFREE(MTYPE_ECOMMUNITY_STR, b);
16219 } else {
16220 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16221 char *b = ecommunity_ecom2str(
16222 bgp->vpn_policy[afi]
16223 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16224 ECOMMUNITY_FORMAT_ROUTE_MAP,
16225 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16226 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16227 XFREE(MTYPE_ECOMMUNITY_STR, b);
16228 }
16229 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16230 char *b = ecommunity_ecom2str(
16231 bgp->vpn_policy[afi]
16232 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16233 ECOMMUNITY_FORMAT_ROUTE_MAP,
16234 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16235 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16236 XFREE(MTYPE_ECOMMUNITY_STR, b);
16237 }
16238 }
bb4f6190
DS
16239
16240 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16241 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16242 bgp->vpn_policy[afi]
16243 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16244
301ad80a
PG
16245 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16246 char *b = ecommunity_ecom2str(
16247 bgp->vpn_policy[afi]
16248 .import_redirect_rtlist,
16249 ECOMMUNITY_FORMAT_ROUTE_MAP,
16250 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16251
9a659715
PG
16252 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16253 != ECOMMUNITY_SIZE)
c6423c31 16254 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16255 indent, "", b);
16256 else
16257 vty_out(vty, "%*srt redirect import %s\n",
16258 indent, "", b);
301ad80a
PG
16259 XFREE(MTYPE_ECOMMUNITY_STR, b);
16260 }
ddb5b488
PZ
16261}
16262
dd65f45e
DL
16263static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16264 afi_t afi, safi_t safi)
16265{
16266 struct bgp_filter *filter;
16267 char *addr;
16268
16269 addr = peer->host;
16270 filter = &peer->filter[afi][safi];
16271
16272 /* distribute-list. */
16273 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16274 FILTER_IN))
16275 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16276 filter->dlist[FILTER_IN].name);
16277
16278 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16279 FILTER_OUT))
16280 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16281 filter->dlist[FILTER_OUT].name);
16282
16283 /* prefix-list. */
16284 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16285 FILTER_IN))
16286 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16287 filter->plist[FILTER_IN].name);
16288
16289 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16290 FILTER_OUT))
16291 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16292 filter->plist[FILTER_OUT].name);
16293
16294 /* route-map. */
16295 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16296 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16297 filter->map[RMAP_IN].name);
16298
16299 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16300 RMAP_OUT))
16301 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16302 filter->map[RMAP_OUT].name);
16303
16304 /* unsuppress-map */
16305 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16306 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16307 filter->usmap.name);
16308
7f7940e6
MK
16309 /* advertise-map : always applied in OUT direction*/
16310 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16311 CONDITION_NON_EXIST))
16312 vty_out(vty,
16313 " neighbor %s advertise-map %s non-exist-map %s\n",
16314 addr, filter->advmap.aname, filter->advmap.cname);
16315
16316 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16317 CONDITION_EXIST))
16318 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16319 addr, filter->advmap.aname, filter->advmap.cname);
16320
dd65f45e
DL
16321 /* filter-list. */
16322 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16323 FILTER_IN))
16324 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16325 filter->aslist[FILTER_IN].name);
16326
16327 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16328 FILTER_OUT))
16329 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16330 filter->aslist[FILTER_OUT].name);
16331}
16332
16333/* BGP peer configuration display function. */
16334static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16335 struct peer *peer)
16336{
16337 struct peer *g_peer = NULL;
16338 char buf[SU_ADDRSTRLEN];
16339 char *addr;
16340 int if_pg_printed = false;
16341 int if_ras_printed = false;
16342
16343 /* Skip dynamic neighbors. */
16344 if (peer_dynamic_neighbor(peer))
16345 return;
16346
16347 if (peer->conf_if)
16348 addr = peer->conf_if;
16349 else
16350 addr = peer->host;
16351
16352 /************************************
16353 ****** Global to the neighbor ******
16354 ************************************/
16355 if (peer->conf_if) {
16356 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16357 vty_out(vty, " neighbor %s interface v6only", addr);
16358 else
16359 vty_out(vty, " neighbor %s interface", addr);
16360
16361 if (peer_group_active(peer)) {
16362 vty_out(vty, " peer-group %s", peer->group->name);
16363 if_pg_printed = true;
16364 } else if (peer->as_type == AS_SPECIFIED) {
16365 vty_out(vty, " remote-as %u", peer->as);
16366 if_ras_printed = true;
16367 } else if (peer->as_type == AS_INTERNAL) {
16368 vty_out(vty, " remote-as internal");
16369 if_ras_printed = true;
16370 } else if (peer->as_type == AS_EXTERNAL) {
16371 vty_out(vty, " remote-as external");
16372 if_ras_printed = true;
16373 }
16374
16375 vty_out(vty, "\n");
16376 }
16377
16378 /* remote-as and peer-group */
16379 /* peer is a member of a peer-group */
16380 if (peer_group_active(peer)) {
16381 g_peer = peer->group->conf;
16382
16383 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16384 if (peer->as_type == AS_SPECIFIED) {
16385 vty_out(vty, " neighbor %s remote-as %u\n",
16386 addr, peer->as);
16387 } else if (peer->as_type == AS_INTERNAL) {
16388 vty_out(vty,
16389 " neighbor %s remote-as internal\n",
16390 addr);
16391 } else if (peer->as_type == AS_EXTERNAL) {
16392 vty_out(vty,
16393 " neighbor %s remote-as external\n",
16394 addr);
16395 }
16396 }
16397
16398 /* For swpX peers we displayed the peer-group
16399 * via 'neighbor swpX interface peer-group PGNAME' */
16400 if (!if_pg_printed)
16401 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16402 peer->group->name);
16403 }
16404
16405 /* peer is NOT a member of a peer-group */
16406 else {
16407 /* peer is a peer-group, declare the peer-group */
16408 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16409 vty_out(vty, " neighbor %s peer-group\n", addr);
16410 }
16411
16412 if (!if_ras_printed) {
16413 if (peer->as_type == AS_SPECIFIED) {
16414 vty_out(vty, " neighbor %s remote-as %u\n",
16415 addr, peer->as);
16416 } else if (peer->as_type == AS_INTERNAL) {
16417 vty_out(vty,
16418 " neighbor %s remote-as internal\n",
16419 addr);
16420 } else if (peer->as_type == AS_EXTERNAL) {
16421 vty_out(vty,
16422 " neighbor %s remote-as external\n",
16423 addr);
16424 }
16425 }
16426 }
16427
16428 /* local-as */
16429 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16430 vty_out(vty, " neighbor %s local-as %u", addr,
16431 peer->change_local_as);
16432 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16433 vty_out(vty, " no-prepend");
16434 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16435 vty_out(vty, " replace-as");
16436 vty_out(vty, "\n");
16437 }
16438
16439 /* description */
16440 if (peer->desc) {
16441 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16442 }
16443
16444 /* shutdown */
16445 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16446 if (peer->tx_shutdown_message)
16447 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16448 peer->tx_shutdown_message);
16449 else
16450 vty_out(vty, " neighbor %s shutdown\n", addr);
16451 }
16452
8336c896
DA
16453 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16454 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16455 peer->rtt_expected, peer->rtt_keepalive_conf);
16456
dd65f45e 16457 /* bfd */
21bfce98
RZ
16458 if (peer->bfd_config)
16459 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
16460
16461 /* password */
16462 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16463 vty_out(vty, " neighbor %s password %s\n", addr,
16464 peer->password);
16465
16466 /* neighbor solo */
16467 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16468 if (!peer_group_active(peer)) {
16469 vty_out(vty, " neighbor %s solo\n", addr);
16470 }
16471 }
16472
16473 /* BGP port */
16474 if (peer->port != BGP_PORT_DEFAULT) {
16475 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16476 }
16477
16478 /* Local interface name */
16479 if (peer->ifname) {
16480 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16481 }
16482
4ab46701
AR
16483 /* TCP max segment size */
16484 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16485 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16486
dd65f45e
DL
16487 /* passive */
16488 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16489 vty_out(vty, " neighbor %s passive\n", addr);
16490
16491 /* ebgp-multihop */
16492 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
16493 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16494 && peer->ttl == MAXTTL)) {
dd65f45e
DL
16495 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16496 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16497 peer->ttl);
16498 }
16499 }
16500
16501 /* ttl-security hops */
e2521429 16502 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
16503 if (!peer_group_active(peer)
16504 || g_peer->gtsm_hops != peer->gtsm_hops) {
16505 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16506 addr, peer->gtsm_hops);
16507 }
16508 }
16509
16510 /* disable-connected-check */
16511 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16512 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16513
27aa23a4
DA
16514 /* link-bw-encoding-ieee */
16515 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16516 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16517 addr);
16518
d08c0c80
DA
16519 /* extended-optional-parameters */
16520 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16521 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16522 addr);
16523
dd65f45e
DL
16524 /* enforce-first-as */
16525 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16526 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16527
16528 /* update-source */
16529 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16530 if (peer->update_source)
16531 vty_out(vty, " neighbor %s update-source %s\n", addr,
16532 sockunion2str(peer->update_source, buf,
16533 SU_ADDRSTRLEN));
16534 else if (peer->update_if)
16535 vty_out(vty, " neighbor %s update-source %s\n", addr,
16536 peer->update_if);
16537 }
16538
16539 /* advertisement-interval */
16540 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16541 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16542 peer->routeadv);
16543
16544 /* timers */
16545 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16546 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16547 peer->keepalive, peer->holdtime);
16548
16549 /* timers connect */
16550 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16551 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16552 peer->connect);
5d5393b9
DL
16553 /* need special-case handling for changed default values due to
16554 * config profile / version (because there is no "timers bgp connect"
16555 * command, we need to save this per-peer :/)
16556 */
16557 else if (!peer_group_active(peer) && !peer->connect &&
16558 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16559 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16560 peer->bgp->default_connect_retry);
dd65f45e 16561
d43114f3
DS
16562 /* timers delayopen */
16563 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16564 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16565 peer->delayopen);
16566 /* Save config even though flag is not set if default values have been
16567 * changed
16568 */
16569 else if (!peer_group_active(peer) && !peer->delayopen
16570 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16571 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16572 peer->bgp->default_delayopen);
16573
dd65f45e
DL
16574 /* capability dynamic */
16575 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16576 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16577
16578 /* capability extended-nexthop */
16579 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
843770f6
DA
16580 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE))
16581 vty_out(vty,
16582 " no neighbor %s capability extended-nexthop\n",
16583 addr);
16584 else if (!peer->conf_if)
16585 vty_out(vty,
16586 " neighbor %s capability extended-nexthop\n",
16587 addr);
dd65f45e
DL
16588 }
16589
16590 /* dont-capability-negotiation */
16591 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16592 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16593
16594 /* override-capability */
16595 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16596 vty_out(vty, " neighbor %s override-capability\n", addr);
16597
16598 /* strict-capability-match */
16599 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16600 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16601
16602 /* Sender side AS path loop detection. */
16603 if (peer->as_path_loop_detection)
16604 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16605 addr);
cfd47646 16606
16607 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16608 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 16609
16610 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16611 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 16612 vty_out(vty,
16613 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
16614 } else if (CHECK_FLAG(
16615 peer->peer_gr_new_status_flag,
16616 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 16617 vty_out(vty,
16618 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
16619 } else if (
16620 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16621 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16622 && !(CHECK_FLAG(
16623 peer->peer_gr_new_status_flag,
16624 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16625 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16626 addr);
cfd47646 16627 }
16628 }
dd65f45e
DL
16629}
16630
16631/* BGP peer configuration display function. */
16632static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16633 struct peer *peer, afi_t afi, safi_t safi)
16634{
16635 struct peer *g_peer = NULL;
16636 char *addr;
16637 bool flag_scomm, flag_secomm, flag_slcomm;
16638
16639 /* Skip dynamic neighbors. */
16640 if (peer_dynamic_neighbor(peer))
16641 return;
16642
16643 if (peer->conf_if)
16644 addr = peer->conf_if;
16645 else
16646 addr = peer->host;
16647
16648 /************************************
16649 ****** Per AF to the neighbor ******
16650 ************************************/
16651 if (peer_group_active(peer)) {
16652 g_peer = peer->group->conf;
16653
16654 /* If the peer-group is active but peer is not, print a 'no
16655 * activate' */
16656 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16657 vty_out(vty, " no neighbor %s activate\n", addr);
16658 }
16659
16660 /* If the peer-group is not active but peer is, print an
16661 'activate' */
16662 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16663 vty_out(vty, " neighbor %s activate\n", addr);
16664 }
16665 } else {
16666 if (peer->afc[afi][safi]) {
38d11af5
TA
16667 if (safi == SAFI_ENCAP)
16668 vty_out(vty, " neighbor %s activate\n", addr);
16669 else if (!bgp->default_af[afi][safi])
dd65f45e
DL
16670 vty_out(vty, " neighbor %s activate\n", addr);
16671 } else {
38d11af5
TA
16672 if (bgp->default_af[afi][safi])
16673 vty_out(vty, " no neighbor %s activate\n",
16674 addr);
dd65f45e
DL
16675 }
16676 }
16677
16678 /* addpath TX knobs */
16679 if (peergroup_af_addpath_check(peer, afi, safi)) {
16680 switch (peer->addpath_type[afi][safi]) {
16681 case BGP_ADDPATH_ALL:
16682 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16683 addr);
16684 break;
16685 case BGP_ADDPATH_BEST_PER_AS:
16686 vty_out(vty,
16687 " neighbor %s addpath-tx-bestpath-per-AS\n",
16688 addr);
16689 break;
16690 case BGP_ADDPATH_MAX:
16691 case BGP_ADDPATH_NONE:
16692 break;
16693 }
16694 }
16695
7c0e4312
DA
16696 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
16697 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
16698
dd65f45e
DL
16699 /* ORF capability. */
16700 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16701 || peergroup_af_flag_check(peer, afi, safi,
16702 PEER_FLAG_ORF_PREFIX_RM)) {
16703 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16704
16705 if (peergroup_af_flag_check(peer, afi, safi,
16706 PEER_FLAG_ORF_PREFIX_SM)
16707 && peergroup_af_flag_check(peer, afi, safi,
16708 PEER_FLAG_ORF_PREFIX_RM))
16709 vty_out(vty, " both");
16710 else if (peergroup_af_flag_check(peer, afi, safi,
16711 PEER_FLAG_ORF_PREFIX_SM))
16712 vty_out(vty, " send");
16713 else
16714 vty_out(vty, " receive");
16715 vty_out(vty, "\n");
16716 }
16717
dd65f45e
DL
16718 /* Route reflector client. */
16719 if (peergroup_af_flag_check(peer, afi, safi,
16720 PEER_FLAG_REFLECTOR_CLIENT)) {
16721 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16722 }
16723
16724 /* next-hop-self force */
16725 if (peergroup_af_flag_check(peer, afi, safi,
16726 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16727 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16728 }
16729
16730 /* next-hop-self */
16731 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16732 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16733 }
16734
16735 /* remove-private-AS */
16736 if (peergroup_af_flag_check(peer, afi, safi,
16737 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16738 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16739 addr);
16740 }
16741
16742 else if (peergroup_af_flag_check(peer, afi, safi,
16743 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16744 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16745 addr);
16746 }
16747
16748 else if (peergroup_af_flag_check(peer, afi, safi,
16749 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16750 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16751 }
16752
16753 else if (peergroup_af_flag_check(peer, afi, safi,
16754 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16755 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16756 }
16757
16758 /* as-override */
16759 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16760 vty_out(vty, " neighbor %s as-override\n", addr);
16761 }
16762
16763 /* send-community print. */
16764 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16765 PEER_FLAG_SEND_COMMUNITY);
16766 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16767 PEER_FLAG_SEND_EXT_COMMUNITY);
16768 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16769 PEER_FLAG_SEND_LARGE_COMMUNITY);
16770
16771 if (flag_scomm && flag_secomm && flag_slcomm) {
16772 vty_out(vty, " no neighbor %s send-community all\n", addr);
16773 } else {
16774 if (flag_scomm)
16775 vty_out(vty, " no neighbor %s send-community\n", addr);
16776 if (flag_secomm)
16777 vty_out(vty,
16778 " no neighbor %s send-community extended\n",
16779 addr);
16780
16781 if (flag_slcomm)
16782 vty_out(vty, " no neighbor %s send-community large\n",
16783 addr);
16784 }
16785
16786 /* Default information */
16787 if (peergroup_af_flag_check(peer, afi, safi,
16788 PEER_FLAG_DEFAULT_ORIGINATE)) {
16789 vty_out(vty, " neighbor %s default-originate", addr);
16790
16791 if (peer->default_rmap[afi][safi].name)
16792 vty_out(vty, " route-map %s",
16793 peer->default_rmap[afi][safi].name);
16794
16795 vty_out(vty, "\n");
16796 }
16797
16798 /* Soft reconfiguration inbound. */
16799 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16800 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16801 addr);
16802 }
16803
16804 /* maximum-prefix. */
16805 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 16806 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
16807 peer->pmax[afi][safi]);
16808
16809 if (peer->pmax_threshold[afi][safi]
16810 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16811 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16812 if (peer_af_flag_check(peer, afi, safi,
16813 PEER_FLAG_MAX_PREFIX_WARNING))
16814 vty_out(vty, " warning-only");
16815 if (peer->pmax_restart[afi][safi])
16816 vty_out(vty, " restart %u",
16817 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
16818 if (peer_af_flag_check(peer, afi, safi,
16819 PEER_FLAG_MAX_PREFIX_FORCE))
16820 vty_out(vty, " force");
dd65f45e
DL
16821
16822 vty_out(vty, "\n");
16823 }
16824
fde246e8
DA
16825 /* maximum-prefix-out */
16826 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 16827 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
16828 addr, peer->pmax_out[afi][safi]);
16829
dd65f45e
DL
16830 /* Route server client. */
16831 if (peergroup_af_flag_check(peer, afi, safi,
16832 PEER_FLAG_RSERVER_CLIENT)) {
16833 vty_out(vty, " neighbor %s route-server-client\n", addr);
16834 }
16835
16836 /* Nexthop-local unchanged. */
16837 if (peergroup_af_flag_check(peer, afi, safi,
16838 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16839 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16840 }
16841
16842 /* allowas-in <1-10> */
16843 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16844 if (peer_af_flag_check(peer, afi, safi,
16845 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16846 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16847 } else if (peer->allowas_in[afi][safi] == 3) {
16848 vty_out(vty, " neighbor %s allowas-in\n", addr);
16849 } else {
16850 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16851 peer->allowas_in[afi][safi]);
16852 }
16853 }
16854
16855 /* weight */
16856 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16857 vty_out(vty, " neighbor %s weight %lu\n", addr,
16858 peer->weight[afi][safi]);
16859
16860 /* Filter. */
16861 bgp_config_write_filter(vty, peer, afi, safi);
16862
16863 /* atribute-unchanged. */
16864 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16865 || (safi != SAFI_EVPN
16866 && peer_af_flag_check(peer, afi, safi,
16867 PEER_FLAG_NEXTHOP_UNCHANGED))
16868 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16869
16870 if (!peer_group_active(peer)
16871 || peergroup_af_flag_check(peer, afi, safi,
16872 PEER_FLAG_AS_PATH_UNCHANGED)
16873 || peergroup_af_flag_check(peer, afi, safi,
16874 PEER_FLAG_NEXTHOP_UNCHANGED)
16875 || peergroup_af_flag_check(peer, afi, safi,
16876 PEER_FLAG_MED_UNCHANGED)) {
16877
16878 vty_out(vty,
16879 " neighbor %s attribute-unchanged%s%s%s\n",
16880 addr,
16881 peer_af_flag_check(peer, afi, safi,
16882 PEER_FLAG_AS_PATH_UNCHANGED)
16883 ? " as-path"
16884 : "",
16885 peer_af_flag_check(peer, afi, safi,
16886 PEER_FLAG_NEXTHOP_UNCHANGED)
16887 ? " next-hop"
16888 : "",
16889 peer_af_flag_check(peer, afi, safi,
16890 PEER_FLAG_MED_UNCHANGED)
16891 ? " med"
16892 : "");
16893 }
16894 }
16895}
16896
16897/* Address family based peer configuration display. */
16898static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
16899 safi_t safi)
16900{
16901 struct peer *peer;
16902 struct peer_group *group;
16903 struct listnode *node, *nnode;
16904
16905
16906 vty_frame(vty, " !\n address-family ");
16907 if (afi == AFI_IP) {
16908 if (safi == SAFI_UNICAST)
16909 vty_frame(vty, "ipv4 unicast");
16910 else if (safi == SAFI_LABELED_UNICAST)
16911 vty_frame(vty, "ipv4 labeled-unicast");
16912 else if (safi == SAFI_MULTICAST)
16913 vty_frame(vty, "ipv4 multicast");
16914 else if (safi == SAFI_MPLS_VPN)
16915 vty_frame(vty, "ipv4 vpn");
16916 else if (safi == SAFI_ENCAP)
16917 vty_frame(vty, "ipv4 encap");
16918 else if (safi == SAFI_FLOWSPEC)
16919 vty_frame(vty, "ipv4 flowspec");
16920 } else if (afi == AFI_IP6) {
16921 if (safi == SAFI_UNICAST)
16922 vty_frame(vty, "ipv6 unicast");
16923 else if (safi == SAFI_LABELED_UNICAST)
16924 vty_frame(vty, "ipv6 labeled-unicast");
16925 else if (safi == SAFI_MULTICAST)
16926 vty_frame(vty, "ipv6 multicast");
16927 else if (safi == SAFI_MPLS_VPN)
16928 vty_frame(vty, "ipv6 vpn");
16929 else if (safi == SAFI_ENCAP)
16930 vty_frame(vty, "ipv6 encap");
16931 else if (safi == SAFI_FLOWSPEC)
16932 vty_frame(vty, "ipv6 flowspec");
16933 } else if (afi == AFI_L2VPN) {
16934 if (safi == SAFI_EVPN)
16935 vty_frame(vty, "l2vpn evpn");
16936 }
16937 vty_frame(vty, "\n");
16938
16939 bgp_config_write_distance(vty, bgp, afi, safi);
16940
16941 bgp_config_write_network(vty, bgp, afi, safi);
16942
16943 bgp_config_write_redistribute(vty, bgp, afi, safi);
16944
8a4e7fe6
DA
16945 /* BGP flag dampening. */
16946 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6c75f4b3 16947 bgp_config_write_damp(vty, afi, safi);
8a4e7fe6 16948
dd65f45e
DL
16949 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
16950 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
16951
16952 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
16953 /* Do not display doppelganger peers */
16954 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16955 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
16956 }
16957
16958 bgp_config_write_maxpaths(vty, bgp, afi, safi);
16959 bgp_config_write_table_map(vty, bgp, afi, safi);
16960
16961 if (safi == SAFI_EVPN)
16962 bgp_config_write_evpn_info(vty, bgp, afi, safi);
16963
16964 if (safi == SAFI_FLOWSPEC)
16965 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
16966
16967 if (safi == SAFI_UNICAST) {
16968 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
16969 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16970 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
16971
16972 vty_out(vty, " export vpn\n");
16973 }
16974 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16975 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
16976
16977 vty_out(vty, " import vpn\n");
16978 }
16979 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16980 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
16981 char *name;
16982
16983 for (ALL_LIST_ELEMENTS_RO(
16984 bgp->vpn_policy[afi].import_vrf, node,
16985 name))
16986 vty_out(vty, " import vrf %s\n", name);
16987 }
16988 }
16989
16990 vty_endframe(vty, " exit-address-family\n");
16991}
16992
16993int bgp_config_write(struct vty *vty)
16994{
16995 struct bgp *bgp;
16996 struct peer_group *group;
16997 struct peer *peer;
16998 struct listnode *node, *nnode;
16999 struct listnode *mnode, *mnnode;
b16bcbba
TA
17000 afi_t afi;
17001 safi_t safi;
dd65f45e
DL
17002
17003 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17004 vty_out(vty, "bgp route-map delay-timer %u\n",
17005 bm->rmap_update_timer);
17006
d70583f7
D
17007 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17008 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17009 if (bm->v_update_delay != bm->v_establish_wait)
17010 vty_out(vty, " %d", bm->v_establish_wait);
17011 vty_out(vty, "\n");
17012 }
17013
9acb67cb
DS
17014 if (bm->wait_for_fib)
17015 vty_out(vty, "bgp suppress-fib-pending\n");
17016
05bd726c 17017 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17018 vty_out(vty, "bgp graceful-shutdown\n");
17019
c163f297
DS
17020 /* No-RIB (Zebra) option flag configuration */
17021 if (bgp_option_check(BGP_OPT_NO_FIB))
17022 vty_out(vty, "bgp no-rib\n");
17023
870791a3
IR
17024 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17025 vty_out(vty, "bgp send-extra-data zebra\n");
e46723a5 17026
dd65f45e
DL
17027 /* BGP configuration. */
17028 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17029
17030 /* skip all auto created vrf as they dont have user config */
17031 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17032 continue;
17033
17034 /* Router bgp ASN */
17035 vty_out(vty, "router bgp %u", bgp->as);
17036
17037 if (bgp->name)
17038 vty_out(vty, " %s %s",
17039 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17040 ? "view" : "vrf", bgp->name);
17041 vty_out(vty, "\n");
17042
17043 /* BGP fast-external-failover. */
17044 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17045 vty_out(vty, " no bgp fast-external-failover\n");
17046
17047 /* BGP router ID. */
3a6290bd 17048 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17049 vty_out(vty, " bgp router-id %pI4\n",
17050 &bgp->router_id_static);
dd65f45e 17051
c208c586
S
17052 /* Suppress fib pending */
17053 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17054 vty_out(vty, " bgp suppress-fib-pending\n");
17055
dd65f45e 17056 /* BGP log-neighbor-changes. */
892fedb6 17057 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17058 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17059 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17060 CHECK_FLAG(bgp->flags,
17061 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17062 ? ""
17063 : "no ");
17064
17065 /* BGP configuration. */
892fedb6 17066 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17067 vty_out(vty, " bgp always-compare-med\n");
17068
17069 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17070 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17071 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17072 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17073 CHECK_FLAG(bgp->flags,
17074 BGP_FLAG_EBGP_REQUIRES_POLICY)
17075 ? ""
17076 : "no ");
dd65f45e
DL
17077
17078 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17079 if (bgp->reject_as_sets)
dd65f45e
DL
17080 vty_out(vty, " bgp reject-as-sets\n");
17081
2adac256
DA
17082 /* Suppress duplicate updates if the route actually not changed
17083 */
17084 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17085 != SAVE_BGP_SUPPRESS_DUPLICATES)
17086 vty_out(vty, " %sbgp suppress-duplicates\n",
17087 CHECK_FLAG(bgp->flags,
17088 BGP_FLAG_SUPPRESS_DUPLICATES)
17089 ? ""
17090 : "no ");
17091
b16bcbba
TA
17092 /* BGP default <afi>-<safi> */
17093 FOREACH_AFI_SAFI (afi, safi) {
17094 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17095 if (!bgp->default_af[afi][safi])
17096 vty_out(vty, " no bgp default %s\n",
17097 get_bgp_default_af_flag(afi,
17098 safi));
17099 } else if (bgp->default_af[afi][safi])
17100 vty_out(vty, " bgp default %s\n",
17101 get_bgp_default_af_flag(afi, safi));
17102 }
e84c59af 17103
dd65f45e
DL
17104 /* BGP default local-preference. */
17105 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17106 vty_out(vty, " bgp default local-preference %u\n",
17107 bgp->default_local_pref);
17108
17109 /* BGP default show-hostname */
892fedb6 17110 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17111 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17112 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17113 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17114 ? ""
17115 : "no ");
17116
aef999a2
DA
17117 /* BGP default show-nexthop-hostname */
17118 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17119 != SAVE_BGP_SHOW_HOSTNAME)
17120 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17121 CHECK_FLAG(bgp->flags,
17122 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17123 ? ""
17124 : "no ");
17125
dd65f45e
DL
17126 /* BGP default subgroup-pkt-queue-max. */
17127 if (bgp->default_subgroup_pkt_queue_max
17128 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17129 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17130 bgp->default_subgroup_pkt_queue_max);
17131
17132 /* BGP client-to-client reflection. */
892fedb6 17133 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17134 vty_out(vty, " no bgp client-to-client reflection\n");
17135
17136 /* BGP cluster ID. */
17137 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17138 vty_out(vty, " bgp cluster-id %pI4\n",
17139 &bgp->cluster_id);
dd65f45e
DL
17140
17141 /* Disable ebgp connected nexthop check */
892fedb6 17142 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17143 vty_out(vty,
17144 " bgp disable-ebgp-connected-route-check\n");
17145
17146 /* Confederation identifier*/
17147 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17148 vty_out(vty, " bgp confederation identifier %u\n",
17149 bgp->confed_id);
17150
17151 /* Confederation peer */
17152 if (bgp->confed_peers_cnt > 0) {
17153 int i;
17154
17155 vty_out(vty, " bgp confederation peers");
17156
17157 for (i = 0; i < bgp->confed_peers_cnt; i++)
17158 vty_out(vty, " %u", bgp->confed_peers[i]);
17159
17160 vty_out(vty, "\n");
17161 }
17162
17163 /* BGP deterministic-med. */
892fedb6 17164 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 17165 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 17166 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
17167 CHECK_FLAG(bgp->flags,
17168 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
17169 ? ""
17170 : "no ");
17171
17172 /* BGP update-delay. */
17173 bgp_config_write_update_delay(vty, bgp);
17174
17175 if (bgp->v_maxmed_onstartup
17176 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17177 vty_out(vty, " bgp max-med on-startup %u",
17178 bgp->v_maxmed_onstartup);
17179 if (bgp->maxmed_onstartup_value
17180 != BGP_MAXMED_VALUE_DEFAULT)
17181 vty_out(vty, " %u",
17182 bgp->maxmed_onstartup_value);
17183 vty_out(vty, "\n");
17184 }
17185 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17186 vty_out(vty, " bgp max-med administrative");
17187 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17188 vty_out(vty, " %u", bgp->maxmed_admin_value);
17189 vty_out(vty, "\n");
17190 }
17191
17192 /* write quanta */
17193 bgp_config_write_wpkt_quanta(vty, bgp);
17194 /* read quanta */
17195 bgp_config_write_rpkt_quanta(vty, bgp);
17196
17197 /* coalesce time */
17198 bgp_config_write_coalesce_time(vty, bgp);
17199
05bd726c 17200 /* BGP per-instance graceful-shutdown */
17201 /* BGP-wide settings and per-instance settings are mutually
17202 * exclusive.
17203 */
17204 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17205 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17206 vty_out(vty, " bgp graceful-shutdown\n");
17207
8606be87
DA
17208 /* Long-lived Graceful Restart */
17209 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17210 vty_out(vty,
17211 " bgp long-lived-graceful-restart stale-time %u\n",
17212 bgp->llgr_stale_time);
17213
dd65f45e
DL
17214 /* BGP graceful-restart. */
17215 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17216 vty_out(vty,
17217 " bgp graceful-restart stalepath-time %u\n",
17218 bgp->stalepath_time);
cfd47646 17219
dd65f45e
DL
17220 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17221 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17222 bgp->restart_time);
cfd47646 17223
17224 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17225 vty_out(vty,
17226 " bgp graceful-restart select-defer-time %u\n",
17227 bgp->select_defer_time);
17228
17229 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
17230 vty_out(vty, " bgp graceful-restart\n");
17231
cfd47646 17232 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17233 vty_out(vty, " bgp graceful-restart-disable\n");
17234
dd65f45e 17235 /* BGP graceful-restart Preserve State F bit. */
892fedb6 17236 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
17237 vty_out(vty,
17238 " bgp graceful-restart preserve-fw-state\n");
17239
dc95985f 17240 /* Stale timer for RIB */
17241 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17242 vty_out(vty,
17243 " bgp graceful-restart rib-stale-time %u\n",
17244 bgp->rib_stale_time);
17245
dd65f45e 17246 /* BGP bestpath method. */
892fedb6 17247 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 17248 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 17249 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
17250 vty_out(vty, " bgp bestpath as-path confed\n");
17251
892fedb6
DA
17252 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17253 if (CHECK_FLAG(bgp->flags,
17254 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
17255 vty_out(vty,
17256 " bgp bestpath as-path multipath-relax as-set\n");
17257 } else {
17258 vty_out(vty,
17259 " bgp bestpath as-path multipath-relax\n");
17260 }
17261 }
17262
892fedb6 17263 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17264 vty_out(vty,
17265 " bgp route-reflector allow-outbound-policy\n");
17266 }
892fedb6 17267 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17268 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17269 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17270 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17271 vty_out(vty, " bgp bestpath med");
892fedb6 17272 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17273 vty_out(vty, " confed");
892fedb6
DA
17274 if (CHECK_FLAG(bgp->flags,
17275 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17276 vty_out(vty, " missing-as-worst");
17277 vty_out(vty, "\n");
17278 }
17279
ee88563a
JM
17280 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17281 vty_out(vty,
17282 " bgp bestpath peer-type multipath-relax\n");
17283
f7e1c681 17284 /* Link bandwidth handling. */
17285 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17286 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17287 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17288 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17289 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17290 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17291
dd65f45e 17292 /* BGP network import check. */
892fedb6 17293 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17294 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17295 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17296 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17297 ? ""
17298 : "no ");
17299
17300 /* BGP timers configuration. */
5d5393b9 17301 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 17302 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17303 vty_out(vty, " timers bgp %u %u\n",
17304 bgp->default_keepalive, bgp->default_holdtime);
17305
b042667a
TI
17306 /* BGP minimum holdtime configuration. */
17307 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17308 && bgp->default_min_holdtime != 0)
17309 vty_out(vty, " bgp minimum-holdtime %u\n",
17310 bgp->default_min_holdtime);
17311
389e4f92
QY
17312 /* Conditional advertisement timer configuration */
17313 if (bgp->condition_check_period
17314 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17315 vty_out(vty,
17316 " bgp conditional-advertisement timer %u\n",
17317 bgp->condition_check_period);
17318
dd65f45e
DL
17319 /* peer-group */
17320 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17321 bgp_config_write_peer_global(vty, bgp, group->conf);
17322 }
17323
17324 /* Normal neighbor configuration. */
17325 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17326 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17327 bgp_config_write_peer_global(vty, bgp, peer);
17328 }
17329
17330 /* listen range and limit for dynamic BGP neighbors */
17331 bgp_config_write_listen(vty, bgp);
17332
17333 /*
17334 * BGP default autoshutdown neighbors
17335 *
17336 * This must be placed after any peer and peer-group
17337 * configuration, to avoid setting all peers to shutdown after
17338 * a daemon restart, which is undesired behavior. (see #2286)
17339 */
17340 if (bgp->autoshutdown)
17341 vty_out(vty, " bgp default shutdown\n");
17342
9cf59432
DS
17343 /* BGP instance administrative shutdown */
17344 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17345 vty_out(vty, " bgp shutdown\n");
17346
f852eb98
PG
17347 if (bgp->fast_convergence)
17348 vty_out(vty, " bgp fast-convergence\n");
17349
a0281b2e
HS
17350 if (bgp->srv6_enabled) {
17351 vty_frame(vty, " !\n segment-routing srv6\n");
96db4340 17352 if (strlen(bgp->srv6_locator_name))
a0281b2e
HS
17353 vty_out(vty, " locator %s\n",
17354 bgp->srv6_locator_name);
ff7c3ee1 17355 vty_endframe(vty, " exit\n");
a0281b2e
HS
17356 }
17357
17358
dd65f45e
DL
17359 /* IPv4 unicast configuration. */
17360 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17361
17362 /* IPv4 multicast configuration. */
17363 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17364
17365 /* IPv4 labeled-unicast configuration. */
17366 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17367
17368 /* IPv4 VPN configuration. */
17369 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17370
17371 /* ENCAPv4 configuration. */
17372 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17373
17374 /* FLOWSPEC v4 configuration. */
17375 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17376
17377 /* IPv6 unicast configuration. */
17378 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17379
17380 /* IPv6 multicast configuration. */
17381 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17382
17383 /* IPv6 labeled-unicast configuration. */
17384 bgp_config_write_family(vty, bgp, AFI_IP6,
17385 SAFI_LABELED_UNICAST);
17386
17387 /* IPv6 VPN configuration. */
17388 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17389
17390 /* ENCAPv6 configuration. */
17391 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17392
17393 /* FLOWSPEC v6 configuration. */
17394 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17395
17396 /* EVPN configuration. */
17397 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17398
17399 hook_call(bgp_inst_config_write, bgp, vty);
17400
49e5a4a0 17401#ifdef ENABLE_BGP_VNC
dd65f45e
DL
17402 bgp_rfapi_cfg_write(vty, bgp);
17403#endif
17404
07679ad9 17405 vty_out(vty, "exit\n");
dd65f45e
DL
17406 vty_out(vty, "!\n");
17407 }
17408 return 0;
17409}
17410
ddb5b488 17411
718e3744 17412/* BGP node structure. */
d62a17ae 17413static struct cmd_node bgp_node = {
f4b8291f 17414 .name = "bgp",
62b346ee 17415 .node = BGP_NODE,
24389580 17416 .parent_node = CONFIG_NODE,
62b346ee 17417 .prompt = "%s(config-router)# ",
612c2c15 17418 .config_write = bgp_config_write,
718e3744 17419};
17420
d62a17ae 17421static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 17422 .name = "bgp ipv4 unicast",
62b346ee 17423 .node = BGP_IPV4_NODE,
24389580 17424 .parent_node = BGP_NODE,
62b346ee 17425 .prompt = "%s(config-router-af)# ",
dd2c81b8 17426 .no_xpath = true,
718e3744 17427};
17428
d62a17ae 17429static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 17430 .name = "bgp ipv4 multicast",
62b346ee 17431 .node = BGP_IPV4M_NODE,
24389580 17432 .parent_node = BGP_NODE,
62b346ee 17433 .prompt = "%s(config-router-af)# ",
dd2c81b8 17434 .no_xpath = true,
718e3744 17435};
17436
d62a17ae 17437static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 17438 .name = "bgp ipv4 labeled unicast",
62b346ee 17439 .node = BGP_IPV4L_NODE,
24389580 17440 .parent_node = BGP_NODE,
62b346ee 17441 .prompt = "%s(config-router-af)# ",
dd2c81b8 17442 .no_xpath = true,
f51bae9c
DS
17443};
17444
d62a17ae 17445static struct cmd_node bgp_ipv6_unicast_node = {
a17cfb3f 17446 .name = "bgp ipv6 unicast",
62b346ee 17447 .node = BGP_IPV6_NODE,
24389580 17448 .parent_node = BGP_NODE,
62b346ee 17449 .prompt = "%s(config-router-af)# ",
dd2c81b8 17450 .no_xpath = true,
718e3744 17451};
17452
d62a17ae 17453static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 17454 .name = "bgp ipv6 multicast",
62b346ee 17455 .node = BGP_IPV6M_NODE,
24389580 17456 .parent_node = BGP_NODE,
62b346ee 17457 .prompt = "%s(config-router-af)# ",
dd2c81b8 17458 .no_xpath = true,
25ffbdc1 17459};
17460
d62a17ae 17461static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 17462 .name = "bgp ipv6 labeled unicast",
62b346ee 17463 .node = BGP_IPV6L_NODE,
24389580 17464 .parent_node = BGP_NODE,
62b346ee 17465 .prompt = "%s(config-router-af)# ",
dd2c81b8 17466 .no_xpath = true,
f51bae9c
DS
17467};
17468
62b346ee 17469static struct cmd_node bgp_vpnv4_node = {
f4b8291f 17470 .name = "bgp vpnv4",
62b346ee 17471 .node = BGP_VPNV4_NODE,
24389580 17472 .parent_node = BGP_NODE,
62b346ee 17473 .prompt = "%s(config-router-af)# ",
dd2c81b8 17474 .no_xpath = true,
62b346ee 17475};
6b0655a2 17476
62b346ee 17477static struct cmd_node bgp_vpnv6_node = {
f4b8291f 17478 .name = "bgp vpnv6",
62b346ee 17479 .node = BGP_VPNV6_NODE,
24389580 17480 .parent_node = BGP_NODE,
62b346ee 17481 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 17482 .no_xpath = true,
62b346ee 17483};
8ecd3266 17484
62b346ee 17485static struct cmd_node bgp_evpn_node = {
f4b8291f 17486 .name = "bgp evpn",
62b346ee 17487 .node = BGP_EVPN_NODE,
24389580 17488 .parent_node = BGP_NODE,
62b346ee 17489 .prompt = "%s(config-router-evpn)# ",
dd2c81b8 17490 .no_xpath = true,
62b346ee 17491};
4e0b7b6d 17492
62b346ee 17493static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 17494 .name = "bgp evpn vni",
62b346ee 17495 .node = BGP_EVPN_VNI_NODE,
24389580 17496 .parent_node = BGP_EVPN_NODE,
62b346ee 17497 .prompt = "%s(config-router-af-vni)# ",
62b346ee 17498};
90e60aa7 17499
62b346ee 17500static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 17501 .name = "bgp ipv4 flowspec",
62b346ee 17502 .node = BGP_FLOWSPECV4_NODE,
24389580 17503 .parent_node = BGP_NODE,
62b346ee 17504 .prompt = "%s(config-router-af)# ",
dd2c81b8 17505 .no_xpath = true,
62b346ee 17506};
7c40bf39 17507
62b346ee 17508static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 17509 .name = "bgp ipv6 flowspec",
62b346ee 17510 .node = BGP_FLOWSPECV6_NODE,
24389580 17511 .parent_node = BGP_NODE,
62b346ee 17512 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 17513 .no_xpath = true,
62b346ee 17514};
7c40bf39 17515
bfaab44d
HS
17516static struct cmd_node bgp_srv6_node = {
17517 .name = "bgp srv6",
17518 .node = BGP_SRV6_NODE,
17519 .parent_node = BGP_NODE,
17520 .prompt = "%s(config-router-srv6)# ",
17521};
17522
d62a17ae 17523static void community_list_vty(void);
1f8ae70b 17524
8c20061f
DA
17525static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17526{
17527 struct bgp *bgp;
17528 struct peer_group *group;
17529 struct listnode *lnbgp, *lnpeer;
17530
17531 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17532 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17533 vector_set(comps,
17534 XSTRDUP(MTYPE_COMPLETION, group->name));
17535 }
17536}
17537
17538static void bgp_ac_peer(vector comps, struct cmd_token *token)
b8a815e5 17539{
d62a17ae 17540 struct bgp *bgp;
17541 struct peer *peer;
d62a17ae 17542 struct listnode *lnbgp, *lnpeer;
b8a815e5 17543
d62a17ae 17544 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17545 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17546 /* only provide suggestions on the appropriate input
17547 * token type,
17548 * they'll otherwise show up multiple times */
17549 enum cmd_token_type match_type;
17550 char *name = peer->host;
d48ed3e0 17551
d62a17ae 17552 if (peer->conf_if) {
17553 match_type = VARIABLE_TKN;
17554 name = peer->conf_if;
17555 } else if (strchr(peer->host, ':'))
17556 match_type = IPV6_TKN;
17557 else
17558 match_type = IPV4_TKN;
d48ed3e0 17559
d62a17ae 17560 if (token->type != match_type)
17561 continue;
d48ed3e0 17562
d62a17ae 17563 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17564 }
d62a17ae 17565 }
b8a815e5
DL
17566}
17567
8c20061f
DA
17568static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17569{
17570 bgp_ac_peer(comps, token);
84de1483
DA
17571
17572 if (token->type == VARIABLE_TKN)
17573 bgp_ac_peergroup(comps, token);
8c20061f
DA
17574}
17575
b8a815e5 17576static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 17577 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17578 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 17579 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 17580 {.completions = NULL}};
17581
47a306a0
DS
17582static const struct cmd_variable_handler bgp_var_peergroup[] = {
17583 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17584 {.completions = NULL} };
17585
d62a17ae 17586void bgp_vty_init(void)
17587{
17588 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 17589 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 17590
17591 /* Install bgp top node. */
612c2c15
DL
17592 install_node(&bgp_node);
17593 install_node(&bgp_ipv4_unicast_node);
17594 install_node(&bgp_ipv4_multicast_node);
17595 install_node(&bgp_ipv4_labeled_unicast_node);
17596 install_node(&bgp_ipv6_unicast_node);
17597 install_node(&bgp_ipv6_multicast_node);
17598 install_node(&bgp_ipv6_labeled_unicast_node);
17599 install_node(&bgp_vpnv4_node);
17600 install_node(&bgp_vpnv6_node);
17601 install_node(&bgp_evpn_node);
17602 install_node(&bgp_evpn_vni_node);
17603 install_node(&bgp_flowspecv4_node);
17604 install_node(&bgp_flowspecv6_node);
bfaab44d 17605 install_node(&bgp_srv6_node);
d62a17ae 17606
17607 /* Install default VTY commands to new nodes. */
17608 install_default(BGP_NODE);
17609 install_default(BGP_IPV4_NODE);
17610 install_default(BGP_IPV4M_NODE);
17611 install_default(BGP_IPV4L_NODE);
17612 install_default(BGP_IPV6_NODE);
17613 install_default(BGP_IPV6M_NODE);
17614 install_default(BGP_IPV6L_NODE);
17615 install_default(BGP_VPNV4_NODE);
17616 install_default(BGP_VPNV6_NODE);
7c40bf39 17617 install_default(BGP_FLOWSPECV4_NODE);
17618 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 17619 install_default(BGP_EVPN_NODE);
17620 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 17621 install_default(BGP_SRV6_NODE);
d62a17ae 17622
8029b216
AK
17623 /* "bgp local-mac" hidden commands. */
17624 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17625 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17626
9acb67cb
DS
17627 /* "bgp suppress-fib-pending" global */
17628 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17629
d62a17ae 17630 /* bgp route-map delay-timer commands. */
17631 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17632 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17633
f852eb98
PG
17634 /* bgp fast-convergence command */
17635 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
17636 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
17637
d70583f7
D
17638 /* global bgp update-delay command */
17639 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17640 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17641
05bd726c 17642 /* global bgp graceful-shutdown command */
17643 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17644 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17645
d62a17ae 17646 /* Dummy commands (Currently not supported) */
17647 install_element(BGP_NODE, &no_synchronization_cmd);
17648 install_element(BGP_NODE, &no_auto_summary_cmd);
17649
17650 /* "router bgp" commands. */
17651 install_element(CONFIG_NODE, &router_bgp_cmd);
17652
17653 /* "no router bgp" commands. */
17654 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17655
17656 /* "bgp router-id" commands. */
17657 install_element(BGP_NODE, &bgp_router_id_cmd);
17658 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17659
c208c586
S
17660 /* "bgp suppress-fib-pending" command */
17661 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17662
d62a17ae 17663 /* "bgp cluster-id" commands. */
17664 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17665 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17666
c163f297
DS
17667 /* "bgp no-rib" commands. */
17668 install_element(CONFIG_NODE, &bgp_norib_cmd);
17669 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17670
e46723a5
DS
17671 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17672
d62a17ae 17673 /* "bgp confederation" commands. */
17674 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17675 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17676
17677 /* "bgp confederation peers" commands. */
17678 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17679 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17680
17681 /* bgp max-med command */
17682 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17683 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17684 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17685 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17686 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17687
17688 /* bgp disable-ebgp-connected-nh-check */
17689 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17690 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17691
17692 /* bgp update-delay command */
17693 install_element(BGP_NODE, &bgp_update_delay_cmd);
17694 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 17695
17696 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 17697 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 17698
17699 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17700 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17701
17702 /* "maximum-paths" commands. */
17703 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17704 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17705 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17706 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17707 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17708 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17709 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17710 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17711 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17712 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17713 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17714 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17715 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17716 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17717 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17718
39edabac
PG
17719 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17720 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17721 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17722 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17723 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 17724 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17725 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17726 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17727 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17728 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17729
17730 /* "timers bgp" commands. */
17731 install_element(BGP_NODE, &bgp_timers_cmd);
17732 install_element(BGP_NODE, &no_bgp_timers_cmd);
17733
b042667a
TI
17734 /* "minimum-holdtime" commands. */
17735 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
17736 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
17737
d62a17ae 17738 /* route-map delay-timer commands - per instance for backwards compat.
17739 */
17740 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17741 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17742
17743 /* "bgp client-to-client reflection" commands */
17744 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17745 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17746
17747 /* "bgp always-compare-med" commands */
17748 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17749 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17750
9dac9fc8
DA
17751 /* bgp ebgp-requires-policy */
17752 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17753 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17754
2adac256
DA
17755 /* bgp suppress-duplicates */
17756 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17757 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17758
fb29348a
DA
17759 /* bgp reject-as-sets */
17760 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17761 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17762
d62a17ae 17763 /* "bgp deterministic-med" commands */
17764 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17765 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17766
055679e9 17767 /* "bgp graceful-restart" command */
36235319
QY
17768 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17769 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 17770
17771 /* "bgp graceful-restart-disable" command */
36235319
QY
17772 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17773 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 17774
17775 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
17776 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17777 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 17778
17779 /* "neighbor a:b:c:d graceful-restart-disable" command */
17780 install_element(BGP_NODE,
17781 &bgp_neighbor_graceful_restart_disable_set_cmd);
17782 install_element(BGP_NODE,
17783 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17784
17785 /* "neighbor a:b:c:d graceful-restart-helper" command */
17786 install_element(BGP_NODE,
17787 &bgp_neighbor_graceful_restart_helper_set_cmd);
17788 install_element(BGP_NODE,
17789 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17790
d62a17ae 17791 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17792 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17793 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17794 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 17795 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 17796 install_element(BGP_NODE,
17797 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 17798 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17799 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17800
d6e3c15b 17801 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17802 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 17803 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17804 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 17805
7f323236
DW
17806 /* "bgp graceful-shutdown" commands */
17807 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17808 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17809
8606be87
DA
17810 /* "bgp long-lived-graceful-restart" commands */
17811 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
17812 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
17813
d62a17ae 17814 /* "bgp fast-external-failover" commands */
17815 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17816 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17817
d62a17ae 17818 /* "bgp bestpath compare-routerid" commands */
17819 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17820 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17821
17822 /* "bgp bestpath as-path ignore" commands */
17823 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17824 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17825
17826 /* "bgp bestpath as-path confed" commands */
17827 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17828 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17829
17830 /* "bgp bestpath as-path multipath-relax" commands */
17831 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17832 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17833
ee88563a
JM
17834 /* "bgp bestpath peer-type multipath-relax" commands */
17835 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
17836 install_element(BGP_NODE,
17837 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
17838
d62a17ae 17839 /* "bgp log-neighbor-changes" commands */
17840 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17841 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17842
17843 /* "bgp bestpath med" commands */
17844 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17845 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17846
f7e1c681 17847 /* "bgp bestpath bandwidth" commands */
17848 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 17849 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 17850
b16bcbba
TA
17851 /* "no bgp default <afi>-<safi>" commands. */
17852 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
e84c59af 17853
d62a17ae 17854 /* "bgp network import-check" commands. */
17855 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17856 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17857 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17858
17859 /* "bgp default local-preference" commands. */
17860 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17861 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17862
17863 /* bgp default show-hostname */
17864 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17865 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17866
aef999a2
DA
17867 /* bgp default show-nexthop-hostname */
17868 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17869 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17870
d62a17ae 17871 /* "bgp default subgroup-pkt-queue-max" commands. */
17872 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17873 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17874
17875 /* bgp ibgp-allow-policy-mods command */
17876 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17877 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17878
17879 /* "bgp listen limit" commands. */
17880 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17881 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17882
17883 /* "bgp listen range" commands. */
17884 install_element(BGP_NODE, &bgp_listen_range_cmd);
17885 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17886
8175f54a 17887 /* "bgp default shutdown" command */
f26845f9 17888 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
17889
17890 /* "bgp shutdown" commands */
17891 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 17892 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 17893 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 17894 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 17895
d62a17ae 17896 /* "neighbor remote-as" commands. */
17897 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17898 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17899 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17900 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17901 install_element(BGP_NODE,
17902 &neighbor_interface_v6only_config_remote_as_cmd);
17903 install_element(BGP_NODE, &no_neighbor_cmd);
17904 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17905
17906 /* "neighbor peer-group" commands. */
17907 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17908 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17909 install_element(BGP_NODE,
17910 &no_neighbor_interface_peer_group_remote_as_cmd);
17911
17912 /* "neighbor local-as" commands. */
17913 install_element(BGP_NODE, &neighbor_local_as_cmd);
17914 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17915 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17916 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17917
17918 /* "neighbor solo" commands. */
17919 install_element(BGP_NODE, &neighbor_solo_cmd);
17920 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17921
17922 /* "neighbor password" commands. */
17923 install_element(BGP_NODE, &neighbor_password_cmd);
17924 install_element(BGP_NODE, &no_neighbor_password_cmd);
17925
17926 /* "neighbor activate" commands. */
17927 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17928 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17929 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17930 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17931 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17932 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17933 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17934 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
17935 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 17936 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
17937 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 17938 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
17939
17940 /* "no neighbor activate" commands. */
17941 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
17942 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
17943 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
17944 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
17945 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
17946 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
17947 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
17948 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
17949 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 17950 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
17951 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 17952 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
17953
17954 /* "neighbor peer-group" set commands. */
17955 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
17956 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17957 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
17958 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17959 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
17960 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
17961 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17962 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 17963 install_element(BGP_FLOWSPECV4_NODE,
17964 &neighbor_set_peer_group_hidden_cmd);
17965 install_element(BGP_FLOWSPECV6_NODE,
17966 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 17967
17968 /* "no neighbor peer-group unset" commands. */
17969 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
17970 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17971 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17972 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17973 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17974 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17975 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17976 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 17977 install_element(BGP_FLOWSPECV4_NODE,
17978 &no_neighbor_set_peer_group_hidden_cmd);
17979 install_element(BGP_FLOWSPECV6_NODE,
17980 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 17981
17982 /* "neighbor softreconfiguration inbound" commands.*/
17983 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
17984 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
17985 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
17986 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17987 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
17988 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17989 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
17990 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17991 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
17992 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17993 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
17994 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17995 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
17996 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17997 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
17998 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17999 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18000 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 18001 install_element(BGP_FLOWSPECV4_NODE,
18002 &neighbor_soft_reconfiguration_cmd);
18003 install_element(BGP_FLOWSPECV4_NODE,
18004 &no_neighbor_soft_reconfiguration_cmd);
18005 install_element(BGP_FLOWSPECV6_NODE,
18006 &neighbor_soft_reconfiguration_cmd);
18007 install_element(BGP_FLOWSPECV6_NODE,
18008 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
18009 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18010 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 18011
18012 /* "neighbor attribute-unchanged" commands. */
18013 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18014 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18015 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18016 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18017 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18018 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18019 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18020 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18021 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18022 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18023 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18024 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18025 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18026 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18027 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18028 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18029 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18030 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18031
18032 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18033 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18034
b8ad84d2
PG
18035 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18036 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18037 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18038 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18039
d62a17ae 18040 /* "nexthop-local unchanged" commands */
18041 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18042 install_element(BGP_IPV6_NODE,
18043 &no_neighbor_nexthop_local_unchanged_cmd);
18044
18045 /* "neighbor next-hop-self" commands. */
18046 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18047 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18048 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18049 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18050 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18051 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18052 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18053 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18054 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18055 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18056 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18057 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18058 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18059 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18060 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18061 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18062 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18063 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
18064 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18065 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 18066
18067 /* "neighbor next-hop-self force" commands. */
18068 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18069 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
18070 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18071 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18072 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18073 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18074 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18075 install_element(BGP_IPV4_NODE,
18076 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18077 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18078 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18079 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18080 install_element(BGP_IPV4M_NODE,
18081 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18082 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18083 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18084 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18085 install_element(BGP_IPV4L_NODE,
18086 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18087 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18088 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18089 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18090 install_element(BGP_IPV6_NODE,
18091 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18092 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18093 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18094 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18095 install_element(BGP_IPV6M_NODE,
18096 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18097 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18098 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18099 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18100 install_element(BGP_IPV6L_NODE,
18101 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18102 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18103 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18104 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18105 install_element(BGP_VPNV4_NODE,
18106 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18107 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18108 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18109 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18110 install_element(BGP_VPNV6_NODE,
18111 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
18112 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18113 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 18114
18115 /* "neighbor as-override" commands. */
18116 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18117 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18118 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18119 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18120 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18121 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18122 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18123 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18124 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18125 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18126 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18127 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18128 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18129 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18130 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18131 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18132 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18133 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18134
18135 /* "neighbor remove-private-AS" commands. */
18136 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18137 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18138 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18139 install_element(BGP_NODE,
18140 &no_neighbor_remove_private_as_all_hidden_cmd);
18141 install_element(BGP_NODE,
18142 &neighbor_remove_private_as_replace_as_hidden_cmd);
18143 install_element(BGP_NODE,
18144 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18145 install_element(BGP_NODE,
18146 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18147 install_element(
18148 BGP_NODE,
18149 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18150 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18151 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18152 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18153 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18154 install_element(BGP_IPV4_NODE,
18155 &neighbor_remove_private_as_replace_as_cmd);
18156 install_element(BGP_IPV4_NODE,
18157 &no_neighbor_remove_private_as_replace_as_cmd);
18158 install_element(BGP_IPV4_NODE,
18159 &neighbor_remove_private_as_all_replace_as_cmd);
18160 install_element(BGP_IPV4_NODE,
18161 &no_neighbor_remove_private_as_all_replace_as_cmd);
18162 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18163 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18164 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18165 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18166 install_element(BGP_IPV4M_NODE,
18167 &neighbor_remove_private_as_replace_as_cmd);
18168 install_element(BGP_IPV4M_NODE,
18169 &no_neighbor_remove_private_as_replace_as_cmd);
18170 install_element(BGP_IPV4M_NODE,
18171 &neighbor_remove_private_as_all_replace_as_cmd);
18172 install_element(BGP_IPV4M_NODE,
18173 &no_neighbor_remove_private_as_all_replace_as_cmd);
18174 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18175 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18176 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18177 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18178 install_element(BGP_IPV4L_NODE,
18179 &neighbor_remove_private_as_replace_as_cmd);
18180 install_element(BGP_IPV4L_NODE,
18181 &no_neighbor_remove_private_as_replace_as_cmd);
18182 install_element(BGP_IPV4L_NODE,
18183 &neighbor_remove_private_as_all_replace_as_cmd);
18184 install_element(BGP_IPV4L_NODE,
18185 &no_neighbor_remove_private_as_all_replace_as_cmd);
18186 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18187 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18188 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18189 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18190 install_element(BGP_IPV6_NODE,
18191 &neighbor_remove_private_as_replace_as_cmd);
18192 install_element(BGP_IPV6_NODE,
18193 &no_neighbor_remove_private_as_replace_as_cmd);
18194 install_element(BGP_IPV6_NODE,
18195 &neighbor_remove_private_as_all_replace_as_cmd);
18196 install_element(BGP_IPV6_NODE,
18197 &no_neighbor_remove_private_as_all_replace_as_cmd);
18198 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18199 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18200 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18201 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18202 install_element(BGP_IPV6M_NODE,
18203 &neighbor_remove_private_as_replace_as_cmd);
18204 install_element(BGP_IPV6M_NODE,
18205 &no_neighbor_remove_private_as_replace_as_cmd);
18206 install_element(BGP_IPV6M_NODE,
18207 &neighbor_remove_private_as_all_replace_as_cmd);
18208 install_element(BGP_IPV6M_NODE,
18209 &no_neighbor_remove_private_as_all_replace_as_cmd);
18210 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18211 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18212 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18213 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18214 install_element(BGP_IPV6L_NODE,
18215 &neighbor_remove_private_as_replace_as_cmd);
18216 install_element(BGP_IPV6L_NODE,
18217 &no_neighbor_remove_private_as_replace_as_cmd);
18218 install_element(BGP_IPV6L_NODE,
18219 &neighbor_remove_private_as_all_replace_as_cmd);
18220 install_element(BGP_IPV6L_NODE,
18221 &no_neighbor_remove_private_as_all_replace_as_cmd);
18222 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18223 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18224 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18225 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18226 install_element(BGP_VPNV4_NODE,
18227 &neighbor_remove_private_as_replace_as_cmd);
18228 install_element(BGP_VPNV4_NODE,
18229 &no_neighbor_remove_private_as_replace_as_cmd);
18230 install_element(BGP_VPNV4_NODE,
18231 &neighbor_remove_private_as_all_replace_as_cmd);
18232 install_element(BGP_VPNV4_NODE,
18233 &no_neighbor_remove_private_as_all_replace_as_cmd);
18234 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18235 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18236 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18237 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18238 install_element(BGP_VPNV6_NODE,
18239 &neighbor_remove_private_as_replace_as_cmd);
18240 install_element(BGP_VPNV6_NODE,
18241 &no_neighbor_remove_private_as_replace_as_cmd);
18242 install_element(BGP_VPNV6_NODE,
18243 &neighbor_remove_private_as_all_replace_as_cmd);
18244 install_element(BGP_VPNV6_NODE,
18245 &no_neighbor_remove_private_as_all_replace_as_cmd);
18246
18247 /* "neighbor send-community" commands.*/
18248 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18249 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18250 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18251 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18252 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18253 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18254 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18255 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18256 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18257 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18258 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18259 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18260 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18261 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18262 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18263 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18264 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18265 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18266 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18267 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18268 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18269 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18270 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18271 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18272 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18273 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18274 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18275 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18276 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18277 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18278 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18279 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18280 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18281 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18282 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18283 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18284
18285 /* "neighbor route-reflector" commands.*/
18286 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18287 install_element(BGP_NODE,
18288 &no_neighbor_route_reflector_client_hidden_cmd);
18289 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18290 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18291 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18292 install_element(BGP_IPV4M_NODE,
18293 &no_neighbor_route_reflector_client_cmd);
18294 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18295 install_element(BGP_IPV4L_NODE,
18296 &no_neighbor_route_reflector_client_cmd);
18297 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18298 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18299 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18300 install_element(BGP_IPV6M_NODE,
18301 &no_neighbor_route_reflector_client_cmd);
18302 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18303 install_element(BGP_IPV6L_NODE,
18304 &no_neighbor_route_reflector_client_cmd);
18305 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18306 install_element(BGP_VPNV4_NODE,
18307 &no_neighbor_route_reflector_client_cmd);
18308 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18309 install_element(BGP_VPNV6_NODE,
18310 &no_neighbor_route_reflector_client_cmd);
7c40bf39 18311 install_element(BGP_FLOWSPECV4_NODE,
18312 &neighbor_route_reflector_client_cmd);
18313 install_element(BGP_FLOWSPECV4_NODE,
18314 &no_neighbor_route_reflector_client_cmd);
18315 install_element(BGP_FLOWSPECV6_NODE,
18316 &neighbor_route_reflector_client_cmd);
18317 install_element(BGP_FLOWSPECV6_NODE,
18318 &no_neighbor_route_reflector_client_cmd);
d62a17ae 18319 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18320 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18321
18322 /* "neighbor route-server" commands.*/
18323 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18324 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18325 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18326 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18327 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18328 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18329 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18330 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18331 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18332 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18333 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18334 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18335 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18336 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18337 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18338 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18339 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18340 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
18341 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18342 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 18343 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18344 install_element(BGP_FLOWSPECV4_NODE,
18345 &no_neighbor_route_server_client_cmd);
18346 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18347 install_element(BGP_FLOWSPECV6_NODE,
18348 &no_neighbor_route_server_client_cmd);
d62a17ae 18349
7c0e4312
DA
18350 /* "neighbor disable-addpath-rx" commands. */
18351 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
18352 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18353 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
18354 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18355 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
18356 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18357 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
18358 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18359 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
18360 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18361 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
18362 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18363 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
18364 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18365 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
18366 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18367
d62a17ae 18368 /* "neighbor addpath-tx-all-paths" commands.*/
18369 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18370 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18371 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18372 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18373 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18374 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18375 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18376 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18377 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18378 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18379 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18380 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18381 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18382 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18383 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18384 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18385 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18386 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18387
18388 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18389 install_element(BGP_NODE,
18390 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18391 install_element(BGP_NODE,
18392 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18393 install_element(BGP_IPV4_NODE,
18394 &neighbor_addpath_tx_bestpath_per_as_cmd);
18395 install_element(BGP_IPV4_NODE,
18396 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18397 install_element(BGP_IPV4M_NODE,
18398 &neighbor_addpath_tx_bestpath_per_as_cmd);
18399 install_element(BGP_IPV4M_NODE,
18400 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18401 install_element(BGP_IPV4L_NODE,
18402 &neighbor_addpath_tx_bestpath_per_as_cmd);
18403 install_element(BGP_IPV4L_NODE,
18404 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18405 install_element(BGP_IPV6_NODE,
18406 &neighbor_addpath_tx_bestpath_per_as_cmd);
18407 install_element(BGP_IPV6_NODE,
18408 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18409 install_element(BGP_IPV6M_NODE,
18410 &neighbor_addpath_tx_bestpath_per_as_cmd);
18411 install_element(BGP_IPV6M_NODE,
18412 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18413 install_element(BGP_IPV6L_NODE,
18414 &neighbor_addpath_tx_bestpath_per_as_cmd);
18415 install_element(BGP_IPV6L_NODE,
18416 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18417 install_element(BGP_VPNV4_NODE,
18418 &neighbor_addpath_tx_bestpath_per_as_cmd);
18419 install_element(BGP_VPNV4_NODE,
18420 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18421 install_element(BGP_VPNV6_NODE,
18422 &neighbor_addpath_tx_bestpath_per_as_cmd);
18423 install_element(BGP_VPNV6_NODE,
18424 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18425
2b31007c
RZ
18426 /* "neighbor sender-as-path-loop-detection" commands. */
18427 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18428 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18429
d62a17ae 18430 /* "neighbor passive" commands. */
18431 install_element(BGP_NODE, &neighbor_passive_cmd);
18432 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18433
18434
18435 /* "neighbor shutdown" commands. */
18436 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18437 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18438 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18439 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
18440 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18441 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 18442
18443 /* "neighbor capability extended-nexthop" commands.*/
18444 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18445 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18446
18447 /* "neighbor capability orf prefix-list" commands.*/
18448 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18449 install_element(BGP_NODE,
18450 &no_neighbor_capability_orf_prefix_hidden_cmd);
18451 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18452 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18453 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18454 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18455 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18456 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18457 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18458 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18459 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18460 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18461 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18462 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18463
18464 /* "neighbor capability dynamic" commands.*/
18465 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18466 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18467
18468 /* "neighbor dont-capability-negotiate" commands. */
18469 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18470 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18471
18472 /* "neighbor ebgp-multihop" commands. */
18473 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18474 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18475 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18476
18477 /* "neighbor disable-connected-check" commands. */
18478 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18479 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18480
7ab294ea
DA
18481 /* "neighbor disable-link-bw-encoding-ieee" commands. */
18482 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
18483 install_element(BGP_NODE,
18484 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
27aa23a4 18485
d08c0c80
DA
18486 /* "neighbor extended-optional-parameters" commands. */
18487 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
18488 install_element(BGP_NODE,
18489 &no_neighbor_extended_optional_parameters_cmd);
18490
47cbc09b
PM
18491 /* "neighbor enforce-first-as" commands. */
18492 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18493 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18494
d62a17ae 18495 /* "neighbor description" commands. */
18496 install_element(BGP_NODE, &neighbor_description_cmd);
18497 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 18498 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 18499
18500 /* "neighbor update-source" commands. "*/
18501 install_element(BGP_NODE, &neighbor_update_source_cmd);
18502 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18503
18504 /* "neighbor default-originate" commands. */
18505 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18506 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18507 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18508 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18509 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18510 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18511 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18512 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18513 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18514 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18515 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18516 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18517 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18518 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18519 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18520 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18521 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18522 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18523 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18524 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18525 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18526
18527 /* "neighbor port" commands. */
18528 install_element(BGP_NODE, &neighbor_port_cmd);
18529 install_element(BGP_NODE, &no_neighbor_port_cmd);
18530
18531 /* "neighbor weight" commands. */
18532 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18533 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18534
18535 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18536 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18537 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18538 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18539 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18540 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18541 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18542 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18543 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18544 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18545 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18546 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18547 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18548 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18549 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18550 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18551
18552 /* "neighbor override-capability" commands. */
18553 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18554 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18555
18556 /* "neighbor strict-capability-match" commands. */
18557 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18558 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18559
18560 /* "neighbor timers" commands. */
18561 install_element(BGP_NODE, &neighbor_timers_cmd);
18562 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18563
18564 /* "neighbor timers connect" commands. */
18565 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18566 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18567
d43114f3
DS
18568 /* "neighbor timers delayopen" commands. */
18569 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18570 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18571
d62a17ae 18572 /* "neighbor advertisement-interval" commands. */
18573 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18574 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18575
18576 /* "neighbor interface" commands. */
18577 install_element(BGP_NODE, &neighbor_interface_cmd);
18578 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18579
18580 /* "neighbor distribute" commands. */
18581 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18582 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18583 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18584 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18585 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18586 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18587 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18588 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18589 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18590 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18591 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18592 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18593 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18594 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18595 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18596 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18597 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18598 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18599
18600 /* "neighbor prefix-list" commands. */
18601 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
642ef664 18602 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
d62a17ae 18603 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18604 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18605 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
642ef664 18606 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18607 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
642ef664 18608 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18609 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18610 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18611 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
642ef664 18612 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18613 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
642ef664 18614 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18615 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18616 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18617 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18618 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18619 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18620 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18621 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18622 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18623
18624 /* "neighbor filter-list" commands. */
18625 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18626 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18627 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18628 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18629 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18630 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18631 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18632 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18633 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18634 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18635 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18636 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18637 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18638 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18639 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18640 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18641 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18642 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 18643 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18644 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18645 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18646 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 18647
18648 /* "neighbor route-map" commands. */
d6d7ed37
IR
18649 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18650 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
d62a17ae 18651 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18652 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18653 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
0ea8d871 18654 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18655 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
0ea8d871 18656 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18657 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18658 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18659 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
0ea8d871 18660 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18661 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
0ea8d871 18662 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18663 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18664 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18665 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18666 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18667 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18668 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18669 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18670 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549 18671 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
0ea8d871 18672 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18673
18674 /* "neighbor unsuppress-map" commands. */
18675 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18676 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18677 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18678 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18679 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18680 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18681 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18682 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18683 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18684 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18685 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18686 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18687 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18688 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18689 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18690 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18691 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18692 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18693
7f7940e6 18694 /* "neighbor advertise-map" commands. */
389e4f92 18695 install_element(BGP_NODE, &bgp_condadv_period_cmd);
7f7940e6 18696 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 18697 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18698 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18699 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18700 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18701 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18702 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18703 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18704 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18705
fde246e8
DA
18706 /* neighbor maximum-prefix-out commands. */
18707 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18708 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18709 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18710 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18711 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18712 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18713 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18714 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18715 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18716 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18717 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18718 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18719 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18720 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18721 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18722 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18723 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18724 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18725
d62a17ae 18726 /* "neighbor maximum-prefix" commands. */
18727 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18728 install_element(BGP_NODE,
18729 &neighbor_maximum_prefix_threshold_hidden_cmd);
18730 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18731 install_element(BGP_NODE,
18732 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18733 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18734 install_element(BGP_NODE,
18735 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18736 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18737 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18738 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18739 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18740 install_element(BGP_IPV4_NODE,
18741 &neighbor_maximum_prefix_threshold_warning_cmd);
18742 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18743 install_element(BGP_IPV4_NODE,
18744 &neighbor_maximum_prefix_threshold_restart_cmd);
18745 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18746 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18747 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18748 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18749 install_element(BGP_IPV4M_NODE,
18750 &neighbor_maximum_prefix_threshold_warning_cmd);
18751 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18752 install_element(BGP_IPV4M_NODE,
18753 &neighbor_maximum_prefix_threshold_restart_cmd);
18754 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18755 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18756 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18757 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18758 install_element(BGP_IPV4L_NODE,
18759 &neighbor_maximum_prefix_threshold_warning_cmd);
18760 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18761 install_element(BGP_IPV4L_NODE,
18762 &neighbor_maximum_prefix_threshold_restart_cmd);
18763 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18764 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18765 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18766 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18767 install_element(BGP_IPV6_NODE,
18768 &neighbor_maximum_prefix_threshold_warning_cmd);
18769 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18770 install_element(BGP_IPV6_NODE,
18771 &neighbor_maximum_prefix_threshold_restart_cmd);
18772 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18773 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18774 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18775 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18776 install_element(BGP_IPV6M_NODE,
18777 &neighbor_maximum_prefix_threshold_warning_cmd);
18778 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18779 install_element(BGP_IPV6M_NODE,
18780 &neighbor_maximum_prefix_threshold_restart_cmd);
18781 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18782 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18783 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18784 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18785 install_element(BGP_IPV6L_NODE,
18786 &neighbor_maximum_prefix_threshold_warning_cmd);
18787 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18788 install_element(BGP_IPV6L_NODE,
18789 &neighbor_maximum_prefix_threshold_restart_cmd);
18790 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18791 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18792 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18793 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18794 install_element(BGP_VPNV4_NODE,
18795 &neighbor_maximum_prefix_threshold_warning_cmd);
18796 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18797 install_element(BGP_VPNV4_NODE,
18798 &neighbor_maximum_prefix_threshold_restart_cmd);
18799 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18800 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18801 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18802 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18803 install_element(BGP_VPNV6_NODE,
18804 &neighbor_maximum_prefix_threshold_warning_cmd);
18805 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18806 install_element(BGP_VPNV6_NODE,
18807 &neighbor_maximum_prefix_threshold_restart_cmd);
18808 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18809
18810 /* "neighbor allowas-in" */
18811 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18812 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18813 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18814 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18815 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18816 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18817 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18818 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18819 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18820 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18821 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18822 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18823 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18824 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18825 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18826 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18827 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18828 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18829 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18830 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18831
18832 /* address-family commands. */
18833 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18834 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 18835#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 18836 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18837 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 18838#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 18839
d62a17ae 18840 install_element(BGP_NODE, &address_family_evpn_cmd);
18841
18842 /* "exit-address-family" command. */
18843 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18844 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18845 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18846 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18847 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18848 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18849 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18850 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 18851 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18852 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 18853 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18854
18855 /* "clear ip bgp commands" */
18856 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18857
18858 /* clear ip bgp prefix */
18859 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18860 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18861 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18862
18863 /* "show [ip] bgp summary" commands. */
18864 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 18865 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 18866 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 18867 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 18868 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18869 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 18870 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18871
18872 /* "show [ip] bgp neighbors" commands. */
18873 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18874
36235319 18875 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 18876
d62a17ae 18877 /* "show [ip] bgp peer-group" commands. */
18878 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18879
18880 /* "show [ip] bgp paths" commands. */
18881 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18882
18883 /* "show [ip] bgp community" commands. */
18884 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18885
18886 /* "show ip bgp large-community" commands. */
18887 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18888 /* "show [ip] bgp attribute-info" commands. */
18889 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 18890 /* "show [ip] bgp route-leak" command */
18891 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 18892
18893 /* "redistribute" commands. */
18894 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18895 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18896 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18897 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18898 install_element(BGP_NODE,
18899 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18900 install_element(BGP_NODE,
18901 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18902 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18903 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18904 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18905 install_element(BGP_NODE,
18906 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18907 install_element(BGP_NODE,
18908 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18909 install_element(BGP_NODE,
18910 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18911 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18912 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18913 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18914 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18915 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18916 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18917 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18918 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18919 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18920 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18921 install_element(BGP_IPV4_NODE,
18922 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18923 install_element(BGP_IPV4_NODE,
18924 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18925 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18926 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18927 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18928 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18929 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18930 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18931
b9c7bc5a
PZ
18932 /* import|export vpn [route-map WORD] */
18933 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18934 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 18935
12a844a5
DS
18936 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18937 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18938
d62a17ae 18939 /* ttl_security commands */
18940 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18941 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18942
18943 /* "show [ip] bgp memory" commands. */
18944 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18945
acf71666
MK
18946 /* "show bgp martian next-hop" */
18947 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18948
48ecf8f5
DS
18949 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18950
d62a17ae 18951 /* "show [ip] bgp views" commands. */
18952 install_element(VIEW_NODE, &show_bgp_views_cmd);
18953
18954 /* "show [ip] bgp vrfs" commands. */
18955 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
18956
18957 /* Community-list. */
18958 community_list_vty();
ddb5b488 18959
ed0e57e3
DA
18960 community_alias_vty();
18961
ddb5b488 18962 /* vpn-policy commands */
b9c7bc5a
PZ
18963 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
18964 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
18965 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
18966 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
18967 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
18968 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
18969 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
18970 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
18971 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
18972 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
18973 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
18974 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 18975
301ad80a
PG
18976 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
18977 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
18978
b9c7bc5a
PZ
18979 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
18980 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
18981 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
18982 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
18983 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
18984 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
18985 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
18986 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
18987 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
18988 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
18989
18990 /* tcp-mss command */
18991 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
18992 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
18993
18994 /* srv6 commands */
ea372e81 18995 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
bfaab44d 18996 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
0249b8b6 18997 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
a0281b2e 18998 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
0249b8b6 18999 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
b72c9e14
HS
19000 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19001 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
718e3744 19002}
6b0655a2 19003
718e3744 19004#include "memory.h"
19005#include "bgp_regex.h"
19006#include "bgp_clist.h"
19007#include "bgp_ecommunity.h"
19008
19009/* VTY functions. */
19010
19011/* Direction value to string conversion. */
d62a17ae 19012static const char *community_direct_str(int direct)
19013{
19014 switch (direct) {
19015 case COMMUNITY_DENY:
19016 return "deny";
19017 case COMMUNITY_PERMIT:
19018 return "permit";
19019 default:
19020 return "unknown";
19021 }
718e3744 19022}
19023
19024/* Display error string. */
d62a17ae 19025static void community_list_perror(struct vty *vty, int ret)
19026{
19027 switch (ret) {
19028 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19029 vty_out(vty, "%% Can't find community-list\n");
19030 break;
19031 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19032 vty_out(vty, "%% Malformed community-list value\n");
19033 break;
19034 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19035 vty_out(vty,
19036 "%% Community name conflict, previously defined as standard community\n");
19037 break;
19038 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19039 vty_out(vty,
19040 "%% Community name conflict, previously defined as expanded community\n");
19041 break;
19042 }
718e3744 19043}
19044
5bf15956
DW
19045/* "community-list" keyword help string. */
19046#define COMMUNITY_LIST_STR "Add a community list entry\n"
19047
7336e101
SP
19048/*community-list standard */
19049DEFUN (community_list_standard,
19050 bgp_community_list_standard_cmd,
a2099c1d 19051 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19052 BGP_STR
718e3744 19053 COMMUNITY_LIST_STR
19054 "Community list number (standard)\n"
5bf15956 19055 "Add an standard community-list entry\n"
718e3744 19056 "Community list name\n"
2f8cc0e5
DA
19057 "Sequence number of an entry\n"
19058 "Sequence number\n"
718e3744 19059 "Specify community to reject\n"
19060 "Specify community to accept\n"
19061 COMMUNITY_VAL_STR)
19062{
d62a17ae 19063 char *cl_name_or_number = NULL;
2f8cc0e5 19064 char *seq = NULL;
d62a17ae 19065 int direct = 0;
19066 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 19067 int idx = 0;
7336e101 19068
a08032fe 19069 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19070 if (idx)
19071 seq = argv[idx]->arg;
19072
19073 idx = 0;
d62a17ae 19074 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19075 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19076 cl_name_or_number = argv[idx]->arg;
19077 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19078 : COMMUNITY_DENY;
19079 argv_find(argv, argc, "AA:NN", &idx);
19080 char *str = argv_concat(argv, argc, idx);
42f914d4 19081
2f8cc0e5
DA
19082 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19083 direct, style);
42f914d4 19084
d62a17ae 19085 XFREE(MTYPE_TMP, str);
42f914d4 19086
d62a17ae 19087 if (ret < 0) {
19088 /* Display error string. */
19089 community_list_perror(vty, ret);
19090 return CMD_WARNING_CONFIG_FAILED;
19091 }
42f914d4 19092
d62a17ae 19093 return CMD_SUCCESS;
718e3744 19094}
19095
7336e101
SP
19096DEFUN (no_community_list_standard_all,
19097 no_bgp_community_list_standard_all_cmd,
a2099c1d 19098 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19099 NO_STR
19100 BGP_STR
19101 COMMUNITY_LIST_STR
19102 "Community list number (standard)\n"
19103 "Add an standard community-list entry\n"
19104 "Community list name\n"
2f8cc0e5
DA
19105 "Sequence number of an entry\n"
19106 "Sequence number\n"
7336e101
SP
19107 "Specify community to reject\n"
19108 "Specify community to accept\n"
19109 COMMUNITY_VAL_STR)
718e3744 19110{
d62a17ae 19111 char *cl_name_or_number = NULL;
174b5cb9 19112 char *str = NULL;
d62a17ae 19113 int direct = 0;
19114 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 19115 char *seq = NULL;
d62a17ae 19116 int idx = 0;
7336e101 19117
a08032fe 19118 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19119 if (idx)
19120 seq = argv[idx]->arg;
19121
19122 idx = 0;
174b5cb9
DA
19123 argv_find(argv, argc, "permit", &idx);
19124 argv_find(argv, argc, "deny", &idx);
19125
19126 if (idx) {
19127 direct = argv_find(argv, argc, "permit", &idx)
19128 ? COMMUNITY_PERMIT
19129 : COMMUNITY_DENY;
19130
19131 idx = 0;
19132 argv_find(argv, argc, "AA:NN", &idx);
19133 str = argv_concat(argv, argc, idx);
19134 }
19135
19136 idx = 0;
d62a17ae 19137 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19138 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19139 cl_name_or_number = argv[idx]->arg;
42f914d4 19140
2f8cc0e5 19141 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19142 direct, style);
42f914d4 19143
d62a17ae 19144 XFREE(MTYPE_TMP, str);
daf9ddbb 19145
d62a17ae 19146 if (ret < 0) {
19147 community_list_perror(vty, ret);
19148 return CMD_WARNING_CONFIG_FAILED;
19149 }
42f914d4 19150
d62a17ae 19151 return CMD_SUCCESS;
718e3744 19152}
7336e101 19153
174b5cb9 19154ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
a2099c1d 19155 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
174b5cb9
DA
19156 NO_STR BGP_STR COMMUNITY_LIST_STR
19157 "Community list number (standard)\n"
19158 "Add an standard community-list entry\n"
19159 "Community list name\n")
19160
7336e101
SP
19161/*community-list expanded */
19162DEFUN (community_list_expanded_all,
19163 bgp_community_list_expanded_all_cmd,
a2099c1d 19164 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19165 BGP_STR
19166 COMMUNITY_LIST_STR
718e3744 19167 "Community list number (expanded)\n"
5bf15956 19168 "Add an expanded community-list entry\n"
718e3744 19169 "Community list name\n"
2f8cc0e5
DA
19170 "Sequence number of an entry\n"
19171 "Sequence number\n"
718e3744 19172 "Specify community to reject\n"
19173 "Specify community to accept\n"
19174 COMMUNITY_VAL_STR)
19175{
d62a17ae 19176 char *cl_name_or_number = NULL;
2f8cc0e5 19177 char *seq = NULL;
d62a17ae 19178 int direct = 0;
19179 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19180 int idx = 0;
7b9a4750 19181
a08032fe 19182 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19183 if (idx)
19184 seq = argv[idx]->arg;
19185
19186 idx = 0;
19187
d62a17ae 19188 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19189 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19190 cl_name_or_number = argv[idx]->arg;
19191 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19192 : COMMUNITY_DENY;
19193 argv_find(argv, argc, "AA:NN", &idx);
19194 char *str = argv_concat(argv, argc, idx);
42f914d4 19195
2f8cc0e5
DA
19196 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19197 direct, style);
42f914d4 19198
d62a17ae 19199 XFREE(MTYPE_TMP, str);
42f914d4 19200
d62a17ae 19201 if (ret < 0) {
19202 /* Display error string. */
19203 community_list_perror(vty, ret);
19204 return CMD_WARNING_CONFIG_FAILED;
19205 }
42f914d4 19206
d62a17ae 19207 return CMD_SUCCESS;
718e3744 19208}
19209
7336e101
SP
19210DEFUN (no_community_list_expanded_all,
19211 no_bgp_community_list_expanded_all_cmd,
a2099c1d 19212 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19213 NO_STR
19214 BGP_STR
19215 COMMUNITY_LIST_STR
19216 "Community list number (expanded)\n"
19217 "Add an expanded community-list entry\n"
19218 "Community list name\n"
2f8cc0e5
DA
19219 "Sequence number of an entry\n"
19220 "Sequence number\n"
7336e101
SP
19221 "Specify community to reject\n"
19222 "Specify community to accept\n"
19223 COMMUNITY_VAL_STR)
718e3744 19224{
d62a17ae 19225 char *cl_name_or_number = NULL;
2f8cc0e5 19226 char *seq = NULL;
174b5cb9 19227 char *str = NULL;
d62a17ae 19228 int direct = 0;
19229 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19230 int idx = 0;
174b5cb9 19231
a08032fe 19232 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19233 if (idx)
19234 seq = argv[idx]->arg;
19235
19236 idx = 0;
174b5cb9
DA
19237 argv_find(argv, argc, "permit", &idx);
19238 argv_find(argv, argc, "deny", &idx);
19239
19240 if (idx) {
19241 direct = argv_find(argv, argc, "permit", &idx)
19242 ? COMMUNITY_PERMIT
19243 : COMMUNITY_DENY;
19244
19245 idx = 0;
19246 argv_find(argv, argc, "AA:NN", &idx);
19247 str = argv_concat(argv, argc, idx);
7336e101 19248 }
174b5cb9
DA
19249
19250 idx = 0;
d62a17ae 19251 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19252 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19253 cl_name_or_number = argv[idx]->arg;
42f914d4 19254
2f8cc0e5 19255 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19256 direct, style);
42f914d4 19257
d62a17ae 19258 XFREE(MTYPE_TMP, str);
daf9ddbb 19259
d62a17ae 19260 if (ret < 0) {
19261 community_list_perror(vty, ret);
19262 return CMD_WARNING_CONFIG_FAILED;
19263 }
42f914d4 19264
d62a17ae 19265 return CMD_SUCCESS;
718e3744 19266}
19267
36d4bb44
EB
19268ALIAS(no_community_list_expanded_all,
19269 no_bgp_community_list_expanded_all_list_cmd,
a2099c1d 19270 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
36d4bb44 19271 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
19272 "Community list number (expanded)\n"
19273 "Add an expanded community-list entry\n"
19274 "Community list name\n")
19275
8d9b8ed9
PM
19276/* Return configuration string of community-list entry. */
19277static const char *community_list_config_str(struct community_entry *entry)
19278{
19279 const char *str;
19280
19281 if (entry->any)
19282 str = "";
19283 else {
19284 if (entry->style == COMMUNITY_LIST_STANDARD)
19285 str = community_str(entry->u.com, false);
19286 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19287 str = lcommunity_str(entry->u.lcom, false);
19288 else
19289 str = entry->config;
19290 }
19291 return str;
19292}
19293
d62a17ae 19294static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 19295{
d62a17ae 19296 struct community_entry *entry;
718e3744 19297
d62a17ae 19298 for (entry = list->head; entry; entry = entry->next) {
19299 if (entry == list->head) {
19300 if (all_digit(list->name))
19301 vty_out(vty, "Community %s list %s\n",
19302 entry->style == COMMUNITY_LIST_STANDARD
19303 ? "standard"
19304 : "(expanded) access",
19305 list->name);
19306 else
19307 vty_out(vty, "Named Community %s list %s\n",
19308 entry->style == COMMUNITY_LIST_STANDARD
19309 ? "standard"
19310 : "expanded",
19311 list->name);
19312 }
19313 if (entry->any)
19314 vty_out(vty, " %s\n",
19315 community_direct_str(entry->direct));
19316 else
19317 vty_out(vty, " %s %s\n",
19318 community_direct_str(entry->direct),
8d9b8ed9 19319 community_list_config_str(entry));
d62a17ae 19320 }
718e3744 19321}
19322
7336e101
SP
19323DEFUN (show_community_list,
19324 show_bgp_community_list_cmd,
19325 "show bgp community-list",
718e3744 19326 SHOW_STR
7336e101 19327 BGP_STR
718e3744 19328 "List community-list\n")
19329{
d62a17ae 19330 struct community_list *list;
19331 struct community_list_master *cm;
718e3744 19332
d62a17ae 19333 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19334 if (!cm)
19335 return CMD_SUCCESS;
718e3744 19336
d62a17ae 19337 for (list = cm->num.head; list; list = list->next)
19338 community_list_show(vty, list);
718e3744 19339
d62a17ae 19340 for (list = cm->str.head; list; list = list->next)
19341 community_list_show(vty, list);
718e3744 19342
d62a17ae 19343 return CMD_SUCCESS;
718e3744 19344}
19345
7336e101
SP
19346DEFUN (show_community_list_arg,
19347 show_bgp_community_list_arg_cmd,
a2099c1d 19348 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
7336e101
SP
19349 SHOW_STR
19350 BGP_STR
718e3744 19351 "List community-list\n"
19352 "Community-list number\n"
960b69b9 19353 "Community-list name\n"
19354 "Detailed information on community-list\n")
718e3744 19355{
d62a17ae 19356 int idx_comm_list = 3;
19357 struct community_list *list;
718e3744 19358
e237b0d2 19359 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19360 COMMUNITY_LIST_MASTER);
19361 if (!list) {
19362 vty_out(vty, "%% Can't find community-list\n");
19363 return CMD_WARNING;
19364 }
718e3744 19365
d62a17ae 19366 community_list_show(vty, list);
718e3744 19367
d62a17ae 19368 return CMD_SUCCESS;
718e3744 19369}
6b0655a2 19370
57d187bc
JS
19371/*
19372 * Large Community code.
19373 */
d62a17ae 19374static int lcommunity_list_set_vty(struct vty *vty, int argc,
19375 struct cmd_token **argv, int style,
19376 int reject_all_digit_name)
19377{
19378 int ret;
19379 int direct;
19380 char *str;
19381 int idx = 0;
19382 char *cl_name;
2f8cc0e5
DA
19383 char *seq = NULL;
19384
a08032fe 19385 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19386 seq = argv[idx]->arg;
d62a17ae 19387
2f8cc0e5 19388 idx = 0;
d62a17ae 19389 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19390 : COMMUNITY_DENY;
19391
19392 /* All digit name check. */
19393 idx = 0;
a2099c1d 19394 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19395 argv_find(argv, argc, "(1-99)", &idx);
19396 argv_find(argv, argc, "(100-500)", &idx);
19397 cl_name = argv[idx]->arg;
19398 if (reject_all_digit_name && all_digit(cl_name)) {
19399 vty_out(vty, "%% Community name cannot have all digits\n");
19400 return CMD_WARNING_CONFIG_FAILED;
19401 }
19402
19403 idx = 0;
19404 argv_find(argv, argc, "AA:BB:CC", &idx);
19405 argv_find(argv, argc, "LINE", &idx);
19406 /* Concat community string argument. */
19407 if (idx)
19408 str = argv_concat(argv, argc, idx);
19409 else
19410 str = NULL;
19411
2f8cc0e5 19412 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 19413
19414 /* Free temporary community list string allocated by
19415 argv_concat(). */
0a22ddfb 19416 XFREE(MTYPE_TMP, str);
d62a17ae 19417
19418 if (ret < 0) {
19419 community_list_perror(vty, ret);
19420 return CMD_WARNING_CONFIG_FAILED;
19421 }
19422 return CMD_SUCCESS;
19423}
19424
19425static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19426 struct cmd_token **argv, int style)
19427{
19428 int ret;
19429 int direct = 0;
19430 char *str = NULL;
19431 int idx = 0;
2f8cc0e5 19432 char *seq = NULL;
d62a17ae 19433
a08032fe 19434 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19435 seq = argv[idx]->arg;
d62a17ae 19436
2f8cc0e5 19437 idx = 0;
d62a17ae 19438 argv_find(argv, argc, "permit", &idx);
19439 argv_find(argv, argc, "deny", &idx);
19440
19441 if (idx) {
19442 /* Check the list direct. */
19443 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19444 direct = COMMUNITY_PERMIT;
19445 else
19446 direct = COMMUNITY_DENY;
19447
19448 idx = 0;
19449 argv_find(argv, argc, "LINE", &idx);
19450 argv_find(argv, argc, "AA:AA:NN", &idx);
19451 /* Concat community string argument. */
19452 str = argv_concat(argv, argc, idx);
19453 }
19454
19455 idx = 0;
19456 argv_find(argv, argc, "(1-99)", &idx);
19457 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19458 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19459
19460 /* Unset community list. */
2f8cc0e5 19461 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 19462 style);
19463
19464 /* Free temporary community list string allocated by
19465 argv_concat(). */
0a22ddfb 19466 XFREE(MTYPE_TMP, str);
d62a17ae 19467
19468 if (ret < 0) {
19469 community_list_perror(vty, ret);
19470 return CMD_WARNING_CONFIG_FAILED;
19471 }
19472
19473 return CMD_SUCCESS;
57d187bc
JS
19474}
19475
19476/* "large-community-list" keyword help string. */
19477#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19478#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19479
7336e101
SP
19480DEFUN (lcommunity_list_standard,
19481 bgp_lcommunity_list_standard_cmd,
a08032fe 19482 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19483 BGP_STR
19484 LCOMMUNITY_LIST_STR
19485 "Large Community list number (standard)\n"
2f8cc0e5
DA
19486 "Sequence number of an entry\n"
19487 "Sequence number\n"
7336e101
SP
19488 "Specify large community to reject\n"
19489 "Specify large community to accept\n"
19490 LCOMMUNITY_VAL_STR)
52951b63 19491{
d62a17ae 19492 return lcommunity_list_set_vty(vty, argc, argv,
19493 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
19494}
19495
7336e101
SP
19496DEFUN (lcommunity_list_expanded,
19497 bgp_lcommunity_list_expanded_cmd,
a08032fe 19498 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19499 BGP_STR
19500 LCOMMUNITY_LIST_STR
19501 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19502 "Sequence number of an entry\n"
19503 "Sequence number\n"
7336e101
SP
19504 "Specify large community to reject\n"
19505 "Specify large community to accept\n"
19506 "An ordered list as a regular-expression\n")
57d187bc 19507{
d62a17ae 19508 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19509 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
19510}
19511
7336e101
SP
19512DEFUN (lcommunity_list_name_standard,
19513 bgp_lcommunity_list_name_standard_cmd,
a2099c1d 19514 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19515 BGP_STR
19516 LCOMMUNITY_LIST_STR
19517 "Specify standard large-community-list\n"
19518 "Large Community list name\n"
2f8cc0e5
DA
19519 "Sequence number of an entry\n"
19520 "Sequence number\n"
7336e101
SP
19521 "Specify large community to reject\n"
19522 "Specify large community to accept\n"
19523 LCOMMUNITY_VAL_STR)
52951b63 19524{
d62a17ae 19525 return lcommunity_list_set_vty(vty, argc, argv,
19526 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
19527}
19528
7336e101
SP
19529DEFUN (lcommunity_list_name_expanded,
19530 bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 19531 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19532 BGP_STR
19533 LCOMMUNITY_LIST_STR
19534 "Specify expanded large-community-list\n"
19535 "Large Community list name\n"
2f8cc0e5
DA
19536 "Sequence number of an entry\n"
19537 "Sequence number\n"
7336e101
SP
19538 "Specify large community to reject\n"
19539 "Specify large community to accept\n"
19540 "An ordered list as a regular-expression\n")
57d187bc 19541{
d62a17ae 19542 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19543 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
19544}
19545
4378f57c
DA
19546DEFUN (no_lcommunity_list_all,
19547 no_bgp_lcommunity_list_all_cmd,
a2099c1d 19548 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
7336e101
SP
19549 NO_STR
19550 BGP_STR
19551 LCOMMUNITY_LIST_STR
19552 "Large Community list number (standard)\n"
19553 "Large Community list number (expanded)\n"
19554 "Large Community list name\n")
57d187bc 19555{
7336e101
SP
19556 return lcommunity_list_unset_vty(vty, argc, argv,
19557 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19558}
19559
4378f57c
DA
19560DEFUN (no_lcommunity_list_name_standard_all,
19561 no_bgp_lcommunity_list_name_standard_all_cmd,
a2099c1d 19562 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
4378f57c
DA
19563 NO_STR
19564 BGP_STR
19565 LCOMMUNITY_LIST_STR
19566 "Specify standard large-community-list\n"
19567 "Large Community list name\n")
19568{
19569 return lcommunity_list_unset_vty(vty, argc, argv,
19570 LARGE_COMMUNITY_LIST_STANDARD);
19571}
19572
7336e101
SP
19573DEFUN (no_lcommunity_list_name_expanded_all,
19574 no_bgp_lcommunity_list_name_expanded_all_cmd,
a2099c1d 19575 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
7336e101
SP
19576 NO_STR
19577 BGP_STR
19578 LCOMMUNITY_LIST_STR
19579 "Specify expanded large-community-list\n"
19580 "Large Community list name\n")
57d187bc 19581{
d62a17ae 19582 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19583 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19584}
19585
7336e101
SP
19586DEFUN (no_lcommunity_list_standard,
19587 no_bgp_lcommunity_list_standard_cmd,
a08032fe 19588 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19589 NO_STR
19590 BGP_STR
19591 LCOMMUNITY_LIST_STR
19592 "Large Community list number (standard)\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_expanded,
19604 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 19605 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19606 NO_STR
19607 BGP_STR
19608 LCOMMUNITY_LIST_STR
19609 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19610 "Sequence number of an entry\n"
19611 "Sequence number\n"
7336e101
SP
19612 "Specify large community to reject\n"
19613 "Specify large community to accept\n"
19614 "An ordered list as a regular-expression\n")
57d187bc 19615{
d62a17ae 19616 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19617 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19618}
19619
7336e101
SP
19620DEFUN (no_lcommunity_list_name_standard,
19621 no_bgp_lcommunity_list_name_standard_cmd,
a2099c1d 19622 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19623 NO_STR
19624 BGP_STR
19625 LCOMMUNITY_LIST_STR
19626 "Specify standard large-community-list\n"
19627 "Large Community list name\n"
2f8cc0e5
DA
19628 "Sequence number of an entry\n"
19629 "Sequence number\n"
7336e101
SP
19630 "Specify large community to reject\n"
19631 "Specify large community to accept\n"
19632 LCOMMUNITY_VAL_STR)
57d187bc 19633{
d62a17ae 19634 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19635 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19636}
19637
7336e101
SP
19638DEFUN (no_lcommunity_list_name_expanded,
19639 no_bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 19640 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19641 NO_STR
19642 BGP_STR
19643 LCOMMUNITY_LIST_STR
19644 "Specify expanded large-community-list\n"
19645 "Large community list name\n"
2f8cc0e5
DA
19646 "Sequence number of an entry\n"
19647 "Sequence number\n"
7336e101
SP
19648 "Specify large community to reject\n"
19649 "Specify large community to accept\n"
19650 "An ordered list as a regular-expression\n")
57d187bc 19651{
d62a17ae 19652 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19653 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19654}
19655
d62a17ae 19656static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19657{
19658 struct community_entry *entry;
19659
19660 for (entry = list->head; entry; entry = entry->next) {
19661 if (entry == list->head) {
19662 if (all_digit(list->name))
19663 vty_out(vty, "Large community %s list %s\n",
169b72c8 19664 entry->style ==
19665 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19666 ? "standard"
19667 : "(expanded) access",
19668 list->name);
19669 else
19670 vty_out(vty,
19671 "Named large community %s list %s\n",
169b72c8 19672 entry->style ==
19673 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19674 ? "standard"
19675 : "expanded",
19676 list->name);
19677 }
19678 if (entry->any)
19679 vty_out(vty, " %s\n",
19680 community_direct_str(entry->direct));
19681 else
19682 vty_out(vty, " %s %s\n",
19683 community_direct_str(entry->direct),
8d9b8ed9 19684 community_list_config_str(entry));
d62a17ae 19685 }
57d187bc
JS
19686}
19687
7336e101
SP
19688DEFUN (show_lcommunity_list,
19689 show_bgp_lcommunity_list_cmd,
19690 "show bgp large-community-list",
57d187bc 19691 SHOW_STR
7336e101 19692 BGP_STR
57d187bc
JS
19693 "List large-community list\n")
19694{
d62a17ae 19695 struct community_list *list;
19696 struct community_list_master *cm;
57d187bc 19697
d62a17ae 19698 cm = community_list_master_lookup(bgp_clist,
19699 LARGE_COMMUNITY_LIST_MASTER);
19700 if (!cm)
19701 return CMD_SUCCESS;
57d187bc 19702
d62a17ae 19703 for (list = cm->num.head; list; list = list->next)
19704 lcommunity_list_show(vty, list);
57d187bc 19705
d62a17ae 19706 for (list = cm->str.head; list; list = list->next)
19707 lcommunity_list_show(vty, list);
57d187bc 19708
d62a17ae 19709 return CMD_SUCCESS;
57d187bc
JS
19710}
19711
7336e101
SP
19712DEFUN (show_lcommunity_list_arg,
19713 show_bgp_lcommunity_list_arg_cmd,
a2099c1d 19714 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
7336e101
SP
19715 SHOW_STR
19716 BGP_STR
57d187bc 19717 "List large-community list\n"
960b69b9 19718 "Large-community-list number\n"
19719 "Large-community-list name\n"
19720 "Detailed information on large-community-list\n")
57d187bc 19721{
d62a17ae 19722 struct community_list *list;
57d187bc 19723
e237b0d2 19724 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 19725 LARGE_COMMUNITY_LIST_MASTER);
19726 if (!list) {
960b69b9 19727 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 19728 return CMD_WARNING;
19729 }
57d187bc 19730
d62a17ae 19731 lcommunity_list_show(vty, list);
57d187bc 19732
d62a17ae 19733 return CMD_SUCCESS;
57d187bc
JS
19734}
19735
718e3744 19736/* "extcommunity-list" keyword help string. */
19737#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19738#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19739
7336e101
SP
19740DEFUN (extcommunity_list_standard,
19741 bgp_extcommunity_list_standard_cmd,
a2099c1d 19742 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19743 BGP_STR
718e3744 19744 EXTCOMMUNITY_LIST_STR
19745 "Extended Community list number (standard)\n"
718e3744 19746 "Specify standard extcommunity-list\n"
5bf15956 19747 "Community list name\n"
2f8cc0e5
DA
19748 "Sequence number of an entry\n"
19749 "Sequence number\n"
718e3744 19750 "Specify community to reject\n"
19751 "Specify community to accept\n"
19752 EXTCOMMUNITY_VAL_STR)
19753{
d62a17ae 19754 int style = EXTCOMMUNITY_LIST_STANDARD;
19755 int direct = 0;
19756 char *cl_number_or_name = NULL;
2f8cc0e5 19757 char *seq = NULL;
42f914d4 19758
d62a17ae 19759 int idx = 0;
7b9a4750 19760
d62a17ae 19761 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19762 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19763 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19764
a08032fe 19765 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19766 seq = argv[idx]->arg;
19767
d62a17ae 19768 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19769 : COMMUNITY_DENY;
19770 argv_find(argv, argc, "AA:NN", &idx);
19771 char *str = argv_concat(argv, argc, idx);
42f914d4 19772
2f8cc0e5 19773 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19774 direct, style);
42f914d4 19775
d62a17ae 19776 XFREE(MTYPE_TMP, str);
42f914d4 19777
d62a17ae 19778 if (ret < 0) {
19779 community_list_perror(vty, ret);
19780 return CMD_WARNING_CONFIG_FAILED;
19781 }
42f914d4 19782
d62a17ae 19783 return CMD_SUCCESS;
718e3744 19784}
19785
7336e101
SP
19786DEFUN (extcommunity_list_name_expanded,
19787 bgp_extcommunity_list_name_expanded_cmd,
a2099c1d 19788 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19789 BGP_STR
19790 EXTCOMMUNITY_LIST_STR
5bf15956 19791 "Extended Community list number (expanded)\n"
718e3744 19792 "Specify expanded extcommunity-list\n"
19793 "Extended Community list name\n"
2f8cc0e5
DA
19794 "Sequence number of an entry\n"
19795 "Sequence number\n"
718e3744 19796 "Specify community to reject\n"
19797 "Specify community to accept\n"
19798 "An ordered list as a regular-expression\n")
19799{
d62a17ae 19800 int style = EXTCOMMUNITY_LIST_EXPANDED;
19801 int direct = 0;
19802 char *cl_number_or_name = NULL;
2f8cc0e5 19803 char *seq = NULL;
d62a17ae 19804 int idx = 0;
7336e101 19805
d62a17ae 19806 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19807 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19808 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19809
a08032fe 19810 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19811 seq = argv[idx]->arg;
19812
d62a17ae 19813 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19814 : COMMUNITY_DENY;
19815 argv_find(argv, argc, "LINE", &idx);
19816 char *str = argv_concat(argv, argc, idx);
42f914d4 19817
2f8cc0e5 19818 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19819 direct, style);
42f914d4 19820
d62a17ae 19821 XFREE(MTYPE_TMP, str);
42f914d4 19822
d62a17ae 19823 if (ret < 0) {
19824 community_list_perror(vty, ret);
19825 return CMD_WARNING_CONFIG_FAILED;
19826 }
42f914d4 19827
d62a17ae 19828 return CMD_SUCCESS;
718e3744 19829}
19830
7336e101
SP
19831DEFUN (no_extcommunity_list_standard_all,
19832 no_bgp_extcommunity_list_standard_all_cmd,
a2099c1d 19833 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19834 NO_STR
19835 BGP_STR
19836 EXTCOMMUNITY_LIST_STR
813d4307 19837 "Extended Community list number (standard)\n"
718e3744 19838 "Specify standard extcommunity-list\n"
5bf15956 19839 "Community list name\n"
2f8cc0e5
DA
19840 "Sequence number of an entry\n"
19841 "Sequence number\n"
718e3744 19842 "Specify community to reject\n"
19843 "Specify community to accept\n"
19844 EXTCOMMUNITY_VAL_STR)
19845{
d62a17ae 19846 int style = EXTCOMMUNITY_LIST_STANDARD;
19847 int direct = 0;
19848 char *cl_number_or_name = NULL;
d4455c89 19849 char *str = NULL;
2f8cc0e5 19850 char *seq = NULL;
d62a17ae 19851 int idx = 0;
d4455c89 19852
a08032fe 19853 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19854 seq = argv[idx]->arg;
19855
19856 idx = 0;
d4455c89
DA
19857 argv_find(argv, argc, "permit", &idx);
19858 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
19859 if (idx) {
19860 direct = argv_find(argv, argc, "permit", &idx)
19861 ? COMMUNITY_PERMIT
19862 : COMMUNITY_DENY;
19863
19864 idx = 0;
19865 argv_find(argv, argc, "AA:NN", &idx);
19866 str = argv_concat(argv, argc, idx);
19867 }
19868
19869 idx = 0;
d62a17ae 19870 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19871 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19872 cl_number_or_name = argv[idx]->arg;
42f914d4 19873
d62a17ae 19874 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19875 seq, direct, style);
42f914d4 19876
d62a17ae 19877 XFREE(MTYPE_TMP, str);
42f914d4 19878
d62a17ae 19879 if (ret < 0) {
19880 community_list_perror(vty, ret);
19881 return CMD_WARNING_CONFIG_FAILED;
19882 }
42f914d4 19883
d62a17ae 19884 return CMD_SUCCESS;
718e3744 19885}
19886
d4455c89
DA
19887ALIAS(no_extcommunity_list_standard_all,
19888 no_bgp_extcommunity_list_standard_all_list_cmd,
a2099c1d 19889 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
36d4bb44 19890 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19891 "Extended Community list number (standard)\n"
19892 "Specify standard extcommunity-list\n"
19893 "Community list name\n")
19894
7336e101
SP
19895DEFUN (no_extcommunity_list_expanded_all,
19896 no_bgp_extcommunity_list_expanded_all_cmd,
a2099c1d 19897 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19898 NO_STR
19899 BGP_STR
19900 EXTCOMMUNITY_LIST_STR
718e3744 19901 "Extended Community list number (expanded)\n"
718e3744 19902 "Specify expanded extcommunity-list\n"
5bf15956 19903 "Extended Community list name\n"
2f8cc0e5
DA
19904 "Sequence number of an entry\n"
19905 "Sequence number\n"
718e3744 19906 "Specify community to reject\n"
19907 "Specify community to accept\n"
19908 "An ordered list as a regular-expression\n")
19909{
d62a17ae 19910 int style = EXTCOMMUNITY_LIST_EXPANDED;
19911 int direct = 0;
19912 char *cl_number_or_name = NULL;
d4455c89 19913 char *str = NULL;
2f8cc0e5 19914 char *seq = NULL;
d62a17ae 19915 int idx = 0;
d4455c89 19916
a08032fe 19917 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19918 seq = argv[idx]->arg;
19919
19920 idx = 0;
d4455c89
DA
19921 argv_find(argv, argc, "permit", &idx);
19922 argv_find(argv, argc, "deny", &idx);
19923
19924 if (idx) {
19925 direct = argv_find(argv, argc, "permit", &idx)
19926 ? COMMUNITY_PERMIT
19927 : COMMUNITY_DENY;
19928
19929 idx = 0;
19930 argv_find(argv, argc, "LINE", &idx);
19931 str = argv_concat(argv, argc, idx);
19932 }
19933
19934 idx = 0;
d62a17ae 19935 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19936 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19937 cl_number_or_name = argv[idx]->arg;
42f914d4 19938
d62a17ae 19939 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19940 seq, direct, style);
42f914d4 19941
d62a17ae 19942 XFREE(MTYPE_TMP, str);
42f914d4 19943
d62a17ae 19944 if (ret < 0) {
19945 community_list_perror(vty, ret);
19946 return CMD_WARNING_CONFIG_FAILED;
19947 }
42f914d4 19948
d62a17ae 19949 return CMD_SUCCESS;
718e3744 19950}
19951
d4455c89
DA
19952ALIAS(no_extcommunity_list_expanded_all,
19953 no_bgp_extcommunity_list_expanded_all_list_cmd,
a2099c1d 19954 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
36d4bb44 19955 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19956 "Extended Community list number (expanded)\n"
19957 "Specify expanded extcommunity-list\n"
19958 "Extended Community list name\n")
19959
d62a17ae 19960static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 19961{
d62a17ae 19962 struct community_entry *entry;
718e3744 19963
d62a17ae 19964 for (entry = list->head; entry; entry = entry->next) {
19965 if (entry == list->head) {
19966 if (all_digit(list->name))
19967 vty_out(vty, "Extended community %s list %s\n",
19968 entry->style == EXTCOMMUNITY_LIST_STANDARD
19969 ? "standard"
19970 : "(expanded) access",
19971 list->name);
19972 else
19973 vty_out(vty,
19974 "Named extended community %s list %s\n",
19975 entry->style == EXTCOMMUNITY_LIST_STANDARD
19976 ? "standard"
19977 : "expanded",
19978 list->name);
19979 }
19980 if (entry->any)
19981 vty_out(vty, " %s\n",
19982 community_direct_str(entry->direct));
19983 else
19984 vty_out(vty, " %s %s\n",
19985 community_direct_str(entry->direct),
8d9b8ed9 19986 community_list_config_str(entry));
d62a17ae 19987 }
718e3744 19988}
19989
7336e101
SP
19990DEFUN (show_extcommunity_list,
19991 show_bgp_extcommunity_list_cmd,
19992 "show bgp extcommunity-list",
718e3744 19993 SHOW_STR
7336e101 19994 BGP_STR
718e3744 19995 "List extended-community list\n")
19996{
d62a17ae 19997 struct community_list *list;
19998 struct community_list_master *cm;
718e3744 19999
d62a17ae 20000 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20001 if (!cm)
20002 return CMD_SUCCESS;
718e3744 20003
d62a17ae 20004 for (list = cm->num.head; list; list = list->next)
20005 extcommunity_list_show(vty, list);
718e3744 20006
d62a17ae 20007 for (list = cm->str.head; list; list = list->next)
20008 extcommunity_list_show(vty, list);
718e3744 20009
d62a17ae 20010 return CMD_SUCCESS;
718e3744 20011}
20012
7336e101
SP
20013DEFUN (show_extcommunity_list_arg,
20014 show_bgp_extcommunity_list_arg_cmd,
a2099c1d 20015 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
7336e101
SP
20016 SHOW_STR
20017 BGP_STR
718e3744 20018 "List extended-community list\n"
20019 "Extcommunity-list number\n"
960b69b9 20020 "Extcommunity-list name\n"
20021 "Detailed information on extcommunity-list\n")
718e3744 20022{
d62a17ae 20023 int idx_comm_list = 3;
20024 struct community_list *list;
718e3744 20025
e237b0d2 20026 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20027 EXTCOMMUNITY_LIST_MASTER);
20028 if (!list) {
20029 vty_out(vty, "%% Can't find extcommunity-list\n");
20030 return CMD_WARNING;
20031 }
718e3744 20032
d62a17ae 20033 extcommunity_list_show(vty, list);
718e3744 20034
d62a17ae 20035 return CMD_SUCCESS;
718e3744 20036}
6b0655a2 20037
718e3744 20038/* Display community-list and extcommunity-list configuration. */
d62a17ae 20039static int community_list_config_write(struct vty *vty)
20040{
20041 struct community_list *list;
20042 struct community_entry *entry;
20043 struct community_list_master *cm;
20044 int write = 0;
20045
20046 /* Community-list. */
20047 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20048
20049 for (list = cm->num.head; list; list = list->next)
20050 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20051 vty_out(vty,
20052 "bgp community-list %s seq %" PRId64 " %s %s\n",
20053 list->name, entry->seq,
d62a17ae 20054 community_direct_str(entry->direct),
20055 community_list_config_str(entry));
20056 write++;
20057 }
20058 for (list = cm->str.head; list; list = list->next)
20059 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20060 vty_out(vty,
20061 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 20062 entry->style == COMMUNITY_LIST_STANDARD
20063 ? "standard"
20064 : "expanded",
2f8cc0e5
DA
20065 list->name, entry->seq,
20066 community_direct_str(entry->direct),
d62a17ae 20067 community_list_config_str(entry));
20068 write++;
20069 }
20070
20071 /* Extcommunity-list. */
20072 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20073
20074 for (list = cm->num.head; list; list = list->next)
20075 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20076 vty_out(vty,
20077 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20078 list->name, entry->seq,
20079 community_direct_str(entry->direct),
d62a17ae 20080 community_list_config_str(entry));
20081 write++;
20082 }
20083 for (list = cm->str.head; list; list = list->next)
20084 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20085 vty_out(vty,
6cde4b45 20086 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 20087 entry->style == EXTCOMMUNITY_LIST_STANDARD
20088 ? "standard"
20089 : "expanded",
2f8cc0e5
DA
20090 list->name, entry->seq,
20091 community_direct_str(entry->direct),
d62a17ae 20092 community_list_config_str(entry));
20093 write++;
20094 }
20095
20096
20097 /* lcommunity-list. */
20098 cm = community_list_master_lookup(bgp_clist,
20099 LARGE_COMMUNITY_LIST_MASTER);
20100
20101 for (list = cm->num.head; list; list = list->next)
20102 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20103 vty_out(vty,
6cde4b45 20104 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
20105 list->name, entry->seq,
20106 community_direct_str(entry->direct),
d62a17ae 20107 community_list_config_str(entry));
20108 write++;
20109 }
20110 for (list = cm->str.head; list; list = list->next)
20111 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20112 vty_out(vty,
6cde4b45 20113 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 20114
d62a17ae 20115 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20116 ? "standard"
20117 : "expanded",
2f8cc0e5 20118 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 20119 community_list_config_str(entry));
20120 write++;
20121 }
20122
20123 return write;
20124}
20125
612c2c15 20126static int community_list_config_write(struct vty *vty);
d62a17ae 20127static struct cmd_node community_list_node = {
f4b8291f 20128 .name = "community list",
62b346ee
DL
20129 .node = COMMUNITY_LIST_NODE,
20130 .prompt = "",
612c2c15 20131 .config_write = community_list_config_write,
718e3744 20132};
20133
d62a17ae 20134static void community_list_vty(void)
20135{
612c2c15 20136 install_node(&community_list_node);
d62a17ae 20137
20138 /* Community-list. */
7336e101
SP
20139 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20140 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20141 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 20142 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 20143 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 20144 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
20145 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20146 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 20147
20148 /* Extcommunity-list. */
7336e101
SP
20149 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20150 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20151 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
20152 install_element(CONFIG_NODE,
20153 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 20154 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
20155 install_element(CONFIG_NODE,
20156 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
20157 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20158 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 20159
20160 /* Large Community List */
7336e101 20161 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
20162 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20163 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 20164 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
20165 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20166 install_element(CONFIG_NODE,
20167 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
20168 install_element(CONFIG_NODE,
20169 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20170 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20171 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20172 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20173 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20174 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20175 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
225096bc
DA
20176
20177 bgp_community_list_command_completion_setup();
5bf15956 20178}
ed0e57e3
DA
20179
20180static struct cmd_node community_alias_node = {
20181 .name = "community alias",
20182 .node = COMMUNITY_ALIAS_NODE,
20183 .prompt = "",
20184 .config_write = bgp_community_alias_write,
20185};
20186
20187void community_alias_vty(void)
20188{
20189 install_node(&community_alias_node);
20190
20191 /* Community-list. */
20192 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
b4ad2fae
DS
20193
20194 bgp_community_alias_command_completion_setup();
ed0e57e3 20195}