]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: Remove unused BGP_ERR_MAX #define
[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;
6dcea6fe
DS
880 case BGP_ERR_PEER_GROUP_MEMBER:
881 str = "Peer-group member cannot override remote-as of peer-group.";
882 break;
883 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
884 str = "Peer-group members must be all internal or all external.";
885 break;
d62a17ae 886 }
887 if (str) {
888 vty_out(vty, "%% %s\n", str);
889 return CMD_WARNING_CONFIG_FAILED;
890 }
891 return CMD_SUCCESS;
718e3744 892}
893
7aafcaca 894/* BGP clear sort. */
d62a17ae 895enum clear_sort {
896 clear_all,
897 clear_peer,
898 clear_group,
899 clear_external,
900 clear_as
7aafcaca
DS
901};
902
1ca2fd11
IR
903static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
904 safi_t safi, int error)
d62a17ae 905{
906 switch (error) {
907 case BGP_ERR_AF_UNCONFIGURED:
1ca2fd11
IR
908 vty_out(vty,
909 "%%BGP: Enable %s address family for the neighbor %s\n",
910 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 911 break;
912 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
1ca2fd11
IR
913 vty_out(vty,
914 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
d62a17ae 915 peer->host);
916 break;
917 default:
918 break;
919 }
7aafcaca
DS
920}
921
dc912615 922static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 923 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
924{
925 int ret = 0;
2adac256 926 struct peer_af *paf;
dc912615
DS
927
928 /* if afi/.safi not specified, spin thru all of them */
929 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
930 afi_t tmp_afi;
931 safi_t tmp_safi;
0e5cdd59
DS
932 enum bgp_af_index index;
933
934 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
935 paf = peer->peer_af_array[index];
936 if (!paf)
937 continue;
dc912615 938
2adac256
DA
939 if (paf && paf->subgroup)
940 SET_FLAG(paf->subgroup->sflags,
941 SUBGRP_STATUS_FORCE_UPDATES);
942
0e5cdd59
DS
943 tmp_afi = paf->afi;
944 tmp_safi = paf->safi;
dc912615
DS
945 if (!peer->afc[tmp_afi][tmp_safi])
946 continue;
947
948 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 949 ret = peer_clear(peer, nnode);
dc912615
DS
950 else
951 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
952 stype);
953 }
954 /* if afi specified and safi not, spin thru safis on this afi */
955 } else if (safi == SAFI_UNSPEC) {
956 safi_t tmp_safi;
957
958 for (tmp_safi = SAFI_UNICAST;
959 tmp_safi < SAFI_MAX; tmp_safi++) {
960 if (!peer->afc[afi][tmp_safi])
961 continue;
962
2adac256
DA
963 paf = peer_af_find(peer, afi, tmp_safi);
964 if (paf && paf->subgroup)
965 SET_FLAG(paf->subgroup->sflags,
966 SUBGRP_STATUS_FORCE_UPDATES);
967
dc912615 968 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 969 ret = peer_clear(peer, nnode);
dc912615
DS
970 else
971 ret = peer_clear_soft(peer, afi,
972 tmp_safi, stype);
973 }
974 /* both afi/safi specified, let the caller know if not defined */
975 } else {
976 if (!peer->afc[afi][safi])
977 return 1;
978
2adac256
DA
979 paf = peer_af_find(peer, afi, safi);
980 if (paf && paf->subgroup)
981 SET_FLAG(paf->subgroup->sflags,
982 SUBGRP_STATUS_FORCE_UPDATES);
983
dc912615 984 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 985 ret = peer_clear(peer, nnode);
dc912615
DS
986 else
987 ret = peer_clear_soft(peer, afi, safi, stype);
988 }
989
990 return ret;
991}
992
7aafcaca 993/* `clear ip bgp' functions. */
1ca2fd11 994static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 995 enum clear_sort sort, enum bgp_clear_type stype,
1ca2fd11 996 const char *arg)
d62a17ae 997{
dc912615 998 int ret = 0;
3ae8bfa5 999 bool found = false;
d62a17ae 1000 struct peer *peer;
dc95985f 1001
1002 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 1003
1004 /* Clear all neighbors. */
1005 /*
1006 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
1007 * nodes on the BGP instance as that may get freed if it is a
1008 * doppelganger
d62a17ae 1009 */
1010 if (sort == clear_all) {
1011 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 1012
1013 bgp_peer_gr_flags_update(peer);
1014
36235319 1015 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 1016 gr_router_detected = true;
1017
c368171c 1018 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 1019 stype);
d62a17ae 1020
1021 if (ret < 0)
1ca2fd11 1022 bgp_clear_vty_error(vty, peer, afi, safi, ret);
dc95985f 1023 }
1024
36235319
QY
1025 if (gr_router_detected
1026 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1027 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1028 } else if (!gr_router_detected
1029 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1030 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 1031 }
d62a17ae 1032
1033 /* This is to apply read-only mode on this clear. */
1034 if (stype == BGP_CLEAR_SOFT_NONE)
1035 bgp->update_delay_over = 0;
1036
1037 return CMD_SUCCESS;
7aafcaca
DS
1038 }
1039
3ae8bfa5 1040 /* Clear specified neighbor. */
d62a17ae 1041 if (sort == clear_peer) {
1042 union sockunion su;
d62a17ae 1043
1044 /* Make sockunion for lookup. */
1045 ret = str2sockunion(arg, &su);
1046 if (ret < 0) {
1047 peer = peer_lookup_by_conf_if(bgp, arg);
1048 if (!peer) {
1049 peer = peer_lookup_by_hostname(bgp, arg);
1050 if (!peer) {
1ca2fd11
IR
1051 vty_out(vty,
1052 "Malformed address or name: %s\n",
d62a17ae 1053 arg);
1054 return CMD_WARNING;
1055 }
1056 }
1057 } else {
1058 peer = peer_lookup(bgp, &su);
1059 if (!peer) {
1ca2fd11
IR
1060 vty_out(vty,
1061 "%%BGP: Unknown neighbor - \"%s\"\n",
1062 arg);
d62a17ae 1063 return CMD_WARNING;
1064 }
1065 }
7aafcaca 1066
dc95985f 1067 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1068 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1069
dc912615
DS
1070 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1071
1072 /* if afi/safi not defined for this peer, let caller know */
1073 if (ret == 1)
3ae8bfa5 1074 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1075
d62a17ae 1076 if (ret < 0)
1ca2fd11 1077 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 1078
d62a17ae 1079 return CMD_SUCCESS;
7aafcaca 1080 }
7aafcaca 1081
3ae8bfa5 1082 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1083 if (sort == clear_group) {
1084 struct peer_group *group;
7aafcaca 1085
d62a17ae 1086 group = peer_group_lookup(bgp, arg);
1087 if (!group) {
1ca2fd11 1088 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
d62a17ae 1089 return CMD_WARNING;
1090 }
1091
1092 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1093 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1094
d62a17ae 1095 if (ret < 0)
1ca2fd11 1096 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1097 else
1098 found = true;
d62a17ae 1099 }
3ae8bfa5
PM
1100
1101 if (!found)
1ca2fd11
IR
1102 vty_out(vty,
1103 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 1104 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1105
d62a17ae 1106 return CMD_SUCCESS;
7aafcaca 1107 }
7aafcaca 1108
3ae8bfa5 1109 /* Clear all external (eBGP) neighbors. */
d62a17ae 1110 if (sort == clear_external) {
1111 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1112 if (peer->sort == BGP_PEER_IBGP)
1113 continue;
7aafcaca 1114
dc95985f 1115 bgp_peer_gr_flags_update(peer);
1116
36235319 1117 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1118 gr_router_detected = true;
dc95985f 1119
c368171c 1120 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1121
d62a17ae 1122 if (ret < 0)
1ca2fd11 1123 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1124 else
1125 found = true;
d62a17ae 1126 }
3ae8bfa5 1127
36235319
QY
1128 if (gr_router_detected
1129 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1130 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1131 } else if (!gr_router_detected
1132 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1133 bgp_zebra_send_capabilities(bgp, true);
1134 }
1135
3ae8bfa5 1136 if (!found)
1ca2fd11
IR
1137 vty_out(vty,
1138 "%%BGP: No external %s peer is configured\n",
1139 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1140
d62a17ae 1141 return CMD_SUCCESS;
1142 }
1143
3ae8bfa5 1144 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1145 if (sort == clear_as) {
3ae8bfa5 1146 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1147
1148 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1149 if (peer->as != as)
1150 continue;
1151
dc95985f 1152 bgp_peer_gr_flags_update(peer);
1153
36235319 1154 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1155 gr_router_detected = true;
dc95985f 1156
c368171c 1157 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1158
1159 if (ret < 0)
1ca2fd11 1160 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1161 else
1162 found = true;
d62a17ae 1163 }
3ae8bfa5 1164
36235319
QY
1165 if (gr_router_detected
1166 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1167 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1168 } else if (!gr_router_detected
1169 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1170 bgp_zebra_send_capabilities(bgp, true);
1171 }
1172
3ae8bfa5 1173 if (!found)
1ca2fd11
IR
1174 vty_out(vty,
1175 "%%BGP: No %s peer is configured with AS %s\n",
1176 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1177
d62a17ae 1178 return CMD_SUCCESS;
1179 }
1180
1181 return CMD_SUCCESS;
1182}
1183
1ca2fd11
IR
1184static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1185 safi_t safi, enum clear_sort sort,
1186 enum bgp_clear_type stype, const char *arg)
d62a17ae 1187{
1188 struct bgp *bgp;
1189
1190 /* BGP structure lookup. */
1191 if (name) {
1192 bgp = bgp_lookup_by_name(name);
1193 if (bgp == NULL) {
1ca2fd11 1194 vty_out(vty, "Can't find BGP instance %s\n", name);
d62a17ae 1195 return CMD_WARNING;
1196 }
1197 } else {
1198 bgp = bgp_get_default();
1199 if (bgp == NULL) {
1ca2fd11 1200 vty_out(vty, "No BGP process is configured\n");
d62a17ae 1201 return CMD_WARNING;
1202 }
1203 }
1204
1ca2fd11 1205 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
1206}
1207
1208/* clear soft inbound */
1ca2fd11 1209static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 1210{
99b3ebd3
NS
1211 afi_t afi;
1212 safi_t safi;
1213
1ca2fd11
IR
1214 FOREACH_AFI_SAFI (afi, safi)
1215 bgp_clear_vty(vty, name, afi, safi, clear_all,
1216 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
1217}
1218
1219/* clear soft outbound */
1ca2fd11 1220static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 1221{
99b3ebd3
NS
1222 afi_t afi;
1223 safi_t safi;
1224
1ca2fd11
IR
1225 FOREACH_AFI_SAFI (afi, safi)
1226 bgp_clear_vty(vty, name, afi, safi, clear_all,
1227 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
1228}
1229
1230
f787d7a0 1231#ifndef VTYSH_EXTRACT_PL
2e4c2296 1232#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1233#endif
1234
8029b216
AK
1235DEFUN_HIDDEN (bgp_local_mac,
1236 bgp_local_mac_cmd,
093e3f23 1237 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1238 BGP_STR
1239 "Local MAC config\n"
1240 "VxLAN Network Identifier\n"
1241 "VNI number\n"
1242 "local mac\n"
1243 "mac address\n"
1244 "mac-mobility sequence\n"
1245 "seq number\n")
1246{
1247 int rv;
1248 vni_t vni;
1249 struct ethaddr mac;
1250 struct ipaddr ip;
1251 uint32_t seq;
1252 struct bgp *bgp;
1253
1254 vni = strtoul(argv[3]->arg, NULL, 10);
1255 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1256 vty_out(vty, "%% Malformed MAC address\n");
1257 return CMD_WARNING;
1258 }
1259 memset(&ip, 0, sizeof(ip));
1260 seq = strtoul(argv[7]->arg, NULL, 10);
1261
1262 bgp = bgp_get_default();
1263 if (!bgp) {
1264 vty_out(vty, "Default BGP instance is not there\n");
1265 return CMD_WARNING;
1266 }
1267
b5e140c8
AK
1268 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1269 zero_esi);
8029b216
AK
1270 if (rv < 0) {
1271 vty_out(vty, "Internal error\n");
1272 return CMD_WARNING;
1273 }
1274
1275 return CMD_SUCCESS;
1276}
1277
1278DEFUN_HIDDEN (no_bgp_local_mac,
1279 no_bgp_local_mac_cmd,
093e3f23 1280 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1281 NO_STR
1282 BGP_STR
1283 "Local MAC config\n"
1284 "VxLAN Network Identifier\n"
1285 "VNI number\n"
1286 "local mac\n"
1287 "mac address\n")
1288{
1289 int rv;
1290 vni_t vni;
1291 struct ethaddr mac;
1292 struct ipaddr ip;
1293 struct bgp *bgp;
1294
1295 vni = strtoul(argv[4]->arg, NULL, 10);
1296 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1297 vty_out(vty, "%% Malformed MAC address\n");
1298 return CMD_WARNING;
1299 }
1300 memset(&ip, 0, sizeof(ip));
1301
1302 bgp = bgp_get_default();
1303 if (!bgp) {
1304 vty_out(vty, "Default BGP instance is not there\n");
1305 return CMD_WARNING;
1306 }
1307
ec0ab544 1308 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1309 if (rv < 0) {
1310 vty_out(vty, "Internal error\n");
1311 return CMD_WARNING;
1312 }
1313
1314 return CMD_SUCCESS;
1315}
1316
718e3744 1317DEFUN (no_synchronization,
1318 no_synchronization_cmd,
1319 "no synchronization",
1320 NO_STR
1321 "Perform IGP synchronization\n")
1322{
d62a17ae 1323 return CMD_SUCCESS;
718e3744 1324}
1325
1326DEFUN (no_auto_summary,
1327 no_auto_summary_cmd,
1328 "no auto-summary",
1329 NO_STR
1330 "Enable automatic network number summarization\n")
1331{
d62a17ae 1332 return CMD_SUCCESS;
718e3744 1333}
3d515fd9 1334
718e3744 1335/* "router bgp" commands. */
1ca2fd11
IR
1336DEFUN_NOSH (router_bgp,
1337 router_bgp_cmd,
1338 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1339 ROUTER_STR
1340 BGP_STR
1341 AS_STR
1342 BGP_INSTANCE_HELP_STR)
718e3744 1343{
d62a17ae 1344 int idx_asn = 2;
1345 int idx_view_vrf = 3;
1346 int idx_vrf = 4;
1ca2fd11
IR
1347 int is_new_bgp = 0;
1348 int ret;
d62a17ae 1349 as_t as;
1350 struct bgp *bgp;
1351 const char *name = NULL;
1352 enum bgp_instance_type inst_type;
1353
1354 // "router bgp" without an ASN
1355 if (argc == 2) {
1356 // Pending: Make VRF option available for ASN less config
1abef40f 1357 bgp = bgp_get_default();
d62a17ae 1358
1abef40f 1359 if (bgp == NULL) {
d62a17ae 1360 vty_out(vty, "%% No BGP process is configured\n");
1361 return CMD_WARNING_CONFIG_FAILED;
1362 }
1363
1364 if (listcount(bm->bgp) > 1) {
996c9314 1365 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1366 return CMD_WARNING_CONFIG_FAILED;
1367 }
1368 }
1369
1370 // "router bgp X"
1371 else {
ff8a8a7a 1372 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1ca2fd11 1373
cc413e2a
DA
1374 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1375 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1376 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1377
d62a17ae 1378 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1379 if (argc > 3) {
1380 name = argv[idx_vrf]->arg;
1381
9a8bdf1c
PG
1382 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1383 if (strmatch(name, VRF_DEFAULT_NAME))
1384 name = NULL;
1385 else
1386 inst_type = BGP_INSTANCE_TYPE_VRF;
1ca2fd11 1387 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1388 inst_type = BGP_INSTANCE_TYPE_VIEW;
d62a17ae 1389 }
1390
1ca2fd11
IR
1391 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1392 is_new_bgp = (bgp_lookup(as, name) == NULL);
3bd70bf8 1393
1ca2fd11
IR
1394 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1395 switch (ret) {
1396 case BGP_ERR_AS_MISMATCH:
1397 vty_out(vty, "BGP is already running; AS is %u\n", as);
1398 return CMD_WARNING_CONFIG_FAILED;
1399 case BGP_ERR_INSTANCE_MISMATCH:
1400 vty_out(vty,
1401 "BGP instance name and AS number mismatch\n");
1402 vty_out(vty,
1403 "BGP instance is already running; AS is %u\n",
1404 as);
1405 return CMD_WARNING_CONFIG_FAILED;
ff8a8a7a 1406 }
1ca2fd11
IR
1407
1408 /*
1409 * If we just instantiated the default instance, complete
1410 * any pending VRF-VPN leaking that was configured via
1411 * earlier "router bgp X vrf FOO" blocks.
1412 */
1413 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1414 vpn_leak_postchange_all();
1415
1416 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1417 bgp_vpn_leak_export(bgp);
1418 /* Pending: handle when user tries to change a view to vrf n vv.
1419 */
d62a17ae 1420 }
1421
1ca2fd11
IR
1422 /* unset the auto created flag as the user config is now present */
1423 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1424 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1425
1426 return CMD_SUCCESS;
718e3744 1427}
1428
718e3744 1429/* "no router bgp" commands. */
1ca2fd11
IR
1430DEFUN (no_router_bgp,
1431 no_router_bgp_cmd,
1432 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1433 NO_STR
1434 ROUTER_STR
1435 BGP_STR
1436 AS_STR
1437 BGP_INSTANCE_HELP_STR)
718e3744 1438{
4fd9919e 1439 int idx_asn = 3;
d62a17ae 1440 int idx_vrf = 5;
1ca2fd11 1441 as_t as;
4fd9919e 1442 struct bgp *bgp;
d62a17ae 1443 const char *name = NULL;
718e3744 1444
d62a17ae 1445 // "no router bgp" without an ASN
1446 if (argc == 3) {
1447 // Pending: Make VRF option available for ASN less config
8382083a 1448 bgp = bgp_get_default();
718e3744 1449
8382083a 1450 if (bgp == NULL) {
d62a17ae 1451 vty_out(vty, "%% No BGP process is configured\n");
1452 return CMD_WARNING_CONFIG_FAILED;
1453 }
7fb21a9f 1454
d62a17ae 1455 if (listcount(bm->bgp) > 1) {
996c9314 1456 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1457 return CMD_WARNING_CONFIG_FAILED;
1458 }
4fd9919e 1459
4fd9919e
IR
1460 if (bgp->l3vni) {
1461 vty_out(vty, "%% Please unconfigure l3vni %u",
1462 bgp->l3vni);
1463 return CMD_WARNING_CONFIG_FAILED;
1464 }
d62a17ae 1465 } else {
4fd9919e
IR
1466 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1467
1ca42c8d 1468 if (argc > 4) {
d62a17ae 1469 name = argv[idx_vrf]->arg;
1ca42c8d
IR
1470 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1471 && strmatch(name, VRF_DEFAULT_NAME))
1472 name = NULL;
1473 }
7fb21a9f 1474
4fd9919e
IR
1475 /* Lookup bgp structure. */
1476 bgp = bgp_lookup(as, name);
1477 if (!bgp) {
1478 vty_out(vty, "%% Can't find BGP instance\n");
1479 return CMD_WARNING_CONFIG_FAILED;
1480 }
1481
1482 if (bgp->l3vni) {
1483 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1484 bgp->l3vni);
1485 return CMD_WARNING_CONFIG_FAILED;
1486 }
1487
1488 /* Cannot delete default instance if vrf instances exist */
1489 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1490 struct listnode *node;
1491 struct bgp *tmp_bgp;
1492
1493 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1494 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1495 continue;
1496 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1497 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1498 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1499 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1500 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1501 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1502 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1503 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1504 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1505 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1506 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1507 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1508 (bgp == bgp_get_evpn() &&
1509 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1510 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1511 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1512 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1513 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1514 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1515 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1516 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1517 (tmp_bgp->vnihash && hashcount(tmp_bgp->vnihash))) {
1518 vty_out(vty,
1519 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1520 return CMD_WARNING_CONFIG_FAILED;
1521 }
1522 }
1523 }
d62a17ae 1524 }
718e3744 1525
1ca2fd11 1526 bgp_delete(bgp);
718e3744 1527
1ca2fd11 1528 return CMD_SUCCESS;
718e3744 1529}
1530
718e3744 1531
ff8a8a7a
CS
1532/* BGP router-id. */
1533
1ca2fd11
IR
1534DEFPY (bgp_router_id,
1535 bgp_router_id_cmd,
1536 "bgp router-id A.B.C.D",
1537 BGP_STR
1538 "Override configured router identifier\n"
1539 "Manually configured router identifier\n")
718e3744 1540{
1ca2fd11
IR
1541 VTY_DECLVAR_CONTEXT(bgp, bgp);
1542 bgp_router_id_static_set(bgp, router_id);
1543 return CMD_SUCCESS;
ff8a8a7a 1544}
718e3744 1545
1ca2fd11
IR
1546DEFPY (no_bgp_router_id,
1547 no_bgp_router_id_cmd,
1548 "no bgp router-id [A.B.C.D]",
1549 NO_STR
1550 BGP_STR
1551 "Override configured router identifier\n"
1552 "Manually configured router identifier\n")
ff8a8a7a 1553{
1ca2fd11 1554 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1555
1ca2fd11
IR
1556 if (router_id_str) {
1557 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1558 vty_out(vty, "%% BGP router-id doesn't match\n");
1559 return CMD_WARNING_CONFIG_FAILED;
1560 }
1561 }
718e3744 1562
1ca2fd11
IR
1563 router_id.s_addr = 0;
1564 bgp_router_id_static_set(bgp, router_id);
1565
1566 return CMD_SUCCESS;
ff8a8a7a 1567}
6b0655a2 1568
ed0e57e3 1569DEFPY(bgp_community_alias, bgp_community_alias_cmd,
b4ad2fae 1570 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
ed0e57e3
DA
1571 NO_STR BGP_STR
1572 "Add community specific parameters\n"
1573 "Create an alias for a community\n"
1574 "Community (AA:BB or AA:BB:CC)\n"
1575 "Alias name\n")
1576{
1577 struct community_alias ca1;
1578 struct community_alias ca2;
1579 struct community_alias *lookup_community;
1580 struct community_alias *lookup_alias;
1581
1582 if (!community_str2com(community) && !lcommunity_str2com(community)) {
1583 vty_out(vty, "Invalid community format\n");
1584 return CMD_WARNING;
1585 }
1586
1587 memset(&ca1, 0, sizeof(ca1));
1588 memset(&ca2, 0, sizeof(ca2));
1589 strlcpy(ca1.community, community, sizeof(ca1.community));
b4ad2fae 1590 strlcpy(ca1.alias, alias_name, sizeof(ca1.alias));
ed0e57e3
DA
1591
1592 lookup_community = bgp_ca_community_lookup(&ca1);
1593 lookup_alias = bgp_ca_alias_lookup(&ca1);
1594
1595 if (no) {
1596 bgp_ca_alias_delete(&ca1);
1597 bgp_ca_community_delete(&ca1);
1598 } else {
1599 if (lookup_alias) {
1600 /* Lookup if community hash table has an item
1601 * with the same alias name.
1602 */
1603 strlcpy(ca2.community, lookup_alias->community,
1604 sizeof(ca2.community));
1605 if (bgp_ca_community_lookup(&ca2)) {
1606 vty_out(vty,
1607 "community (%s) already has this alias (%s)\n",
1608 lookup_alias->community,
1609 lookup_alias->alias);
1610 return CMD_WARNING;
1611 }
1612 bgp_ca_alias_delete(&ca1);
1613 }
1614
1615 if (lookup_community)
1616 bgp_ca_community_delete(&ca1);
1617
1618 bgp_ca_alias_insert(&ca1);
1619 bgp_ca_community_insert(&ca1);
1620 }
1621
1622 return CMD_SUCCESS;
1623}
1624
9acb67cb
DS
1625DEFPY (bgp_global_suppress_fib_pending,
1626 bgp_global_suppress_fib_pending_cmd,
1627 "[no] bgp suppress-fib-pending",
1628 NO_STR
1629 BGP_STR
1630 "Advertise only routes that are programmed in kernel to peers globally\n")
1631{
1632 bm_wait_for_fib_set(!no);
1633
1634 return CMD_SUCCESS;
1635}
1636
c208c586
S
1637DEFPY (bgp_suppress_fib_pending,
1638 bgp_suppress_fib_pending_cmd,
1639 "[no] bgp suppress-fib-pending",
1640 NO_STR
1641 BGP_STR
1642 "Advertise only routes that are programmed in kernel to peers\n")
1643{
1644 VTY_DECLVAR_CONTEXT(bgp, bgp);
1645
1646 bgp_suppress_fib_pending_set(bgp, !no);
1647 return CMD_SUCCESS;
1648}
1649
1650
718e3744 1651/* BGP Cluster ID. */
1ca2fd11
IR
1652DEFUN (bgp_cluster_id,
1653 bgp_cluster_id_cmd,
1654 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1655 BGP_STR
1656 "Configure Route-Reflector Cluster-id\n"
1657 "Route-Reflector Cluster-id in IP address format\n"
1658 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1659{
1ca2fd11 1660 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1661 int idx_ipv4 = 2;
1ca2fd11
IR
1662 int ret;
1663 struct in_addr cluster;
1664
1665 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1666 if (!ret) {
1667 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1668 return CMD_WARNING_CONFIG_FAILED;
1669 }
718e3744 1670
1ca2fd11
IR
1671 bgp_cluster_id_set(bgp, &cluster);
1672 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1673
1ca2fd11 1674 return CMD_SUCCESS;
718e3744 1675}
1676
1ca2fd11
IR
1677DEFUN (no_bgp_cluster_id,
1678 no_bgp_cluster_id_cmd,
1679 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1680 NO_STR
1681 BGP_STR
1682 "Configure Route-Reflector Cluster-id\n"
1683 "Route-Reflector Cluster-id in IP address format\n"
1684 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1685{
1ca2fd11
IR
1686 VTY_DECLVAR_CONTEXT(bgp, bgp);
1687 bgp_cluster_id_unset(bgp);
1688 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1689
1ca2fd11 1690 return CMD_SUCCESS;
718e3744 1691}
1692
c163f297
DS
1693DEFPY (bgp_norib,
1694 bgp_norib_cmd,
1695 "bgp no-rib",
1696 BGP_STR
1697 "Disable BGP route installation to RIB (Zebra)\n")
1698{
1699 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1700 vty_out(vty,
1701 "%% No-RIB option is already set, nothing to do here.\n");
1702 return CMD_SUCCESS;
1703 }
1704
1705 bgp_option_norib_set_runtime();
1706
1707 return CMD_SUCCESS;
1708}
1709
1710DEFPY (no_bgp_norib,
1711 no_bgp_norib_cmd,
1712 "no bgp no-rib",
1713 NO_STR
1714 BGP_STR
1715 "Disable BGP route installation to RIB (Zebra)\n")
1716{
1717 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1718 vty_out(vty,
1719 "%% No-RIB option is not set, nothing to do here.\n");
1720 return CMD_SUCCESS;
1721 }
1722
1723 bgp_option_norib_unset_runtime();
1724
1725 return CMD_SUCCESS;
1726}
1727
e46723a5
DS
1728DEFPY (no_bgp_send_extra_data,
1729 no_bgp_send_extra_data_cmd,
1730 "[no] bgp send-extra-data zebra",
1731 NO_STR
1732 BGP_STR
1733 "Extra data to Zebra for display/use\n"
1734 "To zebra\n")
1735{
ec0acb80
DA
1736 if (no)
1737 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1738 else
1739 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1740
1741 return CMD_SUCCESS;
1742}
1743
1ca2fd11
IR
1744DEFUN (bgp_confederation_identifier,
1745 bgp_confederation_identifier_cmd,
1746 "bgp confederation identifier (1-4294967295)",
e9273987 1747 BGP_STR
1ca2fd11
IR
1748 "AS confederation parameters\n"
1749 "AS number\n"
1750 "Set routing domain confederation AS\n")
718e3744 1751{
1ca2fd11 1752 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1753 int idx_number = 3;
1ca2fd11 1754 as_t as;
718e3744 1755
1ca2fd11 1756 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1757
1ca2fd11 1758 bgp_confederation_id_set(bgp, as);
718e3744 1759
1ca2fd11 1760 return CMD_SUCCESS;
718e3744 1761}
1762
1ca2fd11
IR
1763DEFUN (no_bgp_confederation_identifier,
1764 no_bgp_confederation_identifier_cmd,
1765 "no bgp confederation identifier [(1-4294967295)]",
1766 NO_STR
e9273987 1767 BGP_STR
1ca2fd11
IR
1768 "AS confederation parameters\n"
1769 "AS number\n"
1770 "Set routing domain confederation AS\n")
ff8a8a7a 1771{
1ca2fd11
IR
1772 VTY_DECLVAR_CONTEXT(bgp, bgp);
1773 bgp_confederation_id_unset(bgp);
1774
1775 return CMD_SUCCESS;
ff8a8a7a
CS
1776}
1777
1ca2fd11
IR
1778DEFUN (bgp_confederation_peers,
1779 bgp_confederation_peers_cmd,
1780 "bgp confederation peers (1-4294967295)...",
e9273987 1781 BGP_STR
1ca2fd11
IR
1782 "AS confederation parameters\n"
1783 "Peer ASs in BGP confederation\n"
1784 AS_STR)
718e3744 1785{
1ca2fd11 1786 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1787 int idx_asn = 3;
1ca2fd11 1788 as_t as;
d62a17ae 1789 int i;
718e3744 1790
1ca2fd11
IR
1791 for (i = idx_asn; i < argc; i++) {
1792 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1793
1ca2fd11
IR
1794 if (bgp->as == as) {
1795 vty_out(vty,
1796 "%% Local member-AS not allowed in confed peer list\n");
1797 continue;
1798 }
1799
1800 bgp_confederation_peers_add(bgp, as);
1801 }
1802 return CMD_SUCCESS;
718e3744 1803}
1804
1ca2fd11
IR
1805DEFUN (no_bgp_confederation_peers,
1806 no_bgp_confederation_peers_cmd,
1807 "no bgp confederation peers (1-4294967295)...",
1808 NO_STR
e9273987 1809 BGP_STR
1ca2fd11
IR
1810 "AS confederation parameters\n"
1811 "Peer ASs in BGP confederation\n"
1812 AS_STR)
718e3744 1813{
1ca2fd11 1814 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1815 int idx_asn = 4;
1ca2fd11 1816 as_t as;
d62a17ae 1817 int i;
718e3744 1818
1ca2fd11
IR
1819 for (i = idx_asn; i < argc; i++) {
1820 as = strtoul(argv[i]->arg, NULL, 10);
ff8a8a7a 1821
1ca2fd11
IR
1822 bgp_confederation_peers_remove(bgp, as);
1823 }
1824 return CMD_SUCCESS;
718e3744 1825}
6b0655a2 1826
5e242b0d
DS
1827/**
1828 * Central routine for maximum-paths configuration.
1829 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1830 * @set: 1 for setting values, 0 for removing the max-paths config.
1831 */
585f1adc
IR
1832static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1833 const char *mpaths, uint16_t options,
1834 int set)
d62a17ae 1835{
585f1adc
IR
1836 VTY_DECLVAR_CONTEXT(bgp, bgp);
1837 uint16_t maxpaths = 0;
d62a17ae 1838 int ret;
585f1adc
IR
1839 afi_t afi;
1840 safi_t safi;
1841
1842 afi = bgp_node_afi(vty);
1843 safi = bgp_node_safi(vty);
d62a17ae 1844
1845 if (set) {
585f1adc 1846 maxpaths = strtol(mpaths, NULL, 10);
d62a17ae 1847 if (maxpaths > multipath_num) {
585f1adc 1848 vty_out(vty,
d62a17ae 1849 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1850 maxpaths, multipath_num);
1851 return CMD_WARNING_CONFIG_FAILED;
1852 }
1853 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1854 options);
1855 } else
1856 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1857
1858 if (ret < 0) {
585f1adc 1859 vty_out(vty,
d62a17ae 1860 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1861 (set == 1) ? "" : "un",
1862 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1863 maxpaths, afi, safi);
1864 return CMD_WARNING_CONFIG_FAILED;
1865 }
1866
1867 bgp_recalculate_all_bestpaths(bgp);
1868
1869 return CMD_SUCCESS;
165b5fff
JB
1870}
1871
1ca2fd11
IR
1872DEFUN (bgp_maxmed_admin,
1873 bgp_maxmed_admin_cmd,
1874 "bgp max-med administrative ",
1875 BGP_STR
1876 "Advertise routes with max-med\n"
1877 "Administratively applied, for an indefinite period\n")
abc920f8 1878{
1ca2fd11 1879 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1880
1ca2fd11
IR
1881 bgp->v_maxmed_admin = 1;
1882 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
ff8a8a7a 1883
1ca2fd11 1884 bgp_maxmed_update(bgp);
abc920f8 1885
1ca2fd11 1886 return CMD_SUCCESS;
ff8a8a7a
CS
1887}
1888
1ca2fd11
IR
1889DEFUN (bgp_maxmed_admin_medv,
1890 bgp_maxmed_admin_medv_cmd,
1891 "bgp max-med administrative (0-4294967295)",
1892 BGP_STR
1893 "Advertise routes with max-med\n"
1894 "Administratively applied, for an indefinite period\n"
1895 "Max MED value to be used\n")
abc920f8 1896{
1ca2fd11 1897 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1898 int idx_number = 3;
abc920f8 1899
1ca2fd11
IR
1900 bgp->v_maxmed_admin = 1;
1901 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1902
1ca2fd11 1903 bgp_maxmed_update(bgp);
abc920f8 1904
1ca2fd11 1905 return CMD_SUCCESS;
abc920f8
DS
1906}
1907
1ca2fd11
IR
1908DEFUN (no_bgp_maxmed_admin,
1909 no_bgp_maxmed_admin_cmd,
1910 "no bgp max-med administrative [(0-4294967295)]",
1911 NO_STR
1912 BGP_STR
1913 "Advertise routes with max-med\n"
1914 "Administratively applied, for an indefinite period\n"
1915 "Max MED value to be used\n")
abc920f8 1916{
1ca2fd11
IR
1917 VTY_DECLVAR_CONTEXT(bgp, bgp);
1918 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1919 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1920 bgp_maxmed_update(bgp);
ff8a8a7a 1921
1ca2fd11 1922 return CMD_SUCCESS;
abc920f8
DS
1923}
1924
1ca2fd11
IR
1925DEFUN (bgp_maxmed_onstartup,
1926 bgp_maxmed_onstartup_cmd,
1927 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1928 BGP_STR
1929 "Advertise routes with max-med\n"
1930 "Effective on a startup\n"
1931 "Time (seconds) period for max-med\n"
1932 "Max MED value to be used\n")
abc920f8 1933{
1ca2fd11 1934 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1935 int idx = 0;
4668a151 1936
d62a17ae 1937 argv_find(argv, argc, "(5-86400)", &idx);
1ca2fd11 1938 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 1939 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1ca2fd11 1940 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 1941 else
1ca2fd11 1942 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1943
1ca2fd11
IR
1944 bgp_maxmed_update(bgp);
1945
1946 return CMD_SUCCESS;
abc920f8
DS
1947}
1948
1ca2fd11
IR
1949DEFUN (no_bgp_maxmed_onstartup,
1950 no_bgp_maxmed_onstartup_cmd,
1951 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1952 NO_STR
1953 BGP_STR
1954 "Advertise routes with max-med\n"
1955 "Effective on a startup\n"
1956 "Time (seconds) period for max-med\n"
1957 "Max MED value to be used\n")
abc920f8 1958{
1ca2fd11
IR
1959 VTY_DECLVAR_CONTEXT(bgp, bgp);
1960
1961 /* Cancel max-med onstartup if its on */
1962 if (bgp->t_maxmed_onstartup) {
1963 thread_cancel(&bgp->t_maxmed_onstartup);
1964 bgp->maxmed_onstartup_over = 1;
1965 }
abc920f8 1966
1ca2fd11
IR
1967 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1968 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1969
1ca2fd11
IR
1970 bgp_maxmed_update(bgp);
1971
1972 return CMD_SUCCESS;
abc920f8
DS
1973}
1974
d70583f7
D
1975static int bgp_global_update_delay_config_vty(struct vty *vty,
1976 uint16_t update_delay,
1977 uint16_t establish_wait)
1978{
1979 struct listnode *node, *nnode;
1980 struct bgp *bgp;
1981 bool vrf_cfg = false;
1982
1983 /*
1984 * See if update-delay is set per-vrf and warn user to delete it
1985 * Note that we only need to check this if this is the first time
1986 * setting the global config.
1987 */
1988 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1989 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1990 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1991 vty_out(vty,
1992 "%% update-delay configuration found in vrf %s\n",
1993 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1994 ? VRF_DEFAULT_NAME
1995 : bgp->name);
1996 vrf_cfg = true;
1997 }
1998 }
1999 }
2000
2001 if (vrf_cfg) {
2002 vty_out(vty,
2003 "%%Failed: global update-delay config not permitted\n");
2004 return CMD_WARNING;
2005 }
2006
2007 if (!establish_wait) { /* update-delay <delay> */
2008 bm->v_update_delay = update_delay;
2009 bm->v_establish_wait = bm->v_update_delay;
2010 } else {
2011 /* update-delay <delay> <establish-wait> */
2012 if (update_delay < establish_wait) {
2013 vty_out(vty,
2014 "%%Failed: update-delay less than the establish-wait!\n");
2015 return CMD_WARNING_CONFIG_FAILED;
2016 }
2017
2018 bm->v_update_delay = update_delay;
2019 bm->v_establish_wait = establish_wait;
2020 }
2021
2022 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2023 bgp->v_update_delay = bm->v_update_delay;
2024 bgp->v_establish_wait = bm->v_establish_wait;
2025 }
2026
2027 return CMD_SUCCESS;
2028}
2029
2030static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2031{
2032 struct listnode *node, *nnode;
2033 struct bgp *bgp;
2034
2035 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2036 bm->v_establish_wait = bm->v_update_delay;
2037
2038 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2039 bgp->v_update_delay = bm->v_update_delay;
2040 bgp->v_establish_wait = bm->v_establish_wait;
2041 }
2042
2043 return CMD_SUCCESS;
2044}
2045
2046static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2047 uint16_t establish_wait)
f188f2c4 2048{
d62a17ae 2049 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2050
d70583f7
D
2051 /* if configured globally, per-instance config is not allowed */
2052 if (bm->v_update_delay) {
2053 vty_out(vty,
2054 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2055 return CMD_WARNING_CONFIG_FAILED;
2056 }
2057
f188f2c4 2058
d70583f7 2059 if (!establish_wait) /* update-delay <delay> */
d62a17ae 2060 {
2061 bgp->v_update_delay = update_delay;
2062 bgp->v_establish_wait = bgp->v_update_delay;
2063 return CMD_SUCCESS;
2064 }
f188f2c4 2065
d62a17ae 2066 /* update-delay <delay> <establish-wait> */
d62a17ae 2067 if (update_delay < establish_wait) {
2068 vty_out(vty,
2069 "%%Failed: update-delay less than the establish-wait!\n");
2070 return CMD_WARNING_CONFIG_FAILED;
2071 }
f188f2c4 2072
d62a17ae 2073 bgp->v_update_delay = update_delay;
2074 bgp->v_establish_wait = establish_wait;
f188f2c4 2075
d62a17ae 2076 return CMD_SUCCESS;
f188f2c4
DS
2077}
2078
d62a17ae 2079static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2080{
d62a17ae 2081 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2082
d70583f7
D
2083 /* If configured globally, cannot remove from one bgp instance */
2084 if (bm->v_update_delay) {
2085 vty_out(vty,
2086 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2087 return CMD_WARNING_CONFIG_FAILED;
2088 }
d62a17ae 2089 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2090 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2091
d62a17ae 2092 return CMD_SUCCESS;
f188f2c4
DS
2093}
2094
2b791107 2095void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2096{
d70583f7
D
2097 /* If configured globally, no need to display per-instance value */
2098 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2099 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2100 if (bgp->v_update_delay != bgp->v_establish_wait)
2101 vty_out(vty, " %d", bgp->v_establish_wait);
2102 vty_out(vty, "\n");
2103 }
f188f2c4
DS
2104}
2105
d70583f7
D
2106/* Global update-delay configuration */
2107DEFPY (bgp_global_update_delay,
2108 bgp_global_update_delay_cmd,
2109 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2110 BGP_STR
2111 "Force initial delay for best-path and updates for all bgp instances\n"
2112 "Max delay in seconds\n"
2113 "Establish wait in seconds\n")
2114{
2115 return bgp_global_update_delay_config_vty(vty, delay, wait);
2116}
f188f2c4 2117
d70583f7
D
2118/* Global update-delay deconfiguration */
2119DEFPY (no_bgp_global_update_delay,
2120 no_bgp_global_update_delay_cmd,
2121 "no bgp update-delay [(0-3600) [(1-3600)]]",
2122 NO_STR
2123 BGP_STR
f188f2c4 2124 "Force initial delay for best-path and updates\n"
d70583f7
D
2125 "Max delay in seconds\n"
2126 "Establish wait in seconds\n")
f188f2c4 2127{
d70583f7 2128 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2129}
2130
d70583f7
D
2131/* Update-delay configuration */
2132
2133DEFPY (bgp_update_delay,
2134 bgp_update_delay_cmd,
2135 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2136 "Force initial delay for best-path and updates\n"
d70583f7
D
2137 "Max delay in seconds\n"
2138 "Establish wait in seconds\n")
f188f2c4 2139{
d70583f7 2140 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2141}
2142
2143/* Update-delay deconfiguration */
d70583f7 2144DEFPY (no_bgp_update_delay,
f188f2c4 2145 no_bgp_update_delay_cmd,
838758ac
DW
2146 "no update-delay [(0-3600) [(1-3600)]]",
2147 NO_STR
f188f2c4 2148 "Force initial delay for best-path and updates\n"
d70583f7
D
2149 "Max delay in seconds\n"
2150 "Establish wait in seconds\n")
f188f2c4 2151{
d62a17ae 2152 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2153}
2154
5e242b0d 2155
1ca2fd11
IR
2156static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2157 bool set)
cb1faec9 2158{
1ca2fd11
IR
2159 VTY_DECLVAR_CONTEXT(bgp, bgp);
2160
8fa7732f
QY
2161 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2162 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2163
2164 return CMD_SUCCESS;
2165}
2166
1ca2fd11
IR
2167static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2168 bool set)
555e09d4 2169{
1ca2fd11
IR
2170 VTY_DECLVAR_CONTEXT(bgp, bgp);
2171
8fa7732f
QY
2172 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2173 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2174
d62a17ae 2175 return CMD_SUCCESS;
cb1faec9
DS
2176}
2177
2b791107 2178void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2179{
555e09d4
QY
2180 uint32_t quanta =
2181 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2182 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2183 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2184}
2185
555e09d4
QY
2186void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2187{
2188 uint32_t quanta =
2189 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2190 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2191 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2192}
cb1faec9 2193
8fa7732f
QY
2194/* Packet quanta configuration
2195 *
2196 * XXX: The value set here controls the size of a stack buffer in the IO
2197 * thread. When changing these limits be careful to prevent stack overflow.
2198 *
2199 * Furthermore, the maximums used here should correspond to
2200 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2201 */
1ca2fd11
IR
2202DEFPY (bgp_wpkt_quanta,
2203 bgp_wpkt_quanta_cmd,
2204 "[no] write-quanta (1-64)$quanta",
2205 NO_STR
2206 "How many packets to write to peer socket per run\n"
2207 "Number of packets\n")
2208{
2209 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2210}
cb1faec9 2211
1ca2fd11
IR
2212DEFPY (bgp_rpkt_quanta,
2213 bgp_rpkt_quanta_cmd,
2214 "[no] read-quanta (1-10)$quanta",
2215 NO_STR
2216 "How many packets to read from peer socket per I/O cycle\n"
2217 "Number of packets\n")
2218{
2219 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
2220}
2221
2b791107 2222void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2223{
37a333fe 2224 if (!bgp->heuristic_coalesce)
d62a17ae 2225 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2226}
2227
4668a151 2228
1ca2fd11
IR
2229DEFUN (bgp_coalesce_time,
2230 bgp_coalesce_time_cmd,
2231 "coalesce-time (0-4294967295)",
2232 "Subgroup coalesce timer\n"
2233 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2234{
1ca2fd11 2235 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 2236
1ca2fd11 2237 int idx = 0;
d62a17ae 2238 argv_find(argv, argc, "(0-4294967295)", &idx);
1ca2fd11
IR
2239 bgp->heuristic_coalesce = false;
2240 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2241 return CMD_SUCCESS;
3f9c7369
DS
2242}
2243
1ca2fd11
IR
2244DEFUN (no_bgp_coalesce_time,
2245 no_bgp_coalesce_time_cmd,
2246 "no coalesce-time (0-4294967295)",
2247 NO_STR
2248 "Subgroup coalesce timer\n"
2249 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2250{
1ca2fd11 2251 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 2252
1ca2fd11
IR
2253 bgp->heuristic_coalesce = true;
2254 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2255 return CMD_SUCCESS;
3f9c7369
DS
2256}
2257
5e242b0d 2258/* Maximum-paths configuration */
585f1adc
IR
2259DEFUN (bgp_maxpaths,
2260 bgp_maxpaths_cmd,
2261 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2262 "Forward packets over multiple paths\n"
2263 "Number of paths\n")
5e242b0d 2264{
d62a17ae 2265 int idx_number = 1;
585f1adc
IR
2266 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2267 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
2268}
2269
d62a17ae 2270ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2271 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2272 "Forward packets over multiple paths\n"
2273 "Number of paths\n")
596c17ba 2274
585f1adc
IR
2275DEFUN (bgp_maxpaths_ibgp,
2276 bgp_maxpaths_ibgp_cmd,
2277 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2278 "Forward packets over multiple paths\n"
2279 "iBGP-multipath\n"
2280 "Number of paths\n")
165b5fff 2281{
d62a17ae 2282 int idx_number = 2;
585f1adc
IR
2283 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2284 argv[idx_number]->arg, 0, 1);
5e242b0d 2285}
165b5fff 2286
d62a17ae 2287ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2288 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2289 "Forward packets over multiple paths\n"
2290 "iBGP-multipath\n"
2291 "Number of paths\n")
596c17ba 2292
585f1adc
IR
2293DEFUN (bgp_maxpaths_ibgp_cluster,
2294 bgp_maxpaths_ibgp_cluster_cmd,
2295 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2296 "Forward packets over multiple paths\n"
2297 "iBGP-multipath\n"
2298 "Number of paths\n"
2299 "Match the cluster length\n")
5e242b0d 2300{
d62a17ae 2301 int idx_number = 2;
585f1adc
IR
2302 return bgp_maxpaths_config_vty(
2303 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
2304 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
2305}
2306
d62a17ae 2307ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2308 "maximum-paths ibgp " CMD_RANGE_STR(
2309 1, MULTIPATH_NUM) " equal-cluster-length",
2310 "Forward packets over multiple paths\n"
2311 "iBGP-multipath\n"
2312 "Number of paths\n"
2313 "Match the cluster length\n")
596c17ba 2314
585f1adc
IR
2315DEFUN (no_bgp_maxpaths,
2316 no_bgp_maxpaths_cmd,
2317 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2318 NO_STR
2319 "Forward packets over multiple paths\n"
2320 "Number of paths\n")
165b5fff 2321{
585f1adc 2322 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
2323}
2324
d62a17ae 2325ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2326 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2327 "Forward packets over multiple paths\n"
2328 "Number of paths\n")
596c17ba 2329
585f1adc
IR
2330DEFUN (no_bgp_maxpaths_ibgp,
2331 no_bgp_maxpaths_ibgp_cmd,
2332 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2333 NO_STR
2334 "Forward packets over multiple paths\n"
2335 "iBGP-multipath\n"
2336 "Number of paths\n"
2337 "Match the cluster length\n")
165b5fff 2338{
585f1adc 2339 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
2340}
2341
d62a17ae 2342ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2343 "no maximum-paths ibgp [" CMD_RANGE_STR(
2344 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2345 NO_STR
2346 "Forward packets over multiple paths\n"
2347 "iBGP-multipath\n"
2348 "Number of paths\n"
2349 "Match the cluster length\n")
596c17ba 2350
dd65f45e
DL
2351static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2352 afi_t afi, safi_t safi)
165b5fff 2353{
00908b7a 2354 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2355 vty_out(vty, " maximum-paths %d\n",
2356 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2357 }
165b5fff 2358
00908b7a 2359 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2360 vty_out(vty, " maximum-paths ibgp %d",
2361 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2362 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2363 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2364 vty_out(vty, " equal-cluster-length");
2365 vty_out(vty, "\n");
2366 }
165b5fff 2367}
6b0655a2 2368
718e3744 2369/* BGP timers. */
2370
1ca2fd11
IR
2371DEFUN (bgp_timers,
2372 bgp_timers_cmd,
2373 "timers bgp (0-65535) (0-65535)",
2374 "Adjust routing timers\n"
2375 "BGP timers\n"
2376 "Keepalive interval\n"
2377 "Holdtime\n")
718e3744 2378{
1ca2fd11 2379 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2380 int idx_number = 2;
2381 int idx_number_2 = 3;
1ca2fd11
IR
2382 unsigned long keepalive = 0;
2383 unsigned long holdtime = 0;
718e3744 2384
1ca2fd11
IR
2385 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2386 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 2387
1ca2fd11
IR
2388 /* Holdtime value check. */
2389 if (holdtime < 3 && holdtime != 0) {
2390 vty_out(vty,
2391 "%% hold time value must be either 0 or greater than 3\n");
2392 return CMD_WARNING_CONFIG_FAILED;
2393 }
718e3744 2394
1ca2fd11
IR
2395 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2396 BGP_DEFAULT_DELAYOPEN);
718e3744 2397
1ca2fd11 2398 return CMD_SUCCESS;
718e3744 2399}
2400
1ca2fd11
IR
2401DEFUN (no_bgp_timers,
2402 no_bgp_timers_cmd,
2403 "no timers bgp [(0-65535) (0-65535)]",
2404 NO_STR
2405 "Adjust routing timers\n"
2406 "BGP timers\n"
2407 "Keepalive interval\n"
2408 "Holdtime\n")
718e3744 2409{
1ca2fd11
IR
2410 VTY_DECLVAR_CONTEXT(bgp, bgp);
2411 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2412 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
ff8a8a7a 2413
1ca2fd11 2414 return CMD_SUCCESS;
718e3744 2415}
2416
b042667a
TI
2417/* BGP minimum holdtime. */
2418
2419DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2420 "bgp minimum-holdtime (1-65535)",
2421 "BGP specific commands\n"
2422 "BGP minimum holdtime\n"
2423 "Seconds\n")
2424{
2425 VTY_DECLVAR_CONTEXT(bgp, bgp);
2426 int idx_number = 2;
2427 unsigned long min_holdtime;
2428
2429 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2430
2431 bgp->default_min_holdtime = min_holdtime;
2432
2433 return CMD_SUCCESS;
2434}
2435
2436DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2437 "no bgp minimum-holdtime [(1-65535)]",
2438 NO_STR
2439 "BGP specific commands\n"
2440 "BGP minimum holdtime\n"
2441 "Seconds\n")
2442{
2443 VTY_DECLVAR_CONTEXT(bgp, bgp);
2444
2445 bgp->default_min_holdtime = 0;
2446
2447 return CMD_SUCCESS;
2448}
ff8a8a7a 2449
1ca2fd11
IR
2450DEFUN (bgp_client_to_client_reflection,
2451 bgp_client_to_client_reflection_cmd,
2452 "bgp client-to-client reflection",
e9273987 2453 BGP_STR
1ca2fd11
IR
2454 "Configure client to client route reflection\n"
2455 "reflection of routes allowed\n")
718e3744 2456{
1ca2fd11
IR
2457 VTY_DECLVAR_CONTEXT(bgp, bgp);
2458 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2459 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2460
1ca2fd11 2461 return CMD_SUCCESS;
718e3744 2462}
2463
1ca2fd11
IR
2464DEFUN (no_bgp_client_to_client_reflection,
2465 no_bgp_client_to_client_reflection_cmd,
2466 "no bgp client-to-client reflection",
2467 NO_STR
e9273987 2468 BGP_STR
1ca2fd11
IR
2469 "Configure client to client route reflection\n"
2470 "reflection of routes allowed\n")
718e3744 2471{
1ca2fd11
IR
2472 VTY_DECLVAR_CONTEXT(bgp, bgp);
2473 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2474 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2475
1ca2fd11 2476 return CMD_SUCCESS;
718e3744 2477}
2478
2479/* "bgp always-compare-med" configuration. */
1ca2fd11
IR
2480DEFUN (bgp_always_compare_med,
2481 bgp_always_compare_med_cmd,
2482 "bgp always-compare-med",
e9273987 2483 BGP_STR
1ca2fd11 2484 "Allow comparing MED from different neighbors\n")
718e3744 2485{
1ca2fd11
IR
2486 VTY_DECLVAR_CONTEXT(bgp, bgp);
2487 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2488 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2489
1ca2fd11 2490 return CMD_SUCCESS;
718e3744 2491}
2492
1ca2fd11
IR
2493DEFUN (no_bgp_always_compare_med,
2494 no_bgp_always_compare_med_cmd,
2495 "no bgp always-compare-med",
2496 NO_STR
e9273987 2497 BGP_STR
1ca2fd11 2498 "Allow comparing MED from different neighbors\n")
718e3744 2499{
1ca2fd11
IR
2500 VTY_DECLVAR_CONTEXT(bgp, bgp);
2501 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2502 bgp_recalculate_all_bestpaths(bgp);
6b0655a2 2503
1ca2fd11 2504 return CMD_SUCCESS;
2adac256
DA
2505}
2506
2adac256 2507
1ca2fd11
IR
2508DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2509 "bgp ebgp-requires-policy",
e9273987 2510 BGP_STR
1ca2fd11 2511 "Require in and out policy for eBGP peers (RFC8212)\n")
2adac256 2512{
1ca2fd11
IR
2513 VTY_DECLVAR_CONTEXT(bgp, bgp);
2514 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2515 return CMD_SUCCESS;
2adac256
DA
2516}
2517
1ca2fd11
IR
2518DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2519 "no bgp ebgp-requires-policy",
2520 NO_STR
e9273987 2521 BGP_STR
1ca2fd11 2522 "Require in and out policy for eBGP peers (RFC8212)\n")
ff8a8a7a 2523{
1ca2fd11
IR
2524 VTY_DECLVAR_CONTEXT(bgp, bgp);
2525 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2526 return CMD_SUCCESS;
ff8a8a7a 2527}
9dac9fc8 2528
1ca2fd11
IR
2529DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2530 "bgp suppress-duplicates",
e9273987 2531 BGP_STR
1ca2fd11 2532 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2533{
1ca2fd11
IR
2534 VTY_DECLVAR_CONTEXT(bgp, bgp);
2535 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2536 return CMD_SUCCESS;
9dac9fc8
DA
2537}
2538
1ca2fd11
IR
2539DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2540 "no bgp suppress-duplicates",
2541 NO_STR
e9273987 2542 BGP_STR
1ca2fd11 2543 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2544{
1ca2fd11
IR
2545 VTY_DECLVAR_CONTEXT(bgp, bgp);
2546 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2547 return CMD_SUCCESS;
9dac9fc8
DA
2548}
2549
fb29348a
DA
2550DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2551 "bgp reject-as-sets",
e9273987 2552 BGP_STR
fb29348a
DA
2553 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2554{
2555 VTY_DECLVAR_CONTEXT(bgp, bgp);
2556 struct listnode *node, *nnode;
2557 struct peer *peer;
2558
7f972cd8 2559 bgp->reject_as_sets = true;
fb29348a
DA
2560
2561 /* Reset existing BGP sessions to reject routes
2562 * with aspath containing AS_SET or AS_CONFED_SET.
2563 */
2564 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2565 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2566 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2567 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2568 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2569 }
2570 }
2571
2572 return CMD_SUCCESS;
2573}
2574
2575DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2576 "no bgp reject-as-sets",
2577 NO_STR
e9273987 2578 BGP_STR
fb29348a
DA
2579 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2580{
2581 VTY_DECLVAR_CONTEXT(bgp, bgp);
2582 struct listnode *node, *nnode;
2583 struct peer *peer;
2584
7f972cd8 2585 bgp->reject_as_sets = false;
fb29348a
DA
2586
2587 /* Reset existing BGP sessions to reject routes
2588 * with aspath containing AS_SET or AS_CONFED_SET.
2589 */
2590 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2591 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2592 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2593 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2594 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2595 }
2596 }
2597
2598 return CMD_SUCCESS;
2599}
9dac9fc8 2600
718e3744 2601/* "bgp deterministic-med" configuration. */
1ca2fd11 2602DEFUN (bgp_deterministic_med,
718e3744 2603 bgp_deterministic_med_cmd,
2604 "bgp deterministic-med",
e9273987 2605 BGP_STR
718e3744 2606 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2607{
1ca2fd11
IR
2608 VTY_DECLVAR_CONTEXT(bgp, bgp);
2609
2610 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2611 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2612 bgp_recalculate_all_bestpaths(bgp);
2613 }
7aafcaca 2614
1ca2fd11 2615 return CMD_SUCCESS;
718e3744 2616}
2617
1ca2fd11 2618DEFUN (no_bgp_deterministic_med,
718e3744 2619 no_bgp_deterministic_med_cmd,
2620 "no bgp deterministic-med",
2621 NO_STR
e9273987 2622 BGP_STR
718e3744 2623 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2624{
1ca2fd11
IR
2625 VTY_DECLVAR_CONTEXT(bgp, bgp);
2626 int bestpath_per_as_used;
2627 afi_t afi;
2628 safi_t safi;
2629 struct peer *peer;
2630 struct listnode *node, *nnode;
2631
2632 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2633 bestpath_per_as_used = 0;
2634
2635 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2636 FOREACH_AFI_SAFI (afi, safi)
2637 if (bgp_addpath_dmed_required(
2638 peer->addpath_type[afi][safi])) {
2639 bestpath_per_as_used = 1;
2640 break;
2641 }
2642
2643 if (bestpath_per_as_used)
2644 break;
2645 }
2646
2647 if (bestpath_per_as_used) {
2648 vty_out(vty,
2649 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2650 return CMD_WARNING_CONFIG_FAILED;
2651 } else {
2652 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2653 bgp_recalculate_all_bestpaths(bgp);
2654 }
2655 }
d62a17ae 2656
1ca2fd11 2657 return CMD_SUCCESS;
718e3744 2658}
538621f2 2659
055679e9 2660/* "bgp graceful-restart mode" configuration. */
538621f2 2661DEFUN (bgp_graceful_restart,
2ba1fe69 2662 bgp_graceful_restart_cmd,
2663 "bgp graceful-restart",
e9273987 2664 BGP_STR
2ba1fe69 2665 GR_CMD
055679e9 2666 )
538621f2 2667{
055679e9 2668 int ret = BGP_GR_FAILURE;
2669
2670 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2671 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2672
d62a17ae 2673 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2674
2675 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2676
36235319
QY
2677 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2678 ret);
5cce3f05 2679
055679e9 2680 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2681 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2682 vty_out(vty,
2683 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2684 return bgp_vty_return(vty, ret);
538621f2 2685}
2686
2687DEFUN (no_bgp_graceful_restart,
2ba1fe69 2688 no_bgp_graceful_restart_cmd,
2689 "no bgp graceful-restart",
2690 NO_STR
e9273987 2691 BGP_STR
2ba1fe69 2692 NO_GR_CMD
055679e9 2693 )
538621f2 2694{
d62a17ae 2695 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2696
2697 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2698 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2699
2700 int ret = BGP_GR_FAILURE;
2701
2702 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2703
36235319
QY
2704 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2705 ret);
5cce3f05 2706
055679e9 2707 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2708 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2709 vty_out(vty,
2710 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2711
2712 return bgp_vty_return(vty, ret);
538621f2 2713}
2714
93406d87 2715DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2716 bgp_graceful_restart_stalepath_time_cmd,
2717 "bgp graceful-restart stalepath-time (1-4095)",
e9273987 2718 BGP_STR
2ba1fe69 2719 "Graceful restart capability parameters\n"
2720 "Set the max time to hold onto restarting peer's stale paths\n"
2721 "Delay value (seconds)\n")
93406d87 2722{
d62a17ae 2723 VTY_DECLVAR_CONTEXT(bgp, bgp);
2724 int idx_number = 3;
d7c0a89a 2725 uint32_t stalepath;
93406d87 2726
d62a17ae 2727 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2728 bgp->stalepath_time = stalepath;
2729 return CMD_SUCCESS;
93406d87 2730}
2731
eb6f1b41 2732DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2733 bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2734 "bgp graceful-restart restart-time (0-4095)",
e9273987 2735 BGP_STR
2ba1fe69 2736 "Graceful restart capability parameters\n"
2737 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2738 "Delay value (seconds)\n")
eb6f1b41 2739{
d62a17ae 2740 VTY_DECLVAR_CONTEXT(bgp, bgp);
2741 int idx_number = 3;
d7c0a89a 2742 uint32_t restart;
eb6f1b41 2743
d62a17ae 2744 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2745 bgp->restart_time = restart;
2746 return CMD_SUCCESS;
eb6f1b41
PG
2747}
2748
cfd47646 2749DEFUN (bgp_graceful_restart_select_defer_time,
2750 bgp_graceful_restart_select_defer_time_cmd,
2751 "bgp graceful-restart select-defer-time (0-3600)",
e9273987 2752 BGP_STR
cfd47646 2753 "Graceful restart capability parameters\n"
2754 "Set the time to defer the BGP route selection after restart\n"
2755 "Delay value (seconds, 0 - disable)\n")
2756{
2757 VTY_DECLVAR_CONTEXT(bgp, bgp);
2758 int idx_number = 3;
2759 uint32_t defer_time;
2760
2761 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2762 bgp->select_defer_time = defer_time;
2763 if (defer_time == 0)
892fedb6 2764 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2765 else
892fedb6 2766 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2767
2768 return CMD_SUCCESS;
2769}
2770
93406d87 2771DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2772 no_bgp_graceful_restart_stalepath_time_cmd,
2773 "no bgp graceful-restart stalepath-time [(1-4095)]",
2774 NO_STR
e9273987 2775 BGP_STR
2ba1fe69 2776 "Graceful restart capability parameters\n"
2777 "Set the max time to hold onto restarting peer's stale paths\n"
2778 "Delay value (seconds)\n")
93406d87 2779{
d62a17ae 2780 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2781
d62a17ae 2782 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2783 return CMD_SUCCESS;
93406d87 2784}
2785
eb6f1b41 2786DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2787 no_bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2788 "no bgp graceful-restart restart-time [(0-4095)]",
2ba1fe69 2789 NO_STR
e9273987 2790 BGP_STR
2ba1fe69 2791 "Graceful restart capability parameters\n"
2792 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2793 "Delay value (seconds)\n")
eb6f1b41 2794{
d62a17ae 2795 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2796
d62a17ae 2797 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2798 return CMD_SUCCESS;
eb6f1b41
PG
2799}
2800
cfd47646 2801DEFUN (no_bgp_graceful_restart_select_defer_time,
2802 no_bgp_graceful_restart_select_defer_time_cmd,
2803 "no bgp graceful-restart select-defer-time [(0-3600)]",
2804 NO_STR
e9273987 2805 BGP_STR
cfd47646 2806 "Graceful restart capability parameters\n"
2807 "Set the time to defer the BGP route selection after restart\n"
2808 "Delay value (seconds)\n")
2809{
2810 VTY_DECLVAR_CONTEXT(bgp, bgp);
2811
2812 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2813 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2814
2815 return CMD_SUCCESS;
2816}
2817
43fc21b3 2818DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2819 bgp_graceful_restart_preserve_fw_cmd,
2820 "bgp graceful-restart preserve-fw-state",
e9273987 2821 BGP_STR
2ba1fe69 2822 "Graceful restart capability parameters\n"
2823 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2824{
d62a17ae 2825 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2826 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2827 return CMD_SUCCESS;
43fc21b3
JC
2828}
2829
2830DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2831 no_bgp_graceful_restart_preserve_fw_cmd,
2832 "no bgp graceful-restart preserve-fw-state",
2833 NO_STR
e9273987 2834 BGP_STR
2ba1fe69 2835 "Graceful restart capability parameters\n"
2836 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2837{
d62a17ae 2838 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2839 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2840 return CMD_SUCCESS;
43fc21b3
JC
2841}
2842
055679e9 2843DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2844 bgp_graceful_restart_disable_cmd,
2845 "bgp graceful-restart-disable",
e9273987 2846 BGP_STR
2ba1fe69 2847 GR_DISABLE)
055679e9 2848{
2849 int ret = BGP_GR_FAILURE;
2850
2851 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2852 zlog_debug(
2ba1fe69 2853 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2854
055679e9 2855 VTY_DECLVAR_CONTEXT(bgp, bgp);
2856
2857 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2858
dc95985f 2859 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2860 bgp->peer, ret);
5cce3f05 2861
055679e9 2862 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2863 zlog_debug(
2ba1fe69 2864 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2865 vty_out(vty,
2866 "Graceful restart configuration changed, reset all peers to take effect\n");
2867
055679e9 2868 return bgp_vty_return(vty, ret);
2869}
2870
2871DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2872 no_bgp_graceful_restart_disable_cmd,
2873 "no bgp graceful-restart-disable",
2874 NO_STR
e9273987 2875 BGP_STR
2ba1fe69 2876 NO_GR_DISABLE
055679e9 2877 )
2878{
2879 VTY_DECLVAR_CONTEXT(bgp, bgp);
2880
2881 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2882 zlog_debug(
2ba1fe69 2883 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2884
2885 int ret = BGP_GR_FAILURE;
2886
2887 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2888
36235319
QY
2889 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2890 ret);
5cce3f05 2891
055679e9 2892 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2893 zlog_debug(
2ba1fe69 2894 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2895 vty_out(vty,
2896 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2897
2898 return bgp_vty_return(vty, ret);
2899}
2900
2901DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2902 bgp_neighbor_graceful_restart_set_cmd,
2903 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2904 NEIGHBOR_STR
2905 NEIGHBOR_ADDR_STR2
2906 GR_NEIGHBOR_CMD
055679e9 2907 )
2908{
2909 int idx_peer = 1;
2910 struct peer *peer;
2911 int ret = BGP_GR_FAILURE;
2912
dc95985f 2913 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2914
055679e9 2915 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2916 zlog_debug(
2ba1fe69 2917 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2918
055679e9 2919 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2920 if (!peer)
2921 return CMD_WARNING_CONFIG_FAILED;
2922
2923 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2924
dc95985f 2925 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2926 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2927
2928 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2929 zlog_debug(
2ba1fe69 2930 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2931 vty_out(vty,
2932 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2933
2934 return bgp_vty_return(vty, ret);
2935}
2936
2937DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 2938 no_bgp_neighbor_graceful_restart_set_cmd,
2939 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2940 NO_STR
2941 NEIGHBOR_STR
2942 NEIGHBOR_ADDR_STR2
2943 NO_GR_NEIGHBOR_CMD
055679e9 2944 )
2945{
2946 int idx_peer = 2;
2947 int ret = BGP_GR_FAILURE;
2948 struct peer *peer;
2949
dc95985f 2950 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2951
055679e9 2952 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2953 if (!peer)
2954 return CMD_WARNING_CONFIG_FAILED;
2955
2956 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2957 zlog_debug(
2ba1fe69 2958 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 2959
2960 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2961
dc95985f 2962 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2963 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2964
2965 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2966 zlog_debug(
2ba1fe69 2967 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2968 vty_out(vty,
2969 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2970
2971 return bgp_vty_return(vty, ret);
2972}
2973
2974DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 2975 bgp_neighbor_graceful_restart_helper_set_cmd,
2976 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2977 NEIGHBOR_STR
2978 NEIGHBOR_ADDR_STR2
2979 GR_NEIGHBOR_HELPER_CMD
055679e9 2980 )
2981{
2982 int idx_peer = 1;
2983 struct peer *peer;
2984 int ret = BGP_GR_FAILURE;
2985
dc95985f 2986 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2987
055679e9 2988 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2989 zlog_debug(
2ba1fe69 2990 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 2991
055679e9 2992 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2993
055679e9 2994 if (!peer)
2995 return CMD_WARNING_CONFIG_FAILED;
2996
2997
2998 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 2999
dc95985f 3000 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3001 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 3002
055679e9 3003 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3004 zlog_debug(
2ba1fe69 3005 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3006 vty_out(vty,
3007 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3008
3009 return bgp_vty_return(vty, ret);
3010}
3011
3012DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3013 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3014 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3015 NO_STR
3016 NEIGHBOR_STR
3017 NEIGHBOR_ADDR_STR2
3018 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3019 )
3020{
3021 int idx_peer = 2;
3022 int ret = BGP_GR_FAILURE;
3023 struct peer *peer;
3024
dc95985f 3025 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3026
055679e9 3027 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3028 if (!peer)
3029 return CMD_WARNING_CONFIG_FAILED;
3030
3031 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3032 zlog_debug(
2ba1fe69 3033 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3034
36235319 3035 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3036
dc95985f 3037 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3038 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3039
3040 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3041 zlog_debug(
2ba1fe69 3042 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3043 vty_out(vty,
3044 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3045
3046 return bgp_vty_return(vty, ret);
3047}
3048
3049DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3050 bgp_neighbor_graceful_restart_disable_set_cmd,
3051 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3052 NEIGHBOR_STR
3053 NEIGHBOR_ADDR_STR2
3054 GR_NEIGHBOR_DISABLE_CMD
055679e9 3055 )
3056{
3057 int idx_peer = 1;
3058 struct peer *peer;
3059 int ret = BGP_GR_FAILURE;
3060
dc95985f 3061 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3062
055679e9 3063 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3064 zlog_debug(
2ba1fe69 3065 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3066
3067 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3068 if (!peer)
3069 return CMD_WARNING_CONFIG_FAILED;
3070
36235319 3071 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3072
3073 if (peer->bgp->t_startup)
3074 bgp_peer_gr_flags_update(peer);
3075
dc95985f 3076 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3077 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3078
055679e9 3079 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3080 zlog_debug(
2ba1fe69 3081 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3082 vty_out(vty,
3083 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3084
3085 return bgp_vty_return(vty, ret);
3086}
3087
3088DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3089 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3090 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3091 NO_STR
3092 NEIGHBOR_STR
3093 NEIGHBOR_ADDR_STR2
3094 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3095 )
3096{
3097 int idx_peer = 2;
3098 int ret = BGP_GR_FAILURE;
3099 struct peer *peer;
3100
dc95985f 3101 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3102
055679e9 3103 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3104 if (!peer)
3105 return CMD_WARNING_CONFIG_FAILED;
3106
3107 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3108 zlog_debug(
2ba1fe69 3109 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3110
3111 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3112
dc95985f 3113 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3114 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3115
3116 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3117 zlog_debug(
2ba1fe69 3118 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3119 vty_out(vty,
3120 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3121
3122 return bgp_vty_return(vty, ret);
3123}
3124
d6e3c15b 3125DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3126 bgp_graceful_restart_disable_eor_cmd,
3127 "bgp graceful-restart disable-eor",
e9273987 3128 BGP_STR
d6e3c15b 3129 "Graceful restart configuration parameters\n"
3130 "Disable EOR Check\n")
3131{
3132 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3133 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3134
d6e3c15b 3135 return CMD_SUCCESS;
3136}
3137
3138DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3139 no_bgp_graceful_restart_disable_eor_cmd,
3140 "no bgp graceful-restart disable-eor",
3141 NO_STR
e9273987 3142 BGP_STR
d6e3c15b 3143 "Graceful restart configuration parameters\n"
3144 "Disable EOR Check\n")
3145{
3146 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3147 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3148
3149 return CMD_SUCCESS;
3150}
3151
3152DEFUN (bgp_graceful_restart_rib_stale_time,
3153 bgp_graceful_restart_rib_stale_time_cmd,
3154 "bgp graceful-restart rib-stale-time (1-3600)",
e9273987 3155 BGP_STR
dc95985f 3156 "Graceful restart configuration parameters\n"
3157 "Specify the stale route removal timer in rib\n"
3158 "Delay value (seconds)\n")
3159{
3160 VTY_DECLVAR_CONTEXT(bgp, bgp);
3161 int idx_number = 3;
3162 uint32_t stale_time;
3163
3164 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3165 bgp->rib_stale_time = stale_time;
3166 /* Send the stale timer update message to RIB */
3167 if (bgp_zebra_stale_timer_update(bgp))
3168 return CMD_WARNING;
3169
3170 return CMD_SUCCESS;
3171}
3172
3173DEFUN (no_bgp_graceful_restart_rib_stale_time,
3174 no_bgp_graceful_restart_rib_stale_time_cmd,
3175 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3176 NO_STR
e9273987 3177 BGP_STR
dc95985f 3178 "Graceful restart configuration parameters\n"
3179 "Specify the stale route removal timer in rib\n"
3180 "Delay value (seconds)\n")
3181{
3182 VTY_DECLVAR_CONTEXT(bgp, bgp);
3183
3184 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3185 /* Send the stale timer update message to RIB */
3186 if (bgp_zebra_stale_timer_update(bgp))
3187 return CMD_WARNING;
3188
d6e3c15b 3189 return CMD_SUCCESS;
3190}
3191
8606be87 3192DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
7f8a9a24
DA
3193 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3194 BGP_STR
8606be87
DA
3195 "Enable Long-lived Graceful Restart\n"
3196 "Specifies maximum time to wait before purging long-lived stale routes\n"
3197 "Stale time value (seconds)\n")
3198{
3199 VTY_DECLVAR_CONTEXT(bgp, bgp);
3200
3201 uint32_t llgr_stale_time;
3202
3203 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3204 bgp->llgr_stale_time = llgr_stale_time;
3205
3206 return CMD_SUCCESS;
3207}
3208
3209DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
7f8a9a24 3210 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
8606be87
DA
3211 NO_STR BGP_STR
3212 "Enable Long-lived Graceful Restart\n"
3213 "Specifies maximum time to wait before purging long-lived stale routes\n"
3214 "Stale time value (seconds)\n")
3215{
3216 VTY_DECLVAR_CONTEXT(bgp, bgp);
3217
3218 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3219
3220 return CMD_SUCCESS;
3221}
3222
1ca2fd11
IR
3223static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3224 struct bgp *bgp)
05bd726c 3225{
3226 bgp_static_redo_import_check(bgp);
3227 bgp_redistribute_redo(bgp);
1ca2fd11
IR
3228 bgp_clear_star_soft_out(vty, bgp->name);
3229 bgp_clear_star_soft_in(vty, bgp->name);
05bd726c 3230}
3231
3232static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3233{
3234 struct listnode *node, *nnode;
3235 struct bgp *bgp;
3236 bool vrf_cfg = false;
3237
3238 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3239 return CMD_SUCCESS;
3240
3241 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3242 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3243 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3244 vty_out(vty,
3245 "%% graceful-shutdown configuration found in vrf %s\n",
3246 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3247 VRF_DEFAULT_NAME : bgp->name);
3248 vrf_cfg = true;
3249 }
3250 }
3251
3252 if (vrf_cfg) {
3253 vty_out(vty,
3254 "%%Failed: global graceful-shutdown not permitted\n");
3255 return CMD_WARNING;
3256 }
3257
3258 /* Set flag globally */
3259 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3260
3261 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3262 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3263 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3264
3265 return CMD_SUCCESS;
3266}
3267
3268static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3269{
3270 struct listnode *node, *nnode;
3271 struct bgp *bgp;
3272
3273 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3274 return CMD_SUCCESS;
3275
3276 /* Unset flag globally */
3277 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3278
3279 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3280 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3281 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3282
3283 return CMD_SUCCESS;
3284}
3285
7f323236
DW
3286/* "bgp graceful-shutdown" configuration */
3287DEFUN (bgp_graceful_shutdown,
3288 bgp_graceful_shutdown_cmd,
3289 "bgp graceful-shutdown",
3290 BGP_STR
3291 "Graceful shutdown parameters\n")
3292{
05bd726c 3293 if (vty->node == CONFIG_NODE)
3294 return bgp_global_graceful_shutdown_config_vty(vty);
3295
1ca2fd11 3296 VTY_DECLVAR_CONTEXT(bgp, bgp);
7f323236 3297
1ca2fd11
IR
3298 /* if configured globally, per-instance config is not allowed */
3299 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3300 vty_out(vty,
3301 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3302 return CMD_WARNING_CONFIG_FAILED;
3303 }
3304
3305 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3306 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3307 bgp_initiate_graceful_shut_unshut(vty, bgp);
3308 }
3309
3310 return CMD_SUCCESS;
7f323236
DW
3311}
3312
1ca2fd11 3313DEFUN (no_bgp_graceful_shutdown,
7f323236
DW
3314 no_bgp_graceful_shutdown_cmd,
3315 "no bgp graceful-shutdown",
3316 NO_STR
3317 BGP_STR
3318 "Graceful shutdown parameters\n")
3319{
05bd726c 3320 if (vty->node == CONFIG_NODE)
3321 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3322
1ca2fd11 3323 VTY_DECLVAR_CONTEXT(bgp, bgp);
05bd726c 3324
1ca2fd11
IR
3325 /* If configured globally, cannot remove from one bgp instance */
3326 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3327 vty_out(vty,
3328 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3329 return CMD_WARNING_CONFIG_FAILED;
3330 }
7f323236 3331
1ca2fd11
IR
3332 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3333 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3334 bgp_initiate_graceful_shut_unshut(vty, bgp);
3335 }
3336
3337 return CMD_SUCCESS;
7f323236
DW
3338}
3339
718e3744 3340/* "bgp fast-external-failover" configuration. */
1ca2fd11 3341DEFUN (bgp_fast_external_failover,
718e3744 3342 bgp_fast_external_failover_cmd,
3343 "bgp fast-external-failover",
3344 BGP_STR
3345 "Immediately reset session if a link to a directly connected external peer goes down\n")
3346{
1ca2fd11
IR
3347 VTY_DECLVAR_CONTEXT(bgp, bgp);
3348 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3349 return CMD_SUCCESS;
718e3744 3350}
3351
1ca2fd11 3352DEFUN (no_bgp_fast_external_failover,
718e3744 3353 no_bgp_fast_external_failover_cmd,
3354 "no bgp fast-external-failover",
3355 NO_STR
3356 BGP_STR
3357 "Immediately reset session if a link to a directly connected external peer goes down\n")
3358{
1ca2fd11
IR
3359 VTY_DECLVAR_CONTEXT(bgp, bgp);
3360 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3361 return CMD_SUCCESS;
718e3744 3362}
6b0655a2 3363
718e3744 3364/* "bgp bestpath compare-routerid" configuration. */
1ca2fd11
IR
3365DEFUN (bgp_bestpath_compare_router_id,
3366 bgp_bestpath_compare_router_id_cmd,
3367 "bgp bestpath compare-routerid",
e9273987 3368 BGP_STR
1ca2fd11
IR
3369 "Change the default bestpath selection\n"
3370 "Compare router-id for identical EBGP paths\n")
718e3744 3371{
1ca2fd11
IR
3372 VTY_DECLVAR_CONTEXT(bgp, bgp);
3373 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3374 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3375
1ca2fd11 3376 return CMD_SUCCESS;
718e3744 3377}
3378
1ca2fd11
IR
3379DEFUN (no_bgp_bestpath_compare_router_id,
3380 no_bgp_bestpath_compare_router_id_cmd,
3381 "no bgp bestpath compare-routerid",
3382 NO_STR
e9273987 3383 BGP_STR
1ca2fd11
IR
3384 "Change the default bestpath selection\n"
3385 "Compare router-id for identical EBGP paths\n")
718e3744 3386{
1ca2fd11
IR
3387 VTY_DECLVAR_CONTEXT(bgp, bgp);
3388 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3389 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3390
1ca2fd11 3391 return CMD_SUCCESS;
718e3744 3392}
6b0655a2 3393
718e3744 3394/* "bgp bestpath as-path ignore" configuration. */
1ca2fd11
IR
3395DEFUN (bgp_bestpath_aspath_ignore,
3396 bgp_bestpath_aspath_ignore_cmd,
3397 "bgp bestpath as-path ignore",
e9273987 3398 BGP_STR
1ca2fd11
IR
3399 "Change the default bestpath selection\n"
3400 "AS-path attribute\n"
3401 "Ignore as-path length in selecting a route\n")
718e3744 3402{
1ca2fd11
IR
3403 VTY_DECLVAR_CONTEXT(bgp, bgp);
3404 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3405 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3406
1ca2fd11 3407 return CMD_SUCCESS;
718e3744 3408}
3409
1ca2fd11
IR
3410DEFUN (no_bgp_bestpath_aspath_ignore,
3411 no_bgp_bestpath_aspath_ignore_cmd,
3412 "no bgp bestpath as-path ignore",
3413 NO_STR
e9273987 3414 BGP_STR
1ca2fd11
IR
3415 "Change the default bestpath selection\n"
3416 "AS-path attribute\n"
3417 "Ignore as-path length in selecting a route\n")
718e3744 3418{
1ca2fd11
IR
3419 VTY_DECLVAR_CONTEXT(bgp, bgp);
3420 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3421 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3422
1ca2fd11 3423 return CMD_SUCCESS;
718e3744 3424}
6b0655a2 3425
6811845b 3426/* "bgp bestpath as-path confed" configuration. */
1ca2fd11 3427DEFUN (bgp_bestpath_aspath_confed,
6811845b 3428 bgp_bestpath_aspath_confed_cmd,
3429 "bgp bestpath as-path confed",
e9273987 3430 BGP_STR
6811845b 3431 "Change the default bestpath selection\n"
3432 "AS-path attribute\n"
3433 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3434{
1ca2fd11
IR
3435 VTY_DECLVAR_CONTEXT(bgp, bgp);
3436 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3437 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3438
1ca2fd11 3439 return CMD_SUCCESS;
6811845b 3440}
3441
1ca2fd11 3442DEFUN (no_bgp_bestpath_aspath_confed,
6811845b 3443 no_bgp_bestpath_aspath_confed_cmd,
3444 "no bgp bestpath as-path confed",
3445 NO_STR
e9273987 3446 BGP_STR
6811845b 3447 "Change the default bestpath selection\n"
3448 "AS-path attribute\n"
3449 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3450{
1ca2fd11
IR
3451 VTY_DECLVAR_CONTEXT(bgp, bgp);
3452 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3453 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3454
1ca2fd11 3455 return CMD_SUCCESS;
6811845b 3456}
6b0655a2 3457
2fdd455c 3458/* "bgp bestpath as-path multipath-relax" configuration. */
1ca2fd11 3459DEFUN (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3460 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3461 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
e9273987 3462 BGP_STR
16fc1eec
DS
3463 "Change the default bestpath selection\n"
3464 "AS-path attribute\n"
3465 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3466 "Generate an AS_SET\n"
16fc1eec
DS
3467 "Do not generate an AS_SET\n")
3468{
1ca2fd11 3469 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3470 int idx = 0;
1ca2fd11 3471 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 3472
1ca2fd11
IR
3473 /* no-as-set is now the default behavior so we can silently
3474 * ignore it */
d62a17ae 3475 if (argv_find(argv, argc, "as-set", &idx))
1ca2fd11 3476 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 3477 else
1ca2fd11 3478 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
7aafcaca 3479
1ca2fd11
IR
3480 bgp_recalculate_all_bestpaths(bgp);
3481
3482 return CMD_SUCCESS;
16fc1eec
DS
3483}
3484
1ca2fd11 3485DEFUN (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3486 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3487 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec 3488 NO_STR
e9273987 3489 BGP_STR
16fc1eec
DS
3490 "Change the default bestpath selection\n"
3491 "AS-path attribute\n"
3492 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3493 "Generate an AS_SET\n"
16fc1eec
DS
3494 "Do not generate an AS_SET\n")
3495{
1ca2fd11
IR
3496 VTY_DECLVAR_CONTEXT(bgp, bgp);
3497 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3498 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3499 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3500
1ca2fd11 3501 return CMD_SUCCESS;
2fdd455c 3502}
6b0655a2 3503
ee88563a
JM
3504/* "bgp bestpath peer-type multipath-relax" configuration. */
3505DEFUN(bgp_bestpath_peer_type_multipath_relax,
3506 bgp_bestpath_peer_type_multipath_relax_cmd,
3507 "bgp bestpath peer-type multipath-relax",
3508 BGP_STR
3509 "Change the default bestpath selection\n"
3510 "Peer type\n"
3511 "Allow load sharing across routes learned from different peer types\n")
3512{
3513 VTY_DECLVAR_CONTEXT(bgp, bgp);
3514 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3515 bgp_recalculate_all_bestpaths(bgp);
3516
3517 return CMD_SUCCESS;
3518}
3519
3520DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3521 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3522 "no bgp bestpath peer-type multipath-relax",
3523 NO_STR BGP_STR
3524 "Change the default bestpath selection\n"
3525 "Peer type\n"
3526 "Allow load sharing across routes learned from different peer types\n")
3527{
3528 VTY_DECLVAR_CONTEXT(bgp, bgp);
3529 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3530 bgp_recalculate_all_bestpaths(bgp);
3531
3532 return CMD_SUCCESS;
3533}
3534
848973c7 3535/* "bgp log-neighbor-changes" configuration. */
1ca2fd11
IR
3536DEFUN (bgp_log_neighbor_changes,
3537 bgp_log_neighbor_changes_cmd,
3538 "bgp log-neighbor-changes",
e9273987 3539 BGP_STR
1ca2fd11 3540 "Log neighbor up/down and reset reason\n")
848973c7 3541{
1ca2fd11
IR
3542 VTY_DECLVAR_CONTEXT(bgp, bgp);
3543 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3544 return CMD_SUCCESS;
848973c7 3545}
3546
1ca2fd11
IR
3547DEFUN (no_bgp_log_neighbor_changes,
3548 no_bgp_log_neighbor_changes_cmd,
3549 "no bgp log-neighbor-changes",
3550 NO_STR
e9273987 3551 BGP_STR
1ca2fd11 3552 "Log neighbor up/down and reset reason\n")
848973c7 3553{
1ca2fd11
IR
3554 VTY_DECLVAR_CONTEXT(bgp, bgp);
3555 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3556 return CMD_SUCCESS;
848973c7 3557}
6b0655a2 3558
718e3744 3559/* "bgp bestpath med" configuration. */
1ca2fd11 3560DEFUN (bgp_bestpath_med,
718e3744 3561 bgp_bestpath_med_cmd,
2d8c1a4d 3562 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
e9273987 3563 BGP_STR
718e3744 3564 "Change the default bestpath selection\n"
3565 "MED attribute\n"
3566 "Compare MED among confederation paths\n"
838758ac
DW
3567 "Treat missing MED as the least preferred one\n"
3568 "Treat missing MED as the least preferred one\n"
3569 "Compare MED among confederation paths\n")
718e3744 3570{
1ca2fd11 3571 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3572
1ca2fd11 3573 int idx = 0;
d62a17ae 3574 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3575 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3576 idx = 0;
3577 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11 3578 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 3579
1ca2fd11 3580 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3581
1ca2fd11 3582 return CMD_SUCCESS;
718e3744 3583}
3584
1ca2fd11 3585DEFUN (no_bgp_bestpath_med,
718e3744 3586 no_bgp_bestpath_med_cmd,
2d8c1a4d 3587 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3588 NO_STR
e9273987 3589 BGP_STR
718e3744 3590 "Change the default bestpath selection\n"
3591 "MED attribute\n"
3592 "Compare MED among confederation paths\n"
3a2d747c
QY
3593 "Treat missing MED as the least preferred one\n"
3594 "Treat missing MED as the least preferred one\n"
3595 "Compare MED among confederation paths\n")
718e3744 3596{
1ca2fd11 3597 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3598
1ca2fd11 3599 int idx = 0;
d62a17ae 3600 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3601 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3602 idx = 0;
3603 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11
IR
3604 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3605
3606 bgp_recalculate_all_bestpaths(bgp);
718e3744 3607
1ca2fd11 3608 return CMD_SUCCESS;
718e3744 3609}
3610
f7e1c681 3611/* "bgp bestpath bandwidth" configuration. */
3612DEFPY (bgp_bestpath_bw,
3613 bgp_bestpath_bw_cmd,
ad36d216 3614 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
e9273987 3615 BGP_STR
f7e1c681 3616 "Change the default bestpath selection\n"
3617 "Link Bandwidth attribute\n"
3618 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3619 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3620 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3621{
3622 VTY_DECLVAR_CONTEXT(bgp, bgp);
3623 afi_t afi;
3624 safi_t safi;
3625
ad36d216
DS
3626 if (!bw_cfg) {
3627 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3628 return CMD_ERR_INCOMPLETE;
f7e1c681 3629 }
ad36d216
DS
3630 if (!strcmp(bw_cfg, "ignore"))
3631 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3632 else if (!strcmp(bw_cfg, "skip-missing"))
3633 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3634 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3635 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3636 else
3637 return CMD_ERR_NO_MATCH;
f7e1c681 3638
3639 /* This config is used in route install, so redo that. */
3640 FOREACH_AFI_SAFI (afi, safi) {
3641 if (!bgp_fibupd_safi(safi))
3642 continue;
3643 bgp_zebra_announce_table(bgp, afi, safi);
3644 }
3645
3646 return CMD_SUCCESS;
3647}
3648
ad36d216
DS
3649DEFPY (no_bgp_bestpath_bw,
3650 no_bgp_bestpath_bw_cmd,
3651 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3652 NO_STR
e9273987 3653 BGP_STR
ad36d216
DS
3654 "Change the default bestpath selection\n"
3655 "Link Bandwidth attribute\n"
3656 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3657 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3658 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3659{
3660 VTY_DECLVAR_CONTEXT(bgp, bgp);
3661 afi_t afi;
3662 safi_t safi;
3663
3664 bgp->lb_handling = BGP_LINK_BW_ECMP;
3665
3666 /* This config is used in route install, so redo that. */
3667 FOREACH_AFI_SAFI (afi, safi) {
3668 if (!bgp_fibupd_safi(safi))
3669 continue;
3670 bgp_zebra_announce_table(bgp, afi, safi);
3671 }
3672 return CMD_SUCCESS;
3673}
3674
b16bcbba 3675DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
38d11af5
TA
3676 "[no] bgp default <ipv4-unicast|"
3677 "ipv4-multicast|"
3678 "ipv4-vpn|"
3679 "ipv4-labeled-unicast|"
3680 "ipv4-flowspec|"
3681 "ipv6-unicast|"
3682 "ipv6-multicast|"
3683 "ipv6-vpn|"
3684 "ipv6-labeled-unicast|"
3685 "ipv6-flowspec|"
3686 "l2vpn-evpn>$afi_safi",
b16bcbba 3687 NO_STR
e9273987 3688 BGP_STR
e84c59af 3689 "Configure BGP defaults\n"
b16bcbba 3690 "Activate ipv4-unicast for a peer by default\n"
38d11af5
TA
3691 "Activate ipv4-multicast for a peer by default\n"
3692 "Activate ipv4-vpn for a peer by default\n"
3693 "Activate ipv4-labeled-unicast for a peer by default\n"
3694 "Activate ipv4-flowspec for a peer by default\n"
3695 "Activate ipv6-unicast for a peer by default\n"
3696 "Activate ipv6-multicast for a peer by default\n"
3697 "Activate ipv6-vpn for a peer by default\n"
3698 "Activate ipv6-labeled-unicast for a peer by default\n"
3699 "Activate ipv6-flowspec for a peer by default\n"
3700 "Activate l2vpn-evpn for a peer by default\n")
e84c59af
DA
3701{
3702 VTY_DECLVAR_CONTEXT(bgp, bgp);
b16bcbba
TA
3703 char afi_safi_str[strlen(afi_safi) + 1];
3704 char *afi_safi_str_tok;
e84c59af 3705
b16bcbba
TA
3706 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3707 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3708 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3709 afi_t afi = bgp_vty_afi_from_str(afi_str);
38d11af5 3710 safi_t safi;
e84c59af 3711
38d11af5
TA
3712 if (strmatch(safi_str, "labeled"))
3713 safi = bgp_vty_safi_from_str("labeled-unicast");
3714 else
3715 safi = bgp_vty_safi_from_str(safi_str);
b16bcbba
TA
3716
3717 if (no)
3718 bgp->default_af[afi][safi] = false;
38d11af5
TA
3719 else {
3720 if ((safi == SAFI_LABELED_UNICAST
3721 && bgp->default_af[afi][SAFI_UNICAST])
3722 || (safi == SAFI_UNICAST
3723 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3724 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3725 else
3726 bgp->default_af[afi][safi] = true;
3727 }
718e3744 3728
d62a17ae 3729 return CMD_SUCCESS;
718e3744 3730}
6b0655a2 3731
04b6bdc0 3732/* Display hostname in certain command outputs */
1ca2fd11 3733DEFUN (bgp_default_show_hostname,
04b6bdc0
DW
3734 bgp_default_show_hostname_cmd,
3735 "bgp default show-hostname",
e9273987 3736 BGP_STR
04b6bdc0 3737 "Configure BGP defaults\n"
0437e105 3738 "Show hostname in certain command outputs\n")
04b6bdc0 3739{
1ca2fd11
IR
3740 VTY_DECLVAR_CONTEXT(bgp, bgp);
3741 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3742 return CMD_SUCCESS;
ff8a8a7a
CS
3743}
3744
1ca2fd11
IR
3745DEFUN (no_bgp_default_show_hostname,
3746 no_bgp_default_show_hostname_cmd,
3747 "no bgp default show-hostname",
3748 NO_STR
e9273987 3749 BGP_STR
1ca2fd11
IR
3750 "Configure BGP defaults\n"
3751 "Show hostname in certain command outputs\n")
ff8a8a7a 3752{
1ca2fd11
IR
3753 VTY_DECLVAR_CONTEXT(bgp, bgp);
3754 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3755 return CMD_SUCCESS;
04b6bdc0
DW
3756}
3757
aef999a2 3758/* Display hostname in certain command outputs */
1d80f243
IR
3759DEFUN (bgp_default_show_nexthop_hostname,
3760 bgp_default_show_nexthop_hostname_cmd,
3761 "bgp default show-nexthop-hostname",
e9273987 3762 BGP_STR
1d80f243
IR
3763 "Configure BGP defaults\n"
3764 "Show hostname for nexthop in certain command outputs\n")
aef999a2 3765{
1ca2fd11
IR
3766 VTY_DECLVAR_CONTEXT(bgp, bgp);
3767 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3768 return CMD_SUCCESS;
aef999a2
DA
3769}
3770
3771DEFUN (no_bgp_default_show_nexthop_hostname,
3772 no_bgp_default_show_nexthop_hostname_cmd,
3773 "no bgp default show-nexthop-hostname",
3774 NO_STR
e9273987 3775 BGP_STR
aef999a2
DA
3776 "Configure BGP defaults\n"
3777 "Show hostname for nexthop in certain command outputs\n")
3778{
1ca2fd11
IR
3779 VTY_DECLVAR_CONTEXT(bgp, bgp);
3780 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3781 return CMD_SUCCESS;
aef999a2
DA
3782}
3783
8233ef81 3784/* "bgp network import-check" configuration. */
1ca2fd11
IR
3785DEFUN (bgp_network_import_check,
3786 bgp_network_import_check_cmd,
3787 "bgp network import-check",
e9273987 3788 BGP_STR
1ca2fd11
IR
3789 "BGP network command\n"
3790 "Check BGP network route exists in IGP\n")
718e3744 3791{
1ca2fd11
IR
3792 VTY_DECLVAR_CONTEXT(bgp, bgp);
3793 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3794 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3795 bgp_static_redo_import_check(bgp);
3796 }
078430f6 3797
1ca2fd11 3798 return CMD_SUCCESS;
718e3744 3799}
3800
d62a17ae 3801ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3802 "bgp network import-check exact",
e9273987 3803 BGP_STR
d62a17ae 3804 "BGP network command\n"
3805 "Check BGP network route exists in IGP\n"
3806 "Match route precisely\n")
8233ef81 3807
1ca2fd11
IR
3808DEFUN (no_bgp_network_import_check,
3809 no_bgp_network_import_check_cmd,
3810 "no bgp network import-check",
3811 NO_STR
e9273987 3812 BGP_STR
1ca2fd11
IR
3813 "BGP network command\n"
3814 "Check BGP network route exists in IGP\n")
718e3744 3815{
1ca2fd11
IR
3816 VTY_DECLVAR_CONTEXT(bgp, bgp);
3817 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3818 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3819 bgp_static_redo_import_check(bgp);
3820 }
6b0655a2 3821
1ca2fd11 3822 return CMD_SUCCESS;
ff8a8a7a 3823}
718e3744 3824
1ca2fd11
IR
3825DEFUN (bgp_default_local_preference,
3826 bgp_default_local_preference_cmd,
3827 "bgp default local-preference (0-4294967295)",
e9273987 3828 BGP_STR
1ca2fd11
IR
3829 "Configure BGP defaults\n"
3830 "local preference (higher=more preferred)\n"
3831 "Configure default local preference value\n")
ff8a8a7a 3832{
1ca2fd11 3833 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3834 int idx_number = 3;
1ca2fd11 3835 uint32_t local_pref;
718e3744 3836
1ca2fd11 3837 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 3838
1ca2fd11
IR
3839 bgp_default_local_preference_set(bgp, local_pref);
3840 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 3841
1ca2fd11 3842 return CMD_SUCCESS;
718e3744 3843}
3844
1ca2fd11
IR
3845DEFUN (no_bgp_default_local_preference,
3846 no_bgp_default_local_preference_cmd,
3847 "no bgp default local-preference [(0-4294967295)]",
3848 NO_STR
e9273987 3849 BGP_STR
1ca2fd11
IR
3850 "Configure BGP defaults\n"
3851 "local preference (higher=more preferred)\n"
3852 "Configure default local preference value\n")
ff8a8a7a 3853{
1ca2fd11
IR
3854 VTY_DECLVAR_CONTEXT(bgp, bgp);
3855 bgp_default_local_preference_unset(bgp);
3856 bgp_clear_star_soft_in(vty, bgp->name);
3857
3858 return CMD_SUCCESS;
ff8a8a7a 3859}
6b0655a2 3860
ff8a8a7a 3861
1ca2fd11
IR
3862DEFUN (bgp_default_subgroup_pkt_queue_max,
3863 bgp_default_subgroup_pkt_queue_max_cmd,
3864 "bgp default subgroup-pkt-queue-max (20-100)",
e9273987 3865 BGP_STR
1ca2fd11
IR
3866 "Configure BGP defaults\n"
3867 "subgroup-pkt-queue-max\n"
3868 "Configure subgroup packet queue max\n")
8bd9d948 3869{
1ca2fd11 3870 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3871 int idx_number = 3;
1ca2fd11 3872 uint32_t max_size;
3f9c7369 3873
1ca2fd11 3874 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 3875
1ca2fd11 3876 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
ff8a8a7a 3877
1ca2fd11 3878 return CMD_SUCCESS;
8bd9d948
DS
3879}
3880
1ca2fd11
IR
3881DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3882 no_bgp_default_subgroup_pkt_queue_max_cmd,
3883 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3884 NO_STR
e9273987 3885 BGP_STR
1ca2fd11
IR
3886 "Configure BGP defaults\n"
3887 "subgroup-pkt-queue-max\n"
3888 "Configure subgroup packet queue max\n")
ff8a8a7a 3889{
1ca2fd11
IR
3890 VTY_DECLVAR_CONTEXT(bgp, bgp);
3891 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3892 return CMD_SUCCESS;
ff8a8a7a 3893}
813d4307 3894
8bd9d948 3895
1ca2fd11
IR
3896DEFUN (bgp_rr_allow_outbound_policy,
3897 bgp_rr_allow_outbound_policy_cmd,
3898 "bgp route-reflector allow-outbound-policy",
e9273987 3899 BGP_STR
1ca2fd11
IR
3900 "Allow modifications made by out route-map\n"
3901 "on ibgp neighbors\n")
ff8a8a7a 3902{
1ca2fd11 3903 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3904
1ca2fd11
IR
3905 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3906 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3907 update_group_announce_rrclients(bgp);
3908 bgp_clear_star_soft_out(vty, bgp->name);
3909 }
8bd9d948 3910
1ca2fd11
IR
3911 return CMD_SUCCESS;
3912}
ff8a8a7a 3913
1ca2fd11
IR
3914DEFUN (no_bgp_rr_allow_outbound_policy,
3915 no_bgp_rr_allow_outbound_policy_cmd,
3916 "no bgp route-reflector allow-outbound-policy",
3917 NO_STR
e9273987 3918 BGP_STR
1ca2fd11
IR
3919 "Allow modifications made by out route-map\n"
3920 "on ibgp neighbors\n")
8bd9d948 3921{
1ca2fd11 3922 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 3923
1ca2fd11
IR
3924 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3925 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3926 update_group_announce_rrclients(bgp);
3927 bgp_clear_star_soft_out(vty, bgp->name);
d62a17ae 3928 }
8bd9d948 3929
1ca2fd11 3930 return CMD_SUCCESS;
8bd9d948
DS
3931}
3932
1ca2fd11
IR
3933DEFUN (bgp_listen_limit,
3934 bgp_listen_limit_cmd,
3935 "bgp listen limit (1-65535)",
e9273987 3936 BGP_STR
1ca2fd11
IR
3937 "BGP Dynamic Neighbors listen commands\n"
3938 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3939 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3940{
1ca2fd11 3941 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3942 int idx_number = 3;
1ca2fd11
IR
3943 int listen_limit;
3944
3945 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 3946
1ca2fd11 3947 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 3948
1ca2fd11 3949 return CMD_SUCCESS;
f14e6fdb
DS
3950}
3951
1ca2fd11
IR
3952DEFUN (no_bgp_listen_limit,
3953 no_bgp_listen_limit_cmd,
3954 "no bgp listen limit [(1-65535)]",
3955 NO_STR
e9273987 3956 BGP_STR
1ca2fd11
IR
3957 "BGP Dynamic Neighbors listen commands\n"
3958 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3959 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3960{
1ca2fd11
IR
3961 VTY_DECLVAR_CONTEXT(bgp, bgp);
3962 bgp_listen_limit_unset(bgp);
3963 return CMD_SUCCESS;
f14e6fdb
DS
3964}
3965
3966
20eb8864 3967/*
3968 * Check if this listen range is already configured. Check for exact
3969 * match or overlap based on input.
3970 */
d62a17ae 3971static struct peer_group *listen_range_exists(struct bgp *bgp,
3972 struct prefix *range, int exact)
3973{
3974 struct listnode *node, *nnode;
3975 struct listnode *node1, *nnode1;
3976 struct peer_group *group;
3977 struct prefix *lr;
3978 afi_t afi;
3979 int match;
3980
3981 afi = family2afi(range->family);
3982 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3983 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3984 lr)) {
3985 if (exact)
3986 match = prefix_same(range, lr);
3987 else
3988 match = (prefix_match(range, lr)
3989 || prefix_match(lr, range));
3990 if (match)
3991 return group;
3992 }
3993 }
3994
3995 return NULL;
20eb8864 3996}
3997
f14e6fdb
DS
3998DEFUN (bgp_listen_range,
3999 bgp_listen_range_cmd,
d7b9898c 4000 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
e9273987 4001 BGP_STR
d7fa34c1
QY
4002 "Configure BGP dynamic neighbors listen range\n"
4003 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
4004 NEIGHBOR_ADDR_STR
4005 "Member of the peer-group\n"
4006 "Peer-group name\n")
f14e6fdb 4007{
d62a17ae 4008 VTY_DECLVAR_CONTEXT(bgp, bgp);
4009 struct prefix range;
4010 struct peer_group *group, *existing_group;
4011 afi_t afi;
4012 int ret;
4013 int idx = 0;
4014
4015 argv_find(argv, argc, "A.B.C.D/M", &idx);
4016 argv_find(argv, argc, "X:X::X:X/M", &idx);
4017 char *prefix = argv[idx]->arg;
d7b9898c 4018 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4019 char *peergroup = argv[idx]->arg;
4020
4021 /* Convert IP prefix string to struct prefix. */
4022 ret = str2prefix(prefix, &range);
4023 if (!ret) {
4024 vty_out(vty, "%% Malformed listen range\n");
4025 return CMD_WARNING_CONFIG_FAILED;
4026 }
4027
4028 afi = family2afi(range.family);
4029
4030 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4031 vty_out(vty,
4032 "%% Malformed listen range (link-local address)\n");
4033 return CMD_WARNING_CONFIG_FAILED;
4034 }
4035
4036 apply_mask(&range);
4037
4038 /* Check if same listen range is already configured. */
4039 existing_group = listen_range_exists(bgp, &range, 1);
4040 if (existing_group) {
4041 if (strcmp(existing_group->name, peergroup) == 0)
4042 return CMD_SUCCESS;
4043 else {
4044 vty_out(vty,
4045 "%% Same listen range is attached to peer-group %s\n",
4046 existing_group->name);
4047 return CMD_WARNING_CONFIG_FAILED;
4048 }
4049 }
4050
4051 /* Check if an overlapping listen range exists. */
4052 if (listen_range_exists(bgp, &range, 0)) {
4053 vty_out(vty,
4054 "%% Listen range overlaps with existing listen range\n");
4055 return CMD_WARNING_CONFIG_FAILED;
4056 }
4057
4058 group = peer_group_lookup(bgp, peergroup);
4059 if (!group) {
4060 vty_out(vty, "%% Configure the peer-group first\n");
4061 return CMD_WARNING_CONFIG_FAILED;
4062 }
4063
4064 ret = peer_group_listen_range_add(group, &range);
4065 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4066}
4067
4068DEFUN (no_bgp_listen_range,
4069 no_bgp_listen_range_cmd,
d7b9898c 4070 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4071 NO_STR
e9273987 4072 BGP_STR
d7fa34c1
QY
4073 "Unconfigure BGP dynamic neighbors listen range\n"
4074 "Unconfigure BGP dynamic neighbors listen range\n"
4075 NEIGHBOR_ADDR_STR
4076 "Member of the peer-group\n"
4077 "Peer-group name\n")
f14e6fdb 4078{
d62a17ae 4079 VTY_DECLVAR_CONTEXT(bgp, bgp);
4080 struct prefix range;
4081 struct peer_group *group;
4082 afi_t afi;
4083 int ret;
4084 int idx = 0;
4085
4086 argv_find(argv, argc, "A.B.C.D/M", &idx);
4087 argv_find(argv, argc, "X:X::X:X/M", &idx);
4088 char *prefix = argv[idx]->arg;
21d88a71 4089 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4090 char *peergroup = argv[idx]->arg;
4091
4092 /* Convert IP prefix string to struct prefix. */
4093 ret = str2prefix(prefix, &range);
4094 if (!ret) {
4095 vty_out(vty, "%% Malformed listen range\n");
4096 return CMD_WARNING_CONFIG_FAILED;
4097 }
4098
4099 afi = family2afi(range.family);
4100
4101 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4102 vty_out(vty,
4103 "%% Malformed listen range (link-local address)\n");
4104 return CMD_WARNING_CONFIG_FAILED;
4105 }
4106
4107 apply_mask(&range);
4108
4109 group = peer_group_lookup(bgp, peergroup);
4110 if (!group) {
4111 vty_out(vty, "%% Peer-group does not exist\n");
4112 return CMD_WARNING_CONFIG_FAILED;
4113 }
4114
4115 ret = peer_group_listen_range_del(group, &range);
4116 return bgp_vty_return(vty, ret);
4117}
4118
2b791107 4119void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4120{
4121 struct peer_group *group;
4122 struct listnode *node, *nnode, *rnode, *nrnode;
4123 struct prefix *range;
4124 afi_t afi;
d62a17ae 4125
4126 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4127 vty_out(vty, " bgp listen limit %d\n",
4128 bgp->dynamic_neighbors_limit);
4129
4130 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4131 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4132 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4133 nrnode, range)) {
d62a17ae 4134 vty_out(vty,
2dbe669b
DA
4135 " bgp listen range %pFX peer-group %s\n",
4136 range, group->name);
d62a17ae 4137 }
4138 }
4139 }
f14e6fdb
DS
4140}
4141
4142
1ca2fd11
IR
4143DEFUN (bgp_disable_connected_route_check,
4144 bgp_disable_connected_route_check_cmd,
4145 "bgp disable-ebgp-connected-route-check",
e9273987 4146 BGP_STR
1ca2fd11 4147 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4148{
1ca2fd11
IR
4149 VTY_DECLVAR_CONTEXT(bgp, bgp);
4150 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4151 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 4152
1ca2fd11 4153 return CMD_SUCCESS;
907f92c8
DS
4154}
4155
1ca2fd11
IR
4156DEFUN (no_bgp_disable_connected_route_check,
4157 no_bgp_disable_connected_route_check_cmd,
4158 "no bgp disable-ebgp-connected-route-check",
4159 NO_STR
e9273987 4160 BGP_STR
1ca2fd11 4161 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4162{
1ca2fd11
IR
4163 VTY_DECLVAR_CONTEXT(bgp, bgp);
4164 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4165 bgp_clear_star_soft_in(vty, bgp->name);
d62a17ae 4166
1ca2fd11 4167 return CMD_SUCCESS;
d62a17ae 4168}
4169
4170
28c6e247
IR
4171static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4172 const char *as_str)
4173{
4174 VTY_DECLVAR_CONTEXT(bgp, bgp);
4175 int ret;
4176 as_t as;
4177 int as_type = AS_SPECIFIED;
4178 union sockunion su;
4179
4180 if (as_str[0] == 'i') {
4181 as = 0;
4182 as_type = AS_INTERNAL;
4183 } else if (as_str[0] == 'e') {
4184 as = 0;
4185 as_type = AS_EXTERNAL;
4186 } else {
4187 /* Get AS number. */
4188 as = strtoul(as_str, NULL, 10);
4189 }
4190
4191 /* If peer is peer group or interface peer, call proper function. */
4192 ret = str2sockunion(peer_str, &su);
4193 if (ret < 0) {
4194 struct peer *peer;
4195
4196 /* Check if existing interface peer */
4197 peer = peer_lookup_by_conf_if(bgp, peer_str);
4198
4199 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4200
4201 /* if not interface peer, check peer-group settings */
4202 if (ret < 0 && !peer) {
4203 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4204 if (ret < 0) {
4205 vty_out(vty,
4206 "%% Create the peer-group or interface first\n");
4207 return CMD_WARNING_CONFIG_FAILED;
4208 }
4209 return CMD_SUCCESS;
4210 }
4211 } else {
4212 if (peer_address_self_check(bgp, &su)) {
4213 vty_out(vty,
4214 "%% Can not configure the local system as neighbor\n");
4215 return CMD_WARNING_CONFIG_FAILED;
4216 }
4217 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4218 }
4219
28c6e247
IR
4220 return bgp_vty_return(vty, ret);
4221}
4222
1ca2fd11
IR
4223DEFUN (bgp_default_shutdown,
4224 bgp_default_shutdown_cmd,
4225 "[no] bgp default shutdown",
4226 NO_STR
4227 BGP_STR
4228 "Configure BGP defaults\n"
4229 "Apply administrative shutdown to newly configured peers\n")
ff8a8a7a 4230{
1ca2fd11
IR
4231 VTY_DECLVAR_CONTEXT(bgp, bgp);
4232 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4233 return CMD_SUCCESS;
f26845f9
QY
4234}
4235
736b68f3
DS
4236DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4237 BGP_STR
9ddf4b81 4238 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4239 "Add a shutdown message (RFC 8203)\n"
4240 "Shutdown message\n")
9cf59432 4241{
736b68f3 4242 char *msgstr = NULL;
8389c83a 4243
9cf59432
DS
4244 VTY_DECLVAR_CONTEXT(bgp, bgp);
4245
8389c83a 4246 if (argc > 3)
f80e35b6 4247 msgstr = argv_concat(argv, argc, 3);
8389c83a 4248
b776f48c
DA
4249 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4250 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4251 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4252 return CMD_WARNING_CONFIG_FAILED;
4253 }
4254
8389c83a
DS
4255 bgp_shutdown_enable(bgp, msgstr);
4256 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4257
4258 return CMD_SUCCESS;
4259}
4260
736b68f3 4261DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4262 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4263{
4264 VTY_DECLVAR_CONTEXT(bgp, bgp);
4265
4266 bgp_shutdown_enable(bgp, NULL);
4267
4268 return CMD_SUCCESS;
4269}
8389c83a 4270
736b68f3 4271DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4272 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4273{
4274 VTY_DECLVAR_CONTEXT(bgp, bgp);
4275
4276 bgp_shutdown_disable(bgp);
4277
4278 return CMD_SUCCESS;
4279}
4280
9ddf4b81 4281ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4282 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4283 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4284 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4285
28c6e247
IR
4286DEFUN (neighbor_remote_as,
4287 neighbor_remote_as_cmd,
4288 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4289 NEIGHBOR_STR
4290 NEIGHBOR_ADDR_STR2
4291 "Specify a BGP neighbor\n"
4292 AS_STR
4293 "Internal BGP peer\n"
4294 "External BGP peer\n")
718e3744 4295{
d62a17ae 4296 int idx_peer = 1;
4297 int idx_remote_as = 3;
28c6e247
IR
4298 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4299 argv[idx_remote_as]->arg);
d62a17ae 4300}
f852eb98
PG
4301/* Enable fast convergence of bgp sessions. If this is enabled, bgp
4302 * sessions do not wait for hold timer expiry to bring down the sessions
4303 * when nexthop becomes unreachable
4304 */
4305DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4306 BGP_STR "Fast convergence for bgp sessions\n")
4307{
4308 VTY_DECLVAR_CONTEXT(bgp, bgp);
4309 bgp->fast_convergence = true;
4310
4311 return CMD_SUCCESS;
4312}
4313
4314DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4315 "no bgp fast-convergence",
4316 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4317{
4318 VTY_DECLVAR_CONTEXT(bgp, bgp);
4319 bgp->fast_convergence = false;
4320
4321 return CMD_SUCCESS;
4322}
d62a17ae 4323
28c6e247
IR
4324static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4325 int v6only,
4326 const char *peer_group_name,
4327 const char *as_str)
d62a17ae 4328{
28c6e247
IR
4329 VTY_DECLVAR_CONTEXT(bgp, bgp);
4330 as_t as = 0;
4331 int as_type = AS_UNSPECIFIED;
d62a17ae 4332 struct peer *peer;
4333 struct peer_group *group;
4334 int ret = 0;
d62a17ae 4335
4336 group = peer_group_lookup(bgp, conf_if);
4337
4338 if (group) {
28c6e247
IR
4339 vty_out(vty, "%% Name conflict with peer-group \n");
4340 return CMD_WARNING_CONFIG_FAILED;
4341 }
4342
4343 if (as_str) {
4344 if (as_str[0] == 'i') {
4345 as_type = AS_INTERNAL;
4346 } else if (as_str[0] == 'e') {
4347 as_type = AS_EXTERNAL;
4348 } else {
4349 /* Get AS number. */
4350 as = strtoul(as_str, NULL, 10);
4351 as_type = AS_SPECIFIED;
4352 }
d62a17ae 4353 }
4354
4355 peer = peer_lookup_by_conf_if(bgp, conf_if);
4356 if (peer) {
28c6e247 4357 if (as_str)
e84c59af 4358 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
d62a17ae 4359 } else {
e84c59af
DA
4360 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4361 NULL);
d62a17ae 4362
4363 if (!peer) {
28c6e247
IR
4364 vty_out(vty, "%% BGP failed to create peer\n");
4365 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4366 }
4367
4368 if (v6only)
527de3dc 4369 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4370
4371 /* Request zebra to initiate IPv6 RAs on this interface. We do
4372 * this
4373 * any unnumbered peer in order to not worry about run-time
4374 * transitions
4375 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4376 * address
4377 * gets deleted later etc.)
4378 */
4379 if (peer->ifp)
4380 bgp_zebra_initiate_radv(bgp, peer);
4381 }
4382
4383 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4384 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4385 if (v6only)
527de3dc 4386 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4387 else
527de3dc 4388 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4389
4390 /* v6only flag changed. Reset bgp seesion */
4391 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4392 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4393 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4394 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4395 } else
4396 bgp_session_reset(peer);
4397 }
4398
9fb964de
PM
4399 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4400 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4401 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4402 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4403 }
d62a17ae 4404
4405 if (peer_group_name) {
4406 group = peer_group_lookup(bgp, peer_group_name);
4407 if (!group) {
28c6e247
IR
4408 vty_out(vty, "%% Configure the peer-group first\n");
4409 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4410 }
4411
8395c1f8 4412 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4413 }
4414
28c6e247 4415 return bgp_vty_return(vty, ret);
a80beece
DS
4416}
4417
28c6e247
IR
4418DEFUN (neighbor_interface_config,
4419 neighbor_interface_config_cmd,
4420 "neighbor WORD interface [peer-group PGNAME]",
4421 NEIGHBOR_STR
4422 "Interface name or neighbor tag\n"
4423 "Enable BGP on interface\n"
4424 "Member of the peer-group\n"
4425 "Peer-group name\n")
4c48cf63 4426{
d62a17ae 4427 int idx_word = 1;
4428 int idx_peer_group_word = 4;
f4b8ec07 4429
d62a17ae 4430 if (argc > idx_peer_group_word)
28c6e247
IR
4431 return peer_conf_interface_get(
4432 vty, argv[idx_word]->arg, 0,
4433 argv[idx_peer_group_word]->arg, NULL);
4434 else
4435 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4436 NULL, NULL);
4c48cf63
DW
4437}
4438
28c6e247
IR
4439DEFUN (neighbor_interface_config_v6only,
4440 neighbor_interface_config_v6only_cmd,
4441 "neighbor WORD interface v6only [peer-group PGNAME]",
4442 NEIGHBOR_STR
4443 "Interface name or neighbor tag\n"
4444 "Enable BGP on interface\n"
4445 "Enable BGP with v6 link-local only\n"
4446 "Member of the peer-group\n"
4447 "Peer-group name\n")
4c48cf63 4448{
d62a17ae 4449 int idx_word = 1;
4450 int idx_peer_group_word = 5;
31500417 4451
d62a17ae 4452 if (argc > idx_peer_group_word)
28c6e247
IR
4453 return peer_conf_interface_get(
4454 vty, argv[idx_word]->arg, 1,
4455 argv[idx_peer_group_word]->arg, NULL);
31500417 4456
28c6e247 4457 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4c48cf63
DW
4458}
4459
a80beece 4460
28c6e247
IR
4461DEFUN (neighbor_interface_config_remote_as,
4462 neighbor_interface_config_remote_as_cmd,
4463 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4464 NEIGHBOR_STR
4465 "Interface name or neighbor tag\n"
4466 "Enable BGP on interface\n"
4467 "Specify a BGP neighbor\n"
4468 AS_STR
4469 "Internal BGP peer\n"
4470 "External BGP peer\n")
b3a39dc5 4471{
d62a17ae 4472 int idx_word = 1;
4473 int idx_remote_as = 4;
28c6e247
IR
4474 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4475 argv[idx_remote_as]->arg);
b3a39dc5
DD
4476}
4477
28c6e247
IR
4478DEFUN (neighbor_interface_v6only_config_remote_as,
4479 neighbor_interface_v6only_config_remote_as_cmd,
4480 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4481 NEIGHBOR_STR
4482 "Interface name or neighbor tag\n"
4483 "Enable BGP with v6 link-local only\n"
4484 "Enable BGP on interface\n"
4485 "Specify a BGP neighbor\n"
4486 AS_STR
4487 "Internal BGP peer\n"
4488 "External BGP peer\n")
b3a39dc5 4489{
d62a17ae 4490 int idx_word = 1;
4491 int idx_remote_as = 5;
28c6e247
IR
4492 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4493 argv[idx_remote_as]->arg);
b3a39dc5
DD
4494}
4495
28c6e247
IR
4496DEFUN (neighbor_peer_group,
4497 neighbor_peer_group_cmd,
4498 "neighbor WORD peer-group",
4499 NEIGHBOR_STR
4500 "Interface name or neighbor tag\n"
4501 "Configure peer-group\n")
718e3744 4502{
28c6e247 4503 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4504 int idx_word = 1;
28c6e247
IR
4505 struct peer *peer;
4506 struct peer_group *group;
718e3744 4507
28c6e247
IR
4508 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4509 if (peer) {
4510 vty_out(vty, "%% Name conflict with interface: \n");
4511 return CMD_WARNING_CONFIG_FAILED;
4512 }
718e3744 4513
28c6e247
IR
4514 group = peer_group_get(bgp, argv[idx_word]->arg);
4515 if (!group) {
4516 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4517 return CMD_WARNING_CONFIG_FAILED;
4518 }
718e3744 4519
28c6e247 4520 return CMD_SUCCESS;
718e3744 4521}
4522
1d80f243
IR
4523DEFUN (no_neighbor,
4524 no_neighbor_cmd,
4525 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4526 NO_STR
4527 NEIGHBOR_STR
4528 NEIGHBOR_ADDR_STR2
4529 "Specify a BGP neighbor\n"
4530 AS_STR
4531 "Internal BGP peer\n"
4532 "External BGP peer\n")
718e3744 4533{
28c6e247 4534 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4535 int idx_peer = 2;
28c6e247 4536 int ret;
d62a17ae 4537 union sockunion su;
28c6e247
IR
4538 struct peer_group *group;
4539 struct peer *peer;
4540 struct peer *other;
d62a17ae 4541
28c6e247
IR
4542 ret = str2sockunion(argv[idx_peer]->arg, &su);
4543 if (ret < 0) {
4544 /* look up for neighbor by interface name config. */
4545 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4546 if (peer) {
4547 /* Request zebra to terminate IPv6 RAs on this
4548 * interface. */
4549 if (peer->ifp)
4550 bgp_zebra_terminate_radv(peer->bgp, peer);
4551 peer_notify_unconfig(peer);
4552 peer_delete(peer);
4553 return CMD_SUCCESS;
d62a17ae 4554 }
28c6e247
IR
4555
4556 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4557 if (group) {
4558 peer_group_notify_unconfig(group);
4559 peer_group_delete(group);
4e2786df 4560 } else {
28c6e247 4561 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4562 return CMD_WARNING_CONFIG_FAILED;
4563 }
28c6e247
IR
4564 } else {
4565 peer = peer_lookup(bgp, &su);
4566 if (peer) {
4567 if (peer_dynamic_neighbor(peer)) {
4568 vty_out(vty,
4569 "%% Operation not allowed on a dynamic neighbor\n");
4570 return CMD_WARNING_CONFIG_FAILED;
4571 }
d62a17ae 4572
28c6e247 4573 other = peer->doppelganger;
f4b8ec07 4574
28c6e247
IR
4575 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4576 bgp_zebra_terminate_radv(peer->bgp, peer);
f4b8ec07 4577
28c6e247
IR
4578 peer_notify_unconfig(peer);
4579 peer_delete(peer);
4580 if (other && other->status != Deleted) {
4581 peer_notify_unconfig(other);
4582 peer_delete(other);
4583 }
4584 }
4585 }
4586
4587 return CMD_SUCCESS;
a80beece
DS
4588}
4589
28c6e247
IR
4590DEFUN (no_neighbor_interface_config,
4591 no_neighbor_interface_config_cmd,
4592 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4593 NO_STR
4594 NEIGHBOR_STR
4595 "Interface name\n"
4596 "Configure BGP on interface\n"
4597 "Enable BGP with v6 link-local only\n"
4598 "Member of the peer-group\n"
4599 "Peer-group name\n"
4600 "Specify a BGP neighbor\n"
4601 AS_STR
4602 "Internal BGP peer\n"
4603 "External BGP peer\n")
718e3744 4604{
28c6e247 4605 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4606 int idx_word = 2;
28c6e247 4607 struct peer *peer;
718e3744 4608
28c6e247
IR
4609 /* look up for neighbor by interface name config. */
4610 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4611 if (peer) {
4612 /* Request zebra to terminate IPv6 RAs on this interface. */
4613 if (peer->ifp)
4614 bgp_zebra_terminate_radv(peer->bgp, peer);
4615 peer_notify_unconfig(peer);
4616 peer_delete(peer);
4617 } else {
4618 vty_out(vty, "%% Create the bgp interface first\n");
4619 return CMD_WARNING_CONFIG_FAILED;
4620 }
4621 return CMD_SUCCESS;
718e3744 4622}
4623
28c6e247
IR
4624DEFUN (no_neighbor_peer_group,
4625 no_neighbor_peer_group_cmd,
4626 "no neighbor WORD peer-group",
4627 NO_STR
4628 NEIGHBOR_STR
4629 "Neighbor tag\n"
4630 "Configure peer-group\n")
718e3744 4631{
28c6e247
IR
4632 VTY_DECLVAR_CONTEXT(bgp, bgp);
4633 int idx_word = 2;
4634 struct peer_group *group;
f4b8ec07 4635
28c6e247
IR
4636 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4637 if (group) {
4638 peer_group_notify_unconfig(group);
4639 peer_group_delete(group);
f4b8ec07 4640 } else {
28c6e247 4641 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4642 return CMD_WARNING_CONFIG_FAILED;
4643 }
28c6e247
IR
4644 return CMD_SUCCESS;
4645}
f4b8ec07 4646
28c6e247
IR
4647DEFUN (no_neighbor_interface_peer_group_remote_as,
4648 no_neighbor_interface_peer_group_remote_as_cmd,
4649 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4650 NO_STR
4651 NEIGHBOR_STR
4652 "Interface name or neighbor tag\n"
4653 "Specify a BGP neighbor\n"
4654 AS_STR
4655 "Internal BGP peer\n"
4656 "External BGP peer\n")
4657{
4658 VTY_DECLVAR_CONTEXT(bgp, bgp);
4659 int idx_word = 2;
4660 struct peer_group *group;
4661 struct peer *peer;
f4b8ec07 4662
28c6e247
IR
4663 /* look up for neighbor by interface name config. */
4664 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4665 if (peer) {
4666 peer_as_change(peer, 0, AS_UNSPECIFIED);
4667 return CMD_SUCCESS;
4668 }
f4b8ec07 4669
28c6e247
IR
4670 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4671 if (group)
4672 peer_group_remote_as_delete(group);
4673 else {
4674 vty_out(vty, "%% Create the peer-group or interface first\n");
4675 return CMD_WARNING_CONFIG_FAILED;
4676 }
4677 return CMD_SUCCESS;
718e3744 4678}
6b0655a2 4679
28c6e247
IR
4680DEFUN (neighbor_local_as,
4681 neighbor_local_as_cmd,
4682 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4683 NEIGHBOR_STR
4684 NEIGHBOR_ADDR_STR2
4685 "Specify a local-as number\n"
4686 "AS number used as local AS\n")
718e3744 4687{
d62a17ae 4688 int idx_peer = 1;
4689 int idx_number = 3;
28c6e247
IR
4690 struct peer *peer;
4691 int ret;
4692 as_t as;
718e3744 4693
28c6e247
IR
4694 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4695 if (!peer)
d62a17ae 4696 return CMD_WARNING_CONFIG_FAILED;
718e3744 4697
28c6e247
IR
4698 as = strtoul(argv[idx_number]->arg, NULL, 10);
4699 ret = peer_local_as_set(peer, as, 0, 0);
4700 return bgp_vty_return(vty, ret);
718e3744 4701}
4702
28c6e247
IR
4703DEFUN (neighbor_local_as_no_prepend,
4704 neighbor_local_as_no_prepend_cmd,
4705 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4706 NEIGHBOR_STR
4707 NEIGHBOR_ADDR_STR2
4708 "Specify a local-as number\n"
4709 "AS number used as local AS\n"
4710 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4711{
d62a17ae 4712 int idx_peer = 1;
4713 int idx_number = 3;
28c6e247
IR
4714 struct peer *peer;
4715 int ret;
4716 as_t as;
718e3744 4717
28c6e247
IR
4718 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4719 if (!peer)
d62a17ae 4720 return CMD_WARNING_CONFIG_FAILED;
718e3744 4721
28c6e247
IR
4722 as = strtoul(argv[idx_number]->arg, NULL, 10);
4723 ret = peer_local_as_set(peer, as, 1, 0);
4724 return bgp_vty_return(vty, ret);
718e3744 4725}
4726
28c6e247
IR
4727DEFUN (neighbor_local_as_no_prepend_replace_as,
4728 neighbor_local_as_no_prepend_replace_as_cmd,
4729 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4730 NEIGHBOR_STR
4731 NEIGHBOR_ADDR_STR2
4732 "Specify a local-as number\n"
4733 "AS number used as local AS\n"
4734 "Do not prepend local-as to updates from ebgp peers\n"
4735 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4736{
d62a17ae 4737 int idx_peer = 1;
4738 int idx_number = 3;
28c6e247
IR
4739 struct peer *peer;
4740 int ret;
4741 as_t as;
9d3f9705 4742
28c6e247
IR
4743 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4744 if (!peer)
d62a17ae 4745 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4746
28c6e247
IR
4747 as = strtoul(argv[idx_number]->arg, NULL, 10);
4748 ret = peer_local_as_set(peer, as, 1, 1);
4749 return bgp_vty_return(vty, ret);
9d3f9705
AC
4750}
4751
28c6e247
IR
4752DEFUN (no_neighbor_local_as,
4753 no_neighbor_local_as_cmd,
4754 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4755 NO_STR
4756 NEIGHBOR_STR
4757 NEIGHBOR_ADDR_STR2
4758 "Specify a local-as number\n"
4759 "AS number used as local AS\n"
4760 "Do not prepend local-as to updates from ebgp peers\n"
4761 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4762{
d62a17ae 4763 int idx_peer = 2;
28c6e247
IR
4764 struct peer *peer;
4765 int ret;
718e3744 4766
28c6e247
IR
4767 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4768 if (!peer)
d62a17ae 4769 return CMD_WARNING_CONFIG_FAILED;
718e3744 4770
28c6e247
IR
4771 ret = peer_local_as_unset(peer);
4772 return bgp_vty_return(vty, ret);
718e3744 4773}
4774
718e3744 4775
3f9c7369
DS
4776DEFUN (neighbor_solo,
4777 neighbor_solo_cmd,
9ccf14f7 4778 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4779 NEIGHBOR_STR
4780 NEIGHBOR_ADDR_STR2
4781 "Solo peer - part of its own update group\n")
4782{
d62a17ae 4783 int idx_peer = 1;
4784 struct peer *peer;
4785 int ret;
3f9c7369 4786
d62a17ae 4787 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4788 if (!peer)
4789 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4790
d62a17ae 4791 ret = update_group_adjust_soloness(peer, 1);
4792 return bgp_vty_return(vty, ret);
3f9c7369
DS
4793}
4794
4795DEFUN (no_neighbor_solo,
4796 no_neighbor_solo_cmd,
9ccf14f7 4797 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4798 NO_STR
4799 NEIGHBOR_STR
4800 NEIGHBOR_ADDR_STR2
4801 "Solo peer - part of its own update group\n")
4802{
d62a17ae 4803 int idx_peer = 2;
4804 struct peer *peer;
4805 int ret;
3f9c7369 4806
d62a17ae 4807 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4808 if (!peer)
4809 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4810
d62a17ae 4811 ret = update_group_adjust_soloness(peer, 0);
4812 return bgp_vty_return(vty, ret);
3f9c7369
DS
4813}
4814
28c6e247
IR
4815DEFUN (neighbor_password,
4816 neighbor_password_cmd,
4817 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4818 NEIGHBOR_STR
4819 NEIGHBOR_ADDR_STR2
4820 "Set a password\n"
4821 "The password\n")
0df7c91f 4822{
d62a17ae 4823 int idx_peer = 1;
4824 int idx_line = 3;
28c6e247
IR
4825 struct peer *peer;
4826 int ret;
0df7c91f 4827
28c6e247
IR
4828 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4829 if (!peer)
d62a17ae 4830 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4831
28c6e247
IR
4832 ret = peer_password_set(peer, argv[idx_line]->arg);
4833 return bgp_vty_return(vty, ret);
0df7c91f
PJ
4834}
4835
28c6e247
IR
4836DEFUN (no_neighbor_password,
4837 no_neighbor_password_cmd,
4838 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4839 NO_STR
4840 NEIGHBOR_STR
4841 NEIGHBOR_ADDR_STR2
4842 "Set a password\n"
4843 "The password\n")
0df7c91f 4844{
d62a17ae 4845 int idx_peer = 2;
28c6e247
IR
4846 struct peer *peer;
4847 int ret;
0df7c91f 4848
28c6e247
IR
4849 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4850 if (!peer)
d62a17ae 4851 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4852
28c6e247
IR
4853 ret = peer_password_unset(peer);
4854 return bgp_vty_return(vty, ret);
0df7c91f 4855}
6b0655a2 4856
28c6e247
IR
4857DEFUN (neighbor_activate,
4858 neighbor_activate_cmd,
4859 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4860 NEIGHBOR_STR
4861 NEIGHBOR_ADDR_STR2
4862 "Enable the Address Family for this Neighbor\n")
718e3744 4863{
d62a17ae 4864 int idx_peer = 1;
28c6e247
IR
4865 int ret;
4866 struct peer *peer;
56ceae84 4867
28c6e247
IR
4868 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4869 if (!peer)
d62a17ae 4870 return CMD_WARNING_CONFIG_FAILED;
718e3744 4871
28c6e247
IR
4872 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4873 return bgp_vty_return(vty, ret);
718e3744 4874}
4875
d62a17ae 4876ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4877 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4878 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4879 "Enable the Address Family for this Neighbor\n")
596c17ba 4880
28c6e247
IR
4881DEFUN (no_neighbor_activate,
4882 no_neighbor_activate_cmd,
4883 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4884 NO_STR
4885 NEIGHBOR_STR
4886 NEIGHBOR_ADDR_STR2
4887 "Enable the Address Family for this Neighbor\n")
718e3744 4888{
d62a17ae 4889 int idx_peer = 2;
28c6e247
IR
4890 int ret;
4891 struct peer *peer;
f4b8ec07 4892
28c6e247
IR
4893 /* Lookup peer. */
4894 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4895 if (!peer)
d62a17ae 4896 return CMD_WARNING_CONFIG_FAILED;
718e3744 4897
28c6e247
IR
4898 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4899 return bgp_vty_return(vty, ret);
718e3744 4900}
6b0655a2 4901
d62a17ae 4902ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4903 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4904 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4905 "Enable the Address Family for this Neighbor\n")
596c17ba 4906
28c6e247
IR
4907DEFUN (neighbor_set_peer_group,
4908 neighbor_set_peer_group_cmd,
4909 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4910 NEIGHBOR_STR
4911 NEIGHBOR_ADDR_STR2
4912 "Member of the peer-group\n"
4913 "Peer-group name\n")
718e3744 4914{
28c6e247 4915 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4916 int idx_peer = 1;
4917 int idx_word = 3;
28c6e247
IR
4918 int ret;
4919 as_t as;
4920 union sockunion su;
4921 struct peer *peer;
4922 struct peer_group *group;
4923
4924 ret = str2sockunion(argv[idx_peer]->arg, &su);
4925 if (ret < 0) {
4926 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4927 if (!peer) {
4928 vty_out(vty, "%% Malformed address or name: %s\n",
4929 argv[idx_peer]->arg);
4930 return CMD_WARNING_CONFIG_FAILED;
4931 }
4932 } else {
4933 if (peer_address_self_check(bgp, &su)) {
4934 vty_out(vty,
4935 "%% Can not configure the local system as neighbor\n");
4936 return CMD_WARNING_CONFIG_FAILED;
4937 }
2a059a54 4938
28c6e247
IR
4939 /* Disallow for dynamic neighbor. */
4940 peer = peer_lookup(bgp, &su);
4941 if (peer && peer_dynamic_neighbor(peer)) {
4942 vty_out(vty,
4943 "%% Operation not allowed on a dynamic neighbor\n");
4944 return CMD_WARNING_CONFIG_FAILED;
4945 }
4946 }
4947
4948 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4949 if (!group) {
4950 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 4951 return CMD_WARNING_CONFIG_FAILED;
28c6e247 4952 }
d62a17ae 4953
28c6e247 4954 ret = peer_group_bind(bgp, &su, peer, group, &as);
2a059a54 4955
28c6e247 4956 return bgp_vty_return(vty, ret);
d62a17ae 4957}
4958
4959ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 4960 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4961 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4962 "Member of the peer-group\n"
4963 "Peer-group name\n")
596c17ba 4964
28c6e247
IR
4965DEFUN (no_neighbor_set_peer_group,
4966 no_neighbor_set_peer_group_cmd,
4967 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4968 NO_STR
4969 NEIGHBOR_STR
4970 NEIGHBOR_ADDR_STR2
4971 "Member of the peer-group\n"
4972 "Peer-group name\n")
718e3744 4973{
28c6e247 4974 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4975 int idx_peer = 2;
28c6e247
IR
4976 int idx_word = 4;
4977 int ret;
4978 struct peer *peer;
4979 struct peer_group *group;
d62a17ae 4980
28c6e247
IR
4981 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4982 if (!peer)
d62a17ae 4983 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 4984
28c6e247
IR
4985 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4986 if (!group) {
4987 vty_out(vty, "%% Configure the peer-group first\n");
4988 return CMD_WARNING_CONFIG_FAILED;
4989 }
718e3744 4990
28c6e247
IR
4991 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4992 bgp_zebra_terminate_radv(peer->bgp, peer);
4993
4994 peer_notify_unconfig(peer);
4995 ret = peer_delete(peer);
4996
4997 return bgp_vty_return(vty, ret);
718e3744 4998}
6b0655a2 4999
d62a17ae 5000ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
71cc0c88 5001 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5002 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5003 "Member of the peer-group\n"
5004 "Peer-group name\n")
596c17ba 5005
d62a17ae 5006static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 5007 uint32_t flag, int set)
718e3744 5008{
d62a17ae 5009 int ret;
5010 struct peer *peer;
718e3744 5011
d62a17ae 5012 peer = peer_and_group_lookup_vty(vty, ip_str);
5013 if (!peer)
5014 return CMD_WARNING_CONFIG_FAILED;
718e3744 5015
7ebe625c
QY
5016 /*
5017 * If 'neighbor <interface>', then this is for directly connected peers,
5018 * we should not accept disable-connected-check.
5019 */
5020 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5021 vty_out(vty,
3efd0893 5022 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
5023 ip_str);
5024 return CMD_WARNING_CONFIG_FAILED;
5025 }
5026
d62a17ae 5027 if (!set && flag == PEER_FLAG_SHUTDOWN)
5028 peer_tx_shutdown_message_unset(peer);
ae9b0e11 5029
d62a17ae 5030 if (set)
5031 ret = peer_flag_set(peer, flag);
5032 else
5033 ret = peer_flag_unset(peer, flag);
718e3744 5034
d62a17ae 5035 return bgp_vty_return(vty, ret);
718e3744 5036}
5037
47cbc09b 5038static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 5039{
d62a17ae 5040 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 5041}
5042
d62a17ae 5043static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 5044 uint32_t flag)
718e3744 5045{
d62a17ae 5046 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 5047}
5048
5049/* neighbor passive. */
28c6e247
IR
5050DEFUN (neighbor_passive,
5051 neighbor_passive_cmd,
5052 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5053 NEIGHBOR_STR
5054 NEIGHBOR_ADDR_STR2
5055 "Don't send open messages to this neighbor\n")
718e3744 5056{
d62a17ae 5057 int idx_peer = 1;
28c6e247 5058 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5059}
5060
28c6e247
IR
5061DEFUN (no_neighbor_passive,
5062 no_neighbor_passive_cmd,
5063 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5064 NO_STR
5065 NEIGHBOR_STR
5066 NEIGHBOR_ADDR_STR2
5067 "Don't send open messages to this neighbor\n")
718e3744 5068{
d62a17ae 5069 int idx_peer = 2;
28c6e247 5070 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5071}
6b0655a2 5072
718e3744 5073/* neighbor shutdown. */
28c6e247
IR
5074DEFUN (neighbor_shutdown_msg,
5075 neighbor_shutdown_msg_cmd,
5076 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5077 NEIGHBOR_STR
5078 NEIGHBOR_ADDR_STR2
5079 "Administratively shut down this neighbor\n"
5080 "Add a shutdown message (RFC 8203)\n"
5081 "Shutdown message\n")
718e3744 5082{
d62a17ae 5083 int idx_peer = 1;
73d70fa6 5084
d62a17ae 5085 if (argc >= 5) {
28c6e247
IR
5086 struct peer *peer =
5087 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
d62a17ae 5088 char *message;
73d70fa6 5089
28c6e247
IR
5090 if (!peer)
5091 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5092 message = argv_concat(argv, argc, 4);
28c6e247
IR
5093 peer_tx_shutdown_message_set(peer, message);
5094 XFREE(MTYPE_TMP, message);
d62a17ae 5095 }
73d70fa6 5096
28c6e247 5097 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 5098}
5099
1d80f243 5100ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5101 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5102 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5103 "Administratively shut down this neighbor\n")
73d70fa6 5104
28c6e247
IR
5105DEFUN (no_neighbor_shutdown_msg,
5106 no_neighbor_shutdown_msg_cmd,
5107 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5108 NO_STR
5109 NEIGHBOR_STR
5110 NEIGHBOR_ADDR_STR2
5111 "Administratively shut down this neighbor\n"
5112 "Remove a shutdown message (RFC 8203)\n"
5113 "Shutdown message\n")
718e3744 5114{
d62a17ae 5115 int idx_peer = 2;
73d70fa6 5116
28c6e247
IR
5117 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5118 PEER_FLAG_SHUTDOWN);
718e3744 5119}
6b0655a2 5120
1d80f243 5121ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5122 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5123 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5124 "Administratively shut down this neighbor\n")
73d70fa6 5125
8336c896
DA
5126DEFUN(neighbor_shutdown_rtt,
5127 neighbor_shutdown_rtt_cmd,
5128 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5129 NEIGHBOR_STR
5130 NEIGHBOR_ADDR_STR2
5131 "Administratively shut down this neighbor\n"
5132 "Shutdown if round-trip-time is higher than expected\n"
5133 "Round-trip-time in milliseconds\n"
5134 "Specify the number of keepalives before shutdown\n"
5135 "The number of keepalives with higher RTT to shutdown\n")
5136{
5137 int idx_peer = 1;
5138 int idx_rtt = 4;
5139 int idx_count = 0;
5140 struct peer *peer;
5141
5142 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5143
5144 if (!peer)
5145 return CMD_WARNING_CONFIG_FAILED;
5146
5147 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5148
5149 if (argv_find(argv, argc, "count", &idx_count))
5150 peer->rtt_keepalive_conf =
5151 strtol(argv[idx_count + 1]->arg, NULL, 10);
5152
5153 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5154 PEER_FLAG_RTT_SHUTDOWN);
5155}
5156
5157DEFUN(no_neighbor_shutdown_rtt,
5158 no_neighbor_shutdown_rtt_cmd,
5159 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5160 NO_STR
5161 NEIGHBOR_STR
5162 NEIGHBOR_ADDR_STR2
5163 "Administratively shut down this neighbor\n"
5164 "Shutdown if round-trip-time is higher than expected\n"
5165 "Round-trip-time in milliseconds\n"
5166 "Specify the number of keepalives before shutdown\n"
5167 "The number of keepalives with higher RTT to shutdown\n")
5168{
5169 int idx_peer = 2;
5170 struct peer *peer;
5171
5172 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5173
5174 if (!peer)
5175 return CMD_WARNING_CONFIG_FAILED;
5176
5177 peer->rtt_expected = 0;
5178 peer->rtt_keepalive_conf = 1;
5179
5180 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5181 PEER_FLAG_RTT_SHUTDOWN);
5182}
5183
718e3744 5184/* neighbor capability dynamic. */
28c6e247
IR
5185DEFUN (neighbor_capability_dynamic,
5186 neighbor_capability_dynamic_cmd,
5187 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5188 NEIGHBOR_STR
5189 NEIGHBOR_ADDR_STR2
5190 "Advertise capability to the peer\n"
5191 "Advertise dynamic capability to this neighbor\n")
718e3744 5192{
d62a17ae 5193 int idx_peer = 1;
28c6e247
IR
5194 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5195 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5196}
5197
28c6e247
IR
5198DEFUN (no_neighbor_capability_dynamic,
5199 no_neighbor_capability_dynamic_cmd,
5200 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5201 NO_STR
5202 NEIGHBOR_STR
5203 NEIGHBOR_ADDR_STR2
5204 "Advertise capability to the peer\n"
5205 "Advertise dynamic capability to this neighbor\n")
718e3744 5206{
d62a17ae 5207 int idx_peer = 2;
28c6e247
IR
5208 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5209 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5210}
6b0655a2 5211
718e3744 5212/* neighbor dont-capability-negotiate */
5213DEFUN (neighbor_dont_capability_negotiate,
5214 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5215 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5216 NEIGHBOR_STR
5217 NEIGHBOR_ADDR_STR2
5218 "Do not perform capability negotiation\n")
5219{
d62a17ae 5220 int idx_peer = 1;
5221 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5222 PEER_FLAG_DONT_CAPABILITY);
718e3744 5223}
5224
5225DEFUN (no_neighbor_dont_capability_negotiate,
5226 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5227 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5228 NO_STR
5229 NEIGHBOR_STR
5230 NEIGHBOR_ADDR_STR2
5231 "Do not perform capability negotiation\n")
5232{
28c6e247
IR
5233 int idx_peer = 2;
5234 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5235 PEER_FLAG_DONT_CAPABILITY);
f4b8ec07
CS
5236}
5237
28c6e247
IR
5238/* neighbor capability extended next hop encoding */
5239DEFUN (neighbor_capability_enhe,
5240 neighbor_capability_enhe_cmd,
5241 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5242 NEIGHBOR_STR
5243 NEIGHBOR_ADDR_STR2
5244 "Advertise capability to the peer\n"
5245 "Advertise extended next-hop capability to the peer\n")
f4b8ec07 5246{
28c6e247
IR
5247 int idx_peer = 1;
5248 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5249 PEER_FLAG_CAPABILITY_ENHE);
5250}
f4b8ec07 5251
28c6e247
IR
5252DEFUN (no_neighbor_capability_enhe,
5253 no_neighbor_capability_enhe_cmd,
5254 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5255 NO_STR
5256 NEIGHBOR_STR
5257 NEIGHBOR_ADDR_STR2
5258 "Advertise capability to the peer\n"
5259 "Advertise extended next-hop capability to the peer\n")
5260{
5261 int idx_peer = 2;
5262 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5263 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5264}
5265
d62a17ae 5266static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5267 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5268 int set)
718e3744 5269{
d62a17ae 5270 int ret;
5271 struct peer *peer;
718e3744 5272
d62a17ae 5273 peer = peer_and_group_lookup_vty(vty, peer_str);
5274 if (!peer)
5275 return CMD_WARNING_CONFIG_FAILED;
718e3744 5276
d62a17ae 5277 if (set)
5278 ret = peer_af_flag_set(peer, afi, safi, flag);
5279 else
5280 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5281
d62a17ae 5282 return bgp_vty_return(vty, ret);
718e3744 5283}
5284
d62a17ae 5285static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5286 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5287{
d62a17ae 5288 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5289}
5290
d62a17ae 5291static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5292 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5293{
d62a17ae 5294 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5295}
6b0655a2 5296
718e3744 5297/* neighbor capability orf prefix-list. */
5298DEFUN (neighbor_capability_orf_prefix,
5299 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5300 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5301 NEIGHBOR_STR
5302 NEIGHBOR_ADDR_STR2
5303 "Advertise capability to the peer\n"
5304 "Advertise ORF capability to the peer\n"
5305 "Advertise prefixlist ORF capability to this neighbor\n"
5306 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5307 "Capability to RECEIVE the ORF from this neighbor\n"
5308 "Capability to SEND the ORF to this neighbor\n")
5309{
d62a17ae 5310 int idx_send_recv = 5;
db45f64d
DS
5311 char *peer_str = argv[1]->arg;
5312 struct peer *peer;
5313 afi_t afi = bgp_node_afi(vty);
5314 safi_t safi = bgp_node_safi(vty);
d62a17ae 5315
db45f64d
DS
5316 peer = peer_and_group_lookup_vty(vty, peer_str);
5317 if (!peer)
d62a17ae 5318 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5319
db45f64d
DS
5320 if (strmatch(argv[idx_send_recv]->text, "send"))
5321 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5322 PEER_FLAG_ORF_PREFIX_SM);
5323
5324 if (strmatch(argv[idx_send_recv]->text, "receive"))
5325 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5326 PEER_FLAG_ORF_PREFIX_RM);
5327
5328 if (strmatch(argv[idx_send_recv]->text, "both"))
5329 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5330 PEER_FLAG_ORF_PREFIX_SM)
5331 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5332 PEER_FLAG_ORF_PREFIX_RM);
5333
5334 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5335}
5336
5337ALIAS_HIDDEN(
5338 neighbor_capability_orf_prefix,
5339 neighbor_capability_orf_prefix_hidden_cmd,
5340 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5341 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5342 "Advertise capability to the peer\n"
5343 "Advertise ORF capability to the peer\n"
5344 "Advertise prefixlist ORF capability to this neighbor\n"
5345 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5346 "Capability to RECEIVE the ORF from this neighbor\n"
5347 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5348
718e3744 5349DEFUN (no_neighbor_capability_orf_prefix,
5350 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5351 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5352 NO_STR
5353 NEIGHBOR_STR
5354 NEIGHBOR_ADDR_STR2
5355 "Advertise capability to the peer\n"
5356 "Advertise ORF capability to the peer\n"
5357 "Advertise prefixlist ORF capability to this neighbor\n"
5358 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5359 "Capability to RECEIVE the ORF from this neighbor\n"
5360 "Capability to SEND the ORF to this neighbor\n")
5361{
d62a17ae 5362 int idx_send_recv = 6;
db45f64d
DS
5363 char *peer_str = argv[2]->arg;
5364 struct peer *peer;
5365 afi_t afi = bgp_node_afi(vty);
5366 safi_t safi = bgp_node_safi(vty);
d62a17ae 5367
db45f64d
DS
5368 peer = peer_and_group_lookup_vty(vty, peer_str);
5369 if (!peer)
d62a17ae 5370 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5371
db45f64d
DS
5372 if (strmatch(argv[idx_send_recv]->text, "send"))
5373 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5374 PEER_FLAG_ORF_PREFIX_SM);
5375
5376 if (strmatch(argv[idx_send_recv]->text, "receive"))
5377 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5378 PEER_FLAG_ORF_PREFIX_RM);
5379
5380 if (strmatch(argv[idx_send_recv]->text, "both"))
5381 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5382 PEER_FLAG_ORF_PREFIX_SM)
5383 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5384 PEER_FLAG_ORF_PREFIX_RM);
5385
5386 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5387}
5388
5389ALIAS_HIDDEN(
5390 no_neighbor_capability_orf_prefix,
5391 no_neighbor_capability_orf_prefix_hidden_cmd,
5392 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5393 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5394 "Advertise capability to the peer\n"
5395 "Advertise ORF capability to the peer\n"
5396 "Advertise prefixlist ORF capability to this neighbor\n"
5397 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5398 "Capability to RECEIVE the ORF from this neighbor\n"
5399 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5400
718e3744 5401/* neighbor next-hop-self. */
28c6e247
IR
5402DEFUN (neighbor_nexthop_self,
5403 neighbor_nexthop_self_cmd,
5404 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5405 NEIGHBOR_STR
5406 NEIGHBOR_ADDR_STR2
5407 "Disable the next hop calculation for this neighbor\n")
718e3744 5408{
d62a17ae 5409 int idx_peer = 1;
28c6e247
IR
5410 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5411 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 5412}
9e7a53c1 5413
d62a17ae 5414ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5415 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5416 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5417 "Disable the next hop calculation for this neighbor\n")
596c17ba 5418
f4b8ec07 5419/* neighbor next-hop-self. */
28c6e247
IR
5420DEFUN (neighbor_nexthop_self_force,
5421 neighbor_nexthop_self_force_cmd,
5422 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5423 NEIGHBOR_STR
5424 NEIGHBOR_ADDR_STR2
5425 "Disable the next hop calculation for this neighbor\n"
5426 "Set the next hop to self for reflected routes\n")
f4b8ec07
CS
5427{
5428 int idx_peer = 1;
28c6e247
IR
5429 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5430 bgp_node_safi(vty),
5431 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 5432}
5433
d62a17ae 5434ALIAS_HIDDEN(neighbor_nexthop_self_force,
5435 neighbor_nexthop_self_force_hidden_cmd,
5436 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5437 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5438 "Disable the next hop calculation for this neighbor\n"
5439 "Set the next hop to self for reflected routes\n")
596c17ba 5440
1bc4e531
DA
5441ALIAS_HIDDEN(neighbor_nexthop_self_force,
5442 neighbor_nexthop_self_all_hidden_cmd,
5443 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5444 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5445 "Disable the next hop calculation for this neighbor\n"
5446 "Set the next hop to self for reflected routes\n")
5447
28c6e247
IR
5448DEFUN (no_neighbor_nexthop_self,
5449 no_neighbor_nexthop_self_cmd,
5450 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5451 NO_STR
5452 NEIGHBOR_STR
5453 NEIGHBOR_ADDR_STR2
5454 "Disable the next hop calculation for this neighbor\n")
718e3744 5455{
d62a17ae 5456 int idx_peer = 2;
28c6e247
IR
5457 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5458 bgp_node_afi(vty), bgp_node_safi(vty),
5459 PEER_FLAG_NEXTHOP_SELF);
718e3744 5460}
6b0655a2 5461
d62a17ae 5462ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5463 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5464 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5465 "Disable the next hop calculation for this neighbor\n")
596c17ba 5466
28c6e247
IR
5467DEFUN (no_neighbor_nexthop_self_force,
5468 no_neighbor_nexthop_self_force_cmd,
5469 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5470 NO_STR
5471 NEIGHBOR_STR
5472 NEIGHBOR_ADDR_STR2
5473 "Disable the next hop calculation for this neighbor\n"
5474 "Set the next hop to self for reflected routes\n")
88b8ed8d 5475{
d62a17ae 5476 int idx_peer = 2;
28c6e247
IR
5477 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5478 bgp_node_afi(vty), bgp_node_safi(vty),
5479 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5480}
a538debe 5481
d62a17ae 5482ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5483 no_neighbor_nexthop_self_force_hidden_cmd,
5484 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5485 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5486 "Disable the next hop calculation for this neighbor\n"
5487 "Set the next hop to self for reflected routes\n")
596c17ba 5488
1bc4e531
DA
5489ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5490 no_neighbor_nexthop_self_all_hidden_cmd,
5491 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5492 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5493 "Disable the next hop calculation for this neighbor\n"
5494 "Set the next hop to self for reflected routes\n")
5495
c7122e14 5496/* neighbor as-override */
28c6e247
IR
5497DEFUN (neighbor_as_override,
5498 neighbor_as_override_cmd,
5499 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5500 NEIGHBOR_STR
5501 NEIGHBOR_ADDR_STR2
5502 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5503{
d62a17ae 5504 int idx_peer = 1;
28c6e247
IR
5505 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5506 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5507}
5508
d62a17ae 5509ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5510 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5511 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5512 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5513
28c6e247
IR
5514DEFUN (no_neighbor_as_override,
5515 no_neighbor_as_override_cmd,
5516 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5517 NO_STR
5518 NEIGHBOR_STR
5519 NEIGHBOR_ADDR_STR2
5520 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5521{
d62a17ae 5522 int idx_peer = 2;
28c6e247
IR
5523 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5524 bgp_node_afi(vty), bgp_node_safi(vty),
5525 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5526}
5527
d62a17ae 5528ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5529 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5530 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5531 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5532
718e3744 5533/* neighbor remove-private-AS. */
28c6e247
IR
5534DEFUN (neighbor_remove_private_as,
5535 neighbor_remove_private_as_cmd,
5536 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5537 NEIGHBOR_STR
5538 NEIGHBOR_ADDR_STR2
5539 "Remove private ASNs in outbound updates\n")
718e3744 5540{
d62a17ae 5541 int idx_peer = 1;
28c6e247
IR
5542 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5543 bgp_node_safi(vty),
5544 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5545}
5546
d62a17ae 5547ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5548 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5549 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5550 "Remove private ASNs in outbound updates\n")
596c17ba 5551
28c6e247
IR
5552DEFUN (neighbor_remove_private_as_all,
5553 neighbor_remove_private_as_all_cmd,
5554 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5555 NEIGHBOR_STR
5556 NEIGHBOR_ADDR_STR2
5557 "Remove private ASNs in outbound updates\n"
5558 "Apply to all AS numbers\n")
5000f21c 5559{
d62a17ae 5560 int idx_peer = 1;
28c6e247
IR
5561 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5562 bgp_node_safi(vty),
5563 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
5564}
5565
d62a17ae 5566ALIAS_HIDDEN(neighbor_remove_private_as_all,
5567 neighbor_remove_private_as_all_hidden_cmd,
5568 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5569 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5570 "Remove private ASNs in outbound updates\n"
5571 "Apply to all AS numbers")
596c17ba 5572
28c6e247
IR
5573DEFUN (neighbor_remove_private_as_replace_as,
5574 neighbor_remove_private_as_replace_as_cmd,
5575 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5576 NEIGHBOR_STR
5577 NEIGHBOR_ADDR_STR2
5578 "Remove private ASNs in outbound updates\n"
5579 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5580{
d62a17ae 5581 int idx_peer = 1;
28c6e247
IR
5582 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5583 bgp_node_safi(vty),
5584 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
5585}
5586
d62a17ae 5587ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5588 neighbor_remove_private_as_replace_as_hidden_cmd,
5589 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5590 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5591 "Remove private ASNs in outbound updates\n"
5592 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5593
28c6e247
IR
5594DEFUN (neighbor_remove_private_as_all_replace_as,
5595 neighbor_remove_private_as_all_replace_as_cmd,
5596 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5597 NEIGHBOR_STR
5598 NEIGHBOR_ADDR_STR2
5599 "Remove private ASNs in outbound updates\n"
5600 "Apply to all AS numbers\n"
5601 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5602{
d62a17ae 5603 int idx_peer = 1;
28c6e247
IR
5604 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5605 bgp_node_safi(vty),
5606 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
5607}
5608
d62a17ae 5609ALIAS_HIDDEN(
5610 neighbor_remove_private_as_all_replace_as,
5611 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5612 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5613 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5614 "Remove private ASNs in outbound updates\n"
5615 "Apply to all AS numbers\n"
5616 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5617
28c6e247
IR
5618DEFUN (no_neighbor_remove_private_as,
5619 no_neighbor_remove_private_as_cmd,
5620 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5621 NO_STR
5622 NEIGHBOR_STR
5623 NEIGHBOR_ADDR_STR2
5624 "Remove private ASNs in outbound updates\n")
718e3744 5625{
d62a17ae 5626 int idx_peer = 2;
28c6e247
IR
5627 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5628 bgp_node_afi(vty), bgp_node_safi(vty),
5629 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5630}
6b0655a2 5631
d62a17ae 5632ALIAS_HIDDEN(no_neighbor_remove_private_as,
5633 no_neighbor_remove_private_as_hidden_cmd,
5634 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5635 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5636 "Remove private ASNs in outbound updates\n")
596c17ba 5637
28c6e247
IR
5638DEFUN (no_neighbor_remove_private_as_all,
5639 no_neighbor_remove_private_as_all_cmd,
5640 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5641 NO_STR
5642 NEIGHBOR_STR
5643 NEIGHBOR_ADDR_STR2
5644 "Remove private ASNs in outbound updates\n"
5645 "Apply to all AS numbers\n")
88b8ed8d 5646{
d62a17ae 5647 int idx_peer = 2;
28c6e247
IR
5648 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5649 bgp_node_afi(vty), bgp_node_safi(vty),
5650 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 5651}
5000f21c 5652
d62a17ae 5653ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5654 no_neighbor_remove_private_as_all_hidden_cmd,
5655 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5656 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5657 "Remove private ASNs in outbound updates\n"
5658 "Apply to all AS numbers\n")
596c17ba 5659
28c6e247
IR
5660DEFUN (no_neighbor_remove_private_as_replace_as,
5661 no_neighbor_remove_private_as_replace_as_cmd,
5662 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5663 NO_STR
5664 NEIGHBOR_STR
5665 NEIGHBOR_ADDR_STR2
5666 "Remove private ASNs in outbound updates\n"
5667 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5668{
d62a17ae 5669 int idx_peer = 2;
28c6e247
IR
5670 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5671 bgp_node_afi(vty), bgp_node_safi(vty),
5672 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 5673}
5000f21c 5674
d62a17ae 5675ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5676 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5677 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5678 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5679 "Remove private ASNs in outbound updates\n"
5680 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5681
28c6e247
IR
5682DEFUN (no_neighbor_remove_private_as_all_replace_as,
5683 no_neighbor_remove_private_as_all_replace_as_cmd,
5684 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5685 NO_STR
5686 NEIGHBOR_STR
5687 NEIGHBOR_ADDR_STR2
5688 "Remove private ASNs in outbound updates\n"
5689 "Apply to all AS numbers\n"
5690 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5691{
d62a17ae 5692 int idx_peer = 2;
28c6e247
IR
5693 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5694 bgp_node_afi(vty), bgp_node_safi(vty),
5695 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 5696}
5000f21c 5697
d62a17ae 5698ALIAS_HIDDEN(
5699 no_neighbor_remove_private_as_all_replace_as,
5700 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5701 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5702 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5703 "Remove private ASNs in outbound updates\n"
5704 "Apply to all AS numbers\n"
5705 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5706
5000f21c 5707
718e3744 5708/* neighbor send-community. */
28c6e247
IR
5709DEFUN (neighbor_send_community,
5710 neighbor_send_community_cmd,
5711 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5712 NEIGHBOR_STR
5713 NEIGHBOR_ADDR_STR2
5714 "Send Community attribute to this neighbor\n")
718e3744 5715{
d62a17ae 5716 int idx_peer = 1;
27c05d4d 5717
f63d4054
IR
5718 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5719 bgp_node_safi(vty),
5720 PEER_FLAG_SEND_COMMUNITY);
718e3744 5721}
5722
d62a17ae 5723ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5724 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5725 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5726 "Send Community attribute to this neighbor\n")
596c17ba 5727
28c6e247
IR
5728DEFUN (no_neighbor_send_community,
5729 no_neighbor_send_community_cmd,
5730 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5731 NO_STR
5732 NEIGHBOR_STR
5733 NEIGHBOR_ADDR_STR2
5734 "Send Community attribute to this neighbor\n")
718e3744 5735{
d62a17ae 5736 int idx_peer = 2;
27c05d4d 5737
f63d4054
IR
5738 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5739 bgp_node_afi(vty), bgp_node_safi(vty),
5740 PEER_FLAG_SEND_COMMUNITY);
718e3744 5741}
6b0655a2 5742
d62a17ae 5743ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5744 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5745 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5746 "Send Community attribute to this neighbor\n")
596c17ba 5747
718e3744 5748/* neighbor send-community extended. */
28c6e247
IR
5749DEFUN (neighbor_send_community_type,
5750 neighbor_send_community_type_cmd,
5751 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5752 NEIGHBOR_STR
5753 NEIGHBOR_ADDR_STR2
5754 "Send Community attribute to this neighbor\n"
5755 "Send Standard and Extended Community attributes\n"
5756 "Send Standard, Large and Extended Community attributes\n"
5757 "Send Extended Community attributes\n"
5758 "Send Standard Community attributes\n"
5759 "Send Large Community attributes\n")
718e3744 5760{
27c05d4d 5761 const char *type = argv[argc - 1]->text;
db45f64d 5762 char *peer_str = argv[1]->arg;
28c6e247 5763 struct peer *peer;
db45f64d 5764 afi_t afi = bgp_node_afi(vty);
28c6e247 5765 safi_t safi = bgp_node_safi(vty);
f4b8ec07 5766
28c6e247
IR
5767 peer = peer_and_group_lookup_vty(vty, peer_str);
5768 if (!peer)
5769 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07 5770
28c6e247
IR
5771 if (strmatch(type, "standard"))
5772 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5773 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 5774
28c6e247
IR
5775 if (strmatch(type, "extended"))
5776 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5777 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5778
28c6e247
IR
5779 if (strmatch(type, "large"))
5780 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5781 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07 5782
28c6e247
IR
5783 if (strmatch(type, "both")) {
5784 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5785 PEER_FLAG_SEND_COMMUNITY)
5786 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5787 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5788 }
28c6e247
IR
5789 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5790 PEER_FLAG_SEND_COMMUNITY)
5791 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5792 PEER_FLAG_SEND_EXT_COMMUNITY)
5793 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5794 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5795}
5796
5797ALIAS_HIDDEN(
5798 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5799 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5800 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5801 "Send Community attribute to this neighbor\n"
5802 "Send Standard and Extended Community attributes\n"
5803 "Send Standard, Large and Extended Community attributes\n"
5804 "Send Extended Community attributes\n"
5805 "Send Standard Community attributes\n"
5806 "Send Large Community attributes\n")
596c17ba 5807
28c6e247
IR
5808DEFUN (no_neighbor_send_community_type,
5809 no_neighbor_send_community_type_cmd,
5810 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5811 NO_STR
5812 NEIGHBOR_STR
5813 NEIGHBOR_ADDR_STR2
5814 "Send Community attribute to this neighbor\n"
5815 "Send Standard and Extended Community attributes\n"
5816 "Send Standard, Large and Extended Community attributes\n"
5817 "Send Extended Community attributes\n"
5818 "Send Standard Community attributes\n"
5819 "Send Large Community attributes\n")
718e3744 5820{
d62a17ae 5821 const char *type = argv[argc - 1]->text;
db45f64d 5822 char *peer_str = argv[2]->arg;
28c6e247 5823 struct peer *peer;
db45f64d
DS
5824 afi_t afi = bgp_node_afi(vty);
5825 safi_t safi = bgp_node_safi(vty);
5826
28c6e247
IR
5827 peer = peer_and_group_lookup_vty(vty, peer_str);
5828 if (!peer)
f4b8ec07
CS
5829 return CMD_WARNING_CONFIG_FAILED;
5830
28c6e247
IR
5831 if (strmatch(type, "standard"))
5832 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5833 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 5834
28c6e247
IR
5835 if (strmatch(type, "extended"))
5836 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5837 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5838
28c6e247
IR
5839 if (strmatch(type, "large"))
5840 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5841 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07
CS
5842
5843 if (strmatch(type, "both")) {
db45f64d 5844
28c6e247
IR
5845 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5846 PEER_FLAG_SEND_COMMUNITY)
5847 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5848 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
5849 }
5850
28c6e247
IR
5851 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5852 PEER_FLAG_SEND_COMMUNITY)
5853 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5854 PEER_FLAG_SEND_EXT_COMMUNITY)
5855 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5856 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5857}
5858
5859ALIAS_HIDDEN(
5860 no_neighbor_send_community_type,
5861 no_neighbor_send_community_type_hidden_cmd,
5862 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5863 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5864 "Send Community attribute to this neighbor\n"
5865 "Send Standard and Extended Community attributes\n"
5866 "Send Standard, Large and Extended Community attributes\n"
5867 "Send Extended Community attributes\n"
5868 "Send Standard Community attributes\n"
5869 "Send Large Community attributes\n")
596c17ba 5870
718e3744 5871/* neighbor soft-reconfig. */
28c6e247
IR
5872DEFUN (neighbor_soft_reconfiguration,
5873 neighbor_soft_reconfiguration_cmd,
5874 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5875 NEIGHBOR_STR
5876 NEIGHBOR_ADDR_STR2
5877 "Per neighbor soft reconfiguration\n"
5878 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 5879{
d62a17ae 5880 int idx_peer = 1;
28c6e247
IR
5881 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5882 bgp_node_safi(vty),
5883 PEER_FLAG_SOFT_RECONFIG);
718e3744 5884}
5885
d62a17ae 5886ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5887 neighbor_soft_reconfiguration_hidden_cmd,
5888 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5889 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5890 "Per neighbor soft reconfiguration\n"
5891 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5892
28c6e247
IR
5893DEFUN (no_neighbor_soft_reconfiguration,
5894 no_neighbor_soft_reconfiguration_cmd,
5895 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5896 NO_STR
5897 NEIGHBOR_STR
5898 NEIGHBOR_ADDR_STR2
5899 "Per neighbor soft reconfiguration\n"
5900 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 5901{
d62a17ae 5902 int idx_peer = 2;
28c6e247
IR
5903 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5904 bgp_node_afi(vty), bgp_node_safi(vty),
5905 PEER_FLAG_SOFT_RECONFIG);
718e3744 5906}
6b0655a2 5907
d62a17ae 5908ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5909 no_neighbor_soft_reconfiguration_hidden_cmd,
5910 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5911 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5912 "Per neighbor soft reconfiguration\n"
5913 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5914
28c6e247
IR
5915DEFUN (neighbor_route_reflector_client,
5916 neighbor_route_reflector_client_cmd,
5917 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5918 NEIGHBOR_STR
5919 NEIGHBOR_ADDR_STR2
5920 "Configure a neighbor as Route Reflector client\n")
718e3744 5921{
d62a17ae 5922 int idx_peer = 1;
28c6e247 5923 struct peer *peer;
718e3744 5924
5925
28c6e247
IR
5926 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5927 if (!peer)
d62a17ae 5928 return CMD_WARNING_CONFIG_FAILED;
718e3744 5929
28c6e247
IR
5930 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5931 bgp_node_safi(vty),
5932 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5933}
5934
d62a17ae 5935ALIAS_HIDDEN(neighbor_route_reflector_client,
5936 neighbor_route_reflector_client_hidden_cmd,
5937 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5938 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5939 "Configure a neighbor as Route Reflector client\n")
596c17ba 5940
28c6e247
IR
5941DEFUN (no_neighbor_route_reflector_client,
5942 no_neighbor_route_reflector_client_cmd,
5943 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5944 NO_STR
5945 NEIGHBOR_STR
5946 NEIGHBOR_ADDR_STR2
5947 "Configure a neighbor as Route Reflector client\n")
718e3744 5948{
d62a17ae 5949 int idx_peer = 2;
28c6e247
IR
5950 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5951 bgp_node_afi(vty), bgp_node_safi(vty),
5952 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5953}
6b0655a2 5954
d62a17ae 5955ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5956 no_neighbor_route_reflector_client_hidden_cmd,
5957 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5958 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5959 "Configure a neighbor as Route Reflector client\n")
596c17ba 5960
718e3744 5961/* neighbor route-server-client. */
28c6e247
IR
5962DEFUN (neighbor_route_server_client,
5963 neighbor_route_server_client_cmd,
5964 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5965 NEIGHBOR_STR
5966 NEIGHBOR_ADDR_STR2
5967 "Configure a neighbor as Route Server client\n")
718e3744 5968{
d62a17ae 5969 int idx_peer = 1;
28c6e247 5970 struct peer *peer;
f4b8ec07 5971
28c6e247
IR
5972 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5973 if (!peer)
d62a17ae 5974 return CMD_WARNING_CONFIG_FAILED;
28c6e247
IR
5975 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5976 bgp_node_safi(vty),
5977 PEER_FLAG_RSERVER_CLIENT);
718e3744 5978}
5979
d62a17ae 5980ALIAS_HIDDEN(neighbor_route_server_client,
5981 neighbor_route_server_client_hidden_cmd,
5982 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5983 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5984 "Configure a neighbor as Route Server client\n")
596c17ba 5985
28c6e247
IR
5986DEFUN (no_neighbor_route_server_client,
5987 no_neighbor_route_server_client_cmd,
5988 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5989 NO_STR
5990 NEIGHBOR_STR
5991 NEIGHBOR_ADDR_STR2
5992 "Configure a neighbor as Route Server client\n")
fee0f4c6 5993{
d62a17ae 5994 int idx_peer = 2;
28c6e247
IR
5995 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5996 bgp_node_afi(vty), bgp_node_safi(vty),
5997 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 5998}
6b0655a2 5999
d62a17ae 6000ALIAS_HIDDEN(no_neighbor_route_server_client,
6001 no_neighbor_route_server_client_hidden_cmd,
6002 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6003 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6004 "Configure a neighbor as Route Server client\n")
596c17ba 6005
fee0f4c6 6006DEFUN (neighbor_nexthop_local_unchanged,
6007 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6008 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6009 NEIGHBOR_STR
6010 NEIGHBOR_ADDR_STR2
6011 "Configure treatment of outgoing link-local nexthop attribute\n"
6012 "Leave link-local nexthop unchanged for this peer\n")
6013{
d62a17ae 6014 int idx_peer = 1;
6015 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6016 bgp_node_safi(vty),
6017 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6018}
6b0655a2 6019
fee0f4c6 6020DEFUN (no_neighbor_nexthop_local_unchanged,
6021 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6022 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6023 NO_STR
6024 NEIGHBOR_STR
6025 NEIGHBOR_ADDR_STR2
6026 "Configure treatment of outgoing link-local-nexthop attribute\n"
6027 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6028{
d62a17ae 6029 int idx_peer = 2;
6030 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6031 bgp_node_afi(vty), bgp_node_safi(vty),
6032 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6033}
6b0655a2 6034
28c6e247
IR
6035DEFUN (neighbor_attr_unchanged,
6036 neighbor_attr_unchanged_cmd,
6037 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6038 NEIGHBOR_STR
6039 NEIGHBOR_ADDR_STR2
6040 "BGP attribute is propagated unchanged to this neighbor\n"
6041 "As-path attribute\n"
6042 "Nexthop attribute\n"
6043 "Med attribute\n")
718e3744 6044{
d62a17ae 6045 int idx = 0;
8eeb0335 6046 char *peer_str = argv[1]->arg;
28c6e247 6047 struct peer *peer;
db45f64d
DS
6048 bool aspath = false;
6049 bool nexthop = false;
6050 bool med = false;
8eeb0335
DW
6051 afi_t afi = bgp_node_afi(vty);
6052 safi_t safi = bgp_node_safi(vty);
28c6e247 6053 int ret = 0;
f4b8ec07 6054
28c6e247
IR
6055 peer = peer_and_group_lookup_vty(vty, peer_str);
6056 if (!peer)
8eeb0335 6057 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6058
6059 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6060 aspath = true;
6061
d62a17ae 6062 idx = 0;
6063 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6064 nexthop = true;
6065
d62a17ae 6066 idx = 0;
6067 if (argv_find(argv, argc, "med", &idx))
db45f64d 6068 med = true;
d62a17ae 6069
8eeb0335 6070 /* no flags means all of them! */
db45f64d 6071 if (!aspath && !nexthop && !med) {
28c6e247
IR
6072 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6073 PEER_FLAG_AS_PATH_UNCHANGED);
6074 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6075 PEER_FLAG_NEXTHOP_UNCHANGED);
6076 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6077 PEER_FLAG_MED_UNCHANGED);
8eeb0335 6078 } else {
28c6e247
IR
6079 if (!aspath) {
6080 if (peer_af_flag_check(peer, afi, safi,
6081 PEER_FLAG_AS_PATH_UNCHANGED)) {
6082 ret |= peer_af_flag_unset_vty(
6083 vty, peer_str, afi, safi,
6084 PEER_FLAG_AS_PATH_UNCHANGED);
6085 }
6086 } else
6087 ret |= peer_af_flag_set_vty(
6088 vty, peer_str, afi, safi,
6089 PEER_FLAG_AS_PATH_UNCHANGED);
6090
6091 if (!nexthop) {
6092 if (peer_af_flag_check(peer, afi, safi,
6093 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6094 ret |= peer_af_flag_unset_vty(
6095 vty, peer_str, afi, safi,
6096 PEER_FLAG_NEXTHOP_UNCHANGED);
6097 }
6098 } else
6099 ret |= peer_af_flag_set_vty(
6100 vty, peer_str, afi, safi,
6101 PEER_FLAG_NEXTHOP_UNCHANGED);
6102
6103 if (!med) {
6104 if (peer_af_flag_check(peer, afi, safi,
6105 PEER_FLAG_MED_UNCHANGED)) {
6106 ret |= peer_af_flag_unset_vty(
6107 vty, peer_str, afi, safi,
6108 PEER_FLAG_MED_UNCHANGED);
6109 }
6110 } else
6111 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6112 PEER_FLAG_MED_UNCHANGED);
d62a17ae 6113 }
6114
28c6e247 6115 return ret;
d62a17ae 6116}
6117
6118ALIAS_HIDDEN(
6119 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6120 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6121 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6122 "BGP attribute is propagated unchanged to this neighbor\n"
6123 "As-path attribute\n"
6124 "Nexthop attribute\n"
6125 "Med attribute\n")
596c17ba 6126
28c6e247
IR
6127DEFUN (no_neighbor_attr_unchanged,
6128 no_neighbor_attr_unchanged_cmd,
6129 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6130 NO_STR
6131 NEIGHBOR_STR
6132 NEIGHBOR_ADDR_STR2
6133 "BGP attribute is propagated unchanged to this neighbor\n"
6134 "As-path attribute\n"
6135 "Nexthop attribute\n"
6136 "Med attribute\n")
718e3744 6137{
d62a17ae 6138 int idx = 0;
db45f64d 6139 char *peer_str = argv[2]->arg;
28c6e247 6140 struct peer *peer;
db45f64d
DS
6141 bool aspath = false;
6142 bool nexthop = false;
6143 bool med = false;
6144 afi_t afi = bgp_node_afi(vty);
6145 safi_t safi = bgp_node_safi(vty);
28c6e247 6146 int ret = 0;
f4b8ec07 6147
28c6e247
IR
6148 peer = peer_and_group_lookup_vty(vty, peer_str);
6149 if (!peer)
db45f64d 6150 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6151
6152 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6153 aspath = true;
6154
d62a17ae 6155 idx = 0;
6156 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6157 nexthop = true;
6158
d62a17ae 6159 idx = 0;
6160 if (argv_find(argv, argc, "med", &idx))
db45f64d 6161 med = true;
d62a17ae 6162
28c6e247
IR
6163 if (!aspath && !nexthop && !med) // no flags means all of them!
6164 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6165 PEER_FLAG_AS_PATH_UNCHANGED)
6166 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6167 PEER_FLAG_NEXTHOP_UNCHANGED)
6168 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6169 PEER_FLAG_MED_UNCHANGED);
db45f64d
DS
6170
6171 if (aspath)
28c6e247
IR
6172 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6173 PEER_FLAG_AS_PATH_UNCHANGED);
db45f64d
DS
6174
6175 if (nexthop)
28c6e247
IR
6176 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6177 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 6178
db45f64d 6179 if (med)
28c6e247
IR
6180 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6181 PEER_FLAG_MED_UNCHANGED);
db45f64d 6182
28c6e247 6183 return ret;
d62a17ae 6184}
6185
6186ALIAS_HIDDEN(
6187 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6188 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6189 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6190 "BGP attribute is propagated unchanged to this neighbor\n"
6191 "As-path attribute\n"
6192 "Nexthop attribute\n"
6193 "Med attribute\n")
718e3744 6194
28c6e247
IR
6195/* EBGP multihop configuration. */
6196static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6197 const char *ttl_str)
718e3744 6198{
28c6e247
IR
6199 struct peer *peer;
6200 unsigned int ttl;
718e3744 6201
28c6e247
IR
6202 peer = peer_and_group_lookup_vty(vty, ip_str);
6203 if (!peer)
d62a17ae 6204 return CMD_WARNING_CONFIG_FAILED;
718e3744 6205
28c6e247
IR
6206 if (peer->conf_if)
6207 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6208
6209 if (!ttl_str)
6210 ttl = MAXTTL;
6211 else
6212 ttl = strtoul(ttl_str, NULL, 10);
718e3744 6213
28c6e247 6214 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 6215}
6216
28c6e247 6217static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6218{
28c6e247 6219 struct peer *peer;
718e3744 6220
28c6e247
IR
6221 peer = peer_and_group_lookup_vty(vty, ip_str);
6222 if (!peer)
d62a17ae 6223 return CMD_WARNING_CONFIG_FAILED;
718e3744 6224
28c6e247 6225 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 6226}
6227
28c6e247
IR
6228/* neighbor ebgp-multihop. */
6229DEFUN (neighbor_ebgp_multihop,
6230 neighbor_ebgp_multihop_cmd,
6231 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6232 NEIGHBOR_STR
6233 NEIGHBOR_ADDR_STR2
6234 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6235{
28c6e247
IR
6236 int idx_peer = 1;
6237 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6238}
f4b8ec07 6239
28c6e247
IR
6240DEFUN (neighbor_ebgp_multihop_ttl,
6241 neighbor_ebgp_multihop_ttl_cmd,
6242 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6243 NEIGHBOR_STR
6244 NEIGHBOR_ADDR_STR2
6245 "Allow EBGP neighbors not on directly connected networks\n"
6246 "maximum hop count\n")
6247{
6248 int idx_peer = 1;
6249 int idx_number = 3;
6250 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6251 argv[idx_number]->arg);
6252}
f4b8ec07 6253
28c6e247
IR
6254DEFUN (no_neighbor_ebgp_multihop,
6255 no_neighbor_ebgp_multihop_cmd,
6256 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6257 NO_STR
6258 NEIGHBOR_STR
6259 NEIGHBOR_ADDR_STR2
6260 "Allow EBGP neighbors not on directly connected networks\n"
6261 "maximum hop count\n")
6262{
6263 int idx_peer = 2;
6264 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6265}
6266
6b0655a2 6267
6ffd2079 6268/* disable-connected-check */
28c6e247
IR
6269DEFUN (neighbor_disable_connected_check,
6270 neighbor_disable_connected_check_cmd,
6271 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6272 NEIGHBOR_STR
6273 NEIGHBOR_ADDR_STR2
6274 "one-hop away EBGP peer using loopback address\n"
6275 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6276{
d62a17ae 6277 int idx_peer = 1;
28c6e247
IR
6278 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6279 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6280}
6281
28c6e247
IR
6282DEFUN (no_neighbor_disable_connected_check,
6283 no_neighbor_disable_connected_check_cmd,
6284 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6285 NO_STR
6286 NEIGHBOR_STR
6287 NEIGHBOR_ADDR_STR2
6288 "one-hop away EBGP peer using loopback address\n"
6289 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6290{
d62a17ae 6291 int idx_peer = 2;
28c6e247
IR
6292 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6293 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6294}
6295
7ab294ea
DA
6296/* disable-link-bw-encoding-ieee */
6297DEFUN(neighbor_disable_link_bw_encoding_ieee,
6298 neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6299 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6300 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6301 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6302{
6303 int idx_peer = 1;
6304
6305 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6306 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6307}
6308
7ab294ea
DA
6309DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6310 no_neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6311 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6312 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6313 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6314{
6315 int idx_peer = 2;
6316
6317 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6318 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6319}
6320
d08c0c80
DA
6321/* extended-optional-parameters */
6322DEFUN(neighbor_extended_optional_parameters,
6323 neighbor_extended_optional_parameters_cmd,
6324 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6325 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6326 "Force the extended optional parameters format for OPEN messages\n")
6327{
6328 int idx_peer = 1;
6329
6330 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6331 PEER_FLAG_EXTENDED_OPT_PARAMS);
6332}
6333
6334DEFUN(no_neighbor_extended_optional_parameters,
6335 no_neighbor_extended_optional_parameters_cmd,
6336 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6337 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6338 "Force the extended optional parameters format for OPEN messages\n")
6339{
6340 int idx_peer = 2;
6341
6342 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6343 PEER_FLAG_EXTENDED_OPT_PARAMS);
6344}
47cbc09b
PM
6345
6346/* enforce-first-as */
28c6e247
IR
6347DEFUN (neighbor_enforce_first_as,
6348 neighbor_enforce_first_as_cmd,
6349 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6350 NEIGHBOR_STR
6351 NEIGHBOR_ADDR_STR2
6352 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6353{
6354 int idx_peer = 1;
f4b8ec07 6355
28c6e247
IR
6356 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6357 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6358}
6359
28c6e247
IR
6360DEFUN (no_neighbor_enforce_first_as,
6361 no_neighbor_enforce_first_as_cmd,
6362 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6363 NO_STR
6364 NEIGHBOR_STR
6365 NEIGHBOR_ADDR_STR2
6366 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6367{
6368 int idx_peer = 2;
f4b8ec07 6369
28c6e247
IR
6370 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6371 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6372}
6373
6374
28c6e247
IR
6375DEFUN (neighbor_description,
6376 neighbor_description_cmd,
6377 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6378 NEIGHBOR_STR
6379 NEIGHBOR_ADDR_STR2
6380 "Neighbor specific description\n"
6381 "Up to 80 characters describing this neighbor\n")
718e3744 6382{
d62a17ae 6383 int idx_peer = 1;
6384 int idx_line = 3;
28c6e247 6385 struct peer *peer;
d62a17ae 6386 char *str;
718e3744 6387
28c6e247
IR
6388 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6389 if (!peer)
d62a17ae 6390 return CMD_WARNING_CONFIG_FAILED;
718e3744 6391
d62a17ae 6392 str = argv_concat(argv, argc, idx_line);
718e3744 6393
28c6e247 6394 peer_description_set(peer, str);
718e3744 6395
d62a17ae 6396 XFREE(MTYPE_TMP, str);
718e3744 6397
28c6e247 6398 return CMD_SUCCESS;
718e3744 6399}
6400
28c6e247
IR
6401DEFUN (no_neighbor_description,
6402 no_neighbor_description_cmd,
6403 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6404 NO_STR
6405 NEIGHBOR_STR
6406 NEIGHBOR_ADDR_STR2
6407 "Neighbor specific description\n")
718e3744 6408{
d62a17ae 6409 int idx_peer = 2;
28c6e247 6410 struct peer *peer;
f4b8ec07 6411
28c6e247
IR
6412 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6413 if (!peer)
d62a17ae 6414 return CMD_WARNING_CONFIG_FAILED;
718e3744 6415
28c6e247 6416 peer_description_unset(peer);
718e3744 6417
28c6e247 6418 return CMD_SUCCESS;
718e3744 6419}
6420
1d80f243 6421ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
6422 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6423 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6424 "Neighbor specific description\n"
6425 "Up to 80 characters describing this neighbor\n")
6b0655a2 6426
28c6e247
IR
6427/* Neighbor update-source. */
6428static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6429 const char *source_str)
6430{
6431 struct peer *peer;
6432 struct prefix p;
6433 union sockunion su;
6434
6435 peer = peer_and_group_lookup_vty(vty, peer_str);
6436 if (!peer)
6437 return CMD_WARNING_CONFIG_FAILED;
6438
6439 if (peer->conf_if)
6440 return CMD_WARNING;
6441
6442 if (source_str) {
6443 if (str2sockunion(source_str, &su) == 0)
6444 peer_update_source_addr_set(peer, &su);
6445 else {
6446 if (str2prefix(source_str, &p)) {
6447 vty_out(vty,
6448 "%% Invalid update-source, remove prefix length \n");
6449 return CMD_WARNING_CONFIG_FAILED;
6450 } else
6451 peer_update_source_if_set(peer, source_str);
6452 }
6453 } else
6454 peer_update_source_unset(peer);
6455
6456 return CMD_SUCCESS;
6457}
6458
d62a17ae 6459#define BGP_UPDATE_SOURCE_HELP_STR \
6460 "IPv4 address\n" \
6461 "IPv6 address\n" \
6462 "Interface name (requires zebra to be running)\n"
369688c0 6463
28c6e247
IR
6464DEFUN (neighbor_update_source,
6465 neighbor_update_source_cmd,
6466 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6467 NEIGHBOR_STR
6468 NEIGHBOR_ADDR_STR2
6469 "Source of routing updates\n"
6470 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6471{
d62a17ae 6472 int idx_peer = 1;
6473 int idx_peer_2 = 3;
28c6e247 6474 return peer_update_source_vty(vty, argv[idx_peer]->arg,
d62a17ae 6475 argv[idx_peer_2]->arg);
718e3744 6476}
6477
28c6e247
IR
6478DEFUN (no_neighbor_update_source,
6479 no_neighbor_update_source_cmd,
6480 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6481 NO_STR
6482 NEIGHBOR_STR
6483 NEIGHBOR_ADDR_STR2
6484 "Source of routing updates\n"
6485 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6486{
d62a17ae 6487 int idx_peer = 2;
28c6e247 6488 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6489}
6b0655a2 6490
d62a17ae 6491static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6492 afi_t afi, safi_t safi,
6493 const char *rmap, int set)
718e3744 6494{
d62a17ae 6495 int ret;
6496 struct peer *peer;
80912664 6497 struct route_map *route_map = NULL;
718e3744 6498
d62a17ae 6499 peer = peer_and_group_lookup_vty(vty, peer_str);
6500 if (!peer)
6501 return CMD_WARNING_CONFIG_FAILED;
718e3744 6502
1de27621 6503 if (set) {
80912664
DS
6504 if (rmap)
6505 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
6506 ret = peer_default_originate_set(peer, afi, safi,
6507 rmap, route_map);
6508 } else
d62a17ae 6509 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 6510
d62a17ae 6511 return bgp_vty_return(vty, ret);
718e3744 6512}
6513
6514/* neighbor default-originate. */
6515DEFUN (neighbor_default_originate,
6516 neighbor_default_originate_cmd,
9ccf14f7 6517 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 6518 NEIGHBOR_STR
6519 NEIGHBOR_ADDR_STR2
6520 "Originate default route to this neighbor\n")
6521{
d62a17ae 6522 int idx_peer = 1;
6523 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6524 bgp_node_afi(vty),
6525 bgp_node_safi(vty), NULL, 1);
718e3744 6526}
6527
d62a17ae 6528ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6529 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6530 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6531 "Originate default route to this neighbor\n")
596c17ba 6532
718e3744 6533DEFUN (neighbor_default_originate_rmap,
6534 neighbor_default_originate_rmap_cmd,
9ccf14f7 6535 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 6536 NEIGHBOR_STR
6537 NEIGHBOR_ADDR_STR2
6538 "Originate default route to this neighbor\n"
6539 "Route-map to specify criteria to originate default\n"
6540 "route-map name\n")
6541{
d62a17ae 6542 int idx_peer = 1;
6543 int idx_word = 4;
6544 return peer_default_originate_set_vty(
6545 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6546 argv[idx_word]->arg, 1);
718e3744 6547}
6548
d62a17ae 6549ALIAS_HIDDEN(
6550 neighbor_default_originate_rmap,
6551 neighbor_default_originate_rmap_hidden_cmd,
6552 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6553 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6554 "Originate default route to this neighbor\n"
6555 "Route-map to specify criteria to originate default\n"
6556 "route-map name\n")
596c17ba 6557
718e3744 6558DEFUN (no_neighbor_default_originate,
6559 no_neighbor_default_originate_cmd,
a636c635 6560 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 6561 NO_STR
6562 NEIGHBOR_STR
6563 NEIGHBOR_ADDR_STR2
a636c635
DW
6564 "Originate default route to this neighbor\n"
6565 "Route-map to specify criteria to originate default\n"
6566 "route-map name\n")
718e3744 6567{
d62a17ae 6568 int idx_peer = 2;
6569 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6570 bgp_node_afi(vty),
6571 bgp_node_safi(vty), NULL, 0);
718e3744 6572}
6573
d62a17ae 6574ALIAS_HIDDEN(
6575 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6576 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6577 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6578 "Originate default route to this neighbor\n"
6579 "Route-map to specify criteria to originate default\n"
6580 "route-map name\n")
596c17ba 6581
6b0655a2 6582
28c6e247
IR
6583/* Set neighbor's BGP port. */
6584static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6585 const char *port_str)
718e3744 6586{
28c6e247
IR
6587 struct peer *peer;
6588 uint16_t port;
6589 struct servent *sp;
6590
6591 peer = peer_lookup_vty(vty, ip_str);
6592 if (!peer)
6593 return CMD_WARNING_CONFIG_FAILED;
6594
6595 if (!port_str) {
6596 sp = getservbyname("bgp", "tcp");
6597 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6598 } else {
6599 port = strtoul(port_str, NULL, 10);
6600 }
718e3744 6601
28c6e247 6602 peer_port_set(peer, port);
718e3744 6603
28c6e247
IR
6604 return CMD_SUCCESS;
6605}
f4b8ec07 6606
28c6e247
IR
6607/* Set specified peer's BGP port. */
6608DEFUN (neighbor_port,
6609 neighbor_port_cmd,
6610 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
6611 NEIGHBOR_STR
6612 NEIGHBOR_ADDR_STR
6613 "Neighbor's BGP port\n"
6614 "TCP port number\n")
6615{
6616 int idx_ip = 1;
6617 int idx_number = 3;
6618 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6619 argv[idx_number]->arg);
f4b8ec07 6620}
6b0655a2 6621
28c6e247
IR
6622DEFUN (no_neighbor_port,
6623 no_neighbor_port_cmd,
6624 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
6625 NO_STR
6626 NEIGHBOR_STR
6627 NEIGHBOR_ADDR_STR
6628 "Neighbor's BGP port\n"
6629 "TCP port number\n")
718e3744 6630{
f4b8ec07 6631 int idx_ip = 2;
28c6e247
IR
6632 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6633}
6634
6635
6636/* neighbor weight. */
6637static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6638 safi_t safi, const char *weight_str)
6639{
6640 int ret;
6641 struct peer *peer;
6642 unsigned long weight;
718e3744 6643
28c6e247
IR
6644 peer = peer_and_group_lookup_vty(vty, ip_str);
6645 if (!peer)
6646 return CMD_WARNING_CONFIG_FAILED;
718e3744 6647
28c6e247 6648 weight = strtoul(weight_str, NULL, 10);
718e3744 6649
28c6e247
IR
6650 ret = peer_weight_set(peer, afi, safi, weight);
6651 return bgp_vty_return(vty, ret);
718e3744 6652}
6653
28c6e247
IR
6654static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6655 safi_t safi)
718e3744 6656{
28c6e247
IR
6657 int ret;
6658 struct peer *peer;
f4b8ec07 6659
28c6e247
IR
6660 peer = peer_and_group_lookup_vty(vty, ip_str);
6661 if (!peer)
d62a17ae 6662 return CMD_WARNING_CONFIG_FAILED;
718e3744 6663
28c6e247
IR
6664 ret = peer_weight_unset(peer, afi, safi);
6665 return bgp_vty_return(vty, ret);
6666}
f4b8ec07 6667
28c6e247
IR
6668DEFUN (neighbor_weight,
6669 neighbor_weight_cmd,
6670 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6671 NEIGHBOR_STR
6672 NEIGHBOR_ADDR_STR2
6673 "Set default weight for routes from this neighbor\n"
6674 "default weight\n")
6675{
6676 int idx_peer = 1;
6677 int idx_number = 3;
6678 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6679 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 6680}
6681
d62a17ae 6682ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6683 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6684 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6685 "Set default weight for routes from this neighbor\n"
6686 "default weight\n")
596c17ba 6687
28c6e247
IR
6688DEFUN (no_neighbor_weight,
6689 no_neighbor_weight_cmd,
6690 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6691 NO_STR
6692 NEIGHBOR_STR
6693 NEIGHBOR_ADDR_STR2
6694 "Set default weight for routes from this neighbor\n"
6695 "default weight\n")
718e3744 6696{
d62a17ae 6697 int idx_peer = 2;
28c6e247
IR
6698 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6699 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 6700}
6701
d62a17ae 6702ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6703 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6704 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6705 "Set default weight for routes from this neighbor\n"
6706 "default weight\n")
596c17ba 6707
6b0655a2 6708
718e3744 6709/* Override capability negotiation. */
c36bc05f
IR
6710DEFUN (neighbor_override_capability,
6711 neighbor_override_capability_cmd,
6712 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6713 NEIGHBOR_STR
6714 NEIGHBOR_ADDR_STR2
6715 "Override capability negotiation result\n")
718e3744 6716{
d62a17ae 6717 int idx_peer = 1;
c36bc05f
IR
6718 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6719 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6720}
6721
c36bc05f
IR
6722DEFUN (no_neighbor_override_capability,
6723 no_neighbor_override_capability_cmd,
6724 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6725 NO_STR
6726 NEIGHBOR_STR
6727 NEIGHBOR_ADDR_STR2
6728 "Override capability negotiation result\n")
718e3744 6729{
d62a17ae 6730 int idx_peer = 2;
c36bc05f
IR
6731 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6732 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6733}
6b0655a2 6734
c36bc05f
IR
6735DEFUN (neighbor_strict_capability,
6736 neighbor_strict_capability_cmd,
6737 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6738 NEIGHBOR_STR
6739 NEIGHBOR_ADDR_STR2
6740 "Strict capability negotiation match\n")
718e3744 6741{
9fb964de
PM
6742 int idx_peer = 1;
6743
c36bc05f
IR
6744 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6745 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6746}
6747
c36bc05f
IR
6748DEFUN (no_neighbor_strict_capability,
6749 no_neighbor_strict_capability_cmd,
6750 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6751 NO_STR
6752 NEIGHBOR_STR
6753 NEIGHBOR_ADDR_STR2
6754 "Strict capability negotiation match\n")
718e3744 6755{
9fb964de 6756 int idx_peer = 2;
8611c7f3 6757
c36bc05f
IR
6758 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6759 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6760}
6b0655a2 6761
28c6e247
IR
6762static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6763 const char *keep_str, const char *hold_str)
718e3744 6764{
28c6e247
IR
6765 int ret;
6766 struct peer *peer;
6767 uint32_t keepalive;
6768 uint32_t holdtime;
718e3744 6769
28c6e247
IR
6770 peer = peer_and_group_lookup_vty(vty, ip_str);
6771 if (!peer)
d62a17ae 6772 return CMD_WARNING_CONFIG_FAILED;
718e3744 6773
28c6e247
IR
6774 keepalive = strtoul(keep_str, NULL, 10);
6775 holdtime = strtoul(hold_str, NULL, 10);
718e3744 6776
28c6e247 6777 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 6778
28c6e247 6779 return bgp_vty_return(vty, ret);
718e3744 6780}
6b0655a2 6781
28c6e247 6782static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6783{
28c6e247
IR
6784 int ret;
6785 struct peer *peer;
718e3744 6786
28c6e247
IR
6787 peer = peer_and_group_lookup_vty(vty, ip_str);
6788 if (!peer)
d62a17ae 6789 return CMD_WARNING_CONFIG_FAILED;
718e3744 6790
28c6e247 6791 ret = peer_timers_unset(peer);
718e3744 6792
28c6e247 6793 return bgp_vty_return(vty, ret);
718e3744 6794}
6b0655a2 6795
28c6e247
IR
6796DEFUN (neighbor_timers,
6797 neighbor_timers_cmd,
6798 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
6799 NEIGHBOR_STR
6800 NEIGHBOR_ADDR_STR2
6801 "BGP per neighbor timers\n"
6802 "Keepalive interval\n"
6803 "Holdtime\n")
718e3744 6804{
f4b8ec07 6805 int idx_peer = 1;
28c6e247
IR
6806 int idx_number = 3;
6807 int idx_number_2 = 4;
6808 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6809 argv[idx_number]->arg,
6810 argv[idx_number_2]->arg);
6811}
6812
6813DEFUN (no_neighbor_timers,
6814 no_neighbor_timers_cmd,
6815 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
6816 NO_STR
6817 NEIGHBOR_STR
6818 NEIGHBOR_ADDR_STR2
6819 "BGP per neighbor timers\n"
6820 "Keepalive interval\n"
6821 "Holdtime\n")
6822{
6823 int idx_peer = 2;
6824 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
6825}
6826
6827
6828static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6829 const char *time_str)
6830{
6831 int ret;
6832 struct peer *peer;
6833 uint32_t connect;
718e3744 6834
28c6e247
IR
6835 peer = peer_and_group_lookup_vty(vty, ip_str);
6836 if (!peer)
d62a17ae 6837 return CMD_WARNING_CONFIG_FAILED;
718e3744 6838
28c6e247
IR
6839 connect = strtoul(time_str, NULL, 10);
6840
6841 ret = peer_timers_connect_set(peer, connect);
718e3744 6842
28c6e247 6843 return bgp_vty_return(vty, ret);
718e3744 6844}
6845
28c6e247 6846static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6847{
28c6e247
IR
6848 int ret;
6849 struct peer *peer;
718e3744 6850
28c6e247
IR
6851 peer = peer_and_group_lookup_vty(vty, ip_str);
6852 if (!peer)
d62a17ae 6853 return CMD_WARNING_CONFIG_FAILED;
718e3744 6854
28c6e247
IR
6855 ret = peer_timers_connect_unset(peer);
6856
6857 return bgp_vty_return(vty, ret);
6858}
6859
6860DEFUN (neighbor_timers_connect,
6861 neighbor_timers_connect_cmd,
6862 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
6863 NEIGHBOR_STR
6864 NEIGHBOR_ADDR_STR2
6865 "BGP per neighbor timers\n"
6866 "BGP connect timer\n"
6867 "Connect timer\n")
6868{
6869 int idx_peer = 1;
6870 int idx_number = 4;
6871 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6872 argv[idx_number]->arg);
6873}
718e3744 6874
28c6e247
IR
6875DEFUN (no_neighbor_timers_connect,
6876 no_neighbor_timers_connect_cmd,
6877 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
6878 NO_STR
6879 NEIGHBOR_STR
6880 NEIGHBOR_ADDR_STR2
6881 "BGP per neighbor timers\n"
6882 "BGP connect timer\n"
6883 "Connect timer\n")
6884{
6885 int idx_peer = 2;
6886 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6887}
6888
d43114f3
DS
6889DEFPY (neighbor_timers_delayopen,
6890 neighbor_timers_delayopen_cmd,
6891 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
6892 NEIGHBOR_STR
6893 NEIGHBOR_ADDR_STR2
6894 "BGP per neighbor timers\n"
6895 "RFC 4271 DelayOpenTimer\n"
6896 "DelayOpenTime timer interval\n")
6897{
6898 struct peer *peer;
6899
6900 peer = peer_and_group_lookup_vty(vty, neighbor);
6901 if (!peer)
6902 return CMD_WARNING_CONFIG_FAILED;
6903
6904 if (!interval) {
6905 if (peer_timers_delayopen_unset(peer))
6906 return CMD_WARNING_CONFIG_FAILED;
6907 } else {
6908 if (peer_timers_delayopen_set(peer, interval))
6909 return CMD_WARNING_CONFIG_FAILED;
6910 }
6911
6912 return CMD_SUCCESS;
6913}
6914
6915DEFPY (no_neighbor_timers_delayopen,
6916 no_neighbor_timers_delayopen_cmd,
6917 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
6918 NO_STR
6919 NEIGHBOR_STR
6920 NEIGHBOR_ADDR_STR2
6921 "BGP per neighbor timers\n"
6922 "RFC 4271 DelayOpenTimer\n"
6923 "DelayOpenTime timer interval\n")
6924{
6925 struct peer *peer;
6926
6927 peer = peer_and_group_lookup_vty(vty, neighbor);
6928 if (!peer)
6929 return CMD_WARNING_CONFIG_FAILED;
6930
6931 if (peer_timers_delayopen_unset(peer))
6932 return CMD_WARNING_CONFIG_FAILED;
6933
6934 return CMD_SUCCESS;
6935}
6936
28c6e247
IR
6937static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
6938 const char *time_str, int set)
718e3744 6939{
28c6e247
IR
6940 int ret;
6941 struct peer *peer;
6942 uint32_t routeadv = 0;
718e3744 6943
28c6e247
IR
6944 peer = peer_and_group_lookup_vty(vty, ip_str);
6945 if (!peer)
d62a17ae 6946 return CMD_WARNING_CONFIG_FAILED;
718e3744 6947
28c6e247
IR
6948 if (time_str)
6949 routeadv = strtoul(time_str, NULL, 10);
6950
6951 if (set)
6952 ret = peer_advertise_interval_set(peer, routeadv);
6953 else
6954 ret = peer_advertise_interval_unset(peer);
718e3744 6955
28c6e247 6956 return bgp_vty_return(vty, ret);
718e3744 6957}
6958
28c6e247
IR
6959DEFUN (neighbor_advertise_interval,
6960 neighbor_advertise_interval_cmd,
6961 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
6962 NEIGHBOR_STR
6963 NEIGHBOR_ADDR_STR2
6964 "Minimum interval between sending BGP routing updates\n"
6965 "time in seconds\n")
718e3744 6966{
28c6e247
IR
6967 int idx_peer = 1;
6968 int idx_number = 3;
6969 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
6970 argv[idx_number]->arg, 1);
6971}
f4b8ec07 6972
28c6e247
IR
6973DEFUN (no_neighbor_advertise_interval,
6974 no_neighbor_advertise_interval_cmd,
6975 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
6976 NO_STR
6977 NEIGHBOR_STR
6978 NEIGHBOR_ADDR_STR2
6979 "Minimum interval between sending BGP routing updates\n"
6980 "time in seconds\n")
6981{
6982 int idx_peer = 2;
6983 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 6984}
6985
6b0655a2 6986
518f0eb1
DS
6987/* Time to wait before processing route-map updates */
6988DEFUN (bgp_set_route_map_delay_timer,
6989 bgp_set_route_map_delay_timer_cmd,
6147e2c6 6990 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
6991 SET_STR
6992 "BGP route-map delay timer\n"
6993 "Time in secs to wait before processing route-map changes\n"
f414725f 6994 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 6995{
d62a17ae 6996 int idx_number = 3;
d7c0a89a 6997 uint32_t rmap_delay_timer;
d62a17ae 6998
6999 if (argv[idx_number]->arg) {
7000 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7001 bm->rmap_update_timer = rmap_delay_timer;
7002
7003 /* if the dynamic update handling is being disabled, and a timer
7004 * is
7005 * running, stop the timer and act as if the timer has already
7006 * fired.
7007 */
7008 if (!rmap_delay_timer && bm->t_rmap_update) {
7009 BGP_TIMER_OFF(bm->t_rmap_update);
7010 thread_execute(bm->master, bgp_route_map_update_timer,
7011 NULL, 0);
7012 }
7013 return CMD_SUCCESS;
7014 } else {
7015 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7016 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7017 }
518f0eb1
DS
7018}
7019
7020DEFUN (no_bgp_set_route_map_delay_timer,
7021 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7022 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7023 NO_STR
3a2d747c 7024 BGP_STR
518f0eb1 7025 "Default BGP route-map delay timer\n"
8334fd5a
DW
7026 "Reset to default time to wait for processing route-map changes\n"
7027 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7028{
518f0eb1 7029
d62a17ae 7030 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7031
d62a17ae 7032 return CMD_SUCCESS;
518f0eb1
DS
7033}
7034
28c6e247
IR
7035/* neighbor interface */
7036static int peer_interface_vty(struct vty *vty, const char *ip_str,
7037 const char *str)
718e3744 7038{
28c6e247 7039 struct peer *peer;
718e3744 7040
28c6e247
IR
7041 peer = peer_lookup_vty(vty, ip_str);
7042 if (!peer || peer->conf_if) {
7043 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7044 return CMD_WARNING_CONFIG_FAILED;
7045 }
718e3744 7046
28c6e247
IR
7047 if (str)
7048 peer_interface_set(peer, str);
7049 else
7050 peer_interface_unset(peer);
718e3744 7051
28c6e247 7052 return CMD_SUCCESS;
718e3744 7053}
7054
28c6e247
IR
7055DEFUN (neighbor_interface,
7056 neighbor_interface_cmd,
7057 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7058 NEIGHBOR_STR
7059 NEIGHBOR_ADDR_STR
7060 "Interface\n"
7061 "Interface name\n")
718e3744 7062{
28c6e247
IR
7063 int idx_ip = 1;
7064 int idx_word = 3;
294d8425 7065
28c6e247
IR
7066 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7067}
f4b8ec07 7068
28c6e247
IR
7069DEFUN (no_neighbor_interface,
7070 no_neighbor_interface_cmd,
294d8425 7071 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
28c6e247
IR
7072 NO_STR
7073 NEIGHBOR_STR
294d8425 7074 NEIGHBOR_ADDR_STR
28c6e247
IR
7075 "Interface\n"
7076 "Interface name\n")
7077{
7078 int idx_peer = 2;
294d8425 7079
28c6e247 7080 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 7081}
6b0655a2 7082
718e3744 7083DEFUN (neighbor_distribute_list,
7084 neighbor_distribute_list_cmd,
c60dec36 7085 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7086 NEIGHBOR_STR
7087 NEIGHBOR_ADDR_STR2
7088 "Filter updates to/from this neighbor\n"
718e3744 7089 "IP Access-list name\n"
7090 "Filter incoming updates\n"
7091 "Filter outgoing updates\n")
7092{
d62a17ae 7093 int idx_peer = 1;
7094 int idx_acl = 3;
7095 int direct, ret;
7096 struct peer *peer;
a8206004 7097
d62a17ae 7098 const char *pstr = argv[idx_peer]->arg;
7099 const char *acl = argv[idx_acl]->arg;
7100 const char *inout = argv[argc - 1]->text;
a8206004 7101
d62a17ae 7102 peer = peer_and_group_lookup_vty(vty, pstr);
7103 if (!peer)
7104 return CMD_WARNING_CONFIG_FAILED;
a8206004 7105
d62a17ae 7106 /* Check filter direction. */
7107 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7108 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7109 direct, acl);
a8206004 7110
d62a17ae 7111 return bgp_vty_return(vty, ret);
718e3744 7112}
7113
d62a17ae 7114ALIAS_HIDDEN(
7115 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
c60dec36 7116 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7117 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7118 "Filter updates to/from this neighbor\n"
d62a17ae 7119 "IP Access-list name\n"
7120 "Filter incoming updates\n"
7121 "Filter outgoing updates\n")
596c17ba 7122
718e3744 7123DEFUN (no_neighbor_distribute_list,
7124 no_neighbor_distribute_list_cmd,
c60dec36 7125 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7126 NO_STR
7127 NEIGHBOR_STR
7128 NEIGHBOR_ADDR_STR2
7129 "Filter updates to/from this neighbor\n"
718e3744 7130 "IP Access-list name\n"
7131 "Filter incoming updates\n"
7132 "Filter outgoing updates\n")
7133{
d62a17ae 7134 int idx_peer = 2;
7135 int direct, ret;
7136 struct peer *peer;
a8206004 7137
d62a17ae 7138 const char *pstr = argv[idx_peer]->arg;
7139 const char *inout = argv[argc - 1]->text;
a8206004 7140
d62a17ae 7141 peer = peer_and_group_lookup_vty(vty, pstr);
7142 if (!peer)
7143 return CMD_WARNING_CONFIG_FAILED;
a8206004 7144
d62a17ae 7145 /* Check filter direction. */
7146 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7147 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7148 direct);
a8206004 7149
d62a17ae 7150 return bgp_vty_return(vty, ret);
718e3744 7151}
6b0655a2 7152
d62a17ae 7153ALIAS_HIDDEN(
7154 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
c60dec36 7155 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7156 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7157 "Filter updates to/from this neighbor\n"
d62a17ae 7158 "IP Access-list name\n"
7159 "Filter incoming updates\n"
7160 "Filter outgoing updates\n")
596c17ba 7161
718e3744 7162/* Set prefix list to the peer. */
642ef664
IR
7163static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7164 afi_t afi, safi_t safi,
7165 const char *name_str,
7166 const char *direct_str)
718e3744 7167{
642ef664
IR
7168 int ret;
7169 int direct = FILTER_IN;
7170 struct peer *peer;
718e3744 7171
642ef664
IR
7172 peer = peer_and_group_lookup_vty(vty, ip_str);
7173 if (!peer)
d62a17ae 7174 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7175
642ef664
IR
7176 /* Check filter direction. */
7177 if (strncmp(direct_str, "i", 1) == 0)
7178 direct = FILTER_IN;
7179 else if (strncmp(direct_str, "o", 1) == 0)
7180 direct = FILTER_OUT;
718e3744 7181
642ef664 7182 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 7183
642ef664
IR
7184 return bgp_vty_return(vty, ret);
7185}
7186
7187static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7188 afi_t afi, safi_t safi,
7189 const char *direct_str)
7190{
7191 int ret;
7192 struct peer *peer;
7193 int direct = FILTER_IN;
7194
7195 peer = peer_and_group_lookup_vty(vty, ip_str);
7196 if (!peer)
7197 return CMD_WARNING_CONFIG_FAILED;
7198
7199 /* Check filter direction. */
7200 if (strncmp(direct_str, "i", 1) == 0)
7201 direct = FILTER_IN;
7202 else if (strncmp(direct_str, "o", 1) == 0)
7203 direct = FILTER_OUT;
7204
7205 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7206
7207 return bgp_vty_return(vty, ret);
7208}
7209
7210DEFUN (neighbor_prefix_list,
7211 neighbor_prefix_list_cmd,
7212 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7213 NEIGHBOR_STR
7214 NEIGHBOR_ADDR_STR2
7215 "Filter updates to/from this neighbor\n"
7216 "Name of a prefix list\n"
7217 "Filter incoming updates\n"
7218 "Filter outgoing updates\n")
7219{
7220 int idx_peer = 1;
7221 int idx_word = 3;
7222 int idx_in_out = 4;
7223 return peer_prefix_list_set_vty(
7224 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7225 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7226}
7227
d62a17ae 7228ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7229 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7230 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7231 "Filter updates to/from this neighbor\n"
7232 "Name of a prefix list\n"
7233 "Filter incoming updates\n"
7234 "Filter outgoing updates\n")
596c17ba 7235
642ef664
IR
7236DEFUN (no_neighbor_prefix_list,
7237 no_neighbor_prefix_list_cmd,
7238 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7239 NO_STR
7240 NEIGHBOR_STR
7241 NEIGHBOR_ADDR_STR2
7242 "Filter updates to/from this neighbor\n"
7243 "Name of a prefix list\n"
7244 "Filter incoming updates\n"
7245 "Filter outgoing updates\n")
7246{
7247 int idx_peer = 2;
7248 int idx_in_out = 5;
7249 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7250 bgp_node_afi(vty), bgp_node_safi(vty),
7251 argv[idx_in_out]->arg);
7252}
7253
7254ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7255 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7256 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7257 "Filter updates to/from this neighbor\n"
7258 "Name of a prefix list\n"
7259 "Filter incoming updates\n"
7260 "Filter outgoing updates\n")
7261
d62a17ae 7262static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7263 safi_t safi, const char *name_str,
7264 const char *direct_str)
718e3744 7265{
d62a17ae 7266 int ret;
7267 struct peer *peer;
7268 int direct = FILTER_IN;
718e3744 7269
d62a17ae 7270 peer = peer_and_group_lookup_vty(vty, ip_str);
7271 if (!peer)
7272 return CMD_WARNING_CONFIG_FAILED;
718e3744 7273
d62a17ae 7274 /* Check filter direction. */
7275 if (strncmp(direct_str, "i", 1) == 0)
7276 direct = FILTER_IN;
7277 else if (strncmp(direct_str, "o", 1) == 0)
7278 direct = FILTER_OUT;
718e3744 7279
d62a17ae 7280 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7281
d62a17ae 7282 return bgp_vty_return(vty, ret);
718e3744 7283}
7284
d62a17ae 7285static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7286 safi_t safi, const char *direct_str)
718e3744 7287{
d62a17ae 7288 int ret;
7289 struct peer *peer;
7290 int direct = FILTER_IN;
718e3744 7291
d62a17ae 7292 peer = peer_and_group_lookup_vty(vty, ip_str);
7293 if (!peer)
7294 return CMD_WARNING_CONFIG_FAILED;
718e3744 7295
d62a17ae 7296 /* Check filter direction. */
7297 if (strncmp(direct_str, "i", 1) == 0)
7298 direct = FILTER_IN;
7299 else if (strncmp(direct_str, "o", 1) == 0)
7300 direct = FILTER_OUT;
718e3744 7301
d62a17ae 7302 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7303
d62a17ae 7304 return bgp_vty_return(vty, ret);
718e3744 7305}
7306
7307DEFUN (neighbor_filter_list,
7308 neighbor_filter_list_cmd,
de71d43e 7309 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7310 NEIGHBOR_STR
7311 NEIGHBOR_ADDR_STR2
7312 "Establish BGP filters\n"
7313 "AS path access-list name\n"
7314 "Filter incoming routes\n"
7315 "Filter outgoing routes\n")
7316{
d62a17ae 7317 int idx_peer = 1;
7318 int idx_word = 3;
7319 int idx_in_out = 4;
7320 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7321 bgp_node_safi(vty), argv[idx_word]->arg,
7322 argv[idx_in_out]->arg);
718e3744 7323}
7324
d62a17ae 7325ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
de71d43e 7326 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7327 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7328 "Establish BGP filters\n"
7329 "AS path access-list name\n"
7330 "Filter incoming routes\n"
7331 "Filter outgoing routes\n")
596c17ba 7332
718e3744 7333DEFUN (no_neighbor_filter_list,
7334 no_neighbor_filter_list_cmd,
de71d43e 7335 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7336 NO_STR
7337 NEIGHBOR_STR
7338 NEIGHBOR_ADDR_STR2
7339 "Establish BGP filters\n"
7340 "AS path access-list name\n"
7341 "Filter incoming routes\n"
7342 "Filter outgoing routes\n")
7343{
d62a17ae 7344 int idx_peer = 2;
7345 int idx_in_out = 5;
7346 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7347 bgp_node_afi(vty), bgp_node_safi(vty),
7348 argv[idx_in_out]->arg);
718e3744 7349}
6b0655a2 7350
d62a17ae 7351ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
de71d43e 7352 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7353 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7354 "Establish BGP filters\n"
7355 "AS path access-list name\n"
7356 "Filter incoming routes\n"
7357 "Filter outgoing routes\n")
596c17ba 7358
7f7940e6
MK
7359/* Set advertise-map to the peer. */
7360static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7361 afi_t afi, safi_t safi,
cf2ad4d8
MK
7362 const char *advertise_str,
7363 const char *condition_str, bool condition,
7364 bool set)
7f7940e6
MK
7365{
7366 int ret = CMD_WARNING_CONFIG_FAILED;
7367 struct peer *peer;
7368 struct route_map *advertise_map;
7369 struct route_map *condition_map;
7370
7371 peer = peer_and_group_lookup_vty(vty, ip_str);
7372 if (!peer)
7373 return ret;
7374
7375 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7376 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7377
cf2ad4d8
MK
7378 if (set)
7379 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7380 advertise_map, condition_str,
7381 condition_map, condition);
7382 else
7383 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7384 advertise_map, condition_str,
7385 condition_map, condition);
7f7940e6
MK
7386
7387 return bgp_vty_return(vty, ret);
7388}
7389
389e4f92
QY
7390DEFPY (bgp_condadv_period,
7391 bgp_condadv_period_cmd,
7392 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7393 NO_STR
7394 BGP_STR
7395 "Conditional advertisement settings\n"
7396 "Set period to rescan BGP table to check if condition is met\n"
7397 "Period between BGP table scans, in seconds; default 60\n")
7398{
7399 VTY_DECLVAR_CONTEXT(bgp, bgp);
7400
7401 bgp->condition_check_period =
7402 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7403
7404 return CMD_SUCCESS;
7405}
7406
cf2ad4d8 7407DEFPY (neighbor_advertise_map,
7f7940e6 7408 neighbor_advertise_map_cmd,
52b84062 7409 "[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 7410 NO_STR
7f7940e6
MK
7411 NEIGHBOR_STR
7412 NEIGHBOR_ADDR_STR2
7413 "Route-map to conditionally advertise routes\n"
7414 "Name of advertise map\n"
7415 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7416 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7417 "Name of the exist or non exist map\n")
7f7940e6 7418{
7f7940e6
MK
7419 bool condition = CONDITION_EXIST;
7420
52b84062 7421 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7422 condition = CONDITION_NON_EXIST;
7423
52b84062
MK
7424 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7425 bgp_node_safi(vty), advertise_str,
7426 condition_str, condition, !no);
7f7940e6
MK
7427}
7428
7429ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
52b84062 7430 "[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
7431 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7432 "Route-map to conditionally advertise routes\n"
7433 "Name of advertise map\n"
7434 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7435 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7436 "Name of the exist or non exist map\n")
7f7940e6 7437
718e3744 7438/* Set route-map to the peer. */
0ea8d871
IR
7439static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7440 afi_t afi, safi_t safi, const char *name_str,
7441 const char *direct_str)
718e3744 7442{
0ea8d871
IR
7443 int ret;
7444 struct peer *peer;
7445 int direct = RMAP_IN;
7446 struct route_map *route_map;
718e3744 7447
0ea8d871
IR
7448 peer = peer_and_group_lookup_vty(vty, ip_str);
7449 if (!peer)
d62a17ae 7450 return CMD_WARNING_CONFIG_FAILED;
718e3744 7451
0ea8d871
IR
7452 /* Check filter direction. */
7453 if (strncmp(direct_str, "in", 2) == 0)
7454 direct = RMAP_IN;
7455 else if (strncmp(direct_str, "o", 1) == 0)
7456 direct = RMAP_OUT;
718e3744 7457
0ea8d871
IR
7458 route_map = route_map_lookup_warn_noexist(vty, name_str);
7459 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7460
0ea8d871
IR
7461 return bgp_vty_return(vty, ret);
7462}
7463
7464static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7465 afi_t afi, safi_t safi,
7466 const char *direct_str)
7467{
7468 int ret;
7469 struct peer *peer;
7470 int direct = RMAP_IN;
7471
7472 peer = peer_and_group_lookup_vty(vty, ip_str);
7473 if (!peer)
7474 return CMD_WARNING_CONFIG_FAILED;
7475
7476 /* Check filter direction. */
7477 if (strncmp(direct_str, "in", 2) == 0)
7478 direct = RMAP_IN;
7479 else if (strncmp(direct_str, "o", 1) == 0)
7480 direct = RMAP_OUT;
7481
7482 ret = peer_route_map_unset(peer, afi, safi, direct);
7483
7484 return bgp_vty_return(vty, ret);
7485}
7486
7487DEFUN (neighbor_route_map,
7488 neighbor_route_map_cmd,
7489 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7490 NEIGHBOR_STR
7491 NEIGHBOR_ADDR_STR2
7492 "Apply route map to neighbor\n"
7493 "Name of route map\n"
7494 "Apply map to incoming routes\n"
7495 "Apply map to outbound routes\n")
7496{
7497 int idx_peer = 1;
7498 int idx_word = 3;
7499 int idx_in_out = 4;
7500 return peer_route_map_set_vty(
7501 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7502 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7503}
7504
d6d7ed37
IR
7505ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7506 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7507 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7508 "Apply route map to neighbor\n"
7509 "Name of route map\n"
7510 "Apply map to incoming routes\n"
7511 "Apply map to outbound routes\n")
7512
0ea8d871
IR
7513DEFUN (no_neighbor_route_map,
7514 no_neighbor_route_map_cmd,
7515 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7516 NO_STR
7517 NEIGHBOR_STR
7518 NEIGHBOR_ADDR_STR2
7519 "Apply route map to neighbor\n"
7520 "Name of route map\n"
7521 "Apply map to incoming routes\n"
7522 "Apply map to outbound routes\n")
7523{
7524 int idx_peer = 2;
7525 int idx_in_out = 5;
7526 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7527 bgp_node_afi(vty), bgp_node_safi(vty),
7528 argv[idx_in_out]->arg);
7529}
7530
7531ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
d6d7ed37
IR
7532 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7533 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7534 "Apply route map to neighbor\n"
7535 "Name of route map\n"
7536 "Apply map to incoming routes\n"
7537 "Apply map to outbound routes\n")
7538
718e3744 7539/* Set unsuppress-map to the peer. */
d62a17ae 7540static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7541 afi_t afi, safi_t safi,
7542 const char *name_str)
718e3744 7543{
d62a17ae 7544 int ret;
7545 struct peer *peer;
1de27621 7546 struct route_map *route_map;
718e3744 7547
d62a17ae 7548 peer = peer_and_group_lookup_vty(vty, ip_str);
7549 if (!peer)
7550 return CMD_WARNING_CONFIG_FAILED;
718e3744 7551
1de27621
DA
7552 route_map = route_map_lookup_warn_noexist(vty, name_str);
7553 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 7554
d62a17ae 7555 return bgp_vty_return(vty, ret);
718e3744 7556}
7557
7558/* Unset route-map from the peer. */
d62a17ae 7559static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7560 afi_t afi, safi_t safi)
718e3744 7561{
d62a17ae 7562 int ret;
7563 struct peer *peer;
718e3744 7564
d62a17ae 7565 peer = peer_and_group_lookup_vty(vty, ip_str);
7566 if (!peer)
7567 return CMD_WARNING_CONFIG_FAILED;
718e3744 7568
d62a17ae 7569 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 7570
d62a17ae 7571 return bgp_vty_return(vty, ret);
718e3744 7572}
7573
7574DEFUN (neighbor_unsuppress_map,
7575 neighbor_unsuppress_map_cmd,
9ccf14f7 7576 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7577 NEIGHBOR_STR
7578 NEIGHBOR_ADDR_STR2
7579 "Route-map to selectively unsuppress suppressed routes\n"
7580 "Name of route map\n")
7581{
d62a17ae 7582 int idx_peer = 1;
7583 int idx_word = 3;
7584 return peer_unsuppress_map_set_vty(
7585 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7586 argv[idx_word]->arg);
718e3744 7587}
7588
d62a17ae 7589ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7590 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7591 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7592 "Route-map to selectively unsuppress suppressed routes\n"
7593 "Name of route map\n")
596c17ba 7594
718e3744 7595DEFUN (no_neighbor_unsuppress_map,
7596 no_neighbor_unsuppress_map_cmd,
9ccf14f7 7597 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7598 NO_STR
7599 NEIGHBOR_STR
7600 NEIGHBOR_ADDR_STR2
7601 "Route-map to selectively unsuppress suppressed routes\n"
7602 "Name of route map\n")
7603{
d62a17ae 7604 int idx_peer = 2;
7605 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7606 bgp_node_afi(vty),
7607 bgp_node_safi(vty));
718e3744 7608}
6b0655a2 7609
d62a17ae 7610ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7611 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7612 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7613 "Route-map to selectively unsuppress suppressed routes\n"
7614 "Name of route map\n")
596c17ba 7615
7e62b792
IR
7616static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7617 afi_t afi, safi_t safi,
7618 const char *num_str,
7619 const char *threshold_str, int warning,
7620 const char *restart_str,
7621 const char *force_str)
7622{
7623 int ret;
7624 struct peer *peer;
7625 uint32_t max;
7626 uint8_t threshold;
7627 uint16_t restart;
7628
7629 peer = peer_and_group_lookup_vty(vty, ip_str);
7630 if (!peer)
7631 return CMD_WARNING_CONFIG_FAILED;
7632
7633 max = strtoul(num_str, NULL, 10);
7634 if (threshold_str)
7635 threshold = atoi(threshold_str);
7636 else
7637 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7638
7639 if (restart_str)
7640 restart = atoi(restart_str);
7641 else
7642 restart = 0;
7643
7644 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7645 restart, force_str ? true : false);
7646
7647 return bgp_vty_return(vty, ret);
7648}
7649
7650static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7651 afi_t afi, safi_t safi)
7652{
7653 int ret;
7654 struct peer *peer;
7655
7656 peer = peer_and_group_lookup_vty(vty, ip_str);
7657 if (!peer)
7658 return CMD_WARNING_CONFIG_FAILED;
7659
7660 ret = peer_maximum_prefix_unset(peer, afi, safi);
7661
7662 return bgp_vty_return(vty, ret);
7663}
7664
fde246e8 7665/* Maximum number of prefix to be sent to the neighbor. */
1d80f243
IR
7666DEFUN(neighbor_maximum_prefix_out,
7667 neighbor_maximum_prefix_out_cmd,
7668 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7669 NEIGHBOR_STR
7670 NEIGHBOR_ADDR_STR2
7671 "Maximum number of prefixes to be sent to this peer\n"
7672 "Maximum no. of prefix limit\n")
fde246e8 7673{
80444d30 7674 int ret;
fde246e8
DA
7675 int idx_peer = 1;
7676 int idx_number = 3;
7e62b792
IR
7677 struct peer *peer;
7678 uint32_t max;
fde246e8
DA
7679 afi_t afi = bgp_node_afi(vty);
7680 safi_t safi = bgp_node_safi(vty);
7681
7e62b792
IR
7682 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7683 if (!peer)
fde246e8
DA
7684 return CMD_WARNING_CONFIG_FAILED;
7685
7e62b792 7686 max = strtoul(argv[idx_number]->arg, NULL, 10);
fde246e8 7687
80444d30 7688 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
fde246e8 7689
80444d30 7690 return bgp_vty_return(vty, ret);
fde246e8
DA
7691}
7692
1d80f243
IR
7693DEFUN(no_neighbor_maximum_prefix_out,
7694 no_neighbor_maximum_prefix_out_cmd,
bc03c622 7695 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
1d80f243
IR
7696 NO_STR
7697 NEIGHBOR_STR
7698 NEIGHBOR_ADDR_STR2
bc03c622
LS
7699 "Maximum number of prefixes to be sent to this peer\n"
7700 "Maximum no. of prefix limit\n")
fde246e8 7701{
80444d30 7702 int ret;
fde246e8 7703 int idx_peer = 2;
7e62b792 7704 struct peer *peer;
fde246e8
DA
7705 afi_t afi = bgp_node_afi(vty);
7706 safi_t safi = bgp_node_safi(vty);
7707
7e62b792
IR
7708 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7709 if (!peer)
fde246e8
DA
7710 return CMD_WARNING_CONFIG_FAILED;
7711
80444d30 7712 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
fde246e8 7713
80444d30 7714 return bgp_vty_return(vty, ret);
fde246e8
DA
7715}
7716
9cbd06e0
DA
7717/* Maximum number of prefix configuration. Prefix count is different
7718 for each peer configuration. So this configuration can be set for
718e3744 7719 each peer configuration. */
1d80f243
IR
7720DEFUN (neighbor_maximum_prefix,
7721 neighbor_maximum_prefix_cmd,
7722 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7723 NEIGHBOR_STR
7724 NEIGHBOR_ADDR_STR2
7725 "Maximum number of prefix accept from this peer\n"
7726 "maximum no. of prefix limit\n"
7727 "Force checking all received routes not only accepted\n")
718e3744 7728{
d62a17ae 7729 int idx_peer = 1;
7730 int idx_number = 3;
9cbd06e0 7731 int idx_force = 0;
7e62b792 7732 char *force = NULL;
9cbd06e0
DA
7733
7734 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7735 force = argv[idx_force]->arg;
9cbd06e0 7736
7e62b792
IR
7737 return peer_maximum_prefix_set_vty(
7738 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7739 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 7740}
7741
d62a17ae 7742ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7743 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 7744 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7745 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
7746 "maximum no. of prefix limit\n"
7747 "Force checking all received routes not only accepted\n")
596c17ba 7748
1d80f243
IR
7749DEFUN (neighbor_maximum_prefix_threshold,
7750 neighbor_maximum_prefix_threshold_cmd,
7751 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7752 NEIGHBOR_STR
7753 NEIGHBOR_ADDR_STR2
7754 "Maximum number of prefix accept from this peer\n"
7755 "maximum no. of prefix limit\n"
7756 "Threshold value (%) at which to generate a warning msg\n"
7757 "Force checking all received routes not only accepted\n")
e0701b79 7758{
d62a17ae 7759 int idx_peer = 1;
7760 int idx_number = 3;
7761 int idx_number_2 = 4;
9cbd06e0 7762 int idx_force = 0;
7e62b792 7763 char *force = NULL;
9cbd06e0
DA
7764
7765 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7766 force = argv[idx_force]->arg;
9cbd06e0 7767
7e62b792
IR
7768 return peer_maximum_prefix_set_vty(
7769 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7770 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 7771}
e0701b79 7772
d62a17ae 7773ALIAS_HIDDEN(
7774 neighbor_maximum_prefix_threshold,
7775 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 7776 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 7777 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7778 "Maximum number of prefix accept from this peer\n"
7779 "maximum no. of prefix limit\n"
9cbd06e0
DA
7780 "Threshold value (%) at which to generate a warning msg\n"
7781 "Force checking all received routes not only accepted\n")
596c17ba 7782
1d80f243
IR
7783DEFUN (neighbor_maximum_prefix_warning,
7784 neighbor_maximum_prefix_warning_cmd,
7785 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7786 NEIGHBOR_STR
7787 NEIGHBOR_ADDR_STR2
7788 "Maximum number of prefix accept from this peer\n"
7789 "maximum no. of prefix limit\n"
7790 "Only give warning message when limit is exceeded\n"
7791 "Force checking all received routes not only accepted\n")
718e3744 7792{
d62a17ae 7793 int idx_peer = 1;
7794 int idx_number = 3;
9cbd06e0 7795 int idx_force = 0;
7e62b792 7796 char *force = NULL;
9cbd06e0
DA
7797
7798 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7799 force = argv[idx_force]->arg;
9cbd06e0 7800
7e62b792
IR
7801 return peer_maximum_prefix_set_vty(
7802 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7803 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 7804}
7805
d62a17ae 7806ALIAS_HIDDEN(
7807 neighbor_maximum_prefix_warning,
7808 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 7809 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 7810 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7811 "Maximum number of prefix accept from this peer\n"
7812 "maximum no. of prefix limit\n"
9cbd06e0
DA
7813 "Only give warning message when limit is exceeded\n"
7814 "Force checking all received routes not only accepted\n")
596c17ba 7815
1d80f243
IR
7816DEFUN (neighbor_maximum_prefix_threshold_warning,
7817 neighbor_maximum_prefix_threshold_warning_cmd,
7818 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7819 NEIGHBOR_STR
7820 NEIGHBOR_ADDR_STR2
7821 "Maximum number of prefix accept from this peer\n"
7822 "maximum no. of prefix limit\n"
7823 "Threshold value (%) at which to generate a warning msg\n"
7824 "Only give warning message when limit is exceeded\n"
7825 "Force checking all received routes not only accepted\n")
e0701b79 7826{
d62a17ae 7827 int idx_peer = 1;
7828 int idx_number = 3;
7829 int idx_number_2 = 4;
9cbd06e0 7830 int idx_force = 0;
7e62b792 7831 char *force = NULL;
9cbd06e0
DA
7832
7833 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7834 force = argv[idx_force]->arg;
9cbd06e0 7835
7e62b792
IR
7836 return peer_maximum_prefix_set_vty(
7837 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7838 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 7839}
7840
d62a17ae 7841ALIAS_HIDDEN(
7842 neighbor_maximum_prefix_threshold_warning,
7843 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 7844 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 7845 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7846 "Maximum number of prefix accept from this peer\n"
7847 "maximum no. of prefix limit\n"
7848 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
7849 "Only give warning message when limit is exceeded\n"
7850 "Force checking all received routes not only accepted\n")
596c17ba 7851
1d80f243
IR
7852DEFUN (neighbor_maximum_prefix_restart,
7853 neighbor_maximum_prefix_restart_cmd,
7854 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7855 NEIGHBOR_STR
7856 NEIGHBOR_ADDR_STR2
7857 "Maximum number of prefix accept from this peer\n"
7858 "maximum no. of prefix limit\n"
7859 "Restart bgp connection after limit is exceeded\n"
7860 "Restart interval in minutes\n"
7861 "Force checking all received routes not only accepted\n")
0a486e5f 7862{
d62a17ae 7863 int idx_peer = 1;
7864 int idx_number = 3;
7865 int idx_number_2 = 5;
9cbd06e0 7866 int idx_force = 0;
7e62b792 7867 char *force = NULL;
9cbd06e0
DA
7868
7869 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7870 force = argv[idx_force]->arg;
9cbd06e0 7871
7e62b792
IR
7872 return peer_maximum_prefix_set_vty(
7873 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7874 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 7875}
7876
d62a17ae 7877ALIAS_HIDDEN(
7878 neighbor_maximum_prefix_restart,
7879 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 7880 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 7881 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7882 "Maximum number of prefix accept from this peer\n"
7883 "maximum no. of prefix limit\n"
7884 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7885 "Restart interval in minutes\n"
7886 "Force checking all received routes not only accepted\n")
596c17ba 7887
1d80f243
IR
7888DEFUN (neighbor_maximum_prefix_threshold_restart,
7889 neighbor_maximum_prefix_threshold_restart_cmd,
7890 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7891 NEIGHBOR_STR
7892 NEIGHBOR_ADDR_STR2
7893 "Maximum number of prefixes to accept from this peer\n"
7894 "maximum no. of prefix limit\n"
7895 "Threshold value (%) at which to generate a warning msg\n"
7896 "Restart bgp connection after limit is exceeded\n"
7897 "Restart interval in minutes\n"
7898 "Force checking all received routes not only accepted\n")
0a486e5f 7899{
d62a17ae 7900 int idx_peer = 1;
7901 int idx_number = 3;
7902 int idx_number_2 = 4;
7903 int idx_number_3 = 6;
9cbd06e0 7904 int idx_force = 0;
7e62b792 7905 char *force = NULL;
9cbd06e0
DA
7906
7907 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7908 force = argv[idx_force]->arg;
9cbd06e0 7909
7e62b792
IR
7910 return peer_maximum_prefix_set_vty(
7911 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7912 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
7913 argv[idx_number_3]->arg, force);
d62a17ae 7914}
7915
7916ALIAS_HIDDEN(
7917 neighbor_maximum_prefix_threshold_restart,
7918 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 7919 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 7920 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7921 "Maximum number of prefixes to accept from this peer\n"
7922 "maximum no. of prefix limit\n"
7923 "Threshold value (%) at which to generate a warning msg\n"
7924 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7925 "Restart interval in minutes\n"
7926 "Force checking all received routes not only accepted\n")
596c17ba 7927
1d80f243
IR
7928DEFUN (no_neighbor_maximum_prefix,
7929 no_neighbor_maximum_prefix_cmd,
7930 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
7931 NO_STR
7932 NEIGHBOR_STR
7933 NEIGHBOR_ADDR_STR2
7934 "Maximum number of prefixes to accept from this peer\n"
7935 "maximum no. of prefix limit\n"
7936 "Threshold value (%) at which to generate a warning msg\n"
7937 "Restart bgp connection after limit is exceeded\n"
7938 "Restart interval in minutes\n"
7939 "Only give warning message when limit is exceeded\n"
7940 "Force checking all received routes not only accepted\n")
718e3744 7941{
d62a17ae 7942 int idx_peer = 2;
7e62b792
IR
7943 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
7944 bgp_node_afi(vty),
7945 bgp_node_safi(vty));
718e3744 7946}
e52702f2 7947
d62a17ae 7948ALIAS_HIDDEN(
7949 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7950 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 7951 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7952 "Maximum number of prefixes to accept from this peer\n"
7953 "maximum no. of prefix limit\n"
7954 "Threshold value (%) at which to generate a warning msg\n"
7955 "Restart bgp connection after limit is exceeded\n"
7956 "Restart interval in minutes\n"
9cbd06e0
DA
7957 "Only give warning message when limit is exceeded\n"
7958 "Force checking all received routes not only accepted\n")
596c17ba 7959
718e3744 7960
718e3744 7961/* "neighbor allowas-in" */
7962DEFUN (neighbor_allowas_in,
7963 neighbor_allowas_in_cmd,
fd8503f5 7964 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7965 NEIGHBOR_STR
7966 NEIGHBOR_ADDR_STR2
31500417 7967 "Accept as-path with my AS present in it\n"
f79f7a7b 7968 "Number of occurrences of AS number\n"
fd8503f5 7969 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7970{
d62a17ae 7971 int idx_peer = 1;
7972 int idx_number_origin = 3;
7973 int ret;
7974 int origin = 0;
7975 struct peer *peer;
7976 int allow_num = 0;
7977
7978 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7979 if (!peer)
7980 return CMD_WARNING_CONFIG_FAILED;
7981
7982 if (argc <= idx_number_origin)
7983 allow_num = 3;
7984 else {
7985 if (argv[idx_number_origin]->type == WORD_TKN)
7986 origin = 1;
7987 else
7988 allow_num = atoi(argv[idx_number_origin]->arg);
7989 }
7990
7991 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7992 allow_num, origin);
7993
7994 return bgp_vty_return(vty, ret);
7995}
7996
7997ALIAS_HIDDEN(
7998 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
7999 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8000 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8001 "Accept as-path with my AS present in it\n"
f79f7a7b 8002 "Number of occurrences of AS number\n"
d62a17ae 8003 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8004
718e3744 8005DEFUN (no_neighbor_allowas_in,
8006 no_neighbor_allowas_in_cmd,
fd8503f5 8007 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8008 NO_STR
8009 NEIGHBOR_STR
8010 NEIGHBOR_ADDR_STR2
8334fd5a 8011 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8012 "Number of occurrences of AS number\n"
fd8503f5 8013 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8014{
d62a17ae 8015 int idx_peer = 2;
8016 int ret;
8017 struct peer *peer;
718e3744 8018
d62a17ae 8019 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8020 if (!peer)
8021 return CMD_WARNING_CONFIG_FAILED;
718e3744 8022
d62a17ae 8023 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8024 bgp_node_safi(vty));
718e3744 8025
d62a17ae 8026 return bgp_vty_return(vty, ret);
718e3744 8027}
6b0655a2 8028
d62a17ae 8029ALIAS_HIDDEN(
8030 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8031 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8032 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8033 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8034 "Number of occurrences of AS number\n"
d62a17ae 8035 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8036
28c6e247
IR
8037DEFUN (neighbor_ttl_security,
8038 neighbor_ttl_security_cmd,
8039 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8040 NEIGHBOR_STR
8041 NEIGHBOR_ADDR_STR2
8042 "BGP ttl-security parameters\n"
8043 "Specify the maximum number of hops to the BGP peer\n"
8044 "Number of hops to BGP peer\n")
fa411a21 8045{
d62a17ae 8046 int idx_peer = 1;
8047 int idx_number = 4;
28c6e247
IR
8048 struct peer *peer;
8049 int gtsm_hops;
d62a17ae 8050
28c6e247
IR
8051 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8052 if (!peer)
d62a17ae 8053 return CMD_WARNING_CONFIG_FAILED;
8054
28c6e247
IR
8055 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8056
8057 /*
8058 * If 'neighbor swpX', then this is for directly connected peers,
8059 * we should not accept a ttl-security hops value greater than 1.
8060 */
8061 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8062 vty_out(vty,
8063 "%s is directly connected peer, hops cannot exceed 1\n",
8064 argv[idx_peer]->arg);
8065 return CMD_WARNING_CONFIG_FAILED;
8066 }
7ebe625c 8067
28c6e247 8068 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
8069}
8070
1d80f243
IR
8071DEFUN (no_neighbor_ttl_security,
8072 no_neighbor_ttl_security_cmd,
8073 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8074 NO_STR
8075 NEIGHBOR_STR
8076 NEIGHBOR_ADDR_STR2
8077 "BGP ttl-security parameters\n"
8078 "Specify the maximum number of hops to the BGP peer\n"
8079 "Number of hops to BGP peer\n")
fa411a21 8080{
d62a17ae 8081 int idx_peer = 2;
28c6e247 8082 struct peer *peer;
fa411a21 8083
28c6e247
IR
8084 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8085 if (!peer)
d62a17ae 8086 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8087
28c6e247 8088 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 8089}
6b0655a2 8090
7c0e4312
DA
8091/* disable-addpath-rx */
8092DEFUN(neighbor_disable_addpath_rx,
8093 neighbor_disable_addpath_rx_cmd,
8094 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8095 NEIGHBOR_STR
8096 NEIGHBOR_ADDR_STR2
8097 "Do not accept additional paths\n")
8098{
8099 char *peer_str = argv[1]->arg;
8100 struct peer *peer;
8101 afi_t afi = bgp_node_afi(vty);
8102 safi_t safi = bgp_node_safi(vty);
8103
8104 peer = peer_and_group_lookup_vty(vty, peer_str);
8105 if (!peer)
8106 return CMD_WARNING_CONFIG_FAILED;
8107
8108 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8109 PEER_FLAG_DISABLE_ADDPATH_RX);
8110}
8111
8112DEFUN(no_neighbor_disable_addpath_rx,
8113 no_neighbor_disable_addpath_rx_cmd,
8114 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8115 NO_STR
8116 NEIGHBOR_STR
8117 NEIGHBOR_ADDR_STR2
8118 "Do not accept additional paths\n")
8119{
8120 char *peer_str = argv[2]->arg;
8121 struct peer *peer;
8122 afi_t afi = bgp_node_afi(vty);
8123 safi_t safi = bgp_node_safi(vty);
8124
8125 peer = peer_and_group_lookup_vty(vty, peer_str);
8126 if (!peer)
8127 return CMD_WARNING_CONFIG_FAILED;
8128
8129 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8130 PEER_FLAG_DISABLE_ADDPATH_RX);
8131}
8132
adbac85e
DW
8133DEFUN (neighbor_addpath_tx_all_paths,
8134 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8135 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8136 NEIGHBOR_STR
8137 NEIGHBOR_ADDR_STR2
8138 "Use addpath to advertise all paths to a neighbor\n")
8139{
d62a17ae 8140 int idx_peer = 1;
8141 struct peer *peer;
adbac85e 8142
d62a17ae 8143 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8144 if (!peer)
8145 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8146
dcc68b5e
MS
8147 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8148 BGP_ADDPATH_ALL);
8149 return CMD_SUCCESS;
adbac85e
DW
8150}
8151
d62a17ae 8152ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8153 neighbor_addpath_tx_all_paths_hidden_cmd,
8154 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8155 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8156 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8157
adbac85e
DW
8158DEFUN (no_neighbor_addpath_tx_all_paths,
8159 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8160 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8161 NO_STR
8162 NEIGHBOR_STR
8163 NEIGHBOR_ADDR_STR2
8164 "Use addpath to advertise all paths to a neighbor\n")
8165{
d62a17ae 8166 int idx_peer = 2;
dcc68b5e
MS
8167 struct peer *peer;
8168
8169 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8170 if (!peer)
8171 return CMD_WARNING_CONFIG_FAILED;
8172
8173 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8174 != BGP_ADDPATH_ALL) {
8175 vty_out(vty,
8176 "%% Peer not currently configured to transmit all paths.");
8177 return CMD_WARNING_CONFIG_FAILED;
8178 }
8179
8180 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8181 BGP_ADDPATH_NONE);
8182
8183 return CMD_SUCCESS;
adbac85e
DW
8184}
8185
d62a17ae 8186ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8187 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8188 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8189 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8190 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8191
06370dac
DW
8192DEFUN (neighbor_addpath_tx_bestpath_per_as,
8193 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8194 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8195 NEIGHBOR_STR
8196 NEIGHBOR_ADDR_STR2
8197 "Use addpath to advertise the bestpath per each neighboring AS\n")
8198{
d62a17ae 8199 int idx_peer = 1;
8200 struct peer *peer;
06370dac 8201
d62a17ae 8202 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8203 if (!peer)
8204 return CMD_WARNING_CONFIG_FAILED;
06370dac 8205
dcc68b5e
MS
8206 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8207 BGP_ADDPATH_BEST_PER_AS);
8208
8209 return CMD_SUCCESS;
06370dac
DW
8210}
8211
d62a17ae 8212ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8213 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8214 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8215 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8216 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8217
06370dac
DW
8218DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8219 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8220 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8221 NO_STR
8222 NEIGHBOR_STR
8223 NEIGHBOR_ADDR_STR2
8224 "Use addpath to advertise the bestpath per each neighboring AS\n")
8225{
d62a17ae 8226 int idx_peer = 2;
dcc68b5e
MS
8227 struct peer *peer;
8228
8229 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8230 if (!peer)
8231 return CMD_WARNING_CONFIG_FAILED;
8232
8233 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8234 != BGP_ADDPATH_BEST_PER_AS) {
8235 vty_out(vty,
8236 "%% Peer not currently configured to transmit all best path per as.");
8237 return CMD_WARNING_CONFIG_FAILED;
8238 }
8239
8240 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8241 BGP_ADDPATH_NONE);
8242
8243 return CMD_SUCCESS;
06370dac
DW
8244}
8245
d62a17ae 8246ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8247 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8248 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8249 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8250 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8251
2b31007c
RZ
8252DEFPY(
8253 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8254 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8255 NEIGHBOR_STR
8256 NEIGHBOR_ADDR_STR2
8257 "Detect AS loops before sending to neighbor\n")
8258{
8259 struct peer *peer;
8260
8261 peer = peer_and_group_lookup_vty(vty, neighbor);
8262 if (!peer)
8263 return CMD_WARNING_CONFIG_FAILED;
8264
8265 peer->as_path_loop_detection = true;
8266
8267 return CMD_SUCCESS;
8268}
8269
8270DEFPY(
8271 no_neighbor_aspath_loop_detection,
8272 no_neighbor_aspath_loop_detection_cmd,
8273 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8274 NO_STR
8275 NEIGHBOR_STR
8276 NEIGHBOR_ADDR_STR2
8277 "Detect AS loops before sending to neighbor\n")
8278{
8279 struct peer *peer;
8280
8281 peer = peer_and_group_lookup_vty(vty, neighbor);
8282 if (!peer)
8283 return CMD_WARNING_CONFIG_FAILED;
8284
8285 peer->as_path_loop_detection = false;
8286
8287 return CMD_SUCCESS;
8288}
8289
b9c7bc5a 8290static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8291 struct ecommunity **list, bool is_rt6)
ddb5b488 8292{
b9c7bc5a
PZ
8293 struct ecommunity *ecom = NULL;
8294 struct ecommunity *ecomadd;
ddb5b488 8295
b9c7bc5a 8296 for (; argc; --argc, ++argv) {
9a659715
PG
8297 if (is_rt6)
8298 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8299 ECOMMUNITY_ROUTE_TARGET,
8300 0);
8301 else
8302 ecomadd = ecommunity_str2com(argv[0]->arg,
8303 ECOMMUNITY_ROUTE_TARGET,
8304 0);
b9c7bc5a
PZ
8305 if (!ecomadd) {
8306 vty_out(vty, "Malformed community-list value\n");
8307 if (ecom)
8308 ecommunity_free(&ecom);
8309 return CMD_WARNING_CONFIG_FAILED;
8310 }
ddb5b488 8311
b9c7bc5a
PZ
8312 if (ecom) {
8313 ecommunity_merge(ecom, ecomadd);
8314 ecommunity_free(&ecomadd);
8315 } else {
8316 ecom = ecomadd;
8317 }
8318 }
8319
8320 if (*list) {
8321 ecommunity_free(&*list);
ddb5b488 8322 }
b9c7bc5a
PZ
8323 *list = ecom;
8324
8325 return CMD_SUCCESS;
ddb5b488
PZ
8326}
8327
0ca70ba5
DS
8328/*
8329 * v2vimport is true if we are handling a `import vrf ...` command
8330 */
8331static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8332{
0ca70ba5
DS
8333 afi_t afi;
8334
ddb5b488 8335 switch (vty->node) {
b9c7bc5a 8336 case BGP_IPV4_NODE:
0ca70ba5
DS
8337 afi = AFI_IP;
8338 break;
b9c7bc5a 8339 case BGP_IPV6_NODE:
0ca70ba5
DS
8340 afi = AFI_IP6;
8341 break;
ddb5b488
PZ
8342 default:
8343 vty_out(vty,
b9c7bc5a 8344 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 8345 return AFI_MAX;
ddb5b488 8346 }
69b07479 8347
0ca70ba5
DS
8348 if (!v2vimport) {
8349 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8350 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8351 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8352 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8353 vty_out(vty,
8354 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8355 return AFI_MAX;
8356 }
8357 } else {
8358 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8359 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8360 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8361 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8362 vty_out(vty,
8363 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8364 return AFI_MAX;
8365 }
8366 }
8367 return afi;
ddb5b488
PZ
8368}
8369
585f1adc
IR
8370DEFPY (af_rd_vpn_export,
8371 af_rd_vpn_export_cmd,
8372 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8373 NO_STR
8374 "Specify route distinguisher\n"
8375 "Between current address-family and vpn\n"
8376 "For routes leaked from current address-family to vpn\n"
8377 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 8378{
585f1adc
IR
8379 VTY_DECLVAR_CONTEXT(bgp, bgp);
8380 struct prefix_rd prd;
8381 int ret;
ddb5b488 8382 afi_t afi;
b9c7bc5a 8383 int idx = 0;
585f1adc 8384 bool yes = true;
b9c7bc5a 8385
585f1adc
IR
8386 if (argv_find(argv, argc, "no", &idx))
8387 yes = false;
ddb5b488 8388
585f1adc
IR
8389 if (yes) {
8390 ret = str2prefix_rd(rd_str, &prd);
8391 if (!ret) {
8392 vty_out(vty, "%% Malformed rd\n");
8393 return CMD_WARNING_CONFIG_FAILED;
8394 }
8395 }
ddb5b488 8396
585f1adc
IR
8397 afi = vpn_policy_getafi(vty, bgp, false);
8398 if (afi == AFI_MAX)
8399 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8400
585f1adc
IR
8401 /*
8402 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8403 */
8404 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8405 bgp_get_default(), bgp);
ddb5b488 8406
585f1adc
IR
8407 if (yes) {
8408 bgp->vpn_policy[afi].tovpn_rd = prd;
8409 SET_FLAG(bgp->vpn_policy[afi].flags,
8410 BGP_VPN_POLICY_TOVPN_RD_SET);
8411 } else {
8412 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8413 BGP_VPN_POLICY_TOVPN_RD_SET);
8414 }
69b07479 8415
585f1adc
IR
8416 /* post-change: re-export vpn routes */
8417 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8418 bgp_get_default(), bgp);
8419
8420 return CMD_SUCCESS;
ddb5b488
PZ
8421}
8422
b9c7bc5a
PZ
8423ALIAS (af_rd_vpn_export,
8424 af_no_rd_vpn_export_cmd,
8425 "no rd vpn export",
ddb5b488 8426 NO_STR
b9c7bc5a
PZ
8427 "Specify route distinguisher\n"
8428 "Between current address-family and vpn\n"
8429 "For routes leaked from current address-family to vpn\n")
ddb5b488 8430
b9c7bc5a
PZ
8431DEFPY (af_label_vpn_export,
8432 af_label_vpn_export_cmd,
e70e9f8e 8433 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 8434 NO_STR
ddb5b488 8435 "label value for VRF\n"
b9c7bc5a
PZ
8436 "Between current address-family and vpn\n"
8437 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
8438 "Label Value <0-1048575>\n"
8439 "Automatically assign a label\n")
ddb5b488
PZ
8440{
8441 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8442 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 8443 afi_t afi;
b9c7bc5a 8444 int idx = 0;
c6423c31 8445 bool yes = true;
b9c7bc5a
PZ
8446
8447 if (argv_find(argv, argc, "no", &idx))
c6423c31 8448 yes = false;
ddb5b488 8449
21a16cc2
PZ
8450 /* If "no ...", squash trailing parameter */
8451 if (!yes)
8452 label_auto = NULL;
8453
e70e9f8e
PZ
8454 if (yes) {
8455 if (!label_auto)
8456 label = label_val; /* parser should force unsigned */
8457 }
ddb5b488 8458
0ca70ba5 8459 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8460 if (afi == AFI_MAX)
8461 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 8462
e70e9f8e 8463
69b07479
DS
8464 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8465 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8466 /* no change */
8467 return CMD_SUCCESS;
e70e9f8e 8468
69b07479
DS
8469 /*
8470 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8471 */
8472 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8473 bgp_get_default(), bgp);
8474
8475 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8476 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8477
8478 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8479
8480 /*
8481 * label has previously been automatically
8482 * assigned by labelpool: release it
8483 *
8484 * NB if tovpn_label == MPLS_LABEL_NONE it
8485 * means the automatic assignment is in flight
8486 * and therefore the labelpool callback must
8487 * detect that the auto label is not needed.
8488 */
8489
8490 bgp_lp_release(LP_TYPE_VRF,
8491 &bgp->vpn_policy[afi],
8492 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 8493 }
69b07479
DS
8494 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8495 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8496 }
ddb5b488 8497
69b07479
DS
8498 bgp->vpn_policy[afi].tovpn_label = label;
8499 if (label_auto) {
8500 SET_FLAG(bgp->vpn_policy[afi].flags,
8501 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8502 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8503 vpn_leak_label_callback);
ddb5b488
PZ
8504 }
8505
69b07479
DS
8506 /* post-change: re-export vpn routes */
8507 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8508 bgp_get_default(), bgp);
8509
0d020cd6 8510 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
8511 return CMD_SUCCESS;
8512}
8513
b72c9e14
HS
8514DEFPY (af_sid_vpn_export,
8515 af_sid_vpn_export_cmd,
8516 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8517 NO_STR
8518 "sid value for VRF\n"
8519 "Between current address-family and vpn\n"
8520 "For routes leaked from current address-family to vpn\n"
8521 "Sid allocation index\n"
8522 "Automatically assign a label\n")
8523{
8524 VTY_DECLVAR_CONTEXT(bgp, bgp);
8525 afi_t afi;
8526 int debug = 0;
8527 int idx = 0;
8528 bool yes = true;
8529
8530 if (argv_find(argv, argc, "no", &idx))
8531 yes = false;
8532 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8533 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8534
8535 afi = vpn_policy_getafi(vty, bgp, false);
8536 if (afi == AFI_MAX)
8537 return CMD_WARNING_CONFIG_FAILED;
8538
8539 if (!yes) {
8540 /* implement me */
8541 vty_out(vty, "It's not implemented");
8542 return CMD_WARNING_CONFIG_FAILED;
8543 }
8544
8545 /* skip when it's already configured */
8546 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8547 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8548 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8549 return CMD_SUCCESS;
8550
7de4c885
HS
8551 /*
8552 * mode change between sid_idx and sid_auto isn't supported.
8553 * user must negate sid vpn export when they want to change the mode
8554 */
b72c9e14
HS
8555 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8556 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8557 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8558 vty_out(vty, "it's already configured as %s.\n",
8559 sid_auto ? "auto-mode" : "idx-mode");
8560 return CMD_WARNING_CONFIG_FAILED;
8561 }
8562
8563 /* pre-change */
8564 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8565 bgp_get_default(), bgp);
8566
8567 if (sid_auto) {
8568 /* SID allocation auto-mode */
8569 if (debug)
8570 zlog_debug("%s: auto sid alloc.", __func__);
8571 SET_FLAG(bgp->vpn_policy[afi].flags,
8572 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8573 } else {
8574 /* SID allocation index-mode */
8575 if (debug)
8576 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8577 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8578 }
8579
8580 /* post-change */
8581 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8582 bgp_get_default(), bgp);
8583 return CMD_SUCCESS;
8584}
8585
b9c7bc5a
PZ
8586ALIAS (af_label_vpn_export,
8587 af_no_label_vpn_export_cmd,
8588 "no label vpn export",
8589 NO_STR
8590 "label value for VRF\n"
8591 "Between current address-family and vpn\n"
8592 "For routes leaked from current address-family to vpn\n")
ddb5b488 8593
585f1adc 8594DEFPY (af_nexthop_vpn_export,
b9c7bc5a 8595 af_nexthop_vpn_export_cmd,
8c85ca28 8596 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 8597 NO_STR
ddb5b488 8598 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
8599 "Between current address-family and vpn\n"
8600 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8601 "IPv4 prefix\n"
8602 "IPv6 prefix\n")
8603{
585f1adc 8604 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 8605 afi_t afi;
ddb5b488
PZ
8606 struct prefix p;
8607
8c85ca28
QY
8608 if (!no) {
8609 if (!nexthop_su) {
8610 vty_out(vty, "%% Nexthop required\n");
8611 return CMD_WARNING_CONFIG_FAILED;
8612 }
8c85ca28 8613 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
8614 return CMD_WARNING_CONFIG_FAILED;
8615 }
ddb5b488 8616
585f1adc
IR
8617 afi = vpn_policy_getafi(vty, bgp, false);
8618 if (afi == AFI_MAX)
8619 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8620
585f1adc
IR
8621 /*
8622 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8623 */
8624 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8625 bgp_get_default(), bgp);
ddb5b488 8626
585f1adc
IR
8627 if (!no) {
8628 bgp->vpn_policy[afi].tovpn_nexthop = p;
8629 SET_FLAG(bgp->vpn_policy[afi].flags,
8630 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8631 } else {
8632 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8633 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8634 }
69b07479 8635
585f1adc
IR
8636 /* post-change: re-export vpn routes */
8637 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8638 bgp_get_default(), bgp);
37a87b8f 8639
585f1adc 8640 return CMD_SUCCESS;
ddb5b488
PZ
8641}
8642
b9c7bc5a 8643static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 8644{
b9c7bc5a
PZ
8645 if (!strcmp(dstr, "import")) {
8646 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8647 } else if (!strcmp(dstr, "export")) {
8648 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8649 } else if (!strcmp(dstr, "both")) {
8650 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8651 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8652 } else {
8653 vty_out(vty, "%% direction parse error\n");
8654 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8655 }
ddb5b488
PZ
8656 return CMD_SUCCESS;
8657}
8658
b9c7bc5a
PZ
8659DEFPY (af_rt_vpn_imexport,
8660 af_rt_vpn_imexport_cmd,
8661 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8662 NO_STR
8663 "Specify route target list\n"
ddb5b488 8664 "Specify route target list\n"
b9c7bc5a
PZ
8665 "Between current address-family and vpn\n"
8666 "For routes leaked from vpn to current address-family: match any\n"
8667 "For routes leaked from current address-family to vpn: set\n"
8668 "both import: match any and export: set\n"
ddb5b488
PZ
8669 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8670{
8671 VTY_DECLVAR_CONTEXT(bgp, bgp);
8672 int ret;
8673 struct ecommunity *ecom = NULL;
8674 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
8675 vpn_policy_direction_t dir;
8676 afi_t afi;
8677 int idx = 0;
c6423c31 8678 bool yes = true;
ddb5b488 8679
b9c7bc5a 8680 if (argv_find(argv, argc, "no", &idx))
c6423c31 8681 yes = false;
b9c7bc5a 8682
0ca70ba5 8683 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8684 if (afi == AFI_MAX)
8685 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8686
b9c7bc5a 8687 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
8688 if (ret != CMD_SUCCESS)
8689 return ret;
8690
b9c7bc5a
PZ
8691 if (yes) {
8692 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8693 vty_out(vty, "%% Missing RTLIST\n");
8694 return CMD_WARNING_CONFIG_FAILED;
8695 }
c6423c31 8696 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
8697 if (ret != CMD_SUCCESS) {
8698 return ret;
8699 }
ddb5b488
PZ
8700 }
8701
69b07479
DS
8702 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8703 if (!dodir[dir])
ddb5b488 8704 continue;
ddb5b488 8705
69b07479 8706 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8707
69b07479
DS
8708 if (yes) {
8709 if (bgp->vpn_policy[afi].rtlist[dir])
8710 ecommunity_free(
8711 &bgp->vpn_policy[afi].rtlist[dir]);
8712 bgp->vpn_policy[afi].rtlist[dir] =
8713 ecommunity_dup(ecom);
8714 } else {
8715 if (bgp->vpn_policy[afi].rtlist[dir])
8716 ecommunity_free(
8717 &bgp->vpn_policy[afi].rtlist[dir]);
8718 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 8719 }
69b07479
DS
8720
8721 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8722 }
69b07479 8723
d555f3e9
PZ
8724 if (ecom)
8725 ecommunity_free(&ecom);
ddb5b488
PZ
8726
8727 return CMD_SUCCESS;
8728}
8729
b9c7bc5a
PZ
8730ALIAS (af_rt_vpn_imexport,
8731 af_no_rt_vpn_imexport_cmd,
8732 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
8733 NO_STR
8734 "Specify route target list\n"
b9c7bc5a
PZ
8735 "Specify route target list\n"
8736 "Between current address-family and vpn\n"
8737 "For routes leaked from vpn to current address-family\n"
8738 "For routes leaked from current address-family to vpn\n"
8739 "both import and export\n")
8740
585f1adc 8741DEFPY (af_route_map_vpn_imexport,
b9c7bc5a
PZ
8742 af_route_map_vpn_imexport_cmd,
8743/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8744 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8745 NO_STR
ddb5b488 8746 "Specify route map\n"
b9c7bc5a
PZ
8747 "Between current address-family and vpn\n"
8748 "For routes leaked from vpn to current address-family\n"
8749 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8750 "name of route-map\n")
8751{
585f1adc
IR
8752 VTY_DECLVAR_CONTEXT(bgp, bgp);
8753 int ret;
8754 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8755 vpn_policy_direction_t dir;
ddb5b488 8756 afi_t afi;
ddb5b488 8757 int idx = 0;
585f1adc 8758 bool yes = true;
ddb5b488 8759
585f1adc
IR
8760 if (argv_find(argv, argc, "no", &idx))
8761 yes = false;
ddb5b488 8762
585f1adc
IR
8763 afi = vpn_policy_getafi(vty, bgp, false);
8764 if (afi == AFI_MAX)
8765 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8766
585f1adc
IR
8767 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8768 if (ret != CMD_SUCCESS)
8769 return ret;
ddb5b488 8770
585f1adc
IR
8771 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8772 if (!dodir[dir])
8773 continue;
69b07479 8774
585f1adc
IR
8775 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8776
8777 if (yes) {
8778 if (bgp->vpn_policy[afi].rmap_name[dir])
8779 XFREE(MTYPE_ROUTE_MAP_NAME,
8780 bgp->vpn_policy[afi].rmap_name[dir]);
8781 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
8782 MTYPE_ROUTE_MAP_NAME, rmap_str);
8783 bgp->vpn_policy[afi].rmap[dir] =
8784 route_map_lookup_warn_noexist(vty, rmap_str);
8785 if (!bgp->vpn_policy[afi].rmap[dir])
8786 return CMD_SUCCESS;
8787 } else {
8788 if (bgp->vpn_policy[afi].rmap_name[dir])
8789 XFREE(MTYPE_ROUTE_MAP_NAME,
8790 bgp->vpn_policy[afi].rmap_name[dir]);
8791 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8792 bgp->vpn_policy[afi].rmap[dir] = NULL;
8793 }
8794
8795 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8796 }
ddb5b488 8797
585f1adc 8798 return CMD_SUCCESS;
ddb5b488
PZ
8799}
8800
b9c7bc5a
PZ
8801ALIAS (af_route_map_vpn_imexport,
8802 af_no_route_map_vpn_imexport_cmd,
8803 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
8804 NO_STR
8805 "Specify route map\n"
b9c7bc5a
PZ
8806 "Between current address-family and vpn\n"
8807 "For routes leaked from vpn to current address-family\n"
8808 "For routes leaked from current address-family to vpn\n")
8809
bb4f6190 8810DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 8811 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
8812 "Import routes from another VRF\n"
8813 "Vrf routes being filtered\n"
8814 "Specify route map\n"
8815 "name of route-map\n")
8816{
8817 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
8818 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8819 afi_t afi;
bb4f6190
DS
8820 struct bgp *bgp_default;
8821
0ca70ba5 8822 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
8823 if (afi == AFI_MAX)
8824 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
8825
8826 bgp_default = bgp_get_default();
8827 if (!bgp_default) {
8828 int32_t ret;
8829 as_t as = bgp->as;
8830
8831 /* Auto-create assuming the same AS */
5d5393b9
DL
8832 ret = bgp_get_vty(&bgp_default, &as, NULL,
8833 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
8834
8835 if (ret) {
8836 vty_out(vty,
8837 "VRF default is not configured as a bgp instance\n");
8838 return CMD_WARNING;
8839 }
8840 }
8841
69b07479 8842 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 8843
ae6a6fb4
DS
8844 if (bgp->vpn_policy[afi].rmap_name[dir])
8845 XFREE(MTYPE_ROUTE_MAP_NAME,
8846 bgp->vpn_policy[afi].rmap_name[dir]);
8847 bgp->vpn_policy[afi].rmap_name[dir] =
8848 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8849 bgp->vpn_policy[afi].rmap[dir] =
8850 route_map_lookup_warn_noexist(vty, rmap_str);
8851 if (!bgp->vpn_policy[afi].rmap[dir])
8852 return CMD_SUCCESS;
8853
8854 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8855 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 8856
69b07479
DS
8857 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8858
bb4f6190
DS
8859 return CMD_SUCCESS;
8860}
8861
ae6a6fb4
DS
8862DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
8863 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
8864 NO_STR
8865 "Import routes from another VRF\n"
8866 "Vrf routes being filtered\n"
ae6a6fb4
DS
8867 "Specify route map\n"
8868 "name of route-map\n")
8869{
8870 VTY_DECLVAR_CONTEXT(bgp, bgp);
8871 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8872 afi_t afi;
8873
8874 afi = vpn_policy_getafi(vty, bgp, true);
8875 if (afi == AFI_MAX)
8876 return CMD_WARNING_CONFIG_FAILED;
8877
8878 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8879
8880 if (bgp->vpn_policy[afi].rmap_name[dir])
8881 XFREE(MTYPE_ROUTE_MAP_NAME,
8882 bgp->vpn_policy[afi].rmap_name[dir]);
8883 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8884 bgp->vpn_policy[afi].rmap[dir] = NULL;
8885
8886 if (bgp->vpn_policy[afi].import_vrf->count == 0)
8887 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8888 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8889
8890 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8891
8892 return CMD_SUCCESS;
8893}
bb4f6190 8894
585f1adc
IR
8895DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
8896 "[no] import vrf VIEWVRFNAME$import_name",
8897 NO_STR
8898 "Import routes from another VRF\n"
8899 "VRF to import from\n"
8900 "The name of the VRF\n")
12a844a5 8901{
585f1adc
IR
8902 VTY_DECLVAR_CONTEXT(bgp, bgp);
8903 struct listnode *node;
8904 struct bgp *vrf_bgp, *bgp_default;
8905 int32_t ret = 0;
8906 as_t as = bgp->as;
8907 bool remove = false;
8908 int32_t idx = 0;
8909 char *vname;
8910 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
8911 safi_t safi;
8912 afi_t afi;
8913
867f0cca 8914 if (import_name == NULL) {
8915 vty_out(vty, "%% Missing import name\n");
8916 return CMD_WARNING;
8917 }
8918
ae6a6fb4
DS
8919 if (strcmp(import_name, "route-map") == 0) {
8920 vty_out(vty, "%% Must include route-map name\n");
8921 return CMD_WARNING;
8922 }
8923
585f1adc
IR
8924 if (argv_find(argv, argc, "no", &idx))
8925 remove = true;
8926
8927 afi = vpn_policy_getafi(vty, bgp, true);
8928 if (afi == AFI_MAX)
8929 return CMD_WARNING_CONFIG_FAILED;
8930
12a844a5
DS
8931 safi = bgp_node_safi(vty);
8932
585f1adc
IR
8933 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
8934 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
8935 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
8936 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
8937 remove ? "unimport" : "import", import_name);
8938 return CMD_WARNING;
8939 }
25679caa 8940
585f1adc
IR
8941 bgp_default = bgp_get_default();
8942 if (!bgp_default) {
8943 /* Auto-create assuming the same AS */
8944 ret = bgp_get_vty(&bgp_default, &as, NULL,
8945 BGP_INSTANCE_TYPE_DEFAULT);
12a844a5 8946
585f1adc
IR
8947 if (ret) {
8948 vty_out(vty,
8949 "VRF default is not configured as a bgp instance\n");
8950 return CMD_WARNING;
8951 }
8952 }
12a844a5 8953
585f1adc
IR
8954 vrf_bgp = bgp_lookup_by_name(import_name);
8955 if (!vrf_bgp) {
8956 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
8957 vrf_bgp = bgp_default;
8958 else
8959 /* Auto-create assuming the same AS */
8960 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
8961
8962 if (ret) {
8963 vty_out(vty,
8964 "VRF %s is not configured as a bgp instance\n",
8965 import_name);
8966 return CMD_WARNING;
8967 }
8968 }
8969
8970 if (remove) {
8971 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
8972 } else {
8973 /* Already importing from "import_vrf"? */
8974 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
8975 vname)) {
8976 if (strcmp(vname, import_name) == 0)
8977 return CMD_WARNING;
8978 }
8979
8980 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
8981 }
8982
8983 return CMD_SUCCESS;
12a844a5
DS
8984}
8985
b9c7bc5a 8986/* This command is valid only in a bgp vrf instance or the default instance */
585f1adc 8987DEFPY (bgp_imexport_vpn,
b9c7bc5a
PZ
8988 bgp_imexport_vpn_cmd,
8989 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
8990 NO_STR
8991 "Import routes to this address-family\n"
8992 "Export routes from this address-family\n"
8993 "to/from default instance VPN RIB\n")
ddb5b488 8994{
585f1adc
IR
8995 VTY_DECLVAR_CONTEXT(bgp, bgp);
8996 int previous_state;
37a87b8f 8997 afi_t afi;
585f1adc
IR
8998 safi_t safi;
8999 int idx = 0;
9000 bool yes = true;
9001 int flag;
9002 vpn_policy_direction_t dir;
9003
9004 if (argv_find(argv, argc, "no", &idx))
9005 yes = false;
9006
9007 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9008 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9009
9010 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9011 return CMD_WARNING_CONFIG_FAILED;
9012 }
ddb5b488 9013
b9c7bc5a
PZ
9014 afi = bgp_node_afi(vty);
9015 safi = bgp_node_safi(vty);
585f1adc
IR
9016 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9017 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9018 return CMD_WARNING_CONFIG_FAILED;
9019 }
ddb5b488 9020
b9c7bc5a 9021 if (!strcmp(direction_str, "import")) {
585f1adc
IR
9022 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9023 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b9c7bc5a 9024 } else if (!strcmp(direction_str, "export")) {
585f1adc
IR
9025 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9026 dir = BGP_VPN_POLICY_DIR_TOVPN;
b9c7bc5a
PZ
9027 } else {
9028 vty_out(vty, "%% unknown direction %s\n", direction_str);
9029 return CMD_WARNING_CONFIG_FAILED;
9030 }
9031
585f1adc 9032 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 9033
585f1adc
IR
9034 if (yes) {
9035 SET_FLAG(bgp->af_flags[afi][safi], flag);
9036 if (!previous_state) {
9037 /* trigger export current vrf */
9038 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9039 }
9040 } else {
9041 if (previous_state) {
9042 /* trigger un-export current vrf */
9043 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9044 }
9045 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9046 }
37a87b8f 9047
1ca2fd11
IR
9048 hook_call(bgp_snmp_init_stats, bgp);
9049
585f1adc 9050 return CMD_SUCCESS;
ddb5b488
PZ
9051}
9052
301ad80a
PG
9053DEFPY (af_routetarget_import,
9054 af_routetarget_import_cmd,
9a659715 9055 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9056 NO_STR
9057 "Specify route target list\n"
9058 "Specify route target list\n"
9a659715
PG
9059 "Specify route target list\n"
9060 "Specify route target list\n"
301ad80a
PG
9061 "Flow-spec redirect type route target\n"
9062 "Import routes to this address-family\n"
9a659715 9063 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9064{
9065 VTY_DECLVAR_CONTEXT(bgp, bgp);
9066 int ret;
9067 struct ecommunity *ecom = NULL;
301ad80a 9068 afi_t afi;
9a659715 9069 int idx = 0, idx_unused = 0;
c6423c31
PG
9070 bool yes = true;
9071 bool rt6 = false;
301ad80a
PG
9072
9073 if (argv_find(argv, argc, "no", &idx))
c6423c31 9074 yes = false;
301ad80a 9075
9a659715
PG
9076 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9077 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9078 rt6 = true;
301ad80a 9079
0ca70ba5 9080 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9081 if (afi == AFI_MAX)
9082 return CMD_WARNING_CONFIG_FAILED;
9083
9a659715
PG
9084 if (rt6 && afi != AFI_IP6)
9085 return CMD_WARNING_CONFIG_FAILED;
9086
301ad80a
PG
9087 if (yes) {
9088 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9089 vty_out(vty, "%% Missing RTLIST\n");
9090 return CMD_WARNING_CONFIG_FAILED;
9091 }
9a659715 9092 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9093 if (ret != CMD_SUCCESS)
9094 return ret;
9095 }
69b07479
DS
9096
9097 if (yes) {
9098 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9099 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9100 .import_redirect_rtlist);
69b07479
DS
9101 bgp->vpn_policy[afi].import_redirect_rtlist =
9102 ecommunity_dup(ecom);
9103 } else {
9104 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9105 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9106 .import_redirect_rtlist);
69b07479 9107 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9108 }
69b07479 9109
301ad80a
PG
9110 if (ecom)
9111 ecommunity_free(&ecom);
9112
9113 return CMD_SUCCESS;
9114}
9115
505e5056 9116DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9117 address_family_ipv4_safi_cmd,
9118 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9119 "Enter Address Family command mode\n"
9120 "Address Family\n"
9121 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9122{
f51bae9c 9123
d62a17ae 9124 if (argc == 3) {
585f1adc
IR
9125 VTY_DECLVAR_CONTEXT(bgp, bgp);
9126 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9127 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9128 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9129 && safi != SAFI_EVPN) {
31947174
MK
9130 vty_out(vty,
9131 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9132 return CMD_WARNING_CONFIG_FAILED;
9133 }
585f1adc
IR
9134 vty->node = bgp_node_type(AFI_IP, safi);
9135 } else
9136 vty->node = BGP_IPV4_NODE;
718e3744 9137
d62a17ae 9138 return CMD_SUCCESS;
718e3744 9139}
9140
505e5056 9141DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9142 address_family_ipv6_safi_cmd,
9143 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9144 "Enter Address Family command mode\n"
9145 "Address Family\n"
9146 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9147{
d62a17ae 9148 if (argc == 3) {
585f1adc
IR
9149 VTY_DECLVAR_CONTEXT(bgp, bgp);
9150 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9151 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9152 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9153 && safi != SAFI_EVPN) {
31947174
MK
9154 vty_out(vty,
9155 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9156 return CMD_WARNING_CONFIG_FAILED;
9157 }
585f1adc
IR
9158 vty->node = bgp_node_type(AFI_IP6, safi);
9159 } else
9160 vty->node = BGP_IPV6_NODE;
25ffbdc1 9161
d62a17ae 9162 return CMD_SUCCESS;
25ffbdc1 9163}
718e3744 9164
d6902373 9165#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9166DEFUN_NOSH (address_family_vpnv4,
718e3744 9167 address_family_vpnv4_cmd,
8334fd5a 9168 "address-family vpnv4 [unicast]",
718e3744 9169 "Enter Address Family command mode\n"
8c3deaae 9170 "Address Family\n"
3a2d747c 9171 "Address Family modifier\n")
718e3744 9172{
d62a17ae 9173 vty->node = BGP_VPNV4_NODE;
9174 return CMD_SUCCESS;
718e3744 9175}
9176
505e5056 9177DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9178 address_family_vpnv6_cmd,
8334fd5a 9179 "address-family vpnv6 [unicast]",
8ecd3266 9180 "Enter Address Family command mode\n"
8c3deaae 9181 "Address Family\n"
3a2d747c 9182 "Address Family modifier\n")
8ecd3266 9183{
d62a17ae 9184 vty->node = BGP_VPNV6_NODE;
9185 return CMD_SUCCESS;
8ecd3266 9186}
64e4a6c5 9187#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9188
505e5056 9189DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9190 address_family_evpn_cmd,
7111c1a0 9191 "address-family l2vpn evpn",
4e0b7b6d 9192 "Enter Address Family command mode\n"
7111c1a0
QY
9193 "Address Family\n"
9194 "Address Family modifier\n")
4e0b7b6d 9195{
2131d5cf 9196 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9197 vty->node = BGP_EVPN_NODE;
9198 return CMD_SUCCESS;
4e0b7b6d
PG
9199}
9200
bfaab44d
HS
9201DEFUN_NOSH (bgp_segment_routing_srv6,
9202 bgp_segment_routing_srv6_cmd,
9203 "segment-routing srv6",
9204 "Segment-Routing configuration\n"
9205 "Segment-Routing SRv6 configuration\n")
9206{
9207 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 9208 bgp->srv6_enabled = true;
bfaab44d
HS
9209 vty->node = BGP_SRV6_NODE;
9210 return CMD_SUCCESS;
9211}
9212
0249b8b6
HS
9213DEFUN (no_bgp_segment_routing_srv6,
9214 no_bgp_segment_routing_srv6_cmd,
9215 "no segment-routing srv6",
9216 NO_STR
9217 "Segment-Routing configuration\n"
9218 "Segment-Routing SRv6 configuration\n")
9219{
9220 VTY_DECLVAR_CONTEXT(bgp, bgp);
9221
9222 if (strlen(bgp->srv6_locator_name) > 0)
9223 if (bgp_srv6_locator_unset(bgp) < 0)
9224 return CMD_WARNING_CONFIG_FAILED;
9225
9226 bgp->srv6_enabled = false;
9227 return CMD_SUCCESS;
9228}
9229
a0281b2e
HS
9230DEFPY (bgp_srv6_locator,
9231 bgp_srv6_locator_cmd,
9232 "locator NAME$name",
9233 "Specify SRv6 locator\n"
9234 "Specify SRv6 locator\n")
9235{
9236 VTY_DECLVAR_CONTEXT(bgp, bgp);
7de4c885 9237 int ret;
a0281b2e
HS
9238
9239 if (strlen(bgp->srv6_locator_name) > 0
9240 && strcmp(name, bgp->srv6_locator_name) != 0) {
9241 vty_out(vty, "srv6 locator is already configured\n");
9242 return CMD_WARNING_CONFIG_FAILED;
7de4c885
HS
9243 }
9244
9245 snprintf(bgp->srv6_locator_name,
9246 sizeof(bgp->srv6_locator_name), "%s", name);
a0281b2e 9247
7de4c885 9248 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
a0281b2e
HS
9249 if (ret < 0)
9250 return CMD_WARNING_CONFIG_FAILED;
9251
9252 return CMD_SUCCESS;
9253}
9254
0249b8b6
HS
9255DEFPY (no_bgp_srv6_locator,
9256 no_bgp_srv6_locator_cmd,
9257 "no locator NAME$name",
9258 NO_STR
9259 "Specify SRv6 locator\n"
9260 "Specify SRv6 locator\n")
9261{
9262 VTY_DECLVAR_CONTEXT(bgp, bgp);
9263
9264 /* when locator isn't configured, do nothing */
9265 if (strlen(bgp->srv6_locator_name) < 1)
9266 return CMD_SUCCESS;
9267
9268 /* name validation */
9269 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9270 vty_out(vty, "%% No srv6 locator is configured\n");
9271 return CMD_WARNING_CONFIG_FAILED;
9272 }
9273
9274 /* unset locator */
9275 if (bgp_srv6_locator_unset(bgp) < 0)
9276 return CMD_WARNING_CONFIG_FAILED;
9277
9278 return CMD_SUCCESS;
9279}
9280
ea372e81
HS
9281DEFPY (show_bgp_srv6,
9282 show_bgp_srv6_cmd,
9283 "show bgp segment-routing srv6",
9284 SHOW_STR
9285 BGP_STR
9286 "BGP Segment Routing\n"
9287 "BGP Segment Routing SRv6\n")
9288{
9289 struct bgp *bgp;
9290 struct listnode *node;
9291 struct prefix_ipv6 *chunk;
9292 struct bgp_srv6_function *func;
9293 struct in6_addr *tovpn4_sid;
9294 struct in6_addr *tovpn6_sid;
9295 char buf[256];
9296 char buf_tovpn4_sid[256];
9297 char buf_tovpn6_sid[256];
9298
9299 bgp = bgp_get_default();
96db4340 9300 if (!bgp)
ea372e81
HS
9301 return CMD_SUCCESS;
9302
9303 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9304 vty_out(vty, "locator_chunks:\n");
9305 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9306 prefix2str(chunk, buf, sizeof(buf));
9307 vty_out(vty, "- %s\n", buf);
9308 }
9309
9310 vty_out(vty, "functions:\n");
9311 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9312 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9313 vty_out(vty, "- sid: %s\n", buf);
9314 vty_out(vty, " locator: %s\n", func->locator_name);
9315 }
9316
9317 vty_out(vty, "bgps:\n");
9318 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9319 vty_out(vty, "- name: %s\n",
9320 bgp->name ? bgp->name : "default");
9321
9322 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9323 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9324 if (tovpn4_sid)
9325 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9326 sizeof(buf_tovpn4_sid));
9327 if (tovpn6_sid)
9328 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9329 sizeof(buf_tovpn6_sid));
9330
9331 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9332 tovpn4_sid ? buf_tovpn4_sid : "none");
9333 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9334 tovpn6_sid ? buf_tovpn6_sid : "none");
9335 }
9336
9337 return CMD_SUCCESS;
9338}
9339
505e5056 9340DEFUN_NOSH (exit_address_family,
718e3744 9341 exit_address_family_cmd,
9342 "exit-address-family",
9343 "Exit from Address Family configuration mode\n")
9344{
d62a17ae 9345 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9346 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9347 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9348 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9349 || vty->node == BGP_EVPN_NODE
9350 || vty->node == BGP_FLOWSPECV4_NODE
9351 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9352 vty->node = BGP_NODE;
9353 return CMD_SUCCESS;
718e3744 9354}
6b0655a2 9355
8ad7271d 9356/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9357static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9358 const char *ip_str, afi_t afi, safi_t safi,
9359 struct prefix_rd *prd)
9360{
9361 int ret;
9362 struct prefix match;
9bcb3eef
DS
9363 struct bgp_dest *dest;
9364 struct bgp_dest *rm;
d62a17ae 9365 struct bgp *bgp;
9366 struct bgp_table *table;
9367 struct bgp_table *rib;
9368
9369 /* BGP structure lookup. */
9370 if (view_name) {
9371 bgp = bgp_lookup_by_name(view_name);
9372 if (bgp == NULL) {
9373 vty_out(vty, "%% Can't find BGP instance %s\n",
9374 view_name);
9375 return CMD_WARNING;
9376 }
9377 } else {
9378 bgp = bgp_get_default();
9379 if (bgp == NULL) {
9380 vty_out(vty, "%% No BGP process is configured\n");
9381 return CMD_WARNING;
9382 }
9383 }
9384
9385 /* Check IP address argument. */
9386 ret = str2prefix(ip_str, &match);
9387 if (!ret) {
9388 vty_out(vty, "%% address is malformed\n");
9389 return CMD_WARNING;
9390 }
9391
9392 match.family = afi2family(afi);
9393 rib = bgp->rib[afi][safi];
9394
9395 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9396 for (dest = bgp_table_top(rib); dest;
9397 dest = bgp_route_next(dest)) {
9398 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9399
9bcb3eef 9400 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9401 continue;
9402
9bcb3eef 9403 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9404 if (table == NULL)
9405 continue;
9406
4953391b
DA
9407 rm = bgp_node_match(table, &match);
9408 if (rm != NULL) {
b54892e0 9409 const struct prefix *rm_p =
9bcb3eef 9410 bgp_dest_get_prefix(rm);
b54892e0
DS
9411
9412 if (rm_p->prefixlen == match.prefixlen) {
9413 SET_FLAG(rm->flags,
9414 BGP_NODE_USER_CLEAR);
9415 bgp_process(bgp, rm, afi, safi);
d62a17ae 9416 }
9bcb3eef 9417 bgp_dest_unlock_node(rm);
d62a17ae 9418 }
9419 }
9420 } else {
4953391b
DA
9421 dest = bgp_node_match(rib, &match);
9422 if (dest != NULL) {
9bcb3eef 9423 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9424
9bcb3eef
DS
9425 if (dest_p->prefixlen == match.prefixlen) {
9426 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9427 bgp_process(bgp, dest, afi, safi);
d62a17ae 9428 }
9bcb3eef 9429 bgp_dest_unlock_node(dest);
d62a17ae 9430 }
9431 }
9432
9433 return CMD_SUCCESS;
8ad7271d
DS
9434}
9435
b09b5ae0 9436/* one clear bgp command to rule them all */
718e3744 9437DEFUN (clear_ip_bgp_all,
9438 clear_ip_bgp_all_cmd,
3cb14f26 9439 "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 9440 CLEAR_STR
9441 IP_STR
9442 BGP_STR
838758ac 9443 BGP_INSTANCE_HELP_STR
510afcd6 9444 BGP_AFI_HELP_STR
fd5e7b70 9445 "Address Family\n"
510afcd6 9446 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 9447 "Address Family modifier\n"
b09b5ae0 9448 "Clear all peers\n"
453c92f6 9449 "BGP IPv4 neighbor to clear\n"
a80beece 9450 "BGP IPv6 neighbor to clear\n"
838758ac 9451 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9452 "Clear peers with the AS number\n"
9453 "Clear all external peers\n"
718e3744 9454 "Clear all members of peer-group\n"
b09b5ae0 9455 "BGP peer-group name\n"
b09b5ae0
DW
9456 BGP_SOFT_STR
9457 BGP_SOFT_IN_STR
b09b5ae0
DW
9458 BGP_SOFT_OUT_STR
9459 BGP_SOFT_IN_STR
9460 "Push out prefix-list ORF and do inbound soft reconfig\n"
3cb14f26
DS
9461 BGP_SOFT_OUT_STR
9462 "Reset message statistics\n")
718e3744 9463{
d62a17ae 9464 char *vrf = NULL;
9465
dc912615
DS
9466 afi_t afi = AFI_UNSPEC;
9467 safi_t safi = SAFI_UNSPEC;
d62a17ae 9468 enum clear_sort clr_sort = clear_peer;
9469 enum bgp_clear_type clr_type;
9470 char *clr_arg = NULL;
9471
9472 int idx = 0;
9473
9474 /* clear [ip] bgp */
9475 if (argv_find(argv, argc, "ip", &idx))
9476 afi = AFI_IP;
9477
9a8bdf1c
PG
9478 /* [<vrf> VIEWVRFNAME] */
9479 if (argv_find(argv, argc, "vrf", &idx)) {
9480 vrf = argv[idx + 1]->arg;
9481 idx += 2;
9482 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9483 vrf = NULL;
9484 } else if (argv_find(argv, argc, "view", &idx)) {
9485 /* [<view> VIEWVRFNAME] */
d62a17ae 9486 vrf = argv[idx + 1]->arg;
9487 idx += 2;
9488 }
d62a17ae 9489 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9490 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9491 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9492
d7b9898c 9493 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 9494 if (argv_find(argv, argc, "*", &idx)) {
9495 clr_sort = clear_all;
9496 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9497 clr_sort = clear_peer;
9498 clr_arg = argv[idx]->arg;
9499 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9500 clr_sort = clear_peer;
9501 clr_arg = argv[idx]->arg;
9502 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9503 clr_sort = clear_group;
9504 idx++;
9505 clr_arg = argv[idx]->arg;
d7b9898c 9506 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 9507 clr_sort = clear_peer;
9508 clr_arg = argv[idx]->arg;
8fa7d444
DS
9509 } else if (argv_find(argv, argc, "WORD", &idx)) {
9510 clr_sort = clear_peer;
9511 clr_arg = argv[idx]->arg;
d62a17ae 9512 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9513 clr_sort = clear_as;
9514 clr_arg = argv[idx]->arg;
9515 } else if (argv_find(argv, argc, "external", &idx)) {
9516 clr_sort = clear_external;
9517 }
9518
3cb14f26 9519 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
d62a17ae 9520 if (argv_find(argv, argc, "soft", &idx)) {
9521 if (argv_find(argv, argc, "in", &idx)
9522 || argv_find(argv, argc, "out", &idx))
9523 clr_type = strmatch(argv[idx]->text, "in")
9524 ? BGP_CLEAR_SOFT_IN
9525 : BGP_CLEAR_SOFT_OUT;
9526 else
9527 clr_type = BGP_CLEAR_SOFT_BOTH;
9528 } else if (argv_find(argv, argc, "in", &idx)) {
9529 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9530 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9531 : BGP_CLEAR_SOFT_IN;
9532 } else if (argv_find(argv, argc, "out", &idx)) {
9533 clr_type = BGP_CLEAR_SOFT_OUT;
3cb14f26
DS
9534 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9535 clr_type = BGP_CLEAR_MESSAGE_STATS;
d62a17ae 9536 } else
9537 clr_type = BGP_CLEAR_SOFT_NONE;
9538
1ca2fd11 9539 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 9540}
01080f7c 9541
8ad7271d
DS
9542DEFUN (clear_ip_bgp_prefix,
9543 clear_ip_bgp_prefix_cmd,
18c57037 9544 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
9545 CLEAR_STR
9546 IP_STR
9547 BGP_STR
838758ac 9548 BGP_INSTANCE_HELP_STR
8ad7271d 9549 "Clear bestpath and re-advertise\n"
0c7b1b01 9550 "IPv4 prefix\n")
8ad7271d 9551{
d62a17ae 9552 char *vrf = NULL;
9553 char *prefix = NULL;
8ad7271d 9554
d62a17ae 9555 int idx = 0;
01080f7c 9556
d62a17ae 9557 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
9558 if (argv_find(argv, argc, "vrf", &idx)) {
9559 vrf = argv[idx + 1]->arg;
9560 idx += 2;
9561 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9562 vrf = NULL;
9563 } else if (argv_find(argv, argc, "view", &idx)) {
9564 /* [<view> VIEWVRFNAME] */
9565 vrf = argv[idx + 1]->arg;
9566 idx += 2;
9567 }
0c7b1b01 9568
d62a17ae 9569 prefix = argv[argc - 1]->arg;
8ad7271d 9570
d62a17ae 9571 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 9572}
8ad7271d 9573
b09b5ae0
DW
9574DEFUN (clear_bgp_ipv6_safi_prefix,
9575 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 9576 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9577 CLEAR_STR
3a2d747c 9578 IP_STR
718e3744 9579 BGP_STR
8c3deaae 9580 "Address Family\n"
46f296b4 9581 BGP_SAFI_HELP_STR
b09b5ae0 9582 "Clear bestpath and re-advertise\n"
0c7b1b01 9583 "IPv6 prefix\n")
718e3744 9584{
9b475e76
PG
9585 int idx_safi = 0;
9586 int idx_ipv6_prefix = 0;
9587 safi_t safi = SAFI_UNICAST;
9588 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9589 argv[idx_ipv6_prefix]->arg : NULL;
9590
9591 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 9592 return bgp_clear_prefix(
9b475e76
PG
9593 vty, NULL, prefix, AFI_IP6,
9594 safi, NULL);
838758ac 9595}
01080f7c 9596
b09b5ae0
DW
9597DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9598 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 9599 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9600 CLEAR_STR
3a2d747c 9601 IP_STR
718e3744 9602 BGP_STR
838758ac 9603 BGP_INSTANCE_HELP_STR
8c3deaae 9604 "Address Family\n"
46f296b4 9605 BGP_SAFI_HELP_STR
b09b5ae0 9606 "Clear bestpath and re-advertise\n"
0c7b1b01 9607 "IPv6 prefix\n")
718e3744 9608{
9b475e76 9609 int idx_safi = 0;
9a8bdf1c 9610 int idx_vrfview = 0;
9b475e76
PG
9611 int idx_ipv6_prefix = 0;
9612 safi_t safi = SAFI_UNICAST;
9613 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9614 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 9615 char *vrfview = NULL;
9b475e76 9616
9a8bdf1c
PG
9617 /* [<view|vrf> VIEWVRFNAME] */
9618 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9619 vrfview = argv[idx_vrfview + 1]->arg;
9620 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9621 vrfview = NULL;
9622 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9623 /* [<view> VIEWVRFNAME] */
9624 vrfview = argv[idx_vrfview + 1]->arg;
9625 }
9b475e76
PG
9626 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9627
d62a17ae 9628 return bgp_clear_prefix(
9b475e76
PG
9629 vty, vrfview, prefix,
9630 AFI_IP6, safi, NULL);
718e3744 9631}
9632
b09b5ae0
DW
9633DEFUN (show_bgp_views,
9634 show_bgp_views_cmd,
d6e3c605 9635 "show [ip] bgp views",
b09b5ae0 9636 SHOW_STR
d6e3c605 9637 IP_STR
01080f7c 9638 BGP_STR
b09b5ae0 9639 "Show the defined BGP views\n")
01080f7c 9640{
d62a17ae 9641 struct list *inst = bm->bgp;
9642 struct listnode *node;
9643 struct bgp *bgp;
01080f7c 9644
d62a17ae 9645 vty_out(vty, "Defined BGP views:\n");
9646 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9647 /* Skip VRFs. */
9648 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9649 continue;
9650 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9651 bgp->as);
9652 }
e52702f2 9653
d62a17ae 9654 return CMD_SUCCESS;
e0081f70
ML
9655}
9656
8386ac43 9657DEFUN (show_bgp_vrfs,
9658 show_bgp_vrfs_cmd,
d6e3c605 9659 "show [ip] bgp vrfs [json]",
8386ac43 9660 SHOW_STR
d6e3c605 9661 IP_STR
8386ac43 9662 BGP_STR
9663 "Show BGP VRFs\n"
9973d184 9664 JSON_STR)
8386ac43 9665{
fe1dc5a3 9666 char buf[ETHER_ADDR_STRLEN];
d62a17ae 9667 struct list *inst = bm->bgp;
9668 struct listnode *node;
9669 struct bgp *bgp;
9f049418 9670 bool uj = use_json(argc, argv);
d62a17ae 9671 json_object *json = NULL;
9672 json_object *json_vrfs = NULL;
9673 int count = 0;
d62a17ae 9674
d62a17ae 9675 if (uj) {
9676 json = json_object_new_object();
9677 json_vrfs = json_object_new_object();
9678 }
9679
9680 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9681 const char *name, *type;
9682 struct peer *peer;
7fe96307 9683 struct listnode *node2, *nnode2;
d62a17ae 9684 int peers_cfg, peers_estb;
9685 json_object *json_vrf = NULL;
d62a17ae 9686
9687 /* Skip Views. */
9688 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9689 continue;
9690
9691 count++;
efb4077a 9692 if (!uj && count == 1) {
fe1dc5a3 9693 vty_out(vty,
efb4077a 9694 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 9695 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
9696 "#PeersEstb", "Name");
9697 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9698 "L3-VNI", "RouterMAC", "Interface");
9699 }
d62a17ae 9700
9701 peers_cfg = peers_estb = 0;
9702 if (uj)
9703 json_vrf = json_object_new_object();
9704
9705
7fe96307 9706 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 9707 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9708 continue;
9709 peers_cfg++;
feb17238 9710 if (peer_established(peer))
d62a17ae 9711 peers_estb++;
9712 }
9713
9714 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 9715 name = VRF_DEFAULT_NAME;
d62a17ae 9716 type = "DFLT";
9717 } else {
9718 name = bgp->name;
9719 type = "VRF";
9720 }
9721
a8bf7d9c 9722
d62a17ae 9723 if (uj) {
a4d82a8a
PZ
9724 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9725 ? -1
9726 : (int64_t)bgp->vrf_id;
23d0a753
DA
9727 char buf[BUFSIZ] = {0};
9728
d62a17ae 9729 json_object_string_add(json_vrf, "type", type);
9730 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
c949c771
DA
9731 json_object_string_addf(json_vrf, "routerId", "%pI4",
9732 &bgp->router_id);
d62a17ae 9733 json_object_int_add(json_vrf, "numConfiguredPeers",
9734 peers_cfg);
9735 json_object_int_add(json_vrf, "numEstablishedPeers",
9736 peers_estb);
9737
fe1dc5a3 9738 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
9739 json_object_string_add(
9740 json_vrf, "rmac",
9741 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
9742 json_object_string_add(json_vrf, "interface",
9743 ifindex2ifname(bgp->l3vni_svi_ifindex,
9744 bgp->vrf_id));
d62a17ae 9745 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 9746 } else {
23d0a753 9747 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
9748 type,
9749 bgp->vrf_id == VRF_UNKNOWN ? -1
9750 : (int)bgp->vrf_id,
23d0a753 9751 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
9752 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
9753 bgp->l3vni,
9754 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
9755 ifindex2ifname(bgp->l3vni_svi_ifindex,
9756 bgp->vrf_id));
9757 }
d62a17ae 9758 }
9759
9760 if (uj) {
9761 json_object_object_add(json, "vrfs", json_vrfs);
9762
9763 json_object_int_add(json, "totalVrfs", count);
9764
75eeda93 9765 vty_json(vty, json);
d62a17ae 9766 } else {
9767 if (count)
9768 vty_out(vty,
9769 "\nTotal number of VRFs (including default): %d\n",
9770 count);
9771 }
9772
9773 return CMD_SUCCESS;
8386ac43 9774}
9775
48ecf8f5
DS
9776DEFUN (show_bgp_mac_hash,
9777 show_bgp_mac_hash_cmd,
9778 "show bgp mac hash",
9779 SHOW_STR
9780 BGP_STR
9781 "Mac Address\n"
9782 "Mac Address database\n")
9783{
9784 bgp_mac_dump_table(vty);
9785
9786 return CMD_SUCCESS;
9787}
acf71666 9788
e3b78da8 9789static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 9790{
0291c246 9791 struct vty *vty = (struct vty *)args;
e3b78da8 9792 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 9793
23d0a753 9794 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
9795}
9796
9797static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
9798{
9799 vty_out(vty, "self nexthop database:\n");
af97a18b 9800 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
9801
9802 vty_out(vty, "Tunnel-ip database:\n");
9803 hash_iterate(bgp->tip_hash,
e3b78da8 9804 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
9805 vty);
9806}
9807
15c81ca4
DS
9808DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
9809 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
9810 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
9811 "martian next-hops\n"
9812 "martian next-hop database\n")
acf71666 9813{
0291c246 9814 struct bgp *bgp = NULL;
15c81ca4 9815 int idx = 0;
9a8bdf1c
PG
9816 char *name = NULL;
9817
9818 /* [<vrf> VIEWVRFNAME] */
9819 if (argv_find(argv, argc, "vrf", &idx)) {
9820 name = argv[idx + 1]->arg;
9821 if (name && strmatch(name, VRF_DEFAULT_NAME))
9822 name = NULL;
9823 } else if (argv_find(argv, argc, "view", &idx))
9824 /* [<view> VIEWVRFNAME] */
9825 name = argv[idx + 1]->arg;
9826 if (name)
9827 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
9828 else
9829 bgp = bgp_get_default();
acf71666 9830
acf71666
MK
9831 if (!bgp) {
9832 vty_out(vty, "%% No BGP process is configured\n");
9833 return CMD_WARNING;
9834 }
9835 bgp_show_martian_nexthops(vty, bgp);
9836
9837 return CMD_SUCCESS;
9838}
9839
f412b39a 9840DEFUN (show_bgp_memory,
4bf6a362 9841 show_bgp_memory_cmd,
7fa12b13 9842 "show [ip] bgp memory",
4bf6a362 9843 SHOW_STR
3a2d747c 9844 IP_STR
4bf6a362
PJ
9845 BGP_STR
9846 "Global BGP memory statistics\n")
9847{
d62a17ae 9848 char memstrbuf[MTYPE_MEMSTR_LEN];
9849 unsigned long count;
9850
9851 /* RIB related usage stats */
9852 count = mtype_stats_alloc(MTYPE_BGP_NODE);
9853 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
9854 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 9855 count * sizeof(struct bgp_dest)));
d62a17ae 9856
9857 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
9858 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
9859 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 9860 count * sizeof(struct bgp_path_info)));
d62a17ae 9861 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
9862 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
9863 count,
4b7e6066
DS
9864 mtype_memstr(
9865 memstrbuf, sizeof(memstrbuf),
9866 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 9867
9868 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
9869 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
9870 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9871 count * sizeof(struct bgp_static)));
9872
9873 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
9874 vty_out(vty, "%ld Packets, using %s of memory\n", count,
9875 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9876 count * sizeof(struct bpacket)));
9877
9878 /* Adj-In/Out */
9879 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
9880 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
9881 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9882 count * sizeof(struct bgp_adj_in)));
9883 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
9884 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
9885 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9886 count * sizeof(struct bgp_adj_out)));
9887
9888 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
9889 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
9890 count,
9891 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9892 count * sizeof(struct bgp_nexthop_cache)));
9893
9894 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
9895 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
9896 count,
9897 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9898 count * sizeof(struct bgp_damp_info)));
9899
9900 /* Attributes */
9901 count = attr_count();
9902 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
9903 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9904 count * sizeof(struct attr)));
9905
9906 if ((count = attr_unknown_count()))
9907 vty_out(vty, "%ld unknown attributes\n", count);
9908
9909 /* AS_PATH attributes */
9910 count = aspath_count();
9911 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
9912 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9913 count * sizeof(struct aspath)));
9914
9915 count = mtype_stats_alloc(MTYPE_AS_SEG);
9916 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
9917 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9918 count * sizeof(struct assegment)));
9919
9920 /* Other attributes */
9921 if ((count = community_count()))
9922 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9923 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9924 count * sizeof(struct community)));
d62a17ae 9925 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
9926 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9927 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9928 count * sizeof(struct ecommunity)));
d62a17ae 9929 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
9930 vty_out(vty,
9931 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
9932 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9933 count * sizeof(struct lcommunity)));
d62a17ae 9934
9935 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
9936 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
9937 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9938 count * sizeof(struct cluster_list)));
9939
9940 /* Peer related usage */
9941 count = mtype_stats_alloc(MTYPE_BGP_PEER);
9942 vty_out(vty, "%ld peers, using %s of memory\n", count,
9943 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9944 count * sizeof(struct peer)));
9945
9946 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
9947 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
9948 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9949 count * sizeof(struct peer_group)));
9950
9951 /* Other */
d62a17ae 9952 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
9953 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
9954 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9955 count * sizeof(regex_t)));
d62a17ae 9956 return CMD_SUCCESS;
4bf6a362 9957}
fee0f4c6 9958
57a9c8a8
DS
9959static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
9960{
9961 json_object *bestpath = json_object_new_object();
9962
892fedb6 9963 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
9964 json_object_string_add(bestpath, "asPath", "ignore");
9965
892fedb6 9966 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
9967 json_object_string_add(bestpath, "asPath", "confed");
9968
892fedb6
DA
9969 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
9970 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 9971 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9972 "as-set");
9973 else
a4d82a8a 9974 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9975 "true");
9976 } else
a4d82a8a 9977 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 9978
ee88563a
JM
9979 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
9980 json_object_boolean_true_add(bestpath, "peerTypeRelax");
9981
892fedb6 9982 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 9983 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
9984 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
9985 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
9986 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 9987 json_object_string_add(bestpath, "med", "confed");
892fedb6 9988 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
9989 json_object_string_add(bestpath, "med",
9990 "missing-as-worst");
9991 else
9992 json_object_string_add(bestpath, "med", "true");
9993 }
9994
9995 json_object_object_add(json, "bestPath", bestpath);
9996}
9997
3577f1c5
DD
9998/* Print the error code/subcode for why the peer is down */
9999static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10000 json_object *json_peer, bool use_json)
10001{
10002 const char *code_str;
10003 const char *subcode_str;
10004
10005 if (use_json) {
10006 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10007 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10008 char errorcodesubcode_hexstr[5];
10009 char errorcodesubcode_str[256];
10010
10011 code_str = bgp_notify_code_str(peer->notify.code);
10012 subcode_str = bgp_notify_subcode_str(
10013 peer->notify.code,
10014 peer->notify.subcode);
10015
772270f3
QY
10016 snprintf(errorcodesubcode_hexstr,
10017 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10018 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10019 json_object_string_add(json_peer,
10020 "lastErrorCodeSubcode",
10021 errorcodesubcode_hexstr);
10022 snprintf(errorcodesubcode_str, 255, "%s%s",
10023 code_str, subcode_str);
10024 json_object_string_add(json_peer,
10025 "lastNotificationReason",
10026 errorcodesubcode_str);
10027 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10028 && peer->notify.code == BGP_NOTIFY_CEASE
10029 && (peer->notify.subcode
10030 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10031 || peer->notify.subcode
10032 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10033 && peer->notify.length) {
10034 char msgbuf[1024];
10035 const char *msg_str;
10036
10037 msg_str = bgp_notify_admin_message(
10038 msgbuf, sizeof(msgbuf),
10039 (uint8_t *)peer->notify.data,
10040 peer->notify.length);
10041 if (msg_str)
10042 json_object_string_add(
10043 json_peer,
10044 "lastShutdownDescription",
10045 msg_str);
10046 }
10047
c258527b 10048 }
3577f1c5
DD
10049 json_object_string_add(json_peer, "lastResetDueTo",
10050 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10051 json_object_int_add(json_peer, "lastResetCode",
10052 peer->last_reset);
3577f1c5
DD
10053 } else {
10054 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10055 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10056 code_str = bgp_notify_code_str(peer->notify.code);
10057 subcode_str =
10058 bgp_notify_subcode_str(peer->notify.code,
10059 peer->notify.subcode);
10060 vty_out(vty, " Notification %s (%s%s)\n",
10061 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10062 ? "sent"
10063 : "received",
10064 code_str, subcode_str);
10065 } else {
e91c24c8 10066 vty_out(vty, " %s\n",
3577f1c5
DD
10067 peer_down_str[(int)peer->last_reset]);
10068 }
10069 }
10070}
10071
10072static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10073 safi_t safi)
10074{
feb17238 10075 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
3577f1c5
DD
10076}
10077
10078static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10079 struct peer *peer, json_object *json_peer,
10080 int max_neighbor_width, bool use_json)
10081{
10082 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10083 int len;
10084
10085 if (use_json) {
10086 if (peer_dynamic_neighbor(peer))
10087 json_object_boolean_true_add(json_peer,
10088 "dynamicPeer");
10089 if (peer->hostname)
10090 json_object_string_add(json_peer, "hostname",
10091 peer->hostname);
10092
10093 if (peer->domainname)
10094 json_object_string_add(json_peer, "domainname",
10095 peer->domainname);
10096 json_object_int_add(json_peer, "connectionsEstablished",
10097 peer->established);
10098 json_object_int_add(json_peer, "connectionsDropped",
10099 peer->dropped);
10100 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10101 use_json, json_peer);
feb17238 10102 if (peer_established(peer))
3577f1c5
DD
10103 json_object_string_add(json_peer, "lastResetDueTo",
10104 "AFI/SAFI Not Negotiated");
10105 else
10106 bgp_show_peer_reset(NULL, peer, json_peer, true);
10107 } else {
10108 dn_flag[1] = '\0';
10109 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10110 if (peer->hostname
892fedb6 10111 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10112 len = vty_out(vty, "%s%s(%s)", dn_flag,
10113 peer->hostname, peer->host);
10114 else
10115 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10116
10117 /* pad the neighbor column with spaces */
10118 if (len < max_neighbor_width)
10119 vty_out(vty, "%*s", max_neighbor_width - len,
10120 " ");
e91c24c8 10121 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10122 peer->dropped,
10123 peer_uptime(peer->uptime, timebuf,
10124 BGP_UPTIME_LEN, 0, NULL));
feb17238 10125 if (peer_established(peer))
3577f1c5
DD
10126 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10127 else
10128 bgp_show_peer_reset(vty, peer, NULL,
10129 false);
10130 }
10131}
c258527b 10132
565e9ddd 10133/* Strip peer's description to the given size. */
cb75bb31
DA
10134static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10135{
10136 static char stripped[BUFSIZ];
cb75bb31
DA
10137 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10138
cb75bb31
DA
10139 strlcpy(stripped, desc, len + 1);
10140
10141 return stripped;
10142}
3577f1c5 10143
8c1d4cd5
LS
10144/* Determine whether var peer should be filtered out of the summary. */
10145static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10146 struct peer *fpeer, int as_type,
10147 as_t as)
10148{
10149
10150 /* filter neighbor XXXX */
10151 if (fpeer && fpeer != peer)
10152 return true;
10153
10154 /* filter remote-as (internal|external) */
10155 if (as_type != AS_UNSPECIFIED) {
10156 if (peer->as_type == AS_SPECIFIED) {
10157 if (as_type == AS_INTERNAL) {
10158 if (peer->as != peer->local_as)
10159 return true;
10160 } else if (peer->as == peer->local_as)
10161 return true;
10162 } else if (as_type != peer->as_type)
10163 return true;
10164 } else if (as && as != peer->as) /* filter remote-as XXX */
10165 return true;
10166
10167 return false;
10168}
10169
565e9ddd
DA
10170/* Show BGP peer's summary information.
10171 *
10172 * Peer's description is stripped according to if `wide` option is given
10173 * or not.
10174 *
10175 * When adding new columns to `show bgp summary` output, please make
10176 * sure `Desc` is the lastest column to show because it can contain
10177 * whitespaces and the whole output will be tricky.
10178 */
d62a17ae 10179static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 10180 struct peer *fpeer, int as_type, as_t as,
96c81f66 10181 uint16_t show_flags)
d62a17ae 10182{
10183 struct peer *peer;
10184 struct listnode *node, *nnode;
10185 unsigned int count = 0, dn_count = 0;
10186 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10187 char neighbor_buf[VTY_BUFSIZ];
10188 int neighbor_col_default_width = 16;
3577f1c5 10189 int len, failed_count = 0;
ce1944f0 10190 unsigned int filtered_count = 0;
d62a17ae 10191 int max_neighbor_width = 0;
10192 int pfx_rcd_safi;
3c13337d 10193 json_object *json = NULL;
d62a17ae 10194 json_object *json_peer = NULL;
10195 json_object *json_peers = NULL;
50e05855 10196 struct peer_af *paf;
d3ada366 10197 struct bgp_filter *filter;
85eeb029
DA
10198 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10199 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10200 bool show_established =
10201 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10202 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
96c81f66 10203 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
d62a17ae 10204
10205 /* labeled-unicast routes are installed in the unicast table so in order
10206 * to
10207 * display the correct PfxRcd value we must look at SAFI_UNICAST
10208 */
3577f1c5 10209
d62a17ae 10210 if (safi == SAFI_LABELED_UNICAST)
10211 pfx_rcd_safi = SAFI_UNICAST;
10212 else
10213 pfx_rcd_safi = safi;
10214
10215 if (use_json) {
3c13337d 10216 json = json_object_new_object();
d62a17ae 10217 json_peers = json_object_new_object();
3577f1c5 10218 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10219 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10220 as_type, as)) {
ce1944f0 10221 filtered_count++;
8c1d4cd5
LS
10222 count++;
10223 continue;
10224 }
10225
3577f1c5
DD
10226 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10227 continue;
10228
10229 if (peer->afc[afi][safi]) {
10230 /* See if we have at least a single failed peer */
10231 if (bgp_has_peer_failed(peer, afi, safi))
10232 failed_count++;
10233 count++;
10234 }
10235 if (peer_dynamic_neighbor(peer))
10236 dn_count++;
10237 }
c258527b 10238
d62a17ae 10239 } else {
10240 /* Loop over all neighbors that will be displayed to determine
10241 * how many
10242 * characters are needed for the Neighbor column
10243 */
10244 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10245 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10246 as_type, as)) {
ce1944f0 10247 filtered_count++;
8c1d4cd5
LS
10248 count++;
10249 continue;
10250 }
10251
d62a17ae 10252 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10253 continue;
10254
10255 if (peer->afc[afi][safi]) {
10256 memset(dn_flag, '\0', sizeof(dn_flag));
10257 if (peer_dynamic_neighbor(peer))
10258 dn_flag[0] = '*';
10259
10260 if (peer->hostname
892fedb6
DA
10261 && CHECK_FLAG(bgp->flags,
10262 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10263 snprintf(neighbor_buf,
10264 sizeof(neighbor_buf),
10265 "%s%s(%s) ", dn_flag,
10266 peer->hostname, peer->host);
d62a17ae 10267 else
772270f3
QY
10268 snprintf(neighbor_buf,
10269 sizeof(neighbor_buf), "%s%s ",
10270 dn_flag, peer->host);
d62a17ae 10271
10272 len = strlen(neighbor_buf);
10273
10274 if (len > max_neighbor_width)
10275 max_neighbor_width = len;
c258527b 10276
3577f1c5
DD
10277 /* See if we have at least a single failed peer */
10278 if (bgp_has_peer_failed(peer, afi, safi))
10279 failed_count++;
10280 count++;
d62a17ae 10281 }
10282 }
f933309e 10283
d62a17ae 10284 /* Originally we displayed the Neighbor column as 16
10285 * characters wide so make that the default
10286 */
10287 if (max_neighbor_width < neighbor_col_default_width)
10288 max_neighbor_width = neighbor_col_default_width;
10289 }
f933309e 10290
3577f1c5
DD
10291 if (show_failed && !failed_count) {
10292 if (use_json) {
10293 json_object_int_add(json, "failedPeersCount", 0);
10294 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10295 json_object_int_add(json, "totalPeers", count);
3577f1c5 10296
75eeda93 10297 vty_json(vty, json);
3577f1c5
DD
10298 } else {
10299 vty_out(vty, "%% No failed BGP neighbors found\n");
3577f1c5
DD
10300 }
10301 return CMD_SUCCESS;
10302 }
c258527b 10303
3577f1c5 10304 count = 0; /* Reset the value as its used again */
ce1944f0 10305 filtered_count = 0;
800867d8 10306 dn_count = 0;
d62a17ae 10307 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10308 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10309 continue;
10310
ea47320b
DL
10311 if (!peer->afc[afi][safi])
10312 continue;
d62a17ae 10313
ea47320b
DL
10314 if (!count) {
10315 unsigned long ents;
10316 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10317 int64_t vrf_id_ui;
d62a17ae 10318
a4d82a8a
PZ
10319 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10320 ? -1
10321 : (int64_t)bgp->vrf_id;
ea47320b
DL
10322
10323 /* Usage summary and header */
10324 if (use_json) {
c949c771
DA
10325 json_object_string_addf(json, "routerId",
10326 "%pI4",
10327 &bgp->router_id);
60466a63
QY
10328 json_object_int_add(json, "as", bgp->as);
10329 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10330 json_object_string_add(
10331 json, "vrfName",
10332 (bgp->inst_type
10333 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10334 ? VRF_DEFAULT_NAME
ea47320b
DL
10335 : bgp->name);
10336 } else {
10337 vty_out(vty,
23d0a753
DA
10338 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10339 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10340 bgp->vrf_id == VRF_UNKNOWN
10341 ? -1
10342 : (int)bgp->vrf_id);
ea47320b
DL
10343 vty_out(vty, "\n");
10344 }
d62a17ae 10345
ea47320b 10346 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10347 if (use_json) {
ea47320b 10348 json_object_int_add(
60466a63 10349 json, "updateDelayLimit",
ea47320b 10350 bgp->v_update_delay);
d62a17ae 10351
ea47320b
DL
10352 if (bgp->v_update_delay
10353 != bgp->v_establish_wait)
d62a17ae 10354 json_object_int_add(
10355 json,
ea47320b
DL
10356 "updateDelayEstablishWait",
10357 bgp->v_establish_wait);
d62a17ae 10358
60466a63 10359 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10360 json_object_string_add(
10361 json,
10362 "updateDelayFirstNeighbor",
10363 bgp->update_delay_begin_time);
10364 json_object_boolean_true_add(
10365 json,
10366 "updateDelayInProgress");
10367 } else {
10368 if (bgp->update_delay_over) {
d62a17ae 10369 json_object_string_add(
10370 json,
10371 "updateDelayFirstNeighbor",
10372 bgp->update_delay_begin_time);
ea47320b 10373 json_object_string_add(
d62a17ae 10374 json,
ea47320b
DL
10375 "updateDelayBestpathResumed",
10376 bgp->update_delay_end_time);
10377 json_object_string_add(
d62a17ae 10378 json,
ea47320b
DL
10379 "updateDelayZebraUpdateResume",
10380 bgp->update_delay_zebra_resume_time);
10381 json_object_string_add(
10382 json,
10383 "updateDelayPeerUpdateResume",
10384 bgp->update_delay_peers_resume_time);
d62a17ae 10385 }
ea47320b
DL
10386 }
10387 } else {
10388 vty_out(vty,
10389 "Read-only mode update-delay limit: %d seconds\n",
10390 bgp->v_update_delay);
10391 if (bgp->v_update_delay
10392 != bgp->v_establish_wait)
d62a17ae 10393 vty_out(vty,
ea47320b
DL
10394 " Establish wait: %d seconds\n",
10395 bgp->v_establish_wait);
d62a17ae 10396
60466a63 10397 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10398 vty_out(vty,
10399 " First neighbor established: %s\n",
10400 bgp->update_delay_begin_time);
10401 vty_out(vty,
10402 " Delay in progress\n");
10403 } else {
10404 if (bgp->update_delay_over) {
d62a17ae 10405 vty_out(vty,
10406 " First neighbor established: %s\n",
10407 bgp->update_delay_begin_time);
10408 vty_out(vty,
ea47320b
DL
10409 " Best-paths resumed: %s\n",
10410 bgp->update_delay_end_time);
10411 vty_out(vty,
10412 " zebra update resumed: %s\n",
10413 bgp->update_delay_zebra_resume_time);
10414 vty_out(vty,
10415 " peers update resumed: %s\n",
10416 bgp->update_delay_peers_resume_time);
d62a17ae 10417 }
10418 }
10419 }
ea47320b 10420 }
d62a17ae 10421
ea47320b
DL
10422 if (use_json) {
10423 if (bgp_maxmed_onstartup_configured(bgp)
10424 && bgp->maxmed_active)
10425 json_object_boolean_true_add(
60466a63 10426 json, "maxMedOnStartup");
ea47320b
DL
10427 if (bgp->v_maxmed_admin)
10428 json_object_boolean_true_add(
60466a63 10429 json, "maxMedAdministrative");
d62a17ae 10430
ea47320b
DL
10431 json_object_int_add(
10432 json, "tableVersion",
60466a63 10433 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 10434
60466a63
QY
10435 ents = bgp_table_count(bgp->rib[afi][safi]);
10436 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
10437 json_object_int_add(
10438 json, "ribMemory",
9bcb3eef 10439 ents * sizeof(struct bgp_dest));
d62a17ae 10440
210ec2a0 10441 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
10442 json_object_int_add(json, "peerCount", ents);
10443 json_object_int_add(json, "peerMemory",
10444 ents * sizeof(struct peer));
d62a17ae 10445
ea47320b
DL
10446 if ((ents = listcount(bgp->group))) {
10447 json_object_int_add(
60466a63 10448 json, "peerGroupCount", ents);
ea47320b
DL
10449 json_object_int_add(
10450 json, "peerGroupMemory",
996c9314
LB
10451 ents * sizeof(struct
10452 peer_group));
ea47320b 10453 }
d62a17ae 10454
ea47320b
DL
10455 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10456 BGP_CONFIG_DAMPENING))
10457 json_object_boolean_true_add(
60466a63 10458 json, "dampeningEnabled");
ea47320b 10459 } else {
96c81f66
LS
10460 if (!show_terse) {
10461 if (bgp_maxmed_onstartup_configured(bgp)
10462 && bgp->maxmed_active)
10463 vty_out(vty,
10464 "Max-med on-startup active\n");
10465 if (bgp->v_maxmed_admin)
10466 vty_out(vty,
10467 "Max-med administrative active\n");
d62a17ae 10468
96c81f66
LS
10469 vty_out(vty,
10470 "BGP table version %" PRIu64
10471 "\n",
10472 bgp_table_version(
10473 bgp->rib[afi][safi]));
ea47320b 10474
96c81f66
LS
10475 ents = bgp_table_count(
10476 bgp->rib[afi][safi]);
d62a17ae 10477 vty_out(vty,
96c81f66 10478 "RIB entries %ld, using %s of memory\n",
d62a17ae 10479 ents,
10480 mtype_memstr(
10481 memstrbuf,
10482 sizeof(memstrbuf),
96c81f66
LS
10483 ents
10484 * sizeof(
10485 struct
10486 bgp_dest)));
d62a17ae 10487
96c81f66
LS
10488 /* Peer related usage */
10489 ents = bgp->af_peer_count[afi][safi];
10490 vty_out(vty,
10491 "Peers %ld, using %s of memory\n",
10492 ents,
10493 mtype_memstr(
10494 memstrbuf,
10495 sizeof(memstrbuf),
10496 ents
10497 * sizeof(
10498 struct
10499 peer)));
d62a17ae 10500
96c81f66
LS
10501 if ((ents = listcount(bgp->group)))
10502 vty_out(vty,
10503 "Peer groups %ld, using %s of memory\n",
10504 ents,
10505 mtype_memstr(
10506 memstrbuf,
10507 sizeof(memstrbuf),
10508 ents
10509 * sizeof(
10510 struct
10511 peer_group)));
10512
10513 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10514 BGP_CONFIG_DAMPENING))
10515 vty_out(vty,
10516 "Dampening enabled.\n");
10517 }
10518 if (show_failed) {
10519 vty_out(vty, "\n");
10520
10521 /* Subtract 8 here because 'Neighbor' is
10522 * 8 characters */
10523 vty_out(vty, "Neighbor");
10524 vty_out(vty, "%*s",
10525 max_neighbor_width - 8, " ");
85eeb029
DA
10526 vty_out(vty,
10527 BGP_SHOW_SUMMARY_HEADER_FAILED);
96c81f66 10528 }
d62a17ae 10529 }
ea47320b 10530 }
d62a17ae 10531
d55811cc 10532 paf = peer_af_find(peer, afi, safi);
d3ada366 10533 filter = &peer->filter[afi][safi];
db92d226 10534
ea47320b 10535 count++;
3577f1c5
DD
10536 /* Works for both failed & successful cases */
10537 if (peer_dynamic_neighbor(peer))
10538 dn_count++;
d62a17ae 10539
ea47320b 10540 if (use_json) {
3577f1c5 10541 json_peer = NULL;
8c1d4cd5 10542 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
10543 as_type, as)) {
10544 filtered_count++;
8c1d4cd5 10545 continue;
ce1944f0 10546 }
3577f1c5
DD
10547 if (show_failed &&
10548 bgp_has_peer_failed(peer, afi, safi)) {
10549 json_peer = json_object_new_object();
10550 bgp_show_failed_summary(vty, bgp, peer,
10551 json_peer, 0, use_json);
10552 } else if (!show_failed) {
10b49f14 10553 if (show_established
ce1944f0
LS
10554 && bgp_has_peer_failed(peer, afi, safi)) {
10555 filtered_count++;
10b49f14 10556 continue;
ce1944f0 10557 }
10b49f14 10558
3577f1c5
DD
10559 json_peer = json_object_new_object();
10560 if (peer_dynamic_neighbor(peer)) {
10561 json_object_boolean_true_add(json_peer,
10562 "dynamicPeer");
10563 }
d62a17ae 10564
3577f1c5
DD
10565 if (peer->hostname)
10566 json_object_string_add(json_peer, "hostname",
10567 peer->hostname);
10568
10569 if (peer->domainname)
10570 json_object_string_add(json_peer, "domainname",
10571 peer->domainname);
10572
10573 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
10574 json_object_int_add(
10575 json_peer, "localAs",
10576 peer->change_local_as
10577 ? peer->change_local_as
10578 : peer->local_as);
3577f1c5
DD
10579 json_object_int_add(json_peer, "version", 4);
10580 json_object_int_add(json_peer, "msgRcvd",
10581 PEER_TOTAL_RX(peer));
10582 json_object_int_add(json_peer, "msgSent",
10583 PEER_TOTAL_TX(peer));
10584
43aa5965
QY
10585 atomic_size_t outq_count, inq_count;
10586 outq_count = atomic_load_explicit(
10587 &peer->obuf->count,
10588 memory_order_relaxed);
10589 inq_count = atomic_load_explicit(
10590 &peer->ibuf->count,
10591 memory_order_relaxed);
10592
3577f1c5
DD
10593 json_object_int_add(json_peer, "tableVersion",
10594 peer->version[afi][safi]);
10595 json_object_int_add(json_peer, "outq",
43aa5965
QY
10596 outq_count);
10597 json_object_int_add(json_peer, "inq",
10598 inq_count);
3577f1c5
DD
10599 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10600 use_json, json_peer);
10601
3577f1c5
DD
10602 json_object_int_add(json_peer, "pfxRcd",
10603 peer->pcount[afi][pfx_rcd_safi]);
10604
3577f1c5 10605 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
10606 json_object_int_add(
10607 json_peer, "pfxSnt",
10608 (PAF_SUBGRP(paf))->scount);
10609 else
10610 json_object_int_add(json_peer, "pfxSnt",
10611 0);
0e1f8ab5
DA
10612
10613 /* BGP FSM state */
cb9196e7 10614 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
10615 || CHECK_FLAG(peer->bgp->flags,
10616 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
10617 json_object_string_add(json_peer,
10618 "state",
3577f1c5
DD
10619 "Idle (Admin)");
10620 else if (peer->afc_recv[afi][safi])
10621 json_object_string_add(
0e1f8ab5
DA
10622 json_peer, "state",
10623 lookup_msg(bgp_status_msg,
10624 peer->status, NULL));
10625 else if (CHECK_FLAG(
10626 peer->sflags,
10627 PEER_STATUS_PREFIX_OVERFLOW))
10628 json_object_string_add(json_peer,
10629 "state",
3577f1c5
DD
10630 "Idle (PfxCt)");
10631 else
10632 json_object_string_add(
0e1f8ab5
DA
10633 json_peer, "state",
10634 lookup_msg(bgp_status_msg,
10635 peer->status, NULL));
10636
10637 /* BGP peer state */
10638 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10639 || CHECK_FLAG(peer->bgp->flags,
10640 BGP_FLAG_SHUTDOWN))
10641 json_object_string_add(json_peer,
10642 "peerState",
10643 "Admin");
10644 else if (CHECK_FLAG(
10645 peer->sflags,
10646 PEER_STATUS_PREFIX_OVERFLOW))
10647 json_object_string_add(json_peer,
10648 "peerState",
10649 "PfxCt");
10650 else if (CHECK_FLAG(peer->flags,
10651 PEER_FLAG_PASSIVE))
10652 json_object_string_add(json_peer,
10653 "peerState",
10654 "Passive");
10655 else if (CHECK_FLAG(peer->sflags,
10656 PEER_STATUS_NSF_WAIT))
10657 json_object_string_add(json_peer,
10658 "peerState",
10659 "NSF passive");
10660 else if (CHECK_FLAG(
10661 peer->bgp->flags,
10662 BGP_FLAG_EBGP_REQUIRES_POLICY)
10663 && (!bgp_inbound_policy_exists(peer,
10664 filter)
10665 || !bgp_outbound_policy_exists(
10666 peer, filter)))
10667 json_object_string_add(json_peer,
10668 "peerState",
10669 "Policy");
10670 else
10671 json_object_string_add(
10672 json_peer, "peerState", "OK");
10673
200116db
DD
10674 json_object_int_add(json_peer, "connectionsEstablished",
10675 peer->established);
10676 json_object_int_add(json_peer, "connectionsDropped",
10677 peer->dropped);
aa72bd7e
PG
10678 if (peer->desc)
10679 json_object_string_add(
10680 json_peer, "desc", peer->desc);
b4e9dcba 10681 }
3577f1c5
DD
10682 /* Avoid creating empty peer dicts in JSON */
10683 if (json_peer == NULL)
10684 continue;
ea47320b
DL
10685
10686 if (peer->conf_if)
60466a63 10687 json_object_string_add(json_peer, "idType",
ea47320b
DL
10688 "interface");
10689 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
10690 json_object_string_add(json_peer, "idType",
10691 "ipv4");
ea47320b 10692 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
10693 json_object_string_add(json_peer, "idType",
10694 "ipv6");
ea47320b
DL
10695 json_object_object_add(json_peers, peer->host,
10696 json_peer);
10697 } else {
8c1d4cd5 10698 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
10699 as_type, as)) {
10700 filtered_count++;
8c1d4cd5 10701 continue;
ce1944f0 10702 }
3577f1c5
DD
10703 if (show_failed &&
10704 bgp_has_peer_failed(peer, afi, safi)) {
10705 bgp_show_failed_summary(vty, bgp, peer, NULL,
10706 max_neighbor_width,
10707 use_json);
10708 } else if (!show_failed) {
10b49f14 10709 if (show_established
ce1944f0
LS
10710 && bgp_has_peer_failed(peer, afi, safi)) {
10711 filtered_count++;
10b49f14 10712 continue;
ce1944f0 10713 }
96c81f66
LS
10714
10715 if ((count - filtered_count) == 1) {
10716 /* display headline before the first
10717 * neighbor line */
10718 vty_out(vty, "\n");
10719
10720 /* Subtract 8 here because 'Neighbor' is
10721 * 8 characters */
10722 vty_out(vty, "Neighbor");
10723 vty_out(vty, "%*s",
10724 max_neighbor_width - 8, " ");
10725 vty_out(vty,
10726 show_wide
10727 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10728 : BGP_SHOW_SUMMARY_HEADER_ALL);
10729 }
10730
3577f1c5
DD
10731 memset(dn_flag, '\0', sizeof(dn_flag));
10732 if (peer_dynamic_neighbor(peer)) {
10733 dn_flag[0] = '*';
10734 }
d62a17ae 10735
3577f1c5 10736 if (peer->hostname
892fedb6
DA
10737 && CHECK_FLAG(bgp->flags,
10738 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 10739 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
10740 peer->hostname,
10741 peer->host);
d62a17ae 10742 else
3577f1c5
DD
10743 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10744
10745 /* pad the neighbor column with spaces */
10746 if (len < max_neighbor_width)
10747 vty_out(vty, "%*s", max_neighbor_width - len,
10748 " ");
10749
43aa5965
QY
10750 atomic_size_t outq_count, inq_count;
10751 outq_count = atomic_load_explicit(
10752 &peer->obuf->count,
10753 memory_order_relaxed);
10754 inq_count = atomic_load_explicit(
10755 &peer->ibuf->count,
10756 memory_order_relaxed);
10757
85eeb029
DA
10758 if (show_wide)
10759 vty_out(vty,
10760 "4 %10u %10u %9u %9u %8" PRIu64
10761 " %4zu %4zu %8s",
10762 peer->as,
10763 peer->change_local_as
10764 ? peer->change_local_as
10765 : peer->local_as,
10766 PEER_TOTAL_RX(peer),
10767 PEER_TOTAL_TX(peer),
10768 peer->version[afi][safi],
10769 inq_count, outq_count,
10770 peer_uptime(peer->uptime,
10771 timebuf,
10772 BGP_UPTIME_LEN, 0,
10773 NULL));
10774 else
10775 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
10776 " %4zu %4zu %8s",
10777 peer->as, PEER_TOTAL_RX(peer),
10778 PEER_TOTAL_TX(peer),
10779 peer->version[afi][safi],
10780 inq_count, outq_count,
10781 peer_uptime(peer->uptime,
10782 timebuf,
10783 BGP_UPTIME_LEN, 0,
10784 NULL));
3577f1c5 10785
feb17238 10786 if (peer_established(peer)) {
d3ada366
DA
10787 if (peer->afc_recv[afi][safi]) {
10788 if (CHECK_FLAG(
10789 bgp->flags,
10790 BGP_FLAG_EBGP_REQUIRES_POLICY)
10791 && !bgp_inbound_policy_exists(
10792 peer, filter))
10793 vty_out(vty, " %12s",
10794 "(Policy)");
10795 else
10796 vty_out(vty,
6cde4b45 10797 " %12u",
d3ada366
DA
10798 peer->pcount
10799 [afi]
10800 [pfx_rcd_safi]);
10801 } else {
749d0f27 10802 vty_out(vty, " NoNeg");
d3ada366 10803 }
db92d226 10804
d3ada366
DA
10805 if (paf && PAF_SUBGRP(paf)) {
10806 if (CHECK_FLAG(
10807 bgp->flags,
10808 BGP_FLAG_EBGP_REQUIRES_POLICY)
10809 && !bgp_outbound_policy_exists(
10810 peer, filter))
10811 vty_out(vty, " %8s",
10812 "(Policy)");
10813 else
10814 vty_out(vty,
6cde4b45 10815 " %8u",
d3ada366
DA
10816 (PAF_SUBGRP(
10817 paf))
10818 ->scount);
749d0f27
DA
10819 } else {
10820 vty_out(vty, " NoNeg");
d3ada366 10821 }
db92d226 10822 } else {
736b68f3
DS
10823 if (CHECK_FLAG(peer->flags,
10824 PEER_FLAG_SHUTDOWN)
10825 || CHECK_FLAG(peer->bgp->flags,
10826 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
10827 vty_out(vty, " Idle (Admin)");
10828 else if (CHECK_FLAG(
10829 peer->sflags,
10830 PEER_STATUS_PREFIX_OVERFLOW))
10831 vty_out(vty, " Idle (PfxCt)");
10832 else
10833 vty_out(vty, " %12s",
10834 lookup_msg(bgp_status_msg,
10835 peer->status, NULL));
db92d226 10836
6cde4b45 10837 vty_out(vty, " %8u", 0);
3577f1c5 10838 }
565e9ddd
DA
10839 /* Make sure `Desc` column is the lastest in
10840 * the output.
10841 */
aa72bd7e 10842 if (peer->desc)
cb75bb31
DA
10843 vty_out(vty, " %s",
10844 bgp_peer_description_stripped(
85eeb029
DA
10845 peer->desc,
10846 show_wide ? 64 : 20));
aa72bd7e
PG
10847 else
10848 vty_out(vty, " N/A");
3577f1c5 10849 vty_out(vty, "\n");
d62a17ae 10850 }
3577f1c5 10851
d62a17ae 10852 }
10853 }
f933309e 10854
d62a17ae 10855 if (use_json) {
10856 json_object_object_add(json, "peers", json_peers);
3577f1c5 10857 json_object_int_add(json, "failedPeers", failed_count);
ce1944f0
LS
10858 json_object_int_add(json, "displayedPeers",
10859 count - filtered_count);
d62a17ae 10860 json_object_int_add(json, "totalPeers", count);
10861 json_object_int_add(json, "dynamicPeers", dn_count);
10862
3577f1c5
DD
10863 if (!show_failed)
10864 bgp_show_bestpath_json(bgp, json);
57a9c8a8 10865
75eeda93 10866 vty_json(vty, json);
d62a17ae 10867 } else {
ce1944f0 10868 if (count) {
96c81f66
LS
10869 if (filtered_count == count)
10870 vty_out(vty, "\n%% No matching neighbor\n");
10871 else {
10872 if (show_failed)
10873 vty_out(vty, "\nDisplayed neighbors %d",
10874 failed_count);
10875 else if (as_type != AS_UNSPECIFIED || as
10876 || fpeer || show_established)
ce1944f0
LS
10877 vty_out(vty, "\nDisplayed neighbors %d",
10878 count - filtered_count);
96c81f66
LS
10879
10880 vty_out(vty, "\nTotal number of neighbors %d\n",
10881 count);
ce1944f0 10882 }
ce1944f0 10883 } else {
d6ceaca3 10884 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 10885 get_afi_safi_str(afi, safi, false));
d62a17ae 10886 }
b05a1c8b 10887
d6ceaca3 10888 if (dn_count) {
d62a17ae 10889 vty_out(vty, "* - dynamic neighbor\n");
10890 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
10891 dn_count, bgp->dynamic_neighbors_limit);
10892 }
10893 }
1ff9a340 10894
d62a17ae 10895 return CMD_SUCCESS;
718e3744 10896}
10897
d62a17ae 10898static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5 10899 int safi, struct peer *fpeer, int as_type,
96c81f66 10900 as_t as, uint16_t show_flags)
d62a17ae 10901{
10902 int is_first = 1;
10903 int afi_wildcard = (afi == AFI_MAX);
10904 int safi_wildcard = (safi == SAFI_MAX);
10905 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 10906 bool nbr_output = false;
85eeb029 10907 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 10908
10909 if (use_json && is_wildcard)
10910 vty_out(vty, "{\n");
10911 if (afi_wildcard)
10912 afi = 1; /* AFI_IP */
10913 while (afi < AFI_MAX) {
10914 if (safi_wildcard)
10915 safi = 1; /* SAFI_UNICAST */
10916 while (safi < SAFI_MAX) {
318cac96 10917 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 10918 nbr_output = true;
f86897b9 10919
d62a17ae 10920 if (is_wildcard) {
10921 /*
10922 * So limit output to those afi/safi
10923 * pairs that
10924 * actualy have something interesting in
10925 * them
10926 */
10927 if (use_json) {
d62a17ae 10928 if (!is_first)
10929 vty_out(vty, ",\n");
10930 else
10931 is_first = 0;
10932
10933 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
10934 get_afi_safi_str(afi,
10935 safi,
10936 true));
d62a17ae 10937 } else {
6cac2fcc
LS
10938 vty_out(vty,
10939 "\n%s Summary (%s):\n",
5cb5f4d0
DD
10940 get_afi_safi_str(afi,
10941 safi,
6cac2fcc
LS
10942 false),
10943 bgp->name_pretty);
d62a17ae 10944 }
10945 }
8c1d4cd5
LS
10946 bgp_show_summary(vty, bgp, afi, safi, fpeer,
10947 as_type, as, show_flags);
d62a17ae 10948 }
10949 safi++;
d62a17ae 10950 if (!safi_wildcard)
10951 safi = SAFI_MAX;
10952 }
10953 afi++;
ee851c8c 10954 if (!afi_wildcard)
d62a17ae 10955 afi = AFI_MAX;
10956 }
10957
10958 if (use_json && is_wildcard)
10959 vty_out(vty, "}\n");
ca61fd25
DS
10960 else if (!nbr_output) {
10961 if (use_json)
10962 vty_out(vty, "{}\n");
10963 else
6cac2fcc
LS
10964 vty_out(vty, "%% No BGP neighbors found in %s\n",
10965 bgp->name_pretty);
ca61fd25 10966 }
d62a17ae 10967}
10968
10969static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
10970 safi_t safi,
10971 const char *neighbor,
10972 int as_type, as_t as,
96c81f66 10973 uint16_t show_flags)
d62a17ae 10974{
10975 struct listnode *node, *nnode;
10976 struct bgp *bgp;
8c1d4cd5 10977 struct peer *fpeer = NULL;
d62a17ae 10978 int is_first = 1;
9f049418 10979 bool nbr_output = false;
85eeb029 10980 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 10981
10982 if (use_json)
10983 vty_out(vty, "{\n");
10984
10985 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 10986 nbr_output = true;
d62a17ae 10987 if (use_json) {
d62a17ae 10988 if (!is_first)
10989 vty_out(vty, ",\n");
10990 else
10991 is_first = 0;
10992
10993 vty_out(vty, "\"%s\":",
10994 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10995 ? VRF_DEFAULT_NAME
d62a17ae 10996 : bgp->name);
d62a17ae 10997 }
8c1d4cd5
LS
10998 if (neighbor) {
10999 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11000 use_json);
11001 if (!fpeer)
11002 continue;
11003 }
11004 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11005 as, show_flags);
d62a17ae 11006 }
11007
11008 if (use_json)
11009 vty_out(vty, "}\n");
9f049418
DS
11010 else if (!nbr_output)
11011 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11012}
11013
11014int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5 11015 safi_t safi, const char *neighbor, int as_type,
96c81f66 11016 as_t as, uint16_t show_flags)
d62a17ae 11017{
11018 struct bgp *bgp;
85eeb029 11019 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 11020 struct peer *fpeer = NULL;
d62a17ae 11021
11022 if (name) {
11023 if (strmatch(name, "all")) {
85eeb029 11024 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
11025 neighbor, as_type,
11026 as, show_flags);
d62a17ae 11027 return CMD_SUCCESS;
11028 } else {
11029 bgp = bgp_lookup_by_name(name);
11030
11031 if (!bgp) {
11032 if (use_json)
11033 vty_out(vty, "{}\n");
11034 else
11035 vty_out(vty,
ca61fd25 11036 "%% BGP instance not found\n");
d62a17ae 11037 return CMD_WARNING;
11038 }
11039
8c1d4cd5
LS
11040 if (neighbor) {
11041 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11042 use_json);
11043 if (!fpeer)
11044 return CMD_WARNING;
11045 }
11046 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11047 as_type, as, show_flags);
d62a17ae 11048 return CMD_SUCCESS;
11049 }
11050 }
11051
11052 bgp = bgp_get_default();
11053
8c1d4cd5
LS
11054 if (bgp) {
11055 if (neighbor) {
11056 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11057 use_json);
11058 if (!fpeer)
11059 return CMD_WARNING;
11060 }
11061 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11062 as, show_flags);
11063 } else {
ca61fd25
DS
11064 if (use_json)
11065 vty_out(vty, "{}\n");
11066 else
11067 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11068 return CMD_WARNING;
11069 }
d62a17ae 11070
11071 return CMD_SUCCESS;
4fb25c53
DW
11072}
11073
716b2d8a 11074/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
11075DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11076 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11077 " [" BGP_SAFI_WITH_LABEL_CMD_STR
96c81f66 11078 "]] [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
11079 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11080 BGP_SAFI_WITH_LABEL_HELP_STR
11081 "Display the entries for all address families\n"
11082 "Summary of BGP neighbor status\n"
11083 "Show only sessions in Established state\n"
11084 "Show only sessions not in Established state\n"
11085 "Show only the specified neighbor session\n"
11086 "Neighbor to display information about\n"
11087 "Neighbor to display information about\n"
11088 "Neighbor on BGP configured interface\n"
11089 "Show only the specified remote AS sessions\n"
11090 "AS number\n"
11091 "Internal (iBGP) AS sessions\n"
11092 "External (eBGP) AS sessions\n"
96c81f66 11093 "Shorten the information on BGP instances\n"
8c1d4cd5 11094 "Increase table width for longer output\n" JSON_STR)
718e3744 11095{
d62a17ae 11096 char *vrf = NULL;
11097 afi_t afi = AFI_MAX;
11098 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
11099 as_t as = 0; /* 0 means AS filter not set */
11100 int as_type = AS_UNSPECIFIED;
96c81f66 11101 uint16_t show_flags = 0;
d62a17ae 11102
11103 int idx = 0;
11104
11105 /* show [ip] bgp */
96f3485c 11106 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11107 afi = AFI_IP;
9a8bdf1c
PG
11108 /* [<vrf> VIEWVRFNAME] */
11109 if (argv_find(argv, argc, "vrf", &idx)) {
11110 vrf = argv[idx + 1]->arg;
11111 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11112 vrf = NULL;
11113 } else if (argv_find(argv, argc, "view", &idx))
11114 /* [<view> VIEWVRFNAME] */
11115 vrf = argv[idx + 1]->arg;
d62a17ae 11116 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11117 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11118 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11119 }
11120
3577f1c5 11121 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11122 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11123
10b49f14 11124 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11125 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11126
8c1d4cd5
LS
11127 if (argv_find(argv, argc, "remote-as", &idx)) {
11128 if (argv[idx + 1]->arg[0] == 'i')
11129 as_type = AS_INTERNAL;
11130 else if (argv[idx + 1]->arg[0] == 'e')
11131 as_type = AS_EXTERNAL;
11132 else
11133 as = (as_t)atoi(argv[idx + 1]->arg);
11134 }
11135
96c81f66
LS
11136 if (argv_find(argv, argc, "terse", &idx))
11137 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11138
85eeb029
DA
11139 if (argv_find(argv, argc, "wide", &idx))
11140 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11141
11142 if (argv_find(argv, argc, "json", &idx))
11143 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11144
8c1d4cd5
LS
11145 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11146 show_flags);
d62a17ae 11147}
11148
5cb5f4d0 11149const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11150{
5cb5f4d0
DD
11151 if (for_json)
11152 return get_afi_safi_json_str(afi, safi);
d62a17ae 11153 else
5cb5f4d0 11154 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11155}
11156
d62a17ae 11157
11158static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11159 afi_t afi, safi_t safi,
d7c0a89a
QY
11160 uint16_t adv_smcap, uint16_t adv_rmcap,
11161 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11162 bool use_json, json_object *json_pref)
d62a17ae 11163{
11164 /* Send-Mode */
11165 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11166 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11167 if (use_json) {
11168 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11169 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11170 json_object_string_add(json_pref, "sendMode",
11171 "advertisedAndReceived");
11172 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11173 json_object_string_add(json_pref, "sendMode",
11174 "advertised");
11175 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11176 json_object_string_add(json_pref, "sendMode",
11177 "received");
11178 } else {
11179 vty_out(vty, " Send-mode: ");
11180 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11181 vty_out(vty, "advertised");
11182 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11183 vty_out(vty, "%sreceived",
11184 CHECK_FLAG(p->af_cap[afi][safi],
11185 adv_smcap)
11186 ? ", "
11187 : "");
11188 vty_out(vty, "\n");
11189 }
11190 }
11191
11192 /* Receive-Mode */
11193 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11194 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11195 if (use_json) {
11196 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11197 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11198 json_object_string_add(json_pref, "recvMode",
11199 "advertisedAndReceived");
11200 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11201 json_object_string_add(json_pref, "recvMode",
11202 "advertised");
11203 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11204 json_object_string_add(json_pref, "recvMode",
11205 "received");
11206 } else {
11207 vty_out(vty, " Receive-mode: ");
11208 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11209 vty_out(vty, "advertised");
11210 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11211 vty_out(vty, "%sreceived",
11212 CHECK_FLAG(p->af_cap[afi][safi],
11213 adv_rmcap)
11214 ? ", "
11215 : "");
11216 vty_out(vty, "\n");
11217 }
11218 }
11219}
11220
13909c4f
DS
11221static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11222 struct peer *p,
11223 bool use_json,
11224 json_object *json)
2986cac2 11225{
08c2d52a 11226 bool rbit_status = false;
2986cac2 11227
11228 if (!use_json)
a53ca37b 11229 vty_out(vty, "\n R bit: ");
2986cac2 11230
13909c4f
DS
11231 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11232 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
feb17238 11233 && (peer_established(p))) {
2986cac2 11234
11235 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 11236 rbit_status = true;
2986cac2 11237 else
08c2d52a 11238 rbit_status = false;
2986cac2 11239 }
11240
11241 if (rbit_status) {
11242 if (use_json)
13909c4f 11243 json_object_boolean_true_add(json, "rBit");
2986cac2 11244 else
11245 vty_out(vty, "True\n");
11246 } else {
11247 if (use_json)
13909c4f 11248 json_object_boolean_false_add(json, "rBit");
2986cac2 11249 else
11250 vty_out(vty, "False\n");
11251 }
11252}
11253
13909c4f
DS
11254static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11255 struct peer *peer,
11256 bool use_json,
11257 json_object *json)
2986cac2 11258{
2bb5d39b 11259 const char *mode = "NotApplicable";
2986cac2 11260
11261 if (!use_json)
a53ca37b 11262 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11263
13909c4f 11264 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
feb17238 11265 && (peer_established(peer))) {
2986cac2 11266
13909c4f
DS
11267 if ((peer->nsf_af_count == 0)
11268 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11269
2986cac2 11270 mode = "Disable";
11271
13909c4f
DS
11272 } else if (peer->nsf_af_count == 0
11273 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11274
2986cac2 11275 mode = "Helper";
11276
13909c4f
DS
11277 } else if (peer->nsf_af_count != 0
11278 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11279
2986cac2 11280 mode = "Restart";
2986cac2 11281 }
11282 }
11283
11284 if (use_json) {
13909c4f 11285 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11286 } else
11287 vty_out(vty, mode, "\n");
11288}
11289
13909c4f
DS
11290static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11291 struct peer *p,
11292 bool use_json,
11293 json_object *json)
2986cac2 11294{
11295 const char *mode = "Invalid";
11296
11297 if (!use_json)
a53ca37b 11298 vty_out(vty, " Local GR Mode: ");
2986cac2 11299
11300 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11301 mode = "Helper";
11302 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11303 mode = "Restart";
11304 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11305 mode = "Disable";
2ba1fe69 11306 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11307 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11308 mode = "Helper*";
11309 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11310 mode = "Restart*";
11311 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11312 mode = "Disable*";
11313 else
11314 mode = "Invalid*";
2ba1fe69 11315 }
2986cac2 11316
11317 if (use_json) {
13909c4f 11318 json_object_string_add(json, "localGrMode", mode);
2986cac2 11319 } else {
11320 vty_out(vty, mode, "\n");
11321 }
11322}
11323
13909c4f
DS
11324static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11325 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11326{
2ba1fe69 11327 afi_t afi;
11328 safi_t safi;
2986cac2 11329 json_object *json_afi_safi = NULL;
11330 json_object *json_timer = NULL;
11331 json_object *json_endofrib_status = NULL;
9e3b51a7 11332 bool eor_flag = false;
2986cac2 11333
df8d723c
DA
11334 FOREACH_AFI_SAFI_NSF (afi, safi) {
11335 if (!peer->afc[afi][safi])
11336 continue;
2986cac2 11337
df8d723c
DA
11338 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11339 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11340 continue;
9e3b51a7 11341
df8d723c
DA
11342 if (use_json) {
11343 json_afi_safi = json_object_new_object();
11344 json_endofrib_status = json_object_new_object();
11345 json_timer = json_object_new_object();
11346 }
2986cac2 11347
df8d723c
DA
11348 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11349 eor_flag = true;
11350 else
11351 eor_flag = false;
2986cac2 11352
df8d723c
DA
11353 if (!use_json) {
11354 vty_out(vty, " %s:\n",
11355 get_afi_safi_str(afi, safi, false));
2986cac2 11356
df8d723c
DA
11357 vty_out(vty, " F bit: ");
11358 }
2986cac2 11359
df8d723c
DA
11360 if (peer->nsf[afi][safi] &&
11361 CHECK_FLAG(peer->af_cap[afi][safi],
11362 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11363
df8d723c
DA
11364 if (use_json) {
11365 json_object_boolean_true_add(json_afi_safi,
11366 "fBit");
11367 } else
11368 vty_out(vty, "True\n");
11369 } else {
11370 if (use_json)
11371 json_object_boolean_false_add(json_afi_safi,
11372 "fBit");
11373 else
11374 vty_out(vty, "False\n");
11375 }
2986cac2 11376
df8d723c
DA
11377 if (!use_json)
11378 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11379
df8d723c
DA
11380 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11381 PEER_STATUS_EOR_SEND)) {
11382 if (use_json) {
11383 json_object_boolean_true_add(
11384 json_endofrib_status, "endOfRibSend");
9e3b51a7 11385
df8d723c
DA
11386 PRINT_EOR_JSON(eor_flag);
11387 } else {
11388 vty_out(vty, "Yes\n");
11389 vty_out(vty,
11390 " End-of-RIB sent after update: ");
2986cac2 11391
df8d723c
DA
11392 PRINT_EOR(eor_flag);
11393 }
11394 } else {
11395 if (use_json) {
11396 json_object_boolean_false_add(
11397 json_endofrib_status, "endOfRibSend");
11398 json_object_boolean_false_add(
11399 json_endofrib_status,
11400 "endOfRibSentAfterUpdate");
13909c4f 11401 } else {
df8d723c
DA
11402 vty_out(vty, "No\n");
11403 vty_out(vty,
11404 " End-of-RIB sent after update: ");
11405 vty_out(vty, "No\n");
13909c4f 11406 }
df8d723c 11407 }
2986cac2 11408
df8d723c
DA
11409 if (!use_json)
11410 vty_out(vty, " End-of-RIB received: ");
a53ca37b 11411
df8d723c
DA
11412 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11413 PEER_STATUS_EOR_RECEIVED)) {
11414 if (use_json)
11415 json_object_boolean_true_add(
11416 json_endofrib_status, "endOfRibRecv");
11417 else
11418 vty_out(vty, "Yes\n");
11419 } else {
11420 if (use_json)
11421 json_object_boolean_false_add(
11422 json_endofrib_status, "endOfRibRecv");
11423 else
11424 vty_out(vty, "No\n");
11425 }
11426
11427 if (use_json) {
11428 json_object_int_add(json_timer, "stalePathTimer",
11429 peer->bgp->stalepath_time);
11430
11431 if (peer->t_gr_stale != NULL) {
11432 json_object_int_add(json_timer,
11433 "stalePathTimerRemaining",
11434 thread_timer_remain_second(
11435 peer->t_gr_stale));
a53ca37b
DA
11436 }
11437
df8d723c
DA
11438 /* Display Configured Selection
11439 * Deferral only when when
11440 * Gr mode is enabled.
11441 */
11442 if (CHECK_FLAG(peer->flags,
11443 PEER_FLAG_GRACEFUL_RESTART)) {
13909c4f 11444 json_object_int_add(json_timer,
df8d723c 11445 "selectionDeferralTimer",
13909c4f 11446 peer->bgp->stalepath_time);
df8d723c 11447 }
2986cac2 11448
df8d723c
DA
11449 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11450 NULL) {
2986cac2 11451
df8d723c
DA
11452 json_object_int_add(
11453 json_timer,
11454 "selectionDeferralTimerRemaining",
11455 thread_timer_remain_second(
11456 peer->bgp->gr_info[afi][safi]
11457 .t_select_deferral));
11458 }
11459 } else {
11460 vty_out(vty, " Timers:\n");
11461 vty_out(vty,
11462 " Configured Stale Path Time(sec): %u\n",
11463 peer->bgp->stalepath_time);
2986cac2 11464
df8d723c 11465 if (peer->t_gr_stale != NULL)
13909c4f 11466 vty_out(vty,
df8d723c
DA
11467 " Stale Path Remaining(sec): %ld\n",
11468 thread_timer_remain_second(
11469 peer->t_gr_stale));
11470 /* Display Configured Selection
11471 * Deferral only when when
11472 * Gr mode is enabled.
11473 */
11474 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11475 vty_out(vty,
11476 " Configured Selection Deferral Time(sec): %u\n",
11477 peer->bgp->select_defer_time);
2986cac2 11478
df8d723c
DA
11479 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11480 NULL)
11481 vty_out(vty,
11482 " Selection Deferral Time Remaining(sec): %ld\n",
11483 thread_timer_remain_second(
11484 peer->bgp->gr_info[afi][safi]
11485 .t_select_deferral));
11486 }
11487 if (use_json) {
11488 json_object_object_add(json_afi_safi, "endOfRibStatus",
11489 json_endofrib_status);
11490 json_object_object_add(json_afi_safi, "timers",
11491 json_timer);
11492 json_object_object_add(
11493 json, get_afi_safi_str(afi, safi, true),
11494 json_afi_safi);
2986cac2 11495 }
11496 }
11497}
11498
36235319
QY
11499static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11500 struct peer *p,
11501 bool use_json,
11502 json_object *json)
2986cac2 11503{
11504 if (use_json) {
11505 json_object *json_timer = NULL;
11506
11507 json_timer = json_object_new_object();
11508
13909c4f
DS
11509 json_object_int_add(json_timer, "configuredRestartTimer",
11510 p->bgp->restart_time);
2986cac2 11511
13909c4f
DS
11512 json_object_int_add(json_timer, "receivedRestartTimer",
11513 p->v_gr_restart);
2986cac2 11514
13909c4f
DS
11515 if (p->t_gr_restart != NULL)
11516 json_object_int_add(
11517 json_timer, "restartTimerRemaining",
11518 thread_timer_remain_second(p->t_gr_restart));
2986cac2 11519
11520 json_object_object_add(json, "timers", json_timer);
11521 } else {
11522
a53ca37b
DA
11523 vty_out(vty, " Timers:\n");
11524 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 11525 p->bgp->restart_time);
2986cac2 11526
a53ca37b 11527 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
11528 p->v_gr_restart);
11529 if (p->t_gr_restart != NULL)
a53ca37b 11530 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 11531 thread_timer_remain_second(p->t_gr_restart));
36235319 11532 if (p->t_gr_restart != NULL) {
a53ca37b 11533 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
11534 thread_timer_remain_second(p->t_gr_restart));
11535 }
2986cac2 11536 }
11537}
11538
11539static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 11540 bool use_json, json_object *json)
2986cac2 11541{
11542 char buf[SU_ADDRSTRLEN] = {0};
11543 char dn_flag[2] = {0};
2b7165e7
QY
11544 /* '*' + v6 address of neighbor */
11545 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 11546
2986cac2 11547 if (!p->conf_if && peer_dynamic_neighbor(p))
11548 dn_flag[0] = '*';
11549
11550 if (p->conf_if) {
11551 if (use_json)
13909c4f
DS
11552 json_object_string_add(
11553 json, "neighborAddr",
2986cac2 11554 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
11555 ? "none"
11556 : sockunion2str(&p->su, buf,
11557 SU_ADDRSTRLEN));
2986cac2 11558 else
13909c4f 11559 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 11560 BGP_PEER_SU_UNSPEC(p)
11561 ? "none"
11562 : sockunion2str(&p->su, buf,
11563 SU_ADDRSTRLEN));
11564 } else {
772270f3
QY
11565 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11566 p->host);
2986cac2 11567
11568 if (use_json)
36235319
QY
11569 json_object_string_add(json, "neighborAddr",
11570 neighborAddr);
2986cac2 11571 else
36235319 11572 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 11573 }
11574
11575 /* more gr info in new format */
11576 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11577}
11578
d62a17ae 11579static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 11580 safi_t safi, bool use_json,
d62a17ae 11581 json_object *json_neigh)
11582{
0291c246
MK
11583 struct bgp_filter *filter;
11584 struct peer_af *paf;
11585 char orf_pfx_name[BUFSIZ];
11586 int orf_pfx_count;
11587 json_object *json_af = NULL;
11588 json_object *json_prefA = NULL;
11589 json_object *json_prefB = NULL;
11590 json_object *json_addr = NULL;
fa36596c 11591 json_object *json_advmap = NULL;
d62a17ae 11592
11593 if (use_json) {
11594 json_addr = json_object_new_object();
11595 json_af = json_object_new_object();
11596 filter = &p->filter[afi][safi];
11597
11598 if (peer_group_active(p))
11599 json_object_string_add(json_addr, "peerGroupMember",
11600 p->group->name);
11601
11602 paf = peer_af_find(p, afi, safi);
11603 if (paf && PAF_SUBGRP(paf)) {
11604 json_object_int_add(json_addr, "updateGroupId",
11605 PAF_UPDGRP(paf)->id);
11606 json_object_int_add(json_addr, "subGroupId",
11607 PAF_SUBGRP(paf)->id);
11608 json_object_int_add(json_addr, "packetQueueLength",
11609 bpacket_queue_virtual_length(paf));
11610 }
11611
11612 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11613 || CHECK_FLAG(p->af_cap[afi][safi],
11614 PEER_CAP_ORF_PREFIX_SM_RCV)
11615 || CHECK_FLAG(p->af_cap[afi][safi],
11616 PEER_CAP_ORF_PREFIX_RM_ADV)
11617 || CHECK_FLAG(p->af_cap[afi][safi],
11618 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11619 json_object_int_add(json_af, "orfType",
11620 ORF_TYPE_PREFIX);
11621 json_prefA = json_object_new_object();
11622 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11623 PEER_CAP_ORF_PREFIX_SM_ADV,
11624 PEER_CAP_ORF_PREFIX_RM_ADV,
11625 PEER_CAP_ORF_PREFIX_SM_RCV,
11626 PEER_CAP_ORF_PREFIX_RM_RCV,
11627 use_json, json_prefA);
11628 json_object_object_add(json_af, "orfPrefixList",
11629 json_prefA);
11630 }
11631
11632 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11633 || CHECK_FLAG(p->af_cap[afi][safi],
11634 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11635 || CHECK_FLAG(p->af_cap[afi][safi],
11636 PEER_CAP_ORF_PREFIX_RM_ADV)
11637 || CHECK_FLAG(p->af_cap[afi][safi],
11638 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11639 json_object_int_add(json_af, "orfOldType",
11640 ORF_TYPE_PREFIX_OLD);
11641 json_prefB = json_object_new_object();
11642 bgp_show_peer_afi_orf_cap(
11643 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11644 PEER_CAP_ORF_PREFIX_RM_ADV,
11645 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11646 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11647 json_prefB);
11648 json_object_object_add(json_af, "orfOldPrefixList",
11649 json_prefB);
11650 }
11651
11652 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11653 || CHECK_FLAG(p->af_cap[afi][safi],
11654 PEER_CAP_ORF_PREFIX_SM_RCV)
11655 || CHECK_FLAG(p->af_cap[afi][safi],
11656 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11657 || CHECK_FLAG(p->af_cap[afi][safi],
11658 PEER_CAP_ORF_PREFIX_RM_ADV)
11659 || CHECK_FLAG(p->af_cap[afi][safi],
11660 PEER_CAP_ORF_PREFIX_RM_RCV)
11661 || CHECK_FLAG(p->af_cap[afi][safi],
11662 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11663 json_object_object_add(json_addr, "afDependentCap",
11664 json_af);
11665 else
11666 json_object_free(json_af);
11667
772270f3
QY
11668 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11669 p->host, afi, safi);
d62a17ae 11670 orf_pfx_count = prefix_bgp_show_prefix_list(
11671 NULL, afi, orf_pfx_name, use_json);
11672
11673 if (CHECK_FLAG(p->af_sflags[afi][safi],
11674 PEER_STATUS_ORF_PREFIX_SEND)
11675 || orf_pfx_count) {
11676 if (CHECK_FLAG(p->af_sflags[afi][safi],
11677 PEER_STATUS_ORF_PREFIX_SEND))
11678 json_object_boolean_true_add(json_neigh,
11679 "orfSent");
11680 if (orf_pfx_count)
11681 json_object_int_add(json_addr, "orfRecvCounter",
11682 orf_pfx_count);
11683 }
11684 if (CHECK_FLAG(p->af_sflags[afi][safi],
11685 PEER_STATUS_ORF_WAIT_REFRESH))
11686 json_object_string_add(
11687 json_addr, "orfFirstUpdate",
11688 "deferredUntilORFOrRouteRefreshRecvd");
11689
11690 if (CHECK_FLAG(p->af_flags[afi][safi],
11691 PEER_FLAG_REFLECTOR_CLIENT))
11692 json_object_boolean_true_add(json_addr,
11693 "routeReflectorClient");
11694 if (CHECK_FLAG(p->af_flags[afi][safi],
11695 PEER_FLAG_RSERVER_CLIENT))
11696 json_object_boolean_true_add(json_addr,
11697 "routeServerClient");
11698 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11699 json_object_boolean_true_add(json_addr,
11700 "inboundSoftConfigPermit");
11701
11702 if (CHECK_FLAG(p->af_flags[afi][safi],
11703 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11704 json_object_boolean_true_add(
11705 json_addr,
11706 "privateAsNumsAllReplacedInUpdatesToNbr");
11707 else if (CHECK_FLAG(p->af_flags[afi][safi],
11708 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11709 json_object_boolean_true_add(
11710 json_addr,
11711 "privateAsNumsReplacedInUpdatesToNbr");
11712 else if (CHECK_FLAG(p->af_flags[afi][safi],
11713 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11714 json_object_boolean_true_add(
11715 json_addr,
11716 "privateAsNumsAllRemovedInUpdatesToNbr");
11717 else if (CHECK_FLAG(p->af_flags[afi][safi],
11718 PEER_FLAG_REMOVE_PRIVATE_AS))
11719 json_object_boolean_true_add(
11720 json_addr,
11721 "privateAsNumsRemovedInUpdatesToNbr");
11722
dcc68b5e
MS
11723 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11724 json_object_boolean_true_add(
11725 json_addr,
11726 bgp_addpath_names(p->addpath_type[afi][safi])
11727 ->type_json_name);
d62a17ae 11728
11729 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11730 json_object_string_add(json_addr,
11731 "overrideASNsInOutboundUpdates",
11732 "ifAspathEqualRemoteAs");
11733
11734 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11735 || CHECK_FLAG(p->af_flags[afi][safi],
11736 PEER_FLAG_FORCE_NEXTHOP_SELF))
11737 json_object_boolean_true_add(json_addr,
11738 "routerAlwaysNextHop");
11739 if (CHECK_FLAG(p->af_flags[afi][safi],
11740 PEER_FLAG_AS_PATH_UNCHANGED))
11741 json_object_boolean_true_add(
11742 json_addr, "unchangedAsPathPropogatedToNbr");
11743 if (CHECK_FLAG(p->af_flags[afi][safi],
11744 PEER_FLAG_NEXTHOP_UNCHANGED))
11745 json_object_boolean_true_add(
11746 json_addr, "unchangedNextHopPropogatedToNbr");
11747 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11748 json_object_boolean_true_add(
11749 json_addr, "unchangedMedPropogatedToNbr");
11750 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11751 || CHECK_FLAG(p->af_flags[afi][safi],
11752 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11753 if (CHECK_FLAG(p->af_flags[afi][safi],
11754 PEER_FLAG_SEND_COMMUNITY)
11755 && CHECK_FLAG(p->af_flags[afi][safi],
11756 PEER_FLAG_SEND_EXT_COMMUNITY))
11757 json_object_string_add(json_addr,
11758 "commAttriSentToNbr",
11759 "extendedAndStandard");
11760 else if (CHECK_FLAG(p->af_flags[afi][safi],
11761 PEER_FLAG_SEND_EXT_COMMUNITY))
11762 json_object_string_add(json_addr,
11763 "commAttriSentToNbr",
11764 "extended");
11765 else
11766 json_object_string_add(json_addr,
11767 "commAttriSentToNbr",
11768 "standard");
11769 }
11770 if (CHECK_FLAG(p->af_flags[afi][safi],
11771 PEER_FLAG_DEFAULT_ORIGINATE)) {
11772 if (p->default_rmap[afi][safi].name)
11773 json_object_string_add(
11774 json_addr, "defaultRouteMap",
11775 p->default_rmap[afi][safi].name);
11776
11777 if (paf && PAF_SUBGRP(paf)
11778 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11779 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11780 json_object_boolean_true_add(json_addr,
11781 "defaultSent");
11782 else
11783 json_object_boolean_true_add(json_addr,
11784 "defaultNotSent");
11785 }
11786
dff8f48d 11787 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 11788 if (is_evpn_enabled())
60466a63
QY
11789 json_object_boolean_true_add(
11790 json_addr, "advertiseAllVnis");
dff8f48d
MK
11791 }
11792
d62a17ae 11793 if (filter->plist[FILTER_IN].name
11794 || filter->dlist[FILTER_IN].name
11795 || filter->aslist[FILTER_IN].name
11796 || filter->map[RMAP_IN].name)
11797 json_object_boolean_true_add(json_addr,
11798 "inboundPathPolicyConfig");
11799 if (filter->plist[FILTER_OUT].name
11800 || filter->dlist[FILTER_OUT].name
11801 || filter->aslist[FILTER_OUT].name
11802 || filter->map[RMAP_OUT].name || filter->usmap.name)
11803 json_object_boolean_true_add(
11804 json_addr, "outboundPathPolicyConfig");
11805
11806 /* prefix-list */
11807 if (filter->plist[FILTER_IN].name)
11808 json_object_string_add(json_addr,
11809 "incomingUpdatePrefixFilterList",
11810 filter->plist[FILTER_IN].name);
11811 if (filter->plist[FILTER_OUT].name)
11812 json_object_string_add(json_addr,
11813 "outgoingUpdatePrefixFilterList",
11814 filter->plist[FILTER_OUT].name);
11815
11816 /* distribute-list */
11817 if (filter->dlist[FILTER_IN].name)
11818 json_object_string_add(
11819 json_addr, "incomingUpdateNetworkFilterList",
11820 filter->dlist[FILTER_IN].name);
11821 if (filter->dlist[FILTER_OUT].name)
11822 json_object_string_add(
11823 json_addr, "outgoingUpdateNetworkFilterList",
11824 filter->dlist[FILTER_OUT].name);
11825
11826 /* filter-list. */
11827 if (filter->aslist[FILTER_IN].name)
11828 json_object_string_add(json_addr,
11829 "incomingUpdateAsPathFilterList",
11830 filter->aslist[FILTER_IN].name);
11831 if (filter->aslist[FILTER_OUT].name)
11832 json_object_string_add(json_addr,
11833 "outgoingUpdateAsPathFilterList",
11834 filter->aslist[FILTER_OUT].name);
11835
11836 /* route-map. */
11837 if (filter->map[RMAP_IN].name)
11838 json_object_string_add(
11839 json_addr, "routeMapForIncomingAdvertisements",
11840 filter->map[RMAP_IN].name);
11841 if (filter->map[RMAP_OUT].name)
11842 json_object_string_add(
11843 json_addr, "routeMapForOutgoingAdvertisements",
11844 filter->map[RMAP_OUT].name);
11845
9dac9fc8 11846 /* ebgp-requires-policy (inbound) */
1d3fdccf 11847 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11848 && !bgp_inbound_policy_exists(p, filter))
11849 json_object_string_add(
11850 json_addr, "inboundEbgpRequiresPolicy",
11851 "Inbound updates discarded due to missing policy");
11852
11853 /* ebgp-requires-policy (outbound) */
1d3fdccf 11854 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11855 && (!bgp_outbound_policy_exists(p, filter)))
11856 json_object_string_add(
11857 json_addr, "outboundEbgpRequiresPolicy",
11858 "Outbound updates discarded due to missing policy");
11859
d62a17ae 11860 /* unsuppress-map */
11861 if (filter->usmap.name)
11862 json_object_string_add(json_addr,
11863 "selectiveUnsuppressRouteMap",
11864 filter->usmap.name);
11865
fa36596c
MK
11866 /* advertise-map */
11867 if (filter->advmap.aname) {
11868 json_advmap = json_object_new_object();
11869 json_object_string_add(json_advmap, "condition",
11870 filter->advmap.condition
11871 ? "EXIST"
11872 : "NON_EXIST");
11873 json_object_string_add(json_advmap, "conditionMap",
11874 filter->advmap.cname);
11875 json_object_string_add(json_advmap, "advertiseMap",
11876 filter->advmap.aname);
11877 json_object_string_add(json_advmap, "advertiseStatus",
11878 filter->advmap.update_type
11879 == ADVERTISE
11880 ? "Advertise"
11881 : "Withdraw");
11882 json_object_object_add(json_addr, "advertiseMap",
11883 json_advmap);
11884 }
11885
d62a17ae 11886 /* Receive prefix count */
11887 json_object_int_add(json_addr, "acceptedPrefixCounter",
11888 p->pcount[afi][safi]);
50e05855
AD
11889 if (paf && PAF_SUBGRP(paf))
11890 json_object_int_add(json_addr, "sentPrefixCounter",
11891 (PAF_SUBGRP(paf))->scount);
d62a17ae 11892
fde246e8
DA
11893 /* Maximum prefix */
11894 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
11895 json_object_int_add(json_addr, "prefixOutAllowedMax",
11896 p->pmax_out[afi][safi]);
11897
d62a17ae 11898 /* Maximum prefix */
11899 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11900 json_object_int_add(json_addr, "prefixAllowedMax",
11901 p->pmax[afi][safi]);
11902 if (CHECK_FLAG(p->af_flags[afi][safi],
11903 PEER_FLAG_MAX_PREFIX_WARNING))
11904 json_object_boolean_true_add(
11905 json_addr, "prefixAllowedMaxWarning");
11906 json_object_int_add(json_addr,
11907 "prefixAllowedWarningThresh",
11908 p->pmax_threshold[afi][safi]);
11909 if (p->pmax_restart[afi][safi])
11910 json_object_int_add(
11911 json_addr,
11912 "prefixAllowedRestartIntervalMsecs",
11913 p->pmax_restart[afi][safi] * 60000);
11914 }
2986cac2 11915 json_object_object_add(json_neigh,
36235319 11916 get_afi_safi_str(afi, safi, true),
d62a17ae 11917 json_addr);
11918
11919 } else {
11920 filter = &p->filter[afi][safi];
11921
11922 vty_out(vty, " For address family: %s\n",
5cb5f4d0 11923 get_afi_safi_str(afi, safi, false));
d62a17ae 11924
11925 if (peer_group_active(p))
11926 vty_out(vty, " %s peer-group member\n",
11927 p->group->name);
11928
11929 paf = peer_af_find(p, afi, safi);
11930 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 11931 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 11932 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
11933 vty_out(vty, " Packet Queue length %d\n",
11934 bpacket_queue_virtual_length(paf));
11935 } else {
11936 vty_out(vty, " Not part of any update group\n");
11937 }
11938 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11939 || CHECK_FLAG(p->af_cap[afi][safi],
11940 PEER_CAP_ORF_PREFIX_SM_RCV)
11941 || CHECK_FLAG(p->af_cap[afi][safi],
11942 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11943 || CHECK_FLAG(p->af_cap[afi][safi],
11944 PEER_CAP_ORF_PREFIX_RM_ADV)
11945 || CHECK_FLAG(p->af_cap[afi][safi],
11946 PEER_CAP_ORF_PREFIX_RM_RCV)
11947 || CHECK_FLAG(p->af_cap[afi][safi],
11948 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11949 vty_out(vty, " AF-dependant capabilities:\n");
11950
11951 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11952 || CHECK_FLAG(p->af_cap[afi][safi],
11953 PEER_CAP_ORF_PREFIX_SM_RCV)
11954 || CHECK_FLAG(p->af_cap[afi][safi],
11955 PEER_CAP_ORF_PREFIX_RM_ADV)
11956 || CHECK_FLAG(p->af_cap[afi][safi],
11957 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11958 vty_out(vty,
11959 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11960 ORF_TYPE_PREFIX);
11961 bgp_show_peer_afi_orf_cap(
11962 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11963 PEER_CAP_ORF_PREFIX_RM_ADV,
11964 PEER_CAP_ORF_PREFIX_SM_RCV,
11965 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
11966 }
11967 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11968 || CHECK_FLAG(p->af_cap[afi][safi],
11969 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11970 || CHECK_FLAG(p->af_cap[afi][safi],
11971 PEER_CAP_ORF_PREFIX_RM_ADV)
11972 || CHECK_FLAG(p->af_cap[afi][safi],
11973 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11974 vty_out(vty,
11975 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11976 ORF_TYPE_PREFIX_OLD);
11977 bgp_show_peer_afi_orf_cap(
11978 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11979 PEER_CAP_ORF_PREFIX_RM_ADV,
11980 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11981 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
11982 }
11983
772270f3
QY
11984 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11985 p->host, afi, safi);
d62a17ae 11986 orf_pfx_count = prefix_bgp_show_prefix_list(
11987 NULL, afi, orf_pfx_name, use_json);
11988
11989 if (CHECK_FLAG(p->af_sflags[afi][safi],
11990 PEER_STATUS_ORF_PREFIX_SEND)
11991 || orf_pfx_count) {
11992 vty_out(vty, " Outbound Route Filter (ORF):");
11993 if (CHECK_FLAG(p->af_sflags[afi][safi],
11994 PEER_STATUS_ORF_PREFIX_SEND))
11995 vty_out(vty, " sent;");
11996 if (orf_pfx_count)
11997 vty_out(vty, " received (%d entries)",
11998 orf_pfx_count);
11999 vty_out(vty, "\n");
12000 }
12001 if (CHECK_FLAG(p->af_sflags[afi][safi],
12002 PEER_STATUS_ORF_WAIT_REFRESH))
12003 vty_out(vty,
12004 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12005
12006 if (CHECK_FLAG(p->af_flags[afi][safi],
12007 PEER_FLAG_REFLECTOR_CLIENT))
12008 vty_out(vty, " Route-Reflector Client\n");
12009 if (CHECK_FLAG(p->af_flags[afi][safi],
12010 PEER_FLAG_RSERVER_CLIENT))
12011 vty_out(vty, " Route-Server Client\n");
12012 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12013 vty_out(vty,
12014 " Inbound soft reconfiguration allowed\n");
12015
12016 if (CHECK_FLAG(p->af_flags[afi][safi],
12017 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12018 vty_out(vty,
12019 " Private AS numbers (all) replaced in updates to this neighbor\n");
12020 else if (CHECK_FLAG(p->af_flags[afi][safi],
12021 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12022 vty_out(vty,
12023 " Private AS numbers replaced in updates to this neighbor\n");
12024 else if (CHECK_FLAG(p->af_flags[afi][safi],
12025 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12026 vty_out(vty,
12027 " Private AS numbers (all) removed in updates to this neighbor\n");
12028 else if (CHECK_FLAG(p->af_flags[afi][safi],
12029 PEER_FLAG_REMOVE_PRIVATE_AS))
12030 vty_out(vty,
12031 " Private AS numbers removed in updates to this neighbor\n");
12032
dcc68b5e
MS
12033 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12034 vty_out(vty, " %s\n",
12035 bgp_addpath_names(p->addpath_type[afi][safi])
12036 ->human_description);
d62a17ae 12037
12038 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12039 vty_out(vty,
12040 " Override ASNs in outbound updates if aspath equals remote-as\n");
12041
12042 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12043 || CHECK_FLAG(p->af_flags[afi][safi],
12044 PEER_FLAG_FORCE_NEXTHOP_SELF))
12045 vty_out(vty, " NEXT_HOP is always this router\n");
12046 if (CHECK_FLAG(p->af_flags[afi][safi],
12047 PEER_FLAG_AS_PATH_UNCHANGED))
12048 vty_out(vty,
12049 " AS_PATH is propagated unchanged to this neighbor\n");
12050 if (CHECK_FLAG(p->af_flags[afi][safi],
12051 PEER_FLAG_NEXTHOP_UNCHANGED))
12052 vty_out(vty,
12053 " NEXT_HOP is propagated unchanged to this neighbor\n");
12054 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12055 vty_out(vty,
12056 " MED is propagated unchanged to this neighbor\n");
12057 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12058 || CHECK_FLAG(p->af_flags[afi][safi],
12059 PEER_FLAG_SEND_EXT_COMMUNITY)
12060 || CHECK_FLAG(p->af_flags[afi][safi],
12061 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12062 vty_out(vty,
12063 " Community attribute sent to this neighbor");
12064 if (CHECK_FLAG(p->af_flags[afi][safi],
12065 PEER_FLAG_SEND_COMMUNITY)
12066 && CHECK_FLAG(p->af_flags[afi][safi],
12067 PEER_FLAG_SEND_EXT_COMMUNITY)
12068 && CHECK_FLAG(p->af_flags[afi][safi],
12069 PEER_FLAG_SEND_LARGE_COMMUNITY))
12070 vty_out(vty, "(all)\n");
12071 else if (CHECK_FLAG(p->af_flags[afi][safi],
12072 PEER_FLAG_SEND_LARGE_COMMUNITY))
12073 vty_out(vty, "(large)\n");
12074 else if (CHECK_FLAG(p->af_flags[afi][safi],
12075 PEER_FLAG_SEND_EXT_COMMUNITY))
12076 vty_out(vty, "(extended)\n");
12077 else
12078 vty_out(vty, "(standard)\n");
12079 }
12080 if (CHECK_FLAG(p->af_flags[afi][safi],
12081 PEER_FLAG_DEFAULT_ORIGINATE)) {
12082 vty_out(vty, " Default information originate,");
12083
12084 if (p->default_rmap[afi][safi].name)
12085 vty_out(vty, " default route-map %s%s,",
12086 p->default_rmap[afi][safi].map ? "*"
12087 : "",
12088 p->default_rmap[afi][safi].name);
12089 if (paf && PAF_SUBGRP(paf)
12090 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12091 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12092 vty_out(vty, " default sent\n");
12093 else
12094 vty_out(vty, " default not sent\n");
12095 }
12096
dff8f48d
MK
12097 /* advertise-vni-all */
12098 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12099 if (is_evpn_enabled())
dff8f48d
MK
12100 vty_out(vty, " advertise-all-vni\n");
12101 }
12102
d62a17ae 12103 if (filter->plist[FILTER_IN].name
12104 || filter->dlist[FILTER_IN].name
12105 || filter->aslist[FILTER_IN].name
12106 || filter->map[RMAP_IN].name)
12107 vty_out(vty, " Inbound path policy configured\n");
12108 if (filter->plist[FILTER_OUT].name
12109 || filter->dlist[FILTER_OUT].name
12110 || filter->aslist[FILTER_OUT].name
12111 || filter->map[RMAP_OUT].name || filter->usmap.name)
12112 vty_out(vty, " Outbound path policy configured\n");
12113
12114 /* prefix-list */
12115 if (filter->plist[FILTER_IN].name)
12116 vty_out(vty,
12117 " Incoming update prefix filter list is %s%s\n",
12118 filter->plist[FILTER_IN].plist ? "*" : "",
12119 filter->plist[FILTER_IN].name);
12120 if (filter->plist[FILTER_OUT].name)
12121 vty_out(vty,
12122 " Outgoing update prefix filter list is %s%s\n",
12123 filter->plist[FILTER_OUT].plist ? "*" : "",
12124 filter->plist[FILTER_OUT].name);
12125
12126 /* distribute-list */
12127 if (filter->dlist[FILTER_IN].name)
12128 vty_out(vty,
12129 " Incoming update network filter list is %s%s\n",
12130 filter->dlist[FILTER_IN].alist ? "*" : "",
12131 filter->dlist[FILTER_IN].name);
12132 if (filter->dlist[FILTER_OUT].name)
12133 vty_out(vty,
12134 " Outgoing update network filter list is %s%s\n",
12135 filter->dlist[FILTER_OUT].alist ? "*" : "",
12136 filter->dlist[FILTER_OUT].name);
12137
12138 /* filter-list. */
12139 if (filter->aslist[FILTER_IN].name)
12140 vty_out(vty,
12141 " Incoming update AS path filter list is %s%s\n",
12142 filter->aslist[FILTER_IN].aslist ? "*" : "",
12143 filter->aslist[FILTER_IN].name);
12144 if (filter->aslist[FILTER_OUT].name)
12145 vty_out(vty,
12146 " Outgoing update AS path filter list is %s%s\n",
12147 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12148 filter->aslist[FILTER_OUT].name);
12149
12150 /* route-map. */
12151 if (filter->map[RMAP_IN].name)
12152 vty_out(vty,
12153 " Route map for incoming advertisements is %s%s\n",
12154 filter->map[RMAP_IN].map ? "*" : "",
12155 filter->map[RMAP_IN].name);
12156 if (filter->map[RMAP_OUT].name)
12157 vty_out(vty,
12158 " Route map for outgoing advertisements is %s%s\n",
12159 filter->map[RMAP_OUT].map ? "*" : "",
12160 filter->map[RMAP_OUT].name);
12161
9dac9fc8 12162 /* ebgp-requires-policy (inbound) */
1d3fdccf 12163 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12164 && !bgp_inbound_policy_exists(p, filter))
12165 vty_out(vty,
12166 " Inbound updates discarded due to missing policy\n");
12167
12168 /* ebgp-requires-policy (outbound) */
1d3fdccf 12169 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12170 && !bgp_outbound_policy_exists(p, filter))
12171 vty_out(vty,
12172 " Outbound updates discarded due to missing policy\n");
12173
d62a17ae 12174 /* unsuppress-map */
12175 if (filter->usmap.name)
12176 vty_out(vty,
12177 " Route map for selective unsuppress is %s%s\n",
12178 filter->usmap.map ? "*" : "",
12179 filter->usmap.name);
12180
7f7940e6
MK
12181 /* advertise-map */
12182 if (filter->advmap.aname && filter->advmap.cname)
12183 vty_out(vty,
12184 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12185 filter->advmap.condition ? "EXIST"
12186 : "NON_EXIST",
12187 filter->advmap.cmap ? "*" : "",
12188 filter->advmap.cname,
12189 filter->advmap.amap ? "*" : "",
12190 filter->advmap.aname,
fa36596c 12191 filter->advmap.update_type == ADVERTISE
c385f82a
MK
12192 ? "Advertise"
12193 : "Withdraw");
7f7940e6 12194
d62a17ae 12195 /* Receive prefix count */
6cde4b45 12196 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12197 p->pcount[afi][safi]);
d62a17ae 12198
fde246e8
DA
12199 /* maximum-prefix-out */
12200 if (CHECK_FLAG(p->af_flags[afi][safi],
12201 PEER_FLAG_MAX_PREFIX_OUT))
12202 vty_out(vty,
6cde4b45 12203 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12204 p->pmax_out[afi][safi]);
12205
d62a17ae 12206 /* Maximum prefix */
12207 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12208 vty_out(vty,
6cde4b45 12209 " Maximum prefixes allowed %u%s\n",
d62a17ae 12210 p->pmax[afi][safi],
12211 CHECK_FLAG(p->af_flags[afi][safi],
12212 PEER_FLAG_MAX_PREFIX_WARNING)
12213 ? " (warning-only)"
12214 : "");
12215 vty_out(vty, " Threshold for warning message %d%%",
12216 p->pmax_threshold[afi][safi]);
12217 if (p->pmax_restart[afi][safi])
12218 vty_out(vty, ", restart interval %d min",
12219 p->pmax_restart[afi][safi]);
12220 vty_out(vty, "\n");
12221 }
12222
12223 vty_out(vty, "\n");
12224 }
12225}
12226
9f049418 12227static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12228 json_object *json)
718e3744 12229{
d62a17ae 12230 struct bgp *bgp;
12231 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12232 char timebuf[BGP_UPTIME_LEN];
12233 char dn_flag[2];
d62a17ae 12234 afi_t afi;
12235 safi_t safi;
d7c0a89a
QY
12236 uint16_t i;
12237 uint8_t *msg;
d62a17ae 12238 json_object *json_neigh = NULL;
12239 time_t epoch_tbuf;
4ab46701 12240 uint32_t sync_tcp_mss;
718e3744 12241
d62a17ae 12242 bgp = p->bgp;
12243
12244 if (use_json)
12245 json_neigh = json_object_new_object();
12246
12247 memset(dn_flag, '\0', sizeof(dn_flag));
12248 if (!p->conf_if && peer_dynamic_neighbor(p))
12249 dn_flag[0] = '*';
12250
12251 if (!use_json) {
12252 if (p->conf_if) /* Configured interface name. */
12253 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12254 BGP_PEER_SU_UNSPEC(p)
12255 ? "None"
12256 : sockunion2str(&p->su, buf,
12257 SU_ADDRSTRLEN));
12258 else /* Configured IP address. */
12259 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12260 p->host);
12261 }
12262
12263 if (use_json) {
12264 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12265 json_object_string_add(json_neigh, "bgpNeighborAddr",
12266 "none");
12267 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12268 json_object_string_add(
12269 json_neigh, "bgpNeighborAddr",
12270 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12271
12272 json_object_int_add(json_neigh, "remoteAs", p->as);
12273
12274 if (p->change_local_as)
12275 json_object_int_add(json_neigh, "localAs",
12276 p->change_local_as);
12277 else
12278 json_object_int_add(json_neigh, "localAs", p->local_as);
12279
12280 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12281 json_object_boolean_true_add(json_neigh,
12282 "localAsNoPrepend");
12283
12284 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12285 json_object_boolean_true_add(json_neigh,
12286 "localAsReplaceAs");
12287 } else {
12288 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12289 || (p->as_type == AS_INTERNAL))
12290 vty_out(vty, "remote AS %u, ", p->as);
12291 else
12292 vty_out(vty, "remote AS Unspecified, ");
12293 vty_out(vty, "local AS %u%s%s, ",
12294 p->change_local_as ? p->change_local_as : p->local_as,
12295 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12296 ? " no-prepend"
12297 : "",
12298 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12299 ? " replace-as"
12300 : "");
12301 }
faa16034
DS
12302 /* peer type internal or confed-internal */
12303 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12304 if (use_json) {
12305 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12306 json_object_boolean_true_add(
12307 json_neigh, "nbrConfedInternalLink");
12308 else
12309 json_object_boolean_true_add(json_neigh,
12310 "nbrInternalLink");
12311 } else {
12312 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12313 vty_out(vty, "confed-internal link\n");
12314 else
12315 vty_out(vty, "internal link\n");
12316 }
faa16034
DS
12317 /* peer type external or confed-external */
12318 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12319 if (use_json) {
12320 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12321 json_object_boolean_true_add(
12322 json_neigh, "nbrConfedExternalLink");
12323 else
12324 json_object_boolean_true_add(json_neigh,
12325 "nbrExternalLink");
12326 } else {
12327 if (bgp_confederation_peers_check(bgp, p->as))
12328 vty_out(vty, "confed-external link\n");
12329 else
12330 vty_out(vty, "external link\n");
12331 }
faa16034
DS
12332 } else {
12333 if (use_json)
12334 json_object_boolean_true_add(json_neigh,
12335 "nbrUnspecifiedLink");
12336 else
12337 vty_out(vty, "unspecified link\n");
d62a17ae 12338 }
12339
12340 /* Description. */
12341 if (p->desc) {
12342 if (use_json)
12343 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12344 else
12345 vty_out(vty, " Description: %s\n", p->desc);
12346 }
12347
12348 if (p->hostname) {
12349 if (use_json) {
12350 if (p->hostname)
12351 json_object_string_add(json_neigh, "hostname",
12352 p->hostname);
12353
12354 if (p->domainname)
12355 json_object_string_add(json_neigh, "domainname",
12356 p->domainname);
12357 } else {
12358 if (p->domainname && (p->domainname[0] != '\0'))
12359 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12360 p->domainname);
12361 else
12362 vty_out(vty, "Hostname: %s\n", p->hostname);
12363 }
12364 }
12365
12366 /* Peer-group */
12367 if (p->group) {
12368 if (use_json) {
12369 json_object_string_add(json_neigh, "peerGroup",
12370 p->group->name);
12371
12372 if (dn_flag[0]) {
12373 struct prefix prefix, *range = NULL;
12374
0154d8ce
DS
12375 if (sockunion2hostprefix(&(p->su), &prefix))
12376 range = peer_group_lookup_dynamic_neighbor_range(
12377 p->group, &prefix);
d62a17ae 12378
12379 if (range) {
67d7e256 12380 json_object_string_addf(
d62a17ae 12381 json_neigh,
67d7e256
DA
12382 "peerSubnetRangeGroup", "%pFX",
12383 range);
d62a17ae 12384 }
12385 }
12386 } else {
12387 vty_out(vty,
12388 " Member of peer-group %s for session parameters\n",
12389 p->group->name);
12390
12391 if (dn_flag[0]) {
12392 struct prefix prefix, *range = NULL;
12393
0154d8ce
DS
12394 if (sockunion2hostprefix(&(p->su), &prefix))
12395 range = peer_group_lookup_dynamic_neighbor_range(
12396 p->group, &prefix);
d62a17ae 12397
12398 if (range) {
d62a17ae 12399 vty_out(vty,
1b78780b
DL
12400 " Belongs to the subnet range group: %pFX\n",
12401 range);
d62a17ae 12402 }
12403 }
12404 }
12405 }
12406
12407 if (use_json) {
12408 /* Administrative shutdown. */
cb9196e7
DS
12409 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12410 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12411 json_object_boolean_true_add(json_neigh,
12412 "adminShutDown");
12413
12414 /* BGP Version. */
12415 json_object_int_add(json_neigh, "bgpVersion", 4);
c949c771
DA
12416 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12417 &p->remote_id);
12418 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12419 &bgp->router_id);
d62a17ae 12420
12421 /* Confederation */
12422 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12423 && bgp_confederation_peers_check(bgp, p->as))
12424 json_object_boolean_true_add(json_neigh,
12425 "nbrCommonAdmin");
12426
12427 /* Status. */
12428 json_object_string_add(
12429 json_neigh, "bgpState",
12430 lookup_msg(bgp_status_msg, p->status, NULL));
12431
feb17238 12432 if (peer_established(p)) {
d62a17ae 12433 time_t uptime;
d62a17ae 12434
12435 uptime = bgp_clock();
12436 uptime -= p->uptime;
d62a17ae 12437 epoch_tbuf = time(NULL) - uptime;
12438
d3c7efed
DS
12439 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12440 uptime * 1000);
d62a17ae 12441 json_object_string_add(json_neigh, "bgpTimerUpString",
12442 peer_uptime(p->uptime, timebuf,
12443 BGP_UPTIME_LEN, 0,
12444 NULL));
12445 json_object_int_add(json_neigh,
12446 "bgpTimerUpEstablishedEpoch",
12447 epoch_tbuf);
12448 }
12449
12450 else if (p->status == Active) {
12451 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12452 json_object_string_add(json_neigh, "bgpStateIs",
12453 "passive");
12454 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12455 json_object_string_add(json_neigh, "bgpStateIs",
12456 "passiveNSF");
12457 }
12458
12459 /* read timer */
12460 time_t uptime;
a2700b50 12461 struct tm tm;
d62a17ae 12462
12463 uptime = bgp_clock();
12464 uptime -= p->readtime;
a2700b50
MS
12465 gmtime_r(&uptime, &tm);
12466
d62a17ae 12467 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
12468 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12469 + (tm.tm_hour * 3600000));
d62a17ae 12470
12471 uptime = bgp_clock();
12472 uptime -= p->last_write;
a2700b50
MS
12473 gmtime_r(&uptime, &tm);
12474
d62a17ae 12475 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
12476 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12477 + (tm.tm_hour * 3600000));
d62a17ae 12478
12479 uptime = bgp_clock();
12480 uptime -= p->update_time;
a2700b50
MS
12481 gmtime_r(&uptime, &tm);
12482
d62a17ae 12483 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
12484 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12485 + (tm.tm_hour * 3600000));
d62a17ae 12486
12487 /* Configured timer values. */
12488 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12489 p->v_holdtime * 1000);
12490 json_object_int_add(json_neigh,
12491 "bgpTimerKeepAliveIntervalMsecs",
12492 p->v_keepalive * 1000);
d43114f3
DS
12493 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12494 json_object_int_add(json_neigh,
12495 "bgpTimerDelayOpenTimeMsecs",
12496 p->v_delayopen * 1000);
12497 }
12498
4ab46701
AR
12499 /* Configured and Synced tcp-mss value for peer */
12500 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12501 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12502 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12503 p->tcp_mss);
12504 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12505 sync_tcp_mss);
12506 }
12507
b90a8e13 12508 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12509 json_object_int_add(json_neigh,
12510 "bgpTimerConfiguredHoldTimeMsecs",
12511 p->holdtime * 1000);
12512 json_object_int_add(
12513 json_neigh,
12514 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12515 p->keepalive * 1000);
5d5393b9
DL
12516 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12517 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12518 json_object_int_add(json_neigh,
12519 "bgpTimerConfiguredHoldTimeMsecs",
12520 bgp->default_holdtime);
12521 json_object_int_add(
12522 json_neigh,
12523 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12524 bgp->default_keepalive);
d62a17ae 12525 }
d08c0c80
DA
12526
12527 /* Extended Optional Parameters Length for BGP OPEN Message */
12528 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12529 json_object_boolean_true_add(
12530 json_neigh, "extendedOptionalParametersLength");
12531 else
12532 json_object_boolean_false_add(
12533 json_neigh, "extendedOptionalParametersLength");
d62a17ae 12534 } else {
12535 /* Administrative shutdown. */
cb9196e7
DS
12536 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12537 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12538 vty_out(vty, " Administratively shut down\n");
12539
12540 /* BGP Version. */
12541 vty_out(vty, " BGP version 4");
0e38aeb4 12542 vty_out(vty, ", remote router ID %s",
d62a17ae 12543 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
12544 vty_out(vty, ", local router ID %s\n",
12545 inet_ntop(AF_INET, &bgp->router_id, buf1,
12546 sizeof(buf1)));
d62a17ae 12547
12548 /* Confederation */
12549 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12550 && bgp_confederation_peers_check(bgp, p->as))
12551 vty_out(vty,
12552 " Neighbor under common administration\n");
12553
12554 /* Status. */
12555 vty_out(vty, " BGP state = %s",
12556 lookup_msg(bgp_status_msg, p->status, NULL));
12557
feb17238 12558 if (peer_established(p))
d62a17ae 12559 vty_out(vty, ", up for %8s",
12560 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12561 0, NULL));
12562
12563 else if (p->status == Active) {
12564 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12565 vty_out(vty, " (passive)");
12566 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12567 vty_out(vty, " (NSF passive)");
12568 }
12569 vty_out(vty, "\n");
12570
12571 /* read timer */
12572 vty_out(vty, " Last read %s",
12573 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12574 NULL));
12575 vty_out(vty, ", Last write %s\n",
12576 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12577 NULL));
12578
12579 /* Configured timer values. */
12580 vty_out(vty,
12581 " Hold time is %d, keepalive interval is %d seconds\n",
12582 p->v_holdtime, p->v_keepalive);
b90a8e13 12583 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12584 vty_out(vty, " Configured hold time is %d",
12585 p->holdtime);
12586 vty_out(vty, ", keepalive interval is %d seconds\n",
12587 p->keepalive);
5d5393b9
DL
12588 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12589 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12590 vty_out(vty, " Configured hold time is %d",
12591 bgp->default_holdtime);
12592 vty_out(vty, ", keepalive interval is %d seconds\n",
12593 bgp->default_keepalive);
d62a17ae 12594 }
d43114f3
DS
12595 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12596 vty_out(vty,
12597 " Configured DelayOpenTime is %d seconds\n",
12598 p->delayopen);
4ab46701
AR
12599
12600 /* Configured and synced tcp-mss value for peer */
12601 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12602 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12603 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12604 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12605 }
d08c0c80
DA
12606
12607 /* Extended Optional Parameters Length for BGP OPEN Message */
12608 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12609 vty_out(vty,
12610 " Extended Optional Parameters Length is enabled\n");
d62a17ae 12611 }
12612 /* Capability. */
10711563
DA
12613 if (peer_established(p) &&
12614 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
12615 if (use_json) {
12616 json_object *json_cap = NULL;
d62a17ae 12617
10711563 12618 json_cap = json_object_new_object();
d62a17ae 12619
10711563
DA
12620 /* AS4 */
12621 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
12622 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12623 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
12624 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
ef56aee4 12625 json_object_string_add(
10711563 12626 json_cap, "4byteAs",
ef56aee4 12627 "advertisedAndReceived");
10711563
DA
12628 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
12629 json_object_string_add(json_cap,
12630 "4byteAs",
12631 "advertised");
12632 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12633 json_object_string_add(json_cap,
12634 "4byteAs",
12635 "received");
12636 }
ef56aee4 12637
10711563
DA
12638 /* Extended Message Support */
12639 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
12640 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
12641 json_object_string_add(json_cap,
12642 "extendedMessage",
12643 "advertisedAndReceived");
12644 else if (CHECK_FLAG(p->cap,
12645 PEER_CAP_EXTENDED_MESSAGE_ADV))
12646 json_object_string_add(json_cap,
12647 "extendedMessage",
12648 "advertised");
12649 else if (CHECK_FLAG(p->cap,
12650 PEER_CAP_EXTENDED_MESSAGE_RCV))
12651 json_object_string_add(json_cap,
12652 "extendedMessage",
12653 "received");
ef56aee4 12654
10711563
DA
12655 /* AddPath */
12656 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
12657 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
12658 json_object *json_add = NULL;
12659 const char *print_store;
d62a17ae 12660
10711563 12661 json_add = json_object_new_object();
d62a17ae 12662
10711563
DA
12663 FOREACH_AFI_SAFI (afi, safi) {
12664 json_object *json_sub = NULL;
12665 json_sub = json_object_new_object();
12666 print_store = get_afi_safi_str(
12667 afi, safi, true);
d62a17ae 12668
10711563
DA
12669 if (CHECK_FLAG(
12670 p->af_cap[afi][safi],
12671 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12672 CHECK_FLAG(
12673 p->af_cap[afi][safi],
12674 PEER_CAP_ADDPATH_AF_TX_RCV)) {
05c7a1cc
QY
12675 if (CHECK_FLAG(
12676 p->af_cap[afi]
12677 [safi],
10711563
DA
12678 PEER_CAP_ADDPATH_AF_TX_ADV) &&
12679 CHECK_FLAG(
05c7a1cc
QY
12680 p->af_cap[afi]
12681 [safi],
10711563
DA
12682 PEER_CAP_ADDPATH_AF_TX_RCV))
12683 json_object_boolean_true_add(
12684 json_sub,
12685 "txAdvertisedAndReceived");
12686 else if (
12687 CHECK_FLAG(
12688 p->af_cap[afi]
12689 [safi],
12690 PEER_CAP_ADDPATH_AF_TX_ADV))
12691 json_object_boolean_true_add(
12692 json_sub,
12693 "txAdvertised");
12694 else if (
12695 CHECK_FLAG(
12696 p->af_cap[afi]
12697 [safi],
12698 PEER_CAP_ADDPATH_AF_TX_RCV))
12699 json_object_boolean_true_add(
12700 json_sub,
12701 "txReceived");
12702 }
d62a17ae 12703
10711563
DA
12704 if (CHECK_FLAG(
12705 p->af_cap[afi][safi],
12706 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12707 CHECK_FLAG(
12708 p->af_cap[afi][safi],
12709 PEER_CAP_ADDPATH_AF_RX_RCV)) {
05c7a1cc
QY
12710 if (CHECK_FLAG(
12711 p->af_cap[afi]
12712 [safi],
10711563
DA
12713 PEER_CAP_ADDPATH_AF_RX_ADV) &&
12714 CHECK_FLAG(
12715 p->af_cap[afi]
12716 [safi],
12717 PEER_CAP_ADDPATH_AF_RX_RCV))
12718 json_object_boolean_true_add(
12719 json_sub,
12720 "rxAdvertisedAndReceived");
12721 else if (
12722 CHECK_FLAG(
12723 p->af_cap[afi]
12724 [safi],
12725 PEER_CAP_ADDPATH_AF_RX_ADV))
12726 json_object_boolean_true_add(
12727 json_sub,
12728 "rxAdvertised");
12729 else if (
12730 CHECK_FLAG(
12731 p->af_cap[afi]
12732 [safi],
12733 PEER_CAP_ADDPATH_AF_RX_RCV))
12734 json_object_boolean_true_add(
12735 json_sub,
12736 "rxReceived");
05c7a1cc
QY
12737 }
12738
10711563
DA
12739 if (CHECK_FLAG(
12740 p->af_cap[afi][safi],
12741 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12742 CHECK_FLAG(
12743 p->af_cap[afi][safi],
12744 PEER_CAP_ADDPATH_AF_TX_RCV) ||
12745 CHECK_FLAG(
12746 p->af_cap[afi][safi],
12747 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12748 CHECK_FLAG(
12749 p->af_cap[afi][safi],
12750 PEER_CAP_ADDPATH_AF_RX_RCV))
12751 json_object_object_add(
12752 json_add, print_store,
12753 json_sub);
12754 else
12755 json_object_free(json_sub);
d62a17ae 12756 }
12757
10711563
DA
12758 json_object_object_add(json_cap, "addPath",
12759 json_add);
12760 }
d62a17ae 12761
10711563
DA
12762 /* Dynamic */
12763 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
12764 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
12765 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
12766 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
12767 json_object_string_add(
12768 json_cap, "dynamic",
12769 "advertisedAndReceived");
12770 else if (CHECK_FLAG(p->cap,
12771 PEER_CAP_DYNAMIC_ADV))
12772 json_object_string_add(json_cap,
12773 "dynamic",
12774 "advertised");
12775 else if (CHECK_FLAG(p->cap,
12776 PEER_CAP_DYNAMIC_RCV))
12777 json_object_string_add(json_cap,
12778 "dynamic",
12779 "received");
12780 }
d62a17ae 12781
10711563
DA
12782 /* Extended nexthop */
12783 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
12784 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12785 json_object *json_nxt = NULL;
12786 const char *print_store;
d62a17ae 12787
d62a17ae 12788
10711563
DA
12789 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
12790 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12791 json_object_string_add(
12792 json_cap, "extendedNexthop",
12793 "advertisedAndReceived");
12794 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
12795 json_object_string_add(
12796 json_cap, "extendedNexthop",
12797 "advertised");
12798 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12799 json_object_string_add(
12800 json_cap, "extendedNexthop",
12801 "received");
d62a17ae 12802
10711563
DA
12803 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
12804 json_nxt = json_object_new_object();
d62a17ae 12805
10711563
DA
12806 for (safi = SAFI_UNICAST;
12807 safi < SAFI_MAX; safi++) {
12808 if (CHECK_FLAG(
12809 p->af_cap[AFI_IP]
12810 [safi],
12811 PEER_CAP_ENHE_AF_RCV)) {
12812 print_store =
12813 get_afi_safi_str(
d62a17ae 12814 AFI_IP,
10711563
DA
12815 safi,
12816 true);
12817 json_object_string_add(
12818 json_nxt,
12819 print_store,
12820 "recieved"); /* misspelled for compatibility */
d62a17ae 12821 }
d62a17ae 12822 }
10711563
DA
12823 json_object_object_add(
12824 json_cap,
12825 "extendedNexthopFamililesByPeer",
12826 json_nxt);
d62a17ae 12827 }
10711563 12828 }
d62a17ae 12829
10711563
DA
12830 /* Long-lived Graceful Restart */
12831 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
12832 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
12833 json_object *json_llgr = NULL;
12834 const char *afi_safi_str;
8606be87 12835
10711563
DA
12836 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
12837 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12838 json_object_string_add(
12839 json_cap,
12840 "longLivedGracefulRestart",
12841 "advertisedAndReceived");
12842 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
12843 json_object_string_add(
12844 json_cap,
12845 "longLivedGracefulRestart",
12846 "advertised");
12847 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12848 json_object_string_add(
12849 json_cap,
12850 "longLivedGracefulRestart",
12851 "received");
8606be87 12852
10711563
DA
12853 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
12854 json_llgr = json_object_new_object();
8606be87 12855
10711563
DA
12856 FOREACH_AFI_SAFI (afi, safi) {
12857 if (CHECK_FLAG(
12858 p->af_cap[afi]
12859 [safi],
12860 PEER_CAP_ENHE_AF_RCV)) {
12861 afi_safi_str =
12862 get_afi_safi_str(
8606be87
DA
12863 afi,
12864 safi,
12865 true);
10711563
DA
12866 json_object_string_add(
12867 json_llgr,
12868 afi_safi_str,
12869 "received");
8606be87 12870 }
8606be87 12871 }
10711563
DA
12872 json_object_object_add(
12873 json_cap,
12874 "longLivedGracefulRestartByPeer",
12875 json_llgr);
8606be87 12876 }
10711563 12877 }
8606be87 12878
10711563
DA
12879 /* Route Refresh */
12880 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
12881 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
12882 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
12883 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
12884 (CHECK_FLAG(p->cap,
12885 PEER_CAP_REFRESH_NEW_RCV) ||
12886 CHECK_FLAG(p->cap,
12887 PEER_CAP_REFRESH_OLD_RCV))) {
12888 if (CHECK_FLAG(
12889 p->cap,
12890 PEER_CAP_REFRESH_OLD_RCV) &&
12891 CHECK_FLAG(
12892 p->cap,
12893 PEER_CAP_REFRESH_NEW_RCV))
12894 json_object_string_add(
12895 json_cap,
12896 "routeRefresh",
12897 "advertisedAndReceivedOldNew");
12898 else {
d62a17ae 12899 if (CHECK_FLAG(
12900 p->cap,
10711563 12901 PEER_CAP_REFRESH_OLD_RCV))
d62a17ae 12902 json_object_string_add(
12903 json_cap,
12904 "routeRefresh",
10711563
DA
12905 "advertisedAndReceivedOld");
12906 else
12907 json_object_string_add(
12908 json_cap,
12909 "routeRefresh",
12910 "advertisedAndReceivedNew");
d62a17ae 12911 }
10711563
DA
12912 } else if (CHECK_FLAG(p->cap,
12913 PEER_CAP_REFRESH_ADV))
12914 json_object_string_add(json_cap,
12915 "routeRefresh",
12916 "advertised");
12917 else if (CHECK_FLAG(p->cap,
12918 PEER_CAP_REFRESH_NEW_RCV) ||
12919 CHECK_FLAG(p->cap,
12920 PEER_CAP_REFRESH_OLD_RCV))
12921 json_object_string_add(json_cap,
12922 "routeRefresh",
12923 "received");
12924 }
d62a17ae 12925
10711563
DA
12926 /* Enhanced Route Refresh */
12927 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
12928 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
12929 if (CHECK_FLAG(p->cap,
12930 PEER_CAP_ENHANCED_RR_ADV) &&
12931 CHECK_FLAG(p->cap,
12932 PEER_CAP_ENHANCED_RR_RCV))
d77114b7 12933 json_object_string_add(
10711563
DA
12934 json_cap,
12935 "enhancedRouteRefresh",
12936 "advertisedAndReceived");
12937 else if (CHECK_FLAG(p->cap,
12938 PEER_CAP_ENHANCED_RR_ADV))
d77114b7 12939 json_object_string_add(
10711563
DA
12940 json_cap,
12941 "enhancedRouteRefresh",
12942 "advertised");
12943 else if (CHECK_FLAG(p->cap,
9af52ccf 12944 PEER_CAP_ENHANCED_RR_RCV))
10711563
DA
12945 json_object_string_add(
12946 json_cap,
12947 "enhancedRouteRefresh",
12948 "received");
12949 }
d77114b7 12950
10711563
DA
12951 /* Multiprotocol Extensions */
12952 json_object *json_multi = NULL;
d77114b7 12953
10711563 12954 json_multi = json_object_new_object();
d77114b7 12955
10711563
DA
12956 FOREACH_AFI_SAFI (afi, safi) {
12957 if (p->afc_adv[afi][safi] ||
12958 p->afc_recv[afi][safi]) {
12959 json_object *json_exten = NULL;
12960 json_exten = json_object_new_object();
12961
12962 if (p->afc_adv[afi][safi] &&
12963 p->afc_recv[afi][safi])
12964 json_object_boolean_true_add(
12965 json_exten,
9af52ccf 12966 "advertisedAndReceived");
10711563
DA
12967 else if (p->afc_adv[afi][safi])
12968 json_object_boolean_true_add(
12969 json_exten,
9af52ccf 12970 "advertised");
10711563
DA
12971 else if (p->afc_recv[afi][safi])
12972 json_object_boolean_true_add(
12973 json_exten, "received");
9af52ccf 12974
10711563
DA
12975 json_object_object_add(
12976 json_multi,
12977 get_afi_safi_str(afi, safi,
12978 true),
12979 json_exten);
12980 }
12981 }
12982 json_object_object_add(json_cap,
12983 "multiprotocolExtensions",
12984 json_multi);
d62a17ae 12985
10711563
DA
12986 /* Hostname capabilities */
12987 json_object *json_hname = NULL;
d62a17ae 12988
10711563 12989 json_hname = json_object_new_object();
d62a17ae 12990
10711563
DA
12991 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
12992 json_object_string_add(
12993 json_hname, "advHostName",
12994 bgp->peer_self->hostname
12995 ? bgp->peer_self->hostname
12996 : "n/a");
12997 json_object_string_add(
12998 json_hname, "advDomainName",
12999 bgp->peer_self->domainname
13000 ? bgp->peer_self->domainname
13001 : "n/a");
13002 }
d77114b7 13003
d77114b7 13004
10711563
DA
13005 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13006 json_object_string_add(
13007 json_hname, "rcvHostName",
13008 p->hostname ? p->hostname : "n/a");
13009 json_object_string_add(
13010 json_hname, "rcvDomainName",
13011 p->domainname ? p->domainname : "n/a");
13012 }
d77114b7 13013
10711563
DA
13014 json_object_object_add(json_cap, "hostName",
13015 json_hname);
d77114b7 13016
10711563
DA
13017 /* Gracefull Restart */
13018 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13019 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13020 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13021 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
d77114b7 13022 json_object_string_add(
10711563
DA
13023 json_cap, "gracefulRestart",
13024 "advertisedAndReceived");
13025 else if (CHECK_FLAG(p->cap,
13026 PEER_CAP_RESTART_ADV))
d77114b7 13027 json_object_string_add(
10711563
DA
13028 json_cap,
13029 "gracefulRestartCapability",
13030 "advertised");
13031 else if (CHECK_FLAG(p->cap,
13032 PEER_CAP_RESTART_RCV))
13033 json_object_string_add(
13034 json_cap,
13035 "gracefulRestartCapability",
13036 "received");
d77114b7 13037
10711563
DA
13038 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13039 int restart_af_count = 0;
13040 json_object *json_restart = NULL;
13041 json_restart = json_object_new_object();
d62a17ae 13042
10711563
DA
13043 json_object_int_add(
13044 json_cap,
13045 "gracefulRestartRemoteTimerMsecs",
13046 p->v_gr_restart * 1000);
d62a17ae 13047
10711563 13048 FOREACH_AFI_SAFI (afi, safi) {
05c7a1cc
QY
13049 if (CHECK_FLAG(
13050 p->af_cap[afi]
13051 [safi],
10711563
DA
13052 PEER_CAP_RESTART_AF_RCV)) {
13053 json_object *json_sub =
13054 NULL;
13055 json_sub =
13056 json_object_new_object();
d62a17ae 13057
05c7a1cc
QY
13058 if (CHECK_FLAG(
13059 p->af_cap
13060 [afi]
13061 [safi],
10711563
DA
13062 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13063 json_object_boolean_true_add(
13064 json_sub,
13065 "preserved");
13066 restart_af_count++;
d62a17ae 13067 json_object_object_add(
10711563
DA
13068 json_restart,
13069 get_afi_safi_str(
13070 afi,
13071 safi,
13072 true),
13073 json_sub);
d62a17ae 13074 }
d62a17ae 13075 }
10711563
DA
13076 if (!restart_af_count) {
13077 json_object_string_add(
13078 json_cap,
13079 "addressFamiliesByPeer",
13080 "none");
13081 json_object_free(json_restart);
13082 } else
13083 json_object_object_add(
13084 json_cap,
13085 "addressFamiliesByPeer",
13086 json_restart);
d62a17ae 13087 }
10711563
DA
13088 }
13089 json_object_object_add(
13090 json_neigh, "neighborCapabilities", json_cap);
13091 } else {
13092 vty_out(vty, " Neighbor capabilities:\n");
13093
13094 /* AS4 */
13095 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13096 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13097 vty_out(vty, " 4 Byte AS:");
13098 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13099 vty_out(vty, " advertised");
13100 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13101 vty_out(vty, " %sreceived",
13102 CHECK_FLAG(p->cap,
13103 PEER_CAP_AS4_ADV)
13104 ? "and "
13105 : "");
13106 vty_out(vty, "\n");
13107 }
d62a17ae 13108
10711563
DA
13109 /* Extended Message Support */
13110 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13111 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13112 vty_out(vty, " Extended Message:");
ef56aee4 13113 if (CHECK_FLAG(p->cap,
10711563
DA
13114 PEER_CAP_EXTENDED_MESSAGE_ADV))
13115 vty_out(vty, " advertised");
13116 if (CHECK_FLAG(p->cap,
13117 PEER_CAP_EXTENDED_MESSAGE_RCV))
13118 vty_out(vty, " %sreceived",
13119 CHECK_FLAG(
13120 p->cap,
13121 PEER_CAP_EXTENDED_MESSAGE_ADV)
13122 ? "and "
13123 : "");
13124 vty_out(vty, "\n");
13125 }
d62a17ae 13126
10711563
DA
13127 /* AddPath */
13128 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13129 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13130 vty_out(vty, " AddPath:\n");
d62a17ae 13131
10711563 13132 FOREACH_AFI_SAFI (afi, safi) {
ef56aee4 13133 if (CHECK_FLAG(
10711563
DA
13134 p->af_cap[afi][safi],
13135 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13136 CHECK_FLAG(
13137 p->af_cap[afi][safi],
13138 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13139 vty_out(vty, " %s: TX ",
13140 get_afi_safi_str(
13141 afi, safi,
13142 false));
ef56aee4 13143
10711563
DA
13144 if (CHECK_FLAG(
13145 p->af_cap[afi]
13146 [safi],
13147 PEER_CAP_ADDPATH_AF_TX_ADV))
13148 vty_out(vty,
13149 "advertised");
d62a17ae 13150
05c7a1cc
QY
13151 if (CHECK_FLAG(
13152 p->af_cap[afi]
13153 [safi],
10711563 13154 PEER_CAP_ADDPATH_AF_TX_RCV))
05c7a1cc 13155 vty_out(vty,
10711563
DA
13156 "%sreceived",
13157 CHECK_FLAG(
13158 p->af_cap
13159 [afi]
13160 [safi],
13161 PEER_CAP_ADDPATH_AF_TX_ADV)
13162 ? " and "
13163 : "");
05c7a1cc 13164
10711563
DA
13165 vty_out(vty, "\n");
13166 }
d62a17ae 13167
9af52ccf 13168 if (CHECK_FLAG(
10711563
DA
13169 p->af_cap[afi][safi],
13170 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13171 CHECK_FLAG(
13172 p->af_cap[afi][safi],
13173 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13174 vty_out(vty, " %s: RX ",
5cb5f4d0 13175 get_afi_safi_str(
10711563
DA
13176 afi, safi,
13177 false));
d62a17ae 13178
05c7a1cc
QY
13179 if (CHECK_FLAG(
13180 p->af_cap[afi]
13181 [safi],
10711563 13182 PEER_CAP_ADDPATH_AF_RX_ADV))
05c7a1cc 13183 vty_out(vty,
10711563 13184 "advertised");
d62a17ae 13185
10711563
DA
13186 if (CHECK_FLAG(
13187 p->af_cap[afi]
13188 [safi],
13189 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc 13190 vty_out(vty,
10711563
DA
13191 "%sreceived",
13192 CHECK_FLAG(
13193 p->af_cap
13194 [afi]
13195 [safi],
13196 PEER_CAP_ADDPATH_AF_RX_ADV)
13197 ? " and "
05c7a1cc 13198 : "");
d62a17ae 13199
05c7a1cc 13200 vty_out(vty, "\n");
05c7a1cc 13201 }
d62a17ae 13202 }
10711563 13203 }
d62a17ae 13204
10711563
DA
13205 /* Dynamic */
13206 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13207 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13208 vty_out(vty, " Dynamic:");
13209 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13210 vty_out(vty, " advertised");
13211 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13212 vty_out(vty, " %sreceived",
13213 CHECK_FLAG(p->cap,
13214 PEER_CAP_DYNAMIC_ADV)
13215 ? "and "
13216 : "");
13217 vty_out(vty, "\n");
13218 }
d62a17ae 13219
10711563
DA
13220 /* Extended nexthop */
13221 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13222 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13223 vty_out(vty, " Extended nexthop:");
13224 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13225 vty_out(vty, " advertised");
13226 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13227 vty_out(vty, " %sreceived",
13228 CHECK_FLAG(p->cap,
13229 PEER_CAP_ENHE_ADV)
13230 ? "and "
13231 : "");
13232 vty_out(vty, "\n");
d62a17ae 13233
10711563 13234 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
57f7feb6 13235 vty_out(vty,
10711563
DA
13236 " Address families by peer:\n ");
13237 for (safi = SAFI_UNICAST;
13238 safi < SAFI_MAX; safi++)
13239 if (CHECK_FLAG(
13240 p->af_cap[AFI_IP]
13241 [safi],
13242 PEER_CAP_ENHE_AF_RCV))
13243 vty_out(vty,
13244 " %s\n",
13245 get_afi_safi_str(
13246 AFI_IP,
13247 safi,
13248 false));
d62a17ae 13249 }
10711563 13250 }
d62a17ae 13251
10711563
DA
13252 /* Long-lived Graceful Restart */
13253 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13254 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13255 vty_out(vty,
13256 " Long-lived Graceful Restart:");
13257 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13258 vty_out(vty, " advertised");
13259 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13260 vty_out(vty, " %sreceived",
13261 CHECK_FLAG(p->cap,
13262 PEER_CAP_LLGR_ADV)
13263 ? "and "
13264 : "");
13265 vty_out(vty, "\n");
8606be87 13266
10711563 13267 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
57f7feb6 13268 vty_out(vty,
10711563
DA
13269 " Address families by peer:\n");
13270 FOREACH_AFI_SAFI (afi, safi)
13271 if (CHECK_FLAG(
13272 p->af_cap[afi]
13273 [safi],
13274 PEER_CAP_LLGR_AF_RCV))
13275 vty_out(vty,
13276 " %s\n",
13277 get_afi_safi_str(
13278 afi,
13279 safi,
13280 false));
8606be87 13281 }
10711563 13282 }
8606be87 13283
10711563
DA
13284 /* Route Refresh */
13285 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13286 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13287 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13288 vty_out(vty, " Route refresh:");
13289 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13290 vty_out(vty, " advertised");
13291 if (CHECK_FLAG(p->cap,
13292 PEER_CAP_REFRESH_NEW_RCV) ||
13293 CHECK_FLAG(p->cap,
13294 PEER_CAP_REFRESH_OLD_RCV))
13295 vty_out(vty, " %sreceived(%s)",
13296 CHECK_FLAG(p->cap,
13297 PEER_CAP_REFRESH_ADV)
13298 ? "and "
13299 : "",
13300 (CHECK_FLAG(
13301 p->cap,
13302 PEER_CAP_REFRESH_OLD_RCV) &&
13303 CHECK_FLAG(
13304 p->cap,
13305 PEER_CAP_REFRESH_NEW_RCV))
13306 ? "old & new"
13307 : CHECK_FLAG(
13308 p->cap,
13309 PEER_CAP_REFRESH_OLD_RCV)
13310 ? "old"
13311 : "new");
d62a17ae 13312
d77114b7 13313 vty_out(vty, "\n");
10711563 13314 }
d62a17ae 13315
10711563
DA
13316 /* Enhanced Route Refresh */
13317 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13318 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13319 vty_out(vty, " Enhanced Route Refresh:");
13320 if (CHECK_FLAG(p->cap,
13321 PEER_CAP_ENHANCED_RR_ADV))
13322 vty_out(vty, " advertised");
13323 if (CHECK_FLAG(p->cap,
13324 PEER_CAP_ENHANCED_RR_RCV))
13325 vty_out(vty, " %sreceived",
13326 CHECK_FLAG(p->cap,
13327 PEER_CAP_REFRESH_ADV)
13328 ? "and "
13329 : "");
13330 vty_out(vty, "\n");
13331 }
13332
13333 /* Multiprotocol Extensions */
13334 FOREACH_AFI_SAFI (afi, safi)
13335 if (p->afc_adv[afi][safi] ||
13336 p->afc_recv[afi][safi]) {
13337 vty_out(vty, " Address Family %s:",
13338 get_afi_safi_str(afi, safi,
13339 false));
13340 if (p->afc_adv[afi][safi])
9af52ccf 13341 vty_out(vty, " advertised");
10711563 13342 if (p->afc_recv[afi][safi])
9af52ccf 13343 vty_out(vty, " %sreceived",
10711563 13344 p->afc_adv[afi][safi]
9af52ccf
DA
13345 ? "and "
13346 : "");
13347 vty_out(vty, "\n");
13348 }
13349
10711563
DA
13350 /* Hostname capability */
13351 vty_out(vty, " Hostname Capability:");
d62a17ae 13352
10711563
DA
13353 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13354 vty_out(vty,
13355 " advertised (name: %s,domain name: %s)",
13356 bgp->peer_self->hostname
13357 ? bgp->peer_self->hostname
13358 : "n/a",
13359 bgp->peer_self->domainname
13360 ? bgp->peer_self->domainname
13361 : "n/a");
13362 } else {
13363 vty_out(vty, " not advertised");
13364 }
d77114b7 13365
10711563
DA
13366 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13367 vty_out(vty,
13368 " received (name: %s,domain name: %s)",
13369 p->hostname ? p->hostname : "n/a",
13370 p->domainname ? p->domainname : "n/a");
13371 } else {
13372 vty_out(vty, " not received");
d62a17ae 13373 }
d62a17ae 13374
10711563 13375 vty_out(vty, "\n");
d77114b7 13376
10711563
DA
13377 /* Graceful Restart */
13378 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13379 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13380 vty_out(vty,
13381 " Graceful Restart Capability:");
13382 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13383 vty_out(vty, " advertised");
13384 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13385 vty_out(vty, " %sreceived",
13386 CHECK_FLAG(p->cap,
13387 PEER_CAP_RESTART_ADV)
13388 ? "and "
13389 : "");
d77114b7
MK
13390 vty_out(vty, "\n");
13391
10711563
DA
13392 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13393 int restart_af_count = 0;
d62a17ae 13394
10711563
DA
13395 vty_out(vty,
13396 " Remote Restart timer is %d seconds\n",
13397 p->v_gr_restart);
13398 vty_out(vty,
13399 " Address families by peer:\n ");
d62a17ae 13400
10711563
DA
13401 FOREACH_AFI_SAFI (afi, safi)
13402 if (CHECK_FLAG(
13403 p->af_cap[afi]
13404 [safi],
13405 PEER_CAP_RESTART_AF_RCV)) {
13406 vty_out(vty, "%s%s(%s)",
13407 restart_af_count
13408 ? ", "
13409 : "",
13410 get_afi_safi_str(
13411 afi,
13412 safi,
13413 false),
13414 CHECK_FLAG(
13415 p->af_cap
13416 [afi]
13417 [safi],
13418 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13419 ? "preserved"
13420 : "not preserved");
13421 restart_af_count++;
13422 }
13423 if (!restart_af_count)
13424 vty_out(vty, "none");
13425 vty_out(vty, "\n");
13426 }
13427 } /* Gracefull Restart */
d62a17ae 13428 }
13429 }
13430
13431 /* graceful restart information */
10711563
DA
13432 json_object *json_grace = NULL;
13433 json_object *json_grace_send = NULL;
13434 json_object *json_grace_recv = NULL;
13435 int eor_send_af_count = 0;
13436 int eor_receive_af_count = 0;
d62a17ae 13437
10711563
DA
13438 if (use_json) {
13439 json_grace = json_object_new_object();
13440 json_grace_send = json_object_new_object();
13441 json_grace_recv = json_object_new_object();
13442
13443 if ((peer_established(p)) &&
13444 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13445 FOREACH_AFI_SAFI (afi, safi) {
13446 if (CHECK_FLAG(p->af_sflags[afi][safi],
13447 PEER_STATUS_EOR_SEND)) {
13448 json_object_boolean_true_add(
13449 json_grace_send,
13450 get_afi_safi_str(afi, safi,
13451 true));
13452 eor_send_af_count++;
d62a17ae 13453 }
10711563
DA
13454 }
13455 FOREACH_AFI_SAFI (afi, safi) {
13456 if (CHECK_FLAG(p->af_sflags[afi][safi],
13457 PEER_STATUS_EOR_RECEIVED)) {
13458 json_object_boolean_true_add(
13459 json_grace_recv,
13460 get_afi_safi_str(afi, safi,
13461 true));
13462 eor_receive_af_count++;
d62a17ae 13463 }
13464 }
10711563
DA
13465 }
13466 json_object_object_add(json_grace, "endOfRibSend",
13467 json_grace_send);
13468 json_object_object_add(json_grace, "endOfRibRecv",
13469 json_grace_recv);
d62a17ae 13470
d62a17ae 13471
10711563
DA
13472 if (p->t_gr_restart)
13473 json_object_int_add(
13474 json_grace, "gracefulRestartTimerMsecs",
13475 thread_timer_remain_second(p->t_gr_restart) *
13476 1000);
2986cac2 13477
10711563
DA
13478 if (p->t_gr_stale)
13479 json_object_int_add(
13480 json_grace, "gracefulStalepathTimerMsecs",
13481 thread_timer_remain_second(p->t_gr_stale) *
13482 1000);
13483 /* more gr info in new format */
13484 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13485 json_object_object_add(json_neigh, "gracefulRestartInfo",
13486 json_grace);
13487 } else {
13488 vty_out(vty, " Graceful restart information:\n");
13489 if ((peer_established(p)) &&
13490 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13491
13492 vty_out(vty, " End-of-RIB send: ");
13493 FOREACH_AFI_SAFI (afi, safi) {
13494 if (CHECK_FLAG(p->af_sflags[afi][safi],
13495 PEER_STATUS_EOR_SEND)) {
13496 vty_out(vty, "%s%s",
13497 eor_send_af_count ? ", " : "",
13498 get_afi_safi_str(afi, safi,
13499 false));
13500 eor_send_af_count++;
d62a17ae 13501 }
10711563
DA
13502 }
13503 vty_out(vty, "\n");
13504 vty_out(vty, " End-of-RIB received: ");
13505 FOREACH_AFI_SAFI (afi, safi) {
13506 if (CHECK_FLAG(p->af_sflags[afi][safi],
13507 PEER_STATUS_EOR_RECEIVED)) {
13508 vty_out(vty, "%s%s",
13509 eor_receive_af_count ? ", "
13510 : "",
13511 get_afi_safi_str(afi, safi,
13512 false));
13513 eor_receive_af_count++;
d62a17ae 13514 }
d62a17ae 13515 }
10711563
DA
13516 vty_out(vty, "\n");
13517 }
d62a17ae 13518
10711563
DA
13519 if (p->t_gr_restart)
13520 vty_out(vty,
13521 " The remaining time of restart timer is %ld\n",
13522 thread_timer_remain_second(p->t_gr_restart));
d62a17ae 13523
10711563
DA
13524 if (p->t_gr_stale)
13525 vty_out(vty,
13526 " The remaining time of stalepath timer is %ld\n",
13527 thread_timer_remain_second(p->t_gr_stale));
2986cac2 13528
10711563
DA
13529 /* more gr info in new format */
13530 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13531 }
2986cac2 13532
d62a17ae 13533 if (use_json) {
13534 json_object *json_stat = NULL;
13535 json_stat = json_object_new_object();
13536 /* Packet counts. */
43aa5965
QY
13537
13538 atomic_size_t outq_count, inq_count;
13539 outq_count = atomic_load_explicit(&p->obuf->count,
13540 memory_order_relaxed);
13541 inq_count = atomic_load_explicit(&p->ibuf->count,
13542 memory_order_relaxed);
13543
13544 json_object_int_add(json_stat, "depthInq",
13545 (unsigned long)inq_count);
d62a17ae 13546 json_object_int_add(json_stat, "depthOutq",
43aa5965 13547 (unsigned long)outq_count);
0112e9e0
QY
13548 json_object_int_add(json_stat, "opensSent",
13549 atomic_load_explicit(&p->open_out,
13550 memory_order_relaxed));
13551 json_object_int_add(json_stat, "opensRecv",
13552 atomic_load_explicit(&p->open_in,
13553 memory_order_relaxed));
d62a17ae 13554 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
13555 atomic_load_explicit(&p->notify_out,
13556 memory_order_relaxed));
d62a17ae 13557 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
13558 atomic_load_explicit(&p->notify_in,
13559 memory_order_relaxed));
13560 json_object_int_add(json_stat, "updatesSent",
13561 atomic_load_explicit(&p->update_out,
13562 memory_order_relaxed));
13563 json_object_int_add(json_stat, "updatesRecv",
13564 atomic_load_explicit(&p->update_in,
13565 memory_order_relaxed));
d62a17ae 13566 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
13567 atomic_load_explicit(&p->keepalive_out,
13568 memory_order_relaxed));
d62a17ae 13569 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
13570 atomic_load_explicit(&p->keepalive_in,
13571 memory_order_relaxed));
d62a17ae 13572 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
13573 atomic_load_explicit(&p->refresh_out,
13574 memory_order_relaxed));
d62a17ae 13575 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
13576 atomic_load_explicit(&p->refresh_in,
13577 memory_order_relaxed));
d62a17ae 13578 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
13579 atomic_load_explicit(&p->dynamic_cap_out,
13580 memory_order_relaxed));
d62a17ae 13581 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
13582 atomic_load_explicit(&p->dynamic_cap_in,
13583 memory_order_relaxed));
13584 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13585 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 13586 json_object_object_add(json_neigh, "messageStats", json_stat);
13587 } else {
cb93e0a2
IS
13588 atomic_size_t outq_count, inq_count, open_out, open_in,
13589 notify_out, notify_in, update_out, update_in,
13590 keepalive_out, keepalive_in, refresh_out, refresh_in,
13591 dynamic_cap_out, dynamic_cap_in;
43aa5965
QY
13592 outq_count = atomic_load_explicit(&p->obuf->count,
13593 memory_order_relaxed);
13594 inq_count = atomic_load_explicit(&p->ibuf->count,
13595 memory_order_relaxed);
cb93e0a2
IS
13596 open_out = atomic_load_explicit(&p->open_out,
13597 memory_order_relaxed);
13598 open_in =
13599 atomic_load_explicit(&p->open_in, memory_order_relaxed);
13600 notify_out = atomic_load_explicit(&p->notify_out,
13601 memory_order_relaxed);
13602 notify_in = atomic_load_explicit(&p->notify_in,
13603 memory_order_relaxed);
13604 update_out = atomic_load_explicit(&p->update_out,
13605 memory_order_relaxed);
13606 update_in = atomic_load_explicit(&p->update_in,
13607 memory_order_relaxed);
13608 keepalive_out = atomic_load_explicit(&p->keepalive_out,
13609 memory_order_relaxed);
13610 keepalive_in = atomic_load_explicit(&p->keepalive_in,
13611 memory_order_relaxed);
13612 refresh_out = atomic_load_explicit(&p->refresh_out,
13613 memory_order_relaxed);
13614 refresh_in = atomic_load_explicit(&p->refresh_in,
13615 memory_order_relaxed);
13616 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
13617 memory_order_relaxed);
13618 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
13619 memory_order_relaxed);
43aa5965 13620
d62a17ae 13621 /* Packet counts. */
13622 vty_out(vty, " Message statistics:\n");
43aa5965
QY
13623 vty_out(vty, " Inq depth is %zu\n", inq_count);
13624 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 13625 vty_out(vty, " Sent Rcvd\n");
cb93e0a2
IS
13626 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
13627 open_in);
13628 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
13629 notify_in);
13630 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
13631 update_in);
13632 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
13633 keepalive_in);
13634 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
13635 refresh_in);
13636 vty_out(vty, " Capability: %10zu %10zu\n",
13637 dynamic_cap_out, dynamic_cap_in);
13638 vty_out(vty, " Total: %10u %10u\n",
13639 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
d62a17ae 13640 }
13641
13642 if (use_json) {
13643 /* advertisement-interval */
13644 json_object_int_add(json_neigh,
13645 "minBtwnAdvertisementRunsTimerMsecs",
13646 p->v_routeadv * 1000);
13647
13648 /* Update-source. */
13649 if (p->update_if || p->update_source) {
13650 if (p->update_if)
13651 json_object_string_add(json_neigh,
13652 "updateSource",
13653 p->update_if);
13654 else if (p->update_source)
13655 json_object_string_add(
13656 json_neigh, "updateSource",
13657 sockunion2str(p->update_source, buf1,
13658 SU_ADDRSTRLEN));
13659 }
13660 } else {
13661 /* advertisement-interval */
13662 vty_out(vty,
13663 " Minimum time between advertisement runs is %d seconds\n",
13664 p->v_routeadv);
13665
13666 /* Update-source. */
13667 if (p->update_if || p->update_source) {
13668 vty_out(vty, " Update source is ");
13669 if (p->update_if)
13670 vty_out(vty, "%s", p->update_if);
13671 else if (p->update_source)
13672 vty_out(vty, "%s",
13673 sockunion2str(p->update_source, buf1,
13674 SU_ADDRSTRLEN));
13675 vty_out(vty, "\n");
13676 }
13677
13678 vty_out(vty, "\n");
13679 }
13680
13681 /* Address Family Information */
13682 json_object *json_hold = NULL;
13683
13684 if (use_json)
13685 json_hold = json_object_new_object();
13686
05c7a1cc
QY
13687 FOREACH_AFI_SAFI (afi, safi)
13688 if (p->afc[afi][safi])
13689 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13690 json_hold);
d62a17ae 13691
13692 if (use_json) {
13693 json_object_object_add(json_neigh, "addressFamilyInfo",
13694 json_hold);
13695 json_object_int_add(json_neigh, "connectionsEstablished",
13696 p->established);
13697 json_object_int_add(json_neigh, "connectionsDropped",
13698 p->dropped);
13699 } else
13700 vty_out(vty, " Connections established %d; dropped %d\n",
13701 p->established, p->dropped);
13702
13703 if (!p->last_reset) {
13704 if (use_json)
13705 json_object_string_add(json_neigh, "lastReset",
13706 "never");
13707 else
13708 vty_out(vty, " Last reset never\n");
13709 } else {
13710 if (use_json) {
13711 time_t uptime;
a2700b50 13712 struct tm tm;
d62a17ae 13713
13714 uptime = bgp_clock();
13715 uptime -= p->resettime;
a2700b50
MS
13716 gmtime_r(&uptime, &tm);
13717
d62a17ae 13718 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
13719 (tm.tm_sec * 1000)
13720 + (tm.tm_min * 60000)
13721 + (tm.tm_hour * 3600000));
3577f1c5 13722 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 13723 } else {
13724 vty_out(vty, " Last reset %s, ",
13725 peer_uptime(p->resettime, timebuf,
13726 BGP_UPTIME_LEN, 0, NULL));
13727
3577f1c5 13728 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 13729 if (p->last_reset_cause_size) {
13730 msg = p->last_reset_cause;
13731 vty_out(vty,
13732 " Message received that caused BGP to send a NOTIFICATION:\n ");
13733 for (i = 1; i <= p->last_reset_cause_size;
13734 i++) {
13735 vty_out(vty, "%02X", *msg++);
13736
13737 if (i != p->last_reset_cause_size) {
13738 if (i % 16 == 0) {
13739 vty_out(vty, "\n ");
13740 } else if (i % 4 == 0) {
13741 vty_out(vty, " ");
13742 }
13743 }
13744 }
13745 vty_out(vty, "\n");
13746 }
13747 }
13748 }
13749
13750 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13751 if (use_json)
13752 json_object_boolean_true_add(json_neigh,
13753 "prefixesConfigExceedMax");
13754 else
13755 vty_out(vty,
13756 " Peer had exceeded the max. no. of prefixes configured.\n");
13757
13758 if (p->t_pmax_restart) {
13759 if (use_json) {
13760 json_object_boolean_true_add(
13761 json_neigh, "reducePrefixNumFrom");
13762 json_object_int_add(json_neigh,
13763 "restartInTimerMsec",
13764 thread_timer_remain_second(
13765 p->t_pmax_restart)
13766 * 1000);
13767 } else
13768 vty_out(vty,
13769 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
13770 p->host, thread_timer_remain_second(
13771 p->t_pmax_restart));
d62a17ae 13772 } else {
13773 if (use_json)
13774 json_object_boolean_true_add(
13775 json_neigh,
13776 "reducePrefixNumAndClearIpBgp");
13777 else
13778 vty_out(vty,
13779 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13780 p->host);
13781 }
13782 }
13783
13784 /* EBGP Multihop and GTSM */
13785 if (p->sort != BGP_PEER_IBGP) {
13786 if (use_json) {
e2521429 13787 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13788 json_object_int_add(json_neigh,
13789 "externalBgpNbrMaxHopsAway",
13790 p->gtsm_hops);
c8d6f0d6 13791 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13792 json_object_int_add(json_neigh,
13793 "externalBgpNbrMaxHopsAway",
13794 p->ttl);
13795 } else {
e2521429 13796 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13797 vty_out(vty,
13798 " External BGP neighbor may be up to %d hops away.\n",
13799 p->gtsm_hops);
c8d6f0d6 13800 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13801 vty_out(vty,
13802 " External BGP neighbor may be up to %d hops away.\n",
13803 p->ttl);
13804 }
13805 } else {
e2521429 13806 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 13807 if (use_json)
13808 json_object_int_add(json_neigh,
13809 "internalBgpNbrMaxHopsAway",
13810 p->gtsm_hops);
13811 else
13812 vty_out(vty,
13813 " Internal BGP neighbor may be up to %d hops away.\n",
13814 p->gtsm_hops);
13815 }
13816 }
13817
13818 /* Local address. */
13819 if (p->su_local) {
13820 if (use_json) {
13821 json_object_string_add(json_neigh, "hostLocal",
13822 sockunion2str(p->su_local, buf1,
13823 SU_ADDRSTRLEN));
13824 json_object_int_add(json_neigh, "portLocal",
13825 ntohs(p->su_local->sin.sin_port));
13826 } else
13827 vty_out(vty, "Local host: %s, Local port: %d\n",
13828 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
13829 ntohs(p->su_local->sin.sin_port));
13830 }
13831
13832 /* Remote address. */
13833 if (p->su_remote) {
13834 if (use_json) {
13835 json_object_string_add(json_neigh, "hostForeign",
13836 sockunion2str(p->su_remote, buf1,
13837 SU_ADDRSTRLEN));
13838 json_object_int_add(json_neigh, "portForeign",
13839 ntohs(p->su_remote->sin.sin_port));
13840 } else
13841 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
13842 sockunion2str(p->su_remote, buf1,
13843 SU_ADDRSTRLEN),
13844 ntohs(p->su_remote->sin.sin_port));
13845 }
13846
13847 /* Nexthop display. */
13848 if (p->su_local) {
13849 if (use_json) {
c949c771
DA
13850 json_object_string_addf(json_neigh, "nexthop", "%pI4",
13851 &p->nexthop.v4);
13852 json_object_string_addf(json_neigh, "nexthopGlobal",
13853 "%pI6", &p->nexthop.v6_global);
13854 json_object_string_addf(json_neigh, "nexthopLocal",
13855 "%pI6", &p->nexthop.v6_local);
d62a17ae 13856 if (p->shared_network)
13857 json_object_string_add(json_neigh,
13858 "bgpConnection",
13859 "sharedNetwork");
13860 else
13861 json_object_string_add(json_neigh,
13862 "bgpConnection",
13863 "nonSharedNetwork");
13864 } else {
13865 vty_out(vty, "Nexthop: %s\n",
13866 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
13867 sizeof(buf1)));
13868 vty_out(vty, "Nexthop global: %s\n",
13869 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
13870 sizeof(buf1)));
13871 vty_out(vty, "Nexthop local: %s\n",
13872 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
13873 sizeof(buf1)));
13874 vty_out(vty, "BGP connection: %s\n",
13875 p->shared_network ? "shared network"
13876 : "non shared network");
13877 }
13878 }
13879
13880 /* Timer information. */
13881 if (use_json) {
13882 json_object_int_add(json_neigh, "connectRetryTimer",
13883 p->v_connect);
feb17238 13884 if (peer_established(p) && p->rtt)
d62a17ae 13885 json_object_int_add(json_neigh, "estimatedRttInMsecs",
13886 p->rtt);
13887 if (p->t_start)
13888 json_object_int_add(
13889 json_neigh, "nextStartTimerDueInMsecs",
13890 thread_timer_remain_second(p->t_start) * 1000);
13891 if (p->t_connect)
13892 json_object_int_add(
13893 json_neigh, "nextConnectTimerDueInMsecs",
13894 thread_timer_remain_second(p->t_connect)
13895 * 1000);
13896 if (p->t_routeadv) {
13897 json_object_int_add(json_neigh, "mraiInterval",
13898 p->v_routeadv);
13899 json_object_int_add(
13900 json_neigh, "mraiTimerExpireInMsecs",
13901 thread_timer_remain_second(p->t_routeadv)
13902 * 1000);
13903 }
13904 if (p->password)
13905 json_object_int_add(json_neigh, "authenticationEnabled",
13906 1);
13907
13908 if (p->t_read)
13909 json_object_string_add(json_neigh, "readThread", "on");
13910 else
13911 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
13912
13913 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 13914 json_object_string_add(json_neigh, "writeThread", "on");
13915 else
13916 json_object_string_add(json_neigh, "writeThread",
13917 "off");
13918 } else {
13919 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
13920 p->v_connect);
feb17238 13921 if (peer_established(p) && p->rtt)
d62a17ae 13922 vty_out(vty, "Estimated round trip time: %d ms\n",
13923 p->rtt);
13924 if (p->t_start)
13925 vty_out(vty, "Next start timer due in %ld seconds\n",
13926 thread_timer_remain_second(p->t_start));
13927 if (p->t_connect)
13928 vty_out(vty, "Next connect timer due in %ld seconds\n",
13929 thread_timer_remain_second(p->t_connect));
13930 if (p->t_routeadv)
13931 vty_out(vty,
13932 "MRAI (interval %u) timer expires in %ld seconds\n",
13933 p->v_routeadv,
13934 thread_timer_remain_second(p->t_routeadv));
13935 if (p->password)
13936 vty_out(vty, "Peer Authentication Enabled\n");
13937
cac9e917 13938 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
13939 p->t_read ? "on" : "off",
13940 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
13941 ? "on"
cac9e917 13942 : "off", p->fd);
d62a17ae 13943 }
13944
13945 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
13946 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
13947 bgp_capability_vty_out(vty, p, use_json, json_neigh);
13948
13949 if (!use_json)
13950 vty_out(vty, "\n");
13951
13952 /* BFD information. */
21bfce98
RZ
13953 if (p->bfd_config)
13954 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 13955
13956 if (use_json) {
13957 if (p->conf_if) /* Configured interface name. */
13958 json_object_object_add(json, p->conf_if, json_neigh);
13959 else /* Configured IP address. */
13960 json_object_object_add(json, p->host, json_neigh);
13961 }
13962}
13963
36235319
QY
13964static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
13965 enum show_type type,
13966 union sockunion *su,
13967 const char *conf_if, afi_t afi,
74a630b6 13968 bool use_json)
2986cac2 13969{
13970 struct listnode *node, *nnode;
13971 struct peer *peer;
13972 int find = 0;
13973 safi_t safi = SAFI_UNICAST;
74a630b6 13974 json_object *json = NULL;
2986cac2 13975 json_object *json_neighbor = NULL;
13976
74a630b6
NT
13977 if (use_json) {
13978 json = json_object_new_object();
13979 json_neighbor = json_object_new_object();
13980 }
13981
2986cac2 13982 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13983
13984 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13985 continue;
13986
13987 if ((peer->afc[afi][safi]) == 0)
13988 continue;
13989
2ba1fe69 13990 if (type == show_all) {
2986cac2 13991 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 13992 json_neighbor);
2986cac2 13993
74a630b6 13994 if (use_json) {
13909c4f
DS
13995 json_object_object_add(json, peer->host,
13996 json_neighbor);
74a630b6
NT
13997 json_neighbor = NULL;
13998 }
2986cac2 13999
2ba1fe69 14000 } else if (type == show_peer) {
2986cac2 14001 if (conf_if) {
14002 if ((peer->conf_if
13909c4f
DS
14003 && !strcmp(peer->conf_if, conf_if))
14004 || (peer->hostname
2986cac2 14005 && !strcmp(peer->hostname, conf_if))) {
14006 find = 1;
13909c4f
DS
14007 bgp_show_peer_gr_status(vty, peer,
14008 use_json,
14009 json_neighbor);
2986cac2 14010 }
14011 } else {
14012 if (sockunion_same(&peer->su, su)) {
14013 find = 1;
13909c4f
DS
14014 bgp_show_peer_gr_status(vty, peer,
14015 use_json,
14016 json_neighbor);
2986cac2 14017 }
14018 }
13909c4f
DS
14019 if (use_json && find)
14020 json_object_object_add(json, peer->host,
14021 json_neighbor);
2986cac2 14022 }
14023
74a630b6
NT
14024 if (find) {
14025 json_neighbor = NULL;
2986cac2 14026 break;
74a630b6 14027 }
2986cac2 14028 }
14029
14030 if (type == show_peer && !find) {
14031 if (use_json)
13909c4f 14032 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14033 else
14034 vty_out(vty, "%% No such neighbor\n");
14035 }
14036 if (use_json) {
74a630b6
NT
14037 if (json_neighbor)
14038 json_object_free(json_neighbor);
75eeda93 14039 vty_json(vty, json);
2986cac2 14040 } else {
14041 vty_out(vty, "\n");
14042 }
14043
14044 return CMD_SUCCESS;
14045}
14046
d62a17ae 14047static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14048 enum show_type type, union sockunion *su,
9f049418 14049 const char *conf_if, bool use_json,
d62a17ae 14050 json_object *json)
14051{
14052 struct listnode *node, *nnode;
14053 struct peer *peer;
14054 int find = 0;
9f049418 14055 bool nbr_output = false;
d1927ebe
AS
14056 afi_t afi = AFI_MAX;
14057 safi_t safi = SAFI_MAX;
14058
14059 if (type == show_ipv4_peer || type == show_ipv4_all) {
14060 afi = AFI_IP;
14061 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14062 afi = AFI_IP6;
14063 }
d62a17ae 14064
14065 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14066 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14067 continue;
14068
14069 switch (type) {
14070 case show_all:
14071 bgp_show_peer(vty, peer, use_json, json);
9f049418 14072 nbr_output = true;
d62a17ae 14073 break;
14074 case show_peer:
14075 if (conf_if) {
14076 if ((peer->conf_if
14077 && !strcmp(peer->conf_if, conf_if))
14078 || (peer->hostname
14079 && !strcmp(peer->hostname, conf_if))) {
14080 find = 1;
14081 bgp_show_peer(vty, peer, use_json,
14082 json);
14083 }
14084 } else {
14085 if (sockunion_same(&peer->su, su)) {
14086 find = 1;
14087 bgp_show_peer(vty, peer, use_json,
14088 json);
14089 }
14090 }
14091 break;
d1927ebe
AS
14092 case show_ipv4_peer:
14093 case show_ipv6_peer:
14094 FOREACH_SAFI (safi) {
14095 if (peer->afc[afi][safi]) {
14096 if (conf_if) {
14097 if ((peer->conf_if
14098 && !strcmp(peer->conf_if, conf_if))
14099 || (peer->hostname
14100 && !strcmp(peer->hostname, conf_if))) {
14101 find = 1;
14102 bgp_show_peer(vty, peer, use_json,
14103 json);
14104 break;
14105 }
14106 } else {
14107 if (sockunion_same(&peer->su, su)) {
14108 find = 1;
14109 bgp_show_peer(vty, peer, use_json,
14110 json);
14111 break;
14112 }
14113 }
14114 }
14115 }
14116 break;
14117 case show_ipv4_all:
14118 case show_ipv6_all:
14119 FOREACH_SAFI (safi) {
14120 if (peer->afc[afi][safi]) {
14121 bgp_show_peer(vty, peer, use_json, json);
14122 nbr_output = true;
14123 break;
14124 }
14125 }
14126 break;
d62a17ae 14127 }
14128 }
14129
d1927ebe
AS
14130 if ((type == show_peer || type == show_ipv4_peer ||
14131 type == show_ipv6_peer) && !find) {
d62a17ae 14132 if (use_json)
14133 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14134 else
88b7d255 14135 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14136 }
14137
d1927ebe
AS
14138 if (type != show_peer && type != show_ipv4_peer &&
14139 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14140 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14141
d62a17ae 14142 if (use_json) {
996c9314
LB
14143 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14144 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14145 } else {
14146 vty_out(vty, "\n");
14147 }
14148
14149 return CMD_SUCCESS;
14150}
14151
36235319
QY
14152static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14153 enum show_type type,
14154 const char *ip_str,
14155 afi_t afi, bool use_json)
2986cac2 14156{
14157
14158 int ret;
14159 struct bgp *bgp;
14160 union sockunion su;
2986cac2 14161
14162 bgp = bgp_get_default();
14163
13909c4f
DS
14164 if (!bgp)
14165 return;
2986cac2 14166
13909c4f
DS
14167 if (!use_json)
14168 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14169 NULL);
2986cac2 14170
13909c4f
DS
14171 if (ip_str) {
14172 ret = str2sockunion(ip_str, &su);
14173 if (ret < 0)
13909c4f 14174 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14175 vty, bgp, type, NULL, ip_str, afi, use_json);
14176 else
14177 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14178 NULL, afi, use_json);
13909c4f
DS
14179 } else
14180 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14181 afi, use_json);
2986cac2 14182}
14183
d62a17ae 14184static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14185 enum show_type type,
14186 const char *ip_str,
9f049418 14187 bool use_json)
d62a17ae 14188{
0291c246
MK
14189 struct listnode *node, *nnode;
14190 struct bgp *bgp;
71aedaa3 14191 union sockunion su;
0291c246 14192 json_object *json = NULL;
71aedaa3 14193 int ret, is_first = 1;
9f049418 14194 bool nbr_output = false;
d62a17ae 14195
14196 if (use_json)
14197 vty_out(vty, "{\n");
14198
14199 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14200 nbr_output = true;
d62a17ae 14201 if (use_json) {
14202 if (!(json = json_object_new_object())) {
af4c2728 14203 flog_err(
e50f7cfd 14204 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14205 "Unable to allocate memory for JSON object");
14206 vty_out(vty,
14207 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14208 return;
14209 }
14210
14211 json_object_int_add(json, "vrfId",
14212 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14213 ? -1
14214 : (int64_t)bgp->vrf_id);
d62a17ae 14215 json_object_string_add(
14216 json, "vrfName",
14217 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14218 ? VRF_DEFAULT_NAME
d62a17ae 14219 : bgp->name);
14220
14221 if (!is_first)
14222 vty_out(vty, ",\n");
14223 else
14224 is_first = 0;
14225
14226 vty_out(vty, "\"%s\":",
14227 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14228 ? VRF_DEFAULT_NAME
d62a17ae 14229 : bgp->name);
14230 } else {
14231 vty_out(vty, "\nInstance %s:\n",
14232 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14233 ? VRF_DEFAULT_NAME
d62a17ae 14234 : bgp->name);
14235 }
71aedaa3 14236
d1927ebe
AS
14237 if (type == show_peer || type == show_ipv4_peer ||
14238 type == show_ipv6_peer) {
71aedaa3
DS
14239 ret = str2sockunion(ip_str, &su);
14240 if (ret < 0)
14241 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14242 use_json, json);
14243 else
14244 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14245 use_json, json);
14246 } else {
d1927ebe 14247 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14248 use_json, json);
14249 }
b77004d6 14250 json_object_free(json);
121067e9 14251 json = NULL;
d62a17ae 14252 }
14253
3e78a6ce 14254 if (use_json)
d62a17ae 14255 vty_out(vty, "}\n");
9f049418
DS
14256 else if (!nbr_output)
14257 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14258}
14259
14260static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14261 enum show_type type, const char *ip_str,
9f049418 14262 bool use_json)
d62a17ae 14263{
14264 int ret;
14265 struct bgp *bgp;
14266 union sockunion su;
14267 json_object *json = NULL;
14268
14269 if (name) {
14270 if (strmatch(name, "all")) {
71aedaa3
DS
14271 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14272 use_json);
d62a17ae 14273 return CMD_SUCCESS;
14274 } else {
14275 bgp = bgp_lookup_by_name(name);
14276 if (!bgp) {
14277 if (use_json) {
14278 json = json_object_new_object();
75eeda93 14279 vty_json(vty, json);
d62a17ae 14280 } else
14281 vty_out(vty,
9f049418 14282 "%% BGP instance not found\n");
d62a17ae 14283
14284 return CMD_WARNING;
14285 }
14286 }
14287 } else {
14288 bgp = bgp_get_default();
14289 }
14290
14291 if (bgp) {
14292 json = json_object_new_object();
14293 if (ip_str) {
14294 ret = str2sockunion(ip_str, &su);
14295 if (ret < 0)
14296 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14297 use_json, json);
14298 else
14299 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14300 use_json, json);
14301 } else {
14302 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14303 json);
14304 }
14305 json_object_free(json);
ca61fd25
DS
14306 } else {
14307 if (use_json)
14308 vty_out(vty, "{}\n");
14309 else
14310 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14311 }
14312
14313 return CMD_SUCCESS;
4fb25c53
DW
14314}
14315
2986cac2 14316
14317
14318/* "show [ip] bgp neighbors graceful-restart" commands. */
14319DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14320 show_ip_bgp_neighbors_graceful_restart_cmd,
14321 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14322 SHOW_STR
14323 BGP_STR
14324 IP_STR
14325 IPV6_STR
14326 NEIGHBOR_STR
14327 "Neighbor to display information about\n"
14328 "Neighbor to display information about\n"
14329 "Neighbor on BGP configured interface\n"
14330 GR_SHOW
14331 JSON_STR)
14332{
14333 char *sh_arg = NULL;
14334 enum show_type sh_type;
14335 int idx = 0;
14336 afi_t afi = AFI_MAX;
2986cac2 14337 bool uj = use_json(argc, argv);
14338
36235319 14339 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 14340 afi = AFI_MAX;
14341
14342 idx++;
14343
14344 if (argv_find(argv, argc, "A.B.C.D", &idx)
14345 || argv_find(argv, argc, "X:X::X:X", &idx)
14346 || argv_find(argv, argc, "WORD", &idx)) {
14347 sh_type = show_peer;
14348 sh_arg = argv[idx]->arg;
14349 } else
14350 sh_type = show_all;
14351
14352 if (!argv_find(argv, argc, "graceful-restart", &idx))
14353 return CMD_SUCCESS;
14354
14355
36235319
QY
14356 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14357 afi, uj);
2986cac2 14358}
14359
716b2d8a 14360/* "show [ip] bgp neighbors" commands. */
718e3744 14361DEFUN (show_ip_bgp_neighbors,
14362 show_ip_bgp_neighbors_cmd,
24345e82 14363 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 14364 SHOW_STR
14365 IP_STR
14366 BGP_STR
f2a8972b 14367 BGP_INSTANCE_HELP_STR
8c3deaae
QY
14368 "Address Family\n"
14369 "Address Family\n"
718e3744 14370 "Detailed information on TCP and BGP neighbor connections\n"
14371 "Neighbor to display information about\n"
a80beece 14372 "Neighbor to display information about\n"
91d37724 14373 "Neighbor on BGP configured interface\n"
9973d184 14374 JSON_STR)
718e3744 14375{
d62a17ae 14376 char *vrf = NULL;
14377 char *sh_arg = NULL;
14378 enum show_type sh_type;
d1927ebe 14379 afi_t afi = AFI_MAX;
718e3744 14380
9f049418 14381 bool uj = use_json(argc, argv);
718e3744 14382
d62a17ae 14383 int idx = 0;
718e3744 14384
9a8bdf1c
PG
14385 /* [<vrf> VIEWVRFNAME] */
14386 if (argv_find(argv, argc, "vrf", &idx)) {
14387 vrf = argv[idx + 1]->arg;
14388 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14389 vrf = NULL;
14390 } else if (argv_find(argv, argc, "view", &idx))
14391 /* [<view> VIEWVRFNAME] */
d62a17ae 14392 vrf = argv[idx + 1]->arg;
718e3744 14393
d62a17ae 14394 idx++;
d1927ebe
AS
14395
14396 if (argv_find(argv, argc, "ipv4", &idx)) {
14397 sh_type = show_ipv4_all;
14398 afi = AFI_IP;
14399 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14400 sh_type = show_ipv6_all;
14401 afi = AFI_IP6;
14402 } else {
14403 sh_type = show_all;
14404 }
14405
d62a17ae 14406 if (argv_find(argv, argc, "A.B.C.D", &idx)
14407 || argv_find(argv, argc, "X:X::X:X", &idx)
14408 || argv_find(argv, argc, "WORD", &idx)) {
14409 sh_type = show_peer;
14410 sh_arg = argv[idx]->arg;
d1927ebe
AS
14411 }
14412
14413 if (sh_type == show_peer && afi == AFI_IP) {
14414 sh_type = show_ipv4_peer;
14415 } else if (sh_type == show_peer && afi == AFI_IP6) {
14416 sh_type = show_ipv6_peer;
14417 }
856ca177 14418
d62a17ae 14419 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 14420}
14421
716b2d8a 14422/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 14423 paths' and `show ip mbgp paths'. Those functions results are the
14424 same.*/
f412b39a 14425DEFUN (show_ip_bgp_paths,
718e3744 14426 show_ip_bgp_paths_cmd,
46f296b4 14427 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 14428 SHOW_STR
14429 IP_STR
14430 BGP_STR
46f296b4 14431 BGP_SAFI_HELP_STR
718e3744 14432 "Path information\n")
14433{
d62a17ae 14434 vty_out(vty, "Address Refcnt Path\n");
14435 aspath_print_all_vty(vty);
14436 return CMD_SUCCESS;
718e3744 14437}
14438
718e3744 14439#include "hash.h"
14440
e3b78da8 14441static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14442 struct vty *vty)
718e3744 14443{
d62a17ae 14444 struct community *com;
718e3744 14445
e3b78da8 14446 com = (struct community *)bucket->data;
3f65c5b1 14447 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 14448 community_str(com, false));
718e3744 14449}
14450
14451/* Show BGP's community internal data. */
f412b39a 14452DEFUN (show_ip_bgp_community_info,
718e3744 14453 show_ip_bgp_community_info_cmd,
bec37ba5 14454 "show [ip] bgp community-info",
718e3744 14455 SHOW_STR
14456 IP_STR
14457 BGP_STR
14458 "List all bgp community information\n")
14459{
d62a17ae 14460 vty_out(vty, "Address Refcnt Community\n");
718e3744 14461
d62a17ae 14462 hash_iterate(community_hash(),
e3b78da8 14463 (void (*)(struct hash_bucket *,
d62a17ae 14464 void *))community_show_all_iterator,
14465 vty);
718e3744 14466
d62a17ae 14467 return CMD_SUCCESS;
718e3744 14468}
14469
e3b78da8 14470static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14471 struct vty *vty)
57d187bc 14472{
d62a17ae 14473 struct lcommunity *lcom;
57d187bc 14474
e3b78da8 14475 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 14476 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 14477 lcommunity_str(lcom, false));
57d187bc
JS
14478}
14479
14480/* Show BGP's community internal data. */
14481DEFUN (show_ip_bgp_lcommunity_info,
14482 show_ip_bgp_lcommunity_info_cmd,
14483 "show ip bgp large-community-info",
14484 SHOW_STR
14485 IP_STR
14486 BGP_STR
14487 "List all bgp large-community information\n")
14488{
d62a17ae 14489 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 14490
d62a17ae 14491 hash_iterate(lcommunity_hash(),
e3b78da8 14492 (void (*)(struct hash_bucket *,
d62a17ae 14493 void *))lcommunity_show_all_iterator,
14494 vty);
57d187bc 14495
d62a17ae 14496 return CMD_SUCCESS;
57d187bc 14497}
2986cac2 14498/* Graceful Restart */
14499
14500static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
14501 struct bgp *bgp,
14502 bool use_json,
14503 json_object *json)
2986cac2 14504{
57d187bc
JS
14505
14506
2986cac2 14507 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14508
7318ae88 14509 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 14510
14511 switch (bgp_global_gr_mode) {
14512
14513 case GLOBAL_HELPER:
13909c4f 14514 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 14515 break;
14516
14517 case GLOBAL_GR:
13909c4f 14518 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 14519 break;
14520
14521 case GLOBAL_DISABLE:
13909c4f 14522 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 14523 break;
14524
14525 case GLOBAL_INVALID:
2986cac2 14526 vty_out(vty,
2ba1fe69 14527 "Global BGP GR Mode Invalid\n");
2986cac2 14528 break;
14529 }
14530 vty_out(vty, "\n");
14531}
14532
36235319
QY
14533static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14534 enum show_type type,
14535 const char *ip_str,
14536 afi_t afi, bool use_json)
2986cac2 14537{
14538 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14539 afi = AFI_IP;
14540
14541 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14542
36235319
QY
14543 bgp_show_neighbor_graceful_restart_vty(
14544 vty, type, ip_str, afi, use_json);
2986cac2 14545 afi++;
14546 }
14547 } else if (afi != AFI_MAX) {
36235319
QY
14548 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14549 use_json);
2986cac2 14550 } else {
14551 return CMD_ERR_INCOMPLETE;
14552 }
14553
14554 return CMD_SUCCESS;
14555}
14556/* Graceful Restart */
14557
f412b39a 14558DEFUN (show_ip_bgp_attr_info,
718e3744 14559 show_ip_bgp_attr_info_cmd,
bec37ba5 14560 "show [ip] bgp attribute-info",
718e3744 14561 SHOW_STR
14562 IP_STR
14563 BGP_STR
14564 "List all bgp attribute information\n")
14565{
d62a17ae 14566 attr_show_all(vty);
14567 return CMD_SUCCESS;
718e3744 14568}
6b0655a2 14569
03915806
CS
14570static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14571 afi_t afi, safi_t safi,
14572 bool use_json, json_object *json)
53089bec 14573{
14574 struct bgp *bgp;
14575 struct listnode *node;
14576 char *vname;
14577 char buf1[INET6_ADDRSTRLEN];
14578 char *ecom_str;
14579 vpn_policy_direction_t dir;
14580
03915806 14581 if (json) {
b46dfd20
DS
14582 json_object *json_import_vrfs = NULL;
14583 json_object *json_export_vrfs = NULL;
14584
b46dfd20
DS
14585 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14586
53089bec 14587 if (!bgp) {
75eeda93 14588 vty_json(vty, json);
b46dfd20 14589
53089bec 14590 return CMD_WARNING;
14591 }
b46dfd20 14592
94d4c685
DS
14593 /* Provide context for the block */
14594 json_object_string_add(json, "vrf", name ? name : "default");
14595 json_object_string_add(json, "afiSafi",
5cb5f4d0 14596 get_afi_safi_str(afi, safi, true));
94d4c685 14597
b46dfd20
DS
14598 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14599 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14600 json_object_string_add(json, "importFromVrfs", "none");
14601 json_object_string_add(json, "importRts", "none");
14602 } else {
6ce24e52
DS
14603 json_import_vrfs = json_object_new_array();
14604
b46dfd20
DS
14605 for (ALL_LIST_ELEMENTS_RO(
14606 bgp->vpn_policy[afi].import_vrf,
14607 node, vname))
14608 json_object_array_add(json_import_vrfs,
14609 json_object_new_string(vname));
14610
b20875ea
CS
14611 json_object_object_add(json, "importFromVrfs",
14612 json_import_vrfs);
b46dfd20 14613 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14614 if (bgp->vpn_policy[afi].rtlist[dir]) {
14615 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14616 bgp->vpn_policy[afi].rtlist[dir],
14617 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14618 json_object_string_add(json, "importRts",
14619 ecom_str);
14620 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14621 } else
14622 json_object_string_add(json, "importRts",
14623 "none");
b46dfd20
DS
14624 }
14625
14626 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14627 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14628 json_object_string_add(json, "exportToVrfs", "none");
14629 json_object_string_add(json, "routeDistinguisher",
14630 "none");
14631 json_object_string_add(json, "exportRts", "none");
14632 } else {
6ce24e52
DS
14633 json_export_vrfs = json_object_new_array();
14634
b46dfd20
DS
14635 for (ALL_LIST_ELEMENTS_RO(
14636 bgp->vpn_policy[afi].export_vrf,
14637 node, vname))
14638 json_object_array_add(json_export_vrfs,
14639 json_object_new_string(vname));
14640 json_object_object_add(json, "exportToVrfs",
14641 json_export_vrfs);
14642 json_object_string_add(json, "routeDistinguisher",
14643 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14644 buf1, RD_ADDRSTRLEN));
14645
14646 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14647 if (bgp->vpn_policy[afi].rtlist[dir]) {
14648 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14649 bgp->vpn_policy[afi].rtlist[dir],
14650 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14651 json_object_string_add(json, "exportRts",
14652 ecom_str);
14653 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14654 } else
14655 json_object_string_add(json, "exportRts",
14656 "none");
b46dfd20
DS
14657 }
14658
03915806 14659 if (use_json) {
75eeda93 14660 vty_json(vty, json);
03915806 14661 }
53089bec 14662 } else {
b46dfd20
DS
14663 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14664
53089bec 14665 if (!bgp) {
b46dfd20 14666 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 14667 return CMD_WARNING;
14668 }
53089bec 14669
b46dfd20
DS
14670 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14671 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14672 vty_out(vty,
14673 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 14674 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14675 else {
14676 vty_out(vty,
14677 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 14678 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14679
14680 for (ALL_LIST_ELEMENTS_RO(
14681 bgp->vpn_policy[afi].import_vrf,
14682 node, vname))
14683 vty_out(vty, " %s\n", vname);
14684
14685 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14686 ecom_str = NULL;
14687 if (bgp->vpn_policy[afi].rtlist[dir]) {
14688 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14689 bgp->vpn_policy[afi].rtlist[dir],
14690 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 14691 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 14692
b20875ea
CS
14693 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14694 } else
14695 vty_out(vty, "Import RT(s):\n");
53089bec 14696 }
53089bec 14697
b46dfd20
DS
14698 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14699 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14700 vty_out(vty,
14701 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 14702 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14703 else {
14704 vty_out(vty,
04c9077f 14705 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 14706 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14707
14708 for (ALL_LIST_ELEMENTS_RO(
14709 bgp->vpn_policy[afi].export_vrf,
14710 node, vname))
14711 vty_out(vty, " %s\n", vname);
14712
14713 vty_out(vty, "RD: %s\n",
14714 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14715 buf1, RD_ADDRSTRLEN));
14716
14717 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14718 if (bgp->vpn_policy[afi].rtlist[dir]) {
14719 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14720 bgp->vpn_policy[afi].rtlist[dir],
14721 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14722 vty_out(vty, "Export RT: %s\n", ecom_str);
14723 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14724 } else
14725 vty_out(vty, "Import RT(s):\n");
53089bec 14726 }
53089bec 14727 }
14728
14729 return CMD_SUCCESS;
14730}
14731
03915806
CS
14732static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14733 safi_t safi, bool use_json)
14734{
14735 struct listnode *node, *nnode;
14736 struct bgp *bgp;
14737 char *vrf_name = NULL;
14738 json_object *json = NULL;
14739 json_object *json_vrf = NULL;
14740 json_object *json_vrfs = NULL;
14741
14742 if (use_json) {
14743 json = json_object_new_object();
14744 json_vrfs = json_object_new_object();
14745 }
14746
14747 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14748
14749 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14750 vrf_name = bgp->name;
14751
14752 if (use_json) {
14753 json_vrf = json_object_new_object();
14754 } else {
14755 vty_out(vty, "\nInstance %s:\n",
14756 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14757 ? VRF_DEFAULT_NAME : bgp->name);
14758 }
14759 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14760 if (use_json) {
14761 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14762 json_object_object_add(json_vrfs,
14763 VRF_DEFAULT_NAME, json_vrf);
14764 else
14765 json_object_object_add(json_vrfs, vrf_name,
14766 json_vrf);
14767 }
14768 }
14769
14770 if (use_json) {
14771 json_object_object_add(json, "vrfs", json_vrfs);
75eeda93 14772 vty_json(vty, json);
03915806
CS
14773 }
14774
14775 return CMD_SUCCESS;
14776}
14777
53089bec 14778/* "show [ip] bgp route-leak" command. */
14779DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
14780 show_ip_bgp_route_leak_cmd,
14781 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
14782 SHOW_STR
14783 IP_STR
14784 BGP_STR
14785 BGP_INSTANCE_HELP_STR
14786 BGP_AFI_HELP_STR
14787 BGP_SAFI_HELP_STR
14788 "Route leaking information\n"
14789 JSON_STR)
53089bec 14790{
14791 char *vrf = NULL;
14792 afi_t afi = AFI_MAX;
14793 safi_t safi = SAFI_MAX;
14794
9f049418 14795 bool uj = use_json(argc, argv);
53089bec 14796 int idx = 0;
03915806 14797 json_object *json = NULL;
53089bec 14798
14799 /* show [ip] bgp */
14800 if (argv_find(argv, argc, "ip", &idx)) {
14801 afi = AFI_IP;
14802 safi = SAFI_UNICAST;
14803 }
14804 /* [vrf VIEWVRFNAME] */
14805 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
14806 vty_out(vty,
14807 "%% This command is not applicable to BGP views\n");
53089bec 14808 return CMD_WARNING;
14809 }
14810
9a8bdf1c
PG
14811 if (argv_find(argv, argc, "vrf", &idx)) {
14812 vrf = argv[idx + 1]->arg;
14813 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14814 vrf = NULL;
14815 }
53089bec 14816 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
c48349e3 14817 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
53089bec 14818 argv_find_and_parse_safi(argv, argc, &idx, &safi);
53089bec 14819
14820 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
14821 vty_out(vty,
14822 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 14823 return CMD_WARNING;
14824 }
14825
03915806
CS
14826 if (vrf && strmatch(vrf, "all"))
14827 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
14828
14829 if (uj)
14830 json = json_object_new_object();
14831
14832 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 14833}
14834
d62a17ae 14835static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
14836 safi_t safi)
f186de26 14837{
d62a17ae 14838 struct listnode *node, *nnode;
14839 struct bgp *bgp;
f186de26 14840
d62a17ae 14841 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14842 vty_out(vty, "\nInstance %s:\n",
14843 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14844 ? VRF_DEFAULT_NAME
d62a17ae 14845 : bgp->name);
14846 update_group_show(bgp, afi, safi, vty, 0);
14847 }
f186de26 14848}
14849
d62a17ae 14850static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
14851 int safi, uint64_t subgrp_id)
4fb25c53 14852{
d62a17ae 14853 struct bgp *bgp;
4fb25c53 14854
d62a17ae 14855 if (name) {
14856 if (strmatch(name, "all")) {
14857 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
14858 return CMD_SUCCESS;
14859 } else {
14860 bgp = bgp_lookup_by_name(name);
14861 }
14862 } else {
14863 bgp = bgp_get_default();
14864 }
4fb25c53 14865
d62a17ae 14866 if (bgp)
14867 update_group_show(bgp, afi, safi, vty, subgrp_id);
14868 return CMD_SUCCESS;
4fb25c53
DW
14869}
14870
8fe8a7f6
DS
14871DEFUN (show_ip_bgp_updgrps,
14872 show_ip_bgp_updgrps_cmd,
c1a44e43 14873 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 14874 SHOW_STR
14875 IP_STR
14876 BGP_STR
14877 BGP_INSTANCE_HELP_STR
c9e571b4 14878 BGP_AFI_HELP_STR
9bedbb1e 14879 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
14880 "Detailed info about dynamic update groups\n"
14881 "Specific subgroup to display detailed info for\n")
8386ac43 14882{
d62a17ae 14883 char *vrf = NULL;
14884 afi_t afi = AFI_IP6;
14885 safi_t safi = SAFI_UNICAST;
14886 uint64_t subgrp_id = 0;
14887
14888 int idx = 0;
14889
14890 /* show [ip] bgp */
14891 if (argv_find(argv, argc, "ip", &idx))
14892 afi = AFI_IP;
9a8bdf1c
PG
14893 /* [<vrf> VIEWVRFNAME] */
14894 if (argv_find(argv, argc, "vrf", &idx)) {
14895 vrf = argv[idx + 1]->arg;
14896 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14897 vrf = NULL;
14898 } else if (argv_find(argv, argc, "view", &idx))
14899 /* [<view> VIEWVRFNAME] */
14900 vrf = argv[idx + 1]->arg;
d62a17ae 14901 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14902 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14903 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14904 }
5bf15956 14905
d62a17ae 14906 /* get subgroup id, if provided */
14907 idx = argc - 1;
14908 if (argv[idx]->type == VARIABLE_TKN)
14909 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 14910
d62a17ae 14911 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
14912}
14913
f186de26 14914DEFUN (show_bgp_instance_all_ipv6_updgrps,
14915 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 14916 "show [ip] bgp <view|vrf> all update-groups",
f186de26 14917 SHOW_STR
716b2d8a 14918 IP_STR
f186de26 14919 BGP_STR
14920 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 14921 "Detailed info about dynamic update groups\n")
f186de26 14922{
d62a17ae 14923 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
14924 return CMD_SUCCESS;
f186de26 14925}
14926
43d3f4fc
DS
14927DEFUN (show_bgp_l2vpn_evpn_updgrps,
14928 show_bgp_l2vpn_evpn_updgrps_cmd,
14929 "show [ip] bgp l2vpn evpn update-groups",
14930 SHOW_STR
14931 IP_STR
14932 BGP_STR
14933 "l2vpn address family\n"
14934 "evpn sub-address family\n"
14935 "Detailed info about dynamic update groups\n")
14936{
14937 char *vrf = NULL;
14938 uint64_t subgrp_id = 0;
14939
14940 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
14941 return CMD_SUCCESS;
14942}
14943
5bf15956
DW
14944DEFUN (show_bgp_updgrps_stats,
14945 show_bgp_updgrps_stats_cmd,
716b2d8a 14946 "show [ip] bgp update-groups statistics",
3f9c7369 14947 SHOW_STR
716b2d8a 14948 IP_STR
3f9c7369 14949 BGP_STR
0c7b1b01 14950 "Detailed info about dynamic update groups\n"
3f9c7369
DS
14951 "Statistics\n")
14952{
d62a17ae 14953 struct bgp *bgp;
3f9c7369 14954
d62a17ae 14955 bgp = bgp_get_default();
14956 if (bgp)
14957 update_group_show_stats(bgp, vty);
3f9c7369 14958
d62a17ae 14959 return CMD_SUCCESS;
3f9c7369
DS
14960}
14961
8386ac43 14962DEFUN (show_bgp_instance_updgrps_stats,
14963 show_bgp_instance_updgrps_stats_cmd,
18c57037 14964 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 14965 SHOW_STR
716b2d8a 14966 IP_STR
8386ac43 14967 BGP_STR
14968 BGP_INSTANCE_HELP_STR
0c7b1b01 14969 "Detailed info about dynamic update groups\n"
8386ac43 14970 "Statistics\n")
14971{
d62a17ae 14972 int idx_word = 3;
14973 struct bgp *bgp;
8386ac43 14974
d62a17ae 14975 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
14976 if (bgp)
14977 update_group_show_stats(bgp, vty);
8386ac43 14978
d62a17ae 14979 return CMD_SUCCESS;
8386ac43 14980}
14981
d62a17ae 14982static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
14983 afi_t afi, safi_t safi,
14984 const char *what, uint64_t subgrp_id)
3f9c7369 14985{
d62a17ae 14986 struct bgp *bgp;
8386ac43 14987
d62a17ae 14988 if (name)
14989 bgp = bgp_lookup_by_name(name);
14990 else
14991 bgp = bgp_get_default();
8386ac43 14992
d62a17ae 14993 if (bgp) {
14994 if (!strcmp(what, "advertise-queue"))
14995 update_group_show_adj_queue(bgp, afi, safi, vty,
14996 subgrp_id);
14997 else if (!strcmp(what, "advertised-routes"))
14998 update_group_show_advertised(bgp, afi, safi, vty,
14999 subgrp_id);
15000 else if (!strcmp(what, "packet-queue"))
15001 update_group_show_packet_queue(bgp, afi, safi, vty,
15002 subgrp_id);
15003 }
3f9c7369
DS
15004}
15005
dc64bdec
QY
15006DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15007 show_ip_bgp_instance_updgrps_adj_s_cmd,
15008 "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",
15009 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15010 BGP_SAFI_HELP_STR
15011 "Detailed info about dynamic update groups\n"
15012 "Specific subgroup to display info for\n"
15013 "Advertisement queue\n"
15014 "Announced routes\n"
15015 "Packet queue\n")
3f9c7369 15016{
dc64bdec
QY
15017 uint64_t subgrp_id = 0;
15018 afi_t afiz;
15019 safi_t safiz;
15020 if (sgid)
15021 subgrp_id = strtoull(sgid, NULL, 10);
15022
15023 if (!ip && !afi)
15024 afiz = AFI_IP6;
15025 if (!ip && afi)
15026 afiz = bgp_vty_afi_from_str(afi);
15027 if (ip && !afi)
15028 afiz = AFI_IP;
15029 if (ip && afi) {
15030 afiz = bgp_vty_afi_from_str(afi);
15031 if (afiz != AFI_IP)
15032 vty_out(vty,
15033 "%% Cannot specify both 'ip' and 'ipv6'\n");
15034 return CMD_WARNING;
15035 }
d62a17ae 15036
dc64bdec 15037 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15038
dc64bdec 15039 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15040 return CMD_SUCCESS;
15041}
15042
6f4eacf3
DA
15043static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15044 json_object *json)
d62a17ae 15045{
15046 struct listnode *node, *nnode;
15047 struct prefix *range;
15048 struct peer *conf;
15049 struct peer *peer;
d62a17ae 15050 afi_t afi;
15051 safi_t safi;
15052 const char *peer_status;
d62a17ae 15053 int lr_count;
15054 int dynamic;
6f4eacf3
DA
15055 bool af_cfgd;
15056 json_object *json_peer_group = NULL;
15057 json_object *json_peer_group_afc = NULL;
15058 json_object *json_peer_group_members = NULL;
15059 json_object *json_peer_group_dynamic = NULL;
15060 json_object *json_peer_group_dynamic_af = NULL;
15061 json_object *json_peer_group_ranges = NULL;
d62a17ae 15062
15063 conf = group->conf;
15064
6f4eacf3
DA
15065 if (json) {
15066 json_peer_group = json_object_new_object();
15067 json_peer_group_afc = json_object_new_array();
15068 }
15069
d62a17ae 15070 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3
DA
15071 if (json)
15072 json_object_int_add(json_peer_group, "remoteAs",
15073 conf->as);
15074 else
15075 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15076 group->name, conf->as);
d62a17ae 15077 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3
DA
15078 if (json)
15079 json_object_int_add(json_peer_group, "remoteAs",
15080 group->bgp->as);
15081 else
15082 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15083 group->name, group->bgp->as);
d62a17ae 15084 } else {
6f4eacf3
DA
15085 if (!json)
15086 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 15087 }
f14e6fdb 15088
6f4eacf3
DA
15089 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15090 if (json)
15091 json_object_string_add(json_peer_group, "type",
15092 "internal");
15093 else
15094 vty_out(vty, " Peer-group type is internal\n");
15095 } else {
15096 if (json)
15097 json_object_string_add(json_peer_group, "type",
15098 "external");
15099 else
15100 vty_out(vty, " Peer-group type is external\n");
15101 }
d62a17ae 15102
15103 /* Display AFs configured. */
6f4eacf3
DA
15104 if (!json)
15105 vty_out(vty, " Configured address-families:");
15106
05c7a1cc
QY
15107 FOREACH_AFI_SAFI (afi, safi) {
15108 if (conf->afc[afi][safi]) {
6f4eacf3
DA
15109 af_cfgd = true;
15110 if (json)
15111 json_object_array_add(
15112 json_peer_group_afc,
15113 json_object_new_string(get_afi_safi_str(
15114 afi, safi, false)));
15115 else
15116 vty_out(vty, " %s;",
15117 get_afi_safi_str(afi, safi, false));
d62a17ae 15118 }
05c7a1cc 15119 }
6f4eacf3
DA
15120
15121 if (json) {
15122 json_object_object_add(json_peer_group,
15123 "addressFamiliesConfigured",
15124 json_peer_group_afc);
15125 } else {
15126 if (!af_cfgd)
15127 vty_out(vty, " none\n");
15128 else
15129 vty_out(vty, "\n");
15130 }
d62a17ae 15131
15132 /* Display listen ranges (for dynamic neighbors), if any */
15133 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 15134 lr_count = listcount(group->listen_range[afi]);
15135 if (lr_count) {
6f4eacf3
DA
15136 if (json) {
15137 if (!json_peer_group_dynamic)
15138 json_peer_group_dynamic =
15139 json_object_new_object();
15140
15141 json_peer_group_dynamic_af =
15142 json_object_new_object();
15143 json_peer_group_ranges =
15144 json_object_new_array();
15145 json_object_int_add(json_peer_group_dynamic_af,
15146 "count", lr_count);
15147 } else {
15148 vty_out(vty, " %d %s listen range(s)\n",
15149 lr_count, afi2str(afi));
15150 }
d62a17ae 15151
15152 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
15153 nnode, range)) {
15154 if (json) {
15155 char buf[BUFSIZ];
15156
15157 snprintfrr(buf, sizeof(buf), "%pFX",
15158 range);
15159
15160 json_object_array_add(
15161 json_peer_group_ranges,
15162 json_object_new_string(buf));
15163 } else {
15164 vty_out(vty, " %pFX\n", range);
15165 }
15166 }
15167
15168 if (json) {
15169 json_object_object_add(
15170 json_peer_group_dynamic_af, "ranges",
15171 json_peer_group_ranges);
15172
15173 json_object_object_add(
15174 json_peer_group_dynamic, afi2str(afi),
15175 json_peer_group_dynamic_af);
15176 }
d62a17ae 15177 }
15178 }
f14e6fdb 15179
6f4eacf3
DA
15180 if (json_peer_group_dynamic)
15181 json_object_object_add(json_peer_group, "dynamicRanges",
15182 json_peer_group_dynamic);
15183
d62a17ae 15184 /* Display group members and their status */
15185 if (listcount(group->peer)) {
6f4eacf3
DA
15186 if (json)
15187 json_peer_group_members = json_object_new_object();
15188 else
15189 vty_out(vty, " Peer-group members:\n");
d62a17ae 15190 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15191 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15192 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15193 peer_status = "Idle (Admin)";
15194 else if (CHECK_FLAG(peer->sflags,
15195 PEER_STATUS_PREFIX_OVERFLOW))
15196 peer_status = "Idle (PfxCt)";
15197 else
15198 peer_status = lookup_msg(bgp_status_msg,
15199 peer->status, NULL);
15200
15201 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
15202
15203 if (json) {
15204 json_object *json_peer_group_member =
15205 json_object_new_object();
15206
15207 json_object_string_add(json_peer_group_member,
15208 "status", peer_status);
15209
15210 if (dynamic)
15211 json_object_boolean_true_add(
15212 json_peer_group_member,
15213 "dynamic");
15214
15215 json_object_object_add(json_peer_group_members,
15216 peer->host,
15217 json_peer_group_member);
15218 } else {
15219 vty_out(vty, " %s %s %s \n", peer->host,
15220 dynamic ? "(dynamic)" : "",
15221 peer_status);
15222 }
d62a17ae 15223 }
6f4eacf3
DA
15224 if (json)
15225 json_object_object_add(json_peer_group, "members",
15226 json_peer_group_members);
d62a17ae 15227 }
f14e6fdb 15228
6f4eacf3
DA
15229 if (json)
15230 json_object_object_add(json, group->name, json_peer_group);
15231
d62a17ae 15232 return CMD_SUCCESS;
15233}
15234
ff9959b0 15235static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 15236 const char *group_name, bool uj)
d62a17ae 15237{
ff9959b0 15238 struct bgp *bgp;
d62a17ae 15239 struct listnode *node, *nnode;
15240 struct peer_group *group;
ff9959b0 15241 bool found = false;
6f4eacf3
DA
15242 json_object *json = NULL;
15243
15244 if (uj)
15245 json = json_object_new_object();
ff9959b0
QY
15246
15247 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15248
15249 if (!bgp) {
c48349e3 15250 if (uj)
75eeda93 15251 vty_json(vty, json);
c48349e3 15252 else
6f4eacf3 15253 vty_out(vty, "%% BGP instance not found\n");
6f4eacf3 15254
ff9959b0
QY
15255 return CMD_WARNING;
15256 }
d62a17ae 15257
15258 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15259 if (group_name) {
15260 if (strmatch(group->name, group_name)) {
6f4eacf3 15261 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
15262 found = true;
15263 break;
d62a17ae 15264 }
ff9959b0 15265 } else {
6f4eacf3 15266 bgp_show_one_peer_group(vty, group, json);
d62a17ae 15267 }
f14e6fdb 15268 }
f14e6fdb 15269
6f4eacf3 15270 if (group_name && !found && !uj)
d62a17ae 15271 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15272
c48349e3 15273 if (uj)
75eeda93 15274 vty_json(vty, json);
6f4eacf3 15275
d62a17ae 15276 return CMD_SUCCESS;
f14e6fdb
DS
15277}
15278
6f4eacf3
DA
15279DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15280 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15281 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15282 "Detailed information on BGP peer groups\n"
15283 "Peer group name\n" JSON_STR)
f14e6fdb 15284{
d62a17ae 15285 char *vrf, *pg;
d62a17ae 15286 int idx = 0;
6f4eacf3 15287 bool uj = use_json(argc, argv);
f14e6fdb 15288
a4d82a8a
PZ
15289 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15290 : NULL;
d62a17ae 15291 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15292
6f4eacf3 15293 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 15294}
3f9c7369 15295
d6e3c605 15296
718e3744 15297/* Redistribute VTY commands. */
15298
585f1adc
IR
15299DEFUN (bgp_redistribute_ipv4,
15300 bgp_redistribute_ipv4_cmd,
15301 "redistribute " FRR_IP_REDIST_STR_BGPD,
15302 "Redistribute information from another routing protocol\n"
15303 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 15304{
585f1adc 15305 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15306 int idx_protocol = 1;
585f1adc 15307 int type;
37a87b8f 15308
585f1adc
IR
15309 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15310 if (type < 0) {
15311 vty_out(vty, "%% Invalid route type\n");
15312 return CMD_WARNING_CONFIG_FAILED;
15313 }
7f323236 15314
585f1adc
IR
15315 bgp_redist_add(bgp, AFI_IP, type, 0);
15316 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 15317}
15318
d62a17ae 15319ALIAS_HIDDEN(
15320 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15321 "redistribute " FRR_IP_REDIST_STR_BGPD,
15322 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 15323
585f1adc
IR
15324DEFUN (bgp_redistribute_ipv4_rmap,
15325 bgp_redistribute_ipv4_rmap_cmd,
15326 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15327 "Redistribute information from another routing protocol\n"
15328 FRR_IP_REDIST_HELP_STR_BGPD
15329 "Route map reference\n"
15330 "Pointer to route-map entries\n")
718e3744 15331{
585f1adc 15332 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15333 int idx_protocol = 1;
15334 int idx_word = 3;
585f1adc
IR
15335 int type;
15336 struct bgp_redist *red;
15337 bool changed;
15338 struct route_map *route_map = route_map_lookup_warn_noexist(
15339 vty, argv[idx_word]->arg);
15340
15341 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15342 if (type < 0) {
15343 vty_out(vty, "%% Invalid route type\n");
15344 return CMD_WARNING_CONFIG_FAILED;
15345 }
37a87b8f 15346
585f1adc
IR
15347 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15348 changed =
15349 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15350 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 15351}
15352
d62a17ae 15353ALIAS_HIDDEN(
15354 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15355 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15356 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15357 "Route map reference\n"
15358 "Pointer to route-map entries\n")
596c17ba 15359
585f1adc
IR
15360DEFUN (bgp_redistribute_ipv4_metric,
15361 bgp_redistribute_ipv4_metric_cmd,
15362 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15363 "Redistribute information from another routing protocol\n"
15364 FRR_IP_REDIST_HELP_STR_BGPD
15365 "Metric for redistributed routes\n"
15366 "Default metric\n")
718e3744 15367{
585f1adc 15368 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15369 int idx_protocol = 1;
15370 int idx_number = 3;
585f1adc
IR
15371 int type;
15372 uint32_t metric;
15373 struct bgp_redist *red;
15374 bool changed;
15375
15376 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15377 if (type < 0) {
15378 vty_out(vty, "%% Invalid route type\n");
15379 return CMD_WARNING_CONFIG_FAILED;
15380 }
15381 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15382
585f1adc
IR
15383 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15384 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15385 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15386}
15387
15388ALIAS_HIDDEN(
15389 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15390 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15391 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15392 "Metric for redistributed routes\n"
15393 "Default metric\n")
596c17ba 15394
585f1adc
IR
15395DEFUN (bgp_redistribute_ipv4_rmap_metric,
15396 bgp_redistribute_ipv4_rmap_metric_cmd,
15397 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15398 "Redistribute information from another routing protocol\n"
15399 FRR_IP_REDIST_HELP_STR_BGPD
15400 "Route map reference\n"
15401 "Pointer to route-map entries\n"
15402 "Metric for redistributed routes\n"
15403 "Default metric\n")
718e3744 15404{
585f1adc 15405 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15406 int idx_protocol = 1;
15407 int idx_word = 3;
15408 int idx_number = 5;
585f1adc
IR
15409 int type;
15410 uint32_t metric;
15411 struct bgp_redist *red;
15412 bool changed;
15413 struct route_map *route_map =
15414 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15415
15416 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15417 if (type < 0) {
15418 vty_out(vty, "%% Invalid route type\n");
15419 return CMD_WARNING_CONFIG_FAILED;
15420 }
15421 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15422
585f1adc
IR
15423 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15424 changed =
15425 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15426 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15427 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15428}
15429
15430ALIAS_HIDDEN(
15431 bgp_redistribute_ipv4_rmap_metric,
15432 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15433 "redistribute " FRR_IP_REDIST_STR_BGPD
15434 " route-map WORD metric (0-4294967295)",
15435 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15436 "Route map reference\n"
15437 "Pointer to route-map entries\n"
15438 "Metric for redistributed routes\n"
15439 "Default metric\n")
596c17ba 15440
585f1adc
IR
15441DEFUN (bgp_redistribute_ipv4_metric_rmap,
15442 bgp_redistribute_ipv4_metric_rmap_cmd,
15443 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15444 "Redistribute information from another routing protocol\n"
15445 FRR_IP_REDIST_HELP_STR_BGPD
15446 "Metric for redistributed routes\n"
15447 "Default metric\n"
15448 "Route map reference\n"
15449 "Pointer to route-map entries\n")
718e3744 15450{
585f1adc 15451 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15452 int idx_protocol = 1;
37a87b8f 15453 int idx_number = 3;
585f1adc
IR
15454 int idx_word = 5;
15455 int type;
15456 uint32_t metric;
15457 struct bgp_redist *red;
15458 bool changed;
15459 struct route_map *route_map =
15460 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15461
15462 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15463 if (type < 0) {
15464 vty_out(vty, "%% Invalid route type\n");
15465 return CMD_WARNING_CONFIG_FAILED;
15466 }
15467 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15468
585f1adc
IR
15469 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15470 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15471 changed |=
15472 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15473 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15474}
15475
15476ALIAS_HIDDEN(
15477 bgp_redistribute_ipv4_metric_rmap,
15478 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15479 "redistribute " FRR_IP_REDIST_STR_BGPD
15480 " metric (0-4294967295) route-map WORD",
15481 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15482 "Metric for redistributed routes\n"
15483 "Default metric\n"
15484 "Route map reference\n"
15485 "Pointer to route-map entries\n")
596c17ba 15486
585f1adc
IR
15487DEFUN (bgp_redistribute_ipv4_ospf,
15488 bgp_redistribute_ipv4_ospf_cmd,
15489 "redistribute <ospf|table> (1-65535)",
15490 "Redistribute information from another routing protocol\n"
15491 "Open Shortest Path First (OSPFv2)\n"
15492 "Non-main Kernel Routing Table\n"
15493 "Instance ID/Table ID\n")
7c8ff89e 15494{
585f1adc
IR
15495 VTY_DECLVAR_CONTEXT(bgp, bgp);
15496 int idx_ospf_table = 1;
d62a17ae 15497 int idx_number = 2;
585f1adc
IR
15498 unsigned short instance;
15499 unsigned short protocol;
7c8ff89e 15500
585f1adc 15501 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 15502
585f1adc
IR
15503 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15504 protocol = ZEBRA_ROUTE_OSPF;
15505 else
15506 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 15507
585f1adc
IR
15508 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15509 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
15510}
15511
d62a17ae 15512ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15513 "redistribute <ospf|table> (1-65535)",
15514 "Redistribute information from another routing protocol\n"
15515 "Open Shortest Path First (OSPFv2)\n"
15516 "Non-main Kernel Routing Table\n"
15517 "Instance ID/Table ID\n")
596c17ba 15518
585f1adc
IR
15519DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15520 bgp_redistribute_ipv4_ospf_rmap_cmd,
15521 "redistribute <ospf|table> (1-65535) route-map WORD",
15522 "Redistribute information from another routing protocol\n"
15523 "Open Shortest Path First (OSPFv2)\n"
15524 "Non-main Kernel Routing Table\n"
15525 "Instance ID/Table ID\n"
15526 "Route map reference\n"
15527 "Pointer to route-map entries\n")
7c8ff89e 15528{
585f1adc
IR
15529 VTY_DECLVAR_CONTEXT(bgp, bgp);
15530 int idx_ospf_table = 1;
d62a17ae 15531 int idx_number = 2;
15532 int idx_word = 4;
585f1adc
IR
15533 struct bgp_redist *red;
15534 unsigned short instance;
15535 int protocol;
15536 bool changed;
15537 struct route_map *route_map =
15538 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15539
15540 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15541 protocol = ZEBRA_ROUTE_OSPF;
15542 else
15543 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15544
585f1adc
IR
15545 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15546 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15547 changed =
15548 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15549 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15550}
15551
15552ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15553 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15554 "redistribute <ospf|table> (1-65535) route-map WORD",
15555 "Redistribute information from another routing protocol\n"
15556 "Open Shortest Path First (OSPFv2)\n"
15557 "Non-main Kernel Routing Table\n"
15558 "Instance ID/Table ID\n"
15559 "Route map reference\n"
15560 "Pointer to route-map entries\n")
596c17ba 15561
585f1adc
IR
15562DEFUN (bgp_redistribute_ipv4_ospf_metric,
15563 bgp_redistribute_ipv4_ospf_metric_cmd,
15564 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15565 "Redistribute information from another routing protocol\n"
15566 "Open Shortest Path First (OSPFv2)\n"
15567 "Non-main Kernel Routing Table\n"
15568 "Instance ID/Table ID\n"
15569 "Metric for redistributed routes\n"
15570 "Default metric\n")
7c8ff89e 15571{
585f1adc
IR
15572 VTY_DECLVAR_CONTEXT(bgp, bgp);
15573 int idx_ospf_table = 1;
d62a17ae 15574 int idx_number = 2;
15575 int idx_number_2 = 4;
585f1adc
IR
15576 uint32_t metric;
15577 struct bgp_redist *red;
15578 unsigned short instance;
15579 int protocol;
15580 bool changed;
15581
15582 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15583 protocol = ZEBRA_ROUTE_OSPF;
15584 else
15585 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15586
585f1adc
IR
15587 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15588 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15589
585f1adc
IR
15590 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15591 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15592 metric);
15593 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15594}
15595
15596ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15597 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15598 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15599 "Redistribute information from another routing protocol\n"
15600 "Open Shortest Path First (OSPFv2)\n"
15601 "Non-main Kernel Routing Table\n"
15602 "Instance ID/Table ID\n"
15603 "Metric for redistributed routes\n"
15604 "Default metric\n")
596c17ba 15605
585f1adc
IR
15606DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
15607 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15608 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15609 "Redistribute information from another routing protocol\n"
15610 "Open Shortest Path First (OSPFv2)\n"
15611 "Non-main Kernel Routing Table\n"
15612 "Instance ID/Table ID\n"
15613 "Route map reference\n"
15614 "Pointer to route-map entries\n"
15615 "Metric for redistributed routes\n"
15616 "Default metric\n")
7c8ff89e 15617{
585f1adc
IR
15618 VTY_DECLVAR_CONTEXT(bgp, bgp);
15619 int idx_ospf_table = 1;
d62a17ae 15620 int idx_number = 2;
15621 int idx_word = 4;
15622 int idx_number_2 = 6;
585f1adc
IR
15623 uint32_t metric;
15624 struct bgp_redist *red;
15625 unsigned short instance;
15626 int protocol;
15627 bool changed;
15628 struct route_map *route_map =
15629 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15630
15631 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15632 protocol = ZEBRA_ROUTE_OSPF;
15633 else
15634 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15635
585f1adc
IR
15636 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15637 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15638
585f1adc
IR
15639 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15640 changed =
15641 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15642 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15643 metric);
15644 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15645}
15646
15647ALIAS_HIDDEN(
15648 bgp_redistribute_ipv4_ospf_rmap_metric,
15649 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15650 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15651 "Redistribute information from another routing protocol\n"
15652 "Open Shortest Path First (OSPFv2)\n"
15653 "Non-main Kernel Routing Table\n"
15654 "Instance ID/Table ID\n"
15655 "Route map reference\n"
15656 "Pointer to route-map entries\n"
15657 "Metric for redistributed routes\n"
15658 "Default metric\n")
596c17ba 15659
585f1adc
IR
15660DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
15661 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15662 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
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 "Metric for redistributed routes\n"
15668 "Default metric\n"
15669 "Route map reference\n"
15670 "Pointer to route-map entries\n")
7c8ff89e 15671{
585f1adc
IR
15672 VTY_DECLVAR_CONTEXT(bgp, bgp);
15673 int idx_ospf_table = 1;
d62a17ae 15674 int idx_number = 2;
15675 int idx_number_2 = 4;
15676 int idx_word = 6;
585f1adc
IR
15677 uint32_t metric;
15678 struct bgp_redist *red;
15679 unsigned short instance;
15680 int protocol;
15681 bool changed;
15682 struct route_map *route_map =
15683 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15684
15685 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15686 protocol = ZEBRA_ROUTE_OSPF;
15687 else
15688 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15689
585f1adc
IR
15690 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15691 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15692
585f1adc
IR
15693 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15694 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15695 metric);
15696 changed |=
15697 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15698 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15699}
15700
15701ALIAS_HIDDEN(
15702 bgp_redistribute_ipv4_ospf_metric_rmap,
15703 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15704 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15705 "Redistribute information from another routing protocol\n"
15706 "Open Shortest Path First (OSPFv2)\n"
15707 "Non-main Kernel Routing Table\n"
15708 "Instance ID/Table ID\n"
15709 "Metric for redistributed routes\n"
15710 "Default metric\n"
15711 "Route map reference\n"
15712 "Pointer to route-map entries\n")
596c17ba 15713
585f1adc
IR
15714DEFUN (no_bgp_redistribute_ipv4_ospf,
15715 no_bgp_redistribute_ipv4_ospf_cmd,
15716 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15717 NO_STR
15718 "Redistribute information from another routing protocol\n"
15719 "Open Shortest Path First (OSPFv2)\n"
15720 "Non-main Kernel Routing Table\n"
15721 "Instance ID/Table ID\n"
15722 "Metric for redistributed routes\n"
15723 "Default metric\n"
15724 "Route map reference\n"
15725 "Pointer to route-map entries\n")
7c8ff89e 15726{
585f1adc
IR
15727 VTY_DECLVAR_CONTEXT(bgp, bgp);
15728 int idx_ospf_table = 2;
d62a17ae 15729 int idx_number = 3;
585f1adc
IR
15730 unsigned short instance;
15731 int protocol;
37a87b8f 15732
585f1adc
IR
15733 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15734 protocol = ZEBRA_ROUTE_OSPF;
15735 else
15736 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15737
585f1adc
IR
15738 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15739 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
d62a17ae 15740}
15741
15742ALIAS_HIDDEN(
15743 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 15744 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15745 NO_STR
15746 "Redistribute information from another routing protocol\n"
15747 "Open Shortest Path First (OSPFv2)\n"
15748 "Non-main Kernel Routing Table\n"
15749 "Instance ID/Table ID\n"
15750 "Metric for redistributed routes\n"
15751 "Default metric\n"
15752 "Route map reference\n"
15753 "Pointer to route-map entries\n")
596c17ba 15754
585f1adc
IR
15755DEFUN (no_bgp_redistribute_ipv4,
15756 no_bgp_redistribute_ipv4_cmd,
15757 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15758 NO_STR
15759 "Redistribute information from another routing protocol\n"
15760 FRR_IP_REDIST_HELP_STR_BGPD
15761 "Metric for redistributed routes\n"
15762 "Default metric\n"
15763 "Route map reference\n"
15764 "Pointer to route-map entries\n")
718e3744 15765{
585f1adc 15766 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15767 int idx_protocol = 2;
585f1adc 15768 int type;
d62a17ae 15769
585f1adc
IR
15770 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15771 if (type < 0) {
15772 vty_out(vty, "%% Invalid route type\n");
15773 return CMD_WARNING_CONFIG_FAILED;
15774 }
15775 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
d62a17ae 15776}
15777
15778ALIAS_HIDDEN(
15779 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15780 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 15781 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15782 NO_STR
15783 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15784 "Metric for redistributed routes\n"
15785 "Default metric\n"
15786 "Route map reference\n"
15787 "Pointer to route-map entries\n")
596c17ba 15788
585f1adc
IR
15789DEFUN (bgp_redistribute_ipv6,
15790 bgp_redistribute_ipv6_cmd,
15791 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15792 "Redistribute information from another routing protocol\n"
15793 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 15794{
585f1adc 15795 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15796 int idx_protocol = 1;
585f1adc 15797 int type;
718e3744 15798
585f1adc
IR
15799 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15800 if (type < 0) {
15801 vty_out(vty, "%% Invalid route type\n");
15802 return CMD_WARNING_CONFIG_FAILED;
15803 }
718e3744 15804
585f1adc
IR
15805 bgp_redist_add(bgp, AFI_IP6, type, 0);
15806 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 15807}
15808
585f1adc
IR
15809DEFUN (bgp_redistribute_ipv6_rmap,
15810 bgp_redistribute_ipv6_rmap_cmd,
15811 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
15812 "Redistribute information from another routing protocol\n"
15813 FRR_IP6_REDIST_HELP_STR_BGPD
15814 "Route map reference\n"
15815 "Pointer to route-map entries\n")
718e3744 15816{
585f1adc 15817 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15818 int idx_protocol = 1;
15819 int idx_word = 3;
585f1adc
IR
15820 int type;
15821 struct bgp_redist *red;
15822 bool changed;
15823 struct route_map *route_map =
15824 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15825
15826 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15827 if (type < 0) {
15828 vty_out(vty, "%% Invalid route type\n");
15829 return CMD_WARNING_CONFIG_FAILED;
15830 }
37a87b8f 15831
585f1adc
IR
15832 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15833 changed =
15834 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15835 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15836}
15837
585f1adc 15838DEFUN (bgp_redistribute_ipv6_metric,
718e3744 15839 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 15840 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 15841 "Redistribute information from another routing protocol\n"
ab0181ee 15842 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 15843 "Metric for redistributed routes\n"
15844 "Default metric\n")
15845{
585f1adc 15846 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15847 int idx_protocol = 1;
15848 int idx_number = 3;
585f1adc
IR
15849 int type;
15850 uint32_t metric;
15851 struct bgp_redist *red;
15852 bool changed;
15853
15854 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15855 if (type < 0) {
15856 vty_out(vty, "%% Invalid route type\n");
15857 return CMD_WARNING_CONFIG_FAILED;
15858 }
15859 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15860
585f1adc
IR
15861 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15862 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
15863 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15864}
15865
585f1adc
IR
15866DEFUN (bgp_redistribute_ipv6_rmap_metric,
15867 bgp_redistribute_ipv6_rmap_metric_cmd,
15868 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15869 "Redistribute information from another routing protocol\n"
15870 FRR_IP6_REDIST_HELP_STR_BGPD
15871 "Route map reference\n"
15872 "Pointer to route-map entries\n"
15873 "Metric for redistributed routes\n"
15874 "Default metric\n")
718e3744 15875{
585f1adc 15876 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15877 int idx_protocol = 1;
15878 int idx_word = 3;
15879 int idx_number = 5;
585f1adc
IR
15880 int type;
15881 uint32_t metric;
15882 struct bgp_redist *red;
15883 bool changed;
15884 struct route_map *route_map =
15885 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15886
15887 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15888 if (type < 0) {
15889 vty_out(vty, "%% Invalid route type\n");
15890 return CMD_WARNING_CONFIG_FAILED;
15891 }
15892 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15893
585f1adc
IR
15894 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15895 changed =
15896 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15897 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
15898 metric);
15899 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15900}
15901
585f1adc
IR
15902DEFUN (bgp_redistribute_ipv6_metric_rmap,
15903 bgp_redistribute_ipv6_metric_rmap_cmd,
15904 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15905 "Redistribute information from another routing protocol\n"
15906 FRR_IP6_REDIST_HELP_STR_BGPD
15907 "Metric for redistributed routes\n"
15908 "Default metric\n"
15909 "Route map reference\n"
15910 "Pointer to route-map entries\n")
718e3744 15911{
585f1adc 15912 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15913 int idx_protocol = 1;
37a87b8f 15914 int idx_number = 3;
585f1adc
IR
15915 int idx_word = 5;
15916 int type;
15917 uint32_t metric;
15918 struct bgp_redist *red;
15919 bool changed;
15920 struct route_map *route_map =
15921 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15922
15923 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15924 if (type < 0) {
15925 vty_out(vty, "%% Invalid route type\n");
15926 return CMD_WARNING_CONFIG_FAILED;
15927 }
15928 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15929
585f1adc
IR
15930 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15931 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
15932 metric);
15933 changed |=
15934 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15935 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15936}
15937
585f1adc
IR
15938DEFUN (no_bgp_redistribute_ipv6,
15939 no_bgp_redistribute_ipv6_cmd,
15940 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15941 NO_STR
15942 "Redistribute information from another routing protocol\n"
15943 FRR_IP6_REDIST_HELP_STR_BGPD
15944 "Metric for redistributed routes\n"
15945 "Default metric\n"
15946 "Route map reference\n"
15947 "Pointer to route-map entries\n")
718e3744 15948{
585f1adc 15949 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15950 int idx_protocol = 2;
585f1adc 15951 int type;
37a87b8f 15952
585f1adc
IR
15953 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15954 if (type < 0) {
15955 vty_out(vty, "%% Invalid route type\n");
15956 return CMD_WARNING_CONFIG_FAILED;
15957 }
718e3744 15958
585f1adc 15959 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
d62a17ae 15960}
15961
4ab46701
AR
15962/* Neighbor update tcp-mss. */
15963static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
15964 const char *tcp_mss_str)
15965{
15966 struct peer *peer;
15967 uint32_t tcp_mss_val = 0;
15968
15969 peer = peer_and_group_lookup_vty(vty, peer_str);
15970 if (!peer)
15971 return CMD_WARNING_CONFIG_FAILED;
15972
15973 if (tcp_mss_str) {
15974 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
15975 peer_tcp_mss_set(peer, tcp_mss_val);
15976 } else {
15977 peer_tcp_mss_unset(peer);
15978 }
15979
15980 return CMD_SUCCESS;
15981}
15982
15983DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
15984 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
15985 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
15986 "TCP max segment size\n"
15987 "TCP MSS value\n")
15988{
15989 int peer_index = 1;
15990 int mss_index = 3;
15991
15992 vty_out(vty,
15993 " Warning: Reset BGP session for tcp-mss value to take effect\n");
15994 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
15995 argv[mss_index]->arg);
15996}
15997
15998DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
15999 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16000 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16001 "TCP max segment size\n"
16002 "TCP MSS value\n")
16003{
16004 int peer_index = 2;
16005
16006 vty_out(vty,
16007 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16008 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16009}
16010
dd65f45e
DL
16011static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16012 afi_t afi, safi_t safi)
d62a17ae 16013{
16014 int i;
16015
16016 /* Unicast redistribution only. */
16017 if (safi != SAFI_UNICAST)
2b791107 16018 return;
d62a17ae 16019
16020 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16021 /* Redistribute BGP does not make sense. */
16022 if (i != ZEBRA_ROUTE_BGP) {
16023 struct list *red_list;
16024 struct listnode *node;
16025 struct bgp_redist *red;
16026
16027 red_list = bgp->redist[afi][i];
16028 if (!red_list)
16029 continue;
16030
16031 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16032 /* "redistribute" configuration. */
16033 vty_out(vty, " redistribute %s",
16034 zebra_route_string(i));
16035 if (red->instance)
16036 vty_out(vty, " %d", red->instance);
16037 if (red->redist_metric_flag)
16038 vty_out(vty, " metric %u",
16039 red->redist_metric);
16040 if (red->rmap.name)
16041 vty_out(vty, " route-map %s",
16042 red->rmap.name);
16043 vty_out(vty, "\n");
16044 }
16045 }
16046 }
718e3744 16047}
6b0655a2 16048
dd65f45e
DL
16049/* peer-group helpers for config-write */
16050
16051static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16052{
16053 if (!peer_group_active(peer)) {
16054 if (CHECK_FLAG(peer->flags_invert, flag))
16055 return !CHECK_FLAG(peer->flags, flag);
16056 else
16057 return !!CHECK_FLAG(peer->flags, flag);
16058 }
16059
16060 return !!CHECK_FLAG(peer->flags_override, flag);
16061}
16062
16063static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16064 uint32_t flag)
16065{
16066 if (!peer_group_active(peer)) {
16067 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16068 return !peer_af_flag_check(peer, afi, safi, flag);
16069 else
16070 return !!peer_af_flag_check(peer, afi, safi, flag);
16071 }
16072
16073 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16074}
16075
16076static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16077 uint8_t type, int direct)
16078{
16079 struct bgp_filter *filter;
16080
16081 if (peer_group_active(peer))
16082 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16083 type);
16084
16085 filter = &peer->filter[afi][safi];
16086 switch (type) {
16087 case PEER_FT_DISTRIBUTE_LIST:
16088 return !!(filter->dlist[direct].name);
16089 case PEER_FT_FILTER_LIST:
16090 return !!(filter->aslist[direct].name);
16091 case PEER_FT_PREFIX_LIST:
16092 return !!(filter->plist[direct].name);
16093 case PEER_FT_ROUTE_MAP:
16094 return !!(filter->map[direct].name);
16095 case PEER_FT_UNSUPPRESS_MAP:
16096 return !!(filter->usmap.name);
7f7940e6
MK
16097 case PEER_FT_ADVERTISE_MAP:
16098 return !!(filter->advmap.aname
16099 && ((filter->advmap.condition == direct)
16100 && filter->advmap.cname));
dd65f45e
DL
16101 default:
16102 return false;
16103 }
16104}
16105
16106/* Return true if the addpath type is set for peer and different from
16107 * peer-group.
16108 */
3dc339cd
DA
16109static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16110 safi_t safi)
dd65f45e
DL
16111{
16112 enum bgp_addpath_strat type, g_type;
16113
16114 type = peer->addpath_type[afi][safi];
16115
16116 if (type != BGP_ADDPATH_NONE) {
16117 if (peer_group_active(peer)) {
16118 g_type = peer->group->conf->addpath_type[afi][safi];
16119
16120 if (type != g_type)
3dc339cd 16121 return true;
dd65f45e 16122 else
3dc339cd 16123 return false;
dd65f45e
DL
16124 }
16125
3dc339cd 16126 return true;
dd65f45e
DL
16127 }
16128
3dc339cd 16129 return false;
dd65f45e
DL
16130}
16131
b9c7bc5a 16132/* This is part of the address-family block (unicast only) */
dd65f45e 16133static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16134 afi_t afi)
16135{
b9c7bc5a 16136 int indent = 2;
53970de3 16137 uint32_t tovpn_sid_index = 0;
ddb5b488 16138
8a066a70 16139 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16140 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16141 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16142 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16143 bgp->vpn_policy[afi]
bb4f6190 16144 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16145 else
16146 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16147 bgp->vpn_policy[afi]
16148 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16149 }
12a844a5
DS
16150 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16151 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16152 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16153 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16154 return;
16155
e70e9f8e
PZ
16156 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16157 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16158
16159 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16160
16161 } else {
16162 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16163 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16164 bgp->vpn_policy[afi].tovpn_label);
16165 }
ddb5b488 16166 }
53970de3
RS
16167
16168 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16169 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16170 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16171 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16172 } else if (tovpn_sid_index != 0) {
16173 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16174 tovpn_sid_index);
16175 }
16176
ddb5b488
PZ
16177 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16178 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16179 char buf[RD_ADDRSTRLEN];
b9c7bc5a 16180 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
16181 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16182 sizeof(buf)));
16183 }
16184 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16185 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16186
16187 char buf[PREFIX_STRLEN];
16188 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16189 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16190 sizeof(buf))) {
16191
b9c7bc5a
PZ
16192 vty_out(vty, "%*snexthop vpn export %s\n",
16193 indent, "", buf);
ddb5b488
PZ
16194 }
16195 }
16196 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16197 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16198 && ecommunity_cmp(
16199 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16200 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16201
16202 char *b = ecommunity_ecom2str(
16203 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16204 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16205 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16206 XFREE(MTYPE_ECOMMUNITY_STR, b);
16207 } else {
16208 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16209 char *b = ecommunity_ecom2str(
16210 bgp->vpn_policy[afi]
16211 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16212 ECOMMUNITY_FORMAT_ROUTE_MAP,
16213 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16214 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16215 XFREE(MTYPE_ECOMMUNITY_STR, b);
16216 }
16217 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16218 char *b = ecommunity_ecom2str(
16219 bgp->vpn_policy[afi]
16220 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16221 ECOMMUNITY_FORMAT_ROUTE_MAP,
16222 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16223 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16224 XFREE(MTYPE_ECOMMUNITY_STR, b);
16225 }
16226 }
bb4f6190
DS
16227
16228 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16229 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16230 bgp->vpn_policy[afi]
16231 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16232
301ad80a
PG
16233 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16234 char *b = ecommunity_ecom2str(
16235 bgp->vpn_policy[afi]
16236 .import_redirect_rtlist,
16237 ECOMMUNITY_FORMAT_ROUTE_MAP,
16238 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16239
9a659715
PG
16240 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16241 != ECOMMUNITY_SIZE)
c6423c31 16242 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16243 indent, "", b);
16244 else
16245 vty_out(vty, "%*srt redirect import %s\n",
16246 indent, "", b);
301ad80a
PG
16247 XFREE(MTYPE_ECOMMUNITY_STR, b);
16248 }
ddb5b488
PZ
16249}
16250
dd65f45e
DL
16251static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16252 afi_t afi, safi_t safi)
16253{
16254 struct bgp_filter *filter;
16255 char *addr;
16256
16257 addr = peer->host;
16258 filter = &peer->filter[afi][safi];
16259
16260 /* distribute-list. */
16261 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16262 FILTER_IN))
16263 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16264 filter->dlist[FILTER_IN].name);
16265
16266 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16267 FILTER_OUT))
16268 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16269 filter->dlist[FILTER_OUT].name);
16270
16271 /* prefix-list. */
16272 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16273 FILTER_IN))
16274 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16275 filter->plist[FILTER_IN].name);
16276
16277 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16278 FILTER_OUT))
16279 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16280 filter->plist[FILTER_OUT].name);
16281
16282 /* route-map. */
16283 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16284 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16285 filter->map[RMAP_IN].name);
16286
16287 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16288 RMAP_OUT))
16289 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16290 filter->map[RMAP_OUT].name);
16291
16292 /* unsuppress-map */
16293 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16294 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16295 filter->usmap.name);
16296
7f7940e6
MK
16297 /* advertise-map : always applied in OUT direction*/
16298 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16299 CONDITION_NON_EXIST))
16300 vty_out(vty,
16301 " neighbor %s advertise-map %s non-exist-map %s\n",
16302 addr, filter->advmap.aname, filter->advmap.cname);
16303
16304 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16305 CONDITION_EXIST))
16306 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16307 addr, filter->advmap.aname, filter->advmap.cname);
16308
dd65f45e
DL
16309 /* filter-list. */
16310 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16311 FILTER_IN))
16312 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16313 filter->aslist[FILTER_IN].name);
16314
16315 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16316 FILTER_OUT))
16317 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16318 filter->aslist[FILTER_OUT].name);
16319}
16320
16321/* BGP peer configuration display function. */
16322static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16323 struct peer *peer)
16324{
16325 struct peer *g_peer = NULL;
16326 char buf[SU_ADDRSTRLEN];
16327 char *addr;
16328 int if_pg_printed = false;
16329 int if_ras_printed = false;
16330
16331 /* Skip dynamic neighbors. */
16332 if (peer_dynamic_neighbor(peer))
16333 return;
16334
16335 if (peer->conf_if)
16336 addr = peer->conf_if;
16337 else
16338 addr = peer->host;
16339
16340 /************************************
16341 ****** Global to the neighbor ******
16342 ************************************/
16343 if (peer->conf_if) {
16344 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16345 vty_out(vty, " neighbor %s interface v6only", addr);
16346 else
16347 vty_out(vty, " neighbor %s interface", addr);
16348
16349 if (peer_group_active(peer)) {
16350 vty_out(vty, " peer-group %s", peer->group->name);
16351 if_pg_printed = true;
16352 } else if (peer->as_type == AS_SPECIFIED) {
16353 vty_out(vty, " remote-as %u", peer->as);
16354 if_ras_printed = true;
16355 } else if (peer->as_type == AS_INTERNAL) {
16356 vty_out(vty, " remote-as internal");
16357 if_ras_printed = true;
16358 } else if (peer->as_type == AS_EXTERNAL) {
16359 vty_out(vty, " remote-as external");
16360 if_ras_printed = true;
16361 }
16362
16363 vty_out(vty, "\n");
16364 }
16365
16366 /* remote-as and peer-group */
16367 /* peer is a member of a peer-group */
16368 if (peer_group_active(peer)) {
16369 g_peer = peer->group->conf;
16370
16371 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16372 if (peer->as_type == AS_SPECIFIED) {
16373 vty_out(vty, " neighbor %s remote-as %u\n",
16374 addr, peer->as);
16375 } else if (peer->as_type == AS_INTERNAL) {
16376 vty_out(vty,
16377 " neighbor %s remote-as internal\n",
16378 addr);
16379 } else if (peer->as_type == AS_EXTERNAL) {
16380 vty_out(vty,
16381 " neighbor %s remote-as external\n",
16382 addr);
16383 }
16384 }
16385
16386 /* For swpX peers we displayed the peer-group
16387 * via 'neighbor swpX interface peer-group PGNAME' */
16388 if (!if_pg_printed)
16389 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16390 peer->group->name);
16391 }
16392
16393 /* peer is NOT a member of a peer-group */
16394 else {
16395 /* peer is a peer-group, declare the peer-group */
16396 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16397 vty_out(vty, " neighbor %s peer-group\n", addr);
16398 }
16399
16400 if (!if_ras_printed) {
16401 if (peer->as_type == AS_SPECIFIED) {
16402 vty_out(vty, " neighbor %s remote-as %u\n",
16403 addr, peer->as);
16404 } else if (peer->as_type == AS_INTERNAL) {
16405 vty_out(vty,
16406 " neighbor %s remote-as internal\n",
16407 addr);
16408 } else if (peer->as_type == AS_EXTERNAL) {
16409 vty_out(vty,
16410 " neighbor %s remote-as external\n",
16411 addr);
16412 }
16413 }
16414 }
16415
16416 /* local-as */
16417 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16418 vty_out(vty, " neighbor %s local-as %u", addr,
16419 peer->change_local_as);
16420 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16421 vty_out(vty, " no-prepend");
16422 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16423 vty_out(vty, " replace-as");
16424 vty_out(vty, "\n");
16425 }
16426
16427 /* description */
16428 if (peer->desc) {
16429 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16430 }
16431
16432 /* shutdown */
16433 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16434 if (peer->tx_shutdown_message)
16435 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16436 peer->tx_shutdown_message);
16437 else
16438 vty_out(vty, " neighbor %s shutdown\n", addr);
16439 }
16440
8336c896
DA
16441 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16442 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16443 peer->rtt_expected, peer->rtt_keepalive_conf);
16444
dd65f45e 16445 /* bfd */
21bfce98
RZ
16446 if (peer->bfd_config)
16447 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
16448
16449 /* password */
16450 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16451 vty_out(vty, " neighbor %s password %s\n", addr,
16452 peer->password);
16453
16454 /* neighbor solo */
16455 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16456 if (!peer_group_active(peer)) {
16457 vty_out(vty, " neighbor %s solo\n", addr);
16458 }
16459 }
16460
16461 /* BGP port */
16462 if (peer->port != BGP_PORT_DEFAULT) {
16463 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16464 }
16465
16466 /* Local interface name */
16467 if (peer->ifname) {
16468 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16469 }
16470
4ab46701
AR
16471 /* TCP max segment size */
16472 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16473 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16474
dd65f45e
DL
16475 /* passive */
16476 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16477 vty_out(vty, " neighbor %s passive\n", addr);
16478
16479 /* ebgp-multihop */
16480 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
16481 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16482 && peer->ttl == MAXTTL)) {
dd65f45e
DL
16483 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16484 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16485 peer->ttl);
16486 }
16487 }
16488
16489 /* ttl-security hops */
e2521429 16490 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
16491 if (!peer_group_active(peer)
16492 || g_peer->gtsm_hops != peer->gtsm_hops) {
16493 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16494 addr, peer->gtsm_hops);
16495 }
16496 }
16497
16498 /* disable-connected-check */
16499 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16500 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16501
27aa23a4
DA
16502 /* link-bw-encoding-ieee */
16503 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16504 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16505 addr);
16506
d08c0c80
DA
16507 /* extended-optional-parameters */
16508 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16509 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16510 addr);
16511
dd65f45e
DL
16512 /* enforce-first-as */
16513 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16514 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16515
16516 /* update-source */
16517 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16518 if (peer->update_source)
16519 vty_out(vty, " neighbor %s update-source %s\n", addr,
16520 sockunion2str(peer->update_source, buf,
16521 SU_ADDRSTRLEN));
16522 else if (peer->update_if)
16523 vty_out(vty, " neighbor %s update-source %s\n", addr,
16524 peer->update_if);
16525 }
16526
16527 /* advertisement-interval */
16528 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16529 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16530 peer->routeadv);
16531
16532 /* timers */
16533 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16534 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16535 peer->keepalive, peer->holdtime);
16536
16537 /* timers connect */
16538 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16539 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16540 peer->connect);
5d5393b9
DL
16541 /* need special-case handling for changed default values due to
16542 * config profile / version (because there is no "timers bgp connect"
16543 * command, we need to save this per-peer :/)
16544 */
16545 else if (!peer_group_active(peer) && !peer->connect &&
16546 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16547 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16548 peer->bgp->default_connect_retry);
dd65f45e 16549
d43114f3
DS
16550 /* timers delayopen */
16551 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16552 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16553 peer->delayopen);
16554 /* Save config even though flag is not set if default values have been
16555 * changed
16556 */
16557 else if (!peer_group_active(peer) && !peer->delayopen
16558 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16559 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16560 peer->bgp->default_delayopen);
16561
dd65f45e
DL
16562 /* capability dynamic */
16563 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16564 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16565
16566 /* capability extended-nexthop */
16567 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
843770f6
DA
16568 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE))
16569 vty_out(vty,
16570 " no neighbor %s capability extended-nexthop\n",
16571 addr);
16572 else if (!peer->conf_if)
16573 vty_out(vty,
16574 " neighbor %s capability extended-nexthop\n",
16575 addr);
dd65f45e
DL
16576 }
16577
16578 /* dont-capability-negotiation */
16579 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16580 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16581
16582 /* override-capability */
16583 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16584 vty_out(vty, " neighbor %s override-capability\n", addr);
16585
16586 /* strict-capability-match */
16587 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16588 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16589
16590 /* Sender side AS path loop detection. */
16591 if (peer->as_path_loop_detection)
16592 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16593 addr);
cfd47646 16594
16595 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16596 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 16597
16598 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16599 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 16600 vty_out(vty,
16601 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
16602 } else if (CHECK_FLAG(
16603 peer->peer_gr_new_status_flag,
16604 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 16605 vty_out(vty,
16606 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
16607 } else if (
16608 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16609 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16610 && !(CHECK_FLAG(
16611 peer->peer_gr_new_status_flag,
16612 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16613 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16614 addr);
cfd47646 16615 }
16616 }
dd65f45e
DL
16617}
16618
16619/* BGP peer configuration display function. */
16620static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16621 struct peer *peer, afi_t afi, safi_t safi)
16622{
16623 struct peer *g_peer = NULL;
16624 char *addr;
16625 bool flag_scomm, flag_secomm, flag_slcomm;
16626
16627 /* Skip dynamic neighbors. */
16628 if (peer_dynamic_neighbor(peer))
16629 return;
16630
16631 if (peer->conf_if)
16632 addr = peer->conf_if;
16633 else
16634 addr = peer->host;
16635
16636 /************************************
16637 ****** Per AF to the neighbor ******
16638 ************************************/
16639 if (peer_group_active(peer)) {
16640 g_peer = peer->group->conf;
16641
16642 /* If the peer-group is active but peer is not, print a 'no
16643 * activate' */
16644 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16645 vty_out(vty, " no neighbor %s activate\n", addr);
16646 }
16647
16648 /* If the peer-group is not active but peer is, print an
16649 'activate' */
16650 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16651 vty_out(vty, " neighbor %s activate\n", addr);
16652 }
16653 } else {
16654 if (peer->afc[afi][safi]) {
38d11af5
TA
16655 if (safi == SAFI_ENCAP)
16656 vty_out(vty, " neighbor %s activate\n", addr);
16657 else if (!bgp->default_af[afi][safi])
dd65f45e
DL
16658 vty_out(vty, " neighbor %s activate\n", addr);
16659 } else {
38d11af5
TA
16660 if (bgp->default_af[afi][safi])
16661 vty_out(vty, " no neighbor %s activate\n",
16662 addr);
dd65f45e
DL
16663 }
16664 }
16665
16666 /* addpath TX knobs */
16667 if (peergroup_af_addpath_check(peer, afi, safi)) {
16668 switch (peer->addpath_type[afi][safi]) {
16669 case BGP_ADDPATH_ALL:
16670 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16671 addr);
16672 break;
16673 case BGP_ADDPATH_BEST_PER_AS:
16674 vty_out(vty,
16675 " neighbor %s addpath-tx-bestpath-per-AS\n",
16676 addr);
16677 break;
16678 case BGP_ADDPATH_MAX:
16679 case BGP_ADDPATH_NONE:
16680 break;
16681 }
16682 }
16683
7c0e4312
DA
16684 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
16685 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
16686
dd65f45e
DL
16687 /* ORF capability. */
16688 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16689 || peergroup_af_flag_check(peer, afi, safi,
16690 PEER_FLAG_ORF_PREFIX_RM)) {
16691 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16692
16693 if (peergroup_af_flag_check(peer, afi, safi,
16694 PEER_FLAG_ORF_PREFIX_SM)
16695 && peergroup_af_flag_check(peer, afi, safi,
16696 PEER_FLAG_ORF_PREFIX_RM))
16697 vty_out(vty, " both");
16698 else if (peergroup_af_flag_check(peer, afi, safi,
16699 PEER_FLAG_ORF_PREFIX_SM))
16700 vty_out(vty, " send");
16701 else
16702 vty_out(vty, " receive");
16703 vty_out(vty, "\n");
16704 }
16705
dd65f45e
DL
16706 /* Route reflector client. */
16707 if (peergroup_af_flag_check(peer, afi, safi,
16708 PEER_FLAG_REFLECTOR_CLIENT)) {
16709 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16710 }
16711
16712 /* next-hop-self force */
16713 if (peergroup_af_flag_check(peer, afi, safi,
16714 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16715 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16716 }
16717
16718 /* next-hop-self */
16719 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16720 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16721 }
16722
16723 /* remove-private-AS */
16724 if (peergroup_af_flag_check(peer, afi, safi,
16725 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16726 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16727 addr);
16728 }
16729
16730 else if (peergroup_af_flag_check(peer, afi, safi,
16731 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16732 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16733 addr);
16734 }
16735
16736 else if (peergroup_af_flag_check(peer, afi, safi,
16737 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16738 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16739 }
16740
16741 else if (peergroup_af_flag_check(peer, afi, safi,
16742 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16743 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16744 }
16745
16746 /* as-override */
16747 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16748 vty_out(vty, " neighbor %s as-override\n", addr);
16749 }
16750
16751 /* send-community print. */
16752 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16753 PEER_FLAG_SEND_COMMUNITY);
16754 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16755 PEER_FLAG_SEND_EXT_COMMUNITY);
16756 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16757 PEER_FLAG_SEND_LARGE_COMMUNITY);
16758
16759 if (flag_scomm && flag_secomm && flag_slcomm) {
16760 vty_out(vty, " no neighbor %s send-community all\n", addr);
16761 } else {
16762 if (flag_scomm)
16763 vty_out(vty, " no neighbor %s send-community\n", addr);
16764 if (flag_secomm)
16765 vty_out(vty,
16766 " no neighbor %s send-community extended\n",
16767 addr);
16768
16769 if (flag_slcomm)
16770 vty_out(vty, " no neighbor %s send-community large\n",
16771 addr);
16772 }
16773
16774 /* Default information */
16775 if (peergroup_af_flag_check(peer, afi, safi,
16776 PEER_FLAG_DEFAULT_ORIGINATE)) {
16777 vty_out(vty, " neighbor %s default-originate", addr);
16778
16779 if (peer->default_rmap[afi][safi].name)
16780 vty_out(vty, " route-map %s",
16781 peer->default_rmap[afi][safi].name);
16782
16783 vty_out(vty, "\n");
16784 }
16785
16786 /* Soft reconfiguration inbound. */
16787 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16788 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16789 addr);
16790 }
16791
16792 /* maximum-prefix. */
16793 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 16794 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
16795 peer->pmax[afi][safi]);
16796
16797 if (peer->pmax_threshold[afi][safi]
16798 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16799 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16800 if (peer_af_flag_check(peer, afi, safi,
16801 PEER_FLAG_MAX_PREFIX_WARNING))
16802 vty_out(vty, " warning-only");
16803 if (peer->pmax_restart[afi][safi])
16804 vty_out(vty, " restart %u",
16805 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
16806 if (peer_af_flag_check(peer, afi, safi,
16807 PEER_FLAG_MAX_PREFIX_FORCE))
16808 vty_out(vty, " force");
dd65f45e
DL
16809
16810 vty_out(vty, "\n");
16811 }
16812
fde246e8
DA
16813 /* maximum-prefix-out */
16814 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 16815 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
16816 addr, peer->pmax_out[afi][safi]);
16817
dd65f45e
DL
16818 /* Route server client. */
16819 if (peergroup_af_flag_check(peer, afi, safi,
16820 PEER_FLAG_RSERVER_CLIENT)) {
16821 vty_out(vty, " neighbor %s route-server-client\n", addr);
16822 }
16823
16824 /* Nexthop-local unchanged. */
16825 if (peergroup_af_flag_check(peer, afi, safi,
16826 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16827 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16828 }
16829
16830 /* allowas-in <1-10> */
16831 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16832 if (peer_af_flag_check(peer, afi, safi,
16833 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16834 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16835 } else if (peer->allowas_in[afi][safi] == 3) {
16836 vty_out(vty, " neighbor %s allowas-in\n", addr);
16837 } else {
16838 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16839 peer->allowas_in[afi][safi]);
16840 }
16841 }
16842
16843 /* weight */
16844 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16845 vty_out(vty, " neighbor %s weight %lu\n", addr,
16846 peer->weight[afi][safi]);
16847
16848 /* Filter. */
16849 bgp_config_write_filter(vty, peer, afi, safi);
16850
16851 /* atribute-unchanged. */
16852 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16853 || (safi != SAFI_EVPN
16854 && peer_af_flag_check(peer, afi, safi,
16855 PEER_FLAG_NEXTHOP_UNCHANGED))
16856 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16857
16858 if (!peer_group_active(peer)
16859 || peergroup_af_flag_check(peer, afi, safi,
16860 PEER_FLAG_AS_PATH_UNCHANGED)
16861 || peergroup_af_flag_check(peer, afi, safi,
16862 PEER_FLAG_NEXTHOP_UNCHANGED)
16863 || peergroup_af_flag_check(peer, afi, safi,
16864 PEER_FLAG_MED_UNCHANGED)) {
16865
16866 vty_out(vty,
16867 " neighbor %s attribute-unchanged%s%s%s\n",
16868 addr,
16869 peer_af_flag_check(peer, afi, safi,
16870 PEER_FLAG_AS_PATH_UNCHANGED)
16871 ? " as-path"
16872 : "",
16873 peer_af_flag_check(peer, afi, safi,
16874 PEER_FLAG_NEXTHOP_UNCHANGED)
16875 ? " next-hop"
16876 : "",
16877 peer_af_flag_check(peer, afi, safi,
16878 PEER_FLAG_MED_UNCHANGED)
16879 ? " med"
16880 : "");
16881 }
16882 }
16883}
16884
16885/* Address family based peer configuration display. */
16886static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
16887 safi_t safi)
16888{
16889 struct peer *peer;
16890 struct peer_group *group;
16891 struct listnode *node, *nnode;
16892
16893
16894 vty_frame(vty, " !\n address-family ");
16895 if (afi == AFI_IP) {
16896 if (safi == SAFI_UNICAST)
16897 vty_frame(vty, "ipv4 unicast");
16898 else if (safi == SAFI_LABELED_UNICAST)
16899 vty_frame(vty, "ipv4 labeled-unicast");
16900 else if (safi == SAFI_MULTICAST)
16901 vty_frame(vty, "ipv4 multicast");
16902 else if (safi == SAFI_MPLS_VPN)
16903 vty_frame(vty, "ipv4 vpn");
16904 else if (safi == SAFI_ENCAP)
16905 vty_frame(vty, "ipv4 encap");
16906 else if (safi == SAFI_FLOWSPEC)
16907 vty_frame(vty, "ipv4 flowspec");
16908 } else if (afi == AFI_IP6) {
16909 if (safi == SAFI_UNICAST)
16910 vty_frame(vty, "ipv6 unicast");
16911 else if (safi == SAFI_LABELED_UNICAST)
16912 vty_frame(vty, "ipv6 labeled-unicast");
16913 else if (safi == SAFI_MULTICAST)
16914 vty_frame(vty, "ipv6 multicast");
16915 else if (safi == SAFI_MPLS_VPN)
16916 vty_frame(vty, "ipv6 vpn");
16917 else if (safi == SAFI_ENCAP)
16918 vty_frame(vty, "ipv6 encap");
16919 else if (safi == SAFI_FLOWSPEC)
16920 vty_frame(vty, "ipv6 flowspec");
16921 } else if (afi == AFI_L2VPN) {
16922 if (safi == SAFI_EVPN)
16923 vty_frame(vty, "l2vpn evpn");
16924 }
16925 vty_frame(vty, "\n");
16926
16927 bgp_config_write_distance(vty, bgp, afi, safi);
16928
16929 bgp_config_write_network(vty, bgp, afi, safi);
16930
16931 bgp_config_write_redistribute(vty, bgp, afi, safi);
16932
8a4e7fe6
DA
16933 /* BGP flag dampening. */
16934 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6c75f4b3 16935 bgp_config_write_damp(vty, afi, safi);
8a4e7fe6 16936
dd65f45e
DL
16937 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
16938 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
16939
16940 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
16941 /* Do not display doppelganger peers */
16942 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16943 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
16944 }
16945
16946 bgp_config_write_maxpaths(vty, bgp, afi, safi);
16947 bgp_config_write_table_map(vty, bgp, afi, safi);
16948
16949 if (safi == SAFI_EVPN)
16950 bgp_config_write_evpn_info(vty, bgp, afi, safi);
16951
16952 if (safi == SAFI_FLOWSPEC)
16953 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
16954
16955 if (safi == SAFI_UNICAST) {
16956 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
16957 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16958 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
16959
16960 vty_out(vty, " export vpn\n");
16961 }
16962 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16963 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
16964
16965 vty_out(vty, " import vpn\n");
16966 }
16967 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16968 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
16969 char *name;
16970
16971 for (ALL_LIST_ELEMENTS_RO(
16972 bgp->vpn_policy[afi].import_vrf, node,
16973 name))
16974 vty_out(vty, " import vrf %s\n", name);
16975 }
16976 }
16977
16978 vty_endframe(vty, " exit-address-family\n");
16979}
16980
16981int bgp_config_write(struct vty *vty)
16982{
16983 struct bgp *bgp;
16984 struct peer_group *group;
16985 struct peer *peer;
16986 struct listnode *node, *nnode;
16987 struct listnode *mnode, *mnnode;
b16bcbba
TA
16988 afi_t afi;
16989 safi_t safi;
dd65f45e
DL
16990
16991 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
16992 vty_out(vty, "bgp route-map delay-timer %u\n",
16993 bm->rmap_update_timer);
16994
d70583f7
D
16995 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
16996 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
16997 if (bm->v_update_delay != bm->v_establish_wait)
16998 vty_out(vty, " %d", bm->v_establish_wait);
16999 vty_out(vty, "\n");
17000 }
17001
9acb67cb
DS
17002 if (bm->wait_for_fib)
17003 vty_out(vty, "bgp suppress-fib-pending\n");
17004
05bd726c 17005 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17006 vty_out(vty, "bgp graceful-shutdown\n");
17007
c163f297
DS
17008 /* No-RIB (Zebra) option flag configuration */
17009 if (bgp_option_check(BGP_OPT_NO_FIB))
17010 vty_out(vty, "bgp no-rib\n");
17011
870791a3
IR
17012 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17013 vty_out(vty, "bgp send-extra-data zebra\n");
e46723a5 17014
dd65f45e
DL
17015 /* BGP configuration. */
17016 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17017
17018 /* skip all auto created vrf as they dont have user config */
17019 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17020 continue;
17021
17022 /* Router bgp ASN */
17023 vty_out(vty, "router bgp %u", bgp->as);
17024
17025 if (bgp->name)
17026 vty_out(vty, " %s %s",
17027 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17028 ? "view" : "vrf", bgp->name);
17029 vty_out(vty, "\n");
17030
17031 /* BGP fast-external-failover. */
17032 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17033 vty_out(vty, " no bgp fast-external-failover\n");
17034
17035 /* BGP router ID. */
3a6290bd 17036 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17037 vty_out(vty, " bgp router-id %pI4\n",
17038 &bgp->router_id_static);
dd65f45e 17039
c208c586
S
17040 /* Suppress fib pending */
17041 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17042 vty_out(vty, " bgp suppress-fib-pending\n");
17043
dd65f45e 17044 /* BGP log-neighbor-changes. */
892fedb6 17045 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17046 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17047 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17048 CHECK_FLAG(bgp->flags,
17049 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17050 ? ""
17051 : "no ");
17052
17053 /* BGP configuration. */
892fedb6 17054 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17055 vty_out(vty, " bgp always-compare-med\n");
17056
17057 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17058 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17059 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17060 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17061 CHECK_FLAG(bgp->flags,
17062 BGP_FLAG_EBGP_REQUIRES_POLICY)
17063 ? ""
17064 : "no ");
dd65f45e
DL
17065
17066 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17067 if (bgp->reject_as_sets)
dd65f45e
DL
17068 vty_out(vty, " bgp reject-as-sets\n");
17069
2adac256
DA
17070 /* Suppress duplicate updates if the route actually not changed
17071 */
17072 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17073 != SAVE_BGP_SUPPRESS_DUPLICATES)
17074 vty_out(vty, " %sbgp suppress-duplicates\n",
17075 CHECK_FLAG(bgp->flags,
17076 BGP_FLAG_SUPPRESS_DUPLICATES)
17077 ? ""
17078 : "no ");
17079
b16bcbba
TA
17080 /* BGP default <afi>-<safi> */
17081 FOREACH_AFI_SAFI (afi, safi) {
17082 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17083 if (!bgp->default_af[afi][safi])
17084 vty_out(vty, " no bgp default %s\n",
17085 get_bgp_default_af_flag(afi,
17086 safi));
17087 } else if (bgp->default_af[afi][safi])
17088 vty_out(vty, " bgp default %s\n",
17089 get_bgp_default_af_flag(afi, safi));
17090 }
e84c59af 17091
dd65f45e
DL
17092 /* BGP default local-preference. */
17093 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17094 vty_out(vty, " bgp default local-preference %u\n",
17095 bgp->default_local_pref);
17096
17097 /* BGP default show-hostname */
892fedb6 17098 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17099 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17100 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17101 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17102 ? ""
17103 : "no ");
17104
aef999a2
DA
17105 /* BGP default show-nexthop-hostname */
17106 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17107 != SAVE_BGP_SHOW_HOSTNAME)
17108 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17109 CHECK_FLAG(bgp->flags,
17110 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17111 ? ""
17112 : "no ");
17113
dd65f45e
DL
17114 /* BGP default subgroup-pkt-queue-max. */
17115 if (bgp->default_subgroup_pkt_queue_max
17116 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17117 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17118 bgp->default_subgroup_pkt_queue_max);
17119
17120 /* BGP client-to-client reflection. */
892fedb6 17121 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17122 vty_out(vty, " no bgp client-to-client reflection\n");
17123
17124 /* BGP cluster ID. */
17125 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17126 vty_out(vty, " bgp cluster-id %pI4\n",
17127 &bgp->cluster_id);
dd65f45e
DL
17128
17129 /* Disable ebgp connected nexthop check */
892fedb6 17130 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17131 vty_out(vty,
17132 " bgp disable-ebgp-connected-route-check\n");
17133
17134 /* Confederation identifier*/
17135 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17136 vty_out(vty, " bgp confederation identifier %u\n",
17137 bgp->confed_id);
17138
17139 /* Confederation peer */
17140 if (bgp->confed_peers_cnt > 0) {
17141 int i;
17142
17143 vty_out(vty, " bgp confederation peers");
17144
17145 for (i = 0; i < bgp->confed_peers_cnt; i++)
17146 vty_out(vty, " %u", bgp->confed_peers[i]);
17147
17148 vty_out(vty, "\n");
17149 }
17150
17151 /* BGP deterministic-med. */
892fedb6 17152 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 17153 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 17154 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
17155 CHECK_FLAG(bgp->flags,
17156 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
17157 ? ""
17158 : "no ");
17159
17160 /* BGP update-delay. */
17161 bgp_config_write_update_delay(vty, bgp);
17162
17163 if (bgp->v_maxmed_onstartup
17164 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17165 vty_out(vty, " bgp max-med on-startup %u",
17166 bgp->v_maxmed_onstartup);
17167 if (bgp->maxmed_onstartup_value
17168 != BGP_MAXMED_VALUE_DEFAULT)
17169 vty_out(vty, " %u",
17170 bgp->maxmed_onstartup_value);
17171 vty_out(vty, "\n");
17172 }
17173 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17174 vty_out(vty, " bgp max-med administrative");
17175 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17176 vty_out(vty, " %u", bgp->maxmed_admin_value);
17177 vty_out(vty, "\n");
17178 }
17179
17180 /* write quanta */
17181 bgp_config_write_wpkt_quanta(vty, bgp);
17182 /* read quanta */
17183 bgp_config_write_rpkt_quanta(vty, bgp);
17184
17185 /* coalesce time */
17186 bgp_config_write_coalesce_time(vty, bgp);
17187
05bd726c 17188 /* BGP per-instance graceful-shutdown */
17189 /* BGP-wide settings and per-instance settings are mutually
17190 * exclusive.
17191 */
17192 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17193 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17194 vty_out(vty, " bgp graceful-shutdown\n");
17195
8606be87
DA
17196 /* Long-lived Graceful Restart */
17197 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17198 vty_out(vty,
17199 " bgp long-lived-graceful-restart stale-time %u\n",
17200 bgp->llgr_stale_time);
17201
dd65f45e
DL
17202 /* BGP graceful-restart. */
17203 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17204 vty_out(vty,
17205 " bgp graceful-restart stalepath-time %u\n",
17206 bgp->stalepath_time);
cfd47646 17207
dd65f45e
DL
17208 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17209 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17210 bgp->restart_time);
cfd47646 17211
17212 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17213 vty_out(vty,
17214 " bgp graceful-restart select-defer-time %u\n",
17215 bgp->select_defer_time);
17216
17217 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
17218 vty_out(vty, " bgp graceful-restart\n");
17219
cfd47646 17220 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17221 vty_out(vty, " bgp graceful-restart-disable\n");
17222
dd65f45e 17223 /* BGP graceful-restart Preserve State F bit. */
892fedb6 17224 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
17225 vty_out(vty,
17226 " bgp graceful-restart preserve-fw-state\n");
17227
dc95985f 17228 /* Stale timer for RIB */
17229 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17230 vty_out(vty,
17231 " bgp graceful-restart rib-stale-time %u\n",
17232 bgp->rib_stale_time);
17233
dd65f45e 17234 /* BGP bestpath method. */
892fedb6 17235 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 17236 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 17237 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
17238 vty_out(vty, " bgp bestpath as-path confed\n");
17239
892fedb6
DA
17240 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17241 if (CHECK_FLAG(bgp->flags,
17242 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
17243 vty_out(vty,
17244 " bgp bestpath as-path multipath-relax as-set\n");
17245 } else {
17246 vty_out(vty,
17247 " bgp bestpath as-path multipath-relax\n");
17248 }
17249 }
17250
892fedb6 17251 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17252 vty_out(vty,
17253 " bgp route-reflector allow-outbound-policy\n");
17254 }
892fedb6 17255 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17256 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17257 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17258 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17259 vty_out(vty, " bgp bestpath med");
892fedb6 17260 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17261 vty_out(vty, " confed");
892fedb6
DA
17262 if (CHECK_FLAG(bgp->flags,
17263 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17264 vty_out(vty, " missing-as-worst");
17265 vty_out(vty, "\n");
17266 }
17267
ee88563a
JM
17268 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17269 vty_out(vty,
17270 " bgp bestpath peer-type multipath-relax\n");
17271
f7e1c681 17272 /* Link bandwidth handling. */
17273 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17274 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17275 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17276 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17277 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17278 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17279
dd65f45e 17280 /* BGP network import check. */
892fedb6 17281 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17282 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17283 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17284 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17285 ? ""
17286 : "no ");
17287
17288 /* BGP timers configuration. */
5d5393b9 17289 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 17290 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17291 vty_out(vty, " timers bgp %u %u\n",
17292 bgp->default_keepalive, bgp->default_holdtime);
17293
b042667a
TI
17294 /* BGP minimum holdtime configuration. */
17295 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17296 && bgp->default_min_holdtime != 0)
17297 vty_out(vty, " bgp minimum-holdtime %u\n",
17298 bgp->default_min_holdtime);
17299
389e4f92
QY
17300 /* Conditional advertisement timer configuration */
17301 if (bgp->condition_check_period
17302 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17303 vty_out(vty,
17304 " bgp conditional-advertisement timer %u\n",
17305 bgp->condition_check_period);
17306
dd65f45e
DL
17307 /* peer-group */
17308 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17309 bgp_config_write_peer_global(vty, bgp, group->conf);
17310 }
17311
17312 /* Normal neighbor configuration. */
17313 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17314 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17315 bgp_config_write_peer_global(vty, bgp, peer);
17316 }
17317
17318 /* listen range and limit for dynamic BGP neighbors */
17319 bgp_config_write_listen(vty, bgp);
17320
17321 /*
17322 * BGP default autoshutdown neighbors
17323 *
17324 * This must be placed after any peer and peer-group
17325 * configuration, to avoid setting all peers to shutdown after
17326 * a daemon restart, which is undesired behavior. (see #2286)
17327 */
17328 if (bgp->autoshutdown)
17329 vty_out(vty, " bgp default shutdown\n");
17330
9cf59432
DS
17331 /* BGP instance administrative shutdown */
17332 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17333 vty_out(vty, " bgp shutdown\n");
17334
f852eb98
PG
17335 if (bgp->fast_convergence)
17336 vty_out(vty, " bgp fast-convergence\n");
17337
a0281b2e
HS
17338 if (bgp->srv6_enabled) {
17339 vty_frame(vty, " !\n segment-routing srv6\n");
96db4340 17340 if (strlen(bgp->srv6_locator_name))
a0281b2e
HS
17341 vty_out(vty, " locator %s\n",
17342 bgp->srv6_locator_name);
ff7c3ee1 17343 vty_endframe(vty, " exit\n");
a0281b2e
HS
17344 }
17345
17346
dd65f45e
DL
17347 /* IPv4 unicast configuration. */
17348 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17349
17350 /* IPv4 multicast configuration. */
17351 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17352
17353 /* IPv4 labeled-unicast configuration. */
17354 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17355
17356 /* IPv4 VPN configuration. */
17357 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17358
17359 /* ENCAPv4 configuration. */
17360 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17361
17362 /* FLOWSPEC v4 configuration. */
17363 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17364
17365 /* IPv6 unicast configuration. */
17366 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17367
17368 /* IPv6 multicast configuration. */
17369 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17370
17371 /* IPv6 labeled-unicast configuration. */
17372 bgp_config_write_family(vty, bgp, AFI_IP6,
17373 SAFI_LABELED_UNICAST);
17374
17375 /* IPv6 VPN configuration. */
17376 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17377
17378 /* ENCAPv6 configuration. */
17379 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17380
17381 /* FLOWSPEC v6 configuration. */
17382 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17383
17384 /* EVPN configuration. */
17385 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17386
17387 hook_call(bgp_inst_config_write, bgp, vty);
17388
49e5a4a0 17389#ifdef ENABLE_BGP_VNC
dd65f45e
DL
17390 bgp_rfapi_cfg_write(vty, bgp);
17391#endif
17392
07679ad9 17393 vty_out(vty, "exit\n");
dd65f45e
DL
17394 vty_out(vty, "!\n");
17395 }
17396 return 0;
17397}
17398
ddb5b488 17399
718e3744 17400/* BGP node structure. */
d62a17ae 17401static struct cmd_node bgp_node = {
f4b8291f 17402 .name = "bgp",
62b346ee 17403 .node = BGP_NODE,
24389580 17404 .parent_node = CONFIG_NODE,
62b346ee 17405 .prompt = "%s(config-router)# ",
612c2c15 17406 .config_write = bgp_config_write,
718e3744 17407};
17408
d62a17ae 17409static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 17410 .name = "bgp ipv4 unicast",
62b346ee 17411 .node = BGP_IPV4_NODE,
24389580 17412 .parent_node = BGP_NODE,
62b346ee 17413 .prompt = "%s(config-router-af)# ",
dd2c81b8 17414 .no_xpath = true,
718e3744 17415};
17416
d62a17ae 17417static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 17418 .name = "bgp ipv4 multicast",
62b346ee 17419 .node = BGP_IPV4M_NODE,
24389580 17420 .parent_node = BGP_NODE,
62b346ee 17421 .prompt = "%s(config-router-af)# ",
dd2c81b8 17422 .no_xpath = true,
718e3744 17423};
17424
d62a17ae 17425static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 17426 .name = "bgp ipv4 labeled unicast",
62b346ee 17427 .node = BGP_IPV4L_NODE,
24389580 17428 .parent_node = BGP_NODE,
62b346ee 17429 .prompt = "%s(config-router-af)# ",
dd2c81b8 17430 .no_xpath = true,
f51bae9c
DS
17431};
17432
d62a17ae 17433static struct cmd_node bgp_ipv6_unicast_node = {
a17cfb3f 17434 .name = "bgp ipv6 unicast",
62b346ee 17435 .node = BGP_IPV6_NODE,
24389580 17436 .parent_node = BGP_NODE,
62b346ee 17437 .prompt = "%s(config-router-af)# ",
dd2c81b8 17438 .no_xpath = true,
718e3744 17439};
17440
d62a17ae 17441static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 17442 .name = "bgp ipv6 multicast",
62b346ee 17443 .node = BGP_IPV6M_NODE,
24389580 17444 .parent_node = BGP_NODE,
62b346ee 17445 .prompt = "%s(config-router-af)# ",
dd2c81b8 17446 .no_xpath = true,
25ffbdc1 17447};
17448
d62a17ae 17449static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 17450 .name = "bgp ipv6 labeled unicast",
62b346ee 17451 .node = BGP_IPV6L_NODE,
24389580 17452 .parent_node = BGP_NODE,
62b346ee 17453 .prompt = "%s(config-router-af)# ",
dd2c81b8 17454 .no_xpath = true,
f51bae9c
DS
17455};
17456
62b346ee 17457static struct cmd_node bgp_vpnv4_node = {
f4b8291f 17458 .name = "bgp vpnv4",
62b346ee 17459 .node = BGP_VPNV4_NODE,
24389580 17460 .parent_node = BGP_NODE,
62b346ee 17461 .prompt = "%s(config-router-af)# ",
dd2c81b8 17462 .no_xpath = true,
62b346ee 17463};
6b0655a2 17464
62b346ee 17465static struct cmd_node bgp_vpnv6_node = {
f4b8291f 17466 .name = "bgp vpnv6",
62b346ee 17467 .node = BGP_VPNV6_NODE,
24389580 17468 .parent_node = BGP_NODE,
62b346ee 17469 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 17470 .no_xpath = true,
62b346ee 17471};
8ecd3266 17472
62b346ee 17473static struct cmd_node bgp_evpn_node = {
f4b8291f 17474 .name = "bgp evpn",
62b346ee 17475 .node = BGP_EVPN_NODE,
24389580 17476 .parent_node = BGP_NODE,
62b346ee 17477 .prompt = "%s(config-router-evpn)# ",
dd2c81b8 17478 .no_xpath = true,
62b346ee 17479};
4e0b7b6d 17480
62b346ee 17481static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 17482 .name = "bgp evpn vni",
62b346ee 17483 .node = BGP_EVPN_VNI_NODE,
24389580 17484 .parent_node = BGP_EVPN_NODE,
62b346ee 17485 .prompt = "%s(config-router-af-vni)# ",
62b346ee 17486};
90e60aa7 17487
62b346ee 17488static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 17489 .name = "bgp ipv4 flowspec",
62b346ee 17490 .node = BGP_FLOWSPECV4_NODE,
24389580 17491 .parent_node = BGP_NODE,
62b346ee 17492 .prompt = "%s(config-router-af)# ",
dd2c81b8 17493 .no_xpath = true,
62b346ee 17494};
7c40bf39 17495
62b346ee 17496static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 17497 .name = "bgp ipv6 flowspec",
62b346ee 17498 .node = BGP_FLOWSPECV6_NODE,
24389580 17499 .parent_node = BGP_NODE,
62b346ee 17500 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 17501 .no_xpath = true,
62b346ee 17502};
7c40bf39 17503
bfaab44d
HS
17504static struct cmd_node bgp_srv6_node = {
17505 .name = "bgp srv6",
17506 .node = BGP_SRV6_NODE,
17507 .parent_node = BGP_NODE,
17508 .prompt = "%s(config-router-srv6)# ",
17509};
17510
d62a17ae 17511static void community_list_vty(void);
1f8ae70b 17512
8c20061f
DA
17513static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17514{
17515 struct bgp *bgp;
17516 struct peer_group *group;
17517 struct listnode *lnbgp, *lnpeer;
17518
17519 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17520 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17521 vector_set(comps,
17522 XSTRDUP(MTYPE_COMPLETION, group->name));
17523 }
17524}
17525
17526static void bgp_ac_peer(vector comps, struct cmd_token *token)
b8a815e5 17527{
d62a17ae 17528 struct bgp *bgp;
17529 struct peer *peer;
d62a17ae 17530 struct listnode *lnbgp, *lnpeer;
b8a815e5 17531
d62a17ae 17532 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17533 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17534 /* only provide suggestions on the appropriate input
17535 * token type,
17536 * they'll otherwise show up multiple times */
17537 enum cmd_token_type match_type;
17538 char *name = peer->host;
d48ed3e0 17539
d62a17ae 17540 if (peer->conf_if) {
17541 match_type = VARIABLE_TKN;
17542 name = peer->conf_if;
17543 } else if (strchr(peer->host, ':'))
17544 match_type = IPV6_TKN;
17545 else
17546 match_type = IPV4_TKN;
d48ed3e0 17547
d62a17ae 17548 if (token->type != match_type)
17549 continue;
d48ed3e0 17550
d62a17ae 17551 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17552 }
d62a17ae 17553 }
b8a815e5
DL
17554}
17555
8c20061f
DA
17556static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17557{
17558 bgp_ac_peer(comps, token);
84de1483
DA
17559
17560 if (token->type == VARIABLE_TKN)
17561 bgp_ac_peergroup(comps, token);
8c20061f
DA
17562}
17563
b8a815e5 17564static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 17565 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17566 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 17567 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 17568 {.completions = NULL}};
17569
47a306a0
DS
17570static const struct cmd_variable_handler bgp_var_peergroup[] = {
17571 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17572 {.completions = NULL} };
17573
d62a17ae 17574void bgp_vty_init(void)
17575{
17576 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 17577 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 17578
17579 /* Install bgp top node. */
612c2c15
DL
17580 install_node(&bgp_node);
17581 install_node(&bgp_ipv4_unicast_node);
17582 install_node(&bgp_ipv4_multicast_node);
17583 install_node(&bgp_ipv4_labeled_unicast_node);
17584 install_node(&bgp_ipv6_unicast_node);
17585 install_node(&bgp_ipv6_multicast_node);
17586 install_node(&bgp_ipv6_labeled_unicast_node);
17587 install_node(&bgp_vpnv4_node);
17588 install_node(&bgp_vpnv6_node);
17589 install_node(&bgp_evpn_node);
17590 install_node(&bgp_evpn_vni_node);
17591 install_node(&bgp_flowspecv4_node);
17592 install_node(&bgp_flowspecv6_node);
bfaab44d 17593 install_node(&bgp_srv6_node);
d62a17ae 17594
17595 /* Install default VTY commands to new nodes. */
17596 install_default(BGP_NODE);
17597 install_default(BGP_IPV4_NODE);
17598 install_default(BGP_IPV4M_NODE);
17599 install_default(BGP_IPV4L_NODE);
17600 install_default(BGP_IPV6_NODE);
17601 install_default(BGP_IPV6M_NODE);
17602 install_default(BGP_IPV6L_NODE);
17603 install_default(BGP_VPNV4_NODE);
17604 install_default(BGP_VPNV6_NODE);
7c40bf39 17605 install_default(BGP_FLOWSPECV4_NODE);
17606 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 17607 install_default(BGP_EVPN_NODE);
17608 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 17609 install_default(BGP_SRV6_NODE);
d62a17ae 17610
8029b216
AK
17611 /* "bgp local-mac" hidden commands. */
17612 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17613 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17614
9acb67cb
DS
17615 /* "bgp suppress-fib-pending" global */
17616 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17617
d62a17ae 17618 /* bgp route-map delay-timer commands. */
17619 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17620 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17621
f852eb98
PG
17622 /* bgp fast-convergence command */
17623 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
17624 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
17625
d70583f7
D
17626 /* global bgp update-delay command */
17627 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17628 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17629
05bd726c 17630 /* global bgp graceful-shutdown command */
17631 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17632 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17633
d62a17ae 17634 /* Dummy commands (Currently not supported) */
17635 install_element(BGP_NODE, &no_synchronization_cmd);
17636 install_element(BGP_NODE, &no_auto_summary_cmd);
17637
17638 /* "router bgp" commands. */
17639 install_element(CONFIG_NODE, &router_bgp_cmd);
17640
17641 /* "no router bgp" commands. */
17642 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17643
17644 /* "bgp router-id" commands. */
17645 install_element(BGP_NODE, &bgp_router_id_cmd);
17646 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17647
c208c586
S
17648 /* "bgp suppress-fib-pending" command */
17649 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17650
d62a17ae 17651 /* "bgp cluster-id" commands. */
17652 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17653 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17654
c163f297
DS
17655 /* "bgp no-rib" commands. */
17656 install_element(CONFIG_NODE, &bgp_norib_cmd);
17657 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17658
e46723a5
DS
17659 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17660
d62a17ae 17661 /* "bgp confederation" commands. */
17662 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17663 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17664
17665 /* "bgp confederation peers" commands. */
17666 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17667 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17668
17669 /* bgp max-med command */
17670 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17671 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17672 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17673 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17674 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17675
17676 /* bgp disable-ebgp-connected-nh-check */
17677 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17678 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17679
17680 /* bgp update-delay command */
17681 install_element(BGP_NODE, &bgp_update_delay_cmd);
17682 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 17683
17684 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 17685 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 17686
17687 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17688 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17689
17690 /* "maximum-paths" commands. */
17691 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17692 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17693 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17694 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17695 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17696 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17697 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17698 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17699 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17700 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17701 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17702 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17703 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17704 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17705 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17706
39edabac
PG
17707 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17708 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17709 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17710 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17711 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 17712 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17713 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17714 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17715 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17716 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17717
17718 /* "timers bgp" commands. */
17719 install_element(BGP_NODE, &bgp_timers_cmd);
17720 install_element(BGP_NODE, &no_bgp_timers_cmd);
17721
b042667a
TI
17722 /* "minimum-holdtime" commands. */
17723 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
17724 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
17725
d62a17ae 17726 /* route-map delay-timer commands - per instance for backwards compat.
17727 */
17728 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17729 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17730
17731 /* "bgp client-to-client reflection" commands */
17732 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17733 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17734
17735 /* "bgp always-compare-med" commands */
17736 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17737 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17738
9dac9fc8
DA
17739 /* bgp ebgp-requires-policy */
17740 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17741 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17742
2adac256
DA
17743 /* bgp suppress-duplicates */
17744 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17745 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17746
fb29348a
DA
17747 /* bgp reject-as-sets */
17748 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17749 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17750
d62a17ae 17751 /* "bgp deterministic-med" commands */
17752 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17753 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17754
055679e9 17755 /* "bgp graceful-restart" command */
36235319
QY
17756 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17757 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 17758
17759 /* "bgp graceful-restart-disable" command */
36235319
QY
17760 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17761 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 17762
17763 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
17764 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17765 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 17766
17767 /* "neighbor a:b:c:d graceful-restart-disable" command */
17768 install_element(BGP_NODE,
17769 &bgp_neighbor_graceful_restart_disable_set_cmd);
17770 install_element(BGP_NODE,
17771 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17772
17773 /* "neighbor a:b:c:d graceful-restart-helper" command */
17774 install_element(BGP_NODE,
17775 &bgp_neighbor_graceful_restart_helper_set_cmd);
17776 install_element(BGP_NODE,
17777 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17778
d62a17ae 17779 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17780 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17781 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17782 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 17783 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 17784 install_element(BGP_NODE,
17785 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 17786 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17787 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17788
d6e3c15b 17789 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17790 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 17791 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17792 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 17793
7f323236
DW
17794 /* "bgp graceful-shutdown" commands */
17795 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17796 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17797
8606be87
DA
17798 /* "bgp long-lived-graceful-restart" commands */
17799 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
17800 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
17801
d62a17ae 17802 /* "bgp fast-external-failover" commands */
17803 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17804 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17805
d62a17ae 17806 /* "bgp bestpath compare-routerid" commands */
17807 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17808 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17809
17810 /* "bgp bestpath as-path ignore" commands */
17811 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17812 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17813
17814 /* "bgp bestpath as-path confed" commands */
17815 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17816 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17817
17818 /* "bgp bestpath as-path multipath-relax" commands */
17819 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17820 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17821
ee88563a
JM
17822 /* "bgp bestpath peer-type multipath-relax" commands */
17823 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
17824 install_element(BGP_NODE,
17825 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
17826
d62a17ae 17827 /* "bgp log-neighbor-changes" commands */
17828 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17829 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17830
17831 /* "bgp bestpath med" commands */
17832 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17833 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17834
f7e1c681 17835 /* "bgp bestpath bandwidth" commands */
17836 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 17837 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 17838
b16bcbba
TA
17839 /* "no bgp default <afi>-<safi>" commands. */
17840 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
e84c59af 17841
d62a17ae 17842 /* "bgp network import-check" commands. */
17843 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17844 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17845 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17846
17847 /* "bgp default local-preference" commands. */
17848 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17849 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17850
17851 /* bgp default show-hostname */
17852 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17853 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17854
aef999a2
DA
17855 /* bgp default show-nexthop-hostname */
17856 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17857 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17858
d62a17ae 17859 /* "bgp default subgroup-pkt-queue-max" commands. */
17860 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17861 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17862
17863 /* bgp ibgp-allow-policy-mods command */
17864 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17865 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17866
17867 /* "bgp listen limit" commands. */
17868 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17869 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17870
17871 /* "bgp listen range" commands. */
17872 install_element(BGP_NODE, &bgp_listen_range_cmd);
17873 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17874
8175f54a 17875 /* "bgp default shutdown" command */
f26845f9 17876 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
17877
17878 /* "bgp shutdown" commands */
17879 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 17880 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 17881 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 17882 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 17883
d62a17ae 17884 /* "neighbor remote-as" commands. */
17885 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17886 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17887 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17888 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17889 install_element(BGP_NODE,
17890 &neighbor_interface_v6only_config_remote_as_cmd);
17891 install_element(BGP_NODE, &no_neighbor_cmd);
17892 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17893
17894 /* "neighbor peer-group" commands. */
17895 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17896 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17897 install_element(BGP_NODE,
17898 &no_neighbor_interface_peer_group_remote_as_cmd);
17899
17900 /* "neighbor local-as" commands. */
17901 install_element(BGP_NODE, &neighbor_local_as_cmd);
17902 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17903 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17904 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17905
17906 /* "neighbor solo" commands. */
17907 install_element(BGP_NODE, &neighbor_solo_cmd);
17908 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17909
17910 /* "neighbor password" commands. */
17911 install_element(BGP_NODE, &neighbor_password_cmd);
17912 install_element(BGP_NODE, &no_neighbor_password_cmd);
17913
17914 /* "neighbor activate" commands. */
17915 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17916 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17917 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17918 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17919 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17920 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17921 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17922 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
17923 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 17924 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
17925 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 17926 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
17927
17928 /* "no neighbor activate" commands. */
17929 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
17930 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
17931 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
17932 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
17933 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
17934 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
17935 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
17936 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
17937 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 17938 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
17939 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 17940 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
17941
17942 /* "neighbor peer-group" set commands. */
17943 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
17944 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17945 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
17946 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17947 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
17948 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
17949 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17950 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 17951 install_element(BGP_FLOWSPECV4_NODE,
17952 &neighbor_set_peer_group_hidden_cmd);
17953 install_element(BGP_FLOWSPECV6_NODE,
17954 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 17955
17956 /* "no neighbor peer-group unset" commands. */
17957 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
17958 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17959 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17960 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17961 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17962 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17963 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17964 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 17965 install_element(BGP_FLOWSPECV4_NODE,
17966 &no_neighbor_set_peer_group_hidden_cmd);
17967 install_element(BGP_FLOWSPECV6_NODE,
17968 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 17969
17970 /* "neighbor softreconfiguration inbound" commands.*/
17971 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
17972 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
17973 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
17974 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17975 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
17976 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17977 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
17978 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17979 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
17980 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17981 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
17982 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17983 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
17984 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17985 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
17986 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17987 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
17988 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 17989 install_element(BGP_FLOWSPECV4_NODE,
17990 &neighbor_soft_reconfiguration_cmd);
17991 install_element(BGP_FLOWSPECV4_NODE,
17992 &no_neighbor_soft_reconfiguration_cmd);
17993 install_element(BGP_FLOWSPECV6_NODE,
17994 &neighbor_soft_reconfiguration_cmd);
17995 install_element(BGP_FLOWSPECV6_NODE,
17996 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
17997 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
17998 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 17999
18000 /* "neighbor attribute-unchanged" commands. */
18001 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18002 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18003 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18004 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18005 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18006 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18007 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18008 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18009 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18010 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18011 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18012 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18013 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18014 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18015 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18016 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18017 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18018 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18019
18020 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18021 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18022
b8ad84d2
PG
18023 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18024 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18025 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18026 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18027
d62a17ae 18028 /* "nexthop-local unchanged" commands */
18029 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18030 install_element(BGP_IPV6_NODE,
18031 &no_neighbor_nexthop_local_unchanged_cmd);
18032
18033 /* "neighbor next-hop-self" commands. */
18034 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18035 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18036 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18037 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18038 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18039 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18040 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18041 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18042 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18043 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18044 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18045 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18046 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18047 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18048 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18049 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18050 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18051 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
18052 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18053 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 18054
18055 /* "neighbor next-hop-self force" commands. */
18056 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18057 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
18058 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18059 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18060 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18061 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18062 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18063 install_element(BGP_IPV4_NODE,
18064 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18065 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18066 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18067 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18068 install_element(BGP_IPV4M_NODE,
18069 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18070 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18071 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18072 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18073 install_element(BGP_IPV4L_NODE,
18074 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18075 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18076 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18077 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18078 install_element(BGP_IPV6_NODE,
18079 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18080 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18081 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18082 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18083 install_element(BGP_IPV6M_NODE,
18084 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18085 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18086 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18087 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18088 install_element(BGP_IPV6L_NODE,
18089 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18090 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18091 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18092 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18093 install_element(BGP_VPNV4_NODE,
18094 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18095 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18096 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18097 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18098 install_element(BGP_VPNV6_NODE,
18099 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
18100 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18101 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 18102
18103 /* "neighbor as-override" commands. */
18104 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18105 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18106 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18107 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18108 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18109 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18110 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18111 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18112 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18113 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18114 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18115 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18116 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18117 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18118 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18119 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18120 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18121 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18122
18123 /* "neighbor remove-private-AS" commands. */
18124 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18125 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18126 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18127 install_element(BGP_NODE,
18128 &no_neighbor_remove_private_as_all_hidden_cmd);
18129 install_element(BGP_NODE,
18130 &neighbor_remove_private_as_replace_as_hidden_cmd);
18131 install_element(BGP_NODE,
18132 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18133 install_element(BGP_NODE,
18134 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18135 install_element(
18136 BGP_NODE,
18137 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18138 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18139 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18140 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18141 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18142 install_element(BGP_IPV4_NODE,
18143 &neighbor_remove_private_as_replace_as_cmd);
18144 install_element(BGP_IPV4_NODE,
18145 &no_neighbor_remove_private_as_replace_as_cmd);
18146 install_element(BGP_IPV4_NODE,
18147 &neighbor_remove_private_as_all_replace_as_cmd);
18148 install_element(BGP_IPV4_NODE,
18149 &no_neighbor_remove_private_as_all_replace_as_cmd);
18150 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18151 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18152 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18153 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18154 install_element(BGP_IPV4M_NODE,
18155 &neighbor_remove_private_as_replace_as_cmd);
18156 install_element(BGP_IPV4M_NODE,
18157 &no_neighbor_remove_private_as_replace_as_cmd);
18158 install_element(BGP_IPV4M_NODE,
18159 &neighbor_remove_private_as_all_replace_as_cmd);
18160 install_element(BGP_IPV4M_NODE,
18161 &no_neighbor_remove_private_as_all_replace_as_cmd);
18162 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18163 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18164 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18165 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18166 install_element(BGP_IPV4L_NODE,
18167 &neighbor_remove_private_as_replace_as_cmd);
18168 install_element(BGP_IPV4L_NODE,
18169 &no_neighbor_remove_private_as_replace_as_cmd);
18170 install_element(BGP_IPV4L_NODE,
18171 &neighbor_remove_private_as_all_replace_as_cmd);
18172 install_element(BGP_IPV4L_NODE,
18173 &no_neighbor_remove_private_as_all_replace_as_cmd);
18174 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18175 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18176 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18177 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18178 install_element(BGP_IPV6_NODE,
18179 &neighbor_remove_private_as_replace_as_cmd);
18180 install_element(BGP_IPV6_NODE,
18181 &no_neighbor_remove_private_as_replace_as_cmd);
18182 install_element(BGP_IPV6_NODE,
18183 &neighbor_remove_private_as_all_replace_as_cmd);
18184 install_element(BGP_IPV6_NODE,
18185 &no_neighbor_remove_private_as_all_replace_as_cmd);
18186 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18187 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18188 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18189 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18190 install_element(BGP_IPV6M_NODE,
18191 &neighbor_remove_private_as_replace_as_cmd);
18192 install_element(BGP_IPV6M_NODE,
18193 &no_neighbor_remove_private_as_replace_as_cmd);
18194 install_element(BGP_IPV6M_NODE,
18195 &neighbor_remove_private_as_all_replace_as_cmd);
18196 install_element(BGP_IPV6M_NODE,
18197 &no_neighbor_remove_private_as_all_replace_as_cmd);
18198 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18199 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18200 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18201 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18202 install_element(BGP_IPV6L_NODE,
18203 &neighbor_remove_private_as_replace_as_cmd);
18204 install_element(BGP_IPV6L_NODE,
18205 &no_neighbor_remove_private_as_replace_as_cmd);
18206 install_element(BGP_IPV6L_NODE,
18207 &neighbor_remove_private_as_all_replace_as_cmd);
18208 install_element(BGP_IPV6L_NODE,
18209 &no_neighbor_remove_private_as_all_replace_as_cmd);
18210 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18211 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18212 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18213 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18214 install_element(BGP_VPNV4_NODE,
18215 &neighbor_remove_private_as_replace_as_cmd);
18216 install_element(BGP_VPNV4_NODE,
18217 &no_neighbor_remove_private_as_replace_as_cmd);
18218 install_element(BGP_VPNV4_NODE,
18219 &neighbor_remove_private_as_all_replace_as_cmd);
18220 install_element(BGP_VPNV4_NODE,
18221 &no_neighbor_remove_private_as_all_replace_as_cmd);
18222 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18223 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18224 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18225 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18226 install_element(BGP_VPNV6_NODE,
18227 &neighbor_remove_private_as_replace_as_cmd);
18228 install_element(BGP_VPNV6_NODE,
18229 &no_neighbor_remove_private_as_replace_as_cmd);
18230 install_element(BGP_VPNV6_NODE,
18231 &neighbor_remove_private_as_all_replace_as_cmd);
18232 install_element(BGP_VPNV6_NODE,
18233 &no_neighbor_remove_private_as_all_replace_as_cmd);
18234
18235 /* "neighbor send-community" commands.*/
18236 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18237 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18238 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18239 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18240 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18241 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18242 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18243 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18244 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18245 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18246 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18247 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18248 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18249 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18250 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18251 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18252 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18253 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18254 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18255 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18256 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18257 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18258 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18259 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18260 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18261 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18262 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18263 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18264 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18265 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18266 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18267 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18268 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18269 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18270 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18271 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18272
18273 /* "neighbor route-reflector" commands.*/
18274 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18275 install_element(BGP_NODE,
18276 &no_neighbor_route_reflector_client_hidden_cmd);
18277 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18278 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18279 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18280 install_element(BGP_IPV4M_NODE,
18281 &no_neighbor_route_reflector_client_cmd);
18282 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18283 install_element(BGP_IPV4L_NODE,
18284 &no_neighbor_route_reflector_client_cmd);
18285 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18286 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18287 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18288 install_element(BGP_IPV6M_NODE,
18289 &no_neighbor_route_reflector_client_cmd);
18290 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18291 install_element(BGP_IPV6L_NODE,
18292 &no_neighbor_route_reflector_client_cmd);
18293 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18294 install_element(BGP_VPNV4_NODE,
18295 &no_neighbor_route_reflector_client_cmd);
18296 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18297 install_element(BGP_VPNV6_NODE,
18298 &no_neighbor_route_reflector_client_cmd);
7c40bf39 18299 install_element(BGP_FLOWSPECV4_NODE,
18300 &neighbor_route_reflector_client_cmd);
18301 install_element(BGP_FLOWSPECV4_NODE,
18302 &no_neighbor_route_reflector_client_cmd);
18303 install_element(BGP_FLOWSPECV6_NODE,
18304 &neighbor_route_reflector_client_cmd);
18305 install_element(BGP_FLOWSPECV6_NODE,
18306 &no_neighbor_route_reflector_client_cmd);
d62a17ae 18307 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18308 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18309
18310 /* "neighbor route-server" commands.*/
18311 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18312 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18313 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18314 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18315 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18316 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18317 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18318 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18319 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18320 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18321 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18322 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18323 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18324 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18325 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18326 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18327 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18328 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
18329 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18330 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 18331 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18332 install_element(BGP_FLOWSPECV4_NODE,
18333 &no_neighbor_route_server_client_cmd);
18334 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18335 install_element(BGP_FLOWSPECV6_NODE,
18336 &no_neighbor_route_server_client_cmd);
d62a17ae 18337
7c0e4312
DA
18338 /* "neighbor disable-addpath-rx" commands. */
18339 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
18340 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18341 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
18342 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18343 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
18344 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18345 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
18346 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18347 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
18348 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18349 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
18350 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18351 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
18352 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18353 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
18354 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18355
d62a17ae 18356 /* "neighbor addpath-tx-all-paths" commands.*/
18357 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18358 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18359 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18360 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18361 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18362 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18363 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18364 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18365 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18366 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18367 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18368 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18369 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18370 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18371 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18372 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18373 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18374 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18375
18376 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18377 install_element(BGP_NODE,
18378 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18379 install_element(BGP_NODE,
18380 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18381 install_element(BGP_IPV4_NODE,
18382 &neighbor_addpath_tx_bestpath_per_as_cmd);
18383 install_element(BGP_IPV4_NODE,
18384 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18385 install_element(BGP_IPV4M_NODE,
18386 &neighbor_addpath_tx_bestpath_per_as_cmd);
18387 install_element(BGP_IPV4M_NODE,
18388 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18389 install_element(BGP_IPV4L_NODE,
18390 &neighbor_addpath_tx_bestpath_per_as_cmd);
18391 install_element(BGP_IPV4L_NODE,
18392 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18393 install_element(BGP_IPV6_NODE,
18394 &neighbor_addpath_tx_bestpath_per_as_cmd);
18395 install_element(BGP_IPV6_NODE,
18396 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18397 install_element(BGP_IPV6M_NODE,
18398 &neighbor_addpath_tx_bestpath_per_as_cmd);
18399 install_element(BGP_IPV6M_NODE,
18400 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18401 install_element(BGP_IPV6L_NODE,
18402 &neighbor_addpath_tx_bestpath_per_as_cmd);
18403 install_element(BGP_IPV6L_NODE,
18404 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18405 install_element(BGP_VPNV4_NODE,
18406 &neighbor_addpath_tx_bestpath_per_as_cmd);
18407 install_element(BGP_VPNV4_NODE,
18408 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18409 install_element(BGP_VPNV6_NODE,
18410 &neighbor_addpath_tx_bestpath_per_as_cmd);
18411 install_element(BGP_VPNV6_NODE,
18412 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18413
2b31007c
RZ
18414 /* "neighbor sender-as-path-loop-detection" commands. */
18415 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18416 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18417
d62a17ae 18418 /* "neighbor passive" commands. */
18419 install_element(BGP_NODE, &neighbor_passive_cmd);
18420 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18421
18422
18423 /* "neighbor shutdown" commands. */
18424 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18425 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18426 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18427 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
18428 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18429 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 18430
18431 /* "neighbor capability extended-nexthop" commands.*/
18432 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18433 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18434
18435 /* "neighbor capability orf prefix-list" commands.*/
18436 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18437 install_element(BGP_NODE,
18438 &no_neighbor_capability_orf_prefix_hidden_cmd);
18439 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18440 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18441 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18442 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18443 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18444 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18445 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18446 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18447 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18448 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18449 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18450 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18451
18452 /* "neighbor capability dynamic" commands.*/
18453 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18454 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18455
18456 /* "neighbor dont-capability-negotiate" commands. */
18457 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18458 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18459
18460 /* "neighbor ebgp-multihop" commands. */
18461 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18462 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18463 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18464
18465 /* "neighbor disable-connected-check" commands. */
18466 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18467 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18468
7ab294ea
DA
18469 /* "neighbor disable-link-bw-encoding-ieee" commands. */
18470 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
18471 install_element(BGP_NODE,
18472 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
27aa23a4 18473
d08c0c80
DA
18474 /* "neighbor extended-optional-parameters" commands. */
18475 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
18476 install_element(BGP_NODE,
18477 &no_neighbor_extended_optional_parameters_cmd);
18478
47cbc09b
PM
18479 /* "neighbor enforce-first-as" commands. */
18480 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18481 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18482
d62a17ae 18483 /* "neighbor description" commands. */
18484 install_element(BGP_NODE, &neighbor_description_cmd);
18485 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 18486 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 18487
18488 /* "neighbor update-source" commands. "*/
18489 install_element(BGP_NODE, &neighbor_update_source_cmd);
18490 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18491
18492 /* "neighbor default-originate" commands. */
18493 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18494 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18495 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18496 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18497 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18498 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18499 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18500 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18501 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18502 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18503 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18504 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18505 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18506 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18507 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18508 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18509 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18510 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18511 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18512 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18513 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18514
18515 /* "neighbor port" commands. */
18516 install_element(BGP_NODE, &neighbor_port_cmd);
18517 install_element(BGP_NODE, &no_neighbor_port_cmd);
18518
18519 /* "neighbor weight" commands. */
18520 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18521 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18522
18523 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18524 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18525 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18526 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18527 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18528 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18529 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18530 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18531 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18532 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18533 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18534 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18535 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18536 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18537 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18538 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18539
18540 /* "neighbor override-capability" commands. */
18541 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18542 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18543
18544 /* "neighbor strict-capability-match" commands. */
18545 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18546 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18547
18548 /* "neighbor timers" commands. */
18549 install_element(BGP_NODE, &neighbor_timers_cmd);
18550 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18551
18552 /* "neighbor timers connect" commands. */
18553 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18554 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18555
d43114f3
DS
18556 /* "neighbor timers delayopen" commands. */
18557 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18558 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18559
d62a17ae 18560 /* "neighbor advertisement-interval" commands. */
18561 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18562 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18563
18564 /* "neighbor interface" commands. */
18565 install_element(BGP_NODE, &neighbor_interface_cmd);
18566 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18567
18568 /* "neighbor distribute" commands. */
18569 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18570 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18571 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18572 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18573 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18574 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18575 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18576 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18577 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18578 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18579 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18580 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18581 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18582 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18583 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18584 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18585 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18586 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18587
18588 /* "neighbor prefix-list" commands. */
18589 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
642ef664 18590 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
d62a17ae 18591 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18592 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18593 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
642ef664 18594 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18595 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
642ef664 18596 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18597 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18598 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18599 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
642ef664 18600 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18601 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
642ef664 18602 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18603 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18604 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18605 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18606 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18607 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18608 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18609 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18610 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18611
18612 /* "neighbor filter-list" commands. */
18613 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18614 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18615 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18616 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18617 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18618 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18619 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18620 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18621 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18622 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18623 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18624 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18625 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18626 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18627 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18628 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18629 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18630 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 18631 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18632 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18633 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18634 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 18635
18636 /* "neighbor route-map" commands. */
d6d7ed37
IR
18637 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18638 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
d62a17ae 18639 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18640 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18641 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
0ea8d871 18642 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18643 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
0ea8d871 18644 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18645 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18646 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18647 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
0ea8d871 18648 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18649 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
0ea8d871 18650 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18651 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18652 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18653 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18654 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18655 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18656 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18657 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18658 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549 18659 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
0ea8d871 18660 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18661
18662 /* "neighbor unsuppress-map" commands. */
18663 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18664 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18665 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18666 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18667 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18668 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18669 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18670 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18671 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18672 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18673 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18674 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18675 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18676 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18677 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18678 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18679 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18680 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18681
7f7940e6 18682 /* "neighbor advertise-map" commands. */
389e4f92 18683 install_element(BGP_NODE, &bgp_condadv_period_cmd);
7f7940e6 18684 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 18685 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18686 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18687 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18688 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18689 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18690 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18691 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18692 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18693
fde246e8
DA
18694 /* neighbor maximum-prefix-out commands. */
18695 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18696 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18697 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18698 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18699 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18700 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18701 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18702 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18703 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18704 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18705 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18706 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18707 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18708 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18709 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18710 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18711 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18712 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18713
d62a17ae 18714 /* "neighbor maximum-prefix" commands. */
18715 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18716 install_element(BGP_NODE,
18717 &neighbor_maximum_prefix_threshold_hidden_cmd);
18718 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18719 install_element(BGP_NODE,
18720 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18721 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18722 install_element(BGP_NODE,
18723 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18724 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18725 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18726 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18727 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18728 install_element(BGP_IPV4_NODE,
18729 &neighbor_maximum_prefix_threshold_warning_cmd);
18730 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18731 install_element(BGP_IPV4_NODE,
18732 &neighbor_maximum_prefix_threshold_restart_cmd);
18733 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18734 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18735 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18736 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18737 install_element(BGP_IPV4M_NODE,
18738 &neighbor_maximum_prefix_threshold_warning_cmd);
18739 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18740 install_element(BGP_IPV4M_NODE,
18741 &neighbor_maximum_prefix_threshold_restart_cmd);
18742 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18743 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18744 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18745 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18746 install_element(BGP_IPV4L_NODE,
18747 &neighbor_maximum_prefix_threshold_warning_cmd);
18748 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18749 install_element(BGP_IPV4L_NODE,
18750 &neighbor_maximum_prefix_threshold_restart_cmd);
18751 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18752 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18753 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18754 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18755 install_element(BGP_IPV6_NODE,
18756 &neighbor_maximum_prefix_threshold_warning_cmd);
18757 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18758 install_element(BGP_IPV6_NODE,
18759 &neighbor_maximum_prefix_threshold_restart_cmd);
18760 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18761 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18762 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18763 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18764 install_element(BGP_IPV6M_NODE,
18765 &neighbor_maximum_prefix_threshold_warning_cmd);
18766 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18767 install_element(BGP_IPV6M_NODE,
18768 &neighbor_maximum_prefix_threshold_restart_cmd);
18769 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18770 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18771 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18772 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18773 install_element(BGP_IPV6L_NODE,
18774 &neighbor_maximum_prefix_threshold_warning_cmd);
18775 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18776 install_element(BGP_IPV6L_NODE,
18777 &neighbor_maximum_prefix_threshold_restart_cmd);
18778 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18779 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18780 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18781 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18782 install_element(BGP_VPNV4_NODE,
18783 &neighbor_maximum_prefix_threshold_warning_cmd);
18784 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18785 install_element(BGP_VPNV4_NODE,
18786 &neighbor_maximum_prefix_threshold_restart_cmd);
18787 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18788 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18789 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18790 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18791 install_element(BGP_VPNV6_NODE,
18792 &neighbor_maximum_prefix_threshold_warning_cmd);
18793 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18794 install_element(BGP_VPNV6_NODE,
18795 &neighbor_maximum_prefix_threshold_restart_cmd);
18796 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18797
18798 /* "neighbor allowas-in" */
18799 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18800 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18801 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18802 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18803 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18804 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18805 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18806 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18807 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18808 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18809 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18810 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18811 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18812 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18813 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18814 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18815 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18816 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18817 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18818 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18819
18820 /* address-family commands. */
18821 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18822 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 18823#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 18824 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18825 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 18826#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 18827
d62a17ae 18828 install_element(BGP_NODE, &address_family_evpn_cmd);
18829
18830 /* "exit-address-family" command. */
18831 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18832 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18833 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18834 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18835 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18836 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18837 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18838 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 18839 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18840 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 18841 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18842
18843 /* "clear ip bgp commands" */
18844 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18845
18846 /* clear ip bgp prefix */
18847 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18848 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18849 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18850
18851 /* "show [ip] bgp summary" commands. */
18852 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 18853 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 18854 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 18855 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 18856 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18857 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 18858 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18859
18860 /* "show [ip] bgp neighbors" commands. */
18861 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18862
36235319 18863 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 18864
d62a17ae 18865 /* "show [ip] bgp peer-group" commands. */
18866 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18867
18868 /* "show [ip] bgp paths" commands. */
18869 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18870
18871 /* "show [ip] bgp community" commands. */
18872 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18873
18874 /* "show ip bgp large-community" commands. */
18875 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18876 /* "show [ip] bgp attribute-info" commands. */
18877 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 18878 /* "show [ip] bgp route-leak" command */
18879 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 18880
18881 /* "redistribute" commands. */
18882 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18883 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18884 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18885 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18886 install_element(BGP_NODE,
18887 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18888 install_element(BGP_NODE,
18889 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18890 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18891 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18892 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18893 install_element(BGP_NODE,
18894 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18895 install_element(BGP_NODE,
18896 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18897 install_element(BGP_NODE,
18898 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18899 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18900 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18901 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18902 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18903 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18904 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18905 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18906 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18907 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18908 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18909 install_element(BGP_IPV4_NODE,
18910 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18911 install_element(BGP_IPV4_NODE,
18912 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18913 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18914 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18915 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18916 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18917 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18918 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18919
b9c7bc5a
PZ
18920 /* import|export vpn [route-map WORD] */
18921 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18922 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 18923
12a844a5
DS
18924 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18925 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18926
d62a17ae 18927 /* ttl_security commands */
18928 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18929 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18930
18931 /* "show [ip] bgp memory" commands. */
18932 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18933
acf71666
MK
18934 /* "show bgp martian next-hop" */
18935 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18936
48ecf8f5
DS
18937 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18938
d62a17ae 18939 /* "show [ip] bgp views" commands. */
18940 install_element(VIEW_NODE, &show_bgp_views_cmd);
18941
18942 /* "show [ip] bgp vrfs" commands. */
18943 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
18944
18945 /* Community-list. */
18946 community_list_vty();
ddb5b488 18947
ed0e57e3
DA
18948 community_alias_vty();
18949
ddb5b488 18950 /* vpn-policy commands */
b9c7bc5a
PZ
18951 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
18952 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
18953 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
18954 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
18955 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
18956 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
18957 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
18958 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
18959 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
18960 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
18961 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
18962 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 18963
301ad80a
PG
18964 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
18965 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
18966
b9c7bc5a
PZ
18967 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
18968 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
18969 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
18970 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
18971 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
18972 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
18973 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
18974 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
18975 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
18976 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
18977
18978 /* tcp-mss command */
18979 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
18980 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
18981
18982 /* srv6 commands */
ea372e81 18983 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
bfaab44d 18984 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
0249b8b6 18985 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
a0281b2e 18986 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
0249b8b6 18987 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
b72c9e14
HS
18988 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
18989 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
718e3744 18990}
6b0655a2 18991
718e3744 18992#include "memory.h"
18993#include "bgp_regex.h"
18994#include "bgp_clist.h"
18995#include "bgp_ecommunity.h"
18996
18997/* VTY functions. */
18998
18999/* Direction value to string conversion. */
d62a17ae 19000static const char *community_direct_str(int direct)
19001{
19002 switch (direct) {
19003 case COMMUNITY_DENY:
19004 return "deny";
19005 case COMMUNITY_PERMIT:
19006 return "permit";
19007 default:
19008 return "unknown";
19009 }
718e3744 19010}
19011
19012/* Display error string. */
d62a17ae 19013static void community_list_perror(struct vty *vty, int ret)
19014{
19015 switch (ret) {
19016 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19017 vty_out(vty, "%% Can't find community-list\n");
19018 break;
19019 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19020 vty_out(vty, "%% Malformed community-list value\n");
19021 break;
19022 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19023 vty_out(vty,
19024 "%% Community name conflict, previously defined as standard community\n");
19025 break;
19026 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19027 vty_out(vty,
19028 "%% Community name conflict, previously defined as expanded community\n");
19029 break;
19030 }
718e3744 19031}
19032
5bf15956
DW
19033/* "community-list" keyword help string. */
19034#define COMMUNITY_LIST_STR "Add a community list entry\n"
19035
7336e101
SP
19036/*community-list standard */
19037DEFUN (community_list_standard,
19038 bgp_community_list_standard_cmd,
a2099c1d 19039 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19040 BGP_STR
718e3744 19041 COMMUNITY_LIST_STR
19042 "Community list number (standard)\n"
5bf15956 19043 "Add an standard community-list entry\n"
718e3744 19044 "Community list name\n"
2f8cc0e5
DA
19045 "Sequence number of an entry\n"
19046 "Sequence number\n"
718e3744 19047 "Specify community to reject\n"
19048 "Specify community to accept\n"
19049 COMMUNITY_VAL_STR)
19050{
d62a17ae 19051 char *cl_name_or_number = NULL;
2f8cc0e5 19052 char *seq = NULL;
d62a17ae 19053 int direct = 0;
19054 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 19055 int idx = 0;
7336e101 19056
a08032fe 19057 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19058 if (idx)
19059 seq = argv[idx]->arg;
19060
19061 idx = 0;
d62a17ae 19062 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19063 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19064 cl_name_or_number = argv[idx]->arg;
19065 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19066 : COMMUNITY_DENY;
19067 argv_find(argv, argc, "AA:NN", &idx);
19068 char *str = argv_concat(argv, argc, idx);
42f914d4 19069
2f8cc0e5
DA
19070 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19071 direct, style);
42f914d4 19072
d62a17ae 19073 XFREE(MTYPE_TMP, str);
42f914d4 19074
d62a17ae 19075 if (ret < 0) {
19076 /* Display error string. */
19077 community_list_perror(vty, ret);
19078 return CMD_WARNING_CONFIG_FAILED;
19079 }
42f914d4 19080
d62a17ae 19081 return CMD_SUCCESS;
718e3744 19082}
19083
7336e101
SP
19084DEFUN (no_community_list_standard_all,
19085 no_bgp_community_list_standard_all_cmd,
a2099c1d 19086 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19087 NO_STR
19088 BGP_STR
19089 COMMUNITY_LIST_STR
19090 "Community list number (standard)\n"
19091 "Add an standard community-list entry\n"
19092 "Community list name\n"
2f8cc0e5
DA
19093 "Sequence number of an entry\n"
19094 "Sequence number\n"
7336e101
SP
19095 "Specify community to reject\n"
19096 "Specify community to accept\n"
19097 COMMUNITY_VAL_STR)
718e3744 19098{
d62a17ae 19099 char *cl_name_or_number = NULL;
174b5cb9 19100 char *str = NULL;
d62a17ae 19101 int direct = 0;
19102 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 19103 char *seq = NULL;
d62a17ae 19104 int idx = 0;
7336e101 19105
a08032fe 19106 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19107 if (idx)
19108 seq = argv[idx]->arg;
19109
19110 idx = 0;
174b5cb9
DA
19111 argv_find(argv, argc, "permit", &idx);
19112 argv_find(argv, argc, "deny", &idx);
19113
19114 if (idx) {
19115 direct = argv_find(argv, argc, "permit", &idx)
19116 ? COMMUNITY_PERMIT
19117 : COMMUNITY_DENY;
19118
19119 idx = 0;
19120 argv_find(argv, argc, "AA:NN", &idx);
19121 str = argv_concat(argv, argc, idx);
19122 }
19123
19124 idx = 0;
d62a17ae 19125 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19126 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19127 cl_name_or_number = argv[idx]->arg;
42f914d4 19128
2f8cc0e5 19129 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19130 direct, style);
42f914d4 19131
d62a17ae 19132 XFREE(MTYPE_TMP, str);
daf9ddbb 19133
d62a17ae 19134 if (ret < 0) {
19135 community_list_perror(vty, ret);
19136 return CMD_WARNING_CONFIG_FAILED;
19137 }
42f914d4 19138
d62a17ae 19139 return CMD_SUCCESS;
718e3744 19140}
7336e101 19141
174b5cb9 19142ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
a2099c1d 19143 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
174b5cb9
DA
19144 NO_STR BGP_STR COMMUNITY_LIST_STR
19145 "Community list number (standard)\n"
19146 "Add an standard community-list entry\n"
19147 "Community list name\n")
19148
7336e101
SP
19149/*community-list expanded */
19150DEFUN (community_list_expanded_all,
19151 bgp_community_list_expanded_all_cmd,
a2099c1d 19152 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19153 BGP_STR
19154 COMMUNITY_LIST_STR
718e3744 19155 "Community list number (expanded)\n"
5bf15956 19156 "Add an expanded community-list entry\n"
718e3744 19157 "Community list name\n"
2f8cc0e5
DA
19158 "Sequence number of an entry\n"
19159 "Sequence number\n"
718e3744 19160 "Specify community to reject\n"
19161 "Specify community to accept\n"
19162 COMMUNITY_VAL_STR)
19163{
d62a17ae 19164 char *cl_name_or_number = NULL;
2f8cc0e5 19165 char *seq = NULL;
d62a17ae 19166 int direct = 0;
19167 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19168 int idx = 0;
7b9a4750 19169
a08032fe 19170 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19171 if (idx)
19172 seq = argv[idx]->arg;
19173
19174 idx = 0;
19175
d62a17ae 19176 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19177 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19178 cl_name_or_number = argv[idx]->arg;
19179 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19180 : COMMUNITY_DENY;
19181 argv_find(argv, argc, "AA:NN", &idx);
19182 char *str = argv_concat(argv, argc, idx);
42f914d4 19183
2f8cc0e5
DA
19184 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19185 direct, style);
42f914d4 19186
d62a17ae 19187 XFREE(MTYPE_TMP, str);
42f914d4 19188
d62a17ae 19189 if (ret < 0) {
19190 /* Display error string. */
19191 community_list_perror(vty, ret);
19192 return CMD_WARNING_CONFIG_FAILED;
19193 }
42f914d4 19194
d62a17ae 19195 return CMD_SUCCESS;
718e3744 19196}
19197
7336e101
SP
19198DEFUN (no_community_list_expanded_all,
19199 no_bgp_community_list_expanded_all_cmd,
a2099c1d 19200 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19201 NO_STR
19202 BGP_STR
19203 COMMUNITY_LIST_STR
19204 "Community list number (expanded)\n"
19205 "Add an expanded community-list entry\n"
19206 "Community list name\n"
2f8cc0e5
DA
19207 "Sequence number of an entry\n"
19208 "Sequence number\n"
7336e101
SP
19209 "Specify community to reject\n"
19210 "Specify community to accept\n"
19211 COMMUNITY_VAL_STR)
718e3744 19212{
d62a17ae 19213 char *cl_name_or_number = NULL;
2f8cc0e5 19214 char *seq = NULL;
174b5cb9 19215 char *str = NULL;
d62a17ae 19216 int direct = 0;
19217 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19218 int idx = 0;
174b5cb9 19219
a08032fe 19220 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19221 if (idx)
19222 seq = argv[idx]->arg;
19223
19224 idx = 0;
174b5cb9
DA
19225 argv_find(argv, argc, "permit", &idx);
19226 argv_find(argv, argc, "deny", &idx);
19227
19228 if (idx) {
19229 direct = argv_find(argv, argc, "permit", &idx)
19230 ? COMMUNITY_PERMIT
19231 : COMMUNITY_DENY;
19232
19233 idx = 0;
19234 argv_find(argv, argc, "AA:NN", &idx);
19235 str = argv_concat(argv, argc, idx);
7336e101 19236 }
174b5cb9
DA
19237
19238 idx = 0;
d62a17ae 19239 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19240 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19241 cl_name_or_number = argv[idx]->arg;
42f914d4 19242
2f8cc0e5 19243 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19244 direct, style);
42f914d4 19245
d62a17ae 19246 XFREE(MTYPE_TMP, str);
daf9ddbb 19247
d62a17ae 19248 if (ret < 0) {
19249 community_list_perror(vty, ret);
19250 return CMD_WARNING_CONFIG_FAILED;
19251 }
42f914d4 19252
d62a17ae 19253 return CMD_SUCCESS;
718e3744 19254}
19255
36d4bb44
EB
19256ALIAS(no_community_list_expanded_all,
19257 no_bgp_community_list_expanded_all_list_cmd,
a2099c1d 19258 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
36d4bb44 19259 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
19260 "Community list number (expanded)\n"
19261 "Add an expanded community-list entry\n"
19262 "Community list name\n")
19263
8d9b8ed9
PM
19264/* Return configuration string of community-list entry. */
19265static const char *community_list_config_str(struct community_entry *entry)
19266{
19267 const char *str;
19268
19269 if (entry->any)
19270 str = "";
19271 else {
19272 if (entry->style == COMMUNITY_LIST_STANDARD)
19273 str = community_str(entry->u.com, false);
19274 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19275 str = lcommunity_str(entry->u.lcom, false);
19276 else
19277 str = entry->config;
19278 }
19279 return str;
19280}
19281
d62a17ae 19282static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 19283{
d62a17ae 19284 struct community_entry *entry;
718e3744 19285
d62a17ae 19286 for (entry = list->head; entry; entry = entry->next) {
19287 if (entry == list->head) {
19288 if (all_digit(list->name))
19289 vty_out(vty, "Community %s list %s\n",
19290 entry->style == COMMUNITY_LIST_STANDARD
19291 ? "standard"
19292 : "(expanded) access",
19293 list->name);
19294 else
19295 vty_out(vty, "Named Community %s list %s\n",
19296 entry->style == COMMUNITY_LIST_STANDARD
19297 ? "standard"
19298 : "expanded",
19299 list->name);
19300 }
19301 if (entry->any)
19302 vty_out(vty, " %s\n",
19303 community_direct_str(entry->direct));
19304 else
19305 vty_out(vty, " %s %s\n",
19306 community_direct_str(entry->direct),
8d9b8ed9 19307 community_list_config_str(entry));
d62a17ae 19308 }
718e3744 19309}
19310
7336e101
SP
19311DEFUN (show_community_list,
19312 show_bgp_community_list_cmd,
19313 "show bgp community-list",
718e3744 19314 SHOW_STR
7336e101 19315 BGP_STR
718e3744 19316 "List community-list\n")
19317{
d62a17ae 19318 struct community_list *list;
19319 struct community_list_master *cm;
718e3744 19320
d62a17ae 19321 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19322 if (!cm)
19323 return CMD_SUCCESS;
718e3744 19324
d62a17ae 19325 for (list = cm->num.head; list; list = list->next)
19326 community_list_show(vty, list);
718e3744 19327
d62a17ae 19328 for (list = cm->str.head; list; list = list->next)
19329 community_list_show(vty, list);
718e3744 19330
d62a17ae 19331 return CMD_SUCCESS;
718e3744 19332}
19333
7336e101
SP
19334DEFUN (show_community_list_arg,
19335 show_bgp_community_list_arg_cmd,
a2099c1d 19336 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
7336e101
SP
19337 SHOW_STR
19338 BGP_STR
718e3744 19339 "List community-list\n"
19340 "Community-list number\n"
960b69b9 19341 "Community-list name\n"
19342 "Detailed information on community-list\n")
718e3744 19343{
d62a17ae 19344 int idx_comm_list = 3;
19345 struct community_list *list;
718e3744 19346
e237b0d2 19347 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19348 COMMUNITY_LIST_MASTER);
19349 if (!list) {
19350 vty_out(vty, "%% Can't find community-list\n");
19351 return CMD_WARNING;
19352 }
718e3744 19353
d62a17ae 19354 community_list_show(vty, list);
718e3744 19355
d62a17ae 19356 return CMD_SUCCESS;
718e3744 19357}
6b0655a2 19358
57d187bc
JS
19359/*
19360 * Large Community code.
19361 */
d62a17ae 19362static int lcommunity_list_set_vty(struct vty *vty, int argc,
19363 struct cmd_token **argv, int style,
19364 int reject_all_digit_name)
19365{
19366 int ret;
19367 int direct;
19368 char *str;
19369 int idx = 0;
19370 char *cl_name;
2f8cc0e5
DA
19371 char *seq = NULL;
19372
a08032fe 19373 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19374 seq = argv[idx]->arg;
d62a17ae 19375
2f8cc0e5 19376 idx = 0;
d62a17ae 19377 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19378 : COMMUNITY_DENY;
19379
19380 /* All digit name check. */
19381 idx = 0;
a2099c1d 19382 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19383 argv_find(argv, argc, "(1-99)", &idx);
19384 argv_find(argv, argc, "(100-500)", &idx);
19385 cl_name = argv[idx]->arg;
19386 if (reject_all_digit_name && all_digit(cl_name)) {
19387 vty_out(vty, "%% Community name cannot have all digits\n");
19388 return CMD_WARNING_CONFIG_FAILED;
19389 }
19390
19391 idx = 0;
19392 argv_find(argv, argc, "AA:BB:CC", &idx);
19393 argv_find(argv, argc, "LINE", &idx);
19394 /* Concat community string argument. */
19395 if (idx)
19396 str = argv_concat(argv, argc, idx);
19397 else
19398 str = NULL;
19399
2f8cc0e5 19400 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 19401
19402 /* Free temporary community list string allocated by
19403 argv_concat(). */
0a22ddfb 19404 XFREE(MTYPE_TMP, str);
d62a17ae 19405
19406 if (ret < 0) {
19407 community_list_perror(vty, ret);
19408 return CMD_WARNING_CONFIG_FAILED;
19409 }
19410 return CMD_SUCCESS;
19411}
19412
19413static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19414 struct cmd_token **argv, int style)
19415{
19416 int ret;
19417 int direct = 0;
19418 char *str = NULL;
19419 int idx = 0;
2f8cc0e5 19420 char *seq = NULL;
d62a17ae 19421
a08032fe 19422 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19423 seq = argv[idx]->arg;
d62a17ae 19424
2f8cc0e5 19425 idx = 0;
d62a17ae 19426 argv_find(argv, argc, "permit", &idx);
19427 argv_find(argv, argc, "deny", &idx);
19428
19429 if (idx) {
19430 /* Check the list direct. */
19431 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19432 direct = COMMUNITY_PERMIT;
19433 else
19434 direct = COMMUNITY_DENY;
19435
19436 idx = 0;
19437 argv_find(argv, argc, "LINE", &idx);
19438 argv_find(argv, argc, "AA:AA:NN", &idx);
19439 /* Concat community string argument. */
19440 str = argv_concat(argv, argc, idx);
19441 }
19442
19443 idx = 0;
19444 argv_find(argv, argc, "(1-99)", &idx);
19445 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19446 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19447
19448 /* Unset community list. */
2f8cc0e5 19449 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 19450 style);
19451
19452 /* Free temporary community list string allocated by
19453 argv_concat(). */
0a22ddfb 19454 XFREE(MTYPE_TMP, str);
d62a17ae 19455
19456 if (ret < 0) {
19457 community_list_perror(vty, ret);
19458 return CMD_WARNING_CONFIG_FAILED;
19459 }
19460
19461 return CMD_SUCCESS;
57d187bc
JS
19462}
19463
19464/* "large-community-list" keyword help string. */
19465#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19466#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19467
7336e101
SP
19468DEFUN (lcommunity_list_standard,
19469 bgp_lcommunity_list_standard_cmd,
a08032fe 19470 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19471 BGP_STR
19472 LCOMMUNITY_LIST_STR
19473 "Large Community list number (standard)\n"
2f8cc0e5
DA
19474 "Sequence number of an entry\n"
19475 "Sequence number\n"
7336e101
SP
19476 "Specify large community to reject\n"
19477 "Specify large community to accept\n"
19478 LCOMMUNITY_VAL_STR)
52951b63 19479{
d62a17ae 19480 return lcommunity_list_set_vty(vty, argc, argv,
19481 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
19482}
19483
7336e101
SP
19484DEFUN (lcommunity_list_expanded,
19485 bgp_lcommunity_list_expanded_cmd,
a08032fe 19486 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19487 BGP_STR
19488 LCOMMUNITY_LIST_STR
19489 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19490 "Sequence number of an entry\n"
19491 "Sequence number\n"
7336e101
SP
19492 "Specify large community to reject\n"
19493 "Specify large community to accept\n"
19494 "An ordered list as a regular-expression\n")
57d187bc 19495{
d62a17ae 19496 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19497 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
19498}
19499
7336e101
SP
19500DEFUN (lcommunity_list_name_standard,
19501 bgp_lcommunity_list_name_standard_cmd,
a2099c1d 19502 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19503 BGP_STR
19504 LCOMMUNITY_LIST_STR
19505 "Specify standard large-community-list\n"
19506 "Large Community list name\n"
2f8cc0e5
DA
19507 "Sequence number of an entry\n"
19508 "Sequence number\n"
7336e101
SP
19509 "Specify large community to reject\n"
19510 "Specify large community to accept\n"
19511 LCOMMUNITY_VAL_STR)
52951b63 19512{
d62a17ae 19513 return lcommunity_list_set_vty(vty, argc, argv,
19514 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
19515}
19516
7336e101
SP
19517DEFUN (lcommunity_list_name_expanded,
19518 bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 19519 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19520 BGP_STR
19521 LCOMMUNITY_LIST_STR
19522 "Specify expanded large-community-list\n"
19523 "Large Community list name\n"
2f8cc0e5
DA
19524 "Sequence number of an entry\n"
19525 "Sequence number\n"
7336e101
SP
19526 "Specify large community to reject\n"
19527 "Specify large community to accept\n"
19528 "An ordered list as a regular-expression\n")
57d187bc 19529{
d62a17ae 19530 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19531 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
19532}
19533
4378f57c
DA
19534DEFUN (no_lcommunity_list_all,
19535 no_bgp_lcommunity_list_all_cmd,
a2099c1d 19536 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
7336e101
SP
19537 NO_STR
19538 BGP_STR
19539 LCOMMUNITY_LIST_STR
19540 "Large Community list number (standard)\n"
19541 "Large Community list number (expanded)\n"
19542 "Large Community list name\n")
57d187bc 19543{
7336e101
SP
19544 return lcommunity_list_unset_vty(vty, argc, argv,
19545 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19546}
19547
4378f57c
DA
19548DEFUN (no_lcommunity_list_name_standard_all,
19549 no_bgp_lcommunity_list_name_standard_all_cmd,
a2099c1d 19550 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
4378f57c
DA
19551 NO_STR
19552 BGP_STR
19553 LCOMMUNITY_LIST_STR
19554 "Specify standard large-community-list\n"
19555 "Large Community list name\n")
19556{
19557 return lcommunity_list_unset_vty(vty, argc, argv,
19558 LARGE_COMMUNITY_LIST_STANDARD);
19559}
19560
7336e101
SP
19561DEFUN (no_lcommunity_list_name_expanded_all,
19562 no_bgp_lcommunity_list_name_expanded_all_cmd,
a2099c1d 19563 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
7336e101
SP
19564 NO_STR
19565 BGP_STR
19566 LCOMMUNITY_LIST_STR
19567 "Specify expanded large-community-list\n"
19568 "Large Community list name\n")
57d187bc 19569{
d62a17ae 19570 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19571 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19572}
19573
7336e101
SP
19574DEFUN (no_lcommunity_list_standard,
19575 no_bgp_lcommunity_list_standard_cmd,
a08032fe 19576 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19577 NO_STR
19578 BGP_STR
19579 LCOMMUNITY_LIST_STR
19580 "Large Community list number (standard)\n"
2f8cc0e5
DA
19581 "Sequence number of an entry\n"
19582 "Sequence number\n"
7336e101
SP
19583 "Specify large community to reject\n"
19584 "Specify large community to accept\n"
19585 LCOMMUNITY_VAL_STR)
57d187bc 19586{
d62a17ae 19587 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19588 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19589}
19590
7336e101
SP
19591DEFUN (no_lcommunity_list_expanded,
19592 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 19593 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19594 NO_STR
19595 BGP_STR
19596 LCOMMUNITY_LIST_STR
19597 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19598 "Sequence number of an entry\n"
19599 "Sequence number\n"
7336e101
SP
19600 "Specify large community to reject\n"
19601 "Specify large community to accept\n"
19602 "An ordered list as a regular-expression\n")
57d187bc 19603{
d62a17ae 19604 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19605 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19606}
19607
7336e101
SP
19608DEFUN (no_lcommunity_list_name_standard,
19609 no_bgp_lcommunity_list_name_standard_cmd,
a2099c1d 19610 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19611 NO_STR
19612 BGP_STR
19613 LCOMMUNITY_LIST_STR
19614 "Specify standard large-community-list\n"
19615 "Large Community list name\n"
2f8cc0e5
DA
19616 "Sequence number of an entry\n"
19617 "Sequence number\n"
7336e101
SP
19618 "Specify large community to reject\n"
19619 "Specify large community to accept\n"
19620 LCOMMUNITY_VAL_STR)
57d187bc 19621{
d62a17ae 19622 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19623 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19624}
19625
7336e101
SP
19626DEFUN (no_lcommunity_list_name_expanded,
19627 no_bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 19628 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19629 NO_STR
19630 BGP_STR
19631 LCOMMUNITY_LIST_STR
19632 "Specify expanded large-community-list\n"
19633 "Large community list name\n"
2f8cc0e5
DA
19634 "Sequence number of an entry\n"
19635 "Sequence number\n"
7336e101
SP
19636 "Specify large community to reject\n"
19637 "Specify large community to accept\n"
19638 "An ordered list as a regular-expression\n")
57d187bc 19639{
d62a17ae 19640 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19641 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19642}
19643
d62a17ae 19644static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19645{
19646 struct community_entry *entry;
19647
19648 for (entry = list->head; entry; entry = entry->next) {
19649 if (entry == list->head) {
19650 if (all_digit(list->name))
19651 vty_out(vty, "Large community %s list %s\n",
169b72c8 19652 entry->style ==
19653 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19654 ? "standard"
19655 : "(expanded) access",
19656 list->name);
19657 else
19658 vty_out(vty,
19659 "Named large community %s list %s\n",
169b72c8 19660 entry->style ==
19661 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19662 ? "standard"
19663 : "expanded",
19664 list->name);
19665 }
19666 if (entry->any)
19667 vty_out(vty, " %s\n",
19668 community_direct_str(entry->direct));
19669 else
19670 vty_out(vty, " %s %s\n",
19671 community_direct_str(entry->direct),
8d9b8ed9 19672 community_list_config_str(entry));
d62a17ae 19673 }
57d187bc
JS
19674}
19675
7336e101
SP
19676DEFUN (show_lcommunity_list,
19677 show_bgp_lcommunity_list_cmd,
19678 "show bgp large-community-list",
57d187bc 19679 SHOW_STR
7336e101 19680 BGP_STR
57d187bc
JS
19681 "List large-community list\n")
19682{
d62a17ae 19683 struct community_list *list;
19684 struct community_list_master *cm;
57d187bc 19685
d62a17ae 19686 cm = community_list_master_lookup(bgp_clist,
19687 LARGE_COMMUNITY_LIST_MASTER);
19688 if (!cm)
19689 return CMD_SUCCESS;
57d187bc 19690
d62a17ae 19691 for (list = cm->num.head; list; list = list->next)
19692 lcommunity_list_show(vty, list);
57d187bc 19693
d62a17ae 19694 for (list = cm->str.head; list; list = list->next)
19695 lcommunity_list_show(vty, list);
57d187bc 19696
d62a17ae 19697 return CMD_SUCCESS;
57d187bc
JS
19698}
19699
7336e101
SP
19700DEFUN (show_lcommunity_list_arg,
19701 show_bgp_lcommunity_list_arg_cmd,
a2099c1d 19702 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
7336e101
SP
19703 SHOW_STR
19704 BGP_STR
57d187bc 19705 "List large-community list\n"
960b69b9 19706 "Large-community-list number\n"
19707 "Large-community-list name\n"
19708 "Detailed information on large-community-list\n")
57d187bc 19709{
d62a17ae 19710 struct community_list *list;
57d187bc 19711
e237b0d2 19712 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 19713 LARGE_COMMUNITY_LIST_MASTER);
19714 if (!list) {
960b69b9 19715 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 19716 return CMD_WARNING;
19717 }
57d187bc 19718
d62a17ae 19719 lcommunity_list_show(vty, list);
57d187bc 19720
d62a17ae 19721 return CMD_SUCCESS;
57d187bc
JS
19722}
19723
718e3744 19724/* "extcommunity-list" keyword help string. */
19725#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19726#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19727
7336e101
SP
19728DEFUN (extcommunity_list_standard,
19729 bgp_extcommunity_list_standard_cmd,
a2099c1d 19730 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19731 BGP_STR
718e3744 19732 EXTCOMMUNITY_LIST_STR
19733 "Extended Community list number (standard)\n"
718e3744 19734 "Specify standard extcommunity-list\n"
5bf15956 19735 "Community list name\n"
2f8cc0e5
DA
19736 "Sequence number of an entry\n"
19737 "Sequence number\n"
718e3744 19738 "Specify community to reject\n"
19739 "Specify community to accept\n"
19740 EXTCOMMUNITY_VAL_STR)
19741{
d62a17ae 19742 int style = EXTCOMMUNITY_LIST_STANDARD;
19743 int direct = 0;
19744 char *cl_number_or_name = NULL;
2f8cc0e5 19745 char *seq = NULL;
42f914d4 19746
d62a17ae 19747 int idx = 0;
7b9a4750 19748
d62a17ae 19749 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19750 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19751 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19752
a08032fe 19753 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19754 seq = argv[idx]->arg;
19755
d62a17ae 19756 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19757 : COMMUNITY_DENY;
19758 argv_find(argv, argc, "AA:NN", &idx);
19759 char *str = argv_concat(argv, argc, idx);
42f914d4 19760
2f8cc0e5 19761 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19762 direct, style);
42f914d4 19763
d62a17ae 19764 XFREE(MTYPE_TMP, str);
42f914d4 19765
d62a17ae 19766 if (ret < 0) {
19767 community_list_perror(vty, ret);
19768 return CMD_WARNING_CONFIG_FAILED;
19769 }
42f914d4 19770
d62a17ae 19771 return CMD_SUCCESS;
718e3744 19772}
19773
7336e101
SP
19774DEFUN (extcommunity_list_name_expanded,
19775 bgp_extcommunity_list_name_expanded_cmd,
a2099c1d 19776 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19777 BGP_STR
19778 EXTCOMMUNITY_LIST_STR
5bf15956 19779 "Extended Community list number (expanded)\n"
718e3744 19780 "Specify expanded extcommunity-list\n"
19781 "Extended Community list name\n"
2f8cc0e5
DA
19782 "Sequence number of an entry\n"
19783 "Sequence number\n"
718e3744 19784 "Specify community to reject\n"
19785 "Specify community to accept\n"
19786 "An ordered list as a regular-expression\n")
19787{
d62a17ae 19788 int style = EXTCOMMUNITY_LIST_EXPANDED;
19789 int direct = 0;
19790 char *cl_number_or_name = NULL;
2f8cc0e5 19791 char *seq = NULL;
d62a17ae 19792 int idx = 0;
7336e101 19793
d62a17ae 19794 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19795 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19796 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19797
a08032fe 19798 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19799 seq = argv[idx]->arg;
19800
d62a17ae 19801 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19802 : COMMUNITY_DENY;
19803 argv_find(argv, argc, "LINE", &idx);
19804 char *str = argv_concat(argv, argc, idx);
42f914d4 19805
2f8cc0e5 19806 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19807 direct, style);
42f914d4 19808
d62a17ae 19809 XFREE(MTYPE_TMP, str);
42f914d4 19810
d62a17ae 19811 if (ret < 0) {
19812 community_list_perror(vty, ret);
19813 return CMD_WARNING_CONFIG_FAILED;
19814 }
42f914d4 19815
d62a17ae 19816 return CMD_SUCCESS;
718e3744 19817}
19818
7336e101
SP
19819DEFUN (no_extcommunity_list_standard_all,
19820 no_bgp_extcommunity_list_standard_all_cmd,
a2099c1d 19821 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19822 NO_STR
19823 BGP_STR
19824 EXTCOMMUNITY_LIST_STR
813d4307 19825 "Extended Community list number (standard)\n"
718e3744 19826 "Specify standard extcommunity-list\n"
5bf15956 19827 "Community list name\n"
2f8cc0e5
DA
19828 "Sequence number of an entry\n"
19829 "Sequence number\n"
718e3744 19830 "Specify community to reject\n"
19831 "Specify community to accept\n"
19832 EXTCOMMUNITY_VAL_STR)
19833{
d62a17ae 19834 int style = EXTCOMMUNITY_LIST_STANDARD;
19835 int direct = 0;
19836 char *cl_number_or_name = NULL;
d4455c89 19837 char *str = NULL;
2f8cc0e5 19838 char *seq = NULL;
d62a17ae 19839 int idx = 0;
d4455c89 19840
a08032fe 19841 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19842 seq = argv[idx]->arg;
19843
19844 idx = 0;
d4455c89
DA
19845 argv_find(argv, argc, "permit", &idx);
19846 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
19847 if (idx) {
19848 direct = argv_find(argv, argc, "permit", &idx)
19849 ? COMMUNITY_PERMIT
19850 : COMMUNITY_DENY;
19851
19852 idx = 0;
19853 argv_find(argv, argc, "AA:NN", &idx);
19854 str = argv_concat(argv, argc, idx);
19855 }
19856
19857 idx = 0;
d62a17ae 19858 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19859 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19860 cl_number_or_name = argv[idx]->arg;
42f914d4 19861
d62a17ae 19862 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19863 seq, direct, style);
42f914d4 19864
d62a17ae 19865 XFREE(MTYPE_TMP, str);
42f914d4 19866
d62a17ae 19867 if (ret < 0) {
19868 community_list_perror(vty, ret);
19869 return CMD_WARNING_CONFIG_FAILED;
19870 }
42f914d4 19871
d62a17ae 19872 return CMD_SUCCESS;
718e3744 19873}
19874
d4455c89
DA
19875ALIAS(no_extcommunity_list_standard_all,
19876 no_bgp_extcommunity_list_standard_all_list_cmd,
a2099c1d 19877 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
36d4bb44 19878 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19879 "Extended Community list number (standard)\n"
19880 "Specify standard extcommunity-list\n"
19881 "Community list name\n")
19882
7336e101
SP
19883DEFUN (no_extcommunity_list_expanded_all,
19884 no_bgp_extcommunity_list_expanded_all_cmd,
a2099c1d 19885 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19886 NO_STR
19887 BGP_STR
19888 EXTCOMMUNITY_LIST_STR
718e3744 19889 "Extended Community list number (expanded)\n"
718e3744 19890 "Specify expanded extcommunity-list\n"
5bf15956 19891 "Extended Community list name\n"
2f8cc0e5
DA
19892 "Sequence number of an entry\n"
19893 "Sequence number\n"
718e3744 19894 "Specify community to reject\n"
19895 "Specify community to accept\n"
19896 "An ordered list as a regular-expression\n")
19897{
d62a17ae 19898 int style = EXTCOMMUNITY_LIST_EXPANDED;
19899 int direct = 0;
19900 char *cl_number_or_name = NULL;
d4455c89 19901 char *str = NULL;
2f8cc0e5 19902 char *seq = NULL;
d62a17ae 19903 int idx = 0;
d4455c89 19904
a08032fe 19905 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19906 seq = argv[idx]->arg;
19907
19908 idx = 0;
d4455c89
DA
19909 argv_find(argv, argc, "permit", &idx);
19910 argv_find(argv, argc, "deny", &idx);
19911
19912 if (idx) {
19913 direct = argv_find(argv, argc, "permit", &idx)
19914 ? COMMUNITY_PERMIT
19915 : COMMUNITY_DENY;
19916
19917 idx = 0;
19918 argv_find(argv, argc, "LINE", &idx);
19919 str = argv_concat(argv, argc, idx);
19920 }
19921
19922 idx = 0;
d62a17ae 19923 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19924 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19925 cl_number_or_name = argv[idx]->arg;
42f914d4 19926
d62a17ae 19927 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19928 seq, direct, style);
42f914d4 19929
d62a17ae 19930 XFREE(MTYPE_TMP, str);
42f914d4 19931
d62a17ae 19932 if (ret < 0) {
19933 community_list_perror(vty, ret);
19934 return CMD_WARNING_CONFIG_FAILED;
19935 }
42f914d4 19936
d62a17ae 19937 return CMD_SUCCESS;
718e3744 19938}
19939
d4455c89
DA
19940ALIAS(no_extcommunity_list_expanded_all,
19941 no_bgp_extcommunity_list_expanded_all_list_cmd,
a2099c1d 19942 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
36d4bb44 19943 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19944 "Extended Community list number (expanded)\n"
19945 "Specify expanded extcommunity-list\n"
19946 "Extended Community list name\n")
19947
d62a17ae 19948static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 19949{
d62a17ae 19950 struct community_entry *entry;
718e3744 19951
d62a17ae 19952 for (entry = list->head; entry; entry = entry->next) {
19953 if (entry == list->head) {
19954 if (all_digit(list->name))
19955 vty_out(vty, "Extended community %s list %s\n",
19956 entry->style == EXTCOMMUNITY_LIST_STANDARD
19957 ? "standard"
19958 : "(expanded) access",
19959 list->name);
19960 else
19961 vty_out(vty,
19962 "Named extended community %s list %s\n",
19963 entry->style == EXTCOMMUNITY_LIST_STANDARD
19964 ? "standard"
19965 : "expanded",
19966 list->name);
19967 }
19968 if (entry->any)
19969 vty_out(vty, " %s\n",
19970 community_direct_str(entry->direct));
19971 else
19972 vty_out(vty, " %s %s\n",
19973 community_direct_str(entry->direct),
8d9b8ed9 19974 community_list_config_str(entry));
d62a17ae 19975 }
718e3744 19976}
19977
7336e101
SP
19978DEFUN (show_extcommunity_list,
19979 show_bgp_extcommunity_list_cmd,
19980 "show bgp extcommunity-list",
718e3744 19981 SHOW_STR
7336e101 19982 BGP_STR
718e3744 19983 "List extended-community list\n")
19984{
d62a17ae 19985 struct community_list *list;
19986 struct community_list_master *cm;
718e3744 19987
d62a17ae 19988 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19989 if (!cm)
19990 return CMD_SUCCESS;
718e3744 19991
d62a17ae 19992 for (list = cm->num.head; list; list = list->next)
19993 extcommunity_list_show(vty, list);
718e3744 19994
d62a17ae 19995 for (list = cm->str.head; list; list = list->next)
19996 extcommunity_list_show(vty, list);
718e3744 19997
d62a17ae 19998 return CMD_SUCCESS;
718e3744 19999}
20000
7336e101
SP
20001DEFUN (show_extcommunity_list_arg,
20002 show_bgp_extcommunity_list_arg_cmd,
a2099c1d 20003 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
7336e101
SP
20004 SHOW_STR
20005 BGP_STR
718e3744 20006 "List extended-community list\n"
20007 "Extcommunity-list number\n"
960b69b9 20008 "Extcommunity-list name\n"
20009 "Detailed information on extcommunity-list\n")
718e3744 20010{
d62a17ae 20011 int idx_comm_list = 3;
20012 struct community_list *list;
718e3744 20013
e237b0d2 20014 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20015 EXTCOMMUNITY_LIST_MASTER);
20016 if (!list) {
20017 vty_out(vty, "%% Can't find extcommunity-list\n");
20018 return CMD_WARNING;
20019 }
718e3744 20020
d62a17ae 20021 extcommunity_list_show(vty, list);
718e3744 20022
d62a17ae 20023 return CMD_SUCCESS;
718e3744 20024}
6b0655a2 20025
718e3744 20026/* Display community-list and extcommunity-list configuration. */
d62a17ae 20027static int community_list_config_write(struct vty *vty)
20028{
20029 struct community_list *list;
20030 struct community_entry *entry;
20031 struct community_list_master *cm;
20032 int write = 0;
20033
20034 /* Community-list. */
20035 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20036
20037 for (list = cm->num.head; list; list = list->next)
20038 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20039 vty_out(vty,
20040 "bgp community-list %s seq %" PRId64 " %s %s\n",
20041 list->name, entry->seq,
d62a17ae 20042 community_direct_str(entry->direct),
20043 community_list_config_str(entry));
20044 write++;
20045 }
20046 for (list = cm->str.head; list; list = list->next)
20047 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20048 vty_out(vty,
20049 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 20050 entry->style == COMMUNITY_LIST_STANDARD
20051 ? "standard"
20052 : "expanded",
2f8cc0e5
DA
20053 list->name, entry->seq,
20054 community_direct_str(entry->direct),
d62a17ae 20055 community_list_config_str(entry));
20056 write++;
20057 }
20058
20059 /* Extcommunity-list. */
20060 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20061
20062 for (list = cm->num.head; list; list = list->next)
20063 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20064 vty_out(vty,
20065 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20066 list->name, entry->seq,
20067 community_direct_str(entry->direct),
d62a17ae 20068 community_list_config_str(entry));
20069 write++;
20070 }
20071 for (list = cm->str.head; list; list = list->next)
20072 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20073 vty_out(vty,
6cde4b45 20074 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 20075 entry->style == EXTCOMMUNITY_LIST_STANDARD
20076 ? "standard"
20077 : "expanded",
2f8cc0e5
DA
20078 list->name, entry->seq,
20079 community_direct_str(entry->direct),
d62a17ae 20080 community_list_config_str(entry));
20081 write++;
20082 }
20083
20084
20085 /* lcommunity-list. */
20086 cm = community_list_master_lookup(bgp_clist,
20087 LARGE_COMMUNITY_LIST_MASTER);
20088
20089 for (list = cm->num.head; list; list = list->next)
20090 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20091 vty_out(vty,
6cde4b45 20092 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
20093 list->name, entry->seq,
20094 community_direct_str(entry->direct),
d62a17ae 20095 community_list_config_str(entry));
20096 write++;
20097 }
20098 for (list = cm->str.head; list; list = list->next)
20099 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20100 vty_out(vty,
6cde4b45 20101 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 20102
d62a17ae 20103 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20104 ? "standard"
20105 : "expanded",
2f8cc0e5 20106 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 20107 community_list_config_str(entry));
20108 write++;
20109 }
20110
20111 return write;
20112}
20113
612c2c15 20114static int community_list_config_write(struct vty *vty);
d62a17ae 20115static struct cmd_node community_list_node = {
f4b8291f 20116 .name = "community list",
62b346ee
DL
20117 .node = COMMUNITY_LIST_NODE,
20118 .prompt = "",
612c2c15 20119 .config_write = community_list_config_write,
718e3744 20120};
20121
d62a17ae 20122static void community_list_vty(void)
20123{
612c2c15 20124 install_node(&community_list_node);
d62a17ae 20125
20126 /* Community-list. */
7336e101
SP
20127 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20128 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20129 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 20130 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 20131 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 20132 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
20133 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20134 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 20135
20136 /* Extcommunity-list. */
7336e101
SP
20137 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20138 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20139 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
20140 install_element(CONFIG_NODE,
20141 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 20142 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
20143 install_element(CONFIG_NODE,
20144 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
20145 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20146 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 20147
20148 /* Large Community List */
7336e101 20149 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
20150 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20151 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 20152 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
20153 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20154 install_element(CONFIG_NODE,
20155 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
20156 install_element(CONFIG_NODE,
20157 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20158 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20159 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20160 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20161 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20162 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20163 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
225096bc
DA
20164
20165 bgp_community_list_command_completion_setup();
5bf15956 20166}
ed0e57e3
DA
20167
20168static struct cmd_node community_alias_node = {
20169 .name = "community alias",
20170 .node = COMMUNITY_ALIAS_NODE,
20171 .prompt = "",
20172 .config_write = bgp_community_alias_write,
20173};
20174
20175void community_alias_vty(void)
20176{
20177 install_node(&community_alias_node);
20178
20179 /* Community-list. */
20180 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
b4ad2fae
DS
20181
20182 bgp_community_alias_command_completion_setup();
ed0e57e3 20183}