]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #10665 from opensourcerouting/pim6-fix-warning
[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
4b7e23e9 806int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
d62a17ae 807{
808 const char *str = NULL;
809
810 switch (ret) {
4b7e23e9
DS
811 case BGP_SUCCESS:
812 case BGP_CREATED:
813 case BGP_GR_NO_OPERATION:
814 break;
d62a17ae 815 case BGP_ERR_INVALID_VALUE:
816 str = "Invalid value";
817 break;
818 case BGP_ERR_INVALID_FLAG:
819 str = "Invalid flag";
820 break;
821 case BGP_ERR_PEER_GROUP_SHUTDOWN:
822 str = "Peer-group has been shutdown. Activate the peer-group first";
823 break;
824 case BGP_ERR_PEER_FLAG_CONFLICT:
825 str = "Can't set override-capability and strict-capability-match at the same time";
826 break;
827 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
828 str = "Specify remote-as or peer-group remote AS first";
829 break;
830 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
831 str = "Cannot change the peer-group. Deconfigure first";
832 break;
833 case BGP_ERR_PEER_GROUP_MISMATCH:
834 str = "Peer is not a member of this peer-group";
835 break;
836 case BGP_ERR_PEER_FILTER_CONFLICT:
837 str = "Prefix/distribute list can not co-exist";
838 break;
839 case BGP_ERR_NOT_INTERNAL_PEER:
840 str = "Invalid command. Not an internal neighbor";
841 break;
842 case BGP_ERR_REMOVE_PRIVATE_AS:
843 str = "remove-private-AS cannot be configured for IBGP peers";
844 break;
845 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
846 str = "Local-AS allowed only for EBGP peers";
847 break;
848 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
849 str = "Cannot have local-as same as BGP AS number";
850 break;
851 case BGP_ERR_TCPSIG_FAILED:
852 str = "Error while applying TCP-Sig to session(s)";
853 break;
854 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
855 str = "ebgp-multihop and ttl-security cannot be configured together";
856 break;
857 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
858 str = "ttl-security only allowed for EBGP peers";
859 break;
860 case BGP_ERR_AS_OVERRIDE:
861 str = "as-override cannot be configured for IBGP peers";
862 break;
863 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
864 str = "Invalid limit for number of dynamic neighbors";
865 break;
866 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
867 str = "Dynamic neighbor listen range already exists";
868 break;
869 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
870 str = "Operation not allowed on a dynamic neighbor";
871 break;
872 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
873 str = "Operation not allowed on a directly connected neighbor";
874 break;
875 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 876 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
055679e9 877 break;
878 case BGP_ERR_GR_INVALID_CMD:
879 str = "The Graceful Restart command used is not valid at this moment.";
880 break;
881 case BGP_ERR_GR_OPERATION_FAILED:
882 str = "The Graceful Restart Operation failed due to an err.";
883 break;
6dcea6fe
DS
884 case BGP_ERR_PEER_GROUP_MEMBER:
885 str = "Peer-group member cannot override remote-as of peer-group.";
886 break;
887 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
888 str = "Peer-group members must be all internal or all external.";
889 break;
4b7e23e9
DS
890 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
891 str = "Range specified cannot be deleted because it is not part of current config.";
892 break;
893 case BGP_ERR_INSTANCE_MISMATCH:
894 str = "Instance specified does not match the current instance.";
895 break;
896 case BGP_ERR_NO_INTERFACE_CONFIG:
897 str = "Interface specified is not being used for interface based peer.";
898 break;
899 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
900 str = "No configuration already specified for soft reconfiguration.";
901 break;
902 case BGP_ERR_AS_MISMATCH:
903 str = "BGP is already running.";
904 break;
905 case BGP_ERR_AF_UNCONFIGURED:
906 str = "AFI/SAFI specified is not currently configured.";
907 break;
908 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS_REMOTE_AS:
909 str = "AS specified for local as is the same as the remote as and this is not allowed.";
910 break;
911 case BGP_ERR_INVALID_AS:
912 str = "Confederation AS specified is the same AS as our AS.";
913 break;
d62a17ae 914 }
915 if (str) {
916 vty_out(vty, "%% %s\n", str);
917 return CMD_WARNING_CONFIG_FAILED;
918 }
919 return CMD_SUCCESS;
718e3744 920}
921
7aafcaca 922/* BGP clear sort. */
d62a17ae 923enum clear_sort {
924 clear_all,
925 clear_peer,
926 clear_group,
927 clear_external,
928 clear_as
7aafcaca
DS
929};
930
1ca2fd11
IR
931static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
932 safi_t safi, int error)
d62a17ae 933{
934 switch (error) {
935 case BGP_ERR_AF_UNCONFIGURED:
1ca2fd11
IR
936 vty_out(vty,
937 "%%BGP: Enable %s address family for the neighbor %s\n",
938 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 939 break;
940 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
1ca2fd11
IR
941 vty_out(vty,
942 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
d62a17ae 943 peer->host);
944 break;
945 default:
946 break;
947 }
7aafcaca
DS
948}
949
dc912615 950static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 951 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
952{
953 int ret = 0;
2adac256 954 struct peer_af *paf;
dc912615
DS
955
956 /* if afi/.safi not specified, spin thru all of them */
957 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
958 afi_t tmp_afi;
959 safi_t tmp_safi;
0e5cdd59
DS
960 enum bgp_af_index index;
961
962 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
963 paf = peer->peer_af_array[index];
964 if (!paf)
965 continue;
dc912615 966
2adac256
DA
967 if (paf && paf->subgroup)
968 SET_FLAG(paf->subgroup->sflags,
969 SUBGRP_STATUS_FORCE_UPDATES);
970
0e5cdd59
DS
971 tmp_afi = paf->afi;
972 tmp_safi = paf->safi;
dc912615
DS
973 if (!peer->afc[tmp_afi][tmp_safi])
974 continue;
975
976 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 977 ret = peer_clear(peer, nnode);
dc912615
DS
978 else
979 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
980 stype);
981 }
982 /* if afi specified and safi not, spin thru safis on this afi */
983 } else if (safi == SAFI_UNSPEC) {
984 safi_t tmp_safi;
985
986 for (tmp_safi = SAFI_UNICAST;
987 tmp_safi < SAFI_MAX; tmp_safi++) {
988 if (!peer->afc[afi][tmp_safi])
989 continue;
990
2adac256
DA
991 paf = peer_af_find(peer, afi, tmp_safi);
992 if (paf && paf->subgroup)
993 SET_FLAG(paf->subgroup->sflags,
994 SUBGRP_STATUS_FORCE_UPDATES);
995
dc912615 996 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 997 ret = peer_clear(peer, nnode);
dc912615
DS
998 else
999 ret = peer_clear_soft(peer, afi,
1000 tmp_safi, stype);
1001 }
1002 /* both afi/safi specified, let the caller know if not defined */
1003 } else {
1004 if (!peer->afc[afi][safi])
1005 return 1;
1006
2adac256
DA
1007 paf = peer_af_find(peer, afi, safi);
1008 if (paf && paf->subgroup)
1009 SET_FLAG(paf->subgroup->sflags,
1010 SUBGRP_STATUS_FORCE_UPDATES);
1011
dc912615 1012 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1013 ret = peer_clear(peer, nnode);
dc912615
DS
1014 else
1015 ret = peer_clear_soft(peer, afi, safi, stype);
1016 }
1017
1018 return ret;
1019}
1020
7aafcaca 1021/* `clear ip bgp' functions. */
1ca2fd11 1022static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 1023 enum clear_sort sort, enum bgp_clear_type stype,
1ca2fd11 1024 const char *arg)
d62a17ae 1025{
dc912615 1026 int ret = 0;
3ae8bfa5 1027 bool found = false;
d62a17ae 1028 struct peer *peer;
dc95985f 1029
1030 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 1031
1032 /* Clear all neighbors. */
1033 /*
1034 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
1035 * nodes on the BGP instance as that may get freed if it is a
1036 * doppelganger
d62a17ae 1037 */
1038 if (sort == clear_all) {
1039 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 1040
1041 bgp_peer_gr_flags_update(peer);
1042
36235319 1043 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 1044 gr_router_detected = true;
1045
c368171c 1046 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 1047 stype);
d62a17ae 1048
1049 if (ret < 0)
1ca2fd11 1050 bgp_clear_vty_error(vty, peer, afi, safi, ret);
dc95985f 1051 }
1052
36235319
QY
1053 if (gr_router_detected
1054 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1055 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1056 } else if (!gr_router_detected
1057 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1058 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 1059 }
d62a17ae 1060
1061 /* This is to apply read-only mode on this clear. */
1062 if (stype == BGP_CLEAR_SOFT_NONE)
1063 bgp->update_delay_over = 0;
1064
1065 return CMD_SUCCESS;
7aafcaca
DS
1066 }
1067
3ae8bfa5 1068 /* Clear specified neighbor. */
d62a17ae 1069 if (sort == clear_peer) {
1070 union sockunion su;
d62a17ae 1071
1072 /* Make sockunion for lookup. */
1073 ret = str2sockunion(arg, &su);
1074 if (ret < 0) {
1075 peer = peer_lookup_by_conf_if(bgp, arg);
1076 if (!peer) {
1077 peer = peer_lookup_by_hostname(bgp, arg);
1078 if (!peer) {
1ca2fd11
IR
1079 vty_out(vty,
1080 "Malformed address or name: %s\n",
d62a17ae 1081 arg);
1082 return CMD_WARNING;
1083 }
1084 }
1085 } else {
1086 peer = peer_lookup(bgp, &su);
1087 if (!peer) {
1ca2fd11
IR
1088 vty_out(vty,
1089 "%%BGP: Unknown neighbor - \"%s\"\n",
1090 arg);
d62a17ae 1091 return CMD_WARNING;
1092 }
1093 }
7aafcaca 1094
dc95985f 1095 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1096 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1097
dc912615
DS
1098 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1099
1100 /* if afi/safi not defined for this peer, let caller know */
1101 if (ret == 1)
3ae8bfa5 1102 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1103
d62a17ae 1104 if (ret < 0)
1ca2fd11 1105 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 1106
d62a17ae 1107 return CMD_SUCCESS;
7aafcaca 1108 }
7aafcaca 1109
3ae8bfa5 1110 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1111 if (sort == clear_group) {
1112 struct peer_group *group;
7aafcaca 1113
d62a17ae 1114 group = peer_group_lookup(bgp, arg);
1115 if (!group) {
1ca2fd11 1116 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
d62a17ae 1117 return CMD_WARNING;
1118 }
1119
1120 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1121 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1122
d62a17ae 1123 if (ret < 0)
1ca2fd11 1124 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1125 else
1126 found = true;
d62a17ae 1127 }
3ae8bfa5
PM
1128
1129 if (!found)
1ca2fd11
IR
1130 vty_out(vty,
1131 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 1132 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1133
d62a17ae 1134 return CMD_SUCCESS;
7aafcaca 1135 }
7aafcaca 1136
3ae8bfa5 1137 /* Clear all external (eBGP) neighbors. */
d62a17ae 1138 if (sort == clear_external) {
1139 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1140 if (peer->sort == BGP_PEER_IBGP)
1141 continue;
7aafcaca 1142
dc95985f 1143 bgp_peer_gr_flags_update(peer);
1144
36235319 1145 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1146 gr_router_detected = true;
dc95985f 1147
c368171c 1148 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1149
d62a17ae 1150 if (ret < 0)
1ca2fd11 1151 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1152 else
1153 found = true;
d62a17ae 1154 }
3ae8bfa5 1155
36235319
QY
1156 if (gr_router_detected
1157 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1158 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1159 } else if (!gr_router_detected
1160 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1161 bgp_zebra_send_capabilities(bgp, true);
1162 }
1163
3ae8bfa5 1164 if (!found)
1ca2fd11
IR
1165 vty_out(vty,
1166 "%%BGP: No external %s peer is configured\n",
1167 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1168
d62a17ae 1169 return CMD_SUCCESS;
1170 }
1171
3ae8bfa5 1172 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1173 if (sort == clear_as) {
3ae8bfa5 1174 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1175
1176 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1177 if (peer->as != as)
1178 continue;
1179
dc95985f 1180 bgp_peer_gr_flags_update(peer);
1181
36235319 1182 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1183 gr_router_detected = true;
dc95985f 1184
c368171c 1185 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1186
1187 if (ret < 0)
1ca2fd11 1188 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1189 else
1190 found = true;
d62a17ae 1191 }
3ae8bfa5 1192
36235319
QY
1193 if (gr_router_detected
1194 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1195 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1196 } else if (!gr_router_detected
1197 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1198 bgp_zebra_send_capabilities(bgp, true);
1199 }
1200
3ae8bfa5 1201 if (!found)
1ca2fd11
IR
1202 vty_out(vty,
1203 "%%BGP: No %s peer is configured with AS %s\n",
1204 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1205
d62a17ae 1206 return CMD_SUCCESS;
1207 }
1208
1209 return CMD_SUCCESS;
1210}
1211
1ca2fd11
IR
1212static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1213 safi_t safi, enum clear_sort sort,
1214 enum bgp_clear_type stype, const char *arg)
d62a17ae 1215{
1216 struct bgp *bgp;
1217
1218 /* BGP structure lookup. */
1219 if (name) {
1220 bgp = bgp_lookup_by_name(name);
1221 if (bgp == NULL) {
1ca2fd11 1222 vty_out(vty, "Can't find BGP instance %s\n", name);
d62a17ae 1223 return CMD_WARNING;
1224 }
1225 } else {
1226 bgp = bgp_get_default();
1227 if (bgp == NULL) {
1ca2fd11 1228 vty_out(vty, "No BGP process is configured\n");
d62a17ae 1229 return CMD_WARNING;
1230 }
1231 }
1232
1ca2fd11 1233 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
1234}
1235
1236/* clear soft inbound */
1ca2fd11 1237static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 1238{
99b3ebd3
NS
1239 afi_t afi;
1240 safi_t safi;
1241
1ca2fd11
IR
1242 FOREACH_AFI_SAFI (afi, safi)
1243 bgp_clear_vty(vty, name, afi, safi, clear_all,
1244 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
1245}
1246
1247/* clear soft outbound */
1ca2fd11 1248static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 1249{
99b3ebd3
NS
1250 afi_t afi;
1251 safi_t safi;
1252
1ca2fd11
IR
1253 FOREACH_AFI_SAFI (afi, safi)
1254 bgp_clear_vty(vty, name, afi, safi, clear_all,
1255 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
1256}
1257
1258
f787d7a0 1259#ifndef VTYSH_EXTRACT_PL
2e4c2296 1260#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1261#endif
1262
8029b216
AK
1263DEFUN_HIDDEN (bgp_local_mac,
1264 bgp_local_mac_cmd,
093e3f23 1265 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1266 BGP_STR
1267 "Local MAC config\n"
1268 "VxLAN Network Identifier\n"
1269 "VNI number\n"
1270 "local mac\n"
1271 "mac address\n"
1272 "mac-mobility sequence\n"
1273 "seq number\n")
1274{
1275 int rv;
1276 vni_t vni;
1277 struct ethaddr mac;
1278 struct ipaddr ip;
1279 uint32_t seq;
1280 struct bgp *bgp;
1281
1282 vni = strtoul(argv[3]->arg, NULL, 10);
1283 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1284 vty_out(vty, "%% Malformed MAC address\n");
1285 return CMD_WARNING;
1286 }
1287 memset(&ip, 0, sizeof(ip));
1288 seq = strtoul(argv[7]->arg, NULL, 10);
1289
1290 bgp = bgp_get_default();
1291 if (!bgp) {
1292 vty_out(vty, "Default BGP instance is not there\n");
1293 return CMD_WARNING;
1294 }
1295
b5e140c8
AK
1296 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1297 zero_esi);
8029b216
AK
1298 if (rv < 0) {
1299 vty_out(vty, "Internal error\n");
1300 return CMD_WARNING;
1301 }
1302
1303 return CMD_SUCCESS;
1304}
1305
1306DEFUN_HIDDEN (no_bgp_local_mac,
1307 no_bgp_local_mac_cmd,
093e3f23 1308 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1309 NO_STR
1310 BGP_STR
1311 "Local MAC config\n"
1312 "VxLAN Network Identifier\n"
1313 "VNI number\n"
1314 "local mac\n"
1315 "mac address\n")
1316{
1317 int rv;
1318 vni_t vni;
1319 struct ethaddr mac;
1320 struct ipaddr ip;
1321 struct bgp *bgp;
1322
1323 vni = strtoul(argv[4]->arg, NULL, 10);
1324 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1325 vty_out(vty, "%% Malformed MAC address\n");
1326 return CMD_WARNING;
1327 }
1328 memset(&ip, 0, sizeof(ip));
1329
1330 bgp = bgp_get_default();
1331 if (!bgp) {
1332 vty_out(vty, "Default BGP instance is not there\n");
1333 return CMD_WARNING;
1334 }
1335
ec0ab544 1336 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1337 if (rv < 0) {
1338 vty_out(vty, "Internal error\n");
1339 return CMD_WARNING;
1340 }
1341
1342 return CMD_SUCCESS;
1343}
1344
718e3744 1345DEFUN (no_synchronization,
1346 no_synchronization_cmd,
1347 "no synchronization",
1348 NO_STR
1349 "Perform IGP synchronization\n")
1350{
d62a17ae 1351 return CMD_SUCCESS;
718e3744 1352}
1353
1354DEFUN (no_auto_summary,
1355 no_auto_summary_cmd,
1356 "no auto-summary",
1357 NO_STR
1358 "Enable automatic network number summarization\n")
1359{
d62a17ae 1360 return CMD_SUCCESS;
718e3744 1361}
3d515fd9 1362
718e3744 1363/* "router bgp" commands. */
1ca2fd11
IR
1364DEFUN_NOSH (router_bgp,
1365 router_bgp_cmd,
1366 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1367 ROUTER_STR
1368 BGP_STR
1369 AS_STR
1370 BGP_INSTANCE_HELP_STR)
718e3744 1371{
d62a17ae 1372 int idx_asn = 2;
1373 int idx_view_vrf = 3;
1374 int idx_vrf = 4;
1ca2fd11
IR
1375 int is_new_bgp = 0;
1376 int ret;
d62a17ae 1377 as_t as;
1378 struct bgp *bgp;
1379 const char *name = NULL;
1380 enum bgp_instance_type inst_type;
1381
1382 // "router bgp" without an ASN
1383 if (argc == 2) {
1384 // Pending: Make VRF option available for ASN less config
1abef40f 1385 bgp = bgp_get_default();
d62a17ae 1386
1abef40f 1387 if (bgp == NULL) {
d62a17ae 1388 vty_out(vty, "%% No BGP process is configured\n");
1389 return CMD_WARNING_CONFIG_FAILED;
1390 }
1391
1392 if (listcount(bm->bgp) > 1) {
996c9314 1393 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1394 return CMD_WARNING_CONFIG_FAILED;
1395 }
1396 }
1397
1398 // "router bgp X"
1399 else {
ff8a8a7a 1400 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1ca2fd11 1401
cc413e2a
DA
1402 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1403 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1404 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1405
d62a17ae 1406 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1407 if (argc > 3) {
1408 name = argv[idx_vrf]->arg;
1409
9a8bdf1c
PG
1410 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1411 if (strmatch(name, VRF_DEFAULT_NAME))
1412 name = NULL;
1413 else
1414 inst_type = BGP_INSTANCE_TYPE_VRF;
1ca2fd11 1415 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1416 inst_type = BGP_INSTANCE_TYPE_VIEW;
d62a17ae 1417 }
1418
1ca2fd11
IR
1419 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1420 is_new_bgp = (bgp_lookup(as, name) == NULL);
3bd70bf8 1421
1ca2fd11
IR
1422 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1423 switch (ret) {
1424 case BGP_ERR_AS_MISMATCH:
1425 vty_out(vty, "BGP is already running; AS is %u\n", as);
1426 return CMD_WARNING_CONFIG_FAILED;
1427 case BGP_ERR_INSTANCE_MISMATCH:
1428 vty_out(vty,
1429 "BGP instance name and AS number mismatch\n");
1430 vty_out(vty,
1431 "BGP instance is already running; AS is %u\n",
1432 as);
1433 return CMD_WARNING_CONFIG_FAILED;
ff8a8a7a 1434 }
1ca2fd11
IR
1435
1436 /*
1437 * If we just instantiated the default instance, complete
1438 * any pending VRF-VPN leaking that was configured via
1439 * earlier "router bgp X vrf FOO" blocks.
1440 */
1441 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1442 vpn_leak_postchange_all();
1443
1444 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1445 bgp_vpn_leak_export(bgp);
1446 /* Pending: handle when user tries to change a view to vrf n vv.
1447 */
d62a17ae 1448 }
1449
1ca2fd11
IR
1450 /* unset the auto created flag as the user config is now present */
1451 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1452 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1453
1454 return CMD_SUCCESS;
718e3744 1455}
1456
718e3744 1457/* "no router bgp" commands. */
1ca2fd11
IR
1458DEFUN (no_router_bgp,
1459 no_router_bgp_cmd,
1460 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1461 NO_STR
1462 ROUTER_STR
1463 BGP_STR
1464 AS_STR
1465 BGP_INSTANCE_HELP_STR)
718e3744 1466{
4fd9919e 1467 int idx_asn = 3;
d62a17ae 1468 int idx_vrf = 5;
1ca2fd11 1469 as_t as;
4fd9919e 1470 struct bgp *bgp;
d62a17ae 1471 const char *name = NULL;
718e3744 1472
d62a17ae 1473 // "no router bgp" without an ASN
1474 if (argc == 3) {
1475 // Pending: Make VRF option available for ASN less config
8382083a 1476 bgp = bgp_get_default();
718e3744 1477
8382083a 1478 if (bgp == NULL) {
d62a17ae 1479 vty_out(vty, "%% No BGP process is configured\n");
1480 return CMD_WARNING_CONFIG_FAILED;
1481 }
7fb21a9f 1482
d62a17ae 1483 if (listcount(bm->bgp) > 1) {
996c9314 1484 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1485 return CMD_WARNING_CONFIG_FAILED;
1486 }
4fd9919e 1487
4fd9919e
IR
1488 if (bgp->l3vni) {
1489 vty_out(vty, "%% Please unconfigure l3vni %u",
1490 bgp->l3vni);
1491 return CMD_WARNING_CONFIG_FAILED;
1492 }
d62a17ae 1493 } else {
4fd9919e
IR
1494 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1495
1ca42c8d 1496 if (argc > 4) {
d62a17ae 1497 name = argv[idx_vrf]->arg;
1ca42c8d
IR
1498 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1499 && strmatch(name, VRF_DEFAULT_NAME))
1500 name = NULL;
1501 }
7fb21a9f 1502
4fd9919e
IR
1503 /* Lookup bgp structure. */
1504 bgp = bgp_lookup(as, name);
1505 if (!bgp) {
1506 vty_out(vty, "%% Can't find BGP instance\n");
1507 return CMD_WARNING_CONFIG_FAILED;
1508 }
1509
1510 if (bgp->l3vni) {
1511 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1512 bgp->l3vni);
1513 return CMD_WARNING_CONFIG_FAILED;
1514 }
1515
1516 /* Cannot delete default instance if vrf instances exist */
1517 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1518 struct listnode *node;
1519 struct bgp *tmp_bgp;
1520
1521 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1522 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1523 continue;
1524 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1525 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1526 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1527 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1528 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1529 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1530 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1531 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1532 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1533 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1534 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1535 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1536 (bgp == bgp_get_evpn() &&
1537 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1538 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1539 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1540 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1541 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1542 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1543 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1544 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1545 (tmp_bgp->vnihash && hashcount(tmp_bgp->vnihash))) {
1546 vty_out(vty,
1547 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1548 return CMD_WARNING_CONFIG_FAILED;
1549 }
1550 }
1551 }
d62a17ae 1552 }
718e3744 1553
1ca2fd11 1554 bgp_delete(bgp);
718e3744 1555
1ca2fd11 1556 return CMD_SUCCESS;
718e3744 1557}
1558
718e3744 1559
ff8a8a7a
CS
1560/* BGP router-id. */
1561
1ca2fd11
IR
1562DEFPY (bgp_router_id,
1563 bgp_router_id_cmd,
1564 "bgp router-id A.B.C.D",
1565 BGP_STR
1566 "Override configured router identifier\n"
1567 "Manually configured router identifier\n")
718e3744 1568{
1ca2fd11
IR
1569 VTY_DECLVAR_CONTEXT(bgp, bgp);
1570 bgp_router_id_static_set(bgp, router_id);
1571 return CMD_SUCCESS;
ff8a8a7a 1572}
718e3744 1573
1ca2fd11
IR
1574DEFPY (no_bgp_router_id,
1575 no_bgp_router_id_cmd,
1576 "no bgp router-id [A.B.C.D]",
1577 NO_STR
1578 BGP_STR
1579 "Override configured router identifier\n"
1580 "Manually configured router identifier\n")
ff8a8a7a 1581{
1ca2fd11 1582 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1583
1ca2fd11
IR
1584 if (router_id_str) {
1585 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1586 vty_out(vty, "%% BGP router-id doesn't match\n");
1587 return CMD_WARNING_CONFIG_FAILED;
1588 }
1589 }
718e3744 1590
1ca2fd11
IR
1591 router_id.s_addr = 0;
1592 bgp_router_id_static_set(bgp, router_id);
1593
1594 return CMD_SUCCESS;
ff8a8a7a 1595}
6b0655a2 1596
ed0e57e3 1597DEFPY(bgp_community_alias, bgp_community_alias_cmd,
b4ad2fae 1598 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
ed0e57e3
DA
1599 NO_STR BGP_STR
1600 "Add community specific parameters\n"
1601 "Create an alias for a community\n"
1602 "Community (AA:BB or AA:BB:CC)\n"
1603 "Alias name\n")
1604{
1605 struct community_alias ca1;
1606 struct community_alias ca2;
1607 struct community_alias *lookup_community;
1608 struct community_alias *lookup_alias;
1609
1610 if (!community_str2com(community) && !lcommunity_str2com(community)) {
1611 vty_out(vty, "Invalid community format\n");
1612 return CMD_WARNING;
1613 }
1614
1615 memset(&ca1, 0, sizeof(ca1));
1616 memset(&ca2, 0, sizeof(ca2));
1617 strlcpy(ca1.community, community, sizeof(ca1.community));
b4ad2fae 1618 strlcpy(ca1.alias, alias_name, sizeof(ca1.alias));
ed0e57e3
DA
1619
1620 lookup_community = bgp_ca_community_lookup(&ca1);
1621 lookup_alias = bgp_ca_alias_lookup(&ca1);
1622
1623 if (no) {
1624 bgp_ca_alias_delete(&ca1);
1625 bgp_ca_community_delete(&ca1);
1626 } else {
1627 if (lookup_alias) {
1628 /* Lookup if community hash table has an item
1629 * with the same alias name.
1630 */
1631 strlcpy(ca2.community, lookup_alias->community,
1632 sizeof(ca2.community));
1633 if (bgp_ca_community_lookup(&ca2)) {
1634 vty_out(vty,
1635 "community (%s) already has this alias (%s)\n",
1636 lookup_alias->community,
1637 lookup_alias->alias);
1638 return CMD_WARNING;
1639 }
1640 bgp_ca_alias_delete(&ca1);
1641 }
1642
1643 if (lookup_community)
1644 bgp_ca_community_delete(&ca1);
1645
1646 bgp_ca_alias_insert(&ca1);
1647 bgp_ca_community_insert(&ca1);
1648 }
1649
1650 return CMD_SUCCESS;
1651}
1652
9acb67cb
DS
1653DEFPY (bgp_global_suppress_fib_pending,
1654 bgp_global_suppress_fib_pending_cmd,
1655 "[no] bgp suppress-fib-pending",
1656 NO_STR
1657 BGP_STR
1658 "Advertise only routes that are programmed in kernel to peers globally\n")
1659{
1660 bm_wait_for_fib_set(!no);
1661
1662 return CMD_SUCCESS;
1663}
1664
c208c586
S
1665DEFPY (bgp_suppress_fib_pending,
1666 bgp_suppress_fib_pending_cmd,
1667 "[no] bgp suppress-fib-pending",
1668 NO_STR
1669 BGP_STR
1670 "Advertise only routes that are programmed in kernel to peers\n")
1671{
1672 VTY_DECLVAR_CONTEXT(bgp, bgp);
1673
1674 bgp_suppress_fib_pending_set(bgp, !no);
1675 return CMD_SUCCESS;
1676}
1677
1678
718e3744 1679/* BGP Cluster ID. */
1ca2fd11
IR
1680DEFUN (bgp_cluster_id,
1681 bgp_cluster_id_cmd,
1682 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1683 BGP_STR
1684 "Configure Route-Reflector Cluster-id\n"
1685 "Route-Reflector Cluster-id in IP address format\n"
1686 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1687{
1ca2fd11 1688 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1689 int idx_ipv4 = 2;
1ca2fd11
IR
1690 int ret;
1691 struct in_addr cluster;
1692
1693 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1694 if (!ret) {
1695 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1696 return CMD_WARNING_CONFIG_FAILED;
1697 }
718e3744 1698
1ca2fd11
IR
1699 bgp_cluster_id_set(bgp, &cluster);
1700 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1701
1ca2fd11 1702 return CMD_SUCCESS;
718e3744 1703}
1704
1ca2fd11
IR
1705DEFUN (no_bgp_cluster_id,
1706 no_bgp_cluster_id_cmd,
1707 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1708 NO_STR
1709 BGP_STR
1710 "Configure Route-Reflector Cluster-id\n"
1711 "Route-Reflector Cluster-id in IP address format\n"
1712 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1713{
1ca2fd11
IR
1714 VTY_DECLVAR_CONTEXT(bgp, bgp);
1715 bgp_cluster_id_unset(bgp);
1716 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1717
1ca2fd11 1718 return CMD_SUCCESS;
718e3744 1719}
1720
c163f297
DS
1721DEFPY (bgp_norib,
1722 bgp_norib_cmd,
1723 "bgp no-rib",
1724 BGP_STR
1725 "Disable BGP route installation to RIB (Zebra)\n")
1726{
1727 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1728 vty_out(vty,
1729 "%% No-RIB option is already set, nothing to do here.\n");
1730 return CMD_SUCCESS;
1731 }
1732
1733 bgp_option_norib_set_runtime();
1734
1735 return CMD_SUCCESS;
1736}
1737
1738DEFPY (no_bgp_norib,
1739 no_bgp_norib_cmd,
1740 "no bgp no-rib",
1741 NO_STR
1742 BGP_STR
1743 "Disable BGP route installation to RIB (Zebra)\n")
1744{
1745 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1746 vty_out(vty,
1747 "%% No-RIB option is not set, nothing to do here.\n");
1748 return CMD_SUCCESS;
1749 }
1750
1751 bgp_option_norib_unset_runtime();
1752
1753 return CMD_SUCCESS;
1754}
1755
e46723a5
DS
1756DEFPY (no_bgp_send_extra_data,
1757 no_bgp_send_extra_data_cmd,
1758 "[no] bgp send-extra-data zebra",
1759 NO_STR
1760 BGP_STR
1761 "Extra data to Zebra for display/use\n"
1762 "To zebra\n")
1763{
ec0acb80
DA
1764 if (no)
1765 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1766 else
1767 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1768
1769 return CMD_SUCCESS;
1770}
1771
1ca2fd11
IR
1772DEFUN (bgp_confederation_identifier,
1773 bgp_confederation_identifier_cmd,
1774 "bgp confederation identifier (1-4294967295)",
e9273987 1775 BGP_STR
1ca2fd11
IR
1776 "AS confederation parameters\n"
1777 "AS number\n"
1778 "Set routing domain confederation AS\n")
718e3744 1779{
1ca2fd11 1780 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1781 int idx_number = 3;
1ca2fd11 1782 as_t as;
718e3744 1783
1ca2fd11 1784 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1785
1ca2fd11 1786 bgp_confederation_id_set(bgp, as);
718e3744 1787
1ca2fd11 1788 return CMD_SUCCESS;
718e3744 1789}
1790
1ca2fd11
IR
1791DEFUN (no_bgp_confederation_identifier,
1792 no_bgp_confederation_identifier_cmd,
1793 "no bgp confederation identifier [(1-4294967295)]",
1794 NO_STR
e9273987 1795 BGP_STR
1ca2fd11
IR
1796 "AS confederation parameters\n"
1797 "AS number\n"
1798 "Set routing domain confederation AS\n")
ff8a8a7a 1799{
1ca2fd11
IR
1800 VTY_DECLVAR_CONTEXT(bgp, bgp);
1801 bgp_confederation_id_unset(bgp);
1802
1803 return CMD_SUCCESS;
ff8a8a7a
CS
1804}
1805
1ca2fd11
IR
1806DEFUN (bgp_confederation_peers,
1807 bgp_confederation_peers_cmd,
1808 "bgp confederation peers (1-4294967295)...",
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 = 3;
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);
718e3744 1821
1ca2fd11
IR
1822 if (bgp->as == as) {
1823 vty_out(vty,
1824 "%% Local member-AS not allowed in confed peer list\n");
1825 continue;
1826 }
1827
1828 bgp_confederation_peers_add(bgp, as);
1829 }
1830 return CMD_SUCCESS;
718e3744 1831}
1832
1ca2fd11
IR
1833DEFUN (no_bgp_confederation_peers,
1834 no_bgp_confederation_peers_cmd,
1835 "no bgp confederation peers (1-4294967295)...",
1836 NO_STR
e9273987 1837 BGP_STR
1ca2fd11
IR
1838 "AS confederation parameters\n"
1839 "Peer ASs in BGP confederation\n"
1840 AS_STR)
718e3744 1841{
1ca2fd11 1842 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1843 int idx_asn = 4;
1ca2fd11 1844 as_t as;
d62a17ae 1845 int i;
718e3744 1846
1ca2fd11
IR
1847 for (i = idx_asn; i < argc; i++) {
1848 as = strtoul(argv[i]->arg, NULL, 10);
ff8a8a7a 1849
1ca2fd11
IR
1850 bgp_confederation_peers_remove(bgp, as);
1851 }
1852 return CMD_SUCCESS;
718e3744 1853}
6b0655a2 1854
5e242b0d
DS
1855/**
1856 * Central routine for maximum-paths configuration.
1857 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1858 * @set: 1 for setting values, 0 for removing the max-paths config.
1859 */
585f1adc
IR
1860static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1861 const char *mpaths, uint16_t options,
1862 int set)
d62a17ae 1863{
585f1adc
IR
1864 VTY_DECLVAR_CONTEXT(bgp, bgp);
1865 uint16_t maxpaths = 0;
d62a17ae 1866 int ret;
585f1adc
IR
1867 afi_t afi;
1868 safi_t safi;
1869
1870 afi = bgp_node_afi(vty);
1871 safi = bgp_node_safi(vty);
d62a17ae 1872
1873 if (set) {
585f1adc 1874 maxpaths = strtol(mpaths, NULL, 10);
d62a17ae 1875 if (maxpaths > multipath_num) {
585f1adc 1876 vty_out(vty,
d62a17ae 1877 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1878 maxpaths, multipath_num);
1879 return CMD_WARNING_CONFIG_FAILED;
1880 }
1881 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1882 options);
1883 } else
1884 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1885
1886 if (ret < 0) {
585f1adc 1887 vty_out(vty,
d62a17ae 1888 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1889 (set == 1) ? "" : "un",
1890 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1891 maxpaths, afi, safi);
1892 return CMD_WARNING_CONFIG_FAILED;
1893 }
1894
1895 bgp_recalculate_all_bestpaths(bgp);
1896
1897 return CMD_SUCCESS;
165b5fff
JB
1898}
1899
1ca2fd11
IR
1900DEFUN (bgp_maxmed_admin,
1901 bgp_maxmed_admin_cmd,
1902 "bgp max-med administrative ",
1903 BGP_STR
1904 "Advertise routes with max-med\n"
1905 "Administratively applied, for an indefinite period\n")
abc920f8 1906{
1ca2fd11 1907 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1908
1ca2fd11
IR
1909 bgp->v_maxmed_admin = 1;
1910 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
ff8a8a7a 1911
1ca2fd11 1912 bgp_maxmed_update(bgp);
abc920f8 1913
1ca2fd11 1914 return CMD_SUCCESS;
ff8a8a7a
CS
1915}
1916
1ca2fd11
IR
1917DEFUN (bgp_maxmed_admin_medv,
1918 bgp_maxmed_admin_medv_cmd,
1919 "bgp max-med administrative (0-4294967295)",
1920 BGP_STR
1921 "Advertise routes with max-med\n"
1922 "Administratively applied, for an indefinite period\n"
1923 "Max MED value to be used\n")
abc920f8 1924{
1ca2fd11 1925 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1926 int idx_number = 3;
abc920f8 1927
1ca2fd11
IR
1928 bgp->v_maxmed_admin = 1;
1929 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1930
1ca2fd11 1931 bgp_maxmed_update(bgp);
abc920f8 1932
1ca2fd11 1933 return CMD_SUCCESS;
abc920f8
DS
1934}
1935
1ca2fd11
IR
1936DEFUN (no_bgp_maxmed_admin,
1937 no_bgp_maxmed_admin_cmd,
1938 "no bgp max-med administrative [(0-4294967295)]",
1939 NO_STR
1940 BGP_STR
1941 "Advertise routes with max-med\n"
1942 "Administratively applied, for an indefinite period\n"
1943 "Max MED value to be used\n")
abc920f8 1944{
1ca2fd11
IR
1945 VTY_DECLVAR_CONTEXT(bgp, bgp);
1946 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1947 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1948 bgp_maxmed_update(bgp);
ff8a8a7a 1949
1ca2fd11 1950 return CMD_SUCCESS;
abc920f8
DS
1951}
1952
1ca2fd11
IR
1953DEFUN (bgp_maxmed_onstartup,
1954 bgp_maxmed_onstartup_cmd,
1955 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1956 BGP_STR
1957 "Advertise routes with max-med\n"
1958 "Effective on a startup\n"
1959 "Time (seconds) period for max-med\n"
1960 "Max MED value to be used\n")
abc920f8 1961{
1ca2fd11 1962 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1963 int idx = 0;
4668a151 1964
d62a17ae 1965 argv_find(argv, argc, "(5-86400)", &idx);
1ca2fd11 1966 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 1967 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1ca2fd11 1968 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 1969 else
1ca2fd11 1970 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1971
1ca2fd11
IR
1972 bgp_maxmed_update(bgp);
1973
1974 return CMD_SUCCESS;
abc920f8
DS
1975}
1976
1ca2fd11
IR
1977DEFUN (no_bgp_maxmed_onstartup,
1978 no_bgp_maxmed_onstartup_cmd,
1979 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1980 NO_STR
1981 BGP_STR
1982 "Advertise routes with max-med\n"
1983 "Effective on a startup\n"
1984 "Time (seconds) period for max-med\n"
1985 "Max MED value to be used\n")
abc920f8 1986{
1ca2fd11
IR
1987 VTY_DECLVAR_CONTEXT(bgp, bgp);
1988
1989 /* Cancel max-med onstartup if its on */
1990 if (bgp->t_maxmed_onstartup) {
1991 thread_cancel(&bgp->t_maxmed_onstartup);
1992 bgp->maxmed_onstartup_over = 1;
1993 }
abc920f8 1994
1ca2fd11
IR
1995 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1996 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1997
1ca2fd11
IR
1998 bgp_maxmed_update(bgp);
1999
2000 return CMD_SUCCESS;
abc920f8
DS
2001}
2002
d70583f7
D
2003static int bgp_global_update_delay_config_vty(struct vty *vty,
2004 uint16_t update_delay,
2005 uint16_t establish_wait)
2006{
2007 struct listnode *node, *nnode;
2008 struct bgp *bgp;
2009 bool vrf_cfg = false;
2010
2011 /*
2012 * See if update-delay is set per-vrf and warn user to delete it
2013 * Note that we only need to check this if this is the first time
2014 * setting the global config.
2015 */
2016 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2017 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2018 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2019 vty_out(vty,
2020 "%% update-delay configuration found in vrf %s\n",
2021 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2022 ? VRF_DEFAULT_NAME
2023 : bgp->name);
2024 vrf_cfg = true;
2025 }
2026 }
2027 }
2028
2029 if (vrf_cfg) {
2030 vty_out(vty,
2031 "%%Failed: global update-delay config not permitted\n");
2032 return CMD_WARNING;
2033 }
2034
2035 if (!establish_wait) { /* update-delay <delay> */
2036 bm->v_update_delay = update_delay;
2037 bm->v_establish_wait = bm->v_update_delay;
2038 } else {
2039 /* update-delay <delay> <establish-wait> */
2040 if (update_delay < establish_wait) {
2041 vty_out(vty,
2042 "%%Failed: update-delay less than the establish-wait!\n");
2043 return CMD_WARNING_CONFIG_FAILED;
2044 }
2045
2046 bm->v_update_delay = update_delay;
2047 bm->v_establish_wait = establish_wait;
2048 }
2049
2050 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2051 bgp->v_update_delay = bm->v_update_delay;
2052 bgp->v_establish_wait = bm->v_establish_wait;
2053 }
2054
2055 return CMD_SUCCESS;
2056}
2057
2058static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2059{
2060 struct listnode *node, *nnode;
2061 struct bgp *bgp;
2062
2063 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2064 bm->v_establish_wait = bm->v_update_delay;
2065
2066 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2067 bgp->v_update_delay = bm->v_update_delay;
2068 bgp->v_establish_wait = bm->v_establish_wait;
2069 }
2070
2071 return CMD_SUCCESS;
2072}
2073
2074static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2075 uint16_t establish_wait)
f188f2c4 2076{
d62a17ae 2077 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2078
d70583f7
D
2079 /* if configured globally, per-instance config is not allowed */
2080 if (bm->v_update_delay) {
2081 vty_out(vty,
2082 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2083 return CMD_WARNING_CONFIG_FAILED;
2084 }
2085
f188f2c4 2086
d70583f7 2087 if (!establish_wait) /* update-delay <delay> */
d62a17ae 2088 {
2089 bgp->v_update_delay = update_delay;
2090 bgp->v_establish_wait = bgp->v_update_delay;
2091 return CMD_SUCCESS;
2092 }
f188f2c4 2093
d62a17ae 2094 /* update-delay <delay> <establish-wait> */
d62a17ae 2095 if (update_delay < establish_wait) {
2096 vty_out(vty,
2097 "%%Failed: update-delay less than the establish-wait!\n");
2098 return CMD_WARNING_CONFIG_FAILED;
2099 }
f188f2c4 2100
d62a17ae 2101 bgp->v_update_delay = update_delay;
2102 bgp->v_establish_wait = establish_wait;
f188f2c4 2103
d62a17ae 2104 return CMD_SUCCESS;
f188f2c4
DS
2105}
2106
d62a17ae 2107static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2108{
d62a17ae 2109 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2110
d70583f7
D
2111 /* If configured globally, cannot remove from one bgp instance */
2112 if (bm->v_update_delay) {
2113 vty_out(vty,
2114 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2115 return CMD_WARNING_CONFIG_FAILED;
2116 }
d62a17ae 2117 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2118 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2119
d62a17ae 2120 return CMD_SUCCESS;
f188f2c4
DS
2121}
2122
2b791107 2123void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2124{
d70583f7
D
2125 /* If configured globally, no need to display per-instance value */
2126 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2127 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2128 if (bgp->v_update_delay != bgp->v_establish_wait)
2129 vty_out(vty, " %d", bgp->v_establish_wait);
2130 vty_out(vty, "\n");
2131 }
f188f2c4
DS
2132}
2133
d70583f7
D
2134/* Global update-delay configuration */
2135DEFPY (bgp_global_update_delay,
2136 bgp_global_update_delay_cmd,
2137 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2138 BGP_STR
2139 "Force initial delay for best-path and updates for all bgp instances\n"
2140 "Max delay in seconds\n"
2141 "Establish wait in seconds\n")
2142{
2143 return bgp_global_update_delay_config_vty(vty, delay, wait);
2144}
f188f2c4 2145
d70583f7
D
2146/* Global update-delay deconfiguration */
2147DEFPY (no_bgp_global_update_delay,
2148 no_bgp_global_update_delay_cmd,
2149 "no bgp update-delay [(0-3600) [(1-3600)]]",
2150 NO_STR
2151 BGP_STR
f188f2c4 2152 "Force initial delay for best-path and updates\n"
d70583f7
D
2153 "Max delay in seconds\n"
2154 "Establish wait in seconds\n")
f188f2c4 2155{
d70583f7 2156 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2157}
2158
d70583f7
D
2159/* Update-delay configuration */
2160
2161DEFPY (bgp_update_delay,
2162 bgp_update_delay_cmd,
2163 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2164 "Force initial delay for best-path and updates\n"
d70583f7
D
2165 "Max delay in seconds\n"
2166 "Establish wait in seconds\n")
f188f2c4 2167{
d70583f7 2168 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2169}
2170
2171/* Update-delay deconfiguration */
d70583f7 2172DEFPY (no_bgp_update_delay,
f188f2c4 2173 no_bgp_update_delay_cmd,
838758ac
DW
2174 "no update-delay [(0-3600) [(1-3600)]]",
2175 NO_STR
f188f2c4 2176 "Force initial delay for best-path and updates\n"
d70583f7
D
2177 "Max delay in seconds\n"
2178 "Establish wait in seconds\n")
f188f2c4 2179{
d62a17ae 2180 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2181}
2182
5e242b0d 2183
1ca2fd11
IR
2184static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2185 bool set)
cb1faec9 2186{
1ca2fd11
IR
2187 VTY_DECLVAR_CONTEXT(bgp, bgp);
2188
8fa7732f
QY
2189 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2190 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2191
2192 return CMD_SUCCESS;
2193}
2194
1ca2fd11
IR
2195static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2196 bool set)
555e09d4 2197{
1ca2fd11
IR
2198 VTY_DECLVAR_CONTEXT(bgp, bgp);
2199
8fa7732f
QY
2200 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2201 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2202
d62a17ae 2203 return CMD_SUCCESS;
cb1faec9
DS
2204}
2205
2b791107 2206void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2207{
555e09d4
QY
2208 uint32_t quanta =
2209 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2210 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2211 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2212}
2213
555e09d4
QY
2214void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2215{
2216 uint32_t quanta =
2217 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2218 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2219 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2220}
cb1faec9 2221
8fa7732f
QY
2222/* Packet quanta configuration
2223 *
2224 * XXX: The value set here controls the size of a stack buffer in the IO
2225 * thread. When changing these limits be careful to prevent stack overflow.
2226 *
2227 * Furthermore, the maximums used here should correspond to
2228 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2229 */
1ca2fd11
IR
2230DEFPY (bgp_wpkt_quanta,
2231 bgp_wpkt_quanta_cmd,
2232 "[no] write-quanta (1-64)$quanta",
2233 NO_STR
2234 "How many packets to write to peer socket per run\n"
2235 "Number of packets\n")
2236{
2237 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2238}
cb1faec9 2239
1ca2fd11
IR
2240DEFPY (bgp_rpkt_quanta,
2241 bgp_rpkt_quanta_cmd,
2242 "[no] read-quanta (1-10)$quanta",
2243 NO_STR
2244 "How many packets to read from peer socket per I/O cycle\n"
2245 "Number of packets\n")
2246{
2247 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
2248}
2249
2b791107 2250void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2251{
37a333fe 2252 if (!bgp->heuristic_coalesce)
d62a17ae 2253 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2254}
2255
4668a151 2256
1ca2fd11
IR
2257DEFUN (bgp_coalesce_time,
2258 bgp_coalesce_time_cmd,
2259 "coalesce-time (0-4294967295)",
2260 "Subgroup coalesce timer\n"
2261 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2262{
1ca2fd11 2263 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 2264
1ca2fd11 2265 int idx = 0;
d62a17ae 2266 argv_find(argv, argc, "(0-4294967295)", &idx);
1ca2fd11
IR
2267 bgp->heuristic_coalesce = false;
2268 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2269 return CMD_SUCCESS;
3f9c7369
DS
2270}
2271
1ca2fd11
IR
2272DEFUN (no_bgp_coalesce_time,
2273 no_bgp_coalesce_time_cmd,
2274 "no coalesce-time (0-4294967295)",
2275 NO_STR
2276 "Subgroup coalesce timer\n"
2277 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2278{
1ca2fd11 2279 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 2280
1ca2fd11
IR
2281 bgp->heuristic_coalesce = true;
2282 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2283 return CMD_SUCCESS;
3f9c7369
DS
2284}
2285
5e242b0d 2286/* Maximum-paths configuration */
585f1adc
IR
2287DEFUN (bgp_maxpaths,
2288 bgp_maxpaths_cmd,
2289 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2290 "Forward packets over multiple paths\n"
2291 "Number of paths\n")
5e242b0d 2292{
d62a17ae 2293 int idx_number = 1;
585f1adc
IR
2294 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2295 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
2296}
2297
d62a17ae 2298ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2299 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2300 "Forward packets over multiple paths\n"
2301 "Number of paths\n")
596c17ba 2302
585f1adc
IR
2303DEFUN (bgp_maxpaths_ibgp,
2304 bgp_maxpaths_ibgp_cmd,
2305 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2306 "Forward packets over multiple paths\n"
2307 "iBGP-multipath\n"
2308 "Number of paths\n")
165b5fff 2309{
d62a17ae 2310 int idx_number = 2;
585f1adc
IR
2311 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2312 argv[idx_number]->arg, 0, 1);
5e242b0d 2313}
165b5fff 2314
d62a17ae 2315ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2316 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2317 "Forward packets over multiple paths\n"
2318 "iBGP-multipath\n"
2319 "Number of paths\n")
596c17ba 2320
585f1adc
IR
2321DEFUN (bgp_maxpaths_ibgp_cluster,
2322 bgp_maxpaths_ibgp_cluster_cmd,
2323 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2324 "Forward packets over multiple paths\n"
2325 "iBGP-multipath\n"
2326 "Number of paths\n"
2327 "Match the cluster length\n")
5e242b0d 2328{
d62a17ae 2329 int idx_number = 2;
585f1adc
IR
2330 return bgp_maxpaths_config_vty(
2331 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
2332 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
2333}
2334
d62a17ae 2335ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2336 "maximum-paths ibgp " CMD_RANGE_STR(
2337 1, MULTIPATH_NUM) " equal-cluster-length",
2338 "Forward packets over multiple paths\n"
2339 "iBGP-multipath\n"
2340 "Number of paths\n"
2341 "Match the cluster length\n")
596c17ba 2342
585f1adc
IR
2343DEFUN (no_bgp_maxpaths,
2344 no_bgp_maxpaths_cmd,
2345 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2346 NO_STR
2347 "Forward packets over multiple paths\n"
2348 "Number of paths\n")
165b5fff 2349{
585f1adc 2350 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
2351}
2352
d62a17ae 2353ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2354 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2355 "Forward packets over multiple paths\n"
2356 "Number of paths\n")
596c17ba 2357
585f1adc
IR
2358DEFUN (no_bgp_maxpaths_ibgp,
2359 no_bgp_maxpaths_ibgp_cmd,
2360 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2361 NO_STR
2362 "Forward packets over multiple paths\n"
2363 "iBGP-multipath\n"
2364 "Number of paths\n"
2365 "Match the cluster length\n")
165b5fff 2366{
585f1adc 2367 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
2368}
2369
d62a17ae 2370ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2371 "no maximum-paths ibgp [" CMD_RANGE_STR(
2372 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2373 NO_STR
2374 "Forward packets over multiple paths\n"
2375 "iBGP-multipath\n"
2376 "Number of paths\n"
2377 "Match the cluster length\n")
596c17ba 2378
dd65f45e
DL
2379static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2380 afi_t afi, safi_t safi)
165b5fff 2381{
00908b7a 2382 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2383 vty_out(vty, " maximum-paths %d\n",
2384 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2385 }
165b5fff 2386
00908b7a 2387 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2388 vty_out(vty, " maximum-paths ibgp %d",
2389 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2390 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2391 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2392 vty_out(vty, " equal-cluster-length");
2393 vty_out(vty, "\n");
2394 }
165b5fff 2395}
6b0655a2 2396
718e3744 2397/* BGP timers. */
2398
1ca2fd11
IR
2399DEFUN (bgp_timers,
2400 bgp_timers_cmd,
2401 "timers bgp (0-65535) (0-65535)",
2402 "Adjust routing timers\n"
2403 "BGP timers\n"
2404 "Keepalive interval\n"
2405 "Holdtime\n")
718e3744 2406{
1ca2fd11 2407 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2408 int idx_number = 2;
2409 int idx_number_2 = 3;
1ca2fd11
IR
2410 unsigned long keepalive = 0;
2411 unsigned long holdtime = 0;
718e3744 2412
1ca2fd11
IR
2413 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2414 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 2415
1ca2fd11
IR
2416 /* Holdtime value check. */
2417 if (holdtime < 3 && holdtime != 0) {
2418 vty_out(vty,
2419 "%% hold time value must be either 0 or greater than 3\n");
2420 return CMD_WARNING_CONFIG_FAILED;
2421 }
718e3744 2422
1ca2fd11
IR
2423 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2424 BGP_DEFAULT_DELAYOPEN);
718e3744 2425
1ca2fd11 2426 return CMD_SUCCESS;
718e3744 2427}
2428
1ca2fd11
IR
2429DEFUN (no_bgp_timers,
2430 no_bgp_timers_cmd,
2431 "no timers bgp [(0-65535) (0-65535)]",
2432 NO_STR
2433 "Adjust routing timers\n"
2434 "BGP timers\n"
2435 "Keepalive interval\n"
2436 "Holdtime\n")
718e3744 2437{
1ca2fd11
IR
2438 VTY_DECLVAR_CONTEXT(bgp, bgp);
2439 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2440 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
ff8a8a7a 2441
1ca2fd11 2442 return CMD_SUCCESS;
718e3744 2443}
2444
b042667a
TI
2445/* BGP minimum holdtime. */
2446
2447DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2448 "bgp minimum-holdtime (1-65535)",
2449 "BGP specific commands\n"
2450 "BGP minimum holdtime\n"
2451 "Seconds\n")
2452{
2453 VTY_DECLVAR_CONTEXT(bgp, bgp);
2454 int idx_number = 2;
2455 unsigned long min_holdtime;
2456
2457 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2458
2459 bgp->default_min_holdtime = min_holdtime;
2460
2461 return CMD_SUCCESS;
2462}
2463
2464DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2465 "no bgp minimum-holdtime [(1-65535)]",
2466 NO_STR
2467 "BGP specific commands\n"
2468 "BGP minimum holdtime\n"
2469 "Seconds\n")
2470{
2471 VTY_DECLVAR_CONTEXT(bgp, bgp);
2472
2473 bgp->default_min_holdtime = 0;
2474
2475 return CMD_SUCCESS;
2476}
ff8a8a7a 2477
1ca2fd11
IR
2478DEFUN (bgp_client_to_client_reflection,
2479 bgp_client_to_client_reflection_cmd,
2480 "bgp client-to-client reflection",
e9273987 2481 BGP_STR
1ca2fd11
IR
2482 "Configure client to client route reflection\n"
2483 "reflection of routes allowed\n")
718e3744 2484{
1ca2fd11
IR
2485 VTY_DECLVAR_CONTEXT(bgp, bgp);
2486 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2487 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2488
1ca2fd11 2489 return CMD_SUCCESS;
718e3744 2490}
2491
1ca2fd11
IR
2492DEFUN (no_bgp_client_to_client_reflection,
2493 no_bgp_client_to_client_reflection_cmd,
2494 "no bgp client-to-client reflection",
2495 NO_STR
e9273987 2496 BGP_STR
1ca2fd11
IR
2497 "Configure client to client route reflection\n"
2498 "reflection of routes allowed\n")
718e3744 2499{
1ca2fd11
IR
2500 VTY_DECLVAR_CONTEXT(bgp, bgp);
2501 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2502 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2503
1ca2fd11 2504 return CMD_SUCCESS;
718e3744 2505}
2506
2507/* "bgp always-compare-med" configuration. */
1ca2fd11
IR
2508DEFUN (bgp_always_compare_med,
2509 bgp_always_compare_med_cmd,
2510 "bgp always-compare-med",
e9273987 2511 BGP_STR
1ca2fd11 2512 "Allow comparing MED from different neighbors\n")
718e3744 2513{
1ca2fd11
IR
2514 VTY_DECLVAR_CONTEXT(bgp, bgp);
2515 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2516 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2517
1ca2fd11 2518 return CMD_SUCCESS;
718e3744 2519}
2520
1ca2fd11
IR
2521DEFUN (no_bgp_always_compare_med,
2522 no_bgp_always_compare_med_cmd,
2523 "no bgp always-compare-med",
2524 NO_STR
e9273987 2525 BGP_STR
1ca2fd11 2526 "Allow comparing MED from different neighbors\n")
718e3744 2527{
1ca2fd11
IR
2528 VTY_DECLVAR_CONTEXT(bgp, bgp);
2529 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2530 bgp_recalculate_all_bestpaths(bgp);
6b0655a2 2531
1ca2fd11 2532 return CMD_SUCCESS;
2adac256
DA
2533}
2534
2adac256 2535
1ca2fd11
IR
2536DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2537 "bgp ebgp-requires-policy",
e9273987 2538 BGP_STR
1ca2fd11 2539 "Require in and out policy for eBGP peers (RFC8212)\n")
2adac256 2540{
1ca2fd11
IR
2541 VTY_DECLVAR_CONTEXT(bgp, bgp);
2542 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2543 return CMD_SUCCESS;
2adac256
DA
2544}
2545
1ca2fd11
IR
2546DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2547 "no bgp ebgp-requires-policy",
2548 NO_STR
e9273987 2549 BGP_STR
1ca2fd11 2550 "Require in and out policy for eBGP peers (RFC8212)\n")
ff8a8a7a 2551{
1ca2fd11
IR
2552 VTY_DECLVAR_CONTEXT(bgp, bgp);
2553 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2554 return CMD_SUCCESS;
ff8a8a7a 2555}
9dac9fc8 2556
1ca2fd11
IR
2557DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2558 "bgp suppress-duplicates",
e9273987 2559 BGP_STR
1ca2fd11 2560 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2561{
1ca2fd11
IR
2562 VTY_DECLVAR_CONTEXT(bgp, bgp);
2563 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2564 return CMD_SUCCESS;
9dac9fc8
DA
2565}
2566
1ca2fd11
IR
2567DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2568 "no bgp suppress-duplicates",
2569 NO_STR
e9273987 2570 BGP_STR
1ca2fd11 2571 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2572{
1ca2fd11
IR
2573 VTY_DECLVAR_CONTEXT(bgp, bgp);
2574 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2575 return CMD_SUCCESS;
9dac9fc8
DA
2576}
2577
fb29348a
DA
2578DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2579 "bgp reject-as-sets",
e9273987 2580 BGP_STR
fb29348a
DA
2581 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2582{
2583 VTY_DECLVAR_CONTEXT(bgp, bgp);
2584 struct listnode *node, *nnode;
2585 struct peer *peer;
2586
7f972cd8 2587 bgp->reject_as_sets = true;
fb29348a
DA
2588
2589 /* Reset existing BGP sessions to reject routes
2590 * with aspath containing AS_SET or AS_CONFED_SET.
2591 */
2592 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2593 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2594 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2595 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2596 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2597 }
2598 }
2599
2600 return CMD_SUCCESS;
2601}
2602
2603DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2604 "no bgp reject-as-sets",
2605 NO_STR
e9273987 2606 BGP_STR
fb29348a
DA
2607 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2608{
2609 VTY_DECLVAR_CONTEXT(bgp, bgp);
2610 struct listnode *node, *nnode;
2611 struct peer *peer;
2612
7f972cd8 2613 bgp->reject_as_sets = false;
fb29348a
DA
2614
2615 /* Reset existing BGP sessions to reject routes
2616 * with aspath containing AS_SET or AS_CONFED_SET.
2617 */
2618 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2619 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2620 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2621 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2622 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2623 }
2624 }
2625
2626 return CMD_SUCCESS;
2627}
9dac9fc8 2628
718e3744 2629/* "bgp deterministic-med" configuration. */
1ca2fd11 2630DEFUN (bgp_deterministic_med,
718e3744 2631 bgp_deterministic_med_cmd,
2632 "bgp deterministic-med",
e9273987 2633 BGP_STR
718e3744 2634 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2635{
1ca2fd11
IR
2636 VTY_DECLVAR_CONTEXT(bgp, bgp);
2637
2638 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2639 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2640 bgp_recalculate_all_bestpaths(bgp);
2641 }
7aafcaca 2642
1ca2fd11 2643 return CMD_SUCCESS;
718e3744 2644}
2645
1ca2fd11 2646DEFUN (no_bgp_deterministic_med,
718e3744 2647 no_bgp_deterministic_med_cmd,
2648 "no bgp deterministic-med",
2649 NO_STR
e9273987 2650 BGP_STR
718e3744 2651 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2652{
1ca2fd11
IR
2653 VTY_DECLVAR_CONTEXT(bgp, bgp);
2654 int bestpath_per_as_used;
2655 afi_t afi;
2656 safi_t safi;
2657 struct peer *peer;
2658 struct listnode *node, *nnode;
2659
2660 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2661 bestpath_per_as_used = 0;
2662
2663 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2664 FOREACH_AFI_SAFI (afi, safi)
2665 if (bgp_addpath_dmed_required(
2666 peer->addpath_type[afi][safi])) {
2667 bestpath_per_as_used = 1;
2668 break;
2669 }
2670
2671 if (bestpath_per_as_used)
2672 break;
2673 }
2674
2675 if (bestpath_per_as_used) {
2676 vty_out(vty,
2677 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2678 return CMD_WARNING_CONFIG_FAILED;
2679 } else {
2680 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2681 bgp_recalculate_all_bestpaths(bgp);
2682 }
2683 }
d62a17ae 2684
1ca2fd11 2685 return CMD_SUCCESS;
718e3744 2686}
538621f2 2687
055679e9 2688/* "bgp graceful-restart mode" configuration. */
538621f2 2689DEFUN (bgp_graceful_restart,
2ba1fe69 2690 bgp_graceful_restart_cmd,
2691 "bgp graceful-restart",
e9273987 2692 BGP_STR
2ba1fe69 2693 GR_CMD
055679e9 2694 )
538621f2 2695{
055679e9 2696 int ret = BGP_GR_FAILURE;
2697
2698 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2699 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2700
d62a17ae 2701 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2702
2703 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2704
36235319
QY
2705 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2706 ret);
5cce3f05 2707
055679e9 2708 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2709 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2710 vty_out(vty,
2711 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2712 return bgp_vty_return(vty, ret);
538621f2 2713}
2714
2715DEFUN (no_bgp_graceful_restart,
2ba1fe69 2716 no_bgp_graceful_restart_cmd,
2717 "no bgp graceful-restart",
2718 NO_STR
e9273987 2719 BGP_STR
2ba1fe69 2720 NO_GR_CMD
055679e9 2721 )
538621f2 2722{
d62a17ae 2723 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2724
2725 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2726 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2727
2728 int ret = BGP_GR_FAILURE;
2729
2730 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2731
36235319
QY
2732 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2733 ret);
5cce3f05 2734
055679e9 2735 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2736 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2737 vty_out(vty,
2738 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2739
2740 return bgp_vty_return(vty, ret);
538621f2 2741}
2742
93406d87 2743DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2744 bgp_graceful_restart_stalepath_time_cmd,
2745 "bgp graceful-restart stalepath-time (1-4095)",
e9273987 2746 BGP_STR
2ba1fe69 2747 "Graceful restart capability parameters\n"
2748 "Set the max time to hold onto restarting peer's stale paths\n"
2749 "Delay value (seconds)\n")
93406d87 2750{
d62a17ae 2751 VTY_DECLVAR_CONTEXT(bgp, bgp);
2752 int idx_number = 3;
d7c0a89a 2753 uint32_t stalepath;
93406d87 2754
d62a17ae 2755 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2756 bgp->stalepath_time = stalepath;
2757 return CMD_SUCCESS;
93406d87 2758}
2759
eb6f1b41 2760DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2761 bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2762 "bgp graceful-restart restart-time (0-4095)",
e9273987 2763 BGP_STR
2ba1fe69 2764 "Graceful restart capability parameters\n"
2765 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2766 "Delay value (seconds)\n")
eb6f1b41 2767{
d62a17ae 2768 VTY_DECLVAR_CONTEXT(bgp, bgp);
2769 int idx_number = 3;
d7c0a89a 2770 uint32_t restart;
eb6f1b41 2771
d62a17ae 2772 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2773 bgp->restart_time = restart;
2774 return CMD_SUCCESS;
eb6f1b41
PG
2775}
2776
cfd47646 2777DEFUN (bgp_graceful_restart_select_defer_time,
2778 bgp_graceful_restart_select_defer_time_cmd,
2779 "bgp graceful-restart select-defer-time (0-3600)",
e9273987 2780 BGP_STR
cfd47646 2781 "Graceful restart capability parameters\n"
2782 "Set the time to defer the BGP route selection after restart\n"
2783 "Delay value (seconds, 0 - disable)\n")
2784{
2785 VTY_DECLVAR_CONTEXT(bgp, bgp);
2786 int idx_number = 3;
2787 uint32_t defer_time;
2788
2789 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2790 bgp->select_defer_time = defer_time;
2791 if (defer_time == 0)
892fedb6 2792 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2793 else
892fedb6 2794 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2795
2796 return CMD_SUCCESS;
2797}
2798
93406d87 2799DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2800 no_bgp_graceful_restart_stalepath_time_cmd,
2801 "no bgp graceful-restart stalepath-time [(1-4095)]",
2802 NO_STR
e9273987 2803 BGP_STR
2ba1fe69 2804 "Graceful restart capability parameters\n"
2805 "Set the max time to hold onto restarting peer's stale paths\n"
2806 "Delay value (seconds)\n")
93406d87 2807{
d62a17ae 2808 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2809
d62a17ae 2810 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2811 return CMD_SUCCESS;
93406d87 2812}
2813
eb6f1b41 2814DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2815 no_bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2816 "no bgp graceful-restart restart-time [(0-4095)]",
2ba1fe69 2817 NO_STR
e9273987 2818 BGP_STR
2ba1fe69 2819 "Graceful restart capability parameters\n"
2820 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2821 "Delay value (seconds)\n")
eb6f1b41 2822{
d62a17ae 2823 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2824
d62a17ae 2825 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2826 return CMD_SUCCESS;
eb6f1b41
PG
2827}
2828
cfd47646 2829DEFUN (no_bgp_graceful_restart_select_defer_time,
2830 no_bgp_graceful_restart_select_defer_time_cmd,
2831 "no bgp graceful-restart select-defer-time [(0-3600)]",
2832 NO_STR
e9273987 2833 BGP_STR
cfd47646 2834 "Graceful restart capability parameters\n"
2835 "Set the time to defer the BGP route selection after restart\n"
2836 "Delay value (seconds)\n")
2837{
2838 VTY_DECLVAR_CONTEXT(bgp, bgp);
2839
2840 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2841 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2842
2843 return CMD_SUCCESS;
2844}
2845
43fc21b3 2846DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2847 bgp_graceful_restart_preserve_fw_cmd,
2848 "bgp graceful-restart preserve-fw-state",
e9273987 2849 BGP_STR
2ba1fe69 2850 "Graceful restart capability parameters\n"
2851 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2852{
d62a17ae 2853 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2854 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2855 return CMD_SUCCESS;
43fc21b3
JC
2856}
2857
2858DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2859 no_bgp_graceful_restart_preserve_fw_cmd,
2860 "no bgp graceful-restart preserve-fw-state",
2861 NO_STR
e9273987 2862 BGP_STR
2ba1fe69 2863 "Graceful restart capability parameters\n"
2864 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2865{
d62a17ae 2866 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2867 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2868 return CMD_SUCCESS;
43fc21b3
JC
2869}
2870
055679e9 2871DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2872 bgp_graceful_restart_disable_cmd,
2873 "bgp graceful-restart-disable",
e9273987 2874 BGP_STR
2ba1fe69 2875 GR_DISABLE)
055679e9 2876{
2877 int ret = BGP_GR_FAILURE;
2878
2879 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2880 zlog_debug(
2ba1fe69 2881 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2882
055679e9 2883 VTY_DECLVAR_CONTEXT(bgp, bgp);
2884
2885 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2886
dc95985f 2887 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2888 bgp->peer, ret);
5cce3f05 2889
055679e9 2890 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2891 zlog_debug(
2ba1fe69 2892 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2893 vty_out(vty,
2894 "Graceful restart configuration changed, reset all peers to take effect\n");
2895
055679e9 2896 return bgp_vty_return(vty, ret);
2897}
2898
2899DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2900 no_bgp_graceful_restart_disable_cmd,
2901 "no bgp graceful-restart-disable",
2902 NO_STR
e9273987 2903 BGP_STR
2ba1fe69 2904 NO_GR_DISABLE
055679e9 2905 )
2906{
2907 VTY_DECLVAR_CONTEXT(bgp, bgp);
2908
2909 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2910 zlog_debug(
2ba1fe69 2911 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2912
2913 int ret = BGP_GR_FAILURE;
2914
2915 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2916
36235319
QY
2917 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2918 ret);
5cce3f05 2919
055679e9 2920 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2921 zlog_debug(
2ba1fe69 2922 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2923 vty_out(vty,
2924 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2925
2926 return bgp_vty_return(vty, ret);
2927}
2928
2929DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2930 bgp_neighbor_graceful_restart_set_cmd,
2931 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2932 NEIGHBOR_STR
2933 NEIGHBOR_ADDR_STR2
2934 GR_NEIGHBOR_CMD
055679e9 2935 )
2936{
2937 int idx_peer = 1;
2938 struct peer *peer;
2939 int ret = BGP_GR_FAILURE;
2940
dc95985f 2941 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2942
055679e9 2943 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2944 zlog_debug(
2ba1fe69 2945 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2946
055679e9 2947 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2948 if (!peer)
2949 return CMD_WARNING_CONFIG_FAILED;
2950
2951 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2952
dc95985f 2953 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2954 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2955
2956 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2957 zlog_debug(
2ba1fe69 2958 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2959 vty_out(vty,
2960 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2961
2962 return bgp_vty_return(vty, ret);
2963}
2964
2965DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 2966 no_bgp_neighbor_graceful_restart_set_cmd,
2967 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2968 NO_STR
2969 NEIGHBOR_STR
2970 NEIGHBOR_ADDR_STR2
2971 NO_GR_NEIGHBOR_CMD
055679e9 2972 )
2973{
2974 int idx_peer = 2;
2975 int ret = BGP_GR_FAILURE;
2976 struct peer *peer;
2977
dc95985f 2978 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2979
055679e9 2980 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2981 if (!peer)
2982 return CMD_WARNING_CONFIG_FAILED;
2983
2984 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2985 zlog_debug(
2ba1fe69 2986 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 2987
2988 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2989
dc95985f 2990 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2991 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2992
2993 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2994 zlog_debug(
2ba1fe69 2995 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2996 vty_out(vty,
2997 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2998
2999 return bgp_vty_return(vty, ret);
3000}
3001
3002DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 3003 bgp_neighbor_graceful_restart_helper_set_cmd,
3004 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3005 NEIGHBOR_STR
3006 NEIGHBOR_ADDR_STR2
3007 GR_NEIGHBOR_HELPER_CMD
055679e9 3008 )
3009{
3010 int idx_peer = 1;
3011 struct peer *peer;
3012 int ret = BGP_GR_FAILURE;
3013
dc95985f 3014 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3015
055679e9 3016 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3017 zlog_debug(
2ba1fe69 3018 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 3019
055679e9 3020 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3021
055679e9 3022 if (!peer)
3023 return CMD_WARNING_CONFIG_FAILED;
3024
3025
3026 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 3027
dc95985f 3028 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3029 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 3030
055679e9 3031 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3032 zlog_debug(
2ba1fe69 3033 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3034 vty_out(vty,
3035 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3036
3037 return bgp_vty_return(vty, ret);
3038}
3039
3040DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3041 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3042 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3043 NO_STR
3044 NEIGHBOR_STR
3045 NEIGHBOR_ADDR_STR2
3046 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3047 )
3048{
3049 int idx_peer = 2;
3050 int ret = BGP_GR_FAILURE;
3051 struct peer *peer;
3052
dc95985f 3053 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3054
055679e9 3055 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3056 if (!peer)
3057 return CMD_WARNING_CONFIG_FAILED;
3058
3059 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3060 zlog_debug(
2ba1fe69 3061 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3062
36235319 3063 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3064
dc95985f 3065 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3066 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3067
3068 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3069 zlog_debug(
2ba1fe69 3070 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3071 vty_out(vty,
3072 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3073
3074 return bgp_vty_return(vty, ret);
3075}
3076
3077DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3078 bgp_neighbor_graceful_restart_disable_set_cmd,
3079 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3080 NEIGHBOR_STR
3081 NEIGHBOR_ADDR_STR2
3082 GR_NEIGHBOR_DISABLE_CMD
055679e9 3083 )
3084{
3085 int idx_peer = 1;
3086 struct peer *peer;
3087 int ret = BGP_GR_FAILURE;
3088
dc95985f 3089 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3090
055679e9 3091 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3092 zlog_debug(
2ba1fe69 3093 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3094
3095 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3096 if (!peer)
3097 return CMD_WARNING_CONFIG_FAILED;
3098
36235319 3099 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3100
3101 if (peer->bgp->t_startup)
3102 bgp_peer_gr_flags_update(peer);
3103
dc95985f 3104 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3105 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3106
055679e9 3107 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3108 zlog_debug(
2ba1fe69 3109 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3110 vty_out(vty,
3111 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3112
3113 return bgp_vty_return(vty, ret);
3114}
3115
3116DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3117 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3118 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3119 NO_STR
3120 NEIGHBOR_STR
3121 NEIGHBOR_ADDR_STR2
3122 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3123 )
3124{
3125 int idx_peer = 2;
3126 int ret = BGP_GR_FAILURE;
3127 struct peer *peer;
3128
dc95985f 3129 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3130
055679e9 3131 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3132 if (!peer)
3133 return CMD_WARNING_CONFIG_FAILED;
3134
3135 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3136 zlog_debug(
2ba1fe69 3137 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3138
3139 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3140
dc95985f 3141 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3142 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3143
3144 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3145 zlog_debug(
2ba1fe69 3146 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3147 vty_out(vty,
3148 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3149
3150 return bgp_vty_return(vty, ret);
3151}
3152
d6e3c15b 3153DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3154 bgp_graceful_restart_disable_eor_cmd,
3155 "bgp graceful-restart disable-eor",
e9273987 3156 BGP_STR
d6e3c15b 3157 "Graceful restart configuration parameters\n"
3158 "Disable EOR Check\n")
3159{
3160 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3161 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3162
d6e3c15b 3163 return CMD_SUCCESS;
3164}
3165
3166DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3167 no_bgp_graceful_restart_disable_eor_cmd,
3168 "no bgp graceful-restart disable-eor",
3169 NO_STR
e9273987 3170 BGP_STR
d6e3c15b 3171 "Graceful restart configuration parameters\n"
3172 "Disable EOR Check\n")
3173{
3174 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3175 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3176
3177 return CMD_SUCCESS;
3178}
3179
3180DEFUN (bgp_graceful_restart_rib_stale_time,
3181 bgp_graceful_restart_rib_stale_time_cmd,
3182 "bgp graceful-restart rib-stale-time (1-3600)",
e9273987 3183 BGP_STR
dc95985f 3184 "Graceful restart configuration parameters\n"
3185 "Specify the stale route removal timer in rib\n"
3186 "Delay value (seconds)\n")
3187{
3188 VTY_DECLVAR_CONTEXT(bgp, bgp);
3189 int idx_number = 3;
3190 uint32_t stale_time;
3191
3192 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3193 bgp->rib_stale_time = stale_time;
3194 /* Send the stale timer update message to RIB */
3195 if (bgp_zebra_stale_timer_update(bgp))
3196 return CMD_WARNING;
3197
3198 return CMD_SUCCESS;
3199}
3200
3201DEFUN (no_bgp_graceful_restart_rib_stale_time,
3202 no_bgp_graceful_restart_rib_stale_time_cmd,
3203 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3204 NO_STR
e9273987 3205 BGP_STR
dc95985f 3206 "Graceful restart configuration parameters\n"
3207 "Specify the stale route removal timer in rib\n"
3208 "Delay value (seconds)\n")
3209{
3210 VTY_DECLVAR_CONTEXT(bgp, bgp);
3211
3212 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3213 /* Send the stale timer update message to RIB */
3214 if (bgp_zebra_stale_timer_update(bgp))
3215 return CMD_WARNING;
3216
d6e3c15b 3217 return CMD_SUCCESS;
3218}
3219
8606be87 3220DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
7f8a9a24
DA
3221 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3222 BGP_STR
8606be87
DA
3223 "Enable Long-lived Graceful Restart\n"
3224 "Specifies maximum time to wait before purging long-lived stale routes\n"
3225 "Stale time value (seconds)\n")
3226{
3227 VTY_DECLVAR_CONTEXT(bgp, bgp);
3228
3229 uint32_t llgr_stale_time;
3230
3231 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3232 bgp->llgr_stale_time = llgr_stale_time;
3233
3234 return CMD_SUCCESS;
3235}
3236
3237DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
7f8a9a24 3238 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
8606be87
DA
3239 NO_STR BGP_STR
3240 "Enable Long-lived Graceful Restart\n"
3241 "Specifies maximum time to wait before purging long-lived stale routes\n"
3242 "Stale time value (seconds)\n")
3243{
3244 VTY_DECLVAR_CONTEXT(bgp, bgp);
3245
3246 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3247
3248 return CMD_SUCCESS;
3249}
3250
1ca2fd11
IR
3251static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3252 struct bgp *bgp)
05bd726c 3253{
3254 bgp_static_redo_import_check(bgp);
3255 bgp_redistribute_redo(bgp);
1ca2fd11
IR
3256 bgp_clear_star_soft_out(vty, bgp->name);
3257 bgp_clear_star_soft_in(vty, bgp->name);
05bd726c 3258}
3259
3260static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3261{
3262 struct listnode *node, *nnode;
3263 struct bgp *bgp;
3264 bool vrf_cfg = false;
3265
3266 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3267 return CMD_SUCCESS;
3268
3269 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3270 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3271 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3272 vty_out(vty,
3273 "%% graceful-shutdown configuration found in vrf %s\n",
3274 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3275 VRF_DEFAULT_NAME : bgp->name);
3276 vrf_cfg = true;
3277 }
3278 }
3279
3280 if (vrf_cfg) {
3281 vty_out(vty,
3282 "%%Failed: global graceful-shutdown not permitted\n");
3283 return CMD_WARNING;
3284 }
3285
3286 /* Set flag globally */
3287 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3288
3289 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3290 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3291 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3292
3293 return CMD_SUCCESS;
3294}
3295
3296static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3297{
3298 struct listnode *node, *nnode;
3299 struct bgp *bgp;
3300
3301 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3302 return CMD_SUCCESS;
3303
3304 /* Unset flag globally */
3305 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3306
3307 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3308 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3309 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3310
3311 return CMD_SUCCESS;
3312}
3313
7f323236
DW
3314/* "bgp graceful-shutdown" configuration */
3315DEFUN (bgp_graceful_shutdown,
3316 bgp_graceful_shutdown_cmd,
3317 "bgp graceful-shutdown",
3318 BGP_STR
3319 "Graceful shutdown parameters\n")
3320{
05bd726c 3321 if (vty->node == CONFIG_NODE)
3322 return bgp_global_graceful_shutdown_config_vty(vty);
3323
1ca2fd11 3324 VTY_DECLVAR_CONTEXT(bgp, bgp);
7f323236 3325
1ca2fd11
IR
3326 /* if configured globally, per-instance config is not allowed */
3327 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3328 vty_out(vty,
3329 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3330 return CMD_WARNING_CONFIG_FAILED;
3331 }
3332
3333 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3334 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3335 bgp_initiate_graceful_shut_unshut(vty, bgp);
3336 }
3337
3338 return CMD_SUCCESS;
7f323236
DW
3339}
3340
1ca2fd11 3341DEFUN (no_bgp_graceful_shutdown,
7f323236
DW
3342 no_bgp_graceful_shutdown_cmd,
3343 "no bgp graceful-shutdown",
3344 NO_STR
3345 BGP_STR
3346 "Graceful shutdown parameters\n")
3347{
05bd726c 3348 if (vty->node == CONFIG_NODE)
3349 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3350
1ca2fd11 3351 VTY_DECLVAR_CONTEXT(bgp, bgp);
05bd726c 3352
1ca2fd11
IR
3353 /* If configured globally, cannot remove from one bgp instance */
3354 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3355 vty_out(vty,
3356 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3357 return CMD_WARNING_CONFIG_FAILED;
3358 }
7f323236 3359
1ca2fd11
IR
3360 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3361 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3362 bgp_initiate_graceful_shut_unshut(vty, bgp);
3363 }
3364
3365 return CMD_SUCCESS;
7f323236
DW
3366}
3367
718e3744 3368/* "bgp fast-external-failover" configuration. */
1ca2fd11 3369DEFUN (bgp_fast_external_failover,
718e3744 3370 bgp_fast_external_failover_cmd,
3371 "bgp fast-external-failover",
3372 BGP_STR
3373 "Immediately reset session if a link to a directly connected external peer goes down\n")
3374{
1ca2fd11
IR
3375 VTY_DECLVAR_CONTEXT(bgp, bgp);
3376 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3377 return CMD_SUCCESS;
718e3744 3378}
3379
1ca2fd11 3380DEFUN (no_bgp_fast_external_failover,
718e3744 3381 no_bgp_fast_external_failover_cmd,
3382 "no bgp fast-external-failover",
3383 NO_STR
3384 BGP_STR
3385 "Immediately reset session if a link to a directly connected external peer goes down\n")
3386{
1ca2fd11
IR
3387 VTY_DECLVAR_CONTEXT(bgp, bgp);
3388 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3389 return CMD_SUCCESS;
718e3744 3390}
6b0655a2 3391
718e3744 3392/* "bgp bestpath compare-routerid" configuration. */
1ca2fd11
IR
3393DEFUN (bgp_bestpath_compare_router_id,
3394 bgp_bestpath_compare_router_id_cmd,
3395 "bgp bestpath compare-routerid",
e9273987 3396 BGP_STR
1ca2fd11
IR
3397 "Change the default bestpath selection\n"
3398 "Compare router-id for identical EBGP paths\n")
718e3744 3399{
1ca2fd11
IR
3400 VTY_DECLVAR_CONTEXT(bgp, bgp);
3401 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3402 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3403
1ca2fd11 3404 return CMD_SUCCESS;
718e3744 3405}
3406
1ca2fd11
IR
3407DEFUN (no_bgp_bestpath_compare_router_id,
3408 no_bgp_bestpath_compare_router_id_cmd,
3409 "no bgp bestpath compare-routerid",
3410 NO_STR
e9273987 3411 BGP_STR
1ca2fd11
IR
3412 "Change the default bestpath selection\n"
3413 "Compare router-id for identical EBGP paths\n")
718e3744 3414{
1ca2fd11
IR
3415 VTY_DECLVAR_CONTEXT(bgp, bgp);
3416 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3417 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3418
1ca2fd11 3419 return CMD_SUCCESS;
718e3744 3420}
6b0655a2 3421
718e3744 3422/* "bgp bestpath as-path ignore" configuration. */
1ca2fd11
IR
3423DEFUN (bgp_bestpath_aspath_ignore,
3424 bgp_bestpath_aspath_ignore_cmd,
3425 "bgp bestpath as-path ignore",
e9273987 3426 BGP_STR
1ca2fd11
IR
3427 "Change the default bestpath selection\n"
3428 "AS-path attribute\n"
3429 "Ignore as-path length in selecting a route\n")
718e3744 3430{
1ca2fd11
IR
3431 VTY_DECLVAR_CONTEXT(bgp, bgp);
3432 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3433 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3434
1ca2fd11 3435 return CMD_SUCCESS;
718e3744 3436}
3437
1ca2fd11
IR
3438DEFUN (no_bgp_bestpath_aspath_ignore,
3439 no_bgp_bestpath_aspath_ignore_cmd,
3440 "no bgp bestpath as-path ignore",
3441 NO_STR
e9273987 3442 BGP_STR
1ca2fd11
IR
3443 "Change the default bestpath selection\n"
3444 "AS-path attribute\n"
3445 "Ignore as-path length in selecting a route\n")
718e3744 3446{
1ca2fd11
IR
3447 VTY_DECLVAR_CONTEXT(bgp, bgp);
3448 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3449 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3450
1ca2fd11 3451 return CMD_SUCCESS;
718e3744 3452}
6b0655a2 3453
6811845b 3454/* "bgp bestpath as-path confed" configuration. */
1ca2fd11 3455DEFUN (bgp_bestpath_aspath_confed,
6811845b 3456 bgp_bestpath_aspath_confed_cmd,
3457 "bgp bestpath as-path confed",
e9273987 3458 BGP_STR
6811845b 3459 "Change the default bestpath selection\n"
3460 "AS-path attribute\n"
3461 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3462{
1ca2fd11
IR
3463 VTY_DECLVAR_CONTEXT(bgp, bgp);
3464 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3465 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3466
1ca2fd11 3467 return CMD_SUCCESS;
6811845b 3468}
3469
1ca2fd11 3470DEFUN (no_bgp_bestpath_aspath_confed,
6811845b 3471 no_bgp_bestpath_aspath_confed_cmd,
3472 "no bgp bestpath as-path confed",
3473 NO_STR
e9273987 3474 BGP_STR
6811845b 3475 "Change the default bestpath selection\n"
3476 "AS-path attribute\n"
3477 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3478{
1ca2fd11
IR
3479 VTY_DECLVAR_CONTEXT(bgp, bgp);
3480 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3481 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3482
1ca2fd11 3483 return CMD_SUCCESS;
6811845b 3484}
6b0655a2 3485
2fdd455c 3486/* "bgp bestpath as-path multipath-relax" configuration. */
1ca2fd11 3487DEFUN (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3488 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3489 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
e9273987 3490 BGP_STR
16fc1eec
DS
3491 "Change the default bestpath selection\n"
3492 "AS-path attribute\n"
3493 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3494 "Generate an AS_SET\n"
16fc1eec
DS
3495 "Do not generate an AS_SET\n")
3496{
1ca2fd11 3497 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3498 int idx = 0;
1ca2fd11 3499 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 3500
1ca2fd11
IR
3501 /* no-as-set is now the default behavior so we can silently
3502 * ignore it */
d62a17ae 3503 if (argv_find(argv, argc, "as-set", &idx))
1ca2fd11 3504 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 3505 else
1ca2fd11 3506 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
7aafcaca 3507
1ca2fd11
IR
3508 bgp_recalculate_all_bestpaths(bgp);
3509
3510 return CMD_SUCCESS;
16fc1eec
DS
3511}
3512
1ca2fd11 3513DEFUN (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3514 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3515 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec 3516 NO_STR
e9273987 3517 BGP_STR
16fc1eec
DS
3518 "Change the default bestpath selection\n"
3519 "AS-path attribute\n"
3520 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3521 "Generate an AS_SET\n"
16fc1eec
DS
3522 "Do not generate an AS_SET\n")
3523{
1ca2fd11
IR
3524 VTY_DECLVAR_CONTEXT(bgp, bgp);
3525 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3526 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3527 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3528
1ca2fd11 3529 return CMD_SUCCESS;
2fdd455c 3530}
6b0655a2 3531
ee88563a
JM
3532/* "bgp bestpath peer-type multipath-relax" configuration. */
3533DEFUN(bgp_bestpath_peer_type_multipath_relax,
3534 bgp_bestpath_peer_type_multipath_relax_cmd,
3535 "bgp bestpath peer-type multipath-relax",
3536 BGP_STR
3537 "Change the default bestpath selection\n"
3538 "Peer type\n"
3539 "Allow load sharing across routes learned from different peer types\n")
3540{
3541 VTY_DECLVAR_CONTEXT(bgp, bgp);
3542 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3543 bgp_recalculate_all_bestpaths(bgp);
3544
3545 return CMD_SUCCESS;
3546}
3547
3548DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3549 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3550 "no bgp bestpath peer-type multipath-relax",
3551 NO_STR BGP_STR
3552 "Change the default bestpath selection\n"
3553 "Peer type\n"
3554 "Allow load sharing across routes learned from different peer types\n")
3555{
3556 VTY_DECLVAR_CONTEXT(bgp, bgp);
3557 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3558 bgp_recalculate_all_bestpaths(bgp);
3559
3560 return CMD_SUCCESS;
3561}
3562
848973c7 3563/* "bgp log-neighbor-changes" configuration. */
1ca2fd11
IR
3564DEFUN (bgp_log_neighbor_changes,
3565 bgp_log_neighbor_changes_cmd,
3566 "bgp log-neighbor-changes",
e9273987 3567 BGP_STR
1ca2fd11 3568 "Log neighbor up/down and reset reason\n")
848973c7 3569{
1ca2fd11
IR
3570 VTY_DECLVAR_CONTEXT(bgp, bgp);
3571 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3572 return CMD_SUCCESS;
848973c7 3573}
3574
1ca2fd11
IR
3575DEFUN (no_bgp_log_neighbor_changes,
3576 no_bgp_log_neighbor_changes_cmd,
3577 "no bgp log-neighbor-changes",
3578 NO_STR
e9273987 3579 BGP_STR
1ca2fd11 3580 "Log neighbor up/down and reset reason\n")
848973c7 3581{
1ca2fd11
IR
3582 VTY_DECLVAR_CONTEXT(bgp, bgp);
3583 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3584 return CMD_SUCCESS;
848973c7 3585}
6b0655a2 3586
718e3744 3587/* "bgp bestpath med" configuration. */
1ca2fd11 3588DEFUN (bgp_bestpath_med,
718e3744 3589 bgp_bestpath_med_cmd,
2d8c1a4d 3590 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
e9273987 3591 BGP_STR
718e3744 3592 "Change the default bestpath selection\n"
3593 "MED attribute\n"
3594 "Compare MED among confederation paths\n"
838758ac
DW
3595 "Treat missing MED as the least preferred one\n"
3596 "Treat missing MED as the least preferred one\n"
3597 "Compare MED among confederation paths\n")
718e3744 3598{
1ca2fd11 3599 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3600
1ca2fd11 3601 int idx = 0;
d62a17ae 3602 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3603 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3604 idx = 0;
3605 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11 3606 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 3607
1ca2fd11 3608 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3609
1ca2fd11 3610 return CMD_SUCCESS;
718e3744 3611}
3612
1ca2fd11 3613DEFUN (no_bgp_bestpath_med,
718e3744 3614 no_bgp_bestpath_med_cmd,
2d8c1a4d 3615 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3616 NO_STR
e9273987 3617 BGP_STR
718e3744 3618 "Change the default bestpath selection\n"
3619 "MED attribute\n"
3620 "Compare MED among confederation paths\n"
3a2d747c
QY
3621 "Treat missing MED as the least preferred one\n"
3622 "Treat missing MED as the least preferred one\n"
3623 "Compare MED among confederation paths\n")
718e3744 3624{
1ca2fd11 3625 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3626
1ca2fd11 3627 int idx = 0;
d62a17ae 3628 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3629 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3630 idx = 0;
3631 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11
IR
3632 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3633
3634 bgp_recalculate_all_bestpaths(bgp);
718e3744 3635
1ca2fd11 3636 return CMD_SUCCESS;
718e3744 3637}
3638
f7e1c681 3639/* "bgp bestpath bandwidth" configuration. */
3640DEFPY (bgp_bestpath_bw,
3641 bgp_bestpath_bw_cmd,
ad36d216 3642 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
e9273987 3643 BGP_STR
f7e1c681 3644 "Change the default bestpath selection\n"
3645 "Link Bandwidth attribute\n"
3646 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3647 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3648 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3649{
3650 VTY_DECLVAR_CONTEXT(bgp, bgp);
3651 afi_t afi;
3652 safi_t safi;
3653
ad36d216
DS
3654 if (!bw_cfg) {
3655 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3656 return CMD_ERR_INCOMPLETE;
f7e1c681 3657 }
ad36d216
DS
3658 if (!strcmp(bw_cfg, "ignore"))
3659 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3660 else if (!strcmp(bw_cfg, "skip-missing"))
3661 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3662 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3663 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3664 else
3665 return CMD_ERR_NO_MATCH;
f7e1c681 3666
3667 /* This config is used in route install, so redo that. */
3668 FOREACH_AFI_SAFI (afi, safi) {
3669 if (!bgp_fibupd_safi(safi))
3670 continue;
3671 bgp_zebra_announce_table(bgp, afi, safi);
3672 }
3673
3674 return CMD_SUCCESS;
3675}
3676
ad36d216
DS
3677DEFPY (no_bgp_bestpath_bw,
3678 no_bgp_bestpath_bw_cmd,
3679 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3680 NO_STR
e9273987 3681 BGP_STR
ad36d216
DS
3682 "Change the default bestpath selection\n"
3683 "Link Bandwidth attribute\n"
3684 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3685 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3686 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3687{
3688 VTY_DECLVAR_CONTEXT(bgp, bgp);
3689 afi_t afi;
3690 safi_t safi;
3691
3692 bgp->lb_handling = BGP_LINK_BW_ECMP;
3693
3694 /* This config is used in route install, so redo that. */
3695 FOREACH_AFI_SAFI (afi, safi) {
3696 if (!bgp_fibupd_safi(safi))
3697 continue;
3698 bgp_zebra_announce_table(bgp, afi, safi);
3699 }
3700 return CMD_SUCCESS;
3701}
3702
b16bcbba 3703DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
38d11af5
TA
3704 "[no] bgp default <ipv4-unicast|"
3705 "ipv4-multicast|"
3706 "ipv4-vpn|"
3707 "ipv4-labeled-unicast|"
3708 "ipv4-flowspec|"
3709 "ipv6-unicast|"
3710 "ipv6-multicast|"
3711 "ipv6-vpn|"
3712 "ipv6-labeled-unicast|"
3713 "ipv6-flowspec|"
3714 "l2vpn-evpn>$afi_safi",
b16bcbba 3715 NO_STR
e9273987 3716 BGP_STR
e84c59af 3717 "Configure BGP defaults\n"
b16bcbba 3718 "Activate ipv4-unicast for a peer by default\n"
38d11af5
TA
3719 "Activate ipv4-multicast for a peer by default\n"
3720 "Activate ipv4-vpn for a peer by default\n"
3721 "Activate ipv4-labeled-unicast for a peer by default\n"
3722 "Activate ipv4-flowspec for a peer by default\n"
3723 "Activate ipv6-unicast for a peer by default\n"
3724 "Activate ipv6-multicast for a peer by default\n"
3725 "Activate ipv6-vpn for a peer by default\n"
3726 "Activate ipv6-labeled-unicast for a peer by default\n"
3727 "Activate ipv6-flowspec for a peer by default\n"
3728 "Activate l2vpn-evpn for a peer by default\n")
e84c59af
DA
3729{
3730 VTY_DECLVAR_CONTEXT(bgp, bgp);
b16bcbba
TA
3731 char afi_safi_str[strlen(afi_safi) + 1];
3732 char *afi_safi_str_tok;
e84c59af 3733
b16bcbba
TA
3734 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3735 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3736 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3737 afi_t afi = bgp_vty_afi_from_str(afi_str);
38d11af5 3738 safi_t safi;
e84c59af 3739
38d11af5
TA
3740 if (strmatch(safi_str, "labeled"))
3741 safi = bgp_vty_safi_from_str("labeled-unicast");
3742 else
3743 safi = bgp_vty_safi_from_str(safi_str);
b16bcbba
TA
3744
3745 if (no)
3746 bgp->default_af[afi][safi] = false;
38d11af5
TA
3747 else {
3748 if ((safi == SAFI_LABELED_UNICAST
3749 && bgp->default_af[afi][SAFI_UNICAST])
3750 || (safi == SAFI_UNICAST
3751 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3752 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3753 else
3754 bgp->default_af[afi][safi] = true;
3755 }
718e3744 3756
d62a17ae 3757 return CMD_SUCCESS;
718e3744 3758}
6b0655a2 3759
04b6bdc0 3760/* Display hostname in certain command outputs */
1ca2fd11 3761DEFUN (bgp_default_show_hostname,
04b6bdc0
DW
3762 bgp_default_show_hostname_cmd,
3763 "bgp default show-hostname",
e9273987 3764 BGP_STR
04b6bdc0 3765 "Configure BGP defaults\n"
0437e105 3766 "Show hostname in certain command outputs\n")
04b6bdc0 3767{
1ca2fd11
IR
3768 VTY_DECLVAR_CONTEXT(bgp, bgp);
3769 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3770 return CMD_SUCCESS;
ff8a8a7a
CS
3771}
3772
1ca2fd11
IR
3773DEFUN (no_bgp_default_show_hostname,
3774 no_bgp_default_show_hostname_cmd,
3775 "no bgp default show-hostname",
3776 NO_STR
e9273987 3777 BGP_STR
1ca2fd11
IR
3778 "Configure BGP defaults\n"
3779 "Show hostname in certain command outputs\n")
ff8a8a7a 3780{
1ca2fd11
IR
3781 VTY_DECLVAR_CONTEXT(bgp, bgp);
3782 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3783 return CMD_SUCCESS;
04b6bdc0
DW
3784}
3785
aef999a2 3786/* Display hostname in certain command outputs */
1d80f243
IR
3787DEFUN (bgp_default_show_nexthop_hostname,
3788 bgp_default_show_nexthop_hostname_cmd,
3789 "bgp default show-nexthop-hostname",
e9273987 3790 BGP_STR
1d80f243
IR
3791 "Configure BGP defaults\n"
3792 "Show hostname for nexthop in certain command outputs\n")
aef999a2 3793{
1ca2fd11
IR
3794 VTY_DECLVAR_CONTEXT(bgp, bgp);
3795 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3796 return CMD_SUCCESS;
aef999a2
DA
3797}
3798
3799DEFUN (no_bgp_default_show_nexthop_hostname,
3800 no_bgp_default_show_nexthop_hostname_cmd,
3801 "no bgp default show-nexthop-hostname",
3802 NO_STR
e9273987 3803 BGP_STR
aef999a2
DA
3804 "Configure BGP defaults\n"
3805 "Show hostname for nexthop in certain command outputs\n")
3806{
1ca2fd11
IR
3807 VTY_DECLVAR_CONTEXT(bgp, bgp);
3808 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3809 return CMD_SUCCESS;
aef999a2
DA
3810}
3811
8233ef81 3812/* "bgp network import-check" configuration. */
1ca2fd11
IR
3813DEFUN (bgp_network_import_check,
3814 bgp_network_import_check_cmd,
3815 "bgp network import-check",
e9273987 3816 BGP_STR
1ca2fd11
IR
3817 "BGP network command\n"
3818 "Check BGP network route exists in IGP\n")
718e3744 3819{
1ca2fd11
IR
3820 VTY_DECLVAR_CONTEXT(bgp, bgp);
3821 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3822 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3823 bgp_static_redo_import_check(bgp);
3824 }
078430f6 3825
1ca2fd11 3826 return CMD_SUCCESS;
718e3744 3827}
3828
d62a17ae 3829ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3830 "bgp network import-check exact",
e9273987 3831 BGP_STR
d62a17ae 3832 "BGP network command\n"
3833 "Check BGP network route exists in IGP\n"
3834 "Match route precisely\n")
8233ef81 3835
1ca2fd11
IR
3836DEFUN (no_bgp_network_import_check,
3837 no_bgp_network_import_check_cmd,
3838 "no bgp network import-check",
3839 NO_STR
e9273987 3840 BGP_STR
1ca2fd11
IR
3841 "BGP network command\n"
3842 "Check BGP network route exists in IGP\n")
718e3744 3843{
1ca2fd11
IR
3844 VTY_DECLVAR_CONTEXT(bgp, bgp);
3845 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3846 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3847 bgp_static_redo_import_check(bgp);
3848 }
6b0655a2 3849
1ca2fd11 3850 return CMD_SUCCESS;
ff8a8a7a 3851}
718e3744 3852
1ca2fd11
IR
3853DEFUN (bgp_default_local_preference,
3854 bgp_default_local_preference_cmd,
3855 "bgp default local-preference (0-4294967295)",
e9273987 3856 BGP_STR
1ca2fd11
IR
3857 "Configure BGP defaults\n"
3858 "local preference (higher=more preferred)\n"
3859 "Configure default local preference value\n")
ff8a8a7a 3860{
1ca2fd11 3861 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3862 int idx_number = 3;
1ca2fd11 3863 uint32_t local_pref;
718e3744 3864
1ca2fd11 3865 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 3866
1ca2fd11
IR
3867 bgp_default_local_preference_set(bgp, local_pref);
3868 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 3869
1ca2fd11 3870 return CMD_SUCCESS;
718e3744 3871}
3872
1ca2fd11
IR
3873DEFUN (no_bgp_default_local_preference,
3874 no_bgp_default_local_preference_cmd,
3875 "no bgp default local-preference [(0-4294967295)]",
3876 NO_STR
e9273987 3877 BGP_STR
1ca2fd11
IR
3878 "Configure BGP defaults\n"
3879 "local preference (higher=more preferred)\n"
3880 "Configure default local preference value\n")
ff8a8a7a 3881{
1ca2fd11
IR
3882 VTY_DECLVAR_CONTEXT(bgp, bgp);
3883 bgp_default_local_preference_unset(bgp);
3884 bgp_clear_star_soft_in(vty, bgp->name);
3885
3886 return CMD_SUCCESS;
ff8a8a7a 3887}
6b0655a2 3888
ff8a8a7a 3889
1ca2fd11
IR
3890DEFUN (bgp_default_subgroup_pkt_queue_max,
3891 bgp_default_subgroup_pkt_queue_max_cmd,
3892 "bgp default subgroup-pkt-queue-max (20-100)",
e9273987 3893 BGP_STR
1ca2fd11
IR
3894 "Configure BGP defaults\n"
3895 "subgroup-pkt-queue-max\n"
3896 "Configure subgroup packet queue max\n")
8bd9d948 3897{
1ca2fd11 3898 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3899 int idx_number = 3;
1ca2fd11 3900 uint32_t max_size;
3f9c7369 3901
1ca2fd11 3902 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 3903
1ca2fd11 3904 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
ff8a8a7a 3905
1ca2fd11 3906 return CMD_SUCCESS;
8bd9d948
DS
3907}
3908
1ca2fd11
IR
3909DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3910 no_bgp_default_subgroup_pkt_queue_max_cmd,
3911 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3912 NO_STR
e9273987 3913 BGP_STR
1ca2fd11
IR
3914 "Configure BGP defaults\n"
3915 "subgroup-pkt-queue-max\n"
3916 "Configure subgroup packet queue max\n")
ff8a8a7a 3917{
1ca2fd11
IR
3918 VTY_DECLVAR_CONTEXT(bgp, bgp);
3919 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3920 return CMD_SUCCESS;
ff8a8a7a 3921}
813d4307 3922
8bd9d948 3923
1ca2fd11
IR
3924DEFUN (bgp_rr_allow_outbound_policy,
3925 bgp_rr_allow_outbound_policy_cmd,
3926 "bgp route-reflector allow-outbound-policy",
e9273987 3927 BGP_STR
1ca2fd11
IR
3928 "Allow modifications made by out route-map\n"
3929 "on ibgp neighbors\n")
ff8a8a7a 3930{
1ca2fd11 3931 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3932
1ca2fd11
IR
3933 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3934 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3935 update_group_announce_rrclients(bgp);
3936 bgp_clear_star_soft_out(vty, bgp->name);
3937 }
8bd9d948 3938
1ca2fd11
IR
3939 return CMD_SUCCESS;
3940}
ff8a8a7a 3941
1ca2fd11
IR
3942DEFUN (no_bgp_rr_allow_outbound_policy,
3943 no_bgp_rr_allow_outbound_policy_cmd,
3944 "no bgp route-reflector allow-outbound-policy",
3945 NO_STR
e9273987 3946 BGP_STR
1ca2fd11
IR
3947 "Allow modifications made by out route-map\n"
3948 "on ibgp neighbors\n")
8bd9d948 3949{
1ca2fd11 3950 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 3951
1ca2fd11
IR
3952 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3953 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3954 update_group_announce_rrclients(bgp);
3955 bgp_clear_star_soft_out(vty, bgp->name);
d62a17ae 3956 }
8bd9d948 3957
1ca2fd11 3958 return CMD_SUCCESS;
8bd9d948
DS
3959}
3960
1ca2fd11
IR
3961DEFUN (bgp_listen_limit,
3962 bgp_listen_limit_cmd,
3963 "bgp listen limit (1-65535)",
e9273987 3964 BGP_STR
1ca2fd11
IR
3965 "BGP Dynamic Neighbors listen commands\n"
3966 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3967 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3968{
1ca2fd11 3969 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3970 int idx_number = 3;
1ca2fd11
IR
3971 int listen_limit;
3972
3973 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 3974
1ca2fd11 3975 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 3976
1ca2fd11 3977 return CMD_SUCCESS;
f14e6fdb
DS
3978}
3979
1ca2fd11
IR
3980DEFUN (no_bgp_listen_limit,
3981 no_bgp_listen_limit_cmd,
3982 "no bgp listen limit [(1-65535)]",
3983 NO_STR
e9273987 3984 BGP_STR
1ca2fd11
IR
3985 "BGP Dynamic Neighbors listen commands\n"
3986 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3987 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3988{
1ca2fd11
IR
3989 VTY_DECLVAR_CONTEXT(bgp, bgp);
3990 bgp_listen_limit_unset(bgp);
3991 return CMD_SUCCESS;
f14e6fdb
DS
3992}
3993
3994
20eb8864 3995/*
3996 * Check if this listen range is already configured. Check for exact
3997 * match or overlap based on input.
3998 */
d62a17ae 3999static struct peer_group *listen_range_exists(struct bgp *bgp,
4000 struct prefix *range, int exact)
4001{
4002 struct listnode *node, *nnode;
4003 struct listnode *node1, *nnode1;
4004 struct peer_group *group;
4005 struct prefix *lr;
4006 afi_t afi;
4007 int match;
4008
4009 afi = family2afi(range->family);
4010 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4011 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4012 lr)) {
4013 if (exact)
4014 match = prefix_same(range, lr);
4015 else
4016 match = (prefix_match(range, lr)
4017 || prefix_match(lr, range));
4018 if (match)
4019 return group;
4020 }
4021 }
4022
4023 return NULL;
20eb8864 4024}
4025
f14e6fdb
DS
4026DEFUN (bgp_listen_range,
4027 bgp_listen_range_cmd,
d7b9898c 4028 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
e9273987 4029 BGP_STR
d7fa34c1
QY
4030 "Configure BGP dynamic neighbors listen range\n"
4031 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
4032 NEIGHBOR_ADDR_STR
4033 "Member of the peer-group\n"
4034 "Peer-group name\n")
f14e6fdb 4035{
d62a17ae 4036 VTY_DECLVAR_CONTEXT(bgp, bgp);
4037 struct prefix range;
4038 struct peer_group *group, *existing_group;
4039 afi_t afi;
4040 int ret;
4041 int idx = 0;
4042
4043 argv_find(argv, argc, "A.B.C.D/M", &idx);
4044 argv_find(argv, argc, "X:X::X:X/M", &idx);
4045 char *prefix = argv[idx]->arg;
d7b9898c 4046 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4047 char *peergroup = argv[idx]->arg;
4048
4049 /* Convert IP prefix string to struct prefix. */
4050 ret = str2prefix(prefix, &range);
4051 if (!ret) {
4052 vty_out(vty, "%% Malformed listen range\n");
4053 return CMD_WARNING_CONFIG_FAILED;
4054 }
4055
4056 afi = family2afi(range.family);
4057
4058 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4059 vty_out(vty,
4060 "%% Malformed listen range (link-local address)\n");
4061 return CMD_WARNING_CONFIG_FAILED;
4062 }
4063
4064 apply_mask(&range);
4065
4066 /* Check if same listen range is already configured. */
4067 existing_group = listen_range_exists(bgp, &range, 1);
4068 if (existing_group) {
4069 if (strcmp(existing_group->name, peergroup) == 0)
4070 return CMD_SUCCESS;
4071 else {
4072 vty_out(vty,
4073 "%% Same listen range is attached to peer-group %s\n",
4074 existing_group->name);
4075 return CMD_WARNING_CONFIG_FAILED;
4076 }
4077 }
4078
4079 /* Check if an overlapping listen range exists. */
4080 if (listen_range_exists(bgp, &range, 0)) {
4081 vty_out(vty,
4082 "%% Listen range overlaps with existing listen range\n");
4083 return CMD_WARNING_CONFIG_FAILED;
4084 }
4085
4086 group = peer_group_lookup(bgp, peergroup);
4087 if (!group) {
4088 vty_out(vty, "%% Configure the peer-group first\n");
4089 return CMD_WARNING_CONFIG_FAILED;
4090 }
4091
4092 ret = peer_group_listen_range_add(group, &range);
4093 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4094}
4095
4096DEFUN (no_bgp_listen_range,
4097 no_bgp_listen_range_cmd,
d7b9898c 4098 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4099 NO_STR
e9273987 4100 BGP_STR
d7fa34c1
QY
4101 "Unconfigure BGP dynamic neighbors listen range\n"
4102 "Unconfigure BGP dynamic neighbors listen range\n"
4103 NEIGHBOR_ADDR_STR
4104 "Member of the peer-group\n"
4105 "Peer-group name\n")
f14e6fdb 4106{
d62a17ae 4107 VTY_DECLVAR_CONTEXT(bgp, bgp);
4108 struct prefix range;
4109 struct peer_group *group;
4110 afi_t afi;
4111 int ret;
4112 int idx = 0;
4113
4114 argv_find(argv, argc, "A.B.C.D/M", &idx);
4115 argv_find(argv, argc, "X:X::X:X/M", &idx);
4116 char *prefix = argv[idx]->arg;
21d88a71 4117 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4118 char *peergroup = argv[idx]->arg;
4119
4120 /* Convert IP prefix string to struct prefix. */
4121 ret = str2prefix(prefix, &range);
4122 if (!ret) {
4123 vty_out(vty, "%% Malformed listen range\n");
4124 return CMD_WARNING_CONFIG_FAILED;
4125 }
4126
4127 afi = family2afi(range.family);
4128
4129 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4130 vty_out(vty,
4131 "%% Malformed listen range (link-local address)\n");
4132 return CMD_WARNING_CONFIG_FAILED;
4133 }
4134
4135 apply_mask(&range);
4136
4137 group = peer_group_lookup(bgp, peergroup);
4138 if (!group) {
4139 vty_out(vty, "%% Peer-group does not exist\n");
4140 return CMD_WARNING_CONFIG_FAILED;
4141 }
4142
4143 ret = peer_group_listen_range_del(group, &range);
4144 return bgp_vty_return(vty, ret);
4145}
4146
2b791107 4147void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4148{
4149 struct peer_group *group;
4150 struct listnode *node, *nnode, *rnode, *nrnode;
4151 struct prefix *range;
4152 afi_t afi;
d62a17ae 4153
4154 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4155 vty_out(vty, " bgp listen limit %d\n",
4156 bgp->dynamic_neighbors_limit);
4157
4158 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4159 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4160 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4161 nrnode, range)) {
d62a17ae 4162 vty_out(vty,
2dbe669b
DA
4163 " bgp listen range %pFX peer-group %s\n",
4164 range, group->name);
d62a17ae 4165 }
4166 }
4167 }
f14e6fdb
DS
4168}
4169
4170
1ca2fd11
IR
4171DEFUN (bgp_disable_connected_route_check,
4172 bgp_disable_connected_route_check_cmd,
4173 "bgp disable-ebgp-connected-route-check",
e9273987 4174 BGP_STR
1ca2fd11 4175 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4176{
1ca2fd11
IR
4177 VTY_DECLVAR_CONTEXT(bgp, bgp);
4178 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4179 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 4180
1ca2fd11 4181 return CMD_SUCCESS;
907f92c8
DS
4182}
4183
1ca2fd11
IR
4184DEFUN (no_bgp_disable_connected_route_check,
4185 no_bgp_disable_connected_route_check_cmd,
4186 "no bgp disable-ebgp-connected-route-check",
4187 NO_STR
e9273987 4188 BGP_STR
1ca2fd11 4189 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4190{
1ca2fd11
IR
4191 VTY_DECLVAR_CONTEXT(bgp, bgp);
4192 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4193 bgp_clear_star_soft_in(vty, bgp->name);
d62a17ae 4194
1ca2fd11 4195 return CMD_SUCCESS;
d62a17ae 4196}
4197
4198
28c6e247
IR
4199static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4200 const char *as_str)
4201{
4202 VTY_DECLVAR_CONTEXT(bgp, bgp);
4203 int ret;
4204 as_t as;
4205 int as_type = AS_SPECIFIED;
4206 union sockunion su;
4207
4208 if (as_str[0] == 'i') {
4209 as = 0;
4210 as_type = AS_INTERNAL;
4211 } else if (as_str[0] == 'e') {
4212 as = 0;
4213 as_type = AS_EXTERNAL;
4214 } else {
4215 /* Get AS number. */
4216 as = strtoul(as_str, NULL, 10);
4217 }
4218
4219 /* If peer is peer group or interface peer, call proper function. */
4220 ret = str2sockunion(peer_str, &su);
4221 if (ret < 0) {
4222 struct peer *peer;
4223
4224 /* Check if existing interface peer */
4225 peer = peer_lookup_by_conf_if(bgp, peer_str);
4226
4227 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4228
4229 /* if not interface peer, check peer-group settings */
4230 if (ret < 0 && !peer) {
4231 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4232 if (ret < 0) {
4233 vty_out(vty,
4234 "%% Create the peer-group or interface first\n");
4235 return CMD_WARNING_CONFIG_FAILED;
4236 }
4237 return CMD_SUCCESS;
4238 }
4239 } else {
4240 if (peer_address_self_check(bgp, &su)) {
4241 vty_out(vty,
4242 "%% Can not configure the local system as neighbor\n");
4243 return CMD_WARNING_CONFIG_FAILED;
4244 }
4245 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4246 }
4247
28c6e247
IR
4248 return bgp_vty_return(vty, ret);
4249}
4250
1ca2fd11
IR
4251DEFUN (bgp_default_shutdown,
4252 bgp_default_shutdown_cmd,
4253 "[no] bgp default shutdown",
4254 NO_STR
4255 BGP_STR
4256 "Configure BGP defaults\n"
4257 "Apply administrative shutdown to newly configured peers\n")
ff8a8a7a 4258{
1ca2fd11
IR
4259 VTY_DECLVAR_CONTEXT(bgp, bgp);
4260 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4261 return CMD_SUCCESS;
f26845f9
QY
4262}
4263
736b68f3
DS
4264DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4265 BGP_STR
9ddf4b81 4266 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4267 "Add a shutdown message (RFC 8203)\n"
4268 "Shutdown message\n")
9cf59432 4269{
736b68f3 4270 char *msgstr = NULL;
8389c83a 4271
9cf59432
DS
4272 VTY_DECLVAR_CONTEXT(bgp, bgp);
4273
8389c83a 4274 if (argc > 3)
f80e35b6 4275 msgstr = argv_concat(argv, argc, 3);
8389c83a 4276
b776f48c
DA
4277 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4278 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4279 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4280 return CMD_WARNING_CONFIG_FAILED;
4281 }
4282
8389c83a
DS
4283 bgp_shutdown_enable(bgp, msgstr);
4284 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4285
4286 return CMD_SUCCESS;
4287}
4288
736b68f3 4289DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4290 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4291{
4292 VTY_DECLVAR_CONTEXT(bgp, bgp);
4293
4294 bgp_shutdown_enable(bgp, NULL);
4295
4296 return CMD_SUCCESS;
4297}
8389c83a 4298
736b68f3 4299DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4300 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4301{
4302 VTY_DECLVAR_CONTEXT(bgp, bgp);
4303
4304 bgp_shutdown_disable(bgp);
4305
4306 return CMD_SUCCESS;
4307}
4308
9ddf4b81 4309ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4310 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4311 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4312 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4313
28c6e247
IR
4314DEFUN (neighbor_remote_as,
4315 neighbor_remote_as_cmd,
4316 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4317 NEIGHBOR_STR
4318 NEIGHBOR_ADDR_STR2
4319 "Specify a BGP neighbor\n"
4320 AS_STR
4321 "Internal BGP peer\n"
4322 "External BGP peer\n")
718e3744 4323{
d62a17ae 4324 int idx_peer = 1;
4325 int idx_remote_as = 3;
28c6e247
IR
4326 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4327 argv[idx_remote_as]->arg);
d62a17ae 4328}
f852eb98
PG
4329/* Enable fast convergence of bgp sessions. If this is enabled, bgp
4330 * sessions do not wait for hold timer expiry to bring down the sessions
4331 * when nexthop becomes unreachable
4332 */
4333DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4334 BGP_STR "Fast convergence for bgp sessions\n")
4335{
4336 VTY_DECLVAR_CONTEXT(bgp, bgp);
4337 bgp->fast_convergence = true;
4338
4339 return CMD_SUCCESS;
4340}
4341
4342DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4343 "no bgp fast-convergence",
4344 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4345{
4346 VTY_DECLVAR_CONTEXT(bgp, bgp);
4347 bgp->fast_convergence = false;
4348
4349 return CMD_SUCCESS;
4350}
d62a17ae 4351
28c6e247
IR
4352static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4353 int v6only,
4354 const char *peer_group_name,
4355 const char *as_str)
d62a17ae 4356{
28c6e247
IR
4357 VTY_DECLVAR_CONTEXT(bgp, bgp);
4358 as_t as = 0;
4359 int as_type = AS_UNSPECIFIED;
d62a17ae 4360 struct peer *peer;
4361 struct peer_group *group;
4362 int ret = 0;
d62a17ae 4363
4364 group = peer_group_lookup(bgp, conf_if);
4365
4366 if (group) {
28c6e247
IR
4367 vty_out(vty, "%% Name conflict with peer-group \n");
4368 return CMD_WARNING_CONFIG_FAILED;
4369 }
4370
4371 if (as_str) {
4372 if (as_str[0] == 'i') {
4373 as_type = AS_INTERNAL;
4374 } else if (as_str[0] == 'e') {
4375 as_type = AS_EXTERNAL;
4376 } else {
4377 /* Get AS number. */
4378 as = strtoul(as_str, NULL, 10);
4379 as_type = AS_SPECIFIED;
4380 }
d62a17ae 4381 }
4382
4383 peer = peer_lookup_by_conf_if(bgp, conf_if);
4384 if (peer) {
28c6e247 4385 if (as_str)
e84c59af 4386 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
d62a17ae 4387 } else {
e84c59af
DA
4388 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4389 NULL);
d62a17ae 4390
4391 if (!peer) {
28c6e247
IR
4392 vty_out(vty, "%% BGP failed to create peer\n");
4393 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4394 }
4395
4396 if (v6only)
527de3dc 4397 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4398
4399 /* Request zebra to initiate IPv6 RAs on this interface. We do
4400 * this
4401 * any unnumbered peer in order to not worry about run-time
4402 * transitions
4403 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4404 * address
4405 * gets deleted later etc.)
4406 */
4407 if (peer->ifp)
4408 bgp_zebra_initiate_radv(bgp, peer);
4409 }
4410
4411 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4412 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4413 if (v6only)
527de3dc 4414 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4415 else
527de3dc 4416 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4417
4418 /* v6only flag changed. Reset bgp seesion */
4419 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4420 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4421 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4422 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4423 } else
4424 bgp_session_reset(peer);
4425 }
4426
9fb964de
PM
4427 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4428 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4429 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4430 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4431 }
d62a17ae 4432
4433 if (peer_group_name) {
4434 group = peer_group_lookup(bgp, peer_group_name);
4435 if (!group) {
28c6e247
IR
4436 vty_out(vty, "%% Configure the peer-group first\n");
4437 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4438 }
4439
8395c1f8 4440 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4441 }
4442
28c6e247 4443 return bgp_vty_return(vty, ret);
a80beece
DS
4444}
4445
28c6e247
IR
4446DEFUN (neighbor_interface_config,
4447 neighbor_interface_config_cmd,
4448 "neighbor WORD interface [peer-group PGNAME]",
4449 NEIGHBOR_STR
4450 "Interface name or neighbor tag\n"
4451 "Enable BGP on interface\n"
4452 "Member of the peer-group\n"
4453 "Peer-group name\n")
4c48cf63 4454{
d62a17ae 4455 int idx_word = 1;
4456 int idx_peer_group_word = 4;
f4b8ec07 4457
d62a17ae 4458 if (argc > idx_peer_group_word)
28c6e247
IR
4459 return peer_conf_interface_get(
4460 vty, argv[idx_word]->arg, 0,
4461 argv[idx_peer_group_word]->arg, NULL);
4462 else
4463 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4464 NULL, NULL);
4c48cf63
DW
4465}
4466
28c6e247
IR
4467DEFUN (neighbor_interface_config_v6only,
4468 neighbor_interface_config_v6only_cmd,
4469 "neighbor WORD interface v6only [peer-group PGNAME]",
4470 NEIGHBOR_STR
4471 "Interface name or neighbor tag\n"
4472 "Enable BGP on interface\n"
4473 "Enable BGP with v6 link-local only\n"
4474 "Member of the peer-group\n"
4475 "Peer-group name\n")
4c48cf63 4476{
d62a17ae 4477 int idx_word = 1;
4478 int idx_peer_group_word = 5;
31500417 4479
d62a17ae 4480 if (argc > idx_peer_group_word)
28c6e247
IR
4481 return peer_conf_interface_get(
4482 vty, argv[idx_word]->arg, 1,
4483 argv[idx_peer_group_word]->arg, NULL);
31500417 4484
28c6e247 4485 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4c48cf63
DW
4486}
4487
a80beece 4488
28c6e247
IR
4489DEFUN (neighbor_interface_config_remote_as,
4490 neighbor_interface_config_remote_as_cmd,
4491 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4492 NEIGHBOR_STR
4493 "Interface name or neighbor tag\n"
4494 "Enable BGP on interface\n"
4495 "Specify a BGP neighbor\n"
4496 AS_STR
4497 "Internal BGP peer\n"
4498 "External BGP peer\n")
b3a39dc5 4499{
d62a17ae 4500 int idx_word = 1;
4501 int idx_remote_as = 4;
28c6e247
IR
4502 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4503 argv[idx_remote_as]->arg);
b3a39dc5
DD
4504}
4505
28c6e247
IR
4506DEFUN (neighbor_interface_v6only_config_remote_as,
4507 neighbor_interface_v6only_config_remote_as_cmd,
4508 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4509 NEIGHBOR_STR
4510 "Interface name or neighbor tag\n"
4511 "Enable BGP with v6 link-local only\n"
4512 "Enable BGP on interface\n"
4513 "Specify a BGP neighbor\n"
4514 AS_STR
4515 "Internal BGP peer\n"
4516 "External BGP peer\n")
b3a39dc5 4517{
d62a17ae 4518 int idx_word = 1;
4519 int idx_remote_as = 5;
28c6e247
IR
4520 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4521 argv[idx_remote_as]->arg);
b3a39dc5
DD
4522}
4523
28c6e247
IR
4524DEFUN (neighbor_peer_group,
4525 neighbor_peer_group_cmd,
4526 "neighbor WORD peer-group",
4527 NEIGHBOR_STR
4528 "Interface name or neighbor tag\n"
4529 "Configure peer-group\n")
718e3744 4530{
28c6e247 4531 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4532 int idx_word = 1;
28c6e247
IR
4533 struct peer *peer;
4534 struct peer_group *group;
718e3744 4535
28c6e247
IR
4536 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4537 if (peer) {
4538 vty_out(vty, "%% Name conflict with interface: \n");
4539 return CMD_WARNING_CONFIG_FAILED;
4540 }
718e3744 4541
28c6e247
IR
4542 group = peer_group_get(bgp, argv[idx_word]->arg);
4543 if (!group) {
4544 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4545 return CMD_WARNING_CONFIG_FAILED;
4546 }
718e3744 4547
28c6e247 4548 return CMD_SUCCESS;
718e3744 4549}
4550
1d80f243
IR
4551DEFUN (no_neighbor,
4552 no_neighbor_cmd,
4553 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4554 NO_STR
4555 NEIGHBOR_STR
4556 NEIGHBOR_ADDR_STR2
4557 "Specify a BGP neighbor\n"
4558 AS_STR
4559 "Internal BGP peer\n"
4560 "External BGP peer\n")
718e3744 4561{
28c6e247 4562 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4563 int idx_peer = 2;
28c6e247 4564 int ret;
d62a17ae 4565 union sockunion su;
28c6e247
IR
4566 struct peer_group *group;
4567 struct peer *peer;
4568 struct peer *other;
d62a17ae 4569
28c6e247
IR
4570 ret = str2sockunion(argv[idx_peer]->arg, &su);
4571 if (ret < 0) {
4572 /* look up for neighbor by interface name config. */
4573 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4574 if (peer) {
4575 /* Request zebra to terminate IPv6 RAs on this
4576 * interface. */
4577 if (peer->ifp)
4578 bgp_zebra_terminate_radv(peer->bgp, peer);
4579 peer_notify_unconfig(peer);
4580 peer_delete(peer);
4581 return CMD_SUCCESS;
d62a17ae 4582 }
28c6e247
IR
4583
4584 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4585 if (group) {
4586 peer_group_notify_unconfig(group);
4587 peer_group_delete(group);
4e2786df 4588 } else {
28c6e247 4589 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4590 return CMD_WARNING_CONFIG_FAILED;
4591 }
28c6e247
IR
4592 } else {
4593 peer = peer_lookup(bgp, &su);
4594 if (peer) {
4595 if (peer_dynamic_neighbor(peer)) {
4596 vty_out(vty,
4597 "%% Operation not allowed on a dynamic neighbor\n");
4598 return CMD_WARNING_CONFIG_FAILED;
4599 }
d62a17ae 4600
28c6e247 4601 other = peer->doppelganger;
f4b8ec07 4602
28c6e247
IR
4603 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4604 bgp_zebra_terminate_radv(peer->bgp, peer);
f4b8ec07 4605
28c6e247
IR
4606 peer_notify_unconfig(peer);
4607 peer_delete(peer);
4608 if (other && other->status != Deleted) {
4609 peer_notify_unconfig(other);
4610 peer_delete(other);
4611 }
4612 }
4613 }
4614
4615 return CMD_SUCCESS;
a80beece
DS
4616}
4617
28c6e247
IR
4618DEFUN (no_neighbor_interface_config,
4619 no_neighbor_interface_config_cmd,
4620 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4621 NO_STR
4622 NEIGHBOR_STR
4623 "Interface name\n"
4624 "Configure BGP on interface\n"
4625 "Enable BGP with v6 link-local only\n"
4626 "Member of the peer-group\n"
4627 "Peer-group name\n"
4628 "Specify a BGP neighbor\n"
4629 AS_STR
4630 "Internal BGP peer\n"
4631 "External BGP peer\n")
718e3744 4632{
28c6e247 4633 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4634 int idx_word = 2;
28c6e247 4635 struct peer *peer;
718e3744 4636
28c6e247
IR
4637 /* look up for neighbor by interface name config. */
4638 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4639 if (peer) {
4640 /* Request zebra to terminate IPv6 RAs on this interface. */
4641 if (peer->ifp)
4642 bgp_zebra_terminate_radv(peer->bgp, peer);
4643 peer_notify_unconfig(peer);
4644 peer_delete(peer);
4645 } else {
4646 vty_out(vty, "%% Create the bgp interface first\n");
4647 return CMD_WARNING_CONFIG_FAILED;
4648 }
4649 return CMD_SUCCESS;
718e3744 4650}
4651
28c6e247
IR
4652DEFUN (no_neighbor_peer_group,
4653 no_neighbor_peer_group_cmd,
4654 "no neighbor WORD peer-group",
4655 NO_STR
4656 NEIGHBOR_STR
4657 "Neighbor tag\n"
4658 "Configure peer-group\n")
718e3744 4659{
28c6e247
IR
4660 VTY_DECLVAR_CONTEXT(bgp, bgp);
4661 int idx_word = 2;
4662 struct peer_group *group;
f4b8ec07 4663
28c6e247
IR
4664 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4665 if (group) {
4666 peer_group_notify_unconfig(group);
4667 peer_group_delete(group);
f4b8ec07 4668 } else {
28c6e247 4669 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4670 return CMD_WARNING_CONFIG_FAILED;
4671 }
28c6e247
IR
4672 return CMD_SUCCESS;
4673}
f4b8ec07 4674
28c6e247
IR
4675DEFUN (no_neighbor_interface_peer_group_remote_as,
4676 no_neighbor_interface_peer_group_remote_as_cmd,
4677 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4678 NO_STR
4679 NEIGHBOR_STR
4680 "Interface name or neighbor tag\n"
4681 "Specify a BGP neighbor\n"
4682 AS_STR
4683 "Internal BGP peer\n"
4684 "External BGP peer\n")
4685{
4686 VTY_DECLVAR_CONTEXT(bgp, bgp);
4687 int idx_word = 2;
4688 struct peer_group *group;
4689 struct peer *peer;
f4b8ec07 4690
28c6e247
IR
4691 /* look up for neighbor by interface name config. */
4692 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4693 if (peer) {
4694 peer_as_change(peer, 0, AS_UNSPECIFIED);
4695 return CMD_SUCCESS;
4696 }
f4b8ec07 4697
28c6e247
IR
4698 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4699 if (group)
4700 peer_group_remote_as_delete(group);
4701 else {
4702 vty_out(vty, "%% Create the peer-group or interface first\n");
4703 return CMD_WARNING_CONFIG_FAILED;
4704 }
4705 return CMD_SUCCESS;
718e3744 4706}
6b0655a2 4707
28c6e247
IR
4708DEFUN (neighbor_local_as,
4709 neighbor_local_as_cmd,
4710 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4711 NEIGHBOR_STR
4712 NEIGHBOR_ADDR_STR2
4713 "Specify a local-as number\n"
4714 "AS number used as local AS\n")
718e3744 4715{
d62a17ae 4716 int idx_peer = 1;
4717 int idx_number = 3;
28c6e247
IR
4718 struct peer *peer;
4719 int ret;
4720 as_t as;
718e3744 4721
28c6e247
IR
4722 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4723 if (!peer)
d62a17ae 4724 return CMD_WARNING_CONFIG_FAILED;
718e3744 4725
28c6e247
IR
4726 as = strtoul(argv[idx_number]->arg, NULL, 10);
4727 ret = peer_local_as_set(peer, as, 0, 0);
4728 return bgp_vty_return(vty, ret);
718e3744 4729}
4730
28c6e247
IR
4731DEFUN (neighbor_local_as_no_prepend,
4732 neighbor_local_as_no_prepend_cmd,
4733 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4734 NEIGHBOR_STR
4735 NEIGHBOR_ADDR_STR2
4736 "Specify a local-as number\n"
4737 "AS number used as local AS\n"
4738 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4739{
d62a17ae 4740 int idx_peer = 1;
4741 int idx_number = 3;
28c6e247
IR
4742 struct peer *peer;
4743 int ret;
4744 as_t as;
718e3744 4745
28c6e247
IR
4746 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4747 if (!peer)
d62a17ae 4748 return CMD_WARNING_CONFIG_FAILED;
718e3744 4749
28c6e247
IR
4750 as = strtoul(argv[idx_number]->arg, NULL, 10);
4751 ret = peer_local_as_set(peer, as, 1, 0);
4752 return bgp_vty_return(vty, ret);
718e3744 4753}
4754
28c6e247
IR
4755DEFUN (neighbor_local_as_no_prepend_replace_as,
4756 neighbor_local_as_no_prepend_replace_as_cmd,
4757 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4758 NEIGHBOR_STR
4759 NEIGHBOR_ADDR_STR2
4760 "Specify a local-as number\n"
4761 "AS number used as local AS\n"
4762 "Do not prepend local-as to updates from ebgp peers\n"
4763 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4764{
d62a17ae 4765 int idx_peer = 1;
4766 int idx_number = 3;
28c6e247
IR
4767 struct peer *peer;
4768 int ret;
4769 as_t as;
9d3f9705 4770
28c6e247
IR
4771 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4772 if (!peer)
d62a17ae 4773 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4774
28c6e247
IR
4775 as = strtoul(argv[idx_number]->arg, NULL, 10);
4776 ret = peer_local_as_set(peer, as, 1, 1);
4777 return bgp_vty_return(vty, ret);
9d3f9705
AC
4778}
4779
28c6e247
IR
4780DEFUN (no_neighbor_local_as,
4781 no_neighbor_local_as_cmd,
4782 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4783 NO_STR
4784 NEIGHBOR_STR
4785 NEIGHBOR_ADDR_STR2
4786 "Specify a local-as number\n"
4787 "AS number used as local AS\n"
4788 "Do not prepend local-as to updates from ebgp peers\n"
4789 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4790{
d62a17ae 4791 int idx_peer = 2;
28c6e247
IR
4792 struct peer *peer;
4793 int ret;
718e3744 4794
28c6e247
IR
4795 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4796 if (!peer)
d62a17ae 4797 return CMD_WARNING_CONFIG_FAILED;
718e3744 4798
28c6e247
IR
4799 ret = peer_local_as_unset(peer);
4800 return bgp_vty_return(vty, ret);
718e3744 4801}
4802
718e3744 4803
3f9c7369
DS
4804DEFUN (neighbor_solo,
4805 neighbor_solo_cmd,
9ccf14f7 4806 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4807 NEIGHBOR_STR
4808 NEIGHBOR_ADDR_STR2
4809 "Solo peer - part of its own update group\n")
4810{
d62a17ae 4811 int idx_peer = 1;
4812 struct peer *peer;
4813 int ret;
3f9c7369 4814
d62a17ae 4815 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4816 if (!peer)
4817 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4818
d62a17ae 4819 ret = update_group_adjust_soloness(peer, 1);
4820 return bgp_vty_return(vty, ret);
3f9c7369
DS
4821}
4822
4823DEFUN (no_neighbor_solo,
4824 no_neighbor_solo_cmd,
9ccf14f7 4825 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4826 NO_STR
4827 NEIGHBOR_STR
4828 NEIGHBOR_ADDR_STR2
4829 "Solo peer - part of its own update group\n")
4830{
d62a17ae 4831 int idx_peer = 2;
4832 struct peer *peer;
4833 int ret;
3f9c7369 4834
d62a17ae 4835 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4836 if (!peer)
4837 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4838
d62a17ae 4839 ret = update_group_adjust_soloness(peer, 0);
4840 return bgp_vty_return(vty, ret);
3f9c7369
DS
4841}
4842
28c6e247
IR
4843DEFUN (neighbor_password,
4844 neighbor_password_cmd,
4845 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4846 NEIGHBOR_STR
4847 NEIGHBOR_ADDR_STR2
4848 "Set a password\n"
4849 "The password\n")
0df7c91f 4850{
d62a17ae 4851 int idx_peer = 1;
4852 int idx_line = 3;
28c6e247
IR
4853 struct peer *peer;
4854 int ret;
0df7c91f 4855
28c6e247
IR
4856 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4857 if (!peer)
d62a17ae 4858 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4859
28c6e247
IR
4860 ret = peer_password_set(peer, argv[idx_line]->arg);
4861 return bgp_vty_return(vty, ret);
0df7c91f
PJ
4862}
4863
28c6e247
IR
4864DEFUN (no_neighbor_password,
4865 no_neighbor_password_cmd,
4866 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4867 NO_STR
4868 NEIGHBOR_STR
4869 NEIGHBOR_ADDR_STR2
4870 "Set a password\n"
4871 "The password\n")
0df7c91f 4872{
d62a17ae 4873 int idx_peer = 2;
28c6e247
IR
4874 struct peer *peer;
4875 int ret;
0df7c91f 4876
28c6e247
IR
4877 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4878 if (!peer)
d62a17ae 4879 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4880
28c6e247
IR
4881 ret = peer_password_unset(peer);
4882 return bgp_vty_return(vty, ret);
0df7c91f 4883}
6b0655a2 4884
28c6e247
IR
4885DEFUN (neighbor_activate,
4886 neighbor_activate_cmd,
4887 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4888 NEIGHBOR_STR
4889 NEIGHBOR_ADDR_STR2
4890 "Enable the Address Family for this Neighbor\n")
718e3744 4891{
d62a17ae 4892 int idx_peer = 1;
28c6e247
IR
4893 int ret;
4894 struct peer *peer;
56ceae84 4895
28c6e247
IR
4896 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4897 if (!peer)
d62a17ae 4898 return CMD_WARNING_CONFIG_FAILED;
718e3744 4899
28c6e247
IR
4900 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4901 return bgp_vty_return(vty, ret);
718e3744 4902}
4903
d62a17ae 4904ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4905 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4906 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4907 "Enable the Address Family for this Neighbor\n")
596c17ba 4908
28c6e247
IR
4909DEFUN (no_neighbor_activate,
4910 no_neighbor_activate_cmd,
4911 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4912 NO_STR
4913 NEIGHBOR_STR
4914 NEIGHBOR_ADDR_STR2
4915 "Enable the Address Family for this Neighbor\n")
718e3744 4916{
d62a17ae 4917 int idx_peer = 2;
28c6e247
IR
4918 int ret;
4919 struct peer *peer;
f4b8ec07 4920
28c6e247
IR
4921 /* Lookup peer. */
4922 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4923 if (!peer)
d62a17ae 4924 return CMD_WARNING_CONFIG_FAILED;
718e3744 4925
28c6e247
IR
4926 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4927 return bgp_vty_return(vty, ret);
718e3744 4928}
6b0655a2 4929
d62a17ae 4930ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4931 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4932 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4933 "Enable the Address Family for this Neighbor\n")
596c17ba 4934
28c6e247
IR
4935DEFUN (neighbor_set_peer_group,
4936 neighbor_set_peer_group_cmd,
4937 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4938 NEIGHBOR_STR
4939 NEIGHBOR_ADDR_STR2
4940 "Member of the peer-group\n"
4941 "Peer-group name\n")
718e3744 4942{
28c6e247 4943 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4944 int idx_peer = 1;
4945 int idx_word = 3;
28c6e247
IR
4946 int ret;
4947 as_t as;
4948 union sockunion su;
4949 struct peer *peer;
4950 struct peer_group *group;
4951
4952 ret = str2sockunion(argv[idx_peer]->arg, &su);
4953 if (ret < 0) {
4954 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4955 if (!peer) {
4956 vty_out(vty, "%% Malformed address or name: %s\n",
4957 argv[idx_peer]->arg);
4958 return CMD_WARNING_CONFIG_FAILED;
4959 }
4960 } else {
4961 if (peer_address_self_check(bgp, &su)) {
4962 vty_out(vty,
4963 "%% Can not configure the local system as neighbor\n");
4964 return CMD_WARNING_CONFIG_FAILED;
4965 }
2a059a54 4966
28c6e247
IR
4967 /* Disallow for dynamic neighbor. */
4968 peer = peer_lookup(bgp, &su);
4969 if (peer && peer_dynamic_neighbor(peer)) {
4970 vty_out(vty,
4971 "%% Operation not allowed on a dynamic neighbor\n");
4972 return CMD_WARNING_CONFIG_FAILED;
4973 }
4974 }
4975
4976 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4977 if (!group) {
4978 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 4979 return CMD_WARNING_CONFIG_FAILED;
28c6e247 4980 }
d62a17ae 4981
28c6e247 4982 ret = peer_group_bind(bgp, &su, peer, group, &as);
2a059a54 4983
28c6e247 4984 return bgp_vty_return(vty, ret);
d62a17ae 4985}
4986
4987ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 4988 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4989 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4990 "Member of the peer-group\n"
4991 "Peer-group name\n")
596c17ba 4992
28c6e247
IR
4993DEFUN (no_neighbor_set_peer_group,
4994 no_neighbor_set_peer_group_cmd,
4995 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4996 NO_STR
4997 NEIGHBOR_STR
4998 NEIGHBOR_ADDR_STR2
4999 "Member of the peer-group\n"
5000 "Peer-group name\n")
718e3744 5001{
28c6e247 5002 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5003 int idx_peer = 2;
28c6e247
IR
5004 int idx_word = 4;
5005 int ret;
5006 struct peer *peer;
5007 struct peer_group *group;
d62a17ae 5008
28c6e247
IR
5009 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5010 if (!peer)
d62a17ae 5011 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 5012
28c6e247
IR
5013 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5014 if (!group) {
5015 vty_out(vty, "%% Configure the peer-group first\n");
5016 return CMD_WARNING_CONFIG_FAILED;
5017 }
718e3744 5018
28c6e247
IR
5019 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5020 bgp_zebra_terminate_radv(peer->bgp, peer);
5021
5022 peer_notify_unconfig(peer);
5023 ret = peer_delete(peer);
5024
5025 return bgp_vty_return(vty, ret);
718e3744 5026}
6b0655a2 5027
d62a17ae 5028ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
71cc0c88 5029 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5030 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5031 "Member of the peer-group\n"
5032 "Peer-group name\n")
596c17ba 5033
d62a17ae 5034static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 5035 uint32_t flag, int set)
718e3744 5036{
d62a17ae 5037 int ret;
5038 struct peer *peer;
718e3744 5039
d62a17ae 5040 peer = peer_and_group_lookup_vty(vty, ip_str);
5041 if (!peer)
5042 return CMD_WARNING_CONFIG_FAILED;
718e3744 5043
7ebe625c
QY
5044 /*
5045 * If 'neighbor <interface>', then this is for directly connected peers,
5046 * we should not accept disable-connected-check.
5047 */
5048 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5049 vty_out(vty,
3efd0893 5050 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
5051 ip_str);
5052 return CMD_WARNING_CONFIG_FAILED;
5053 }
5054
d62a17ae 5055 if (!set && flag == PEER_FLAG_SHUTDOWN)
5056 peer_tx_shutdown_message_unset(peer);
ae9b0e11 5057
d62a17ae 5058 if (set)
5059 ret = peer_flag_set(peer, flag);
5060 else
5061 ret = peer_flag_unset(peer, flag);
718e3744 5062
d62a17ae 5063 return bgp_vty_return(vty, ret);
718e3744 5064}
5065
47cbc09b 5066static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 5067{
d62a17ae 5068 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 5069}
5070
d62a17ae 5071static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 5072 uint32_t flag)
718e3744 5073{
d62a17ae 5074 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 5075}
5076
5077/* neighbor passive. */
28c6e247
IR
5078DEFUN (neighbor_passive,
5079 neighbor_passive_cmd,
5080 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5081 NEIGHBOR_STR
5082 NEIGHBOR_ADDR_STR2
5083 "Don't send open messages to this neighbor\n")
718e3744 5084{
d62a17ae 5085 int idx_peer = 1;
28c6e247 5086 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5087}
5088
28c6e247
IR
5089DEFUN (no_neighbor_passive,
5090 no_neighbor_passive_cmd,
5091 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5092 NO_STR
5093 NEIGHBOR_STR
5094 NEIGHBOR_ADDR_STR2
5095 "Don't send open messages to this neighbor\n")
718e3744 5096{
d62a17ae 5097 int idx_peer = 2;
28c6e247 5098 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5099}
6b0655a2 5100
718e3744 5101/* neighbor shutdown. */
28c6e247
IR
5102DEFUN (neighbor_shutdown_msg,
5103 neighbor_shutdown_msg_cmd,
5104 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5105 NEIGHBOR_STR
5106 NEIGHBOR_ADDR_STR2
5107 "Administratively shut down this neighbor\n"
5108 "Add a shutdown message (RFC 8203)\n"
5109 "Shutdown message\n")
718e3744 5110{
d62a17ae 5111 int idx_peer = 1;
73d70fa6 5112
d62a17ae 5113 if (argc >= 5) {
28c6e247
IR
5114 struct peer *peer =
5115 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
d62a17ae 5116 char *message;
73d70fa6 5117
28c6e247
IR
5118 if (!peer)
5119 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5120 message = argv_concat(argv, argc, 4);
28c6e247
IR
5121 peer_tx_shutdown_message_set(peer, message);
5122 XFREE(MTYPE_TMP, message);
d62a17ae 5123 }
73d70fa6 5124
28c6e247 5125 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 5126}
5127
1d80f243 5128ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5129 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5130 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5131 "Administratively shut down this neighbor\n")
73d70fa6 5132
28c6e247
IR
5133DEFUN (no_neighbor_shutdown_msg,
5134 no_neighbor_shutdown_msg_cmd,
5135 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5136 NO_STR
5137 NEIGHBOR_STR
5138 NEIGHBOR_ADDR_STR2
5139 "Administratively shut down this neighbor\n"
5140 "Remove a shutdown message (RFC 8203)\n"
5141 "Shutdown message\n")
718e3744 5142{
d62a17ae 5143 int idx_peer = 2;
73d70fa6 5144
28c6e247
IR
5145 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5146 PEER_FLAG_SHUTDOWN);
718e3744 5147}
6b0655a2 5148
1d80f243 5149ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5150 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5151 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5152 "Administratively shut down this neighbor\n")
73d70fa6 5153
8336c896
DA
5154DEFUN(neighbor_shutdown_rtt,
5155 neighbor_shutdown_rtt_cmd,
5156 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5157 NEIGHBOR_STR
5158 NEIGHBOR_ADDR_STR2
5159 "Administratively shut down this neighbor\n"
5160 "Shutdown if round-trip-time is higher than expected\n"
5161 "Round-trip-time in milliseconds\n"
5162 "Specify the number of keepalives before shutdown\n"
5163 "The number of keepalives with higher RTT to shutdown\n")
5164{
5165 int idx_peer = 1;
5166 int idx_rtt = 4;
5167 int idx_count = 0;
5168 struct peer *peer;
5169
5170 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5171
5172 if (!peer)
5173 return CMD_WARNING_CONFIG_FAILED;
5174
5175 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5176
5177 if (argv_find(argv, argc, "count", &idx_count))
5178 peer->rtt_keepalive_conf =
5179 strtol(argv[idx_count + 1]->arg, NULL, 10);
5180
5181 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5182 PEER_FLAG_RTT_SHUTDOWN);
5183}
5184
5185DEFUN(no_neighbor_shutdown_rtt,
5186 no_neighbor_shutdown_rtt_cmd,
5187 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5188 NO_STR
5189 NEIGHBOR_STR
5190 NEIGHBOR_ADDR_STR2
5191 "Administratively shut down this neighbor\n"
5192 "Shutdown if round-trip-time is higher than expected\n"
5193 "Round-trip-time in milliseconds\n"
5194 "Specify the number of keepalives before shutdown\n"
5195 "The number of keepalives with higher RTT to shutdown\n")
5196{
5197 int idx_peer = 2;
5198 struct peer *peer;
5199
5200 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5201
5202 if (!peer)
5203 return CMD_WARNING_CONFIG_FAILED;
5204
5205 peer->rtt_expected = 0;
5206 peer->rtt_keepalive_conf = 1;
5207
5208 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5209 PEER_FLAG_RTT_SHUTDOWN);
5210}
5211
718e3744 5212/* neighbor capability dynamic. */
28c6e247
IR
5213DEFUN (neighbor_capability_dynamic,
5214 neighbor_capability_dynamic_cmd,
5215 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5216 NEIGHBOR_STR
5217 NEIGHBOR_ADDR_STR2
5218 "Advertise capability to the peer\n"
5219 "Advertise dynamic capability to this neighbor\n")
718e3744 5220{
d62a17ae 5221 int idx_peer = 1;
28c6e247
IR
5222 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5223 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5224}
5225
28c6e247
IR
5226DEFUN (no_neighbor_capability_dynamic,
5227 no_neighbor_capability_dynamic_cmd,
5228 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5229 NO_STR
5230 NEIGHBOR_STR
5231 NEIGHBOR_ADDR_STR2
5232 "Advertise capability to the peer\n"
5233 "Advertise dynamic capability to this neighbor\n")
718e3744 5234{
d62a17ae 5235 int idx_peer = 2;
28c6e247
IR
5236 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5237 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5238}
6b0655a2 5239
718e3744 5240/* neighbor dont-capability-negotiate */
5241DEFUN (neighbor_dont_capability_negotiate,
5242 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5243 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5244 NEIGHBOR_STR
5245 NEIGHBOR_ADDR_STR2
5246 "Do not perform capability negotiation\n")
5247{
d62a17ae 5248 int idx_peer = 1;
5249 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5250 PEER_FLAG_DONT_CAPABILITY);
718e3744 5251}
5252
5253DEFUN (no_neighbor_dont_capability_negotiate,
5254 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5255 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5256 NO_STR
5257 NEIGHBOR_STR
5258 NEIGHBOR_ADDR_STR2
5259 "Do not perform capability negotiation\n")
5260{
28c6e247
IR
5261 int idx_peer = 2;
5262 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5263 PEER_FLAG_DONT_CAPABILITY);
f4b8ec07
CS
5264}
5265
28c6e247
IR
5266/* neighbor capability extended next hop encoding */
5267DEFUN (neighbor_capability_enhe,
5268 neighbor_capability_enhe_cmd,
5269 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5270 NEIGHBOR_STR
5271 NEIGHBOR_ADDR_STR2
5272 "Advertise capability to the peer\n"
5273 "Advertise extended next-hop capability to the peer\n")
f4b8ec07 5274{
28c6e247
IR
5275 int idx_peer = 1;
5276 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5277 PEER_FLAG_CAPABILITY_ENHE);
5278}
f4b8ec07 5279
28c6e247
IR
5280DEFUN (no_neighbor_capability_enhe,
5281 no_neighbor_capability_enhe_cmd,
5282 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5283 NO_STR
5284 NEIGHBOR_STR
5285 NEIGHBOR_ADDR_STR2
5286 "Advertise capability to the peer\n"
5287 "Advertise extended next-hop capability to the peer\n")
5288{
5289 int idx_peer = 2;
5290 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5291 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5292}
5293
d62a17ae 5294static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5295 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5296 int set)
718e3744 5297{
d62a17ae 5298 int ret;
5299 struct peer *peer;
718e3744 5300
d62a17ae 5301 peer = peer_and_group_lookup_vty(vty, peer_str);
5302 if (!peer)
5303 return CMD_WARNING_CONFIG_FAILED;
718e3744 5304
d62a17ae 5305 if (set)
5306 ret = peer_af_flag_set(peer, afi, safi, flag);
5307 else
5308 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5309
d62a17ae 5310 return bgp_vty_return(vty, ret);
718e3744 5311}
5312
d62a17ae 5313static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5314 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5315{
d62a17ae 5316 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5317}
5318
d62a17ae 5319static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5320 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5321{
d62a17ae 5322 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5323}
6b0655a2 5324
718e3744 5325/* neighbor capability orf prefix-list. */
5326DEFUN (neighbor_capability_orf_prefix,
5327 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5328 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5329 NEIGHBOR_STR
5330 NEIGHBOR_ADDR_STR2
5331 "Advertise capability to the peer\n"
5332 "Advertise ORF capability to the peer\n"
5333 "Advertise prefixlist ORF capability to this neighbor\n"
5334 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5335 "Capability to RECEIVE the ORF from this neighbor\n"
5336 "Capability to SEND the ORF to this neighbor\n")
5337{
d62a17ae 5338 int idx_send_recv = 5;
db45f64d
DS
5339 char *peer_str = argv[1]->arg;
5340 struct peer *peer;
5341 afi_t afi = bgp_node_afi(vty);
5342 safi_t safi = bgp_node_safi(vty);
d62a17ae 5343
db45f64d
DS
5344 peer = peer_and_group_lookup_vty(vty, peer_str);
5345 if (!peer)
d62a17ae 5346 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5347
db45f64d
DS
5348 if (strmatch(argv[idx_send_recv]->text, "send"))
5349 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5350 PEER_FLAG_ORF_PREFIX_SM);
5351
5352 if (strmatch(argv[idx_send_recv]->text, "receive"))
5353 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5354 PEER_FLAG_ORF_PREFIX_RM);
5355
5356 if (strmatch(argv[idx_send_recv]->text, "both"))
5357 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5358 PEER_FLAG_ORF_PREFIX_SM)
5359 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5360 PEER_FLAG_ORF_PREFIX_RM);
5361
5362 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5363}
5364
5365ALIAS_HIDDEN(
5366 neighbor_capability_orf_prefix,
5367 neighbor_capability_orf_prefix_hidden_cmd,
5368 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5369 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5370 "Advertise capability to the peer\n"
5371 "Advertise ORF capability to the peer\n"
5372 "Advertise prefixlist ORF capability to this neighbor\n"
5373 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5374 "Capability to RECEIVE the ORF from this neighbor\n"
5375 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5376
718e3744 5377DEFUN (no_neighbor_capability_orf_prefix,
5378 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5379 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5380 NO_STR
5381 NEIGHBOR_STR
5382 NEIGHBOR_ADDR_STR2
5383 "Advertise capability to the peer\n"
5384 "Advertise ORF capability to the peer\n"
5385 "Advertise prefixlist ORF capability to this neighbor\n"
5386 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5387 "Capability to RECEIVE the ORF from this neighbor\n"
5388 "Capability to SEND the ORF to this neighbor\n")
5389{
d62a17ae 5390 int idx_send_recv = 6;
db45f64d
DS
5391 char *peer_str = argv[2]->arg;
5392 struct peer *peer;
5393 afi_t afi = bgp_node_afi(vty);
5394 safi_t safi = bgp_node_safi(vty);
d62a17ae 5395
db45f64d
DS
5396 peer = peer_and_group_lookup_vty(vty, peer_str);
5397 if (!peer)
d62a17ae 5398 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5399
db45f64d
DS
5400 if (strmatch(argv[idx_send_recv]->text, "send"))
5401 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5402 PEER_FLAG_ORF_PREFIX_SM);
5403
5404 if (strmatch(argv[idx_send_recv]->text, "receive"))
5405 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5406 PEER_FLAG_ORF_PREFIX_RM);
5407
5408 if (strmatch(argv[idx_send_recv]->text, "both"))
5409 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5410 PEER_FLAG_ORF_PREFIX_SM)
5411 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5412 PEER_FLAG_ORF_PREFIX_RM);
5413
5414 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5415}
5416
5417ALIAS_HIDDEN(
5418 no_neighbor_capability_orf_prefix,
5419 no_neighbor_capability_orf_prefix_hidden_cmd,
5420 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5421 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5422 "Advertise capability to the peer\n"
5423 "Advertise ORF capability to the peer\n"
5424 "Advertise prefixlist ORF capability to this neighbor\n"
5425 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5426 "Capability to RECEIVE the ORF from this neighbor\n"
5427 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5428
718e3744 5429/* neighbor next-hop-self. */
28c6e247
IR
5430DEFUN (neighbor_nexthop_self,
5431 neighbor_nexthop_self_cmd,
5432 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5433 NEIGHBOR_STR
5434 NEIGHBOR_ADDR_STR2
5435 "Disable the next hop calculation for this neighbor\n")
718e3744 5436{
d62a17ae 5437 int idx_peer = 1;
28c6e247
IR
5438 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5439 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 5440}
9e7a53c1 5441
d62a17ae 5442ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5443 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5444 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5445 "Disable the next hop calculation for this neighbor\n")
596c17ba 5446
f4b8ec07 5447/* neighbor next-hop-self. */
28c6e247
IR
5448DEFUN (neighbor_nexthop_self_force,
5449 neighbor_nexthop_self_force_cmd,
5450 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5451 NEIGHBOR_STR
5452 NEIGHBOR_ADDR_STR2
5453 "Disable the next hop calculation for this neighbor\n"
5454 "Set the next hop to self for reflected routes\n")
f4b8ec07
CS
5455{
5456 int idx_peer = 1;
28c6e247
IR
5457 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5458 bgp_node_safi(vty),
5459 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 5460}
5461
d62a17ae 5462ALIAS_HIDDEN(neighbor_nexthop_self_force,
5463 neighbor_nexthop_self_force_hidden_cmd,
5464 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5465 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5466 "Disable the next hop calculation for this neighbor\n"
5467 "Set the next hop to self for reflected routes\n")
596c17ba 5468
1bc4e531
DA
5469ALIAS_HIDDEN(neighbor_nexthop_self_force,
5470 neighbor_nexthop_self_all_hidden_cmd,
5471 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5472 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5473 "Disable the next hop calculation for this neighbor\n"
5474 "Set the next hop to self for reflected routes\n")
5475
28c6e247
IR
5476DEFUN (no_neighbor_nexthop_self,
5477 no_neighbor_nexthop_self_cmd,
5478 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5479 NO_STR
5480 NEIGHBOR_STR
5481 NEIGHBOR_ADDR_STR2
5482 "Disable the next hop calculation for this neighbor\n")
718e3744 5483{
d62a17ae 5484 int idx_peer = 2;
28c6e247
IR
5485 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5486 bgp_node_afi(vty), bgp_node_safi(vty),
5487 PEER_FLAG_NEXTHOP_SELF);
718e3744 5488}
6b0655a2 5489
d62a17ae 5490ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5491 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5492 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5493 "Disable the next hop calculation for this neighbor\n")
596c17ba 5494
28c6e247
IR
5495DEFUN (no_neighbor_nexthop_self_force,
5496 no_neighbor_nexthop_self_force_cmd,
5497 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5498 NO_STR
5499 NEIGHBOR_STR
5500 NEIGHBOR_ADDR_STR2
5501 "Disable the next hop calculation for this neighbor\n"
5502 "Set the next hop to self for reflected routes\n")
88b8ed8d 5503{
d62a17ae 5504 int idx_peer = 2;
28c6e247
IR
5505 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5506 bgp_node_afi(vty), bgp_node_safi(vty),
5507 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5508}
a538debe 5509
d62a17ae 5510ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5511 no_neighbor_nexthop_self_force_hidden_cmd,
5512 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5513 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5514 "Disable the next hop calculation for this neighbor\n"
5515 "Set the next hop to self for reflected routes\n")
596c17ba 5516
1bc4e531
DA
5517ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5518 no_neighbor_nexthop_self_all_hidden_cmd,
5519 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5520 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5521 "Disable the next hop calculation for this neighbor\n"
5522 "Set the next hop to self for reflected routes\n")
5523
c7122e14 5524/* neighbor as-override */
28c6e247
IR
5525DEFUN (neighbor_as_override,
5526 neighbor_as_override_cmd,
5527 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5528 NEIGHBOR_STR
5529 NEIGHBOR_ADDR_STR2
5530 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5531{
d62a17ae 5532 int idx_peer = 1;
28c6e247
IR
5533 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5534 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5535}
5536
d62a17ae 5537ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5538 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5539 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5540 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5541
28c6e247
IR
5542DEFUN (no_neighbor_as_override,
5543 no_neighbor_as_override_cmd,
5544 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5545 NO_STR
5546 NEIGHBOR_STR
5547 NEIGHBOR_ADDR_STR2
5548 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5549{
d62a17ae 5550 int idx_peer = 2;
28c6e247
IR
5551 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5552 bgp_node_afi(vty), bgp_node_safi(vty),
5553 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5554}
5555
d62a17ae 5556ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5557 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5558 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5559 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5560
718e3744 5561/* neighbor remove-private-AS. */
28c6e247
IR
5562DEFUN (neighbor_remove_private_as,
5563 neighbor_remove_private_as_cmd,
5564 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5565 NEIGHBOR_STR
5566 NEIGHBOR_ADDR_STR2
5567 "Remove private ASNs in outbound updates\n")
718e3744 5568{
d62a17ae 5569 int idx_peer = 1;
28c6e247
IR
5570 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5571 bgp_node_safi(vty),
5572 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5573}
5574
d62a17ae 5575ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5576 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5577 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5578 "Remove private ASNs in outbound updates\n")
596c17ba 5579
28c6e247
IR
5580DEFUN (neighbor_remove_private_as_all,
5581 neighbor_remove_private_as_all_cmd,
5582 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5583 NEIGHBOR_STR
5584 NEIGHBOR_ADDR_STR2
5585 "Remove private ASNs in outbound updates\n"
5586 "Apply to all AS numbers\n")
5000f21c 5587{
d62a17ae 5588 int idx_peer = 1;
28c6e247
IR
5589 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5590 bgp_node_safi(vty),
5591 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
5592}
5593
d62a17ae 5594ALIAS_HIDDEN(neighbor_remove_private_as_all,
5595 neighbor_remove_private_as_all_hidden_cmd,
5596 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5597 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5598 "Remove private ASNs in outbound updates\n"
5599 "Apply to all AS numbers")
596c17ba 5600
28c6e247
IR
5601DEFUN (neighbor_remove_private_as_replace_as,
5602 neighbor_remove_private_as_replace_as_cmd,
5603 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5604 NEIGHBOR_STR
5605 NEIGHBOR_ADDR_STR2
5606 "Remove private ASNs in outbound updates\n"
5607 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5608{
d62a17ae 5609 int idx_peer = 1;
28c6e247
IR
5610 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5611 bgp_node_safi(vty),
5612 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
5613}
5614
d62a17ae 5615ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5616 neighbor_remove_private_as_replace_as_hidden_cmd,
5617 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5618 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5619 "Remove private ASNs in outbound updates\n"
5620 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5621
28c6e247
IR
5622DEFUN (neighbor_remove_private_as_all_replace_as,
5623 neighbor_remove_private_as_all_replace_as_cmd,
5624 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5625 NEIGHBOR_STR
5626 NEIGHBOR_ADDR_STR2
5627 "Remove private ASNs in outbound updates\n"
5628 "Apply to all AS numbers\n"
5629 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5630{
d62a17ae 5631 int idx_peer = 1;
28c6e247
IR
5632 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5633 bgp_node_safi(vty),
5634 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
5635}
5636
d62a17ae 5637ALIAS_HIDDEN(
5638 neighbor_remove_private_as_all_replace_as,
5639 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5640 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5641 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5642 "Remove private ASNs in outbound updates\n"
5643 "Apply to all AS numbers\n"
5644 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5645
28c6e247
IR
5646DEFUN (no_neighbor_remove_private_as,
5647 no_neighbor_remove_private_as_cmd,
5648 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5649 NO_STR
5650 NEIGHBOR_STR
5651 NEIGHBOR_ADDR_STR2
5652 "Remove private ASNs in outbound updates\n")
718e3744 5653{
d62a17ae 5654 int idx_peer = 2;
28c6e247
IR
5655 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5656 bgp_node_afi(vty), bgp_node_safi(vty),
5657 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5658}
6b0655a2 5659
d62a17ae 5660ALIAS_HIDDEN(no_neighbor_remove_private_as,
5661 no_neighbor_remove_private_as_hidden_cmd,
5662 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5663 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5664 "Remove private ASNs in outbound updates\n")
596c17ba 5665
28c6e247
IR
5666DEFUN (no_neighbor_remove_private_as_all,
5667 no_neighbor_remove_private_as_all_cmd,
5668 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5669 NO_STR
5670 NEIGHBOR_STR
5671 NEIGHBOR_ADDR_STR2
5672 "Remove private ASNs in outbound updates\n"
5673 "Apply to all AS numbers\n")
88b8ed8d 5674{
d62a17ae 5675 int idx_peer = 2;
28c6e247
IR
5676 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5677 bgp_node_afi(vty), bgp_node_safi(vty),
5678 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 5679}
5000f21c 5680
d62a17ae 5681ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5682 no_neighbor_remove_private_as_all_hidden_cmd,
5683 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5684 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5685 "Remove private ASNs in outbound updates\n"
5686 "Apply to all AS numbers\n")
596c17ba 5687
28c6e247
IR
5688DEFUN (no_neighbor_remove_private_as_replace_as,
5689 no_neighbor_remove_private_as_replace_as_cmd,
5690 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5691 NO_STR
5692 NEIGHBOR_STR
5693 NEIGHBOR_ADDR_STR2
5694 "Remove private ASNs in outbound updates\n"
5695 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5696{
d62a17ae 5697 int idx_peer = 2;
28c6e247
IR
5698 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5699 bgp_node_afi(vty), bgp_node_safi(vty),
5700 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 5701}
5000f21c 5702
d62a17ae 5703ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5704 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5705 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5706 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5707 "Remove private ASNs in outbound updates\n"
5708 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5709
28c6e247
IR
5710DEFUN (no_neighbor_remove_private_as_all_replace_as,
5711 no_neighbor_remove_private_as_all_replace_as_cmd,
5712 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5713 NO_STR
5714 NEIGHBOR_STR
5715 NEIGHBOR_ADDR_STR2
5716 "Remove private ASNs in outbound updates\n"
5717 "Apply to all AS numbers\n"
5718 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5719{
d62a17ae 5720 int idx_peer = 2;
28c6e247
IR
5721 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5722 bgp_node_afi(vty), bgp_node_safi(vty),
5723 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 5724}
5000f21c 5725
d62a17ae 5726ALIAS_HIDDEN(
5727 no_neighbor_remove_private_as_all_replace_as,
5728 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5729 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5730 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5731 "Remove private ASNs in outbound updates\n"
5732 "Apply to all AS numbers\n"
5733 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5734
5000f21c 5735
718e3744 5736/* neighbor send-community. */
28c6e247
IR
5737DEFUN (neighbor_send_community,
5738 neighbor_send_community_cmd,
5739 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5740 NEIGHBOR_STR
5741 NEIGHBOR_ADDR_STR2
5742 "Send Community attribute to this neighbor\n")
718e3744 5743{
d62a17ae 5744 int idx_peer = 1;
27c05d4d 5745
f63d4054
IR
5746 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5747 bgp_node_safi(vty),
5748 PEER_FLAG_SEND_COMMUNITY);
718e3744 5749}
5750
d62a17ae 5751ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5752 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5753 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5754 "Send Community attribute to this neighbor\n")
596c17ba 5755
28c6e247
IR
5756DEFUN (no_neighbor_send_community,
5757 no_neighbor_send_community_cmd,
5758 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5759 NO_STR
5760 NEIGHBOR_STR
5761 NEIGHBOR_ADDR_STR2
5762 "Send Community attribute to this neighbor\n")
718e3744 5763{
d62a17ae 5764 int idx_peer = 2;
27c05d4d 5765
f63d4054
IR
5766 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5767 bgp_node_afi(vty), bgp_node_safi(vty),
5768 PEER_FLAG_SEND_COMMUNITY);
718e3744 5769}
6b0655a2 5770
d62a17ae 5771ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5772 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5773 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5774 "Send Community attribute to this neighbor\n")
596c17ba 5775
718e3744 5776/* neighbor send-community extended. */
28c6e247
IR
5777DEFUN (neighbor_send_community_type,
5778 neighbor_send_community_type_cmd,
5779 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5780 NEIGHBOR_STR
5781 NEIGHBOR_ADDR_STR2
5782 "Send Community attribute to this neighbor\n"
5783 "Send Standard and Extended Community attributes\n"
5784 "Send Standard, Large and Extended Community attributes\n"
5785 "Send Extended Community attributes\n"
5786 "Send Standard Community attributes\n"
5787 "Send Large Community attributes\n")
718e3744 5788{
27c05d4d 5789 const char *type = argv[argc - 1]->text;
db45f64d 5790 char *peer_str = argv[1]->arg;
28c6e247 5791 struct peer *peer;
db45f64d 5792 afi_t afi = bgp_node_afi(vty);
28c6e247 5793 safi_t safi = bgp_node_safi(vty);
f4b8ec07 5794
28c6e247
IR
5795 peer = peer_and_group_lookup_vty(vty, peer_str);
5796 if (!peer)
5797 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07 5798
28c6e247
IR
5799 if (strmatch(type, "standard"))
5800 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5801 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 5802
28c6e247
IR
5803 if (strmatch(type, "extended"))
5804 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5805 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5806
28c6e247
IR
5807 if (strmatch(type, "large"))
5808 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5809 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07 5810
28c6e247
IR
5811 if (strmatch(type, "both")) {
5812 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5813 PEER_FLAG_SEND_COMMUNITY)
5814 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5815 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5816 }
28c6e247
IR
5817 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5818 PEER_FLAG_SEND_COMMUNITY)
5819 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5820 PEER_FLAG_SEND_EXT_COMMUNITY)
5821 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5822 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5823}
5824
5825ALIAS_HIDDEN(
5826 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5827 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5828 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5829 "Send Community attribute to this neighbor\n"
5830 "Send Standard and Extended Community attributes\n"
5831 "Send Standard, Large and Extended Community attributes\n"
5832 "Send Extended Community attributes\n"
5833 "Send Standard Community attributes\n"
5834 "Send Large Community attributes\n")
596c17ba 5835
28c6e247
IR
5836DEFUN (no_neighbor_send_community_type,
5837 no_neighbor_send_community_type_cmd,
5838 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5839 NO_STR
5840 NEIGHBOR_STR
5841 NEIGHBOR_ADDR_STR2
5842 "Send Community attribute to this neighbor\n"
5843 "Send Standard and Extended Community attributes\n"
5844 "Send Standard, Large and Extended Community attributes\n"
5845 "Send Extended Community attributes\n"
5846 "Send Standard Community attributes\n"
5847 "Send Large Community attributes\n")
718e3744 5848{
d62a17ae 5849 const char *type = argv[argc - 1]->text;
db45f64d 5850 char *peer_str = argv[2]->arg;
28c6e247 5851 struct peer *peer;
db45f64d
DS
5852 afi_t afi = bgp_node_afi(vty);
5853 safi_t safi = bgp_node_safi(vty);
5854
28c6e247
IR
5855 peer = peer_and_group_lookup_vty(vty, peer_str);
5856 if (!peer)
f4b8ec07
CS
5857 return CMD_WARNING_CONFIG_FAILED;
5858
28c6e247
IR
5859 if (strmatch(type, "standard"))
5860 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5861 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 5862
28c6e247
IR
5863 if (strmatch(type, "extended"))
5864 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5865 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5866
28c6e247
IR
5867 if (strmatch(type, "large"))
5868 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5869 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07
CS
5870
5871 if (strmatch(type, "both")) {
db45f64d 5872
28c6e247
IR
5873 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5874 PEER_FLAG_SEND_COMMUNITY)
5875 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5876 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
5877 }
5878
28c6e247
IR
5879 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5880 PEER_FLAG_SEND_COMMUNITY)
5881 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5882 PEER_FLAG_SEND_EXT_COMMUNITY)
5883 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5884 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5885}
5886
5887ALIAS_HIDDEN(
5888 no_neighbor_send_community_type,
5889 no_neighbor_send_community_type_hidden_cmd,
5890 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5891 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5892 "Send Community attribute to this neighbor\n"
5893 "Send Standard and Extended Community attributes\n"
5894 "Send Standard, Large and Extended Community attributes\n"
5895 "Send Extended Community attributes\n"
5896 "Send Standard Community attributes\n"
5897 "Send Large Community attributes\n")
596c17ba 5898
718e3744 5899/* neighbor soft-reconfig. */
28c6e247
IR
5900DEFUN (neighbor_soft_reconfiguration,
5901 neighbor_soft_reconfiguration_cmd,
5902 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5903 NEIGHBOR_STR
5904 NEIGHBOR_ADDR_STR2
5905 "Per neighbor soft reconfiguration\n"
5906 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 5907{
d62a17ae 5908 int idx_peer = 1;
28c6e247
IR
5909 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5910 bgp_node_safi(vty),
5911 PEER_FLAG_SOFT_RECONFIG);
718e3744 5912}
5913
d62a17ae 5914ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5915 neighbor_soft_reconfiguration_hidden_cmd,
5916 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5917 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5918 "Per neighbor soft reconfiguration\n"
5919 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5920
28c6e247
IR
5921DEFUN (no_neighbor_soft_reconfiguration,
5922 no_neighbor_soft_reconfiguration_cmd,
5923 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5924 NO_STR
5925 NEIGHBOR_STR
5926 NEIGHBOR_ADDR_STR2
5927 "Per neighbor soft reconfiguration\n"
5928 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 5929{
d62a17ae 5930 int idx_peer = 2;
28c6e247
IR
5931 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5932 bgp_node_afi(vty), bgp_node_safi(vty),
5933 PEER_FLAG_SOFT_RECONFIG);
718e3744 5934}
6b0655a2 5935
d62a17ae 5936ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5937 no_neighbor_soft_reconfiguration_hidden_cmd,
5938 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5939 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5940 "Per neighbor soft reconfiguration\n"
5941 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5942
28c6e247
IR
5943DEFUN (neighbor_route_reflector_client,
5944 neighbor_route_reflector_client_cmd,
5945 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5946 NEIGHBOR_STR
5947 NEIGHBOR_ADDR_STR2
5948 "Configure a neighbor as Route Reflector client\n")
718e3744 5949{
d62a17ae 5950 int idx_peer = 1;
28c6e247 5951 struct peer *peer;
718e3744 5952
5953
28c6e247
IR
5954 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5955 if (!peer)
d62a17ae 5956 return CMD_WARNING_CONFIG_FAILED;
718e3744 5957
28c6e247
IR
5958 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5959 bgp_node_safi(vty),
5960 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5961}
5962
d62a17ae 5963ALIAS_HIDDEN(neighbor_route_reflector_client,
5964 neighbor_route_reflector_client_hidden_cmd,
5965 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5966 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5967 "Configure a neighbor as Route Reflector client\n")
596c17ba 5968
28c6e247
IR
5969DEFUN (no_neighbor_route_reflector_client,
5970 no_neighbor_route_reflector_client_cmd,
5971 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5972 NO_STR
5973 NEIGHBOR_STR
5974 NEIGHBOR_ADDR_STR2
5975 "Configure a neighbor as Route Reflector client\n")
718e3744 5976{
d62a17ae 5977 int idx_peer = 2;
28c6e247
IR
5978 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5979 bgp_node_afi(vty), bgp_node_safi(vty),
5980 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5981}
6b0655a2 5982
d62a17ae 5983ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5984 no_neighbor_route_reflector_client_hidden_cmd,
5985 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5986 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5987 "Configure a neighbor as Route Reflector client\n")
596c17ba 5988
718e3744 5989/* neighbor route-server-client. */
28c6e247
IR
5990DEFUN (neighbor_route_server_client,
5991 neighbor_route_server_client_cmd,
5992 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5993 NEIGHBOR_STR
5994 NEIGHBOR_ADDR_STR2
5995 "Configure a neighbor as Route Server client\n")
718e3744 5996{
d62a17ae 5997 int idx_peer = 1;
28c6e247 5998 struct peer *peer;
f4b8ec07 5999
28c6e247
IR
6000 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6001 if (!peer)
d62a17ae 6002 return CMD_WARNING_CONFIG_FAILED;
28c6e247
IR
6003 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6004 bgp_node_safi(vty),
6005 PEER_FLAG_RSERVER_CLIENT);
718e3744 6006}
6007
d62a17ae 6008ALIAS_HIDDEN(neighbor_route_server_client,
6009 neighbor_route_server_client_hidden_cmd,
6010 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6011 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6012 "Configure a neighbor as Route Server client\n")
596c17ba 6013
28c6e247
IR
6014DEFUN (no_neighbor_route_server_client,
6015 no_neighbor_route_server_client_cmd,
6016 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6017 NO_STR
6018 NEIGHBOR_STR
6019 NEIGHBOR_ADDR_STR2
6020 "Configure a neighbor as Route Server client\n")
fee0f4c6 6021{
d62a17ae 6022 int idx_peer = 2;
28c6e247
IR
6023 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6024 bgp_node_afi(vty), bgp_node_safi(vty),
6025 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 6026}
6b0655a2 6027
d62a17ae 6028ALIAS_HIDDEN(no_neighbor_route_server_client,
6029 no_neighbor_route_server_client_hidden_cmd,
6030 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6031 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6032 "Configure a neighbor as Route Server client\n")
596c17ba 6033
fee0f4c6 6034DEFUN (neighbor_nexthop_local_unchanged,
6035 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6036 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6037 NEIGHBOR_STR
6038 NEIGHBOR_ADDR_STR2
6039 "Configure treatment of outgoing link-local nexthop attribute\n"
6040 "Leave link-local nexthop unchanged for this peer\n")
6041{
d62a17ae 6042 int idx_peer = 1;
6043 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6044 bgp_node_safi(vty),
6045 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6046}
6b0655a2 6047
fee0f4c6 6048DEFUN (no_neighbor_nexthop_local_unchanged,
6049 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6050 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6051 NO_STR
6052 NEIGHBOR_STR
6053 NEIGHBOR_ADDR_STR2
6054 "Configure treatment of outgoing link-local-nexthop attribute\n"
6055 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6056{
d62a17ae 6057 int idx_peer = 2;
6058 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6059 bgp_node_afi(vty), bgp_node_safi(vty),
6060 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6061}
6b0655a2 6062
28c6e247
IR
6063DEFUN (neighbor_attr_unchanged,
6064 neighbor_attr_unchanged_cmd,
6065 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6066 NEIGHBOR_STR
6067 NEIGHBOR_ADDR_STR2
6068 "BGP attribute is propagated unchanged to this neighbor\n"
6069 "As-path attribute\n"
6070 "Nexthop attribute\n"
6071 "Med attribute\n")
718e3744 6072{
d62a17ae 6073 int idx = 0;
8eeb0335 6074 char *peer_str = argv[1]->arg;
28c6e247 6075 struct peer *peer;
db45f64d
DS
6076 bool aspath = false;
6077 bool nexthop = false;
6078 bool med = false;
8eeb0335
DW
6079 afi_t afi = bgp_node_afi(vty);
6080 safi_t safi = bgp_node_safi(vty);
28c6e247 6081 int ret = 0;
f4b8ec07 6082
28c6e247
IR
6083 peer = peer_and_group_lookup_vty(vty, peer_str);
6084 if (!peer)
8eeb0335 6085 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6086
6087 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6088 aspath = true;
6089
d62a17ae 6090 idx = 0;
6091 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6092 nexthop = true;
6093
d62a17ae 6094 idx = 0;
6095 if (argv_find(argv, argc, "med", &idx))
db45f64d 6096 med = true;
d62a17ae 6097
8eeb0335 6098 /* no flags means all of them! */
db45f64d 6099 if (!aspath && !nexthop && !med) {
28c6e247
IR
6100 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6101 PEER_FLAG_AS_PATH_UNCHANGED);
6102 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6103 PEER_FLAG_NEXTHOP_UNCHANGED);
6104 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6105 PEER_FLAG_MED_UNCHANGED);
8eeb0335 6106 } else {
28c6e247
IR
6107 if (!aspath) {
6108 if (peer_af_flag_check(peer, afi, safi,
6109 PEER_FLAG_AS_PATH_UNCHANGED)) {
6110 ret |= peer_af_flag_unset_vty(
6111 vty, peer_str, afi, safi,
6112 PEER_FLAG_AS_PATH_UNCHANGED);
6113 }
6114 } else
6115 ret |= peer_af_flag_set_vty(
6116 vty, peer_str, afi, safi,
6117 PEER_FLAG_AS_PATH_UNCHANGED);
6118
6119 if (!nexthop) {
6120 if (peer_af_flag_check(peer, afi, safi,
6121 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6122 ret |= peer_af_flag_unset_vty(
6123 vty, peer_str, afi, safi,
6124 PEER_FLAG_NEXTHOP_UNCHANGED);
6125 }
6126 } else
6127 ret |= peer_af_flag_set_vty(
6128 vty, peer_str, afi, safi,
6129 PEER_FLAG_NEXTHOP_UNCHANGED);
6130
6131 if (!med) {
6132 if (peer_af_flag_check(peer, afi, safi,
6133 PEER_FLAG_MED_UNCHANGED)) {
6134 ret |= peer_af_flag_unset_vty(
6135 vty, peer_str, afi, safi,
6136 PEER_FLAG_MED_UNCHANGED);
6137 }
6138 } else
6139 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6140 PEER_FLAG_MED_UNCHANGED);
d62a17ae 6141 }
6142
28c6e247 6143 return ret;
d62a17ae 6144}
6145
6146ALIAS_HIDDEN(
6147 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6148 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6149 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6150 "BGP attribute is propagated unchanged to this neighbor\n"
6151 "As-path attribute\n"
6152 "Nexthop attribute\n"
6153 "Med attribute\n")
596c17ba 6154
28c6e247
IR
6155DEFUN (no_neighbor_attr_unchanged,
6156 no_neighbor_attr_unchanged_cmd,
6157 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6158 NO_STR
6159 NEIGHBOR_STR
6160 NEIGHBOR_ADDR_STR2
6161 "BGP attribute is propagated unchanged to this neighbor\n"
6162 "As-path attribute\n"
6163 "Nexthop attribute\n"
6164 "Med attribute\n")
718e3744 6165{
d62a17ae 6166 int idx = 0;
db45f64d 6167 char *peer_str = argv[2]->arg;
28c6e247 6168 struct peer *peer;
db45f64d
DS
6169 bool aspath = false;
6170 bool nexthop = false;
6171 bool med = false;
6172 afi_t afi = bgp_node_afi(vty);
6173 safi_t safi = bgp_node_safi(vty);
28c6e247 6174 int ret = 0;
f4b8ec07 6175
28c6e247
IR
6176 peer = peer_and_group_lookup_vty(vty, peer_str);
6177 if (!peer)
db45f64d 6178 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6179
6180 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6181 aspath = true;
6182
d62a17ae 6183 idx = 0;
6184 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6185 nexthop = true;
6186
d62a17ae 6187 idx = 0;
6188 if (argv_find(argv, argc, "med", &idx))
db45f64d 6189 med = true;
d62a17ae 6190
28c6e247
IR
6191 if (!aspath && !nexthop && !med) // no flags means all of them!
6192 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6193 PEER_FLAG_AS_PATH_UNCHANGED)
6194 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6195 PEER_FLAG_NEXTHOP_UNCHANGED)
6196 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6197 PEER_FLAG_MED_UNCHANGED);
db45f64d
DS
6198
6199 if (aspath)
28c6e247
IR
6200 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6201 PEER_FLAG_AS_PATH_UNCHANGED);
db45f64d
DS
6202
6203 if (nexthop)
28c6e247
IR
6204 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6205 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 6206
db45f64d 6207 if (med)
28c6e247
IR
6208 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6209 PEER_FLAG_MED_UNCHANGED);
db45f64d 6210
28c6e247 6211 return ret;
d62a17ae 6212}
6213
6214ALIAS_HIDDEN(
6215 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6216 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6217 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6218 "BGP attribute is propagated unchanged to this neighbor\n"
6219 "As-path attribute\n"
6220 "Nexthop attribute\n"
6221 "Med attribute\n")
718e3744 6222
28c6e247
IR
6223/* EBGP multihop configuration. */
6224static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6225 const char *ttl_str)
718e3744 6226{
28c6e247
IR
6227 struct peer *peer;
6228 unsigned int ttl;
718e3744 6229
28c6e247
IR
6230 peer = peer_and_group_lookup_vty(vty, ip_str);
6231 if (!peer)
d62a17ae 6232 return CMD_WARNING_CONFIG_FAILED;
718e3744 6233
28c6e247
IR
6234 if (peer->conf_if)
6235 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6236
6237 if (!ttl_str)
6238 ttl = MAXTTL;
6239 else
6240 ttl = strtoul(ttl_str, NULL, 10);
718e3744 6241
28c6e247 6242 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 6243}
6244
28c6e247 6245static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6246{
28c6e247 6247 struct peer *peer;
718e3744 6248
28c6e247
IR
6249 peer = peer_and_group_lookup_vty(vty, ip_str);
6250 if (!peer)
d62a17ae 6251 return CMD_WARNING_CONFIG_FAILED;
718e3744 6252
28c6e247 6253 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 6254}
6255
28c6e247
IR
6256/* neighbor ebgp-multihop. */
6257DEFUN (neighbor_ebgp_multihop,
6258 neighbor_ebgp_multihop_cmd,
6259 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6260 NEIGHBOR_STR
6261 NEIGHBOR_ADDR_STR2
6262 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6263{
28c6e247
IR
6264 int idx_peer = 1;
6265 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6266}
f4b8ec07 6267
28c6e247
IR
6268DEFUN (neighbor_ebgp_multihop_ttl,
6269 neighbor_ebgp_multihop_ttl_cmd,
6270 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6271 NEIGHBOR_STR
6272 NEIGHBOR_ADDR_STR2
6273 "Allow EBGP neighbors not on directly connected networks\n"
6274 "maximum hop count\n")
6275{
6276 int idx_peer = 1;
6277 int idx_number = 3;
6278 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6279 argv[idx_number]->arg);
6280}
f4b8ec07 6281
28c6e247
IR
6282DEFUN (no_neighbor_ebgp_multihop,
6283 no_neighbor_ebgp_multihop_cmd,
6284 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6285 NO_STR
6286 NEIGHBOR_STR
6287 NEIGHBOR_ADDR_STR2
6288 "Allow EBGP neighbors not on directly connected networks\n"
6289 "maximum hop count\n")
6290{
6291 int idx_peer = 2;
6292 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6293}
6294
6b0655a2 6295
6ffd2079 6296/* disable-connected-check */
28c6e247
IR
6297DEFUN (neighbor_disable_connected_check,
6298 neighbor_disable_connected_check_cmd,
6299 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6300 NEIGHBOR_STR
6301 NEIGHBOR_ADDR_STR2
6302 "one-hop away EBGP peer using loopback address\n"
6303 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6304{
d62a17ae 6305 int idx_peer = 1;
28c6e247
IR
6306 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6307 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6308}
6309
28c6e247
IR
6310DEFUN (no_neighbor_disable_connected_check,
6311 no_neighbor_disable_connected_check_cmd,
6312 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6313 NO_STR
6314 NEIGHBOR_STR
6315 NEIGHBOR_ADDR_STR2
6316 "one-hop away EBGP peer using loopback address\n"
6317 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6318{
d62a17ae 6319 int idx_peer = 2;
28c6e247
IR
6320 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6321 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6322}
6323
7ab294ea
DA
6324/* disable-link-bw-encoding-ieee */
6325DEFUN(neighbor_disable_link_bw_encoding_ieee,
6326 neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6327 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6328 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6329 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6330{
6331 int idx_peer = 1;
6332
6333 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6334 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6335}
6336
7ab294ea
DA
6337DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6338 no_neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6339 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6340 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6341 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6342{
6343 int idx_peer = 2;
6344
6345 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6346 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6347}
6348
d08c0c80
DA
6349/* extended-optional-parameters */
6350DEFUN(neighbor_extended_optional_parameters,
6351 neighbor_extended_optional_parameters_cmd,
6352 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6353 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6354 "Force the extended optional parameters format for OPEN messages\n")
6355{
6356 int idx_peer = 1;
6357
6358 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6359 PEER_FLAG_EXTENDED_OPT_PARAMS);
6360}
6361
6362DEFUN(no_neighbor_extended_optional_parameters,
6363 no_neighbor_extended_optional_parameters_cmd,
6364 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6365 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6366 "Force the extended optional parameters format for OPEN messages\n")
6367{
6368 int idx_peer = 2;
6369
6370 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6371 PEER_FLAG_EXTENDED_OPT_PARAMS);
6372}
47cbc09b
PM
6373
6374/* enforce-first-as */
28c6e247
IR
6375DEFUN (neighbor_enforce_first_as,
6376 neighbor_enforce_first_as_cmd,
6377 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6378 NEIGHBOR_STR
6379 NEIGHBOR_ADDR_STR2
6380 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6381{
6382 int idx_peer = 1;
f4b8ec07 6383
28c6e247
IR
6384 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6385 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6386}
6387
28c6e247
IR
6388DEFUN (no_neighbor_enforce_first_as,
6389 no_neighbor_enforce_first_as_cmd,
6390 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6391 NO_STR
6392 NEIGHBOR_STR
6393 NEIGHBOR_ADDR_STR2
6394 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6395{
6396 int idx_peer = 2;
f4b8ec07 6397
28c6e247
IR
6398 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6399 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6400}
6401
6402
28c6e247
IR
6403DEFUN (neighbor_description,
6404 neighbor_description_cmd,
6405 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6406 NEIGHBOR_STR
6407 NEIGHBOR_ADDR_STR2
6408 "Neighbor specific description\n"
6409 "Up to 80 characters describing this neighbor\n")
718e3744 6410{
d62a17ae 6411 int idx_peer = 1;
6412 int idx_line = 3;
28c6e247 6413 struct peer *peer;
d62a17ae 6414 char *str;
718e3744 6415
28c6e247
IR
6416 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6417 if (!peer)
d62a17ae 6418 return CMD_WARNING_CONFIG_FAILED;
718e3744 6419
d62a17ae 6420 str = argv_concat(argv, argc, idx_line);
718e3744 6421
28c6e247 6422 peer_description_set(peer, str);
718e3744 6423
d62a17ae 6424 XFREE(MTYPE_TMP, str);
718e3744 6425
28c6e247 6426 return CMD_SUCCESS;
718e3744 6427}
6428
28c6e247
IR
6429DEFUN (no_neighbor_description,
6430 no_neighbor_description_cmd,
6431 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6432 NO_STR
6433 NEIGHBOR_STR
6434 NEIGHBOR_ADDR_STR2
6435 "Neighbor specific description\n")
718e3744 6436{
d62a17ae 6437 int idx_peer = 2;
28c6e247 6438 struct peer *peer;
f4b8ec07 6439
28c6e247
IR
6440 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6441 if (!peer)
d62a17ae 6442 return CMD_WARNING_CONFIG_FAILED;
718e3744 6443
28c6e247 6444 peer_description_unset(peer);
718e3744 6445
28c6e247 6446 return CMD_SUCCESS;
718e3744 6447}
6448
1d80f243 6449ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
6450 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6451 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6452 "Neighbor specific description\n"
6453 "Up to 80 characters describing this neighbor\n")
6b0655a2 6454
28c6e247
IR
6455/* Neighbor update-source. */
6456static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6457 const char *source_str)
6458{
6459 struct peer *peer;
6460 struct prefix p;
6461 union sockunion su;
6462
6463 peer = peer_and_group_lookup_vty(vty, peer_str);
6464 if (!peer)
6465 return CMD_WARNING_CONFIG_FAILED;
6466
6467 if (peer->conf_if)
6468 return CMD_WARNING;
6469
6470 if (source_str) {
6471 if (str2sockunion(source_str, &su) == 0)
6472 peer_update_source_addr_set(peer, &su);
6473 else {
6474 if (str2prefix(source_str, &p)) {
6475 vty_out(vty,
6476 "%% Invalid update-source, remove prefix length \n");
6477 return CMD_WARNING_CONFIG_FAILED;
6478 } else
6479 peer_update_source_if_set(peer, source_str);
6480 }
6481 } else
6482 peer_update_source_unset(peer);
6483
6484 return CMD_SUCCESS;
6485}
6486
d62a17ae 6487#define BGP_UPDATE_SOURCE_HELP_STR \
6488 "IPv4 address\n" \
6489 "IPv6 address\n" \
6490 "Interface name (requires zebra to be running)\n"
369688c0 6491
28c6e247
IR
6492DEFUN (neighbor_update_source,
6493 neighbor_update_source_cmd,
6494 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6495 NEIGHBOR_STR
6496 NEIGHBOR_ADDR_STR2
6497 "Source of routing updates\n"
6498 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6499{
d62a17ae 6500 int idx_peer = 1;
6501 int idx_peer_2 = 3;
28c6e247 6502 return peer_update_source_vty(vty, argv[idx_peer]->arg,
d62a17ae 6503 argv[idx_peer_2]->arg);
718e3744 6504}
6505
28c6e247
IR
6506DEFUN (no_neighbor_update_source,
6507 no_neighbor_update_source_cmd,
6508 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6509 NO_STR
6510 NEIGHBOR_STR
6511 NEIGHBOR_ADDR_STR2
6512 "Source of routing updates\n"
6513 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6514{
d62a17ae 6515 int idx_peer = 2;
28c6e247 6516 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6517}
6b0655a2 6518
d62a17ae 6519static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6520 afi_t afi, safi_t safi,
6521 const char *rmap, int set)
718e3744 6522{
d62a17ae 6523 int ret;
6524 struct peer *peer;
80912664 6525 struct route_map *route_map = NULL;
718e3744 6526
d62a17ae 6527 peer = peer_and_group_lookup_vty(vty, peer_str);
6528 if (!peer)
6529 return CMD_WARNING_CONFIG_FAILED;
718e3744 6530
1de27621 6531 if (set) {
80912664
DS
6532 if (rmap)
6533 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
6534 ret = peer_default_originate_set(peer, afi, safi,
6535 rmap, route_map);
6536 } else
d62a17ae 6537 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 6538
d62a17ae 6539 return bgp_vty_return(vty, ret);
718e3744 6540}
6541
6542/* neighbor default-originate. */
6543DEFUN (neighbor_default_originate,
6544 neighbor_default_originate_cmd,
9ccf14f7 6545 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 6546 NEIGHBOR_STR
6547 NEIGHBOR_ADDR_STR2
6548 "Originate default route to this neighbor\n")
6549{
d62a17ae 6550 int idx_peer = 1;
6551 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6552 bgp_node_afi(vty),
6553 bgp_node_safi(vty), NULL, 1);
718e3744 6554}
6555
d62a17ae 6556ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6557 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6558 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6559 "Originate default route to this neighbor\n")
596c17ba 6560
718e3744 6561DEFUN (neighbor_default_originate_rmap,
6562 neighbor_default_originate_rmap_cmd,
9ccf14f7 6563 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 6564 NEIGHBOR_STR
6565 NEIGHBOR_ADDR_STR2
6566 "Originate default route to this neighbor\n"
6567 "Route-map to specify criteria to originate default\n"
6568 "route-map name\n")
6569{
d62a17ae 6570 int idx_peer = 1;
6571 int idx_word = 4;
6572 return peer_default_originate_set_vty(
6573 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6574 argv[idx_word]->arg, 1);
718e3744 6575}
6576
d62a17ae 6577ALIAS_HIDDEN(
6578 neighbor_default_originate_rmap,
6579 neighbor_default_originate_rmap_hidden_cmd,
6580 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6581 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6582 "Originate default route to this neighbor\n"
6583 "Route-map to specify criteria to originate default\n"
6584 "route-map name\n")
596c17ba 6585
718e3744 6586DEFUN (no_neighbor_default_originate,
6587 no_neighbor_default_originate_cmd,
a636c635 6588 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 6589 NO_STR
6590 NEIGHBOR_STR
6591 NEIGHBOR_ADDR_STR2
a636c635
DW
6592 "Originate default route to this neighbor\n"
6593 "Route-map to specify criteria to originate default\n"
6594 "route-map name\n")
718e3744 6595{
d62a17ae 6596 int idx_peer = 2;
6597 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6598 bgp_node_afi(vty),
6599 bgp_node_safi(vty), NULL, 0);
718e3744 6600}
6601
d62a17ae 6602ALIAS_HIDDEN(
6603 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6604 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6605 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6606 "Originate default route to this neighbor\n"
6607 "Route-map to specify criteria to originate default\n"
6608 "route-map name\n")
596c17ba 6609
6b0655a2 6610
28c6e247
IR
6611/* Set neighbor's BGP port. */
6612static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6613 const char *port_str)
718e3744 6614{
28c6e247
IR
6615 struct peer *peer;
6616 uint16_t port;
6617 struct servent *sp;
6618
6619 peer = peer_lookup_vty(vty, ip_str);
6620 if (!peer)
6621 return CMD_WARNING_CONFIG_FAILED;
6622
6623 if (!port_str) {
6624 sp = getservbyname("bgp", "tcp");
6625 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6626 } else {
6627 port = strtoul(port_str, NULL, 10);
6628 }
718e3744 6629
28c6e247 6630 peer_port_set(peer, port);
718e3744 6631
28c6e247
IR
6632 return CMD_SUCCESS;
6633}
f4b8ec07 6634
28c6e247
IR
6635/* Set specified peer's BGP port. */
6636DEFUN (neighbor_port,
6637 neighbor_port_cmd,
6638 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
6639 NEIGHBOR_STR
6640 NEIGHBOR_ADDR_STR
6641 "Neighbor's BGP port\n"
6642 "TCP port number\n")
6643{
6644 int idx_ip = 1;
6645 int idx_number = 3;
6646 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6647 argv[idx_number]->arg);
f4b8ec07 6648}
6b0655a2 6649
28c6e247
IR
6650DEFUN (no_neighbor_port,
6651 no_neighbor_port_cmd,
6652 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
6653 NO_STR
6654 NEIGHBOR_STR
6655 NEIGHBOR_ADDR_STR
6656 "Neighbor's BGP port\n"
6657 "TCP port number\n")
718e3744 6658{
f4b8ec07 6659 int idx_ip = 2;
28c6e247
IR
6660 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6661}
6662
6663
6664/* neighbor weight. */
6665static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6666 safi_t safi, const char *weight_str)
6667{
6668 int ret;
6669 struct peer *peer;
6670 unsigned long weight;
718e3744 6671
28c6e247
IR
6672 peer = peer_and_group_lookup_vty(vty, ip_str);
6673 if (!peer)
6674 return CMD_WARNING_CONFIG_FAILED;
718e3744 6675
28c6e247 6676 weight = strtoul(weight_str, NULL, 10);
718e3744 6677
28c6e247
IR
6678 ret = peer_weight_set(peer, afi, safi, weight);
6679 return bgp_vty_return(vty, ret);
718e3744 6680}
6681
28c6e247
IR
6682static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6683 safi_t safi)
718e3744 6684{
28c6e247
IR
6685 int ret;
6686 struct peer *peer;
f4b8ec07 6687
28c6e247
IR
6688 peer = peer_and_group_lookup_vty(vty, ip_str);
6689 if (!peer)
d62a17ae 6690 return CMD_WARNING_CONFIG_FAILED;
718e3744 6691
28c6e247
IR
6692 ret = peer_weight_unset(peer, afi, safi);
6693 return bgp_vty_return(vty, ret);
6694}
f4b8ec07 6695
28c6e247
IR
6696DEFUN (neighbor_weight,
6697 neighbor_weight_cmd,
6698 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6699 NEIGHBOR_STR
6700 NEIGHBOR_ADDR_STR2
6701 "Set default weight for routes from this neighbor\n"
6702 "default weight\n")
6703{
6704 int idx_peer = 1;
6705 int idx_number = 3;
6706 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6707 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 6708}
6709
d62a17ae 6710ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6711 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6712 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6713 "Set default weight for routes from this neighbor\n"
6714 "default weight\n")
596c17ba 6715
28c6e247
IR
6716DEFUN (no_neighbor_weight,
6717 no_neighbor_weight_cmd,
6718 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6719 NO_STR
6720 NEIGHBOR_STR
6721 NEIGHBOR_ADDR_STR2
6722 "Set default weight for routes from this neighbor\n"
6723 "default weight\n")
718e3744 6724{
d62a17ae 6725 int idx_peer = 2;
28c6e247
IR
6726 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6727 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 6728}
6729
d62a17ae 6730ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6731 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6732 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6733 "Set default weight for routes from this neighbor\n"
6734 "default weight\n")
596c17ba 6735
6b0655a2 6736
718e3744 6737/* Override capability negotiation. */
c36bc05f
IR
6738DEFUN (neighbor_override_capability,
6739 neighbor_override_capability_cmd,
6740 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6741 NEIGHBOR_STR
6742 NEIGHBOR_ADDR_STR2
6743 "Override capability negotiation result\n")
718e3744 6744{
d62a17ae 6745 int idx_peer = 1;
c36bc05f
IR
6746 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6747 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6748}
6749
c36bc05f
IR
6750DEFUN (no_neighbor_override_capability,
6751 no_neighbor_override_capability_cmd,
6752 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6753 NO_STR
6754 NEIGHBOR_STR
6755 NEIGHBOR_ADDR_STR2
6756 "Override capability negotiation result\n")
718e3744 6757{
d62a17ae 6758 int idx_peer = 2;
c36bc05f
IR
6759 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6760 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6761}
6b0655a2 6762
c36bc05f
IR
6763DEFUN (neighbor_strict_capability,
6764 neighbor_strict_capability_cmd,
6765 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6766 NEIGHBOR_STR
6767 NEIGHBOR_ADDR_STR2
6768 "Strict capability negotiation match\n")
718e3744 6769{
9fb964de
PM
6770 int idx_peer = 1;
6771
c36bc05f
IR
6772 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6773 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6774}
6775
c36bc05f
IR
6776DEFUN (no_neighbor_strict_capability,
6777 no_neighbor_strict_capability_cmd,
6778 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6779 NO_STR
6780 NEIGHBOR_STR
6781 NEIGHBOR_ADDR_STR2
6782 "Strict capability negotiation match\n")
718e3744 6783{
9fb964de 6784 int idx_peer = 2;
8611c7f3 6785
c36bc05f
IR
6786 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6787 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6788}
6b0655a2 6789
28c6e247
IR
6790static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6791 const char *keep_str, const char *hold_str)
718e3744 6792{
28c6e247
IR
6793 int ret;
6794 struct peer *peer;
6795 uint32_t keepalive;
6796 uint32_t holdtime;
718e3744 6797
28c6e247
IR
6798 peer = peer_and_group_lookup_vty(vty, ip_str);
6799 if (!peer)
d62a17ae 6800 return CMD_WARNING_CONFIG_FAILED;
718e3744 6801
28c6e247
IR
6802 keepalive = strtoul(keep_str, NULL, 10);
6803 holdtime = strtoul(hold_str, NULL, 10);
718e3744 6804
28c6e247 6805 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 6806
28c6e247 6807 return bgp_vty_return(vty, ret);
718e3744 6808}
6b0655a2 6809
28c6e247 6810static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6811{
28c6e247
IR
6812 int ret;
6813 struct peer *peer;
718e3744 6814
28c6e247
IR
6815 peer = peer_and_group_lookup_vty(vty, ip_str);
6816 if (!peer)
d62a17ae 6817 return CMD_WARNING_CONFIG_FAILED;
718e3744 6818
28c6e247 6819 ret = peer_timers_unset(peer);
718e3744 6820
28c6e247 6821 return bgp_vty_return(vty, ret);
718e3744 6822}
6b0655a2 6823
28c6e247
IR
6824DEFUN (neighbor_timers,
6825 neighbor_timers_cmd,
6826 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
6827 NEIGHBOR_STR
6828 NEIGHBOR_ADDR_STR2
6829 "BGP per neighbor timers\n"
6830 "Keepalive interval\n"
6831 "Holdtime\n")
718e3744 6832{
f4b8ec07 6833 int idx_peer = 1;
28c6e247
IR
6834 int idx_number = 3;
6835 int idx_number_2 = 4;
6836 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6837 argv[idx_number]->arg,
6838 argv[idx_number_2]->arg);
6839}
6840
6841DEFUN (no_neighbor_timers,
6842 no_neighbor_timers_cmd,
6843 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
6844 NO_STR
6845 NEIGHBOR_STR
6846 NEIGHBOR_ADDR_STR2
6847 "BGP per neighbor timers\n"
6848 "Keepalive interval\n"
6849 "Holdtime\n")
6850{
6851 int idx_peer = 2;
6852 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
6853}
6854
6855
6856static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6857 const char *time_str)
6858{
6859 int ret;
6860 struct peer *peer;
6861 uint32_t connect;
718e3744 6862
28c6e247
IR
6863 peer = peer_and_group_lookup_vty(vty, ip_str);
6864 if (!peer)
d62a17ae 6865 return CMD_WARNING_CONFIG_FAILED;
718e3744 6866
28c6e247
IR
6867 connect = strtoul(time_str, NULL, 10);
6868
6869 ret = peer_timers_connect_set(peer, connect);
718e3744 6870
28c6e247 6871 return bgp_vty_return(vty, ret);
718e3744 6872}
6873
28c6e247 6874static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6875{
28c6e247
IR
6876 int ret;
6877 struct peer *peer;
718e3744 6878
28c6e247
IR
6879 peer = peer_and_group_lookup_vty(vty, ip_str);
6880 if (!peer)
d62a17ae 6881 return CMD_WARNING_CONFIG_FAILED;
718e3744 6882
28c6e247
IR
6883 ret = peer_timers_connect_unset(peer);
6884
6885 return bgp_vty_return(vty, ret);
6886}
6887
6888DEFUN (neighbor_timers_connect,
6889 neighbor_timers_connect_cmd,
6890 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
6891 NEIGHBOR_STR
6892 NEIGHBOR_ADDR_STR2
6893 "BGP per neighbor timers\n"
6894 "BGP connect timer\n"
6895 "Connect timer\n")
6896{
6897 int idx_peer = 1;
6898 int idx_number = 4;
6899 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6900 argv[idx_number]->arg);
6901}
718e3744 6902
28c6e247
IR
6903DEFUN (no_neighbor_timers_connect,
6904 no_neighbor_timers_connect_cmd,
6905 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
6906 NO_STR
6907 NEIGHBOR_STR
6908 NEIGHBOR_ADDR_STR2
6909 "BGP per neighbor timers\n"
6910 "BGP connect timer\n"
6911 "Connect timer\n")
6912{
6913 int idx_peer = 2;
6914 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6915}
6916
d43114f3
DS
6917DEFPY (neighbor_timers_delayopen,
6918 neighbor_timers_delayopen_cmd,
6919 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
6920 NEIGHBOR_STR
6921 NEIGHBOR_ADDR_STR2
6922 "BGP per neighbor timers\n"
6923 "RFC 4271 DelayOpenTimer\n"
6924 "DelayOpenTime timer interval\n")
6925{
6926 struct peer *peer;
6927
6928 peer = peer_and_group_lookup_vty(vty, neighbor);
6929 if (!peer)
6930 return CMD_WARNING_CONFIG_FAILED;
6931
6932 if (!interval) {
6933 if (peer_timers_delayopen_unset(peer))
6934 return CMD_WARNING_CONFIG_FAILED;
6935 } else {
6936 if (peer_timers_delayopen_set(peer, interval))
6937 return CMD_WARNING_CONFIG_FAILED;
6938 }
6939
6940 return CMD_SUCCESS;
6941}
6942
6943DEFPY (no_neighbor_timers_delayopen,
6944 no_neighbor_timers_delayopen_cmd,
6945 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
6946 NO_STR
6947 NEIGHBOR_STR
6948 NEIGHBOR_ADDR_STR2
6949 "BGP per neighbor timers\n"
6950 "RFC 4271 DelayOpenTimer\n"
6951 "DelayOpenTime timer interval\n")
6952{
6953 struct peer *peer;
6954
6955 peer = peer_and_group_lookup_vty(vty, neighbor);
6956 if (!peer)
6957 return CMD_WARNING_CONFIG_FAILED;
6958
6959 if (peer_timers_delayopen_unset(peer))
6960 return CMD_WARNING_CONFIG_FAILED;
6961
6962 return CMD_SUCCESS;
6963}
6964
28c6e247
IR
6965static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
6966 const char *time_str, int set)
718e3744 6967{
28c6e247
IR
6968 int ret;
6969 struct peer *peer;
6970 uint32_t routeadv = 0;
718e3744 6971
28c6e247
IR
6972 peer = peer_and_group_lookup_vty(vty, ip_str);
6973 if (!peer)
d62a17ae 6974 return CMD_WARNING_CONFIG_FAILED;
718e3744 6975
28c6e247
IR
6976 if (time_str)
6977 routeadv = strtoul(time_str, NULL, 10);
6978
6979 if (set)
6980 ret = peer_advertise_interval_set(peer, routeadv);
6981 else
6982 ret = peer_advertise_interval_unset(peer);
718e3744 6983
28c6e247 6984 return bgp_vty_return(vty, ret);
718e3744 6985}
6986
28c6e247
IR
6987DEFUN (neighbor_advertise_interval,
6988 neighbor_advertise_interval_cmd,
6989 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
6990 NEIGHBOR_STR
6991 NEIGHBOR_ADDR_STR2
6992 "Minimum interval between sending BGP routing updates\n"
6993 "time in seconds\n")
718e3744 6994{
28c6e247
IR
6995 int idx_peer = 1;
6996 int idx_number = 3;
6997 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
6998 argv[idx_number]->arg, 1);
6999}
f4b8ec07 7000
28c6e247
IR
7001DEFUN (no_neighbor_advertise_interval,
7002 no_neighbor_advertise_interval_cmd,
7003 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7004 NO_STR
7005 NEIGHBOR_STR
7006 NEIGHBOR_ADDR_STR2
7007 "Minimum interval between sending BGP routing updates\n"
7008 "time in seconds\n")
7009{
7010 int idx_peer = 2;
7011 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 7012}
7013
6b0655a2 7014
518f0eb1
DS
7015/* Time to wait before processing route-map updates */
7016DEFUN (bgp_set_route_map_delay_timer,
7017 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7018 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7019 SET_STR
7020 "BGP route-map delay timer\n"
7021 "Time in secs to wait before processing route-map changes\n"
f414725f 7022 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7023{
d62a17ae 7024 int idx_number = 3;
d7c0a89a 7025 uint32_t rmap_delay_timer;
d62a17ae 7026
7027 if (argv[idx_number]->arg) {
7028 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7029 bm->rmap_update_timer = rmap_delay_timer;
7030
7031 /* if the dynamic update handling is being disabled, and a timer
7032 * is
7033 * running, stop the timer and act as if the timer has already
7034 * fired.
7035 */
7036 if (!rmap_delay_timer && bm->t_rmap_update) {
7037 BGP_TIMER_OFF(bm->t_rmap_update);
7038 thread_execute(bm->master, bgp_route_map_update_timer,
7039 NULL, 0);
7040 }
7041 return CMD_SUCCESS;
7042 } else {
7043 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7044 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7045 }
518f0eb1
DS
7046}
7047
7048DEFUN (no_bgp_set_route_map_delay_timer,
7049 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7050 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7051 NO_STR
3a2d747c 7052 BGP_STR
518f0eb1 7053 "Default BGP route-map delay timer\n"
8334fd5a
DW
7054 "Reset to default time to wait for processing route-map changes\n"
7055 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7056{
518f0eb1 7057
d62a17ae 7058 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7059
d62a17ae 7060 return CMD_SUCCESS;
518f0eb1
DS
7061}
7062
28c6e247
IR
7063/* neighbor interface */
7064static int peer_interface_vty(struct vty *vty, const char *ip_str,
7065 const char *str)
718e3744 7066{
28c6e247 7067 struct peer *peer;
718e3744 7068
28c6e247
IR
7069 peer = peer_lookup_vty(vty, ip_str);
7070 if (!peer || peer->conf_if) {
7071 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7072 return CMD_WARNING_CONFIG_FAILED;
7073 }
718e3744 7074
28c6e247
IR
7075 if (str)
7076 peer_interface_set(peer, str);
7077 else
7078 peer_interface_unset(peer);
718e3744 7079
28c6e247 7080 return CMD_SUCCESS;
718e3744 7081}
7082
28c6e247
IR
7083DEFUN (neighbor_interface,
7084 neighbor_interface_cmd,
7085 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7086 NEIGHBOR_STR
7087 NEIGHBOR_ADDR_STR
7088 "Interface\n"
7089 "Interface name\n")
718e3744 7090{
28c6e247
IR
7091 int idx_ip = 1;
7092 int idx_word = 3;
294d8425 7093
28c6e247
IR
7094 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7095}
f4b8ec07 7096
28c6e247
IR
7097DEFUN (no_neighbor_interface,
7098 no_neighbor_interface_cmd,
294d8425 7099 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
28c6e247
IR
7100 NO_STR
7101 NEIGHBOR_STR
294d8425 7102 NEIGHBOR_ADDR_STR
28c6e247
IR
7103 "Interface\n"
7104 "Interface name\n")
7105{
7106 int idx_peer = 2;
294d8425 7107
28c6e247 7108 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 7109}
6b0655a2 7110
718e3744 7111DEFUN (neighbor_distribute_list,
7112 neighbor_distribute_list_cmd,
c60dec36 7113 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7114 NEIGHBOR_STR
7115 NEIGHBOR_ADDR_STR2
7116 "Filter updates to/from this neighbor\n"
718e3744 7117 "IP Access-list name\n"
7118 "Filter incoming updates\n"
7119 "Filter outgoing updates\n")
7120{
d62a17ae 7121 int idx_peer = 1;
7122 int idx_acl = 3;
7123 int direct, ret;
7124 struct peer *peer;
a8206004 7125
d62a17ae 7126 const char *pstr = argv[idx_peer]->arg;
7127 const char *acl = argv[idx_acl]->arg;
7128 const char *inout = argv[argc - 1]->text;
a8206004 7129
d62a17ae 7130 peer = peer_and_group_lookup_vty(vty, pstr);
7131 if (!peer)
7132 return CMD_WARNING_CONFIG_FAILED;
a8206004 7133
d62a17ae 7134 /* Check filter direction. */
7135 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7136 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7137 direct, acl);
a8206004 7138
d62a17ae 7139 return bgp_vty_return(vty, ret);
718e3744 7140}
7141
d62a17ae 7142ALIAS_HIDDEN(
7143 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
c60dec36 7144 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7145 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7146 "Filter updates to/from this neighbor\n"
d62a17ae 7147 "IP Access-list name\n"
7148 "Filter incoming updates\n"
7149 "Filter outgoing updates\n")
596c17ba 7150
718e3744 7151DEFUN (no_neighbor_distribute_list,
7152 no_neighbor_distribute_list_cmd,
c60dec36 7153 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7154 NO_STR
7155 NEIGHBOR_STR
7156 NEIGHBOR_ADDR_STR2
7157 "Filter updates to/from this neighbor\n"
718e3744 7158 "IP Access-list name\n"
7159 "Filter incoming updates\n"
7160 "Filter outgoing updates\n")
7161{
d62a17ae 7162 int idx_peer = 2;
7163 int direct, ret;
7164 struct peer *peer;
a8206004 7165
d62a17ae 7166 const char *pstr = argv[idx_peer]->arg;
7167 const char *inout = argv[argc - 1]->text;
a8206004 7168
d62a17ae 7169 peer = peer_and_group_lookup_vty(vty, pstr);
7170 if (!peer)
7171 return CMD_WARNING_CONFIG_FAILED;
a8206004 7172
d62a17ae 7173 /* Check filter direction. */
7174 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7175 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7176 direct);
a8206004 7177
d62a17ae 7178 return bgp_vty_return(vty, ret);
718e3744 7179}
6b0655a2 7180
d62a17ae 7181ALIAS_HIDDEN(
7182 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
c60dec36 7183 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7184 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7185 "Filter updates to/from this neighbor\n"
d62a17ae 7186 "IP Access-list name\n"
7187 "Filter incoming updates\n"
7188 "Filter outgoing updates\n")
596c17ba 7189
718e3744 7190/* Set prefix list to the peer. */
642ef664
IR
7191static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7192 afi_t afi, safi_t safi,
7193 const char *name_str,
7194 const char *direct_str)
718e3744 7195{
642ef664
IR
7196 int ret;
7197 int direct = FILTER_IN;
7198 struct peer *peer;
718e3744 7199
642ef664
IR
7200 peer = peer_and_group_lookup_vty(vty, ip_str);
7201 if (!peer)
d62a17ae 7202 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7203
642ef664
IR
7204 /* Check filter direction. */
7205 if (strncmp(direct_str, "i", 1) == 0)
7206 direct = FILTER_IN;
7207 else if (strncmp(direct_str, "o", 1) == 0)
7208 direct = FILTER_OUT;
718e3744 7209
642ef664 7210 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 7211
642ef664
IR
7212 return bgp_vty_return(vty, ret);
7213}
7214
7215static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7216 afi_t afi, safi_t safi,
7217 const char *direct_str)
7218{
7219 int ret;
7220 struct peer *peer;
7221 int direct = FILTER_IN;
7222
7223 peer = peer_and_group_lookup_vty(vty, ip_str);
7224 if (!peer)
7225 return CMD_WARNING_CONFIG_FAILED;
7226
7227 /* Check filter direction. */
7228 if (strncmp(direct_str, "i", 1) == 0)
7229 direct = FILTER_IN;
7230 else if (strncmp(direct_str, "o", 1) == 0)
7231 direct = FILTER_OUT;
7232
7233 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7234
7235 return bgp_vty_return(vty, ret);
7236}
7237
7238DEFUN (neighbor_prefix_list,
7239 neighbor_prefix_list_cmd,
7240 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7241 NEIGHBOR_STR
7242 NEIGHBOR_ADDR_STR2
7243 "Filter updates to/from this neighbor\n"
7244 "Name of a prefix list\n"
7245 "Filter incoming updates\n"
7246 "Filter outgoing updates\n")
7247{
7248 int idx_peer = 1;
7249 int idx_word = 3;
7250 int idx_in_out = 4;
7251 return peer_prefix_list_set_vty(
7252 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7253 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7254}
7255
d62a17ae 7256ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7257 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7258 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7259 "Filter updates to/from this neighbor\n"
7260 "Name of a prefix list\n"
7261 "Filter incoming updates\n"
7262 "Filter outgoing updates\n")
596c17ba 7263
642ef664
IR
7264DEFUN (no_neighbor_prefix_list,
7265 no_neighbor_prefix_list_cmd,
7266 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7267 NO_STR
7268 NEIGHBOR_STR
7269 NEIGHBOR_ADDR_STR2
7270 "Filter updates to/from this neighbor\n"
7271 "Name of a prefix list\n"
7272 "Filter incoming updates\n"
7273 "Filter outgoing updates\n")
7274{
7275 int idx_peer = 2;
7276 int idx_in_out = 5;
7277 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7278 bgp_node_afi(vty), bgp_node_safi(vty),
7279 argv[idx_in_out]->arg);
7280}
7281
7282ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7283 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7284 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7285 "Filter updates to/from this neighbor\n"
7286 "Name of a prefix list\n"
7287 "Filter incoming updates\n"
7288 "Filter outgoing updates\n")
7289
d62a17ae 7290static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7291 safi_t safi, const char *name_str,
7292 const char *direct_str)
718e3744 7293{
d62a17ae 7294 int ret;
7295 struct peer *peer;
7296 int direct = FILTER_IN;
718e3744 7297
d62a17ae 7298 peer = peer_and_group_lookup_vty(vty, ip_str);
7299 if (!peer)
7300 return CMD_WARNING_CONFIG_FAILED;
718e3744 7301
d62a17ae 7302 /* Check filter direction. */
7303 if (strncmp(direct_str, "i", 1) == 0)
7304 direct = FILTER_IN;
7305 else if (strncmp(direct_str, "o", 1) == 0)
7306 direct = FILTER_OUT;
718e3744 7307
d62a17ae 7308 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7309
d62a17ae 7310 return bgp_vty_return(vty, ret);
718e3744 7311}
7312
d62a17ae 7313static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7314 safi_t safi, const char *direct_str)
718e3744 7315{
d62a17ae 7316 int ret;
7317 struct peer *peer;
7318 int direct = FILTER_IN;
718e3744 7319
d62a17ae 7320 peer = peer_and_group_lookup_vty(vty, ip_str);
7321 if (!peer)
7322 return CMD_WARNING_CONFIG_FAILED;
718e3744 7323
d62a17ae 7324 /* Check filter direction. */
7325 if (strncmp(direct_str, "i", 1) == 0)
7326 direct = FILTER_IN;
7327 else if (strncmp(direct_str, "o", 1) == 0)
7328 direct = FILTER_OUT;
718e3744 7329
d62a17ae 7330 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7331
d62a17ae 7332 return bgp_vty_return(vty, ret);
718e3744 7333}
7334
7335DEFUN (neighbor_filter_list,
7336 neighbor_filter_list_cmd,
de71d43e 7337 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7338 NEIGHBOR_STR
7339 NEIGHBOR_ADDR_STR2
7340 "Establish BGP filters\n"
7341 "AS path access-list name\n"
7342 "Filter incoming routes\n"
7343 "Filter outgoing routes\n")
7344{
d62a17ae 7345 int idx_peer = 1;
7346 int idx_word = 3;
7347 int idx_in_out = 4;
7348 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7349 bgp_node_safi(vty), argv[idx_word]->arg,
7350 argv[idx_in_out]->arg);
718e3744 7351}
7352
d62a17ae 7353ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
de71d43e 7354 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7355 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7356 "Establish BGP filters\n"
7357 "AS path access-list name\n"
7358 "Filter incoming routes\n"
7359 "Filter outgoing routes\n")
596c17ba 7360
718e3744 7361DEFUN (no_neighbor_filter_list,
7362 no_neighbor_filter_list_cmd,
de71d43e 7363 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7364 NO_STR
7365 NEIGHBOR_STR
7366 NEIGHBOR_ADDR_STR2
7367 "Establish BGP filters\n"
7368 "AS path access-list name\n"
7369 "Filter incoming routes\n"
7370 "Filter outgoing routes\n")
7371{
d62a17ae 7372 int idx_peer = 2;
7373 int idx_in_out = 5;
7374 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7375 bgp_node_afi(vty), bgp_node_safi(vty),
7376 argv[idx_in_out]->arg);
718e3744 7377}
6b0655a2 7378
d62a17ae 7379ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
de71d43e 7380 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7381 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7382 "Establish BGP filters\n"
7383 "AS path access-list name\n"
7384 "Filter incoming routes\n"
7385 "Filter outgoing routes\n")
596c17ba 7386
7f7940e6
MK
7387/* Set advertise-map to the peer. */
7388static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7389 afi_t afi, safi_t safi,
cf2ad4d8
MK
7390 const char *advertise_str,
7391 const char *condition_str, bool condition,
7392 bool set)
7f7940e6
MK
7393{
7394 int ret = CMD_WARNING_CONFIG_FAILED;
7395 struct peer *peer;
7396 struct route_map *advertise_map;
7397 struct route_map *condition_map;
7398
7399 peer = peer_and_group_lookup_vty(vty, ip_str);
7400 if (!peer)
7401 return ret;
7402
7403 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7404 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7405
cf2ad4d8
MK
7406 if (set)
7407 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7408 advertise_map, condition_str,
7409 condition_map, condition);
7410 else
7411 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7412 advertise_map, condition_str,
7413 condition_map, condition);
7f7940e6
MK
7414
7415 return bgp_vty_return(vty, ret);
7416}
7417
389e4f92
QY
7418DEFPY (bgp_condadv_period,
7419 bgp_condadv_period_cmd,
7420 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7421 NO_STR
7422 BGP_STR
7423 "Conditional advertisement settings\n"
7424 "Set period to rescan BGP table to check if condition is met\n"
7425 "Period between BGP table scans, in seconds; default 60\n")
7426{
7427 VTY_DECLVAR_CONTEXT(bgp, bgp);
7428
7429 bgp->condition_check_period =
7430 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7431
7432 return CMD_SUCCESS;
7433}
7434
cf2ad4d8 7435DEFPY (neighbor_advertise_map,
7f7940e6 7436 neighbor_advertise_map_cmd,
52b84062 7437 "[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 7438 NO_STR
7f7940e6
MK
7439 NEIGHBOR_STR
7440 NEIGHBOR_ADDR_STR2
7441 "Route-map to conditionally advertise routes\n"
7442 "Name of advertise map\n"
7443 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7444 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7445 "Name of the exist or non exist map\n")
7f7940e6 7446{
7f7940e6
MK
7447 bool condition = CONDITION_EXIST;
7448
52b84062 7449 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7450 condition = CONDITION_NON_EXIST;
7451
52b84062
MK
7452 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7453 bgp_node_safi(vty), advertise_str,
7454 condition_str, condition, !no);
7f7940e6
MK
7455}
7456
7457ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
52b84062 7458 "[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
7459 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7460 "Route-map to conditionally advertise routes\n"
7461 "Name of advertise map\n"
7462 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7463 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7464 "Name of the exist or non exist map\n")
7f7940e6 7465
718e3744 7466/* Set route-map to the peer. */
0ea8d871
IR
7467static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7468 afi_t afi, safi_t safi, const char *name_str,
7469 const char *direct_str)
718e3744 7470{
0ea8d871
IR
7471 int ret;
7472 struct peer *peer;
7473 int direct = RMAP_IN;
7474 struct route_map *route_map;
718e3744 7475
0ea8d871
IR
7476 peer = peer_and_group_lookup_vty(vty, ip_str);
7477 if (!peer)
d62a17ae 7478 return CMD_WARNING_CONFIG_FAILED;
718e3744 7479
0ea8d871
IR
7480 /* Check filter direction. */
7481 if (strncmp(direct_str, "in", 2) == 0)
7482 direct = RMAP_IN;
7483 else if (strncmp(direct_str, "o", 1) == 0)
7484 direct = RMAP_OUT;
718e3744 7485
0ea8d871
IR
7486 route_map = route_map_lookup_warn_noexist(vty, name_str);
7487 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7488
0ea8d871
IR
7489 return bgp_vty_return(vty, ret);
7490}
7491
7492static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7493 afi_t afi, safi_t safi,
7494 const char *direct_str)
7495{
7496 int ret;
7497 struct peer *peer;
7498 int direct = RMAP_IN;
7499
7500 peer = peer_and_group_lookup_vty(vty, ip_str);
7501 if (!peer)
7502 return CMD_WARNING_CONFIG_FAILED;
7503
7504 /* Check filter direction. */
7505 if (strncmp(direct_str, "in", 2) == 0)
7506 direct = RMAP_IN;
7507 else if (strncmp(direct_str, "o", 1) == 0)
7508 direct = RMAP_OUT;
7509
7510 ret = peer_route_map_unset(peer, afi, safi, direct);
7511
7512 return bgp_vty_return(vty, ret);
7513}
7514
7515DEFUN (neighbor_route_map,
7516 neighbor_route_map_cmd,
7517 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7518 NEIGHBOR_STR
7519 NEIGHBOR_ADDR_STR2
7520 "Apply route map to neighbor\n"
7521 "Name of route map\n"
7522 "Apply map to incoming routes\n"
7523 "Apply map to outbound routes\n")
7524{
7525 int idx_peer = 1;
7526 int idx_word = 3;
7527 int idx_in_out = 4;
7528 return peer_route_map_set_vty(
7529 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7530 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7531}
7532
d6d7ed37
IR
7533ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7534 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7535 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7536 "Apply route map to neighbor\n"
7537 "Name of route map\n"
7538 "Apply map to incoming routes\n"
7539 "Apply map to outbound routes\n")
7540
0ea8d871
IR
7541DEFUN (no_neighbor_route_map,
7542 no_neighbor_route_map_cmd,
7543 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7544 NO_STR
7545 NEIGHBOR_STR
7546 NEIGHBOR_ADDR_STR2
7547 "Apply route map to neighbor\n"
7548 "Name of route map\n"
7549 "Apply map to incoming routes\n"
7550 "Apply map to outbound routes\n")
7551{
7552 int idx_peer = 2;
7553 int idx_in_out = 5;
7554 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7555 bgp_node_afi(vty), bgp_node_safi(vty),
7556 argv[idx_in_out]->arg);
7557}
7558
7559ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
d6d7ed37
IR
7560 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7561 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7562 "Apply route map to neighbor\n"
7563 "Name of route map\n"
7564 "Apply map to incoming routes\n"
7565 "Apply map to outbound routes\n")
7566
718e3744 7567/* Set unsuppress-map to the peer. */
d62a17ae 7568static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7569 afi_t afi, safi_t safi,
7570 const char *name_str)
718e3744 7571{
d62a17ae 7572 int ret;
7573 struct peer *peer;
1de27621 7574 struct route_map *route_map;
718e3744 7575
d62a17ae 7576 peer = peer_and_group_lookup_vty(vty, ip_str);
7577 if (!peer)
7578 return CMD_WARNING_CONFIG_FAILED;
718e3744 7579
1de27621
DA
7580 route_map = route_map_lookup_warn_noexist(vty, name_str);
7581 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 7582
d62a17ae 7583 return bgp_vty_return(vty, ret);
718e3744 7584}
7585
7586/* Unset route-map from the peer. */
d62a17ae 7587static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7588 afi_t afi, safi_t safi)
718e3744 7589{
d62a17ae 7590 int ret;
7591 struct peer *peer;
718e3744 7592
d62a17ae 7593 peer = peer_and_group_lookup_vty(vty, ip_str);
7594 if (!peer)
7595 return CMD_WARNING_CONFIG_FAILED;
718e3744 7596
d62a17ae 7597 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 7598
d62a17ae 7599 return bgp_vty_return(vty, ret);
718e3744 7600}
7601
7602DEFUN (neighbor_unsuppress_map,
7603 neighbor_unsuppress_map_cmd,
9ccf14f7 7604 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7605 NEIGHBOR_STR
7606 NEIGHBOR_ADDR_STR2
7607 "Route-map to selectively unsuppress suppressed routes\n"
7608 "Name of route map\n")
7609{
d62a17ae 7610 int idx_peer = 1;
7611 int idx_word = 3;
7612 return peer_unsuppress_map_set_vty(
7613 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7614 argv[idx_word]->arg);
718e3744 7615}
7616
d62a17ae 7617ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7618 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7619 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7620 "Route-map to selectively unsuppress suppressed routes\n"
7621 "Name of route map\n")
596c17ba 7622
718e3744 7623DEFUN (no_neighbor_unsuppress_map,
7624 no_neighbor_unsuppress_map_cmd,
9ccf14f7 7625 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7626 NO_STR
7627 NEIGHBOR_STR
7628 NEIGHBOR_ADDR_STR2
7629 "Route-map to selectively unsuppress suppressed routes\n"
7630 "Name of route map\n")
7631{
d62a17ae 7632 int idx_peer = 2;
7633 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7634 bgp_node_afi(vty),
7635 bgp_node_safi(vty));
718e3744 7636}
6b0655a2 7637
d62a17ae 7638ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7639 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7640 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7641 "Route-map to selectively unsuppress suppressed routes\n"
7642 "Name of route map\n")
596c17ba 7643
7e62b792
IR
7644static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7645 afi_t afi, safi_t safi,
7646 const char *num_str,
7647 const char *threshold_str, int warning,
7648 const char *restart_str,
7649 const char *force_str)
7650{
7651 int ret;
7652 struct peer *peer;
7653 uint32_t max;
7654 uint8_t threshold;
7655 uint16_t restart;
7656
7657 peer = peer_and_group_lookup_vty(vty, ip_str);
7658 if (!peer)
7659 return CMD_WARNING_CONFIG_FAILED;
7660
7661 max = strtoul(num_str, NULL, 10);
7662 if (threshold_str)
7663 threshold = atoi(threshold_str);
7664 else
7665 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7666
7667 if (restart_str)
7668 restart = atoi(restart_str);
7669 else
7670 restart = 0;
7671
7672 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7673 restart, force_str ? true : false);
7674
7675 return bgp_vty_return(vty, ret);
7676}
7677
7678static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7679 afi_t afi, safi_t safi)
7680{
7681 int ret;
7682 struct peer *peer;
7683
7684 peer = peer_and_group_lookup_vty(vty, ip_str);
7685 if (!peer)
7686 return CMD_WARNING_CONFIG_FAILED;
7687
7688 ret = peer_maximum_prefix_unset(peer, afi, safi);
7689
7690 return bgp_vty_return(vty, ret);
7691}
7692
fde246e8 7693/* Maximum number of prefix to be sent to the neighbor. */
1d80f243
IR
7694DEFUN(neighbor_maximum_prefix_out,
7695 neighbor_maximum_prefix_out_cmd,
7696 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7697 NEIGHBOR_STR
7698 NEIGHBOR_ADDR_STR2
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
DA
7703 int idx_peer = 1;
7704 int idx_number = 3;
7e62b792
IR
7705 struct peer *peer;
7706 uint32_t max;
fde246e8
DA
7707 afi_t afi = bgp_node_afi(vty);
7708 safi_t safi = bgp_node_safi(vty);
7709
7e62b792
IR
7710 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7711 if (!peer)
fde246e8
DA
7712 return CMD_WARNING_CONFIG_FAILED;
7713
7e62b792 7714 max = strtoul(argv[idx_number]->arg, NULL, 10);
fde246e8 7715
80444d30 7716 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
fde246e8 7717
80444d30 7718 return bgp_vty_return(vty, ret);
fde246e8
DA
7719}
7720
1d80f243
IR
7721DEFUN(no_neighbor_maximum_prefix_out,
7722 no_neighbor_maximum_prefix_out_cmd,
bc03c622 7723 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
1d80f243
IR
7724 NO_STR
7725 NEIGHBOR_STR
7726 NEIGHBOR_ADDR_STR2
bc03c622
LS
7727 "Maximum number of prefixes to be sent to this peer\n"
7728 "Maximum no. of prefix limit\n")
fde246e8 7729{
80444d30 7730 int ret;
fde246e8 7731 int idx_peer = 2;
7e62b792 7732 struct peer *peer;
fde246e8
DA
7733 afi_t afi = bgp_node_afi(vty);
7734 safi_t safi = bgp_node_safi(vty);
7735
7e62b792
IR
7736 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7737 if (!peer)
fde246e8
DA
7738 return CMD_WARNING_CONFIG_FAILED;
7739
80444d30 7740 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
fde246e8 7741
80444d30 7742 return bgp_vty_return(vty, ret);
fde246e8
DA
7743}
7744
9cbd06e0
DA
7745/* Maximum number of prefix configuration. Prefix count is different
7746 for each peer configuration. So this configuration can be set for
718e3744 7747 each peer configuration. */
1d80f243
IR
7748DEFUN (neighbor_maximum_prefix,
7749 neighbor_maximum_prefix_cmd,
7750 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7751 NEIGHBOR_STR
7752 NEIGHBOR_ADDR_STR2
7753 "Maximum number of prefix accept from this peer\n"
7754 "maximum no. of prefix limit\n"
7755 "Force checking all received routes not only accepted\n")
718e3744 7756{
d62a17ae 7757 int idx_peer = 1;
7758 int idx_number = 3;
9cbd06e0 7759 int idx_force = 0;
7e62b792 7760 char *force = NULL;
9cbd06e0
DA
7761
7762 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7763 force = argv[idx_force]->arg;
9cbd06e0 7764
7e62b792
IR
7765 return peer_maximum_prefix_set_vty(
7766 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7767 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 7768}
7769
d62a17ae 7770ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7771 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 7772 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7773 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
7774 "maximum no. of prefix limit\n"
7775 "Force checking all received routes not only accepted\n")
596c17ba 7776
1d80f243
IR
7777DEFUN (neighbor_maximum_prefix_threshold,
7778 neighbor_maximum_prefix_threshold_cmd,
7779 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7780 NEIGHBOR_STR
7781 NEIGHBOR_ADDR_STR2
7782 "Maximum number of prefix accept from this peer\n"
7783 "maximum no. of prefix limit\n"
7784 "Threshold value (%) at which to generate a warning msg\n"
7785 "Force checking all received routes not only accepted\n")
e0701b79 7786{
d62a17ae 7787 int idx_peer = 1;
7788 int idx_number = 3;
7789 int idx_number_2 = 4;
9cbd06e0 7790 int idx_force = 0;
7e62b792 7791 char *force = NULL;
9cbd06e0
DA
7792
7793 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7794 force = argv[idx_force]->arg;
9cbd06e0 7795
7e62b792
IR
7796 return peer_maximum_prefix_set_vty(
7797 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7798 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 7799}
e0701b79 7800
d62a17ae 7801ALIAS_HIDDEN(
7802 neighbor_maximum_prefix_threshold,
7803 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 7804 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 7805 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7806 "Maximum number of prefix accept from this peer\n"
7807 "maximum no. of prefix limit\n"
9cbd06e0
DA
7808 "Threshold value (%) at which to generate a warning msg\n"
7809 "Force checking all received routes not only accepted\n")
596c17ba 7810
1d80f243
IR
7811DEFUN (neighbor_maximum_prefix_warning,
7812 neighbor_maximum_prefix_warning_cmd,
7813 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7814 NEIGHBOR_STR
7815 NEIGHBOR_ADDR_STR2
7816 "Maximum number of prefix accept from this peer\n"
7817 "maximum no. of prefix limit\n"
7818 "Only give warning message when limit is exceeded\n"
7819 "Force checking all received routes not only accepted\n")
718e3744 7820{
d62a17ae 7821 int idx_peer = 1;
7822 int idx_number = 3;
9cbd06e0 7823 int idx_force = 0;
7e62b792 7824 char *force = NULL;
9cbd06e0
DA
7825
7826 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7827 force = argv[idx_force]->arg;
9cbd06e0 7828
7e62b792
IR
7829 return peer_maximum_prefix_set_vty(
7830 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7831 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 7832}
7833
d62a17ae 7834ALIAS_HIDDEN(
7835 neighbor_maximum_prefix_warning,
7836 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 7837 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 7838 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7839 "Maximum number of prefix accept from this peer\n"
7840 "maximum no. of prefix limit\n"
9cbd06e0
DA
7841 "Only give warning message when limit is exceeded\n"
7842 "Force checking all received routes not only accepted\n")
596c17ba 7843
1d80f243
IR
7844DEFUN (neighbor_maximum_prefix_threshold_warning,
7845 neighbor_maximum_prefix_threshold_warning_cmd,
7846 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7847 NEIGHBOR_STR
7848 NEIGHBOR_ADDR_STR2
7849 "Maximum number of prefix accept from this peer\n"
7850 "maximum no. of prefix limit\n"
7851 "Threshold value (%) at which to generate a warning msg\n"
7852 "Only give warning message when limit is exceeded\n"
7853 "Force checking all received routes not only accepted\n")
e0701b79 7854{
d62a17ae 7855 int idx_peer = 1;
7856 int idx_number = 3;
7857 int idx_number_2 = 4;
9cbd06e0 7858 int idx_force = 0;
7e62b792 7859 char *force = NULL;
9cbd06e0
DA
7860
7861 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7862 force = argv[idx_force]->arg;
9cbd06e0 7863
7e62b792
IR
7864 return peer_maximum_prefix_set_vty(
7865 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7866 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 7867}
7868
d62a17ae 7869ALIAS_HIDDEN(
7870 neighbor_maximum_prefix_threshold_warning,
7871 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 7872 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 7873 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7874 "Maximum number of prefix accept from this peer\n"
7875 "maximum no. of prefix limit\n"
7876 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
7877 "Only give warning message when limit is exceeded\n"
7878 "Force checking all received routes not only accepted\n")
596c17ba 7879
1d80f243
IR
7880DEFUN (neighbor_maximum_prefix_restart,
7881 neighbor_maximum_prefix_restart_cmd,
7882 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7883 NEIGHBOR_STR
7884 NEIGHBOR_ADDR_STR2
7885 "Maximum number of prefix accept from this peer\n"
7886 "maximum no. of prefix limit\n"
7887 "Restart bgp connection after limit is exceeded\n"
7888 "Restart interval in minutes\n"
7889 "Force checking all received routes not only accepted\n")
0a486e5f 7890{
d62a17ae 7891 int idx_peer = 1;
7892 int idx_number = 3;
7893 int idx_number_2 = 5;
9cbd06e0 7894 int idx_force = 0;
7e62b792 7895 char *force = NULL;
9cbd06e0
DA
7896
7897 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7898 force = argv[idx_force]->arg;
9cbd06e0 7899
7e62b792
IR
7900 return peer_maximum_prefix_set_vty(
7901 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7902 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 7903}
7904
d62a17ae 7905ALIAS_HIDDEN(
7906 neighbor_maximum_prefix_restart,
7907 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 7908 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 7909 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7910 "Maximum number of prefix accept from this peer\n"
7911 "maximum no. of prefix limit\n"
7912 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7913 "Restart interval in minutes\n"
7914 "Force checking all received routes not only accepted\n")
596c17ba 7915
1d80f243
IR
7916DEFUN (neighbor_maximum_prefix_threshold_restart,
7917 neighbor_maximum_prefix_threshold_restart_cmd,
7918 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7919 NEIGHBOR_STR
7920 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"
7925 "Restart interval in minutes\n"
7926 "Force checking all received routes not only accepted\n")
0a486e5f 7927{
d62a17ae 7928 int idx_peer = 1;
7929 int idx_number = 3;
7930 int idx_number_2 = 4;
7931 int idx_number_3 = 6;
9cbd06e0 7932 int idx_force = 0;
7e62b792 7933 char *force = NULL;
9cbd06e0
DA
7934
7935 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7936 force = argv[idx_force]->arg;
9cbd06e0 7937
7e62b792
IR
7938 return peer_maximum_prefix_set_vty(
7939 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7940 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
7941 argv[idx_number_3]->arg, force);
d62a17ae 7942}
7943
7944ALIAS_HIDDEN(
7945 neighbor_maximum_prefix_threshold_restart,
7946 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 7947 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 7948 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7949 "Maximum number of prefixes to accept from this peer\n"
7950 "maximum no. of prefix limit\n"
7951 "Threshold value (%) at which to generate a warning msg\n"
7952 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7953 "Restart interval in minutes\n"
7954 "Force checking all received routes not only accepted\n")
596c17ba 7955
1d80f243
IR
7956DEFUN (no_neighbor_maximum_prefix,
7957 no_neighbor_maximum_prefix_cmd,
7958 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
7959 NO_STR
7960 NEIGHBOR_STR
7961 NEIGHBOR_ADDR_STR2
7962 "Maximum number of prefixes to accept from this peer\n"
7963 "maximum no. of prefix limit\n"
7964 "Threshold value (%) at which to generate a warning msg\n"
7965 "Restart bgp connection after limit is exceeded\n"
7966 "Restart interval in minutes\n"
7967 "Only give warning message when limit is exceeded\n"
7968 "Force checking all received routes not only accepted\n")
718e3744 7969{
d62a17ae 7970 int idx_peer = 2;
7e62b792
IR
7971 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
7972 bgp_node_afi(vty),
7973 bgp_node_safi(vty));
718e3744 7974}
e52702f2 7975
d62a17ae 7976ALIAS_HIDDEN(
7977 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7978 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 7979 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7980 "Maximum number of prefixes to accept from this peer\n"
7981 "maximum no. of prefix limit\n"
7982 "Threshold value (%) at which to generate a warning msg\n"
7983 "Restart bgp connection after limit is exceeded\n"
7984 "Restart interval in minutes\n"
9cbd06e0
DA
7985 "Only give warning message when limit is exceeded\n"
7986 "Force checking all received routes not only accepted\n")
596c17ba 7987
718e3744 7988
718e3744 7989/* "neighbor allowas-in" */
7990DEFUN (neighbor_allowas_in,
7991 neighbor_allowas_in_cmd,
fd8503f5 7992 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7993 NEIGHBOR_STR
7994 NEIGHBOR_ADDR_STR2
31500417 7995 "Accept as-path with my AS present in it\n"
f79f7a7b 7996 "Number of occurrences of AS number\n"
fd8503f5 7997 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7998{
d62a17ae 7999 int idx_peer = 1;
8000 int idx_number_origin = 3;
8001 int ret;
8002 int origin = 0;
8003 struct peer *peer;
8004 int allow_num = 0;
8005
8006 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8007 if (!peer)
8008 return CMD_WARNING_CONFIG_FAILED;
8009
8010 if (argc <= idx_number_origin)
8011 allow_num = 3;
8012 else {
8013 if (argv[idx_number_origin]->type == WORD_TKN)
8014 origin = 1;
8015 else
8016 allow_num = atoi(argv[idx_number_origin]->arg);
8017 }
8018
8019 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8020 allow_num, origin);
8021
8022 return bgp_vty_return(vty, ret);
8023}
8024
8025ALIAS_HIDDEN(
8026 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8027 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8028 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8029 "Accept as-path with my AS present in it\n"
f79f7a7b 8030 "Number of occurrences of AS number\n"
d62a17ae 8031 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8032
718e3744 8033DEFUN (no_neighbor_allowas_in,
8034 no_neighbor_allowas_in_cmd,
fd8503f5 8035 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8036 NO_STR
8037 NEIGHBOR_STR
8038 NEIGHBOR_ADDR_STR2
8334fd5a 8039 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8040 "Number of occurrences of AS number\n"
fd8503f5 8041 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8042{
d62a17ae 8043 int idx_peer = 2;
8044 int ret;
8045 struct peer *peer;
718e3744 8046
d62a17ae 8047 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8048 if (!peer)
8049 return CMD_WARNING_CONFIG_FAILED;
718e3744 8050
d62a17ae 8051 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8052 bgp_node_safi(vty));
718e3744 8053
d62a17ae 8054 return bgp_vty_return(vty, ret);
718e3744 8055}
6b0655a2 8056
d62a17ae 8057ALIAS_HIDDEN(
8058 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8059 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8060 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8061 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8062 "Number of occurrences of AS number\n"
d62a17ae 8063 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8064
28c6e247
IR
8065DEFUN (neighbor_ttl_security,
8066 neighbor_ttl_security_cmd,
8067 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8068 NEIGHBOR_STR
8069 NEIGHBOR_ADDR_STR2
8070 "BGP ttl-security parameters\n"
8071 "Specify the maximum number of hops to the BGP peer\n"
8072 "Number of hops to BGP peer\n")
fa411a21 8073{
d62a17ae 8074 int idx_peer = 1;
8075 int idx_number = 4;
28c6e247
IR
8076 struct peer *peer;
8077 int gtsm_hops;
d62a17ae 8078
28c6e247
IR
8079 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8080 if (!peer)
d62a17ae 8081 return CMD_WARNING_CONFIG_FAILED;
8082
28c6e247
IR
8083 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8084
8085 /*
8086 * If 'neighbor swpX', then this is for directly connected peers,
8087 * we should not accept a ttl-security hops value greater than 1.
8088 */
8089 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8090 vty_out(vty,
8091 "%s is directly connected peer, hops cannot exceed 1\n",
8092 argv[idx_peer]->arg);
8093 return CMD_WARNING_CONFIG_FAILED;
8094 }
7ebe625c 8095
28c6e247 8096 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
8097}
8098
1d80f243
IR
8099DEFUN (no_neighbor_ttl_security,
8100 no_neighbor_ttl_security_cmd,
8101 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8102 NO_STR
8103 NEIGHBOR_STR
8104 NEIGHBOR_ADDR_STR2
8105 "BGP ttl-security parameters\n"
8106 "Specify the maximum number of hops to the BGP peer\n"
8107 "Number of hops to BGP peer\n")
fa411a21 8108{
d62a17ae 8109 int idx_peer = 2;
28c6e247 8110 struct peer *peer;
fa411a21 8111
28c6e247
IR
8112 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8113 if (!peer)
d62a17ae 8114 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8115
28c6e247 8116 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 8117}
6b0655a2 8118
7c0e4312
DA
8119/* disable-addpath-rx */
8120DEFUN(neighbor_disable_addpath_rx,
8121 neighbor_disable_addpath_rx_cmd,
8122 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8123 NEIGHBOR_STR
8124 NEIGHBOR_ADDR_STR2
8125 "Do not accept additional paths\n")
8126{
8127 char *peer_str = argv[1]->arg;
8128 struct peer *peer;
8129 afi_t afi = bgp_node_afi(vty);
8130 safi_t safi = bgp_node_safi(vty);
8131
8132 peer = peer_and_group_lookup_vty(vty, peer_str);
8133 if (!peer)
8134 return CMD_WARNING_CONFIG_FAILED;
8135
8136 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8137 PEER_FLAG_DISABLE_ADDPATH_RX);
8138}
8139
8140DEFUN(no_neighbor_disable_addpath_rx,
8141 no_neighbor_disable_addpath_rx_cmd,
8142 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8143 NO_STR
8144 NEIGHBOR_STR
8145 NEIGHBOR_ADDR_STR2
8146 "Do not accept additional paths\n")
8147{
8148 char *peer_str = argv[2]->arg;
8149 struct peer *peer;
8150 afi_t afi = bgp_node_afi(vty);
8151 safi_t safi = bgp_node_safi(vty);
8152
8153 peer = peer_and_group_lookup_vty(vty, peer_str);
8154 if (!peer)
8155 return CMD_WARNING_CONFIG_FAILED;
8156
8157 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8158 PEER_FLAG_DISABLE_ADDPATH_RX);
8159}
8160
adbac85e
DW
8161DEFUN (neighbor_addpath_tx_all_paths,
8162 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8163 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8164 NEIGHBOR_STR
8165 NEIGHBOR_ADDR_STR2
8166 "Use addpath to advertise all paths to a neighbor\n")
8167{
d62a17ae 8168 int idx_peer = 1;
8169 struct peer *peer;
adbac85e 8170
d62a17ae 8171 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8172 if (!peer)
8173 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8174
dcc68b5e
MS
8175 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8176 BGP_ADDPATH_ALL);
8177 return CMD_SUCCESS;
adbac85e
DW
8178}
8179
d62a17ae 8180ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8181 neighbor_addpath_tx_all_paths_hidden_cmd,
8182 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8183 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8184 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8185
adbac85e
DW
8186DEFUN (no_neighbor_addpath_tx_all_paths,
8187 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8188 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8189 NO_STR
8190 NEIGHBOR_STR
8191 NEIGHBOR_ADDR_STR2
8192 "Use addpath to advertise all paths to a neighbor\n")
8193{
d62a17ae 8194 int idx_peer = 2;
dcc68b5e
MS
8195 struct peer *peer;
8196
8197 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8198 if (!peer)
8199 return CMD_WARNING_CONFIG_FAILED;
8200
8201 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8202 != BGP_ADDPATH_ALL) {
8203 vty_out(vty,
8204 "%% Peer not currently configured to transmit all paths.");
8205 return CMD_WARNING_CONFIG_FAILED;
8206 }
8207
8208 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8209 BGP_ADDPATH_NONE);
8210
8211 return CMD_SUCCESS;
adbac85e
DW
8212}
8213
d62a17ae 8214ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8215 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8216 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8217 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8218 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8219
06370dac
DW
8220DEFUN (neighbor_addpath_tx_bestpath_per_as,
8221 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8222 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8223 NEIGHBOR_STR
8224 NEIGHBOR_ADDR_STR2
8225 "Use addpath to advertise the bestpath per each neighboring AS\n")
8226{
d62a17ae 8227 int idx_peer = 1;
8228 struct peer *peer;
06370dac 8229
d62a17ae 8230 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8231 if (!peer)
8232 return CMD_WARNING_CONFIG_FAILED;
06370dac 8233
dcc68b5e
MS
8234 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8235 BGP_ADDPATH_BEST_PER_AS);
8236
8237 return CMD_SUCCESS;
06370dac
DW
8238}
8239
d62a17ae 8240ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8241 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8242 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8243 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8244 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8245
06370dac
DW
8246DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8247 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8248 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8249 NO_STR
8250 NEIGHBOR_STR
8251 NEIGHBOR_ADDR_STR2
8252 "Use addpath to advertise the bestpath per each neighboring AS\n")
8253{
d62a17ae 8254 int idx_peer = 2;
dcc68b5e
MS
8255 struct peer *peer;
8256
8257 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8258 if (!peer)
8259 return CMD_WARNING_CONFIG_FAILED;
8260
8261 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8262 != BGP_ADDPATH_BEST_PER_AS) {
8263 vty_out(vty,
8264 "%% Peer not currently configured to transmit all best path per as.");
8265 return CMD_WARNING_CONFIG_FAILED;
8266 }
8267
8268 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8269 BGP_ADDPATH_NONE);
8270
8271 return CMD_SUCCESS;
06370dac
DW
8272}
8273
d62a17ae 8274ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8275 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8276 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8277 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8278 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8279
2b31007c
RZ
8280DEFPY(
8281 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8282 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8283 NEIGHBOR_STR
8284 NEIGHBOR_ADDR_STR2
8285 "Detect AS loops before sending to neighbor\n")
8286{
8287 struct peer *peer;
8288
8289 peer = peer_and_group_lookup_vty(vty, neighbor);
8290 if (!peer)
8291 return CMD_WARNING_CONFIG_FAILED;
8292
8293 peer->as_path_loop_detection = true;
8294
8295 return CMD_SUCCESS;
8296}
8297
8298DEFPY(
8299 no_neighbor_aspath_loop_detection,
8300 no_neighbor_aspath_loop_detection_cmd,
8301 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8302 NO_STR
8303 NEIGHBOR_STR
8304 NEIGHBOR_ADDR_STR2
8305 "Detect AS loops before sending to neighbor\n")
8306{
8307 struct peer *peer;
8308
8309 peer = peer_and_group_lookup_vty(vty, neighbor);
8310 if (!peer)
8311 return CMD_WARNING_CONFIG_FAILED;
8312
8313 peer->as_path_loop_detection = false;
8314
8315 return CMD_SUCCESS;
8316}
8317
b9c7bc5a 8318static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8319 struct ecommunity **list, bool is_rt6)
ddb5b488 8320{
b9c7bc5a
PZ
8321 struct ecommunity *ecom = NULL;
8322 struct ecommunity *ecomadd;
ddb5b488 8323
b9c7bc5a 8324 for (; argc; --argc, ++argv) {
9a659715
PG
8325 if (is_rt6)
8326 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8327 ECOMMUNITY_ROUTE_TARGET,
8328 0);
8329 else
8330 ecomadd = ecommunity_str2com(argv[0]->arg,
8331 ECOMMUNITY_ROUTE_TARGET,
8332 0);
b9c7bc5a
PZ
8333 if (!ecomadd) {
8334 vty_out(vty, "Malformed community-list value\n");
8335 if (ecom)
8336 ecommunity_free(&ecom);
8337 return CMD_WARNING_CONFIG_FAILED;
8338 }
ddb5b488 8339
b9c7bc5a
PZ
8340 if (ecom) {
8341 ecommunity_merge(ecom, ecomadd);
8342 ecommunity_free(&ecomadd);
8343 } else {
8344 ecom = ecomadd;
8345 }
8346 }
8347
8348 if (*list) {
8349 ecommunity_free(&*list);
ddb5b488 8350 }
b9c7bc5a
PZ
8351 *list = ecom;
8352
8353 return CMD_SUCCESS;
ddb5b488
PZ
8354}
8355
0ca70ba5
DS
8356/*
8357 * v2vimport is true if we are handling a `import vrf ...` command
8358 */
8359static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8360{
0ca70ba5
DS
8361 afi_t afi;
8362
ddb5b488 8363 switch (vty->node) {
b9c7bc5a 8364 case BGP_IPV4_NODE:
0ca70ba5
DS
8365 afi = AFI_IP;
8366 break;
b9c7bc5a 8367 case BGP_IPV6_NODE:
0ca70ba5
DS
8368 afi = AFI_IP6;
8369 break;
ddb5b488
PZ
8370 default:
8371 vty_out(vty,
b9c7bc5a 8372 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 8373 return AFI_MAX;
ddb5b488 8374 }
69b07479 8375
0ca70ba5
DS
8376 if (!v2vimport) {
8377 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8378 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8379 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8380 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8381 vty_out(vty,
8382 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8383 return AFI_MAX;
8384 }
8385 } else {
8386 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8387 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8388 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8389 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8390 vty_out(vty,
8391 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8392 return AFI_MAX;
8393 }
8394 }
8395 return afi;
ddb5b488
PZ
8396}
8397
585f1adc
IR
8398DEFPY (af_rd_vpn_export,
8399 af_rd_vpn_export_cmd,
8400 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8401 NO_STR
8402 "Specify route distinguisher\n"
8403 "Between current address-family and vpn\n"
8404 "For routes leaked from current address-family to vpn\n"
8405 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 8406{
585f1adc
IR
8407 VTY_DECLVAR_CONTEXT(bgp, bgp);
8408 struct prefix_rd prd;
8409 int ret;
ddb5b488 8410 afi_t afi;
b9c7bc5a 8411 int idx = 0;
585f1adc 8412 bool yes = true;
b9c7bc5a 8413
585f1adc
IR
8414 if (argv_find(argv, argc, "no", &idx))
8415 yes = false;
ddb5b488 8416
585f1adc
IR
8417 if (yes) {
8418 ret = str2prefix_rd(rd_str, &prd);
8419 if (!ret) {
8420 vty_out(vty, "%% Malformed rd\n");
8421 return CMD_WARNING_CONFIG_FAILED;
8422 }
8423 }
ddb5b488 8424
585f1adc
IR
8425 afi = vpn_policy_getafi(vty, bgp, false);
8426 if (afi == AFI_MAX)
8427 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8428
585f1adc
IR
8429 /*
8430 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8431 */
8432 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8433 bgp_get_default(), bgp);
ddb5b488 8434
585f1adc
IR
8435 if (yes) {
8436 bgp->vpn_policy[afi].tovpn_rd = prd;
8437 SET_FLAG(bgp->vpn_policy[afi].flags,
8438 BGP_VPN_POLICY_TOVPN_RD_SET);
8439 } else {
8440 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8441 BGP_VPN_POLICY_TOVPN_RD_SET);
8442 }
69b07479 8443
585f1adc
IR
8444 /* post-change: re-export vpn routes */
8445 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8446 bgp_get_default(), bgp);
8447
8448 return CMD_SUCCESS;
ddb5b488
PZ
8449}
8450
b9c7bc5a
PZ
8451ALIAS (af_rd_vpn_export,
8452 af_no_rd_vpn_export_cmd,
8453 "no rd vpn export",
ddb5b488 8454 NO_STR
b9c7bc5a
PZ
8455 "Specify route distinguisher\n"
8456 "Between current address-family and vpn\n"
8457 "For routes leaked from current address-family to vpn\n")
ddb5b488 8458
b9c7bc5a
PZ
8459DEFPY (af_label_vpn_export,
8460 af_label_vpn_export_cmd,
e70e9f8e 8461 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 8462 NO_STR
ddb5b488 8463 "label value for VRF\n"
b9c7bc5a
PZ
8464 "Between current address-family and vpn\n"
8465 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
8466 "Label Value <0-1048575>\n"
8467 "Automatically assign a label\n")
ddb5b488
PZ
8468{
8469 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8470 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 8471 afi_t afi;
b9c7bc5a 8472 int idx = 0;
c6423c31 8473 bool yes = true;
b9c7bc5a
PZ
8474
8475 if (argv_find(argv, argc, "no", &idx))
c6423c31 8476 yes = false;
ddb5b488 8477
21a16cc2
PZ
8478 /* If "no ...", squash trailing parameter */
8479 if (!yes)
8480 label_auto = NULL;
8481
e70e9f8e
PZ
8482 if (yes) {
8483 if (!label_auto)
8484 label = label_val; /* parser should force unsigned */
8485 }
ddb5b488 8486
0ca70ba5 8487 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8488 if (afi == AFI_MAX)
8489 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 8490
e70e9f8e 8491
69b07479
DS
8492 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8493 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8494 /* no change */
8495 return CMD_SUCCESS;
e70e9f8e 8496
69b07479
DS
8497 /*
8498 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8499 */
8500 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8501 bgp_get_default(), bgp);
8502
8503 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8504 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8505
8506 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8507
8508 /*
8509 * label has previously been automatically
8510 * assigned by labelpool: release it
8511 *
8512 * NB if tovpn_label == MPLS_LABEL_NONE it
8513 * means the automatic assignment is in flight
8514 * and therefore the labelpool callback must
8515 * detect that the auto label is not needed.
8516 */
8517
8518 bgp_lp_release(LP_TYPE_VRF,
8519 &bgp->vpn_policy[afi],
8520 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 8521 }
69b07479
DS
8522 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8523 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8524 }
ddb5b488 8525
69b07479
DS
8526 bgp->vpn_policy[afi].tovpn_label = label;
8527 if (label_auto) {
8528 SET_FLAG(bgp->vpn_policy[afi].flags,
8529 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8530 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8531 vpn_leak_label_callback);
ddb5b488
PZ
8532 }
8533
69b07479
DS
8534 /* post-change: re-export vpn routes */
8535 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8536 bgp_get_default(), bgp);
8537
0d020cd6 8538 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
8539 return CMD_SUCCESS;
8540}
8541
b72c9e14
HS
8542DEFPY (af_sid_vpn_export,
8543 af_sid_vpn_export_cmd,
8544 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8545 NO_STR
8546 "sid value for VRF\n"
8547 "Between current address-family and vpn\n"
8548 "For routes leaked from current address-family to vpn\n"
8549 "Sid allocation index\n"
8550 "Automatically assign a label\n")
8551{
8552 VTY_DECLVAR_CONTEXT(bgp, bgp);
8553 afi_t afi;
8554 int debug = 0;
8555 int idx = 0;
8556 bool yes = true;
8557
8558 if (argv_find(argv, argc, "no", &idx))
8559 yes = false;
8560 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8561 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8562
8563 afi = vpn_policy_getafi(vty, bgp, false);
8564 if (afi == AFI_MAX)
8565 return CMD_WARNING_CONFIG_FAILED;
8566
8567 if (!yes) {
8568 /* implement me */
8569 vty_out(vty, "It's not implemented");
8570 return CMD_WARNING_CONFIG_FAILED;
8571 }
8572
8573 /* skip when it's already configured */
8574 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8575 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8576 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8577 return CMD_SUCCESS;
8578
7de4c885
HS
8579 /*
8580 * mode change between sid_idx and sid_auto isn't supported.
8581 * user must negate sid vpn export when they want to change the mode
8582 */
b72c9e14
HS
8583 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8584 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8585 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8586 vty_out(vty, "it's already configured as %s.\n",
8587 sid_auto ? "auto-mode" : "idx-mode");
8588 return CMD_WARNING_CONFIG_FAILED;
8589 }
8590
8591 /* pre-change */
8592 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8593 bgp_get_default(), bgp);
8594
8595 if (sid_auto) {
8596 /* SID allocation auto-mode */
8597 if (debug)
8598 zlog_debug("%s: auto sid alloc.", __func__);
8599 SET_FLAG(bgp->vpn_policy[afi].flags,
8600 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8601 } else {
8602 /* SID allocation index-mode */
8603 if (debug)
8604 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8605 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8606 }
8607
8608 /* post-change */
8609 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8610 bgp_get_default(), bgp);
8611 return CMD_SUCCESS;
8612}
8613
b9c7bc5a
PZ
8614ALIAS (af_label_vpn_export,
8615 af_no_label_vpn_export_cmd,
8616 "no label vpn export",
8617 NO_STR
8618 "label value for VRF\n"
8619 "Between current address-family and vpn\n"
8620 "For routes leaked from current address-family to vpn\n")
ddb5b488 8621
585f1adc 8622DEFPY (af_nexthop_vpn_export,
b9c7bc5a 8623 af_nexthop_vpn_export_cmd,
8c85ca28 8624 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 8625 NO_STR
ddb5b488 8626 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
8627 "Between current address-family and vpn\n"
8628 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8629 "IPv4 prefix\n"
8630 "IPv6 prefix\n")
8631{
585f1adc 8632 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 8633 afi_t afi;
ddb5b488
PZ
8634 struct prefix p;
8635
8c85ca28
QY
8636 if (!no) {
8637 if (!nexthop_su) {
8638 vty_out(vty, "%% Nexthop required\n");
8639 return CMD_WARNING_CONFIG_FAILED;
8640 }
8c85ca28 8641 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
8642 return CMD_WARNING_CONFIG_FAILED;
8643 }
ddb5b488 8644
585f1adc
IR
8645 afi = vpn_policy_getafi(vty, bgp, false);
8646 if (afi == AFI_MAX)
8647 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8648
585f1adc
IR
8649 /*
8650 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8651 */
8652 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8653 bgp_get_default(), bgp);
ddb5b488 8654
585f1adc
IR
8655 if (!no) {
8656 bgp->vpn_policy[afi].tovpn_nexthop = p;
8657 SET_FLAG(bgp->vpn_policy[afi].flags,
8658 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8659 } else {
8660 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8661 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8662 }
69b07479 8663
585f1adc
IR
8664 /* post-change: re-export vpn routes */
8665 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8666 bgp_get_default(), bgp);
37a87b8f 8667
585f1adc 8668 return CMD_SUCCESS;
ddb5b488
PZ
8669}
8670
b9c7bc5a 8671static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 8672{
b9c7bc5a
PZ
8673 if (!strcmp(dstr, "import")) {
8674 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8675 } else if (!strcmp(dstr, "export")) {
8676 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8677 } else if (!strcmp(dstr, "both")) {
8678 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8679 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8680 } else {
8681 vty_out(vty, "%% direction parse error\n");
8682 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8683 }
ddb5b488
PZ
8684 return CMD_SUCCESS;
8685}
8686
b9c7bc5a
PZ
8687DEFPY (af_rt_vpn_imexport,
8688 af_rt_vpn_imexport_cmd,
8689 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8690 NO_STR
8691 "Specify route target list\n"
ddb5b488 8692 "Specify route target list\n"
b9c7bc5a
PZ
8693 "Between current address-family and vpn\n"
8694 "For routes leaked from vpn to current address-family: match any\n"
8695 "For routes leaked from current address-family to vpn: set\n"
8696 "both import: match any and export: set\n"
ddb5b488
PZ
8697 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8698{
8699 VTY_DECLVAR_CONTEXT(bgp, bgp);
8700 int ret;
8701 struct ecommunity *ecom = NULL;
8702 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
8703 vpn_policy_direction_t dir;
8704 afi_t afi;
8705 int idx = 0;
c6423c31 8706 bool yes = true;
ddb5b488 8707
b9c7bc5a 8708 if (argv_find(argv, argc, "no", &idx))
c6423c31 8709 yes = false;
b9c7bc5a 8710
0ca70ba5 8711 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8712 if (afi == AFI_MAX)
8713 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8714
b9c7bc5a 8715 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
8716 if (ret != CMD_SUCCESS)
8717 return ret;
8718
b9c7bc5a
PZ
8719 if (yes) {
8720 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8721 vty_out(vty, "%% Missing RTLIST\n");
8722 return CMD_WARNING_CONFIG_FAILED;
8723 }
c6423c31 8724 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
8725 if (ret != CMD_SUCCESS) {
8726 return ret;
8727 }
ddb5b488
PZ
8728 }
8729
69b07479
DS
8730 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8731 if (!dodir[dir])
ddb5b488 8732 continue;
ddb5b488 8733
69b07479 8734 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8735
69b07479
DS
8736 if (yes) {
8737 if (bgp->vpn_policy[afi].rtlist[dir])
8738 ecommunity_free(
8739 &bgp->vpn_policy[afi].rtlist[dir]);
8740 bgp->vpn_policy[afi].rtlist[dir] =
8741 ecommunity_dup(ecom);
8742 } else {
8743 if (bgp->vpn_policy[afi].rtlist[dir])
8744 ecommunity_free(
8745 &bgp->vpn_policy[afi].rtlist[dir]);
8746 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 8747 }
69b07479
DS
8748
8749 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8750 }
69b07479 8751
d555f3e9
PZ
8752 if (ecom)
8753 ecommunity_free(&ecom);
ddb5b488
PZ
8754
8755 return CMD_SUCCESS;
8756}
8757
b9c7bc5a
PZ
8758ALIAS (af_rt_vpn_imexport,
8759 af_no_rt_vpn_imexport_cmd,
8760 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
8761 NO_STR
8762 "Specify route target list\n"
b9c7bc5a
PZ
8763 "Specify route target list\n"
8764 "Between current address-family and vpn\n"
8765 "For routes leaked from vpn to current address-family\n"
8766 "For routes leaked from current address-family to vpn\n"
8767 "both import and export\n")
8768
585f1adc 8769DEFPY (af_route_map_vpn_imexport,
b9c7bc5a
PZ
8770 af_route_map_vpn_imexport_cmd,
8771/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8772 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8773 NO_STR
ddb5b488 8774 "Specify route map\n"
b9c7bc5a
PZ
8775 "Between current address-family and vpn\n"
8776 "For routes leaked from vpn to current address-family\n"
8777 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8778 "name of route-map\n")
8779{
585f1adc
IR
8780 VTY_DECLVAR_CONTEXT(bgp, bgp);
8781 int ret;
8782 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8783 vpn_policy_direction_t dir;
ddb5b488 8784 afi_t afi;
ddb5b488 8785 int idx = 0;
585f1adc 8786 bool yes = true;
ddb5b488 8787
585f1adc
IR
8788 if (argv_find(argv, argc, "no", &idx))
8789 yes = false;
ddb5b488 8790
585f1adc
IR
8791 afi = vpn_policy_getafi(vty, bgp, false);
8792 if (afi == AFI_MAX)
8793 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8794
585f1adc
IR
8795 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8796 if (ret != CMD_SUCCESS)
8797 return ret;
ddb5b488 8798
585f1adc
IR
8799 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8800 if (!dodir[dir])
8801 continue;
69b07479 8802
585f1adc
IR
8803 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8804
8805 if (yes) {
8806 if (bgp->vpn_policy[afi].rmap_name[dir])
8807 XFREE(MTYPE_ROUTE_MAP_NAME,
8808 bgp->vpn_policy[afi].rmap_name[dir]);
8809 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
8810 MTYPE_ROUTE_MAP_NAME, rmap_str);
8811 bgp->vpn_policy[afi].rmap[dir] =
8812 route_map_lookup_warn_noexist(vty, rmap_str);
8813 if (!bgp->vpn_policy[afi].rmap[dir])
8814 return CMD_SUCCESS;
8815 } else {
8816 if (bgp->vpn_policy[afi].rmap_name[dir])
8817 XFREE(MTYPE_ROUTE_MAP_NAME,
8818 bgp->vpn_policy[afi].rmap_name[dir]);
8819 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8820 bgp->vpn_policy[afi].rmap[dir] = NULL;
8821 }
8822
8823 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8824 }
ddb5b488 8825
585f1adc 8826 return CMD_SUCCESS;
ddb5b488
PZ
8827}
8828
b9c7bc5a
PZ
8829ALIAS (af_route_map_vpn_imexport,
8830 af_no_route_map_vpn_imexport_cmd,
8831 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
8832 NO_STR
8833 "Specify route map\n"
b9c7bc5a
PZ
8834 "Between current address-family and vpn\n"
8835 "For routes leaked from vpn to current address-family\n"
8836 "For routes leaked from current address-family to vpn\n")
8837
bb4f6190 8838DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 8839 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
8840 "Import routes from another VRF\n"
8841 "Vrf routes being filtered\n"
8842 "Specify route map\n"
8843 "name of route-map\n")
8844{
8845 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
8846 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8847 afi_t afi;
bb4f6190
DS
8848 struct bgp *bgp_default;
8849
0ca70ba5 8850 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
8851 if (afi == AFI_MAX)
8852 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
8853
8854 bgp_default = bgp_get_default();
8855 if (!bgp_default) {
8856 int32_t ret;
8857 as_t as = bgp->as;
8858
8859 /* Auto-create assuming the same AS */
5d5393b9
DL
8860 ret = bgp_get_vty(&bgp_default, &as, NULL,
8861 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
8862
8863 if (ret) {
8864 vty_out(vty,
8865 "VRF default is not configured as a bgp instance\n");
8866 return CMD_WARNING;
8867 }
8868 }
8869
69b07479 8870 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 8871
ae6a6fb4
DS
8872 if (bgp->vpn_policy[afi].rmap_name[dir])
8873 XFREE(MTYPE_ROUTE_MAP_NAME,
8874 bgp->vpn_policy[afi].rmap_name[dir]);
8875 bgp->vpn_policy[afi].rmap_name[dir] =
8876 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8877 bgp->vpn_policy[afi].rmap[dir] =
8878 route_map_lookup_warn_noexist(vty, rmap_str);
8879 if (!bgp->vpn_policy[afi].rmap[dir])
8880 return CMD_SUCCESS;
8881
8882 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8883 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 8884
69b07479
DS
8885 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8886
bb4f6190
DS
8887 return CMD_SUCCESS;
8888}
8889
ae6a6fb4
DS
8890DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
8891 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
8892 NO_STR
8893 "Import routes from another VRF\n"
8894 "Vrf routes being filtered\n"
ae6a6fb4
DS
8895 "Specify route map\n"
8896 "name of route-map\n")
8897{
8898 VTY_DECLVAR_CONTEXT(bgp, bgp);
8899 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8900 afi_t afi;
8901
8902 afi = vpn_policy_getafi(vty, bgp, true);
8903 if (afi == AFI_MAX)
8904 return CMD_WARNING_CONFIG_FAILED;
8905
8906 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8907
8908 if (bgp->vpn_policy[afi].rmap_name[dir])
8909 XFREE(MTYPE_ROUTE_MAP_NAME,
8910 bgp->vpn_policy[afi].rmap_name[dir]);
8911 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8912 bgp->vpn_policy[afi].rmap[dir] = NULL;
8913
8914 if (bgp->vpn_policy[afi].import_vrf->count == 0)
8915 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8916 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8917
8918 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8919
8920 return CMD_SUCCESS;
8921}
bb4f6190 8922
585f1adc
IR
8923DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
8924 "[no] import vrf VIEWVRFNAME$import_name",
8925 NO_STR
8926 "Import routes from another VRF\n"
8927 "VRF to import from\n"
8928 "The name of the VRF\n")
12a844a5 8929{
585f1adc
IR
8930 VTY_DECLVAR_CONTEXT(bgp, bgp);
8931 struct listnode *node;
8932 struct bgp *vrf_bgp, *bgp_default;
8933 int32_t ret = 0;
8934 as_t as = bgp->as;
8935 bool remove = false;
8936 int32_t idx = 0;
8937 char *vname;
8938 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
8939 safi_t safi;
8940 afi_t afi;
8941
867f0cca 8942 if (import_name == NULL) {
8943 vty_out(vty, "%% Missing import name\n");
8944 return CMD_WARNING;
8945 }
8946
ae6a6fb4
DS
8947 if (strcmp(import_name, "route-map") == 0) {
8948 vty_out(vty, "%% Must include route-map name\n");
8949 return CMD_WARNING;
8950 }
8951
585f1adc
IR
8952 if (argv_find(argv, argc, "no", &idx))
8953 remove = true;
8954
8955 afi = vpn_policy_getafi(vty, bgp, true);
8956 if (afi == AFI_MAX)
8957 return CMD_WARNING_CONFIG_FAILED;
8958
12a844a5
DS
8959 safi = bgp_node_safi(vty);
8960
585f1adc
IR
8961 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
8962 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
8963 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
8964 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
8965 remove ? "unimport" : "import", import_name);
8966 return CMD_WARNING;
8967 }
25679caa 8968
585f1adc
IR
8969 bgp_default = bgp_get_default();
8970 if (!bgp_default) {
8971 /* Auto-create assuming the same AS */
8972 ret = bgp_get_vty(&bgp_default, &as, NULL,
8973 BGP_INSTANCE_TYPE_DEFAULT);
12a844a5 8974
585f1adc
IR
8975 if (ret) {
8976 vty_out(vty,
8977 "VRF default is not configured as a bgp instance\n");
8978 return CMD_WARNING;
8979 }
8980 }
12a844a5 8981
585f1adc
IR
8982 vrf_bgp = bgp_lookup_by_name(import_name);
8983 if (!vrf_bgp) {
8984 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
8985 vrf_bgp = bgp_default;
8986 else
8987 /* Auto-create assuming the same AS */
8988 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
8989
8990 if (ret) {
8991 vty_out(vty,
8992 "VRF %s is not configured as a bgp instance\n",
8993 import_name);
8994 return CMD_WARNING;
8995 }
8996 }
8997
8998 if (remove) {
8999 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9000 } else {
9001 /* Already importing from "import_vrf"? */
9002 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9003 vname)) {
9004 if (strcmp(vname, import_name) == 0)
9005 return CMD_WARNING;
9006 }
9007
9008 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9009 }
9010
9011 return CMD_SUCCESS;
12a844a5
DS
9012}
9013
b9c7bc5a 9014/* This command is valid only in a bgp vrf instance or the default instance */
585f1adc 9015DEFPY (bgp_imexport_vpn,
b9c7bc5a
PZ
9016 bgp_imexport_vpn_cmd,
9017 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9018 NO_STR
9019 "Import routes to this address-family\n"
9020 "Export routes from this address-family\n"
9021 "to/from default instance VPN RIB\n")
ddb5b488 9022{
585f1adc
IR
9023 VTY_DECLVAR_CONTEXT(bgp, bgp);
9024 int previous_state;
37a87b8f 9025 afi_t afi;
585f1adc
IR
9026 safi_t safi;
9027 int idx = 0;
9028 bool yes = true;
9029 int flag;
9030 vpn_policy_direction_t dir;
9031
9032 if (argv_find(argv, argc, "no", &idx))
9033 yes = false;
9034
9035 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9036 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9037
9038 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9039 return CMD_WARNING_CONFIG_FAILED;
9040 }
ddb5b488 9041
b9c7bc5a
PZ
9042 afi = bgp_node_afi(vty);
9043 safi = bgp_node_safi(vty);
585f1adc
IR
9044 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9045 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9046 return CMD_WARNING_CONFIG_FAILED;
9047 }
ddb5b488 9048
b9c7bc5a 9049 if (!strcmp(direction_str, "import")) {
585f1adc
IR
9050 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9051 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b9c7bc5a 9052 } else if (!strcmp(direction_str, "export")) {
585f1adc
IR
9053 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9054 dir = BGP_VPN_POLICY_DIR_TOVPN;
b9c7bc5a
PZ
9055 } else {
9056 vty_out(vty, "%% unknown direction %s\n", direction_str);
9057 return CMD_WARNING_CONFIG_FAILED;
9058 }
9059
585f1adc 9060 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 9061
585f1adc
IR
9062 if (yes) {
9063 SET_FLAG(bgp->af_flags[afi][safi], flag);
9064 if (!previous_state) {
9065 /* trigger export current vrf */
9066 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9067 }
9068 } else {
9069 if (previous_state) {
9070 /* trigger un-export current vrf */
9071 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9072 }
9073 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9074 }
37a87b8f 9075
1ca2fd11
IR
9076 hook_call(bgp_snmp_init_stats, bgp);
9077
585f1adc 9078 return CMD_SUCCESS;
ddb5b488
PZ
9079}
9080
301ad80a
PG
9081DEFPY (af_routetarget_import,
9082 af_routetarget_import_cmd,
9a659715 9083 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9084 NO_STR
9085 "Specify route target list\n"
9086 "Specify route target list\n"
9a659715
PG
9087 "Specify route target list\n"
9088 "Specify route target list\n"
301ad80a
PG
9089 "Flow-spec redirect type route target\n"
9090 "Import routes to this address-family\n"
9a659715 9091 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9092{
9093 VTY_DECLVAR_CONTEXT(bgp, bgp);
9094 int ret;
9095 struct ecommunity *ecom = NULL;
301ad80a 9096 afi_t afi;
9a659715 9097 int idx = 0, idx_unused = 0;
c6423c31
PG
9098 bool yes = true;
9099 bool rt6 = false;
301ad80a
PG
9100
9101 if (argv_find(argv, argc, "no", &idx))
c6423c31 9102 yes = false;
301ad80a 9103
9a659715
PG
9104 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9105 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9106 rt6 = true;
301ad80a 9107
0ca70ba5 9108 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9109 if (afi == AFI_MAX)
9110 return CMD_WARNING_CONFIG_FAILED;
9111
9a659715
PG
9112 if (rt6 && afi != AFI_IP6)
9113 return CMD_WARNING_CONFIG_FAILED;
9114
301ad80a
PG
9115 if (yes) {
9116 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9117 vty_out(vty, "%% Missing RTLIST\n");
9118 return CMD_WARNING_CONFIG_FAILED;
9119 }
9a659715 9120 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9121 if (ret != CMD_SUCCESS)
9122 return ret;
9123 }
69b07479
DS
9124
9125 if (yes) {
9126 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9127 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9128 .import_redirect_rtlist);
69b07479
DS
9129 bgp->vpn_policy[afi].import_redirect_rtlist =
9130 ecommunity_dup(ecom);
9131 } else {
9132 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9133 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9134 .import_redirect_rtlist);
69b07479 9135 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9136 }
69b07479 9137
301ad80a
PG
9138 if (ecom)
9139 ecommunity_free(&ecom);
9140
9141 return CMD_SUCCESS;
9142}
9143
505e5056 9144DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9145 address_family_ipv4_safi_cmd,
9146 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9147 "Enter Address Family command mode\n"
9148 "Address Family\n"
9149 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9150{
f51bae9c 9151
d62a17ae 9152 if (argc == 3) {
585f1adc
IR
9153 VTY_DECLVAR_CONTEXT(bgp, bgp);
9154 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9155 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9156 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9157 && safi != SAFI_EVPN) {
31947174
MK
9158 vty_out(vty,
9159 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9160 return CMD_WARNING_CONFIG_FAILED;
9161 }
585f1adc
IR
9162 vty->node = bgp_node_type(AFI_IP, safi);
9163 } else
9164 vty->node = BGP_IPV4_NODE;
718e3744 9165
d62a17ae 9166 return CMD_SUCCESS;
718e3744 9167}
9168
505e5056 9169DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9170 address_family_ipv6_safi_cmd,
9171 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9172 "Enter Address Family command mode\n"
9173 "Address Family\n"
9174 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9175{
d62a17ae 9176 if (argc == 3) {
585f1adc
IR
9177 VTY_DECLVAR_CONTEXT(bgp, bgp);
9178 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9179 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9180 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9181 && safi != SAFI_EVPN) {
31947174
MK
9182 vty_out(vty,
9183 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9184 return CMD_WARNING_CONFIG_FAILED;
9185 }
585f1adc
IR
9186 vty->node = bgp_node_type(AFI_IP6, safi);
9187 } else
9188 vty->node = BGP_IPV6_NODE;
25ffbdc1 9189
d62a17ae 9190 return CMD_SUCCESS;
25ffbdc1 9191}
718e3744 9192
d6902373 9193#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9194DEFUN_NOSH (address_family_vpnv4,
718e3744 9195 address_family_vpnv4_cmd,
8334fd5a 9196 "address-family vpnv4 [unicast]",
718e3744 9197 "Enter Address Family command mode\n"
8c3deaae 9198 "Address Family\n"
3a2d747c 9199 "Address Family modifier\n")
718e3744 9200{
d62a17ae 9201 vty->node = BGP_VPNV4_NODE;
9202 return CMD_SUCCESS;
718e3744 9203}
9204
505e5056 9205DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9206 address_family_vpnv6_cmd,
8334fd5a 9207 "address-family vpnv6 [unicast]",
8ecd3266 9208 "Enter Address Family command mode\n"
8c3deaae 9209 "Address Family\n"
3a2d747c 9210 "Address Family modifier\n")
8ecd3266 9211{
d62a17ae 9212 vty->node = BGP_VPNV6_NODE;
9213 return CMD_SUCCESS;
8ecd3266 9214}
64e4a6c5 9215#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9216
505e5056 9217DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9218 address_family_evpn_cmd,
7111c1a0 9219 "address-family l2vpn evpn",
4e0b7b6d 9220 "Enter Address Family command mode\n"
7111c1a0
QY
9221 "Address Family\n"
9222 "Address Family modifier\n")
4e0b7b6d 9223{
2131d5cf 9224 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9225 vty->node = BGP_EVPN_NODE;
9226 return CMD_SUCCESS;
4e0b7b6d
PG
9227}
9228
bfaab44d
HS
9229DEFUN_NOSH (bgp_segment_routing_srv6,
9230 bgp_segment_routing_srv6_cmd,
9231 "segment-routing srv6",
9232 "Segment-Routing configuration\n"
9233 "Segment-Routing SRv6 configuration\n")
9234{
9235 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 9236 bgp->srv6_enabled = true;
bfaab44d
HS
9237 vty->node = BGP_SRV6_NODE;
9238 return CMD_SUCCESS;
9239}
9240
0249b8b6
HS
9241DEFUN (no_bgp_segment_routing_srv6,
9242 no_bgp_segment_routing_srv6_cmd,
9243 "no segment-routing srv6",
9244 NO_STR
9245 "Segment-Routing configuration\n"
9246 "Segment-Routing SRv6 configuration\n")
9247{
9248 VTY_DECLVAR_CONTEXT(bgp, bgp);
9249
9250 if (strlen(bgp->srv6_locator_name) > 0)
9251 if (bgp_srv6_locator_unset(bgp) < 0)
9252 return CMD_WARNING_CONFIG_FAILED;
9253
9254 bgp->srv6_enabled = false;
9255 return CMD_SUCCESS;
9256}
9257
a0281b2e
HS
9258DEFPY (bgp_srv6_locator,
9259 bgp_srv6_locator_cmd,
9260 "locator NAME$name",
9261 "Specify SRv6 locator\n"
9262 "Specify SRv6 locator\n")
9263{
9264 VTY_DECLVAR_CONTEXT(bgp, bgp);
7de4c885 9265 int ret;
a0281b2e
HS
9266
9267 if (strlen(bgp->srv6_locator_name) > 0
9268 && strcmp(name, bgp->srv6_locator_name) != 0) {
9269 vty_out(vty, "srv6 locator is already configured\n");
9270 return CMD_WARNING_CONFIG_FAILED;
7de4c885
HS
9271 }
9272
9273 snprintf(bgp->srv6_locator_name,
9274 sizeof(bgp->srv6_locator_name), "%s", name);
a0281b2e 9275
7de4c885 9276 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
a0281b2e
HS
9277 if (ret < 0)
9278 return CMD_WARNING_CONFIG_FAILED;
9279
9280 return CMD_SUCCESS;
9281}
9282
0249b8b6
HS
9283DEFPY (no_bgp_srv6_locator,
9284 no_bgp_srv6_locator_cmd,
9285 "no locator NAME$name",
9286 NO_STR
9287 "Specify SRv6 locator\n"
9288 "Specify SRv6 locator\n")
9289{
9290 VTY_DECLVAR_CONTEXT(bgp, bgp);
9291
9292 /* when locator isn't configured, do nothing */
9293 if (strlen(bgp->srv6_locator_name) < 1)
9294 return CMD_SUCCESS;
9295
9296 /* name validation */
9297 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9298 vty_out(vty, "%% No srv6 locator is configured\n");
9299 return CMD_WARNING_CONFIG_FAILED;
9300 }
9301
9302 /* unset locator */
9303 if (bgp_srv6_locator_unset(bgp) < 0)
9304 return CMD_WARNING_CONFIG_FAILED;
9305
9306 return CMD_SUCCESS;
9307}
9308
ea372e81
HS
9309DEFPY (show_bgp_srv6,
9310 show_bgp_srv6_cmd,
9311 "show bgp segment-routing srv6",
9312 SHOW_STR
9313 BGP_STR
9314 "BGP Segment Routing\n"
9315 "BGP Segment Routing SRv6\n")
9316{
9317 struct bgp *bgp;
9318 struct listnode *node;
9319 struct prefix_ipv6 *chunk;
9320 struct bgp_srv6_function *func;
9321 struct in6_addr *tovpn4_sid;
9322 struct in6_addr *tovpn6_sid;
9323 char buf[256];
9324 char buf_tovpn4_sid[256];
9325 char buf_tovpn6_sid[256];
9326
9327 bgp = bgp_get_default();
96db4340 9328 if (!bgp)
ea372e81
HS
9329 return CMD_SUCCESS;
9330
9331 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9332 vty_out(vty, "locator_chunks:\n");
9333 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9334 prefix2str(chunk, buf, sizeof(buf));
9335 vty_out(vty, "- %s\n", buf);
9336 }
9337
9338 vty_out(vty, "functions:\n");
9339 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9340 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9341 vty_out(vty, "- sid: %s\n", buf);
9342 vty_out(vty, " locator: %s\n", func->locator_name);
9343 }
9344
9345 vty_out(vty, "bgps:\n");
9346 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9347 vty_out(vty, "- name: %s\n",
9348 bgp->name ? bgp->name : "default");
9349
9350 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9351 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9352 if (tovpn4_sid)
9353 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9354 sizeof(buf_tovpn4_sid));
9355 if (tovpn6_sid)
9356 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9357 sizeof(buf_tovpn6_sid));
9358
9359 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9360 tovpn4_sid ? buf_tovpn4_sid : "none");
9361 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9362 tovpn6_sid ? buf_tovpn6_sid : "none");
9363 }
9364
9365 return CMD_SUCCESS;
9366}
9367
505e5056 9368DEFUN_NOSH (exit_address_family,
718e3744 9369 exit_address_family_cmd,
9370 "exit-address-family",
9371 "Exit from Address Family configuration mode\n")
9372{
d62a17ae 9373 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9374 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9375 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9376 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9377 || vty->node == BGP_EVPN_NODE
9378 || vty->node == BGP_FLOWSPECV4_NODE
9379 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9380 vty->node = BGP_NODE;
9381 return CMD_SUCCESS;
718e3744 9382}
6b0655a2 9383
8ad7271d 9384/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9385static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9386 const char *ip_str, afi_t afi, safi_t safi,
9387 struct prefix_rd *prd)
9388{
9389 int ret;
9390 struct prefix match;
9bcb3eef
DS
9391 struct bgp_dest *dest;
9392 struct bgp_dest *rm;
d62a17ae 9393 struct bgp *bgp;
9394 struct bgp_table *table;
9395 struct bgp_table *rib;
9396
9397 /* BGP structure lookup. */
9398 if (view_name) {
9399 bgp = bgp_lookup_by_name(view_name);
9400 if (bgp == NULL) {
9401 vty_out(vty, "%% Can't find BGP instance %s\n",
9402 view_name);
9403 return CMD_WARNING;
9404 }
9405 } else {
9406 bgp = bgp_get_default();
9407 if (bgp == NULL) {
9408 vty_out(vty, "%% No BGP process is configured\n");
9409 return CMD_WARNING;
9410 }
9411 }
9412
9413 /* Check IP address argument. */
9414 ret = str2prefix(ip_str, &match);
9415 if (!ret) {
9416 vty_out(vty, "%% address is malformed\n");
9417 return CMD_WARNING;
9418 }
9419
9420 match.family = afi2family(afi);
9421 rib = bgp->rib[afi][safi];
9422
9423 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9424 for (dest = bgp_table_top(rib); dest;
9425 dest = bgp_route_next(dest)) {
9426 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9427
9bcb3eef 9428 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9429 continue;
9430
9bcb3eef 9431 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9432 if (table == NULL)
9433 continue;
9434
4953391b
DA
9435 rm = bgp_node_match(table, &match);
9436 if (rm != NULL) {
b54892e0 9437 const struct prefix *rm_p =
9bcb3eef 9438 bgp_dest_get_prefix(rm);
b54892e0
DS
9439
9440 if (rm_p->prefixlen == match.prefixlen) {
9441 SET_FLAG(rm->flags,
9442 BGP_NODE_USER_CLEAR);
9443 bgp_process(bgp, rm, afi, safi);
d62a17ae 9444 }
9bcb3eef 9445 bgp_dest_unlock_node(rm);
d62a17ae 9446 }
9447 }
9448 } else {
4953391b
DA
9449 dest = bgp_node_match(rib, &match);
9450 if (dest != NULL) {
9bcb3eef 9451 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9452
9bcb3eef
DS
9453 if (dest_p->prefixlen == match.prefixlen) {
9454 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9455 bgp_process(bgp, dest, afi, safi);
d62a17ae 9456 }
9bcb3eef 9457 bgp_dest_unlock_node(dest);
d62a17ae 9458 }
9459 }
9460
9461 return CMD_SUCCESS;
8ad7271d
DS
9462}
9463
b09b5ae0 9464/* one clear bgp command to rule them all */
718e3744 9465DEFUN (clear_ip_bgp_all,
9466 clear_ip_bgp_all_cmd,
3cb14f26 9467 "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 9468 CLEAR_STR
9469 IP_STR
9470 BGP_STR
838758ac 9471 BGP_INSTANCE_HELP_STR
510afcd6 9472 BGP_AFI_HELP_STR
fd5e7b70 9473 "Address Family\n"
510afcd6 9474 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 9475 "Address Family modifier\n"
b09b5ae0 9476 "Clear all peers\n"
453c92f6 9477 "BGP IPv4 neighbor to clear\n"
a80beece 9478 "BGP IPv6 neighbor to clear\n"
838758ac 9479 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9480 "Clear peers with the AS number\n"
9481 "Clear all external peers\n"
718e3744 9482 "Clear all members of peer-group\n"
b09b5ae0 9483 "BGP peer-group name\n"
b09b5ae0
DW
9484 BGP_SOFT_STR
9485 BGP_SOFT_IN_STR
b09b5ae0
DW
9486 BGP_SOFT_OUT_STR
9487 BGP_SOFT_IN_STR
9488 "Push out prefix-list ORF and do inbound soft reconfig\n"
3cb14f26
DS
9489 BGP_SOFT_OUT_STR
9490 "Reset message statistics\n")
718e3744 9491{
d62a17ae 9492 char *vrf = NULL;
9493
dc912615
DS
9494 afi_t afi = AFI_UNSPEC;
9495 safi_t safi = SAFI_UNSPEC;
d62a17ae 9496 enum clear_sort clr_sort = clear_peer;
9497 enum bgp_clear_type clr_type;
9498 char *clr_arg = NULL;
9499
9500 int idx = 0;
9501
9502 /* clear [ip] bgp */
9503 if (argv_find(argv, argc, "ip", &idx))
9504 afi = AFI_IP;
9505
9a8bdf1c
PG
9506 /* [<vrf> VIEWVRFNAME] */
9507 if (argv_find(argv, argc, "vrf", &idx)) {
9508 vrf = argv[idx + 1]->arg;
9509 idx += 2;
9510 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9511 vrf = NULL;
9512 } else if (argv_find(argv, argc, "view", &idx)) {
9513 /* [<view> VIEWVRFNAME] */
d62a17ae 9514 vrf = argv[idx + 1]->arg;
9515 idx += 2;
9516 }
d62a17ae 9517 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9518 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9519 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9520
d7b9898c 9521 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 9522 if (argv_find(argv, argc, "*", &idx)) {
9523 clr_sort = clear_all;
9524 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9525 clr_sort = clear_peer;
9526 clr_arg = argv[idx]->arg;
9527 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9528 clr_sort = clear_peer;
9529 clr_arg = argv[idx]->arg;
9530 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9531 clr_sort = clear_group;
9532 idx++;
9533 clr_arg = argv[idx]->arg;
d7b9898c 9534 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 9535 clr_sort = clear_peer;
9536 clr_arg = argv[idx]->arg;
8fa7d444
DS
9537 } else if (argv_find(argv, argc, "WORD", &idx)) {
9538 clr_sort = clear_peer;
9539 clr_arg = argv[idx]->arg;
d62a17ae 9540 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9541 clr_sort = clear_as;
9542 clr_arg = argv[idx]->arg;
9543 } else if (argv_find(argv, argc, "external", &idx)) {
9544 clr_sort = clear_external;
9545 }
9546
3cb14f26 9547 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
d62a17ae 9548 if (argv_find(argv, argc, "soft", &idx)) {
9549 if (argv_find(argv, argc, "in", &idx)
9550 || argv_find(argv, argc, "out", &idx))
9551 clr_type = strmatch(argv[idx]->text, "in")
9552 ? BGP_CLEAR_SOFT_IN
9553 : BGP_CLEAR_SOFT_OUT;
9554 else
9555 clr_type = BGP_CLEAR_SOFT_BOTH;
9556 } else if (argv_find(argv, argc, "in", &idx)) {
9557 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9558 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9559 : BGP_CLEAR_SOFT_IN;
9560 } else if (argv_find(argv, argc, "out", &idx)) {
9561 clr_type = BGP_CLEAR_SOFT_OUT;
3cb14f26
DS
9562 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9563 clr_type = BGP_CLEAR_MESSAGE_STATS;
d62a17ae 9564 } else
9565 clr_type = BGP_CLEAR_SOFT_NONE;
9566
1ca2fd11 9567 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 9568}
01080f7c 9569
8ad7271d
DS
9570DEFUN (clear_ip_bgp_prefix,
9571 clear_ip_bgp_prefix_cmd,
18c57037 9572 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
9573 CLEAR_STR
9574 IP_STR
9575 BGP_STR
838758ac 9576 BGP_INSTANCE_HELP_STR
8ad7271d 9577 "Clear bestpath and re-advertise\n"
0c7b1b01 9578 "IPv4 prefix\n")
8ad7271d 9579{
d62a17ae 9580 char *vrf = NULL;
9581 char *prefix = NULL;
8ad7271d 9582
d62a17ae 9583 int idx = 0;
01080f7c 9584
d62a17ae 9585 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
9586 if (argv_find(argv, argc, "vrf", &idx)) {
9587 vrf = argv[idx + 1]->arg;
9588 idx += 2;
9589 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9590 vrf = NULL;
9591 } else if (argv_find(argv, argc, "view", &idx)) {
9592 /* [<view> VIEWVRFNAME] */
9593 vrf = argv[idx + 1]->arg;
9594 idx += 2;
9595 }
0c7b1b01 9596
d62a17ae 9597 prefix = argv[argc - 1]->arg;
8ad7271d 9598
d62a17ae 9599 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 9600}
8ad7271d 9601
b09b5ae0
DW
9602DEFUN (clear_bgp_ipv6_safi_prefix,
9603 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 9604 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9605 CLEAR_STR
3a2d747c 9606 IP_STR
718e3744 9607 BGP_STR
8c3deaae 9608 "Address Family\n"
46f296b4 9609 BGP_SAFI_HELP_STR
b09b5ae0 9610 "Clear bestpath and re-advertise\n"
0c7b1b01 9611 "IPv6 prefix\n")
718e3744 9612{
9b475e76
PG
9613 int idx_safi = 0;
9614 int idx_ipv6_prefix = 0;
9615 safi_t safi = SAFI_UNICAST;
9616 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9617 argv[idx_ipv6_prefix]->arg : NULL;
9618
9619 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 9620 return bgp_clear_prefix(
9b475e76
PG
9621 vty, NULL, prefix, AFI_IP6,
9622 safi, NULL);
838758ac 9623}
01080f7c 9624
b09b5ae0
DW
9625DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9626 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 9627 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9628 CLEAR_STR
3a2d747c 9629 IP_STR
718e3744 9630 BGP_STR
838758ac 9631 BGP_INSTANCE_HELP_STR
8c3deaae 9632 "Address Family\n"
46f296b4 9633 BGP_SAFI_HELP_STR
b09b5ae0 9634 "Clear bestpath and re-advertise\n"
0c7b1b01 9635 "IPv6 prefix\n")
718e3744 9636{
9b475e76 9637 int idx_safi = 0;
9a8bdf1c 9638 int idx_vrfview = 0;
9b475e76
PG
9639 int idx_ipv6_prefix = 0;
9640 safi_t safi = SAFI_UNICAST;
9641 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9642 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 9643 char *vrfview = NULL;
9b475e76 9644
9a8bdf1c
PG
9645 /* [<view|vrf> VIEWVRFNAME] */
9646 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9647 vrfview = argv[idx_vrfview + 1]->arg;
9648 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9649 vrfview = NULL;
9650 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9651 /* [<view> VIEWVRFNAME] */
9652 vrfview = argv[idx_vrfview + 1]->arg;
9653 }
9b475e76
PG
9654 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9655
d62a17ae 9656 return bgp_clear_prefix(
9b475e76
PG
9657 vty, vrfview, prefix,
9658 AFI_IP6, safi, NULL);
718e3744 9659}
9660
b09b5ae0
DW
9661DEFUN (show_bgp_views,
9662 show_bgp_views_cmd,
d6e3c605 9663 "show [ip] bgp views",
b09b5ae0 9664 SHOW_STR
d6e3c605 9665 IP_STR
01080f7c 9666 BGP_STR
b09b5ae0 9667 "Show the defined BGP views\n")
01080f7c 9668{
d62a17ae 9669 struct list *inst = bm->bgp;
9670 struct listnode *node;
9671 struct bgp *bgp;
01080f7c 9672
d62a17ae 9673 vty_out(vty, "Defined BGP views:\n");
9674 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9675 /* Skip VRFs. */
9676 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9677 continue;
9678 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9679 bgp->as);
9680 }
e52702f2 9681
d62a17ae 9682 return CMD_SUCCESS;
e0081f70
ML
9683}
9684
8386ac43 9685DEFUN (show_bgp_vrfs,
9686 show_bgp_vrfs_cmd,
d6e3c605 9687 "show [ip] bgp vrfs [json]",
8386ac43 9688 SHOW_STR
d6e3c605 9689 IP_STR
8386ac43 9690 BGP_STR
9691 "Show BGP VRFs\n"
9973d184 9692 JSON_STR)
8386ac43 9693{
fe1dc5a3 9694 char buf[ETHER_ADDR_STRLEN];
d62a17ae 9695 struct list *inst = bm->bgp;
9696 struct listnode *node;
9697 struct bgp *bgp;
9f049418 9698 bool uj = use_json(argc, argv);
d62a17ae 9699 json_object *json = NULL;
9700 json_object *json_vrfs = NULL;
9701 int count = 0;
d62a17ae 9702
d62a17ae 9703 if (uj) {
9704 json = json_object_new_object();
9705 json_vrfs = json_object_new_object();
9706 }
9707
9708 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9709 const char *name, *type;
9710 struct peer *peer;
7fe96307 9711 struct listnode *node2, *nnode2;
d62a17ae 9712 int peers_cfg, peers_estb;
9713 json_object *json_vrf = NULL;
d62a17ae 9714
9715 /* Skip Views. */
9716 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9717 continue;
9718
9719 count++;
efb4077a 9720 if (!uj && count == 1) {
fe1dc5a3 9721 vty_out(vty,
efb4077a 9722 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 9723 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
9724 "#PeersEstb", "Name");
9725 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9726 "L3-VNI", "RouterMAC", "Interface");
9727 }
d62a17ae 9728
9729 peers_cfg = peers_estb = 0;
9730 if (uj)
9731 json_vrf = json_object_new_object();
9732
9733
7fe96307 9734 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 9735 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9736 continue;
9737 peers_cfg++;
feb17238 9738 if (peer_established(peer))
d62a17ae 9739 peers_estb++;
9740 }
9741
9742 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 9743 name = VRF_DEFAULT_NAME;
d62a17ae 9744 type = "DFLT";
9745 } else {
9746 name = bgp->name;
9747 type = "VRF";
9748 }
9749
a8bf7d9c 9750
d62a17ae 9751 if (uj) {
a4d82a8a
PZ
9752 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9753 ? -1
9754 : (int64_t)bgp->vrf_id;
23d0a753
DA
9755 char buf[BUFSIZ] = {0};
9756
d62a17ae 9757 json_object_string_add(json_vrf, "type", type);
9758 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
c949c771
DA
9759 json_object_string_addf(json_vrf, "routerId", "%pI4",
9760 &bgp->router_id);
d62a17ae 9761 json_object_int_add(json_vrf, "numConfiguredPeers",
9762 peers_cfg);
9763 json_object_int_add(json_vrf, "numEstablishedPeers",
9764 peers_estb);
9765
fe1dc5a3 9766 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
9767 json_object_string_add(
9768 json_vrf, "rmac",
9769 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
9770 json_object_string_add(json_vrf, "interface",
9771 ifindex2ifname(bgp->l3vni_svi_ifindex,
9772 bgp->vrf_id));
d62a17ae 9773 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 9774 } else {
23d0a753 9775 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
9776 type,
9777 bgp->vrf_id == VRF_UNKNOWN ? -1
9778 : (int)bgp->vrf_id,
23d0a753 9779 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
9780 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
9781 bgp->l3vni,
9782 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
9783 ifindex2ifname(bgp->l3vni_svi_ifindex,
9784 bgp->vrf_id));
9785 }
d62a17ae 9786 }
9787
9788 if (uj) {
9789 json_object_object_add(json, "vrfs", json_vrfs);
9790
9791 json_object_int_add(json, "totalVrfs", count);
9792
75eeda93 9793 vty_json(vty, json);
d62a17ae 9794 } else {
9795 if (count)
9796 vty_out(vty,
9797 "\nTotal number of VRFs (including default): %d\n",
9798 count);
9799 }
9800
9801 return CMD_SUCCESS;
8386ac43 9802}
9803
48ecf8f5
DS
9804DEFUN (show_bgp_mac_hash,
9805 show_bgp_mac_hash_cmd,
9806 "show bgp mac hash",
9807 SHOW_STR
9808 BGP_STR
9809 "Mac Address\n"
9810 "Mac Address database\n")
9811{
9812 bgp_mac_dump_table(vty);
9813
9814 return CMD_SUCCESS;
9815}
acf71666 9816
e3b78da8 9817static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 9818{
0291c246 9819 struct vty *vty = (struct vty *)args;
e3b78da8 9820 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 9821
23d0a753 9822 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
9823}
9824
9825static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
9826{
9827 vty_out(vty, "self nexthop database:\n");
af97a18b 9828 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
9829
9830 vty_out(vty, "Tunnel-ip database:\n");
9831 hash_iterate(bgp->tip_hash,
e3b78da8 9832 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
9833 vty);
9834}
9835
15c81ca4
DS
9836DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
9837 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
9838 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
9839 "martian next-hops\n"
9840 "martian next-hop database\n")
acf71666 9841{
0291c246 9842 struct bgp *bgp = NULL;
15c81ca4 9843 int idx = 0;
9a8bdf1c
PG
9844 char *name = NULL;
9845
9846 /* [<vrf> VIEWVRFNAME] */
9847 if (argv_find(argv, argc, "vrf", &idx)) {
9848 name = argv[idx + 1]->arg;
9849 if (name && strmatch(name, VRF_DEFAULT_NAME))
9850 name = NULL;
9851 } else if (argv_find(argv, argc, "view", &idx))
9852 /* [<view> VIEWVRFNAME] */
9853 name = argv[idx + 1]->arg;
9854 if (name)
9855 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
9856 else
9857 bgp = bgp_get_default();
acf71666 9858
acf71666
MK
9859 if (!bgp) {
9860 vty_out(vty, "%% No BGP process is configured\n");
9861 return CMD_WARNING;
9862 }
9863 bgp_show_martian_nexthops(vty, bgp);
9864
9865 return CMD_SUCCESS;
9866}
9867
f412b39a 9868DEFUN (show_bgp_memory,
4bf6a362 9869 show_bgp_memory_cmd,
7fa12b13 9870 "show [ip] bgp memory",
4bf6a362 9871 SHOW_STR
3a2d747c 9872 IP_STR
4bf6a362
PJ
9873 BGP_STR
9874 "Global BGP memory statistics\n")
9875{
d62a17ae 9876 char memstrbuf[MTYPE_MEMSTR_LEN];
9877 unsigned long count;
9878
9879 /* RIB related usage stats */
9880 count = mtype_stats_alloc(MTYPE_BGP_NODE);
9881 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
9882 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 9883 count * sizeof(struct bgp_dest)));
d62a17ae 9884
9885 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
9886 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
9887 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 9888 count * sizeof(struct bgp_path_info)));
d62a17ae 9889 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
9890 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
9891 count,
4b7e6066
DS
9892 mtype_memstr(
9893 memstrbuf, sizeof(memstrbuf),
9894 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 9895
9896 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
9897 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
9898 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9899 count * sizeof(struct bgp_static)));
9900
9901 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
9902 vty_out(vty, "%ld Packets, using %s of memory\n", count,
9903 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9904 count * sizeof(struct bpacket)));
9905
9906 /* Adj-In/Out */
9907 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
9908 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
9909 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9910 count * sizeof(struct bgp_adj_in)));
9911 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
9912 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
9913 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9914 count * sizeof(struct bgp_adj_out)));
9915
9916 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
9917 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
9918 count,
9919 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9920 count * sizeof(struct bgp_nexthop_cache)));
9921
9922 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
9923 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
9924 count,
9925 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9926 count * sizeof(struct bgp_damp_info)));
9927
9928 /* Attributes */
9929 count = attr_count();
9930 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
9931 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9932 count * sizeof(struct attr)));
9933
9934 if ((count = attr_unknown_count()))
9935 vty_out(vty, "%ld unknown attributes\n", count);
9936
9937 /* AS_PATH attributes */
9938 count = aspath_count();
9939 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
9940 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9941 count * sizeof(struct aspath)));
9942
9943 count = mtype_stats_alloc(MTYPE_AS_SEG);
9944 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
9945 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9946 count * sizeof(struct assegment)));
9947
9948 /* Other attributes */
9949 if ((count = community_count()))
9950 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9951 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9952 count * sizeof(struct community)));
d62a17ae 9953 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
9954 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9955 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9956 count * sizeof(struct ecommunity)));
d62a17ae 9957 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
9958 vty_out(vty,
9959 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
9960 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9961 count * sizeof(struct lcommunity)));
d62a17ae 9962
9963 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
9964 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
9965 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9966 count * sizeof(struct cluster_list)));
9967
9968 /* Peer related usage */
9969 count = mtype_stats_alloc(MTYPE_BGP_PEER);
9970 vty_out(vty, "%ld peers, using %s of memory\n", count,
9971 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9972 count * sizeof(struct peer)));
9973
9974 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
9975 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
9976 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9977 count * sizeof(struct peer_group)));
9978
9979 /* Other */
d62a17ae 9980 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
9981 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
9982 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9983 count * sizeof(regex_t)));
d62a17ae 9984 return CMD_SUCCESS;
4bf6a362 9985}
fee0f4c6 9986
57a9c8a8
DS
9987static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
9988{
9989 json_object *bestpath = json_object_new_object();
9990
892fedb6 9991 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
9992 json_object_string_add(bestpath, "asPath", "ignore");
9993
892fedb6 9994 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
9995 json_object_string_add(bestpath, "asPath", "confed");
9996
892fedb6
DA
9997 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
9998 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 9999 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10000 "as-set");
10001 else
a4d82a8a 10002 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10003 "true");
10004 } else
a4d82a8a 10005 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10006
ee88563a
JM
10007 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10008 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10009
892fedb6 10010 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10011 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10012 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10013 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10014 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10015 json_object_string_add(bestpath, "med", "confed");
892fedb6 10016 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10017 json_object_string_add(bestpath, "med",
10018 "missing-as-worst");
10019 else
10020 json_object_string_add(bestpath, "med", "true");
10021 }
10022
10023 json_object_object_add(json, "bestPath", bestpath);
10024}
10025
3577f1c5
DD
10026/* Print the error code/subcode for why the peer is down */
10027static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10028 json_object *json_peer, bool use_json)
10029{
10030 const char *code_str;
10031 const char *subcode_str;
10032
10033 if (use_json) {
10034 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10035 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10036 char errorcodesubcode_hexstr[5];
10037 char errorcodesubcode_str[256];
10038
10039 code_str = bgp_notify_code_str(peer->notify.code);
10040 subcode_str = bgp_notify_subcode_str(
10041 peer->notify.code,
10042 peer->notify.subcode);
10043
772270f3
QY
10044 snprintf(errorcodesubcode_hexstr,
10045 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10046 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10047 json_object_string_add(json_peer,
10048 "lastErrorCodeSubcode",
10049 errorcodesubcode_hexstr);
10050 snprintf(errorcodesubcode_str, 255, "%s%s",
10051 code_str, subcode_str);
10052 json_object_string_add(json_peer,
10053 "lastNotificationReason",
10054 errorcodesubcode_str);
10055 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10056 && peer->notify.code == BGP_NOTIFY_CEASE
10057 && (peer->notify.subcode
10058 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10059 || peer->notify.subcode
10060 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10061 && peer->notify.length) {
10062 char msgbuf[1024];
10063 const char *msg_str;
10064
10065 msg_str = bgp_notify_admin_message(
10066 msgbuf, sizeof(msgbuf),
10067 (uint8_t *)peer->notify.data,
10068 peer->notify.length);
10069 if (msg_str)
10070 json_object_string_add(
10071 json_peer,
10072 "lastShutdownDescription",
10073 msg_str);
10074 }
10075
c258527b 10076 }
3577f1c5
DD
10077 json_object_string_add(json_peer, "lastResetDueTo",
10078 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10079 json_object_int_add(json_peer, "lastResetCode",
10080 peer->last_reset);
3577f1c5
DD
10081 } else {
10082 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10083 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10084 code_str = bgp_notify_code_str(peer->notify.code);
10085 subcode_str =
10086 bgp_notify_subcode_str(peer->notify.code,
10087 peer->notify.subcode);
10088 vty_out(vty, " Notification %s (%s%s)\n",
10089 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10090 ? "sent"
10091 : "received",
10092 code_str, subcode_str);
10093 } else {
e91c24c8 10094 vty_out(vty, " %s\n",
3577f1c5
DD
10095 peer_down_str[(int)peer->last_reset]);
10096 }
10097 }
10098}
10099
10100static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10101 safi_t safi)
10102{
feb17238 10103 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
3577f1c5
DD
10104}
10105
10106static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10107 struct peer *peer, json_object *json_peer,
10108 int max_neighbor_width, bool use_json)
10109{
10110 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10111 int len;
10112
10113 if (use_json) {
10114 if (peer_dynamic_neighbor(peer))
10115 json_object_boolean_true_add(json_peer,
10116 "dynamicPeer");
10117 if (peer->hostname)
10118 json_object_string_add(json_peer, "hostname",
10119 peer->hostname);
10120
10121 if (peer->domainname)
10122 json_object_string_add(json_peer, "domainname",
10123 peer->domainname);
10124 json_object_int_add(json_peer, "connectionsEstablished",
10125 peer->established);
10126 json_object_int_add(json_peer, "connectionsDropped",
10127 peer->dropped);
10128 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10129 use_json, json_peer);
feb17238 10130 if (peer_established(peer))
3577f1c5
DD
10131 json_object_string_add(json_peer, "lastResetDueTo",
10132 "AFI/SAFI Not Negotiated");
10133 else
10134 bgp_show_peer_reset(NULL, peer, json_peer, true);
10135 } else {
10136 dn_flag[1] = '\0';
10137 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10138 if (peer->hostname
892fedb6 10139 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10140 len = vty_out(vty, "%s%s(%s)", dn_flag,
10141 peer->hostname, peer->host);
10142 else
10143 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10144
10145 /* pad the neighbor column with spaces */
10146 if (len < max_neighbor_width)
10147 vty_out(vty, "%*s", max_neighbor_width - len,
10148 " ");
e91c24c8 10149 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10150 peer->dropped,
10151 peer_uptime(peer->uptime, timebuf,
10152 BGP_UPTIME_LEN, 0, NULL));
feb17238 10153 if (peer_established(peer))
3577f1c5
DD
10154 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10155 else
10156 bgp_show_peer_reset(vty, peer, NULL,
10157 false);
10158 }
10159}
c258527b 10160
565e9ddd 10161/* Strip peer's description to the given size. */
cb75bb31
DA
10162static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10163{
10164 static char stripped[BUFSIZ];
cb75bb31
DA
10165 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10166
cb75bb31
DA
10167 strlcpy(stripped, desc, len + 1);
10168
10169 return stripped;
10170}
3577f1c5 10171
8c1d4cd5
LS
10172/* Determine whether var peer should be filtered out of the summary. */
10173static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10174 struct peer *fpeer, int as_type,
10175 as_t as)
10176{
10177
10178 /* filter neighbor XXXX */
10179 if (fpeer && fpeer != peer)
10180 return true;
10181
10182 /* filter remote-as (internal|external) */
10183 if (as_type != AS_UNSPECIFIED) {
10184 if (peer->as_type == AS_SPECIFIED) {
10185 if (as_type == AS_INTERNAL) {
10186 if (peer->as != peer->local_as)
10187 return true;
10188 } else if (peer->as == peer->local_as)
10189 return true;
10190 } else if (as_type != peer->as_type)
10191 return true;
10192 } else if (as && as != peer->as) /* filter remote-as XXX */
10193 return true;
10194
10195 return false;
10196}
10197
565e9ddd
DA
10198/* Show BGP peer's summary information.
10199 *
10200 * Peer's description is stripped according to if `wide` option is given
10201 * or not.
10202 *
10203 * When adding new columns to `show bgp summary` output, please make
10204 * sure `Desc` is the lastest column to show because it can contain
10205 * whitespaces and the whole output will be tricky.
10206 */
d62a17ae 10207static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 10208 struct peer *fpeer, int as_type, as_t as,
96c81f66 10209 uint16_t show_flags)
d62a17ae 10210{
10211 struct peer *peer;
10212 struct listnode *node, *nnode;
10213 unsigned int count = 0, dn_count = 0;
10214 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10215 char neighbor_buf[VTY_BUFSIZ];
10216 int neighbor_col_default_width = 16;
3577f1c5 10217 int len, failed_count = 0;
ce1944f0 10218 unsigned int filtered_count = 0;
d62a17ae 10219 int max_neighbor_width = 0;
10220 int pfx_rcd_safi;
3c13337d 10221 json_object *json = NULL;
d62a17ae 10222 json_object *json_peer = NULL;
10223 json_object *json_peers = NULL;
50e05855 10224 struct peer_af *paf;
d3ada366 10225 struct bgp_filter *filter;
85eeb029
DA
10226 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10227 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10228 bool show_established =
10229 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10230 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
96c81f66 10231 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
d62a17ae 10232
10233 /* labeled-unicast routes are installed in the unicast table so in order
10234 * to
10235 * display the correct PfxRcd value we must look at SAFI_UNICAST
10236 */
3577f1c5 10237
d62a17ae 10238 if (safi == SAFI_LABELED_UNICAST)
10239 pfx_rcd_safi = SAFI_UNICAST;
10240 else
10241 pfx_rcd_safi = safi;
10242
10243 if (use_json) {
3c13337d 10244 json = json_object_new_object();
d62a17ae 10245 json_peers = json_object_new_object();
3577f1c5 10246 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10247 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10248 as_type, as)) {
ce1944f0 10249 filtered_count++;
8c1d4cd5
LS
10250 count++;
10251 continue;
10252 }
10253
3577f1c5
DD
10254 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10255 continue;
10256
10257 if (peer->afc[afi][safi]) {
10258 /* See if we have at least a single failed peer */
10259 if (bgp_has_peer_failed(peer, afi, safi))
10260 failed_count++;
10261 count++;
10262 }
10263 if (peer_dynamic_neighbor(peer))
10264 dn_count++;
10265 }
c258527b 10266
d62a17ae 10267 } else {
10268 /* Loop over all neighbors that will be displayed to determine
10269 * how many
10270 * characters are needed for the Neighbor column
10271 */
10272 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10273 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10274 as_type, as)) {
ce1944f0 10275 filtered_count++;
8c1d4cd5
LS
10276 count++;
10277 continue;
10278 }
10279
d62a17ae 10280 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10281 continue;
10282
10283 if (peer->afc[afi][safi]) {
10284 memset(dn_flag, '\0', sizeof(dn_flag));
10285 if (peer_dynamic_neighbor(peer))
10286 dn_flag[0] = '*';
10287
10288 if (peer->hostname
892fedb6
DA
10289 && CHECK_FLAG(bgp->flags,
10290 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10291 snprintf(neighbor_buf,
10292 sizeof(neighbor_buf),
10293 "%s%s(%s) ", dn_flag,
10294 peer->hostname, peer->host);
d62a17ae 10295 else
772270f3
QY
10296 snprintf(neighbor_buf,
10297 sizeof(neighbor_buf), "%s%s ",
10298 dn_flag, peer->host);
d62a17ae 10299
10300 len = strlen(neighbor_buf);
10301
10302 if (len > max_neighbor_width)
10303 max_neighbor_width = len;
c258527b 10304
3577f1c5
DD
10305 /* See if we have at least a single failed peer */
10306 if (bgp_has_peer_failed(peer, afi, safi))
10307 failed_count++;
10308 count++;
d62a17ae 10309 }
10310 }
f933309e 10311
d62a17ae 10312 /* Originally we displayed the Neighbor column as 16
10313 * characters wide so make that the default
10314 */
10315 if (max_neighbor_width < neighbor_col_default_width)
10316 max_neighbor_width = neighbor_col_default_width;
10317 }
f933309e 10318
3577f1c5
DD
10319 if (show_failed && !failed_count) {
10320 if (use_json) {
10321 json_object_int_add(json, "failedPeersCount", 0);
10322 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10323 json_object_int_add(json, "totalPeers", count);
3577f1c5 10324
75eeda93 10325 vty_json(vty, json);
3577f1c5
DD
10326 } else {
10327 vty_out(vty, "%% No failed BGP neighbors found\n");
3577f1c5
DD
10328 }
10329 return CMD_SUCCESS;
10330 }
c258527b 10331
3577f1c5 10332 count = 0; /* Reset the value as its used again */
ce1944f0 10333 filtered_count = 0;
800867d8 10334 dn_count = 0;
d62a17ae 10335 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10336 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10337 continue;
10338
ea47320b
DL
10339 if (!peer->afc[afi][safi])
10340 continue;
d62a17ae 10341
ea47320b
DL
10342 if (!count) {
10343 unsigned long ents;
10344 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10345 int64_t vrf_id_ui;
d62a17ae 10346
a4d82a8a
PZ
10347 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10348 ? -1
10349 : (int64_t)bgp->vrf_id;
ea47320b
DL
10350
10351 /* Usage summary and header */
10352 if (use_json) {
c949c771
DA
10353 json_object_string_addf(json, "routerId",
10354 "%pI4",
10355 &bgp->router_id);
60466a63
QY
10356 json_object_int_add(json, "as", bgp->as);
10357 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10358 json_object_string_add(
10359 json, "vrfName",
10360 (bgp->inst_type
10361 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10362 ? VRF_DEFAULT_NAME
ea47320b
DL
10363 : bgp->name);
10364 } else {
10365 vty_out(vty,
23d0a753
DA
10366 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10367 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10368 bgp->vrf_id == VRF_UNKNOWN
10369 ? -1
10370 : (int)bgp->vrf_id);
ea47320b
DL
10371 vty_out(vty, "\n");
10372 }
d62a17ae 10373
ea47320b 10374 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10375 if (use_json) {
ea47320b 10376 json_object_int_add(
60466a63 10377 json, "updateDelayLimit",
ea47320b 10378 bgp->v_update_delay);
d62a17ae 10379
ea47320b
DL
10380 if (bgp->v_update_delay
10381 != bgp->v_establish_wait)
d62a17ae 10382 json_object_int_add(
10383 json,
ea47320b
DL
10384 "updateDelayEstablishWait",
10385 bgp->v_establish_wait);
d62a17ae 10386
60466a63 10387 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10388 json_object_string_add(
10389 json,
10390 "updateDelayFirstNeighbor",
10391 bgp->update_delay_begin_time);
10392 json_object_boolean_true_add(
10393 json,
10394 "updateDelayInProgress");
10395 } else {
10396 if (bgp->update_delay_over) {
d62a17ae 10397 json_object_string_add(
10398 json,
10399 "updateDelayFirstNeighbor",
10400 bgp->update_delay_begin_time);
ea47320b 10401 json_object_string_add(
d62a17ae 10402 json,
ea47320b
DL
10403 "updateDelayBestpathResumed",
10404 bgp->update_delay_end_time);
10405 json_object_string_add(
d62a17ae 10406 json,
ea47320b
DL
10407 "updateDelayZebraUpdateResume",
10408 bgp->update_delay_zebra_resume_time);
10409 json_object_string_add(
10410 json,
10411 "updateDelayPeerUpdateResume",
10412 bgp->update_delay_peers_resume_time);
d62a17ae 10413 }
ea47320b
DL
10414 }
10415 } else {
10416 vty_out(vty,
10417 "Read-only mode update-delay limit: %d seconds\n",
10418 bgp->v_update_delay);
10419 if (bgp->v_update_delay
10420 != bgp->v_establish_wait)
d62a17ae 10421 vty_out(vty,
ea47320b
DL
10422 " Establish wait: %d seconds\n",
10423 bgp->v_establish_wait);
d62a17ae 10424
60466a63 10425 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10426 vty_out(vty,
10427 " First neighbor established: %s\n",
10428 bgp->update_delay_begin_time);
10429 vty_out(vty,
10430 " Delay in progress\n");
10431 } else {
10432 if (bgp->update_delay_over) {
d62a17ae 10433 vty_out(vty,
10434 " First neighbor established: %s\n",
10435 bgp->update_delay_begin_time);
10436 vty_out(vty,
ea47320b
DL
10437 " Best-paths resumed: %s\n",
10438 bgp->update_delay_end_time);
10439 vty_out(vty,
10440 " zebra update resumed: %s\n",
10441 bgp->update_delay_zebra_resume_time);
10442 vty_out(vty,
10443 " peers update resumed: %s\n",
10444 bgp->update_delay_peers_resume_time);
d62a17ae 10445 }
10446 }
10447 }
ea47320b 10448 }
d62a17ae 10449
ea47320b
DL
10450 if (use_json) {
10451 if (bgp_maxmed_onstartup_configured(bgp)
10452 && bgp->maxmed_active)
10453 json_object_boolean_true_add(
60466a63 10454 json, "maxMedOnStartup");
ea47320b
DL
10455 if (bgp->v_maxmed_admin)
10456 json_object_boolean_true_add(
60466a63 10457 json, "maxMedAdministrative");
d62a17ae 10458
ea47320b
DL
10459 json_object_int_add(
10460 json, "tableVersion",
60466a63 10461 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 10462
60466a63
QY
10463 ents = bgp_table_count(bgp->rib[afi][safi]);
10464 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
10465 json_object_int_add(
10466 json, "ribMemory",
9bcb3eef 10467 ents * sizeof(struct bgp_dest));
d62a17ae 10468
210ec2a0 10469 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
10470 json_object_int_add(json, "peerCount", ents);
10471 json_object_int_add(json, "peerMemory",
10472 ents * sizeof(struct peer));
d62a17ae 10473
ea47320b
DL
10474 if ((ents = listcount(bgp->group))) {
10475 json_object_int_add(
60466a63 10476 json, "peerGroupCount", ents);
ea47320b
DL
10477 json_object_int_add(
10478 json, "peerGroupMemory",
996c9314
LB
10479 ents * sizeof(struct
10480 peer_group));
ea47320b 10481 }
d62a17ae 10482
ea47320b
DL
10483 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10484 BGP_CONFIG_DAMPENING))
10485 json_object_boolean_true_add(
60466a63 10486 json, "dampeningEnabled");
ea47320b 10487 } else {
96c81f66
LS
10488 if (!show_terse) {
10489 if (bgp_maxmed_onstartup_configured(bgp)
10490 && bgp->maxmed_active)
10491 vty_out(vty,
10492 "Max-med on-startup active\n");
10493 if (bgp->v_maxmed_admin)
10494 vty_out(vty,
10495 "Max-med administrative active\n");
d62a17ae 10496
96c81f66
LS
10497 vty_out(vty,
10498 "BGP table version %" PRIu64
10499 "\n",
10500 bgp_table_version(
10501 bgp->rib[afi][safi]));
ea47320b 10502
96c81f66
LS
10503 ents = bgp_table_count(
10504 bgp->rib[afi][safi]);
d62a17ae 10505 vty_out(vty,
96c81f66 10506 "RIB entries %ld, using %s of memory\n",
d62a17ae 10507 ents,
10508 mtype_memstr(
10509 memstrbuf,
10510 sizeof(memstrbuf),
96c81f66
LS
10511 ents
10512 * sizeof(
10513 struct
10514 bgp_dest)));
d62a17ae 10515
96c81f66
LS
10516 /* Peer related usage */
10517 ents = bgp->af_peer_count[afi][safi];
10518 vty_out(vty,
10519 "Peers %ld, using %s of memory\n",
10520 ents,
10521 mtype_memstr(
10522 memstrbuf,
10523 sizeof(memstrbuf),
10524 ents
10525 * sizeof(
10526 struct
10527 peer)));
d62a17ae 10528
96c81f66
LS
10529 if ((ents = listcount(bgp->group)))
10530 vty_out(vty,
10531 "Peer groups %ld, using %s of memory\n",
10532 ents,
10533 mtype_memstr(
10534 memstrbuf,
10535 sizeof(memstrbuf),
10536 ents
10537 * sizeof(
10538 struct
10539 peer_group)));
10540
10541 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10542 BGP_CONFIG_DAMPENING))
10543 vty_out(vty,
10544 "Dampening enabled.\n");
10545 }
10546 if (show_failed) {
10547 vty_out(vty, "\n");
10548
10549 /* Subtract 8 here because 'Neighbor' is
10550 * 8 characters */
10551 vty_out(vty, "Neighbor");
10552 vty_out(vty, "%*s",
10553 max_neighbor_width - 8, " ");
85eeb029
DA
10554 vty_out(vty,
10555 BGP_SHOW_SUMMARY_HEADER_FAILED);
96c81f66 10556 }
d62a17ae 10557 }
ea47320b 10558 }
d62a17ae 10559
d55811cc 10560 paf = peer_af_find(peer, afi, safi);
d3ada366 10561 filter = &peer->filter[afi][safi];
db92d226 10562
ea47320b 10563 count++;
3577f1c5
DD
10564 /* Works for both failed & successful cases */
10565 if (peer_dynamic_neighbor(peer))
10566 dn_count++;
d62a17ae 10567
ea47320b 10568 if (use_json) {
3577f1c5 10569 json_peer = NULL;
8c1d4cd5 10570 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
10571 as_type, as)) {
10572 filtered_count++;
8c1d4cd5 10573 continue;
ce1944f0 10574 }
3577f1c5
DD
10575 if (show_failed &&
10576 bgp_has_peer_failed(peer, afi, safi)) {
10577 json_peer = json_object_new_object();
10578 bgp_show_failed_summary(vty, bgp, peer,
10579 json_peer, 0, use_json);
10580 } else if (!show_failed) {
10b49f14 10581 if (show_established
ce1944f0
LS
10582 && bgp_has_peer_failed(peer, afi, safi)) {
10583 filtered_count++;
10b49f14 10584 continue;
ce1944f0 10585 }
10b49f14 10586
3577f1c5
DD
10587 json_peer = json_object_new_object();
10588 if (peer_dynamic_neighbor(peer)) {
10589 json_object_boolean_true_add(json_peer,
10590 "dynamicPeer");
10591 }
d62a17ae 10592
3577f1c5
DD
10593 if (peer->hostname)
10594 json_object_string_add(json_peer, "hostname",
10595 peer->hostname);
10596
10597 if (peer->domainname)
10598 json_object_string_add(json_peer, "domainname",
10599 peer->domainname);
10600
10601 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
10602 json_object_int_add(
10603 json_peer, "localAs",
10604 peer->change_local_as
10605 ? peer->change_local_as
10606 : peer->local_as);
3577f1c5
DD
10607 json_object_int_add(json_peer, "version", 4);
10608 json_object_int_add(json_peer, "msgRcvd",
10609 PEER_TOTAL_RX(peer));
10610 json_object_int_add(json_peer, "msgSent",
10611 PEER_TOTAL_TX(peer));
10612
43aa5965
QY
10613 atomic_size_t outq_count, inq_count;
10614 outq_count = atomic_load_explicit(
10615 &peer->obuf->count,
10616 memory_order_relaxed);
10617 inq_count = atomic_load_explicit(
10618 &peer->ibuf->count,
10619 memory_order_relaxed);
10620
3577f1c5
DD
10621 json_object_int_add(json_peer, "tableVersion",
10622 peer->version[afi][safi]);
10623 json_object_int_add(json_peer, "outq",
43aa5965
QY
10624 outq_count);
10625 json_object_int_add(json_peer, "inq",
10626 inq_count);
3577f1c5
DD
10627 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10628 use_json, json_peer);
10629
3577f1c5
DD
10630 json_object_int_add(json_peer, "pfxRcd",
10631 peer->pcount[afi][pfx_rcd_safi]);
10632
3577f1c5 10633 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
10634 json_object_int_add(
10635 json_peer, "pfxSnt",
10636 (PAF_SUBGRP(paf))->scount);
10637 else
10638 json_object_int_add(json_peer, "pfxSnt",
10639 0);
0e1f8ab5
DA
10640
10641 /* BGP FSM state */
cb9196e7 10642 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
10643 || CHECK_FLAG(peer->bgp->flags,
10644 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
10645 json_object_string_add(json_peer,
10646 "state",
3577f1c5
DD
10647 "Idle (Admin)");
10648 else if (peer->afc_recv[afi][safi])
10649 json_object_string_add(
0e1f8ab5
DA
10650 json_peer, "state",
10651 lookup_msg(bgp_status_msg,
10652 peer->status, NULL));
10653 else if (CHECK_FLAG(
10654 peer->sflags,
10655 PEER_STATUS_PREFIX_OVERFLOW))
10656 json_object_string_add(json_peer,
10657 "state",
3577f1c5
DD
10658 "Idle (PfxCt)");
10659 else
10660 json_object_string_add(
0e1f8ab5
DA
10661 json_peer, "state",
10662 lookup_msg(bgp_status_msg,
10663 peer->status, NULL));
10664
10665 /* BGP peer state */
10666 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10667 || CHECK_FLAG(peer->bgp->flags,
10668 BGP_FLAG_SHUTDOWN))
10669 json_object_string_add(json_peer,
10670 "peerState",
10671 "Admin");
10672 else if (CHECK_FLAG(
10673 peer->sflags,
10674 PEER_STATUS_PREFIX_OVERFLOW))
10675 json_object_string_add(json_peer,
10676 "peerState",
10677 "PfxCt");
10678 else if (CHECK_FLAG(peer->flags,
10679 PEER_FLAG_PASSIVE))
10680 json_object_string_add(json_peer,
10681 "peerState",
10682 "Passive");
10683 else if (CHECK_FLAG(peer->sflags,
10684 PEER_STATUS_NSF_WAIT))
10685 json_object_string_add(json_peer,
10686 "peerState",
10687 "NSF passive");
10688 else if (CHECK_FLAG(
10689 peer->bgp->flags,
10690 BGP_FLAG_EBGP_REQUIRES_POLICY)
10691 && (!bgp_inbound_policy_exists(peer,
10692 filter)
10693 || !bgp_outbound_policy_exists(
10694 peer, filter)))
10695 json_object_string_add(json_peer,
10696 "peerState",
10697 "Policy");
10698 else
10699 json_object_string_add(
10700 json_peer, "peerState", "OK");
10701
200116db
DD
10702 json_object_int_add(json_peer, "connectionsEstablished",
10703 peer->established);
10704 json_object_int_add(json_peer, "connectionsDropped",
10705 peer->dropped);
aa72bd7e
PG
10706 if (peer->desc)
10707 json_object_string_add(
10708 json_peer, "desc", peer->desc);
b4e9dcba 10709 }
3577f1c5
DD
10710 /* Avoid creating empty peer dicts in JSON */
10711 if (json_peer == NULL)
10712 continue;
ea47320b
DL
10713
10714 if (peer->conf_if)
60466a63 10715 json_object_string_add(json_peer, "idType",
ea47320b
DL
10716 "interface");
10717 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
10718 json_object_string_add(json_peer, "idType",
10719 "ipv4");
ea47320b 10720 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
10721 json_object_string_add(json_peer, "idType",
10722 "ipv6");
ea47320b
DL
10723 json_object_object_add(json_peers, peer->host,
10724 json_peer);
10725 } else {
8c1d4cd5 10726 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
10727 as_type, as)) {
10728 filtered_count++;
8c1d4cd5 10729 continue;
ce1944f0 10730 }
3577f1c5
DD
10731 if (show_failed &&
10732 bgp_has_peer_failed(peer, afi, safi)) {
10733 bgp_show_failed_summary(vty, bgp, peer, NULL,
10734 max_neighbor_width,
10735 use_json);
10736 } else if (!show_failed) {
10b49f14 10737 if (show_established
ce1944f0
LS
10738 && bgp_has_peer_failed(peer, afi, safi)) {
10739 filtered_count++;
10b49f14 10740 continue;
ce1944f0 10741 }
96c81f66
LS
10742
10743 if ((count - filtered_count) == 1) {
10744 /* display headline before the first
10745 * neighbor line */
10746 vty_out(vty, "\n");
10747
10748 /* Subtract 8 here because 'Neighbor' is
10749 * 8 characters */
10750 vty_out(vty, "Neighbor");
10751 vty_out(vty, "%*s",
10752 max_neighbor_width - 8, " ");
10753 vty_out(vty,
10754 show_wide
10755 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10756 : BGP_SHOW_SUMMARY_HEADER_ALL);
10757 }
10758
3577f1c5
DD
10759 memset(dn_flag, '\0', sizeof(dn_flag));
10760 if (peer_dynamic_neighbor(peer)) {
10761 dn_flag[0] = '*';
10762 }
d62a17ae 10763
3577f1c5 10764 if (peer->hostname
892fedb6
DA
10765 && CHECK_FLAG(bgp->flags,
10766 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 10767 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
10768 peer->hostname,
10769 peer->host);
d62a17ae 10770 else
3577f1c5
DD
10771 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10772
10773 /* pad the neighbor column with spaces */
10774 if (len < max_neighbor_width)
10775 vty_out(vty, "%*s", max_neighbor_width - len,
10776 " ");
10777
43aa5965
QY
10778 atomic_size_t outq_count, inq_count;
10779 outq_count = atomic_load_explicit(
10780 &peer->obuf->count,
10781 memory_order_relaxed);
10782 inq_count = atomic_load_explicit(
10783 &peer->ibuf->count,
10784 memory_order_relaxed);
10785
85eeb029
DA
10786 if (show_wide)
10787 vty_out(vty,
10788 "4 %10u %10u %9u %9u %8" PRIu64
10789 " %4zu %4zu %8s",
10790 peer->as,
10791 peer->change_local_as
10792 ? peer->change_local_as
10793 : peer->local_as,
10794 PEER_TOTAL_RX(peer),
10795 PEER_TOTAL_TX(peer),
10796 peer->version[afi][safi],
10797 inq_count, outq_count,
10798 peer_uptime(peer->uptime,
10799 timebuf,
10800 BGP_UPTIME_LEN, 0,
10801 NULL));
10802 else
10803 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
10804 " %4zu %4zu %8s",
10805 peer->as, PEER_TOTAL_RX(peer),
10806 PEER_TOTAL_TX(peer),
10807 peer->version[afi][safi],
10808 inq_count, outq_count,
10809 peer_uptime(peer->uptime,
10810 timebuf,
10811 BGP_UPTIME_LEN, 0,
10812 NULL));
3577f1c5 10813
feb17238 10814 if (peer_established(peer)) {
d3ada366
DA
10815 if (peer->afc_recv[afi][safi]) {
10816 if (CHECK_FLAG(
10817 bgp->flags,
10818 BGP_FLAG_EBGP_REQUIRES_POLICY)
10819 && !bgp_inbound_policy_exists(
10820 peer, filter))
10821 vty_out(vty, " %12s",
10822 "(Policy)");
10823 else
10824 vty_out(vty,
6cde4b45 10825 " %12u",
d3ada366
DA
10826 peer->pcount
10827 [afi]
10828 [pfx_rcd_safi]);
10829 } else {
749d0f27 10830 vty_out(vty, " NoNeg");
d3ada366 10831 }
db92d226 10832
d3ada366
DA
10833 if (paf && PAF_SUBGRP(paf)) {
10834 if (CHECK_FLAG(
10835 bgp->flags,
10836 BGP_FLAG_EBGP_REQUIRES_POLICY)
10837 && !bgp_outbound_policy_exists(
10838 peer, filter))
10839 vty_out(vty, " %8s",
10840 "(Policy)");
10841 else
10842 vty_out(vty,
6cde4b45 10843 " %8u",
d3ada366
DA
10844 (PAF_SUBGRP(
10845 paf))
10846 ->scount);
749d0f27
DA
10847 } else {
10848 vty_out(vty, " NoNeg");
d3ada366 10849 }
db92d226 10850 } else {
736b68f3
DS
10851 if (CHECK_FLAG(peer->flags,
10852 PEER_FLAG_SHUTDOWN)
10853 || CHECK_FLAG(peer->bgp->flags,
10854 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
10855 vty_out(vty, " Idle (Admin)");
10856 else if (CHECK_FLAG(
10857 peer->sflags,
10858 PEER_STATUS_PREFIX_OVERFLOW))
10859 vty_out(vty, " Idle (PfxCt)");
10860 else
10861 vty_out(vty, " %12s",
10862 lookup_msg(bgp_status_msg,
10863 peer->status, NULL));
db92d226 10864
6cde4b45 10865 vty_out(vty, " %8u", 0);
3577f1c5 10866 }
565e9ddd
DA
10867 /* Make sure `Desc` column is the lastest in
10868 * the output.
10869 */
aa72bd7e 10870 if (peer->desc)
cb75bb31
DA
10871 vty_out(vty, " %s",
10872 bgp_peer_description_stripped(
85eeb029
DA
10873 peer->desc,
10874 show_wide ? 64 : 20));
aa72bd7e
PG
10875 else
10876 vty_out(vty, " N/A");
3577f1c5 10877 vty_out(vty, "\n");
d62a17ae 10878 }
3577f1c5 10879
d62a17ae 10880 }
10881 }
f933309e 10882
d62a17ae 10883 if (use_json) {
10884 json_object_object_add(json, "peers", json_peers);
3577f1c5 10885 json_object_int_add(json, "failedPeers", failed_count);
ce1944f0
LS
10886 json_object_int_add(json, "displayedPeers",
10887 count - filtered_count);
d62a17ae 10888 json_object_int_add(json, "totalPeers", count);
10889 json_object_int_add(json, "dynamicPeers", dn_count);
10890
3577f1c5
DD
10891 if (!show_failed)
10892 bgp_show_bestpath_json(bgp, json);
57a9c8a8 10893
75eeda93 10894 vty_json(vty, json);
d62a17ae 10895 } else {
ce1944f0 10896 if (count) {
96c81f66
LS
10897 if (filtered_count == count)
10898 vty_out(vty, "\n%% No matching neighbor\n");
10899 else {
10900 if (show_failed)
10901 vty_out(vty, "\nDisplayed neighbors %d",
10902 failed_count);
10903 else if (as_type != AS_UNSPECIFIED || as
10904 || fpeer || show_established)
ce1944f0
LS
10905 vty_out(vty, "\nDisplayed neighbors %d",
10906 count - filtered_count);
96c81f66
LS
10907
10908 vty_out(vty, "\nTotal number of neighbors %d\n",
10909 count);
ce1944f0 10910 }
ce1944f0 10911 } else {
d6ceaca3 10912 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 10913 get_afi_safi_str(afi, safi, false));
d62a17ae 10914 }
b05a1c8b 10915
d6ceaca3 10916 if (dn_count) {
d62a17ae 10917 vty_out(vty, "* - dynamic neighbor\n");
10918 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
10919 dn_count, bgp->dynamic_neighbors_limit);
10920 }
10921 }
1ff9a340 10922
d62a17ae 10923 return CMD_SUCCESS;
718e3744 10924}
10925
d62a17ae 10926static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5 10927 int safi, struct peer *fpeer, int as_type,
96c81f66 10928 as_t as, uint16_t show_flags)
d62a17ae 10929{
10930 int is_first = 1;
10931 int afi_wildcard = (afi == AFI_MAX);
10932 int safi_wildcard = (safi == SAFI_MAX);
10933 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 10934 bool nbr_output = false;
85eeb029 10935 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 10936
10937 if (use_json && is_wildcard)
10938 vty_out(vty, "{\n");
10939 if (afi_wildcard)
10940 afi = 1; /* AFI_IP */
10941 while (afi < AFI_MAX) {
10942 if (safi_wildcard)
10943 safi = 1; /* SAFI_UNICAST */
10944 while (safi < SAFI_MAX) {
318cac96 10945 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 10946 nbr_output = true;
f86897b9 10947
d62a17ae 10948 if (is_wildcard) {
10949 /*
10950 * So limit output to those afi/safi
10951 * pairs that
10952 * actualy have something interesting in
10953 * them
10954 */
10955 if (use_json) {
d62a17ae 10956 if (!is_first)
10957 vty_out(vty, ",\n");
10958 else
10959 is_first = 0;
10960
10961 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
10962 get_afi_safi_str(afi,
10963 safi,
10964 true));
d62a17ae 10965 } else {
6cac2fcc
LS
10966 vty_out(vty,
10967 "\n%s Summary (%s):\n",
5cb5f4d0
DD
10968 get_afi_safi_str(afi,
10969 safi,
6cac2fcc
LS
10970 false),
10971 bgp->name_pretty);
d62a17ae 10972 }
10973 }
8c1d4cd5
LS
10974 bgp_show_summary(vty, bgp, afi, safi, fpeer,
10975 as_type, as, show_flags);
d62a17ae 10976 }
10977 safi++;
d62a17ae 10978 if (!safi_wildcard)
10979 safi = SAFI_MAX;
10980 }
10981 afi++;
ee851c8c 10982 if (!afi_wildcard)
d62a17ae 10983 afi = AFI_MAX;
10984 }
10985
10986 if (use_json && is_wildcard)
10987 vty_out(vty, "}\n");
ca61fd25
DS
10988 else if (!nbr_output) {
10989 if (use_json)
10990 vty_out(vty, "{}\n");
10991 else
6cac2fcc
LS
10992 vty_out(vty, "%% No BGP neighbors found in %s\n",
10993 bgp->name_pretty);
ca61fd25 10994 }
d62a17ae 10995}
10996
10997static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
10998 safi_t safi,
10999 const char *neighbor,
11000 int as_type, as_t as,
96c81f66 11001 uint16_t show_flags)
d62a17ae 11002{
11003 struct listnode *node, *nnode;
11004 struct bgp *bgp;
8c1d4cd5 11005 struct peer *fpeer = NULL;
d62a17ae 11006 int is_first = 1;
9f049418 11007 bool nbr_output = false;
85eeb029 11008 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11009
11010 if (use_json)
11011 vty_out(vty, "{\n");
11012
11013 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11014 nbr_output = true;
d62a17ae 11015 if (use_json) {
d62a17ae 11016 if (!is_first)
11017 vty_out(vty, ",\n");
11018 else
11019 is_first = 0;
11020
11021 vty_out(vty, "\"%s\":",
11022 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11023 ? VRF_DEFAULT_NAME
d62a17ae 11024 : bgp->name);
d62a17ae 11025 }
8c1d4cd5
LS
11026 if (neighbor) {
11027 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11028 use_json);
11029 if (!fpeer)
11030 continue;
11031 }
11032 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11033 as, show_flags);
d62a17ae 11034 }
11035
11036 if (use_json)
11037 vty_out(vty, "}\n");
9f049418
DS
11038 else if (!nbr_output)
11039 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11040}
11041
11042int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5 11043 safi_t safi, const char *neighbor, int as_type,
96c81f66 11044 as_t as, uint16_t show_flags)
d62a17ae 11045{
11046 struct bgp *bgp;
85eeb029 11047 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 11048 struct peer *fpeer = NULL;
d62a17ae 11049
11050 if (name) {
11051 if (strmatch(name, "all")) {
85eeb029 11052 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
11053 neighbor, as_type,
11054 as, show_flags);
d62a17ae 11055 return CMD_SUCCESS;
11056 } else {
11057 bgp = bgp_lookup_by_name(name);
11058
11059 if (!bgp) {
11060 if (use_json)
11061 vty_out(vty, "{}\n");
11062 else
11063 vty_out(vty,
ca61fd25 11064 "%% BGP instance not found\n");
d62a17ae 11065 return CMD_WARNING;
11066 }
11067
8c1d4cd5
LS
11068 if (neighbor) {
11069 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11070 use_json);
11071 if (!fpeer)
11072 return CMD_WARNING;
11073 }
11074 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11075 as_type, as, show_flags);
d62a17ae 11076 return CMD_SUCCESS;
11077 }
11078 }
11079
11080 bgp = bgp_get_default();
11081
8c1d4cd5
LS
11082 if (bgp) {
11083 if (neighbor) {
11084 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11085 use_json);
11086 if (!fpeer)
11087 return CMD_WARNING;
11088 }
11089 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11090 as, show_flags);
11091 } else {
ca61fd25
DS
11092 if (use_json)
11093 vty_out(vty, "{}\n");
11094 else
11095 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11096 return CMD_WARNING;
11097 }
d62a17ae 11098
11099 return CMD_SUCCESS;
4fb25c53
DW
11100}
11101
716b2d8a 11102/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
11103DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11104 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11105 " [" BGP_SAFI_WITH_LABEL_CMD_STR
96c81f66 11106 "]] [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
11107 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11108 BGP_SAFI_WITH_LABEL_HELP_STR
11109 "Display the entries for all address families\n"
11110 "Summary of BGP neighbor status\n"
11111 "Show only sessions in Established state\n"
11112 "Show only sessions not in Established state\n"
11113 "Show only the specified neighbor session\n"
11114 "Neighbor to display information about\n"
11115 "Neighbor to display information about\n"
11116 "Neighbor on BGP configured interface\n"
11117 "Show only the specified remote AS sessions\n"
11118 "AS number\n"
11119 "Internal (iBGP) AS sessions\n"
11120 "External (eBGP) AS sessions\n"
96c81f66 11121 "Shorten the information on BGP instances\n"
8c1d4cd5 11122 "Increase table width for longer output\n" JSON_STR)
718e3744 11123{
d62a17ae 11124 char *vrf = NULL;
11125 afi_t afi = AFI_MAX;
11126 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
11127 as_t as = 0; /* 0 means AS filter not set */
11128 int as_type = AS_UNSPECIFIED;
96c81f66 11129 uint16_t show_flags = 0;
d62a17ae 11130
11131 int idx = 0;
11132
11133 /* show [ip] bgp */
96f3485c 11134 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11135 afi = AFI_IP;
9a8bdf1c
PG
11136 /* [<vrf> VIEWVRFNAME] */
11137 if (argv_find(argv, argc, "vrf", &idx)) {
11138 vrf = argv[idx + 1]->arg;
11139 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11140 vrf = NULL;
11141 } else if (argv_find(argv, argc, "view", &idx))
11142 /* [<view> VIEWVRFNAME] */
11143 vrf = argv[idx + 1]->arg;
d62a17ae 11144 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11145 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11146 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11147 }
11148
3577f1c5 11149 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11150 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11151
10b49f14 11152 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11153 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11154
8c1d4cd5
LS
11155 if (argv_find(argv, argc, "remote-as", &idx)) {
11156 if (argv[idx + 1]->arg[0] == 'i')
11157 as_type = AS_INTERNAL;
11158 else if (argv[idx + 1]->arg[0] == 'e')
11159 as_type = AS_EXTERNAL;
11160 else
11161 as = (as_t)atoi(argv[idx + 1]->arg);
11162 }
11163
96c81f66
LS
11164 if (argv_find(argv, argc, "terse", &idx))
11165 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11166
85eeb029
DA
11167 if (argv_find(argv, argc, "wide", &idx))
11168 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11169
11170 if (argv_find(argv, argc, "json", &idx))
11171 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11172
8c1d4cd5
LS
11173 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11174 show_flags);
d62a17ae 11175}
11176
5cb5f4d0 11177const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11178{
5cb5f4d0
DD
11179 if (for_json)
11180 return get_afi_safi_json_str(afi, safi);
d62a17ae 11181 else
5cb5f4d0 11182 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11183}
11184
d62a17ae 11185
11186static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11187 afi_t afi, safi_t safi,
d7c0a89a
QY
11188 uint16_t adv_smcap, uint16_t adv_rmcap,
11189 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11190 bool use_json, json_object *json_pref)
d62a17ae 11191{
11192 /* Send-Mode */
11193 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11194 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11195 if (use_json) {
11196 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11197 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11198 json_object_string_add(json_pref, "sendMode",
11199 "advertisedAndReceived");
11200 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11201 json_object_string_add(json_pref, "sendMode",
11202 "advertised");
11203 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11204 json_object_string_add(json_pref, "sendMode",
11205 "received");
11206 } else {
11207 vty_out(vty, " Send-mode: ");
11208 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11209 vty_out(vty, "advertised");
11210 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11211 vty_out(vty, "%sreceived",
11212 CHECK_FLAG(p->af_cap[afi][safi],
11213 adv_smcap)
11214 ? ", "
11215 : "");
11216 vty_out(vty, "\n");
11217 }
11218 }
11219
11220 /* Receive-Mode */
11221 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11222 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11223 if (use_json) {
11224 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11225 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11226 json_object_string_add(json_pref, "recvMode",
11227 "advertisedAndReceived");
11228 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11229 json_object_string_add(json_pref, "recvMode",
11230 "advertised");
11231 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11232 json_object_string_add(json_pref, "recvMode",
11233 "received");
11234 } else {
11235 vty_out(vty, " Receive-mode: ");
11236 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11237 vty_out(vty, "advertised");
11238 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11239 vty_out(vty, "%sreceived",
11240 CHECK_FLAG(p->af_cap[afi][safi],
11241 adv_rmcap)
11242 ? ", "
11243 : "");
11244 vty_out(vty, "\n");
11245 }
11246 }
11247}
11248
13909c4f
DS
11249static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11250 struct peer *p,
11251 bool use_json,
11252 json_object *json)
2986cac2 11253{
08c2d52a 11254 bool rbit_status = false;
2986cac2 11255
11256 if (!use_json)
a53ca37b 11257 vty_out(vty, "\n R bit: ");
2986cac2 11258
13909c4f
DS
11259 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11260 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
feb17238 11261 && (peer_established(p))) {
2986cac2 11262
11263 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 11264 rbit_status = true;
2986cac2 11265 else
08c2d52a 11266 rbit_status = false;
2986cac2 11267 }
11268
11269 if (rbit_status) {
11270 if (use_json)
13909c4f 11271 json_object_boolean_true_add(json, "rBit");
2986cac2 11272 else
11273 vty_out(vty, "True\n");
11274 } else {
11275 if (use_json)
13909c4f 11276 json_object_boolean_false_add(json, "rBit");
2986cac2 11277 else
11278 vty_out(vty, "False\n");
11279 }
11280}
11281
13909c4f
DS
11282static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11283 struct peer *peer,
11284 bool use_json,
11285 json_object *json)
2986cac2 11286{
2bb5d39b 11287 const char *mode = "NotApplicable";
2986cac2 11288
11289 if (!use_json)
a53ca37b 11290 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11291
13909c4f 11292 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
feb17238 11293 && (peer_established(peer))) {
2986cac2 11294
13909c4f
DS
11295 if ((peer->nsf_af_count == 0)
11296 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11297
2986cac2 11298 mode = "Disable";
11299
13909c4f
DS
11300 } else if (peer->nsf_af_count == 0
11301 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11302
2986cac2 11303 mode = "Helper";
11304
13909c4f
DS
11305 } else if (peer->nsf_af_count != 0
11306 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11307
2986cac2 11308 mode = "Restart";
2986cac2 11309 }
11310 }
11311
11312 if (use_json) {
13909c4f 11313 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11314 } else
11315 vty_out(vty, mode, "\n");
11316}
11317
13909c4f
DS
11318static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11319 struct peer *p,
11320 bool use_json,
11321 json_object *json)
2986cac2 11322{
11323 const char *mode = "Invalid";
11324
11325 if (!use_json)
a53ca37b 11326 vty_out(vty, " Local GR Mode: ");
2986cac2 11327
11328 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11329 mode = "Helper";
11330 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11331 mode = "Restart";
11332 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11333 mode = "Disable";
2ba1fe69 11334 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11335 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11336 mode = "Helper*";
11337 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11338 mode = "Restart*";
11339 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11340 mode = "Disable*";
11341 else
11342 mode = "Invalid*";
2ba1fe69 11343 }
2986cac2 11344
11345 if (use_json) {
13909c4f 11346 json_object_string_add(json, "localGrMode", mode);
2986cac2 11347 } else {
11348 vty_out(vty, mode, "\n");
11349 }
11350}
11351
13909c4f
DS
11352static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11353 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11354{
2ba1fe69 11355 afi_t afi;
11356 safi_t safi;
2986cac2 11357 json_object *json_afi_safi = NULL;
11358 json_object *json_timer = NULL;
11359 json_object *json_endofrib_status = NULL;
9e3b51a7 11360 bool eor_flag = false;
2986cac2 11361
df8d723c
DA
11362 FOREACH_AFI_SAFI_NSF (afi, safi) {
11363 if (!peer->afc[afi][safi])
11364 continue;
2986cac2 11365
df8d723c
DA
11366 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11367 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11368 continue;
9e3b51a7 11369
df8d723c
DA
11370 if (use_json) {
11371 json_afi_safi = json_object_new_object();
11372 json_endofrib_status = json_object_new_object();
11373 json_timer = json_object_new_object();
11374 }
2986cac2 11375
df8d723c
DA
11376 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11377 eor_flag = true;
11378 else
11379 eor_flag = false;
2986cac2 11380
df8d723c
DA
11381 if (!use_json) {
11382 vty_out(vty, " %s:\n",
11383 get_afi_safi_str(afi, safi, false));
2986cac2 11384
df8d723c
DA
11385 vty_out(vty, " F bit: ");
11386 }
2986cac2 11387
df8d723c
DA
11388 if (peer->nsf[afi][safi] &&
11389 CHECK_FLAG(peer->af_cap[afi][safi],
11390 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11391
df8d723c
DA
11392 if (use_json) {
11393 json_object_boolean_true_add(json_afi_safi,
11394 "fBit");
11395 } else
11396 vty_out(vty, "True\n");
11397 } else {
11398 if (use_json)
11399 json_object_boolean_false_add(json_afi_safi,
11400 "fBit");
11401 else
11402 vty_out(vty, "False\n");
11403 }
2986cac2 11404
df8d723c
DA
11405 if (!use_json)
11406 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11407
df8d723c
DA
11408 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11409 PEER_STATUS_EOR_SEND)) {
11410 if (use_json) {
11411 json_object_boolean_true_add(
11412 json_endofrib_status, "endOfRibSend");
9e3b51a7 11413
df8d723c
DA
11414 PRINT_EOR_JSON(eor_flag);
11415 } else {
11416 vty_out(vty, "Yes\n");
11417 vty_out(vty,
11418 " End-of-RIB sent after update: ");
2986cac2 11419
df8d723c
DA
11420 PRINT_EOR(eor_flag);
11421 }
11422 } else {
11423 if (use_json) {
11424 json_object_boolean_false_add(
11425 json_endofrib_status, "endOfRibSend");
11426 json_object_boolean_false_add(
11427 json_endofrib_status,
11428 "endOfRibSentAfterUpdate");
13909c4f 11429 } else {
df8d723c
DA
11430 vty_out(vty, "No\n");
11431 vty_out(vty,
11432 " End-of-RIB sent after update: ");
11433 vty_out(vty, "No\n");
13909c4f 11434 }
df8d723c 11435 }
2986cac2 11436
df8d723c
DA
11437 if (!use_json)
11438 vty_out(vty, " End-of-RIB received: ");
a53ca37b 11439
df8d723c
DA
11440 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11441 PEER_STATUS_EOR_RECEIVED)) {
11442 if (use_json)
11443 json_object_boolean_true_add(
11444 json_endofrib_status, "endOfRibRecv");
11445 else
11446 vty_out(vty, "Yes\n");
11447 } else {
11448 if (use_json)
11449 json_object_boolean_false_add(
11450 json_endofrib_status, "endOfRibRecv");
11451 else
11452 vty_out(vty, "No\n");
11453 }
11454
11455 if (use_json) {
11456 json_object_int_add(json_timer, "stalePathTimer",
11457 peer->bgp->stalepath_time);
11458
11459 if (peer->t_gr_stale != NULL) {
11460 json_object_int_add(json_timer,
11461 "stalePathTimerRemaining",
11462 thread_timer_remain_second(
11463 peer->t_gr_stale));
a53ca37b
DA
11464 }
11465
df8d723c
DA
11466 /* Display Configured Selection
11467 * Deferral only when when
11468 * Gr mode is enabled.
11469 */
11470 if (CHECK_FLAG(peer->flags,
11471 PEER_FLAG_GRACEFUL_RESTART)) {
13909c4f 11472 json_object_int_add(json_timer,
df8d723c 11473 "selectionDeferralTimer",
13909c4f 11474 peer->bgp->stalepath_time);
df8d723c 11475 }
2986cac2 11476
df8d723c
DA
11477 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11478 NULL) {
2986cac2 11479
df8d723c
DA
11480 json_object_int_add(
11481 json_timer,
11482 "selectionDeferralTimerRemaining",
11483 thread_timer_remain_second(
11484 peer->bgp->gr_info[afi][safi]
11485 .t_select_deferral));
11486 }
11487 } else {
11488 vty_out(vty, " Timers:\n");
11489 vty_out(vty,
11490 " Configured Stale Path Time(sec): %u\n",
11491 peer->bgp->stalepath_time);
2986cac2 11492
df8d723c 11493 if (peer->t_gr_stale != NULL)
13909c4f 11494 vty_out(vty,
df8d723c
DA
11495 " Stale Path Remaining(sec): %ld\n",
11496 thread_timer_remain_second(
11497 peer->t_gr_stale));
11498 /* Display Configured Selection
11499 * Deferral only when when
11500 * Gr mode is enabled.
11501 */
11502 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11503 vty_out(vty,
11504 " Configured Selection Deferral Time(sec): %u\n",
11505 peer->bgp->select_defer_time);
2986cac2 11506
df8d723c
DA
11507 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11508 NULL)
11509 vty_out(vty,
11510 " Selection Deferral Time Remaining(sec): %ld\n",
11511 thread_timer_remain_second(
11512 peer->bgp->gr_info[afi][safi]
11513 .t_select_deferral));
11514 }
11515 if (use_json) {
11516 json_object_object_add(json_afi_safi, "endOfRibStatus",
11517 json_endofrib_status);
11518 json_object_object_add(json_afi_safi, "timers",
11519 json_timer);
11520 json_object_object_add(
11521 json, get_afi_safi_str(afi, safi, true),
11522 json_afi_safi);
2986cac2 11523 }
11524 }
11525}
11526
36235319
QY
11527static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11528 struct peer *p,
11529 bool use_json,
11530 json_object *json)
2986cac2 11531{
11532 if (use_json) {
11533 json_object *json_timer = NULL;
11534
11535 json_timer = json_object_new_object();
11536
13909c4f
DS
11537 json_object_int_add(json_timer, "configuredRestartTimer",
11538 p->bgp->restart_time);
2986cac2 11539
13909c4f
DS
11540 json_object_int_add(json_timer, "receivedRestartTimer",
11541 p->v_gr_restart);
2986cac2 11542
13909c4f
DS
11543 if (p->t_gr_restart != NULL)
11544 json_object_int_add(
11545 json_timer, "restartTimerRemaining",
11546 thread_timer_remain_second(p->t_gr_restart));
2986cac2 11547
11548 json_object_object_add(json, "timers", json_timer);
11549 } else {
11550
a53ca37b
DA
11551 vty_out(vty, " Timers:\n");
11552 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 11553 p->bgp->restart_time);
2986cac2 11554
a53ca37b 11555 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
11556 p->v_gr_restart);
11557 if (p->t_gr_restart != NULL)
a53ca37b 11558 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 11559 thread_timer_remain_second(p->t_gr_restart));
36235319 11560 if (p->t_gr_restart != NULL) {
a53ca37b 11561 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
11562 thread_timer_remain_second(p->t_gr_restart));
11563 }
2986cac2 11564 }
11565}
11566
11567static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 11568 bool use_json, json_object *json)
2986cac2 11569{
11570 char buf[SU_ADDRSTRLEN] = {0};
11571 char dn_flag[2] = {0};
2b7165e7
QY
11572 /* '*' + v6 address of neighbor */
11573 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 11574
2986cac2 11575 if (!p->conf_if && peer_dynamic_neighbor(p))
11576 dn_flag[0] = '*';
11577
11578 if (p->conf_if) {
11579 if (use_json)
13909c4f
DS
11580 json_object_string_add(
11581 json, "neighborAddr",
2986cac2 11582 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
11583 ? "none"
11584 : sockunion2str(&p->su, buf,
11585 SU_ADDRSTRLEN));
2986cac2 11586 else
13909c4f 11587 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 11588 BGP_PEER_SU_UNSPEC(p)
11589 ? "none"
11590 : sockunion2str(&p->su, buf,
11591 SU_ADDRSTRLEN));
11592 } else {
772270f3
QY
11593 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11594 p->host);
2986cac2 11595
11596 if (use_json)
36235319
QY
11597 json_object_string_add(json, "neighborAddr",
11598 neighborAddr);
2986cac2 11599 else
36235319 11600 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 11601 }
11602
11603 /* more gr info in new format */
11604 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11605}
11606
d62a17ae 11607static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 11608 safi_t safi, bool use_json,
d62a17ae 11609 json_object *json_neigh)
11610{
0291c246
MK
11611 struct bgp_filter *filter;
11612 struct peer_af *paf;
11613 char orf_pfx_name[BUFSIZ];
11614 int orf_pfx_count;
11615 json_object *json_af = NULL;
11616 json_object *json_prefA = NULL;
11617 json_object *json_prefB = NULL;
11618 json_object *json_addr = NULL;
fa36596c 11619 json_object *json_advmap = NULL;
d62a17ae 11620
11621 if (use_json) {
11622 json_addr = json_object_new_object();
11623 json_af = json_object_new_object();
11624 filter = &p->filter[afi][safi];
11625
11626 if (peer_group_active(p))
11627 json_object_string_add(json_addr, "peerGroupMember",
11628 p->group->name);
11629
11630 paf = peer_af_find(p, afi, safi);
11631 if (paf && PAF_SUBGRP(paf)) {
11632 json_object_int_add(json_addr, "updateGroupId",
11633 PAF_UPDGRP(paf)->id);
11634 json_object_int_add(json_addr, "subGroupId",
11635 PAF_SUBGRP(paf)->id);
11636 json_object_int_add(json_addr, "packetQueueLength",
11637 bpacket_queue_virtual_length(paf));
11638 }
11639
11640 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11641 || CHECK_FLAG(p->af_cap[afi][safi],
11642 PEER_CAP_ORF_PREFIX_SM_RCV)
11643 || CHECK_FLAG(p->af_cap[afi][safi],
11644 PEER_CAP_ORF_PREFIX_RM_ADV)
11645 || CHECK_FLAG(p->af_cap[afi][safi],
11646 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11647 json_object_int_add(json_af, "orfType",
11648 ORF_TYPE_PREFIX);
11649 json_prefA = json_object_new_object();
11650 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11651 PEER_CAP_ORF_PREFIX_SM_ADV,
11652 PEER_CAP_ORF_PREFIX_RM_ADV,
11653 PEER_CAP_ORF_PREFIX_SM_RCV,
11654 PEER_CAP_ORF_PREFIX_RM_RCV,
11655 use_json, json_prefA);
11656 json_object_object_add(json_af, "orfPrefixList",
11657 json_prefA);
11658 }
11659
11660 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11661 || CHECK_FLAG(p->af_cap[afi][safi],
11662 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11663 || CHECK_FLAG(p->af_cap[afi][safi],
11664 PEER_CAP_ORF_PREFIX_RM_ADV)
11665 || CHECK_FLAG(p->af_cap[afi][safi],
11666 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11667 json_object_int_add(json_af, "orfOldType",
11668 ORF_TYPE_PREFIX_OLD);
11669 json_prefB = json_object_new_object();
11670 bgp_show_peer_afi_orf_cap(
11671 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11672 PEER_CAP_ORF_PREFIX_RM_ADV,
11673 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11674 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11675 json_prefB);
11676 json_object_object_add(json_af, "orfOldPrefixList",
11677 json_prefB);
11678 }
11679
11680 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11681 || CHECK_FLAG(p->af_cap[afi][safi],
11682 PEER_CAP_ORF_PREFIX_SM_RCV)
11683 || CHECK_FLAG(p->af_cap[afi][safi],
11684 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11685 || CHECK_FLAG(p->af_cap[afi][safi],
11686 PEER_CAP_ORF_PREFIX_RM_ADV)
11687 || CHECK_FLAG(p->af_cap[afi][safi],
11688 PEER_CAP_ORF_PREFIX_RM_RCV)
11689 || CHECK_FLAG(p->af_cap[afi][safi],
11690 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11691 json_object_object_add(json_addr, "afDependentCap",
11692 json_af);
11693 else
11694 json_object_free(json_af);
11695
772270f3
QY
11696 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11697 p->host, afi, safi);
d62a17ae 11698 orf_pfx_count = prefix_bgp_show_prefix_list(
11699 NULL, afi, orf_pfx_name, use_json);
11700
11701 if (CHECK_FLAG(p->af_sflags[afi][safi],
11702 PEER_STATUS_ORF_PREFIX_SEND)
11703 || orf_pfx_count) {
11704 if (CHECK_FLAG(p->af_sflags[afi][safi],
11705 PEER_STATUS_ORF_PREFIX_SEND))
11706 json_object_boolean_true_add(json_neigh,
11707 "orfSent");
11708 if (orf_pfx_count)
11709 json_object_int_add(json_addr, "orfRecvCounter",
11710 orf_pfx_count);
11711 }
11712 if (CHECK_FLAG(p->af_sflags[afi][safi],
11713 PEER_STATUS_ORF_WAIT_REFRESH))
11714 json_object_string_add(
11715 json_addr, "orfFirstUpdate",
11716 "deferredUntilORFOrRouteRefreshRecvd");
11717
11718 if (CHECK_FLAG(p->af_flags[afi][safi],
11719 PEER_FLAG_REFLECTOR_CLIENT))
11720 json_object_boolean_true_add(json_addr,
11721 "routeReflectorClient");
11722 if (CHECK_FLAG(p->af_flags[afi][safi],
11723 PEER_FLAG_RSERVER_CLIENT))
11724 json_object_boolean_true_add(json_addr,
11725 "routeServerClient");
11726 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11727 json_object_boolean_true_add(json_addr,
11728 "inboundSoftConfigPermit");
11729
11730 if (CHECK_FLAG(p->af_flags[afi][safi],
11731 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11732 json_object_boolean_true_add(
11733 json_addr,
11734 "privateAsNumsAllReplacedInUpdatesToNbr");
11735 else if (CHECK_FLAG(p->af_flags[afi][safi],
11736 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11737 json_object_boolean_true_add(
11738 json_addr,
11739 "privateAsNumsReplacedInUpdatesToNbr");
11740 else if (CHECK_FLAG(p->af_flags[afi][safi],
11741 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11742 json_object_boolean_true_add(
11743 json_addr,
11744 "privateAsNumsAllRemovedInUpdatesToNbr");
11745 else if (CHECK_FLAG(p->af_flags[afi][safi],
11746 PEER_FLAG_REMOVE_PRIVATE_AS))
11747 json_object_boolean_true_add(
11748 json_addr,
11749 "privateAsNumsRemovedInUpdatesToNbr");
11750
dcc68b5e
MS
11751 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11752 json_object_boolean_true_add(
11753 json_addr,
11754 bgp_addpath_names(p->addpath_type[afi][safi])
11755 ->type_json_name);
d62a17ae 11756
11757 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11758 json_object_string_add(json_addr,
11759 "overrideASNsInOutboundUpdates",
11760 "ifAspathEqualRemoteAs");
11761
11762 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11763 || CHECK_FLAG(p->af_flags[afi][safi],
11764 PEER_FLAG_FORCE_NEXTHOP_SELF))
11765 json_object_boolean_true_add(json_addr,
11766 "routerAlwaysNextHop");
11767 if (CHECK_FLAG(p->af_flags[afi][safi],
11768 PEER_FLAG_AS_PATH_UNCHANGED))
11769 json_object_boolean_true_add(
11770 json_addr, "unchangedAsPathPropogatedToNbr");
11771 if (CHECK_FLAG(p->af_flags[afi][safi],
11772 PEER_FLAG_NEXTHOP_UNCHANGED))
11773 json_object_boolean_true_add(
11774 json_addr, "unchangedNextHopPropogatedToNbr");
11775 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11776 json_object_boolean_true_add(
11777 json_addr, "unchangedMedPropogatedToNbr");
11778 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11779 || CHECK_FLAG(p->af_flags[afi][safi],
11780 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11781 if (CHECK_FLAG(p->af_flags[afi][safi],
11782 PEER_FLAG_SEND_COMMUNITY)
11783 && CHECK_FLAG(p->af_flags[afi][safi],
11784 PEER_FLAG_SEND_EXT_COMMUNITY))
11785 json_object_string_add(json_addr,
11786 "commAttriSentToNbr",
11787 "extendedAndStandard");
11788 else if (CHECK_FLAG(p->af_flags[afi][safi],
11789 PEER_FLAG_SEND_EXT_COMMUNITY))
11790 json_object_string_add(json_addr,
11791 "commAttriSentToNbr",
11792 "extended");
11793 else
11794 json_object_string_add(json_addr,
11795 "commAttriSentToNbr",
11796 "standard");
11797 }
11798 if (CHECK_FLAG(p->af_flags[afi][safi],
11799 PEER_FLAG_DEFAULT_ORIGINATE)) {
11800 if (p->default_rmap[afi][safi].name)
11801 json_object_string_add(
11802 json_addr, "defaultRouteMap",
11803 p->default_rmap[afi][safi].name);
11804
11805 if (paf && PAF_SUBGRP(paf)
11806 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11807 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11808 json_object_boolean_true_add(json_addr,
11809 "defaultSent");
11810 else
11811 json_object_boolean_true_add(json_addr,
11812 "defaultNotSent");
11813 }
11814
dff8f48d 11815 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 11816 if (is_evpn_enabled())
60466a63
QY
11817 json_object_boolean_true_add(
11818 json_addr, "advertiseAllVnis");
dff8f48d
MK
11819 }
11820
d62a17ae 11821 if (filter->plist[FILTER_IN].name
11822 || filter->dlist[FILTER_IN].name
11823 || filter->aslist[FILTER_IN].name
11824 || filter->map[RMAP_IN].name)
11825 json_object_boolean_true_add(json_addr,
11826 "inboundPathPolicyConfig");
11827 if (filter->plist[FILTER_OUT].name
11828 || filter->dlist[FILTER_OUT].name
11829 || filter->aslist[FILTER_OUT].name
11830 || filter->map[RMAP_OUT].name || filter->usmap.name)
11831 json_object_boolean_true_add(
11832 json_addr, "outboundPathPolicyConfig");
11833
11834 /* prefix-list */
11835 if (filter->plist[FILTER_IN].name)
11836 json_object_string_add(json_addr,
11837 "incomingUpdatePrefixFilterList",
11838 filter->plist[FILTER_IN].name);
11839 if (filter->plist[FILTER_OUT].name)
11840 json_object_string_add(json_addr,
11841 "outgoingUpdatePrefixFilterList",
11842 filter->plist[FILTER_OUT].name);
11843
11844 /* distribute-list */
11845 if (filter->dlist[FILTER_IN].name)
11846 json_object_string_add(
11847 json_addr, "incomingUpdateNetworkFilterList",
11848 filter->dlist[FILTER_IN].name);
11849 if (filter->dlist[FILTER_OUT].name)
11850 json_object_string_add(
11851 json_addr, "outgoingUpdateNetworkFilterList",
11852 filter->dlist[FILTER_OUT].name);
11853
11854 /* filter-list. */
11855 if (filter->aslist[FILTER_IN].name)
11856 json_object_string_add(json_addr,
11857 "incomingUpdateAsPathFilterList",
11858 filter->aslist[FILTER_IN].name);
11859 if (filter->aslist[FILTER_OUT].name)
11860 json_object_string_add(json_addr,
11861 "outgoingUpdateAsPathFilterList",
11862 filter->aslist[FILTER_OUT].name);
11863
11864 /* route-map. */
11865 if (filter->map[RMAP_IN].name)
11866 json_object_string_add(
11867 json_addr, "routeMapForIncomingAdvertisements",
11868 filter->map[RMAP_IN].name);
11869 if (filter->map[RMAP_OUT].name)
11870 json_object_string_add(
11871 json_addr, "routeMapForOutgoingAdvertisements",
11872 filter->map[RMAP_OUT].name);
11873
9dac9fc8 11874 /* ebgp-requires-policy (inbound) */
1d3fdccf 11875 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11876 && !bgp_inbound_policy_exists(p, filter))
11877 json_object_string_add(
11878 json_addr, "inboundEbgpRequiresPolicy",
11879 "Inbound updates discarded due to missing policy");
11880
11881 /* ebgp-requires-policy (outbound) */
1d3fdccf 11882 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11883 && (!bgp_outbound_policy_exists(p, filter)))
11884 json_object_string_add(
11885 json_addr, "outboundEbgpRequiresPolicy",
11886 "Outbound updates discarded due to missing policy");
11887
d62a17ae 11888 /* unsuppress-map */
11889 if (filter->usmap.name)
11890 json_object_string_add(json_addr,
11891 "selectiveUnsuppressRouteMap",
11892 filter->usmap.name);
11893
fa36596c
MK
11894 /* advertise-map */
11895 if (filter->advmap.aname) {
11896 json_advmap = json_object_new_object();
11897 json_object_string_add(json_advmap, "condition",
11898 filter->advmap.condition
11899 ? "EXIST"
11900 : "NON_EXIST");
11901 json_object_string_add(json_advmap, "conditionMap",
11902 filter->advmap.cname);
11903 json_object_string_add(json_advmap, "advertiseMap",
11904 filter->advmap.aname);
11905 json_object_string_add(json_advmap, "advertiseStatus",
11906 filter->advmap.update_type
11907 == ADVERTISE
11908 ? "Advertise"
11909 : "Withdraw");
11910 json_object_object_add(json_addr, "advertiseMap",
11911 json_advmap);
11912 }
11913
d62a17ae 11914 /* Receive prefix count */
11915 json_object_int_add(json_addr, "acceptedPrefixCounter",
11916 p->pcount[afi][safi]);
50e05855
AD
11917 if (paf && PAF_SUBGRP(paf))
11918 json_object_int_add(json_addr, "sentPrefixCounter",
11919 (PAF_SUBGRP(paf))->scount);
d62a17ae 11920
fde246e8
DA
11921 /* Maximum prefix */
11922 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
11923 json_object_int_add(json_addr, "prefixOutAllowedMax",
11924 p->pmax_out[afi][safi]);
11925
d62a17ae 11926 /* Maximum prefix */
11927 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11928 json_object_int_add(json_addr, "prefixAllowedMax",
11929 p->pmax[afi][safi]);
11930 if (CHECK_FLAG(p->af_flags[afi][safi],
11931 PEER_FLAG_MAX_PREFIX_WARNING))
11932 json_object_boolean_true_add(
11933 json_addr, "prefixAllowedMaxWarning");
11934 json_object_int_add(json_addr,
11935 "prefixAllowedWarningThresh",
11936 p->pmax_threshold[afi][safi]);
11937 if (p->pmax_restart[afi][safi])
11938 json_object_int_add(
11939 json_addr,
11940 "prefixAllowedRestartIntervalMsecs",
11941 p->pmax_restart[afi][safi] * 60000);
11942 }
2986cac2 11943 json_object_object_add(json_neigh,
36235319 11944 get_afi_safi_str(afi, safi, true),
d62a17ae 11945 json_addr);
11946
11947 } else {
11948 filter = &p->filter[afi][safi];
11949
11950 vty_out(vty, " For address family: %s\n",
5cb5f4d0 11951 get_afi_safi_str(afi, safi, false));
d62a17ae 11952
11953 if (peer_group_active(p))
11954 vty_out(vty, " %s peer-group member\n",
11955 p->group->name);
11956
11957 paf = peer_af_find(p, afi, safi);
11958 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 11959 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 11960 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
11961 vty_out(vty, " Packet Queue length %d\n",
11962 bpacket_queue_virtual_length(paf));
11963 } else {
11964 vty_out(vty, " Not part of any update group\n");
11965 }
11966 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11967 || CHECK_FLAG(p->af_cap[afi][safi],
11968 PEER_CAP_ORF_PREFIX_SM_RCV)
11969 || CHECK_FLAG(p->af_cap[afi][safi],
11970 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11971 || CHECK_FLAG(p->af_cap[afi][safi],
11972 PEER_CAP_ORF_PREFIX_RM_ADV)
11973 || CHECK_FLAG(p->af_cap[afi][safi],
11974 PEER_CAP_ORF_PREFIX_RM_RCV)
11975 || CHECK_FLAG(p->af_cap[afi][safi],
11976 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11977 vty_out(vty, " AF-dependant capabilities:\n");
11978
11979 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11980 || CHECK_FLAG(p->af_cap[afi][safi],
11981 PEER_CAP_ORF_PREFIX_SM_RCV)
11982 || CHECK_FLAG(p->af_cap[afi][safi],
11983 PEER_CAP_ORF_PREFIX_RM_ADV)
11984 || CHECK_FLAG(p->af_cap[afi][safi],
11985 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11986 vty_out(vty,
11987 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11988 ORF_TYPE_PREFIX);
11989 bgp_show_peer_afi_orf_cap(
11990 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11991 PEER_CAP_ORF_PREFIX_RM_ADV,
11992 PEER_CAP_ORF_PREFIX_SM_RCV,
11993 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
11994 }
11995 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11996 || CHECK_FLAG(p->af_cap[afi][safi],
11997 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11998 || CHECK_FLAG(p->af_cap[afi][safi],
11999 PEER_CAP_ORF_PREFIX_RM_ADV)
12000 || CHECK_FLAG(p->af_cap[afi][safi],
12001 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12002 vty_out(vty,
12003 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12004 ORF_TYPE_PREFIX_OLD);
12005 bgp_show_peer_afi_orf_cap(
12006 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12007 PEER_CAP_ORF_PREFIX_RM_ADV,
12008 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12009 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12010 }
12011
772270f3
QY
12012 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12013 p->host, afi, safi);
d62a17ae 12014 orf_pfx_count = prefix_bgp_show_prefix_list(
12015 NULL, afi, orf_pfx_name, use_json);
12016
12017 if (CHECK_FLAG(p->af_sflags[afi][safi],
12018 PEER_STATUS_ORF_PREFIX_SEND)
12019 || orf_pfx_count) {
12020 vty_out(vty, " Outbound Route Filter (ORF):");
12021 if (CHECK_FLAG(p->af_sflags[afi][safi],
12022 PEER_STATUS_ORF_PREFIX_SEND))
12023 vty_out(vty, " sent;");
12024 if (orf_pfx_count)
12025 vty_out(vty, " received (%d entries)",
12026 orf_pfx_count);
12027 vty_out(vty, "\n");
12028 }
12029 if (CHECK_FLAG(p->af_sflags[afi][safi],
12030 PEER_STATUS_ORF_WAIT_REFRESH))
12031 vty_out(vty,
12032 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12033
12034 if (CHECK_FLAG(p->af_flags[afi][safi],
12035 PEER_FLAG_REFLECTOR_CLIENT))
12036 vty_out(vty, " Route-Reflector Client\n");
12037 if (CHECK_FLAG(p->af_flags[afi][safi],
12038 PEER_FLAG_RSERVER_CLIENT))
12039 vty_out(vty, " Route-Server Client\n");
12040 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12041 vty_out(vty,
12042 " Inbound soft reconfiguration allowed\n");
12043
12044 if (CHECK_FLAG(p->af_flags[afi][safi],
12045 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12046 vty_out(vty,
12047 " Private AS numbers (all) replaced in updates to this neighbor\n");
12048 else if (CHECK_FLAG(p->af_flags[afi][safi],
12049 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12050 vty_out(vty,
12051 " Private AS numbers replaced in updates to this neighbor\n");
12052 else if (CHECK_FLAG(p->af_flags[afi][safi],
12053 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12054 vty_out(vty,
12055 " Private AS numbers (all) removed in updates to this neighbor\n");
12056 else if (CHECK_FLAG(p->af_flags[afi][safi],
12057 PEER_FLAG_REMOVE_PRIVATE_AS))
12058 vty_out(vty,
12059 " Private AS numbers removed in updates to this neighbor\n");
12060
dcc68b5e
MS
12061 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12062 vty_out(vty, " %s\n",
12063 bgp_addpath_names(p->addpath_type[afi][safi])
12064 ->human_description);
d62a17ae 12065
12066 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12067 vty_out(vty,
12068 " Override ASNs in outbound updates if aspath equals remote-as\n");
12069
12070 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12071 || CHECK_FLAG(p->af_flags[afi][safi],
12072 PEER_FLAG_FORCE_NEXTHOP_SELF))
12073 vty_out(vty, " NEXT_HOP is always this router\n");
12074 if (CHECK_FLAG(p->af_flags[afi][safi],
12075 PEER_FLAG_AS_PATH_UNCHANGED))
12076 vty_out(vty,
12077 " AS_PATH is propagated unchanged to this neighbor\n");
12078 if (CHECK_FLAG(p->af_flags[afi][safi],
12079 PEER_FLAG_NEXTHOP_UNCHANGED))
12080 vty_out(vty,
12081 " NEXT_HOP is propagated unchanged to this neighbor\n");
12082 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12083 vty_out(vty,
12084 " MED is propagated unchanged to this neighbor\n");
12085 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12086 || CHECK_FLAG(p->af_flags[afi][safi],
12087 PEER_FLAG_SEND_EXT_COMMUNITY)
12088 || CHECK_FLAG(p->af_flags[afi][safi],
12089 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12090 vty_out(vty,
12091 " Community attribute sent to this neighbor");
12092 if (CHECK_FLAG(p->af_flags[afi][safi],
12093 PEER_FLAG_SEND_COMMUNITY)
12094 && CHECK_FLAG(p->af_flags[afi][safi],
12095 PEER_FLAG_SEND_EXT_COMMUNITY)
12096 && CHECK_FLAG(p->af_flags[afi][safi],
12097 PEER_FLAG_SEND_LARGE_COMMUNITY))
12098 vty_out(vty, "(all)\n");
12099 else if (CHECK_FLAG(p->af_flags[afi][safi],
12100 PEER_FLAG_SEND_LARGE_COMMUNITY))
12101 vty_out(vty, "(large)\n");
12102 else if (CHECK_FLAG(p->af_flags[afi][safi],
12103 PEER_FLAG_SEND_EXT_COMMUNITY))
12104 vty_out(vty, "(extended)\n");
12105 else
12106 vty_out(vty, "(standard)\n");
12107 }
12108 if (CHECK_FLAG(p->af_flags[afi][safi],
12109 PEER_FLAG_DEFAULT_ORIGINATE)) {
12110 vty_out(vty, " Default information originate,");
12111
12112 if (p->default_rmap[afi][safi].name)
12113 vty_out(vty, " default route-map %s%s,",
12114 p->default_rmap[afi][safi].map ? "*"
12115 : "",
12116 p->default_rmap[afi][safi].name);
12117 if (paf && PAF_SUBGRP(paf)
12118 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12119 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12120 vty_out(vty, " default sent\n");
12121 else
12122 vty_out(vty, " default not sent\n");
12123 }
12124
dff8f48d
MK
12125 /* advertise-vni-all */
12126 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12127 if (is_evpn_enabled())
dff8f48d
MK
12128 vty_out(vty, " advertise-all-vni\n");
12129 }
12130
d62a17ae 12131 if (filter->plist[FILTER_IN].name
12132 || filter->dlist[FILTER_IN].name
12133 || filter->aslist[FILTER_IN].name
12134 || filter->map[RMAP_IN].name)
12135 vty_out(vty, " Inbound path policy configured\n");
12136 if (filter->plist[FILTER_OUT].name
12137 || filter->dlist[FILTER_OUT].name
12138 || filter->aslist[FILTER_OUT].name
12139 || filter->map[RMAP_OUT].name || filter->usmap.name)
12140 vty_out(vty, " Outbound path policy configured\n");
12141
12142 /* prefix-list */
12143 if (filter->plist[FILTER_IN].name)
12144 vty_out(vty,
12145 " Incoming update prefix filter list is %s%s\n",
12146 filter->plist[FILTER_IN].plist ? "*" : "",
12147 filter->plist[FILTER_IN].name);
12148 if (filter->plist[FILTER_OUT].name)
12149 vty_out(vty,
12150 " Outgoing update prefix filter list is %s%s\n",
12151 filter->plist[FILTER_OUT].plist ? "*" : "",
12152 filter->plist[FILTER_OUT].name);
12153
12154 /* distribute-list */
12155 if (filter->dlist[FILTER_IN].name)
12156 vty_out(vty,
12157 " Incoming update network filter list is %s%s\n",
12158 filter->dlist[FILTER_IN].alist ? "*" : "",
12159 filter->dlist[FILTER_IN].name);
12160 if (filter->dlist[FILTER_OUT].name)
12161 vty_out(vty,
12162 " Outgoing update network filter list is %s%s\n",
12163 filter->dlist[FILTER_OUT].alist ? "*" : "",
12164 filter->dlist[FILTER_OUT].name);
12165
12166 /* filter-list. */
12167 if (filter->aslist[FILTER_IN].name)
12168 vty_out(vty,
12169 " Incoming update AS path filter list is %s%s\n",
12170 filter->aslist[FILTER_IN].aslist ? "*" : "",
12171 filter->aslist[FILTER_IN].name);
12172 if (filter->aslist[FILTER_OUT].name)
12173 vty_out(vty,
12174 " Outgoing update AS path filter list is %s%s\n",
12175 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12176 filter->aslist[FILTER_OUT].name);
12177
12178 /* route-map. */
12179 if (filter->map[RMAP_IN].name)
12180 vty_out(vty,
12181 " Route map for incoming advertisements is %s%s\n",
12182 filter->map[RMAP_IN].map ? "*" : "",
12183 filter->map[RMAP_IN].name);
12184 if (filter->map[RMAP_OUT].name)
12185 vty_out(vty,
12186 " Route map for outgoing advertisements is %s%s\n",
12187 filter->map[RMAP_OUT].map ? "*" : "",
12188 filter->map[RMAP_OUT].name);
12189
9dac9fc8 12190 /* ebgp-requires-policy (inbound) */
1d3fdccf 12191 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12192 && !bgp_inbound_policy_exists(p, filter))
12193 vty_out(vty,
12194 " Inbound updates discarded due to missing policy\n");
12195
12196 /* ebgp-requires-policy (outbound) */
1d3fdccf 12197 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12198 && !bgp_outbound_policy_exists(p, filter))
12199 vty_out(vty,
12200 " Outbound updates discarded due to missing policy\n");
12201
d62a17ae 12202 /* unsuppress-map */
12203 if (filter->usmap.name)
12204 vty_out(vty,
12205 " Route map for selective unsuppress is %s%s\n",
12206 filter->usmap.map ? "*" : "",
12207 filter->usmap.name);
12208
7f7940e6
MK
12209 /* advertise-map */
12210 if (filter->advmap.aname && filter->advmap.cname)
12211 vty_out(vty,
12212 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12213 filter->advmap.condition ? "EXIST"
12214 : "NON_EXIST",
12215 filter->advmap.cmap ? "*" : "",
12216 filter->advmap.cname,
12217 filter->advmap.amap ? "*" : "",
12218 filter->advmap.aname,
fa36596c 12219 filter->advmap.update_type == ADVERTISE
c385f82a
MK
12220 ? "Advertise"
12221 : "Withdraw");
7f7940e6 12222
d62a17ae 12223 /* Receive prefix count */
6cde4b45 12224 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12225 p->pcount[afi][safi]);
d62a17ae 12226
fde246e8
DA
12227 /* maximum-prefix-out */
12228 if (CHECK_FLAG(p->af_flags[afi][safi],
12229 PEER_FLAG_MAX_PREFIX_OUT))
12230 vty_out(vty,
6cde4b45 12231 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12232 p->pmax_out[afi][safi]);
12233
d62a17ae 12234 /* Maximum prefix */
12235 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12236 vty_out(vty,
6cde4b45 12237 " Maximum prefixes allowed %u%s\n",
d62a17ae 12238 p->pmax[afi][safi],
12239 CHECK_FLAG(p->af_flags[afi][safi],
12240 PEER_FLAG_MAX_PREFIX_WARNING)
12241 ? " (warning-only)"
12242 : "");
12243 vty_out(vty, " Threshold for warning message %d%%",
12244 p->pmax_threshold[afi][safi]);
12245 if (p->pmax_restart[afi][safi])
12246 vty_out(vty, ", restart interval %d min",
12247 p->pmax_restart[afi][safi]);
12248 vty_out(vty, "\n");
12249 }
12250
12251 vty_out(vty, "\n");
12252 }
12253}
12254
9f049418 12255static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12256 json_object *json)
718e3744 12257{
d62a17ae 12258 struct bgp *bgp;
12259 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12260 char timebuf[BGP_UPTIME_LEN];
12261 char dn_flag[2];
d62a17ae 12262 afi_t afi;
12263 safi_t safi;
d7c0a89a
QY
12264 uint16_t i;
12265 uint8_t *msg;
d62a17ae 12266 json_object *json_neigh = NULL;
12267 time_t epoch_tbuf;
4ab46701 12268 uint32_t sync_tcp_mss;
718e3744 12269
d62a17ae 12270 bgp = p->bgp;
12271
12272 if (use_json)
12273 json_neigh = json_object_new_object();
12274
12275 memset(dn_flag, '\0', sizeof(dn_flag));
12276 if (!p->conf_if && peer_dynamic_neighbor(p))
12277 dn_flag[0] = '*';
12278
12279 if (!use_json) {
12280 if (p->conf_if) /* Configured interface name. */
12281 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12282 BGP_PEER_SU_UNSPEC(p)
12283 ? "None"
12284 : sockunion2str(&p->su, buf,
12285 SU_ADDRSTRLEN));
12286 else /* Configured IP address. */
12287 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12288 p->host);
12289 }
12290
12291 if (use_json) {
12292 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12293 json_object_string_add(json_neigh, "bgpNeighborAddr",
12294 "none");
12295 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12296 json_object_string_add(
12297 json_neigh, "bgpNeighborAddr",
12298 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12299
12300 json_object_int_add(json_neigh, "remoteAs", p->as);
12301
12302 if (p->change_local_as)
12303 json_object_int_add(json_neigh, "localAs",
12304 p->change_local_as);
12305 else
12306 json_object_int_add(json_neigh, "localAs", p->local_as);
12307
12308 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12309 json_object_boolean_true_add(json_neigh,
12310 "localAsNoPrepend");
12311
12312 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12313 json_object_boolean_true_add(json_neigh,
12314 "localAsReplaceAs");
12315 } else {
12316 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12317 || (p->as_type == AS_INTERNAL))
12318 vty_out(vty, "remote AS %u, ", p->as);
12319 else
12320 vty_out(vty, "remote AS Unspecified, ");
12321 vty_out(vty, "local AS %u%s%s, ",
12322 p->change_local_as ? p->change_local_as : p->local_as,
12323 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12324 ? " no-prepend"
12325 : "",
12326 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12327 ? " replace-as"
12328 : "");
12329 }
faa16034
DS
12330 /* peer type internal or confed-internal */
12331 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12332 if (use_json) {
12333 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12334 json_object_boolean_true_add(
12335 json_neigh, "nbrConfedInternalLink");
12336 else
12337 json_object_boolean_true_add(json_neigh,
12338 "nbrInternalLink");
12339 } else {
12340 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12341 vty_out(vty, "confed-internal link\n");
12342 else
12343 vty_out(vty, "internal link\n");
12344 }
faa16034
DS
12345 /* peer type external or confed-external */
12346 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12347 if (use_json) {
12348 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12349 json_object_boolean_true_add(
12350 json_neigh, "nbrConfedExternalLink");
12351 else
12352 json_object_boolean_true_add(json_neigh,
12353 "nbrExternalLink");
12354 } else {
12355 if (bgp_confederation_peers_check(bgp, p->as))
12356 vty_out(vty, "confed-external link\n");
12357 else
12358 vty_out(vty, "external link\n");
12359 }
faa16034
DS
12360 } else {
12361 if (use_json)
12362 json_object_boolean_true_add(json_neigh,
12363 "nbrUnspecifiedLink");
12364 else
12365 vty_out(vty, "unspecified link\n");
d62a17ae 12366 }
12367
12368 /* Description. */
12369 if (p->desc) {
12370 if (use_json)
12371 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12372 else
12373 vty_out(vty, " Description: %s\n", p->desc);
12374 }
12375
12376 if (p->hostname) {
12377 if (use_json) {
12378 if (p->hostname)
12379 json_object_string_add(json_neigh, "hostname",
12380 p->hostname);
12381
12382 if (p->domainname)
12383 json_object_string_add(json_neigh, "domainname",
12384 p->domainname);
12385 } else {
12386 if (p->domainname && (p->domainname[0] != '\0'))
12387 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12388 p->domainname);
12389 else
12390 vty_out(vty, "Hostname: %s\n", p->hostname);
12391 }
12392 }
12393
12394 /* Peer-group */
12395 if (p->group) {
12396 if (use_json) {
12397 json_object_string_add(json_neigh, "peerGroup",
12398 p->group->name);
12399
12400 if (dn_flag[0]) {
12401 struct prefix prefix, *range = NULL;
12402
0154d8ce
DS
12403 if (sockunion2hostprefix(&(p->su), &prefix))
12404 range = peer_group_lookup_dynamic_neighbor_range(
12405 p->group, &prefix);
d62a17ae 12406
12407 if (range) {
67d7e256 12408 json_object_string_addf(
d62a17ae 12409 json_neigh,
67d7e256
DA
12410 "peerSubnetRangeGroup", "%pFX",
12411 range);
d62a17ae 12412 }
12413 }
12414 } else {
12415 vty_out(vty,
12416 " Member of peer-group %s for session parameters\n",
12417 p->group->name);
12418
12419 if (dn_flag[0]) {
12420 struct prefix prefix, *range = NULL;
12421
0154d8ce
DS
12422 if (sockunion2hostprefix(&(p->su), &prefix))
12423 range = peer_group_lookup_dynamic_neighbor_range(
12424 p->group, &prefix);
d62a17ae 12425
12426 if (range) {
d62a17ae 12427 vty_out(vty,
1b78780b
DL
12428 " Belongs to the subnet range group: %pFX\n",
12429 range);
d62a17ae 12430 }
12431 }
12432 }
12433 }
12434
12435 if (use_json) {
12436 /* Administrative shutdown. */
cb9196e7
DS
12437 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12438 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12439 json_object_boolean_true_add(json_neigh,
12440 "adminShutDown");
12441
12442 /* BGP Version. */
12443 json_object_int_add(json_neigh, "bgpVersion", 4);
c949c771
DA
12444 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12445 &p->remote_id);
12446 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12447 &bgp->router_id);
d62a17ae 12448
12449 /* Confederation */
12450 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12451 && bgp_confederation_peers_check(bgp, p->as))
12452 json_object_boolean_true_add(json_neigh,
12453 "nbrCommonAdmin");
12454
12455 /* Status. */
12456 json_object_string_add(
12457 json_neigh, "bgpState",
12458 lookup_msg(bgp_status_msg, p->status, NULL));
12459
feb17238 12460 if (peer_established(p)) {
d62a17ae 12461 time_t uptime;
d62a17ae 12462
12463 uptime = bgp_clock();
12464 uptime -= p->uptime;
d62a17ae 12465 epoch_tbuf = time(NULL) - uptime;
12466
d3c7efed
DS
12467 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12468 uptime * 1000);
d62a17ae 12469 json_object_string_add(json_neigh, "bgpTimerUpString",
12470 peer_uptime(p->uptime, timebuf,
12471 BGP_UPTIME_LEN, 0,
12472 NULL));
12473 json_object_int_add(json_neigh,
12474 "bgpTimerUpEstablishedEpoch",
12475 epoch_tbuf);
12476 }
12477
12478 else if (p->status == Active) {
12479 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12480 json_object_string_add(json_neigh, "bgpStateIs",
12481 "passive");
12482 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12483 json_object_string_add(json_neigh, "bgpStateIs",
12484 "passiveNSF");
12485 }
12486
12487 /* read timer */
12488 time_t uptime;
a2700b50 12489 struct tm tm;
d62a17ae 12490
12491 uptime = bgp_clock();
12492 uptime -= p->readtime;
a2700b50
MS
12493 gmtime_r(&uptime, &tm);
12494
d62a17ae 12495 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
12496 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12497 + (tm.tm_hour * 3600000));
d62a17ae 12498
12499 uptime = bgp_clock();
12500 uptime -= p->last_write;
a2700b50
MS
12501 gmtime_r(&uptime, &tm);
12502
d62a17ae 12503 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
12504 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12505 + (tm.tm_hour * 3600000));
d62a17ae 12506
12507 uptime = bgp_clock();
12508 uptime -= p->update_time;
a2700b50
MS
12509 gmtime_r(&uptime, &tm);
12510
d62a17ae 12511 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
12512 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12513 + (tm.tm_hour * 3600000));
d62a17ae 12514
12515 /* Configured timer values. */
12516 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12517 p->v_holdtime * 1000);
12518 json_object_int_add(json_neigh,
12519 "bgpTimerKeepAliveIntervalMsecs",
12520 p->v_keepalive * 1000);
d43114f3
DS
12521 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12522 json_object_int_add(json_neigh,
12523 "bgpTimerDelayOpenTimeMsecs",
12524 p->v_delayopen * 1000);
12525 }
12526
4ab46701
AR
12527 /* Configured and Synced tcp-mss value for peer */
12528 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12529 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12530 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12531 p->tcp_mss);
12532 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12533 sync_tcp_mss);
12534 }
12535
b90a8e13 12536 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12537 json_object_int_add(json_neigh,
12538 "bgpTimerConfiguredHoldTimeMsecs",
12539 p->holdtime * 1000);
12540 json_object_int_add(
12541 json_neigh,
12542 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12543 p->keepalive * 1000);
5d5393b9
DL
12544 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12545 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12546 json_object_int_add(json_neigh,
12547 "bgpTimerConfiguredHoldTimeMsecs",
12548 bgp->default_holdtime);
12549 json_object_int_add(
12550 json_neigh,
12551 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12552 bgp->default_keepalive);
d62a17ae 12553 }
d08c0c80
DA
12554
12555 /* Extended Optional Parameters Length for BGP OPEN Message */
12556 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12557 json_object_boolean_true_add(
12558 json_neigh, "extendedOptionalParametersLength");
12559 else
12560 json_object_boolean_false_add(
12561 json_neigh, "extendedOptionalParametersLength");
d62a17ae 12562 } else {
12563 /* Administrative shutdown. */
cb9196e7
DS
12564 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12565 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12566 vty_out(vty, " Administratively shut down\n");
12567
12568 /* BGP Version. */
12569 vty_out(vty, " BGP version 4");
0e38aeb4 12570 vty_out(vty, ", remote router ID %s",
d62a17ae 12571 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
12572 vty_out(vty, ", local router ID %s\n",
12573 inet_ntop(AF_INET, &bgp->router_id, buf1,
12574 sizeof(buf1)));
d62a17ae 12575
12576 /* Confederation */
12577 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12578 && bgp_confederation_peers_check(bgp, p->as))
12579 vty_out(vty,
12580 " Neighbor under common administration\n");
12581
12582 /* Status. */
12583 vty_out(vty, " BGP state = %s",
12584 lookup_msg(bgp_status_msg, p->status, NULL));
12585
feb17238 12586 if (peer_established(p))
d62a17ae 12587 vty_out(vty, ", up for %8s",
12588 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12589 0, NULL));
12590
12591 else if (p->status == Active) {
12592 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12593 vty_out(vty, " (passive)");
12594 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12595 vty_out(vty, " (NSF passive)");
12596 }
12597 vty_out(vty, "\n");
12598
12599 /* read timer */
12600 vty_out(vty, " Last read %s",
12601 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12602 NULL));
12603 vty_out(vty, ", Last write %s\n",
12604 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12605 NULL));
12606
12607 /* Configured timer values. */
12608 vty_out(vty,
12609 " Hold time is %d, keepalive interval is %d seconds\n",
12610 p->v_holdtime, p->v_keepalive);
b90a8e13 12611 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12612 vty_out(vty, " Configured hold time is %d",
12613 p->holdtime);
12614 vty_out(vty, ", keepalive interval is %d seconds\n",
12615 p->keepalive);
5d5393b9
DL
12616 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12617 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12618 vty_out(vty, " Configured hold time is %d",
12619 bgp->default_holdtime);
12620 vty_out(vty, ", keepalive interval is %d seconds\n",
12621 bgp->default_keepalive);
d62a17ae 12622 }
d43114f3
DS
12623 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12624 vty_out(vty,
12625 " Configured DelayOpenTime is %d seconds\n",
12626 p->delayopen);
4ab46701
AR
12627
12628 /* Configured and synced tcp-mss value for peer */
12629 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12630 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12631 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12632 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12633 }
d08c0c80
DA
12634
12635 /* Extended Optional Parameters Length for BGP OPEN Message */
12636 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12637 vty_out(vty,
12638 " Extended Optional Parameters Length is enabled\n");
d62a17ae 12639 }
12640 /* Capability. */
10711563
DA
12641 if (peer_established(p) &&
12642 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
12643 if (use_json) {
12644 json_object *json_cap = NULL;
d62a17ae 12645
10711563 12646 json_cap = json_object_new_object();
d62a17ae 12647
10711563
DA
12648 /* AS4 */
12649 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
12650 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12651 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
12652 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
ef56aee4 12653 json_object_string_add(
10711563 12654 json_cap, "4byteAs",
ef56aee4 12655 "advertisedAndReceived");
10711563
DA
12656 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
12657 json_object_string_add(json_cap,
12658 "4byteAs",
12659 "advertised");
12660 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12661 json_object_string_add(json_cap,
12662 "4byteAs",
12663 "received");
12664 }
ef56aee4 12665
10711563
DA
12666 /* Extended Message Support */
12667 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
12668 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
12669 json_object_string_add(json_cap,
12670 "extendedMessage",
12671 "advertisedAndReceived");
12672 else if (CHECK_FLAG(p->cap,
12673 PEER_CAP_EXTENDED_MESSAGE_ADV))
12674 json_object_string_add(json_cap,
12675 "extendedMessage",
12676 "advertised");
12677 else if (CHECK_FLAG(p->cap,
12678 PEER_CAP_EXTENDED_MESSAGE_RCV))
12679 json_object_string_add(json_cap,
12680 "extendedMessage",
12681 "received");
ef56aee4 12682
10711563
DA
12683 /* AddPath */
12684 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
12685 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
12686 json_object *json_add = NULL;
12687 const char *print_store;
d62a17ae 12688
10711563 12689 json_add = json_object_new_object();
d62a17ae 12690
10711563
DA
12691 FOREACH_AFI_SAFI (afi, safi) {
12692 json_object *json_sub = NULL;
12693 json_sub = json_object_new_object();
12694 print_store = get_afi_safi_str(
12695 afi, safi, true);
d62a17ae 12696
10711563
DA
12697 if (CHECK_FLAG(
12698 p->af_cap[afi][safi],
12699 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12700 CHECK_FLAG(
12701 p->af_cap[afi][safi],
12702 PEER_CAP_ADDPATH_AF_TX_RCV)) {
05c7a1cc
QY
12703 if (CHECK_FLAG(
12704 p->af_cap[afi]
12705 [safi],
10711563
DA
12706 PEER_CAP_ADDPATH_AF_TX_ADV) &&
12707 CHECK_FLAG(
05c7a1cc
QY
12708 p->af_cap[afi]
12709 [safi],
10711563
DA
12710 PEER_CAP_ADDPATH_AF_TX_RCV))
12711 json_object_boolean_true_add(
12712 json_sub,
12713 "txAdvertisedAndReceived");
12714 else if (
12715 CHECK_FLAG(
12716 p->af_cap[afi]
12717 [safi],
12718 PEER_CAP_ADDPATH_AF_TX_ADV))
12719 json_object_boolean_true_add(
12720 json_sub,
12721 "txAdvertised");
12722 else if (
12723 CHECK_FLAG(
12724 p->af_cap[afi]
12725 [safi],
12726 PEER_CAP_ADDPATH_AF_TX_RCV))
12727 json_object_boolean_true_add(
12728 json_sub,
12729 "txReceived");
12730 }
d62a17ae 12731
10711563
DA
12732 if (CHECK_FLAG(
12733 p->af_cap[afi][safi],
12734 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12735 CHECK_FLAG(
12736 p->af_cap[afi][safi],
12737 PEER_CAP_ADDPATH_AF_RX_RCV)) {
05c7a1cc
QY
12738 if (CHECK_FLAG(
12739 p->af_cap[afi]
12740 [safi],
10711563
DA
12741 PEER_CAP_ADDPATH_AF_RX_ADV) &&
12742 CHECK_FLAG(
12743 p->af_cap[afi]
12744 [safi],
12745 PEER_CAP_ADDPATH_AF_RX_RCV))
12746 json_object_boolean_true_add(
12747 json_sub,
12748 "rxAdvertisedAndReceived");
12749 else if (
12750 CHECK_FLAG(
12751 p->af_cap[afi]
12752 [safi],
12753 PEER_CAP_ADDPATH_AF_RX_ADV))
12754 json_object_boolean_true_add(
12755 json_sub,
12756 "rxAdvertised");
12757 else if (
12758 CHECK_FLAG(
12759 p->af_cap[afi]
12760 [safi],
12761 PEER_CAP_ADDPATH_AF_RX_RCV))
12762 json_object_boolean_true_add(
12763 json_sub,
12764 "rxReceived");
05c7a1cc
QY
12765 }
12766
10711563
DA
12767 if (CHECK_FLAG(
12768 p->af_cap[afi][safi],
12769 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12770 CHECK_FLAG(
12771 p->af_cap[afi][safi],
12772 PEER_CAP_ADDPATH_AF_TX_RCV) ||
12773 CHECK_FLAG(
12774 p->af_cap[afi][safi],
12775 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12776 CHECK_FLAG(
12777 p->af_cap[afi][safi],
12778 PEER_CAP_ADDPATH_AF_RX_RCV))
12779 json_object_object_add(
12780 json_add, print_store,
12781 json_sub);
12782 else
12783 json_object_free(json_sub);
d62a17ae 12784 }
12785
10711563
DA
12786 json_object_object_add(json_cap, "addPath",
12787 json_add);
12788 }
d62a17ae 12789
10711563
DA
12790 /* Dynamic */
12791 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
12792 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
12793 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
12794 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
12795 json_object_string_add(
12796 json_cap, "dynamic",
12797 "advertisedAndReceived");
12798 else if (CHECK_FLAG(p->cap,
12799 PEER_CAP_DYNAMIC_ADV))
12800 json_object_string_add(json_cap,
12801 "dynamic",
12802 "advertised");
12803 else if (CHECK_FLAG(p->cap,
12804 PEER_CAP_DYNAMIC_RCV))
12805 json_object_string_add(json_cap,
12806 "dynamic",
12807 "received");
12808 }
d62a17ae 12809
10711563
DA
12810 /* Extended nexthop */
12811 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
12812 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12813 json_object *json_nxt = NULL;
12814 const char *print_store;
d62a17ae 12815
d62a17ae 12816
10711563
DA
12817 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
12818 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12819 json_object_string_add(
12820 json_cap, "extendedNexthop",
12821 "advertisedAndReceived");
12822 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
12823 json_object_string_add(
12824 json_cap, "extendedNexthop",
12825 "advertised");
12826 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12827 json_object_string_add(
12828 json_cap, "extendedNexthop",
12829 "received");
d62a17ae 12830
10711563
DA
12831 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
12832 json_nxt = json_object_new_object();
d62a17ae 12833
10711563
DA
12834 for (safi = SAFI_UNICAST;
12835 safi < SAFI_MAX; safi++) {
12836 if (CHECK_FLAG(
12837 p->af_cap[AFI_IP]
12838 [safi],
12839 PEER_CAP_ENHE_AF_RCV)) {
12840 print_store =
12841 get_afi_safi_str(
d62a17ae 12842 AFI_IP,
10711563
DA
12843 safi,
12844 true);
12845 json_object_string_add(
12846 json_nxt,
12847 print_store,
12848 "recieved"); /* misspelled for compatibility */
d62a17ae 12849 }
d62a17ae 12850 }
10711563
DA
12851 json_object_object_add(
12852 json_cap,
12853 "extendedNexthopFamililesByPeer",
12854 json_nxt);
d62a17ae 12855 }
10711563 12856 }
d62a17ae 12857
10711563
DA
12858 /* Long-lived Graceful Restart */
12859 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
12860 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
12861 json_object *json_llgr = NULL;
12862 const char *afi_safi_str;
8606be87 12863
10711563
DA
12864 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
12865 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12866 json_object_string_add(
12867 json_cap,
12868 "longLivedGracefulRestart",
12869 "advertisedAndReceived");
12870 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
12871 json_object_string_add(
12872 json_cap,
12873 "longLivedGracefulRestart",
12874 "advertised");
12875 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12876 json_object_string_add(
12877 json_cap,
12878 "longLivedGracefulRestart",
12879 "received");
8606be87 12880
10711563
DA
12881 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
12882 json_llgr = json_object_new_object();
8606be87 12883
10711563
DA
12884 FOREACH_AFI_SAFI (afi, safi) {
12885 if (CHECK_FLAG(
12886 p->af_cap[afi]
12887 [safi],
12888 PEER_CAP_ENHE_AF_RCV)) {
12889 afi_safi_str =
12890 get_afi_safi_str(
8606be87
DA
12891 afi,
12892 safi,
12893 true);
10711563
DA
12894 json_object_string_add(
12895 json_llgr,
12896 afi_safi_str,
12897 "received");
8606be87 12898 }
8606be87 12899 }
10711563
DA
12900 json_object_object_add(
12901 json_cap,
12902 "longLivedGracefulRestartByPeer",
12903 json_llgr);
8606be87 12904 }
10711563 12905 }
8606be87 12906
10711563
DA
12907 /* Route Refresh */
12908 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
12909 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
12910 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
12911 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
12912 (CHECK_FLAG(p->cap,
12913 PEER_CAP_REFRESH_NEW_RCV) ||
12914 CHECK_FLAG(p->cap,
12915 PEER_CAP_REFRESH_OLD_RCV))) {
12916 if (CHECK_FLAG(
12917 p->cap,
12918 PEER_CAP_REFRESH_OLD_RCV) &&
12919 CHECK_FLAG(
12920 p->cap,
12921 PEER_CAP_REFRESH_NEW_RCV))
12922 json_object_string_add(
12923 json_cap,
12924 "routeRefresh",
12925 "advertisedAndReceivedOldNew");
12926 else {
d62a17ae 12927 if (CHECK_FLAG(
12928 p->cap,
10711563 12929 PEER_CAP_REFRESH_OLD_RCV))
d62a17ae 12930 json_object_string_add(
12931 json_cap,
12932 "routeRefresh",
10711563
DA
12933 "advertisedAndReceivedOld");
12934 else
12935 json_object_string_add(
12936 json_cap,
12937 "routeRefresh",
12938 "advertisedAndReceivedNew");
d62a17ae 12939 }
10711563
DA
12940 } else if (CHECK_FLAG(p->cap,
12941 PEER_CAP_REFRESH_ADV))
12942 json_object_string_add(json_cap,
12943 "routeRefresh",
12944 "advertised");
12945 else if (CHECK_FLAG(p->cap,
12946 PEER_CAP_REFRESH_NEW_RCV) ||
12947 CHECK_FLAG(p->cap,
12948 PEER_CAP_REFRESH_OLD_RCV))
12949 json_object_string_add(json_cap,
12950 "routeRefresh",
12951 "received");
12952 }
d62a17ae 12953
10711563
DA
12954 /* Enhanced Route Refresh */
12955 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
12956 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
12957 if (CHECK_FLAG(p->cap,
12958 PEER_CAP_ENHANCED_RR_ADV) &&
12959 CHECK_FLAG(p->cap,
12960 PEER_CAP_ENHANCED_RR_RCV))
d77114b7 12961 json_object_string_add(
10711563
DA
12962 json_cap,
12963 "enhancedRouteRefresh",
12964 "advertisedAndReceived");
12965 else if (CHECK_FLAG(p->cap,
12966 PEER_CAP_ENHANCED_RR_ADV))
d77114b7 12967 json_object_string_add(
10711563
DA
12968 json_cap,
12969 "enhancedRouteRefresh",
12970 "advertised");
12971 else if (CHECK_FLAG(p->cap,
9af52ccf 12972 PEER_CAP_ENHANCED_RR_RCV))
10711563
DA
12973 json_object_string_add(
12974 json_cap,
12975 "enhancedRouteRefresh",
12976 "received");
12977 }
d77114b7 12978
10711563
DA
12979 /* Multiprotocol Extensions */
12980 json_object *json_multi = NULL;
d77114b7 12981
10711563 12982 json_multi = json_object_new_object();
d77114b7 12983
10711563
DA
12984 FOREACH_AFI_SAFI (afi, safi) {
12985 if (p->afc_adv[afi][safi] ||
12986 p->afc_recv[afi][safi]) {
12987 json_object *json_exten = NULL;
12988 json_exten = json_object_new_object();
12989
12990 if (p->afc_adv[afi][safi] &&
12991 p->afc_recv[afi][safi])
12992 json_object_boolean_true_add(
12993 json_exten,
9af52ccf 12994 "advertisedAndReceived");
10711563
DA
12995 else if (p->afc_adv[afi][safi])
12996 json_object_boolean_true_add(
12997 json_exten,
9af52ccf 12998 "advertised");
10711563
DA
12999 else if (p->afc_recv[afi][safi])
13000 json_object_boolean_true_add(
13001 json_exten, "received");
9af52ccf 13002
10711563
DA
13003 json_object_object_add(
13004 json_multi,
13005 get_afi_safi_str(afi, safi,
13006 true),
13007 json_exten);
13008 }
13009 }
13010 json_object_object_add(json_cap,
13011 "multiprotocolExtensions",
13012 json_multi);
d62a17ae 13013
10711563
DA
13014 /* Hostname capabilities */
13015 json_object *json_hname = NULL;
d62a17ae 13016
10711563 13017 json_hname = json_object_new_object();
d62a17ae 13018
10711563
DA
13019 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13020 json_object_string_add(
13021 json_hname, "advHostName",
13022 bgp->peer_self->hostname
13023 ? bgp->peer_self->hostname
13024 : "n/a");
13025 json_object_string_add(
13026 json_hname, "advDomainName",
13027 bgp->peer_self->domainname
13028 ? bgp->peer_self->domainname
13029 : "n/a");
13030 }
d77114b7 13031
d77114b7 13032
10711563
DA
13033 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13034 json_object_string_add(
13035 json_hname, "rcvHostName",
13036 p->hostname ? p->hostname : "n/a");
13037 json_object_string_add(
13038 json_hname, "rcvDomainName",
13039 p->domainname ? p->domainname : "n/a");
13040 }
d77114b7 13041
10711563
DA
13042 json_object_object_add(json_cap, "hostName",
13043 json_hname);
d77114b7 13044
10711563
DA
13045 /* Gracefull Restart */
13046 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13047 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13048 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13049 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
d77114b7 13050 json_object_string_add(
10711563
DA
13051 json_cap, "gracefulRestart",
13052 "advertisedAndReceived");
13053 else if (CHECK_FLAG(p->cap,
13054 PEER_CAP_RESTART_ADV))
d77114b7 13055 json_object_string_add(
10711563
DA
13056 json_cap,
13057 "gracefulRestartCapability",
13058 "advertised");
13059 else if (CHECK_FLAG(p->cap,
13060 PEER_CAP_RESTART_RCV))
13061 json_object_string_add(
13062 json_cap,
13063 "gracefulRestartCapability",
13064 "received");
d77114b7 13065
10711563
DA
13066 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13067 int restart_af_count = 0;
13068 json_object *json_restart = NULL;
13069 json_restart = json_object_new_object();
d62a17ae 13070
10711563
DA
13071 json_object_int_add(
13072 json_cap,
13073 "gracefulRestartRemoteTimerMsecs",
13074 p->v_gr_restart * 1000);
d62a17ae 13075
10711563 13076 FOREACH_AFI_SAFI (afi, safi) {
05c7a1cc
QY
13077 if (CHECK_FLAG(
13078 p->af_cap[afi]
13079 [safi],
10711563
DA
13080 PEER_CAP_RESTART_AF_RCV)) {
13081 json_object *json_sub =
13082 NULL;
13083 json_sub =
13084 json_object_new_object();
d62a17ae 13085
05c7a1cc
QY
13086 if (CHECK_FLAG(
13087 p->af_cap
13088 [afi]
13089 [safi],
10711563
DA
13090 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13091 json_object_boolean_true_add(
13092 json_sub,
13093 "preserved");
13094 restart_af_count++;
d62a17ae 13095 json_object_object_add(
10711563
DA
13096 json_restart,
13097 get_afi_safi_str(
13098 afi,
13099 safi,
13100 true),
13101 json_sub);
d62a17ae 13102 }
d62a17ae 13103 }
10711563
DA
13104 if (!restart_af_count) {
13105 json_object_string_add(
13106 json_cap,
13107 "addressFamiliesByPeer",
13108 "none");
13109 json_object_free(json_restart);
13110 } else
13111 json_object_object_add(
13112 json_cap,
13113 "addressFamiliesByPeer",
13114 json_restart);
d62a17ae 13115 }
10711563
DA
13116 }
13117 json_object_object_add(
13118 json_neigh, "neighborCapabilities", json_cap);
13119 } else {
13120 vty_out(vty, " Neighbor capabilities:\n");
13121
13122 /* AS4 */
13123 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13124 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13125 vty_out(vty, " 4 Byte AS:");
13126 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13127 vty_out(vty, " advertised");
13128 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13129 vty_out(vty, " %sreceived",
13130 CHECK_FLAG(p->cap,
13131 PEER_CAP_AS4_ADV)
13132 ? "and "
13133 : "");
13134 vty_out(vty, "\n");
13135 }
d62a17ae 13136
10711563
DA
13137 /* Extended Message Support */
13138 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13139 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13140 vty_out(vty, " Extended Message:");
ef56aee4 13141 if (CHECK_FLAG(p->cap,
10711563
DA
13142 PEER_CAP_EXTENDED_MESSAGE_ADV))
13143 vty_out(vty, " advertised");
13144 if (CHECK_FLAG(p->cap,
13145 PEER_CAP_EXTENDED_MESSAGE_RCV))
13146 vty_out(vty, " %sreceived",
13147 CHECK_FLAG(
13148 p->cap,
13149 PEER_CAP_EXTENDED_MESSAGE_ADV)
13150 ? "and "
13151 : "");
13152 vty_out(vty, "\n");
13153 }
d62a17ae 13154
10711563
DA
13155 /* AddPath */
13156 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13157 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13158 vty_out(vty, " AddPath:\n");
d62a17ae 13159
10711563 13160 FOREACH_AFI_SAFI (afi, safi) {
ef56aee4 13161 if (CHECK_FLAG(
10711563
DA
13162 p->af_cap[afi][safi],
13163 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13164 CHECK_FLAG(
13165 p->af_cap[afi][safi],
13166 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13167 vty_out(vty, " %s: TX ",
13168 get_afi_safi_str(
13169 afi, safi,
13170 false));
ef56aee4 13171
10711563
DA
13172 if (CHECK_FLAG(
13173 p->af_cap[afi]
13174 [safi],
13175 PEER_CAP_ADDPATH_AF_TX_ADV))
13176 vty_out(vty,
13177 "advertised");
d62a17ae 13178
05c7a1cc
QY
13179 if (CHECK_FLAG(
13180 p->af_cap[afi]
13181 [safi],
10711563 13182 PEER_CAP_ADDPATH_AF_TX_RCV))
05c7a1cc 13183 vty_out(vty,
10711563
DA
13184 "%sreceived",
13185 CHECK_FLAG(
13186 p->af_cap
13187 [afi]
13188 [safi],
13189 PEER_CAP_ADDPATH_AF_TX_ADV)
13190 ? " and "
13191 : "");
05c7a1cc 13192
10711563
DA
13193 vty_out(vty, "\n");
13194 }
d62a17ae 13195
9af52ccf 13196 if (CHECK_FLAG(
10711563
DA
13197 p->af_cap[afi][safi],
13198 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13199 CHECK_FLAG(
13200 p->af_cap[afi][safi],
13201 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13202 vty_out(vty, " %s: RX ",
5cb5f4d0 13203 get_afi_safi_str(
10711563
DA
13204 afi, safi,
13205 false));
d62a17ae 13206
05c7a1cc
QY
13207 if (CHECK_FLAG(
13208 p->af_cap[afi]
13209 [safi],
10711563 13210 PEER_CAP_ADDPATH_AF_RX_ADV))
05c7a1cc 13211 vty_out(vty,
10711563 13212 "advertised");
d62a17ae 13213
10711563
DA
13214 if (CHECK_FLAG(
13215 p->af_cap[afi]
13216 [safi],
13217 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc 13218 vty_out(vty,
10711563
DA
13219 "%sreceived",
13220 CHECK_FLAG(
13221 p->af_cap
13222 [afi]
13223 [safi],
13224 PEER_CAP_ADDPATH_AF_RX_ADV)
13225 ? " and "
05c7a1cc 13226 : "");
d62a17ae 13227
05c7a1cc 13228 vty_out(vty, "\n");
05c7a1cc 13229 }
d62a17ae 13230 }
10711563 13231 }
d62a17ae 13232
10711563
DA
13233 /* Dynamic */
13234 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13235 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13236 vty_out(vty, " Dynamic:");
13237 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13238 vty_out(vty, " advertised");
13239 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13240 vty_out(vty, " %sreceived",
13241 CHECK_FLAG(p->cap,
13242 PEER_CAP_DYNAMIC_ADV)
13243 ? "and "
13244 : "");
13245 vty_out(vty, "\n");
13246 }
d62a17ae 13247
10711563
DA
13248 /* Extended nexthop */
13249 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13250 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13251 vty_out(vty, " Extended nexthop:");
13252 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13253 vty_out(vty, " advertised");
13254 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13255 vty_out(vty, " %sreceived",
13256 CHECK_FLAG(p->cap,
13257 PEER_CAP_ENHE_ADV)
13258 ? "and "
13259 : "");
13260 vty_out(vty, "\n");
d62a17ae 13261
10711563 13262 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
57f7feb6 13263 vty_out(vty,
10711563
DA
13264 " Address families by peer:\n ");
13265 for (safi = SAFI_UNICAST;
13266 safi < SAFI_MAX; safi++)
13267 if (CHECK_FLAG(
13268 p->af_cap[AFI_IP]
13269 [safi],
13270 PEER_CAP_ENHE_AF_RCV))
13271 vty_out(vty,
13272 " %s\n",
13273 get_afi_safi_str(
13274 AFI_IP,
13275 safi,
13276 false));
d62a17ae 13277 }
10711563 13278 }
d62a17ae 13279
10711563
DA
13280 /* Long-lived Graceful Restart */
13281 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13282 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13283 vty_out(vty,
13284 " Long-lived Graceful Restart:");
13285 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13286 vty_out(vty, " advertised");
13287 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13288 vty_out(vty, " %sreceived",
13289 CHECK_FLAG(p->cap,
13290 PEER_CAP_LLGR_ADV)
13291 ? "and "
13292 : "");
13293 vty_out(vty, "\n");
8606be87 13294
10711563 13295 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
57f7feb6 13296 vty_out(vty,
10711563
DA
13297 " Address families by peer:\n");
13298 FOREACH_AFI_SAFI (afi, safi)
13299 if (CHECK_FLAG(
13300 p->af_cap[afi]
13301 [safi],
13302 PEER_CAP_LLGR_AF_RCV))
13303 vty_out(vty,
13304 " %s\n",
13305 get_afi_safi_str(
13306 afi,
13307 safi,
13308 false));
8606be87 13309 }
10711563 13310 }
8606be87 13311
10711563
DA
13312 /* Route Refresh */
13313 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13314 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13315 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13316 vty_out(vty, " Route refresh:");
13317 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13318 vty_out(vty, " advertised");
13319 if (CHECK_FLAG(p->cap,
13320 PEER_CAP_REFRESH_NEW_RCV) ||
13321 CHECK_FLAG(p->cap,
13322 PEER_CAP_REFRESH_OLD_RCV))
13323 vty_out(vty, " %sreceived(%s)",
13324 CHECK_FLAG(p->cap,
13325 PEER_CAP_REFRESH_ADV)
13326 ? "and "
13327 : "",
13328 (CHECK_FLAG(
13329 p->cap,
13330 PEER_CAP_REFRESH_OLD_RCV) &&
13331 CHECK_FLAG(
13332 p->cap,
13333 PEER_CAP_REFRESH_NEW_RCV))
13334 ? "old & new"
13335 : CHECK_FLAG(
13336 p->cap,
13337 PEER_CAP_REFRESH_OLD_RCV)
13338 ? "old"
13339 : "new");
d62a17ae 13340
d77114b7 13341 vty_out(vty, "\n");
10711563 13342 }
d62a17ae 13343
10711563
DA
13344 /* Enhanced Route Refresh */
13345 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13346 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13347 vty_out(vty, " Enhanced Route Refresh:");
13348 if (CHECK_FLAG(p->cap,
13349 PEER_CAP_ENHANCED_RR_ADV))
13350 vty_out(vty, " advertised");
13351 if (CHECK_FLAG(p->cap,
13352 PEER_CAP_ENHANCED_RR_RCV))
13353 vty_out(vty, " %sreceived",
13354 CHECK_FLAG(p->cap,
13355 PEER_CAP_REFRESH_ADV)
13356 ? "and "
13357 : "");
13358 vty_out(vty, "\n");
13359 }
13360
13361 /* Multiprotocol Extensions */
13362 FOREACH_AFI_SAFI (afi, safi)
13363 if (p->afc_adv[afi][safi] ||
13364 p->afc_recv[afi][safi]) {
13365 vty_out(vty, " Address Family %s:",
13366 get_afi_safi_str(afi, safi,
13367 false));
13368 if (p->afc_adv[afi][safi])
9af52ccf 13369 vty_out(vty, " advertised");
10711563 13370 if (p->afc_recv[afi][safi])
9af52ccf 13371 vty_out(vty, " %sreceived",
10711563 13372 p->afc_adv[afi][safi]
9af52ccf
DA
13373 ? "and "
13374 : "");
13375 vty_out(vty, "\n");
13376 }
13377
10711563
DA
13378 /* Hostname capability */
13379 vty_out(vty, " Hostname Capability:");
d62a17ae 13380
10711563
DA
13381 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13382 vty_out(vty,
13383 " advertised (name: %s,domain name: %s)",
13384 bgp->peer_self->hostname
13385 ? bgp->peer_self->hostname
13386 : "n/a",
13387 bgp->peer_self->domainname
13388 ? bgp->peer_self->domainname
13389 : "n/a");
13390 } else {
13391 vty_out(vty, " not advertised");
13392 }
d77114b7 13393
10711563
DA
13394 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13395 vty_out(vty,
13396 " received (name: %s,domain name: %s)",
13397 p->hostname ? p->hostname : "n/a",
13398 p->domainname ? p->domainname : "n/a");
13399 } else {
13400 vty_out(vty, " not received");
d62a17ae 13401 }
d62a17ae 13402
10711563 13403 vty_out(vty, "\n");
d77114b7 13404
10711563
DA
13405 /* Graceful Restart */
13406 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13407 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13408 vty_out(vty,
13409 " Graceful Restart Capability:");
13410 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13411 vty_out(vty, " advertised");
13412 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13413 vty_out(vty, " %sreceived",
13414 CHECK_FLAG(p->cap,
13415 PEER_CAP_RESTART_ADV)
13416 ? "and "
13417 : "");
d77114b7
MK
13418 vty_out(vty, "\n");
13419
10711563
DA
13420 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13421 int restart_af_count = 0;
d62a17ae 13422
10711563
DA
13423 vty_out(vty,
13424 " Remote Restart timer is %d seconds\n",
13425 p->v_gr_restart);
13426 vty_out(vty,
13427 " Address families by peer:\n ");
d62a17ae 13428
10711563
DA
13429 FOREACH_AFI_SAFI (afi, safi)
13430 if (CHECK_FLAG(
13431 p->af_cap[afi]
13432 [safi],
13433 PEER_CAP_RESTART_AF_RCV)) {
13434 vty_out(vty, "%s%s(%s)",
13435 restart_af_count
13436 ? ", "
13437 : "",
13438 get_afi_safi_str(
13439 afi,
13440 safi,
13441 false),
13442 CHECK_FLAG(
13443 p->af_cap
13444 [afi]
13445 [safi],
13446 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13447 ? "preserved"
13448 : "not preserved");
13449 restart_af_count++;
13450 }
13451 if (!restart_af_count)
13452 vty_out(vty, "none");
13453 vty_out(vty, "\n");
13454 }
13455 } /* Gracefull Restart */
d62a17ae 13456 }
13457 }
13458
13459 /* graceful restart information */
10711563
DA
13460 json_object *json_grace = NULL;
13461 json_object *json_grace_send = NULL;
13462 json_object *json_grace_recv = NULL;
13463 int eor_send_af_count = 0;
13464 int eor_receive_af_count = 0;
d62a17ae 13465
10711563
DA
13466 if (use_json) {
13467 json_grace = json_object_new_object();
13468 json_grace_send = json_object_new_object();
13469 json_grace_recv = json_object_new_object();
13470
13471 if ((peer_established(p)) &&
13472 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13473 FOREACH_AFI_SAFI (afi, safi) {
13474 if (CHECK_FLAG(p->af_sflags[afi][safi],
13475 PEER_STATUS_EOR_SEND)) {
13476 json_object_boolean_true_add(
13477 json_grace_send,
13478 get_afi_safi_str(afi, safi,
13479 true));
13480 eor_send_af_count++;
d62a17ae 13481 }
10711563
DA
13482 }
13483 FOREACH_AFI_SAFI (afi, safi) {
13484 if (CHECK_FLAG(p->af_sflags[afi][safi],
13485 PEER_STATUS_EOR_RECEIVED)) {
13486 json_object_boolean_true_add(
13487 json_grace_recv,
13488 get_afi_safi_str(afi, safi,
13489 true));
13490 eor_receive_af_count++;
d62a17ae 13491 }
13492 }
10711563
DA
13493 }
13494 json_object_object_add(json_grace, "endOfRibSend",
13495 json_grace_send);
13496 json_object_object_add(json_grace, "endOfRibRecv",
13497 json_grace_recv);
d62a17ae 13498
d62a17ae 13499
10711563
DA
13500 if (p->t_gr_restart)
13501 json_object_int_add(
13502 json_grace, "gracefulRestartTimerMsecs",
13503 thread_timer_remain_second(p->t_gr_restart) *
13504 1000);
2986cac2 13505
10711563
DA
13506 if (p->t_gr_stale)
13507 json_object_int_add(
13508 json_grace, "gracefulStalepathTimerMsecs",
13509 thread_timer_remain_second(p->t_gr_stale) *
13510 1000);
13511 /* more gr info in new format */
13512 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13513 json_object_object_add(json_neigh, "gracefulRestartInfo",
13514 json_grace);
13515 } else {
13516 vty_out(vty, " Graceful restart information:\n");
13517 if ((peer_established(p)) &&
13518 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13519
13520 vty_out(vty, " End-of-RIB send: ");
13521 FOREACH_AFI_SAFI (afi, safi) {
13522 if (CHECK_FLAG(p->af_sflags[afi][safi],
13523 PEER_STATUS_EOR_SEND)) {
13524 vty_out(vty, "%s%s",
13525 eor_send_af_count ? ", " : "",
13526 get_afi_safi_str(afi, safi,
13527 false));
13528 eor_send_af_count++;
d62a17ae 13529 }
10711563
DA
13530 }
13531 vty_out(vty, "\n");
13532 vty_out(vty, " End-of-RIB received: ");
13533 FOREACH_AFI_SAFI (afi, safi) {
13534 if (CHECK_FLAG(p->af_sflags[afi][safi],
13535 PEER_STATUS_EOR_RECEIVED)) {
13536 vty_out(vty, "%s%s",
13537 eor_receive_af_count ? ", "
13538 : "",
13539 get_afi_safi_str(afi, safi,
13540 false));
13541 eor_receive_af_count++;
d62a17ae 13542 }
d62a17ae 13543 }
10711563
DA
13544 vty_out(vty, "\n");
13545 }
d62a17ae 13546
10711563
DA
13547 if (p->t_gr_restart)
13548 vty_out(vty,
13549 " The remaining time of restart timer is %ld\n",
13550 thread_timer_remain_second(p->t_gr_restart));
d62a17ae 13551
10711563
DA
13552 if (p->t_gr_stale)
13553 vty_out(vty,
13554 " The remaining time of stalepath timer is %ld\n",
13555 thread_timer_remain_second(p->t_gr_stale));
2986cac2 13556
10711563
DA
13557 /* more gr info in new format */
13558 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13559 }
2986cac2 13560
d62a17ae 13561 if (use_json) {
13562 json_object *json_stat = NULL;
13563 json_stat = json_object_new_object();
13564 /* Packet counts. */
43aa5965
QY
13565
13566 atomic_size_t outq_count, inq_count;
13567 outq_count = atomic_load_explicit(&p->obuf->count,
13568 memory_order_relaxed);
13569 inq_count = atomic_load_explicit(&p->ibuf->count,
13570 memory_order_relaxed);
13571
13572 json_object_int_add(json_stat, "depthInq",
13573 (unsigned long)inq_count);
d62a17ae 13574 json_object_int_add(json_stat, "depthOutq",
43aa5965 13575 (unsigned long)outq_count);
0112e9e0
QY
13576 json_object_int_add(json_stat, "opensSent",
13577 atomic_load_explicit(&p->open_out,
13578 memory_order_relaxed));
13579 json_object_int_add(json_stat, "opensRecv",
13580 atomic_load_explicit(&p->open_in,
13581 memory_order_relaxed));
d62a17ae 13582 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
13583 atomic_load_explicit(&p->notify_out,
13584 memory_order_relaxed));
d62a17ae 13585 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
13586 atomic_load_explicit(&p->notify_in,
13587 memory_order_relaxed));
13588 json_object_int_add(json_stat, "updatesSent",
13589 atomic_load_explicit(&p->update_out,
13590 memory_order_relaxed));
13591 json_object_int_add(json_stat, "updatesRecv",
13592 atomic_load_explicit(&p->update_in,
13593 memory_order_relaxed));
d62a17ae 13594 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
13595 atomic_load_explicit(&p->keepalive_out,
13596 memory_order_relaxed));
d62a17ae 13597 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
13598 atomic_load_explicit(&p->keepalive_in,
13599 memory_order_relaxed));
d62a17ae 13600 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
13601 atomic_load_explicit(&p->refresh_out,
13602 memory_order_relaxed));
d62a17ae 13603 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
13604 atomic_load_explicit(&p->refresh_in,
13605 memory_order_relaxed));
d62a17ae 13606 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
13607 atomic_load_explicit(&p->dynamic_cap_out,
13608 memory_order_relaxed));
d62a17ae 13609 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
13610 atomic_load_explicit(&p->dynamic_cap_in,
13611 memory_order_relaxed));
13612 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13613 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 13614 json_object_object_add(json_neigh, "messageStats", json_stat);
13615 } else {
cb93e0a2
IS
13616 atomic_size_t outq_count, inq_count, open_out, open_in,
13617 notify_out, notify_in, update_out, update_in,
13618 keepalive_out, keepalive_in, refresh_out, refresh_in,
13619 dynamic_cap_out, dynamic_cap_in;
43aa5965
QY
13620 outq_count = atomic_load_explicit(&p->obuf->count,
13621 memory_order_relaxed);
13622 inq_count = atomic_load_explicit(&p->ibuf->count,
13623 memory_order_relaxed);
cb93e0a2
IS
13624 open_out = atomic_load_explicit(&p->open_out,
13625 memory_order_relaxed);
13626 open_in =
13627 atomic_load_explicit(&p->open_in, memory_order_relaxed);
13628 notify_out = atomic_load_explicit(&p->notify_out,
13629 memory_order_relaxed);
13630 notify_in = atomic_load_explicit(&p->notify_in,
13631 memory_order_relaxed);
13632 update_out = atomic_load_explicit(&p->update_out,
13633 memory_order_relaxed);
13634 update_in = atomic_load_explicit(&p->update_in,
13635 memory_order_relaxed);
13636 keepalive_out = atomic_load_explicit(&p->keepalive_out,
13637 memory_order_relaxed);
13638 keepalive_in = atomic_load_explicit(&p->keepalive_in,
13639 memory_order_relaxed);
13640 refresh_out = atomic_load_explicit(&p->refresh_out,
13641 memory_order_relaxed);
13642 refresh_in = atomic_load_explicit(&p->refresh_in,
13643 memory_order_relaxed);
13644 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
13645 memory_order_relaxed);
13646 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
13647 memory_order_relaxed);
43aa5965 13648
d62a17ae 13649 /* Packet counts. */
13650 vty_out(vty, " Message statistics:\n");
43aa5965
QY
13651 vty_out(vty, " Inq depth is %zu\n", inq_count);
13652 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 13653 vty_out(vty, " Sent Rcvd\n");
cb93e0a2
IS
13654 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
13655 open_in);
13656 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
13657 notify_in);
13658 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
13659 update_in);
13660 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
13661 keepalive_in);
13662 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
13663 refresh_in);
13664 vty_out(vty, " Capability: %10zu %10zu\n",
13665 dynamic_cap_out, dynamic_cap_in);
13666 vty_out(vty, " Total: %10u %10u\n",
13667 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
d62a17ae 13668 }
13669
13670 if (use_json) {
13671 /* advertisement-interval */
13672 json_object_int_add(json_neigh,
13673 "minBtwnAdvertisementRunsTimerMsecs",
13674 p->v_routeadv * 1000);
13675
13676 /* Update-source. */
13677 if (p->update_if || p->update_source) {
13678 if (p->update_if)
13679 json_object_string_add(json_neigh,
13680 "updateSource",
13681 p->update_if);
13682 else if (p->update_source)
13683 json_object_string_add(
13684 json_neigh, "updateSource",
13685 sockunion2str(p->update_source, buf1,
13686 SU_ADDRSTRLEN));
13687 }
13688 } else {
13689 /* advertisement-interval */
13690 vty_out(vty,
13691 " Minimum time between advertisement runs is %d seconds\n",
13692 p->v_routeadv);
13693
13694 /* Update-source. */
13695 if (p->update_if || p->update_source) {
13696 vty_out(vty, " Update source is ");
13697 if (p->update_if)
13698 vty_out(vty, "%s", p->update_if);
13699 else if (p->update_source)
13700 vty_out(vty, "%s",
13701 sockunion2str(p->update_source, buf1,
13702 SU_ADDRSTRLEN));
13703 vty_out(vty, "\n");
13704 }
13705
13706 vty_out(vty, "\n");
13707 }
13708
13709 /* Address Family Information */
13710 json_object *json_hold = NULL;
13711
13712 if (use_json)
13713 json_hold = json_object_new_object();
13714
05c7a1cc
QY
13715 FOREACH_AFI_SAFI (afi, safi)
13716 if (p->afc[afi][safi])
13717 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13718 json_hold);
d62a17ae 13719
13720 if (use_json) {
13721 json_object_object_add(json_neigh, "addressFamilyInfo",
13722 json_hold);
13723 json_object_int_add(json_neigh, "connectionsEstablished",
13724 p->established);
13725 json_object_int_add(json_neigh, "connectionsDropped",
13726 p->dropped);
13727 } else
13728 vty_out(vty, " Connections established %d; dropped %d\n",
13729 p->established, p->dropped);
13730
13731 if (!p->last_reset) {
13732 if (use_json)
13733 json_object_string_add(json_neigh, "lastReset",
13734 "never");
13735 else
13736 vty_out(vty, " Last reset never\n");
13737 } else {
13738 if (use_json) {
13739 time_t uptime;
a2700b50 13740 struct tm tm;
d62a17ae 13741
13742 uptime = bgp_clock();
13743 uptime -= p->resettime;
a2700b50
MS
13744 gmtime_r(&uptime, &tm);
13745
d62a17ae 13746 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
13747 (tm.tm_sec * 1000)
13748 + (tm.tm_min * 60000)
13749 + (tm.tm_hour * 3600000));
3577f1c5 13750 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 13751 } else {
13752 vty_out(vty, " Last reset %s, ",
13753 peer_uptime(p->resettime, timebuf,
13754 BGP_UPTIME_LEN, 0, NULL));
13755
3577f1c5 13756 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 13757 if (p->last_reset_cause_size) {
13758 msg = p->last_reset_cause;
13759 vty_out(vty,
13760 " Message received that caused BGP to send a NOTIFICATION:\n ");
13761 for (i = 1; i <= p->last_reset_cause_size;
13762 i++) {
13763 vty_out(vty, "%02X", *msg++);
13764
13765 if (i != p->last_reset_cause_size) {
13766 if (i % 16 == 0) {
13767 vty_out(vty, "\n ");
13768 } else if (i % 4 == 0) {
13769 vty_out(vty, " ");
13770 }
13771 }
13772 }
13773 vty_out(vty, "\n");
13774 }
13775 }
13776 }
13777
13778 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13779 if (use_json)
13780 json_object_boolean_true_add(json_neigh,
13781 "prefixesConfigExceedMax");
13782 else
13783 vty_out(vty,
13784 " Peer had exceeded the max. no. of prefixes configured.\n");
13785
13786 if (p->t_pmax_restart) {
13787 if (use_json) {
13788 json_object_boolean_true_add(
13789 json_neigh, "reducePrefixNumFrom");
13790 json_object_int_add(json_neigh,
13791 "restartInTimerMsec",
13792 thread_timer_remain_second(
13793 p->t_pmax_restart)
13794 * 1000);
13795 } else
13796 vty_out(vty,
13797 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
13798 p->host, thread_timer_remain_second(
13799 p->t_pmax_restart));
d62a17ae 13800 } else {
13801 if (use_json)
13802 json_object_boolean_true_add(
13803 json_neigh,
13804 "reducePrefixNumAndClearIpBgp");
13805 else
13806 vty_out(vty,
13807 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13808 p->host);
13809 }
13810 }
13811
13812 /* EBGP Multihop and GTSM */
13813 if (p->sort != BGP_PEER_IBGP) {
13814 if (use_json) {
e2521429 13815 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13816 json_object_int_add(json_neigh,
13817 "externalBgpNbrMaxHopsAway",
13818 p->gtsm_hops);
c8d6f0d6 13819 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13820 json_object_int_add(json_neigh,
13821 "externalBgpNbrMaxHopsAway",
13822 p->ttl);
13823 } else {
e2521429 13824 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13825 vty_out(vty,
13826 " External BGP neighbor may be up to %d hops away.\n",
13827 p->gtsm_hops);
c8d6f0d6 13828 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13829 vty_out(vty,
13830 " External BGP neighbor may be up to %d hops away.\n",
13831 p->ttl);
13832 }
13833 } else {
e2521429 13834 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 13835 if (use_json)
13836 json_object_int_add(json_neigh,
13837 "internalBgpNbrMaxHopsAway",
13838 p->gtsm_hops);
13839 else
13840 vty_out(vty,
13841 " Internal BGP neighbor may be up to %d hops away.\n",
13842 p->gtsm_hops);
13843 }
13844 }
13845
13846 /* Local address. */
13847 if (p->su_local) {
13848 if (use_json) {
13849 json_object_string_add(json_neigh, "hostLocal",
13850 sockunion2str(p->su_local, buf1,
13851 SU_ADDRSTRLEN));
13852 json_object_int_add(json_neigh, "portLocal",
13853 ntohs(p->su_local->sin.sin_port));
13854 } else
13855 vty_out(vty, "Local host: %s, Local port: %d\n",
13856 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
13857 ntohs(p->su_local->sin.sin_port));
13858 }
13859
13860 /* Remote address. */
13861 if (p->su_remote) {
13862 if (use_json) {
13863 json_object_string_add(json_neigh, "hostForeign",
13864 sockunion2str(p->su_remote, buf1,
13865 SU_ADDRSTRLEN));
13866 json_object_int_add(json_neigh, "portForeign",
13867 ntohs(p->su_remote->sin.sin_port));
13868 } else
13869 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
13870 sockunion2str(p->su_remote, buf1,
13871 SU_ADDRSTRLEN),
13872 ntohs(p->su_remote->sin.sin_port));
13873 }
13874
13875 /* Nexthop display. */
13876 if (p->su_local) {
13877 if (use_json) {
c949c771
DA
13878 json_object_string_addf(json_neigh, "nexthop", "%pI4",
13879 &p->nexthop.v4);
13880 json_object_string_addf(json_neigh, "nexthopGlobal",
13881 "%pI6", &p->nexthop.v6_global);
13882 json_object_string_addf(json_neigh, "nexthopLocal",
13883 "%pI6", &p->nexthop.v6_local);
d62a17ae 13884 if (p->shared_network)
13885 json_object_string_add(json_neigh,
13886 "bgpConnection",
13887 "sharedNetwork");
13888 else
13889 json_object_string_add(json_neigh,
13890 "bgpConnection",
13891 "nonSharedNetwork");
13892 } else {
13893 vty_out(vty, "Nexthop: %s\n",
13894 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
13895 sizeof(buf1)));
13896 vty_out(vty, "Nexthop global: %s\n",
13897 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
13898 sizeof(buf1)));
13899 vty_out(vty, "Nexthop local: %s\n",
13900 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
13901 sizeof(buf1)));
13902 vty_out(vty, "BGP connection: %s\n",
13903 p->shared_network ? "shared network"
13904 : "non shared network");
13905 }
13906 }
13907
13908 /* Timer information. */
13909 if (use_json) {
13910 json_object_int_add(json_neigh, "connectRetryTimer",
13911 p->v_connect);
feb17238 13912 if (peer_established(p) && p->rtt)
d62a17ae 13913 json_object_int_add(json_neigh, "estimatedRttInMsecs",
13914 p->rtt);
13915 if (p->t_start)
13916 json_object_int_add(
13917 json_neigh, "nextStartTimerDueInMsecs",
13918 thread_timer_remain_second(p->t_start) * 1000);
13919 if (p->t_connect)
13920 json_object_int_add(
13921 json_neigh, "nextConnectTimerDueInMsecs",
13922 thread_timer_remain_second(p->t_connect)
13923 * 1000);
13924 if (p->t_routeadv) {
13925 json_object_int_add(json_neigh, "mraiInterval",
13926 p->v_routeadv);
13927 json_object_int_add(
13928 json_neigh, "mraiTimerExpireInMsecs",
13929 thread_timer_remain_second(p->t_routeadv)
13930 * 1000);
13931 }
13932 if (p->password)
13933 json_object_int_add(json_neigh, "authenticationEnabled",
13934 1);
13935
13936 if (p->t_read)
13937 json_object_string_add(json_neigh, "readThread", "on");
13938 else
13939 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
13940
13941 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 13942 json_object_string_add(json_neigh, "writeThread", "on");
13943 else
13944 json_object_string_add(json_neigh, "writeThread",
13945 "off");
13946 } else {
13947 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
13948 p->v_connect);
feb17238 13949 if (peer_established(p) && p->rtt)
d62a17ae 13950 vty_out(vty, "Estimated round trip time: %d ms\n",
13951 p->rtt);
13952 if (p->t_start)
13953 vty_out(vty, "Next start timer due in %ld seconds\n",
13954 thread_timer_remain_second(p->t_start));
13955 if (p->t_connect)
13956 vty_out(vty, "Next connect timer due in %ld seconds\n",
13957 thread_timer_remain_second(p->t_connect));
13958 if (p->t_routeadv)
13959 vty_out(vty,
13960 "MRAI (interval %u) timer expires in %ld seconds\n",
13961 p->v_routeadv,
13962 thread_timer_remain_second(p->t_routeadv));
13963 if (p->password)
13964 vty_out(vty, "Peer Authentication Enabled\n");
13965
cac9e917 13966 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
13967 p->t_read ? "on" : "off",
13968 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
13969 ? "on"
cac9e917 13970 : "off", p->fd);
d62a17ae 13971 }
13972
13973 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
13974 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
13975 bgp_capability_vty_out(vty, p, use_json, json_neigh);
13976
13977 if (!use_json)
13978 vty_out(vty, "\n");
13979
13980 /* BFD information. */
21bfce98
RZ
13981 if (p->bfd_config)
13982 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 13983
13984 if (use_json) {
13985 if (p->conf_if) /* Configured interface name. */
13986 json_object_object_add(json, p->conf_if, json_neigh);
13987 else /* Configured IP address. */
13988 json_object_object_add(json, p->host, json_neigh);
13989 }
13990}
13991
36235319
QY
13992static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
13993 enum show_type type,
13994 union sockunion *su,
13995 const char *conf_if, afi_t afi,
74a630b6 13996 bool use_json)
2986cac2 13997{
13998 struct listnode *node, *nnode;
13999 struct peer *peer;
14000 int find = 0;
14001 safi_t safi = SAFI_UNICAST;
74a630b6 14002 json_object *json = NULL;
2986cac2 14003 json_object *json_neighbor = NULL;
14004
74a630b6
NT
14005 if (use_json) {
14006 json = json_object_new_object();
14007 json_neighbor = json_object_new_object();
14008 }
14009
2986cac2 14010 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14011
14012 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14013 continue;
14014
14015 if ((peer->afc[afi][safi]) == 0)
14016 continue;
14017
2ba1fe69 14018 if (type == show_all) {
2986cac2 14019 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 14020 json_neighbor);
2986cac2 14021
74a630b6 14022 if (use_json) {
13909c4f
DS
14023 json_object_object_add(json, peer->host,
14024 json_neighbor);
74a630b6
NT
14025 json_neighbor = NULL;
14026 }
2986cac2 14027
2ba1fe69 14028 } else if (type == show_peer) {
2986cac2 14029 if (conf_if) {
14030 if ((peer->conf_if
13909c4f
DS
14031 && !strcmp(peer->conf_if, conf_if))
14032 || (peer->hostname
2986cac2 14033 && !strcmp(peer->hostname, conf_if))) {
14034 find = 1;
13909c4f
DS
14035 bgp_show_peer_gr_status(vty, peer,
14036 use_json,
14037 json_neighbor);
2986cac2 14038 }
14039 } else {
14040 if (sockunion_same(&peer->su, su)) {
14041 find = 1;
13909c4f
DS
14042 bgp_show_peer_gr_status(vty, peer,
14043 use_json,
14044 json_neighbor);
2986cac2 14045 }
14046 }
13909c4f
DS
14047 if (use_json && find)
14048 json_object_object_add(json, peer->host,
14049 json_neighbor);
2986cac2 14050 }
14051
74a630b6
NT
14052 if (find) {
14053 json_neighbor = NULL;
2986cac2 14054 break;
74a630b6 14055 }
2986cac2 14056 }
14057
14058 if (type == show_peer && !find) {
14059 if (use_json)
13909c4f 14060 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14061 else
14062 vty_out(vty, "%% No such neighbor\n");
14063 }
14064 if (use_json) {
74a630b6
NT
14065 if (json_neighbor)
14066 json_object_free(json_neighbor);
75eeda93 14067 vty_json(vty, json);
2986cac2 14068 } else {
14069 vty_out(vty, "\n");
14070 }
14071
14072 return CMD_SUCCESS;
14073}
14074
d62a17ae 14075static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14076 enum show_type type, union sockunion *su,
9f049418 14077 const char *conf_if, bool use_json,
d62a17ae 14078 json_object *json)
14079{
14080 struct listnode *node, *nnode;
14081 struct peer *peer;
14082 int find = 0;
9f049418 14083 bool nbr_output = false;
d1927ebe
AS
14084 afi_t afi = AFI_MAX;
14085 safi_t safi = SAFI_MAX;
14086
14087 if (type == show_ipv4_peer || type == show_ipv4_all) {
14088 afi = AFI_IP;
14089 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14090 afi = AFI_IP6;
14091 }
d62a17ae 14092
14093 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14094 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14095 continue;
14096
14097 switch (type) {
14098 case show_all:
14099 bgp_show_peer(vty, peer, use_json, json);
9f049418 14100 nbr_output = true;
d62a17ae 14101 break;
14102 case show_peer:
14103 if (conf_if) {
14104 if ((peer->conf_if
14105 && !strcmp(peer->conf_if, conf_if))
14106 || (peer->hostname
14107 && !strcmp(peer->hostname, conf_if))) {
14108 find = 1;
14109 bgp_show_peer(vty, peer, use_json,
14110 json);
14111 }
14112 } else {
14113 if (sockunion_same(&peer->su, su)) {
14114 find = 1;
14115 bgp_show_peer(vty, peer, use_json,
14116 json);
14117 }
14118 }
14119 break;
d1927ebe
AS
14120 case show_ipv4_peer:
14121 case show_ipv6_peer:
14122 FOREACH_SAFI (safi) {
14123 if (peer->afc[afi][safi]) {
14124 if (conf_if) {
14125 if ((peer->conf_if
14126 && !strcmp(peer->conf_if, conf_if))
14127 || (peer->hostname
14128 && !strcmp(peer->hostname, conf_if))) {
14129 find = 1;
14130 bgp_show_peer(vty, peer, use_json,
14131 json);
14132 break;
14133 }
14134 } else {
14135 if (sockunion_same(&peer->su, su)) {
14136 find = 1;
14137 bgp_show_peer(vty, peer, use_json,
14138 json);
14139 break;
14140 }
14141 }
14142 }
14143 }
14144 break;
14145 case show_ipv4_all:
14146 case show_ipv6_all:
14147 FOREACH_SAFI (safi) {
14148 if (peer->afc[afi][safi]) {
14149 bgp_show_peer(vty, peer, use_json, json);
14150 nbr_output = true;
14151 break;
14152 }
14153 }
14154 break;
d62a17ae 14155 }
14156 }
14157
d1927ebe
AS
14158 if ((type == show_peer || type == show_ipv4_peer ||
14159 type == show_ipv6_peer) && !find) {
d62a17ae 14160 if (use_json)
14161 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14162 else
88b7d255 14163 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14164 }
14165
d1927ebe
AS
14166 if (type != show_peer && type != show_ipv4_peer &&
14167 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14168 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14169
d62a17ae 14170 if (use_json) {
996c9314
LB
14171 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14172 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14173 } else {
14174 vty_out(vty, "\n");
14175 }
14176
14177 return CMD_SUCCESS;
14178}
14179
36235319
QY
14180static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14181 enum show_type type,
14182 const char *ip_str,
14183 afi_t afi, bool use_json)
2986cac2 14184{
14185
14186 int ret;
14187 struct bgp *bgp;
14188 union sockunion su;
2986cac2 14189
14190 bgp = bgp_get_default();
14191
13909c4f
DS
14192 if (!bgp)
14193 return;
2986cac2 14194
13909c4f
DS
14195 if (!use_json)
14196 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14197 NULL);
2986cac2 14198
13909c4f
DS
14199 if (ip_str) {
14200 ret = str2sockunion(ip_str, &su);
14201 if (ret < 0)
13909c4f 14202 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14203 vty, bgp, type, NULL, ip_str, afi, use_json);
14204 else
14205 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14206 NULL, afi, use_json);
13909c4f
DS
14207 } else
14208 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14209 afi, use_json);
2986cac2 14210}
14211
d62a17ae 14212static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14213 enum show_type type,
14214 const char *ip_str,
9f049418 14215 bool use_json)
d62a17ae 14216{
0291c246
MK
14217 struct listnode *node, *nnode;
14218 struct bgp *bgp;
71aedaa3 14219 union sockunion su;
0291c246 14220 json_object *json = NULL;
71aedaa3 14221 int ret, is_first = 1;
9f049418 14222 bool nbr_output = false;
d62a17ae 14223
14224 if (use_json)
14225 vty_out(vty, "{\n");
14226
14227 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14228 nbr_output = true;
d62a17ae 14229 if (use_json) {
14230 if (!(json = json_object_new_object())) {
af4c2728 14231 flog_err(
e50f7cfd 14232 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14233 "Unable to allocate memory for JSON object");
14234 vty_out(vty,
14235 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14236 return;
14237 }
14238
14239 json_object_int_add(json, "vrfId",
14240 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14241 ? -1
14242 : (int64_t)bgp->vrf_id);
d62a17ae 14243 json_object_string_add(
14244 json, "vrfName",
14245 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14246 ? VRF_DEFAULT_NAME
d62a17ae 14247 : bgp->name);
14248
14249 if (!is_first)
14250 vty_out(vty, ",\n");
14251 else
14252 is_first = 0;
14253
14254 vty_out(vty, "\"%s\":",
14255 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14256 ? VRF_DEFAULT_NAME
d62a17ae 14257 : bgp->name);
14258 } else {
14259 vty_out(vty, "\nInstance %s:\n",
14260 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14261 ? VRF_DEFAULT_NAME
d62a17ae 14262 : bgp->name);
14263 }
71aedaa3 14264
d1927ebe
AS
14265 if (type == show_peer || type == show_ipv4_peer ||
14266 type == show_ipv6_peer) {
71aedaa3
DS
14267 ret = str2sockunion(ip_str, &su);
14268 if (ret < 0)
14269 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14270 use_json, json);
14271 else
14272 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14273 use_json, json);
14274 } else {
d1927ebe 14275 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14276 use_json, json);
14277 }
b77004d6 14278 json_object_free(json);
121067e9 14279 json = NULL;
d62a17ae 14280 }
14281
3e78a6ce 14282 if (use_json)
d62a17ae 14283 vty_out(vty, "}\n");
9f049418
DS
14284 else if (!nbr_output)
14285 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14286}
14287
14288static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14289 enum show_type type, const char *ip_str,
9f049418 14290 bool use_json)
d62a17ae 14291{
14292 int ret;
14293 struct bgp *bgp;
14294 union sockunion su;
14295 json_object *json = NULL;
14296
14297 if (name) {
14298 if (strmatch(name, "all")) {
71aedaa3
DS
14299 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14300 use_json);
d62a17ae 14301 return CMD_SUCCESS;
14302 } else {
14303 bgp = bgp_lookup_by_name(name);
14304 if (!bgp) {
14305 if (use_json) {
14306 json = json_object_new_object();
75eeda93 14307 vty_json(vty, json);
d62a17ae 14308 } else
14309 vty_out(vty,
9f049418 14310 "%% BGP instance not found\n");
d62a17ae 14311
14312 return CMD_WARNING;
14313 }
14314 }
14315 } else {
14316 bgp = bgp_get_default();
14317 }
14318
14319 if (bgp) {
14320 json = json_object_new_object();
14321 if (ip_str) {
14322 ret = str2sockunion(ip_str, &su);
14323 if (ret < 0)
14324 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14325 use_json, json);
14326 else
14327 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14328 use_json, json);
14329 } else {
14330 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14331 json);
14332 }
14333 json_object_free(json);
ca61fd25
DS
14334 } else {
14335 if (use_json)
14336 vty_out(vty, "{}\n");
14337 else
14338 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14339 }
14340
14341 return CMD_SUCCESS;
4fb25c53
DW
14342}
14343
2986cac2 14344
14345
14346/* "show [ip] bgp neighbors graceful-restart" commands. */
14347DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14348 show_ip_bgp_neighbors_graceful_restart_cmd,
14349 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14350 SHOW_STR
14351 BGP_STR
14352 IP_STR
14353 IPV6_STR
14354 NEIGHBOR_STR
14355 "Neighbor to display information about\n"
14356 "Neighbor to display information about\n"
14357 "Neighbor on BGP configured interface\n"
14358 GR_SHOW
14359 JSON_STR)
14360{
14361 char *sh_arg = NULL;
14362 enum show_type sh_type;
14363 int idx = 0;
14364 afi_t afi = AFI_MAX;
2986cac2 14365 bool uj = use_json(argc, argv);
14366
36235319 14367 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 14368 afi = AFI_MAX;
14369
14370 idx++;
14371
14372 if (argv_find(argv, argc, "A.B.C.D", &idx)
14373 || argv_find(argv, argc, "X:X::X:X", &idx)
14374 || argv_find(argv, argc, "WORD", &idx)) {
14375 sh_type = show_peer;
14376 sh_arg = argv[idx]->arg;
14377 } else
14378 sh_type = show_all;
14379
14380 if (!argv_find(argv, argc, "graceful-restart", &idx))
14381 return CMD_SUCCESS;
14382
14383
36235319
QY
14384 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14385 afi, uj);
2986cac2 14386}
14387
716b2d8a 14388/* "show [ip] bgp neighbors" commands. */
718e3744 14389DEFUN (show_ip_bgp_neighbors,
14390 show_ip_bgp_neighbors_cmd,
24345e82 14391 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 14392 SHOW_STR
14393 IP_STR
14394 BGP_STR
f2a8972b 14395 BGP_INSTANCE_HELP_STR
8c3deaae
QY
14396 "Address Family\n"
14397 "Address Family\n"
718e3744 14398 "Detailed information on TCP and BGP neighbor connections\n"
14399 "Neighbor to display information about\n"
a80beece 14400 "Neighbor to display information about\n"
91d37724 14401 "Neighbor on BGP configured interface\n"
9973d184 14402 JSON_STR)
718e3744 14403{
d62a17ae 14404 char *vrf = NULL;
14405 char *sh_arg = NULL;
14406 enum show_type sh_type;
d1927ebe 14407 afi_t afi = AFI_MAX;
718e3744 14408
9f049418 14409 bool uj = use_json(argc, argv);
718e3744 14410
d62a17ae 14411 int idx = 0;
718e3744 14412
9a8bdf1c
PG
14413 /* [<vrf> VIEWVRFNAME] */
14414 if (argv_find(argv, argc, "vrf", &idx)) {
14415 vrf = argv[idx + 1]->arg;
14416 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14417 vrf = NULL;
14418 } else if (argv_find(argv, argc, "view", &idx))
14419 /* [<view> VIEWVRFNAME] */
d62a17ae 14420 vrf = argv[idx + 1]->arg;
718e3744 14421
d62a17ae 14422 idx++;
d1927ebe
AS
14423
14424 if (argv_find(argv, argc, "ipv4", &idx)) {
14425 sh_type = show_ipv4_all;
14426 afi = AFI_IP;
14427 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14428 sh_type = show_ipv6_all;
14429 afi = AFI_IP6;
14430 } else {
14431 sh_type = show_all;
14432 }
14433
d62a17ae 14434 if (argv_find(argv, argc, "A.B.C.D", &idx)
14435 || argv_find(argv, argc, "X:X::X:X", &idx)
14436 || argv_find(argv, argc, "WORD", &idx)) {
14437 sh_type = show_peer;
14438 sh_arg = argv[idx]->arg;
d1927ebe
AS
14439 }
14440
14441 if (sh_type == show_peer && afi == AFI_IP) {
14442 sh_type = show_ipv4_peer;
14443 } else if (sh_type == show_peer && afi == AFI_IP6) {
14444 sh_type = show_ipv6_peer;
14445 }
856ca177 14446
d62a17ae 14447 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 14448}
14449
716b2d8a 14450/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 14451 paths' and `show ip mbgp paths'. Those functions results are the
14452 same.*/
f412b39a 14453DEFUN (show_ip_bgp_paths,
718e3744 14454 show_ip_bgp_paths_cmd,
46f296b4 14455 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 14456 SHOW_STR
14457 IP_STR
14458 BGP_STR
46f296b4 14459 BGP_SAFI_HELP_STR
718e3744 14460 "Path information\n")
14461{
d62a17ae 14462 vty_out(vty, "Address Refcnt Path\n");
14463 aspath_print_all_vty(vty);
14464 return CMD_SUCCESS;
718e3744 14465}
14466
718e3744 14467#include "hash.h"
14468
e3b78da8 14469static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14470 struct vty *vty)
718e3744 14471{
d62a17ae 14472 struct community *com;
718e3744 14473
e3b78da8 14474 com = (struct community *)bucket->data;
3f65c5b1 14475 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 14476 community_str(com, false));
718e3744 14477}
14478
14479/* Show BGP's community internal data. */
f412b39a 14480DEFUN (show_ip_bgp_community_info,
718e3744 14481 show_ip_bgp_community_info_cmd,
bec37ba5 14482 "show [ip] bgp community-info",
718e3744 14483 SHOW_STR
14484 IP_STR
14485 BGP_STR
14486 "List all bgp community information\n")
14487{
d62a17ae 14488 vty_out(vty, "Address Refcnt Community\n");
718e3744 14489
d62a17ae 14490 hash_iterate(community_hash(),
e3b78da8 14491 (void (*)(struct hash_bucket *,
d62a17ae 14492 void *))community_show_all_iterator,
14493 vty);
718e3744 14494
d62a17ae 14495 return CMD_SUCCESS;
718e3744 14496}
14497
e3b78da8 14498static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14499 struct vty *vty)
57d187bc 14500{
d62a17ae 14501 struct lcommunity *lcom;
57d187bc 14502
e3b78da8 14503 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 14504 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 14505 lcommunity_str(lcom, false));
57d187bc
JS
14506}
14507
14508/* Show BGP's community internal data. */
14509DEFUN (show_ip_bgp_lcommunity_info,
14510 show_ip_bgp_lcommunity_info_cmd,
14511 "show ip bgp large-community-info",
14512 SHOW_STR
14513 IP_STR
14514 BGP_STR
14515 "List all bgp large-community information\n")
14516{
d62a17ae 14517 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 14518
d62a17ae 14519 hash_iterate(lcommunity_hash(),
e3b78da8 14520 (void (*)(struct hash_bucket *,
d62a17ae 14521 void *))lcommunity_show_all_iterator,
14522 vty);
57d187bc 14523
d62a17ae 14524 return CMD_SUCCESS;
57d187bc 14525}
2986cac2 14526/* Graceful Restart */
14527
14528static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
14529 struct bgp *bgp,
14530 bool use_json,
14531 json_object *json)
2986cac2 14532{
57d187bc
JS
14533
14534
2986cac2 14535 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14536
7318ae88 14537 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 14538
14539 switch (bgp_global_gr_mode) {
14540
14541 case GLOBAL_HELPER:
13909c4f 14542 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 14543 break;
14544
14545 case GLOBAL_GR:
13909c4f 14546 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 14547 break;
14548
14549 case GLOBAL_DISABLE:
13909c4f 14550 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 14551 break;
14552
14553 case GLOBAL_INVALID:
2986cac2 14554 vty_out(vty,
2ba1fe69 14555 "Global BGP GR Mode Invalid\n");
2986cac2 14556 break;
14557 }
14558 vty_out(vty, "\n");
14559}
14560
36235319
QY
14561static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14562 enum show_type type,
14563 const char *ip_str,
14564 afi_t afi, bool use_json)
2986cac2 14565{
14566 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14567 afi = AFI_IP;
14568
14569 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14570
36235319
QY
14571 bgp_show_neighbor_graceful_restart_vty(
14572 vty, type, ip_str, afi, use_json);
2986cac2 14573 afi++;
14574 }
14575 } else if (afi != AFI_MAX) {
36235319
QY
14576 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14577 use_json);
2986cac2 14578 } else {
14579 return CMD_ERR_INCOMPLETE;
14580 }
14581
14582 return CMD_SUCCESS;
14583}
14584/* Graceful Restart */
14585
f412b39a 14586DEFUN (show_ip_bgp_attr_info,
718e3744 14587 show_ip_bgp_attr_info_cmd,
bec37ba5 14588 "show [ip] bgp attribute-info",
718e3744 14589 SHOW_STR
14590 IP_STR
14591 BGP_STR
14592 "List all bgp attribute information\n")
14593{
d62a17ae 14594 attr_show_all(vty);
14595 return CMD_SUCCESS;
718e3744 14596}
6b0655a2 14597
03915806
CS
14598static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14599 afi_t afi, safi_t safi,
14600 bool use_json, json_object *json)
53089bec 14601{
14602 struct bgp *bgp;
14603 struct listnode *node;
14604 char *vname;
14605 char buf1[INET6_ADDRSTRLEN];
14606 char *ecom_str;
14607 vpn_policy_direction_t dir;
14608
03915806 14609 if (json) {
b46dfd20
DS
14610 json_object *json_import_vrfs = NULL;
14611 json_object *json_export_vrfs = NULL;
14612
b46dfd20
DS
14613 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14614
53089bec 14615 if (!bgp) {
75eeda93 14616 vty_json(vty, json);
b46dfd20 14617
53089bec 14618 return CMD_WARNING;
14619 }
b46dfd20 14620
94d4c685
DS
14621 /* Provide context for the block */
14622 json_object_string_add(json, "vrf", name ? name : "default");
14623 json_object_string_add(json, "afiSafi",
5cb5f4d0 14624 get_afi_safi_str(afi, safi, true));
94d4c685 14625
b46dfd20
DS
14626 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14627 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14628 json_object_string_add(json, "importFromVrfs", "none");
14629 json_object_string_add(json, "importRts", "none");
14630 } else {
6ce24e52
DS
14631 json_import_vrfs = json_object_new_array();
14632
b46dfd20
DS
14633 for (ALL_LIST_ELEMENTS_RO(
14634 bgp->vpn_policy[afi].import_vrf,
14635 node, vname))
14636 json_object_array_add(json_import_vrfs,
14637 json_object_new_string(vname));
14638
b20875ea
CS
14639 json_object_object_add(json, "importFromVrfs",
14640 json_import_vrfs);
b46dfd20 14641 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14642 if (bgp->vpn_policy[afi].rtlist[dir]) {
14643 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14644 bgp->vpn_policy[afi].rtlist[dir],
14645 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14646 json_object_string_add(json, "importRts",
14647 ecom_str);
14648 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14649 } else
14650 json_object_string_add(json, "importRts",
14651 "none");
b46dfd20
DS
14652 }
14653
14654 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14655 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14656 json_object_string_add(json, "exportToVrfs", "none");
14657 json_object_string_add(json, "routeDistinguisher",
14658 "none");
14659 json_object_string_add(json, "exportRts", "none");
14660 } else {
6ce24e52
DS
14661 json_export_vrfs = json_object_new_array();
14662
b46dfd20
DS
14663 for (ALL_LIST_ELEMENTS_RO(
14664 bgp->vpn_policy[afi].export_vrf,
14665 node, vname))
14666 json_object_array_add(json_export_vrfs,
14667 json_object_new_string(vname));
14668 json_object_object_add(json, "exportToVrfs",
14669 json_export_vrfs);
14670 json_object_string_add(json, "routeDistinguisher",
14671 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14672 buf1, RD_ADDRSTRLEN));
14673
14674 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14675 if (bgp->vpn_policy[afi].rtlist[dir]) {
14676 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14677 bgp->vpn_policy[afi].rtlist[dir],
14678 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14679 json_object_string_add(json, "exportRts",
14680 ecom_str);
14681 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14682 } else
14683 json_object_string_add(json, "exportRts",
14684 "none");
b46dfd20
DS
14685 }
14686
03915806 14687 if (use_json) {
75eeda93 14688 vty_json(vty, json);
03915806 14689 }
53089bec 14690 } else {
b46dfd20
DS
14691 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14692
53089bec 14693 if (!bgp) {
b46dfd20 14694 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 14695 return CMD_WARNING;
14696 }
53089bec 14697
b46dfd20
DS
14698 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14699 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14700 vty_out(vty,
14701 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 14702 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14703 else {
14704 vty_out(vty,
14705 "This VRF is importing %s routes from 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].import_vrf,
14710 node, vname))
14711 vty_out(vty, " %s\n", vname);
14712
14713 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14714 ecom_str = NULL;
14715 if (bgp->vpn_policy[afi].rtlist[dir]) {
14716 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14717 bgp->vpn_policy[afi].rtlist[dir],
14718 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 14719 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 14720
b20875ea
CS
14721 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14722 } else
14723 vty_out(vty, "Import RT(s):\n");
53089bec 14724 }
53089bec 14725
b46dfd20
DS
14726 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14727 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14728 vty_out(vty,
14729 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 14730 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14731 else {
14732 vty_out(vty,
04c9077f 14733 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 14734 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14735
14736 for (ALL_LIST_ELEMENTS_RO(
14737 bgp->vpn_policy[afi].export_vrf,
14738 node, vname))
14739 vty_out(vty, " %s\n", vname);
14740
14741 vty_out(vty, "RD: %s\n",
14742 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14743 buf1, RD_ADDRSTRLEN));
14744
14745 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14746 if (bgp->vpn_policy[afi].rtlist[dir]) {
14747 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14748 bgp->vpn_policy[afi].rtlist[dir],
14749 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14750 vty_out(vty, "Export RT: %s\n", ecom_str);
14751 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14752 } else
14753 vty_out(vty, "Import RT(s):\n");
53089bec 14754 }
53089bec 14755 }
14756
14757 return CMD_SUCCESS;
14758}
14759
03915806
CS
14760static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14761 safi_t safi, bool use_json)
14762{
14763 struct listnode *node, *nnode;
14764 struct bgp *bgp;
14765 char *vrf_name = NULL;
14766 json_object *json = NULL;
14767 json_object *json_vrf = NULL;
14768 json_object *json_vrfs = NULL;
14769
14770 if (use_json) {
14771 json = json_object_new_object();
14772 json_vrfs = json_object_new_object();
14773 }
14774
14775 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14776
14777 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14778 vrf_name = bgp->name;
14779
14780 if (use_json) {
14781 json_vrf = json_object_new_object();
14782 } else {
14783 vty_out(vty, "\nInstance %s:\n",
14784 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14785 ? VRF_DEFAULT_NAME : bgp->name);
14786 }
14787 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14788 if (use_json) {
14789 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14790 json_object_object_add(json_vrfs,
14791 VRF_DEFAULT_NAME, json_vrf);
14792 else
14793 json_object_object_add(json_vrfs, vrf_name,
14794 json_vrf);
14795 }
14796 }
14797
14798 if (use_json) {
14799 json_object_object_add(json, "vrfs", json_vrfs);
75eeda93 14800 vty_json(vty, json);
03915806
CS
14801 }
14802
14803 return CMD_SUCCESS;
14804}
14805
53089bec 14806/* "show [ip] bgp route-leak" command. */
14807DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
14808 show_ip_bgp_route_leak_cmd,
14809 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
14810 SHOW_STR
14811 IP_STR
14812 BGP_STR
14813 BGP_INSTANCE_HELP_STR
14814 BGP_AFI_HELP_STR
14815 BGP_SAFI_HELP_STR
14816 "Route leaking information\n"
14817 JSON_STR)
53089bec 14818{
14819 char *vrf = NULL;
14820 afi_t afi = AFI_MAX;
14821 safi_t safi = SAFI_MAX;
14822
9f049418 14823 bool uj = use_json(argc, argv);
53089bec 14824 int idx = 0;
03915806 14825 json_object *json = NULL;
53089bec 14826
14827 /* show [ip] bgp */
14828 if (argv_find(argv, argc, "ip", &idx)) {
14829 afi = AFI_IP;
14830 safi = SAFI_UNICAST;
14831 }
14832 /* [vrf VIEWVRFNAME] */
14833 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
14834 vty_out(vty,
14835 "%% This command is not applicable to BGP views\n");
53089bec 14836 return CMD_WARNING;
14837 }
14838
9a8bdf1c
PG
14839 if (argv_find(argv, argc, "vrf", &idx)) {
14840 vrf = argv[idx + 1]->arg;
14841 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14842 vrf = NULL;
14843 }
53089bec 14844 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
c48349e3 14845 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
53089bec 14846 argv_find_and_parse_safi(argv, argc, &idx, &safi);
53089bec 14847
14848 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
14849 vty_out(vty,
14850 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 14851 return CMD_WARNING;
14852 }
14853
03915806
CS
14854 if (vrf && strmatch(vrf, "all"))
14855 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
14856
14857 if (uj)
14858 json = json_object_new_object();
14859
14860 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 14861}
14862
d62a17ae 14863static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
14864 safi_t safi)
f186de26 14865{
d62a17ae 14866 struct listnode *node, *nnode;
14867 struct bgp *bgp;
f186de26 14868
d62a17ae 14869 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14870 vty_out(vty, "\nInstance %s:\n",
14871 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14872 ? VRF_DEFAULT_NAME
d62a17ae 14873 : bgp->name);
14874 update_group_show(bgp, afi, safi, vty, 0);
14875 }
f186de26 14876}
14877
d62a17ae 14878static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
14879 int safi, uint64_t subgrp_id)
4fb25c53 14880{
d62a17ae 14881 struct bgp *bgp;
4fb25c53 14882
d62a17ae 14883 if (name) {
14884 if (strmatch(name, "all")) {
14885 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
14886 return CMD_SUCCESS;
14887 } else {
14888 bgp = bgp_lookup_by_name(name);
14889 }
14890 } else {
14891 bgp = bgp_get_default();
14892 }
4fb25c53 14893
d62a17ae 14894 if (bgp)
14895 update_group_show(bgp, afi, safi, vty, subgrp_id);
14896 return CMD_SUCCESS;
4fb25c53
DW
14897}
14898
8fe8a7f6
DS
14899DEFUN (show_ip_bgp_updgrps,
14900 show_ip_bgp_updgrps_cmd,
c1a44e43 14901 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 14902 SHOW_STR
14903 IP_STR
14904 BGP_STR
14905 BGP_INSTANCE_HELP_STR
c9e571b4 14906 BGP_AFI_HELP_STR
9bedbb1e 14907 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
14908 "Detailed info about dynamic update groups\n"
14909 "Specific subgroup to display detailed info for\n")
8386ac43 14910{
d62a17ae 14911 char *vrf = NULL;
14912 afi_t afi = AFI_IP6;
14913 safi_t safi = SAFI_UNICAST;
14914 uint64_t subgrp_id = 0;
14915
14916 int idx = 0;
14917
14918 /* show [ip] bgp */
14919 if (argv_find(argv, argc, "ip", &idx))
14920 afi = AFI_IP;
9a8bdf1c
PG
14921 /* [<vrf> VIEWVRFNAME] */
14922 if (argv_find(argv, argc, "vrf", &idx)) {
14923 vrf = argv[idx + 1]->arg;
14924 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14925 vrf = NULL;
14926 } else if (argv_find(argv, argc, "view", &idx))
14927 /* [<view> VIEWVRFNAME] */
14928 vrf = argv[idx + 1]->arg;
d62a17ae 14929 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14930 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14931 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14932 }
5bf15956 14933
d62a17ae 14934 /* get subgroup id, if provided */
14935 idx = argc - 1;
14936 if (argv[idx]->type == VARIABLE_TKN)
14937 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 14938
d62a17ae 14939 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
14940}
14941
f186de26 14942DEFUN (show_bgp_instance_all_ipv6_updgrps,
14943 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 14944 "show [ip] bgp <view|vrf> all update-groups",
f186de26 14945 SHOW_STR
716b2d8a 14946 IP_STR
f186de26 14947 BGP_STR
14948 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 14949 "Detailed info about dynamic update groups\n")
f186de26 14950{
d62a17ae 14951 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
14952 return CMD_SUCCESS;
f186de26 14953}
14954
43d3f4fc
DS
14955DEFUN (show_bgp_l2vpn_evpn_updgrps,
14956 show_bgp_l2vpn_evpn_updgrps_cmd,
14957 "show [ip] bgp l2vpn evpn update-groups",
14958 SHOW_STR
14959 IP_STR
14960 BGP_STR
14961 "l2vpn address family\n"
14962 "evpn sub-address family\n"
14963 "Detailed info about dynamic update groups\n")
14964{
14965 char *vrf = NULL;
14966 uint64_t subgrp_id = 0;
14967
14968 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
14969 return CMD_SUCCESS;
14970}
14971
5bf15956
DW
14972DEFUN (show_bgp_updgrps_stats,
14973 show_bgp_updgrps_stats_cmd,
716b2d8a 14974 "show [ip] bgp update-groups statistics",
3f9c7369 14975 SHOW_STR
716b2d8a 14976 IP_STR
3f9c7369 14977 BGP_STR
0c7b1b01 14978 "Detailed info about dynamic update groups\n"
3f9c7369
DS
14979 "Statistics\n")
14980{
d62a17ae 14981 struct bgp *bgp;
3f9c7369 14982
d62a17ae 14983 bgp = bgp_get_default();
14984 if (bgp)
14985 update_group_show_stats(bgp, vty);
3f9c7369 14986
d62a17ae 14987 return CMD_SUCCESS;
3f9c7369
DS
14988}
14989
8386ac43 14990DEFUN (show_bgp_instance_updgrps_stats,
14991 show_bgp_instance_updgrps_stats_cmd,
18c57037 14992 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 14993 SHOW_STR
716b2d8a 14994 IP_STR
8386ac43 14995 BGP_STR
14996 BGP_INSTANCE_HELP_STR
0c7b1b01 14997 "Detailed info about dynamic update groups\n"
8386ac43 14998 "Statistics\n")
14999{
d62a17ae 15000 int idx_word = 3;
15001 struct bgp *bgp;
8386ac43 15002
d62a17ae 15003 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15004 if (bgp)
15005 update_group_show_stats(bgp, vty);
8386ac43 15006
d62a17ae 15007 return CMD_SUCCESS;
8386ac43 15008}
15009
d62a17ae 15010static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15011 afi_t afi, safi_t safi,
15012 const char *what, uint64_t subgrp_id)
3f9c7369 15013{
d62a17ae 15014 struct bgp *bgp;
8386ac43 15015
d62a17ae 15016 if (name)
15017 bgp = bgp_lookup_by_name(name);
15018 else
15019 bgp = bgp_get_default();
8386ac43 15020
d62a17ae 15021 if (bgp) {
15022 if (!strcmp(what, "advertise-queue"))
15023 update_group_show_adj_queue(bgp, afi, safi, vty,
15024 subgrp_id);
15025 else if (!strcmp(what, "advertised-routes"))
15026 update_group_show_advertised(bgp, afi, safi, vty,
15027 subgrp_id);
15028 else if (!strcmp(what, "packet-queue"))
15029 update_group_show_packet_queue(bgp, afi, safi, vty,
15030 subgrp_id);
15031 }
3f9c7369
DS
15032}
15033
dc64bdec
QY
15034DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15035 show_ip_bgp_instance_updgrps_adj_s_cmd,
15036 "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",
15037 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15038 BGP_SAFI_HELP_STR
15039 "Detailed info about dynamic update groups\n"
15040 "Specific subgroup to display info for\n"
15041 "Advertisement queue\n"
15042 "Announced routes\n"
15043 "Packet queue\n")
3f9c7369 15044{
dc64bdec
QY
15045 uint64_t subgrp_id = 0;
15046 afi_t afiz;
15047 safi_t safiz;
15048 if (sgid)
15049 subgrp_id = strtoull(sgid, NULL, 10);
15050
15051 if (!ip && !afi)
15052 afiz = AFI_IP6;
15053 if (!ip && afi)
15054 afiz = bgp_vty_afi_from_str(afi);
15055 if (ip && !afi)
15056 afiz = AFI_IP;
15057 if (ip && afi) {
15058 afiz = bgp_vty_afi_from_str(afi);
15059 if (afiz != AFI_IP)
15060 vty_out(vty,
15061 "%% Cannot specify both 'ip' and 'ipv6'\n");
15062 return CMD_WARNING;
15063 }
d62a17ae 15064
dc64bdec 15065 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15066
dc64bdec 15067 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15068 return CMD_SUCCESS;
15069}
15070
6f4eacf3
DA
15071static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15072 json_object *json)
d62a17ae 15073{
15074 struct listnode *node, *nnode;
15075 struct prefix *range;
15076 struct peer *conf;
15077 struct peer *peer;
d62a17ae 15078 afi_t afi;
15079 safi_t safi;
15080 const char *peer_status;
d62a17ae 15081 int lr_count;
15082 int dynamic;
6f4eacf3
DA
15083 bool af_cfgd;
15084 json_object *json_peer_group = NULL;
15085 json_object *json_peer_group_afc = NULL;
15086 json_object *json_peer_group_members = NULL;
15087 json_object *json_peer_group_dynamic = NULL;
15088 json_object *json_peer_group_dynamic_af = NULL;
15089 json_object *json_peer_group_ranges = NULL;
d62a17ae 15090
15091 conf = group->conf;
15092
6f4eacf3
DA
15093 if (json) {
15094 json_peer_group = json_object_new_object();
15095 json_peer_group_afc = json_object_new_array();
15096 }
15097
d62a17ae 15098 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3
DA
15099 if (json)
15100 json_object_int_add(json_peer_group, "remoteAs",
15101 conf->as);
15102 else
15103 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15104 group->name, conf->as);
d62a17ae 15105 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3
DA
15106 if (json)
15107 json_object_int_add(json_peer_group, "remoteAs",
15108 group->bgp->as);
15109 else
15110 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15111 group->name, group->bgp->as);
d62a17ae 15112 } else {
6f4eacf3
DA
15113 if (!json)
15114 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 15115 }
f14e6fdb 15116
6f4eacf3
DA
15117 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15118 if (json)
15119 json_object_string_add(json_peer_group, "type",
15120 "internal");
15121 else
15122 vty_out(vty, " Peer-group type is internal\n");
15123 } else {
15124 if (json)
15125 json_object_string_add(json_peer_group, "type",
15126 "external");
15127 else
15128 vty_out(vty, " Peer-group type is external\n");
15129 }
d62a17ae 15130
15131 /* Display AFs configured. */
6f4eacf3
DA
15132 if (!json)
15133 vty_out(vty, " Configured address-families:");
15134
05c7a1cc
QY
15135 FOREACH_AFI_SAFI (afi, safi) {
15136 if (conf->afc[afi][safi]) {
6f4eacf3
DA
15137 af_cfgd = true;
15138 if (json)
15139 json_object_array_add(
15140 json_peer_group_afc,
15141 json_object_new_string(get_afi_safi_str(
15142 afi, safi, false)));
15143 else
15144 vty_out(vty, " %s;",
15145 get_afi_safi_str(afi, safi, false));
d62a17ae 15146 }
05c7a1cc 15147 }
6f4eacf3
DA
15148
15149 if (json) {
15150 json_object_object_add(json_peer_group,
15151 "addressFamiliesConfigured",
15152 json_peer_group_afc);
15153 } else {
15154 if (!af_cfgd)
15155 vty_out(vty, " none\n");
15156 else
15157 vty_out(vty, "\n");
15158 }
d62a17ae 15159
15160 /* Display listen ranges (for dynamic neighbors), if any */
15161 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 15162 lr_count = listcount(group->listen_range[afi]);
15163 if (lr_count) {
6f4eacf3
DA
15164 if (json) {
15165 if (!json_peer_group_dynamic)
15166 json_peer_group_dynamic =
15167 json_object_new_object();
15168
15169 json_peer_group_dynamic_af =
15170 json_object_new_object();
15171 json_peer_group_ranges =
15172 json_object_new_array();
15173 json_object_int_add(json_peer_group_dynamic_af,
15174 "count", lr_count);
15175 } else {
15176 vty_out(vty, " %d %s listen range(s)\n",
15177 lr_count, afi2str(afi));
15178 }
d62a17ae 15179
15180 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
15181 nnode, range)) {
15182 if (json) {
15183 char buf[BUFSIZ];
15184
15185 snprintfrr(buf, sizeof(buf), "%pFX",
15186 range);
15187
15188 json_object_array_add(
15189 json_peer_group_ranges,
15190 json_object_new_string(buf));
15191 } else {
15192 vty_out(vty, " %pFX\n", range);
15193 }
15194 }
15195
15196 if (json) {
15197 json_object_object_add(
15198 json_peer_group_dynamic_af, "ranges",
15199 json_peer_group_ranges);
15200
15201 json_object_object_add(
15202 json_peer_group_dynamic, afi2str(afi),
15203 json_peer_group_dynamic_af);
15204 }
d62a17ae 15205 }
15206 }
f14e6fdb 15207
6f4eacf3
DA
15208 if (json_peer_group_dynamic)
15209 json_object_object_add(json_peer_group, "dynamicRanges",
15210 json_peer_group_dynamic);
15211
d62a17ae 15212 /* Display group members and their status */
15213 if (listcount(group->peer)) {
6f4eacf3
DA
15214 if (json)
15215 json_peer_group_members = json_object_new_object();
15216 else
15217 vty_out(vty, " Peer-group members:\n");
d62a17ae 15218 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15219 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15220 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15221 peer_status = "Idle (Admin)";
15222 else if (CHECK_FLAG(peer->sflags,
15223 PEER_STATUS_PREFIX_OVERFLOW))
15224 peer_status = "Idle (PfxCt)";
15225 else
15226 peer_status = lookup_msg(bgp_status_msg,
15227 peer->status, NULL);
15228
15229 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
15230
15231 if (json) {
15232 json_object *json_peer_group_member =
15233 json_object_new_object();
15234
15235 json_object_string_add(json_peer_group_member,
15236 "status", peer_status);
15237
15238 if (dynamic)
15239 json_object_boolean_true_add(
15240 json_peer_group_member,
15241 "dynamic");
15242
15243 json_object_object_add(json_peer_group_members,
15244 peer->host,
15245 json_peer_group_member);
15246 } else {
15247 vty_out(vty, " %s %s %s \n", peer->host,
15248 dynamic ? "(dynamic)" : "",
15249 peer_status);
15250 }
d62a17ae 15251 }
6f4eacf3
DA
15252 if (json)
15253 json_object_object_add(json_peer_group, "members",
15254 json_peer_group_members);
d62a17ae 15255 }
f14e6fdb 15256
6f4eacf3
DA
15257 if (json)
15258 json_object_object_add(json, group->name, json_peer_group);
15259
d62a17ae 15260 return CMD_SUCCESS;
15261}
15262
ff9959b0 15263static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 15264 const char *group_name, bool uj)
d62a17ae 15265{
ff9959b0 15266 struct bgp *bgp;
d62a17ae 15267 struct listnode *node, *nnode;
15268 struct peer_group *group;
ff9959b0 15269 bool found = false;
6f4eacf3
DA
15270 json_object *json = NULL;
15271
15272 if (uj)
15273 json = json_object_new_object();
ff9959b0
QY
15274
15275 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15276
15277 if (!bgp) {
c48349e3 15278 if (uj)
75eeda93 15279 vty_json(vty, json);
c48349e3 15280 else
6f4eacf3 15281 vty_out(vty, "%% BGP instance not found\n");
6f4eacf3 15282
ff9959b0
QY
15283 return CMD_WARNING;
15284 }
d62a17ae 15285
15286 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15287 if (group_name) {
15288 if (strmatch(group->name, group_name)) {
6f4eacf3 15289 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
15290 found = true;
15291 break;
d62a17ae 15292 }
ff9959b0 15293 } else {
6f4eacf3 15294 bgp_show_one_peer_group(vty, group, json);
d62a17ae 15295 }
f14e6fdb 15296 }
f14e6fdb 15297
6f4eacf3 15298 if (group_name && !found && !uj)
d62a17ae 15299 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15300
c48349e3 15301 if (uj)
75eeda93 15302 vty_json(vty, json);
6f4eacf3 15303
d62a17ae 15304 return CMD_SUCCESS;
f14e6fdb
DS
15305}
15306
6f4eacf3
DA
15307DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15308 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15309 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15310 "Detailed information on BGP peer groups\n"
15311 "Peer group name\n" JSON_STR)
f14e6fdb 15312{
d62a17ae 15313 char *vrf, *pg;
d62a17ae 15314 int idx = 0;
6f4eacf3 15315 bool uj = use_json(argc, argv);
f14e6fdb 15316
a4d82a8a
PZ
15317 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15318 : NULL;
d62a17ae 15319 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15320
6f4eacf3 15321 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 15322}
3f9c7369 15323
d6e3c605 15324
718e3744 15325/* Redistribute VTY commands. */
15326
585f1adc
IR
15327DEFUN (bgp_redistribute_ipv4,
15328 bgp_redistribute_ipv4_cmd,
15329 "redistribute " FRR_IP_REDIST_STR_BGPD,
15330 "Redistribute information from another routing protocol\n"
15331 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 15332{
585f1adc 15333 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15334 int idx_protocol = 1;
585f1adc 15335 int type;
37a87b8f 15336
585f1adc
IR
15337 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15338 if (type < 0) {
15339 vty_out(vty, "%% Invalid route type\n");
15340 return CMD_WARNING_CONFIG_FAILED;
15341 }
7f323236 15342
585f1adc
IR
15343 bgp_redist_add(bgp, AFI_IP, type, 0);
15344 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 15345}
15346
d62a17ae 15347ALIAS_HIDDEN(
15348 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15349 "redistribute " FRR_IP_REDIST_STR_BGPD,
15350 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 15351
585f1adc
IR
15352DEFUN (bgp_redistribute_ipv4_rmap,
15353 bgp_redistribute_ipv4_rmap_cmd,
15354 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15355 "Redistribute information from another routing protocol\n"
15356 FRR_IP_REDIST_HELP_STR_BGPD
15357 "Route map reference\n"
15358 "Pointer to route-map entries\n")
718e3744 15359{
585f1adc 15360 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15361 int idx_protocol = 1;
15362 int idx_word = 3;
585f1adc
IR
15363 int type;
15364 struct bgp_redist *red;
15365 bool changed;
15366 struct route_map *route_map = route_map_lookup_warn_noexist(
15367 vty, argv[idx_word]->arg);
15368
15369 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15370 if (type < 0) {
15371 vty_out(vty, "%% Invalid route type\n");
15372 return CMD_WARNING_CONFIG_FAILED;
15373 }
37a87b8f 15374
585f1adc
IR
15375 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15376 changed =
15377 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15378 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 15379}
15380
d62a17ae 15381ALIAS_HIDDEN(
15382 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15383 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15384 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15385 "Route map reference\n"
15386 "Pointer to route-map entries\n")
596c17ba 15387
585f1adc
IR
15388DEFUN (bgp_redistribute_ipv4_metric,
15389 bgp_redistribute_ipv4_metric_cmd,
15390 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15391 "Redistribute information from another routing protocol\n"
15392 FRR_IP_REDIST_HELP_STR_BGPD
15393 "Metric for redistributed routes\n"
15394 "Default metric\n")
718e3744 15395{
585f1adc 15396 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15397 int idx_protocol = 1;
15398 int idx_number = 3;
585f1adc
IR
15399 int type;
15400 uint32_t metric;
15401 struct bgp_redist *red;
15402 bool changed;
15403
15404 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15405 if (type < 0) {
15406 vty_out(vty, "%% Invalid route type\n");
15407 return CMD_WARNING_CONFIG_FAILED;
15408 }
15409 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15410
585f1adc
IR
15411 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15412 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15413 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15414}
15415
15416ALIAS_HIDDEN(
15417 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15418 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15419 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15420 "Metric for redistributed routes\n"
15421 "Default metric\n")
596c17ba 15422
585f1adc
IR
15423DEFUN (bgp_redistribute_ipv4_rmap_metric,
15424 bgp_redistribute_ipv4_rmap_metric_cmd,
15425 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15426 "Redistribute information from another routing protocol\n"
15427 FRR_IP_REDIST_HELP_STR_BGPD
15428 "Route map reference\n"
15429 "Pointer to route-map entries\n"
15430 "Metric for redistributed routes\n"
15431 "Default metric\n")
718e3744 15432{
585f1adc 15433 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15434 int idx_protocol = 1;
15435 int idx_word = 3;
15436 int idx_number = 5;
585f1adc
IR
15437 int type;
15438 uint32_t metric;
15439 struct bgp_redist *red;
15440 bool changed;
15441 struct route_map *route_map =
15442 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15443
15444 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15445 if (type < 0) {
15446 vty_out(vty, "%% Invalid route type\n");
15447 return CMD_WARNING_CONFIG_FAILED;
15448 }
15449 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15450
585f1adc
IR
15451 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15452 changed =
15453 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15454 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15455 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15456}
15457
15458ALIAS_HIDDEN(
15459 bgp_redistribute_ipv4_rmap_metric,
15460 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15461 "redistribute " FRR_IP_REDIST_STR_BGPD
15462 " route-map WORD metric (0-4294967295)",
15463 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15464 "Route map reference\n"
15465 "Pointer to route-map entries\n"
15466 "Metric for redistributed routes\n"
15467 "Default metric\n")
596c17ba 15468
585f1adc
IR
15469DEFUN (bgp_redistribute_ipv4_metric_rmap,
15470 bgp_redistribute_ipv4_metric_rmap_cmd,
15471 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15472 "Redistribute information from another routing protocol\n"
15473 FRR_IP_REDIST_HELP_STR_BGPD
15474 "Metric for redistributed routes\n"
15475 "Default metric\n"
15476 "Route map reference\n"
15477 "Pointer to route-map entries\n")
718e3744 15478{
585f1adc 15479 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15480 int idx_protocol = 1;
37a87b8f 15481 int idx_number = 3;
585f1adc
IR
15482 int idx_word = 5;
15483 int type;
15484 uint32_t metric;
15485 struct bgp_redist *red;
15486 bool changed;
15487 struct route_map *route_map =
15488 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15489
15490 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15491 if (type < 0) {
15492 vty_out(vty, "%% Invalid route type\n");
15493 return CMD_WARNING_CONFIG_FAILED;
15494 }
15495 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15496
585f1adc
IR
15497 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15498 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15499 changed |=
15500 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15501 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15502}
15503
15504ALIAS_HIDDEN(
15505 bgp_redistribute_ipv4_metric_rmap,
15506 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15507 "redistribute " FRR_IP_REDIST_STR_BGPD
15508 " metric (0-4294967295) route-map WORD",
15509 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15510 "Metric for redistributed routes\n"
15511 "Default metric\n"
15512 "Route map reference\n"
15513 "Pointer to route-map entries\n")
596c17ba 15514
585f1adc
IR
15515DEFUN (bgp_redistribute_ipv4_ospf,
15516 bgp_redistribute_ipv4_ospf_cmd,
15517 "redistribute <ospf|table> (1-65535)",
15518 "Redistribute information from another routing protocol\n"
15519 "Open Shortest Path First (OSPFv2)\n"
15520 "Non-main Kernel Routing Table\n"
15521 "Instance ID/Table ID\n")
7c8ff89e 15522{
585f1adc
IR
15523 VTY_DECLVAR_CONTEXT(bgp, bgp);
15524 int idx_ospf_table = 1;
d62a17ae 15525 int idx_number = 2;
585f1adc
IR
15526 unsigned short instance;
15527 unsigned short protocol;
7c8ff89e 15528
585f1adc 15529 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 15530
585f1adc
IR
15531 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15532 protocol = ZEBRA_ROUTE_OSPF;
15533 else
15534 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 15535
585f1adc
IR
15536 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15537 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
15538}
15539
d62a17ae 15540ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15541 "redistribute <ospf|table> (1-65535)",
15542 "Redistribute information from another routing protocol\n"
15543 "Open Shortest Path First (OSPFv2)\n"
15544 "Non-main Kernel Routing Table\n"
15545 "Instance ID/Table ID\n")
596c17ba 15546
585f1adc
IR
15547DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15548 bgp_redistribute_ipv4_ospf_rmap_cmd,
15549 "redistribute <ospf|table> (1-65535) route-map WORD",
15550 "Redistribute information from another routing protocol\n"
15551 "Open Shortest Path First (OSPFv2)\n"
15552 "Non-main Kernel Routing Table\n"
15553 "Instance ID/Table ID\n"
15554 "Route map reference\n"
15555 "Pointer to route-map entries\n")
7c8ff89e 15556{
585f1adc
IR
15557 VTY_DECLVAR_CONTEXT(bgp, bgp);
15558 int idx_ospf_table = 1;
d62a17ae 15559 int idx_number = 2;
15560 int idx_word = 4;
585f1adc
IR
15561 struct bgp_redist *red;
15562 unsigned short instance;
15563 int protocol;
15564 bool changed;
15565 struct route_map *route_map =
15566 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15567
15568 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15569 protocol = ZEBRA_ROUTE_OSPF;
15570 else
15571 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15572
585f1adc
IR
15573 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15574 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15575 changed =
15576 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15577 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15578}
15579
15580ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15581 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15582 "redistribute <ospf|table> (1-65535) route-map WORD",
15583 "Redistribute information from another routing protocol\n"
15584 "Open Shortest Path First (OSPFv2)\n"
15585 "Non-main Kernel Routing Table\n"
15586 "Instance ID/Table ID\n"
15587 "Route map reference\n"
15588 "Pointer to route-map entries\n")
596c17ba 15589
585f1adc
IR
15590DEFUN (bgp_redistribute_ipv4_ospf_metric,
15591 bgp_redistribute_ipv4_ospf_metric_cmd,
15592 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15593 "Redistribute information from another routing protocol\n"
15594 "Open Shortest Path First (OSPFv2)\n"
15595 "Non-main Kernel Routing Table\n"
15596 "Instance ID/Table ID\n"
15597 "Metric for redistributed routes\n"
15598 "Default metric\n")
7c8ff89e 15599{
585f1adc
IR
15600 VTY_DECLVAR_CONTEXT(bgp, bgp);
15601 int idx_ospf_table = 1;
d62a17ae 15602 int idx_number = 2;
15603 int idx_number_2 = 4;
585f1adc
IR
15604 uint32_t metric;
15605 struct bgp_redist *red;
15606 unsigned short instance;
15607 int protocol;
15608 bool changed;
15609
15610 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15611 protocol = ZEBRA_ROUTE_OSPF;
15612 else
15613 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15614
585f1adc
IR
15615 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15616 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15617
585f1adc
IR
15618 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15619 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15620 metric);
15621 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15622}
15623
15624ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15625 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15626 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15627 "Redistribute information from another routing protocol\n"
15628 "Open Shortest Path First (OSPFv2)\n"
15629 "Non-main Kernel Routing Table\n"
15630 "Instance ID/Table ID\n"
15631 "Metric for redistributed routes\n"
15632 "Default metric\n")
596c17ba 15633
585f1adc
IR
15634DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
15635 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15636 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15637 "Redistribute information from another routing protocol\n"
15638 "Open Shortest Path First (OSPFv2)\n"
15639 "Non-main Kernel Routing Table\n"
15640 "Instance ID/Table ID\n"
15641 "Route map reference\n"
15642 "Pointer to route-map entries\n"
15643 "Metric for redistributed routes\n"
15644 "Default metric\n")
7c8ff89e 15645{
585f1adc
IR
15646 VTY_DECLVAR_CONTEXT(bgp, bgp);
15647 int idx_ospf_table = 1;
d62a17ae 15648 int idx_number = 2;
15649 int idx_word = 4;
15650 int idx_number_2 = 6;
585f1adc
IR
15651 uint32_t metric;
15652 struct bgp_redist *red;
15653 unsigned short instance;
15654 int protocol;
15655 bool changed;
15656 struct route_map *route_map =
15657 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15658
15659 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15660 protocol = ZEBRA_ROUTE_OSPF;
15661 else
15662 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15663
585f1adc
IR
15664 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15665 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15666
585f1adc
IR
15667 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15668 changed =
15669 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15670 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15671 metric);
15672 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15673}
15674
15675ALIAS_HIDDEN(
15676 bgp_redistribute_ipv4_ospf_rmap_metric,
15677 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15678 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15679 "Redistribute information from another routing protocol\n"
15680 "Open Shortest Path First (OSPFv2)\n"
15681 "Non-main Kernel Routing Table\n"
15682 "Instance ID/Table ID\n"
15683 "Route map reference\n"
15684 "Pointer to route-map entries\n"
15685 "Metric for redistributed routes\n"
15686 "Default metric\n")
596c17ba 15687
585f1adc
IR
15688DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
15689 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15690 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15691 "Redistribute information from another routing protocol\n"
15692 "Open Shortest Path First (OSPFv2)\n"
15693 "Non-main Kernel Routing Table\n"
15694 "Instance ID/Table ID\n"
15695 "Metric for redistributed routes\n"
15696 "Default metric\n"
15697 "Route map reference\n"
15698 "Pointer to route-map entries\n")
7c8ff89e 15699{
585f1adc
IR
15700 VTY_DECLVAR_CONTEXT(bgp, bgp);
15701 int idx_ospf_table = 1;
d62a17ae 15702 int idx_number = 2;
15703 int idx_number_2 = 4;
15704 int idx_word = 6;
585f1adc
IR
15705 uint32_t metric;
15706 struct bgp_redist *red;
15707 unsigned short instance;
15708 int protocol;
15709 bool changed;
15710 struct route_map *route_map =
15711 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15712
15713 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15714 protocol = ZEBRA_ROUTE_OSPF;
15715 else
15716 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15717
585f1adc
IR
15718 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15719 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15720
585f1adc
IR
15721 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15722 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15723 metric);
15724 changed |=
15725 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15726 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15727}
15728
15729ALIAS_HIDDEN(
15730 bgp_redistribute_ipv4_ospf_metric_rmap,
15731 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15732 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15733 "Redistribute information from another routing protocol\n"
15734 "Open Shortest Path First (OSPFv2)\n"
15735 "Non-main Kernel Routing Table\n"
15736 "Instance ID/Table ID\n"
15737 "Metric for redistributed routes\n"
15738 "Default metric\n"
15739 "Route map reference\n"
15740 "Pointer to route-map entries\n")
596c17ba 15741
585f1adc
IR
15742DEFUN (no_bgp_redistribute_ipv4_ospf,
15743 no_bgp_redistribute_ipv4_ospf_cmd,
15744 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
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")
7c8ff89e 15754{
585f1adc
IR
15755 VTY_DECLVAR_CONTEXT(bgp, bgp);
15756 int idx_ospf_table = 2;
d62a17ae 15757 int idx_number = 3;
585f1adc
IR
15758 unsigned short instance;
15759 int protocol;
37a87b8f 15760
585f1adc
IR
15761 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15762 protocol = ZEBRA_ROUTE_OSPF;
15763 else
15764 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15765
585f1adc
IR
15766 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15767 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
d62a17ae 15768}
15769
15770ALIAS_HIDDEN(
15771 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 15772 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15773 NO_STR
15774 "Redistribute information from another routing protocol\n"
15775 "Open Shortest Path First (OSPFv2)\n"
15776 "Non-main Kernel Routing Table\n"
15777 "Instance ID/Table ID\n"
15778 "Metric for redistributed routes\n"
15779 "Default metric\n"
15780 "Route map reference\n"
15781 "Pointer to route-map entries\n")
596c17ba 15782
585f1adc
IR
15783DEFUN (no_bgp_redistribute_ipv4,
15784 no_bgp_redistribute_ipv4_cmd,
15785 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15786 NO_STR
15787 "Redistribute information from another routing protocol\n"
15788 FRR_IP_REDIST_HELP_STR_BGPD
15789 "Metric for redistributed routes\n"
15790 "Default metric\n"
15791 "Route map reference\n"
15792 "Pointer to route-map entries\n")
718e3744 15793{
585f1adc 15794 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15795 int idx_protocol = 2;
585f1adc 15796 int type;
d62a17ae 15797
585f1adc
IR
15798 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15799 if (type < 0) {
15800 vty_out(vty, "%% Invalid route type\n");
15801 return CMD_WARNING_CONFIG_FAILED;
15802 }
15803 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
d62a17ae 15804}
15805
15806ALIAS_HIDDEN(
15807 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15808 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 15809 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15810 NO_STR
15811 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15812 "Metric for redistributed routes\n"
15813 "Default metric\n"
15814 "Route map reference\n"
15815 "Pointer to route-map entries\n")
596c17ba 15816
585f1adc
IR
15817DEFUN (bgp_redistribute_ipv6,
15818 bgp_redistribute_ipv6_cmd,
15819 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15820 "Redistribute information from another routing protocol\n"
15821 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 15822{
585f1adc 15823 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15824 int idx_protocol = 1;
585f1adc 15825 int type;
718e3744 15826
585f1adc
IR
15827 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15828 if (type < 0) {
15829 vty_out(vty, "%% Invalid route type\n");
15830 return CMD_WARNING_CONFIG_FAILED;
15831 }
718e3744 15832
585f1adc
IR
15833 bgp_redist_add(bgp, AFI_IP6, type, 0);
15834 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 15835}
15836
585f1adc
IR
15837DEFUN (bgp_redistribute_ipv6_rmap,
15838 bgp_redistribute_ipv6_rmap_cmd,
15839 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
15840 "Redistribute information from another routing protocol\n"
15841 FRR_IP6_REDIST_HELP_STR_BGPD
15842 "Route map reference\n"
15843 "Pointer to route-map entries\n")
718e3744 15844{
585f1adc 15845 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15846 int idx_protocol = 1;
15847 int idx_word = 3;
585f1adc
IR
15848 int type;
15849 struct bgp_redist *red;
15850 bool changed;
15851 struct route_map *route_map =
15852 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
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 }
37a87b8f 15859
585f1adc
IR
15860 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15861 changed =
15862 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15863 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15864}
15865
585f1adc 15866DEFUN (bgp_redistribute_ipv6_metric,
718e3744 15867 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 15868 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 15869 "Redistribute information from another routing protocol\n"
ab0181ee 15870 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 15871 "Metric for redistributed routes\n"
15872 "Default metric\n")
15873{
585f1adc 15874 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15875 int idx_protocol = 1;
15876 int idx_number = 3;
585f1adc
IR
15877 int type;
15878 uint32_t metric;
15879 struct bgp_redist *red;
15880 bool changed;
15881
15882 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15883 if (type < 0) {
15884 vty_out(vty, "%% Invalid route type\n");
15885 return CMD_WARNING_CONFIG_FAILED;
15886 }
15887 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15888
585f1adc
IR
15889 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15890 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
15891 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15892}
15893
585f1adc
IR
15894DEFUN (bgp_redistribute_ipv6_rmap_metric,
15895 bgp_redistribute_ipv6_rmap_metric_cmd,
15896 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15897 "Redistribute information from another routing protocol\n"
15898 FRR_IP6_REDIST_HELP_STR_BGPD
15899 "Route map reference\n"
15900 "Pointer to route-map entries\n"
15901 "Metric for redistributed routes\n"
15902 "Default metric\n")
718e3744 15903{
585f1adc 15904 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15905 int idx_protocol = 1;
15906 int idx_word = 3;
15907 int idx_number = 5;
585f1adc
IR
15908 int type;
15909 uint32_t metric;
15910 struct bgp_redist *red;
15911 bool changed;
15912 struct route_map *route_map =
15913 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15914
15915 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15916 if (type < 0) {
15917 vty_out(vty, "%% Invalid route type\n");
15918 return CMD_WARNING_CONFIG_FAILED;
15919 }
15920 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15921
585f1adc
IR
15922 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15923 changed =
15924 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15925 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
15926 metric);
15927 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15928}
15929
585f1adc
IR
15930DEFUN (bgp_redistribute_ipv6_metric_rmap,
15931 bgp_redistribute_ipv6_metric_rmap_cmd,
15932 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15933 "Redistribute information from another routing protocol\n"
15934 FRR_IP6_REDIST_HELP_STR_BGPD
15935 "Metric for redistributed routes\n"
15936 "Default metric\n"
15937 "Route map reference\n"
15938 "Pointer to route-map entries\n")
718e3744 15939{
585f1adc 15940 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15941 int idx_protocol = 1;
37a87b8f 15942 int idx_number = 3;
585f1adc
IR
15943 int idx_word = 5;
15944 int type;
15945 uint32_t metric;
15946 struct bgp_redist *red;
15947 bool changed;
15948 struct route_map *route_map =
15949 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15950
15951 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15952 if (type < 0) {
15953 vty_out(vty, "%% Invalid route type\n");
15954 return CMD_WARNING_CONFIG_FAILED;
15955 }
15956 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15957
585f1adc
IR
15958 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15959 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
15960 metric);
15961 changed |=
15962 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15963 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15964}
15965
585f1adc
IR
15966DEFUN (no_bgp_redistribute_ipv6,
15967 no_bgp_redistribute_ipv6_cmd,
15968 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15969 NO_STR
15970 "Redistribute information from another routing protocol\n"
15971 FRR_IP6_REDIST_HELP_STR_BGPD
15972 "Metric for redistributed routes\n"
15973 "Default metric\n"
15974 "Route map reference\n"
15975 "Pointer to route-map entries\n")
718e3744 15976{
585f1adc 15977 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15978 int idx_protocol = 2;
585f1adc 15979 int type;
37a87b8f 15980
585f1adc
IR
15981 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15982 if (type < 0) {
15983 vty_out(vty, "%% Invalid route type\n");
15984 return CMD_WARNING_CONFIG_FAILED;
15985 }
718e3744 15986
585f1adc 15987 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
d62a17ae 15988}
15989
4ab46701
AR
15990/* Neighbor update tcp-mss. */
15991static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
15992 const char *tcp_mss_str)
15993{
15994 struct peer *peer;
15995 uint32_t tcp_mss_val = 0;
15996
15997 peer = peer_and_group_lookup_vty(vty, peer_str);
15998 if (!peer)
15999 return CMD_WARNING_CONFIG_FAILED;
16000
16001 if (tcp_mss_str) {
16002 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16003 peer_tcp_mss_set(peer, tcp_mss_val);
16004 } else {
16005 peer_tcp_mss_unset(peer);
16006 }
16007
16008 return CMD_SUCCESS;
16009}
16010
16011DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16012 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16013 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16014 "TCP max segment size\n"
16015 "TCP MSS value\n")
16016{
16017 int peer_index = 1;
16018 int mss_index = 3;
16019
16020 vty_out(vty,
16021 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16022 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16023 argv[mss_index]->arg);
16024}
16025
16026DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16027 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16028 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16029 "TCP max segment size\n"
16030 "TCP MSS value\n")
16031{
16032 int peer_index = 2;
16033
16034 vty_out(vty,
16035 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16036 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16037}
16038
dd65f45e
DL
16039static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16040 afi_t afi, safi_t safi)
d62a17ae 16041{
16042 int i;
16043
16044 /* Unicast redistribution only. */
16045 if (safi != SAFI_UNICAST)
2b791107 16046 return;
d62a17ae 16047
16048 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16049 /* Redistribute BGP does not make sense. */
16050 if (i != ZEBRA_ROUTE_BGP) {
16051 struct list *red_list;
16052 struct listnode *node;
16053 struct bgp_redist *red;
16054
16055 red_list = bgp->redist[afi][i];
16056 if (!red_list)
16057 continue;
16058
16059 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16060 /* "redistribute" configuration. */
16061 vty_out(vty, " redistribute %s",
16062 zebra_route_string(i));
16063 if (red->instance)
16064 vty_out(vty, " %d", red->instance);
16065 if (red->redist_metric_flag)
16066 vty_out(vty, " metric %u",
16067 red->redist_metric);
16068 if (red->rmap.name)
16069 vty_out(vty, " route-map %s",
16070 red->rmap.name);
16071 vty_out(vty, "\n");
16072 }
16073 }
16074 }
718e3744 16075}
6b0655a2 16076
dd65f45e
DL
16077/* peer-group helpers for config-write */
16078
16079static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16080{
16081 if (!peer_group_active(peer)) {
16082 if (CHECK_FLAG(peer->flags_invert, flag))
16083 return !CHECK_FLAG(peer->flags, flag);
16084 else
16085 return !!CHECK_FLAG(peer->flags, flag);
16086 }
16087
16088 return !!CHECK_FLAG(peer->flags_override, flag);
16089}
16090
16091static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16092 uint32_t flag)
16093{
16094 if (!peer_group_active(peer)) {
16095 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16096 return !peer_af_flag_check(peer, afi, safi, flag);
16097 else
16098 return !!peer_af_flag_check(peer, afi, safi, flag);
16099 }
16100
16101 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16102}
16103
16104static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16105 uint8_t type, int direct)
16106{
16107 struct bgp_filter *filter;
16108
16109 if (peer_group_active(peer))
16110 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16111 type);
16112
16113 filter = &peer->filter[afi][safi];
16114 switch (type) {
16115 case PEER_FT_DISTRIBUTE_LIST:
16116 return !!(filter->dlist[direct].name);
16117 case PEER_FT_FILTER_LIST:
16118 return !!(filter->aslist[direct].name);
16119 case PEER_FT_PREFIX_LIST:
16120 return !!(filter->plist[direct].name);
16121 case PEER_FT_ROUTE_MAP:
16122 return !!(filter->map[direct].name);
16123 case PEER_FT_UNSUPPRESS_MAP:
16124 return !!(filter->usmap.name);
7f7940e6
MK
16125 case PEER_FT_ADVERTISE_MAP:
16126 return !!(filter->advmap.aname
16127 && ((filter->advmap.condition == direct)
16128 && filter->advmap.cname));
dd65f45e
DL
16129 default:
16130 return false;
16131 }
16132}
16133
16134/* Return true if the addpath type is set for peer and different from
16135 * peer-group.
16136 */
3dc339cd
DA
16137static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16138 safi_t safi)
dd65f45e
DL
16139{
16140 enum bgp_addpath_strat type, g_type;
16141
16142 type = peer->addpath_type[afi][safi];
16143
16144 if (type != BGP_ADDPATH_NONE) {
16145 if (peer_group_active(peer)) {
16146 g_type = peer->group->conf->addpath_type[afi][safi];
16147
16148 if (type != g_type)
3dc339cd 16149 return true;
dd65f45e 16150 else
3dc339cd 16151 return false;
dd65f45e
DL
16152 }
16153
3dc339cd 16154 return true;
dd65f45e
DL
16155 }
16156
3dc339cd 16157 return false;
dd65f45e
DL
16158}
16159
b9c7bc5a 16160/* This is part of the address-family block (unicast only) */
dd65f45e 16161static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16162 afi_t afi)
16163{
b9c7bc5a 16164 int indent = 2;
53970de3 16165 uint32_t tovpn_sid_index = 0;
ddb5b488 16166
8a066a70 16167 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16168 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16169 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16170 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16171 bgp->vpn_policy[afi]
bb4f6190 16172 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16173 else
16174 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16175 bgp->vpn_policy[afi]
16176 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16177 }
12a844a5
DS
16178 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16179 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16180 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16181 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16182 return;
16183
e70e9f8e
PZ
16184 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16185 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16186
16187 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16188
16189 } else {
16190 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16191 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16192 bgp->vpn_policy[afi].tovpn_label);
16193 }
ddb5b488 16194 }
53970de3
RS
16195
16196 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16197 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16198 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16199 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16200 } else if (tovpn_sid_index != 0) {
16201 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16202 tovpn_sid_index);
16203 }
16204
ddb5b488
PZ
16205 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16206 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16207 char buf[RD_ADDRSTRLEN];
b9c7bc5a 16208 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
16209 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16210 sizeof(buf)));
16211 }
16212 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16213 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16214
16215 char buf[PREFIX_STRLEN];
16216 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16217 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16218 sizeof(buf))) {
16219
b9c7bc5a
PZ
16220 vty_out(vty, "%*snexthop vpn export %s\n",
16221 indent, "", buf);
ddb5b488
PZ
16222 }
16223 }
16224 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16225 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16226 && ecommunity_cmp(
16227 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16228 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16229
16230 char *b = ecommunity_ecom2str(
16231 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16232 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16233 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16234 XFREE(MTYPE_ECOMMUNITY_STR, b);
16235 } else {
16236 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16237 char *b = ecommunity_ecom2str(
16238 bgp->vpn_policy[afi]
16239 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16240 ECOMMUNITY_FORMAT_ROUTE_MAP,
16241 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16242 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16243 XFREE(MTYPE_ECOMMUNITY_STR, b);
16244 }
16245 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16246 char *b = ecommunity_ecom2str(
16247 bgp->vpn_policy[afi]
16248 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16249 ECOMMUNITY_FORMAT_ROUTE_MAP,
16250 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16251 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16252 XFREE(MTYPE_ECOMMUNITY_STR, b);
16253 }
16254 }
bb4f6190
DS
16255
16256 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16257 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16258 bgp->vpn_policy[afi]
16259 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16260
301ad80a
PG
16261 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16262 char *b = ecommunity_ecom2str(
16263 bgp->vpn_policy[afi]
16264 .import_redirect_rtlist,
16265 ECOMMUNITY_FORMAT_ROUTE_MAP,
16266 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16267
9a659715
PG
16268 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16269 != ECOMMUNITY_SIZE)
c6423c31 16270 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16271 indent, "", b);
16272 else
16273 vty_out(vty, "%*srt redirect import %s\n",
16274 indent, "", b);
301ad80a
PG
16275 XFREE(MTYPE_ECOMMUNITY_STR, b);
16276 }
ddb5b488
PZ
16277}
16278
dd65f45e
DL
16279static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16280 afi_t afi, safi_t safi)
16281{
16282 struct bgp_filter *filter;
16283 char *addr;
16284
16285 addr = peer->host;
16286 filter = &peer->filter[afi][safi];
16287
16288 /* distribute-list. */
16289 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16290 FILTER_IN))
16291 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16292 filter->dlist[FILTER_IN].name);
16293
16294 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16295 FILTER_OUT))
16296 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16297 filter->dlist[FILTER_OUT].name);
16298
16299 /* prefix-list. */
16300 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16301 FILTER_IN))
16302 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16303 filter->plist[FILTER_IN].name);
16304
16305 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16306 FILTER_OUT))
16307 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16308 filter->plist[FILTER_OUT].name);
16309
16310 /* route-map. */
16311 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16312 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16313 filter->map[RMAP_IN].name);
16314
16315 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16316 RMAP_OUT))
16317 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16318 filter->map[RMAP_OUT].name);
16319
16320 /* unsuppress-map */
16321 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16322 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16323 filter->usmap.name);
16324
7f7940e6
MK
16325 /* advertise-map : always applied in OUT direction*/
16326 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16327 CONDITION_NON_EXIST))
16328 vty_out(vty,
16329 " neighbor %s advertise-map %s non-exist-map %s\n",
16330 addr, filter->advmap.aname, filter->advmap.cname);
16331
16332 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16333 CONDITION_EXIST))
16334 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16335 addr, filter->advmap.aname, filter->advmap.cname);
16336
dd65f45e
DL
16337 /* filter-list. */
16338 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16339 FILTER_IN))
16340 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16341 filter->aslist[FILTER_IN].name);
16342
16343 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16344 FILTER_OUT))
16345 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16346 filter->aslist[FILTER_OUT].name);
16347}
16348
16349/* BGP peer configuration display function. */
16350static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16351 struct peer *peer)
16352{
16353 struct peer *g_peer = NULL;
16354 char buf[SU_ADDRSTRLEN];
16355 char *addr;
16356 int if_pg_printed = false;
16357 int if_ras_printed = false;
16358
16359 /* Skip dynamic neighbors. */
16360 if (peer_dynamic_neighbor(peer))
16361 return;
16362
16363 if (peer->conf_if)
16364 addr = peer->conf_if;
16365 else
16366 addr = peer->host;
16367
16368 /************************************
16369 ****** Global to the neighbor ******
16370 ************************************/
16371 if (peer->conf_if) {
16372 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16373 vty_out(vty, " neighbor %s interface v6only", addr);
16374 else
16375 vty_out(vty, " neighbor %s interface", addr);
16376
16377 if (peer_group_active(peer)) {
16378 vty_out(vty, " peer-group %s", peer->group->name);
16379 if_pg_printed = true;
16380 } else if (peer->as_type == AS_SPECIFIED) {
16381 vty_out(vty, " remote-as %u", peer->as);
16382 if_ras_printed = true;
16383 } else if (peer->as_type == AS_INTERNAL) {
16384 vty_out(vty, " remote-as internal");
16385 if_ras_printed = true;
16386 } else if (peer->as_type == AS_EXTERNAL) {
16387 vty_out(vty, " remote-as external");
16388 if_ras_printed = true;
16389 }
16390
16391 vty_out(vty, "\n");
16392 }
16393
16394 /* remote-as and peer-group */
16395 /* peer is a member of a peer-group */
16396 if (peer_group_active(peer)) {
16397 g_peer = peer->group->conf;
16398
16399 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16400 if (peer->as_type == AS_SPECIFIED) {
16401 vty_out(vty, " neighbor %s remote-as %u\n",
16402 addr, peer->as);
16403 } else if (peer->as_type == AS_INTERNAL) {
16404 vty_out(vty,
16405 " neighbor %s remote-as internal\n",
16406 addr);
16407 } else if (peer->as_type == AS_EXTERNAL) {
16408 vty_out(vty,
16409 " neighbor %s remote-as external\n",
16410 addr);
16411 }
16412 }
16413
16414 /* For swpX peers we displayed the peer-group
16415 * via 'neighbor swpX interface peer-group PGNAME' */
16416 if (!if_pg_printed)
16417 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16418 peer->group->name);
16419 }
16420
16421 /* peer is NOT a member of a peer-group */
16422 else {
16423 /* peer is a peer-group, declare the peer-group */
16424 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16425 vty_out(vty, " neighbor %s peer-group\n", addr);
16426 }
16427
16428 if (!if_ras_printed) {
16429 if (peer->as_type == AS_SPECIFIED) {
16430 vty_out(vty, " neighbor %s remote-as %u\n",
16431 addr, peer->as);
16432 } else if (peer->as_type == AS_INTERNAL) {
16433 vty_out(vty,
16434 " neighbor %s remote-as internal\n",
16435 addr);
16436 } else if (peer->as_type == AS_EXTERNAL) {
16437 vty_out(vty,
16438 " neighbor %s remote-as external\n",
16439 addr);
16440 }
16441 }
16442 }
16443
16444 /* local-as */
16445 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16446 vty_out(vty, " neighbor %s local-as %u", addr,
16447 peer->change_local_as);
16448 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16449 vty_out(vty, " no-prepend");
16450 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16451 vty_out(vty, " replace-as");
16452 vty_out(vty, "\n");
16453 }
16454
16455 /* description */
16456 if (peer->desc) {
16457 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16458 }
16459
16460 /* shutdown */
16461 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16462 if (peer->tx_shutdown_message)
16463 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16464 peer->tx_shutdown_message);
16465 else
16466 vty_out(vty, " neighbor %s shutdown\n", addr);
16467 }
16468
8336c896
DA
16469 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16470 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16471 peer->rtt_expected, peer->rtt_keepalive_conf);
16472
dd65f45e 16473 /* bfd */
21bfce98
RZ
16474 if (peer->bfd_config)
16475 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
16476
16477 /* password */
16478 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16479 vty_out(vty, " neighbor %s password %s\n", addr,
16480 peer->password);
16481
16482 /* neighbor solo */
16483 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16484 if (!peer_group_active(peer)) {
16485 vty_out(vty, " neighbor %s solo\n", addr);
16486 }
16487 }
16488
16489 /* BGP port */
16490 if (peer->port != BGP_PORT_DEFAULT) {
16491 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16492 }
16493
16494 /* Local interface name */
16495 if (peer->ifname) {
16496 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16497 }
16498
4ab46701
AR
16499 /* TCP max segment size */
16500 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16501 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16502
dd65f45e
DL
16503 /* passive */
16504 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16505 vty_out(vty, " neighbor %s passive\n", addr);
16506
16507 /* ebgp-multihop */
16508 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
16509 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16510 && peer->ttl == MAXTTL)) {
dd65f45e
DL
16511 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16512 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16513 peer->ttl);
16514 }
16515 }
16516
16517 /* ttl-security hops */
e2521429 16518 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
16519 if (!peer_group_active(peer)
16520 || g_peer->gtsm_hops != peer->gtsm_hops) {
16521 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16522 addr, peer->gtsm_hops);
16523 }
16524 }
16525
16526 /* disable-connected-check */
16527 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16528 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16529
27aa23a4
DA
16530 /* link-bw-encoding-ieee */
16531 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16532 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16533 addr);
16534
d08c0c80
DA
16535 /* extended-optional-parameters */
16536 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16537 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16538 addr);
16539
dd65f45e
DL
16540 /* enforce-first-as */
16541 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16542 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16543
16544 /* update-source */
16545 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16546 if (peer->update_source)
16547 vty_out(vty, " neighbor %s update-source %s\n", addr,
16548 sockunion2str(peer->update_source, buf,
16549 SU_ADDRSTRLEN));
16550 else if (peer->update_if)
16551 vty_out(vty, " neighbor %s update-source %s\n", addr,
16552 peer->update_if);
16553 }
16554
16555 /* advertisement-interval */
16556 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16557 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16558 peer->routeadv);
16559
16560 /* timers */
16561 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16562 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16563 peer->keepalive, peer->holdtime);
16564
16565 /* timers connect */
16566 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16567 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16568 peer->connect);
5d5393b9
DL
16569 /* need special-case handling for changed default values due to
16570 * config profile / version (because there is no "timers bgp connect"
16571 * command, we need to save this per-peer :/)
16572 */
16573 else if (!peer_group_active(peer) && !peer->connect &&
16574 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16575 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16576 peer->bgp->default_connect_retry);
dd65f45e 16577
d43114f3
DS
16578 /* timers delayopen */
16579 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16580 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16581 peer->delayopen);
16582 /* Save config even though flag is not set if default values have been
16583 * changed
16584 */
16585 else if (!peer_group_active(peer) && !peer->delayopen
16586 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16587 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16588 peer->bgp->default_delayopen);
16589
dd65f45e
DL
16590 /* capability dynamic */
16591 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16592 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16593
16594 /* capability extended-nexthop */
16595 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
843770f6
DA
16596 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE))
16597 vty_out(vty,
16598 " no neighbor %s capability extended-nexthop\n",
16599 addr);
16600 else if (!peer->conf_if)
16601 vty_out(vty,
16602 " neighbor %s capability extended-nexthop\n",
16603 addr);
dd65f45e
DL
16604 }
16605
16606 /* dont-capability-negotiation */
16607 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16608 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16609
16610 /* override-capability */
16611 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16612 vty_out(vty, " neighbor %s override-capability\n", addr);
16613
16614 /* strict-capability-match */
16615 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16616 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16617
16618 /* Sender side AS path loop detection. */
16619 if (peer->as_path_loop_detection)
16620 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16621 addr);
cfd47646 16622
16623 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16624 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 16625
16626 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16627 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 16628 vty_out(vty,
16629 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
16630 } else if (CHECK_FLAG(
16631 peer->peer_gr_new_status_flag,
16632 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 16633 vty_out(vty,
16634 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
16635 } else if (
16636 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16637 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16638 && !(CHECK_FLAG(
16639 peer->peer_gr_new_status_flag,
16640 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16641 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16642 addr);
cfd47646 16643 }
16644 }
dd65f45e
DL
16645}
16646
16647/* BGP peer configuration display function. */
16648static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16649 struct peer *peer, afi_t afi, safi_t safi)
16650{
16651 struct peer *g_peer = NULL;
16652 char *addr;
16653 bool flag_scomm, flag_secomm, flag_slcomm;
16654
16655 /* Skip dynamic neighbors. */
16656 if (peer_dynamic_neighbor(peer))
16657 return;
16658
16659 if (peer->conf_if)
16660 addr = peer->conf_if;
16661 else
16662 addr = peer->host;
16663
16664 /************************************
16665 ****** Per AF to the neighbor ******
16666 ************************************/
16667 if (peer_group_active(peer)) {
16668 g_peer = peer->group->conf;
16669
16670 /* If the peer-group is active but peer is not, print a 'no
16671 * activate' */
16672 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16673 vty_out(vty, " no neighbor %s activate\n", addr);
16674 }
16675
16676 /* If the peer-group is not active but peer is, print an
16677 'activate' */
16678 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16679 vty_out(vty, " neighbor %s activate\n", addr);
16680 }
16681 } else {
16682 if (peer->afc[afi][safi]) {
38d11af5
TA
16683 if (safi == SAFI_ENCAP)
16684 vty_out(vty, " neighbor %s activate\n", addr);
16685 else if (!bgp->default_af[afi][safi])
dd65f45e
DL
16686 vty_out(vty, " neighbor %s activate\n", addr);
16687 } else {
38d11af5
TA
16688 if (bgp->default_af[afi][safi])
16689 vty_out(vty, " no neighbor %s activate\n",
16690 addr);
dd65f45e
DL
16691 }
16692 }
16693
16694 /* addpath TX knobs */
16695 if (peergroup_af_addpath_check(peer, afi, safi)) {
16696 switch (peer->addpath_type[afi][safi]) {
16697 case BGP_ADDPATH_ALL:
16698 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16699 addr);
16700 break;
16701 case BGP_ADDPATH_BEST_PER_AS:
16702 vty_out(vty,
16703 " neighbor %s addpath-tx-bestpath-per-AS\n",
16704 addr);
16705 break;
16706 case BGP_ADDPATH_MAX:
16707 case BGP_ADDPATH_NONE:
16708 break;
16709 }
16710 }
16711
7c0e4312
DA
16712 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
16713 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
16714
dd65f45e
DL
16715 /* ORF capability. */
16716 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16717 || peergroup_af_flag_check(peer, afi, safi,
16718 PEER_FLAG_ORF_PREFIX_RM)) {
16719 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16720
16721 if (peergroup_af_flag_check(peer, afi, safi,
16722 PEER_FLAG_ORF_PREFIX_SM)
16723 && peergroup_af_flag_check(peer, afi, safi,
16724 PEER_FLAG_ORF_PREFIX_RM))
16725 vty_out(vty, " both");
16726 else if (peergroup_af_flag_check(peer, afi, safi,
16727 PEER_FLAG_ORF_PREFIX_SM))
16728 vty_out(vty, " send");
16729 else
16730 vty_out(vty, " receive");
16731 vty_out(vty, "\n");
16732 }
16733
dd65f45e
DL
16734 /* Route reflector client. */
16735 if (peergroup_af_flag_check(peer, afi, safi,
16736 PEER_FLAG_REFLECTOR_CLIENT)) {
16737 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16738 }
16739
16740 /* next-hop-self force */
16741 if (peergroup_af_flag_check(peer, afi, safi,
16742 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16743 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16744 }
16745
16746 /* next-hop-self */
16747 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16748 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16749 }
16750
16751 /* remove-private-AS */
16752 if (peergroup_af_flag_check(peer, afi, safi,
16753 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16754 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16755 addr);
16756 }
16757
16758 else if (peergroup_af_flag_check(peer, afi, safi,
16759 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16760 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16761 addr);
16762 }
16763
16764 else if (peergroup_af_flag_check(peer, afi, safi,
16765 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16766 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16767 }
16768
16769 else if (peergroup_af_flag_check(peer, afi, safi,
16770 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16771 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16772 }
16773
16774 /* as-override */
16775 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16776 vty_out(vty, " neighbor %s as-override\n", addr);
16777 }
16778
16779 /* send-community print. */
16780 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16781 PEER_FLAG_SEND_COMMUNITY);
16782 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16783 PEER_FLAG_SEND_EXT_COMMUNITY);
16784 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16785 PEER_FLAG_SEND_LARGE_COMMUNITY);
16786
16787 if (flag_scomm && flag_secomm && flag_slcomm) {
16788 vty_out(vty, " no neighbor %s send-community all\n", addr);
16789 } else {
16790 if (flag_scomm)
16791 vty_out(vty, " no neighbor %s send-community\n", addr);
16792 if (flag_secomm)
16793 vty_out(vty,
16794 " no neighbor %s send-community extended\n",
16795 addr);
16796
16797 if (flag_slcomm)
16798 vty_out(vty, " no neighbor %s send-community large\n",
16799 addr);
16800 }
16801
16802 /* Default information */
16803 if (peergroup_af_flag_check(peer, afi, safi,
16804 PEER_FLAG_DEFAULT_ORIGINATE)) {
16805 vty_out(vty, " neighbor %s default-originate", addr);
16806
16807 if (peer->default_rmap[afi][safi].name)
16808 vty_out(vty, " route-map %s",
16809 peer->default_rmap[afi][safi].name);
16810
16811 vty_out(vty, "\n");
16812 }
16813
16814 /* Soft reconfiguration inbound. */
16815 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16816 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16817 addr);
16818 }
16819
16820 /* maximum-prefix. */
16821 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 16822 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
16823 peer->pmax[afi][safi]);
16824
16825 if (peer->pmax_threshold[afi][safi]
16826 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16827 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16828 if (peer_af_flag_check(peer, afi, safi,
16829 PEER_FLAG_MAX_PREFIX_WARNING))
16830 vty_out(vty, " warning-only");
16831 if (peer->pmax_restart[afi][safi])
16832 vty_out(vty, " restart %u",
16833 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
16834 if (peer_af_flag_check(peer, afi, safi,
16835 PEER_FLAG_MAX_PREFIX_FORCE))
16836 vty_out(vty, " force");
dd65f45e
DL
16837
16838 vty_out(vty, "\n");
16839 }
16840
fde246e8
DA
16841 /* maximum-prefix-out */
16842 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 16843 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
16844 addr, peer->pmax_out[afi][safi]);
16845
dd65f45e
DL
16846 /* Route server client. */
16847 if (peergroup_af_flag_check(peer, afi, safi,
16848 PEER_FLAG_RSERVER_CLIENT)) {
16849 vty_out(vty, " neighbor %s route-server-client\n", addr);
16850 }
16851
16852 /* Nexthop-local unchanged. */
16853 if (peergroup_af_flag_check(peer, afi, safi,
16854 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16855 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16856 }
16857
16858 /* allowas-in <1-10> */
16859 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16860 if (peer_af_flag_check(peer, afi, safi,
16861 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16862 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16863 } else if (peer->allowas_in[afi][safi] == 3) {
16864 vty_out(vty, " neighbor %s allowas-in\n", addr);
16865 } else {
16866 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16867 peer->allowas_in[afi][safi]);
16868 }
16869 }
16870
16871 /* weight */
16872 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16873 vty_out(vty, " neighbor %s weight %lu\n", addr,
16874 peer->weight[afi][safi]);
16875
16876 /* Filter. */
16877 bgp_config_write_filter(vty, peer, afi, safi);
16878
16879 /* atribute-unchanged. */
16880 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16881 || (safi != SAFI_EVPN
16882 && peer_af_flag_check(peer, afi, safi,
16883 PEER_FLAG_NEXTHOP_UNCHANGED))
16884 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16885
16886 if (!peer_group_active(peer)
16887 || peergroup_af_flag_check(peer, afi, safi,
16888 PEER_FLAG_AS_PATH_UNCHANGED)
16889 || peergroup_af_flag_check(peer, afi, safi,
16890 PEER_FLAG_NEXTHOP_UNCHANGED)
16891 || peergroup_af_flag_check(peer, afi, safi,
16892 PEER_FLAG_MED_UNCHANGED)) {
16893
16894 vty_out(vty,
16895 " neighbor %s attribute-unchanged%s%s%s\n",
16896 addr,
16897 peer_af_flag_check(peer, afi, safi,
16898 PEER_FLAG_AS_PATH_UNCHANGED)
16899 ? " as-path"
16900 : "",
16901 peer_af_flag_check(peer, afi, safi,
16902 PEER_FLAG_NEXTHOP_UNCHANGED)
16903 ? " next-hop"
16904 : "",
16905 peer_af_flag_check(peer, afi, safi,
16906 PEER_FLAG_MED_UNCHANGED)
16907 ? " med"
16908 : "");
16909 }
16910 }
16911}
16912
16913/* Address family based peer configuration display. */
16914static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
16915 safi_t safi)
16916{
16917 struct peer *peer;
16918 struct peer_group *group;
16919 struct listnode *node, *nnode;
16920
16921
16922 vty_frame(vty, " !\n address-family ");
16923 if (afi == AFI_IP) {
16924 if (safi == SAFI_UNICAST)
16925 vty_frame(vty, "ipv4 unicast");
16926 else if (safi == SAFI_LABELED_UNICAST)
16927 vty_frame(vty, "ipv4 labeled-unicast");
16928 else if (safi == SAFI_MULTICAST)
16929 vty_frame(vty, "ipv4 multicast");
16930 else if (safi == SAFI_MPLS_VPN)
16931 vty_frame(vty, "ipv4 vpn");
16932 else if (safi == SAFI_ENCAP)
16933 vty_frame(vty, "ipv4 encap");
16934 else if (safi == SAFI_FLOWSPEC)
16935 vty_frame(vty, "ipv4 flowspec");
16936 } else if (afi == AFI_IP6) {
16937 if (safi == SAFI_UNICAST)
16938 vty_frame(vty, "ipv6 unicast");
16939 else if (safi == SAFI_LABELED_UNICAST)
16940 vty_frame(vty, "ipv6 labeled-unicast");
16941 else if (safi == SAFI_MULTICAST)
16942 vty_frame(vty, "ipv6 multicast");
16943 else if (safi == SAFI_MPLS_VPN)
16944 vty_frame(vty, "ipv6 vpn");
16945 else if (safi == SAFI_ENCAP)
16946 vty_frame(vty, "ipv6 encap");
16947 else if (safi == SAFI_FLOWSPEC)
16948 vty_frame(vty, "ipv6 flowspec");
16949 } else if (afi == AFI_L2VPN) {
16950 if (safi == SAFI_EVPN)
16951 vty_frame(vty, "l2vpn evpn");
16952 }
16953 vty_frame(vty, "\n");
16954
16955 bgp_config_write_distance(vty, bgp, afi, safi);
16956
16957 bgp_config_write_network(vty, bgp, afi, safi);
16958
16959 bgp_config_write_redistribute(vty, bgp, afi, safi);
16960
8a4e7fe6
DA
16961 /* BGP flag dampening. */
16962 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6c75f4b3 16963 bgp_config_write_damp(vty, afi, safi);
8a4e7fe6 16964
dd65f45e
DL
16965 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
16966 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
16967
16968 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
16969 /* Do not display doppelganger peers */
16970 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16971 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
16972 }
16973
16974 bgp_config_write_maxpaths(vty, bgp, afi, safi);
16975 bgp_config_write_table_map(vty, bgp, afi, safi);
16976
16977 if (safi == SAFI_EVPN)
16978 bgp_config_write_evpn_info(vty, bgp, afi, safi);
16979
16980 if (safi == SAFI_FLOWSPEC)
16981 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
16982
16983 if (safi == SAFI_UNICAST) {
16984 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
16985 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16986 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
16987
16988 vty_out(vty, " export vpn\n");
16989 }
16990 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16991 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
16992
16993 vty_out(vty, " import vpn\n");
16994 }
16995 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16996 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
16997 char *name;
16998
16999 for (ALL_LIST_ELEMENTS_RO(
17000 bgp->vpn_policy[afi].import_vrf, node,
17001 name))
17002 vty_out(vty, " import vrf %s\n", name);
17003 }
17004 }
17005
17006 vty_endframe(vty, " exit-address-family\n");
17007}
17008
17009int bgp_config_write(struct vty *vty)
17010{
17011 struct bgp *bgp;
17012 struct peer_group *group;
17013 struct peer *peer;
17014 struct listnode *node, *nnode;
17015 struct listnode *mnode, *mnnode;
b16bcbba
TA
17016 afi_t afi;
17017 safi_t safi;
dd65f45e
DL
17018
17019 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17020 vty_out(vty, "bgp route-map delay-timer %u\n",
17021 bm->rmap_update_timer);
17022
d70583f7
D
17023 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17024 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17025 if (bm->v_update_delay != bm->v_establish_wait)
17026 vty_out(vty, " %d", bm->v_establish_wait);
17027 vty_out(vty, "\n");
17028 }
17029
9acb67cb
DS
17030 if (bm->wait_for_fib)
17031 vty_out(vty, "bgp suppress-fib-pending\n");
17032
05bd726c 17033 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17034 vty_out(vty, "bgp graceful-shutdown\n");
17035
c163f297
DS
17036 /* No-RIB (Zebra) option flag configuration */
17037 if (bgp_option_check(BGP_OPT_NO_FIB))
17038 vty_out(vty, "bgp no-rib\n");
17039
870791a3
IR
17040 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17041 vty_out(vty, "bgp send-extra-data zebra\n");
e46723a5 17042
dd65f45e
DL
17043 /* BGP configuration. */
17044 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17045
17046 /* skip all auto created vrf as they dont have user config */
17047 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17048 continue;
17049
17050 /* Router bgp ASN */
17051 vty_out(vty, "router bgp %u", bgp->as);
17052
17053 if (bgp->name)
17054 vty_out(vty, " %s %s",
17055 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17056 ? "view" : "vrf", bgp->name);
17057 vty_out(vty, "\n");
17058
17059 /* BGP fast-external-failover. */
17060 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17061 vty_out(vty, " no bgp fast-external-failover\n");
17062
17063 /* BGP router ID. */
3a6290bd 17064 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17065 vty_out(vty, " bgp router-id %pI4\n",
17066 &bgp->router_id_static);
dd65f45e 17067
c208c586
S
17068 /* Suppress fib pending */
17069 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17070 vty_out(vty, " bgp suppress-fib-pending\n");
17071
dd65f45e 17072 /* BGP log-neighbor-changes. */
892fedb6 17073 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17074 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17075 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17076 CHECK_FLAG(bgp->flags,
17077 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17078 ? ""
17079 : "no ");
17080
17081 /* BGP configuration. */
892fedb6 17082 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17083 vty_out(vty, " bgp always-compare-med\n");
17084
17085 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17086 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17087 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17088 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17089 CHECK_FLAG(bgp->flags,
17090 BGP_FLAG_EBGP_REQUIRES_POLICY)
17091 ? ""
17092 : "no ");
dd65f45e
DL
17093
17094 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17095 if (bgp->reject_as_sets)
dd65f45e
DL
17096 vty_out(vty, " bgp reject-as-sets\n");
17097
2adac256
DA
17098 /* Suppress duplicate updates if the route actually not changed
17099 */
17100 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17101 != SAVE_BGP_SUPPRESS_DUPLICATES)
17102 vty_out(vty, " %sbgp suppress-duplicates\n",
17103 CHECK_FLAG(bgp->flags,
17104 BGP_FLAG_SUPPRESS_DUPLICATES)
17105 ? ""
17106 : "no ");
17107
b16bcbba
TA
17108 /* BGP default <afi>-<safi> */
17109 FOREACH_AFI_SAFI (afi, safi) {
17110 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17111 if (!bgp->default_af[afi][safi])
17112 vty_out(vty, " no bgp default %s\n",
17113 get_bgp_default_af_flag(afi,
17114 safi));
17115 } else if (bgp->default_af[afi][safi])
17116 vty_out(vty, " bgp default %s\n",
17117 get_bgp_default_af_flag(afi, safi));
17118 }
e84c59af 17119
dd65f45e
DL
17120 /* BGP default local-preference. */
17121 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17122 vty_out(vty, " bgp default local-preference %u\n",
17123 bgp->default_local_pref);
17124
17125 /* BGP default show-hostname */
892fedb6 17126 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17127 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17128 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17129 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17130 ? ""
17131 : "no ");
17132
aef999a2
DA
17133 /* BGP default show-nexthop-hostname */
17134 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17135 != SAVE_BGP_SHOW_HOSTNAME)
17136 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17137 CHECK_FLAG(bgp->flags,
17138 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17139 ? ""
17140 : "no ");
17141
dd65f45e
DL
17142 /* BGP default subgroup-pkt-queue-max. */
17143 if (bgp->default_subgroup_pkt_queue_max
17144 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17145 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17146 bgp->default_subgroup_pkt_queue_max);
17147
17148 /* BGP client-to-client reflection. */
892fedb6 17149 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17150 vty_out(vty, " no bgp client-to-client reflection\n");
17151
17152 /* BGP cluster ID. */
17153 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17154 vty_out(vty, " bgp cluster-id %pI4\n",
17155 &bgp->cluster_id);
dd65f45e
DL
17156
17157 /* Disable ebgp connected nexthop check */
892fedb6 17158 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17159 vty_out(vty,
17160 " bgp disable-ebgp-connected-route-check\n");
17161
17162 /* Confederation identifier*/
17163 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17164 vty_out(vty, " bgp confederation identifier %u\n",
17165 bgp->confed_id);
17166
17167 /* Confederation peer */
17168 if (bgp->confed_peers_cnt > 0) {
17169 int i;
17170
17171 vty_out(vty, " bgp confederation peers");
17172
17173 for (i = 0; i < bgp->confed_peers_cnt; i++)
17174 vty_out(vty, " %u", bgp->confed_peers[i]);
17175
17176 vty_out(vty, "\n");
17177 }
17178
17179 /* BGP deterministic-med. */
892fedb6 17180 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 17181 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 17182 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
17183 CHECK_FLAG(bgp->flags,
17184 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
17185 ? ""
17186 : "no ");
17187
17188 /* BGP update-delay. */
17189 bgp_config_write_update_delay(vty, bgp);
17190
17191 if (bgp->v_maxmed_onstartup
17192 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17193 vty_out(vty, " bgp max-med on-startup %u",
17194 bgp->v_maxmed_onstartup);
17195 if (bgp->maxmed_onstartup_value
17196 != BGP_MAXMED_VALUE_DEFAULT)
17197 vty_out(vty, " %u",
17198 bgp->maxmed_onstartup_value);
17199 vty_out(vty, "\n");
17200 }
17201 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17202 vty_out(vty, " bgp max-med administrative");
17203 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17204 vty_out(vty, " %u", bgp->maxmed_admin_value);
17205 vty_out(vty, "\n");
17206 }
17207
17208 /* write quanta */
17209 bgp_config_write_wpkt_quanta(vty, bgp);
17210 /* read quanta */
17211 bgp_config_write_rpkt_quanta(vty, bgp);
17212
17213 /* coalesce time */
17214 bgp_config_write_coalesce_time(vty, bgp);
17215
05bd726c 17216 /* BGP per-instance graceful-shutdown */
17217 /* BGP-wide settings and per-instance settings are mutually
17218 * exclusive.
17219 */
17220 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17221 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17222 vty_out(vty, " bgp graceful-shutdown\n");
17223
8606be87
DA
17224 /* Long-lived Graceful Restart */
17225 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17226 vty_out(vty,
17227 " bgp long-lived-graceful-restart stale-time %u\n",
17228 bgp->llgr_stale_time);
17229
dd65f45e
DL
17230 /* BGP graceful-restart. */
17231 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17232 vty_out(vty,
17233 " bgp graceful-restart stalepath-time %u\n",
17234 bgp->stalepath_time);
cfd47646 17235
dd65f45e
DL
17236 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17237 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17238 bgp->restart_time);
cfd47646 17239
17240 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17241 vty_out(vty,
17242 " bgp graceful-restart select-defer-time %u\n",
17243 bgp->select_defer_time);
17244
17245 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
17246 vty_out(vty, " bgp graceful-restart\n");
17247
cfd47646 17248 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17249 vty_out(vty, " bgp graceful-restart-disable\n");
17250
dd65f45e 17251 /* BGP graceful-restart Preserve State F bit. */
892fedb6 17252 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
17253 vty_out(vty,
17254 " bgp graceful-restart preserve-fw-state\n");
17255
dc95985f 17256 /* Stale timer for RIB */
17257 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17258 vty_out(vty,
17259 " bgp graceful-restart rib-stale-time %u\n",
17260 bgp->rib_stale_time);
17261
dd65f45e 17262 /* BGP bestpath method. */
892fedb6 17263 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 17264 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 17265 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
17266 vty_out(vty, " bgp bestpath as-path confed\n");
17267
892fedb6
DA
17268 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17269 if (CHECK_FLAG(bgp->flags,
17270 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
17271 vty_out(vty,
17272 " bgp bestpath as-path multipath-relax as-set\n");
17273 } else {
17274 vty_out(vty,
17275 " bgp bestpath as-path multipath-relax\n");
17276 }
17277 }
17278
892fedb6 17279 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17280 vty_out(vty,
17281 " bgp route-reflector allow-outbound-policy\n");
17282 }
892fedb6 17283 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17284 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17285 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17286 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17287 vty_out(vty, " bgp bestpath med");
892fedb6 17288 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17289 vty_out(vty, " confed");
892fedb6
DA
17290 if (CHECK_FLAG(bgp->flags,
17291 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17292 vty_out(vty, " missing-as-worst");
17293 vty_out(vty, "\n");
17294 }
17295
ee88563a
JM
17296 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17297 vty_out(vty,
17298 " bgp bestpath peer-type multipath-relax\n");
17299
f7e1c681 17300 /* Link bandwidth handling. */
17301 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17302 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17303 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17304 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17305 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17306 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17307
dd65f45e 17308 /* BGP network import check. */
892fedb6 17309 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17310 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17311 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17312 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17313 ? ""
17314 : "no ");
17315
17316 /* BGP timers configuration. */
5d5393b9 17317 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 17318 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17319 vty_out(vty, " timers bgp %u %u\n",
17320 bgp->default_keepalive, bgp->default_holdtime);
17321
b042667a
TI
17322 /* BGP minimum holdtime configuration. */
17323 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17324 && bgp->default_min_holdtime != 0)
17325 vty_out(vty, " bgp minimum-holdtime %u\n",
17326 bgp->default_min_holdtime);
17327
389e4f92
QY
17328 /* Conditional advertisement timer configuration */
17329 if (bgp->condition_check_period
17330 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17331 vty_out(vty,
17332 " bgp conditional-advertisement timer %u\n",
17333 bgp->condition_check_period);
17334
dd65f45e
DL
17335 /* peer-group */
17336 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17337 bgp_config_write_peer_global(vty, bgp, group->conf);
17338 }
17339
17340 /* Normal neighbor configuration. */
17341 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17342 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17343 bgp_config_write_peer_global(vty, bgp, peer);
17344 }
17345
17346 /* listen range and limit for dynamic BGP neighbors */
17347 bgp_config_write_listen(vty, bgp);
17348
17349 /*
17350 * BGP default autoshutdown neighbors
17351 *
17352 * This must be placed after any peer and peer-group
17353 * configuration, to avoid setting all peers to shutdown after
17354 * a daemon restart, which is undesired behavior. (see #2286)
17355 */
17356 if (bgp->autoshutdown)
17357 vty_out(vty, " bgp default shutdown\n");
17358
9cf59432
DS
17359 /* BGP instance administrative shutdown */
17360 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17361 vty_out(vty, " bgp shutdown\n");
17362
f852eb98
PG
17363 if (bgp->fast_convergence)
17364 vty_out(vty, " bgp fast-convergence\n");
17365
a0281b2e
HS
17366 if (bgp->srv6_enabled) {
17367 vty_frame(vty, " !\n segment-routing srv6\n");
96db4340 17368 if (strlen(bgp->srv6_locator_name))
a0281b2e
HS
17369 vty_out(vty, " locator %s\n",
17370 bgp->srv6_locator_name);
ff7c3ee1 17371 vty_endframe(vty, " exit\n");
a0281b2e
HS
17372 }
17373
17374
dd65f45e
DL
17375 /* IPv4 unicast configuration. */
17376 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17377
17378 /* IPv4 multicast configuration. */
17379 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17380
17381 /* IPv4 labeled-unicast configuration. */
17382 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17383
17384 /* IPv4 VPN configuration. */
17385 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17386
17387 /* ENCAPv4 configuration. */
17388 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17389
17390 /* FLOWSPEC v4 configuration. */
17391 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17392
17393 /* IPv6 unicast configuration. */
17394 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17395
17396 /* IPv6 multicast configuration. */
17397 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17398
17399 /* IPv6 labeled-unicast configuration. */
17400 bgp_config_write_family(vty, bgp, AFI_IP6,
17401 SAFI_LABELED_UNICAST);
17402
17403 /* IPv6 VPN configuration. */
17404 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17405
17406 /* ENCAPv6 configuration. */
17407 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17408
17409 /* FLOWSPEC v6 configuration. */
17410 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17411
17412 /* EVPN configuration. */
17413 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17414
17415 hook_call(bgp_inst_config_write, bgp, vty);
17416
49e5a4a0 17417#ifdef ENABLE_BGP_VNC
dd65f45e
DL
17418 bgp_rfapi_cfg_write(vty, bgp);
17419#endif
17420
07679ad9 17421 vty_out(vty, "exit\n");
dd65f45e
DL
17422 vty_out(vty, "!\n");
17423 }
17424 return 0;
17425}
17426
ddb5b488 17427
718e3744 17428/* BGP node structure. */
d62a17ae 17429static struct cmd_node bgp_node = {
f4b8291f 17430 .name = "bgp",
62b346ee 17431 .node = BGP_NODE,
24389580 17432 .parent_node = CONFIG_NODE,
62b346ee 17433 .prompt = "%s(config-router)# ",
612c2c15 17434 .config_write = bgp_config_write,
718e3744 17435};
17436
d62a17ae 17437static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 17438 .name = "bgp ipv4 unicast",
62b346ee 17439 .node = BGP_IPV4_NODE,
24389580 17440 .parent_node = BGP_NODE,
62b346ee 17441 .prompt = "%s(config-router-af)# ",
dd2c81b8 17442 .no_xpath = true,
718e3744 17443};
17444
d62a17ae 17445static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 17446 .name = "bgp ipv4 multicast",
62b346ee 17447 .node = BGP_IPV4M_NODE,
24389580 17448 .parent_node = BGP_NODE,
62b346ee 17449 .prompt = "%s(config-router-af)# ",
dd2c81b8 17450 .no_xpath = true,
718e3744 17451};
17452
d62a17ae 17453static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 17454 .name = "bgp ipv4 labeled unicast",
62b346ee 17455 .node = BGP_IPV4L_NODE,
24389580 17456 .parent_node = BGP_NODE,
62b346ee 17457 .prompt = "%s(config-router-af)# ",
dd2c81b8 17458 .no_xpath = true,
f51bae9c
DS
17459};
17460
d62a17ae 17461static struct cmd_node bgp_ipv6_unicast_node = {
a17cfb3f 17462 .name = "bgp ipv6 unicast",
62b346ee 17463 .node = BGP_IPV6_NODE,
24389580 17464 .parent_node = BGP_NODE,
62b346ee 17465 .prompt = "%s(config-router-af)# ",
dd2c81b8 17466 .no_xpath = true,
718e3744 17467};
17468
d62a17ae 17469static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 17470 .name = "bgp ipv6 multicast",
62b346ee 17471 .node = BGP_IPV6M_NODE,
24389580 17472 .parent_node = BGP_NODE,
62b346ee 17473 .prompt = "%s(config-router-af)# ",
dd2c81b8 17474 .no_xpath = true,
25ffbdc1 17475};
17476
d62a17ae 17477static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 17478 .name = "bgp ipv6 labeled unicast",
62b346ee 17479 .node = BGP_IPV6L_NODE,
24389580 17480 .parent_node = BGP_NODE,
62b346ee 17481 .prompt = "%s(config-router-af)# ",
dd2c81b8 17482 .no_xpath = true,
f51bae9c
DS
17483};
17484
62b346ee 17485static struct cmd_node bgp_vpnv4_node = {
f4b8291f 17486 .name = "bgp vpnv4",
62b346ee 17487 .node = BGP_VPNV4_NODE,
24389580 17488 .parent_node = BGP_NODE,
62b346ee 17489 .prompt = "%s(config-router-af)# ",
dd2c81b8 17490 .no_xpath = true,
62b346ee 17491};
6b0655a2 17492
62b346ee 17493static struct cmd_node bgp_vpnv6_node = {
f4b8291f 17494 .name = "bgp vpnv6",
62b346ee 17495 .node = BGP_VPNV6_NODE,
24389580 17496 .parent_node = BGP_NODE,
62b346ee 17497 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 17498 .no_xpath = true,
62b346ee 17499};
8ecd3266 17500
62b346ee 17501static struct cmd_node bgp_evpn_node = {
f4b8291f 17502 .name = "bgp evpn",
62b346ee 17503 .node = BGP_EVPN_NODE,
24389580 17504 .parent_node = BGP_NODE,
62b346ee 17505 .prompt = "%s(config-router-evpn)# ",
dd2c81b8 17506 .no_xpath = true,
62b346ee 17507};
4e0b7b6d 17508
62b346ee 17509static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 17510 .name = "bgp evpn vni",
62b346ee 17511 .node = BGP_EVPN_VNI_NODE,
24389580 17512 .parent_node = BGP_EVPN_NODE,
62b346ee 17513 .prompt = "%s(config-router-af-vni)# ",
62b346ee 17514};
90e60aa7 17515
62b346ee 17516static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 17517 .name = "bgp ipv4 flowspec",
62b346ee 17518 .node = BGP_FLOWSPECV4_NODE,
24389580 17519 .parent_node = BGP_NODE,
62b346ee 17520 .prompt = "%s(config-router-af)# ",
dd2c81b8 17521 .no_xpath = true,
62b346ee 17522};
7c40bf39 17523
62b346ee 17524static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 17525 .name = "bgp ipv6 flowspec",
62b346ee 17526 .node = BGP_FLOWSPECV6_NODE,
24389580 17527 .parent_node = BGP_NODE,
62b346ee 17528 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 17529 .no_xpath = true,
62b346ee 17530};
7c40bf39 17531
bfaab44d
HS
17532static struct cmd_node bgp_srv6_node = {
17533 .name = "bgp srv6",
17534 .node = BGP_SRV6_NODE,
17535 .parent_node = BGP_NODE,
17536 .prompt = "%s(config-router-srv6)# ",
17537};
17538
d62a17ae 17539static void community_list_vty(void);
1f8ae70b 17540
8c20061f
DA
17541static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17542{
17543 struct bgp *bgp;
17544 struct peer_group *group;
17545 struct listnode *lnbgp, *lnpeer;
17546
17547 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17548 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17549 vector_set(comps,
17550 XSTRDUP(MTYPE_COMPLETION, group->name));
17551 }
17552}
17553
17554static void bgp_ac_peer(vector comps, struct cmd_token *token)
b8a815e5 17555{
d62a17ae 17556 struct bgp *bgp;
17557 struct peer *peer;
d62a17ae 17558 struct listnode *lnbgp, *lnpeer;
b8a815e5 17559
d62a17ae 17560 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17561 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17562 /* only provide suggestions on the appropriate input
17563 * token type,
17564 * they'll otherwise show up multiple times */
17565 enum cmd_token_type match_type;
17566 char *name = peer->host;
d48ed3e0 17567
d62a17ae 17568 if (peer->conf_if) {
17569 match_type = VARIABLE_TKN;
17570 name = peer->conf_if;
17571 } else if (strchr(peer->host, ':'))
17572 match_type = IPV6_TKN;
17573 else
17574 match_type = IPV4_TKN;
d48ed3e0 17575
d62a17ae 17576 if (token->type != match_type)
17577 continue;
d48ed3e0 17578
d62a17ae 17579 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17580 }
d62a17ae 17581 }
b8a815e5
DL
17582}
17583
8c20061f
DA
17584static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17585{
17586 bgp_ac_peer(comps, token);
84de1483
DA
17587
17588 if (token->type == VARIABLE_TKN)
17589 bgp_ac_peergroup(comps, token);
8c20061f
DA
17590}
17591
b8a815e5 17592static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 17593 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17594 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 17595 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 17596 {.completions = NULL}};
17597
47a306a0
DS
17598static const struct cmd_variable_handler bgp_var_peergroup[] = {
17599 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17600 {.completions = NULL} };
17601
d62a17ae 17602void bgp_vty_init(void)
17603{
17604 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 17605 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 17606
17607 /* Install bgp top node. */
612c2c15
DL
17608 install_node(&bgp_node);
17609 install_node(&bgp_ipv4_unicast_node);
17610 install_node(&bgp_ipv4_multicast_node);
17611 install_node(&bgp_ipv4_labeled_unicast_node);
17612 install_node(&bgp_ipv6_unicast_node);
17613 install_node(&bgp_ipv6_multicast_node);
17614 install_node(&bgp_ipv6_labeled_unicast_node);
17615 install_node(&bgp_vpnv4_node);
17616 install_node(&bgp_vpnv6_node);
17617 install_node(&bgp_evpn_node);
17618 install_node(&bgp_evpn_vni_node);
17619 install_node(&bgp_flowspecv4_node);
17620 install_node(&bgp_flowspecv6_node);
bfaab44d 17621 install_node(&bgp_srv6_node);
d62a17ae 17622
17623 /* Install default VTY commands to new nodes. */
17624 install_default(BGP_NODE);
17625 install_default(BGP_IPV4_NODE);
17626 install_default(BGP_IPV4M_NODE);
17627 install_default(BGP_IPV4L_NODE);
17628 install_default(BGP_IPV6_NODE);
17629 install_default(BGP_IPV6M_NODE);
17630 install_default(BGP_IPV6L_NODE);
17631 install_default(BGP_VPNV4_NODE);
17632 install_default(BGP_VPNV6_NODE);
7c40bf39 17633 install_default(BGP_FLOWSPECV4_NODE);
17634 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 17635 install_default(BGP_EVPN_NODE);
17636 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 17637 install_default(BGP_SRV6_NODE);
d62a17ae 17638
8029b216
AK
17639 /* "bgp local-mac" hidden commands. */
17640 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17641 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17642
9acb67cb
DS
17643 /* "bgp suppress-fib-pending" global */
17644 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17645
d62a17ae 17646 /* bgp route-map delay-timer commands. */
17647 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17648 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17649
f852eb98
PG
17650 /* bgp fast-convergence command */
17651 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
17652 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
17653
d70583f7
D
17654 /* global bgp update-delay command */
17655 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17656 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17657
05bd726c 17658 /* global bgp graceful-shutdown command */
17659 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17660 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17661
d62a17ae 17662 /* Dummy commands (Currently not supported) */
17663 install_element(BGP_NODE, &no_synchronization_cmd);
17664 install_element(BGP_NODE, &no_auto_summary_cmd);
17665
17666 /* "router bgp" commands. */
17667 install_element(CONFIG_NODE, &router_bgp_cmd);
17668
17669 /* "no router bgp" commands. */
17670 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17671
17672 /* "bgp router-id" commands. */
17673 install_element(BGP_NODE, &bgp_router_id_cmd);
17674 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17675
c208c586
S
17676 /* "bgp suppress-fib-pending" command */
17677 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17678
d62a17ae 17679 /* "bgp cluster-id" commands. */
17680 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17681 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17682
c163f297
DS
17683 /* "bgp no-rib" commands. */
17684 install_element(CONFIG_NODE, &bgp_norib_cmd);
17685 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17686
e46723a5
DS
17687 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17688
d62a17ae 17689 /* "bgp confederation" commands. */
17690 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17691 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17692
17693 /* "bgp confederation peers" commands. */
17694 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17695 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17696
17697 /* bgp max-med command */
17698 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17699 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17700 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17701 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17702 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17703
17704 /* bgp disable-ebgp-connected-nh-check */
17705 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17706 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17707
17708 /* bgp update-delay command */
17709 install_element(BGP_NODE, &bgp_update_delay_cmd);
17710 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 17711
17712 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 17713 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 17714
17715 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17716 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17717
17718 /* "maximum-paths" commands. */
17719 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17720 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17721 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17722 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17723 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17724 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17725 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17726 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17727 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17728 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17729 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17730 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17731 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17732 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17733 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17734
39edabac
PG
17735 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17736 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17737 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17738 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17739 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 17740 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17741 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17742 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17743 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17744 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17745
17746 /* "timers bgp" commands. */
17747 install_element(BGP_NODE, &bgp_timers_cmd);
17748 install_element(BGP_NODE, &no_bgp_timers_cmd);
17749
b042667a
TI
17750 /* "minimum-holdtime" commands. */
17751 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
17752 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
17753
d62a17ae 17754 /* route-map delay-timer commands - per instance for backwards compat.
17755 */
17756 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17757 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17758
17759 /* "bgp client-to-client reflection" commands */
17760 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17761 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17762
17763 /* "bgp always-compare-med" commands */
17764 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17765 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17766
9dac9fc8
DA
17767 /* bgp ebgp-requires-policy */
17768 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17769 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17770
2adac256
DA
17771 /* bgp suppress-duplicates */
17772 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17773 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17774
fb29348a
DA
17775 /* bgp reject-as-sets */
17776 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17777 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17778
d62a17ae 17779 /* "bgp deterministic-med" commands */
17780 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17781 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17782
055679e9 17783 /* "bgp graceful-restart" command */
36235319
QY
17784 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17785 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 17786
17787 /* "bgp graceful-restart-disable" command */
36235319
QY
17788 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17789 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 17790
17791 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
17792 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17793 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 17794
17795 /* "neighbor a:b:c:d graceful-restart-disable" command */
17796 install_element(BGP_NODE,
17797 &bgp_neighbor_graceful_restart_disable_set_cmd);
17798 install_element(BGP_NODE,
17799 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17800
17801 /* "neighbor a:b:c:d graceful-restart-helper" command */
17802 install_element(BGP_NODE,
17803 &bgp_neighbor_graceful_restart_helper_set_cmd);
17804 install_element(BGP_NODE,
17805 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17806
d62a17ae 17807 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17808 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17809 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17810 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 17811 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 17812 install_element(BGP_NODE,
17813 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 17814 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17815 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17816
d6e3c15b 17817 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17818 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 17819 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17820 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 17821
7f323236
DW
17822 /* "bgp graceful-shutdown" commands */
17823 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17824 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17825
8606be87
DA
17826 /* "bgp long-lived-graceful-restart" commands */
17827 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
17828 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
17829
d62a17ae 17830 /* "bgp fast-external-failover" commands */
17831 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17832 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17833
d62a17ae 17834 /* "bgp bestpath compare-routerid" commands */
17835 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17836 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17837
17838 /* "bgp bestpath as-path ignore" commands */
17839 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17840 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17841
17842 /* "bgp bestpath as-path confed" commands */
17843 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17844 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17845
17846 /* "bgp bestpath as-path multipath-relax" commands */
17847 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17848 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17849
ee88563a
JM
17850 /* "bgp bestpath peer-type multipath-relax" commands */
17851 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
17852 install_element(BGP_NODE,
17853 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
17854
d62a17ae 17855 /* "bgp log-neighbor-changes" commands */
17856 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17857 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17858
17859 /* "bgp bestpath med" commands */
17860 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17861 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17862
f7e1c681 17863 /* "bgp bestpath bandwidth" commands */
17864 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 17865 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 17866
b16bcbba
TA
17867 /* "no bgp default <afi>-<safi>" commands. */
17868 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
e84c59af 17869
d62a17ae 17870 /* "bgp network import-check" commands. */
17871 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17872 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17873 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17874
17875 /* "bgp default local-preference" commands. */
17876 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17877 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17878
17879 /* bgp default show-hostname */
17880 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17881 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17882
aef999a2
DA
17883 /* bgp default show-nexthop-hostname */
17884 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17885 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17886
d62a17ae 17887 /* "bgp default subgroup-pkt-queue-max" commands. */
17888 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17889 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17890
17891 /* bgp ibgp-allow-policy-mods command */
17892 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17893 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17894
17895 /* "bgp listen limit" commands. */
17896 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17897 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17898
17899 /* "bgp listen range" commands. */
17900 install_element(BGP_NODE, &bgp_listen_range_cmd);
17901 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17902
8175f54a 17903 /* "bgp default shutdown" command */
f26845f9 17904 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
17905
17906 /* "bgp shutdown" commands */
17907 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 17908 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 17909 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 17910 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 17911
d62a17ae 17912 /* "neighbor remote-as" commands. */
17913 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17914 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17915 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17916 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17917 install_element(BGP_NODE,
17918 &neighbor_interface_v6only_config_remote_as_cmd);
17919 install_element(BGP_NODE, &no_neighbor_cmd);
17920 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17921
17922 /* "neighbor peer-group" commands. */
17923 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17924 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17925 install_element(BGP_NODE,
17926 &no_neighbor_interface_peer_group_remote_as_cmd);
17927
17928 /* "neighbor local-as" commands. */
17929 install_element(BGP_NODE, &neighbor_local_as_cmd);
17930 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17931 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17932 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17933
17934 /* "neighbor solo" commands. */
17935 install_element(BGP_NODE, &neighbor_solo_cmd);
17936 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17937
17938 /* "neighbor password" commands. */
17939 install_element(BGP_NODE, &neighbor_password_cmd);
17940 install_element(BGP_NODE, &no_neighbor_password_cmd);
17941
17942 /* "neighbor activate" commands. */
17943 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17944 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17945 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17946 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17947 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17948 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17949 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17950 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
17951 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 17952 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
17953 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 17954 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
17955
17956 /* "no neighbor activate" commands. */
17957 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
17958 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
17959 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
17960 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
17961 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
17962 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
17963 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
17964 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
17965 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 17966 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
17967 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 17968 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
17969
17970 /* "neighbor peer-group" set commands. */
17971 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
17972 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17973 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
17974 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17975 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
17976 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
17977 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17978 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 17979 install_element(BGP_FLOWSPECV4_NODE,
17980 &neighbor_set_peer_group_hidden_cmd);
17981 install_element(BGP_FLOWSPECV6_NODE,
17982 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 17983
17984 /* "no neighbor peer-group unset" commands. */
17985 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
17986 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17987 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17988 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17989 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17990 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17991 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17992 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 17993 install_element(BGP_FLOWSPECV4_NODE,
17994 &no_neighbor_set_peer_group_hidden_cmd);
17995 install_element(BGP_FLOWSPECV6_NODE,
17996 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 17997
17998 /* "neighbor softreconfiguration inbound" commands.*/
17999 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18000 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18001 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18002 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18003 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18004 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18005 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18006 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18007 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18008 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18009 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18010 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18011 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18012 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18013 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18014 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18015 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18016 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 18017 install_element(BGP_FLOWSPECV4_NODE,
18018 &neighbor_soft_reconfiguration_cmd);
18019 install_element(BGP_FLOWSPECV4_NODE,
18020 &no_neighbor_soft_reconfiguration_cmd);
18021 install_element(BGP_FLOWSPECV6_NODE,
18022 &neighbor_soft_reconfiguration_cmd);
18023 install_element(BGP_FLOWSPECV6_NODE,
18024 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
18025 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18026 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 18027
18028 /* "neighbor attribute-unchanged" commands. */
18029 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18030 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18031 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18032 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18033 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18034 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18035 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18036 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18037 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18038 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18039 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18040 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18041 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18042 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18043 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18044 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18045 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18046 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18047
18048 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18049 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18050
b8ad84d2
PG
18051 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18052 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18053 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18054 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18055
d62a17ae 18056 /* "nexthop-local unchanged" commands */
18057 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18058 install_element(BGP_IPV6_NODE,
18059 &no_neighbor_nexthop_local_unchanged_cmd);
18060
18061 /* "neighbor next-hop-self" commands. */
18062 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18063 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18064 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18065 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18066 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18067 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18068 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18069 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18070 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18071 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18072 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18073 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18074 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18075 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18076 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18077 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18078 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18079 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
18080 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18081 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 18082
18083 /* "neighbor next-hop-self force" commands. */
18084 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18085 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
18086 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18087 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18088 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18089 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18090 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18091 install_element(BGP_IPV4_NODE,
18092 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18093 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18094 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18095 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18096 install_element(BGP_IPV4M_NODE,
18097 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18098 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18099 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18100 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18101 install_element(BGP_IPV4L_NODE,
18102 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18103 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18104 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18105 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18106 install_element(BGP_IPV6_NODE,
18107 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18108 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18109 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18110 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18111 install_element(BGP_IPV6M_NODE,
18112 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18113 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18114 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18115 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18116 install_element(BGP_IPV6L_NODE,
18117 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18118 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18119 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18120 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18121 install_element(BGP_VPNV4_NODE,
18122 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18123 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18124 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18125 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18126 install_element(BGP_VPNV6_NODE,
18127 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
18128 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18129 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 18130
18131 /* "neighbor as-override" commands. */
18132 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18133 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18134 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18135 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18136 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18137 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18138 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18139 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18140 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18141 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18142 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18143 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18144 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18145 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18146 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18147 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18148 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18149 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18150
18151 /* "neighbor remove-private-AS" commands. */
18152 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18153 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18154 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18155 install_element(BGP_NODE,
18156 &no_neighbor_remove_private_as_all_hidden_cmd);
18157 install_element(BGP_NODE,
18158 &neighbor_remove_private_as_replace_as_hidden_cmd);
18159 install_element(BGP_NODE,
18160 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18161 install_element(BGP_NODE,
18162 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18163 install_element(
18164 BGP_NODE,
18165 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18166 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18167 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18168 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18169 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18170 install_element(BGP_IPV4_NODE,
18171 &neighbor_remove_private_as_replace_as_cmd);
18172 install_element(BGP_IPV4_NODE,
18173 &no_neighbor_remove_private_as_replace_as_cmd);
18174 install_element(BGP_IPV4_NODE,
18175 &neighbor_remove_private_as_all_replace_as_cmd);
18176 install_element(BGP_IPV4_NODE,
18177 &no_neighbor_remove_private_as_all_replace_as_cmd);
18178 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18179 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18180 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18181 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18182 install_element(BGP_IPV4M_NODE,
18183 &neighbor_remove_private_as_replace_as_cmd);
18184 install_element(BGP_IPV4M_NODE,
18185 &no_neighbor_remove_private_as_replace_as_cmd);
18186 install_element(BGP_IPV4M_NODE,
18187 &neighbor_remove_private_as_all_replace_as_cmd);
18188 install_element(BGP_IPV4M_NODE,
18189 &no_neighbor_remove_private_as_all_replace_as_cmd);
18190 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18191 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18192 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18193 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18194 install_element(BGP_IPV4L_NODE,
18195 &neighbor_remove_private_as_replace_as_cmd);
18196 install_element(BGP_IPV4L_NODE,
18197 &no_neighbor_remove_private_as_replace_as_cmd);
18198 install_element(BGP_IPV4L_NODE,
18199 &neighbor_remove_private_as_all_replace_as_cmd);
18200 install_element(BGP_IPV4L_NODE,
18201 &no_neighbor_remove_private_as_all_replace_as_cmd);
18202 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18203 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18204 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18205 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18206 install_element(BGP_IPV6_NODE,
18207 &neighbor_remove_private_as_replace_as_cmd);
18208 install_element(BGP_IPV6_NODE,
18209 &no_neighbor_remove_private_as_replace_as_cmd);
18210 install_element(BGP_IPV6_NODE,
18211 &neighbor_remove_private_as_all_replace_as_cmd);
18212 install_element(BGP_IPV6_NODE,
18213 &no_neighbor_remove_private_as_all_replace_as_cmd);
18214 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18215 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18216 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18217 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18218 install_element(BGP_IPV6M_NODE,
18219 &neighbor_remove_private_as_replace_as_cmd);
18220 install_element(BGP_IPV6M_NODE,
18221 &no_neighbor_remove_private_as_replace_as_cmd);
18222 install_element(BGP_IPV6M_NODE,
18223 &neighbor_remove_private_as_all_replace_as_cmd);
18224 install_element(BGP_IPV6M_NODE,
18225 &no_neighbor_remove_private_as_all_replace_as_cmd);
18226 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18227 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18228 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18229 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18230 install_element(BGP_IPV6L_NODE,
18231 &neighbor_remove_private_as_replace_as_cmd);
18232 install_element(BGP_IPV6L_NODE,
18233 &no_neighbor_remove_private_as_replace_as_cmd);
18234 install_element(BGP_IPV6L_NODE,
18235 &neighbor_remove_private_as_all_replace_as_cmd);
18236 install_element(BGP_IPV6L_NODE,
18237 &no_neighbor_remove_private_as_all_replace_as_cmd);
18238 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18239 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18240 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18241 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18242 install_element(BGP_VPNV4_NODE,
18243 &neighbor_remove_private_as_replace_as_cmd);
18244 install_element(BGP_VPNV4_NODE,
18245 &no_neighbor_remove_private_as_replace_as_cmd);
18246 install_element(BGP_VPNV4_NODE,
18247 &neighbor_remove_private_as_all_replace_as_cmd);
18248 install_element(BGP_VPNV4_NODE,
18249 &no_neighbor_remove_private_as_all_replace_as_cmd);
18250 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18251 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18252 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18253 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18254 install_element(BGP_VPNV6_NODE,
18255 &neighbor_remove_private_as_replace_as_cmd);
18256 install_element(BGP_VPNV6_NODE,
18257 &no_neighbor_remove_private_as_replace_as_cmd);
18258 install_element(BGP_VPNV6_NODE,
18259 &neighbor_remove_private_as_all_replace_as_cmd);
18260 install_element(BGP_VPNV6_NODE,
18261 &no_neighbor_remove_private_as_all_replace_as_cmd);
18262
18263 /* "neighbor send-community" commands.*/
18264 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18265 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18266 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18267 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18268 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18269 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18270 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18271 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18272 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18273 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18274 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18275 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18276 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18277 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18278 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18279 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18280 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18281 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18282 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18283 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18284 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18285 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18286 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18287 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18288 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18289 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18290 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18291 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18292 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18293 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18294 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18295 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18296 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18297 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18298 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18299 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18300
18301 /* "neighbor route-reflector" commands.*/
18302 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18303 install_element(BGP_NODE,
18304 &no_neighbor_route_reflector_client_hidden_cmd);
18305 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18306 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18307 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18308 install_element(BGP_IPV4M_NODE,
18309 &no_neighbor_route_reflector_client_cmd);
18310 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18311 install_element(BGP_IPV4L_NODE,
18312 &no_neighbor_route_reflector_client_cmd);
18313 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18314 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18315 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18316 install_element(BGP_IPV6M_NODE,
18317 &no_neighbor_route_reflector_client_cmd);
18318 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18319 install_element(BGP_IPV6L_NODE,
18320 &no_neighbor_route_reflector_client_cmd);
18321 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18322 install_element(BGP_VPNV4_NODE,
18323 &no_neighbor_route_reflector_client_cmd);
18324 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18325 install_element(BGP_VPNV6_NODE,
18326 &no_neighbor_route_reflector_client_cmd);
7c40bf39 18327 install_element(BGP_FLOWSPECV4_NODE,
18328 &neighbor_route_reflector_client_cmd);
18329 install_element(BGP_FLOWSPECV4_NODE,
18330 &no_neighbor_route_reflector_client_cmd);
18331 install_element(BGP_FLOWSPECV6_NODE,
18332 &neighbor_route_reflector_client_cmd);
18333 install_element(BGP_FLOWSPECV6_NODE,
18334 &no_neighbor_route_reflector_client_cmd);
d62a17ae 18335 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18336 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18337
18338 /* "neighbor route-server" commands.*/
18339 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18340 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18341 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18342 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18343 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18344 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18345 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18346 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18347 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18348 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18349 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18350 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18351 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18352 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18353 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18354 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18355 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18356 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
18357 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18358 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 18359 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18360 install_element(BGP_FLOWSPECV4_NODE,
18361 &no_neighbor_route_server_client_cmd);
18362 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18363 install_element(BGP_FLOWSPECV6_NODE,
18364 &no_neighbor_route_server_client_cmd);
d62a17ae 18365
7c0e4312
DA
18366 /* "neighbor disable-addpath-rx" commands. */
18367 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
18368 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18369 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
18370 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18371 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
18372 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18373 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
18374 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18375 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
18376 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18377 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
18378 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18379 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
18380 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18381 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
18382 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18383
d62a17ae 18384 /* "neighbor addpath-tx-all-paths" commands.*/
18385 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18386 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18387 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18388 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18389 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18390 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18391 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18392 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18393 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18394 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18395 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18396 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18397 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18398 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18399 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18400 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18401 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18402 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18403
18404 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18405 install_element(BGP_NODE,
18406 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18407 install_element(BGP_NODE,
18408 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18409 install_element(BGP_IPV4_NODE,
18410 &neighbor_addpath_tx_bestpath_per_as_cmd);
18411 install_element(BGP_IPV4_NODE,
18412 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18413 install_element(BGP_IPV4M_NODE,
18414 &neighbor_addpath_tx_bestpath_per_as_cmd);
18415 install_element(BGP_IPV4M_NODE,
18416 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18417 install_element(BGP_IPV4L_NODE,
18418 &neighbor_addpath_tx_bestpath_per_as_cmd);
18419 install_element(BGP_IPV4L_NODE,
18420 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18421 install_element(BGP_IPV6_NODE,
18422 &neighbor_addpath_tx_bestpath_per_as_cmd);
18423 install_element(BGP_IPV6_NODE,
18424 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18425 install_element(BGP_IPV6M_NODE,
18426 &neighbor_addpath_tx_bestpath_per_as_cmd);
18427 install_element(BGP_IPV6M_NODE,
18428 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18429 install_element(BGP_IPV6L_NODE,
18430 &neighbor_addpath_tx_bestpath_per_as_cmd);
18431 install_element(BGP_IPV6L_NODE,
18432 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18433 install_element(BGP_VPNV4_NODE,
18434 &neighbor_addpath_tx_bestpath_per_as_cmd);
18435 install_element(BGP_VPNV4_NODE,
18436 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18437 install_element(BGP_VPNV6_NODE,
18438 &neighbor_addpath_tx_bestpath_per_as_cmd);
18439 install_element(BGP_VPNV6_NODE,
18440 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18441
2b31007c
RZ
18442 /* "neighbor sender-as-path-loop-detection" commands. */
18443 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18444 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18445
d62a17ae 18446 /* "neighbor passive" commands. */
18447 install_element(BGP_NODE, &neighbor_passive_cmd);
18448 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18449
18450
18451 /* "neighbor shutdown" commands. */
18452 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18453 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18454 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18455 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
18456 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18457 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 18458
18459 /* "neighbor capability extended-nexthop" commands.*/
18460 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18461 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18462
18463 /* "neighbor capability orf prefix-list" commands.*/
18464 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18465 install_element(BGP_NODE,
18466 &no_neighbor_capability_orf_prefix_hidden_cmd);
18467 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18468 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18469 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18470 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18471 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18472 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18473 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18474 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18475 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18476 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18477 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18478 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18479
18480 /* "neighbor capability dynamic" commands.*/
18481 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18482 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18483
18484 /* "neighbor dont-capability-negotiate" commands. */
18485 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18486 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18487
18488 /* "neighbor ebgp-multihop" commands. */
18489 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18490 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18491 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18492
18493 /* "neighbor disable-connected-check" commands. */
18494 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18495 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18496
7ab294ea
DA
18497 /* "neighbor disable-link-bw-encoding-ieee" commands. */
18498 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
18499 install_element(BGP_NODE,
18500 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
27aa23a4 18501
d08c0c80
DA
18502 /* "neighbor extended-optional-parameters" commands. */
18503 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
18504 install_element(BGP_NODE,
18505 &no_neighbor_extended_optional_parameters_cmd);
18506
47cbc09b
PM
18507 /* "neighbor enforce-first-as" commands. */
18508 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18509 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18510
d62a17ae 18511 /* "neighbor description" commands. */
18512 install_element(BGP_NODE, &neighbor_description_cmd);
18513 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 18514 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 18515
18516 /* "neighbor update-source" commands. "*/
18517 install_element(BGP_NODE, &neighbor_update_source_cmd);
18518 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18519
18520 /* "neighbor default-originate" commands. */
18521 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18522 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18523 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18524 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18525 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18526 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18527 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18528 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18529 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18530 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18531 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18532 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18533 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18534 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18535 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18536 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18537 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18538 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18539 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18540 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18541 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18542
18543 /* "neighbor port" commands. */
18544 install_element(BGP_NODE, &neighbor_port_cmd);
18545 install_element(BGP_NODE, &no_neighbor_port_cmd);
18546
18547 /* "neighbor weight" commands. */
18548 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18549 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18550
18551 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18552 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18553 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18554 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18555 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18556 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18557 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18558 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18559 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18560 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18561 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18562 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18563 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18564 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18565 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18566 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18567
18568 /* "neighbor override-capability" commands. */
18569 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18570 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18571
18572 /* "neighbor strict-capability-match" commands. */
18573 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18574 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18575
18576 /* "neighbor timers" commands. */
18577 install_element(BGP_NODE, &neighbor_timers_cmd);
18578 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18579
18580 /* "neighbor timers connect" commands. */
18581 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18582 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18583
d43114f3
DS
18584 /* "neighbor timers delayopen" commands. */
18585 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18586 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18587
d62a17ae 18588 /* "neighbor advertisement-interval" commands. */
18589 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18590 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18591
18592 /* "neighbor interface" commands. */
18593 install_element(BGP_NODE, &neighbor_interface_cmd);
18594 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18595
18596 /* "neighbor distribute" commands. */
18597 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18598 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18599 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18600 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18601 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18602 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18603 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18604 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18605 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18606 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18607 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18608 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18609 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18610 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18611 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18612 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18613 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18614 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18615
18616 /* "neighbor prefix-list" commands. */
18617 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
642ef664 18618 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
d62a17ae 18619 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18620 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18621 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
642ef664 18622 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18623 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
642ef664 18624 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18625 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18626 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18627 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
642ef664 18628 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18629 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
642ef664 18630 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18631 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18632 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18633 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18634 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18635 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18636 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18637 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18638 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18639
18640 /* "neighbor filter-list" commands. */
18641 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18642 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18643 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18644 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18645 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18646 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18647 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18648 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18649 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18650 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18651 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18652 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18653 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18654 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18655 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18656 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18657 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18658 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 18659 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18660 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18661 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18662 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 18663
18664 /* "neighbor route-map" commands. */
d6d7ed37
IR
18665 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18666 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
d62a17ae 18667 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18668 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18669 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
0ea8d871 18670 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18671 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
0ea8d871 18672 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18673 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18674 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18675 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
0ea8d871 18676 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18677 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
0ea8d871 18678 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18679 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18680 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18681 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18682 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18683 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18684 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18685 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18686 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549 18687 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
0ea8d871 18688 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18689
18690 /* "neighbor unsuppress-map" commands. */
18691 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18692 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18693 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18694 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18695 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18696 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18697 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18698 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18699 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18700 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18701 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18702 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18703 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18704 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18705 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18706 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18707 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18708 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18709
7f7940e6 18710 /* "neighbor advertise-map" commands. */
389e4f92 18711 install_element(BGP_NODE, &bgp_condadv_period_cmd);
7f7940e6 18712 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 18713 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18714 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18715 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18716 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18717 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18718 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18719 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18720 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18721
fde246e8
DA
18722 /* neighbor maximum-prefix-out commands. */
18723 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18724 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18725 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18726 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18727 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18728 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18729 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18730 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18731 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18732 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18733 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18734 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18735 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18736 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18737 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18738 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18739 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18740 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18741
d62a17ae 18742 /* "neighbor maximum-prefix" commands. */
18743 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18744 install_element(BGP_NODE,
18745 &neighbor_maximum_prefix_threshold_hidden_cmd);
18746 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18747 install_element(BGP_NODE,
18748 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18749 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18750 install_element(BGP_NODE,
18751 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18752 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18753 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18754 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18755 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18756 install_element(BGP_IPV4_NODE,
18757 &neighbor_maximum_prefix_threshold_warning_cmd);
18758 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18759 install_element(BGP_IPV4_NODE,
18760 &neighbor_maximum_prefix_threshold_restart_cmd);
18761 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18762 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18763 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18764 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18765 install_element(BGP_IPV4M_NODE,
18766 &neighbor_maximum_prefix_threshold_warning_cmd);
18767 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18768 install_element(BGP_IPV4M_NODE,
18769 &neighbor_maximum_prefix_threshold_restart_cmd);
18770 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18771 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18772 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18773 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18774 install_element(BGP_IPV4L_NODE,
18775 &neighbor_maximum_prefix_threshold_warning_cmd);
18776 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18777 install_element(BGP_IPV4L_NODE,
18778 &neighbor_maximum_prefix_threshold_restart_cmd);
18779 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18780 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18781 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18782 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18783 install_element(BGP_IPV6_NODE,
18784 &neighbor_maximum_prefix_threshold_warning_cmd);
18785 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18786 install_element(BGP_IPV6_NODE,
18787 &neighbor_maximum_prefix_threshold_restart_cmd);
18788 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18789 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18790 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18791 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18792 install_element(BGP_IPV6M_NODE,
18793 &neighbor_maximum_prefix_threshold_warning_cmd);
18794 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18795 install_element(BGP_IPV6M_NODE,
18796 &neighbor_maximum_prefix_threshold_restart_cmd);
18797 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18798 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18799 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18800 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18801 install_element(BGP_IPV6L_NODE,
18802 &neighbor_maximum_prefix_threshold_warning_cmd);
18803 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18804 install_element(BGP_IPV6L_NODE,
18805 &neighbor_maximum_prefix_threshold_restart_cmd);
18806 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18807 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18808 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18809 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18810 install_element(BGP_VPNV4_NODE,
18811 &neighbor_maximum_prefix_threshold_warning_cmd);
18812 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18813 install_element(BGP_VPNV4_NODE,
18814 &neighbor_maximum_prefix_threshold_restart_cmd);
18815 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18816 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18817 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18818 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18819 install_element(BGP_VPNV6_NODE,
18820 &neighbor_maximum_prefix_threshold_warning_cmd);
18821 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18822 install_element(BGP_VPNV6_NODE,
18823 &neighbor_maximum_prefix_threshold_restart_cmd);
18824 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18825
18826 /* "neighbor allowas-in" */
18827 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18828 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18829 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18830 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18831 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18832 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18833 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18834 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18835 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18836 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18837 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18838 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18839 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18840 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18841 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18842 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18843 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18844 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18845 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18846 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18847
18848 /* address-family commands. */
18849 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18850 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 18851#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 18852 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18853 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 18854#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 18855
d62a17ae 18856 install_element(BGP_NODE, &address_family_evpn_cmd);
18857
18858 /* "exit-address-family" command. */
18859 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18860 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18861 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18862 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18863 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18864 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18865 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18866 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 18867 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18868 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 18869 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18870
18871 /* "clear ip bgp commands" */
18872 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18873
18874 /* clear ip bgp prefix */
18875 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18876 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18877 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18878
18879 /* "show [ip] bgp summary" commands. */
18880 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 18881 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 18882 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 18883 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 18884 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18885 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 18886 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18887
18888 /* "show [ip] bgp neighbors" commands. */
18889 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18890
36235319 18891 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 18892
d62a17ae 18893 /* "show [ip] bgp peer-group" commands. */
18894 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18895
18896 /* "show [ip] bgp paths" commands. */
18897 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18898
18899 /* "show [ip] bgp community" commands. */
18900 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18901
18902 /* "show ip bgp large-community" commands. */
18903 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18904 /* "show [ip] bgp attribute-info" commands. */
18905 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 18906 /* "show [ip] bgp route-leak" command */
18907 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 18908
18909 /* "redistribute" commands. */
18910 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18911 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18912 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18913 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18914 install_element(BGP_NODE,
18915 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18916 install_element(BGP_NODE,
18917 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18918 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18919 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18920 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18921 install_element(BGP_NODE,
18922 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18923 install_element(BGP_NODE,
18924 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18925 install_element(BGP_NODE,
18926 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18927 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18928 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18929 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18930 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18931 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18932 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18933 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18934 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18935 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18936 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18937 install_element(BGP_IPV4_NODE,
18938 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18939 install_element(BGP_IPV4_NODE,
18940 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18941 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18942 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18943 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18944 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18945 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18946 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18947
b9c7bc5a
PZ
18948 /* import|export vpn [route-map WORD] */
18949 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18950 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 18951
12a844a5
DS
18952 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18953 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18954
d62a17ae 18955 /* ttl_security commands */
18956 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18957 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18958
18959 /* "show [ip] bgp memory" commands. */
18960 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18961
acf71666
MK
18962 /* "show bgp martian next-hop" */
18963 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18964
48ecf8f5
DS
18965 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18966
d62a17ae 18967 /* "show [ip] bgp views" commands. */
18968 install_element(VIEW_NODE, &show_bgp_views_cmd);
18969
18970 /* "show [ip] bgp vrfs" commands. */
18971 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
18972
18973 /* Community-list. */
18974 community_list_vty();
ddb5b488 18975
ed0e57e3
DA
18976 community_alias_vty();
18977
ddb5b488 18978 /* vpn-policy commands */
b9c7bc5a
PZ
18979 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
18980 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
18981 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
18982 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
18983 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
18984 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
18985 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
18986 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
18987 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
18988 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
18989 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
18990 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 18991
301ad80a
PG
18992 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
18993 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
18994
b9c7bc5a
PZ
18995 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
18996 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
18997 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
18998 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
18999 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19000 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19001 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19002 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
19003 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19004 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
19005
19006 /* tcp-mss command */
19007 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19008 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
19009
19010 /* srv6 commands */
ea372e81 19011 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
bfaab44d 19012 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
0249b8b6 19013 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
a0281b2e 19014 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
0249b8b6 19015 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
b72c9e14
HS
19016 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19017 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
718e3744 19018}
6b0655a2 19019
718e3744 19020#include "memory.h"
19021#include "bgp_regex.h"
19022#include "bgp_clist.h"
19023#include "bgp_ecommunity.h"
19024
19025/* VTY functions. */
19026
19027/* Direction value to string conversion. */
d62a17ae 19028static const char *community_direct_str(int direct)
19029{
19030 switch (direct) {
19031 case COMMUNITY_DENY:
19032 return "deny";
19033 case COMMUNITY_PERMIT:
19034 return "permit";
19035 default:
19036 return "unknown";
19037 }
718e3744 19038}
19039
19040/* Display error string. */
d62a17ae 19041static void community_list_perror(struct vty *vty, int ret)
19042{
19043 switch (ret) {
19044 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19045 vty_out(vty, "%% Can't find community-list\n");
19046 break;
19047 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19048 vty_out(vty, "%% Malformed community-list value\n");
19049 break;
19050 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19051 vty_out(vty,
19052 "%% Community name conflict, previously defined as standard community\n");
19053 break;
19054 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19055 vty_out(vty,
19056 "%% Community name conflict, previously defined as expanded community\n");
19057 break;
19058 }
718e3744 19059}
19060
5bf15956
DW
19061/* "community-list" keyword help string. */
19062#define COMMUNITY_LIST_STR "Add a community list entry\n"
19063
7336e101
SP
19064/*community-list standard */
19065DEFUN (community_list_standard,
19066 bgp_community_list_standard_cmd,
a2099c1d 19067 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19068 BGP_STR
718e3744 19069 COMMUNITY_LIST_STR
19070 "Community list number (standard)\n"
5bf15956 19071 "Add an standard community-list entry\n"
718e3744 19072 "Community list name\n"
2f8cc0e5
DA
19073 "Sequence number of an entry\n"
19074 "Sequence number\n"
718e3744 19075 "Specify community to reject\n"
19076 "Specify community to accept\n"
19077 COMMUNITY_VAL_STR)
19078{
d62a17ae 19079 char *cl_name_or_number = NULL;
2f8cc0e5 19080 char *seq = NULL;
d62a17ae 19081 int direct = 0;
19082 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 19083 int idx = 0;
7336e101 19084
a08032fe 19085 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19086 if (idx)
19087 seq = argv[idx]->arg;
19088
19089 idx = 0;
d62a17ae 19090 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19091 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19092 cl_name_or_number = argv[idx]->arg;
19093 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19094 : COMMUNITY_DENY;
19095 argv_find(argv, argc, "AA:NN", &idx);
19096 char *str = argv_concat(argv, argc, idx);
42f914d4 19097
2f8cc0e5
DA
19098 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19099 direct, style);
42f914d4 19100
d62a17ae 19101 XFREE(MTYPE_TMP, str);
42f914d4 19102
d62a17ae 19103 if (ret < 0) {
19104 /* Display error string. */
19105 community_list_perror(vty, ret);
19106 return CMD_WARNING_CONFIG_FAILED;
19107 }
42f914d4 19108
d62a17ae 19109 return CMD_SUCCESS;
718e3744 19110}
19111
7336e101
SP
19112DEFUN (no_community_list_standard_all,
19113 no_bgp_community_list_standard_all_cmd,
a2099c1d 19114 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19115 NO_STR
19116 BGP_STR
19117 COMMUNITY_LIST_STR
19118 "Community list number (standard)\n"
19119 "Add an standard community-list entry\n"
19120 "Community list name\n"
2f8cc0e5
DA
19121 "Sequence number of an entry\n"
19122 "Sequence number\n"
7336e101
SP
19123 "Specify community to reject\n"
19124 "Specify community to accept\n"
19125 COMMUNITY_VAL_STR)
718e3744 19126{
d62a17ae 19127 char *cl_name_or_number = NULL;
174b5cb9 19128 char *str = NULL;
d62a17ae 19129 int direct = 0;
19130 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 19131 char *seq = NULL;
d62a17ae 19132 int idx = 0;
7336e101 19133
a08032fe 19134 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19135 if (idx)
19136 seq = argv[idx]->arg;
19137
19138 idx = 0;
174b5cb9
DA
19139 argv_find(argv, argc, "permit", &idx);
19140 argv_find(argv, argc, "deny", &idx);
19141
19142 if (idx) {
19143 direct = argv_find(argv, argc, "permit", &idx)
19144 ? COMMUNITY_PERMIT
19145 : COMMUNITY_DENY;
19146
19147 idx = 0;
19148 argv_find(argv, argc, "AA:NN", &idx);
19149 str = argv_concat(argv, argc, idx);
19150 }
19151
19152 idx = 0;
d62a17ae 19153 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19154 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19155 cl_name_or_number = argv[idx]->arg;
42f914d4 19156
2f8cc0e5 19157 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19158 direct, style);
42f914d4 19159
d62a17ae 19160 XFREE(MTYPE_TMP, str);
daf9ddbb 19161
d62a17ae 19162 if (ret < 0) {
19163 community_list_perror(vty, ret);
19164 return CMD_WARNING_CONFIG_FAILED;
19165 }
42f914d4 19166
d62a17ae 19167 return CMD_SUCCESS;
718e3744 19168}
7336e101 19169
174b5cb9 19170ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
a2099c1d 19171 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
174b5cb9
DA
19172 NO_STR BGP_STR COMMUNITY_LIST_STR
19173 "Community list number (standard)\n"
19174 "Add an standard community-list entry\n"
19175 "Community list name\n")
19176
7336e101
SP
19177/*community-list expanded */
19178DEFUN (community_list_expanded_all,
19179 bgp_community_list_expanded_all_cmd,
a2099c1d 19180 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19181 BGP_STR
19182 COMMUNITY_LIST_STR
718e3744 19183 "Community list number (expanded)\n"
5bf15956 19184 "Add an expanded community-list entry\n"
718e3744 19185 "Community list name\n"
2f8cc0e5
DA
19186 "Sequence number of an entry\n"
19187 "Sequence number\n"
718e3744 19188 "Specify community to reject\n"
19189 "Specify community to accept\n"
19190 COMMUNITY_VAL_STR)
19191{
d62a17ae 19192 char *cl_name_or_number = NULL;
2f8cc0e5 19193 char *seq = NULL;
d62a17ae 19194 int direct = 0;
19195 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19196 int idx = 0;
7b9a4750 19197
a08032fe 19198 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19199 if (idx)
19200 seq = argv[idx]->arg;
19201
19202 idx = 0;
19203
d62a17ae 19204 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19205 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19206 cl_name_or_number = argv[idx]->arg;
19207 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19208 : COMMUNITY_DENY;
19209 argv_find(argv, argc, "AA:NN", &idx);
19210 char *str = argv_concat(argv, argc, idx);
42f914d4 19211
2f8cc0e5
DA
19212 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19213 direct, style);
42f914d4 19214
d62a17ae 19215 XFREE(MTYPE_TMP, str);
42f914d4 19216
d62a17ae 19217 if (ret < 0) {
19218 /* Display error string. */
19219 community_list_perror(vty, ret);
19220 return CMD_WARNING_CONFIG_FAILED;
19221 }
42f914d4 19222
d62a17ae 19223 return CMD_SUCCESS;
718e3744 19224}
19225
7336e101
SP
19226DEFUN (no_community_list_expanded_all,
19227 no_bgp_community_list_expanded_all_cmd,
a2099c1d 19228 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19229 NO_STR
19230 BGP_STR
19231 COMMUNITY_LIST_STR
19232 "Community list number (expanded)\n"
19233 "Add an expanded community-list entry\n"
19234 "Community list name\n"
2f8cc0e5
DA
19235 "Sequence number of an entry\n"
19236 "Sequence number\n"
7336e101
SP
19237 "Specify community to reject\n"
19238 "Specify community to accept\n"
19239 COMMUNITY_VAL_STR)
718e3744 19240{
d62a17ae 19241 char *cl_name_or_number = NULL;
2f8cc0e5 19242 char *seq = NULL;
174b5cb9 19243 char *str = NULL;
d62a17ae 19244 int direct = 0;
19245 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19246 int idx = 0;
174b5cb9 19247
a08032fe 19248 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19249 if (idx)
19250 seq = argv[idx]->arg;
19251
19252 idx = 0;
174b5cb9
DA
19253 argv_find(argv, argc, "permit", &idx);
19254 argv_find(argv, argc, "deny", &idx);
19255
19256 if (idx) {
19257 direct = argv_find(argv, argc, "permit", &idx)
19258 ? COMMUNITY_PERMIT
19259 : COMMUNITY_DENY;
19260
19261 idx = 0;
19262 argv_find(argv, argc, "AA:NN", &idx);
19263 str = argv_concat(argv, argc, idx);
7336e101 19264 }
174b5cb9
DA
19265
19266 idx = 0;
d62a17ae 19267 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19268 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19269 cl_name_or_number = argv[idx]->arg;
42f914d4 19270
2f8cc0e5 19271 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19272 direct, style);
42f914d4 19273
d62a17ae 19274 XFREE(MTYPE_TMP, str);
daf9ddbb 19275
d62a17ae 19276 if (ret < 0) {
19277 community_list_perror(vty, ret);
19278 return CMD_WARNING_CONFIG_FAILED;
19279 }
42f914d4 19280
d62a17ae 19281 return CMD_SUCCESS;
718e3744 19282}
19283
36d4bb44
EB
19284ALIAS(no_community_list_expanded_all,
19285 no_bgp_community_list_expanded_all_list_cmd,
a2099c1d 19286 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
36d4bb44 19287 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
19288 "Community list number (expanded)\n"
19289 "Add an expanded community-list entry\n"
19290 "Community list name\n")
19291
8d9b8ed9
PM
19292/* Return configuration string of community-list entry. */
19293static const char *community_list_config_str(struct community_entry *entry)
19294{
19295 const char *str;
19296
19297 if (entry->any)
19298 str = "";
19299 else {
19300 if (entry->style == COMMUNITY_LIST_STANDARD)
19301 str = community_str(entry->u.com, false);
19302 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19303 str = lcommunity_str(entry->u.lcom, false);
19304 else
19305 str = entry->config;
19306 }
19307 return str;
19308}
19309
d62a17ae 19310static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 19311{
d62a17ae 19312 struct community_entry *entry;
718e3744 19313
d62a17ae 19314 for (entry = list->head; entry; entry = entry->next) {
19315 if (entry == list->head) {
19316 if (all_digit(list->name))
19317 vty_out(vty, "Community %s list %s\n",
19318 entry->style == COMMUNITY_LIST_STANDARD
19319 ? "standard"
19320 : "(expanded) access",
19321 list->name);
19322 else
19323 vty_out(vty, "Named Community %s list %s\n",
19324 entry->style == COMMUNITY_LIST_STANDARD
19325 ? "standard"
19326 : "expanded",
19327 list->name);
19328 }
19329 if (entry->any)
19330 vty_out(vty, " %s\n",
19331 community_direct_str(entry->direct));
19332 else
19333 vty_out(vty, " %s %s\n",
19334 community_direct_str(entry->direct),
8d9b8ed9 19335 community_list_config_str(entry));
d62a17ae 19336 }
718e3744 19337}
19338
7336e101
SP
19339DEFUN (show_community_list,
19340 show_bgp_community_list_cmd,
19341 "show bgp community-list",
718e3744 19342 SHOW_STR
7336e101 19343 BGP_STR
718e3744 19344 "List community-list\n")
19345{
d62a17ae 19346 struct community_list *list;
19347 struct community_list_master *cm;
718e3744 19348
d62a17ae 19349 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19350 if (!cm)
19351 return CMD_SUCCESS;
718e3744 19352
d62a17ae 19353 for (list = cm->num.head; list; list = list->next)
19354 community_list_show(vty, list);
718e3744 19355
d62a17ae 19356 for (list = cm->str.head; list; list = list->next)
19357 community_list_show(vty, list);
718e3744 19358
d62a17ae 19359 return CMD_SUCCESS;
718e3744 19360}
19361
7336e101
SP
19362DEFUN (show_community_list_arg,
19363 show_bgp_community_list_arg_cmd,
a2099c1d 19364 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
7336e101
SP
19365 SHOW_STR
19366 BGP_STR
718e3744 19367 "List community-list\n"
19368 "Community-list number\n"
960b69b9 19369 "Community-list name\n"
19370 "Detailed information on community-list\n")
718e3744 19371{
d62a17ae 19372 int idx_comm_list = 3;
19373 struct community_list *list;
718e3744 19374
e237b0d2 19375 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19376 COMMUNITY_LIST_MASTER);
19377 if (!list) {
19378 vty_out(vty, "%% Can't find community-list\n");
19379 return CMD_WARNING;
19380 }
718e3744 19381
d62a17ae 19382 community_list_show(vty, list);
718e3744 19383
d62a17ae 19384 return CMD_SUCCESS;
718e3744 19385}
6b0655a2 19386
57d187bc
JS
19387/*
19388 * Large Community code.
19389 */
d62a17ae 19390static int lcommunity_list_set_vty(struct vty *vty, int argc,
19391 struct cmd_token **argv, int style,
19392 int reject_all_digit_name)
19393{
19394 int ret;
19395 int direct;
19396 char *str;
19397 int idx = 0;
19398 char *cl_name;
2f8cc0e5
DA
19399 char *seq = NULL;
19400
a08032fe 19401 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19402 seq = argv[idx]->arg;
d62a17ae 19403
2f8cc0e5 19404 idx = 0;
d62a17ae 19405 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19406 : COMMUNITY_DENY;
19407
19408 /* All digit name check. */
19409 idx = 0;
a2099c1d 19410 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19411 argv_find(argv, argc, "(1-99)", &idx);
19412 argv_find(argv, argc, "(100-500)", &idx);
19413 cl_name = argv[idx]->arg;
19414 if (reject_all_digit_name && all_digit(cl_name)) {
19415 vty_out(vty, "%% Community name cannot have all digits\n");
19416 return CMD_WARNING_CONFIG_FAILED;
19417 }
19418
19419 idx = 0;
19420 argv_find(argv, argc, "AA:BB:CC", &idx);
19421 argv_find(argv, argc, "LINE", &idx);
19422 /* Concat community string argument. */
19423 if (idx)
19424 str = argv_concat(argv, argc, idx);
19425 else
19426 str = NULL;
19427
2f8cc0e5 19428 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 19429
19430 /* Free temporary community list string allocated by
19431 argv_concat(). */
0a22ddfb 19432 XFREE(MTYPE_TMP, str);
d62a17ae 19433
19434 if (ret < 0) {
19435 community_list_perror(vty, ret);
19436 return CMD_WARNING_CONFIG_FAILED;
19437 }
19438 return CMD_SUCCESS;
19439}
19440
19441static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19442 struct cmd_token **argv, int style)
19443{
19444 int ret;
19445 int direct = 0;
19446 char *str = NULL;
19447 int idx = 0;
2f8cc0e5 19448 char *seq = NULL;
d62a17ae 19449
a08032fe 19450 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19451 seq = argv[idx]->arg;
d62a17ae 19452
2f8cc0e5 19453 idx = 0;
d62a17ae 19454 argv_find(argv, argc, "permit", &idx);
19455 argv_find(argv, argc, "deny", &idx);
19456
19457 if (idx) {
19458 /* Check the list direct. */
19459 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19460 direct = COMMUNITY_PERMIT;
19461 else
19462 direct = COMMUNITY_DENY;
19463
19464 idx = 0;
19465 argv_find(argv, argc, "LINE", &idx);
19466 argv_find(argv, argc, "AA:AA:NN", &idx);
19467 /* Concat community string argument. */
19468 str = argv_concat(argv, argc, idx);
19469 }
19470
19471 idx = 0;
19472 argv_find(argv, argc, "(1-99)", &idx);
19473 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19474 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19475
19476 /* Unset community list. */
2f8cc0e5 19477 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 19478 style);
19479
19480 /* Free temporary community list string allocated by
19481 argv_concat(). */
0a22ddfb 19482 XFREE(MTYPE_TMP, str);
d62a17ae 19483
19484 if (ret < 0) {
19485 community_list_perror(vty, ret);
19486 return CMD_WARNING_CONFIG_FAILED;
19487 }
19488
19489 return CMD_SUCCESS;
57d187bc
JS
19490}
19491
19492/* "large-community-list" keyword help string. */
19493#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19494#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19495
7336e101
SP
19496DEFUN (lcommunity_list_standard,
19497 bgp_lcommunity_list_standard_cmd,
a08032fe 19498 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19499 BGP_STR
19500 LCOMMUNITY_LIST_STR
19501 "Large Community list number (standard)\n"
2f8cc0e5
DA
19502 "Sequence number of an entry\n"
19503 "Sequence number\n"
7336e101
SP
19504 "Specify large community to reject\n"
19505 "Specify large community to accept\n"
19506 LCOMMUNITY_VAL_STR)
52951b63 19507{
d62a17ae 19508 return lcommunity_list_set_vty(vty, argc, argv,
19509 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
19510}
19511
7336e101
SP
19512DEFUN (lcommunity_list_expanded,
19513 bgp_lcommunity_list_expanded_cmd,
a08032fe 19514 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19515 BGP_STR
19516 LCOMMUNITY_LIST_STR
19517 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19518 "Sequence number of an entry\n"
19519 "Sequence number\n"
7336e101
SP
19520 "Specify large community to reject\n"
19521 "Specify large community to accept\n"
19522 "An ordered list as a regular-expression\n")
57d187bc 19523{
d62a17ae 19524 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19525 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
19526}
19527
7336e101
SP
19528DEFUN (lcommunity_list_name_standard,
19529 bgp_lcommunity_list_name_standard_cmd,
a2099c1d 19530 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19531 BGP_STR
19532 LCOMMUNITY_LIST_STR
19533 "Specify standard large-community-list\n"
19534 "Large Community list name\n"
2f8cc0e5
DA
19535 "Sequence number of an entry\n"
19536 "Sequence number\n"
7336e101
SP
19537 "Specify large community to reject\n"
19538 "Specify large community to accept\n"
19539 LCOMMUNITY_VAL_STR)
52951b63 19540{
d62a17ae 19541 return lcommunity_list_set_vty(vty, argc, argv,
19542 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
19543}
19544
7336e101
SP
19545DEFUN (lcommunity_list_name_expanded,
19546 bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 19547 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19548 BGP_STR
19549 LCOMMUNITY_LIST_STR
19550 "Specify expanded large-community-list\n"
19551 "Large Community list name\n"
2f8cc0e5
DA
19552 "Sequence number of an entry\n"
19553 "Sequence number\n"
7336e101
SP
19554 "Specify large community to reject\n"
19555 "Specify large community to accept\n"
19556 "An ordered list as a regular-expression\n")
57d187bc 19557{
d62a17ae 19558 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19559 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
19560}
19561
4378f57c
DA
19562DEFUN (no_lcommunity_list_all,
19563 no_bgp_lcommunity_list_all_cmd,
a2099c1d 19564 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
7336e101
SP
19565 NO_STR
19566 BGP_STR
19567 LCOMMUNITY_LIST_STR
19568 "Large Community list number (standard)\n"
19569 "Large Community list number (expanded)\n"
19570 "Large Community list name\n")
57d187bc 19571{
7336e101
SP
19572 return lcommunity_list_unset_vty(vty, argc, argv,
19573 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19574}
19575
4378f57c
DA
19576DEFUN (no_lcommunity_list_name_standard_all,
19577 no_bgp_lcommunity_list_name_standard_all_cmd,
a2099c1d 19578 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
4378f57c
DA
19579 NO_STR
19580 BGP_STR
19581 LCOMMUNITY_LIST_STR
19582 "Specify standard large-community-list\n"
19583 "Large Community list name\n")
19584{
19585 return lcommunity_list_unset_vty(vty, argc, argv,
19586 LARGE_COMMUNITY_LIST_STANDARD);
19587}
19588
7336e101
SP
19589DEFUN (no_lcommunity_list_name_expanded_all,
19590 no_bgp_lcommunity_list_name_expanded_all_cmd,
a2099c1d 19591 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
7336e101
SP
19592 NO_STR
19593 BGP_STR
19594 LCOMMUNITY_LIST_STR
19595 "Specify expanded large-community-list\n"
19596 "Large Community list name\n")
57d187bc 19597{
d62a17ae 19598 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19599 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19600}
19601
7336e101
SP
19602DEFUN (no_lcommunity_list_standard,
19603 no_bgp_lcommunity_list_standard_cmd,
a08032fe 19604 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19605 NO_STR
19606 BGP_STR
19607 LCOMMUNITY_LIST_STR
19608 "Large Community list number (standard)\n"
2f8cc0e5
DA
19609 "Sequence number of an entry\n"
19610 "Sequence number\n"
7336e101
SP
19611 "Specify large community to reject\n"
19612 "Specify large community to accept\n"
19613 LCOMMUNITY_VAL_STR)
57d187bc 19614{
d62a17ae 19615 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19616 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19617}
19618
7336e101
SP
19619DEFUN (no_lcommunity_list_expanded,
19620 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 19621 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19622 NO_STR
19623 BGP_STR
19624 LCOMMUNITY_LIST_STR
19625 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19626 "Sequence number of an entry\n"
19627 "Sequence number\n"
7336e101
SP
19628 "Specify large community to reject\n"
19629 "Specify large community to accept\n"
19630 "An ordered list as a regular-expression\n")
57d187bc 19631{
d62a17ae 19632 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19633 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19634}
19635
7336e101
SP
19636DEFUN (no_lcommunity_list_name_standard,
19637 no_bgp_lcommunity_list_name_standard_cmd,
a2099c1d 19638 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19639 NO_STR
19640 BGP_STR
19641 LCOMMUNITY_LIST_STR
19642 "Specify standard large-community-list\n"
19643 "Large Community list name\n"
2f8cc0e5
DA
19644 "Sequence number of an entry\n"
19645 "Sequence number\n"
7336e101
SP
19646 "Specify large community to reject\n"
19647 "Specify large community to accept\n"
19648 LCOMMUNITY_VAL_STR)
57d187bc 19649{
d62a17ae 19650 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19651 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19652}
19653
7336e101
SP
19654DEFUN (no_lcommunity_list_name_expanded,
19655 no_bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 19656 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19657 NO_STR
19658 BGP_STR
19659 LCOMMUNITY_LIST_STR
19660 "Specify expanded large-community-list\n"
19661 "Large community list name\n"
2f8cc0e5
DA
19662 "Sequence number of an entry\n"
19663 "Sequence number\n"
7336e101
SP
19664 "Specify large community to reject\n"
19665 "Specify large community to accept\n"
19666 "An ordered list as a regular-expression\n")
57d187bc 19667{
d62a17ae 19668 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19669 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19670}
19671
d62a17ae 19672static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19673{
19674 struct community_entry *entry;
19675
19676 for (entry = list->head; entry; entry = entry->next) {
19677 if (entry == list->head) {
19678 if (all_digit(list->name))
19679 vty_out(vty, "Large community %s list %s\n",
169b72c8 19680 entry->style ==
19681 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19682 ? "standard"
19683 : "(expanded) access",
19684 list->name);
19685 else
19686 vty_out(vty,
19687 "Named large community %s list %s\n",
169b72c8 19688 entry->style ==
19689 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19690 ? "standard"
19691 : "expanded",
19692 list->name);
19693 }
19694 if (entry->any)
19695 vty_out(vty, " %s\n",
19696 community_direct_str(entry->direct));
19697 else
19698 vty_out(vty, " %s %s\n",
19699 community_direct_str(entry->direct),
8d9b8ed9 19700 community_list_config_str(entry));
d62a17ae 19701 }
57d187bc
JS
19702}
19703
7336e101
SP
19704DEFUN (show_lcommunity_list,
19705 show_bgp_lcommunity_list_cmd,
19706 "show bgp large-community-list",
57d187bc 19707 SHOW_STR
7336e101 19708 BGP_STR
57d187bc
JS
19709 "List large-community list\n")
19710{
d62a17ae 19711 struct community_list *list;
19712 struct community_list_master *cm;
57d187bc 19713
d62a17ae 19714 cm = community_list_master_lookup(bgp_clist,
19715 LARGE_COMMUNITY_LIST_MASTER);
19716 if (!cm)
19717 return CMD_SUCCESS;
57d187bc 19718
d62a17ae 19719 for (list = cm->num.head; list; list = list->next)
19720 lcommunity_list_show(vty, list);
57d187bc 19721
d62a17ae 19722 for (list = cm->str.head; list; list = list->next)
19723 lcommunity_list_show(vty, list);
57d187bc 19724
d62a17ae 19725 return CMD_SUCCESS;
57d187bc
JS
19726}
19727
7336e101
SP
19728DEFUN (show_lcommunity_list_arg,
19729 show_bgp_lcommunity_list_arg_cmd,
a2099c1d 19730 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
7336e101
SP
19731 SHOW_STR
19732 BGP_STR
57d187bc 19733 "List large-community list\n"
960b69b9 19734 "Large-community-list number\n"
19735 "Large-community-list name\n"
19736 "Detailed information on large-community-list\n")
57d187bc 19737{
d62a17ae 19738 struct community_list *list;
57d187bc 19739
e237b0d2 19740 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 19741 LARGE_COMMUNITY_LIST_MASTER);
19742 if (!list) {
960b69b9 19743 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 19744 return CMD_WARNING;
19745 }
57d187bc 19746
d62a17ae 19747 lcommunity_list_show(vty, list);
57d187bc 19748
d62a17ae 19749 return CMD_SUCCESS;
57d187bc
JS
19750}
19751
718e3744 19752/* "extcommunity-list" keyword help string. */
19753#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19754#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19755
7336e101
SP
19756DEFUN (extcommunity_list_standard,
19757 bgp_extcommunity_list_standard_cmd,
a2099c1d 19758 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19759 BGP_STR
718e3744 19760 EXTCOMMUNITY_LIST_STR
19761 "Extended Community list number (standard)\n"
718e3744 19762 "Specify standard extcommunity-list\n"
5bf15956 19763 "Community list name\n"
2f8cc0e5
DA
19764 "Sequence number of an entry\n"
19765 "Sequence number\n"
718e3744 19766 "Specify community to reject\n"
19767 "Specify community to accept\n"
19768 EXTCOMMUNITY_VAL_STR)
19769{
d62a17ae 19770 int style = EXTCOMMUNITY_LIST_STANDARD;
19771 int direct = 0;
19772 char *cl_number_or_name = NULL;
2f8cc0e5 19773 char *seq = NULL;
42f914d4 19774
d62a17ae 19775 int idx = 0;
7b9a4750 19776
d62a17ae 19777 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19778 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19779 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19780
a08032fe 19781 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19782 seq = argv[idx]->arg;
19783
d62a17ae 19784 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19785 : COMMUNITY_DENY;
19786 argv_find(argv, argc, "AA:NN", &idx);
19787 char *str = argv_concat(argv, argc, idx);
42f914d4 19788
2f8cc0e5 19789 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19790 direct, style);
42f914d4 19791
d62a17ae 19792 XFREE(MTYPE_TMP, str);
42f914d4 19793
d62a17ae 19794 if (ret < 0) {
19795 community_list_perror(vty, ret);
19796 return CMD_WARNING_CONFIG_FAILED;
19797 }
42f914d4 19798
d62a17ae 19799 return CMD_SUCCESS;
718e3744 19800}
19801
7336e101
SP
19802DEFUN (extcommunity_list_name_expanded,
19803 bgp_extcommunity_list_name_expanded_cmd,
a2099c1d 19804 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19805 BGP_STR
19806 EXTCOMMUNITY_LIST_STR
5bf15956 19807 "Extended Community list number (expanded)\n"
718e3744 19808 "Specify expanded extcommunity-list\n"
19809 "Extended Community list name\n"
2f8cc0e5
DA
19810 "Sequence number of an entry\n"
19811 "Sequence number\n"
718e3744 19812 "Specify community to reject\n"
19813 "Specify community to accept\n"
19814 "An ordered list as a regular-expression\n")
19815{
d62a17ae 19816 int style = EXTCOMMUNITY_LIST_EXPANDED;
19817 int direct = 0;
19818 char *cl_number_or_name = NULL;
2f8cc0e5 19819 char *seq = NULL;
d62a17ae 19820 int idx = 0;
7336e101 19821
d62a17ae 19822 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19823 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19824 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19825
a08032fe 19826 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19827 seq = argv[idx]->arg;
19828
d62a17ae 19829 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19830 : COMMUNITY_DENY;
19831 argv_find(argv, argc, "LINE", &idx);
19832 char *str = argv_concat(argv, argc, idx);
42f914d4 19833
2f8cc0e5 19834 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19835 direct, style);
42f914d4 19836
d62a17ae 19837 XFREE(MTYPE_TMP, str);
42f914d4 19838
d62a17ae 19839 if (ret < 0) {
19840 community_list_perror(vty, ret);
19841 return CMD_WARNING_CONFIG_FAILED;
19842 }
42f914d4 19843
d62a17ae 19844 return CMD_SUCCESS;
718e3744 19845}
19846
7336e101
SP
19847DEFUN (no_extcommunity_list_standard_all,
19848 no_bgp_extcommunity_list_standard_all_cmd,
a2099c1d 19849 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19850 NO_STR
19851 BGP_STR
19852 EXTCOMMUNITY_LIST_STR
813d4307 19853 "Extended Community list number (standard)\n"
718e3744 19854 "Specify standard extcommunity-list\n"
5bf15956 19855 "Community list name\n"
2f8cc0e5
DA
19856 "Sequence number of an entry\n"
19857 "Sequence number\n"
718e3744 19858 "Specify community to reject\n"
19859 "Specify community to accept\n"
19860 EXTCOMMUNITY_VAL_STR)
19861{
d62a17ae 19862 int style = EXTCOMMUNITY_LIST_STANDARD;
19863 int direct = 0;
19864 char *cl_number_or_name = NULL;
d4455c89 19865 char *str = NULL;
2f8cc0e5 19866 char *seq = NULL;
d62a17ae 19867 int idx = 0;
d4455c89 19868
a08032fe 19869 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19870 seq = argv[idx]->arg;
19871
19872 idx = 0;
d4455c89
DA
19873 argv_find(argv, argc, "permit", &idx);
19874 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
19875 if (idx) {
19876 direct = argv_find(argv, argc, "permit", &idx)
19877 ? COMMUNITY_PERMIT
19878 : COMMUNITY_DENY;
19879
19880 idx = 0;
19881 argv_find(argv, argc, "AA:NN", &idx);
19882 str = argv_concat(argv, argc, idx);
19883 }
19884
19885 idx = 0;
d62a17ae 19886 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19887 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19888 cl_number_or_name = argv[idx]->arg;
42f914d4 19889
d62a17ae 19890 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19891 seq, direct, style);
42f914d4 19892
d62a17ae 19893 XFREE(MTYPE_TMP, str);
42f914d4 19894
d62a17ae 19895 if (ret < 0) {
19896 community_list_perror(vty, ret);
19897 return CMD_WARNING_CONFIG_FAILED;
19898 }
42f914d4 19899
d62a17ae 19900 return CMD_SUCCESS;
718e3744 19901}
19902
d4455c89
DA
19903ALIAS(no_extcommunity_list_standard_all,
19904 no_bgp_extcommunity_list_standard_all_list_cmd,
a2099c1d 19905 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
36d4bb44 19906 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19907 "Extended Community list number (standard)\n"
19908 "Specify standard extcommunity-list\n"
19909 "Community list name\n")
19910
7336e101
SP
19911DEFUN (no_extcommunity_list_expanded_all,
19912 no_bgp_extcommunity_list_expanded_all_cmd,
a2099c1d 19913 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19914 NO_STR
19915 BGP_STR
19916 EXTCOMMUNITY_LIST_STR
718e3744 19917 "Extended Community list number (expanded)\n"
718e3744 19918 "Specify expanded extcommunity-list\n"
5bf15956 19919 "Extended Community list name\n"
2f8cc0e5
DA
19920 "Sequence number of an entry\n"
19921 "Sequence number\n"
718e3744 19922 "Specify community to reject\n"
19923 "Specify community to accept\n"
19924 "An ordered list as a regular-expression\n")
19925{
d62a17ae 19926 int style = EXTCOMMUNITY_LIST_EXPANDED;
19927 int direct = 0;
19928 char *cl_number_or_name = NULL;
d4455c89 19929 char *str = NULL;
2f8cc0e5 19930 char *seq = NULL;
d62a17ae 19931 int idx = 0;
d4455c89 19932
a08032fe 19933 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19934 seq = argv[idx]->arg;
19935
19936 idx = 0;
d4455c89
DA
19937 argv_find(argv, argc, "permit", &idx);
19938 argv_find(argv, argc, "deny", &idx);
19939
19940 if (idx) {
19941 direct = argv_find(argv, argc, "permit", &idx)
19942 ? COMMUNITY_PERMIT
19943 : COMMUNITY_DENY;
19944
19945 idx = 0;
19946 argv_find(argv, argc, "LINE", &idx);
19947 str = argv_concat(argv, argc, idx);
19948 }
19949
19950 idx = 0;
d62a17ae 19951 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19952 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19953 cl_number_or_name = argv[idx]->arg;
42f914d4 19954
d62a17ae 19955 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19956 seq, direct, style);
42f914d4 19957
d62a17ae 19958 XFREE(MTYPE_TMP, str);
42f914d4 19959
d62a17ae 19960 if (ret < 0) {
19961 community_list_perror(vty, ret);
19962 return CMD_WARNING_CONFIG_FAILED;
19963 }
42f914d4 19964
d62a17ae 19965 return CMD_SUCCESS;
718e3744 19966}
19967
d4455c89
DA
19968ALIAS(no_extcommunity_list_expanded_all,
19969 no_bgp_extcommunity_list_expanded_all_list_cmd,
a2099c1d 19970 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
36d4bb44 19971 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19972 "Extended Community list number (expanded)\n"
19973 "Specify expanded extcommunity-list\n"
19974 "Extended Community list name\n")
19975
d62a17ae 19976static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 19977{
d62a17ae 19978 struct community_entry *entry;
718e3744 19979
d62a17ae 19980 for (entry = list->head; entry; entry = entry->next) {
19981 if (entry == list->head) {
19982 if (all_digit(list->name))
19983 vty_out(vty, "Extended community %s list %s\n",
19984 entry->style == EXTCOMMUNITY_LIST_STANDARD
19985 ? "standard"
19986 : "(expanded) access",
19987 list->name);
19988 else
19989 vty_out(vty,
19990 "Named extended community %s list %s\n",
19991 entry->style == EXTCOMMUNITY_LIST_STANDARD
19992 ? "standard"
19993 : "expanded",
19994 list->name);
19995 }
19996 if (entry->any)
19997 vty_out(vty, " %s\n",
19998 community_direct_str(entry->direct));
19999 else
20000 vty_out(vty, " %s %s\n",
20001 community_direct_str(entry->direct),
8d9b8ed9 20002 community_list_config_str(entry));
d62a17ae 20003 }
718e3744 20004}
20005
7336e101
SP
20006DEFUN (show_extcommunity_list,
20007 show_bgp_extcommunity_list_cmd,
20008 "show bgp extcommunity-list",
718e3744 20009 SHOW_STR
7336e101 20010 BGP_STR
718e3744 20011 "List extended-community list\n")
20012{
d62a17ae 20013 struct community_list *list;
20014 struct community_list_master *cm;
718e3744 20015
d62a17ae 20016 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20017 if (!cm)
20018 return CMD_SUCCESS;
718e3744 20019
d62a17ae 20020 for (list = cm->num.head; list; list = list->next)
20021 extcommunity_list_show(vty, list);
718e3744 20022
d62a17ae 20023 for (list = cm->str.head; list; list = list->next)
20024 extcommunity_list_show(vty, list);
718e3744 20025
d62a17ae 20026 return CMD_SUCCESS;
718e3744 20027}
20028
7336e101
SP
20029DEFUN (show_extcommunity_list_arg,
20030 show_bgp_extcommunity_list_arg_cmd,
a2099c1d 20031 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
7336e101
SP
20032 SHOW_STR
20033 BGP_STR
718e3744 20034 "List extended-community list\n"
20035 "Extcommunity-list number\n"
960b69b9 20036 "Extcommunity-list name\n"
20037 "Detailed information on extcommunity-list\n")
718e3744 20038{
d62a17ae 20039 int idx_comm_list = 3;
20040 struct community_list *list;
718e3744 20041
e237b0d2 20042 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20043 EXTCOMMUNITY_LIST_MASTER);
20044 if (!list) {
20045 vty_out(vty, "%% Can't find extcommunity-list\n");
20046 return CMD_WARNING;
20047 }
718e3744 20048
d62a17ae 20049 extcommunity_list_show(vty, list);
718e3744 20050
d62a17ae 20051 return CMD_SUCCESS;
718e3744 20052}
6b0655a2 20053
718e3744 20054/* Display community-list and extcommunity-list configuration. */
d62a17ae 20055static int community_list_config_write(struct vty *vty)
20056{
20057 struct community_list *list;
20058 struct community_entry *entry;
20059 struct community_list_master *cm;
20060 int write = 0;
20061
20062 /* Community-list. */
20063 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20064
20065 for (list = cm->num.head; list; list = list->next)
20066 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20067 vty_out(vty,
20068 "bgp community-list %s seq %" PRId64 " %s %s\n",
20069 list->name, entry->seq,
d62a17ae 20070 community_direct_str(entry->direct),
20071 community_list_config_str(entry));
20072 write++;
20073 }
20074 for (list = cm->str.head; list; list = list->next)
20075 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20076 vty_out(vty,
20077 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 20078 entry->style == COMMUNITY_LIST_STANDARD
20079 ? "standard"
20080 : "expanded",
2f8cc0e5
DA
20081 list->name, entry->seq,
20082 community_direct_str(entry->direct),
d62a17ae 20083 community_list_config_str(entry));
20084 write++;
20085 }
20086
20087 /* Extcommunity-list. */
20088 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20089
20090 for (list = cm->num.head; list; list = list->next)
20091 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20092 vty_out(vty,
20093 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20094 list->name, entry->seq,
20095 community_direct_str(entry->direct),
d62a17ae 20096 community_list_config_str(entry));
20097 write++;
20098 }
20099 for (list = cm->str.head; list; list = list->next)
20100 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20101 vty_out(vty,
6cde4b45 20102 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 20103 entry->style == EXTCOMMUNITY_LIST_STANDARD
20104 ? "standard"
20105 : "expanded",
2f8cc0e5
DA
20106 list->name, entry->seq,
20107 community_direct_str(entry->direct),
d62a17ae 20108 community_list_config_str(entry));
20109 write++;
20110 }
20111
20112
20113 /* lcommunity-list. */
20114 cm = community_list_master_lookup(bgp_clist,
20115 LARGE_COMMUNITY_LIST_MASTER);
20116
20117 for (list = cm->num.head; list; list = list->next)
20118 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20119 vty_out(vty,
6cde4b45 20120 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
20121 list->name, entry->seq,
20122 community_direct_str(entry->direct),
d62a17ae 20123 community_list_config_str(entry));
20124 write++;
20125 }
20126 for (list = cm->str.head; list; list = list->next)
20127 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20128 vty_out(vty,
6cde4b45 20129 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 20130
d62a17ae 20131 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20132 ? "standard"
20133 : "expanded",
2f8cc0e5 20134 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 20135 community_list_config_str(entry));
20136 write++;
20137 }
20138
20139 return write;
20140}
20141
612c2c15 20142static int community_list_config_write(struct vty *vty);
d62a17ae 20143static struct cmd_node community_list_node = {
f4b8291f 20144 .name = "community list",
62b346ee
DL
20145 .node = COMMUNITY_LIST_NODE,
20146 .prompt = "",
612c2c15 20147 .config_write = community_list_config_write,
718e3744 20148};
20149
d62a17ae 20150static void community_list_vty(void)
20151{
612c2c15 20152 install_node(&community_list_node);
d62a17ae 20153
20154 /* Community-list. */
7336e101
SP
20155 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20156 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20157 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 20158 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 20159 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 20160 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
20161 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20162 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 20163
20164 /* Extcommunity-list. */
7336e101
SP
20165 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20166 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20167 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
20168 install_element(CONFIG_NODE,
20169 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 20170 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
20171 install_element(CONFIG_NODE,
20172 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
20173 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20174 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 20175
20176 /* Large Community List */
7336e101 20177 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
20178 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20179 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 20180 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
20181 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20182 install_element(CONFIG_NODE,
20183 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
20184 install_element(CONFIG_NODE,
20185 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20186 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20187 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20188 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20189 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20190 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20191 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
225096bc
DA
20192
20193 bgp_community_list_command_completion_setup();
5bf15956 20194}
ed0e57e3
DA
20195
20196static struct cmd_node community_alias_node = {
20197 .name = "community alias",
20198 .node = COMMUNITY_ALIAS_NODE,
20199 .prompt = "",
20200 .config_write = bgp_community_alias_write,
20201};
20202
20203void community_alias_vty(void)
20204{
20205 install_node(&community_alias_node);
20206
20207 /* Community-list. */
20208 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
b4ad2fae
DS
20209
20210 bgp_community_alias_command_completion_setup();
ed0e57e3 20211}