]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: Fixing dead code
[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
DA
689 if (su->sa.sa_family == AF_INET) {
690 str2sockunion("0.0.0.0", &all_su);
d62a17ae 691 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
4122b697
DA
692 } else if (su->sa.sa_family == AF_INET6) {
693 str2sockunion("::", &all_su);
d62a17ae 694 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
695 su->sin6.sin6_scope_id,
696 bgp->vrf_id);
4122b697 697 }
d62a17ae 698
4122b697
DA
699 if (ifp) {
700 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
701 if (sockunion_family(su) !=
702 sockunion_family(&listener->su))
703 continue;
704
705 /* If 0.0.0.0/:: is a listener, then treat as self and
706 * reject.
707 */
708 if (!sockunion_cmp(&listener->su, su) ||
709 !sockunion_cmp(&listener->su, &all_su))
710 return true;
711 }
712 }
d62a17ae 713
3dc339cd 714 return false;
718e3744 715}
716
28c6e247
IR
717/* Utility function for looking up peer from VTY. */
718/* This is used only for configuration, so disallow if attempted on
719 * a dynamic neighbor.
720 */
721static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
722{
723 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
724 int ret;
725 union sockunion su;
726 struct peer *peer;
727
728 if (!bgp) {
729 return NULL;
730 }
731
732 ret = str2sockunion(ip_str, &su);
733 if (ret < 0) {
734 peer = peer_lookup_by_conf_if(bgp, ip_str);
735 if (!peer) {
736 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
737 == NULL) {
738 vty_out(vty,
739 "%% Malformed address or name: %s\n",
740 ip_str);
741 return NULL;
742 }
743 }
744 } else {
745 peer = peer_lookup(bgp, &su);
746 if (!peer) {
747 vty_out(vty,
748 "%% Specify remote-as or peer-group commands first\n");
749 return NULL;
750 }
751 if (peer_dynamic_neighbor(peer)) {
752 vty_out(vty,
753 "%% Operation not allowed on a dynamic neighbor\n");
754 return NULL;
755 }
756 }
757 return peer;
758}
759
718e3744 760/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
761/* This is used only for configuration, so disallow if attempted on
762 * a dynamic neighbor.
763 */
d62a17ae 764struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
765{
766 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
767 int ret;
768 union sockunion su;
769 struct peer *peer = NULL;
770 struct peer_group *group = NULL;
771
772 if (!bgp) {
773 return NULL;
774 }
775
776 ret = str2sockunion(peer_str, &su);
777 if (ret == 0) {
778 /* IP address, locate peer. */
779 peer = peer_lookup(bgp, &su);
780 } else {
781 /* Not IP, could match either peer configured on interface or a
782 * group. */
783 peer = peer_lookup_by_conf_if(bgp, peer_str);
784 if (!peer)
785 group = peer_group_lookup(bgp, peer_str);
786 }
787
788 if (peer) {
789 if (peer_dynamic_neighbor(peer)) {
790 vty_out(vty,
791 "%% Operation not allowed on a dynamic neighbor\n");
792 return NULL;
793 }
794
795 return peer;
796 }
797
798 if (group)
799 return group->conf;
800
801 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
802
803 return NULL;
804}
805
806int bgp_vty_return(struct vty *vty, int ret)
807{
808 const char *str = NULL;
809
810 switch (ret) {
811 case BGP_ERR_INVALID_VALUE:
812 str = "Invalid value";
813 break;
814 case BGP_ERR_INVALID_FLAG:
815 str = "Invalid flag";
816 break;
817 case BGP_ERR_PEER_GROUP_SHUTDOWN:
818 str = "Peer-group has been shutdown. Activate the peer-group first";
819 break;
820 case BGP_ERR_PEER_FLAG_CONFLICT:
821 str = "Can't set override-capability and strict-capability-match at the same time";
822 break;
823 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
824 str = "Specify remote-as or peer-group remote AS first";
825 break;
826 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
827 str = "Cannot change the peer-group. Deconfigure first";
828 break;
829 case BGP_ERR_PEER_GROUP_MISMATCH:
830 str = "Peer is not a member of this peer-group";
831 break;
832 case BGP_ERR_PEER_FILTER_CONFLICT:
833 str = "Prefix/distribute list can not co-exist";
834 break;
835 case BGP_ERR_NOT_INTERNAL_PEER:
836 str = "Invalid command. Not an internal neighbor";
837 break;
838 case BGP_ERR_REMOVE_PRIVATE_AS:
839 str = "remove-private-AS cannot be configured for IBGP peers";
840 break;
841 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
842 str = "Local-AS allowed only for EBGP peers";
843 break;
844 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
845 str = "Cannot have local-as same as BGP AS number";
846 break;
847 case BGP_ERR_TCPSIG_FAILED:
848 str = "Error while applying TCP-Sig to session(s)";
849 break;
850 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
851 str = "ebgp-multihop and ttl-security cannot be configured together";
852 break;
853 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
854 str = "ttl-security only allowed for EBGP peers";
855 break;
856 case BGP_ERR_AS_OVERRIDE:
857 str = "as-override cannot be configured for IBGP peers";
858 break;
859 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
860 str = "Invalid limit for number of dynamic neighbors";
861 break;
862 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
863 str = "Dynamic neighbor listen range already exists";
864 break;
865 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
866 str = "Operation not allowed on a dynamic neighbor";
867 break;
868 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
869 str = "Operation not allowed on a directly connected neighbor";
870 break;
871 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 872 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
055679e9 873 break;
874 case BGP_ERR_GR_INVALID_CMD:
875 str = "The Graceful Restart command used is not valid at this moment.";
876 break;
877 case BGP_ERR_GR_OPERATION_FAILED:
878 str = "The Graceful Restart Operation failed due to an err.";
879 break;
d62a17ae 880 }
881 if (str) {
882 vty_out(vty, "%% %s\n", str);
883 return CMD_WARNING_CONFIG_FAILED;
884 }
885 return CMD_SUCCESS;
718e3744 886}
887
7aafcaca 888/* BGP clear sort. */
d62a17ae 889enum clear_sort {
890 clear_all,
891 clear_peer,
892 clear_group,
893 clear_external,
894 clear_as
7aafcaca
DS
895};
896
1ca2fd11
IR
897static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
898 safi_t safi, int error)
d62a17ae 899{
900 switch (error) {
901 case BGP_ERR_AF_UNCONFIGURED:
1ca2fd11
IR
902 vty_out(vty,
903 "%%BGP: Enable %s address family for the neighbor %s\n",
904 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 905 break;
906 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
1ca2fd11
IR
907 vty_out(vty,
908 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
d62a17ae 909 peer->host);
910 break;
911 default:
912 break;
913 }
7aafcaca
DS
914}
915
dc912615 916static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 917 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
918{
919 int ret = 0;
2adac256 920 struct peer_af *paf;
dc912615
DS
921
922 /* if afi/.safi not specified, spin thru all of them */
923 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
924 afi_t tmp_afi;
925 safi_t tmp_safi;
0e5cdd59
DS
926 enum bgp_af_index index;
927
928 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
929 paf = peer->peer_af_array[index];
930 if (!paf)
931 continue;
dc912615 932
2adac256
DA
933 if (paf && paf->subgroup)
934 SET_FLAG(paf->subgroup->sflags,
935 SUBGRP_STATUS_FORCE_UPDATES);
936
0e5cdd59
DS
937 tmp_afi = paf->afi;
938 tmp_safi = paf->safi;
dc912615
DS
939 if (!peer->afc[tmp_afi][tmp_safi])
940 continue;
941
942 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 943 ret = peer_clear(peer, nnode);
dc912615
DS
944 else
945 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
946 stype);
947 }
948 /* if afi specified and safi not, spin thru safis on this afi */
949 } else if (safi == SAFI_UNSPEC) {
950 safi_t tmp_safi;
951
952 for (tmp_safi = SAFI_UNICAST;
953 tmp_safi < SAFI_MAX; tmp_safi++) {
954 if (!peer->afc[afi][tmp_safi])
955 continue;
956
2adac256
DA
957 paf = peer_af_find(peer, afi, tmp_safi);
958 if (paf && paf->subgroup)
959 SET_FLAG(paf->subgroup->sflags,
960 SUBGRP_STATUS_FORCE_UPDATES);
961
dc912615 962 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 963 ret = peer_clear(peer, nnode);
dc912615
DS
964 else
965 ret = peer_clear_soft(peer, afi,
966 tmp_safi, stype);
967 }
968 /* both afi/safi specified, let the caller know if not defined */
969 } else {
970 if (!peer->afc[afi][safi])
971 return 1;
972
2adac256
DA
973 paf = peer_af_find(peer, afi, safi);
974 if (paf && paf->subgroup)
975 SET_FLAG(paf->subgroup->sflags,
976 SUBGRP_STATUS_FORCE_UPDATES);
977
dc912615 978 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 979 ret = peer_clear(peer, nnode);
dc912615
DS
980 else
981 ret = peer_clear_soft(peer, afi, safi, stype);
982 }
983
984 return ret;
985}
986
7aafcaca 987/* `clear ip bgp' functions. */
1ca2fd11 988static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 989 enum clear_sort sort, enum bgp_clear_type stype,
1ca2fd11 990 const char *arg)
d62a17ae 991{
dc912615 992 int ret = 0;
3ae8bfa5 993 bool found = false;
d62a17ae 994 struct peer *peer;
dc95985f 995
996 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 997
998 /* Clear all neighbors. */
999 /*
1000 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
1001 * nodes on the BGP instance as that may get freed if it is a
1002 * doppelganger
d62a17ae 1003 */
1004 if (sort == clear_all) {
1005 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 1006
1007 bgp_peer_gr_flags_update(peer);
1008
36235319 1009 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 1010 gr_router_detected = true;
1011
c368171c 1012 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 1013 stype);
d62a17ae 1014
1015 if (ret < 0)
1ca2fd11 1016 bgp_clear_vty_error(vty, peer, afi, safi, ret);
dc95985f 1017 }
1018
36235319
QY
1019 if (gr_router_detected
1020 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1021 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1022 } else if (!gr_router_detected
1023 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1024 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 1025 }
d62a17ae 1026
1027 /* This is to apply read-only mode on this clear. */
1028 if (stype == BGP_CLEAR_SOFT_NONE)
1029 bgp->update_delay_over = 0;
1030
1031 return CMD_SUCCESS;
7aafcaca
DS
1032 }
1033
3ae8bfa5 1034 /* Clear specified neighbor. */
d62a17ae 1035 if (sort == clear_peer) {
1036 union sockunion su;
d62a17ae 1037
1038 /* Make sockunion for lookup. */
1039 ret = str2sockunion(arg, &su);
1040 if (ret < 0) {
1041 peer = peer_lookup_by_conf_if(bgp, arg);
1042 if (!peer) {
1043 peer = peer_lookup_by_hostname(bgp, arg);
1044 if (!peer) {
1ca2fd11
IR
1045 vty_out(vty,
1046 "Malformed address or name: %s\n",
d62a17ae 1047 arg);
1048 return CMD_WARNING;
1049 }
1050 }
1051 } else {
1052 peer = peer_lookup(bgp, &su);
1053 if (!peer) {
1ca2fd11
IR
1054 vty_out(vty,
1055 "%%BGP: Unknown neighbor - \"%s\"\n",
1056 arg);
d62a17ae 1057 return CMD_WARNING;
1058 }
1059 }
7aafcaca 1060
dc95985f 1061 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1062 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1063
dc912615
DS
1064 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1065
1066 /* if afi/safi not defined for this peer, let caller know */
1067 if (ret == 1)
3ae8bfa5 1068 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1069
d62a17ae 1070 if (ret < 0)
1ca2fd11 1071 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 1072
d62a17ae 1073 return CMD_SUCCESS;
7aafcaca 1074 }
7aafcaca 1075
3ae8bfa5 1076 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1077 if (sort == clear_group) {
1078 struct peer_group *group;
7aafcaca 1079
d62a17ae 1080 group = peer_group_lookup(bgp, arg);
1081 if (!group) {
1ca2fd11 1082 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
d62a17ae 1083 return CMD_WARNING;
1084 }
1085
1086 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1087 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1088
d62a17ae 1089 if (ret < 0)
1ca2fd11 1090 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1091 else
1092 found = true;
d62a17ae 1093 }
3ae8bfa5
PM
1094
1095 if (!found)
1ca2fd11
IR
1096 vty_out(vty,
1097 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 1098 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1099
d62a17ae 1100 return CMD_SUCCESS;
7aafcaca 1101 }
7aafcaca 1102
3ae8bfa5 1103 /* Clear all external (eBGP) neighbors. */
d62a17ae 1104 if (sort == clear_external) {
1105 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1106 if (peer->sort == BGP_PEER_IBGP)
1107 continue;
7aafcaca 1108
dc95985f 1109 bgp_peer_gr_flags_update(peer);
1110
36235319 1111 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1112 gr_router_detected = true;
dc95985f 1113
c368171c 1114 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1115
d62a17ae 1116 if (ret < 0)
1ca2fd11 1117 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1118 else
1119 found = true;
d62a17ae 1120 }
3ae8bfa5 1121
36235319
QY
1122 if (gr_router_detected
1123 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1124 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1125 } else if (!gr_router_detected
1126 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1127 bgp_zebra_send_capabilities(bgp, true);
1128 }
1129
3ae8bfa5 1130 if (!found)
1ca2fd11
IR
1131 vty_out(vty,
1132 "%%BGP: No external %s peer is configured\n",
1133 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1134
d62a17ae 1135 return CMD_SUCCESS;
1136 }
1137
3ae8bfa5 1138 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1139 if (sort == clear_as) {
3ae8bfa5 1140 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1141
1142 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1143 if (peer->as != as)
1144 continue;
1145
dc95985f 1146 bgp_peer_gr_flags_update(peer);
1147
36235319 1148 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1149 gr_router_detected = true;
dc95985f 1150
c368171c 1151 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1152
1153 if (ret < 0)
1ca2fd11 1154 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1155 else
1156 found = true;
d62a17ae 1157 }
3ae8bfa5 1158
36235319
QY
1159 if (gr_router_detected
1160 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1161 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1162 } else if (!gr_router_detected
1163 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1164 bgp_zebra_send_capabilities(bgp, true);
1165 }
1166
3ae8bfa5 1167 if (!found)
1ca2fd11
IR
1168 vty_out(vty,
1169 "%%BGP: No %s peer is configured with AS %s\n",
1170 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1171
d62a17ae 1172 return CMD_SUCCESS;
1173 }
1174
1175 return CMD_SUCCESS;
1176}
1177
1ca2fd11
IR
1178static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1179 safi_t safi, enum clear_sort sort,
1180 enum bgp_clear_type stype, const char *arg)
d62a17ae 1181{
1182 struct bgp *bgp;
1183
1184 /* BGP structure lookup. */
1185 if (name) {
1186 bgp = bgp_lookup_by_name(name);
1187 if (bgp == NULL) {
1ca2fd11 1188 vty_out(vty, "Can't find BGP instance %s\n", name);
d62a17ae 1189 return CMD_WARNING;
1190 }
1191 } else {
1192 bgp = bgp_get_default();
1193 if (bgp == NULL) {
1ca2fd11 1194 vty_out(vty, "No BGP process is configured\n");
d62a17ae 1195 return CMD_WARNING;
1196 }
1197 }
1198
1ca2fd11 1199 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
1200}
1201
1202/* clear soft inbound */
1ca2fd11 1203static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 1204{
99b3ebd3
NS
1205 afi_t afi;
1206 safi_t safi;
1207
1ca2fd11
IR
1208 FOREACH_AFI_SAFI (afi, safi)
1209 bgp_clear_vty(vty, name, afi, safi, clear_all,
1210 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
1211}
1212
1213/* clear soft outbound */
1ca2fd11 1214static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 1215{
99b3ebd3
NS
1216 afi_t afi;
1217 safi_t safi;
1218
1ca2fd11
IR
1219 FOREACH_AFI_SAFI (afi, safi)
1220 bgp_clear_vty(vty, name, afi, safi, clear_all,
1221 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
1222}
1223
1224
f787d7a0 1225#ifndef VTYSH_EXTRACT_PL
2e4c2296 1226#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1227#endif
1228
8029b216
AK
1229DEFUN_HIDDEN (bgp_local_mac,
1230 bgp_local_mac_cmd,
093e3f23 1231 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1232 BGP_STR
1233 "Local MAC config\n"
1234 "VxLAN Network Identifier\n"
1235 "VNI number\n"
1236 "local mac\n"
1237 "mac address\n"
1238 "mac-mobility sequence\n"
1239 "seq number\n")
1240{
1241 int rv;
1242 vni_t vni;
1243 struct ethaddr mac;
1244 struct ipaddr ip;
1245 uint32_t seq;
1246 struct bgp *bgp;
1247
1248 vni = strtoul(argv[3]->arg, NULL, 10);
1249 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1250 vty_out(vty, "%% Malformed MAC address\n");
1251 return CMD_WARNING;
1252 }
1253 memset(&ip, 0, sizeof(ip));
1254 seq = strtoul(argv[7]->arg, NULL, 10);
1255
1256 bgp = bgp_get_default();
1257 if (!bgp) {
1258 vty_out(vty, "Default BGP instance is not there\n");
1259 return CMD_WARNING;
1260 }
1261
b5e140c8
AK
1262 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1263 zero_esi);
8029b216
AK
1264 if (rv < 0) {
1265 vty_out(vty, "Internal error\n");
1266 return CMD_WARNING;
1267 }
1268
1269 return CMD_SUCCESS;
1270}
1271
1272DEFUN_HIDDEN (no_bgp_local_mac,
1273 no_bgp_local_mac_cmd,
093e3f23 1274 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1275 NO_STR
1276 BGP_STR
1277 "Local MAC config\n"
1278 "VxLAN Network Identifier\n"
1279 "VNI number\n"
1280 "local mac\n"
1281 "mac address\n")
1282{
1283 int rv;
1284 vni_t vni;
1285 struct ethaddr mac;
1286 struct ipaddr ip;
1287 struct bgp *bgp;
1288
1289 vni = strtoul(argv[4]->arg, NULL, 10);
1290 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1291 vty_out(vty, "%% Malformed MAC address\n");
1292 return CMD_WARNING;
1293 }
1294 memset(&ip, 0, sizeof(ip));
1295
1296 bgp = bgp_get_default();
1297 if (!bgp) {
1298 vty_out(vty, "Default BGP instance is not there\n");
1299 return CMD_WARNING;
1300 }
1301
ec0ab544 1302 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1303 if (rv < 0) {
1304 vty_out(vty, "Internal error\n");
1305 return CMD_WARNING;
1306 }
1307
1308 return CMD_SUCCESS;
1309}
1310
718e3744 1311DEFUN (no_synchronization,
1312 no_synchronization_cmd,
1313 "no synchronization",
1314 NO_STR
1315 "Perform IGP synchronization\n")
1316{
d62a17ae 1317 return CMD_SUCCESS;
718e3744 1318}
1319
1320DEFUN (no_auto_summary,
1321 no_auto_summary_cmd,
1322 "no auto-summary",
1323 NO_STR
1324 "Enable automatic network number summarization\n")
1325{
d62a17ae 1326 return CMD_SUCCESS;
718e3744 1327}
3d515fd9 1328
718e3744 1329/* "router bgp" commands. */
1ca2fd11
IR
1330DEFUN_NOSH (router_bgp,
1331 router_bgp_cmd,
1332 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1333 ROUTER_STR
1334 BGP_STR
1335 AS_STR
1336 BGP_INSTANCE_HELP_STR)
718e3744 1337{
d62a17ae 1338 int idx_asn = 2;
1339 int idx_view_vrf = 3;
1340 int idx_vrf = 4;
1ca2fd11
IR
1341 int is_new_bgp = 0;
1342 int ret;
d62a17ae 1343 as_t as;
1344 struct bgp *bgp;
1345 const char *name = NULL;
1346 enum bgp_instance_type inst_type;
1347
1348 // "router bgp" without an ASN
1349 if (argc == 2) {
1350 // Pending: Make VRF option available for ASN less config
1abef40f 1351 bgp = bgp_get_default();
d62a17ae 1352
1abef40f 1353 if (bgp == NULL) {
d62a17ae 1354 vty_out(vty, "%% No BGP process is configured\n");
1355 return CMD_WARNING_CONFIG_FAILED;
1356 }
1357
1358 if (listcount(bm->bgp) > 1) {
996c9314 1359 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1360 return CMD_WARNING_CONFIG_FAILED;
1361 }
1362 }
1363
1364 // "router bgp X"
1365 else {
ff8a8a7a 1366 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1ca2fd11 1367
cc413e2a
DA
1368 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1369 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1370 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1371
d62a17ae 1372 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1373 if (argc > 3) {
1374 name = argv[idx_vrf]->arg;
1375
9a8bdf1c
PG
1376 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1377 if (strmatch(name, VRF_DEFAULT_NAME))
1378 name = NULL;
1379 else
1380 inst_type = BGP_INSTANCE_TYPE_VRF;
1ca2fd11 1381 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1382 inst_type = BGP_INSTANCE_TYPE_VIEW;
d62a17ae 1383 }
1384
1ca2fd11
IR
1385 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1386 is_new_bgp = (bgp_lookup(as, name) == NULL);
3bd70bf8 1387
1ca2fd11
IR
1388 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1389 switch (ret) {
1390 case BGP_ERR_AS_MISMATCH:
1391 vty_out(vty, "BGP is already running; AS is %u\n", as);
1392 return CMD_WARNING_CONFIG_FAILED;
1393 case BGP_ERR_INSTANCE_MISMATCH:
1394 vty_out(vty,
1395 "BGP instance name and AS number mismatch\n");
1396 vty_out(vty,
1397 "BGP instance is already running; AS is %u\n",
1398 as);
1399 return CMD_WARNING_CONFIG_FAILED;
ff8a8a7a 1400 }
1ca2fd11
IR
1401
1402 /*
1403 * If we just instantiated the default instance, complete
1404 * any pending VRF-VPN leaking that was configured via
1405 * earlier "router bgp X vrf FOO" blocks.
1406 */
1407 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1408 vpn_leak_postchange_all();
1409
1410 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1411 bgp_vpn_leak_export(bgp);
1412 /* Pending: handle when user tries to change a view to vrf n vv.
1413 */
d62a17ae 1414 }
1415
1ca2fd11
IR
1416 /* unset the auto created flag as the user config is now present */
1417 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1418 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1419
1420 return CMD_SUCCESS;
718e3744 1421}
1422
718e3744 1423/* "no router bgp" commands. */
1ca2fd11
IR
1424DEFUN (no_router_bgp,
1425 no_router_bgp_cmd,
1426 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1427 NO_STR
1428 ROUTER_STR
1429 BGP_STR
1430 AS_STR
1431 BGP_INSTANCE_HELP_STR)
718e3744 1432{
4fd9919e 1433 int idx_asn = 3;
d62a17ae 1434 int idx_vrf = 5;
1ca2fd11 1435 as_t as;
4fd9919e 1436 struct bgp *bgp;
d62a17ae 1437 const char *name = NULL;
718e3744 1438
d62a17ae 1439 // "no router bgp" without an ASN
1440 if (argc == 3) {
1441 // Pending: Make VRF option available for ASN less config
8382083a 1442 bgp = bgp_get_default();
718e3744 1443
8382083a 1444 if (bgp == NULL) {
d62a17ae 1445 vty_out(vty, "%% No BGP process is configured\n");
1446 return CMD_WARNING_CONFIG_FAILED;
1447 }
7fb21a9f 1448
d62a17ae 1449 if (listcount(bm->bgp) > 1) {
996c9314 1450 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1451 return CMD_WARNING_CONFIG_FAILED;
1452 }
4fd9919e 1453
4fd9919e
IR
1454 if (bgp->l3vni) {
1455 vty_out(vty, "%% Please unconfigure l3vni %u",
1456 bgp->l3vni);
1457 return CMD_WARNING_CONFIG_FAILED;
1458 }
d62a17ae 1459 } else {
4fd9919e
IR
1460 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1461
1ca42c8d 1462 if (argc > 4) {
d62a17ae 1463 name = argv[idx_vrf]->arg;
1ca42c8d
IR
1464 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1465 && strmatch(name, VRF_DEFAULT_NAME))
1466 name = NULL;
1467 }
7fb21a9f 1468
4fd9919e
IR
1469 /* Lookup bgp structure. */
1470 bgp = bgp_lookup(as, name);
1471 if (!bgp) {
1472 vty_out(vty, "%% Can't find BGP instance\n");
1473 return CMD_WARNING_CONFIG_FAILED;
1474 }
1475
1476 if (bgp->l3vni) {
1477 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1478 bgp->l3vni);
1479 return CMD_WARNING_CONFIG_FAILED;
1480 }
1481
1482 /* Cannot delete default instance if vrf instances exist */
1483 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1484 struct listnode *node;
1485 struct bgp *tmp_bgp;
1486
1487 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1488 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1489 continue;
1490 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1491 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1492 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1493 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1494 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1495 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1496 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1497 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1498 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1499 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1500 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1501 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1502 (bgp == bgp_get_evpn() &&
1503 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1504 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1505 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1506 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1507 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1508 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1509 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1510 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1511 (tmp_bgp->vnihash && hashcount(tmp_bgp->vnihash))) {
1512 vty_out(vty,
1513 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1514 return CMD_WARNING_CONFIG_FAILED;
1515 }
1516 }
1517 }
d62a17ae 1518 }
718e3744 1519
1ca2fd11 1520 bgp_delete(bgp);
718e3744 1521
1ca2fd11 1522 return CMD_SUCCESS;
718e3744 1523}
1524
718e3744 1525
ff8a8a7a
CS
1526/* BGP router-id. */
1527
1ca2fd11
IR
1528DEFPY (bgp_router_id,
1529 bgp_router_id_cmd,
1530 "bgp router-id A.B.C.D",
1531 BGP_STR
1532 "Override configured router identifier\n"
1533 "Manually configured router identifier\n")
718e3744 1534{
1ca2fd11
IR
1535 VTY_DECLVAR_CONTEXT(bgp, bgp);
1536 bgp_router_id_static_set(bgp, router_id);
1537 return CMD_SUCCESS;
ff8a8a7a 1538}
718e3744 1539
1ca2fd11
IR
1540DEFPY (no_bgp_router_id,
1541 no_bgp_router_id_cmd,
1542 "no bgp router-id [A.B.C.D]",
1543 NO_STR
1544 BGP_STR
1545 "Override configured router identifier\n"
1546 "Manually configured router identifier\n")
ff8a8a7a 1547{
1ca2fd11 1548 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1549
1ca2fd11
IR
1550 if (router_id_str) {
1551 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1552 vty_out(vty, "%% BGP router-id doesn't match\n");
1553 return CMD_WARNING_CONFIG_FAILED;
1554 }
1555 }
718e3744 1556
1ca2fd11
IR
1557 router_id.s_addr = 0;
1558 bgp_router_id_static_set(bgp, router_id);
1559
1560 return CMD_SUCCESS;
ff8a8a7a 1561}
6b0655a2 1562
ed0e57e3 1563DEFPY(bgp_community_alias, bgp_community_alias_cmd,
b4ad2fae 1564 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
ed0e57e3
DA
1565 NO_STR BGP_STR
1566 "Add community specific parameters\n"
1567 "Create an alias for a community\n"
1568 "Community (AA:BB or AA:BB:CC)\n"
1569 "Alias name\n")
1570{
1571 struct community_alias ca1;
1572 struct community_alias ca2;
1573 struct community_alias *lookup_community;
1574 struct community_alias *lookup_alias;
1575
1576 if (!community_str2com(community) && !lcommunity_str2com(community)) {
1577 vty_out(vty, "Invalid community format\n");
1578 return CMD_WARNING;
1579 }
1580
1581 memset(&ca1, 0, sizeof(ca1));
1582 memset(&ca2, 0, sizeof(ca2));
1583 strlcpy(ca1.community, community, sizeof(ca1.community));
b4ad2fae 1584 strlcpy(ca1.alias, alias_name, sizeof(ca1.alias));
ed0e57e3
DA
1585
1586 lookup_community = bgp_ca_community_lookup(&ca1);
1587 lookup_alias = bgp_ca_alias_lookup(&ca1);
1588
1589 if (no) {
1590 bgp_ca_alias_delete(&ca1);
1591 bgp_ca_community_delete(&ca1);
1592 } else {
1593 if (lookup_alias) {
1594 /* Lookup if community hash table has an item
1595 * with the same alias name.
1596 */
1597 strlcpy(ca2.community, lookup_alias->community,
1598 sizeof(ca2.community));
1599 if (bgp_ca_community_lookup(&ca2)) {
1600 vty_out(vty,
1601 "community (%s) already has this alias (%s)\n",
1602 lookup_alias->community,
1603 lookup_alias->alias);
1604 return CMD_WARNING;
1605 }
1606 bgp_ca_alias_delete(&ca1);
1607 }
1608
1609 if (lookup_community)
1610 bgp_ca_community_delete(&ca1);
1611
1612 bgp_ca_alias_insert(&ca1);
1613 bgp_ca_community_insert(&ca1);
1614 }
1615
1616 return CMD_SUCCESS;
1617}
1618
9acb67cb
DS
1619DEFPY (bgp_global_suppress_fib_pending,
1620 bgp_global_suppress_fib_pending_cmd,
1621 "[no] bgp suppress-fib-pending",
1622 NO_STR
1623 BGP_STR
1624 "Advertise only routes that are programmed in kernel to peers globally\n")
1625{
1626 bm_wait_for_fib_set(!no);
1627
1628 return CMD_SUCCESS;
1629}
1630
c208c586
S
1631DEFPY (bgp_suppress_fib_pending,
1632 bgp_suppress_fib_pending_cmd,
1633 "[no] bgp suppress-fib-pending",
1634 NO_STR
1635 BGP_STR
1636 "Advertise only routes that are programmed in kernel to peers\n")
1637{
1638 VTY_DECLVAR_CONTEXT(bgp, bgp);
1639
1640 bgp_suppress_fib_pending_set(bgp, !no);
1641 return CMD_SUCCESS;
1642}
1643
1644
718e3744 1645/* BGP Cluster ID. */
1ca2fd11
IR
1646DEFUN (bgp_cluster_id,
1647 bgp_cluster_id_cmd,
1648 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1649 BGP_STR
1650 "Configure Route-Reflector Cluster-id\n"
1651 "Route-Reflector Cluster-id in IP address format\n"
1652 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1653{
1ca2fd11 1654 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1655 int idx_ipv4 = 2;
1ca2fd11
IR
1656 int ret;
1657 struct in_addr cluster;
1658
1659 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1660 if (!ret) {
1661 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1662 return CMD_WARNING_CONFIG_FAILED;
1663 }
718e3744 1664
1ca2fd11
IR
1665 bgp_cluster_id_set(bgp, &cluster);
1666 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1667
1ca2fd11 1668 return CMD_SUCCESS;
718e3744 1669}
1670
1ca2fd11
IR
1671DEFUN (no_bgp_cluster_id,
1672 no_bgp_cluster_id_cmd,
1673 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1674 NO_STR
1675 BGP_STR
1676 "Configure Route-Reflector Cluster-id\n"
1677 "Route-Reflector Cluster-id in IP address format\n"
1678 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1679{
1ca2fd11
IR
1680 VTY_DECLVAR_CONTEXT(bgp, bgp);
1681 bgp_cluster_id_unset(bgp);
1682 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1683
1ca2fd11 1684 return CMD_SUCCESS;
718e3744 1685}
1686
c163f297
DS
1687DEFPY (bgp_norib,
1688 bgp_norib_cmd,
1689 "bgp no-rib",
1690 BGP_STR
1691 "Disable BGP route installation to RIB (Zebra)\n")
1692{
1693 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1694 vty_out(vty,
1695 "%% No-RIB option is already set, nothing to do here.\n");
1696 return CMD_SUCCESS;
1697 }
1698
1699 bgp_option_norib_set_runtime();
1700
1701 return CMD_SUCCESS;
1702}
1703
1704DEFPY (no_bgp_norib,
1705 no_bgp_norib_cmd,
1706 "no bgp no-rib",
1707 NO_STR
1708 BGP_STR
1709 "Disable BGP route installation to RIB (Zebra)\n")
1710{
1711 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1712 vty_out(vty,
1713 "%% No-RIB option is not set, nothing to do here.\n");
1714 return CMD_SUCCESS;
1715 }
1716
1717 bgp_option_norib_unset_runtime();
1718
1719 return CMD_SUCCESS;
1720}
1721
e46723a5
DS
1722DEFPY (no_bgp_send_extra_data,
1723 no_bgp_send_extra_data_cmd,
1724 "[no] bgp send-extra-data zebra",
1725 NO_STR
1726 BGP_STR
1727 "Extra data to Zebra for display/use\n"
1728 "To zebra\n")
1729{
ec0acb80
DA
1730 if (no)
1731 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1732 else
1733 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1734
1735 return CMD_SUCCESS;
1736}
1737
1ca2fd11
IR
1738DEFUN (bgp_confederation_identifier,
1739 bgp_confederation_identifier_cmd,
1740 "bgp confederation identifier (1-4294967295)",
e9273987 1741 BGP_STR
1ca2fd11
IR
1742 "AS confederation parameters\n"
1743 "AS number\n"
1744 "Set routing domain confederation AS\n")
718e3744 1745{
1ca2fd11 1746 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1747 int idx_number = 3;
1ca2fd11 1748 as_t as;
718e3744 1749
1ca2fd11 1750 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1751
1ca2fd11 1752 bgp_confederation_id_set(bgp, as);
718e3744 1753
1ca2fd11 1754 return CMD_SUCCESS;
718e3744 1755}
1756
1ca2fd11
IR
1757DEFUN (no_bgp_confederation_identifier,
1758 no_bgp_confederation_identifier_cmd,
1759 "no bgp confederation identifier [(1-4294967295)]",
1760 NO_STR
e9273987 1761 BGP_STR
1ca2fd11
IR
1762 "AS confederation parameters\n"
1763 "AS number\n"
1764 "Set routing domain confederation AS\n")
ff8a8a7a 1765{
1ca2fd11
IR
1766 VTY_DECLVAR_CONTEXT(bgp, bgp);
1767 bgp_confederation_id_unset(bgp);
1768
1769 return CMD_SUCCESS;
ff8a8a7a
CS
1770}
1771
1ca2fd11
IR
1772DEFUN (bgp_confederation_peers,
1773 bgp_confederation_peers_cmd,
1774 "bgp confederation peers (1-4294967295)...",
e9273987 1775 BGP_STR
1ca2fd11
IR
1776 "AS confederation parameters\n"
1777 "Peer ASs in BGP confederation\n"
1778 AS_STR)
718e3744 1779{
1ca2fd11 1780 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1781 int idx_asn = 3;
1ca2fd11 1782 as_t as;
d62a17ae 1783 int i;
718e3744 1784
1ca2fd11
IR
1785 for (i = idx_asn; i < argc; i++) {
1786 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1787
1ca2fd11
IR
1788 if (bgp->as == as) {
1789 vty_out(vty,
1790 "%% Local member-AS not allowed in confed peer list\n");
1791 continue;
1792 }
1793
1794 bgp_confederation_peers_add(bgp, as);
1795 }
1796 return CMD_SUCCESS;
718e3744 1797}
1798
1ca2fd11
IR
1799DEFUN (no_bgp_confederation_peers,
1800 no_bgp_confederation_peers_cmd,
1801 "no bgp confederation peers (1-4294967295)...",
1802 NO_STR
e9273987 1803 BGP_STR
1ca2fd11
IR
1804 "AS confederation parameters\n"
1805 "Peer ASs in BGP confederation\n"
1806 AS_STR)
718e3744 1807{
1ca2fd11 1808 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1809 int idx_asn = 4;
1ca2fd11 1810 as_t as;
d62a17ae 1811 int i;
718e3744 1812
1ca2fd11
IR
1813 for (i = idx_asn; i < argc; i++) {
1814 as = strtoul(argv[i]->arg, NULL, 10);
ff8a8a7a 1815
1ca2fd11
IR
1816 bgp_confederation_peers_remove(bgp, as);
1817 }
1818 return CMD_SUCCESS;
718e3744 1819}
6b0655a2 1820
5e242b0d
DS
1821/**
1822 * Central routine for maximum-paths configuration.
1823 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1824 * @set: 1 for setting values, 0 for removing the max-paths config.
1825 */
585f1adc
IR
1826static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1827 const char *mpaths, uint16_t options,
1828 int set)
d62a17ae 1829{
585f1adc
IR
1830 VTY_DECLVAR_CONTEXT(bgp, bgp);
1831 uint16_t maxpaths = 0;
d62a17ae 1832 int ret;
585f1adc
IR
1833 afi_t afi;
1834 safi_t safi;
1835
1836 afi = bgp_node_afi(vty);
1837 safi = bgp_node_safi(vty);
d62a17ae 1838
1839 if (set) {
585f1adc 1840 maxpaths = strtol(mpaths, NULL, 10);
d62a17ae 1841 if (maxpaths > multipath_num) {
585f1adc 1842 vty_out(vty,
d62a17ae 1843 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1844 maxpaths, multipath_num);
1845 return CMD_WARNING_CONFIG_FAILED;
1846 }
1847 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1848 options);
1849 } else
1850 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1851
1852 if (ret < 0) {
585f1adc 1853 vty_out(vty,
d62a17ae 1854 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1855 (set == 1) ? "" : "un",
1856 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1857 maxpaths, afi, safi);
1858 return CMD_WARNING_CONFIG_FAILED;
1859 }
1860
1861 bgp_recalculate_all_bestpaths(bgp);
1862
1863 return CMD_SUCCESS;
165b5fff
JB
1864}
1865
1ca2fd11
IR
1866DEFUN (bgp_maxmed_admin,
1867 bgp_maxmed_admin_cmd,
1868 "bgp max-med administrative ",
1869 BGP_STR
1870 "Advertise routes with max-med\n"
1871 "Administratively applied, for an indefinite period\n")
abc920f8 1872{
1ca2fd11 1873 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1874
1ca2fd11
IR
1875 bgp->v_maxmed_admin = 1;
1876 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
ff8a8a7a 1877
1ca2fd11 1878 bgp_maxmed_update(bgp);
abc920f8 1879
1ca2fd11 1880 return CMD_SUCCESS;
ff8a8a7a
CS
1881}
1882
1ca2fd11
IR
1883DEFUN (bgp_maxmed_admin_medv,
1884 bgp_maxmed_admin_medv_cmd,
1885 "bgp max-med administrative (0-4294967295)",
1886 BGP_STR
1887 "Advertise routes with max-med\n"
1888 "Administratively applied, for an indefinite period\n"
1889 "Max MED value to be used\n")
abc920f8 1890{
1ca2fd11 1891 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1892 int idx_number = 3;
abc920f8 1893
1ca2fd11
IR
1894 bgp->v_maxmed_admin = 1;
1895 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1896
1ca2fd11 1897 bgp_maxmed_update(bgp);
abc920f8 1898
1ca2fd11 1899 return CMD_SUCCESS;
abc920f8
DS
1900}
1901
1ca2fd11
IR
1902DEFUN (no_bgp_maxmed_admin,
1903 no_bgp_maxmed_admin_cmd,
1904 "no bgp max-med administrative [(0-4294967295)]",
1905 NO_STR
1906 BGP_STR
1907 "Advertise routes with max-med\n"
1908 "Administratively applied, for an indefinite period\n"
1909 "Max MED value to be used\n")
abc920f8 1910{
1ca2fd11
IR
1911 VTY_DECLVAR_CONTEXT(bgp, bgp);
1912 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1913 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1914 bgp_maxmed_update(bgp);
ff8a8a7a 1915
1ca2fd11 1916 return CMD_SUCCESS;
abc920f8
DS
1917}
1918
1ca2fd11
IR
1919DEFUN (bgp_maxmed_onstartup,
1920 bgp_maxmed_onstartup_cmd,
1921 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1922 BGP_STR
1923 "Advertise routes with max-med\n"
1924 "Effective on a startup\n"
1925 "Time (seconds) period for max-med\n"
1926 "Max MED value to be used\n")
abc920f8 1927{
1ca2fd11 1928 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1929 int idx = 0;
4668a151 1930
d62a17ae 1931 argv_find(argv, argc, "(5-86400)", &idx);
1ca2fd11 1932 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 1933 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1ca2fd11 1934 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 1935 else
1ca2fd11 1936 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1937
1ca2fd11
IR
1938 bgp_maxmed_update(bgp);
1939
1940 return CMD_SUCCESS;
abc920f8
DS
1941}
1942
1ca2fd11
IR
1943DEFUN (no_bgp_maxmed_onstartup,
1944 no_bgp_maxmed_onstartup_cmd,
1945 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1946 NO_STR
1947 BGP_STR
1948 "Advertise routes with max-med\n"
1949 "Effective on a startup\n"
1950 "Time (seconds) period for max-med\n"
1951 "Max MED value to be used\n")
abc920f8 1952{
1ca2fd11
IR
1953 VTY_DECLVAR_CONTEXT(bgp, bgp);
1954
1955 /* Cancel max-med onstartup if its on */
1956 if (bgp->t_maxmed_onstartup) {
1957 thread_cancel(&bgp->t_maxmed_onstartup);
1958 bgp->maxmed_onstartup_over = 1;
1959 }
abc920f8 1960
1ca2fd11
IR
1961 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1962 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1963
1ca2fd11
IR
1964 bgp_maxmed_update(bgp);
1965
1966 return CMD_SUCCESS;
abc920f8
DS
1967}
1968
d70583f7
D
1969static int bgp_global_update_delay_config_vty(struct vty *vty,
1970 uint16_t update_delay,
1971 uint16_t establish_wait)
1972{
1973 struct listnode *node, *nnode;
1974 struct bgp *bgp;
1975 bool vrf_cfg = false;
1976
1977 /*
1978 * See if update-delay is set per-vrf and warn user to delete it
1979 * Note that we only need to check this if this is the first time
1980 * setting the global config.
1981 */
1982 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1983 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1984 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1985 vty_out(vty,
1986 "%% update-delay configuration found in vrf %s\n",
1987 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1988 ? VRF_DEFAULT_NAME
1989 : bgp->name);
1990 vrf_cfg = true;
1991 }
1992 }
1993 }
1994
1995 if (vrf_cfg) {
1996 vty_out(vty,
1997 "%%Failed: global update-delay config not permitted\n");
1998 return CMD_WARNING;
1999 }
2000
2001 if (!establish_wait) { /* update-delay <delay> */
2002 bm->v_update_delay = update_delay;
2003 bm->v_establish_wait = bm->v_update_delay;
2004 } else {
2005 /* update-delay <delay> <establish-wait> */
2006 if (update_delay < establish_wait) {
2007 vty_out(vty,
2008 "%%Failed: update-delay less than the establish-wait!\n");
2009 return CMD_WARNING_CONFIG_FAILED;
2010 }
2011
2012 bm->v_update_delay = update_delay;
2013 bm->v_establish_wait = establish_wait;
2014 }
2015
2016 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2017 bgp->v_update_delay = bm->v_update_delay;
2018 bgp->v_establish_wait = bm->v_establish_wait;
2019 }
2020
2021 return CMD_SUCCESS;
2022}
2023
2024static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2025{
2026 struct listnode *node, *nnode;
2027 struct bgp *bgp;
2028
2029 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2030 bm->v_establish_wait = bm->v_update_delay;
2031
2032 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2033 bgp->v_update_delay = bm->v_update_delay;
2034 bgp->v_establish_wait = bm->v_establish_wait;
2035 }
2036
2037 return CMD_SUCCESS;
2038}
2039
2040static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2041 uint16_t establish_wait)
f188f2c4 2042{
d62a17ae 2043 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2044
d70583f7
D
2045 /* if configured globally, per-instance config is not allowed */
2046 if (bm->v_update_delay) {
2047 vty_out(vty,
2048 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2049 return CMD_WARNING_CONFIG_FAILED;
2050 }
2051
f188f2c4 2052
d70583f7 2053 if (!establish_wait) /* update-delay <delay> */
d62a17ae 2054 {
2055 bgp->v_update_delay = update_delay;
2056 bgp->v_establish_wait = bgp->v_update_delay;
2057 return CMD_SUCCESS;
2058 }
f188f2c4 2059
d62a17ae 2060 /* update-delay <delay> <establish-wait> */
d62a17ae 2061 if (update_delay < establish_wait) {
2062 vty_out(vty,
2063 "%%Failed: update-delay less than the establish-wait!\n");
2064 return CMD_WARNING_CONFIG_FAILED;
2065 }
f188f2c4 2066
d62a17ae 2067 bgp->v_update_delay = update_delay;
2068 bgp->v_establish_wait = establish_wait;
f188f2c4 2069
d62a17ae 2070 return CMD_SUCCESS;
f188f2c4
DS
2071}
2072
d62a17ae 2073static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2074{
d62a17ae 2075 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2076
d70583f7
D
2077 /* If configured globally, cannot remove from one bgp instance */
2078 if (bm->v_update_delay) {
2079 vty_out(vty,
2080 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2081 return CMD_WARNING_CONFIG_FAILED;
2082 }
d62a17ae 2083 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2084 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2085
d62a17ae 2086 return CMD_SUCCESS;
f188f2c4
DS
2087}
2088
2b791107 2089void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2090{
d70583f7
D
2091 /* If configured globally, no need to display per-instance value */
2092 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2093 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2094 if (bgp->v_update_delay != bgp->v_establish_wait)
2095 vty_out(vty, " %d", bgp->v_establish_wait);
2096 vty_out(vty, "\n");
2097 }
f188f2c4
DS
2098}
2099
d70583f7
D
2100/* Global update-delay configuration */
2101DEFPY (bgp_global_update_delay,
2102 bgp_global_update_delay_cmd,
2103 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2104 BGP_STR
2105 "Force initial delay for best-path and updates for all bgp instances\n"
2106 "Max delay in seconds\n"
2107 "Establish wait in seconds\n")
2108{
2109 return bgp_global_update_delay_config_vty(vty, delay, wait);
2110}
f188f2c4 2111
d70583f7
D
2112/* Global update-delay deconfiguration */
2113DEFPY (no_bgp_global_update_delay,
2114 no_bgp_global_update_delay_cmd,
2115 "no bgp update-delay [(0-3600) [(1-3600)]]",
2116 NO_STR
2117 BGP_STR
f188f2c4 2118 "Force initial delay for best-path and updates\n"
d70583f7
D
2119 "Max delay in seconds\n"
2120 "Establish wait in seconds\n")
f188f2c4 2121{
d70583f7 2122 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2123}
2124
d70583f7
D
2125/* Update-delay configuration */
2126
2127DEFPY (bgp_update_delay,
2128 bgp_update_delay_cmd,
2129 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2130 "Force initial delay for best-path and updates\n"
d70583f7
D
2131 "Max delay in seconds\n"
2132 "Establish wait in seconds\n")
f188f2c4 2133{
d70583f7 2134 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2135}
2136
2137/* Update-delay deconfiguration */
d70583f7 2138DEFPY (no_bgp_update_delay,
f188f2c4 2139 no_bgp_update_delay_cmd,
838758ac
DW
2140 "no update-delay [(0-3600) [(1-3600)]]",
2141 NO_STR
f188f2c4 2142 "Force initial delay for best-path and updates\n"
d70583f7
D
2143 "Max delay in seconds\n"
2144 "Establish wait in seconds\n")
f188f2c4 2145{
d62a17ae 2146 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2147}
2148
5e242b0d 2149
1ca2fd11
IR
2150static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2151 bool set)
cb1faec9 2152{
1ca2fd11
IR
2153 VTY_DECLVAR_CONTEXT(bgp, bgp);
2154
8fa7732f
QY
2155 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2156 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2157
2158 return CMD_SUCCESS;
2159}
2160
1ca2fd11
IR
2161static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2162 bool set)
555e09d4 2163{
1ca2fd11
IR
2164 VTY_DECLVAR_CONTEXT(bgp, bgp);
2165
8fa7732f
QY
2166 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2167 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2168
d62a17ae 2169 return CMD_SUCCESS;
cb1faec9
DS
2170}
2171
2b791107 2172void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2173{
555e09d4
QY
2174 uint32_t quanta =
2175 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2176 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2177 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2178}
2179
555e09d4
QY
2180void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2181{
2182 uint32_t quanta =
2183 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2184 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2185 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2186}
cb1faec9 2187
8fa7732f
QY
2188/* Packet quanta configuration
2189 *
2190 * XXX: The value set here controls the size of a stack buffer in the IO
2191 * thread. When changing these limits be careful to prevent stack overflow.
2192 *
2193 * Furthermore, the maximums used here should correspond to
2194 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2195 */
1ca2fd11
IR
2196DEFPY (bgp_wpkt_quanta,
2197 bgp_wpkt_quanta_cmd,
2198 "[no] write-quanta (1-64)$quanta",
2199 NO_STR
2200 "How many packets to write to peer socket per run\n"
2201 "Number of packets\n")
2202{
2203 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2204}
cb1faec9 2205
1ca2fd11
IR
2206DEFPY (bgp_rpkt_quanta,
2207 bgp_rpkt_quanta_cmd,
2208 "[no] read-quanta (1-10)$quanta",
2209 NO_STR
2210 "How many packets to read from peer socket per I/O cycle\n"
2211 "Number of packets\n")
2212{
2213 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
2214}
2215
2b791107 2216void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2217{
37a333fe 2218 if (!bgp->heuristic_coalesce)
d62a17ae 2219 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2220}
2221
4668a151 2222
1ca2fd11
IR
2223DEFUN (bgp_coalesce_time,
2224 bgp_coalesce_time_cmd,
2225 "coalesce-time (0-4294967295)",
2226 "Subgroup coalesce timer\n"
2227 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2228{
1ca2fd11 2229 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 2230
1ca2fd11 2231 int idx = 0;
d62a17ae 2232 argv_find(argv, argc, "(0-4294967295)", &idx);
1ca2fd11
IR
2233 bgp->heuristic_coalesce = false;
2234 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2235 return CMD_SUCCESS;
3f9c7369
DS
2236}
2237
1ca2fd11
IR
2238DEFUN (no_bgp_coalesce_time,
2239 no_bgp_coalesce_time_cmd,
2240 "no coalesce-time (0-4294967295)",
2241 NO_STR
2242 "Subgroup coalesce timer\n"
2243 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2244{
1ca2fd11 2245 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 2246
1ca2fd11
IR
2247 bgp->heuristic_coalesce = true;
2248 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2249 return CMD_SUCCESS;
3f9c7369
DS
2250}
2251
5e242b0d 2252/* Maximum-paths configuration */
585f1adc
IR
2253DEFUN (bgp_maxpaths,
2254 bgp_maxpaths_cmd,
2255 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2256 "Forward packets over multiple paths\n"
2257 "Number of paths\n")
5e242b0d 2258{
d62a17ae 2259 int idx_number = 1;
585f1adc
IR
2260 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2261 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
2262}
2263
d62a17ae 2264ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2265 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2266 "Forward packets over multiple paths\n"
2267 "Number of paths\n")
596c17ba 2268
585f1adc
IR
2269DEFUN (bgp_maxpaths_ibgp,
2270 bgp_maxpaths_ibgp_cmd,
2271 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2272 "Forward packets over multiple paths\n"
2273 "iBGP-multipath\n"
2274 "Number of paths\n")
165b5fff 2275{
d62a17ae 2276 int idx_number = 2;
585f1adc
IR
2277 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2278 argv[idx_number]->arg, 0, 1);
5e242b0d 2279}
165b5fff 2280
d62a17ae 2281ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2282 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2283 "Forward packets over multiple paths\n"
2284 "iBGP-multipath\n"
2285 "Number of paths\n")
596c17ba 2286
585f1adc
IR
2287DEFUN (bgp_maxpaths_ibgp_cluster,
2288 bgp_maxpaths_ibgp_cluster_cmd,
2289 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2290 "Forward packets over multiple paths\n"
2291 "iBGP-multipath\n"
2292 "Number of paths\n"
2293 "Match the cluster length\n")
5e242b0d 2294{
d62a17ae 2295 int idx_number = 2;
585f1adc
IR
2296 return bgp_maxpaths_config_vty(
2297 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
2298 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
2299}
2300
d62a17ae 2301ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2302 "maximum-paths ibgp " CMD_RANGE_STR(
2303 1, MULTIPATH_NUM) " equal-cluster-length",
2304 "Forward packets over multiple paths\n"
2305 "iBGP-multipath\n"
2306 "Number of paths\n"
2307 "Match the cluster length\n")
596c17ba 2308
585f1adc
IR
2309DEFUN (no_bgp_maxpaths,
2310 no_bgp_maxpaths_cmd,
2311 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2312 NO_STR
2313 "Forward packets over multiple paths\n"
2314 "Number of paths\n")
165b5fff 2315{
585f1adc 2316 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
2317}
2318
d62a17ae 2319ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2320 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2321 "Forward packets over multiple paths\n"
2322 "Number of paths\n")
596c17ba 2323
585f1adc
IR
2324DEFUN (no_bgp_maxpaths_ibgp,
2325 no_bgp_maxpaths_ibgp_cmd,
2326 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2327 NO_STR
2328 "Forward packets over multiple paths\n"
2329 "iBGP-multipath\n"
2330 "Number of paths\n"
2331 "Match the cluster length\n")
165b5fff 2332{
585f1adc 2333 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
2334}
2335
d62a17ae 2336ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2337 "no maximum-paths ibgp [" CMD_RANGE_STR(
2338 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2339 NO_STR
2340 "Forward packets over multiple paths\n"
2341 "iBGP-multipath\n"
2342 "Number of paths\n"
2343 "Match the cluster length\n")
596c17ba 2344
dd65f45e
DL
2345static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2346 afi_t afi, safi_t safi)
165b5fff 2347{
00908b7a 2348 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2349 vty_out(vty, " maximum-paths %d\n",
2350 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2351 }
165b5fff 2352
00908b7a 2353 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2354 vty_out(vty, " maximum-paths ibgp %d",
2355 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2356 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2357 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2358 vty_out(vty, " equal-cluster-length");
2359 vty_out(vty, "\n");
2360 }
165b5fff 2361}
6b0655a2 2362
718e3744 2363/* BGP timers. */
2364
1ca2fd11
IR
2365DEFUN (bgp_timers,
2366 bgp_timers_cmd,
2367 "timers bgp (0-65535) (0-65535)",
2368 "Adjust routing timers\n"
2369 "BGP timers\n"
2370 "Keepalive interval\n"
2371 "Holdtime\n")
718e3744 2372{
1ca2fd11 2373 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2374 int idx_number = 2;
2375 int idx_number_2 = 3;
1ca2fd11
IR
2376 unsigned long keepalive = 0;
2377 unsigned long holdtime = 0;
718e3744 2378
1ca2fd11
IR
2379 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2380 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 2381
1ca2fd11
IR
2382 /* Holdtime value check. */
2383 if (holdtime < 3 && holdtime != 0) {
2384 vty_out(vty,
2385 "%% hold time value must be either 0 or greater than 3\n");
2386 return CMD_WARNING_CONFIG_FAILED;
2387 }
718e3744 2388
1ca2fd11
IR
2389 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2390 BGP_DEFAULT_DELAYOPEN);
718e3744 2391
1ca2fd11 2392 return CMD_SUCCESS;
718e3744 2393}
2394
1ca2fd11
IR
2395DEFUN (no_bgp_timers,
2396 no_bgp_timers_cmd,
2397 "no timers bgp [(0-65535) (0-65535)]",
2398 NO_STR
2399 "Adjust routing timers\n"
2400 "BGP timers\n"
2401 "Keepalive interval\n"
2402 "Holdtime\n")
718e3744 2403{
1ca2fd11
IR
2404 VTY_DECLVAR_CONTEXT(bgp, bgp);
2405 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2406 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
ff8a8a7a 2407
1ca2fd11 2408 return CMD_SUCCESS;
718e3744 2409}
2410
b042667a
TI
2411/* BGP minimum holdtime. */
2412
2413DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2414 "bgp minimum-holdtime (1-65535)",
2415 "BGP specific commands\n"
2416 "BGP minimum holdtime\n"
2417 "Seconds\n")
2418{
2419 VTY_DECLVAR_CONTEXT(bgp, bgp);
2420 int idx_number = 2;
2421 unsigned long min_holdtime;
2422
2423 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2424
2425 bgp->default_min_holdtime = min_holdtime;
2426
2427 return CMD_SUCCESS;
2428}
2429
2430DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2431 "no bgp minimum-holdtime [(1-65535)]",
2432 NO_STR
2433 "BGP specific commands\n"
2434 "BGP minimum holdtime\n"
2435 "Seconds\n")
2436{
2437 VTY_DECLVAR_CONTEXT(bgp, bgp);
2438
2439 bgp->default_min_holdtime = 0;
2440
2441 return CMD_SUCCESS;
2442}
ff8a8a7a 2443
1ca2fd11
IR
2444DEFUN (bgp_client_to_client_reflection,
2445 bgp_client_to_client_reflection_cmd,
2446 "bgp client-to-client reflection",
e9273987 2447 BGP_STR
1ca2fd11
IR
2448 "Configure client to client route reflection\n"
2449 "reflection of routes allowed\n")
718e3744 2450{
1ca2fd11
IR
2451 VTY_DECLVAR_CONTEXT(bgp, bgp);
2452 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2453 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2454
1ca2fd11 2455 return CMD_SUCCESS;
718e3744 2456}
2457
1ca2fd11
IR
2458DEFUN (no_bgp_client_to_client_reflection,
2459 no_bgp_client_to_client_reflection_cmd,
2460 "no bgp client-to-client reflection",
2461 NO_STR
e9273987 2462 BGP_STR
1ca2fd11
IR
2463 "Configure client to client route reflection\n"
2464 "reflection of routes allowed\n")
718e3744 2465{
1ca2fd11
IR
2466 VTY_DECLVAR_CONTEXT(bgp, bgp);
2467 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2468 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2469
1ca2fd11 2470 return CMD_SUCCESS;
718e3744 2471}
2472
2473/* "bgp always-compare-med" configuration. */
1ca2fd11
IR
2474DEFUN (bgp_always_compare_med,
2475 bgp_always_compare_med_cmd,
2476 "bgp always-compare-med",
e9273987 2477 BGP_STR
1ca2fd11 2478 "Allow comparing MED from different neighbors\n")
718e3744 2479{
1ca2fd11
IR
2480 VTY_DECLVAR_CONTEXT(bgp, bgp);
2481 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2482 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2483
1ca2fd11 2484 return CMD_SUCCESS;
718e3744 2485}
2486
1ca2fd11
IR
2487DEFUN (no_bgp_always_compare_med,
2488 no_bgp_always_compare_med_cmd,
2489 "no bgp always-compare-med",
2490 NO_STR
e9273987 2491 BGP_STR
1ca2fd11 2492 "Allow comparing MED from different neighbors\n")
718e3744 2493{
1ca2fd11
IR
2494 VTY_DECLVAR_CONTEXT(bgp, bgp);
2495 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2496 bgp_recalculate_all_bestpaths(bgp);
6b0655a2 2497
1ca2fd11 2498 return CMD_SUCCESS;
2adac256
DA
2499}
2500
2adac256 2501
1ca2fd11
IR
2502DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2503 "bgp ebgp-requires-policy",
e9273987 2504 BGP_STR
1ca2fd11 2505 "Require in and out policy for eBGP peers (RFC8212)\n")
2adac256 2506{
1ca2fd11
IR
2507 VTY_DECLVAR_CONTEXT(bgp, bgp);
2508 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2509 return CMD_SUCCESS;
2adac256
DA
2510}
2511
1ca2fd11
IR
2512DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2513 "no bgp ebgp-requires-policy",
2514 NO_STR
e9273987 2515 BGP_STR
1ca2fd11 2516 "Require in and out policy for eBGP peers (RFC8212)\n")
ff8a8a7a 2517{
1ca2fd11
IR
2518 VTY_DECLVAR_CONTEXT(bgp, bgp);
2519 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2520 return CMD_SUCCESS;
ff8a8a7a 2521}
9dac9fc8 2522
1ca2fd11
IR
2523DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2524 "bgp suppress-duplicates",
e9273987 2525 BGP_STR
1ca2fd11 2526 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2527{
1ca2fd11
IR
2528 VTY_DECLVAR_CONTEXT(bgp, bgp);
2529 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2530 return CMD_SUCCESS;
9dac9fc8
DA
2531}
2532
1ca2fd11
IR
2533DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2534 "no bgp suppress-duplicates",
2535 NO_STR
e9273987 2536 BGP_STR
1ca2fd11 2537 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2538{
1ca2fd11
IR
2539 VTY_DECLVAR_CONTEXT(bgp, bgp);
2540 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2541 return CMD_SUCCESS;
9dac9fc8
DA
2542}
2543
fb29348a
DA
2544DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2545 "bgp reject-as-sets",
e9273987 2546 BGP_STR
fb29348a
DA
2547 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2548{
2549 VTY_DECLVAR_CONTEXT(bgp, bgp);
2550 struct listnode *node, *nnode;
2551 struct peer *peer;
2552
7f972cd8 2553 bgp->reject_as_sets = true;
fb29348a
DA
2554
2555 /* Reset existing BGP sessions to reject routes
2556 * with aspath containing AS_SET or AS_CONFED_SET.
2557 */
2558 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2559 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2560 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2561 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2562 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2563 }
2564 }
2565
2566 return CMD_SUCCESS;
2567}
2568
2569DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2570 "no bgp reject-as-sets",
2571 NO_STR
e9273987 2572 BGP_STR
fb29348a
DA
2573 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2574{
2575 VTY_DECLVAR_CONTEXT(bgp, bgp);
2576 struct listnode *node, *nnode;
2577 struct peer *peer;
2578
7f972cd8 2579 bgp->reject_as_sets = false;
fb29348a
DA
2580
2581 /* Reset existing BGP sessions to reject routes
2582 * with aspath containing AS_SET or AS_CONFED_SET.
2583 */
2584 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2585 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2586 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2587 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2588 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2589 }
2590 }
2591
2592 return CMD_SUCCESS;
2593}
9dac9fc8 2594
718e3744 2595/* "bgp deterministic-med" configuration. */
1ca2fd11 2596DEFUN (bgp_deterministic_med,
718e3744 2597 bgp_deterministic_med_cmd,
2598 "bgp deterministic-med",
e9273987 2599 BGP_STR
718e3744 2600 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2601{
1ca2fd11
IR
2602 VTY_DECLVAR_CONTEXT(bgp, bgp);
2603
2604 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2605 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2606 bgp_recalculate_all_bestpaths(bgp);
2607 }
7aafcaca 2608
1ca2fd11 2609 return CMD_SUCCESS;
718e3744 2610}
2611
1ca2fd11 2612DEFUN (no_bgp_deterministic_med,
718e3744 2613 no_bgp_deterministic_med_cmd,
2614 "no bgp deterministic-med",
2615 NO_STR
e9273987 2616 BGP_STR
718e3744 2617 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2618{
1ca2fd11
IR
2619 VTY_DECLVAR_CONTEXT(bgp, bgp);
2620 int bestpath_per_as_used;
2621 afi_t afi;
2622 safi_t safi;
2623 struct peer *peer;
2624 struct listnode *node, *nnode;
2625
2626 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2627 bestpath_per_as_used = 0;
2628
2629 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2630 FOREACH_AFI_SAFI (afi, safi)
2631 if (bgp_addpath_dmed_required(
2632 peer->addpath_type[afi][safi])) {
2633 bestpath_per_as_used = 1;
2634 break;
2635 }
2636
2637 if (bestpath_per_as_used)
2638 break;
2639 }
2640
2641 if (bestpath_per_as_used) {
2642 vty_out(vty,
2643 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2644 return CMD_WARNING_CONFIG_FAILED;
2645 } else {
2646 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2647 bgp_recalculate_all_bestpaths(bgp);
2648 }
2649 }
d62a17ae 2650
1ca2fd11 2651 return CMD_SUCCESS;
718e3744 2652}
538621f2 2653
055679e9 2654/* "bgp graceful-restart mode" configuration. */
538621f2 2655DEFUN (bgp_graceful_restart,
2ba1fe69 2656 bgp_graceful_restart_cmd,
2657 "bgp graceful-restart",
e9273987 2658 BGP_STR
2ba1fe69 2659 GR_CMD
055679e9 2660 )
538621f2 2661{
055679e9 2662 int ret = BGP_GR_FAILURE;
2663
2664 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2665 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2666
d62a17ae 2667 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2668
2669 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2670
36235319
QY
2671 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2672 ret);
5cce3f05 2673
055679e9 2674 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2675 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2676 vty_out(vty,
2677 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2678 return bgp_vty_return(vty, ret);
538621f2 2679}
2680
2681DEFUN (no_bgp_graceful_restart,
2ba1fe69 2682 no_bgp_graceful_restart_cmd,
2683 "no bgp graceful-restart",
2684 NO_STR
e9273987 2685 BGP_STR
2ba1fe69 2686 NO_GR_CMD
055679e9 2687 )
538621f2 2688{
d62a17ae 2689 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2690
2691 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2692 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2693
2694 int ret = BGP_GR_FAILURE;
2695
2696 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2697
36235319
QY
2698 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2699 ret);
5cce3f05 2700
055679e9 2701 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2702 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2703 vty_out(vty,
2704 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2705
2706 return bgp_vty_return(vty, ret);
538621f2 2707}
2708
93406d87 2709DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2710 bgp_graceful_restart_stalepath_time_cmd,
2711 "bgp graceful-restart stalepath-time (1-4095)",
e9273987 2712 BGP_STR
2ba1fe69 2713 "Graceful restart capability parameters\n"
2714 "Set the max time to hold onto restarting peer's stale paths\n"
2715 "Delay value (seconds)\n")
93406d87 2716{
d62a17ae 2717 VTY_DECLVAR_CONTEXT(bgp, bgp);
2718 int idx_number = 3;
d7c0a89a 2719 uint32_t stalepath;
93406d87 2720
d62a17ae 2721 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2722 bgp->stalepath_time = stalepath;
2723 return CMD_SUCCESS;
93406d87 2724}
2725
eb6f1b41 2726DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2727 bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2728 "bgp graceful-restart restart-time (0-4095)",
e9273987 2729 BGP_STR
2ba1fe69 2730 "Graceful restart capability parameters\n"
2731 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2732 "Delay value (seconds)\n")
eb6f1b41 2733{
d62a17ae 2734 VTY_DECLVAR_CONTEXT(bgp, bgp);
2735 int idx_number = 3;
d7c0a89a 2736 uint32_t restart;
eb6f1b41 2737
d62a17ae 2738 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2739 bgp->restart_time = restart;
2740 return CMD_SUCCESS;
eb6f1b41
PG
2741}
2742
cfd47646 2743DEFUN (bgp_graceful_restart_select_defer_time,
2744 bgp_graceful_restart_select_defer_time_cmd,
2745 "bgp graceful-restart select-defer-time (0-3600)",
e9273987 2746 BGP_STR
cfd47646 2747 "Graceful restart capability parameters\n"
2748 "Set the time to defer the BGP route selection after restart\n"
2749 "Delay value (seconds, 0 - disable)\n")
2750{
2751 VTY_DECLVAR_CONTEXT(bgp, bgp);
2752 int idx_number = 3;
2753 uint32_t defer_time;
2754
2755 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2756 bgp->select_defer_time = defer_time;
2757 if (defer_time == 0)
892fedb6 2758 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2759 else
892fedb6 2760 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2761
2762 return CMD_SUCCESS;
2763}
2764
93406d87 2765DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2766 no_bgp_graceful_restart_stalepath_time_cmd,
2767 "no bgp graceful-restart stalepath-time [(1-4095)]",
2768 NO_STR
e9273987 2769 BGP_STR
2ba1fe69 2770 "Graceful restart capability parameters\n"
2771 "Set the max time to hold onto restarting peer's stale paths\n"
2772 "Delay value (seconds)\n")
93406d87 2773{
d62a17ae 2774 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2775
d62a17ae 2776 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2777 return CMD_SUCCESS;
93406d87 2778}
2779
eb6f1b41 2780DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2781 no_bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2782 "no bgp graceful-restart restart-time [(0-4095)]",
2ba1fe69 2783 NO_STR
e9273987 2784 BGP_STR
2ba1fe69 2785 "Graceful restart capability parameters\n"
2786 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2787 "Delay value (seconds)\n")
eb6f1b41 2788{
d62a17ae 2789 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2790
d62a17ae 2791 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2792 return CMD_SUCCESS;
eb6f1b41
PG
2793}
2794
cfd47646 2795DEFUN (no_bgp_graceful_restart_select_defer_time,
2796 no_bgp_graceful_restart_select_defer_time_cmd,
2797 "no bgp graceful-restart select-defer-time [(0-3600)]",
2798 NO_STR
e9273987 2799 BGP_STR
cfd47646 2800 "Graceful restart capability parameters\n"
2801 "Set the time to defer the BGP route selection after restart\n"
2802 "Delay value (seconds)\n")
2803{
2804 VTY_DECLVAR_CONTEXT(bgp, bgp);
2805
2806 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2807 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2808
2809 return CMD_SUCCESS;
2810}
2811
43fc21b3 2812DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2813 bgp_graceful_restart_preserve_fw_cmd,
2814 "bgp graceful-restart preserve-fw-state",
e9273987 2815 BGP_STR
2ba1fe69 2816 "Graceful restart capability parameters\n"
2817 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2818{
d62a17ae 2819 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2820 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2821 return CMD_SUCCESS;
43fc21b3
JC
2822}
2823
2824DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2825 no_bgp_graceful_restart_preserve_fw_cmd,
2826 "no bgp graceful-restart preserve-fw-state",
2827 NO_STR
e9273987 2828 BGP_STR
2ba1fe69 2829 "Graceful restart capability parameters\n"
2830 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2831{
d62a17ae 2832 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2833 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2834 return CMD_SUCCESS;
43fc21b3
JC
2835}
2836
055679e9 2837DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2838 bgp_graceful_restart_disable_cmd,
2839 "bgp graceful-restart-disable",
e9273987 2840 BGP_STR
2ba1fe69 2841 GR_DISABLE)
055679e9 2842{
2843 int ret = BGP_GR_FAILURE;
2844
2845 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2846 zlog_debug(
2ba1fe69 2847 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2848
055679e9 2849 VTY_DECLVAR_CONTEXT(bgp, bgp);
2850
2851 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2852
dc95985f 2853 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2854 bgp->peer, ret);
5cce3f05 2855
055679e9 2856 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2857 zlog_debug(
2ba1fe69 2858 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2859 vty_out(vty,
2860 "Graceful restart configuration changed, reset all peers to take effect\n");
2861
055679e9 2862 return bgp_vty_return(vty, ret);
2863}
2864
2865DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2866 no_bgp_graceful_restart_disable_cmd,
2867 "no bgp graceful-restart-disable",
2868 NO_STR
e9273987 2869 BGP_STR
2ba1fe69 2870 NO_GR_DISABLE
055679e9 2871 )
2872{
2873 VTY_DECLVAR_CONTEXT(bgp, bgp);
2874
2875 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2876 zlog_debug(
2ba1fe69 2877 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2878
2879 int ret = BGP_GR_FAILURE;
2880
2881 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2882
36235319
QY
2883 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2884 ret);
5cce3f05 2885
055679e9 2886 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2887 zlog_debug(
2ba1fe69 2888 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2889 vty_out(vty,
2890 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2891
2892 return bgp_vty_return(vty, ret);
2893}
2894
2895DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2896 bgp_neighbor_graceful_restart_set_cmd,
2897 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2898 NEIGHBOR_STR
2899 NEIGHBOR_ADDR_STR2
2900 GR_NEIGHBOR_CMD
055679e9 2901 )
2902{
2903 int idx_peer = 1;
2904 struct peer *peer;
2905 int ret = BGP_GR_FAILURE;
2906
dc95985f 2907 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2908
055679e9 2909 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2910 zlog_debug(
2ba1fe69 2911 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2912
055679e9 2913 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2914 if (!peer)
2915 return CMD_WARNING_CONFIG_FAILED;
2916
2917 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2918
dc95985f 2919 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2920 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2921
2922 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2923 zlog_debug(
2ba1fe69 2924 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2925 vty_out(vty,
2926 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2927
2928 return bgp_vty_return(vty, ret);
2929}
2930
2931DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 2932 no_bgp_neighbor_graceful_restart_set_cmd,
2933 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2934 NO_STR
2935 NEIGHBOR_STR
2936 NEIGHBOR_ADDR_STR2
2937 NO_GR_NEIGHBOR_CMD
055679e9 2938 )
2939{
2940 int idx_peer = 2;
2941 int ret = BGP_GR_FAILURE;
2942 struct peer *peer;
2943
dc95985f 2944 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2945
055679e9 2946 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2947 if (!peer)
2948 return CMD_WARNING_CONFIG_FAILED;
2949
2950 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2951 zlog_debug(
2ba1fe69 2952 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 2953
2954 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2955
dc95985f 2956 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2957 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2958
2959 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2960 zlog_debug(
2ba1fe69 2961 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2962 vty_out(vty,
2963 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2964
2965 return bgp_vty_return(vty, ret);
2966}
2967
2968DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 2969 bgp_neighbor_graceful_restart_helper_set_cmd,
2970 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2971 NEIGHBOR_STR
2972 NEIGHBOR_ADDR_STR2
2973 GR_NEIGHBOR_HELPER_CMD
055679e9 2974 )
2975{
2976 int idx_peer = 1;
2977 struct peer *peer;
2978 int ret = BGP_GR_FAILURE;
2979
dc95985f 2980 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2981
055679e9 2982 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2983 zlog_debug(
2ba1fe69 2984 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 2985
055679e9 2986 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2987
055679e9 2988 if (!peer)
2989 return CMD_WARNING_CONFIG_FAILED;
2990
2991
2992 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 2993
dc95985f 2994 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2995 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 2996
055679e9 2997 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2998 zlog_debug(
2ba1fe69 2999 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3000 vty_out(vty,
3001 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3002
3003 return bgp_vty_return(vty, ret);
3004}
3005
3006DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3007 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3008 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3009 NO_STR
3010 NEIGHBOR_STR
3011 NEIGHBOR_ADDR_STR2
3012 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3013 )
3014{
3015 int idx_peer = 2;
3016 int ret = BGP_GR_FAILURE;
3017 struct peer *peer;
3018
dc95985f 3019 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3020
055679e9 3021 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3022 if (!peer)
3023 return CMD_WARNING_CONFIG_FAILED;
3024
3025 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3026 zlog_debug(
2ba1fe69 3027 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3028
36235319 3029 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3030
dc95985f 3031 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3032 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3033
3034 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3035 zlog_debug(
2ba1fe69 3036 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3037 vty_out(vty,
3038 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3039
3040 return bgp_vty_return(vty, ret);
3041}
3042
3043DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3044 bgp_neighbor_graceful_restart_disable_set_cmd,
3045 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3046 NEIGHBOR_STR
3047 NEIGHBOR_ADDR_STR2
3048 GR_NEIGHBOR_DISABLE_CMD
055679e9 3049 )
3050{
3051 int idx_peer = 1;
3052 struct peer *peer;
3053 int ret = BGP_GR_FAILURE;
3054
dc95985f 3055 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3056
055679e9 3057 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3058 zlog_debug(
2ba1fe69 3059 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3060
3061 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3062 if (!peer)
3063 return CMD_WARNING_CONFIG_FAILED;
3064
36235319 3065 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3066
3067 if (peer->bgp->t_startup)
3068 bgp_peer_gr_flags_update(peer);
3069
dc95985f 3070 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3071 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3072
055679e9 3073 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3074 zlog_debug(
2ba1fe69 3075 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3076 vty_out(vty,
3077 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3078
3079 return bgp_vty_return(vty, ret);
3080}
3081
3082DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3083 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3084 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3085 NO_STR
3086 NEIGHBOR_STR
3087 NEIGHBOR_ADDR_STR2
3088 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3089 )
3090{
3091 int idx_peer = 2;
3092 int ret = BGP_GR_FAILURE;
3093 struct peer *peer;
3094
dc95985f 3095 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3096
055679e9 3097 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3098 if (!peer)
3099 return CMD_WARNING_CONFIG_FAILED;
3100
3101 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3102 zlog_debug(
2ba1fe69 3103 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3104
3105 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3106
dc95985f 3107 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3108 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3109
3110 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3111 zlog_debug(
2ba1fe69 3112 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3113 vty_out(vty,
3114 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3115
3116 return bgp_vty_return(vty, ret);
3117}
3118
d6e3c15b 3119DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3120 bgp_graceful_restart_disable_eor_cmd,
3121 "bgp graceful-restart disable-eor",
e9273987 3122 BGP_STR
d6e3c15b 3123 "Graceful restart configuration parameters\n"
3124 "Disable EOR Check\n")
3125{
3126 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3127 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3128
d6e3c15b 3129 return CMD_SUCCESS;
3130}
3131
3132DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3133 no_bgp_graceful_restart_disable_eor_cmd,
3134 "no bgp graceful-restart disable-eor",
3135 NO_STR
e9273987 3136 BGP_STR
d6e3c15b 3137 "Graceful restart configuration parameters\n"
3138 "Disable EOR Check\n")
3139{
3140 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3141 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3142
3143 return CMD_SUCCESS;
3144}
3145
3146DEFUN (bgp_graceful_restart_rib_stale_time,
3147 bgp_graceful_restart_rib_stale_time_cmd,
3148 "bgp graceful-restart rib-stale-time (1-3600)",
e9273987 3149 BGP_STR
dc95985f 3150 "Graceful restart configuration parameters\n"
3151 "Specify the stale route removal timer in rib\n"
3152 "Delay value (seconds)\n")
3153{
3154 VTY_DECLVAR_CONTEXT(bgp, bgp);
3155 int idx_number = 3;
3156 uint32_t stale_time;
3157
3158 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3159 bgp->rib_stale_time = stale_time;
3160 /* Send the stale timer update message to RIB */
3161 if (bgp_zebra_stale_timer_update(bgp))
3162 return CMD_WARNING;
3163
3164 return CMD_SUCCESS;
3165}
3166
3167DEFUN (no_bgp_graceful_restart_rib_stale_time,
3168 no_bgp_graceful_restart_rib_stale_time_cmd,
3169 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3170 NO_STR
e9273987 3171 BGP_STR
dc95985f 3172 "Graceful restart configuration parameters\n"
3173 "Specify the stale route removal timer in rib\n"
3174 "Delay value (seconds)\n")
3175{
3176 VTY_DECLVAR_CONTEXT(bgp, bgp);
3177
3178 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3179 /* Send the stale timer update message to RIB */
3180 if (bgp_zebra_stale_timer_update(bgp))
3181 return CMD_WARNING;
3182
d6e3c15b 3183 return CMD_SUCCESS;
3184}
3185
8606be87 3186DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
7f8a9a24
DA
3187 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3188 BGP_STR
8606be87
DA
3189 "Enable Long-lived Graceful Restart\n"
3190 "Specifies maximum time to wait before purging long-lived stale routes\n"
3191 "Stale time value (seconds)\n")
3192{
3193 VTY_DECLVAR_CONTEXT(bgp, bgp);
3194
3195 uint32_t llgr_stale_time;
3196
3197 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3198 bgp->llgr_stale_time = llgr_stale_time;
3199
3200 return CMD_SUCCESS;
3201}
3202
3203DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
7f8a9a24 3204 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
8606be87
DA
3205 NO_STR BGP_STR
3206 "Enable Long-lived Graceful Restart\n"
3207 "Specifies maximum time to wait before purging long-lived stale routes\n"
3208 "Stale time value (seconds)\n")
3209{
3210 VTY_DECLVAR_CONTEXT(bgp, bgp);
3211
3212 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3213
3214 return CMD_SUCCESS;
3215}
3216
1ca2fd11
IR
3217static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3218 struct bgp *bgp)
05bd726c 3219{
3220 bgp_static_redo_import_check(bgp);
3221 bgp_redistribute_redo(bgp);
1ca2fd11
IR
3222 bgp_clear_star_soft_out(vty, bgp->name);
3223 bgp_clear_star_soft_in(vty, bgp->name);
05bd726c 3224}
3225
3226static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3227{
3228 struct listnode *node, *nnode;
3229 struct bgp *bgp;
3230 bool vrf_cfg = false;
3231
3232 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3233 return CMD_SUCCESS;
3234
3235 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3236 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3237 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3238 vty_out(vty,
3239 "%% graceful-shutdown configuration found in vrf %s\n",
3240 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3241 VRF_DEFAULT_NAME : bgp->name);
3242 vrf_cfg = true;
3243 }
3244 }
3245
3246 if (vrf_cfg) {
3247 vty_out(vty,
3248 "%%Failed: global graceful-shutdown not permitted\n");
3249 return CMD_WARNING;
3250 }
3251
3252 /* Set flag globally */
3253 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3254
3255 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3256 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3257 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3258
3259 return CMD_SUCCESS;
3260}
3261
3262static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3263{
3264 struct listnode *node, *nnode;
3265 struct bgp *bgp;
3266
3267 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3268 return CMD_SUCCESS;
3269
3270 /* Unset flag globally */
3271 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3272
3273 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3274 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3275 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3276
3277 return CMD_SUCCESS;
3278}
3279
7f323236
DW
3280/* "bgp graceful-shutdown" configuration */
3281DEFUN (bgp_graceful_shutdown,
3282 bgp_graceful_shutdown_cmd,
3283 "bgp graceful-shutdown",
3284 BGP_STR
3285 "Graceful shutdown parameters\n")
3286{
05bd726c 3287 if (vty->node == CONFIG_NODE)
3288 return bgp_global_graceful_shutdown_config_vty(vty);
3289
1ca2fd11 3290 VTY_DECLVAR_CONTEXT(bgp, bgp);
7f323236 3291
1ca2fd11
IR
3292 /* if configured globally, per-instance config is not allowed */
3293 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3294 vty_out(vty,
3295 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3296 return CMD_WARNING_CONFIG_FAILED;
3297 }
3298
3299 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3300 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3301 bgp_initiate_graceful_shut_unshut(vty, bgp);
3302 }
3303
3304 return CMD_SUCCESS;
7f323236
DW
3305}
3306
1ca2fd11 3307DEFUN (no_bgp_graceful_shutdown,
7f323236
DW
3308 no_bgp_graceful_shutdown_cmd,
3309 "no bgp graceful-shutdown",
3310 NO_STR
3311 BGP_STR
3312 "Graceful shutdown parameters\n")
3313{
05bd726c 3314 if (vty->node == CONFIG_NODE)
3315 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3316
1ca2fd11 3317 VTY_DECLVAR_CONTEXT(bgp, bgp);
05bd726c 3318
1ca2fd11
IR
3319 /* If configured globally, cannot remove from one bgp instance */
3320 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3321 vty_out(vty,
3322 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3323 return CMD_WARNING_CONFIG_FAILED;
3324 }
7f323236 3325
1ca2fd11
IR
3326 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3327 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3328 bgp_initiate_graceful_shut_unshut(vty, bgp);
3329 }
3330
3331 return CMD_SUCCESS;
7f323236
DW
3332}
3333
718e3744 3334/* "bgp fast-external-failover" configuration. */
1ca2fd11 3335DEFUN (bgp_fast_external_failover,
718e3744 3336 bgp_fast_external_failover_cmd,
3337 "bgp fast-external-failover",
3338 BGP_STR
3339 "Immediately reset session if a link to a directly connected external peer goes down\n")
3340{
1ca2fd11
IR
3341 VTY_DECLVAR_CONTEXT(bgp, bgp);
3342 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3343 return CMD_SUCCESS;
718e3744 3344}
3345
1ca2fd11 3346DEFUN (no_bgp_fast_external_failover,
718e3744 3347 no_bgp_fast_external_failover_cmd,
3348 "no bgp fast-external-failover",
3349 NO_STR
3350 BGP_STR
3351 "Immediately reset session if a link to a directly connected external peer goes down\n")
3352{
1ca2fd11
IR
3353 VTY_DECLVAR_CONTEXT(bgp, bgp);
3354 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3355 return CMD_SUCCESS;
718e3744 3356}
6b0655a2 3357
718e3744 3358/* "bgp bestpath compare-routerid" configuration. */
1ca2fd11
IR
3359DEFUN (bgp_bestpath_compare_router_id,
3360 bgp_bestpath_compare_router_id_cmd,
3361 "bgp bestpath compare-routerid",
e9273987 3362 BGP_STR
1ca2fd11
IR
3363 "Change the default bestpath selection\n"
3364 "Compare router-id for identical EBGP paths\n")
718e3744 3365{
1ca2fd11
IR
3366 VTY_DECLVAR_CONTEXT(bgp, bgp);
3367 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3368 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3369
1ca2fd11 3370 return CMD_SUCCESS;
718e3744 3371}
3372
1ca2fd11
IR
3373DEFUN (no_bgp_bestpath_compare_router_id,
3374 no_bgp_bestpath_compare_router_id_cmd,
3375 "no bgp bestpath compare-routerid",
3376 NO_STR
e9273987 3377 BGP_STR
1ca2fd11
IR
3378 "Change the default bestpath selection\n"
3379 "Compare router-id for identical EBGP paths\n")
718e3744 3380{
1ca2fd11
IR
3381 VTY_DECLVAR_CONTEXT(bgp, bgp);
3382 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3383 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3384
1ca2fd11 3385 return CMD_SUCCESS;
718e3744 3386}
6b0655a2 3387
718e3744 3388/* "bgp bestpath as-path ignore" configuration. */
1ca2fd11
IR
3389DEFUN (bgp_bestpath_aspath_ignore,
3390 bgp_bestpath_aspath_ignore_cmd,
3391 "bgp bestpath as-path ignore",
e9273987 3392 BGP_STR
1ca2fd11
IR
3393 "Change the default bestpath selection\n"
3394 "AS-path attribute\n"
3395 "Ignore as-path length in selecting a route\n")
718e3744 3396{
1ca2fd11
IR
3397 VTY_DECLVAR_CONTEXT(bgp, bgp);
3398 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3399 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3400
1ca2fd11 3401 return CMD_SUCCESS;
718e3744 3402}
3403
1ca2fd11
IR
3404DEFUN (no_bgp_bestpath_aspath_ignore,
3405 no_bgp_bestpath_aspath_ignore_cmd,
3406 "no bgp bestpath as-path ignore",
3407 NO_STR
e9273987 3408 BGP_STR
1ca2fd11
IR
3409 "Change the default bestpath selection\n"
3410 "AS-path attribute\n"
3411 "Ignore as-path length in selecting a route\n")
718e3744 3412{
1ca2fd11
IR
3413 VTY_DECLVAR_CONTEXT(bgp, bgp);
3414 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3415 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3416
1ca2fd11 3417 return CMD_SUCCESS;
718e3744 3418}
6b0655a2 3419
6811845b 3420/* "bgp bestpath as-path confed" configuration. */
1ca2fd11 3421DEFUN (bgp_bestpath_aspath_confed,
6811845b 3422 bgp_bestpath_aspath_confed_cmd,
3423 "bgp bestpath as-path confed",
e9273987 3424 BGP_STR
6811845b 3425 "Change the default bestpath selection\n"
3426 "AS-path attribute\n"
3427 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3428{
1ca2fd11
IR
3429 VTY_DECLVAR_CONTEXT(bgp, bgp);
3430 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3431 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3432
1ca2fd11 3433 return CMD_SUCCESS;
6811845b 3434}
3435
1ca2fd11 3436DEFUN (no_bgp_bestpath_aspath_confed,
6811845b 3437 no_bgp_bestpath_aspath_confed_cmd,
3438 "no bgp bestpath as-path confed",
3439 NO_STR
e9273987 3440 BGP_STR
6811845b 3441 "Change the default bestpath selection\n"
3442 "AS-path attribute\n"
3443 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3444{
1ca2fd11
IR
3445 VTY_DECLVAR_CONTEXT(bgp, bgp);
3446 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3447 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3448
1ca2fd11 3449 return CMD_SUCCESS;
6811845b 3450}
6b0655a2 3451
2fdd455c 3452/* "bgp bestpath as-path multipath-relax" configuration. */
1ca2fd11 3453DEFUN (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3454 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3455 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
e9273987 3456 BGP_STR
16fc1eec
DS
3457 "Change the default bestpath selection\n"
3458 "AS-path attribute\n"
3459 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3460 "Generate an AS_SET\n"
16fc1eec
DS
3461 "Do not generate an AS_SET\n")
3462{
1ca2fd11 3463 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3464 int idx = 0;
1ca2fd11 3465 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 3466
1ca2fd11
IR
3467 /* no-as-set is now the default behavior so we can silently
3468 * ignore it */
d62a17ae 3469 if (argv_find(argv, argc, "as-set", &idx))
1ca2fd11 3470 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 3471 else
1ca2fd11 3472 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
7aafcaca 3473
1ca2fd11
IR
3474 bgp_recalculate_all_bestpaths(bgp);
3475
3476 return CMD_SUCCESS;
16fc1eec
DS
3477}
3478
1ca2fd11 3479DEFUN (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3480 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3481 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec 3482 NO_STR
e9273987 3483 BGP_STR
16fc1eec
DS
3484 "Change the default bestpath selection\n"
3485 "AS-path attribute\n"
3486 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3487 "Generate an AS_SET\n"
16fc1eec
DS
3488 "Do not generate an AS_SET\n")
3489{
1ca2fd11
IR
3490 VTY_DECLVAR_CONTEXT(bgp, bgp);
3491 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3492 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3493 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3494
1ca2fd11 3495 return CMD_SUCCESS;
2fdd455c 3496}
6b0655a2 3497
ee88563a
JM
3498/* "bgp bestpath peer-type multipath-relax" configuration. */
3499DEFUN(bgp_bestpath_peer_type_multipath_relax,
3500 bgp_bestpath_peer_type_multipath_relax_cmd,
3501 "bgp bestpath peer-type multipath-relax",
3502 BGP_STR
3503 "Change the default bestpath selection\n"
3504 "Peer type\n"
3505 "Allow load sharing across routes learned from different peer types\n")
3506{
3507 VTY_DECLVAR_CONTEXT(bgp, bgp);
3508 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3509 bgp_recalculate_all_bestpaths(bgp);
3510
3511 return CMD_SUCCESS;
3512}
3513
3514DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3515 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3516 "no bgp bestpath peer-type multipath-relax",
3517 NO_STR BGP_STR
3518 "Change the default bestpath selection\n"
3519 "Peer type\n"
3520 "Allow load sharing across routes learned from different peer types\n")
3521{
3522 VTY_DECLVAR_CONTEXT(bgp, bgp);
3523 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3524 bgp_recalculate_all_bestpaths(bgp);
3525
3526 return CMD_SUCCESS;
3527}
3528
848973c7 3529/* "bgp log-neighbor-changes" configuration. */
1ca2fd11
IR
3530DEFUN (bgp_log_neighbor_changes,
3531 bgp_log_neighbor_changes_cmd,
3532 "bgp log-neighbor-changes",
e9273987 3533 BGP_STR
1ca2fd11 3534 "Log neighbor up/down and reset reason\n")
848973c7 3535{
1ca2fd11
IR
3536 VTY_DECLVAR_CONTEXT(bgp, bgp);
3537 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3538 return CMD_SUCCESS;
848973c7 3539}
3540
1ca2fd11
IR
3541DEFUN (no_bgp_log_neighbor_changes,
3542 no_bgp_log_neighbor_changes_cmd,
3543 "no bgp log-neighbor-changes",
3544 NO_STR
e9273987 3545 BGP_STR
1ca2fd11 3546 "Log neighbor up/down and reset reason\n")
848973c7 3547{
1ca2fd11
IR
3548 VTY_DECLVAR_CONTEXT(bgp, bgp);
3549 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3550 return CMD_SUCCESS;
848973c7 3551}
6b0655a2 3552
718e3744 3553/* "bgp bestpath med" configuration. */
1ca2fd11 3554DEFUN (bgp_bestpath_med,
718e3744 3555 bgp_bestpath_med_cmd,
2d8c1a4d 3556 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
e9273987 3557 BGP_STR
718e3744 3558 "Change the default bestpath selection\n"
3559 "MED attribute\n"
3560 "Compare MED among confederation paths\n"
838758ac
DW
3561 "Treat missing MED as the least preferred one\n"
3562 "Treat missing MED as the least preferred one\n"
3563 "Compare MED among confederation paths\n")
718e3744 3564{
1ca2fd11 3565 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3566
1ca2fd11 3567 int idx = 0;
d62a17ae 3568 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3569 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3570 idx = 0;
3571 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11 3572 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 3573
1ca2fd11 3574 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3575
1ca2fd11 3576 return CMD_SUCCESS;
718e3744 3577}
3578
1ca2fd11 3579DEFUN (no_bgp_bestpath_med,
718e3744 3580 no_bgp_bestpath_med_cmd,
2d8c1a4d 3581 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3582 NO_STR
e9273987 3583 BGP_STR
718e3744 3584 "Change the default bestpath selection\n"
3585 "MED attribute\n"
3586 "Compare MED among confederation paths\n"
3a2d747c
QY
3587 "Treat missing MED as the least preferred one\n"
3588 "Treat missing MED as the least preferred one\n"
3589 "Compare MED among confederation paths\n")
718e3744 3590{
1ca2fd11 3591 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3592
1ca2fd11 3593 int idx = 0;
d62a17ae 3594 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3595 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3596 idx = 0;
3597 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11
IR
3598 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3599
3600 bgp_recalculate_all_bestpaths(bgp);
718e3744 3601
1ca2fd11 3602 return CMD_SUCCESS;
718e3744 3603}
3604
f7e1c681 3605/* "bgp bestpath bandwidth" configuration. */
3606DEFPY (bgp_bestpath_bw,
3607 bgp_bestpath_bw_cmd,
ad36d216 3608 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
e9273987 3609 BGP_STR
f7e1c681 3610 "Change the default bestpath selection\n"
3611 "Link Bandwidth attribute\n"
3612 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3613 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3614 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3615{
3616 VTY_DECLVAR_CONTEXT(bgp, bgp);
3617 afi_t afi;
3618 safi_t safi;
3619
ad36d216
DS
3620 if (!bw_cfg) {
3621 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3622 return CMD_ERR_INCOMPLETE;
f7e1c681 3623 }
ad36d216
DS
3624 if (!strcmp(bw_cfg, "ignore"))
3625 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3626 else if (!strcmp(bw_cfg, "skip-missing"))
3627 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3628 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3629 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3630 else
3631 return CMD_ERR_NO_MATCH;
f7e1c681 3632
3633 /* This config is used in route install, so redo that. */
3634 FOREACH_AFI_SAFI (afi, safi) {
3635 if (!bgp_fibupd_safi(safi))
3636 continue;
3637 bgp_zebra_announce_table(bgp, afi, safi);
3638 }
3639
3640 return CMD_SUCCESS;
3641}
3642
ad36d216
DS
3643DEFPY (no_bgp_bestpath_bw,
3644 no_bgp_bestpath_bw_cmd,
3645 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3646 NO_STR
e9273987 3647 BGP_STR
ad36d216
DS
3648 "Change the default bestpath selection\n"
3649 "Link Bandwidth attribute\n"
3650 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3651 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3652 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3653{
3654 VTY_DECLVAR_CONTEXT(bgp, bgp);
3655 afi_t afi;
3656 safi_t safi;
3657
3658 bgp->lb_handling = BGP_LINK_BW_ECMP;
3659
3660 /* This config is used in route install, so redo that. */
3661 FOREACH_AFI_SAFI (afi, safi) {
3662 if (!bgp_fibupd_safi(safi))
3663 continue;
3664 bgp_zebra_announce_table(bgp, afi, safi);
3665 }
3666 return CMD_SUCCESS;
3667}
3668
b16bcbba 3669DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
38d11af5
TA
3670 "[no] bgp default <ipv4-unicast|"
3671 "ipv4-multicast|"
3672 "ipv4-vpn|"
3673 "ipv4-labeled-unicast|"
3674 "ipv4-flowspec|"
3675 "ipv6-unicast|"
3676 "ipv6-multicast|"
3677 "ipv6-vpn|"
3678 "ipv6-labeled-unicast|"
3679 "ipv6-flowspec|"
3680 "l2vpn-evpn>$afi_safi",
b16bcbba 3681 NO_STR
e9273987 3682 BGP_STR
e84c59af 3683 "Configure BGP defaults\n"
b16bcbba 3684 "Activate ipv4-unicast for a peer by default\n"
38d11af5
TA
3685 "Activate ipv4-multicast for a peer by default\n"
3686 "Activate ipv4-vpn for a peer by default\n"
3687 "Activate ipv4-labeled-unicast for a peer by default\n"
3688 "Activate ipv4-flowspec for a peer by default\n"
3689 "Activate ipv6-unicast for a peer by default\n"
3690 "Activate ipv6-multicast for a peer by default\n"
3691 "Activate ipv6-vpn for a peer by default\n"
3692 "Activate ipv6-labeled-unicast for a peer by default\n"
3693 "Activate ipv6-flowspec for a peer by default\n"
3694 "Activate l2vpn-evpn for a peer by default\n")
e84c59af
DA
3695{
3696 VTY_DECLVAR_CONTEXT(bgp, bgp);
b16bcbba
TA
3697 char afi_safi_str[strlen(afi_safi) + 1];
3698 char *afi_safi_str_tok;
e84c59af 3699
b16bcbba
TA
3700 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3701 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3702 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3703 afi_t afi = bgp_vty_afi_from_str(afi_str);
38d11af5 3704 safi_t safi;
e84c59af 3705
38d11af5
TA
3706 if (strmatch(safi_str, "labeled"))
3707 safi = bgp_vty_safi_from_str("labeled-unicast");
3708 else
3709 safi = bgp_vty_safi_from_str(safi_str);
b16bcbba
TA
3710
3711 if (no)
3712 bgp->default_af[afi][safi] = false;
38d11af5
TA
3713 else {
3714 if ((safi == SAFI_LABELED_UNICAST
3715 && bgp->default_af[afi][SAFI_UNICAST])
3716 || (safi == SAFI_UNICAST
3717 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3718 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3719 else
3720 bgp->default_af[afi][safi] = true;
3721 }
718e3744 3722
d62a17ae 3723 return CMD_SUCCESS;
718e3744 3724}
6b0655a2 3725
04b6bdc0 3726/* Display hostname in certain command outputs */
1ca2fd11 3727DEFUN (bgp_default_show_hostname,
04b6bdc0
DW
3728 bgp_default_show_hostname_cmd,
3729 "bgp default show-hostname",
e9273987 3730 BGP_STR
04b6bdc0 3731 "Configure BGP defaults\n"
0437e105 3732 "Show hostname in certain command outputs\n")
04b6bdc0 3733{
1ca2fd11
IR
3734 VTY_DECLVAR_CONTEXT(bgp, bgp);
3735 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3736 return CMD_SUCCESS;
ff8a8a7a
CS
3737}
3738
1ca2fd11
IR
3739DEFUN (no_bgp_default_show_hostname,
3740 no_bgp_default_show_hostname_cmd,
3741 "no bgp default show-hostname",
3742 NO_STR
e9273987 3743 BGP_STR
1ca2fd11
IR
3744 "Configure BGP defaults\n"
3745 "Show hostname in certain command outputs\n")
ff8a8a7a 3746{
1ca2fd11
IR
3747 VTY_DECLVAR_CONTEXT(bgp, bgp);
3748 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3749 return CMD_SUCCESS;
04b6bdc0
DW
3750}
3751
aef999a2 3752/* Display hostname in certain command outputs */
1d80f243
IR
3753DEFUN (bgp_default_show_nexthop_hostname,
3754 bgp_default_show_nexthop_hostname_cmd,
3755 "bgp default show-nexthop-hostname",
e9273987 3756 BGP_STR
1d80f243
IR
3757 "Configure BGP defaults\n"
3758 "Show hostname for nexthop in certain command outputs\n")
aef999a2 3759{
1ca2fd11
IR
3760 VTY_DECLVAR_CONTEXT(bgp, bgp);
3761 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3762 return CMD_SUCCESS;
aef999a2
DA
3763}
3764
3765DEFUN (no_bgp_default_show_nexthop_hostname,
3766 no_bgp_default_show_nexthop_hostname_cmd,
3767 "no bgp default show-nexthop-hostname",
3768 NO_STR
e9273987 3769 BGP_STR
aef999a2
DA
3770 "Configure BGP defaults\n"
3771 "Show hostname for nexthop in certain command outputs\n")
3772{
1ca2fd11
IR
3773 VTY_DECLVAR_CONTEXT(bgp, bgp);
3774 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3775 return CMD_SUCCESS;
aef999a2
DA
3776}
3777
8233ef81 3778/* "bgp network import-check" configuration. */
1ca2fd11
IR
3779DEFUN (bgp_network_import_check,
3780 bgp_network_import_check_cmd,
3781 "bgp network import-check",
e9273987 3782 BGP_STR
1ca2fd11
IR
3783 "BGP network command\n"
3784 "Check BGP network route exists in IGP\n")
718e3744 3785{
1ca2fd11
IR
3786 VTY_DECLVAR_CONTEXT(bgp, bgp);
3787 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3788 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3789 bgp_static_redo_import_check(bgp);
3790 }
078430f6 3791
1ca2fd11 3792 return CMD_SUCCESS;
718e3744 3793}
3794
d62a17ae 3795ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3796 "bgp network import-check exact",
e9273987 3797 BGP_STR
d62a17ae 3798 "BGP network command\n"
3799 "Check BGP network route exists in IGP\n"
3800 "Match route precisely\n")
8233ef81 3801
1ca2fd11
IR
3802DEFUN (no_bgp_network_import_check,
3803 no_bgp_network_import_check_cmd,
3804 "no bgp network import-check",
3805 NO_STR
e9273987 3806 BGP_STR
1ca2fd11
IR
3807 "BGP network command\n"
3808 "Check BGP network route exists in IGP\n")
718e3744 3809{
1ca2fd11
IR
3810 VTY_DECLVAR_CONTEXT(bgp, bgp);
3811 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3812 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3813 bgp_static_redo_import_check(bgp);
3814 }
6b0655a2 3815
1ca2fd11 3816 return CMD_SUCCESS;
ff8a8a7a 3817}
718e3744 3818
1ca2fd11
IR
3819DEFUN (bgp_default_local_preference,
3820 bgp_default_local_preference_cmd,
3821 "bgp default local-preference (0-4294967295)",
e9273987 3822 BGP_STR
1ca2fd11
IR
3823 "Configure BGP defaults\n"
3824 "local preference (higher=more preferred)\n"
3825 "Configure default local preference value\n")
ff8a8a7a 3826{
1ca2fd11 3827 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3828 int idx_number = 3;
1ca2fd11 3829 uint32_t local_pref;
718e3744 3830
1ca2fd11 3831 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 3832
1ca2fd11
IR
3833 bgp_default_local_preference_set(bgp, local_pref);
3834 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 3835
1ca2fd11 3836 return CMD_SUCCESS;
718e3744 3837}
3838
1ca2fd11
IR
3839DEFUN (no_bgp_default_local_preference,
3840 no_bgp_default_local_preference_cmd,
3841 "no bgp default local-preference [(0-4294967295)]",
3842 NO_STR
e9273987 3843 BGP_STR
1ca2fd11
IR
3844 "Configure BGP defaults\n"
3845 "local preference (higher=more preferred)\n"
3846 "Configure default local preference value\n")
ff8a8a7a 3847{
1ca2fd11
IR
3848 VTY_DECLVAR_CONTEXT(bgp, bgp);
3849 bgp_default_local_preference_unset(bgp);
3850 bgp_clear_star_soft_in(vty, bgp->name);
3851
3852 return CMD_SUCCESS;
ff8a8a7a 3853}
6b0655a2 3854
ff8a8a7a 3855
1ca2fd11
IR
3856DEFUN (bgp_default_subgroup_pkt_queue_max,
3857 bgp_default_subgroup_pkt_queue_max_cmd,
3858 "bgp default subgroup-pkt-queue-max (20-100)",
e9273987 3859 BGP_STR
1ca2fd11
IR
3860 "Configure BGP defaults\n"
3861 "subgroup-pkt-queue-max\n"
3862 "Configure subgroup packet queue max\n")
8bd9d948 3863{
1ca2fd11 3864 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3865 int idx_number = 3;
1ca2fd11 3866 uint32_t max_size;
3f9c7369 3867
1ca2fd11 3868 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 3869
1ca2fd11 3870 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
ff8a8a7a 3871
1ca2fd11 3872 return CMD_SUCCESS;
8bd9d948
DS
3873}
3874
1ca2fd11
IR
3875DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3876 no_bgp_default_subgroup_pkt_queue_max_cmd,
3877 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3878 NO_STR
e9273987 3879 BGP_STR
1ca2fd11
IR
3880 "Configure BGP defaults\n"
3881 "subgroup-pkt-queue-max\n"
3882 "Configure subgroup packet queue max\n")
ff8a8a7a 3883{
1ca2fd11
IR
3884 VTY_DECLVAR_CONTEXT(bgp, bgp);
3885 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3886 return CMD_SUCCESS;
ff8a8a7a 3887}
813d4307 3888
8bd9d948 3889
1ca2fd11
IR
3890DEFUN (bgp_rr_allow_outbound_policy,
3891 bgp_rr_allow_outbound_policy_cmd,
3892 "bgp route-reflector allow-outbound-policy",
e9273987 3893 BGP_STR
1ca2fd11
IR
3894 "Allow modifications made by out route-map\n"
3895 "on ibgp neighbors\n")
ff8a8a7a 3896{
1ca2fd11 3897 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3898
1ca2fd11
IR
3899 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3900 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3901 update_group_announce_rrclients(bgp);
3902 bgp_clear_star_soft_out(vty, bgp->name);
3903 }
8bd9d948 3904
1ca2fd11
IR
3905 return CMD_SUCCESS;
3906}
ff8a8a7a 3907
1ca2fd11
IR
3908DEFUN (no_bgp_rr_allow_outbound_policy,
3909 no_bgp_rr_allow_outbound_policy_cmd,
3910 "no bgp route-reflector allow-outbound-policy",
3911 NO_STR
e9273987 3912 BGP_STR
1ca2fd11
IR
3913 "Allow modifications made by out route-map\n"
3914 "on ibgp neighbors\n")
8bd9d948 3915{
1ca2fd11 3916 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 3917
1ca2fd11
IR
3918 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3919 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3920 update_group_announce_rrclients(bgp);
3921 bgp_clear_star_soft_out(vty, bgp->name);
d62a17ae 3922 }
8bd9d948 3923
1ca2fd11 3924 return CMD_SUCCESS;
8bd9d948
DS
3925}
3926
1ca2fd11
IR
3927DEFUN (bgp_listen_limit,
3928 bgp_listen_limit_cmd,
3929 "bgp listen limit (1-65535)",
e9273987 3930 BGP_STR
1ca2fd11
IR
3931 "BGP Dynamic Neighbors listen commands\n"
3932 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3933 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3934{
1ca2fd11 3935 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3936 int idx_number = 3;
1ca2fd11
IR
3937 int listen_limit;
3938
3939 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 3940
1ca2fd11 3941 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 3942
1ca2fd11 3943 return CMD_SUCCESS;
f14e6fdb
DS
3944}
3945
1ca2fd11
IR
3946DEFUN (no_bgp_listen_limit,
3947 no_bgp_listen_limit_cmd,
3948 "no bgp listen limit [(1-65535)]",
3949 NO_STR
e9273987 3950 BGP_STR
1ca2fd11
IR
3951 "BGP Dynamic Neighbors listen commands\n"
3952 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3953 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3954{
1ca2fd11
IR
3955 VTY_DECLVAR_CONTEXT(bgp, bgp);
3956 bgp_listen_limit_unset(bgp);
3957 return CMD_SUCCESS;
f14e6fdb
DS
3958}
3959
3960
20eb8864 3961/*
3962 * Check if this listen range is already configured. Check for exact
3963 * match or overlap based on input.
3964 */
d62a17ae 3965static struct peer_group *listen_range_exists(struct bgp *bgp,
3966 struct prefix *range, int exact)
3967{
3968 struct listnode *node, *nnode;
3969 struct listnode *node1, *nnode1;
3970 struct peer_group *group;
3971 struct prefix *lr;
3972 afi_t afi;
3973 int match;
3974
3975 afi = family2afi(range->family);
3976 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3977 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3978 lr)) {
3979 if (exact)
3980 match = prefix_same(range, lr);
3981 else
3982 match = (prefix_match(range, lr)
3983 || prefix_match(lr, range));
3984 if (match)
3985 return group;
3986 }
3987 }
3988
3989 return NULL;
20eb8864 3990}
3991
f14e6fdb
DS
3992DEFUN (bgp_listen_range,
3993 bgp_listen_range_cmd,
d7b9898c 3994 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
e9273987 3995 BGP_STR
d7fa34c1
QY
3996 "Configure BGP dynamic neighbors listen range\n"
3997 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
3998 NEIGHBOR_ADDR_STR
3999 "Member of the peer-group\n"
4000 "Peer-group name\n")
f14e6fdb 4001{
d62a17ae 4002 VTY_DECLVAR_CONTEXT(bgp, bgp);
4003 struct prefix range;
4004 struct peer_group *group, *existing_group;
4005 afi_t afi;
4006 int ret;
4007 int idx = 0;
4008
4009 argv_find(argv, argc, "A.B.C.D/M", &idx);
4010 argv_find(argv, argc, "X:X::X:X/M", &idx);
4011 char *prefix = argv[idx]->arg;
d7b9898c 4012 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4013 char *peergroup = argv[idx]->arg;
4014
4015 /* Convert IP prefix string to struct prefix. */
4016 ret = str2prefix(prefix, &range);
4017 if (!ret) {
4018 vty_out(vty, "%% Malformed listen range\n");
4019 return CMD_WARNING_CONFIG_FAILED;
4020 }
4021
4022 afi = family2afi(range.family);
4023
4024 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4025 vty_out(vty,
4026 "%% Malformed listen range (link-local address)\n");
4027 return CMD_WARNING_CONFIG_FAILED;
4028 }
4029
4030 apply_mask(&range);
4031
4032 /* Check if same listen range is already configured. */
4033 existing_group = listen_range_exists(bgp, &range, 1);
4034 if (existing_group) {
4035 if (strcmp(existing_group->name, peergroup) == 0)
4036 return CMD_SUCCESS;
4037 else {
4038 vty_out(vty,
4039 "%% Same listen range is attached to peer-group %s\n",
4040 existing_group->name);
4041 return CMD_WARNING_CONFIG_FAILED;
4042 }
4043 }
4044
4045 /* Check if an overlapping listen range exists. */
4046 if (listen_range_exists(bgp, &range, 0)) {
4047 vty_out(vty,
4048 "%% Listen range overlaps with existing listen range\n");
4049 return CMD_WARNING_CONFIG_FAILED;
4050 }
4051
4052 group = peer_group_lookup(bgp, peergroup);
4053 if (!group) {
4054 vty_out(vty, "%% Configure the peer-group first\n");
4055 return CMD_WARNING_CONFIG_FAILED;
4056 }
4057
4058 ret = peer_group_listen_range_add(group, &range);
4059 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4060}
4061
4062DEFUN (no_bgp_listen_range,
4063 no_bgp_listen_range_cmd,
d7b9898c 4064 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4065 NO_STR
e9273987 4066 BGP_STR
d7fa34c1
QY
4067 "Unconfigure BGP dynamic neighbors listen range\n"
4068 "Unconfigure BGP dynamic neighbors listen range\n"
4069 NEIGHBOR_ADDR_STR
4070 "Member of the peer-group\n"
4071 "Peer-group name\n")
f14e6fdb 4072{
d62a17ae 4073 VTY_DECLVAR_CONTEXT(bgp, bgp);
4074 struct prefix range;
4075 struct peer_group *group;
4076 afi_t afi;
4077 int ret;
4078 int idx = 0;
4079
4080 argv_find(argv, argc, "A.B.C.D/M", &idx);
4081 argv_find(argv, argc, "X:X::X:X/M", &idx);
4082 char *prefix = argv[idx]->arg;
21d88a71 4083 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4084 char *peergroup = argv[idx]->arg;
4085
4086 /* Convert IP prefix string to struct prefix. */
4087 ret = str2prefix(prefix, &range);
4088 if (!ret) {
4089 vty_out(vty, "%% Malformed listen range\n");
4090 return CMD_WARNING_CONFIG_FAILED;
4091 }
4092
4093 afi = family2afi(range.family);
4094
4095 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4096 vty_out(vty,
4097 "%% Malformed listen range (link-local address)\n");
4098 return CMD_WARNING_CONFIG_FAILED;
4099 }
4100
4101 apply_mask(&range);
4102
4103 group = peer_group_lookup(bgp, peergroup);
4104 if (!group) {
4105 vty_out(vty, "%% Peer-group does not exist\n");
4106 return CMD_WARNING_CONFIG_FAILED;
4107 }
4108
4109 ret = peer_group_listen_range_del(group, &range);
4110 return bgp_vty_return(vty, ret);
4111}
4112
2b791107 4113void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4114{
4115 struct peer_group *group;
4116 struct listnode *node, *nnode, *rnode, *nrnode;
4117 struct prefix *range;
4118 afi_t afi;
d62a17ae 4119
4120 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4121 vty_out(vty, " bgp listen limit %d\n",
4122 bgp->dynamic_neighbors_limit);
4123
4124 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4125 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4126 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4127 nrnode, range)) {
d62a17ae 4128 vty_out(vty,
2dbe669b
DA
4129 " bgp listen range %pFX peer-group %s\n",
4130 range, group->name);
d62a17ae 4131 }
4132 }
4133 }
f14e6fdb
DS
4134}
4135
4136
1ca2fd11
IR
4137DEFUN (bgp_disable_connected_route_check,
4138 bgp_disable_connected_route_check_cmd,
4139 "bgp disable-ebgp-connected-route-check",
e9273987 4140 BGP_STR
1ca2fd11 4141 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4142{
1ca2fd11
IR
4143 VTY_DECLVAR_CONTEXT(bgp, bgp);
4144 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4145 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 4146
1ca2fd11 4147 return CMD_SUCCESS;
907f92c8
DS
4148}
4149
1ca2fd11
IR
4150DEFUN (no_bgp_disable_connected_route_check,
4151 no_bgp_disable_connected_route_check_cmd,
4152 "no bgp disable-ebgp-connected-route-check",
4153 NO_STR
e9273987 4154 BGP_STR
1ca2fd11 4155 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4156{
1ca2fd11
IR
4157 VTY_DECLVAR_CONTEXT(bgp, bgp);
4158 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4159 bgp_clear_star_soft_in(vty, bgp->name);
d62a17ae 4160
1ca2fd11 4161 return CMD_SUCCESS;
d62a17ae 4162}
4163
4164
28c6e247
IR
4165static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4166 const char *as_str)
4167{
4168 VTY_DECLVAR_CONTEXT(bgp, bgp);
4169 int ret;
4170 as_t as;
4171 int as_type = AS_SPECIFIED;
4172 union sockunion su;
4173
4174 if (as_str[0] == 'i') {
4175 as = 0;
4176 as_type = AS_INTERNAL;
4177 } else if (as_str[0] == 'e') {
4178 as = 0;
4179 as_type = AS_EXTERNAL;
4180 } else {
4181 /* Get AS number. */
4182 as = strtoul(as_str, NULL, 10);
4183 }
4184
4185 /* If peer is peer group or interface peer, call proper function. */
4186 ret = str2sockunion(peer_str, &su);
4187 if (ret < 0) {
4188 struct peer *peer;
4189
4190 /* Check if existing interface peer */
4191 peer = peer_lookup_by_conf_if(bgp, peer_str);
4192
4193 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4194
4195 /* if not interface peer, check peer-group settings */
4196 if (ret < 0 && !peer) {
4197 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4198 if (ret < 0) {
4199 vty_out(vty,
4200 "%% Create the peer-group or interface first\n");
4201 return CMD_WARNING_CONFIG_FAILED;
4202 }
4203 return CMD_SUCCESS;
4204 }
4205 } else {
4206 if (peer_address_self_check(bgp, &su)) {
4207 vty_out(vty,
4208 "%% Can not configure the local system as neighbor\n");
4209 return CMD_WARNING_CONFIG_FAILED;
4210 }
4211 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4212 }
4213
4214 /* This peer belongs to peer group. */
4215 switch (ret) {
4216 case BGP_ERR_PEER_GROUP_MEMBER:
4217 vty_out(vty,
4218 "%% Peer-group member cannot override remote-as of peer-group\n");
4219 return CMD_WARNING_CONFIG_FAILED;
4220 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
4221 vty_out(vty,
4222 "%% Peer-group members must be all internal or all external\n");
4223 return CMD_WARNING_CONFIG_FAILED;
4224 }
4225 return bgp_vty_return(vty, ret);
4226}
4227
1ca2fd11
IR
4228DEFUN (bgp_default_shutdown,
4229 bgp_default_shutdown_cmd,
4230 "[no] bgp default shutdown",
4231 NO_STR
4232 BGP_STR
4233 "Configure BGP defaults\n"
4234 "Apply administrative shutdown to newly configured peers\n")
ff8a8a7a 4235{
1ca2fd11
IR
4236 VTY_DECLVAR_CONTEXT(bgp, bgp);
4237 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4238 return CMD_SUCCESS;
f26845f9
QY
4239}
4240
736b68f3
DS
4241DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4242 BGP_STR
9ddf4b81 4243 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4244 "Add a shutdown message (RFC 8203)\n"
4245 "Shutdown message\n")
9cf59432 4246{
736b68f3 4247 char *msgstr = NULL;
8389c83a 4248
9cf59432
DS
4249 VTY_DECLVAR_CONTEXT(bgp, bgp);
4250
8389c83a 4251 if (argc > 3)
f80e35b6 4252 msgstr = argv_concat(argv, argc, 3);
8389c83a 4253
b776f48c
DA
4254 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4255 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4256 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4257 return CMD_WARNING_CONFIG_FAILED;
4258 }
4259
8389c83a
DS
4260 bgp_shutdown_enable(bgp, msgstr);
4261 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4262
4263 return CMD_SUCCESS;
4264}
4265
736b68f3 4266DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4267 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4268{
4269 VTY_DECLVAR_CONTEXT(bgp, bgp);
4270
4271 bgp_shutdown_enable(bgp, NULL);
4272
4273 return CMD_SUCCESS;
4274}
8389c83a 4275
736b68f3 4276DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4277 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4278{
4279 VTY_DECLVAR_CONTEXT(bgp, bgp);
4280
4281 bgp_shutdown_disable(bgp);
4282
4283 return CMD_SUCCESS;
4284}
4285
9ddf4b81 4286ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4287 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4288 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4289 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4290
28c6e247
IR
4291DEFUN (neighbor_remote_as,
4292 neighbor_remote_as_cmd,
4293 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4294 NEIGHBOR_STR
4295 NEIGHBOR_ADDR_STR2
4296 "Specify a BGP neighbor\n"
4297 AS_STR
4298 "Internal BGP peer\n"
4299 "External BGP peer\n")
718e3744 4300{
d62a17ae 4301 int idx_peer = 1;
4302 int idx_remote_as = 3;
28c6e247
IR
4303 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4304 argv[idx_remote_as]->arg);
d62a17ae 4305}
f852eb98
PG
4306/* Enable fast convergence of bgp sessions. If this is enabled, bgp
4307 * sessions do not wait for hold timer expiry to bring down the sessions
4308 * when nexthop becomes unreachable
4309 */
4310DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4311 BGP_STR "Fast convergence for bgp sessions\n")
4312{
4313 VTY_DECLVAR_CONTEXT(bgp, bgp);
4314 bgp->fast_convergence = true;
4315
4316 return CMD_SUCCESS;
4317}
4318
4319DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4320 "no bgp fast-convergence",
4321 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4322{
4323 VTY_DECLVAR_CONTEXT(bgp, bgp);
4324 bgp->fast_convergence = false;
4325
4326 return CMD_SUCCESS;
4327}
d62a17ae 4328
28c6e247
IR
4329static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4330 int v6only,
4331 const char *peer_group_name,
4332 const char *as_str)
d62a17ae 4333{
28c6e247
IR
4334 VTY_DECLVAR_CONTEXT(bgp, bgp);
4335 as_t as = 0;
4336 int as_type = AS_UNSPECIFIED;
d62a17ae 4337 struct peer *peer;
4338 struct peer_group *group;
4339 int ret = 0;
d62a17ae 4340
4341 group = peer_group_lookup(bgp, conf_if);
4342
4343 if (group) {
28c6e247
IR
4344 vty_out(vty, "%% Name conflict with peer-group \n");
4345 return CMD_WARNING_CONFIG_FAILED;
4346 }
4347
4348 if (as_str) {
4349 if (as_str[0] == 'i') {
4350 as_type = AS_INTERNAL;
4351 } else if (as_str[0] == 'e') {
4352 as_type = AS_EXTERNAL;
4353 } else {
4354 /* Get AS number. */
4355 as = strtoul(as_str, NULL, 10);
4356 as_type = AS_SPECIFIED;
4357 }
d62a17ae 4358 }
4359
4360 peer = peer_lookup_by_conf_if(bgp, conf_if);
4361 if (peer) {
28c6e247 4362 if (as_str)
e84c59af 4363 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
d62a17ae 4364 } else {
e84c59af
DA
4365 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4366 NULL);
d62a17ae 4367
4368 if (!peer) {
28c6e247
IR
4369 vty_out(vty, "%% BGP failed to create peer\n");
4370 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4371 }
4372
4373 if (v6only)
527de3dc 4374 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4375
4376 /* Request zebra to initiate IPv6 RAs on this interface. We do
4377 * this
4378 * any unnumbered peer in order to not worry about run-time
4379 * transitions
4380 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4381 * address
4382 * gets deleted later etc.)
4383 */
4384 if (peer->ifp)
4385 bgp_zebra_initiate_radv(bgp, peer);
4386 }
4387
4388 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4389 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4390 if (v6only)
527de3dc 4391 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4392 else
527de3dc 4393 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4394
4395 /* v6only flag changed. Reset bgp seesion */
4396 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4397 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4398 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4399 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4400 } else
4401 bgp_session_reset(peer);
4402 }
4403
9fb964de
PM
4404 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4405 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4406 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4407 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4408 }
d62a17ae 4409
4410 if (peer_group_name) {
4411 group = peer_group_lookup(bgp, peer_group_name);
4412 if (!group) {
28c6e247
IR
4413 vty_out(vty, "%% Configure the peer-group first\n");
4414 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4415 }
4416
8395c1f8 4417 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4418 }
4419
28c6e247 4420 return bgp_vty_return(vty, ret);
a80beece
DS
4421}
4422
28c6e247
IR
4423DEFUN (neighbor_interface_config,
4424 neighbor_interface_config_cmd,
4425 "neighbor WORD interface [peer-group PGNAME]",
4426 NEIGHBOR_STR
4427 "Interface name or neighbor tag\n"
4428 "Enable BGP on interface\n"
4429 "Member of the peer-group\n"
4430 "Peer-group name\n")
4c48cf63 4431{
d62a17ae 4432 int idx_word = 1;
4433 int idx_peer_group_word = 4;
f4b8ec07 4434
d62a17ae 4435 if (argc > idx_peer_group_word)
28c6e247
IR
4436 return peer_conf_interface_get(
4437 vty, argv[idx_word]->arg, 0,
4438 argv[idx_peer_group_word]->arg, NULL);
4439 else
4440 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4441 NULL, NULL);
4c48cf63
DW
4442}
4443
28c6e247
IR
4444DEFUN (neighbor_interface_config_v6only,
4445 neighbor_interface_config_v6only_cmd,
4446 "neighbor WORD interface v6only [peer-group PGNAME]",
4447 NEIGHBOR_STR
4448 "Interface name or neighbor tag\n"
4449 "Enable BGP on interface\n"
4450 "Enable BGP with v6 link-local only\n"
4451 "Member of the peer-group\n"
4452 "Peer-group name\n")
4c48cf63 4453{
d62a17ae 4454 int idx_word = 1;
4455 int idx_peer_group_word = 5;
31500417 4456
d62a17ae 4457 if (argc > idx_peer_group_word)
28c6e247
IR
4458 return peer_conf_interface_get(
4459 vty, argv[idx_word]->arg, 1,
4460 argv[idx_peer_group_word]->arg, NULL);
31500417 4461
28c6e247 4462 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4c48cf63
DW
4463}
4464
a80beece 4465
28c6e247
IR
4466DEFUN (neighbor_interface_config_remote_as,
4467 neighbor_interface_config_remote_as_cmd,
4468 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4469 NEIGHBOR_STR
4470 "Interface name or neighbor tag\n"
4471 "Enable BGP on interface\n"
4472 "Specify a BGP neighbor\n"
4473 AS_STR
4474 "Internal BGP peer\n"
4475 "External BGP peer\n")
b3a39dc5 4476{
d62a17ae 4477 int idx_word = 1;
4478 int idx_remote_as = 4;
28c6e247
IR
4479 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4480 argv[idx_remote_as]->arg);
b3a39dc5
DD
4481}
4482
28c6e247
IR
4483DEFUN (neighbor_interface_v6only_config_remote_as,
4484 neighbor_interface_v6only_config_remote_as_cmd,
4485 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4486 NEIGHBOR_STR
4487 "Interface name or neighbor tag\n"
4488 "Enable BGP with v6 link-local only\n"
4489 "Enable BGP on interface\n"
4490 "Specify a BGP neighbor\n"
4491 AS_STR
4492 "Internal BGP peer\n"
4493 "External BGP peer\n")
b3a39dc5 4494{
d62a17ae 4495 int idx_word = 1;
4496 int idx_remote_as = 5;
28c6e247
IR
4497 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4498 argv[idx_remote_as]->arg);
b3a39dc5
DD
4499}
4500
28c6e247
IR
4501DEFUN (neighbor_peer_group,
4502 neighbor_peer_group_cmd,
4503 "neighbor WORD peer-group",
4504 NEIGHBOR_STR
4505 "Interface name or neighbor tag\n"
4506 "Configure peer-group\n")
718e3744 4507{
28c6e247 4508 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4509 int idx_word = 1;
28c6e247
IR
4510 struct peer *peer;
4511 struct peer_group *group;
718e3744 4512
28c6e247
IR
4513 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4514 if (peer) {
4515 vty_out(vty, "%% Name conflict with interface: \n");
4516 return CMD_WARNING_CONFIG_FAILED;
4517 }
718e3744 4518
28c6e247
IR
4519 group = peer_group_get(bgp, argv[idx_word]->arg);
4520 if (!group) {
4521 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4522 return CMD_WARNING_CONFIG_FAILED;
4523 }
718e3744 4524
28c6e247 4525 return CMD_SUCCESS;
718e3744 4526}
4527
1d80f243
IR
4528DEFUN (no_neighbor,
4529 no_neighbor_cmd,
4530 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4531 NO_STR
4532 NEIGHBOR_STR
4533 NEIGHBOR_ADDR_STR2
4534 "Specify a BGP neighbor\n"
4535 AS_STR
4536 "Internal BGP peer\n"
4537 "External BGP peer\n")
718e3744 4538{
28c6e247 4539 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4540 int idx_peer = 2;
28c6e247 4541 int ret;
d62a17ae 4542 union sockunion su;
28c6e247
IR
4543 struct peer_group *group;
4544 struct peer *peer;
4545 struct peer *other;
d62a17ae 4546
28c6e247
IR
4547 ret = str2sockunion(argv[idx_peer]->arg, &su);
4548 if (ret < 0) {
4549 /* look up for neighbor by interface name config. */
4550 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4551 if (peer) {
4552 /* Request zebra to terminate IPv6 RAs on this
4553 * interface. */
4554 if (peer->ifp)
4555 bgp_zebra_terminate_radv(peer->bgp, peer);
4556 peer_notify_unconfig(peer);
4557 peer_delete(peer);
4558 return CMD_SUCCESS;
d62a17ae 4559 }
28c6e247
IR
4560
4561 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4562 if (group) {
4563 peer_group_notify_unconfig(group);
4564 peer_group_delete(group);
4e2786df 4565 } else {
28c6e247 4566 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4567 return CMD_WARNING_CONFIG_FAILED;
4568 }
28c6e247
IR
4569 } else {
4570 peer = peer_lookup(bgp, &su);
4571 if (peer) {
4572 if (peer_dynamic_neighbor(peer)) {
4573 vty_out(vty,
4574 "%% Operation not allowed on a dynamic neighbor\n");
4575 return CMD_WARNING_CONFIG_FAILED;
4576 }
d62a17ae 4577
28c6e247 4578 other = peer->doppelganger;
f4b8ec07 4579
28c6e247
IR
4580 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4581 bgp_zebra_terminate_radv(peer->bgp, peer);
f4b8ec07 4582
28c6e247
IR
4583 peer_notify_unconfig(peer);
4584 peer_delete(peer);
4585 if (other && other->status != Deleted) {
4586 peer_notify_unconfig(other);
4587 peer_delete(other);
4588 }
4589 }
4590 }
4591
4592 return CMD_SUCCESS;
a80beece
DS
4593}
4594
28c6e247
IR
4595DEFUN (no_neighbor_interface_config,
4596 no_neighbor_interface_config_cmd,
4597 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4598 NO_STR
4599 NEIGHBOR_STR
4600 "Interface name\n"
4601 "Configure BGP on interface\n"
4602 "Enable BGP with v6 link-local only\n"
4603 "Member of the peer-group\n"
4604 "Peer-group name\n"
4605 "Specify a BGP neighbor\n"
4606 AS_STR
4607 "Internal BGP peer\n"
4608 "External BGP peer\n")
718e3744 4609{
28c6e247 4610 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4611 int idx_word = 2;
28c6e247 4612 struct peer *peer;
718e3744 4613
28c6e247
IR
4614 /* look up for neighbor by interface name config. */
4615 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4616 if (peer) {
4617 /* Request zebra to terminate IPv6 RAs on this interface. */
4618 if (peer->ifp)
4619 bgp_zebra_terminate_radv(peer->bgp, peer);
4620 peer_notify_unconfig(peer);
4621 peer_delete(peer);
4622 } else {
4623 vty_out(vty, "%% Create the bgp interface first\n");
4624 return CMD_WARNING_CONFIG_FAILED;
4625 }
4626 return CMD_SUCCESS;
718e3744 4627}
4628
28c6e247
IR
4629DEFUN (no_neighbor_peer_group,
4630 no_neighbor_peer_group_cmd,
4631 "no neighbor WORD peer-group",
4632 NO_STR
4633 NEIGHBOR_STR
4634 "Neighbor tag\n"
4635 "Configure peer-group\n")
718e3744 4636{
28c6e247
IR
4637 VTY_DECLVAR_CONTEXT(bgp, bgp);
4638 int idx_word = 2;
4639 struct peer_group *group;
f4b8ec07 4640
28c6e247
IR
4641 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4642 if (group) {
4643 peer_group_notify_unconfig(group);
4644 peer_group_delete(group);
f4b8ec07 4645 } else {
28c6e247 4646 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4647 return CMD_WARNING_CONFIG_FAILED;
4648 }
28c6e247
IR
4649 return CMD_SUCCESS;
4650}
f4b8ec07 4651
28c6e247
IR
4652DEFUN (no_neighbor_interface_peer_group_remote_as,
4653 no_neighbor_interface_peer_group_remote_as_cmd,
4654 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4655 NO_STR
4656 NEIGHBOR_STR
4657 "Interface name or neighbor tag\n"
4658 "Specify a BGP neighbor\n"
4659 AS_STR
4660 "Internal BGP peer\n"
4661 "External BGP peer\n")
4662{
4663 VTY_DECLVAR_CONTEXT(bgp, bgp);
4664 int idx_word = 2;
4665 struct peer_group *group;
4666 struct peer *peer;
f4b8ec07 4667
28c6e247
IR
4668 /* look up for neighbor by interface name config. */
4669 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4670 if (peer) {
4671 peer_as_change(peer, 0, AS_UNSPECIFIED);
4672 return CMD_SUCCESS;
4673 }
f4b8ec07 4674
28c6e247
IR
4675 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4676 if (group)
4677 peer_group_remote_as_delete(group);
4678 else {
4679 vty_out(vty, "%% Create the peer-group or interface first\n");
4680 return CMD_WARNING_CONFIG_FAILED;
4681 }
4682 return CMD_SUCCESS;
718e3744 4683}
6b0655a2 4684
28c6e247
IR
4685DEFUN (neighbor_local_as,
4686 neighbor_local_as_cmd,
4687 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4688 NEIGHBOR_STR
4689 NEIGHBOR_ADDR_STR2
4690 "Specify a local-as number\n"
4691 "AS number used as local AS\n")
718e3744 4692{
d62a17ae 4693 int idx_peer = 1;
4694 int idx_number = 3;
28c6e247
IR
4695 struct peer *peer;
4696 int ret;
4697 as_t as;
718e3744 4698
28c6e247
IR
4699 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4700 if (!peer)
d62a17ae 4701 return CMD_WARNING_CONFIG_FAILED;
718e3744 4702
28c6e247
IR
4703 as = strtoul(argv[idx_number]->arg, NULL, 10);
4704 ret = peer_local_as_set(peer, as, 0, 0);
4705 return bgp_vty_return(vty, ret);
718e3744 4706}
4707
28c6e247
IR
4708DEFUN (neighbor_local_as_no_prepend,
4709 neighbor_local_as_no_prepend_cmd,
4710 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4711 NEIGHBOR_STR
4712 NEIGHBOR_ADDR_STR2
4713 "Specify a local-as number\n"
4714 "AS number used as local AS\n"
4715 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4716{
d62a17ae 4717 int idx_peer = 1;
4718 int idx_number = 3;
28c6e247
IR
4719 struct peer *peer;
4720 int ret;
4721 as_t as;
718e3744 4722
28c6e247
IR
4723 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4724 if (!peer)
d62a17ae 4725 return CMD_WARNING_CONFIG_FAILED;
718e3744 4726
28c6e247
IR
4727 as = strtoul(argv[idx_number]->arg, NULL, 10);
4728 ret = peer_local_as_set(peer, as, 1, 0);
4729 return bgp_vty_return(vty, ret);
718e3744 4730}
4731
28c6e247
IR
4732DEFUN (neighbor_local_as_no_prepend_replace_as,
4733 neighbor_local_as_no_prepend_replace_as_cmd,
4734 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4735 NEIGHBOR_STR
4736 NEIGHBOR_ADDR_STR2
4737 "Specify a local-as number\n"
4738 "AS number used as local AS\n"
4739 "Do not prepend local-as to updates from ebgp peers\n"
4740 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4741{
d62a17ae 4742 int idx_peer = 1;
4743 int idx_number = 3;
28c6e247
IR
4744 struct peer *peer;
4745 int ret;
4746 as_t as;
9d3f9705 4747
28c6e247
IR
4748 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4749 if (!peer)
d62a17ae 4750 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4751
28c6e247
IR
4752 as = strtoul(argv[idx_number]->arg, NULL, 10);
4753 ret = peer_local_as_set(peer, as, 1, 1);
4754 return bgp_vty_return(vty, ret);
9d3f9705
AC
4755}
4756
28c6e247
IR
4757DEFUN (no_neighbor_local_as,
4758 no_neighbor_local_as_cmd,
4759 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4760 NO_STR
4761 NEIGHBOR_STR
4762 NEIGHBOR_ADDR_STR2
4763 "Specify a local-as number\n"
4764 "AS number used as local AS\n"
4765 "Do not prepend local-as to updates from ebgp peers\n"
4766 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4767{
d62a17ae 4768 int idx_peer = 2;
28c6e247
IR
4769 struct peer *peer;
4770 int ret;
718e3744 4771
28c6e247
IR
4772 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4773 if (!peer)
d62a17ae 4774 return CMD_WARNING_CONFIG_FAILED;
718e3744 4775
28c6e247
IR
4776 ret = peer_local_as_unset(peer);
4777 return bgp_vty_return(vty, ret);
718e3744 4778}
4779
718e3744 4780
3f9c7369
DS
4781DEFUN (neighbor_solo,
4782 neighbor_solo_cmd,
9ccf14f7 4783 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4784 NEIGHBOR_STR
4785 NEIGHBOR_ADDR_STR2
4786 "Solo peer - part of its own update group\n")
4787{
d62a17ae 4788 int idx_peer = 1;
4789 struct peer *peer;
4790 int ret;
3f9c7369 4791
d62a17ae 4792 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4793 if (!peer)
4794 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4795
d62a17ae 4796 ret = update_group_adjust_soloness(peer, 1);
4797 return bgp_vty_return(vty, ret);
3f9c7369
DS
4798}
4799
4800DEFUN (no_neighbor_solo,
4801 no_neighbor_solo_cmd,
9ccf14f7 4802 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4803 NO_STR
4804 NEIGHBOR_STR
4805 NEIGHBOR_ADDR_STR2
4806 "Solo peer - part of its own update group\n")
4807{
d62a17ae 4808 int idx_peer = 2;
4809 struct peer *peer;
4810 int ret;
3f9c7369 4811
d62a17ae 4812 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4813 if (!peer)
4814 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4815
d62a17ae 4816 ret = update_group_adjust_soloness(peer, 0);
4817 return bgp_vty_return(vty, ret);
3f9c7369
DS
4818}
4819
28c6e247
IR
4820DEFUN (neighbor_password,
4821 neighbor_password_cmd,
4822 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4823 NEIGHBOR_STR
4824 NEIGHBOR_ADDR_STR2
4825 "Set a password\n"
4826 "The password\n")
0df7c91f 4827{
d62a17ae 4828 int idx_peer = 1;
4829 int idx_line = 3;
28c6e247
IR
4830 struct peer *peer;
4831 int ret;
0df7c91f 4832
28c6e247
IR
4833 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4834 if (!peer)
d62a17ae 4835 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4836
28c6e247
IR
4837 ret = peer_password_set(peer, argv[idx_line]->arg);
4838 return bgp_vty_return(vty, ret);
0df7c91f
PJ
4839}
4840
28c6e247
IR
4841DEFUN (no_neighbor_password,
4842 no_neighbor_password_cmd,
4843 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4844 NO_STR
4845 NEIGHBOR_STR
4846 NEIGHBOR_ADDR_STR2
4847 "Set a password\n"
4848 "The password\n")
0df7c91f 4849{
d62a17ae 4850 int idx_peer = 2;
28c6e247
IR
4851 struct peer *peer;
4852 int ret;
0df7c91f 4853
28c6e247
IR
4854 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4855 if (!peer)
d62a17ae 4856 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4857
28c6e247
IR
4858 ret = peer_password_unset(peer);
4859 return bgp_vty_return(vty, ret);
0df7c91f 4860}
6b0655a2 4861
28c6e247
IR
4862DEFUN (neighbor_activate,
4863 neighbor_activate_cmd,
4864 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4865 NEIGHBOR_STR
4866 NEIGHBOR_ADDR_STR2
4867 "Enable the Address Family for this Neighbor\n")
718e3744 4868{
d62a17ae 4869 int idx_peer = 1;
28c6e247
IR
4870 int ret;
4871 struct peer *peer;
56ceae84 4872
28c6e247
IR
4873 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4874 if (!peer)
d62a17ae 4875 return CMD_WARNING_CONFIG_FAILED;
718e3744 4876
28c6e247
IR
4877 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4878 return bgp_vty_return(vty, ret);
718e3744 4879}
4880
d62a17ae 4881ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4882 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4883 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4884 "Enable the Address Family for this Neighbor\n")
596c17ba 4885
28c6e247
IR
4886DEFUN (no_neighbor_activate,
4887 no_neighbor_activate_cmd,
4888 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4889 NO_STR
4890 NEIGHBOR_STR
4891 NEIGHBOR_ADDR_STR2
4892 "Enable the Address Family for this Neighbor\n")
718e3744 4893{
d62a17ae 4894 int idx_peer = 2;
28c6e247
IR
4895 int ret;
4896 struct peer *peer;
f4b8ec07 4897
28c6e247
IR
4898 /* Lookup peer. */
4899 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4900 if (!peer)
d62a17ae 4901 return CMD_WARNING_CONFIG_FAILED;
718e3744 4902
28c6e247
IR
4903 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4904 return bgp_vty_return(vty, ret);
718e3744 4905}
6b0655a2 4906
d62a17ae 4907ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4908 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4909 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4910 "Enable the Address Family for this Neighbor\n")
596c17ba 4911
28c6e247
IR
4912DEFUN (neighbor_set_peer_group,
4913 neighbor_set_peer_group_cmd,
4914 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4915 NEIGHBOR_STR
4916 NEIGHBOR_ADDR_STR2
4917 "Member of the peer-group\n"
4918 "Peer-group name\n")
718e3744 4919{
28c6e247 4920 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4921 int idx_peer = 1;
4922 int idx_word = 3;
28c6e247
IR
4923 int ret;
4924 as_t as;
4925 union sockunion su;
4926 struct peer *peer;
4927 struct peer_group *group;
4928
4929 ret = str2sockunion(argv[idx_peer]->arg, &su);
4930 if (ret < 0) {
4931 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4932 if (!peer) {
4933 vty_out(vty, "%% Malformed address or name: %s\n",
4934 argv[idx_peer]->arg);
4935 return CMD_WARNING_CONFIG_FAILED;
4936 }
4937 } else {
4938 if (peer_address_self_check(bgp, &su)) {
4939 vty_out(vty,
4940 "%% Can not configure the local system as neighbor\n");
4941 return CMD_WARNING_CONFIG_FAILED;
4942 }
2a059a54 4943
28c6e247
IR
4944 /* Disallow for dynamic neighbor. */
4945 peer = peer_lookup(bgp, &su);
4946 if (peer && peer_dynamic_neighbor(peer)) {
4947 vty_out(vty,
4948 "%% Operation not allowed on a dynamic neighbor\n");
4949 return CMD_WARNING_CONFIG_FAILED;
4950 }
4951 }
4952
4953 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4954 if (!group) {
4955 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 4956 return CMD_WARNING_CONFIG_FAILED;
28c6e247 4957 }
d62a17ae 4958
28c6e247 4959 ret = peer_group_bind(bgp, &su, peer, group, &as);
2a059a54 4960
28c6e247
IR
4961 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4962 vty_out(vty,
4963 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4964 as);
4965 return CMD_WARNING_CONFIG_FAILED;
4966 }
4967
4968 return bgp_vty_return(vty, ret);
d62a17ae 4969}
4970
4971ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 4972 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4973 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4974 "Member of the peer-group\n"
4975 "Peer-group name\n")
596c17ba 4976
28c6e247
IR
4977DEFUN (no_neighbor_set_peer_group,
4978 no_neighbor_set_peer_group_cmd,
4979 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4980 NO_STR
4981 NEIGHBOR_STR
4982 NEIGHBOR_ADDR_STR2
4983 "Member of the peer-group\n"
4984 "Peer-group name\n")
718e3744 4985{
28c6e247 4986 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4987 int idx_peer = 2;
28c6e247
IR
4988 int idx_word = 4;
4989 int ret;
4990 struct peer *peer;
4991 struct peer_group *group;
d62a17ae 4992
28c6e247
IR
4993 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4994 if (!peer)
d62a17ae 4995 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 4996
28c6e247
IR
4997 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4998 if (!group) {
4999 vty_out(vty, "%% Configure the peer-group first\n");
5000 return CMD_WARNING_CONFIG_FAILED;
5001 }
718e3744 5002
28c6e247
IR
5003 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5004 bgp_zebra_terminate_radv(peer->bgp, peer);
5005
5006 peer_notify_unconfig(peer);
5007 ret = peer_delete(peer);
5008
5009 return bgp_vty_return(vty, ret);
718e3744 5010}
6b0655a2 5011
d62a17ae 5012ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
71cc0c88 5013 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5014 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5015 "Member of the peer-group\n"
5016 "Peer-group name\n")
596c17ba 5017
d62a17ae 5018static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 5019 uint32_t flag, int set)
718e3744 5020{
d62a17ae 5021 int ret;
5022 struct peer *peer;
718e3744 5023
d62a17ae 5024 peer = peer_and_group_lookup_vty(vty, ip_str);
5025 if (!peer)
5026 return CMD_WARNING_CONFIG_FAILED;
718e3744 5027
7ebe625c
QY
5028 /*
5029 * If 'neighbor <interface>', then this is for directly connected peers,
5030 * we should not accept disable-connected-check.
5031 */
5032 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5033 vty_out(vty,
3efd0893 5034 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
5035 ip_str);
5036 return CMD_WARNING_CONFIG_FAILED;
5037 }
5038
d62a17ae 5039 if (!set && flag == PEER_FLAG_SHUTDOWN)
5040 peer_tx_shutdown_message_unset(peer);
ae9b0e11 5041
d62a17ae 5042 if (set)
5043 ret = peer_flag_set(peer, flag);
5044 else
5045 ret = peer_flag_unset(peer, flag);
718e3744 5046
d62a17ae 5047 return bgp_vty_return(vty, ret);
718e3744 5048}
5049
47cbc09b 5050static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 5051{
d62a17ae 5052 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 5053}
5054
d62a17ae 5055static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 5056 uint32_t flag)
718e3744 5057{
d62a17ae 5058 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 5059}
5060
5061/* neighbor passive. */
28c6e247
IR
5062DEFUN (neighbor_passive,
5063 neighbor_passive_cmd,
5064 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5065 NEIGHBOR_STR
5066 NEIGHBOR_ADDR_STR2
5067 "Don't send open messages to this neighbor\n")
718e3744 5068{
d62a17ae 5069 int idx_peer = 1;
28c6e247 5070 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5071}
5072
28c6e247
IR
5073DEFUN (no_neighbor_passive,
5074 no_neighbor_passive_cmd,
5075 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5076 NO_STR
5077 NEIGHBOR_STR
5078 NEIGHBOR_ADDR_STR2
5079 "Don't send open messages to this neighbor\n")
718e3744 5080{
d62a17ae 5081 int idx_peer = 2;
28c6e247 5082 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5083}
6b0655a2 5084
718e3744 5085/* neighbor shutdown. */
28c6e247
IR
5086DEFUN (neighbor_shutdown_msg,
5087 neighbor_shutdown_msg_cmd,
5088 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5089 NEIGHBOR_STR
5090 NEIGHBOR_ADDR_STR2
5091 "Administratively shut down this neighbor\n"
5092 "Add a shutdown message (RFC 8203)\n"
5093 "Shutdown message\n")
718e3744 5094{
d62a17ae 5095 int idx_peer = 1;
73d70fa6 5096
d62a17ae 5097 if (argc >= 5) {
28c6e247
IR
5098 struct peer *peer =
5099 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
d62a17ae 5100 char *message;
73d70fa6 5101
28c6e247
IR
5102 if (!peer)
5103 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5104 message = argv_concat(argv, argc, 4);
28c6e247
IR
5105 peer_tx_shutdown_message_set(peer, message);
5106 XFREE(MTYPE_TMP, message);
d62a17ae 5107 }
73d70fa6 5108
28c6e247 5109 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 5110}
5111
1d80f243 5112ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5113 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5114 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5115 "Administratively shut down this neighbor\n")
73d70fa6 5116
28c6e247
IR
5117DEFUN (no_neighbor_shutdown_msg,
5118 no_neighbor_shutdown_msg_cmd,
5119 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5120 NO_STR
5121 NEIGHBOR_STR
5122 NEIGHBOR_ADDR_STR2
5123 "Administratively shut down this neighbor\n"
5124 "Remove a shutdown message (RFC 8203)\n"
5125 "Shutdown message\n")
718e3744 5126{
d62a17ae 5127 int idx_peer = 2;
73d70fa6 5128
28c6e247
IR
5129 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5130 PEER_FLAG_SHUTDOWN);
718e3744 5131}
6b0655a2 5132
1d80f243 5133ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5134 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5135 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5136 "Administratively shut down this neighbor\n")
73d70fa6 5137
8336c896
DA
5138DEFUN(neighbor_shutdown_rtt,
5139 neighbor_shutdown_rtt_cmd,
5140 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5141 NEIGHBOR_STR
5142 NEIGHBOR_ADDR_STR2
5143 "Administratively shut down this neighbor\n"
5144 "Shutdown if round-trip-time is higher than expected\n"
5145 "Round-trip-time in milliseconds\n"
5146 "Specify the number of keepalives before shutdown\n"
5147 "The number of keepalives with higher RTT to shutdown\n")
5148{
5149 int idx_peer = 1;
5150 int idx_rtt = 4;
5151 int idx_count = 0;
5152 struct peer *peer;
5153
5154 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5155
5156 if (!peer)
5157 return CMD_WARNING_CONFIG_FAILED;
5158
5159 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5160
5161 if (argv_find(argv, argc, "count", &idx_count))
5162 peer->rtt_keepalive_conf =
5163 strtol(argv[idx_count + 1]->arg, NULL, 10);
5164
5165 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5166 PEER_FLAG_RTT_SHUTDOWN);
5167}
5168
5169DEFUN(no_neighbor_shutdown_rtt,
5170 no_neighbor_shutdown_rtt_cmd,
5171 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5172 NO_STR
5173 NEIGHBOR_STR
5174 NEIGHBOR_ADDR_STR2
5175 "Administratively shut down this neighbor\n"
5176 "Shutdown if round-trip-time is higher than expected\n"
5177 "Round-trip-time in milliseconds\n"
5178 "Specify the number of keepalives before shutdown\n"
5179 "The number of keepalives with higher RTT to shutdown\n")
5180{
5181 int idx_peer = 2;
5182 struct peer *peer;
5183
5184 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5185
5186 if (!peer)
5187 return CMD_WARNING_CONFIG_FAILED;
5188
5189 peer->rtt_expected = 0;
5190 peer->rtt_keepalive_conf = 1;
5191
5192 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5193 PEER_FLAG_RTT_SHUTDOWN);
5194}
5195
718e3744 5196/* neighbor capability dynamic. */
28c6e247
IR
5197DEFUN (neighbor_capability_dynamic,
5198 neighbor_capability_dynamic_cmd,
5199 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5200 NEIGHBOR_STR
5201 NEIGHBOR_ADDR_STR2
5202 "Advertise capability to the peer\n"
5203 "Advertise dynamic capability to this neighbor\n")
718e3744 5204{
d62a17ae 5205 int idx_peer = 1;
28c6e247
IR
5206 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5207 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5208}
5209
28c6e247
IR
5210DEFUN (no_neighbor_capability_dynamic,
5211 no_neighbor_capability_dynamic_cmd,
5212 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5213 NO_STR
5214 NEIGHBOR_STR
5215 NEIGHBOR_ADDR_STR2
5216 "Advertise capability to the peer\n"
5217 "Advertise dynamic capability to this neighbor\n")
718e3744 5218{
d62a17ae 5219 int idx_peer = 2;
28c6e247
IR
5220 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5221 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5222}
6b0655a2 5223
718e3744 5224/* neighbor dont-capability-negotiate */
5225DEFUN (neighbor_dont_capability_negotiate,
5226 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5227 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5228 NEIGHBOR_STR
5229 NEIGHBOR_ADDR_STR2
5230 "Do not perform capability negotiation\n")
5231{
d62a17ae 5232 int idx_peer = 1;
5233 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5234 PEER_FLAG_DONT_CAPABILITY);
718e3744 5235}
5236
5237DEFUN (no_neighbor_dont_capability_negotiate,
5238 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5239 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5240 NO_STR
5241 NEIGHBOR_STR
5242 NEIGHBOR_ADDR_STR2
5243 "Do not perform capability negotiation\n")
5244{
28c6e247
IR
5245 int idx_peer = 2;
5246 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5247 PEER_FLAG_DONT_CAPABILITY);
f4b8ec07
CS
5248}
5249
28c6e247
IR
5250/* neighbor capability extended next hop encoding */
5251DEFUN (neighbor_capability_enhe,
5252 neighbor_capability_enhe_cmd,
5253 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5254 NEIGHBOR_STR
5255 NEIGHBOR_ADDR_STR2
5256 "Advertise capability to the peer\n"
5257 "Advertise extended next-hop capability to the peer\n")
f4b8ec07 5258{
28c6e247
IR
5259 int idx_peer = 1;
5260 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5261 PEER_FLAG_CAPABILITY_ENHE);
5262}
f4b8ec07 5263
28c6e247
IR
5264DEFUN (no_neighbor_capability_enhe,
5265 no_neighbor_capability_enhe_cmd,
5266 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5267 NO_STR
5268 NEIGHBOR_STR
5269 NEIGHBOR_ADDR_STR2
5270 "Advertise capability to the peer\n"
5271 "Advertise extended next-hop capability to the peer\n")
5272{
5273 int idx_peer = 2;
5274 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5275 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5276}
5277
d62a17ae 5278static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5279 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5280 int set)
718e3744 5281{
d62a17ae 5282 int ret;
5283 struct peer *peer;
718e3744 5284
d62a17ae 5285 peer = peer_and_group_lookup_vty(vty, peer_str);
5286 if (!peer)
5287 return CMD_WARNING_CONFIG_FAILED;
718e3744 5288
d62a17ae 5289 if (set)
5290 ret = peer_af_flag_set(peer, afi, safi, flag);
5291 else
5292 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5293
d62a17ae 5294 return bgp_vty_return(vty, ret);
718e3744 5295}
5296
d62a17ae 5297static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5298 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5299{
d62a17ae 5300 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5301}
5302
d62a17ae 5303static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5304 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5305{
d62a17ae 5306 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5307}
6b0655a2 5308
718e3744 5309/* neighbor capability orf prefix-list. */
5310DEFUN (neighbor_capability_orf_prefix,
5311 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5312 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5313 NEIGHBOR_STR
5314 NEIGHBOR_ADDR_STR2
5315 "Advertise capability to the peer\n"
5316 "Advertise ORF capability to the peer\n"
5317 "Advertise prefixlist ORF capability to this neighbor\n"
5318 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5319 "Capability to RECEIVE the ORF from this neighbor\n"
5320 "Capability to SEND the ORF to this neighbor\n")
5321{
d62a17ae 5322 int idx_send_recv = 5;
db45f64d
DS
5323 char *peer_str = argv[1]->arg;
5324 struct peer *peer;
5325 afi_t afi = bgp_node_afi(vty);
5326 safi_t safi = bgp_node_safi(vty);
d62a17ae 5327
db45f64d
DS
5328 peer = peer_and_group_lookup_vty(vty, peer_str);
5329 if (!peer)
d62a17ae 5330 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5331
db45f64d
DS
5332 if (strmatch(argv[idx_send_recv]->text, "send"))
5333 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5334 PEER_FLAG_ORF_PREFIX_SM);
5335
5336 if (strmatch(argv[idx_send_recv]->text, "receive"))
5337 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5338 PEER_FLAG_ORF_PREFIX_RM);
5339
5340 if (strmatch(argv[idx_send_recv]->text, "both"))
5341 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5342 PEER_FLAG_ORF_PREFIX_SM)
5343 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5344 PEER_FLAG_ORF_PREFIX_RM);
5345
5346 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5347}
5348
5349ALIAS_HIDDEN(
5350 neighbor_capability_orf_prefix,
5351 neighbor_capability_orf_prefix_hidden_cmd,
5352 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5353 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5354 "Advertise capability to the peer\n"
5355 "Advertise ORF capability to the peer\n"
5356 "Advertise prefixlist ORF capability to this neighbor\n"
5357 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5358 "Capability to RECEIVE the ORF from this neighbor\n"
5359 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5360
718e3744 5361DEFUN (no_neighbor_capability_orf_prefix,
5362 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5363 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5364 NO_STR
5365 NEIGHBOR_STR
5366 NEIGHBOR_ADDR_STR2
5367 "Advertise capability to the peer\n"
5368 "Advertise ORF capability to the peer\n"
5369 "Advertise prefixlist ORF capability to this neighbor\n"
5370 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5371 "Capability to RECEIVE the ORF from this neighbor\n"
5372 "Capability to SEND the ORF to this neighbor\n")
5373{
d62a17ae 5374 int idx_send_recv = 6;
db45f64d
DS
5375 char *peer_str = argv[2]->arg;
5376 struct peer *peer;
5377 afi_t afi = bgp_node_afi(vty);
5378 safi_t safi = bgp_node_safi(vty);
d62a17ae 5379
db45f64d
DS
5380 peer = peer_and_group_lookup_vty(vty, peer_str);
5381 if (!peer)
d62a17ae 5382 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5383
db45f64d
DS
5384 if (strmatch(argv[idx_send_recv]->text, "send"))
5385 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5386 PEER_FLAG_ORF_PREFIX_SM);
5387
5388 if (strmatch(argv[idx_send_recv]->text, "receive"))
5389 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5390 PEER_FLAG_ORF_PREFIX_RM);
5391
5392 if (strmatch(argv[idx_send_recv]->text, "both"))
5393 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5394 PEER_FLAG_ORF_PREFIX_SM)
5395 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5396 PEER_FLAG_ORF_PREFIX_RM);
5397
5398 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5399}
5400
5401ALIAS_HIDDEN(
5402 no_neighbor_capability_orf_prefix,
5403 no_neighbor_capability_orf_prefix_hidden_cmd,
5404 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5405 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5406 "Advertise capability to the peer\n"
5407 "Advertise ORF capability to the peer\n"
5408 "Advertise prefixlist ORF capability to this neighbor\n"
5409 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5410 "Capability to RECEIVE the ORF from this neighbor\n"
5411 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5412
718e3744 5413/* neighbor next-hop-self. */
28c6e247
IR
5414DEFUN (neighbor_nexthop_self,
5415 neighbor_nexthop_self_cmd,
5416 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5417 NEIGHBOR_STR
5418 NEIGHBOR_ADDR_STR2
5419 "Disable the next hop calculation for this neighbor\n")
718e3744 5420{
d62a17ae 5421 int idx_peer = 1;
28c6e247
IR
5422 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5423 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 5424}
9e7a53c1 5425
d62a17ae 5426ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5427 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5428 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5429 "Disable the next hop calculation for this neighbor\n")
596c17ba 5430
f4b8ec07 5431/* neighbor next-hop-self. */
28c6e247
IR
5432DEFUN (neighbor_nexthop_self_force,
5433 neighbor_nexthop_self_force_cmd,
5434 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5435 NEIGHBOR_STR
5436 NEIGHBOR_ADDR_STR2
5437 "Disable the next hop calculation for this neighbor\n"
5438 "Set the next hop to self for reflected routes\n")
f4b8ec07
CS
5439{
5440 int idx_peer = 1;
28c6e247
IR
5441 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5442 bgp_node_safi(vty),
5443 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 5444}
5445
d62a17ae 5446ALIAS_HIDDEN(neighbor_nexthop_self_force,
5447 neighbor_nexthop_self_force_hidden_cmd,
5448 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5449 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5450 "Disable the next hop calculation for this neighbor\n"
5451 "Set the next hop to self for reflected routes\n")
596c17ba 5452
1bc4e531
DA
5453ALIAS_HIDDEN(neighbor_nexthop_self_force,
5454 neighbor_nexthop_self_all_hidden_cmd,
5455 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5456 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5457 "Disable the next hop calculation for this neighbor\n"
5458 "Set the next hop to self for reflected routes\n")
5459
28c6e247
IR
5460DEFUN (no_neighbor_nexthop_self,
5461 no_neighbor_nexthop_self_cmd,
5462 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5463 NO_STR
5464 NEIGHBOR_STR
5465 NEIGHBOR_ADDR_STR2
5466 "Disable the next hop calculation for this neighbor\n")
718e3744 5467{
d62a17ae 5468 int idx_peer = 2;
28c6e247
IR
5469 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5470 bgp_node_afi(vty), bgp_node_safi(vty),
5471 PEER_FLAG_NEXTHOP_SELF);
718e3744 5472}
6b0655a2 5473
d62a17ae 5474ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5475 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5476 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5477 "Disable the next hop calculation for this neighbor\n")
596c17ba 5478
28c6e247
IR
5479DEFUN (no_neighbor_nexthop_self_force,
5480 no_neighbor_nexthop_self_force_cmd,
5481 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5482 NO_STR
5483 NEIGHBOR_STR
5484 NEIGHBOR_ADDR_STR2
5485 "Disable the next hop calculation for this neighbor\n"
5486 "Set the next hop to self for reflected routes\n")
88b8ed8d 5487{
d62a17ae 5488 int idx_peer = 2;
28c6e247
IR
5489 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5490 bgp_node_afi(vty), bgp_node_safi(vty),
5491 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5492}
a538debe 5493
d62a17ae 5494ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5495 no_neighbor_nexthop_self_force_hidden_cmd,
5496 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5497 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5498 "Disable the next hop calculation for this neighbor\n"
5499 "Set the next hop to self for reflected routes\n")
596c17ba 5500
1bc4e531
DA
5501ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5502 no_neighbor_nexthop_self_all_hidden_cmd,
5503 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5504 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5505 "Disable the next hop calculation for this neighbor\n"
5506 "Set the next hop to self for reflected routes\n")
5507
c7122e14 5508/* neighbor as-override */
28c6e247
IR
5509DEFUN (neighbor_as_override,
5510 neighbor_as_override_cmd,
5511 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5512 NEIGHBOR_STR
5513 NEIGHBOR_ADDR_STR2
5514 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5515{
d62a17ae 5516 int idx_peer = 1;
28c6e247
IR
5517 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5518 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5519}
5520
d62a17ae 5521ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5522 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5523 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5524 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5525
28c6e247
IR
5526DEFUN (no_neighbor_as_override,
5527 no_neighbor_as_override_cmd,
5528 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5529 NO_STR
5530 NEIGHBOR_STR
5531 NEIGHBOR_ADDR_STR2
5532 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5533{
d62a17ae 5534 int idx_peer = 2;
28c6e247
IR
5535 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5536 bgp_node_afi(vty), bgp_node_safi(vty),
5537 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5538}
5539
d62a17ae 5540ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5541 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5542 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5543 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5544
718e3744 5545/* neighbor remove-private-AS. */
28c6e247
IR
5546DEFUN (neighbor_remove_private_as,
5547 neighbor_remove_private_as_cmd,
5548 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5549 NEIGHBOR_STR
5550 NEIGHBOR_ADDR_STR2
5551 "Remove private ASNs in outbound updates\n")
718e3744 5552{
d62a17ae 5553 int idx_peer = 1;
28c6e247
IR
5554 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5555 bgp_node_safi(vty),
5556 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5557}
5558
d62a17ae 5559ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5560 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5561 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5562 "Remove private ASNs in outbound updates\n")
596c17ba 5563
28c6e247
IR
5564DEFUN (neighbor_remove_private_as_all,
5565 neighbor_remove_private_as_all_cmd,
5566 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5567 NEIGHBOR_STR
5568 NEIGHBOR_ADDR_STR2
5569 "Remove private ASNs in outbound updates\n"
5570 "Apply to all AS numbers\n")
5000f21c 5571{
d62a17ae 5572 int idx_peer = 1;
28c6e247
IR
5573 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5574 bgp_node_safi(vty),
5575 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
5576}
5577
d62a17ae 5578ALIAS_HIDDEN(neighbor_remove_private_as_all,
5579 neighbor_remove_private_as_all_hidden_cmd,
5580 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5581 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5582 "Remove private ASNs in outbound updates\n"
5583 "Apply to all AS numbers")
596c17ba 5584
28c6e247
IR
5585DEFUN (neighbor_remove_private_as_replace_as,
5586 neighbor_remove_private_as_replace_as_cmd,
5587 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5588 NEIGHBOR_STR
5589 NEIGHBOR_ADDR_STR2
5590 "Remove private ASNs in outbound updates\n"
5591 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5592{
d62a17ae 5593 int idx_peer = 1;
28c6e247
IR
5594 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5595 bgp_node_safi(vty),
5596 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
5597}
5598
d62a17ae 5599ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5600 neighbor_remove_private_as_replace_as_hidden_cmd,
5601 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5602 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5603 "Remove private ASNs in outbound updates\n"
5604 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5605
28c6e247
IR
5606DEFUN (neighbor_remove_private_as_all_replace_as,
5607 neighbor_remove_private_as_all_replace_as_cmd,
5608 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5609 NEIGHBOR_STR
5610 NEIGHBOR_ADDR_STR2
5611 "Remove private ASNs in outbound updates\n"
5612 "Apply to all AS numbers\n"
5613 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5614{
d62a17ae 5615 int idx_peer = 1;
28c6e247
IR
5616 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5617 bgp_node_safi(vty),
5618 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
5619}
5620
d62a17ae 5621ALIAS_HIDDEN(
5622 neighbor_remove_private_as_all_replace_as,
5623 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5624 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5625 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5626 "Remove private ASNs in outbound updates\n"
5627 "Apply to all AS numbers\n"
5628 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5629
28c6e247
IR
5630DEFUN (no_neighbor_remove_private_as,
5631 no_neighbor_remove_private_as_cmd,
5632 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5633 NO_STR
5634 NEIGHBOR_STR
5635 NEIGHBOR_ADDR_STR2
5636 "Remove private ASNs in outbound updates\n")
718e3744 5637{
d62a17ae 5638 int idx_peer = 2;
28c6e247
IR
5639 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5640 bgp_node_afi(vty), bgp_node_safi(vty),
5641 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5642}
6b0655a2 5643
d62a17ae 5644ALIAS_HIDDEN(no_neighbor_remove_private_as,
5645 no_neighbor_remove_private_as_hidden_cmd,
5646 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5647 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5648 "Remove private ASNs in outbound updates\n")
596c17ba 5649
28c6e247
IR
5650DEFUN (no_neighbor_remove_private_as_all,
5651 no_neighbor_remove_private_as_all_cmd,
5652 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5653 NO_STR
5654 NEIGHBOR_STR
5655 NEIGHBOR_ADDR_STR2
5656 "Remove private ASNs in outbound updates\n"
5657 "Apply to all AS numbers\n")
88b8ed8d 5658{
d62a17ae 5659 int idx_peer = 2;
28c6e247
IR
5660 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5661 bgp_node_afi(vty), bgp_node_safi(vty),
5662 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 5663}
5000f21c 5664
d62a17ae 5665ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5666 no_neighbor_remove_private_as_all_hidden_cmd,
5667 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5668 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5669 "Remove private ASNs in outbound updates\n"
5670 "Apply to all AS numbers\n")
596c17ba 5671
28c6e247
IR
5672DEFUN (no_neighbor_remove_private_as_replace_as,
5673 no_neighbor_remove_private_as_replace_as_cmd,
5674 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5675 NO_STR
5676 NEIGHBOR_STR
5677 NEIGHBOR_ADDR_STR2
5678 "Remove private ASNs in outbound updates\n"
5679 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5680{
d62a17ae 5681 int idx_peer = 2;
28c6e247
IR
5682 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5683 bgp_node_afi(vty), bgp_node_safi(vty),
5684 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 5685}
5000f21c 5686
d62a17ae 5687ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5688 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5689 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5690 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5691 "Remove private ASNs in outbound updates\n"
5692 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5693
28c6e247
IR
5694DEFUN (no_neighbor_remove_private_as_all_replace_as,
5695 no_neighbor_remove_private_as_all_replace_as_cmd,
5696 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5697 NO_STR
5698 NEIGHBOR_STR
5699 NEIGHBOR_ADDR_STR2
5700 "Remove private ASNs in outbound updates\n"
5701 "Apply to all AS numbers\n"
5702 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5703{
d62a17ae 5704 int idx_peer = 2;
28c6e247
IR
5705 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5706 bgp_node_afi(vty), bgp_node_safi(vty),
5707 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 5708}
5000f21c 5709
d62a17ae 5710ALIAS_HIDDEN(
5711 no_neighbor_remove_private_as_all_replace_as,
5712 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5713 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5714 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5715 "Remove private ASNs in outbound updates\n"
5716 "Apply to all AS numbers\n"
5717 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5718
5000f21c 5719
718e3744 5720/* neighbor send-community. */
28c6e247
IR
5721DEFUN (neighbor_send_community,
5722 neighbor_send_community_cmd,
5723 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5724 NEIGHBOR_STR
5725 NEIGHBOR_ADDR_STR2
5726 "Send Community attribute to this neighbor\n")
718e3744 5727{
d62a17ae 5728 int idx_peer = 1;
27c05d4d 5729
f63d4054
IR
5730 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5731 bgp_node_safi(vty),
5732 PEER_FLAG_SEND_COMMUNITY);
718e3744 5733}
5734
d62a17ae 5735ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5736 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5737 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5738 "Send Community attribute to this neighbor\n")
596c17ba 5739
28c6e247
IR
5740DEFUN (no_neighbor_send_community,
5741 no_neighbor_send_community_cmd,
5742 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5743 NO_STR
5744 NEIGHBOR_STR
5745 NEIGHBOR_ADDR_STR2
5746 "Send Community attribute to this neighbor\n")
718e3744 5747{
d62a17ae 5748 int idx_peer = 2;
27c05d4d 5749
f63d4054
IR
5750 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5751 bgp_node_afi(vty), bgp_node_safi(vty),
5752 PEER_FLAG_SEND_COMMUNITY);
718e3744 5753}
6b0655a2 5754
d62a17ae 5755ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5756 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5757 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5758 "Send Community attribute to this neighbor\n")
596c17ba 5759
718e3744 5760/* neighbor send-community extended. */
28c6e247
IR
5761DEFUN (neighbor_send_community_type,
5762 neighbor_send_community_type_cmd,
5763 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5764 NEIGHBOR_STR
5765 NEIGHBOR_ADDR_STR2
5766 "Send Community attribute to this neighbor\n"
5767 "Send Standard and Extended Community attributes\n"
5768 "Send Standard, Large and Extended Community attributes\n"
5769 "Send Extended Community attributes\n"
5770 "Send Standard Community attributes\n"
5771 "Send Large Community attributes\n")
718e3744 5772{
27c05d4d 5773 const char *type = argv[argc - 1]->text;
db45f64d 5774 char *peer_str = argv[1]->arg;
28c6e247 5775 struct peer *peer;
db45f64d 5776 afi_t afi = bgp_node_afi(vty);
28c6e247 5777 safi_t safi = bgp_node_safi(vty);
f4b8ec07 5778
28c6e247
IR
5779 peer = peer_and_group_lookup_vty(vty, peer_str);
5780 if (!peer)
5781 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07 5782
28c6e247
IR
5783 if (strmatch(type, "standard"))
5784 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5785 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 5786
28c6e247
IR
5787 if (strmatch(type, "extended"))
5788 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5789 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5790
28c6e247
IR
5791 if (strmatch(type, "large"))
5792 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5793 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07 5794
28c6e247
IR
5795 if (strmatch(type, "both")) {
5796 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5797 PEER_FLAG_SEND_COMMUNITY)
5798 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5799 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5800 }
28c6e247
IR
5801 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5802 PEER_FLAG_SEND_COMMUNITY)
5803 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5804 PEER_FLAG_SEND_EXT_COMMUNITY)
5805 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5806 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5807}
5808
5809ALIAS_HIDDEN(
5810 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5811 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5812 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5813 "Send Community attribute to this neighbor\n"
5814 "Send Standard and Extended Community attributes\n"
5815 "Send Standard, Large and Extended Community attributes\n"
5816 "Send Extended Community attributes\n"
5817 "Send Standard Community attributes\n"
5818 "Send Large Community attributes\n")
596c17ba 5819
28c6e247
IR
5820DEFUN (no_neighbor_send_community_type,
5821 no_neighbor_send_community_type_cmd,
5822 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5823 NO_STR
5824 NEIGHBOR_STR
5825 NEIGHBOR_ADDR_STR2
5826 "Send Community attribute to this neighbor\n"
5827 "Send Standard and Extended Community attributes\n"
5828 "Send Standard, Large and Extended Community attributes\n"
5829 "Send Extended Community attributes\n"
5830 "Send Standard Community attributes\n"
5831 "Send Large Community attributes\n")
718e3744 5832{
d62a17ae 5833 const char *type = argv[argc - 1]->text;
db45f64d 5834 char *peer_str = argv[2]->arg;
28c6e247 5835 struct peer *peer;
db45f64d
DS
5836 afi_t afi = bgp_node_afi(vty);
5837 safi_t safi = bgp_node_safi(vty);
5838
28c6e247
IR
5839 peer = peer_and_group_lookup_vty(vty, peer_str);
5840 if (!peer)
f4b8ec07
CS
5841 return CMD_WARNING_CONFIG_FAILED;
5842
28c6e247
IR
5843 if (strmatch(type, "standard"))
5844 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5845 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 5846
28c6e247
IR
5847 if (strmatch(type, "extended"))
5848 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5849 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5850
28c6e247
IR
5851 if (strmatch(type, "large"))
5852 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5853 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07
CS
5854
5855 if (strmatch(type, "both")) {
db45f64d 5856
28c6e247
IR
5857 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5858 PEER_FLAG_SEND_COMMUNITY)
5859 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5860 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
5861 }
5862
28c6e247
IR
5863 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5864 PEER_FLAG_SEND_COMMUNITY)
5865 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5866 PEER_FLAG_SEND_EXT_COMMUNITY)
5867 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5868 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5869}
5870
5871ALIAS_HIDDEN(
5872 no_neighbor_send_community_type,
5873 no_neighbor_send_community_type_hidden_cmd,
5874 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5875 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5876 "Send Community attribute to this neighbor\n"
5877 "Send Standard and Extended Community attributes\n"
5878 "Send Standard, Large and Extended Community attributes\n"
5879 "Send Extended Community attributes\n"
5880 "Send Standard Community attributes\n"
5881 "Send Large Community attributes\n")
596c17ba 5882
718e3744 5883/* neighbor soft-reconfig. */
28c6e247
IR
5884DEFUN (neighbor_soft_reconfiguration,
5885 neighbor_soft_reconfiguration_cmd,
5886 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5887 NEIGHBOR_STR
5888 NEIGHBOR_ADDR_STR2
5889 "Per neighbor soft reconfiguration\n"
5890 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 5891{
d62a17ae 5892 int idx_peer = 1;
28c6e247
IR
5893 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5894 bgp_node_safi(vty),
5895 PEER_FLAG_SOFT_RECONFIG);
718e3744 5896}
5897
d62a17ae 5898ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5899 neighbor_soft_reconfiguration_hidden_cmd,
5900 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5901 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5902 "Per neighbor soft reconfiguration\n"
5903 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5904
28c6e247
IR
5905DEFUN (no_neighbor_soft_reconfiguration,
5906 no_neighbor_soft_reconfiguration_cmd,
5907 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5908 NO_STR
5909 NEIGHBOR_STR
5910 NEIGHBOR_ADDR_STR2
5911 "Per neighbor soft reconfiguration\n"
5912 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 5913{
d62a17ae 5914 int idx_peer = 2;
28c6e247
IR
5915 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5916 bgp_node_afi(vty), bgp_node_safi(vty),
5917 PEER_FLAG_SOFT_RECONFIG);
718e3744 5918}
6b0655a2 5919
d62a17ae 5920ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5921 no_neighbor_soft_reconfiguration_hidden_cmd,
5922 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5923 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5924 "Per neighbor soft reconfiguration\n"
5925 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5926
28c6e247
IR
5927DEFUN (neighbor_route_reflector_client,
5928 neighbor_route_reflector_client_cmd,
5929 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5930 NEIGHBOR_STR
5931 NEIGHBOR_ADDR_STR2
5932 "Configure a neighbor as Route Reflector client\n")
718e3744 5933{
d62a17ae 5934 int idx_peer = 1;
28c6e247 5935 struct peer *peer;
718e3744 5936
5937
28c6e247
IR
5938 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5939 if (!peer)
d62a17ae 5940 return CMD_WARNING_CONFIG_FAILED;
718e3744 5941
28c6e247
IR
5942 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5943 bgp_node_safi(vty),
5944 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5945}
5946
d62a17ae 5947ALIAS_HIDDEN(neighbor_route_reflector_client,
5948 neighbor_route_reflector_client_hidden_cmd,
5949 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5950 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5951 "Configure a neighbor as Route Reflector client\n")
596c17ba 5952
28c6e247
IR
5953DEFUN (no_neighbor_route_reflector_client,
5954 no_neighbor_route_reflector_client_cmd,
5955 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5956 NO_STR
5957 NEIGHBOR_STR
5958 NEIGHBOR_ADDR_STR2
5959 "Configure a neighbor as Route Reflector client\n")
718e3744 5960{
d62a17ae 5961 int idx_peer = 2;
28c6e247
IR
5962 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5963 bgp_node_afi(vty), bgp_node_safi(vty),
5964 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5965}
6b0655a2 5966
d62a17ae 5967ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5968 no_neighbor_route_reflector_client_hidden_cmd,
5969 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5970 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5971 "Configure a neighbor as Route Reflector client\n")
596c17ba 5972
718e3744 5973/* neighbor route-server-client. */
28c6e247
IR
5974DEFUN (neighbor_route_server_client,
5975 neighbor_route_server_client_cmd,
5976 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5977 NEIGHBOR_STR
5978 NEIGHBOR_ADDR_STR2
5979 "Configure a neighbor as Route Server client\n")
718e3744 5980{
d62a17ae 5981 int idx_peer = 1;
28c6e247 5982 struct peer *peer;
f4b8ec07 5983
28c6e247
IR
5984 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5985 if (!peer)
d62a17ae 5986 return CMD_WARNING_CONFIG_FAILED;
28c6e247
IR
5987 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5988 bgp_node_safi(vty),
5989 PEER_FLAG_RSERVER_CLIENT);
718e3744 5990}
5991
d62a17ae 5992ALIAS_HIDDEN(neighbor_route_server_client,
5993 neighbor_route_server_client_hidden_cmd,
5994 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5995 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5996 "Configure a neighbor as Route Server client\n")
596c17ba 5997
28c6e247
IR
5998DEFUN (no_neighbor_route_server_client,
5999 no_neighbor_route_server_client_cmd,
6000 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6001 NO_STR
6002 NEIGHBOR_STR
6003 NEIGHBOR_ADDR_STR2
6004 "Configure a neighbor as Route Server client\n")
fee0f4c6 6005{
d62a17ae 6006 int idx_peer = 2;
28c6e247
IR
6007 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6008 bgp_node_afi(vty), bgp_node_safi(vty),
6009 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 6010}
6b0655a2 6011
d62a17ae 6012ALIAS_HIDDEN(no_neighbor_route_server_client,
6013 no_neighbor_route_server_client_hidden_cmd,
6014 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6015 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6016 "Configure a neighbor as Route Server client\n")
596c17ba 6017
fee0f4c6 6018DEFUN (neighbor_nexthop_local_unchanged,
6019 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6020 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6021 NEIGHBOR_STR
6022 NEIGHBOR_ADDR_STR2
6023 "Configure treatment of outgoing link-local nexthop attribute\n"
6024 "Leave link-local nexthop unchanged for this peer\n")
6025{
d62a17ae 6026 int idx_peer = 1;
6027 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6028 bgp_node_safi(vty),
6029 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6030}
6b0655a2 6031
fee0f4c6 6032DEFUN (no_neighbor_nexthop_local_unchanged,
6033 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6034 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6035 NO_STR
6036 NEIGHBOR_STR
6037 NEIGHBOR_ADDR_STR2
6038 "Configure treatment of outgoing link-local-nexthop attribute\n"
6039 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6040{
d62a17ae 6041 int idx_peer = 2;
6042 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6043 bgp_node_afi(vty), bgp_node_safi(vty),
6044 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6045}
6b0655a2 6046
28c6e247
IR
6047DEFUN (neighbor_attr_unchanged,
6048 neighbor_attr_unchanged_cmd,
6049 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6050 NEIGHBOR_STR
6051 NEIGHBOR_ADDR_STR2
6052 "BGP attribute is propagated unchanged to this neighbor\n"
6053 "As-path attribute\n"
6054 "Nexthop attribute\n"
6055 "Med attribute\n")
718e3744 6056{
d62a17ae 6057 int idx = 0;
8eeb0335 6058 char *peer_str = argv[1]->arg;
28c6e247 6059 struct peer *peer;
db45f64d
DS
6060 bool aspath = false;
6061 bool nexthop = false;
6062 bool med = false;
8eeb0335
DW
6063 afi_t afi = bgp_node_afi(vty);
6064 safi_t safi = bgp_node_safi(vty);
28c6e247 6065 int ret = 0;
f4b8ec07 6066
28c6e247
IR
6067 peer = peer_and_group_lookup_vty(vty, peer_str);
6068 if (!peer)
8eeb0335 6069 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6070
6071 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6072 aspath = true;
6073
d62a17ae 6074 idx = 0;
6075 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6076 nexthop = true;
6077
d62a17ae 6078 idx = 0;
6079 if (argv_find(argv, argc, "med", &idx))
db45f64d 6080 med = true;
d62a17ae 6081
8eeb0335 6082 /* no flags means all of them! */
db45f64d 6083 if (!aspath && !nexthop && !med) {
28c6e247
IR
6084 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6085 PEER_FLAG_AS_PATH_UNCHANGED);
6086 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6087 PEER_FLAG_NEXTHOP_UNCHANGED);
6088 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6089 PEER_FLAG_MED_UNCHANGED);
8eeb0335 6090 } else {
28c6e247
IR
6091 if (!aspath) {
6092 if (peer_af_flag_check(peer, afi, safi,
6093 PEER_FLAG_AS_PATH_UNCHANGED)) {
6094 ret |= peer_af_flag_unset_vty(
6095 vty, peer_str, afi, safi,
6096 PEER_FLAG_AS_PATH_UNCHANGED);
6097 }
6098 } else
6099 ret |= peer_af_flag_set_vty(
6100 vty, peer_str, afi, safi,
6101 PEER_FLAG_AS_PATH_UNCHANGED);
6102
6103 if (!nexthop) {
6104 if (peer_af_flag_check(peer, afi, safi,
6105 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6106 ret |= peer_af_flag_unset_vty(
6107 vty, peer_str, afi, safi,
6108 PEER_FLAG_NEXTHOP_UNCHANGED);
6109 }
6110 } else
6111 ret |= peer_af_flag_set_vty(
6112 vty, peer_str, afi, safi,
6113 PEER_FLAG_NEXTHOP_UNCHANGED);
6114
6115 if (!med) {
6116 if (peer_af_flag_check(peer, afi, safi,
6117 PEER_FLAG_MED_UNCHANGED)) {
6118 ret |= peer_af_flag_unset_vty(
6119 vty, peer_str, afi, safi,
6120 PEER_FLAG_MED_UNCHANGED);
6121 }
6122 } else
6123 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6124 PEER_FLAG_MED_UNCHANGED);
d62a17ae 6125 }
6126
28c6e247 6127 return ret;
d62a17ae 6128}
6129
6130ALIAS_HIDDEN(
6131 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6132 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6133 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6134 "BGP attribute is propagated unchanged to this neighbor\n"
6135 "As-path attribute\n"
6136 "Nexthop attribute\n"
6137 "Med attribute\n")
596c17ba 6138
28c6e247
IR
6139DEFUN (no_neighbor_attr_unchanged,
6140 no_neighbor_attr_unchanged_cmd,
6141 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6142 NO_STR
6143 NEIGHBOR_STR
6144 NEIGHBOR_ADDR_STR2
6145 "BGP attribute is propagated unchanged to this neighbor\n"
6146 "As-path attribute\n"
6147 "Nexthop attribute\n"
6148 "Med attribute\n")
718e3744 6149{
d62a17ae 6150 int idx = 0;
db45f64d 6151 char *peer_str = argv[2]->arg;
28c6e247 6152 struct peer *peer;
db45f64d
DS
6153 bool aspath = false;
6154 bool nexthop = false;
6155 bool med = false;
6156 afi_t afi = bgp_node_afi(vty);
6157 safi_t safi = bgp_node_safi(vty);
28c6e247 6158 int ret = 0;
f4b8ec07 6159
28c6e247
IR
6160 peer = peer_and_group_lookup_vty(vty, peer_str);
6161 if (!peer)
db45f64d 6162 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6163
6164 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6165 aspath = true;
6166
d62a17ae 6167 idx = 0;
6168 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6169 nexthop = true;
6170
d62a17ae 6171 idx = 0;
6172 if (argv_find(argv, argc, "med", &idx))
db45f64d 6173 med = true;
d62a17ae 6174
28c6e247
IR
6175 if (!aspath && !nexthop && !med) // no flags means all of them!
6176 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6177 PEER_FLAG_AS_PATH_UNCHANGED)
6178 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6179 PEER_FLAG_NEXTHOP_UNCHANGED)
6180 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6181 PEER_FLAG_MED_UNCHANGED);
db45f64d
DS
6182
6183 if (aspath)
28c6e247
IR
6184 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6185 PEER_FLAG_AS_PATH_UNCHANGED);
db45f64d
DS
6186
6187 if (nexthop)
28c6e247
IR
6188 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6189 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 6190
db45f64d 6191 if (med)
28c6e247
IR
6192 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6193 PEER_FLAG_MED_UNCHANGED);
db45f64d 6194
28c6e247 6195 return ret;
d62a17ae 6196}
6197
6198ALIAS_HIDDEN(
6199 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6200 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6201 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6202 "BGP attribute is propagated unchanged to this neighbor\n"
6203 "As-path attribute\n"
6204 "Nexthop attribute\n"
6205 "Med attribute\n")
718e3744 6206
28c6e247
IR
6207/* EBGP multihop configuration. */
6208static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6209 const char *ttl_str)
718e3744 6210{
28c6e247
IR
6211 struct peer *peer;
6212 unsigned int ttl;
718e3744 6213
28c6e247
IR
6214 peer = peer_and_group_lookup_vty(vty, ip_str);
6215 if (!peer)
d62a17ae 6216 return CMD_WARNING_CONFIG_FAILED;
718e3744 6217
28c6e247
IR
6218 if (peer->conf_if)
6219 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6220
6221 if (!ttl_str)
6222 ttl = MAXTTL;
6223 else
6224 ttl = strtoul(ttl_str, NULL, 10);
718e3744 6225
28c6e247 6226 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 6227}
6228
28c6e247 6229static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6230{
28c6e247 6231 struct peer *peer;
718e3744 6232
28c6e247
IR
6233 peer = peer_and_group_lookup_vty(vty, ip_str);
6234 if (!peer)
d62a17ae 6235 return CMD_WARNING_CONFIG_FAILED;
718e3744 6236
28c6e247 6237 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 6238}
6239
28c6e247
IR
6240/* neighbor ebgp-multihop. */
6241DEFUN (neighbor_ebgp_multihop,
6242 neighbor_ebgp_multihop_cmd,
6243 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6244 NEIGHBOR_STR
6245 NEIGHBOR_ADDR_STR2
6246 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6247{
28c6e247
IR
6248 int idx_peer = 1;
6249 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6250}
f4b8ec07 6251
28c6e247
IR
6252DEFUN (neighbor_ebgp_multihop_ttl,
6253 neighbor_ebgp_multihop_ttl_cmd,
6254 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6255 NEIGHBOR_STR
6256 NEIGHBOR_ADDR_STR2
6257 "Allow EBGP neighbors not on directly connected networks\n"
6258 "maximum hop count\n")
6259{
6260 int idx_peer = 1;
6261 int idx_number = 3;
6262 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6263 argv[idx_number]->arg);
6264}
f4b8ec07 6265
28c6e247
IR
6266DEFUN (no_neighbor_ebgp_multihop,
6267 no_neighbor_ebgp_multihop_cmd,
6268 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6269 NO_STR
6270 NEIGHBOR_STR
6271 NEIGHBOR_ADDR_STR2
6272 "Allow EBGP neighbors not on directly connected networks\n"
6273 "maximum hop count\n")
6274{
6275 int idx_peer = 2;
6276 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6277}
6278
6b0655a2 6279
6ffd2079 6280/* disable-connected-check */
28c6e247
IR
6281DEFUN (neighbor_disable_connected_check,
6282 neighbor_disable_connected_check_cmd,
6283 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6284 NEIGHBOR_STR
6285 NEIGHBOR_ADDR_STR2
6286 "one-hop away EBGP peer using loopback address\n"
6287 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6288{
d62a17ae 6289 int idx_peer = 1;
28c6e247
IR
6290 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6291 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6292}
6293
28c6e247
IR
6294DEFUN (no_neighbor_disable_connected_check,
6295 no_neighbor_disable_connected_check_cmd,
6296 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6297 NO_STR
6298 NEIGHBOR_STR
6299 NEIGHBOR_ADDR_STR2
6300 "one-hop away EBGP peer using loopback address\n"
6301 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6302{
d62a17ae 6303 int idx_peer = 2;
28c6e247
IR
6304 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6305 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6306}
6307
7ab294ea
DA
6308/* disable-link-bw-encoding-ieee */
6309DEFUN(neighbor_disable_link_bw_encoding_ieee,
6310 neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6311 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6312 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6313 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6314{
6315 int idx_peer = 1;
6316
6317 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6318 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6319}
6320
7ab294ea
DA
6321DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6322 no_neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6323 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6324 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6325 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6326{
6327 int idx_peer = 2;
6328
6329 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6330 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6331}
6332
d08c0c80
DA
6333/* extended-optional-parameters */
6334DEFUN(neighbor_extended_optional_parameters,
6335 neighbor_extended_optional_parameters_cmd,
6336 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6337 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6338 "Force the extended optional parameters format for OPEN messages\n")
6339{
6340 int idx_peer = 1;
6341
6342 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6343 PEER_FLAG_EXTENDED_OPT_PARAMS);
6344}
6345
6346DEFUN(no_neighbor_extended_optional_parameters,
6347 no_neighbor_extended_optional_parameters_cmd,
6348 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6349 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6350 "Force the extended optional parameters format for OPEN messages\n")
6351{
6352 int idx_peer = 2;
6353
6354 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6355 PEER_FLAG_EXTENDED_OPT_PARAMS);
6356}
47cbc09b
PM
6357
6358/* enforce-first-as */
28c6e247
IR
6359DEFUN (neighbor_enforce_first_as,
6360 neighbor_enforce_first_as_cmd,
6361 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6362 NEIGHBOR_STR
6363 NEIGHBOR_ADDR_STR2
6364 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6365{
6366 int idx_peer = 1;
f4b8ec07 6367
28c6e247
IR
6368 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6369 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6370}
6371
28c6e247
IR
6372DEFUN (no_neighbor_enforce_first_as,
6373 no_neighbor_enforce_first_as_cmd,
6374 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6375 NO_STR
6376 NEIGHBOR_STR
6377 NEIGHBOR_ADDR_STR2
6378 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6379{
6380 int idx_peer = 2;
f4b8ec07 6381
28c6e247
IR
6382 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6383 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6384}
6385
6386
28c6e247
IR
6387DEFUN (neighbor_description,
6388 neighbor_description_cmd,
6389 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6390 NEIGHBOR_STR
6391 NEIGHBOR_ADDR_STR2
6392 "Neighbor specific description\n"
6393 "Up to 80 characters describing this neighbor\n")
718e3744 6394{
d62a17ae 6395 int idx_peer = 1;
6396 int idx_line = 3;
28c6e247 6397 struct peer *peer;
d62a17ae 6398 char *str;
718e3744 6399
28c6e247
IR
6400 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6401 if (!peer)
d62a17ae 6402 return CMD_WARNING_CONFIG_FAILED;
718e3744 6403
d62a17ae 6404 str = argv_concat(argv, argc, idx_line);
718e3744 6405
28c6e247 6406 peer_description_set(peer, str);
718e3744 6407
d62a17ae 6408 XFREE(MTYPE_TMP, str);
718e3744 6409
28c6e247 6410 return CMD_SUCCESS;
718e3744 6411}
6412
28c6e247
IR
6413DEFUN (no_neighbor_description,
6414 no_neighbor_description_cmd,
6415 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6416 NO_STR
6417 NEIGHBOR_STR
6418 NEIGHBOR_ADDR_STR2
6419 "Neighbor specific description\n")
718e3744 6420{
d62a17ae 6421 int idx_peer = 2;
28c6e247 6422 struct peer *peer;
f4b8ec07 6423
28c6e247
IR
6424 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6425 if (!peer)
d62a17ae 6426 return CMD_WARNING_CONFIG_FAILED;
718e3744 6427
28c6e247 6428 peer_description_unset(peer);
718e3744 6429
28c6e247 6430 return CMD_SUCCESS;
718e3744 6431}
6432
1d80f243 6433ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
6434 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6435 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6436 "Neighbor specific description\n"
6437 "Up to 80 characters describing this neighbor\n")
6b0655a2 6438
28c6e247
IR
6439/* Neighbor update-source. */
6440static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6441 const char *source_str)
6442{
6443 struct peer *peer;
6444 struct prefix p;
6445 union sockunion su;
6446
6447 peer = peer_and_group_lookup_vty(vty, peer_str);
6448 if (!peer)
6449 return CMD_WARNING_CONFIG_FAILED;
6450
6451 if (peer->conf_if)
6452 return CMD_WARNING;
6453
6454 if (source_str) {
6455 if (str2sockunion(source_str, &su) == 0)
6456 peer_update_source_addr_set(peer, &su);
6457 else {
6458 if (str2prefix(source_str, &p)) {
6459 vty_out(vty,
6460 "%% Invalid update-source, remove prefix length \n");
6461 return CMD_WARNING_CONFIG_FAILED;
6462 } else
6463 peer_update_source_if_set(peer, source_str);
6464 }
6465 } else
6466 peer_update_source_unset(peer);
6467
6468 return CMD_SUCCESS;
6469}
6470
d62a17ae 6471#define BGP_UPDATE_SOURCE_HELP_STR \
6472 "IPv4 address\n" \
6473 "IPv6 address\n" \
6474 "Interface name (requires zebra to be running)\n"
369688c0 6475
28c6e247
IR
6476DEFUN (neighbor_update_source,
6477 neighbor_update_source_cmd,
6478 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6479 NEIGHBOR_STR
6480 NEIGHBOR_ADDR_STR2
6481 "Source of routing updates\n"
6482 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6483{
d62a17ae 6484 int idx_peer = 1;
6485 int idx_peer_2 = 3;
28c6e247 6486 return peer_update_source_vty(vty, argv[idx_peer]->arg,
d62a17ae 6487 argv[idx_peer_2]->arg);
718e3744 6488}
6489
28c6e247
IR
6490DEFUN (no_neighbor_update_source,
6491 no_neighbor_update_source_cmd,
6492 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6493 NO_STR
6494 NEIGHBOR_STR
6495 NEIGHBOR_ADDR_STR2
6496 "Source of routing updates\n"
6497 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6498{
d62a17ae 6499 int idx_peer = 2;
28c6e247 6500 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6501}
6b0655a2 6502
d62a17ae 6503static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6504 afi_t afi, safi_t safi,
6505 const char *rmap, int set)
718e3744 6506{
d62a17ae 6507 int ret;
6508 struct peer *peer;
80912664 6509 struct route_map *route_map = NULL;
718e3744 6510
d62a17ae 6511 peer = peer_and_group_lookup_vty(vty, peer_str);
6512 if (!peer)
6513 return CMD_WARNING_CONFIG_FAILED;
718e3744 6514
1de27621 6515 if (set) {
80912664
DS
6516 if (rmap)
6517 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
6518 ret = peer_default_originate_set(peer, afi, safi,
6519 rmap, route_map);
6520 } else
d62a17ae 6521 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 6522
d62a17ae 6523 return bgp_vty_return(vty, ret);
718e3744 6524}
6525
6526/* neighbor default-originate. */
6527DEFUN (neighbor_default_originate,
6528 neighbor_default_originate_cmd,
9ccf14f7 6529 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 6530 NEIGHBOR_STR
6531 NEIGHBOR_ADDR_STR2
6532 "Originate default route to this neighbor\n")
6533{
d62a17ae 6534 int idx_peer = 1;
6535 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6536 bgp_node_afi(vty),
6537 bgp_node_safi(vty), NULL, 1);
718e3744 6538}
6539
d62a17ae 6540ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6541 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6542 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6543 "Originate default route to this neighbor\n")
596c17ba 6544
718e3744 6545DEFUN (neighbor_default_originate_rmap,
6546 neighbor_default_originate_rmap_cmd,
9ccf14f7 6547 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 6548 NEIGHBOR_STR
6549 NEIGHBOR_ADDR_STR2
6550 "Originate default route to this neighbor\n"
6551 "Route-map to specify criteria to originate default\n"
6552 "route-map name\n")
6553{
d62a17ae 6554 int idx_peer = 1;
6555 int idx_word = 4;
6556 return peer_default_originate_set_vty(
6557 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6558 argv[idx_word]->arg, 1);
718e3744 6559}
6560
d62a17ae 6561ALIAS_HIDDEN(
6562 neighbor_default_originate_rmap,
6563 neighbor_default_originate_rmap_hidden_cmd,
6564 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6565 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6566 "Originate default route to this neighbor\n"
6567 "Route-map to specify criteria to originate default\n"
6568 "route-map name\n")
596c17ba 6569
718e3744 6570DEFUN (no_neighbor_default_originate,
6571 no_neighbor_default_originate_cmd,
a636c635 6572 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 6573 NO_STR
6574 NEIGHBOR_STR
6575 NEIGHBOR_ADDR_STR2
a636c635
DW
6576 "Originate default route to this neighbor\n"
6577 "Route-map to specify criteria to originate default\n"
6578 "route-map name\n")
718e3744 6579{
d62a17ae 6580 int idx_peer = 2;
6581 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6582 bgp_node_afi(vty),
6583 bgp_node_safi(vty), NULL, 0);
718e3744 6584}
6585
d62a17ae 6586ALIAS_HIDDEN(
6587 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6588 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6589 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6590 "Originate default route to this neighbor\n"
6591 "Route-map to specify criteria to originate default\n"
6592 "route-map name\n")
596c17ba 6593
6b0655a2 6594
28c6e247
IR
6595/* Set neighbor's BGP port. */
6596static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6597 const char *port_str)
718e3744 6598{
28c6e247
IR
6599 struct peer *peer;
6600 uint16_t port;
6601 struct servent *sp;
6602
6603 peer = peer_lookup_vty(vty, ip_str);
6604 if (!peer)
6605 return CMD_WARNING_CONFIG_FAILED;
6606
6607 if (!port_str) {
6608 sp = getservbyname("bgp", "tcp");
6609 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6610 } else {
6611 port = strtoul(port_str, NULL, 10);
6612 }
718e3744 6613
28c6e247 6614 peer_port_set(peer, port);
718e3744 6615
28c6e247
IR
6616 return CMD_SUCCESS;
6617}
f4b8ec07 6618
28c6e247
IR
6619/* Set specified peer's BGP port. */
6620DEFUN (neighbor_port,
6621 neighbor_port_cmd,
6622 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
6623 NEIGHBOR_STR
6624 NEIGHBOR_ADDR_STR
6625 "Neighbor's BGP port\n"
6626 "TCP port number\n")
6627{
6628 int idx_ip = 1;
6629 int idx_number = 3;
6630 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6631 argv[idx_number]->arg);
f4b8ec07 6632}
6b0655a2 6633
28c6e247
IR
6634DEFUN (no_neighbor_port,
6635 no_neighbor_port_cmd,
6636 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
6637 NO_STR
6638 NEIGHBOR_STR
6639 NEIGHBOR_ADDR_STR
6640 "Neighbor's BGP port\n"
6641 "TCP port number\n")
718e3744 6642{
f4b8ec07 6643 int idx_ip = 2;
28c6e247
IR
6644 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6645}
6646
6647
6648/* neighbor weight. */
6649static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6650 safi_t safi, const char *weight_str)
6651{
6652 int ret;
6653 struct peer *peer;
6654 unsigned long weight;
718e3744 6655
28c6e247
IR
6656 peer = peer_and_group_lookup_vty(vty, ip_str);
6657 if (!peer)
6658 return CMD_WARNING_CONFIG_FAILED;
718e3744 6659
28c6e247 6660 weight = strtoul(weight_str, NULL, 10);
718e3744 6661
28c6e247
IR
6662 ret = peer_weight_set(peer, afi, safi, weight);
6663 return bgp_vty_return(vty, ret);
718e3744 6664}
6665
28c6e247
IR
6666static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6667 safi_t safi)
718e3744 6668{
28c6e247
IR
6669 int ret;
6670 struct peer *peer;
f4b8ec07 6671
28c6e247
IR
6672 peer = peer_and_group_lookup_vty(vty, ip_str);
6673 if (!peer)
d62a17ae 6674 return CMD_WARNING_CONFIG_FAILED;
718e3744 6675
28c6e247
IR
6676 ret = peer_weight_unset(peer, afi, safi);
6677 return bgp_vty_return(vty, ret);
6678}
f4b8ec07 6679
28c6e247
IR
6680DEFUN (neighbor_weight,
6681 neighbor_weight_cmd,
6682 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6683 NEIGHBOR_STR
6684 NEIGHBOR_ADDR_STR2
6685 "Set default weight for routes from this neighbor\n"
6686 "default weight\n")
6687{
6688 int idx_peer = 1;
6689 int idx_number = 3;
6690 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6691 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 6692}
6693
d62a17ae 6694ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6695 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6696 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6697 "Set default weight for routes from this neighbor\n"
6698 "default weight\n")
596c17ba 6699
28c6e247
IR
6700DEFUN (no_neighbor_weight,
6701 no_neighbor_weight_cmd,
6702 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6703 NO_STR
6704 NEIGHBOR_STR
6705 NEIGHBOR_ADDR_STR2
6706 "Set default weight for routes from this neighbor\n"
6707 "default weight\n")
718e3744 6708{
d62a17ae 6709 int idx_peer = 2;
28c6e247
IR
6710 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6711 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 6712}
6713
d62a17ae 6714ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6715 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6716 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6717 "Set default weight for routes from this neighbor\n"
6718 "default weight\n")
596c17ba 6719
6b0655a2 6720
718e3744 6721/* Override capability negotiation. */
c36bc05f
IR
6722DEFUN (neighbor_override_capability,
6723 neighbor_override_capability_cmd,
6724 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6725 NEIGHBOR_STR
6726 NEIGHBOR_ADDR_STR2
6727 "Override capability negotiation result\n")
718e3744 6728{
d62a17ae 6729 int idx_peer = 1;
c36bc05f
IR
6730 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6731 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6732}
6733
c36bc05f
IR
6734DEFUN (no_neighbor_override_capability,
6735 no_neighbor_override_capability_cmd,
6736 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6737 NO_STR
6738 NEIGHBOR_STR
6739 NEIGHBOR_ADDR_STR2
6740 "Override capability negotiation result\n")
718e3744 6741{
d62a17ae 6742 int idx_peer = 2;
c36bc05f
IR
6743 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6744 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6745}
6b0655a2 6746
c36bc05f
IR
6747DEFUN (neighbor_strict_capability,
6748 neighbor_strict_capability_cmd,
6749 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6750 NEIGHBOR_STR
6751 NEIGHBOR_ADDR_STR2
6752 "Strict capability negotiation match\n")
718e3744 6753{
9fb964de
PM
6754 int idx_peer = 1;
6755
c36bc05f
IR
6756 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6757 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6758}
6759
c36bc05f
IR
6760DEFUN (no_neighbor_strict_capability,
6761 no_neighbor_strict_capability_cmd,
6762 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6763 NO_STR
6764 NEIGHBOR_STR
6765 NEIGHBOR_ADDR_STR2
6766 "Strict capability negotiation match\n")
718e3744 6767{
9fb964de 6768 int idx_peer = 2;
8611c7f3 6769
c36bc05f
IR
6770 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6771 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6772}
6b0655a2 6773
28c6e247
IR
6774static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6775 const char *keep_str, const char *hold_str)
718e3744 6776{
28c6e247
IR
6777 int ret;
6778 struct peer *peer;
6779 uint32_t keepalive;
6780 uint32_t holdtime;
718e3744 6781
28c6e247
IR
6782 peer = peer_and_group_lookup_vty(vty, ip_str);
6783 if (!peer)
d62a17ae 6784 return CMD_WARNING_CONFIG_FAILED;
718e3744 6785
28c6e247
IR
6786 keepalive = strtoul(keep_str, NULL, 10);
6787 holdtime = strtoul(hold_str, NULL, 10);
718e3744 6788
28c6e247 6789 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 6790
28c6e247 6791 return bgp_vty_return(vty, ret);
718e3744 6792}
6b0655a2 6793
28c6e247 6794static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6795{
28c6e247
IR
6796 int ret;
6797 struct peer *peer;
718e3744 6798
28c6e247
IR
6799 peer = peer_and_group_lookup_vty(vty, ip_str);
6800 if (!peer)
d62a17ae 6801 return CMD_WARNING_CONFIG_FAILED;
718e3744 6802
28c6e247 6803 ret = peer_timers_unset(peer);
718e3744 6804
28c6e247 6805 return bgp_vty_return(vty, ret);
718e3744 6806}
6b0655a2 6807
28c6e247
IR
6808DEFUN (neighbor_timers,
6809 neighbor_timers_cmd,
6810 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
6811 NEIGHBOR_STR
6812 NEIGHBOR_ADDR_STR2
6813 "BGP per neighbor timers\n"
6814 "Keepalive interval\n"
6815 "Holdtime\n")
718e3744 6816{
f4b8ec07 6817 int idx_peer = 1;
28c6e247
IR
6818 int idx_number = 3;
6819 int idx_number_2 = 4;
6820 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6821 argv[idx_number]->arg,
6822 argv[idx_number_2]->arg);
6823}
6824
6825DEFUN (no_neighbor_timers,
6826 no_neighbor_timers_cmd,
6827 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
6828 NO_STR
6829 NEIGHBOR_STR
6830 NEIGHBOR_ADDR_STR2
6831 "BGP per neighbor timers\n"
6832 "Keepalive interval\n"
6833 "Holdtime\n")
6834{
6835 int idx_peer = 2;
6836 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
6837}
6838
6839
6840static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6841 const char *time_str)
6842{
6843 int ret;
6844 struct peer *peer;
6845 uint32_t connect;
718e3744 6846
28c6e247
IR
6847 peer = peer_and_group_lookup_vty(vty, ip_str);
6848 if (!peer)
d62a17ae 6849 return CMD_WARNING_CONFIG_FAILED;
718e3744 6850
28c6e247
IR
6851 connect = strtoul(time_str, NULL, 10);
6852
6853 ret = peer_timers_connect_set(peer, connect);
718e3744 6854
28c6e247 6855 return bgp_vty_return(vty, ret);
718e3744 6856}
6857
28c6e247 6858static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6859{
28c6e247
IR
6860 int ret;
6861 struct peer *peer;
718e3744 6862
28c6e247
IR
6863 peer = peer_and_group_lookup_vty(vty, ip_str);
6864 if (!peer)
d62a17ae 6865 return CMD_WARNING_CONFIG_FAILED;
718e3744 6866
28c6e247
IR
6867 ret = peer_timers_connect_unset(peer);
6868
6869 return bgp_vty_return(vty, ret);
6870}
6871
6872DEFUN (neighbor_timers_connect,
6873 neighbor_timers_connect_cmd,
6874 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
6875 NEIGHBOR_STR
6876 NEIGHBOR_ADDR_STR2
6877 "BGP per neighbor timers\n"
6878 "BGP connect timer\n"
6879 "Connect timer\n")
6880{
6881 int idx_peer = 1;
6882 int idx_number = 4;
6883 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6884 argv[idx_number]->arg);
6885}
718e3744 6886
28c6e247
IR
6887DEFUN (no_neighbor_timers_connect,
6888 no_neighbor_timers_connect_cmd,
6889 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
6890 NO_STR
6891 NEIGHBOR_STR
6892 NEIGHBOR_ADDR_STR2
6893 "BGP per neighbor timers\n"
6894 "BGP connect timer\n"
6895 "Connect timer\n")
6896{
6897 int idx_peer = 2;
6898 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6899}
6900
d43114f3
DS
6901DEFPY (neighbor_timers_delayopen,
6902 neighbor_timers_delayopen_cmd,
6903 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
6904 NEIGHBOR_STR
6905 NEIGHBOR_ADDR_STR2
6906 "BGP per neighbor timers\n"
6907 "RFC 4271 DelayOpenTimer\n"
6908 "DelayOpenTime timer interval\n")
6909{
6910 struct peer *peer;
6911
6912 peer = peer_and_group_lookup_vty(vty, neighbor);
6913 if (!peer)
6914 return CMD_WARNING_CONFIG_FAILED;
6915
6916 if (!interval) {
6917 if (peer_timers_delayopen_unset(peer))
6918 return CMD_WARNING_CONFIG_FAILED;
6919 } else {
6920 if (peer_timers_delayopen_set(peer, interval))
6921 return CMD_WARNING_CONFIG_FAILED;
6922 }
6923
6924 return CMD_SUCCESS;
6925}
6926
6927DEFPY (no_neighbor_timers_delayopen,
6928 no_neighbor_timers_delayopen_cmd,
6929 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
6930 NO_STR
6931 NEIGHBOR_STR
6932 NEIGHBOR_ADDR_STR2
6933 "BGP per neighbor timers\n"
6934 "RFC 4271 DelayOpenTimer\n"
6935 "DelayOpenTime timer interval\n")
6936{
6937 struct peer *peer;
6938
6939 peer = peer_and_group_lookup_vty(vty, neighbor);
6940 if (!peer)
6941 return CMD_WARNING_CONFIG_FAILED;
6942
6943 if (peer_timers_delayopen_unset(peer))
6944 return CMD_WARNING_CONFIG_FAILED;
6945
6946 return CMD_SUCCESS;
6947}
6948
28c6e247
IR
6949static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
6950 const char *time_str, int set)
718e3744 6951{
28c6e247
IR
6952 int ret;
6953 struct peer *peer;
6954 uint32_t routeadv = 0;
718e3744 6955
28c6e247
IR
6956 peer = peer_and_group_lookup_vty(vty, ip_str);
6957 if (!peer)
d62a17ae 6958 return CMD_WARNING_CONFIG_FAILED;
718e3744 6959
28c6e247
IR
6960 if (time_str)
6961 routeadv = strtoul(time_str, NULL, 10);
6962
6963 if (set)
6964 ret = peer_advertise_interval_set(peer, routeadv);
6965 else
6966 ret = peer_advertise_interval_unset(peer);
718e3744 6967
28c6e247 6968 return bgp_vty_return(vty, ret);
718e3744 6969}
6970
28c6e247
IR
6971DEFUN (neighbor_advertise_interval,
6972 neighbor_advertise_interval_cmd,
6973 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
6974 NEIGHBOR_STR
6975 NEIGHBOR_ADDR_STR2
6976 "Minimum interval between sending BGP routing updates\n"
6977 "time in seconds\n")
718e3744 6978{
28c6e247
IR
6979 int idx_peer = 1;
6980 int idx_number = 3;
6981 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
6982 argv[idx_number]->arg, 1);
6983}
f4b8ec07 6984
28c6e247
IR
6985DEFUN (no_neighbor_advertise_interval,
6986 no_neighbor_advertise_interval_cmd,
6987 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
6988 NO_STR
6989 NEIGHBOR_STR
6990 NEIGHBOR_ADDR_STR2
6991 "Minimum interval between sending BGP routing updates\n"
6992 "time in seconds\n")
6993{
6994 int idx_peer = 2;
6995 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 6996}
6997
6b0655a2 6998
518f0eb1
DS
6999/* Time to wait before processing route-map updates */
7000DEFUN (bgp_set_route_map_delay_timer,
7001 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7002 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7003 SET_STR
7004 "BGP route-map delay timer\n"
7005 "Time in secs to wait before processing route-map changes\n"
f414725f 7006 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7007{
d62a17ae 7008 int idx_number = 3;
d7c0a89a 7009 uint32_t rmap_delay_timer;
d62a17ae 7010
7011 if (argv[idx_number]->arg) {
7012 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7013 bm->rmap_update_timer = rmap_delay_timer;
7014
7015 /* if the dynamic update handling is being disabled, and a timer
7016 * is
7017 * running, stop the timer and act as if the timer has already
7018 * fired.
7019 */
7020 if (!rmap_delay_timer && bm->t_rmap_update) {
7021 BGP_TIMER_OFF(bm->t_rmap_update);
7022 thread_execute(bm->master, bgp_route_map_update_timer,
7023 NULL, 0);
7024 }
7025 return CMD_SUCCESS;
7026 } else {
7027 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7028 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7029 }
518f0eb1
DS
7030}
7031
7032DEFUN (no_bgp_set_route_map_delay_timer,
7033 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7034 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7035 NO_STR
3a2d747c 7036 BGP_STR
518f0eb1 7037 "Default BGP route-map delay timer\n"
8334fd5a
DW
7038 "Reset to default time to wait for processing route-map changes\n"
7039 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7040{
518f0eb1 7041
d62a17ae 7042 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7043
d62a17ae 7044 return CMD_SUCCESS;
518f0eb1
DS
7045}
7046
28c6e247
IR
7047/* neighbor interface */
7048static int peer_interface_vty(struct vty *vty, const char *ip_str,
7049 const char *str)
718e3744 7050{
28c6e247 7051 struct peer *peer;
718e3744 7052
28c6e247
IR
7053 peer = peer_lookup_vty(vty, ip_str);
7054 if (!peer || peer->conf_if) {
7055 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7056 return CMD_WARNING_CONFIG_FAILED;
7057 }
718e3744 7058
28c6e247
IR
7059 if (str)
7060 peer_interface_set(peer, str);
7061 else
7062 peer_interface_unset(peer);
718e3744 7063
28c6e247 7064 return CMD_SUCCESS;
718e3744 7065}
7066
28c6e247
IR
7067DEFUN (neighbor_interface,
7068 neighbor_interface_cmd,
7069 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7070 NEIGHBOR_STR
7071 NEIGHBOR_ADDR_STR
7072 "Interface\n"
7073 "Interface name\n")
718e3744 7074{
28c6e247
IR
7075 int idx_ip = 1;
7076 int idx_word = 3;
294d8425 7077
28c6e247
IR
7078 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7079}
f4b8ec07 7080
28c6e247
IR
7081DEFUN (no_neighbor_interface,
7082 no_neighbor_interface_cmd,
294d8425 7083 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
28c6e247
IR
7084 NO_STR
7085 NEIGHBOR_STR
294d8425 7086 NEIGHBOR_ADDR_STR
28c6e247
IR
7087 "Interface\n"
7088 "Interface name\n")
7089{
7090 int idx_peer = 2;
294d8425 7091
28c6e247 7092 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 7093}
6b0655a2 7094
718e3744 7095DEFUN (neighbor_distribute_list,
7096 neighbor_distribute_list_cmd,
c60dec36 7097 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7098 NEIGHBOR_STR
7099 NEIGHBOR_ADDR_STR2
7100 "Filter updates to/from this neighbor\n"
718e3744 7101 "IP Access-list name\n"
7102 "Filter incoming updates\n"
7103 "Filter outgoing updates\n")
7104{
d62a17ae 7105 int idx_peer = 1;
7106 int idx_acl = 3;
7107 int direct, ret;
7108 struct peer *peer;
a8206004 7109
d62a17ae 7110 const char *pstr = argv[idx_peer]->arg;
7111 const char *acl = argv[idx_acl]->arg;
7112 const char *inout = argv[argc - 1]->text;
a8206004 7113
d62a17ae 7114 peer = peer_and_group_lookup_vty(vty, pstr);
7115 if (!peer)
7116 return CMD_WARNING_CONFIG_FAILED;
a8206004 7117
d62a17ae 7118 /* Check filter direction. */
7119 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7120 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7121 direct, acl);
a8206004 7122
d62a17ae 7123 return bgp_vty_return(vty, ret);
718e3744 7124}
7125
d62a17ae 7126ALIAS_HIDDEN(
7127 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
c60dec36 7128 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7129 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7130 "Filter updates to/from this neighbor\n"
d62a17ae 7131 "IP Access-list name\n"
7132 "Filter incoming updates\n"
7133 "Filter outgoing updates\n")
596c17ba 7134
718e3744 7135DEFUN (no_neighbor_distribute_list,
7136 no_neighbor_distribute_list_cmd,
c60dec36 7137 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7138 NO_STR
7139 NEIGHBOR_STR
7140 NEIGHBOR_ADDR_STR2
7141 "Filter updates to/from this neighbor\n"
718e3744 7142 "IP Access-list name\n"
7143 "Filter incoming updates\n"
7144 "Filter outgoing updates\n")
7145{
d62a17ae 7146 int idx_peer = 2;
7147 int direct, ret;
7148 struct peer *peer;
a8206004 7149
d62a17ae 7150 const char *pstr = argv[idx_peer]->arg;
7151 const char *inout = argv[argc - 1]->text;
a8206004 7152
d62a17ae 7153 peer = peer_and_group_lookup_vty(vty, pstr);
7154 if (!peer)
7155 return CMD_WARNING_CONFIG_FAILED;
a8206004 7156
d62a17ae 7157 /* Check filter direction. */
7158 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7159 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7160 direct);
a8206004 7161
d62a17ae 7162 return bgp_vty_return(vty, ret);
718e3744 7163}
6b0655a2 7164
d62a17ae 7165ALIAS_HIDDEN(
7166 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
c60dec36 7167 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7168 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7169 "Filter updates to/from this neighbor\n"
d62a17ae 7170 "IP Access-list name\n"
7171 "Filter incoming updates\n"
7172 "Filter outgoing updates\n")
596c17ba 7173
718e3744 7174/* Set prefix list to the peer. */
642ef664
IR
7175static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7176 afi_t afi, safi_t safi,
7177 const char *name_str,
7178 const char *direct_str)
718e3744 7179{
642ef664
IR
7180 int ret;
7181 int direct = FILTER_IN;
7182 struct peer *peer;
718e3744 7183
642ef664
IR
7184 peer = peer_and_group_lookup_vty(vty, ip_str);
7185 if (!peer)
d62a17ae 7186 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7187
642ef664
IR
7188 /* Check filter direction. */
7189 if (strncmp(direct_str, "i", 1) == 0)
7190 direct = FILTER_IN;
7191 else if (strncmp(direct_str, "o", 1) == 0)
7192 direct = FILTER_OUT;
718e3744 7193
642ef664 7194 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 7195
642ef664
IR
7196 return bgp_vty_return(vty, ret);
7197}
7198
7199static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7200 afi_t afi, safi_t safi,
7201 const char *direct_str)
7202{
7203 int ret;
7204 struct peer *peer;
7205 int direct = FILTER_IN;
7206
7207 peer = peer_and_group_lookup_vty(vty, ip_str);
7208 if (!peer)
7209 return CMD_WARNING_CONFIG_FAILED;
7210
7211 /* Check filter direction. */
7212 if (strncmp(direct_str, "i", 1) == 0)
7213 direct = FILTER_IN;
7214 else if (strncmp(direct_str, "o", 1) == 0)
7215 direct = FILTER_OUT;
7216
7217 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7218
7219 return bgp_vty_return(vty, ret);
7220}
7221
7222DEFUN (neighbor_prefix_list,
7223 neighbor_prefix_list_cmd,
7224 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7225 NEIGHBOR_STR
7226 NEIGHBOR_ADDR_STR2
7227 "Filter updates to/from this neighbor\n"
7228 "Name of a prefix list\n"
7229 "Filter incoming updates\n"
7230 "Filter outgoing updates\n")
7231{
7232 int idx_peer = 1;
7233 int idx_word = 3;
7234 int idx_in_out = 4;
7235 return peer_prefix_list_set_vty(
7236 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7237 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7238}
7239
d62a17ae 7240ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7241 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7242 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7243 "Filter updates to/from this neighbor\n"
7244 "Name of a prefix list\n"
7245 "Filter incoming updates\n"
7246 "Filter outgoing updates\n")
596c17ba 7247
642ef664
IR
7248DEFUN (no_neighbor_prefix_list,
7249 no_neighbor_prefix_list_cmd,
7250 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7251 NO_STR
7252 NEIGHBOR_STR
7253 NEIGHBOR_ADDR_STR2
7254 "Filter updates to/from this neighbor\n"
7255 "Name of a prefix list\n"
7256 "Filter incoming updates\n"
7257 "Filter outgoing updates\n")
7258{
7259 int idx_peer = 2;
7260 int idx_in_out = 5;
7261 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7262 bgp_node_afi(vty), bgp_node_safi(vty),
7263 argv[idx_in_out]->arg);
7264}
7265
7266ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7267 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7268 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7269 "Filter updates to/from this neighbor\n"
7270 "Name of a prefix list\n"
7271 "Filter incoming updates\n"
7272 "Filter outgoing updates\n")
7273
d62a17ae 7274static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7275 safi_t safi, const char *name_str,
7276 const char *direct_str)
718e3744 7277{
d62a17ae 7278 int ret;
7279 struct peer *peer;
7280 int direct = FILTER_IN;
718e3744 7281
d62a17ae 7282 peer = peer_and_group_lookup_vty(vty, ip_str);
7283 if (!peer)
7284 return CMD_WARNING_CONFIG_FAILED;
718e3744 7285
d62a17ae 7286 /* Check filter direction. */
7287 if (strncmp(direct_str, "i", 1) == 0)
7288 direct = FILTER_IN;
7289 else if (strncmp(direct_str, "o", 1) == 0)
7290 direct = FILTER_OUT;
718e3744 7291
d62a17ae 7292 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7293
d62a17ae 7294 return bgp_vty_return(vty, ret);
718e3744 7295}
7296
d62a17ae 7297static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7298 safi_t safi, const char *direct_str)
718e3744 7299{
d62a17ae 7300 int ret;
7301 struct peer *peer;
7302 int direct = FILTER_IN;
718e3744 7303
d62a17ae 7304 peer = peer_and_group_lookup_vty(vty, ip_str);
7305 if (!peer)
7306 return CMD_WARNING_CONFIG_FAILED;
718e3744 7307
d62a17ae 7308 /* Check filter direction. */
7309 if (strncmp(direct_str, "i", 1) == 0)
7310 direct = FILTER_IN;
7311 else if (strncmp(direct_str, "o", 1) == 0)
7312 direct = FILTER_OUT;
718e3744 7313
d62a17ae 7314 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7315
d62a17ae 7316 return bgp_vty_return(vty, ret);
718e3744 7317}
7318
7319DEFUN (neighbor_filter_list,
7320 neighbor_filter_list_cmd,
de71d43e 7321 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7322 NEIGHBOR_STR
7323 NEIGHBOR_ADDR_STR2
7324 "Establish BGP filters\n"
7325 "AS path access-list name\n"
7326 "Filter incoming routes\n"
7327 "Filter outgoing routes\n")
7328{
d62a17ae 7329 int idx_peer = 1;
7330 int idx_word = 3;
7331 int idx_in_out = 4;
7332 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7333 bgp_node_safi(vty), argv[idx_word]->arg,
7334 argv[idx_in_out]->arg);
718e3744 7335}
7336
d62a17ae 7337ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
de71d43e 7338 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7339 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7340 "Establish BGP filters\n"
7341 "AS path access-list name\n"
7342 "Filter incoming routes\n"
7343 "Filter outgoing routes\n")
596c17ba 7344
718e3744 7345DEFUN (no_neighbor_filter_list,
7346 no_neighbor_filter_list_cmd,
de71d43e 7347 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7348 NO_STR
7349 NEIGHBOR_STR
7350 NEIGHBOR_ADDR_STR2
7351 "Establish BGP filters\n"
7352 "AS path access-list name\n"
7353 "Filter incoming routes\n"
7354 "Filter outgoing routes\n")
7355{
d62a17ae 7356 int idx_peer = 2;
7357 int idx_in_out = 5;
7358 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7359 bgp_node_afi(vty), bgp_node_safi(vty),
7360 argv[idx_in_out]->arg);
718e3744 7361}
6b0655a2 7362
d62a17ae 7363ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
de71d43e 7364 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7365 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7366 "Establish BGP filters\n"
7367 "AS path access-list name\n"
7368 "Filter incoming routes\n"
7369 "Filter outgoing routes\n")
596c17ba 7370
7f7940e6
MK
7371/* Set advertise-map to the peer. */
7372static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7373 afi_t afi, safi_t safi,
cf2ad4d8
MK
7374 const char *advertise_str,
7375 const char *condition_str, bool condition,
7376 bool set)
7f7940e6
MK
7377{
7378 int ret = CMD_WARNING_CONFIG_FAILED;
7379 struct peer *peer;
7380 struct route_map *advertise_map;
7381 struct route_map *condition_map;
7382
7383 peer = peer_and_group_lookup_vty(vty, ip_str);
7384 if (!peer)
7385 return ret;
7386
7387 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7388 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7389
cf2ad4d8
MK
7390 if (set)
7391 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7392 advertise_map, condition_str,
7393 condition_map, condition);
7394 else
7395 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7396 advertise_map, condition_str,
7397 condition_map, condition);
7f7940e6
MK
7398
7399 return bgp_vty_return(vty, ret);
7400}
7401
389e4f92
QY
7402DEFPY (bgp_condadv_period,
7403 bgp_condadv_period_cmd,
7404 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7405 NO_STR
7406 BGP_STR
7407 "Conditional advertisement settings\n"
7408 "Set period to rescan BGP table to check if condition is met\n"
7409 "Period between BGP table scans, in seconds; default 60\n")
7410{
7411 VTY_DECLVAR_CONTEXT(bgp, bgp);
7412
7413 bgp->condition_check_period =
7414 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7415
7416 return CMD_SUCCESS;
7417}
7418
cf2ad4d8 7419DEFPY (neighbor_advertise_map,
7f7940e6 7420 neighbor_advertise_map_cmd,
52b84062 7421 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
cf2ad4d8 7422 NO_STR
7f7940e6
MK
7423 NEIGHBOR_STR
7424 NEIGHBOR_ADDR_STR2
7425 "Route-map to conditionally advertise routes\n"
7426 "Name of advertise map\n"
7427 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7428 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7429 "Name of the exist or non exist map\n")
7f7940e6 7430{
7f7940e6
MK
7431 bool condition = CONDITION_EXIST;
7432
52b84062 7433 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7434 condition = CONDITION_NON_EXIST;
7435
52b84062
MK
7436 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7437 bgp_node_safi(vty), advertise_str,
7438 condition_str, condition, !no);
7f7940e6
MK
7439}
7440
7441ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
52b84062 7442 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
7f7940e6
MK
7443 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7444 "Route-map to conditionally advertise routes\n"
7445 "Name of advertise map\n"
7446 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7447 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7448 "Name of the exist or non exist map\n")
7f7940e6 7449
718e3744 7450/* Set route-map to the peer. */
0ea8d871
IR
7451static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7452 afi_t afi, safi_t safi, const char *name_str,
7453 const char *direct_str)
718e3744 7454{
0ea8d871
IR
7455 int ret;
7456 struct peer *peer;
7457 int direct = RMAP_IN;
7458 struct route_map *route_map;
718e3744 7459
0ea8d871
IR
7460 peer = peer_and_group_lookup_vty(vty, ip_str);
7461 if (!peer)
d62a17ae 7462 return CMD_WARNING_CONFIG_FAILED;
718e3744 7463
0ea8d871
IR
7464 /* Check filter direction. */
7465 if (strncmp(direct_str, "in", 2) == 0)
7466 direct = RMAP_IN;
7467 else if (strncmp(direct_str, "o", 1) == 0)
7468 direct = RMAP_OUT;
718e3744 7469
0ea8d871
IR
7470 route_map = route_map_lookup_warn_noexist(vty, name_str);
7471 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7472
0ea8d871
IR
7473 return bgp_vty_return(vty, ret);
7474}
7475
7476static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7477 afi_t afi, safi_t safi,
7478 const char *direct_str)
7479{
7480 int ret;
7481 struct peer *peer;
7482 int direct = RMAP_IN;
7483
7484 peer = peer_and_group_lookup_vty(vty, ip_str);
7485 if (!peer)
7486 return CMD_WARNING_CONFIG_FAILED;
7487
7488 /* Check filter direction. */
7489 if (strncmp(direct_str, "in", 2) == 0)
7490 direct = RMAP_IN;
7491 else if (strncmp(direct_str, "o", 1) == 0)
7492 direct = RMAP_OUT;
7493
7494 ret = peer_route_map_unset(peer, afi, safi, direct);
7495
7496 return bgp_vty_return(vty, ret);
7497}
7498
7499DEFUN (neighbor_route_map,
7500 neighbor_route_map_cmd,
7501 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7502 NEIGHBOR_STR
7503 NEIGHBOR_ADDR_STR2
7504 "Apply route map to neighbor\n"
7505 "Name of route map\n"
7506 "Apply map to incoming routes\n"
7507 "Apply map to outbound routes\n")
7508{
7509 int idx_peer = 1;
7510 int idx_word = 3;
7511 int idx_in_out = 4;
7512 return peer_route_map_set_vty(
7513 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7514 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7515}
7516
d6d7ed37
IR
7517ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7518 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7519 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7520 "Apply route map to neighbor\n"
7521 "Name of route map\n"
7522 "Apply map to incoming routes\n"
7523 "Apply map to outbound routes\n")
7524
0ea8d871
IR
7525DEFUN (no_neighbor_route_map,
7526 no_neighbor_route_map_cmd,
7527 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7528 NO_STR
7529 NEIGHBOR_STR
7530 NEIGHBOR_ADDR_STR2
7531 "Apply route map to neighbor\n"
7532 "Name of route map\n"
7533 "Apply map to incoming routes\n"
7534 "Apply map to outbound routes\n")
7535{
7536 int idx_peer = 2;
7537 int idx_in_out = 5;
7538 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7539 bgp_node_afi(vty), bgp_node_safi(vty),
7540 argv[idx_in_out]->arg);
7541}
7542
7543ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
d6d7ed37
IR
7544 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7545 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7546 "Apply route map to neighbor\n"
7547 "Name of route map\n"
7548 "Apply map to incoming routes\n"
7549 "Apply map to outbound routes\n")
7550
718e3744 7551/* Set unsuppress-map to the peer. */
d62a17ae 7552static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7553 afi_t afi, safi_t safi,
7554 const char *name_str)
718e3744 7555{
d62a17ae 7556 int ret;
7557 struct peer *peer;
1de27621 7558 struct route_map *route_map;
718e3744 7559
d62a17ae 7560 peer = peer_and_group_lookup_vty(vty, ip_str);
7561 if (!peer)
7562 return CMD_WARNING_CONFIG_FAILED;
718e3744 7563
1de27621
DA
7564 route_map = route_map_lookup_warn_noexist(vty, name_str);
7565 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 7566
d62a17ae 7567 return bgp_vty_return(vty, ret);
718e3744 7568}
7569
7570/* Unset route-map from the peer. */
d62a17ae 7571static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7572 afi_t afi, safi_t safi)
718e3744 7573{
d62a17ae 7574 int ret;
7575 struct peer *peer;
718e3744 7576
d62a17ae 7577 peer = peer_and_group_lookup_vty(vty, ip_str);
7578 if (!peer)
7579 return CMD_WARNING_CONFIG_FAILED;
718e3744 7580
d62a17ae 7581 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 7582
d62a17ae 7583 return bgp_vty_return(vty, ret);
718e3744 7584}
7585
7586DEFUN (neighbor_unsuppress_map,
7587 neighbor_unsuppress_map_cmd,
9ccf14f7 7588 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7589 NEIGHBOR_STR
7590 NEIGHBOR_ADDR_STR2
7591 "Route-map to selectively unsuppress suppressed routes\n"
7592 "Name of route map\n")
7593{
d62a17ae 7594 int idx_peer = 1;
7595 int idx_word = 3;
7596 return peer_unsuppress_map_set_vty(
7597 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7598 argv[idx_word]->arg);
718e3744 7599}
7600
d62a17ae 7601ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7602 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7603 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7604 "Route-map to selectively unsuppress suppressed routes\n"
7605 "Name of route map\n")
596c17ba 7606
718e3744 7607DEFUN (no_neighbor_unsuppress_map,
7608 no_neighbor_unsuppress_map_cmd,
9ccf14f7 7609 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7610 NO_STR
7611 NEIGHBOR_STR
7612 NEIGHBOR_ADDR_STR2
7613 "Route-map to selectively unsuppress suppressed routes\n"
7614 "Name of route map\n")
7615{
d62a17ae 7616 int idx_peer = 2;
7617 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7618 bgp_node_afi(vty),
7619 bgp_node_safi(vty));
718e3744 7620}
6b0655a2 7621
d62a17ae 7622ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7623 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7624 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7625 "Route-map to selectively unsuppress suppressed routes\n"
7626 "Name of route map\n")
596c17ba 7627
7e62b792
IR
7628static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7629 afi_t afi, safi_t safi,
7630 const char *num_str,
7631 const char *threshold_str, int warning,
7632 const char *restart_str,
7633 const char *force_str)
7634{
7635 int ret;
7636 struct peer *peer;
7637 uint32_t max;
7638 uint8_t threshold;
7639 uint16_t restart;
7640
7641 peer = peer_and_group_lookup_vty(vty, ip_str);
7642 if (!peer)
7643 return CMD_WARNING_CONFIG_FAILED;
7644
7645 max = strtoul(num_str, NULL, 10);
7646 if (threshold_str)
7647 threshold = atoi(threshold_str);
7648 else
7649 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7650
7651 if (restart_str)
7652 restart = atoi(restart_str);
7653 else
7654 restart = 0;
7655
7656 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7657 restart, force_str ? true : false);
7658
7659 return bgp_vty_return(vty, ret);
7660}
7661
7662static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7663 afi_t afi, safi_t safi)
7664{
7665 int ret;
7666 struct peer *peer;
7667
7668 peer = peer_and_group_lookup_vty(vty, ip_str);
7669 if (!peer)
7670 return CMD_WARNING_CONFIG_FAILED;
7671
7672 ret = peer_maximum_prefix_unset(peer, afi, safi);
7673
7674 return bgp_vty_return(vty, ret);
7675}
7676
fde246e8 7677/* Maximum number of prefix to be sent to the neighbor. */
1d80f243
IR
7678DEFUN(neighbor_maximum_prefix_out,
7679 neighbor_maximum_prefix_out_cmd,
7680 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7681 NEIGHBOR_STR
7682 NEIGHBOR_ADDR_STR2
7683 "Maximum number of prefixes to be sent to this peer\n"
7684 "Maximum no. of prefix limit\n")
fde246e8 7685{
80444d30 7686 int ret;
fde246e8
DA
7687 int idx_peer = 1;
7688 int idx_number = 3;
7e62b792
IR
7689 struct peer *peer;
7690 uint32_t max;
fde246e8
DA
7691 afi_t afi = bgp_node_afi(vty);
7692 safi_t safi = bgp_node_safi(vty);
7693
7e62b792
IR
7694 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7695 if (!peer)
fde246e8
DA
7696 return CMD_WARNING_CONFIG_FAILED;
7697
7e62b792 7698 max = strtoul(argv[idx_number]->arg, NULL, 10);
fde246e8 7699
80444d30 7700 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
fde246e8 7701
80444d30 7702 return bgp_vty_return(vty, ret);
fde246e8
DA
7703}
7704
1d80f243
IR
7705DEFUN(no_neighbor_maximum_prefix_out,
7706 no_neighbor_maximum_prefix_out_cmd,
bc03c622 7707 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
1d80f243
IR
7708 NO_STR
7709 NEIGHBOR_STR
7710 NEIGHBOR_ADDR_STR2
bc03c622
LS
7711 "Maximum number of prefixes to be sent to this peer\n"
7712 "Maximum no. of prefix limit\n")
fde246e8 7713{
80444d30 7714 int ret;
fde246e8 7715 int idx_peer = 2;
7e62b792 7716 struct peer *peer;
fde246e8
DA
7717 afi_t afi = bgp_node_afi(vty);
7718 safi_t safi = bgp_node_safi(vty);
7719
7e62b792
IR
7720 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7721 if (!peer)
fde246e8
DA
7722 return CMD_WARNING_CONFIG_FAILED;
7723
80444d30 7724 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
fde246e8 7725
80444d30 7726 return bgp_vty_return(vty, ret);
fde246e8
DA
7727}
7728
9cbd06e0
DA
7729/* Maximum number of prefix configuration. Prefix count is different
7730 for each peer configuration. So this configuration can be set for
718e3744 7731 each peer configuration. */
1d80f243
IR
7732DEFUN (neighbor_maximum_prefix,
7733 neighbor_maximum_prefix_cmd,
7734 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7735 NEIGHBOR_STR
7736 NEIGHBOR_ADDR_STR2
7737 "Maximum number of prefix accept from this peer\n"
7738 "maximum no. of prefix limit\n"
7739 "Force checking all received routes not only accepted\n")
718e3744 7740{
d62a17ae 7741 int idx_peer = 1;
7742 int idx_number = 3;
9cbd06e0 7743 int idx_force = 0;
7e62b792 7744 char *force = NULL;
9cbd06e0
DA
7745
7746 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7747 force = argv[idx_force]->arg;
9cbd06e0 7748
7e62b792
IR
7749 return peer_maximum_prefix_set_vty(
7750 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7751 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 7752}
7753
d62a17ae 7754ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7755 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 7756 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7757 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
7758 "maximum no. of prefix limit\n"
7759 "Force checking all received routes not only accepted\n")
596c17ba 7760
1d80f243
IR
7761DEFUN (neighbor_maximum_prefix_threshold,
7762 neighbor_maximum_prefix_threshold_cmd,
7763 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7764 NEIGHBOR_STR
7765 NEIGHBOR_ADDR_STR2
7766 "Maximum number of prefix accept from this peer\n"
7767 "maximum no. of prefix limit\n"
7768 "Threshold value (%) at which to generate a warning msg\n"
7769 "Force checking all received routes not only accepted\n")
e0701b79 7770{
d62a17ae 7771 int idx_peer = 1;
7772 int idx_number = 3;
7773 int idx_number_2 = 4;
9cbd06e0 7774 int idx_force = 0;
7e62b792 7775 char *force = NULL;
9cbd06e0
DA
7776
7777 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7778 force = argv[idx_force]->arg;
9cbd06e0 7779
7e62b792
IR
7780 return peer_maximum_prefix_set_vty(
7781 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7782 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 7783}
e0701b79 7784
d62a17ae 7785ALIAS_HIDDEN(
7786 neighbor_maximum_prefix_threshold,
7787 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 7788 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 7789 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7790 "Maximum number of prefix accept from this peer\n"
7791 "maximum no. of prefix limit\n"
9cbd06e0
DA
7792 "Threshold value (%) at which to generate a warning msg\n"
7793 "Force checking all received routes not only accepted\n")
596c17ba 7794
1d80f243
IR
7795DEFUN (neighbor_maximum_prefix_warning,
7796 neighbor_maximum_prefix_warning_cmd,
7797 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7798 NEIGHBOR_STR
7799 NEIGHBOR_ADDR_STR2
7800 "Maximum number of prefix accept from this peer\n"
7801 "maximum no. of prefix limit\n"
7802 "Only give warning message when limit is exceeded\n"
7803 "Force checking all received routes not only accepted\n")
718e3744 7804{
d62a17ae 7805 int idx_peer = 1;
7806 int idx_number = 3;
9cbd06e0 7807 int idx_force = 0;
7e62b792 7808 char *force = NULL;
9cbd06e0
DA
7809
7810 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7811 force = argv[idx_force]->arg;
9cbd06e0 7812
7e62b792
IR
7813 return peer_maximum_prefix_set_vty(
7814 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7815 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 7816}
7817
d62a17ae 7818ALIAS_HIDDEN(
7819 neighbor_maximum_prefix_warning,
7820 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 7821 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 7822 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7823 "Maximum number of prefix accept from this peer\n"
7824 "maximum no. of prefix limit\n"
9cbd06e0
DA
7825 "Only give warning message when limit is exceeded\n"
7826 "Force checking all received routes not only accepted\n")
596c17ba 7827
1d80f243
IR
7828DEFUN (neighbor_maximum_prefix_threshold_warning,
7829 neighbor_maximum_prefix_threshold_warning_cmd,
7830 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7831 NEIGHBOR_STR
7832 NEIGHBOR_ADDR_STR2
7833 "Maximum number of prefix accept from this peer\n"
7834 "maximum no. of prefix limit\n"
7835 "Threshold value (%) at which to generate a warning msg\n"
7836 "Only give warning message when limit is exceeded\n"
7837 "Force checking all received routes not only accepted\n")
e0701b79 7838{
d62a17ae 7839 int idx_peer = 1;
7840 int idx_number = 3;
7841 int idx_number_2 = 4;
9cbd06e0 7842 int idx_force = 0;
7e62b792 7843 char *force = NULL;
9cbd06e0
DA
7844
7845 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7846 force = argv[idx_force]->arg;
9cbd06e0 7847
7e62b792
IR
7848 return peer_maximum_prefix_set_vty(
7849 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7850 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 7851}
7852
d62a17ae 7853ALIAS_HIDDEN(
7854 neighbor_maximum_prefix_threshold_warning,
7855 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 7856 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 7857 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7858 "Maximum number of prefix accept from this peer\n"
7859 "maximum no. of prefix limit\n"
7860 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
7861 "Only give warning message when limit is exceeded\n"
7862 "Force checking all received routes not only accepted\n")
596c17ba 7863
1d80f243
IR
7864DEFUN (neighbor_maximum_prefix_restart,
7865 neighbor_maximum_prefix_restart_cmd,
7866 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7867 NEIGHBOR_STR
7868 NEIGHBOR_ADDR_STR2
7869 "Maximum number of prefix accept from this peer\n"
7870 "maximum no. of prefix limit\n"
7871 "Restart bgp connection after limit is exceeded\n"
7872 "Restart interval in minutes\n"
7873 "Force checking all received routes not only accepted\n")
0a486e5f 7874{
d62a17ae 7875 int idx_peer = 1;
7876 int idx_number = 3;
7877 int idx_number_2 = 5;
9cbd06e0 7878 int idx_force = 0;
7e62b792 7879 char *force = NULL;
9cbd06e0
DA
7880
7881 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7882 force = argv[idx_force]->arg;
9cbd06e0 7883
7e62b792
IR
7884 return peer_maximum_prefix_set_vty(
7885 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7886 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 7887}
7888
d62a17ae 7889ALIAS_HIDDEN(
7890 neighbor_maximum_prefix_restart,
7891 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 7892 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 7893 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7894 "Maximum number of prefix accept from this peer\n"
7895 "maximum no. of prefix limit\n"
7896 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7897 "Restart interval in minutes\n"
7898 "Force checking all received routes not only accepted\n")
596c17ba 7899
1d80f243
IR
7900DEFUN (neighbor_maximum_prefix_threshold_restart,
7901 neighbor_maximum_prefix_threshold_restart_cmd,
7902 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7903 NEIGHBOR_STR
7904 NEIGHBOR_ADDR_STR2
7905 "Maximum number of prefixes to accept from this peer\n"
7906 "maximum no. of prefix limit\n"
7907 "Threshold value (%) at which to generate a warning msg\n"
7908 "Restart bgp connection after limit is exceeded\n"
7909 "Restart interval in minutes\n"
7910 "Force checking all received routes not only accepted\n")
0a486e5f 7911{
d62a17ae 7912 int idx_peer = 1;
7913 int idx_number = 3;
7914 int idx_number_2 = 4;
7915 int idx_number_3 = 6;
9cbd06e0 7916 int idx_force = 0;
7e62b792 7917 char *force = NULL;
9cbd06e0
DA
7918
7919 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7920 force = argv[idx_force]->arg;
9cbd06e0 7921
7e62b792
IR
7922 return peer_maximum_prefix_set_vty(
7923 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7924 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
7925 argv[idx_number_3]->arg, force);
d62a17ae 7926}
7927
7928ALIAS_HIDDEN(
7929 neighbor_maximum_prefix_threshold_restart,
7930 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 7931 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 7932 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7933 "Maximum number of prefixes to accept from this peer\n"
7934 "maximum no. of prefix limit\n"
7935 "Threshold value (%) at which to generate a warning msg\n"
7936 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7937 "Restart interval in minutes\n"
7938 "Force checking all received routes not only accepted\n")
596c17ba 7939
1d80f243
IR
7940DEFUN (no_neighbor_maximum_prefix,
7941 no_neighbor_maximum_prefix_cmd,
7942 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
7943 NO_STR
7944 NEIGHBOR_STR
7945 NEIGHBOR_ADDR_STR2
7946 "Maximum number of prefixes to accept from this peer\n"
7947 "maximum no. of prefix limit\n"
7948 "Threshold value (%) at which to generate a warning msg\n"
7949 "Restart bgp connection after limit is exceeded\n"
7950 "Restart interval in minutes\n"
7951 "Only give warning message when limit is exceeded\n"
7952 "Force checking all received routes not only accepted\n")
718e3744 7953{
d62a17ae 7954 int idx_peer = 2;
7e62b792
IR
7955 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
7956 bgp_node_afi(vty),
7957 bgp_node_safi(vty));
718e3744 7958}
e52702f2 7959
d62a17ae 7960ALIAS_HIDDEN(
7961 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7962 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 7963 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7964 "Maximum number of prefixes to accept from this peer\n"
7965 "maximum no. of prefix limit\n"
7966 "Threshold value (%) at which to generate a warning msg\n"
7967 "Restart bgp connection after limit is exceeded\n"
7968 "Restart interval in minutes\n"
9cbd06e0
DA
7969 "Only give warning message when limit is exceeded\n"
7970 "Force checking all received routes not only accepted\n")
596c17ba 7971
718e3744 7972
718e3744 7973/* "neighbor allowas-in" */
7974DEFUN (neighbor_allowas_in,
7975 neighbor_allowas_in_cmd,
fd8503f5 7976 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7977 NEIGHBOR_STR
7978 NEIGHBOR_ADDR_STR2
31500417 7979 "Accept as-path with my AS present in it\n"
f79f7a7b 7980 "Number of occurrences of AS number\n"
fd8503f5 7981 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7982{
d62a17ae 7983 int idx_peer = 1;
7984 int idx_number_origin = 3;
7985 int ret;
7986 int origin = 0;
7987 struct peer *peer;
7988 int allow_num = 0;
7989
7990 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7991 if (!peer)
7992 return CMD_WARNING_CONFIG_FAILED;
7993
7994 if (argc <= idx_number_origin)
7995 allow_num = 3;
7996 else {
7997 if (argv[idx_number_origin]->type == WORD_TKN)
7998 origin = 1;
7999 else
8000 allow_num = atoi(argv[idx_number_origin]->arg);
8001 }
8002
8003 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8004 allow_num, origin);
8005
8006 return bgp_vty_return(vty, ret);
8007}
8008
8009ALIAS_HIDDEN(
8010 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8011 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8012 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8013 "Accept as-path with my AS present in it\n"
f79f7a7b 8014 "Number of occurrences of AS number\n"
d62a17ae 8015 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8016
718e3744 8017DEFUN (no_neighbor_allowas_in,
8018 no_neighbor_allowas_in_cmd,
fd8503f5 8019 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8020 NO_STR
8021 NEIGHBOR_STR
8022 NEIGHBOR_ADDR_STR2
8334fd5a 8023 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8024 "Number of occurrences of AS number\n"
fd8503f5 8025 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8026{
d62a17ae 8027 int idx_peer = 2;
8028 int ret;
8029 struct peer *peer;
718e3744 8030
d62a17ae 8031 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8032 if (!peer)
8033 return CMD_WARNING_CONFIG_FAILED;
718e3744 8034
d62a17ae 8035 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8036 bgp_node_safi(vty));
718e3744 8037
d62a17ae 8038 return bgp_vty_return(vty, ret);
718e3744 8039}
6b0655a2 8040
d62a17ae 8041ALIAS_HIDDEN(
8042 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8043 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8044 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8045 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8046 "Number of occurrences of AS number\n"
d62a17ae 8047 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8048
28c6e247
IR
8049DEFUN (neighbor_ttl_security,
8050 neighbor_ttl_security_cmd,
8051 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8052 NEIGHBOR_STR
8053 NEIGHBOR_ADDR_STR2
8054 "BGP ttl-security parameters\n"
8055 "Specify the maximum number of hops to the BGP peer\n"
8056 "Number of hops to BGP peer\n")
fa411a21 8057{
d62a17ae 8058 int idx_peer = 1;
8059 int idx_number = 4;
28c6e247
IR
8060 struct peer *peer;
8061 int gtsm_hops;
d62a17ae 8062
28c6e247
IR
8063 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8064 if (!peer)
d62a17ae 8065 return CMD_WARNING_CONFIG_FAILED;
8066
28c6e247
IR
8067 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8068
8069 /*
8070 * If 'neighbor swpX', then this is for directly connected peers,
8071 * we should not accept a ttl-security hops value greater than 1.
8072 */
8073 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8074 vty_out(vty,
8075 "%s is directly connected peer, hops cannot exceed 1\n",
8076 argv[idx_peer]->arg);
8077 return CMD_WARNING_CONFIG_FAILED;
8078 }
7ebe625c 8079
28c6e247 8080 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
8081}
8082
1d80f243
IR
8083DEFUN (no_neighbor_ttl_security,
8084 no_neighbor_ttl_security_cmd,
8085 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8086 NO_STR
8087 NEIGHBOR_STR
8088 NEIGHBOR_ADDR_STR2
8089 "BGP ttl-security parameters\n"
8090 "Specify the maximum number of hops to the BGP peer\n"
8091 "Number of hops to BGP peer\n")
fa411a21 8092{
d62a17ae 8093 int idx_peer = 2;
28c6e247 8094 struct peer *peer;
fa411a21 8095
28c6e247
IR
8096 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8097 if (!peer)
d62a17ae 8098 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8099
28c6e247 8100 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 8101}
6b0655a2 8102
7c0e4312
DA
8103/* disable-addpath-rx */
8104DEFUN(neighbor_disable_addpath_rx,
8105 neighbor_disable_addpath_rx_cmd,
8106 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8107 NEIGHBOR_STR
8108 NEIGHBOR_ADDR_STR2
8109 "Do not accept additional paths\n")
8110{
8111 char *peer_str = argv[1]->arg;
8112 struct peer *peer;
8113 afi_t afi = bgp_node_afi(vty);
8114 safi_t safi = bgp_node_safi(vty);
8115
8116 peer = peer_and_group_lookup_vty(vty, peer_str);
8117 if (!peer)
8118 return CMD_WARNING_CONFIG_FAILED;
8119
8120 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8121 PEER_FLAG_DISABLE_ADDPATH_RX);
8122}
8123
8124DEFUN(no_neighbor_disable_addpath_rx,
8125 no_neighbor_disable_addpath_rx_cmd,
8126 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8127 NO_STR
8128 NEIGHBOR_STR
8129 NEIGHBOR_ADDR_STR2
8130 "Do not accept additional paths\n")
8131{
8132 char *peer_str = argv[2]->arg;
8133 struct peer *peer;
8134 afi_t afi = bgp_node_afi(vty);
8135 safi_t safi = bgp_node_safi(vty);
8136
8137 peer = peer_and_group_lookup_vty(vty, peer_str);
8138 if (!peer)
8139 return CMD_WARNING_CONFIG_FAILED;
8140
8141 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8142 PEER_FLAG_DISABLE_ADDPATH_RX);
8143}
8144
adbac85e
DW
8145DEFUN (neighbor_addpath_tx_all_paths,
8146 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8147 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8148 NEIGHBOR_STR
8149 NEIGHBOR_ADDR_STR2
8150 "Use addpath to advertise all paths to a neighbor\n")
8151{
d62a17ae 8152 int idx_peer = 1;
8153 struct peer *peer;
adbac85e 8154
d62a17ae 8155 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8156 if (!peer)
8157 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8158
dcc68b5e
MS
8159 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8160 BGP_ADDPATH_ALL);
8161 return CMD_SUCCESS;
adbac85e
DW
8162}
8163
d62a17ae 8164ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8165 neighbor_addpath_tx_all_paths_hidden_cmd,
8166 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8167 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8168 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8169
adbac85e
DW
8170DEFUN (no_neighbor_addpath_tx_all_paths,
8171 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8172 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8173 NO_STR
8174 NEIGHBOR_STR
8175 NEIGHBOR_ADDR_STR2
8176 "Use addpath to advertise all paths to a neighbor\n")
8177{
d62a17ae 8178 int idx_peer = 2;
dcc68b5e
MS
8179 struct peer *peer;
8180
8181 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8182 if (!peer)
8183 return CMD_WARNING_CONFIG_FAILED;
8184
8185 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8186 != BGP_ADDPATH_ALL) {
8187 vty_out(vty,
8188 "%% Peer not currently configured to transmit all paths.");
8189 return CMD_WARNING_CONFIG_FAILED;
8190 }
8191
8192 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8193 BGP_ADDPATH_NONE);
8194
8195 return CMD_SUCCESS;
adbac85e
DW
8196}
8197
d62a17ae 8198ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8199 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8200 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8201 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8202 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8203
06370dac
DW
8204DEFUN (neighbor_addpath_tx_bestpath_per_as,
8205 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8206 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8207 NEIGHBOR_STR
8208 NEIGHBOR_ADDR_STR2
8209 "Use addpath to advertise the bestpath per each neighboring AS\n")
8210{
d62a17ae 8211 int idx_peer = 1;
8212 struct peer *peer;
06370dac 8213
d62a17ae 8214 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8215 if (!peer)
8216 return CMD_WARNING_CONFIG_FAILED;
06370dac 8217
dcc68b5e
MS
8218 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8219 BGP_ADDPATH_BEST_PER_AS);
8220
8221 return CMD_SUCCESS;
06370dac
DW
8222}
8223
d62a17ae 8224ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8225 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8226 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8227 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8228 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8229
06370dac
DW
8230DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8231 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8232 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8233 NO_STR
8234 NEIGHBOR_STR
8235 NEIGHBOR_ADDR_STR2
8236 "Use addpath to advertise the bestpath per each neighboring AS\n")
8237{
d62a17ae 8238 int idx_peer = 2;
dcc68b5e
MS
8239 struct peer *peer;
8240
8241 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8242 if (!peer)
8243 return CMD_WARNING_CONFIG_FAILED;
8244
8245 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8246 != BGP_ADDPATH_BEST_PER_AS) {
8247 vty_out(vty,
8248 "%% Peer not currently configured to transmit all best path per as.");
8249 return CMD_WARNING_CONFIG_FAILED;
8250 }
8251
8252 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8253 BGP_ADDPATH_NONE);
8254
8255 return CMD_SUCCESS;
06370dac
DW
8256}
8257
d62a17ae 8258ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8259 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8260 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8261 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8262 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8263
2b31007c
RZ
8264DEFPY(
8265 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8266 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8267 NEIGHBOR_STR
8268 NEIGHBOR_ADDR_STR2
8269 "Detect AS loops before sending to neighbor\n")
8270{
8271 struct peer *peer;
8272
8273 peer = peer_and_group_lookup_vty(vty, neighbor);
8274 if (!peer)
8275 return CMD_WARNING_CONFIG_FAILED;
8276
8277 peer->as_path_loop_detection = true;
8278
8279 return CMD_SUCCESS;
8280}
8281
8282DEFPY(
8283 no_neighbor_aspath_loop_detection,
8284 no_neighbor_aspath_loop_detection_cmd,
8285 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8286 NO_STR
8287 NEIGHBOR_STR
8288 NEIGHBOR_ADDR_STR2
8289 "Detect AS loops before sending to neighbor\n")
8290{
8291 struct peer *peer;
8292
8293 peer = peer_and_group_lookup_vty(vty, neighbor);
8294 if (!peer)
8295 return CMD_WARNING_CONFIG_FAILED;
8296
8297 peer->as_path_loop_detection = false;
8298
8299 return CMD_SUCCESS;
8300}
8301
b9c7bc5a 8302static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8303 struct ecommunity **list, bool is_rt6)
ddb5b488 8304{
b9c7bc5a
PZ
8305 struct ecommunity *ecom = NULL;
8306 struct ecommunity *ecomadd;
ddb5b488 8307
b9c7bc5a 8308 for (; argc; --argc, ++argv) {
9a659715
PG
8309 if (is_rt6)
8310 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8311 ECOMMUNITY_ROUTE_TARGET,
8312 0);
8313 else
8314 ecomadd = ecommunity_str2com(argv[0]->arg,
8315 ECOMMUNITY_ROUTE_TARGET,
8316 0);
b9c7bc5a
PZ
8317 if (!ecomadd) {
8318 vty_out(vty, "Malformed community-list value\n");
8319 if (ecom)
8320 ecommunity_free(&ecom);
8321 return CMD_WARNING_CONFIG_FAILED;
8322 }
ddb5b488 8323
b9c7bc5a
PZ
8324 if (ecom) {
8325 ecommunity_merge(ecom, ecomadd);
8326 ecommunity_free(&ecomadd);
8327 } else {
8328 ecom = ecomadd;
8329 }
8330 }
8331
8332 if (*list) {
8333 ecommunity_free(&*list);
ddb5b488 8334 }
b9c7bc5a
PZ
8335 *list = ecom;
8336
8337 return CMD_SUCCESS;
ddb5b488
PZ
8338}
8339
0ca70ba5
DS
8340/*
8341 * v2vimport is true if we are handling a `import vrf ...` command
8342 */
8343static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8344{
0ca70ba5
DS
8345 afi_t afi;
8346
ddb5b488 8347 switch (vty->node) {
b9c7bc5a 8348 case BGP_IPV4_NODE:
0ca70ba5
DS
8349 afi = AFI_IP;
8350 break;
b9c7bc5a 8351 case BGP_IPV6_NODE:
0ca70ba5
DS
8352 afi = AFI_IP6;
8353 break;
ddb5b488
PZ
8354 default:
8355 vty_out(vty,
b9c7bc5a 8356 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 8357 return AFI_MAX;
ddb5b488 8358 }
69b07479 8359
0ca70ba5
DS
8360 if (!v2vimport) {
8361 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8362 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8363 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8364 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8365 vty_out(vty,
8366 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8367 return AFI_MAX;
8368 }
8369 } else {
8370 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8371 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8372 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8373 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8374 vty_out(vty,
8375 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8376 return AFI_MAX;
8377 }
8378 }
8379 return afi;
ddb5b488
PZ
8380}
8381
585f1adc
IR
8382DEFPY (af_rd_vpn_export,
8383 af_rd_vpn_export_cmd,
8384 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8385 NO_STR
8386 "Specify route distinguisher\n"
8387 "Between current address-family and vpn\n"
8388 "For routes leaked from current address-family to vpn\n"
8389 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 8390{
585f1adc
IR
8391 VTY_DECLVAR_CONTEXT(bgp, bgp);
8392 struct prefix_rd prd;
8393 int ret;
ddb5b488 8394 afi_t afi;
b9c7bc5a 8395 int idx = 0;
585f1adc 8396 bool yes = true;
b9c7bc5a 8397
585f1adc
IR
8398 if (argv_find(argv, argc, "no", &idx))
8399 yes = false;
ddb5b488 8400
585f1adc
IR
8401 if (yes) {
8402 ret = str2prefix_rd(rd_str, &prd);
8403 if (!ret) {
8404 vty_out(vty, "%% Malformed rd\n");
8405 return CMD_WARNING_CONFIG_FAILED;
8406 }
8407 }
ddb5b488 8408
585f1adc
IR
8409 afi = vpn_policy_getafi(vty, bgp, false);
8410 if (afi == AFI_MAX)
8411 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8412
585f1adc
IR
8413 /*
8414 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8415 */
8416 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8417 bgp_get_default(), bgp);
ddb5b488 8418
585f1adc
IR
8419 if (yes) {
8420 bgp->vpn_policy[afi].tovpn_rd = prd;
8421 SET_FLAG(bgp->vpn_policy[afi].flags,
8422 BGP_VPN_POLICY_TOVPN_RD_SET);
8423 } else {
8424 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8425 BGP_VPN_POLICY_TOVPN_RD_SET);
8426 }
69b07479 8427
585f1adc
IR
8428 /* post-change: re-export vpn routes */
8429 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8430 bgp_get_default(), bgp);
8431
8432 return CMD_SUCCESS;
ddb5b488
PZ
8433}
8434
b9c7bc5a
PZ
8435ALIAS (af_rd_vpn_export,
8436 af_no_rd_vpn_export_cmd,
8437 "no rd vpn export",
ddb5b488 8438 NO_STR
b9c7bc5a
PZ
8439 "Specify route distinguisher\n"
8440 "Between current address-family and vpn\n"
8441 "For routes leaked from current address-family to vpn\n")
ddb5b488 8442
b9c7bc5a
PZ
8443DEFPY (af_label_vpn_export,
8444 af_label_vpn_export_cmd,
e70e9f8e 8445 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 8446 NO_STR
ddb5b488 8447 "label value for VRF\n"
b9c7bc5a
PZ
8448 "Between current address-family and vpn\n"
8449 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
8450 "Label Value <0-1048575>\n"
8451 "Automatically assign a label\n")
ddb5b488
PZ
8452{
8453 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8454 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 8455 afi_t afi;
b9c7bc5a 8456 int idx = 0;
c6423c31 8457 bool yes = true;
b9c7bc5a
PZ
8458
8459 if (argv_find(argv, argc, "no", &idx))
c6423c31 8460 yes = false;
ddb5b488 8461
21a16cc2
PZ
8462 /* If "no ...", squash trailing parameter */
8463 if (!yes)
8464 label_auto = NULL;
8465
e70e9f8e
PZ
8466 if (yes) {
8467 if (!label_auto)
8468 label = label_val; /* parser should force unsigned */
8469 }
ddb5b488 8470
0ca70ba5 8471 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8472 if (afi == AFI_MAX)
8473 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 8474
e70e9f8e 8475
69b07479
DS
8476 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8477 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8478 /* no change */
8479 return CMD_SUCCESS;
e70e9f8e 8480
69b07479
DS
8481 /*
8482 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8483 */
8484 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8485 bgp_get_default(), bgp);
8486
8487 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8488 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8489
8490 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8491
8492 /*
8493 * label has previously been automatically
8494 * assigned by labelpool: release it
8495 *
8496 * NB if tovpn_label == MPLS_LABEL_NONE it
8497 * means the automatic assignment is in flight
8498 * and therefore the labelpool callback must
8499 * detect that the auto label is not needed.
8500 */
8501
8502 bgp_lp_release(LP_TYPE_VRF,
8503 &bgp->vpn_policy[afi],
8504 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 8505 }
69b07479
DS
8506 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8507 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8508 }
ddb5b488 8509
69b07479
DS
8510 bgp->vpn_policy[afi].tovpn_label = label;
8511 if (label_auto) {
8512 SET_FLAG(bgp->vpn_policy[afi].flags,
8513 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8514 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8515 vpn_leak_label_callback);
ddb5b488
PZ
8516 }
8517
69b07479
DS
8518 /* post-change: re-export vpn routes */
8519 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8520 bgp_get_default(), bgp);
8521
0d020cd6 8522 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
8523 return CMD_SUCCESS;
8524}
8525
b72c9e14
HS
8526DEFPY (af_sid_vpn_export,
8527 af_sid_vpn_export_cmd,
8528 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8529 NO_STR
8530 "sid value for VRF\n"
8531 "Between current address-family and vpn\n"
8532 "For routes leaked from current address-family to vpn\n"
8533 "Sid allocation index\n"
8534 "Automatically assign a label\n")
8535{
8536 VTY_DECLVAR_CONTEXT(bgp, bgp);
8537 afi_t afi;
8538 int debug = 0;
8539 int idx = 0;
8540 bool yes = true;
8541
8542 if (argv_find(argv, argc, "no", &idx))
8543 yes = false;
8544 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8545 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8546
8547 afi = vpn_policy_getafi(vty, bgp, false);
8548 if (afi == AFI_MAX)
8549 return CMD_WARNING_CONFIG_FAILED;
8550
8551 if (!yes) {
8552 /* implement me */
8553 vty_out(vty, "It's not implemented");
8554 return CMD_WARNING_CONFIG_FAILED;
8555 }
8556
8557 /* skip when it's already configured */
8558 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8559 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8560 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8561 return CMD_SUCCESS;
8562
7de4c885
HS
8563 /*
8564 * mode change between sid_idx and sid_auto isn't supported.
8565 * user must negate sid vpn export when they want to change the mode
8566 */
b72c9e14
HS
8567 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8568 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8569 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8570 vty_out(vty, "it's already configured as %s.\n",
8571 sid_auto ? "auto-mode" : "idx-mode");
8572 return CMD_WARNING_CONFIG_FAILED;
8573 }
8574
8575 /* pre-change */
8576 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8577 bgp_get_default(), bgp);
8578
8579 if (sid_auto) {
8580 /* SID allocation auto-mode */
8581 if (debug)
8582 zlog_debug("%s: auto sid alloc.", __func__);
8583 SET_FLAG(bgp->vpn_policy[afi].flags,
8584 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8585 } else {
8586 /* SID allocation index-mode */
8587 if (debug)
8588 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8589 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8590 }
8591
8592 /* post-change */
8593 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8594 bgp_get_default(), bgp);
8595 return CMD_SUCCESS;
8596}
8597
b9c7bc5a
PZ
8598ALIAS (af_label_vpn_export,
8599 af_no_label_vpn_export_cmd,
8600 "no label vpn export",
8601 NO_STR
8602 "label value for VRF\n"
8603 "Between current address-family and vpn\n"
8604 "For routes leaked from current address-family to vpn\n")
ddb5b488 8605
585f1adc 8606DEFPY (af_nexthop_vpn_export,
b9c7bc5a 8607 af_nexthop_vpn_export_cmd,
8c85ca28 8608 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 8609 NO_STR
ddb5b488 8610 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
8611 "Between current address-family and vpn\n"
8612 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8613 "IPv4 prefix\n"
8614 "IPv6 prefix\n")
8615{
585f1adc 8616 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 8617 afi_t afi;
ddb5b488
PZ
8618 struct prefix p;
8619
8c85ca28
QY
8620 if (!no) {
8621 if (!nexthop_su) {
8622 vty_out(vty, "%% Nexthop required\n");
8623 return CMD_WARNING_CONFIG_FAILED;
8624 }
8c85ca28 8625 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
8626 return CMD_WARNING_CONFIG_FAILED;
8627 }
ddb5b488 8628
585f1adc
IR
8629 afi = vpn_policy_getafi(vty, bgp, false);
8630 if (afi == AFI_MAX)
8631 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8632
585f1adc
IR
8633 /*
8634 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8635 */
8636 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8637 bgp_get_default(), bgp);
ddb5b488 8638
585f1adc
IR
8639 if (!no) {
8640 bgp->vpn_policy[afi].tovpn_nexthop = p;
8641 SET_FLAG(bgp->vpn_policy[afi].flags,
8642 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8643 } else {
8644 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8645 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8646 }
69b07479 8647
585f1adc
IR
8648 /* post-change: re-export vpn routes */
8649 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8650 bgp_get_default(), bgp);
37a87b8f 8651
585f1adc 8652 return CMD_SUCCESS;
ddb5b488
PZ
8653}
8654
b9c7bc5a 8655static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 8656{
b9c7bc5a
PZ
8657 if (!strcmp(dstr, "import")) {
8658 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8659 } else if (!strcmp(dstr, "export")) {
8660 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8661 } else if (!strcmp(dstr, "both")) {
8662 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8663 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8664 } else {
8665 vty_out(vty, "%% direction parse error\n");
8666 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8667 }
ddb5b488
PZ
8668 return CMD_SUCCESS;
8669}
8670
b9c7bc5a
PZ
8671DEFPY (af_rt_vpn_imexport,
8672 af_rt_vpn_imexport_cmd,
8673 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8674 NO_STR
8675 "Specify route target list\n"
ddb5b488 8676 "Specify route target list\n"
b9c7bc5a
PZ
8677 "Between current address-family and vpn\n"
8678 "For routes leaked from vpn to current address-family: match any\n"
8679 "For routes leaked from current address-family to vpn: set\n"
8680 "both import: match any and export: set\n"
ddb5b488
PZ
8681 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8682{
8683 VTY_DECLVAR_CONTEXT(bgp, bgp);
8684 int ret;
8685 struct ecommunity *ecom = NULL;
8686 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
8687 vpn_policy_direction_t dir;
8688 afi_t afi;
8689 int idx = 0;
c6423c31 8690 bool yes = true;
ddb5b488 8691
b9c7bc5a 8692 if (argv_find(argv, argc, "no", &idx))
c6423c31 8693 yes = false;
b9c7bc5a 8694
0ca70ba5 8695 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8696 if (afi == AFI_MAX)
8697 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8698
b9c7bc5a 8699 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
8700 if (ret != CMD_SUCCESS)
8701 return ret;
8702
b9c7bc5a
PZ
8703 if (yes) {
8704 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8705 vty_out(vty, "%% Missing RTLIST\n");
8706 return CMD_WARNING_CONFIG_FAILED;
8707 }
c6423c31 8708 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
8709 if (ret != CMD_SUCCESS) {
8710 return ret;
8711 }
ddb5b488
PZ
8712 }
8713
69b07479
DS
8714 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8715 if (!dodir[dir])
ddb5b488 8716 continue;
ddb5b488 8717
69b07479 8718 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8719
69b07479
DS
8720 if (yes) {
8721 if (bgp->vpn_policy[afi].rtlist[dir])
8722 ecommunity_free(
8723 &bgp->vpn_policy[afi].rtlist[dir]);
8724 bgp->vpn_policy[afi].rtlist[dir] =
8725 ecommunity_dup(ecom);
8726 } else {
8727 if (bgp->vpn_policy[afi].rtlist[dir])
8728 ecommunity_free(
8729 &bgp->vpn_policy[afi].rtlist[dir]);
8730 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 8731 }
69b07479
DS
8732
8733 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8734 }
69b07479 8735
d555f3e9
PZ
8736 if (ecom)
8737 ecommunity_free(&ecom);
ddb5b488
PZ
8738
8739 return CMD_SUCCESS;
8740}
8741
b9c7bc5a
PZ
8742ALIAS (af_rt_vpn_imexport,
8743 af_no_rt_vpn_imexport_cmd,
8744 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
8745 NO_STR
8746 "Specify route target list\n"
b9c7bc5a
PZ
8747 "Specify route target list\n"
8748 "Between current address-family and vpn\n"
8749 "For routes leaked from vpn to current address-family\n"
8750 "For routes leaked from current address-family to vpn\n"
8751 "both import and export\n")
8752
585f1adc 8753DEFPY (af_route_map_vpn_imexport,
b9c7bc5a
PZ
8754 af_route_map_vpn_imexport_cmd,
8755/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8756 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8757 NO_STR
ddb5b488 8758 "Specify route map\n"
b9c7bc5a
PZ
8759 "Between current address-family and vpn\n"
8760 "For routes leaked from vpn to current address-family\n"
8761 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8762 "name of route-map\n")
8763{
585f1adc
IR
8764 VTY_DECLVAR_CONTEXT(bgp, bgp);
8765 int ret;
8766 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8767 vpn_policy_direction_t dir;
ddb5b488 8768 afi_t afi;
ddb5b488 8769 int idx = 0;
585f1adc 8770 bool yes = true;
ddb5b488 8771
585f1adc
IR
8772 if (argv_find(argv, argc, "no", &idx))
8773 yes = false;
ddb5b488 8774
585f1adc
IR
8775 afi = vpn_policy_getafi(vty, bgp, false);
8776 if (afi == AFI_MAX)
8777 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8778
585f1adc
IR
8779 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8780 if (ret != CMD_SUCCESS)
8781 return ret;
ddb5b488 8782
585f1adc
IR
8783 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8784 if (!dodir[dir])
8785 continue;
69b07479 8786
585f1adc
IR
8787 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8788
8789 if (yes) {
8790 if (bgp->vpn_policy[afi].rmap_name[dir])
8791 XFREE(MTYPE_ROUTE_MAP_NAME,
8792 bgp->vpn_policy[afi].rmap_name[dir]);
8793 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
8794 MTYPE_ROUTE_MAP_NAME, rmap_str);
8795 bgp->vpn_policy[afi].rmap[dir] =
8796 route_map_lookup_warn_noexist(vty, rmap_str);
8797 if (!bgp->vpn_policy[afi].rmap[dir])
8798 return CMD_SUCCESS;
8799 } else {
8800 if (bgp->vpn_policy[afi].rmap_name[dir])
8801 XFREE(MTYPE_ROUTE_MAP_NAME,
8802 bgp->vpn_policy[afi].rmap_name[dir]);
8803 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8804 bgp->vpn_policy[afi].rmap[dir] = NULL;
8805 }
8806
8807 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8808 }
ddb5b488 8809
585f1adc 8810 return CMD_SUCCESS;
ddb5b488
PZ
8811}
8812
b9c7bc5a
PZ
8813ALIAS (af_route_map_vpn_imexport,
8814 af_no_route_map_vpn_imexport_cmd,
8815 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
8816 NO_STR
8817 "Specify route map\n"
b9c7bc5a
PZ
8818 "Between current address-family and vpn\n"
8819 "For routes leaked from vpn to current address-family\n"
8820 "For routes leaked from current address-family to vpn\n")
8821
bb4f6190 8822DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 8823 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
8824 "Import routes from another VRF\n"
8825 "Vrf routes being filtered\n"
8826 "Specify route map\n"
8827 "name of route-map\n")
8828{
8829 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
8830 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8831 afi_t afi;
bb4f6190
DS
8832 struct bgp *bgp_default;
8833
0ca70ba5 8834 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
8835 if (afi == AFI_MAX)
8836 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
8837
8838 bgp_default = bgp_get_default();
8839 if (!bgp_default) {
8840 int32_t ret;
8841 as_t as = bgp->as;
8842
8843 /* Auto-create assuming the same AS */
5d5393b9
DL
8844 ret = bgp_get_vty(&bgp_default, &as, NULL,
8845 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
8846
8847 if (ret) {
8848 vty_out(vty,
8849 "VRF default is not configured as a bgp instance\n");
8850 return CMD_WARNING;
8851 }
8852 }
8853
69b07479 8854 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 8855
ae6a6fb4
DS
8856 if (bgp->vpn_policy[afi].rmap_name[dir])
8857 XFREE(MTYPE_ROUTE_MAP_NAME,
8858 bgp->vpn_policy[afi].rmap_name[dir]);
8859 bgp->vpn_policy[afi].rmap_name[dir] =
8860 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8861 bgp->vpn_policy[afi].rmap[dir] =
8862 route_map_lookup_warn_noexist(vty, rmap_str);
8863 if (!bgp->vpn_policy[afi].rmap[dir])
8864 return CMD_SUCCESS;
8865
8866 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8867 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 8868
69b07479
DS
8869 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8870
bb4f6190
DS
8871 return CMD_SUCCESS;
8872}
8873
ae6a6fb4
DS
8874DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
8875 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
8876 NO_STR
8877 "Import routes from another VRF\n"
8878 "Vrf routes being filtered\n"
ae6a6fb4
DS
8879 "Specify route map\n"
8880 "name of route-map\n")
8881{
8882 VTY_DECLVAR_CONTEXT(bgp, bgp);
8883 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8884 afi_t afi;
8885
8886 afi = vpn_policy_getafi(vty, bgp, true);
8887 if (afi == AFI_MAX)
8888 return CMD_WARNING_CONFIG_FAILED;
8889
8890 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8891
8892 if (bgp->vpn_policy[afi].rmap_name[dir])
8893 XFREE(MTYPE_ROUTE_MAP_NAME,
8894 bgp->vpn_policy[afi].rmap_name[dir]);
8895 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8896 bgp->vpn_policy[afi].rmap[dir] = NULL;
8897
8898 if (bgp->vpn_policy[afi].import_vrf->count == 0)
8899 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8900 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8901
8902 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8903
8904 return CMD_SUCCESS;
8905}
bb4f6190 8906
585f1adc
IR
8907DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
8908 "[no] import vrf VIEWVRFNAME$import_name",
8909 NO_STR
8910 "Import routes from another VRF\n"
8911 "VRF to import from\n"
8912 "The name of the VRF\n")
12a844a5 8913{
585f1adc
IR
8914 VTY_DECLVAR_CONTEXT(bgp, bgp);
8915 struct listnode *node;
8916 struct bgp *vrf_bgp, *bgp_default;
8917 int32_t ret = 0;
8918 as_t as = bgp->as;
8919 bool remove = false;
8920 int32_t idx = 0;
8921 char *vname;
8922 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
8923 safi_t safi;
8924 afi_t afi;
8925
867f0cca 8926 if (import_name == NULL) {
8927 vty_out(vty, "%% Missing import name\n");
8928 return CMD_WARNING;
8929 }
8930
ae6a6fb4
DS
8931 if (strcmp(import_name, "route-map") == 0) {
8932 vty_out(vty, "%% Must include route-map name\n");
8933 return CMD_WARNING;
8934 }
8935
585f1adc
IR
8936 if (argv_find(argv, argc, "no", &idx))
8937 remove = true;
8938
8939 afi = vpn_policy_getafi(vty, bgp, true);
8940 if (afi == AFI_MAX)
8941 return CMD_WARNING_CONFIG_FAILED;
8942
12a844a5
DS
8943 safi = bgp_node_safi(vty);
8944
585f1adc
IR
8945 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
8946 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
8947 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
8948 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
8949 remove ? "unimport" : "import", import_name);
8950 return CMD_WARNING;
8951 }
25679caa 8952
585f1adc
IR
8953 bgp_default = bgp_get_default();
8954 if (!bgp_default) {
8955 /* Auto-create assuming the same AS */
8956 ret = bgp_get_vty(&bgp_default, &as, NULL,
8957 BGP_INSTANCE_TYPE_DEFAULT);
12a844a5 8958
585f1adc
IR
8959 if (ret) {
8960 vty_out(vty,
8961 "VRF default is not configured as a bgp instance\n");
8962 return CMD_WARNING;
8963 }
8964 }
12a844a5 8965
585f1adc
IR
8966 vrf_bgp = bgp_lookup_by_name(import_name);
8967 if (!vrf_bgp) {
8968 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
8969 vrf_bgp = bgp_default;
8970 else
8971 /* Auto-create assuming the same AS */
8972 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
8973
8974 if (ret) {
8975 vty_out(vty,
8976 "VRF %s is not configured as a bgp instance\n",
8977 import_name);
8978 return CMD_WARNING;
8979 }
8980 }
8981
8982 if (remove) {
8983 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
8984 } else {
8985 /* Already importing from "import_vrf"? */
8986 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
8987 vname)) {
8988 if (strcmp(vname, import_name) == 0)
8989 return CMD_WARNING;
8990 }
8991
8992 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
8993 }
8994
8995 return CMD_SUCCESS;
12a844a5
DS
8996}
8997
b9c7bc5a 8998/* This command is valid only in a bgp vrf instance or the default instance */
585f1adc 8999DEFPY (bgp_imexport_vpn,
b9c7bc5a
PZ
9000 bgp_imexport_vpn_cmd,
9001 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9002 NO_STR
9003 "Import routes to this address-family\n"
9004 "Export routes from this address-family\n"
9005 "to/from default instance VPN RIB\n")
ddb5b488 9006{
585f1adc
IR
9007 VTY_DECLVAR_CONTEXT(bgp, bgp);
9008 int previous_state;
37a87b8f 9009 afi_t afi;
585f1adc
IR
9010 safi_t safi;
9011 int idx = 0;
9012 bool yes = true;
9013 int flag;
9014 vpn_policy_direction_t dir;
9015
9016 if (argv_find(argv, argc, "no", &idx))
9017 yes = false;
9018
9019 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9020 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9021
9022 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9023 return CMD_WARNING_CONFIG_FAILED;
9024 }
ddb5b488 9025
b9c7bc5a
PZ
9026 afi = bgp_node_afi(vty);
9027 safi = bgp_node_safi(vty);
585f1adc
IR
9028 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9029 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9030 return CMD_WARNING_CONFIG_FAILED;
9031 }
ddb5b488 9032
b9c7bc5a 9033 if (!strcmp(direction_str, "import")) {
585f1adc
IR
9034 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9035 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b9c7bc5a 9036 } else if (!strcmp(direction_str, "export")) {
585f1adc
IR
9037 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9038 dir = BGP_VPN_POLICY_DIR_TOVPN;
b9c7bc5a
PZ
9039 } else {
9040 vty_out(vty, "%% unknown direction %s\n", direction_str);
9041 return CMD_WARNING_CONFIG_FAILED;
9042 }
9043
585f1adc 9044 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 9045
585f1adc
IR
9046 if (yes) {
9047 SET_FLAG(bgp->af_flags[afi][safi], flag);
9048 if (!previous_state) {
9049 /* trigger export current vrf */
9050 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9051 }
9052 } else {
9053 if (previous_state) {
9054 /* trigger un-export current vrf */
9055 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9056 }
9057 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9058 }
37a87b8f 9059
1ca2fd11
IR
9060 hook_call(bgp_snmp_init_stats, bgp);
9061
585f1adc 9062 return CMD_SUCCESS;
ddb5b488
PZ
9063}
9064
301ad80a
PG
9065DEFPY (af_routetarget_import,
9066 af_routetarget_import_cmd,
9a659715 9067 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9068 NO_STR
9069 "Specify route target list\n"
9070 "Specify route target list\n"
9a659715
PG
9071 "Specify route target list\n"
9072 "Specify route target list\n"
301ad80a
PG
9073 "Flow-spec redirect type route target\n"
9074 "Import routes to this address-family\n"
9a659715 9075 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9076{
9077 VTY_DECLVAR_CONTEXT(bgp, bgp);
9078 int ret;
9079 struct ecommunity *ecom = NULL;
301ad80a 9080 afi_t afi;
9a659715 9081 int idx = 0, idx_unused = 0;
c6423c31
PG
9082 bool yes = true;
9083 bool rt6 = false;
301ad80a
PG
9084
9085 if (argv_find(argv, argc, "no", &idx))
c6423c31 9086 yes = false;
301ad80a 9087
9a659715
PG
9088 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9089 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9090 rt6 = true;
301ad80a 9091
0ca70ba5 9092 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9093 if (afi == AFI_MAX)
9094 return CMD_WARNING_CONFIG_FAILED;
9095
9a659715
PG
9096 if (rt6 && afi != AFI_IP6)
9097 return CMD_WARNING_CONFIG_FAILED;
9098
301ad80a
PG
9099 if (yes) {
9100 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9101 vty_out(vty, "%% Missing RTLIST\n");
9102 return CMD_WARNING_CONFIG_FAILED;
9103 }
9a659715 9104 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9105 if (ret != CMD_SUCCESS)
9106 return ret;
9107 }
69b07479
DS
9108
9109 if (yes) {
9110 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9111 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9112 .import_redirect_rtlist);
69b07479
DS
9113 bgp->vpn_policy[afi].import_redirect_rtlist =
9114 ecommunity_dup(ecom);
9115 } else {
9116 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9117 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9118 .import_redirect_rtlist);
69b07479 9119 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9120 }
69b07479 9121
301ad80a
PG
9122 if (ecom)
9123 ecommunity_free(&ecom);
9124
9125 return CMD_SUCCESS;
9126}
9127
505e5056 9128DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9129 address_family_ipv4_safi_cmd,
9130 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9131 "Enter Address Family command mode\n"
9132 "Address Family\n"
9133 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9134{
f51bae9c 9135
d62a17ae 9136 if (argc == 3) {
585f1adc
IR
9137 VTY_DECLVAR_CONTEXT(bgp, bgp);
9138 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9139 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9140 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9141 && safi != SAFI_EVPN) {
31947174
MK
9142 vty_out(vty,
9143 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9144 return CMD_WARNING_CONFIG_FAILED;
9145 }
585f1adc
IR
9146 vty->node = bgp_node_type(AFI_IP, safi);
9147 } else
9148 vty->node = BGP_IPV4_NODE;
718e3744 9149
d62a17ae 9150 return CMD_SUCCESS;
718e3744 9151}
9152
505e5056 9153DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9154 address_family_ipv6_safi_cmd,
9155 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9156 "Enter Address Family command mode\n"
9157 "Address Family\n"
9158 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9159{
d62a17ae 9160 if (argc == 3) {
585f1adc
IR
9161 VTY_DECLVAR_CONTEXT(bgp, bgp);
9162 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9163 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9164 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9165 && safi != SAFI_EVPN) {
31947174
MK
9166 vty_out(vty,
9167 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9168 return CMD_WARNING_CONFIG_FAILED;
9169 }
585f1adc
IR
9170 vty->node = bgp_node_type(AFI_IP6, safi);
9171 } else
9172 vty->node = BGP_IPV6_NODE;
25ffbdc1 9173
d62a17ae 9174 return CMD_SUCCESS;
25ffbdc1 9175}
718e3744 9176
d6902373 9177#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9178DEFUN_NOSH (address_family_vpnv4,
718e3744 9179 address_family_vpnv4_cmd,
8334fd5a 9180 "address-family vpnv4 [unicast]",
718e3744 9181 "Enter Address Family command mode\n"
8c3deaae 9182 "Address Family\n"
3a2d747c 9183 "Address Family modifier\n")
718e3744 9184{
d62a17ae 9185 vty->node = BGP_VPNV4_NODE;
9186 return CMD_SUCCESS;
718e3744 9187}
9188
505e5056 9189DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9190 address_family_vpnv6_cmd,
8334fd5a 9191 "address-family vpnv6 [unicast]",
8ecd3266 9192 "Enter Address Family command mode\n"
8c3deaae 9193 "Address Family\n"
3a2d747c 9194 "Address Family modifier\n")
8ecd3266 9195{
d62a17ae 9196 vty->node = BGP_VPNV6_NODE;
9197 return CMD_SUCCESS;
8ecd3266 9198}
64e4a6c5 9199#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9200
505e5056 9201DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9202 address_family_evpn_cmd,
7111c1a0 9203 "address-family l2vpn evpn",
4e0b7b6d 9204 "Enter Address Family command mode\n"
7111c1a0
QY
9205 "Address Family\n"
9206 "Address Family modifier\n")
4e0b7b6d 9207{
2131d5cf 9208 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9209 vty->node = BGP_EVPN_NODE;
9210 return CMD_SUCCESS;
4e0b7b6d
PG
9211}
9212
bfaab44d
HS
9213DEFUN_NOSH (bgp_segment_routing_srv6,
9214 bgp_segment_routing_srv6_cmd,
9215 "segment-routing srv6",
9216 "Segment-Routing configuration\n"
9217 "Segment-Routing SRv6 configuration\n")
9218{
9219 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 9220 bgp->srv6_enabled = true;
bfaab44d
HS
9221 vty->node = BGP_SRV6_NODE;
9222 return CMD_SUCCESS;
9223}
9224
0249b8b6
HS
9225DEFUN (no_bgp_segment_routing_srv6,
9226 no_bgp_segment_routing_srv6_cmd,
9227 "no segment-routing srv6",
9228 NO_STR
9229 "Segment-Routing configuration\n"
9230 "Segment-Routing SRv6 configuration\n")
9231{
9232 VTY_DECLVAR_CONTEXT(bgp, bgp);
9233
9234 if (strlen(bgp->srv6_locator_name) > 0)
9235 if (bgp_srv6_locator_unset(bgp) < 0)
9236 return CMD_WARNING_CONFIG_FAILED;
9237
9238 bgp->srv6_enabled = false;
9239 return CMD_SUCCESS;
9240}
9241
a0281b2e
HS
9242DEFPY (bgp_srv6_locator,
9243 bgp_srv6_locator_cmd,
9244 "locator NAME$name",
9245 "Specify SRv6 locator\n"
9246 "Specify SRv6 locator\n")
9247{
9248 VTY_DECLVAR_CONTEXT(bgp, bgp);
7de4c885 9249 int ret;
a0281b2e
HS
9250
9251 if (strlen(bgp->srv6_locator_name) > 0
9252 && strcmp(name, bgp->srv6_locator_name) != 0) {
9253 vty_out(vty, "srv6 locator is already configured\n");
9254 return CMD_WARNING_CONFIG_FAILED;
7de4c885
HS
9255 }
9256
9257 snprintf(bgp->srv6_locator_name,
9258 sizeof(bgp->srv6_locator_name), "%s", name);
a0281b2e 9259
7de4c885 9260 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
a0281b2e
HS
9261 if (ret < 0)
9262 return CMD_WARNING_CONFIG_FAILED;
9263
9264 return CMD_SUCCESS;
9265}
9266
0249b8b6
HS
9267DEFPY (no_bgp_srv6_locator,
9268 no_bgp_srv6_locator_cmd,
9269 "no locator NAME$name",
9270 NO_STR
9271 "Specify SRv6 locator\n"
9272 "Specify SRv6 locator\n")
9273{
9274 VTY_DECLVAR_CONTEXT(bgp, bgp);
9275
9276 /* when locator isn't configured, do nothing */
9277 if (strlen(bgp->srv6_locator_name) < 1)
9278 return CMD_SUCCESS;
9279
9280 /* name validation */
9281 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9282 vty_out(vty, "%% No srv6 locator is configured\n");
9283 return CMD_WARNING_CONFIG_FAILED;
9284 }
9285
9286 /* unset locator */
9287 if (bgp_srv6_locator_unset(bgp) < 0)
9288 return CMD_WARNING_CONFIG_FAILED;
9289
9290 return CMD_SUCCESS;
9291}
9292
ea372e81
HS
9293DEFPY (show_bgp_srv6,
9294 show_bgp_srv6_cmd,
9295 "show bgp segment-routing srv6",
9296 SHOW_STR
9297 BGP_STR
9298 "BGP Segment Routing\n"
9299 "BGP Segment Routing SRv6\n")
9300{
9301 struct bgp *bgp;
9302 struct listnode *node;
9303 struct prefix_ipv6 *chunk;
9304 struct bgp_srv6_function *func;
9305 struct in6_addr *tovpn4_sid;
9306 struct in6_addr *tovpn6_sid;
9307 char buf[256];
9308 char buf_tovpn4_sid[256];
9309 char buf_tovpn6_sid[256];
9310
9311 bgp = bgp_get_default();
96db4340 9312 if (!bgp)
ea372e81
HS
9313 return CMD_SUCCESS;
9314
9315 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9316 vty_out(vty, "locator_chunks:\n");
9317 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9318 prefix2str(chunk, buf, sizeof(buf));
9319 vty_out(vty, "- %s\n", buf);
9320 }
9321
9322 vty_out(vty, "functions:\n");
9323 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9324 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9325 vty_out(vty, "- sid: %s\n", buf);
9326 vty_out(vty, " locator: %s\n", func->locator_name);
9327 }
9328
9329 vty_out(vty, "bgps:\n");
9330 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9331 vty_out(vty, "- name: %s\n",
9332 bgp->name ? bgp->name : "default");
9333
9334 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9335 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9336 if (tovpn4_sid)
9337 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9338 sizeof(buf_tovpn4_sid));
9339 if (tovpn6_sid)
9340 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9341 sizeof(buf_tovpn6_sid));
9342
9343 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9344 tovpn4_sid ? buf_tovpn4_sid : "none");
9345 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9346 tovpn6_sid ? buf_tovpn6_sid : "none");
9347 }
9348
9349 return CMD_SUCCESS;
9350}
9351
505e5056 9352DEFUN_NOSH (exit_address_family,
718e3744 9353 exit_address_family_cmd,
9354 "exit-address-family",
9355 "Exit from Address Family configuration mode\n")
9356{
d62a17ae 9357 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9358 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9359 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9360 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9361 || vty->node == BGP_EVPN_NODE
9362 || vty->node == BGP_FLOWSPECV4_NODE
9363 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9364 vty->node = BGP_NODE;
9365 return CMD_SUCCESS;
718e3744 9366}
6b0655a2 9367
8ad7271d 9368/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9369static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9370 const char *ip_str, afi_t afi, safi_t safi,
9371 struct prefix_rd *prd)
9372{
9373 int ret;
9374 struct prefix match;
9bcb3eef
DS
9375 struct bgp_dest *dest;
9376 struct bgp_dest *rm;
d62a17ae 9377 struct bgp *bgp;
9378 struct bgp_table *table;
9379 struct bgp_table *rib;
9380
9381 /* BGP structure lookup. */
9382 if (view_name) {
9383 bgp = bgp_lookup_by_name(view_name);
9384 if (bgp == NULL) {
9385 vty_out(vty, "%% Can't find BGP instance %s\n",
9386 view_name);
9387 return CMD_WARNING;
9388 }
9389 } else {
9390 bgp = bgp_get_default();
9391 if (bgp == NULL) {
9392 vty_out(vty, "%% No BGP process is configured\n");
9393 return CMD_WARNING;
9394 }
9395 }
9396
9397 /* Check IP address argument. */
9398 ret = str2prefix(ip_str, &match);
9399 if (!ret) {
9400 vty_out(vty, "%% address is malformed\n");
9401 return CMD_WARNING;
9402 }
9403
9404 match.family = afi2family(afi);
9405 rib = bgp->rib[afi][safi];
9406
9407 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9408 for (dest = bgp_table_top(rib); dest;
9409 dest = bgp_route_next(dest)) {
9410 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9411
9bcb3eef 9412 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9413 continue;
9414
9bcb3eef 9415 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9416 if (table == NULL)
9417 continue;
9418
4953391b
DA
9419 rm = bgp_node_match(table, &match);
9420 if (rm != NULL) {
b54892e0 9421 const struct prefix *rm_p =
9bcb3eef 9422 bgp_dest_get_prefix(rm);
b54892e0
DS
9423
9424 if (rm_p->prefixlen == match.prefixlen) {
9425 SET_FLAG(rm->flags,
9426 BGP_NODE_USER_CLEAR);
9427 bgp_process(bgp, rm, afi, safi);
d62a17ae 9428 }
9bcb3eef 9429 bgp_dest_unlock_node(rm);
d62a17ae 9430 }
9431 }
9432 } else {
4953391b
DA
9433 dest = bgp_node_match(rib, &match);
9434 if (dest != NULL) {
9bcb3eef 9435 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9436
9bcb3eef
DS
9437 if (dest_p->prefixlen == match.prefixlen) {
9438 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9439 bgp_process(bgp, dest, afi, safi);
d62a17ae 9440 }
9bcb3eef 9441 bgp_dest_unlock_node(dest);
d62a17ae 9442 }
9443 }
9444
9445 return CMD_SUCCESS;
8ad7271d
DS
9446}
9447
b09b5ae0 9448/* one clear bgp command to rule them all */
718e3744 9449DEFUN (clear_ip_bgp_all,
9450 clear_ip_bgp_all_cmd,
3cb14f26 9451 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D$neighbor|X:X::X:X$neighbor|WORD$neighbor|(1-4294967295)|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out|message-stats>]",
718e3744 9452 CLEAR_STR
9453 IP_STR
9454 BGP_STR
838758ac 9455 BGP_INSTANCE_HELP_STR
510afcd6 9456 BGP_AFI_HELP_STR
fd5e7b70 9457 "Address Family\n"
510afcd6 9458 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 9459 "Address Family modifier\n"
b09b5ae0 9460 "Clear all peers\n"
453c92f6 9461 "BGP IPv4 neighbor to clear\n"
a80beece 9462 "BGP IPv6 neighbor to clear\n"
838758ac 9463 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9464 "Clear peers with the AS number\n"
9465 "Clear all external peers\n"
718e3744 9466 "Clear all members of peer-group\n"
b09b5ae0 9467 "BGP peer-group name\n"
b09b5ae0
DW
9468 BGP_SOFT_STR
9469 BGP_SOFT_IN_STR
b09b5ae0
DW
9470 BGP_SOFT_OUT_STR
9471 BGP_SOFT_IN_STR
9472 "Push out prefix-list ORF and do inbound soft reconfig\n"
3cb14f26
DS
9473 BGP_SOFT_OUT_STR
9474 "Reset message statistics\n")
718e3744 9475{
d62a17ae 9476 char *vrf = NULL;
9477
dc912615
DS
9478 afi_t afi = AFI_UNSPEC;
9479 safi_t safi = SAFI_UNSPEC;
d62a17ae 9480 enum clear_sort clr_sort = clear_peer;
9481 enum bgp_clear_type clr_type;
9482 char *clr_arg = NULL;
9483
9484 int idx = 0;
9485
9486 /* clear [ip] bgp */
9487 if (argv_find(argv, argc, "ip", &idx))
9488 afi = AFI_IP;
9489
9a8bdf1c
PG
9490 /* [<vrf> VIEWVRFNAME] */
9491 if (argv_find(argv, argc, "vrf", &idx)) {
9492 vrf = argv[idx + 1]->arg;
9493 idx += 2;
9494 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9495 vrf = NULL;
9496 } else if (argv_find(argv, argc, "view", &idx)) {
9497 /* [<view> VIEWVRFNAME] */
d62a17ae 9498 vrf = argv[idx + 1]->arg;
9499 idx += 2;
9500 }
d62a17ae 9501 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9502 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9503 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9504
d7b9898c 9505 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 9506 if (argv_find(argv, argc, "*", &idx)) {
9507 clr_sort = clear_all;
9508 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9509 clr_sort = clear_peer;
9510 clr_arg = argv[idx]->arg;
9511 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9512 clr_sort = clear_peer;
9513 clr_arg = argv[idx]->arg;
9514 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9515 clr_sort = clear_group;
9516 idx++;
9517 clr_arg = argv[idx]->arg;
d7b9898c 9518 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 9519 clr_sort = clear_peer;
9520 clr_arg = argv[idx]->arg;
8fa7d444
DS
9521 } else if (argv_find(argv, argc, "WORD", &idx)) {
9522 clr_sort = clear_peer;
9523 clr_arg = argv[idx]->arg;
d62a17ae 9524 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9525 clr_sort = clear_as;
9526 clr_arg = argv[idx]->arg;
9527 } else if (argv_find(argv, argc, "external", &idx)) {
9528 clr_sort = clear_external;
9529 }
9530
3cb14f26 9531 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
d62a17ae 9532 if (argv_find(argv, argc, "soft", &idx)) {
9533 if (argv_find(argv, argc, "in", &idx)
9534 || argv_find(argv, argc, "out", &idx))
9535 clr_type = strmatch(argv[idx]->text, "in")
9536 ? BGP_CLEAR_SOFT_IN
9537 : BGP_CLEAR_SOFT_OUT;
9538 else
9539 clr_type = BGP_CLEAR_SOFT_BOTH;
9540 } else if (argv_find(argv, argc, "in", &idx)) {
9541 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9542 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9543 : BGP_CLEAR_SOFT_IN;
9544 } else if (argv_find(argv, argc, "out", &idx)) {
9545 clr_type = BGP_CLEAR_SOFT_OUT;
3cb14f26
DS
9546 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9547 clr_type = BGP_CLEAR_MESSAGE_STATS;
d62a17ae 9548 } else
9549 clr_type = BGP_CLEAR_SOFT_NONE;
9550
1ca2fd11 9551 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 9552}
01080f7c 9553
8ad7271d
DS
9554DEFUN (clear_ip_bgp_prefix,
9555 clear_ip_bgp_prefix_cmd,
18c57037 9556 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
9557 CLEAR_STR
9558 IP_STR
9559 BGP_STR
838758ac 9560 BGP_INSTANCE_HELP_STR
8ad7271d 9561 "Clear bestpath and re-advertise\n"
0c7b1b01 9562 "IPv4 prefix\n")
8ad7271d 9563{
d62a17ae 9564 char *vrf = NULL;
9565 char *prefix = NULL;
8ad7271d 9566
d62a17ae 9567 int idx = 0;
01080f7c 9568
d62a17ae 9569 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
9570 if (argv_find(argv, argc, "vrf", &idx)) {
9571 vrf = argv[idx + 1]->arg;
9572 idx += 2;
9573 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9574 vrf = NULL;
9575 } else if (argv_find(argv, argc, "view", &idx)) {
9576 /* [<view> VIEWVRFNAME] */
9577 vrf = argv[idx + 1]->arg;
9578 idx += 2;
9579 }
0c7b1b01 9580
d62a17ae 9581 prefix = argv[argc - 1]->arg;
8ad7271d 9582
d62a17ae 9583 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 9584}
8ad7271d 9585
b09b5ae0
DW
9586DEFUN (clear_bgp_ipv6_safi_prefix,
9587 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 9588 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9589 CLEAR_STR
3a2d747c 9590 IP_STR
718e3744 9591 BGP_STR
8c3deaae 9592 "Address Family\n"
46f296b4 9593 BGP_SAFI_HELP_STR
b09b5ae0 9594 "Clear bestpath and re-advertise\n"
0c7b1b01 9595 "IPv6 prefix\n")
718e3744 9596{
9b475e76
PG
9597 int idx_safi = 0;
9598 int idx_ipv6_prefix = 0;
9599 safi_t safi = SAFI_UNICAST;
9600 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9601 argv[idx_ipv6_prefix]->arg : NULL;
9602
9603 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 9604 return bgp_clear_prefix(
9b475e76
PG
9605 vty, NULL, prefix, AFI_IP6,
9606 safi, NULL);
838758ac 9607}
01080f7c 9608
b09b5ae0
DW
9609DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9610 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 9611 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9612 CLEAR_STR
3a2d747c 9613 IP_STR
718e3744 9614 BGP_STR
838758ac 9615 BGP_INSTANCE_HELP_STR
8c3deaae 9616 "Address Family\n"
46f296b4 9617 BGP_SAFI_HELP_STR
b09b5ae0 9618 "Clear bestpath and re-advertise\n"
0c7b1b01 9619 "IPv6 prefix\n")
718e3744 9620{
9b475e76 9621 int idx_safi = 0;
9a8bdf1c 9622 int idx_vrfview = 0;
9b475e76
PG
9623 int idx_ipv6_prefix = 0;
9624 safi_t safi = SAFI_UNICAST;
9625 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9626 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 9627 char *vrfview = NULL;
9b475e76 9628
9a8bdf1c
PG
9629 /* [<view|vrf> VIEWVRFNAME] */
9630 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9631 vrfview = argv[idx_vrfview + 1]->arg;
9632 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9633 vrfview = NULL;
9634 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9635 /* [<view> VIEWVRFNAME] */
9636 vrfview = argv[idx_vrfview + 1]->arg;
9637 }
9b475e76
PG
9638 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9639
d62a17ae 9640 return bgp_clear_prefix(
9b475e76
PG
9641 vty, vrfview, prefix,
9642 AFI_IP6, safi, NULL);
718e3744 9643}
9644
b09b5ae0
DW
9645DEFUN (show_bgp_views,
9646 show_bgp_views_cmd,
d6e3c605 9647 "show [ip] bgp views",
b09b5ae0 9648 SHOW_STR
d6e3c605 9649 IP_STR
01080f7c 9650 BGP_STR
b09b5ae0 9651 "Show the defined BGP views\n")
01080f7c 9652{
d62a17ae 9653 struct list *inst = bm->bgp;
9654 struct listnode *node;
9655 struct bgp *bgp;
01080f7c 9656
d62a17ae 9657 vty_out(vty, "Defined BGP views:\n");
9658 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9659 /* Skip VRFs. */
9660 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9661 continue;
9662 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9663 bgp->as);
9664 }
e52702f2 9665
d62a17ae 9666 return CMD_SUCCESS;
e0081f70
ML
9667}
9668
8386ac43 9669DEFUN (show_bgp_vrfs,
9670 show_bgp_vrfs_cmd,
d6e3c605 9671 "show [ip] bgp vrfs [json]",
8386ac43 9672 SHOW_STR
d6e3c605 9673 IP_STR
8386ac43 9674 BGP_STR
9675 "Show BGP VRFs\n"
9973d184 9676 JSON_STR)
8386ac43 9677{
fe1dc5a3 9678 char buf[ETHER_ADDR_STRLEN];
d62a17ae 9679 struct list *inst = bm->bgp;
9680 struct listnode *node;
9681 struct bgp *bgp;
9f049418 9682 bool uj = use_json(argc, argv);
d62a17ae 9683 json_object *json = NULL;
9684 json_object *json_vrfs = NULL;
9685 int count = 0;
d62a17ae 9686
d62a17ae 9687 if (uj) {
9688 json = json_object_new_object();
9689 json_vrfs = json_object_new_object();
9690 }
9691
9692 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9693 const char *name, *type;
9694 struct peer *peer;
7fe96307 9695 struct listnode *node2, *nnode2;
d62a17ae 9696 int peers_cfg, peers_estb;
9697 json_object *json_vrf = NULL;
d62a17ae 9698
9699 /* Skip Views. */
9700 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9701 continue;
9702
9703 count++;
efb4077a 9704 if (!uj && count == 1) {
fe1dc5a3 9705 vty_out(vty,
efb4077a 9706 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 9707 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
9708 "#PeersEstb", "Name");
9709 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9710 "L3-VNI", "RouterMAC", "Interface");
9711 }
d62a17ae 9712
9713 peers_cfg = peers_estb = 0;
9714 if (uj)
9715 json_vrf = json_object_new_object();
9716
9717
7fe96307 9718 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 9719 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9720 continue;
9721 peers_cfg++;
feb17238 9722 if (peer_established(peer))
d62a17ae 9723 peers_estb++;
9724 }
9725
9726 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 9727 name = VRF_DEFAULT_NAME;
d62a17ae 9728 type = "DFLT";
9729 } else {
9730 name = bgp->name;
9731 type = "VRF";
9732 }
9733
a8bf7d9c 9734
d62a17ae 9735 if (uj) {
a4d82a8a
PZ
9736 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9737 ? -1
9738 : (int64_t)bgp->vrf_id;
23d0a753
DA
9739 char buf[BUFSIZ] = {0};
9740
d62a17ae 9741 json_object_string_add(json_vrf, "type", type);
9742 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
c949c771
DA
9743 json_object_string_addf(json_vrf, "routerId", "%pI4",
9744 &bgp->router_id);
d62a17ae 9745 json_object_int_add(json_vrf, "numConfiguredPeers",
9746 peers_cfg);
9747 json_object_int_add(json_vrf, "numEstablishedPeers",
9748 peers_estb);
9749
fe1dc5a3 9750 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
9751 json_object_string_add(
9752 json_vrf, "rmac",
9753 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
9754 json_object_string_add(json_vrf, "interface",
9755 ifindex2ifname(bgp->l3vni_svi_ifindex,
9756 bgp->vrf_id));
d62a17ae 9757 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 9758 } else {
23d0a753 9759 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
9760 type,
9761 bgp->vrf_id == VRF_UNKNOWN ? -1
9762 : (int)bgp->vrf_id,
23d0a753 9763 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
9764 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
9765 bgp->l3vni,
9766 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
9767 ifindex2ifname(bgp->l3vni_svi_ifindex,
9768 bgp->vrf_id));
9769 }
d62a17ae 9770 }
9771
9772 if (uj) {
9773 json_object_object_add(json, "vrfs", json_vrfs);
9774
9775 json_object_int_add(json, "totalVrfs", count);
9776
75eeda93 9777 vty_json(vty, json);
d62a17ae 9778 } else {
9779 if (count)
9780 vty_out(vty,
9781 "\nTotal number of VRFs (including default): %d\n",
9782 count);
9783 }
9784
9785 return CMD_SUCCESS;
8386ac43 9786}
9787
48ecf8f5
DS
9788DEFUN (show_bgp_mac_hash,
9789 show_bgp_mac_hash_cmd,
9790 "show bgp mac hash",
9791 SHOW_STR
9792 BGP_STR
9793 "Mac Address\n"
9794 "Mac Address database\n")
9795{
9796 bgp_mac_dump_table(vty);
9797
9798 return CMD_SUCCESS;
9799}
acf71666 9800
e3b78da8 9801static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 9802{
0291c246 9803 struct vty *vty = (struct vty *)args;
e3b78da8 9804 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 9805
23d0a753 9806 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
9807}
9808
9809static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
9810{
9811 vty_out(vty, "self nexthop database:\n");
af97a18b 9812 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
9813
9814 vty_out(vty, "Tunnel-ip database:\n");
9815 hash_iterate(bgp->tip_hash,
e3b78da8 9816 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
9817 vty);
9818}
9819
15c81ca4
DS
9820DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
9821 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
9822 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
9823 "martian next-hops\n"
9824 "martian next-hop database\n")
acf71666 9825{
0291c246 9826 struct bgp *bgp = NULL;
15c81ca4 9827 int idx = 0;
9a8bdf1c
PG
9828 char *name = NULL;
9829
9830 /* [<vrf> VIEWVRFNAME] */
9831 if (argv_find(argv, argc, "vrf", &idx)) {
9832 name = argv[idx + 1]->arg;
9833 if (name && strmatch(name, VRF_DEFAULT_NAME))
9834 name = NULL;
9835 } else if (argv_find(argv, argc, "view", &idx))
9836 /* [<view> VIEWVRFNAME] */
9837 name = argv[idx + 1]->arg;
9838 if (name)
9839 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
9840 else
9841 bgp = bgp_get_default();
acf71666 9842
acf71666
MK
9843 if (!bgp) {
9844 vty_out(vty, "%% No BGP process is configured\n");
9845 return CMD_WARNING;
9846 }
9847 bgp_show_martian_nexthops(vty, bgp);
9848
9849 return CMD_SUCCESS;
9850}
9851
f412b39a 9852DEFUN (show_bgp_memory,
4bf6a362 9853 show_bgp_memory_cmd,
7fa12b13 9854 "show [ip] bgp memory",
4bf6a362 9855 SHOW_STR
3a2d747c 9856 IP_STR
4bf6a362
PJ
9857 BGP_STR
9858 "Global BGP memory statistics\n")
9859{
d62a17ae 9860 char memstrbuf[MTYPE_MEMSTR_LEN];
9861 unsigned long count;
9862
9863 /* RIB related usage stats */
9864 count = mtype_stats_alloc(MTYPE_BGP_NODE);
9865 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
9866 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 9867 count * sizeof(struct bgp_dest)));
d62a17ae 9868
9869 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
9870 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
9871 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 9872 count * sizeof(struct bgp_path_info)));
d62a17ae 9873 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
9874 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
9875 count,
4b7e6066
DS
9876 mtype_memstr(
9877 memstrbuf, sizeof(memstrbuf),
9878 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 9879
9880 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
9881 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
9882 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9883 count * sizeof(struct bgp_static)));
9884
9885 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
9886 vty_out(vty, "%ld Packets, using %s of memory\n", count,
9887 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9888 count * sizeof(struct bpacket)));
9889
9890 /* Adj-In/Out */
9891 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
9892 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
9893 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9894 count * sizeof(struct bgp_adj_in)));
9895 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
9896 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
9897 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9898 count * sizeof(struct bgp_adj_out)));
9899
9900 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
9901 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
9902 count,
9903 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9904 count * sizeof(struct bgp_nexthop_cache)));
9905
9906 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
9907 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
9908 count,
9909 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9910 count * sizeof(struct bgp_damp_info)));
9911
9912 /* Attributes */
9913 count = attr_count();
9914 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
9915 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9916 count * sizeof(struct attr)));
9917
9918 if ((count = attr_unknown_count()))
9919 vty_out(vty, "%ld unknown attributes\n", count);
9920
9921 /* AS_PATH attributes */
9922 count = aspath_count();
9923 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
9924 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9925 count * sizeof(struct aspath)));
9926
9927 count = mtype_stats_alloc(MTYPE_AS_SEG);
9928 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
9929 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9930 count * sizeof(struct assegment)));
9931
9932 /* Other attributes */
9933 if ((count = community_count()))
9934 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9935 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9936 count * sizeof(struct community)));
d62a17ae 9937 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
9938 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9939 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9940 count * sizeof(struct ecommunity)));
d62a17ae 9941 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
9942 vty_out(vty,
9943 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
9944 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9945 count * sizeof(struct lcommunity)));
d62a17ae 9946
9947 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
9948 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
9949 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9950 count * sizeof(struct cluster_list)));
9951
9952 /* Peer related usage */
9953 count = mtype_stats_alloc(MTYPE_BGP_PEER);
9954 vty_out(vty, "%ld peers, using %s of memory\n", count,
9955 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9956 count * sizeof(struct peer)));
9957
9958 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
9959 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
9960 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9961 count * sizeof(struct peer_group)));
9962
9963 /* Other */
d62a17ae 9964 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
9965 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
9966 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9967 count * sizeof(regex_t)));
d62a17ae 9968 return CMD_SUCCESS;
4bf6a362 9969}
fee0f4c6 9970
57a9c8a8
DS
9971static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
9972{
9973 json_object *bestpath = json_object_new_object();
9974
892fedb6 9975 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
9976 json_object_string_add(bestpath, "asPath", "ignore");
9977
892fedb6 9978 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
9979 json_object_string_add(bestpath, "asPath", "confed");
9980
892fedb6
DA
9981 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
9982 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 9983 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9984 "as-set");
9985 else
a4d82a8a 9986 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9987 "true");
9988 } else
a4d82a8a 9989 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 9990
ee88563a
JM
9991 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
9992 json_object_boolean_true_add(bestpath, "peerTypeRelax");
9993
892fedb6 9994 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 9995 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
9996 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
9997 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
9998 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 9999 json_object_string_add(bestpath, "med", "confed");
892fedb6 10000 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10001 json_object_string_add(bestpath, "med",
10002 "missing-as-worst");
10003 else
10004 json_object_string_add(bestpath, "med", "true");
10005 }
10006
10007 json_object_object_add(json, "bestPath", bestpath);
10008}
10009
3577f1c5
DD
10010/* Print the error code/subcode for why the peer is down */
10011static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10012 json_object *json_peer, bool use_json)
10013{
10014 const char *code_str;
10015 const char *subcode_str;
10016
10017 if (use_json) {
10018 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10019 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10020 char errorcodesubcode_hexstr[5];
10021 char errorcodesubcode_str[256];
10022
10023 code_str = bgp_notify_code_str(peer->notify.code);
10024 subcode_str = bgp_notify_subcode_str(
10025 peer->notify.code,
10026 peer->notify.subcode);
10027
772270f3
QY
10028 snprintf(errorcodesubcode_hexstr,
10029 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10030 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10031 json_object_string_add(json_peer,
10032 "lastErrorCodeSubcode",
10033 errorcodesubcode_hexstr);
10034 snprintf(errorcodesubcode_str, 255, "%s%s",
10035 code_str, subcode_str);
10036 json_object_string_add(json_peer,
10037 "lastNotificationReason",
10038 errorcodesubcode_str);
10039 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10040 && peer->notify.code == BGP_NOTIFY_CEASE
10041 && (peer->notify.subcode
10042 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10043 || peer->notify.subcode
10044 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10045 && peer->notify.length) {
10046 char msgbuf[1024];
10047 const char *msg_str;
10048
10049 msg_str = bgp_notify_admin_message(
10050 msgbuf, sizeof(msgbuf),
10051 (uint8_t *)peer->notify.data,
10052 peer->notify.length);
10053 if (msg_str)
10054 json_object_string_add(
10055 json_peer,
10056 "lastShutdownDescription",
10057 msg_str);
10058 }
10059
c258527b 10060 }
3577f1c5
DD
10061 json_object_string_add(json_peer, "lastResetDueTo",
10062 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10063 json_object_int_add(json_peer, "lastResetCode",
10064 peer->last_reset);
3577f1c5
DD
10065 } else {
10066 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10067 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10068 code_str = bgp_notify_code_str(peer->notify.code);
10069 subcode_str =
10070 bgp_notify_subcode_str(peer->notify.code,
10071 peer->notify.subcode);
10072 vty_out(vty, " Notification %s (%s%s)\n",
10073 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10074 ? "sent"
10075 : "received",
10076 code_str, subcode_str);
10077 } else {
e91c24c8 10078 vty_out(vty, " %s\n",
3577f1c5
DD
10079 peer_down_str[(int)peer->last_reset]);
10080 }
10081 }
10082}
10083
10084static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10085 safi_t safi)
10086{
feb17238 10087 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
3577f1c5
DD
10088}
10089
10090static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10091 struct peer *peer, json_object *json_peer,
10092 int max_neighbor_width, bool use_json)
10093{
10094 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10095 int len;
10096
10097 if (use_json) {
10098 if (peer_dynamic_neighbor(peer))
10099 json_object_boolean_true_add(json_peer,
10100 "dynamicPeer");
10101 if (peer->hostname)
10102 json_object_string_add(json_peer, "hostname",
10103 peer->hostname);
10104
10105 if (peer->domainname)
10106 json_object_string_add(json_peer, "domainname",
10107 peer->domainname);
10108 json_object_int_add(json_peer, "connectionsEstablished",
10109 peer->established);
10110 json_object_int_add(json_peer, "connectionsDropped",
10111 peer->dropped);
10112 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10113 use_json, json_peer);
feb17238 10114 if (peer_established(peer))
3577f1c5
DD
10115 json_object_string_add(json_peer, "lastResetDueTo",
10116 "AFI/SAFI Not Negotiated");
10117 else
10118 bgp_show_peer_reset(NULL, peer, json_peer, true);
10119 } else {
10120 dn_flag[1] = '\0';
10121 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10122 if (peer->hostname
892fedb6 10123 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10124 len = vty_out(vty, "%s%s(%s)", dn_flag,
10125 peer->hostname, peer->host);
10126 else
10127 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10128
10129 /* pad the neighbor column with spaces */
10130 if (len < max_neighbor_width)
10131 vty_out(vty, "%*s", max_neighbor_width - len,
10132 " ");
e91c24c8 10133 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10134 peer->dropped,
10135 peer_uptime(peer->uptime, timebuf,
10136 BGP_UPTIME_LEN, 0, NULL));
feb17238 10137 if (peer_established(peer))
3577f1c5
DD
10138 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10139 else
10140 bgp_show_peer_reset(vty, peer, NULL,
10141 false);
10142 }
10143}
c258527b 10144
565e9ddd 10145/* Strip peer's description to the given size. */
cb75bb31
DA
10146static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10147{
10148 static char stripped[BUFSIZ];
cb75bb31
DA
10149 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10150
cb75bb31
DA
10151 strlcpy(stripped, desc, len + 1);
10152
10153 return stripped;
10154}
3577f1c5 10155
8c1d4cd5
LS
10156/* Determine whether var peer should be filtered out of the summary. */
10157static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10158 struct peer *fpeer, int as_type,
10159 as_t as)
10160{
10161
10162 /* filter neighbor XXXX */
10163 if (fpeer && fpeer != peer)
10164 return true;
10165
10166 /* filter remote-as (internal|external) */
10167 if (as_type != AS_UNSPECIFIED) {
10168 if (peer->as_type == AS_SPECIFIED) {
10169 if (as_type == AS_INTERNAL) {
10170 if (peer->as != peer->local_as)
10171 return true;
10172 } else if (peer->as == peer->local_as)
10173 return true;
10174 } else if (as_type != peer->as_type)
10175 return true;
10176 } else if (as && as != peer->as) /* filter remote-as XXX */
10177 return true;
10178
10179 return false;
10180}
10181
565e9ddd
DA
10182/* Show BGP peer's summary information.
10183 *
10184 * Peer's description is stripped according to if `wide` option is given
10185 * or not.
10186 *
10187 * When adding new columns to `show bgp summary` output, please make
10188 * sure `Desc` is the lastest column to show because it can contain
10189 * whitespaces and the whole output will be tricky.
10190 */
d62a17ae 10191static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 10192 struct peer *fpeer, int as_type, as_t as,
96c81f66 10193 uint16_t show_flags)
d62a17ae 10194{
10195 struct peer *peer;
10196 struct listnode *node, *nnode;
10197 unsigned int count = 0, dn_count = 0;
10198 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10199 char neighbor_buf[VTY_BUFSIZ];
10200 int neighbor_col_default_width = 16;
3577f1c5 10201 int len, failed_count = 0;
ce1944f0 10202 unsigned int filtered_count = 0;
d62a17ae 10203 int max_neighbor_width = 0;
10204 int pfx_rcd_safi;
3c13337d 10205 json_object *json = NULL;
d62a17ae 10206 json_object *json_peer = NULL;
10207 json_object *json_peers = NULL;
50e05855 10208 struct peer_af *paf;
d3ada366 10209 struct bgp_filter *filter;
85eeb029
DA
10210 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10211 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10212 bool show_established =
10213 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10214 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
96c81f66 10215 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
d62a17ae 10216
10217 /* labeled-unicast routes are installed in the unicast table so in order
10218 * to
10219 * display the correct PfxRcd value we must look at SAFI_UNICAST
10220 */
3577f1c5 10221
d62a17ae 10222 if (safi == SAFI_LABELED_UNICAST)
10223 pfx_rcd_safi = SAFI_UNICAST;
10224 else
10225 pfx_rcd_safi = safi;
10226
10227 if (use_json) {
3c13337d 10228 json = json_object_new_object();
d62a17ae 10229 json_peers = json_object_new_object();
3577f1c5 10230 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10231 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10232 as_type, as)) {
ce1944f0 10233 filtered_count++;
8c1d4cd5
LS
10234 count++;
10235 continue;
10236 }
10237
3577f1c5
DD
10238 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10239 continue;
10240
10241 if (peer->afc[afi][safi]) {
10242 /* See if we have at least a single failed peer */
10243 if (bgp_has_peer_failed(peer, afi, safi))
10244 failed_count++;
10245 count++;
10246 }
10247 if (peer_dynamic_neighbor(peer))
10248 dn_count++;
10249 }
c258527b 10250
d62a17ae 10251 } else {
10252 /* Loop over all neighbors that will be displayed to determine
10253 * how many
10254 * characters are needed for the Neighbor column
10255 */
10256 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10257 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10258 as_type, as)) {
ce1944f0 10259 filtered_count++;
8c1d4cd5
LS
10260 count++;
10261 continue;
10262 }
10263
d62a17ae 10264 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10265 continue;
10266
10267 if (peer->afc[afi][safi]) {
10268 memset(dn_flag, '\0', sizeof(dn_flag));
10269 if (peer_dynamic_neighbor(peer))
10270 dn_flag[0] = '*';
10271
10272 if (peer->hostname
892fedb6
DA
10273 && CHECK_FLAG(bgp->flags,
10274 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10275 snprintf(neighbor_buf,
10276 sizeof(neighbor_buf),
10277 "%s%s(%s) ", dn_flag,
10278 peer->hostname, peer->host);
d62a17ae 10279 else
772270f3
QY
10280 snprintf(neighbor_buf,
10281 sizeof(neighbor_buf), "%s%s ",
10282 dn_flag, peer->host);
d62a17ae 10283
10284 len = strlen(neighbor_buf);
10285
10286 if (len > max_neighbor_width)
10287 max_neighbor_width = len;
c258527b 10288
3577f1c5
DD
10289 /* See if we have at least a single failed peer */
10290 if (bgp_has_peer_failed(peer, afi, safi))
10291 failed_count++;
10292 count++;
d62a17ae 10293 }
10294 }
f933309e 10295
d62a17ae 10296 /* Originally we displayed the Neighbor column as 16
10297 * characters wide so make that the default
10298 */
10299 if (max_neighbor_width < neighbor_col_default_width)
10300 max_neighbor_width = neighbor_col_default_width;
10301 }
f933309e 10302
3577f1c5
DD
10303 if (show_failed && !failed_count) {
10304 if (use_json) {
10305 json_object_int_add(json, "failedPeersCount", 0);
10306 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10307 json_object_int_add(json, "totalPeers", count);
3577f1c5 10308
75eeda93 10309 vty_json(vty, json);
3577f1c5
DD
10310 } else {
10311 vty_out(vty, "%% No failed BGP neighbors found\n");
3577f1c5
DD
10312 }
10313 return CMD_SUCCESS;
10314 }
c258527b 10315
3577f1c5 10316 count = 0; /* Reset the value as its used again */
ce1944f0 10317 filtered_count = 0;
800867d8 10318 dn_count = 0;
d62a17ae 10319 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10320 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10321 continue;
10322
ea47320b
DL
10323 if (!peer->afc[afi][safi])
10324 continue;
d62a17ae 10325
ea47320b
DL
10326 if (!count) {
10327 unsigned long ents;
10328 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10329 int64_t vrf_id_ui;
d62a17ae 10330
a4d82a8a
PZ
10331 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10332 ? -1
10333 : (int64_t)bgp->vrf_id;
ea47320b
DL
10334
10335 /* Usage summary and header */
10336 if (use_json) {
c949c771
DA
10337 json_object_string_addf(json, "routerId",
10338 "%pI4",
10339 &bgp->router_id);
60466a63
QY
10340 json_object_int_add(json, "as", bgp->as);
10341 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10342 json_object_string_add(
10343 json, "vrfName",
10344 (bgp->inst_type
10345 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10346 ? VRF_DEFAULT_NAME
ea47320b
DL
10347 : bgp->name);
10348 } else {
10349 vty_out(vty,
23d0a753
DA
10350 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10351 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10352 bgp->vrf_id == VRF_UNKNOWN
10353 ? -1
10354 : (int)bgp->vrf_id);
ea47320b
DL
10355 vty_out(vty, "\n");
10356 }
d62a17ae 10357
ea47320b 10358 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10359 if (use_json) {
ea47320b 10360 json_object_int_add(
60466a63 10361 json, "updateDelayLimit",
ea47320b 10362 bgp->v_update_delay);
d62a17ae 10363
ea47320b
DL
10364 if (bgp->v_update_delay
10365 != bgp->v_establish_wait)
d62a17ae 10366 json_object_int_add(
10367 json,
ea47320b
DL
10368 "updateDelayEstablishWait",
10369 bgp->v_establish_wait);
d62a17ae 10370
60466a63 10371 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10372 json_object_string_add(
10373 json,
10374 "updateDelayFirstNeighbor",
10375 bgp->update_delay_begin_time);
10376 json_object_boolean_true_add(
10377 json,
10378 "updateDelayInProgress");
10379 } else {
10380 if (bgp->update_delay_over) {
d62a17ae 10381 json_object_string_add(
10382 json,
10383 "updateDelayFirstNeighbor",
10384 bgp->update_delay_begin_time);
ea47320b 10385 json_object_string_add(
d62a17ae 10386 json,
ea47320b
DL
10387 "updateDelayBestpathResumed",
10388 bgp->update_delay_end_time);
10389 json_object_string_add(
d62a17ae 10390 json,
ea47320b
DL
10391 "updateDelayZebraUpdateResume",
10392 bgp->update_delay_zebra_resume_time);
10393 json_object_string_add(
10394 json,
10395 "updateDelayPeerUpdateResume",
10396 bgp->update_delay_peers_resume_time);
d62a17ae 10397 }
ea47320b
DL
10398 }
10399 } else {
10400 vty_out(vty,
10401 "Read-only mode update-delay limit: %d seconds\n",
10402 bgp->v_update_delay);
10403 if (bgp->v_update_delay
10404 != bgp->v_establish_wait)
d62a17ae 10405 vty_out(vty,
ea47320b
DL
10406 " Establish wait: %d seconds\n",
10407 bgp->v_establish_wait);
d62a17ae 10408
60466a63 10409 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10410 vty_out(vty,
10411 " First neighbor established: %s\n",
10412 bgp->update_delay_begin_time);
10413 vty_out(vty,
10414 " Delay in progress\n");
10415 } else {
10416 if (bgp->update_delay_over) {
d62a17ae 10417 vty_out(vty,
10418 " First neighbor established: %s\n",
10419 bgp->update_delay_begin_time);
10420 vty_out(vty,
ea47320b
DL
10421 " Best-paths resumed: %s\n",
10422 bgp->update_delay_end_time);
10423 vty_out(vty,
10424 " zebra update resumed: %s\n",
10425 bgp->update_delay_zebra_resume_time);
10426 vty_out(vty,
10427 " peers update resumed: %s\n",
10428 bgp->update_delay_peers_resume_time);
d62a17ae 10429 }
10430 }
10431 }
ea47320b 10432 }
d62a17ae 10433
ea47320b
DL
10434 if (use_json) {
10435 if (bgp_maxmed_onstartup_configured(bgp)
10436 && bgp->maxmed_active)
10437 json_object_boolean_true_add(
60466a63 10438 json, "maxMedOnStartup");
ea47320b
DL
10439 if (bgp->v_maxmed_admin)
10440 json_object_boolean_true_add(
60466a63 10441 json, "maxMedAdministrative");
d62a17ae 10442
ea47320b
DL
10443 json_object_int_add(
10444 json, "tableVersion",
60466a63 10445 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 10446
60466a63
QY
10447 ents = bgp_table_count(bgp->rib[afi][safi]);
10448 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
10449 json_object_int_add(
10450 json, "ribMemory",
9bcb3eef 10451 ents * sizeof(struct bgp_dest));
d62a17ae 10452
210ec2a0 10453 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
10454 json_object_int_add(json, "peerCount", ents);
10455 json_object_int_add(json, "peerMemory",
10456 ents * sizeof(struct peer));
d62a17ae 10457
ea47320b
DL
10458 if ((ents = listcount(bgp->group))) {
10459 json_object_int_add(
60466a63 10460 json, "peerGroupCount", ents);
ea47320b
DL
10461 json_object_int_add(
10462 json, "peerGroupMemory",
996c9314
LB
10463 ents * sizeof(struct
10464 peer_group));
ea47320b 10465 }
d62a17ae 10466
ea47320b
DL
10467 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10468 BGP_CONFIG_DAMPENING))
10469 json_object_boolean_true_add(
60466a63 10470 json, "dampeningEnabled");
ea47320b 10471 } else {
96c81f66
LS
10472 if (!show_terse) {
10473 if (bgp_maxmed_onstartup_configured(bgp)
10474 && bgp->maxmed_active)
10475 vty_out(vty,
10476 "Max-med on-startup active\n");
10477 if (bgp->v_maxmed_admin)
10478 vty_out(vty,
10479 "Max-med administrative active\n");
d62a17ae 10480
96c81f66
LS
10481 vty_out(vty,
10482 "BGP table version %" PRIu64
10483 "\n",
10484 bgp_table_version(
10485 bgp->rib[afi][safi]));
ea47320b 10486
96c81f66
LS
10487 ents = bgp_table_count(
10488 bgp->rib[afi][safi]);
d62a17ae 10489 vty_out(vty,
96c81f66 10490 "RIB entries %ld, using %s of memory\n",
d62a17ae 10491 ents,
10492 mtype_memstr(
10493 memstrbuf,
10494 sizeof(memstrbuf),
96c81f66
LS
10495 ents
10496 * sizeof(
10497 struct
10498 bgp_dest)));
d62a17ae 10499
96c81f66
LS
10500 /* Peer related usage */
10501 ents = bgp->af_peer_count[afi][safi];
10502 vty_out(vty,
10503 "Peers %ld, using %s of memory\n",
10504 ents,
10505 mtype_memstr(
10506 memstrbuf,
10507 sizeof(memstrbuf),
10508 ents
10509 * sizeof(
10510 struct
10511 peer)));
d62a17ae 10512
96c81f66
LS
10513 if ((ents = listcount(bgp->group)))
10514 vty_out(vty,
10515 "Peer groups %ld, using %s of memory\n",
10516 ents,
10517 mtype_memstr(
10518 memstrbuf,
10519 sizeof(memstrbuf),
10520 ents
10521 * sizeof(
10522 struct
10523 peer_group)));
10524
10525 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10526 BGP_CONFIG_DAMPENING))
10527 vty_out(vty,
10528 "Dampening enabled.\n");
10529 }
10530 if (show_failed) {
10531 vty_out(vty, "\n");
10532
10533 /* Subtract 8 here because 'Neighbor' is
10534 * 8 characters */
10535 vty_out(vty, "Neighbor");
10536 vty_out(vty, "%*s",
10537 max_neighbor_width - 8, " ");
85eeb029
DA
10538 vty_out(vty,
10539 BGP_SHOW_SUMMARY_HEADER_FAILED);
96c81f66 10540 }
d62a17ae 10541 }
ea47320b 10542 }
d62a17ae 10543
d55811cc 10544 paf = peer_af_find(peer, afi, safi);
d3ada366 10545 filter = &peer->filter[afi][safi];
db92d226 10546
ea47320b 10547 count++;
3577f1c5
DD
10548 /* Works for both failed & successful cases */
10549 if (peer_dynamic_neighbor(peer))
10550 dn_count++;
d62a17ae 10551
ea47320b 10552 if (use_json) {
3577f1c5 10553 json_peer = NULL;
8c1d4cd5 10554 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
10555 as_type, as)) {
10556 filtered_count++;
8c1d4cd5 10557 continue;
ce1944f0 10558 }
3577f1c5
DD
10559 if (show_failed &&
10560 bgp_has_peer_failed(peer, afi, safi)) {
10561 json_peer = json_object_new_object();
10562 bgp_show_failed_summary(vty, bgp, peer,
10563 json_peer, 0, use_json);
10564 } else if (!show_failed) {
10b49f14 10565 if (show_established
ce1944f0
LS
10566 && bgp_has_peer_failed(peer, afi, safi)) {
10567 filtered_count++;
10b49f14 10568 continue;
ce1944f0 10569 }
10b49f14 10570
3577f1c5
DD
10571 json_peer = json_object_new_object();
10572 if (peer_dynamic_neighbor(peer)) {
10573 json_object_boolean_true_add(json_peer,
10574 "dynamicPeer");
10575 }
d62a17ae 10576
3577f1c5
DD
10577 if (peer->hostname)
10578 json_object_string_add(json_peer, "hostname",
10579 peer->hostname);
10580
10581 if (peer->domainname)
10582 json_object_string_add(json_peer, "domainname",
10583 peer->domainname);
10584
10585 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
10586 json_object_int_add(
10587 json_peer, "localAs",
10588 peer->change_local_as
10589 ? peer->change_local_as
10590 : peer->local_as);
3577f1c5
DD
10591 json_object_int_add(json_peer, "version", 4);
10592 json_object_int_add(json_peer, "msgRcvd",
10593 PEER_TOTAL_RX(peer));
10594 json_object_int_add(json_peer, "msgSent",
10595 PEER_TOTAL_TX(peer));
10596
43aa5965
QY
10597 atomic_size_t outq_count, inq_count;
10598 outq_count = atomic_load_explicit(
10599 &peer->obuf->count,
10600 memory_order_relaxed);
10601 inq_count = atomic_load_explicit(
10602 &peer->ibuf->count,
10603 memory_order_relaxed);
10604
3577f1c5
DD
10605 json_object_int_add(json_peer, "tableVersion",
10606 peer->version[afi][safi]);
10607 json_object_int_add(json_peer, "outq",
43aa5965
QY
10608 outq_count);
10609 json_object_int_add(json_peer, "inq",
10610 inq_count);
3577f1c5
DD
10611 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10612 use_json, json_peer);
10613
3577f1c5
DD
10614 json_object_int_add(json_peer, "pfxRcd",
10615 peer->pcount[afi][pfx_rcd_safi]);
10616
3577f1c5 10617 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
10618 json_object_int_add(
10619 json_peer, "pfxSnt",
10620 (PAF_SUBGRP(paf))->scount);
10621 else
10622 json_object_int_add(json_peer, "pfxSnt",
10623 0);
0e1f8ab5
DA
10624
10625 /* BGP FSM state */
cb9196e7 10626 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
10627 || CHECK_FLAG(peer->bgp->flags,
10628 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
10629 json_object_string_add(json_peer,
10630 "state",
3577f1c5
DD
10631 "Idle (Admin)");
10632 else if (peer->afc_recv[afi][safi])
10633 json_object_string_add(
0e1f8ab5
DA
10634 json_peer, "state",
10635 lookup_msg(bgp_status_msg,
10636 peer->status, NULL));
10637 else if (CHECK_FLAG(
10638 peer->sflags,
10639 PEER_STATUS_PREFIX_OVERFLOW))
10640 json_object_string_add(json_peer,
10641 "state",
3577f1c5
DD
10642 "Idle (PfxCt)");
10643 else
10644 json_object_string_add(
0e1f8ab5
DA
10645 json_peer, "state",
10646 lookup_msg(bgp_status_msg,
10647 peer->status, NULL));
10648
10649 /* BGP peer state */
10650 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10651 || CHECK_FLAG(peer->bgp->flags,
10652 BGP_FLAG_SHUTDOWN))
10653 json_object_string_add(json_peer,
10654 "peerState",
10655 "Admin");
10656 else if (CHECK_FLAG(
10657 peer->sflags,
10658 PEER_STATUS_PREFIX_OVERFLOW))
10659 json_object_string_add(json_peer,
10660 "peerState",
10661 "PfxCt");
10662 else if (CHECK_FLAG(peer->flags,
10663 PEER_FLAG_PASSIVE))
10664 json_object_string_add(json_peer,
10665 "peerState",
10666 "Passive");
10667 else if (CHECK_FLAG(peer->sflags,
10668 PEER_STATUS_NSF_WAIT))
10669 json_object_string_add(json_peer,
10670 "peerState",
10671 "NSF passive");
10672 else if (CHECK_FLAG(
10673 peer->bgp->flags,
10674 BGP_FLAG_EBGP_REQUIRES_POLICY)
10675 && (!bgp_inbound_policy_exists(peer,
10676 filter)
10677 || !bgp_outbound_policy_exists(
10678 peer, filter)))
10679 json_object_string_add(json_peer,
10680 "peerState",
10681 "Policy");
10682 else
10683 json_object_string_add(
10684 json_peer, "peerState", "OK");
10685
200116db
DD
10686 json_object_int_add(json_peer, "connectionsEstablished",
10687 peer->established);
10688 json_object_int_add(json_peer, "connectionsDropped",
10689 peer->dropped);
aa72bd7e
PG
10690 if (peer->desc)
10691 json_object_string_add(
10692 json_peer, "desc", peer->desc);
b4e9dcba 10693 }
3577f1c5
DD
10694 /* Avoid creating empty peer dicts in JSON */
10695 if (json_peer == NULL)
10696 continue;
ea47320b
DL
10697
10698 if (peer->conf_if)
60466a63 10699 json_object_string_add(json_peer, "idType",
ea47320b
DL
10700 "interface");
10701 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
10702 json_object_string_add(json_peer, "idType",
10703 "ipv4");
ea47320b 10704 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
10705 json_object_string_add(json_peer, "idType",
10706 "ipv6");
ea47320b
DL
10707 json_object_object_add(json_peers, peer->host,
10708 json_peer);
10709 } else {
8c1d4cd5 10710 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
10711 as_type, as)) {
10712 filtered_count++;
8c1d4cd5 10713 continue;
ce1944f0 10714 }
3577f1c5
DD
10715 if (show_failed &&
10716 bgp_has_peer_failed(peer, afi, safi)) {
10717 bgp_show_failed_summary(vty, bgp, peer, NULL,
10718 max_neighbor_width,
10719 use_json);
10720 } else if (!show_failed) {
10b49f14 10721 if (show_established
ce1944f0
LS
10722 && bgp_has_peer_failed(peer, afi, safi)) {
10723 filtered_count++;
10b49f14 10724 continue;
ce1944f0 10725 }
96c81f66
LS
10726
10727 if ((count - filtered_count) == 1) {
10728 /* display headline before the first
10729 * neighbor line */
10730 vty_out(vty, "\n");
10731
10732 /* Subtract 8 here because 'Neighbor' is
10733 * 8 characters */
10734 vty_out(vty, "Neighbor");
10735 vty_out(vty, "%*s",
10736 max_neighbor_width - 8, " ");
10737 vty_out(vty,
10738 show_wide
10739 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10740 : BGP_SHOW_SUMMARY_HEADER_ALL);
10741 }
10742
3577f1c5
DD
10743 memset(dn_flag, '\0', sizeof(dn_flag));
10744 if (peer_dynamic_neighbor(peer)) {
10745 dn_flag[0] = '*';
10746 }
d62a17ae 10747
3577f1c5 10748 if (peer->hostname
892fedb6
DA
10749 && CHECK_FLAG(bgp->flags,
10750 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 10751 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
10752 peer->hostname,
10753 peer->host);
d62a17ae 10754 else
3577f1c5
DD
10755 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10756
10757 /* pad the neighbor column with spaces */
10758 if (len < max_neighbor_width)
10759 vty_out(vty, "%*s", max_neighbor_width - len,
10760 " ");
10761
43aa5965
QY
10762 atomic_size_t outq_count, inq_count;
10763 outq_count = atomic_load_explicit(
10764 &peer->obuf->count,
10765 memory_order_relaxed);
10766 inq_count = atomic_load_explicit(
10767 &peer->ibuf->count,
10768 memory_order_relaxed);
10769
85eeb029
DA
10770 if (show_wide)
10771 vty_out(vty,
10772 "4 %10u %10u %9u %9u %8" PRIu64
10773 " %4zu %4zu %8s",
10774 peer->as,
10775 peer->change_local_as
10776 ? peer->change_local_as
10777 : peer->local_as,
10778 PEER_TOTAL_RX(peer),
10779 PEER_TOTAL_TX(peer),
10780 peer->version[afi][safi],
10781 inq_count, outq_count,
10782 peer_uptime(peer->uptime,
10783 timebuf,
10784 BGP_UPTIME_LEN, 0,
10785 NULL));
10786 else
10787 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
10788 " %4zu %4zu %8s",
10789 peer->as, PEER_TOTAL_RX(peer),
10790 PEER_TOTAL_TX(peer),
10791 peer->version[afi][safi],
10792 inq_count, outq_count,
10793 peer_uptime(peer->uptime,
10794 timebuf,
10795 BGP_UPTIME_LEN, 0,
10796 NULL));
3577f1c5 10797
feb17238 10798 if (peer_established(peer)) {
d3ada366
DA
10799 if (peer->afc_recv[afi][safi]) {
10800 if (CHECK_FLAG(
10801 bgp->flags,
10802 BGP_FLAG_EBGP_REQUIRES_POLICY)
10803 && !bgp_inbound_policy_exists(
10804 peer, filter))
10805 vty_out(vty, " %12s",
10806 "(Policy)");
10807 else
10808 vty_out(vty,
6cde4b45 10809 " %12u",
d3ada366
DA
10810 peer->pcount
10811 [afi]
10812 [pfx_rcd_safi]);
10813 } else {
749d0f27 10814 vty_out(vty, " NoNeg");
d3ada366 10815 }
db92d226 10816
d3ada366
DA
10817 if (paf && PAF_SUBGRP(paf)) {
10818 if (CHECK_FLAG(
10819 bgp->flags,
10820 BGP_FLAG_EBGP_REQUIRES_POLICY)
10821 && !bgp_outbound_policy_exists(
10822 peer, filter))
10823 vty_out(vty, " %8s",
10824 "(Policy)");
10825 else
10826 vty_out(vty,
6cde4b45 10827 " %8u",
d3ada366
DA
10828 (PAF_SUBGRP(
10829 paf))
10830 ->scount);
749d0f27
DA
10831 } else {
10832 vty_out(vty, " NoNeg");
d3ada366 10833 }
db92d226 10834 } else {
736b68f3
DS
10835 if (CHECK_FLAG(peer->flags,
10836 PEER_FLAG_SHUTDOWN)
10837 || CHECK_FLAG(peer->bgp->flags,
10838 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
10839 vty_out(vty, " Idle (Admin)");
10840 else if (CHECK_FLAG(
10841 peer->sflags,
10842 PEER_STATUS_PREFIX_OVERFLOW))
10843 vty_out(vty, " Idle (PfxCt)");
10844 else
10845 vty_out(vty, " %12s",
10846 lookup_msg(bgp_status_msg,
10847 peer->status, NULL));
db92d226 10848
6cde4b45 10849 vty_out(vty, " %8u", 0);
3577f1c5 10850 }
565e9ddd
DA
10851 /* Make sure `Desc` column is the lastest in
10852 * the output.
10853 */
aa72bd7e 10854 if (peer->desc)
cb75bb31
DA
10855 vty_out(vty, " %s",
10856 bgp_peer_description_stripped(
85eeb029
DA
10857 peer->desc,
10858 show_wide ? 64 : 20));
aa72bd7e
PG
10859 else
10860 vty_out(vty, " N/A");
3577f1c5 10861 vty_out(vty, "\n");
d62a17ae 10862 }
3577f1c5 10863
d62a17ae 10864 }
10865 }
f933309e 10866
d62a17ae 10867 if (use_json) {
10868 json_object_object_add(json, "peers", json_peers);
3577f1c5 10869 json_object_int_add(json, "failedPeers", failed_count);
ce1944f0
LS
10870 json_object_int_add(json, "displayedPeers",
10871 count - filtered_count);
d62a17ae 10872 json_object_int_add(json, "totalPeers", count);
10873 json_object_int_add(json, "dynamicPeers", dn_count);
10874
3577f1c5
DD
10875 if (!show_failed)
10876 bgp_show_bestpath_json(bgp, json);
57a9c8a8 10877
75eeda93 10878 vty_json(vty, json);
d62a17ae 10879 } else {
ce1944f0 10880 if (count) {
96c81f66
LS
10881 if (filtered_count == count)
10882 vty_out(vty, "\n%% No matching neighbor\n");
10883 else {
10884 if (show_failed)
10885 vty_out(vty, "\nDisplayed neighbors %d",
10886 failed_count);
10887 else if (as_type != AS_UNSPECIFIED || as
10888 || fpeer || show_established)
ce1944f0
LS
10889 vty_out(vty, "\nDisplayed neighbors %d",
10890 count - filtered_count);
96c81f66
LS
10891
10892 vty_out(vty, "\nTotal number of neighbors %d\n",
10893 count);
ce1944f0 10894 }
ce1944f0 10895 } else {
d6ceaca3 10896 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 10897 get_afi_safi_str(afi, safi, false));
d62a17ae 10898 }
b05a1c8b 10899
d6ceaca3 10900 if (dn_count) {
d62a17ae 10901 vty_out(vty, "* - dynamic neighbor\n");
10902 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
10903 dn_count, bgp->dynamic_neighbors_limit);
10904 }
10905 }
1ff9a340 10906
d62a17ae 10907 return CMD_SUCCESS;
718e3744 10908}
10909
d62a17ae 10910static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5 10911 int safi, struct peer *fpeer, int as_type,
96c81f66 10912 as_t as, uint16_t show_flags)
d62a17ae 10913{
10914 int is_first = 1;
10915 int afi_wildcard = (afi == AFI_MAX);
10916 int safi_wildcard = (safi == SAFI_MAX);
10917 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 10918 bool nbr_output = false;
85eeb029 10919 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 10920
10921 if (use_json && is_wildcard)
10922 vty_out(vty, "{\n");
10923 if (afi_wildcard)
10924 afi = 1; /* AFI_IP */
10925 while (afi < AFI_MAX) {
10926 if (safi_wildcard)
10927 safi = 1; /* SAFI_UNICAST */
10928 while (safi < SAFI_MAX) {
318cac96 10929 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 10930 nbr_output = true;
f86897b9 10931
d62a17ae 10932 if (is_wildcard) {
10933 /*
10934 * So limit output to those afi/safi
10935 * pairs that
10936 * actualy have something interesting in
10937 * them
10938 */
10939 if (use_json) {
d62a17ae 10940 if (!is_first)
10941 vty_out(vty, ",\n");
10942 else
10943 is_first = 0;
10944
10945 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
10946 get_afi_safi_str(afi,
10947 safi,
10948 true));
d62a17ae 10949 } else {
6cac2fcc
LS
10950 vty_out(vty,
10951 "\n%s Summary (%s):\n",
5cb5f4d0
DD
10952 get_afi_safi_str(afi,
10953 safi,
6cac2fcc
LS
10954 false),
10955 bgp->name_pretty);
d62a17ae 10956 }
10957 }
8c1d4cd5
LS
10958 bgp_show_summary(vty, bgp, afi, safi, fpeer,
10959 as_type, as, show_flags);
d62a17ae 10960 }
10961 safi++;
d62a17ae 10962 if (!safi_wildcard)
10963 safi = SAFI_MAX;
10964 }
10965 afi++;
ee851c8c 10966 if (!afi_wildcard)
d62a17ae 10967 afi = AFI_MAX;
10968 }
10969
10970 if (use_json && is_wildcard)
10971 vty_out(vty, "}\n");
ca61fd25
DS
10972 else if (!nbr_output) {
10973 if (use_json)
10974 vty_out(vty, "{}\n");
10975 else
6cac2fcc
LS
10976 vty_out(vty, "%% No BGP neighbors found in %s\n",
10977 bgp->name_pretty);
ca61fd25 10978 }
d62a17ae 10979}
10980
10981static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
10982 safi_t safi,
10983 const char *neighbor,
10984 int as_type, as_t as,
96c81f66 10985 uint16_t show_flags)
d62a17ae 10986{
10987 struct listnode *node, *nnode;
10988 struct bgp *bgp;
8c1d4cd5 10989 struct peer *fpeer = NULL;
d62a17ae 10990 int is_first = 1;
9f049418 10991 bool nbr_output = false;
85eeb029 10992 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 10993
10994 if (use_json)
10995 vty_out(vty, "{\n");
10996
10997 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 10998 nbr_output = true;
d62a17ae 10999 if (use_json) {
d62a17ae 11000 if (!is_first)
11001 vty_out(vty, ",\n");
11002 else
11003 is_first = 0;
11004
11005 vty_out(vty, "\"%s\":",
11006 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11007 ? VRF_DEFAULT_NAME
d62a17ae 11008 : bgp->name);
d62a17ae 11009 }
8c1d4cd5
LS
11010 if (neighbor) {
11011 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11012 use_json);
11013 if (!fpeer)
11014 continue;
11015 }
11016 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11017 as, show_flags);
d62a17ae 11018 }
11019
11020 if (use_json)
11021 vty_out(vty, "}\n");
9f049418
DS
11022 else if (!nbr_output)
11023 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11024}
11025
11026int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5 11027 safi_t safi, const char *neighbor, int as_type,
96c81f66 11028 as_t as, uint16_t show_flags)
d62a17ae 11029{
11030 struct bgp *bgp;
85eeb029 11031 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 11032 struct peer *fpeer = NULL;
d62a17ae 11033
11034 if (name) {
11035 if (strmatch(name, "all")) {
85eeb029 11036 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
11037 neighbor, as_type,
11038 as, show_flags);
d62a17ae 11039 return CMD_SUCCESS;
11040 } else {
11041 bgp = bgp_lookup_by_name(name);
11042
11043 if (!bgp) {
11044 if (use_json)
11045 vty_out(vty, "{}\n");
11046 else
11047 vty_out(vty,
ca61fd25 11048 "%% BGP instance not found\n");
d62a17ae 11049 return CMD_WARNING;
11050 }
11051
8c1d4cd5
LS
11052 if (neighbor) {
11053 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11054 use_json);
11055 if (!fpeer)
11056 return CMD_WARNING;
11057 }
11058 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11059 as_type, as, show_flags);
d62a17ae 11060 return CMD_SUCCESS;
11061 }
11062 }
11063
11064 bgp = bgp_get_default();
11065
8c1d4cd5
LS
11066 if (bgp) {
11067 if (neighbor) {
11068 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11069 use_json);
11070 if (!fpeer)
11071 return CMD_WARNING;
11072 }
11073 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11074 as, show_flags);
11075 } else {
ca61fd25
DS
11076 if (use_json)
11077 vty_out(vty, "{}\n");
11078 else
11079 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11080 return CMD_WARNING;
11081 }
d62a17ae 11082
11083 return CMD_SUCCESS;
4fb25c53
DW
11084}
11085
716b2d8a 11086/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
11087DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11088 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11089 " [" BGP_SAFI_WITH_LABEL_CMD_STR
96c81f66 11090 "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <(1-4294967295)|internal|external>>] [terse] [wide] [json$uj]",
8c1d4cd5
LS
11091 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11092 BGP_SAFI_WITH_LABEL_HELP_STR
11093 "Display the entries for all address families\n"
11094 "Summary of BGP neighbor status\n"
11095 "Show only sessions in Established state\n"
11096 "Show only sessions not in Established state\n"
11097 "Show only the specified neighbor session\n"
11098 "Neighbor to display information about\n"
11099 "Neighbor to display information about\n"
11100 "Neighbor on BGP configured interface\n"
11101 "Show only the specified remote AS sessions\n"
11102 "AS number\n"
11103 "Internal (iBGP) AS sessions\n"
11104 "External (eBGP) AS sessions\n"
96c81f66 11105 "Shorten the information on BGP instances\n"
8c1d4cd5 11106 "Increase table width for longer output\n" JSON_STR)
718e3744 11107{
d62a17ae 11108 char *vrf = NULL;
11109 afi_t afi = AFI_MAX;
11110 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
11111 as_t as = 0; /* 0 means AS filter not set */
11112 int as_type = AS_UNSPECIFIED;
96c81f66 11113 uint16_t show_flags = 0;
d62a17ae 11114
11115 int idx = 0;
11116
11117 /* show [ip] bgp */
96f3485c 11118 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11119 afi = AFI_IP;
9a8bdf1c
PG
11120 /* [<vrf> VIEWVRFNAME] */
11121 if (argv_find(argv, argc, "vrf", &idx)) {
11122 vrf = argv[idx + 1]->arg;
11123 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11124 vrf = NULL;
11125 } else if (argv_find(argv, argc, "view", &idx))
11126 /* [<view> VIEWVRFNAME] */
11127 vrf = argv[idx + 1]->arg;
d62a17ae 11128 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11129 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11130 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11131 }
11132
3577f1c5 11133 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11134 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11135
10b49f14 11136 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11137 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11138
8c1d4cd5
LS
11139 if (argv_find(argv, argc, "remote-as", &idx)) {
11140 if (argv[idx + 1]->arg[0] == 'i')
11141 as_type = AS_INTERNAL;
11142 else if (argv[idx + 1]->arg[0] == 'e')
11143 as_type = AS_EXTERNAL;
11144 else
11145 as = (as_t)atoi(argv[idx + 1]->arg);
11146 }
11147
96c81f66
LS
11148 if (argv_find(argv, argc, "terse", &idx))
11149 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11150
85eeb029
DA
11151 if (argv_find(argv, argc, "wide", &idx))
11152 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11153
11154 if (argv_find(argv, argc, "json", &idx))
11155 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11156
8c1d4cd5
LS
11157 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11158 show_flags);
d62a17ae 11159}
11160
5cb5f4d0 11161const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11162{
5cb5f4d0
DD
11163 if (for_json)
11164 return get_afi_safi_json_str(afi, safi);
d62a17ae 11165 else
5cb5f4d0 11166 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11167}
11168
d62a17ae 11169
11170static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11171 afi_t afi, safi_t safi,
d7c0a89a
QY
11172 uint16_t adv_smcap, uint16_t adv_rmcap,
11173 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11174 bool use_json, json_object *json_pref)
d62a17ae 11175{
11176 /* Send-Mode */
11177 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11178 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11179 if (use_json) {
11180 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11181 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11182 json_object_string_add(json_pref, "sendMode",
11183 "advertisedAndReceived");
11184 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11185 json_object_string_add(json_pref, "sendMode",
11186 "advertised");
11187 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11188 json_object_string_add(json_pref, "sendMode",
11189 "received");
11190 } else {
11191 vty_out(vty, " Send-mode: ");
11192 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11193 vty_out(vty, "advertised");
11194 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11195 vty_out(vty, "%sreceived",
11196 CHECK_FLAG(p->af_cap[afi][safi],
11197 adv_smcap)
11198 ? ", "
11199 : "");
11200 vty_out(vty, "\n");
11201 }
11202 }
11203
11204 /* Receive-Mode */
11205 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11206 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11207 if (use_json) {
11208 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11209 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11210 json_object_string_add(json_pref, "recvMode",
11211 "advertisedAndReceived");
11212 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11213 json_object_string_add(json_pref, "recvMode",
11214 "advertised");
11215 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11216 json_object_string_add(json_pref, "recvMode",
11217 "received");
11218 } else {
11219 vty_out(vty, " Receive-mode: ");
11220 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11221 vty_out(vty, "advertised");
11222 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11223 vty_out(vty, "%sreceived",
11224 CHECK_FLAG(p->af_cap[afi][safi],
11225 adv_rmcap)
11226 ? ", "
11227 : "");
11228 vty_out(vty, "\n");
11229 }
11230 }
11231}
11232
13909c4f
DS
11233static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11234 struct peer *p,
11235 bool use_json,
11236 json_object *json)
2986cac2 11237{
08c2d52a 11238 bool rbit_status = false;
2986cac2 11239
11240 if (!use_json)
a53ca37b 11241 vty_out(vty, "\n R bit: ");
2986cac2 11242
13909c4f
DS
11243 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11244 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
feb17238 11245 && (peer_established(p))) {
2986cac2 11246
11247 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 11248 rbit_status = true;
2986cac2 11249 else
08c2d52a 11250 rbit_status = false;
2986cac2 11251 }
11252
11253 if (rbit_status) {
11254 if (use_json)
13909c4f 11255 json_object_boolean_true_add(json, "rBit");
2986cac2 11256 else
11257 vty_out(vty, "True\n");
11258 } else {
11259 if (use_json)
13909c4f 11260 json_object_boolean_false_add(json, "rBit");
2986cac2 11261 else
11262 vty_out(vty, "False\n");
11263 }
11264}
11265
13909c4f
DS
11266static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11267 struct peer *peer,
11268 bool use_json,
11269 json_object *json)
2986cac2 11270{
2bb5d39b 11271 const char *mode = "NotApplicable";
2986cac2 11272
11273 if (!use_json)
a53ca37b 11274 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11275
13909c4f 11276 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
feb17238 11277 && (peer_established(peer))) {
2986cac2 11278
13909c4f
DS
11279 if ((peer->nsf_af_count == 0)
11280 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11281
2986cac2 11282 mode = "Disable";
11283
13909c4f
DS
11284 } else if (peer->nsf_af_count == 0
11285 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11286
2986cac2 11287 mode = "Helper";
11288
13909c4f
DS
11289 } else if (peer->nsf_af_count != 0
11290 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11291
2986cac2 11292 mode = "Restart";
2986cac2 11293 }
11294 }
11295
11296 if (use_json) {
13909c4f 11297 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11298 } else
11299 vty_out(vty, mode, "\n");
11300}
11301
13909c4f
DS
11302static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11303 struct peer *p,
11304 bool use_json,
11305 json_object *json)
2986cac2 11306{
11307 const char *mode = "Invalid";
11308
11309 if (!use_json)
a53ca37b 11310 vty_out(vty, " Local GR Mode: ");
2986cac2 11311
11312 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11313 mode = "Helper";
11314 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11315 mode = "Restart";
11316 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11317 mode = "Disable";
2ba1fe69 11318 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11319 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11320 mode = "Helper*";
11321 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11322 mode = "Restart*";
11323 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11324 mode = "Disable*";
11325 else
11326 mode = "Invalid*";
2ba1fe69 11327 }
2986cac2 11328
11329 if (use_json) {
13909c4f 11330 json_object_string_add(json, "localGrMode", mode);
2986cac2 11331 } else {
11332 vty_out(vty, mode, "\n");
11333 }
11334}
11335
13909c4f
DS
11336static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11337 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11338{
2ba1fe69 11339 afi_t afi;
11340 safi_t safi;
2986cac2 11341 json_object *json_afi_safi = NULL;
11342 json_object *json_timer = NULL;
11343 json_object *json_endofrib_status = NULL;
9e3b51a7 11344 bool eor_flag = false;
2986cac2 11345
df8d723c
DA
11346 FOREACH_AFI_SAFI_NSF (afi, safi) {
11347 if (!peer->afc[afi][safi])
11348 continue;
2986cac2 11349
df8d723c
DA
11350 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11351 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11352 continue;
9e3b51a7 11353
df8d723c
DA
11354 if (use_json) {
11355 json_afi_safi = json_object_new_object();
11356 json_endofrib_status = json_object_new_object();
11357 json_timer = json_object_new_object();
11358 }
2986cac2 11359
df8d723c
DA
11360 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11361 eor_flag = true;
11362 else
11363 eor_flag = false;
2986cac2 11364
df8d723c
DA
11365 if (!use_json) {
11366 vty_out(vty, " %s:\n",
11367 get_afi_safi_str(afi, safi, false));
2986cac2 11368
df8d723c
DA
11369 vty_out(vty, " F bit: ");
11370 }
2986cac2 11371
df8d723c
DA
11372 if (peer->nsf[afi][safi] &&
11373 CHECK_FLAG(peer->af_cap[afi][safi],
11374 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11375
df8d723c
DA
11376 if (use_json) {
11377 json_object_boolean_true_add(json_afi_safi,
11378 "fBit");
11379 } else
11380 vty_out(vty, "True\n");
11381 } else {
11382 if (use_json)
11383 json_object_boolean_false_add(json_afi_safi,
11384 "fBit");
11385 else
11386 vty_out(vty, "False\n");
11387 }
2986cac2 11388
df8d723c
DA
11389 if (!use_json)
11390 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11391
df8d723c
DA
11392 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11393 PEER_STATUS_EOR_SEND)) {
11394 if (use_json) {
11395 json_object_boolean_true_add(
11396 json_endofrib_status, "endOfRibSend");
9e3b51a7 11397
df8d723c
DA
11398 PRINT_EOR_JSON(eor_flag);
11399 } else {
11400 vty_out(vty, "Yes\n");
11401 vty_out(vty,
11402 " End-of-RIB sent after update: ");
2986cac2 11403
df8d723c
DA
11404 PRINT_EOR(eor_flag);
11405 }
11406 } else {
11407 if (use_json) {
11408 json_object_boolean_false_add(
11409 json_endofrib_status, "endOfRibSend");
11410 json_object_boolean_false_add(
11411 json_endofrib_status,
11412 "endOfRibSentAfterUpdate");
13909c4f 11413 } else {
df8d723c
DA
11414 vty_out(vty, "No\n");
11415 vty_out(vty,
11416 " End-of-RIB sent after update: ");
11417 vty_out(vty, "No\n");
13909c4f 11418 }
df8d723c 11419 }
2986cac2 11420
df8d723c
DA
11421 if (!use_json)
11422 vty_out(vty, " End-of-RIB received: ");
a53ca37b 11423
df8d723c
DA
11424 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11425 PEER_STATUS_EOR_RECEIVED)) {
11426 if (use_json)
11427 json_object_boolean_true_add(
11428 json_endofrib_status, "endOfRibRecv");
11429 else
11430 vty_out(vty, "Yes\n");
11431 } else {
11432 if (use_json)
11433 json_object_boolean_false_add(
11434 json_endofrib_status, "endOfRibRecv");
11435 else
11436 vty_out(vty, "No\n");
11437 }
11438
11439 if (use_json) {
11440 json_object_int_add(json_timer, "stalePathTimer",
11441 peer->bgp->stalepath_time);
11442
11443 if (peer->t_gr_stale != NULL) {
11444 json_object_int_add(json_timer,
11445 "stalePathTimerRemaining",
11446 thread_timer_remain_second(
11447 peer->t_gr_stale));
a53ca37b
DA
11448 }
11449
df8d723c
DA
11450 /* Display Configured Selection
11451 * Deferral only when when
11452 * Gr mode is enabled.
11453 */
11454 if (CHECK_FLAG(peer->flags,
11455 PEER_FLAG_GRACEFUL_RESTART)) {
13909c4f 11456 json_object_int_add(json_timer,
df8d723c 11457 "selectionDeferralTimer",
13909c4f 11458 peer->bgp->stalepath_time);
df8d723c 11459 }
2986cac2 11460
df8d723c
DA
11461 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11462 NULL) {
2986cac2 11463
df8d723c
DA
11464 json_object_int_add(
11465 json_timer,
11466 "selectionDeferralTimerRemaining",
11467 thread_timer_remain_second(
11468 peer->bgp->gr_info[afi][safi]
11469 .t_select_deferral));
11470 }
11471 } else {
11472 vty_out(vty, " Timers:\n");
11473 vty_out(vty,
11474 " Configured Stale Path Time(sec): %u\n",
11475 peer->bgp->stalepath_time);
2986cac2 11476
df8d723c 11477 if (peer->t_gr_stale != NULL)
13909c4f 11478 vty_out(vty,
df8d723c
DA
11479 " Stale Path Remaining(sec): %ld\n",
11480 thread_timer_remain_second(
11481 peer->t_gr_stale));
11482 /* Display Configured Selection
11483 * Deferral only when when
11484 * Gr mode is enabled.
11485 */
11486 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11487 vty_out(vty,
11488 " Configured Selection Deferral Time(sec): %u\n",
11489 peer->bgp->select_defer_time);
2986cac2 11490
df8d723c
DA
11491 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11492 NULL)
11493 vty_out(vty,
11494 " Selection Deferral Time Remaining(sec): %ld\n",
11495 thread_timer_remain_second(
11496 peer->bgp->gr_info[afi][safi]
11497 .t_select_deferral));
11498 }
11499 if (use_json) {
11500 json_object_object_add(json_afi_safi, "endOfRibStatus",
11501 json_endofrib_status);
11502 json_object_object_add(json_afi_safi, "timers",
11503 json_timer);
11504 json_object_object_add(
11505 json, get_afi_safi_str(afi, safi, true),
11506 json_afi_safi);
2986cac2 11507 }
11508 }
11509}
11510
36235319
QY
11511static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11512 struct peer *p,
11513 bool use_json,
11514 json_object *json)
2986cac2 11515{
11516 if (use_json) {
11517 json_object *json_timer = NULL;
11518
11519 json_timer = json_object_new_object();
11520
13909c4f
DS
11521 json_object_int_add(json_timer, "configuredRestartTimer",
11522 p->bgp->restart_time);
2986cac2 11523
13909c4f
DS
11524 json_object_int_add(json_timer, "receivedRestartTimer",
11525 p->v_gr_restart);
2986cac2 11526
13909c4f
DS
11527 if (p->t_gr_restart != NULL)
11528 json_object_int_add(
11529 json_timer, "restartTimerRemaining",
11530 thread_timer_remain_second(p->t_gr_restart));
2986cac2 11531
11532 json_object_object_add(json, "timers", json_timer);
11533 } else {
11534
a53ca37b
DA
11535 vty_out(vty, " Timers:\n");
11536 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 11537 p->bgp->restart_time);
2986cac2 11538
a53ca37b 11539 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
11540 p->v_gr_restart);
11541 if (p->t_gr_restart != NULL)
a53ca37b 11542 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 11543 thread_timer_remain_second(p->t_gr_restart));
36235319 11544 if (p->t_gr_restart != NULL) {
a53ca37b 11545 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
11546 thread_timer_remain_second(p->t_gr_restart));
11547 }
2986cac2 11548 }
11549}
11550
11551static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 11552 bool use_json, json_object *json)
2986cac2 11553{
11554 char buf[SU_ADDRSTRLEN] = {0};
11555 char dn_flag[2] = {0};
2b7165e7
QY
11556 /* '*' + v6 address of neighbor */
11557 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 11558
2986cac2 11559 if (!p->conf_if && peer_dynamic_neighbor(p))
11560 dn_flag[0] = '*';
11561
11562 if (p->conf_if) {
11563 if (use_json)
13909c4f
DS
11564 json_object_string_add(
11565 json, "neighborAddr",
2986cac2 11566 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
11567 ? "none"
11568 : sockunion2str(&p->su, buf,
11569 SU_ADDRSTRLEN));
2986cac2 11570 else
13909c4f 11571 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 11572 BGP_PEER_SU_UNSPEC(p)
11573 ? "none"
11574 : sockunion2str(&p->su, buf,
11575 SU_ADDRSTRLEN));
11576 } else {
772270f3
QY
11577 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11578 p->host);
2986cac2 11579
11580 if (use_json)
36235319
QY
11581 json_object_string_add(json, "neighborAddr",
11582 neighborAddr);
2986cac2 11583 else
36235319 11584 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 11585 }
11586
11587 /* more gr info in new format */
11588 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11589}
11590
d62a17ae 11591static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 11592 safi_t safi, bool use_json,
d62a17ae 11593 json_object *json_neigh)
11594{
0291c246
MK
11595 struct bgp_filter *filter;
11596 struct peer_af *paf;
11597 char orf_pfx_name[BUFSIZ];
11598 int orf_pfx_count;
11599 json_object *json_af = NULL;
11600 json_object *json_prefA = NULL;
11601 json_object *json_prefB = NULL;
11602 json_object *json_addr = NULL;
fa36596c 11603 json_object *json_advmap = NULL;
d62a17ae 11604
11605 if (use_json) {
11606 json_addr = json_object_new_object();
11607 json_af = json_object_new_object();
11608 filter = &p->filter[afi][safi];
11609
11610 if (peer_group_active(p))
11611 json_object_string_add(json_addr, "peerGroupMember",
11612 p->group->name);
11613
11614 paf = peer_af_find(p, afi, safi);
11615 if (paf && PAF_SUBGRP(paf)) {
11616 json_object_int_add(json_addr, "updateGroupId",
11617 PAF_UPDGRP(paf)->id);
11618 json_object_int_add(json_addr, "subGroupId",
11619 PAF_SUBGRP(paf)->id);
11620 json_object_int_add(json_addr, "packetQueueLength",
11621 bpacket_queue_virtual_length(paf));
11622 }
11623
11624 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11625 || CHECK_FLAG(p->af_cap[afi][safi],
11626 PEER_CAP_ORF_PREFIX_SM_RCV)
11627 || CHECK_FLAG(p->af_cap[afi][safi],
11628 PEER_CAP_ORF_PREFIX_RM_ADV)
11629 || CHECK_FLAG(p->af_cap[afi][safi],
11630 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11631 json_object_int_add(json_af, "orfType",
11632 ORF_TYPE_PREFIX);
11633 json_prefA = json_object_new_object();
11634 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11635 PEER_CAP_ORF_PREFIX_SM_ADV,
11636 PEER_CAP_ORF_PREFIX_RM_ADV,
11637 PEER_CAP_ORF_PREFIX_SM_RCV,
11638 PEER_CAP_ORF_PREFIX_RM_RCV,
11639 use_json, json_prefA);
11640 json_object_object_add(json_af, "orfPrefixList",
11641 json_prefA);
11642 }
11643
11644 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11645 || CHECK_FLAG(p->af_cap[afi][safi],
11646 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11647 || CHECK_FLAG(p->af_cap[afi][safi],
11648 PEER_CAP_ORF_PREFIX_RM_ADV)
11649 || CHECK_FLAG(p->af_cap[afi][safi],
11650 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11651 json_object_int_add(json_af, "orfOldType",
11652 ORF_TYPE_PREFIX_OLD);
11653 json_prefB = json_object_new_object();
11654 bgp_show_peer_afi_orf_cap(
11655 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11656 PEER_CAP_ORF_PREFIX_RM_ADV,
11657 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11658 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11659 json_prefB);
11660 json_object_object_add(json_af, "orfOldPrefixList",
11661 json_prefB);
11662 }
11663
11664 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11665 || CHECK_FLAG(p->af_cap[afi][safi],
11666 PEER_CAP_ORF_PREFIX_SM_RCV)
11667 || CHECK_FLAG(p->af_cap[afi][safi],
11668 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11669 || CHECK_FLAG(p->af_cap[afi][safi],
11670 PEER_CAP_ORF_PREFIX_RM_ADV)
11671 || CHECK_FLAG(p->af_cap[afi][safi],
11672 PEER_CAP_ORF_PREFIX_RM_RCV)
11673 || CHECK_FLAG(p->af_cap[afi][safi],
11674 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11675 json_object_object_add(json_addr, "afDependentCap",
11676 json_af);
11677 else
11678 json_object_free(json_af);
11679
772270f3
QY
11680 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11681 p->host, afi, safi);
d62a17ae 11682 orf_pfx_count = prefix_bgp_show_prefix_list(
11683 NULL, afi, orf_pfx_name, use_json);
11684
11685 if (CHECK_FLAG(p->af_sflags[afi][safi],
11686 PEER_STATUS_ORF_PREFIX_SEND)
11687 || orf_pfx_count) {
11688 if (CHECK_FLAG(p->af_sflags[afi][safi],
11689 PEER_STATUS_ORF_PREFIX_SEND))
11690 json_object_boolean_true_add(json_neigh,
11691 "orfSent");
11692 if (orf_pfx_count)
11693 json_object_int_add(json_addr, "orfRecvCounter",
11694 orf_pfx_count);
11695 }
11696 if (CHECK_FLAG(p->af_sflags[afi][safi],
11697 PEER_STATUS_ORF_WAIT_REFRESH))
11698 json_object_string_add(
11699 json_addr, "orfFirstUpdate",
11700 "deferredUntilORFOrRouteRefreshRecvd");
11701
11702 if (CHECK_FLAG(p->af_flags[afi][safi],
11703 PEER_FLAG_REFLECTOR_CLIENT))
11704 json_object_boolean_true_add(json_addr,
11705 "routeReflectorClient");
11706 if (CHECK_FLAG(p->af_flags[afi][safi],
11707 PEER_FLAG_RSERVER_CLIENT))
11708 json_object_boolean_true_add(json_addr,
11709 "routeServerClient");
11710 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11711 json_object_boolean_true_add(json_addr,
11712 "inboundSoftConfigPermit");
11713
11714 if (CHECK_FLAG(p->af_flags[afi][safi],
11715 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11716 json_object_boolean_true_add(
11717 json_addr,
11718 "privateAsNumsAllReplacedInUpdatesToNbr");
11719 else if (CHECK_FLAG(p->af_flags[afi][safi],
11720 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11721 json_object_boolean_true_add(
11722 json_addr,
11723 "privateAsNumsReplacedInUpdatesToNbr");
11724 else if (CHECK_FLAG(p->af_flags[afi][safi],
11725 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11726 json_object_boolean_true_add(
11727 json_addr,
11728 "privateAsNumsAllRemovedInUpdatesToNbr");
11729 else if (CHECK_FLAG(p->af_flags[afi][safi],
11730 PEER_FLAG_REMOVE_PRIVATE_AS))
11731 json_object_boolean_true_add(
11732 json_addr,
11733 "privateAsNumsRemovedInUpdatesToNbr");
11734
dcc68b5e
MS
11735 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11736 json_object_boolean_true_add(
11737 json_addr,
11738 bgp_addpath_names(p->addpath_type[afi][safi])
11739 ->type_json_name);
d62a17ae 11740
11741 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11742 json_object_string_add(json_addr,
11743 "overrideASNsInOutboundUpdates",
11744 "ifAspathEqualRemoteAs");
11745
11746 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11747 || CHECK_FLAG(p->af_flags[afi][safi],
11748 PEER_FLAG_FORCE_NEXTHOP_SELF))
11749 json_object_boolean_true_add(json_addr,
11750 "routerAlwaysNextHop");
11751 if (CHECK_FLAG(p->af_flags[afi][safi],
11752 PEER_FLAG_AS_PATH_UNCHANGED))
11753 json_object_boolean_true_add(
11754 json_addr, "unchangedAsPathPropogatedToNbr");
11755 if (CHECK_FLAG(p->af_flags[afi][safi],
11756 PEER_FLAG_NEXTHOP_UNCHANGED))
11757 json_object_boolean_true_add(
11758 json_addr, "unchangedNextHopPropogatedToNbr");
11759 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11760 json_object_boolean_true_add(
11761 json_addr, "unchangedMedPropogatedToNbr");
11762 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11763 || CHECK_FLAG(p->af_flags[afi][safi],
11764 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11765 if (CHECK_FLAG(p->af_flags[afi][safi],
11766 PEER_FLAG_SEND_COMMUNITY)
11767 && CHECK_FLAG(p->af_flags[afi][safi],
11768 PEER_FLAG_SEND_EXT_COMMUNITY))
11769 json_object_string_add(json_addr,
11770 "commAttriSentToNbr",
11771 "extendedAndStandard");
11772 else if (CHECK_FLAG(p->af_flags[afi][safi],
11773 PEER_FLAG_SEND_EXT_COMMUNITY))
11774 json_object_string_add(json_addr,
11775 "commAttriSentToNbr",
11776 "extended");
11777 else
11778 json_object_string_add(json_addr,
11779 "commAttriSentToNbr",
11780 "standard");
11781 }
11782 if (CHECK_FLAG(p->af_flags[afi][safi],
11783 PEER_FLAG_DEFAULT_ORIGINATE)) {
11784 if (p->default_rmap[afi][safi].name)
11785 json_object_string_add(
11786 json_addr, "defaultRouteMap",
11787 p->default_rmap[afi][safi].name);
11788
11789 if (paf && PAF_SUBGRP(paf)
11790 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11791 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11792 json_object_boolean_true_add(json_addr,
11793 "defaultSent");
11794 else
11795 json_object_boolean_true_add(json_addr,
11796 "defaultNotSent");
11797 }
11798
dff8f48d 11799 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 11800 if (is_evpn_enabled())
60466a63
QY
11801 json_object_boolean_true_add(
11802 json_addr, "advertiseAllVnis");
dff8f48d
MK
11803 }
11804
d62a17ae 11805 if (filter->plist[FILTER_IN].name
11806 || filter->dlist[FILTER_IN].name
11807 || filter->aslist[FILTER_IN].name
11808 || filter->map[RMAP_IN].name)
11809 json_object_boolean_true_add(json_addr,
11810 "inboundPathPolicyConfig");
11811 if (filter->plist[FILTER_OUT].name
11812 || filter->dlist[FILTER_OUT].name
11813 || filter->aslist[FILTER_OUT].name
11814 || filter->map[RMAP_OUT].name || filter->usmap.name)
11815 json_object_boolean_true_add(
11816 json_addr, "outboundPathPolicyConfig");
11817
11818 /* prefix-list */
11819 if (filter->plist[FILTER_IN].name)
11820 json_object_string_add(json_addr,
11821 "incomingUpdatePrefixFilterList",
11822 filter->plist[FILTER_IN].name);
11823 if (filter->plist[FILTER_OUT].name)
11824 json_object_string_add(json_addr,
11825 "outgoingUpdatePrefixFilterList",
11826 filter->plist[FILTER_OUT].name);
11827
11828 /* distribute-list */
11829 if (filter->dlist[FILTER_IN].name)
11830 json_object_string_add(
11831 json_addr, "incomingUpdateNetworkFilterList",
11832 filter->dlist[FILTER_IN].name);
11833 if (filter->dlist[FILTER_OUT].name)
11834 json_object_string_add(
11835 json_addr, "outgoingUpdateNetworkFilterList",
11836 filter->dlist[FILTER_OUT].name);
11837
11838 /* filter-list. */
11839 if (filter->aslist[FILTER_IN].name)
11840 json_object_string_add(json_addr,
11841 "incomingUpdateAsPathFilterList",
11842 filter->aslist[FILTER_IN].name);
11843 if (filter->aslist[FILTER_OUT].name)
11844 json_object_string_add(json_addr,
11845 "outgoingUpdateAsPathFilterList",
11846 filter->aslist[FILTER_OUT].name);
11847
11848 /* route-map. */
11849 if (filter->map[RMAP_IN].name)
11850 json_object_string_add(
11851 json_addr, "routeMapForIncomingAdvertisements",
11852 filter->map[RMAP_IN].name);
11853 if (filter->map[RMAP_OUT].name)
11854 json_object_string_add(
11855 json_addr, "routeMapForOutgoingAdvertisements",
11856 filter->map[RMAP_OUT].name);
11857
9dac9fc8 11858 /* ebgp-requires-policy (inbound) */
1d3fdccf 11859 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11860 && !bgp_inbound_policy_exists(p, filter))
11861 json_object_string_add(
11862 json_addr, "inboundEbgpRequiresPolicy",
11863 "Inbound updates discarded due to missing policy");
11864
11865 /* ebgp-requires-policy (outbound) */
1d3fdccf 11866 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11867 && (!bgp_outbound_policy_exists(p, filter)))
11868 json_object_string_add(
11869 json_addr, "outboundEbgpRequiresPolicy",
11870 "Outbound updates discarded due to missing policy");
11871
d62a17ae 11872 /* unsuppress-map */
11873 if (filter->usmap.name)
11874 json_object_string_add(json_addr,
11875 "selectiveUnsuppressRouteMap",
11876 filter->usmap.name);
11877
fa36596c
MK
11878 /* advertise-map */
11879 if (filter->advmap.aname) {
11880 json_advmap = json_object_new_object();
11881 json_object_string_add(json_advmap, "condition",
11882 filter->advmap.condition
11883 ? "EXIST"
11884 : "NON_EXIST");
11885 json_object_string_add(json_advmap, "conditionMap",
11886 filter->advmap.cname);
11887 json_object_string_add(json_advmap, "advertiseMap",
11888 filter->advmap.aname);
11889 json_object_string_add(json_advmap, "advertiseStatus",
11890 filter->advmap.update_type
11891 == ADVERTISE
11892 ? "Advertise"
11893 : "Withdraw");
11894 json_object_object_add(json_addr, "advertiseMap",
11895 json_advmap);
11896 }
11897
d62a17ae 11898 /* Receive prefix count */
11899 json_object_int_add(json_addr, "acceptedPrefixCounter",
11900 p->pcount[afi][safi]);
50e05855
AD
11901 if (paf && PAF_SUBGRP(paf))
11902 json_object_int_add(json_addr, "sentPrefixCounter",
11903 (PAF_SUBGRP(paf))->scount);
d62a17ae 11904
fde246e8
DA
11905 /* Maximum prefix */
11906 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
11907 json_object_int_add(json_addr, "prefixOutAllowedMax",
11908 p->pmax_out[afi][safi]);
11909
d62a17ae 11910 /* Maximum prefix */
11911 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11912 json_object_int_add(json_addr, "prefixAllowedMax",
11913 p->pmax[afi][safi]);
11914 if (CHECK_FLAG(p->af_flags[afi][safi],
11915 PEER_FLAG_MAX_PREFIX_WARNING))
11916 json_object_boolean_true_add(
11917 json_addr, "prefixAllowedMaxWarning");
11918 json_object_int_add(json_addr,
11919 "prefixAllowedWarningThresh",
11920 p->pmax_threshold[afi][safi]);
11921 if (p->pmax_restart[afi][safi])
11922 json_object_int_add(
11923 json_addr,
11924 "prefixAllowedRestartIntervalMsecs",
11925 p->pmax_restart[afi][safi] * 60000);
11926 }
2986cac2 11927 json_object_object_add(json_neigh,
36235319 11928 get_afi_safi_str(afi, safi, true),
d62a17ae 11929 json_addr);
11930
11931 } else {
11932 filter = &p->filter[afi][safi];
11933
11934 vty_out(vty, " For address family: %s\n",
5cb5f4d0 11935 get_afi_safi_str(afi, safi, false));
d62a17ae 11936
11937 if (peer_group_active(p))
11938 vty_out(vty, " %s peer-group member\n",
11939 p->group->name);
11940
11941 paf = peer_af_find(p, afi, safi);
11942 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 11943 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 11944 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
11945 vty_out(vty, " Packet Queue length %d\n",
11946 bpacket_queue_virtual_length(paf));
11947 } else {
11948 vty_out(vty, " Not part of any update group\n");
11949 }
11950 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11951 || CHECK_FLAG(p->af_cap[afi][safi],
11952 PEER_CAP_ORF_PREFIX_SM_RCV)
11953 || CHECK_FLAG(p->af_cap[afi][safi],
11954 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11955 || CHECK_FLAG(p->af_cap[afi][safi],
11956 PEER_CAP_ORF_PREFIX_RM_ADV)
11957 || CHECK_FLAG(p->af_cap[afi][safi],
11958 PEER_CAP_ORF_PREFIX_RM_RCV)
11959 || CHECK_FLAG(p->af_cap[afi][safi],
11960 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11961 vty_out(vty, " AF-dependant capabilities:\n");
11962
11963 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11964 || CHECK_FLAG(p->af_cap[afi][safi],
11965 PEER_CAP_ORF_PREFIX_SM_RCV)
11966 || CHECK_FLAG(p->af_cap[afi][safi],
11967 PEER_CAP_ORF_PREFIX_RM_ADV)
11968 || CHECK_FLAG(p->af_cap[afi][safi],
11969 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11970 vty_out(vty,
11971 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11972 ORF_TYPE_PREFIX);
11973 bgp_show_peer_afi_orf_cap(
11974 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11975 PEER_CAP_ORF_PREFIX_RM_ADV,
11976 PEER_CAP_ORF_PREFIX_SM_RCV,
11977 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
11978 }
11979 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11980 || CHECK_FLAG(p->af_cap[afi][safi],
11981 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11982 || CHECK_FLAG(p->af_cap[afi][safi],
11983 PEER_CAP_ORF_PREFIX_RM_ADV)
11984 || CHECK_FLAG(p->af_cap[afi][safi],
11985 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11986 vty_out(vty,
11987 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11988 ORF_TYPE_PREFIX_OLD);
11989 bgp_show_peer_afi_orf_cap(
11990 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11991 PEER_CAP_ORF_PREFIX_RM_ADV,
11992 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11993 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
11994 }
11995
772270f3
QY
11996 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11997 p->host, afi, safi);
d62a17ae 11998 orf_pfx_count = prefix_bgp_show_prefix_list(
11999 NULL, afi, orf_pfx_name, use_json);
12000
12001 if (CHECK_FLAG(p->af_sflags[afi][safi],
12002 PEER_STATUS_ORF_PREFIX_SEND)
12003 || orf_pfx_count) {
12004 vty_out(vty, " Outbound Route Filter (ORF):");
12005 if (CHECK_FLAG(p->af_sflags[afi][safi],
12006 PEER_STATUS_ORF_PREFIX_SEND))
12007 vty_out(vty, " sent;");
12008 if (orf_pfx_count)
12009 vty_out(vty, " received (%d entries)",
12010 orf_pfx_count);
12011 vty_out(vty, "\n");
12012 }
12013 if (CHECK_FLAG(p->af_sflags[afi][safi],
12014 PEER_STATUS_ORF_WAIT_REFRESH))
12015 vty_out(vty,
12016 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12017
12018 if (CHECK_FLAG(p->af_flags[afi][safi],
12019 PEER_FLAG_REFLECTOR_CLIENT))
12020 vty_out(vty, " Route-Reflector Client\n");
12021 if (CHECK_FLAG(p->af_flags[afi][safi],
12022 PEER_FLAG_RSERVER_CLIENT))
12023 vty_out(vty, " Route-Server Client\n");
12024 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12025 vty_out(vty,
12026 " Inbound soft reconfiguration allowed\n");
12027
12028 if (CHECK_FLAG(p->af_flags[afi][safi],
12029 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12030 vty_out(vty,
12031 " Private AS numbers (all) replaced in updates to this neighbor\n");
12032 else if (CHECK_FLAG(p->af_flags[afi][safi],
12033 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12034 vty_out(vty,
12035 " Private AS numbers replaced in updates to this neighbor\n");
12036 else if (CHECK_FLAG(p->af_flags[afi][safi],
12037 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12038 vty_out(vty,
12039 " Private AS numbers (all) removed in updates to this neighbor\n");
12040 else if (CHECK_FLAG(p->af_flags[afi][safi],
12041 PEER_FLAG_REMOVE_PRIVATE_AS))
12042 vty_out(vty,
12043 " Private AS numbers removed in updates to this neighbor\n");
12044
dcc68b5e
MS
12045 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12046 vty_out(vty, " %s\n",
12047 bgp_addpath_names(p->addpath_type[afi][safi])
12048 ->human_description);
d62a17ae 12049
12050 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12051 vty_out(vty,
12052 " Override ASNs in outbound updates if aspath equals remote-as\n");
12053
12054 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12055 || CHECK_FLAG(p->af_flags[afi][safi],
12056 PEER_FLAG_FORCE_NEXTHOP_SELF))
12057 vty_out(vty, " NEXT_HOP is always this router\n");
12058 if (CHECK_FLAG(p->af_flags[afi][safi],
12059 PEER_FLAG_AS_PATH_UNCHANGED))
12060 vty_out(vty,
12061 " AS_PATH is propagated unchanged to this neighbor\n");
12062 if (CHECK_FLAG(p->af_flags[afi][safi],
12063 PEER_FLAG_NEXTHOP_UNCHANGED))
12064 vty_out(vty,
12065 " NEXT_HOP is propagated unchanged to this neighbor\n");
12066 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12067 vty_out(vty,
12068 " MED is propagated unchanged to this neighbor\n");
12069 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12070 || CHECK_FLAG(p->af_flags[afi][safi],
12071 PEER_FLAG_SEND_EXT_COMMUNITY)
12072 || CHECK_FLAG(p->af_flags[afi][safi],
12073 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12074 vty_out(vty,
12075 " Community attribute sent to this neighbor");
12076 if (CHECK_FLAG(p->af_flags[afi][safi],
12077 PEER_FLAG_SEND_COMMUNITY)
12078 && CHECK_FLAG(p->af_flags[afi][safi],
12079 PEER_FLAG_SEND_EXT_COMMUNITY)
12080 && CHECK_FLAG(p->af_flags[afi][safi],
12081 PEER_FLAG_SEND_LARGE_COMMUNITY))
12082 vty_out(vty, "(all)\n");
12083 else if (CHECK_FLAG(p->af_flags[afi][safi],
12084 PEER_FLAG_SEND_LARGE_COMMUNITY))
12085 vty_out(vty, "(large)\n");
12086 else if (CHECK_FLAG(p->af_flags[afi][safi],
12087 PEER_FLAG_SEND_EXT_COMMUNITY))
12088 vty_out(vty, "(extended)\n");
12089 else
12090 vty_out(vty, "(standard)\n");
12091 }
12092 if (CHECK_FLAG(p->af_flags[afi][safi],
12093 PEER_FLAG_DEFAULT_ORIGINATE)) {
12094 vty_out(vty, " Default information originate,");
12095
12096 if (p->default_rmap[afi][safi].name)
12097 vty_out(vty, " default route-map %s%s,",
12098 p->default_rmap[afi][safi].map ? "*"
12099 : "",
12100 p->default_rmap[afi][safi].name);
12101 if (paf && PAF_SUBGRP(paf)
12102 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12103 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12104 vty_out(vty, " default sent\n");
12105 else
12106 vty_out(vty, " default not sent\n");
12107 }
12108
dff8f48d
MK
12109 /* advertise-vni-all */
12110 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12111 if (is_evpn_enabled())
dff8f48d
MK
12112 vty_out(vty, " advertise-all-vni\n");
12113 }
12114
d62a17ae 12115 if (filter->plist[FILTER_IN].name
12116 || filter->dlist[FILTER_IN].name
12117 || filter->aslist[FILTER_IN].name
12118 || filter->map[RMAP_IN].name)
12119 vty_out(vty, " Inbound path policy configured\n");
12120 if (filter->plist[FILTER_OUT].name
12121 || filter->dlist[FILTER_OUT].name
12122 || filter->aslist[FILTER_OUT].name
12123 || filter->map[RMAP_OUT].name || filter->usmap.name)
12124 vty_out(vty, " Outbound path policy configured\n");
12125
12126 /* prefix-list */
12127 if (filter->plist[FILTER_IN].name)
12128 vty_out(vty,
12129 " Incoming update prefix filter list is %s%s\n",
12130 filter->plist[FILTER_IN].plist ? "*" : "",
12131 filter->plist[FILTER_IN].name);
12132 if (filter->plist[FILTER_OUT].name)
12133 vty_out(vty,
12134 " Outgoing update prefix filter list is %s%s\n",
12135 filter->plist[FILTER_OUT].plist ? "*" : "",
12136 filter->plist[FILTER_OUT].name);
12137
12138 /* distribute-list */
12139 if (filter->dlist[FILTER_IN].name)
12140 vty_out(vty,
12141 " Incoming update network filter list is %s%s\n",
12142 filter->dlist[FILTER_IN].alist ? "*" : "",
12143 filter->dlist[FILTER_IN].name);
12144 if (filter->dlist[FILTER_OUT].name)
12145 vty_out(vty,
12146 " Outgoing update network filter list is %s%s\n",
12147 filter->dlist[FILTER_OUT].alist ? "*" : "",
12148 filter->dlist[FILTER_OUT].name);
12149
12150 /* filter-list. */
12151 if (filter->aslist[FILTER_IN].name)
12152 vty_out(vty,
12153 " Incoming update AS path filter list is %s%s\n",
12154 filter->aslist[FILTER_IN].aslist ? "*" : "",
12155 filter->aslist[FILTER_IN].name);
12156 if (filter->aslist[FILTER_OUT].name)
12157 vty_out(vty,
12158 " Outgoing update AS path filter list is %s%s\n",
12159 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12160 filter->aslist[FILTER_OUT].name);
12161
12162 /* route-map. */
12163 if (filter->map[RMAP_IN].name)
12164 vty_out(vty,
12165 " Route map for incoming advertisements is %s%s\n",
12166 filter->map[RMAP_IN].map ? "*" : "",
12167 filter->map[RMAP_IN].name);
12168 if (filter->map[RMAP_OUT].name)
12169 vty_out(vty,
12170 " Route map for outgoing advertisements is %s%s\n",
12171 filter->map[RMAP_OUT].map ? "*" : "",
12172 filter->map[RMAP_OUT].name);
12173
9dac9fc8 12174 /* ebgp-requires-policy (inbound) */
1d3fdccf 12175 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12176 && !bgp_inbound_policy_exists(p, filter))
12177 vty_out(vty,
12178 " Inbound updates discarded due to missing policy\n");
12179
12180 /* ebgp-requires-policy (outbound) */
1d3fdccf 12181 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12182 && !bgp_outbound_policy_exists(p, filter))
12183 vty_out(vty,
12184 " Outbound updates discarded due to missing policy\n");
12185
d62a17ae 12186 /* unsuppress-map */
12187 if (filter->usmap.name)
12188 vty_out(vty,
12189 " Route map for selective unsuppress is %s%s\n",
12190 filter->usmap.map ? "*" : "",
12191 filter->usmap.name);
12192
7f7940e6
MK
12193 /* advertise-map */
12194 if (filter->advmap.aname && filter->advmap.cname)
12195 vty_out(vty,
12196 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12197 filter->advmap.condition ? "EXIST"
12198 : "NON_EXIST",
12199 filter->advmap.cmap ? "*" : "",
12200 filter->advmap.cname,
12201 filter->advmap.amap ? "*" : "",
12202 filter->advmap.aname,
fa36596c 12203 filter->advmap.update_type == ADVERTISE
c385f82a
MK
12204 ? "Advertise"
12205 : "Withdraw");
7f7940e6 12206
d62a17ae 12207 /* Receive prefix count */
6cde4b45 12208 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12209 p->pcount[afi][safi]);
d62a17ae 12210
fde246e8
DA
12211 /* maximum-prefix-out */
12212 if (CHECK_FLAG(p->af_flags[afi][safi],
12213 PEER_FLAG_MAX_PREFIX_OUT))
12214 vty_out(vty,
6cde4b45 12215 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12216 p->pmax_out[afi][safi]);
12217
d62a17ae 12218 /* Maximum prefix */
12219 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12220 vty_out(vty,
6cde4b45 12221 " Maximum prefixes allowed %u%s\n",
d62a17ae 12222 p->pmax[afi][safi],
12223 CHECK_FLAG(p->af_flags[afi][safi],
12224 PEER_FLAG_MAX_PREFIX_WARNING)
12225 ? " (warning-only)"
12226 : "");
12227 vty_out(vty, " Threshold for warning message %d%%",
12228 p->pmax_threshold[afi][safi]);
12229 if (p->pmax_restart[afi][safi])
12230 vty_out(vty, ", restart interval %d min",
12231 p->pmax_restart[afi][safi]);
12232 vty_out(vty, "\n");
12233 }
12234
12235 vty_out(vty, "\n");
12236 }
12237}
12238
9f049418 12239static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12240 json_object *json)
718e3744 12241{
d62a17ae 12242 struct bgp *bgp;
12243 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12244 char timebuf[BGP_UPTIME_LEN];
12245 char dn_flag[2];
d62a17ae 12246 afi_t afi;
12247 safi_t safi;
d7c0a89a
QY
12248 uint16_t i;
12249 uint8_t *msg;
d62a17ae 12250 json_object *json_neigh = NULL;
12251 time_t epoch_tbuf;
4ab46701 12252 uint32_t sync_tcp_mss;
718e3744 12253
d62a17ae 12254 bgp = p->bgp;
12255
12256 if (use_json)
12257 json_neigh = json_object_new_object();
12258
12259 memset(dn_flag, '\0', sizeof(dn_flag));
12260 if (!p->conf_if && peer_dynamic_neighbor(p))
12261 dn_flag[0] = '*';
12262
12263 if (!use_json) {
12264 if (p->conf_if) /* Configured interface name. */
12265 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12266 BGP_PEER_SU_UNSPEC(p)
12267 ? "None"
12268 : sockunion2str(&p->su, buf,
12269 SU_ADDRSTRLEN));
12270 else /* Configured IP address. */
12271 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12272 p->host);
12273 }
12274
12275 if (use_json) {
12276 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12277 json_object_string_add(json_neigh, "bgpNeighborAddr",
12278 "none");
12279 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12280 json_object_string_add(
12281 json_neigh, "bgpNeighborAddr",
12282 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12283
12284 json_object_int_add(json_neigh, "remoteAs", p->as);
12285
12286 if (p->change_local_as)
12287 json_object_int_add(json_neigh, "localAs",
12288 p->change_local_as);
12289 else
12290 json_object_int_add(json_neigh, "localAs", p->local_as);
12291
12292 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12293 json_object_boolean_true_add(json_neigh,
12294 "localAsNoPrepend");
12295
12296 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12297 json_object_boolean_true_add(json_neigh,
12298 "localAsReplaceAs");
12299 } else {
12300 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12301 || (p->as_type == AS_INTERNAL))
12302 vty_out(vty, "remote AS %u, ", p->as);
12303 else
12304 vty_out(vty, "remote AS Unspecified, ");
12305 vty_out(vty, "local AS %u%s%s, ",
12306 p->change_local_as ? p->change_local_as : p->local_as,
12307 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12308 ? " no-prepend"
12309 : "",
12310 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12311 ? " replace-as"
12312 : "");
12313 }
faa16034
DS
12314 /* peer type internal or confed-internal */
12315 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12316 if (use_json) {
12317 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12318 json_object_boolean_true_add(
12319 json_neigh, "nbrConfedInternalLink");
12320 else
12321 json_object_boolean_true_add(json_neigh,
12322 "nbrInternalLink");
12323 } else {
12324 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12325 vty_out(vty, "confed-internal link\n");
12326 else
12327 vty_out(vty, "internal link\n");
12328 }
faa16034
DS
12329 /* peer type external or confed-external */
12330 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12331 if (use_json) {
12332 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12333 json_object_boolean_true_add(
12334 json_neigh, "nbrConfedExternalLink");
12335 else
12336 json_object_boolean_true_add(json_neigh,
12337 "nbrExternalLink");
12338 } else {
12339 if (bgp_confederation_peers_check(bgp, p->as))
12340 vty_out(vty, "confed-external link\n");
12341 else
12342 vty_out(vty, "external link\n");
12343 }
faa16034
DS
12344 } else {
12345 if (use_json)
12346 json_object_boolean_true_add(json_neigh,
12347 "nbrUnspecifiedLink");
12348 else
12349 vty_out(vty, "unspecified link\n");
d62a17ae 12350 }
12351
12352 /* Description. */
12353 if (p->desc) {
12354 if (use_json)
12355 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12356 else
12357 vty_out(vty, " Description: %s\n", p->desc);
12358 }
12359
12360 if (p->hostname) {
12361 if (use_json) {
12362 if (p->hostname)
12363 json_object_string_add(json_neigh, "hostname",
12364 p->hostname);
12365
12366 if (p->domainname)
12367 json_object_string_add(json_neigh, "domainname",
12368 p->domainname);
12369 } else {
12370 if (p->domainname && (p->domainname[0] != '\0'))
12371 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12372 p->domainname);
12373 else
12374 vty_out(vty, "Hostname: %s\n", p->hostname);
12375 }
12376 }
12377
12378 /* Peer-group */
12379 if (p->group) {
12380 if (use_json) {
12381 json_object_string_add(json_neigh, "peerGroup",
12382 p->group->name);
12383
12384 if (dn_flag[0]) {
12385 struct prefix prefix, *range = NULL;
12386
0154d8ce
DS
12387 if (sockunion2hostprefix(&(p->su), &prefix))
12388 range = peer_group_lookup_dynamic_neighbor_range(
12389 p->group, &prefix);
d62a17ae 12390
12391 if (range) {
67d7e256 12392 json_object_string_addf(
d62a17ae 12393 json_neigh,
67d7e256
DA
12394 "peerSubnetRangeGroup", "%pFX",
12395 range);
d62a17ae 12396 }
12397 }
12398 } else {
12399 vty_out(vty,
12400 " Member of peer-group %s for session parameters\n",
12401 p->group->name);
12402
12403 if (dn_flag[0]) {
12404 struct prefix prefix, *range = NULL;
12405
0154d8ce
DS
12406 if (sockunion2hostprefix(&(p->su), &prefix))
12407 range = peer_group_lookup_dynamic_neighbor_range(
12408 p->group, &prefix);
d62a17ae 12409
12410 if (range) {
d62a17ae 12411 vty_out(vty,
1b78780b
DL
12412 " Belongs to the subnet range group: %pFX\n",
12413 range);
d62a17ae 12414 }
12415 }
12416 }
12417 }
12418
12419 if (use_json) {
12420 /* Administrative shutdown. */
cb9196e7
DS
12421 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12422 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12423 json_object_boolean_true_add(json_neigh,
12424 "adminShutDown");
12425
12426 /* BGP Version. */
12427 json_object_int_add(json_neigh, "bgpVersion", 4);
c949c771
DA
12428 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12429 &p->remote_id);
12430 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12431 &bgp->router_id);
d62a17ae 12432
12433 /* Confederation */
12434 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12435 && bgp_confederation_peers_check(bgp, p->as))
12436 json_object_boolean_true_add(json_neigh,
12437 "nbrCommonAdmin");
12438
12439 /* Status. */
12440 json_object_string_add(
12441 json_neigh, "bgpState",
12442 lookup_msg(bgp_status_msg, p->status, NULL));
12443
feb17238 12444 if (peer_established(p)) {
d62a17ae 12445 time_t uptime;
d62a17ae 12446
12447 uptime = bgp_clock();
12448 uptime -= p->uptime;
d62a17ae 12449 epoch_tbuf = time(NULL) - uptime;
12450
d3c7efed
DS
12451 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12452 uptime * 1000);
d62a17ae 12453 json_object_string_add(json_neigh, "bgpTimerUpString",
12454 peer_uptime(p->uptime, timebuf,
12455 BGP_UPTIME_LEN, 0,
12456 NULL));
12457 json_object_int_add(json_neigh,
12458 "bgpTimerUpEstablishedEpoch",
12459 epoch_tbuf);
12460 }
12461
12462 else if (p->status == Active) {
12463 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12464 json_object_string_add(json_neigh, "bgpStateIs",
12465 "passive");
12466 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12467 json_object_string_add(json_neigh, "bgpStateIs",
12468 "passiveNSF");
12469 }
12470
12471 /* read timer */
12472 time_t uptime;
a2700b50 12473 struct tm tm;
d62a17ae 12474
12475 uptime = bgp_clock();
12476 uptime -= p->readtime;
a2700b50
MS
12477 gmtime_r(&uptime, &tm);
12478
d62a17ae 12479 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
12480 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12481 + (tm.tm_hour * 3600000));
d62a17ae 12482
12483 uptime = bgp_clock();
12484 uptime -= p->last_write;
a2700b50
MS
12485 gmtime_r(&uptime, &tm);
12486
d62a17ae 12487 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
12488 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12489 + (tm.tm_hour * 3600000));
d62a17ae 12490
12491 uptime = bgp_clock();
12492 uptime -= p->update_time;
a2700b50
MS
12493 gmtime_r(&uptime, &tm);
12494
d62a17ae 12495 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
12496 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12497 + (tm.tm_hour * 3600000));
d62a17ae 12498
12499 /* Configured timer values. */
12500 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12501 p->v_holdtime * 1000);
12502 json_object_int_add(json_neigh,
12503 "bgpTimerKeepAliveIntervalMsecs",
12504 p->v_keepalive * 1000);
d43114f3
DS
12505 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12506 json_object_int_add(json_neigh,
12507 "bgpTimerDelayOpenTimeMsecs",
12508 p->v_delayopen * 1000);
12509 }
12510
4ab46701
AR
12511 /* Configured and Synced tcp-mss value for peer */
12512 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12513 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12514 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12515 p->tcp_mss);
12516 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12517 sync_tcp_mss);
12518 }
12519
b90a8e13 12520 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12521 json_object_int_add(json_neigh,
12522 "bgpTimerConfiguredHoldTimeMsecs",
12523 p->holdtime * 1000);
12524 json_object_int_add(
12525 json_neigh,
12526 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12527 p->keepalive * 1000);
5d5393b9
DL
12528 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12529 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12530 json_object_int_add(json_neigh,
12531 "bgpTimerConfiguredHoldTimeMsecs",
12532 bgp->default_holdtime);
12533 json_object_int_add(
12534 json_neigh,
12535 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12536 bgp->default_keepalive);
d62a17ae 12537 }
d08c0c80
DA
12538
12539 /* Extended Optional Parameters Length for BGP OPEN Message */
12540 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12541 json_object_boolean_true_add(
12542 json_neigh, "extendedOptionalParametersLength");
12543 else
12544 json_object_boolean_false_add(
12545 json_neigh, "extendedOptionalParametersLength");
d62a17ae 12546 } else {
12547 /* Administrative shutdown. */
cb9196e7
DS
12548 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12549 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12550 vty_out(vty, " Administratively shut down\n");
12551
12552 /* BGP Version. */
12553 vty_out(vty, " BGP version 4");
0e38aeb4 12554 vty_out(vty, ", remote router ID %s",
d62a17ae 12555 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
12556 vty_out(vty, ", local router ID %s\n",
12557 inet_ntop(AF_INET, &bgp->router_id, buf1,
12558 sizeof(buf1)));
d62a17ae 12559
12560 /* Confederation */
12561 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12562 && bgp_confederation_peers_check(bgp, p->as))
12563 vty_out(vty,
12564 " Neighbor under common administration\n");
12565
12566 /* Status. */
12567 vty_out(vty, " BGP state = %s",
12568 lookup_msg(bgp_status_msg, p->status, NULL));
12569
feb17238 12570 if (peer_established(p))
d62a17ae 12571 vty_out(vty, ", up for %8s",
12572 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12573 0, NULL));
12574
12575 else if (p->status == Active) {
12576 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12577 vty_out(vty, " (passive)");
12578 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12579 vty_out(vty, " (NSF passive)");
12580 }
12581 vty_out(vty, "\n");
12582
12583 /* read timer */
12584 vty_out(vty, " Last read %s",
12585 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12586 NULL));
12587 vty_out(vty, ", Last write %s\n",
12588 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12589 NULL));
12590
12591 /* Configured timer values. */
12592 vty_out(vty,
12593 " Hold time is %d, keepalive interval is %d seconds\n",
12594 p->v_holdtime, p->v_keepalive);
b90a8e13 12595 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12596 vty_out(vty, " Configured hold time is %d",
12597 p->holdtime);
12598 vty_out(vty, ", keepalive interval is %d seconds\n",
12599 p->keepalive);
5d5393b9
DL
12600 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12601 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12602 vty_out(vty, " Configured hold time is %d",
12603 bgp->default_holdtime);
12604 vty_out(vty, ", keepalive interval is %d seconds\n",
12605 bgp->default_keepalive);
d62a17ae 12606 }
d43114f3
DS
12607 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12608 vty_out(vty,
12609 " Configured DelayOpenTime is %d seconds\n",
12610 p->delayopen);
4ab46701
AR
12611
12612 /* Configured and synced tcp-mss value for peer */
12613 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12614 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12615 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12616 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12617 }
d08c0c80
DA
12618
12619 /* Extended Optional Parameters Length for BGP OPEN Message */
12620 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12621 vty_out(vty,
12622 " Extended Optional Parameters Length is enabled\n");
d62a17ae 12623 }
12624 /* Capability. */
10711563
DA
12625 if (peer_established(p) &&
12626 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
12627 if (use_json) {
12628 json_object *json_cap = NULL;
d62a17ae 12629
10711563 12630 json_cap = json_object_new_object();
d62a17ae 12631
10711563
DA
12632 /* AS4 */
12633 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
12634 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12635 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
12636 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
ef56aee4 12637 json_object_string_add(
10711563 12638 json_cap, "4byteAs",
ef56aee4 12639 "advertisedAndReceived");
10711563
DA
12640 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
12641 json_object_string_add(json_cap,
12642 "4byteAs",
12643 "advertised");
12644 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12645 json_object_string_add(json_cap,
12646 "4byteAs",
12647 "received");
12648 }
ef56aee4 12649
10711563
DA
12650 /* Extended Message Support */
12651 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
12652 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
12653 json_object_string_add(json_cap,
12654 "extendedMessage",
12655 "advertisedAndReceived");
12656 else if (CHECK_FLAG(p->cap,
12657 PEER_CAP_EXTENDED_MESSAGE_ADV))
12658 json_object_string_add(json_cap,
12659 "extendedMessage",
12660 "advertised");
12661 else if (CHECK_FLAG(p->cap,
12662 PEER_CAP_EXTENDED_MESSAGE_RCV))
12663 json_object_string_add(json_cap,
12664 "extendedMessage",
12665 "received");
ef56aee4 12666
10711563
DA
12667 /* AddPath */
12668 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
12669 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
12670 json_object *json_add = NULL;
12671 const char *print_store;
d62a17ae 12672
10711563 12673 json_add = json_object_new_object();
d62a17ae 12674
10711563
DA
12675 FOREACH_AFI_SAFI (afi, safi) {
12676 json_object *json_sub = NULL;
12677 json_sub = json_object_new_object();
12678 print_store = get_afi_safi_str(
12679 afi, safi, true);
d62a17ae 12680
10711563
DA
12681 if (CHECK_FLAG(
12682 p->af_cap[afi][safi],
12683 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12684 CHECK_FLAG(
12685 p->af_cap[afi][safi],
12686 PEER_CAP_ADDPATH_AF_TX_RCV)) {
05c7a1cc
QY
12687 if (CHECK_FLAG(
12688 p->af_cap[afi]
12689 [safi],
10711563
DA
12690 PEER_CAP_ADDPATH_AF_TX_ADV) &&
12691 CHECK_FLAG(
05c7a1cc
QY
12692 p->af_cap[afi]
12693 [safi],
10711563
DA
12694 PEER_CAP_ADDPATH_AF_TX_RCV))
12695 json_object_boolean_true_add(
12696 json_sub,
12697 "txAdvertisedAndReceived");
12698 else if (
12699 CHECK_FLAG(
12700 p->af_cap[afi]
12701 [safi],
12702 PEER_CAP_ADDPATH_AF_TX_ADV))
12703 json_object_boolean_true_add(
12704 json_sub,
12705 "txAdvertised");
12706 else if (
12707 CHECK_FLAG(
12708 p->af_cap[afi]
12709 [safi],
12710 PEER_CAP_ADDPATH_AF_TX_RCV))
12711 json_object_boolean_true_add(
12712 json_sub,
12713 "txReceived");
12714 }
d62a17ae 12715
10711563
DA
12716 if (CHECK_FLAG(
12717 p->af_cap[afi][safi],
12718 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12719 CHECK_FLAG(
12720 p->af_cap[afi][safi],
12721 PEER_CAP_ADDPATH_AF_RX_RCV)) {
05c7a1cc
QY
12722 if (CHECK_FLAG(
12723 p->af_cap[afi]
12724 [safi],
10711563
DA
12725 PEER_CAP_ADDPATH_AF_RX_ADV) &&
12726 CHECK_FLAG(
12727 p->af_cap[afi]
12728 [safi],
12729 PEER_CAP_ADDPATH_AF_RX_RCV))
12730 json_object_boolean_true_add(
12731 json_sub,
12732 "rxAdvertisedAndReceived");
12733 else if (
12734 CHECK_FLAG(
12735 p->af_cap[afi]
12736 [safi],
12737 PEER_CAP_ADDPATH_AF_RX_ADV))
12738 json_object_boolean_true_add(
12739 json_sub,
12740 "rxAdvertised");
12741 else if (
12742 CHECK_FLAG(
12743 p->af_cap[afi]
12744 [safi],
12745 PEER_CAP_ADDPATH_AF_RX_RCV))
12746 json_object_boolean_true_add(
12747 json_sub,
12748 "rxReceived");
05c7a1cc
QY
12749 }
12750
10711563
DA
12751 if (CHECK_FLAG(
12752 p->af_cap[afi][safi],
12753 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12754 CHECK_FLAG(
12755 p->af_cap[afi][safi],
12756 PEER_CAP_ADDPATH_AF_TX_RCV) ||
12757 CHECK_FLAG(
12758 p->af_cap[afi][safi],
12759 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12760 CHECK_FLAG(
12761 p->af_cap[afi][safi],
12762 PEER_CAP_ADDPATH_AF_RX_RCV))
12763 json_object_object_add(
12764 json_add, print_store,
12765 json_sub);
12766 else
12767 json_object_free(json_sub);
d62a17ae 12768 }
12769
10711563
DA
12770 json_object_object_add(json_cap, "addPath",
12771 json_add);
12772 }
d62a17ae 12773
10711563
DA
12774 /* Dynamic */
12775 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
12776 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
12777 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
12778 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
12779 json_object_string_add(
12780 json_cap, "dynamic",
12781 "advertisedAndReceived");
12782 else if (CHECK_FLAG(p->cap,
12783 PEER_CAP_DYNAMIC_ADV))
12784 json_object_string_add(json_cap,
12785 "dynamic",
12786 "advertised");
12787 else if (CHECK_FLAG(p->cap,
12788 PEER_CAP_DYNAMIC_RCV))
12789 json_object_string_add(json_cap,
12790 "dynamic",
12791 "received");
12792 }
d62a17ae 12793
10711563
DA
12794 /* Extended nexthop */
12795 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
12796 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12797 json_object *json_nxt = NULL;
12798 const char *print_store;
d62a17ae 12799
d62a17ae 12800
10711563
DA
12801 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
12802 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12803 json_object_string_add(
12804 json_cap, "extendedNexthop",
12805 "advertisedAndReceived");
12806 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
12807 json_object_string_add(
12808 json_cap, "extendedNexthop",
12809 "advertised");
12810 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12811 json_object_string_add(
12812 json_cap, "extendedNexthop",
12813 "received");
d62a17ae 12814
10711563
DA
12815 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
12816 json_nxt = json_object_new_object();
d62a17ae 12817
10711563
DA
12818 for (safi = SAFI_UNICAST;
12819 safi < SAFI_MAX; safi++) {
12820 if (CHECK_FLAG(
12821 p->af_cap[AFI_IP]
12822 [safi],
12823 PEER_CAP_ENHE_AF_RCV)) {
12824 print_store =
12825 get_afi_safi_str(
d62a17ae 12826 AFI_IP,
10711563
DA
12827 safi,
12828 true);
12829 json_object_string_add(
12830 json_nxt,
12831 print_store,
12832 "recieved"); /* misspelled for compatibility */
d62a17ae 12833 }
d62a17ae 12834 }
10711563
DA
12835 json_object_object_add(
12836 json_cap,
12837 "extendedNexthopFamililesByPeer",
12838 json_nxt);
d62a17ae 12839 }
10711563 12840 }
d62a17ae 12841
10711563
DA
12842 /* Long-lived Graceful Restart */
12843 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
12844 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
12845 json_object *json_llgr = NULL;
12846 const char *afi_safi_str;
8606be87 12847
10711563
DA
12848 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
12849 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12850 json_object_string_add(
12851 json_cap,
12852 "longLivedGracefulRestart",
12853 "advertisedAndReceived");
12854 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
12855 json_object_string_add(
12856 json_cap,
12857 "longLivedGracefulRestart",
12858 "advertised");
12859 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12860 json_object_string_add(
12861 json_cap,
12862 "longLivedGracefulRestart",
12863 "received");
8606be87 12864
10711563
DA
12865 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
12866 json_llgr = json_object_new_object();
8606be87 12867
10711563
DA
12868 FOREACH_AFI_SAFI (afi, safi) {
12869 if (CHECK_FLAG(
12870 p->af_cap[afi]
12871 [safi],
12872 PEER_CAP_ENHE_AF_RCV)) {
12873 afi_safi_str =
12874 get_afi_safi_str(
8606be87
DA
12875 afi,
12876 safi,
12877 true);
10711563
DA
12878 json_object_string_add(
12879 json_llgr,
12880 afi_safi_str,
12881 "received");
8606be87 12882 }
8606be87 12883 }
10711563
DA
12884 json_object_object_add(
12885 json_cap,
12886 "longLivedGracefulRestartByPeer",
12887 json_llgr);
8606be87 12888 }
10711563 12889 }
8606be87 12890
10711563
DA
12891 /* Route Refresh */
12892 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
12893 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
12894 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
12895 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
12896 (CHECK_FLAG(p->cap,
12897 PEER_CAP_REFRESH_NEW_RCV) ||
12898 CHECK_FLAG(p->cap,
12899 PEER_CAP_REFRESH_OLD_RCV))) {
12900 if (CHECK_FLAG(
12901 p->cap,
12902 PEER_CAP_REFRESH_OLD_RCV) &&
12903 CHECK_FLAG(
12904 p->cap,
12905 PEER_CAP_REFRESH_NEW_RCV))
12906 json_object_string_add(
12907 json_cap,
12908 "routeRefresh",
12909 "advertisedAndReceivedOldNew");
12910 else {
d62a17ae 12911 if (CHECK_FLAG(
12912 p->cap,
10711563 12913 PEER_CAP_REFRESH_OLD_RCV))
d62a17ae 12914 json_object_string_add(
12915 json_cap,
12916 "routeRefresh",
10711563
DA
12917 "advertisedAndReceivedOld");
12918 else
12919 json_object_string_add(
12920 json_cap,
12921 "routeRefresh",
12922 "advertisedAndReceivedNew");
d62a17ae 12923 }
10711563
DA
12924 } else if (CHECK_FLAG(p->cap,
12925 PEER_CAP_REFRESH_ADV))
12926 json_object_string_add(json_cap,
12927 "routeRefresh",
12928 "advertised");
12929 else if (CHECK_FLAG(p->cap,
12930 PEER_CAP_REFRESH_NEW_RCV) ||
12931 CHECK_FLAG(p->cap,
12932 PEER_CAP_REFRESH_OLD_RCV))
12933 json_object_string_add(json_cap,
12934 "routeRefresh",
12935 "received");
12936 }
d62a17ae 12937
10711563
DA
12938 /* Enhanced Route Refresh */
12939 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
12940 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
12941 if (CHECK_FLAG(p->cap,
12942 PEER_CAP_ENHANCED_RR_ADV) &&
12943 CHECK_FLAG(p->cap,
12944 PEER_CAP_ENHANCED_RR_RCV))
d77114b7 12945 json_object_string_add(
10711563
DA
12946 json_cap,
12947 "enhancedRouteRefresh",
12948 "advertisedAndReceived");
12949 else if (CHECK_FLAG(p->cap,
12950 PEER_CAP_ENHANCED_RR_ADV))
d77114b7 12951 json_object_string_add(
10711563
DA
12952 json_cap,
12953 "enhancedRouteRefresh",
12954 "advertised");
12955 else if (CHECK_FLAG(p->cap,
9af52ccf 12956 PEER_CAP_ENHANCED_RR_RCV))
10711563
DA
12957 json_object_string_add(
12958 json_cap,
12959 "enhancedRouteRefresh",
12960 "received");
12961 }
d77114b7 12962
10711563
DA
12963 /* Multiprotocol Extensions */
12964 json_object *json_multi = NULL;
d77114b7 12965
10711563 12966 json_multi = json_object_new_object();
d77114b7 12967
10711563
DA
12968 FOREACH_AFI_SAFI (afi, safi) {
12969 if (p->afc_adv[afi][safi] ||
12970 p->afc_recv[afi][safi]) {
12971 json_object *json_exten = NULL;
12972 json_exten = json_object_new_object();
12973
12974 if (p->afc_adv[afi][safi] &&
12975 p->afc_recv[afi][safi])
12976 json_object_boolean_true_add(
12977 json_exten,
9af52ccf 12978 "advertisedAndReceived");
10711563
DA
12979 else if (p->afc_adv[afi][safi])
12980 json_object_boolean_true_add(
12981 json_exten,
9af52ccf 12982 "advertised");
10711563
DA
12983 else if (p->afc_recv[afi][safi])
12984 json_object_boolean_true_add(
12985 json_exten, "received");
9af52ccf 12986
10711563
DA
12987 json_object_object_add(
12988 json_multi,
12989 get_afi_safi_str(afi, safi,
12990 true),
12991 json_exten);
12992 }
12993 }
12994 json_object_object_add(json_cap,
12995 "multiprotocolExtensions",
12996 json_multi);
d62a17ae 12997
10711563
DA
12998 /* Hostname capabilities */
12999 json_object *json_hname = NULL;
d62a17ae 13000
10711563 13001 json_hname = json_object_new_object();
d62a17ae 13002
10711563
DA
13003 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13004 json_object_string_add(
13005 json_hname, "advHostName",
13006 bgp->peer_self->hostname
13007 ? bgp->peer_self->hostname
13008 : "n/a");
13009 json_object_string_add(
13010 json_hname, "advDomainName",
13011 bgp->peer_self->domainname
13012 ? bgp->peer_self->domainname
13013 : "n/a");
13014 }
d77114b7 13015
d77114b7 13016
10711563
DA
13017 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13018 json_object_string_add(
13019 json_hname, "rcvHostName",
13020 p->hostname ? p->hostname : "n/a");
13021 json_object_string_add(
13022 json_hname, "rcvDomainName",
13023 p->domainname ? p->domainname : "n/a");
13024 }
d77114b7 13025
10711563
DA
13026 json_object_object_add(json_cap, "hostName",
13027 json_hname);
d77114b7 13028
10711563
DA
13029 /* Gracefull Restart */
13030 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13031 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13032 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13033 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
d77114b7 13034 json_object_string_add(
10711563
DA
13035 json_cap, "gracefulRestart",
13036 "advertisedAndReceived");
13037 else if (CHECK_FLAG(p->cap,
13038 PEER_CAP_RESTART_ADV))
d77114b7 13039 json_object_string_add(
10711563
DA
13040 json_cap,
13041 "gracefulRestartCapability",
13042 "advertised");
13043 else if (CHECK_FLAG(p->cap,
13044 PEER_CAP_RESTART_RCV))
13045 json_object_string_add(
13046 json_cap,
13047 "gracefulRestartCapability",
13048 "received");
d77114b7 13049
10711563
DA
13050 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13051 int restart_af_count = 0;
13052 json_object *json_restart = NULL;
13053 json_restart = json_object_new_object();
d62a17ae 13054
10711563
DA
13055 json_object_int_add(
13056 json_cap,
13057 "gracefulRestartRemoteTimerMsecs",
13058 p->v_gr_restart * 1000);
d62a17ae 13059
10711563 13060 FOREACH_AFI_SAFI (afi, safi) {
05c7a1cc
QY
13061 if (CHECK_FLAG(
13062 p->af_cap[afi]
13063 [safi],
10711563
DA
13064 PEER_CAP_RESTART_AF_RCV)) {
13065 json_object *json_sub =
13066 NULL;
13067 json_sub =
13068 json_object_new_object();
d62a17ae 13069
05c7a1cc
QY
13070 if (CHECK_FLAG(
13071 p->af_cap
13072 [afi]
13073 [safi],
10711563
DA
13074 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13075 json_object_boolean_true_add(
13076 json_sub,
13077 "preserved");
13078 restart_af_count++;
d62a17ae 13079 json_object_object_add(
10711563
DA
13080 json_restart,
13081 get_afi_safi_str(
13082 afi,
13083 safi,
13084 true),
13085 json_sub);
d62a17ae 13086 }
d62a17ae 13087 }
10711563
DA
13088 if (!restart_af_count) {
13089 json_object_string_add(
13090 json_cap,
13091 "addressFamiliesByPeer",
13092 "none");
13093 json_object_free(json_restart);
13094 } else
13095 json_object_object_add(
13096 json_cap,
13097 "addressFamiliesByPeer",
13098 json_restart);
d62a17ae 13099 }
10711563
DA
13100 }
13101 json_object_object_add(
13102 json_neigh, "neighborCapabilities", json_cap);
13103 } else {
13104 vty_out(vty, " Neighbor capabilities:\n");
13105
13106 /* AS4 */
13107 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13108 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13109 vty_out(vty, " 4 Byte AS:");
13110 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13111 vty_out(vty, " advertised");
13112 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13113 vty_out(vty, " %sreceived",
13114 CHECK_FLAG(p->cap,
13115 PEER_CAP_AS4_ADV)
13116 ? "and "
13117 : "");
13118 vty_out(vty, "\n");
13119 }
d62a17ae 13120
10711563
DA
13121 /* Extended Message Support */
13122 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13123 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13124 vty_out(vty, " Extended Message:");
ef56aee4 13125 if (CHECK_FLAG(p->cap,
10711563
DA
13126 PEER_CAP_EXTENDED_MESSAGE_ADV))
13127 vty_out(vty, " advertised");
13128 if (CHECK_FLAG(p->cap,
13129 PEER_CAP_EXTENDED_MESSAGE_RCV))
13130 vty_out(vty, " %sreceived",
13131 CHECK_FLAG(
13132 p->cap,
13133 PEER_CAP_EXTENDED_MESSAGE_ADV)
13134 ? "and "
13135 : "");
13136 vty_out(vty, "\n");
13137 }
d62a17ae 13138
10711563
DA
13139 /* AddPath */
13140 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13141 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13142 vty_out(vty, " AddPath:\n");
d62a17ae 13143
10711563 13144 FOREACH_AFI_SAFI (afi, safi) {
ef56aee4 13145 if (CHECK_FLAG(
10711563
DA
13146 p->af_cap[afi][safi],
13147 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13148 CHECK_FLAG(
13149 p->af_cap[afi][safi],
13150 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13151 vty_out(vty, " %s: TX ",
13152 get_afi_safi_str(
13153 afi, safi,
13154 false));
ef56aee4 13155
10711563
DA
13156 if (CHECK_FLAG(
13157 p->af_cap[afi]
13158 [safi],
13159 PEER_CAP_ADDPATH_AF_TX_ADV))
13160 vty_out(vty,
13161 "advertised");
d62a17ae 13162
05c7a1cc
QY
13163 if (CHECK_FLAG(
13164 p->af_cap[afi]
13165 [safi],
10711563 13166 PEER_CAP_ADDPATH_AF_TX_RCV))
05c7a1cc 13167 vty_out(vty,
10711563
DA
13168 "%sreceived",
13169 CHECK_FLAG(
13170 p->af_cap
13171 [afi]
13172 [safi],
13173 PEER_CAP_ADDPATH_AF_TX_ADV)
13174 ? " and "
13175 : "");
05c7a1cc 13176
10711563
DA
13177 vty_out(vty, "\n");
13178 }
d62a17ae 13179
9af52ccf 13180 if (CHECK_FLAG(
10711563
DA
13181 p->af_cap[afi][safi],
13182 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13183 CHECK_FLAG(
13184 p->af_cap[afi][safi],
13185 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13186 vty_out(vty, " %s: RX ",
5cb5f4d0 13187 get_afi_safi_str(
10711563
DA
13188 afi, safi,
13189 false));
d62a17ae 13190
05c7a1cc
QY
13191 if (CHECK_FLAG(
13192 p->af_cap[afi]
13193 [safi],
10711563 13194 PEER_CAP_ADDPATH_AF_RX_ADV))
05c7a1cc 13195 vty_out(vty,
10711563 13196 "advertised");
d62a17ae 13197
10711563
DA
13198 if (CHECK_FLAG(
13199 p->af_cap[afi]
13200 [safi],
13201 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc 13202 vty_out(vty,
10711563
DA
13203 "%sreceived",
13204 CHECK_FLAG(
13205 p->af_cap
13206 [afi]
13207 [safi],
13208 PEER_CAP_ADDPATH_AF_RX_ADV)
13209 ? " and "
05c7a1cc 13210 : "");
d62a17ae 13211
05c7a1cc 13212 vty_out(vty, "\n");
05c7a1cc 13213 }
d62a17ae 13214 }
10711563 13215 }
d62a17ae 13216
10711563
DA
13217 /* Dynamic */
13218 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13219 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13220 vty_out(vty, " Dynamic:");
13221 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13222 vty_out(vty, " advertised");
13223 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13224 vty_out(vty, " %sreceived",
13225 CHECK_FLAG(p->cap,
13226 PEER_CAP_DYNAMIC_ADV)
13227 ? "and "
13228 : "");
13229 vty_out(vty, "\n");
13230 }
d62a17ae 13231
10711563
DA
13232 /* Extended nexthop */
13233 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13234 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13235 vty_out(vty, " Extended nexthop:");
13236 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13237 vty_out(vty, " advertised");
13238 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13239 vty_out(vty, " %sreceived",
13240 CHECK_FLAG(p->cap,
13241 PEER_CAP_ENHE_ADV)
13242 ? "and "
13243 : "");
13244 vty_out(vty, "\n");
d62a17ae 13245
10711563 13246 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
57f7feb6 13247 vty_out(vty,
10711563
DA
13248 " Address families by peer:\n ");
13249 for (safi = SAFI_UNICAST;
13250 safi < SAFI_MAX; safi++)
13251 if (CHECK_FLAG(
13252 p->af_cap[AFI_IP]
13253 [safi],
13254 PEER_CAP_ENHE_AF_RCV))
13255 vty_out(vty,
13256 " %s\n",
13257 get_afi_safi_str(
13258 AFI_IP,
13259 safi,
13260 false));
d62a17ae 13261 }
10711563 13262 }
d62a17ae 13263
10711563
DA
13264 /* Long-lived Graceful Restart */
13265 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13266 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13267 vty_out(vty,
13268 " Long-lived Graceful Restart:");
13269 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13270 vty_out(vty, " advertised");
13271 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13272 vty_out(vty, " %sreceived",
13273 CHECK_FLAG(p->cap,
13274 PEER_CAP_LLGR_ADV)
13275 ? "and "
13276 : "");
13277 vty_out(vty, "\n");
8606be87 13278
10711563 13279 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
57f7feb6 13280 vty_out(vty,
10711563
DA
13281 " Address families by peer:\n");
13282 FOREACH_AFI_SAFI (afi, safi)
13283 if (CHECK_FLAG(
13284 p->af_cap[afi]
13285 [safi],
13286 PEER_CAP_LLGR_AF_RCV))
13287 vty_out(vty,
13288 " %s\n",
13289 get_afi_safi_str(
13290 afi,
13291 safi,
13292 false));
8606be87 13293 }
10711563 13294 }
8606be87 13295
10711563
DA
13296 /* Route Refresh */
13297 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13298 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13299 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13300 vty_out(vty, " Route refresh:");
13301 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13302 vty_out(vty, " advertised");
13303 if (CHECK_FLAG(p->cap,
13304 PEER_CAP_REFRESH_NEW_RCV) ||
13305 CHECK_FLAG(p->cap,
13306 PEER_CAP_REFRESH_OLD_RCV))
13307 vty_out(vty, " %sreceived(%s)",
13308 CHECK_FLAG(p->cap,
13309 PEER_CAP_REFRESH_ADV)
13310 ? "and "
13311 : "",
13312 (CHECK_FLAG(
13313 p->cap,
13314 PEER_CAP_REFRESH_OLD_RCV) &&
13315 CHECK_FLAG(
13316 p->cap,
13317 PEER_CAP_REFRESH_NEW_RCV))
13318 ? "old & new"
13319 : CHECK_FLAG(
13320 p->cap,
13321 PEER_CAP_REFRESH_OLD_RCV)
13322 ? "old"
13323 : "new");
d62a17ae 13324
d77114b7 13325 vty_out(vty, "\n");
10711563 13326 }
d62a17ae 13327
10711563
DA
13328 /* Enhanced Route Refresh */
13329 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13330 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13331 vty_out(vty, " Enhanced Route Refresh:");
13332 if (CHECK_FLAG(p->cap,
13333 PEER_CAP_ENHANCED_RR_ADV))
13334 vty_out(vty, " advertised");
13335 if (CHECK_FLAG(p->cap,
13336 PEER_CAP_ENHANCED_RR_RCV))
13337 vty_out(vty, " %sreceived",
13338 CHECK_FLAG(p->cap,
13339 PEER_CAP_REFRESH_ADV)
13340 ? "and "
13341 : "");
13342 vty_out(vty, "\n");
13343 }
13344
13345 /* Multiprotocol Extensions */
13346 FOREACH_AFI_SAFI (afi, safi)
13347 if (p->afc_adv[afi][safi] ||
13348 p->afc_recv[afi][safi]) {
13349 vty_out(vty, " Address Family %s:",
13350 get_afi_safi_str(afi, safi,
13351 false));
13352 if (p->afc_adv[afi][safi])
9af52ccf 13353 vty_out(vty, " advertised");
10711563 13354 if (p->afc_recv[afi][safi])
9af52ccf 13355 vty_out(vty, " %sreceived",
10711563 13356 p->afc_adv[afi][safi]
9af52ccf
DA
13357 ? "and "
13358 : "");
13359 vty_out(vty, "\n");
13360 }
13361
10711563
DA
13362 /* Hostname capability */
13363 vty_out(vty, " Hostname Capability:");
d62a17ae 13364
10711563
DA
13365 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13366 vty_out(vty,
13367 " advertised (name: %s,domain name: %s)",
13368 bgp->peer_self->hostname
13369 ? bgp->peer_self->hostname
13370 : "n/a",
13371 bgp->peer_self->domainname
13372 ? bgp->peer_self->domainname
13373 : "n/a");
13374 } else {
13375 vty_out(vty, " not advertised");
13376 }
d77114b7 13377
10711563
DA
13378 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13379 vty_out(vty,
13380 " received (name: %s,domain name: %s)",
13381 p->hostname ? p->hostname : "n/a",
13382 p->domainname ? p->domainname : "n/a");
13383 } else {
13384 vty_out(vty, " not received");
d62a17ae 13385 }
d62a17ae 13386
10711563 13387 vty_out(vty, "\n");
d77114b7 13388
10711563
DA
13389 /* Graceful Restart */
13390 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13391 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13392 vty_out(vty,
13393 " Graceful Restart Capability:");
13394 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13395 vty_out(vty, " advertised");
13396 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13397 vty_out(vty, " %sreceived",
13398 CHECK_FLAG(p->cap,
13399 PEER_CAP_RESTART_ADV)
13400 ? "and "
13401 : "");
d77114b7
MK
13402 vty_out(vty, "\n");
13403
10711563
DA
13404 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13405 int restart_af_count = 0;
d62a17ae 13406
10711563
DA
13407 vty_out(vty,
13408 " Remote Restart timer is %d seconds\n",
13409 p->v_gr_restart);
13410 vty_out(vty,
13411 " Address families by peer:\n ");
d62a17ae 13412
10711563
DA
13413 FOREACH_AFI_SAFI (afi, safi)
13414 if (CHECK_FLAG(
13415 p->af_cap[afi]
13416 [safi],
13417 PEER_CAP_RESTART_AF_RCV)) {
13418 vty_out(vty, "%s%s(%s)",
13419 restart_af_count
13420 ? ", "
13421 : "",
13422 get_afi_safi_str(
13423 afi,
13424 safi,
13425 false),
13426 CHECK_FLAG(
13427 p->af_cap
13428 [afi]
13429 [safi],
13430 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13431 ? "preserved"
13432 : "not preserved");
13433 restart_af_count++;
13434 }
13435 if (!restart_af_count)
13436 vty_out(vty, "none");
13437 vty_out(vty, "\n");
13438 }
13439 } /* Gracefull Restart */
d62a17ae 13440 }
13441 }
13442
13443 /* graceful restart information */
10711563
DA
13444 json_object *json_grace = NULL;
13445 json_object *json_grace_send = NULL;
13446 json_object *json_grace_recv = NULL;
13447 int eor_send_af_count = 0;
13448 int eor_receive_af_count = 0;
d62a17ae 13449
10711563
DA
13450 if (use_json) {
13451 json_grace = json_object_new_object();
13452 json_grace_send = json_object_new_object();
13453 json_grace_recv = json_object_new_object();
13454
13455 if ((peer_established(p)) &&
13456 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13457 FOREACH_AFI_SAFI (afi, safi) {
13458 if (CHECK_FLAG(p->af_sflags[afi][safi],
13459 PEER_STATUS_EOR_SEND)) {
13460 json_object_boolean_true_add(
13461 json_grace_send,
13462 get_afi_safi_str(afi, safi,
13463 true));
13464 eor_send_af_count++;
d62a17ae 13465 }
10711563
DA
13466 }
13467 FOREACH_AFI_SAFI (afi, safi) {
13468 if (CHECK_FLAG(p->af_sflags[afi][safi],
13469 PEER_STATUS_EOR_RECEIVED)) {
13470 json_object_boolean_true_add(
13471 json_grace_recv,
13472 get_afi_safi_str(afi, safi,
13473 true));
13474 eor_receive_af_count++;
d62a17ae 13475 }
13476 }
10711563
DA
13477 }
13478 json_object_object_add(json_grace, "endOfRibSend",
13479 json_grace_send);
13480 json_object_object_add(json_grace, "endOfRibRecv",
13481 json_grace_recv);
d62a17ae 13482
d62a17ae 13483
10711563
DA
13484 if (p->t_gr_restart)
13485 json_object_int_add(
13486 json_grace, "gracefulRestartTimerMsecs",
13487 thread_timer_remain_second(p->t_gr_restart) *
13488 1000);
2986cac2 13489
10711563
DA
13490 if (p->t_gr_stale)
13491 json_object_int_add(
13492 json_grace, "gracefulStalepathTimerMsecs",
13493 thread_timer_remain_second(p->t_gr_stale) *
13494 1000);
13495 /* more gr info in new format */
13496 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13497 json_object_object_add(json_neigh, "gracefulRestartInfo",
13498 json_grace);
13499 } else {
13500 vty_out(vty, " Graceful restart information:\n");
13501 if ((peer_established(p)) &&
13502 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13503
13504 vty_out(vty, " End-of-RIB send: ");
13505 FOREACH_AFI_SAFI (afi, safi) {
13506 if (CHECK_FLAG(p->af_sflags[afi][safi],
13507 PEER_STATUS_EOR_SEND)) {
13508 vty_out(vty, "%s%s",
13509 eor_send_af_count ? ", " : "",
13510 get_afi_safi_str(afi, safi,
13511 false));
13512 eor_send_af_count++;
d62a17ae 13513 }
10711563
DA
13514 }
13515 vty_out(vty, "\n");
13516 vty_out(vty, " End-of-RIB received: ");
13517 FOREACH_AFI_SAFI (afi, safi) {
13518 if (CHECK_FLAG(p->af_sflags[afi][safi],
13519 PEER_STATUS_EOR_RECEIVED)) {
13520 vty_out(vty, "%s%s",
13521 eor_receive_af_count ? ", "
13522 : "",
13523 get_afi_safi_str(afi, safi,
13524 false));
13525 eor_receive_af_count++;
d62a17ae 13526 }
d62a17ae 13527 }
10711563
DA
13528 vty_out(vty, "\n");
13529 }
d62a17ae 13530
10711563
DA
13531 if (p->t_gr_restart)
13532 vty_out(vty,
13533 " The remaining time of restart timer is %ld\n",
13534 thread_timer_remain_second(p->t_gr_restart));
d62a17ae 13535
10711563
DA
13536 if (p->t_gr_stale)
13537 vty_out(vty,
13538 " The remaining time of stalepath timer is %ld\n",
13539 thread_timer_remain_second(p->t_gr_stale));
2986cac2 13540
10711563
DA
13541 /* more gr info in new format */
13542 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13543 }
2986cac2 13544
d62a17ae 13545 if (use_json) {
13546 json_object *json_stat = NULL;
13547 json_stat = json_object_new_object();
13548 /* Packet counts. */
43aa5965
QY
13549
13550 atomic_size_t outq_count, inq_count;
13551 outq_count = atomic_load_explicit(&p->obuf->count,
13552 memory_order_relaxed);
13553 inq_count = atomic_load_explicit(&p->ibuf->count,
13554 memory_order_relaxed);
13555
13556 json_object_int_add(json_stat, "depthInq",
13557 (unsigned long)inq_count);
d62a17ae 13558 json_object_int_add(json_stat, "depthOutq",
43aa5965 13559 (unsigned long)outq_count);
0112e9e0
QY
13560 json_object_int_add(json_stat, "opensSent",
13561 atomic_load_explicit(&p->open_out,
13562 memory_order_relaxed));
13563 json_object_int_add(json_stat, "opensRecv",
13564 atomic_load_explicit(&p->open_in,
13565 memory_order_relaxed));
d62a17ae 13566 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
13567 atomic_load_explicit(&p->notify_out,
13568 memory_order_relaxed));
d62a17ae 13569 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
13570 atomic_load_explicit(&p->notify_in,
13571 memory_order_relaxed));
13572 json_object_int_add(json_stat, "updatesSent",
13573 atomic_load_explicit(&p->update_out,
13574 memory_order_relaxed));
13575 json_object_int_add(json_stat, "updatesRecv",
13576 atomic_load_explicit(&p->update_in,
13577 memory_order_relaxed));
d62a17ae 13578 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
13579 atomic_load_explicit(&p->keepalive_out,
13580 memory_order_relaxed));
d62a17ae 13581 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
13582 atomic_load_explicit(&p->keepalive_in,
13583 memory_order_relaxed));
d62a17ae 13584 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
13585 atomic_load_explicit(&p->refresh_out,
13586 memory_order_relaxed));
d62a17ae 13587 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
13588 atomic_load_explicit(&p->refresh_in,
13589 memory_order_relaxed));
d62a17ae 13590 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
13591 atomic_load_explicit(&p->dynamic_cap_out,
13592 memory_order_relaxed));
d62a17ae 13593 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
13594 atomic_load_explicit(&p->dynamic_cap_in,
13595 memory_order_relaxed));
13596 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13597 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 13598 json_object_object_add(json_neigh, "messageStats", json_stat);
13599 } else {
43aa5965
QY
13600 atomic_size_t outq_count, inq_count;
13601 outq_count = atomic_load_explicit(&p->obuf->count,
13602 memory_order_relaxed);
13603 inq_count = atomic_load_explicit(&p->ibuf->count,
13604 memory_order_relaxed);
13605
d62a17ae 13606 /* Packet counts. */
13607 vty_out(vty, " Message statistics:\n");
43aa5965
QY
13608 vty_out(vty, " Inq depth is %zu\n", inq_count);
13609 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 13610 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
13611 vty_out(vty, " Opens: %10d %10d\n",
13612 atomic_load_explicit(&p->open_out,
13613 memory_order_relaxed),
13614 atomic_load_explicit(&p->open_in,
13615 memory_order_relaxed));
13616 vty_out(vty, " Notifications: %10d %10d\n",
13617 atomic_load_explicit(&p->notify_out,
13618 memory_order_relaxed),
13619 atomic_load_explicit(&p->notify_in,
13620 memory_order_relaxed));
13621 vty_out(vty, " Updates: %10d %10d\n",
13622 atomic_load_explicit(&p->update_out,
13623 memory_order_relaxed),
13624 atomic_load_explicit(&p->update_in,
13625 memory_order_relaxed));
13626 vty_out(vty, " Keepalives: %10d %10d\n",
13627 atomic_load_explicit(&p->keepalive_out,
13628 memory_order_relaxed),
13629 atomic_load_explicit(&p->keepalive_in,
13630 memory_order_relaxed));
13631 vty_out(vty, " Route Refresh: %10d %10d\n",
13632 atomic_load_explicit(&p->refresh_out,
13633 memory_order_relaxed),
13634 atomic_load_explicit(&p->refresh_in,
13635 memory_order_relaxed));
d62a17ae 13636 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
13637 atomic_load_explicit(&p->dynamic_cap_out,
13638 memory_order_relaxed),
13639 atomic_load_explicit(&p->dynamic_cap_in,
13640 memory_order_relaxed));
13641 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
13642 PEER_TOTAL_RX(p));
d62a17ae 13643 }
13644
13645 if (use_json) {
13646 /* advertisement-interval */
13647 json_object_int_add(json_neigh,
13648 "minBtwnAdvertisementRunsTimerMsecs",
13649 p->v_routeadv * 1000);
13650
13651 /* Update-source. */
13652 if (p->update_if || p->update_source) {
13653 if (p->update_if)
13654 json_object_string_add(json_neigh,
13655 "updateSource",
13656 p->update_if);
13657 else if (p->update_source)
13658 json_object_string_add(
13659 json_neigh, "updateSource",
13660 sockunion2str(p->update_source, buf1,
13661 SU_ADDRSTRLEN));
13662 }
13663 } else {
13664 /* advertisement-interval */
13665 vty_out(vty,
13666 " Minimum time between advertisement runs is %d seconds\n",
13667 p->v_routeadv);
13668
13669 /* Update-source. */
13670 if (p->update_if || p->update_source) {
13671 vty_out(vty, " Update source is ");
13672 if (p->update_if)
13673 vty_out(vty, "%s", p->update_if);
13674 else if (p->update_source)
13675 vty_out(vty, "%s",
13676 sockunion2str(p->update_source, buf1,
13677 SU_ADDRSTRLEN));
13678 vty_out(vty, "\n");
13679 }
13680
13681 vty_out(vty, "\n");
13682 }
13683
13684 /* Address Family Information */
13685 json_object *json_hold = NULL;
13686
13687 if (use_json)
13688 json_hold = json_object_new_object();
13689
05c7a1cc
QY
13690 FOREACH_AFI_SAFI (afi, safi)
13691 if (p->afc[afi][safi])
13692 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13693 json_hold);
d62a17ae 13694
13695 if (use_json) {
13696 json_object_object_add(json_neigh, "addressFamilyInfo",
13697 json_hold);
13698 json_object_int_add(json_neigh, "connectionsEstablished",
13699 p->established);
13700 json_object_int_add(json_neigh, "connectionsDropped",
13701 p->dropped);
13702 } else
13703 vty_out(vty, " Connections established %d; dropped %d\n",
13704 p->established, p->dropped);
13705
13706 if (!p->last_reset) {
13707 if (use_json)
13708 json_object_string_add(json_neigh, "lastReset",
13709 "never");
13710 else
13711 vty_out(vty, " Last reset never\n");
13712 } else {
13713 if (use_json) {
13714 time_t uptime;
a2700b50 13715 struct tm tm;
d62a17ae 13716
13717 uptime = bgp_clock();
13718 uptime -= p->resettime;
a2700b50
MS
13719 gmtime_r(&uptime, &tm);
13720
d62a17ae 13721 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
13722 (tm.tm_sec * 1000)
13723 + (tm.tm_min * 60000)
13724 + (tm.tm_hour * 3600000));
3577f1c5 13725 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 13726 } else {
13727 vty_out(vty, " Last reset %s, ",
13728 peer_uptime(p->resettime, timebuf,
13729 BGP_UPTIME_LEN, 0, NULL));
13730
3577f1c5 13731 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 13732 if (p->last_reset_cause_size) {
13733 msg = p->last_reset_cause;
13734 vty_out(vty,
13735 " Message received that caused BGP to send a NOTIFICATION:\n ");
13736 for (i = 1; i <= p->last_reset_cause_size;
13737 i++) {
13738 vty_out(vty, "%02X", *msg++);
13739
13740 if (i != p->last_reset_cause_size) {
13741 if (i % 16 == 0) {
13742 vty_out(vty, "\n ");
13743 } else if (i % 4 == 0) {
13744 vty_out(vty, " ");
13745 }
13746 }
13747 }
13748 vty_out(vty, "\n");
13749 }
13750 }
13751 }
13752
13753 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13754 if (use_json)
13755 json_object_boolean_true_add(json_neigh,
13756 "prefixesConfigExceedMax");
13757 else
13758 vty_out(vty,
13759 " Peer had exceeded the max. no. of prefixes configured.\n");
13760
13761 if (p->t_pmax_restart) {
13762 if (use_json) {
13763 json_object_boolean_true_add(
13764 json_neigh, "reducePrefixNumFrom");
13765 json_object_int_add(json_neigh,
13766 "restartInTimerMsec",
13767 thread_timer_remain_second(
13768 p->t_pmax_restart)
13769 * 1000);
13770 } else
13771 vty_out(vty,
13772 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
13773 p->host, thread_timer_remain_second(
13774 p->t_pmax_restart));
d62a17ae 13775 } else {
13776 if (use_json)
13777 json_object_boolean_true_add(
13778 json_neigh,
13779 "reducePrefixNumAndClearIpBgp");
13780 else
13781 vty_out(vty,
13782 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13783 p->host);
13784 }
13785 }
13786
13787 /* EBGP Multihop and GTSM */
13788 if (p->sort != BGP_PEER_IBGP) {
13789 if (use_json) {
e2521429 13790 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13791 json_object_int_add(json_neigh,
13792 "externalBgpNbrMaxHopsAway",
13793 p->gtsm_hops);
c8d6f0d6 13794 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13795 json_object_int_add(json_neigh,
13796 "externalBgpNbrMaxHopsAway",
13797 p->ttl);
13798 } else {
e2521429 13799 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13800 vty_out(vty,
13801 " External BGP neighbor may be up to %d hops away.\n",
13802 p->gtsm_hops);
c8d6f0d6 13803 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13804 vty_out(vty,
13805 " External BGP neighbor may be up to %d hops away.\n",
13806 p->ttl);
13807 }
13808 } else {
e2521429 13809 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 13810 if (use_json)
13811 json_object_int_add(json_neigh,
13812 "internalBgpNbrMaxHopsAway",
13813 p->gtsm_hops);
13814 else
13815 vty_out(vty,
13816 " Internal BGP neighbor may be up to %d hops away.\n",
13817 p->gtsm_hops);
13818 }
13819 }
13820
13821 /* Local address. */
13822 if (p->su_local) {
13823 if (use_json) {
13824 json_object_string_add(json_neigh, "hostLocal",
13825 sockunion2str(p->su_local, buf1,
13826 SU_ADDRSTRLEN));
13827 json_object_int_add(json_neigh, "portLocal",
13828 ntohs(p->su_local->sin.sin_port));
13829 } else
13830 vty_out(vty, "Local host: %s, Local port: %d\n",
13831 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
13832 ntohs(p->su_local->sin.sin_port));
13833 }
13834
13835 /* Remote address. */
13836 if (p->su_remote) {
13837 if (use_json) {
13838 json_object_string_add(json_neigh, "hostForeign",
13839 sockunion2str(p->su_remote, buf1,
13840 SU_ADDRSTRLEN));
13841 json_object_int_add(json_neigh, "portForeign",
13842 ntohs(p->su_remote->sin.sin_port));
13843 } else
13844 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
13845 sockunion2str(p->su_remote, buf1,
13846 SU_ADDRSTRLEN),
13847 ntohs(p->su_remote->sin.sin_port));
13848 }
13849
13850 /* Nexthop display. */
13851 if (p->su_local) {
13852 if (use_json) {
c949c771
DA
13853 json_object_string_addf(json_neigh, "nexthop", "%pI4",
13854 &p->nexthop.v4);
13855 json_object_string_addf(json_neigh, "nexthopGlobal",
13856 "%pI6", &p->nexthop.v6_global);
13857 json_object_string_addf(json_neigh, "nexthopLocal",
13858 "%pI6", &p->nexthop.v6_local);
d62a17ae 13859 if (p->shared_network)
13860 json_object_string_add(json_neigh,
13861 "bgpConnection",
13862 "sharedNetwork");
13863 else
13864 json_object_string_add(json_neigh,
13865 "bgpConnection",
13866 "nonSharedNetwork");
13867 } else {
13868 vty_out(vty, "Nexthop: %s\n",
13869 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
13870 sizeof(buf1)));
13871 vty_out(vty, "Nexthop global: %s\n",
13872 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
13873 sizeof(buf1)));
13874 vty_out(vty, "Nexthop local: %s\n",
13875 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
13876 sizeof(buf1)));
13877 vty_out(vty, "BGP connection: %s\n",
13878 p->shared_network ? "shared network"
13879 : "non shared network");
13880 }
13881 }
13882
13883 /* Timer information. */
13884 if (use_json) {
13885 json_object_int_add(json_neigh, "connectRetryTimer",
13886 p->v_connect);
feb17238 13887 if (peer_established(p) && p->rtt)
d62a17ae 13888 json_object_int_add(json_neigh, "estimatedRttInMsecs",
13889 p->rtt);
13890 if (p->t_start)
13891 json_object_int_add(
13892 json_neigh, "nextStartTimerDueInMsecs",
13893 thread_timer_remain_second(p->t_start) * 1000);
13894 if (p->t_connect)
13895 json_object_int_add(
13896 json_neigh, "nextConnectTimerDueInMsecs",
13897 thread_timer_remain_second(p->t_connect)
13898 * 1000);
13899 if (p->t_routeadv) {
13900 json_object_int_add(json_neigh, "mraiInterval",
13901 p->v_routeadv);
13902 json_object_int_add(
13903 json_neigh, "mraiTimerExpireInMsecs",
13904 thread_timer_remain_second(p->t_routeadv)
13905 * 1000);
13906 }
13907 if (p->password)
13908 json_object_int_add(json_neigh, "authenticationEnabled",
13909 1);
13910
13911 if (p->t_read)
13912 json_object_string_add(json_neigh, "readThread", "on");
13913 else
13914 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
13915
13916 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 13917 json_object_string_add(json_neigh, "writeThread", "on");
13918 else
13919 json_object_string_add(json_neigh, "writeThread",
13920 "off");
13921 } else {
13922 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
13923 p->v_connect);
feb17238 13924 if (peer_established(p) && p->rtt)
d62a17ae 13925 vty_out(vty, "Estimated round trip time: %d ms\n",
13926 p->rtt);
13927 if (p->t_start)
13928 vty_out(vty, "Next start timer due in %ld seconds\n",
13929 thread_timer_remain_second(p->t_start));
13930 if (p->t_connect)
13931 vty_out(vty, "Next connect timer due in %ld seconds\n",
13932 thread_timer_remain_second(p->t_connect));
13933 if (p->t_routeadv)
13934 vty_out(vty,
13935 "MRAI (interval %u) timer expires in %ld seconds\n",
13936 p->v_routeadv,
13937 thread_timer_remain_second(p->t_routeadv));
13938 if (p->password)
13939 vty_out(vty, "Peer Authentication Enabled\n");
13940
cac9e917 13941 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
13942 p->t_read ? "on" : "off",
13943 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
13944 ? "on"
cac9e917 13945 : "off", p->fd);
d62a17ae 13946 }
13947
13948 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
13949 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
13950 bgp_capability_vty_out(vty, p, use_json, json_neigh);
13951
13952 if (!use_json)
13953 vty_out(vty, "\n");
13954
13955 /* BFD information. */
21bfce98
RZ
13956 if (p->bfd_config)
13957 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 13958
13959 if (use_json) {
13960 if (p->conf_if) /* Configured interface name. */
13961 json_object_object_add(json, p->conf_if, json_neigh);
13962 else /* Configured IP address. */
13963 json_object_object_add(json, p->host, json_neigh);
13964 }
13965}
13966
36235319
QY
13967static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
13968 enum show_type type,
13969 union sockunion *su,
13970 const char *conf_if, afi_t afi,
74a630b6 13971 bool use_json)
2986cac2 13972{
13973 struct listnode *node, *nnode;
13974 struct peer *peer;
13975 int find = 0;
13976 safi_t safi = SAFI_UNICAST;
74a630b6 13977 json_object *json = NULL;
2986cac2 13978 json_object *json_neighbor = NULL;
13979
74a630b6
NT
13980 if (use_json) {
13981 json = json_object_new_object();
13982 json_neighbor = json_object_new_object();
13983 }
13984
2986cac2 13985 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13986
13987 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13988 continue;
13989
13990 if ((peer->afc[afi][safi]) == 0)
13991 continue;
13992
2ba1fe69 13993 if (type == show_all) {
2986cac2 13994 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 13995 json_neighbor);
2986cac2 13996
74a630b6 13997 if (use_json) {
13909c4f
DS
13998 json_object_object_add(json, peer->host,
13999 json_neighbor);
74a630b6
NT
14000 json_neighbor = NULL;
14001 }
2986cac2 14002
2ba1fe69 14003 } else if (type == show_peer) {
2986cac2 14004 if (conf_if) {
14005 if ((peer->conf_if
13909c4f
DS
14006 && !strcmp(peer->conf_if, conf_if))
14007 || (peer->hostname
2986cac2 14008 && !strcmp(peer->hostname, conf_if))) {
14009 find = 1;
13909c4f
DS
14010 bgp_show_peer_gr_status(vty, peer,
14011 use_json,
14012 json_neighbor);
2986cac2 14013 }
14014 } else {
14015 if (sockunion_same(&peer->su, su)) {
14016 find = 1;
13909c4f
DS
14017 bgp_show_peer_gr_status(vty, peer,
14018 use_json,
14019 json_neighbor);
2986cac2 14020 }
14021 }
13909c4f
DS
14022 if (use_json && find)
14023 json_object_object_add(json, peer->host,
14024 json_neighbor);
2986cac2 14025 }
14026
74a630b6
NT
14027 if (find) {
14028 json_neighbor = NULL;
2986cac2 14029 break;
74a630b6 14030 }
2986cac2 14031 }
14032
14033 if (type == show_peer && !find) {
14034 if (use_json)
13909c4f 14035 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14036 else
14037 vty_out(vty, "%% No such neighbor\n");
14038 }
14039 if (use_json) {
74a630b6
NT
14040 if (json_neighbor)
14041 json_object_free(json_neighbor);
75eeda93 14042 vty_json(vty, json);
2986cac2 14043 } else {
14044 vty_out(vty, "\n");
14045 }
14046
14047 return CMD_SUCCESS;
14048}
14049
d62a17ae 14050static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14051 enum show_type type, union sockunion *su,
9f049418 14052 const char *conf_if, bool use_json,
d62a17ae 14053 json_object *json)
14054{
14055 struct listnode *node, *nnode;
14056 struct peer *peer;
14057 int find = 0;
9f049418 14058 bool nbr_output = false;
d1927ebe
AS
14059 afi_t afi = AFI_MAX;
14060 safi_t safi = SAFI_MAX;
14061
14062 if (type == show_ipv4_peer || type == show_ipv4_all) {
14063 afi = AFI_IP;
14064 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14065 afi = AFI_IP6;
14066 }
d62a17ae 14067
14068 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14069 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14070 continue;
14071
14072 switch (type) {
14073 case show_all:
14074 bgp_show_peer(vty, peer, use_json, json);
9f049418 14075 nbr_output = true;
d62a17ae 14076 break;
14077 case show_peer:
14078 if (conf_if) {
14079 if ((peer->conf_if
14080 && !strcmp(peer->conf_if, conf_if))
14081 || (peer->hostname
14082 && !strcmp(peer->hostname, conf_if))) {
14083 find = 1;
14084 bgp_show_peer(vty, peer, use_json,
14085 json);
14086 }
14087 } else {
14088 if (sockunion_same(&peer->su, su)) {
14089 find = 1;
14090 bgp_show_peer(vty, peer, use_json,
14091 json);
14092 }
14093 }
14094 break;
d1927ebe
AS
14095 case show_ipv4_peer:
14096 case show_ipv6_peer:
14097 FOREACH_SAFI (safi) {
14098 if (peer->afc[afi][safi]) {
14099 if (conf_if) {
14100 if ((peer->conf_if
14101 && !strcmp(peer->conf_if, conf_if))
14102 || (peer->hostname
14103 && !strcmp(peer->hostname, conf_if))) {
14104 find = 1;
14105 bgp_show_peer(vty, peer, use_json,
14106 json);
14107 break;
14108 }
14109 } else {
14110 if (sockunion_same(&peer->su, su)) {
14111 find = 1;
14112 bgp_show_peer(vty, peer, use_json,
14113 json);
14114 break;
14115 }
14116 }
14117 }
14118 }
14119 break;
14120 case show_ipv4_all:
14121 case show_ipv6_all:
14122 FOREACH_SAFI (safi) {
14123 if (peer->afc[afi][safi]) {
14124 bgp_show_peer(vty, peer, use_json, json);
14125 nbr_output = true;
14126 break;
14127 }
14128 }
14129 break;
d62a17ae 14130 }
14131 }
14132
d1927ebe
AS
14133 if ((type == show_peer || type == show_ipv4_peer ||
14134 type == show_ipv6_peer) && !find) {
d62a17ae 14135 if (use_json)
14136 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14137 else
88b7d255 14138 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14139 }
14140
d1927ebe
AS
14141 if (type != show_peer && type != show_ipv4_peer &&
14142 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14143 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14144
d62a17ae 14145 if (use_json) {
996c9314
LB
14146 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14147 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14148 } else {
14149 vty_out(vty, "\n");
14150 }
14151
14152 return CMD_SUCCESS;
14153}
14154
36235319
QY
14155static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14156 enum show_type type,
14157 const char *ip_str,
14158 afi_t afi, bool use_json)
2986cac2 14159{
14160
14161 int ret;
14162 struct bgp *bgp;
14163 union sockunion su;
2986cac2 14164
14165 bgp = bgp_get_default();
14166
13909c4f
DS
14167 if (!bgp)
14168 return;
2986cac2 14169
13909c4f
DS
14170 if (!use_json)
14171 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14172 NULL);
2986cac2 14173
13909c4f
DS
14174 if (ip_str) {
14175 ret = str2sockunion(ip_str, &su);
14176 if (ret < 0)
13909c4f 14177 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14178 vty, bgp, type, NULL, ip_str, afi, use_json);
14179 else
14180 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14181 NULL, afi, use_json);
13909c4f
DS
14182 } else
14183 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14184 afi, use_json);
2986cac2 14185}
14186
d62a17ae 14187static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14188 enum show_type type,
14189 const char *ip_str,
9f049418 14190 bool use_json)
d62a17ae 14191{
0291c246
MK
14192 struct listnode *node, *nnode;
14193 struct bgp *bgp;
71aedaa3 14194 union sockunion su;
0291c246 14195 json_object *json = NULL;
71aedaa3 14196 int ret, is_first = 1;
9f049418 14197 bool nbr_output = false;
d62a17ae 14198
14199 if (use_json)
14200 vty_out(vty, "{\n");
14201
14202 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14203 nbr_output = true;
d62a17ae 14204 if (use_json) {
14205 if (!(json = json_object_new_object())) {
af4c2728 14206 flog_err(
e50f7cfd 14207 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14208 "Unable to allocate memory for JSON object");
14209 vty_out(vty,
14210 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14211 return;
14212 }
14213
14214 json_object_int_add(json, "vrfId",
14215 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14216 ? -1
14217 : (int64_t)bgp->vrf_id);
d62a17ae 14218 json_object_string_add(
14219 json, "vrfName",
14220 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14221 ? VRF_DEFAULT_NAME
d62a17ae 14222 : bgp->name);
14223
14224 if (!is_first)
14225 vty_out(vty, ",\n");
14226 else
14227 is_first = 0;
14228
14229 vty_out(vty, "\"%s\":",
14230 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14231 ? VRF_DEFAULT_NAME
d62a17ae 14232 : bgp->name);
14233 } else {
14234 vty_out(vty, "\nInstance %s:\n",
14235 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14236 ? VRF_DEFAULT_NAME
d62a17ae 14237 : bgp->name);
14238 }
71aedaa3 14239
d1927ebe
AS
14240 if (type == show_peer || type == show_ipv4_peer ||
14241 type == show_ipv6_peer) {
71aedaa3
DS
14242 ret = str2sockunion(ip_str, &su);
14243 if (ret < 0)
14244 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14245 use_json, json);
14246 else
14247 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14248 use_json, json);
14249 } else {
d1927ebe 14250 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14251 use_json, json);
14252 }
b77004d6 14253 json_object_free(json);
121067e9 14254 json = NULL;
d62a17ae 14255 }
14256
3e78a6ce 14257 if (use_json)
d62a17ae 14258 vty_out(vty, "}\n");
9f049418
DS
14259 else if (!nbr_output)
14260 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14261}
14262
14263static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14264 enum show_type type, const char *ip_str,
9f049418 14265 bool use_json)
d62a17ae 14266{
14267 int ret;
14268 struct bgp *bgp;
14269 union sockunion su;
14270 json_object *json = NULL;
14271
14272 if (name) {
14273 if (strmatch(name, "all")) {
71aedaa3
DS
14274 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14275 use_json);
d62a17ae 14276 return CMD_SUCCESS;
14277 } else {
14278 bgp = bgp_lookup_by_name(name);
14279 if (!bgp) {
14280 if (use_json) {
14281 json = json_object_new_object();
75eeda93 14282 vty_json(vty, json);
d62a17ae 14283 } else
14284 vty_out(vty,
9f049418 14285 "%% BGP instance not found\n");
d62a17ae 14286
14287 return CMD_WARNING;
14288 }
14289 }
14290 } else {
14291 bgp = bgp_get_default();
14292 }
14293
14294 if (bgp) {
14295 json = json_object_new_object();
14296 if (ip_str) {
14297 ret = str2sockunion(ip_str, &su);
14298 if (ret < 0)
14299 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14300 use_json, json);
14301 else
14302 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14303 use_json, json);
14304 } else {
14305 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14306 json);
14307 }
14308 json_object_free(json);
ca61fd25
DS
14309 } else {
14310 if (use_json)
14311 vty_out(vty, "{}\n");
14312 else
14313 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14314 }
14315
14316 return CMD_SUCCESS;
4fb25c53
DW
14317}
14318
2986cac2 14319
14320
14321/* "show [ip] bgp neighbors graceful-restart" commands. */
14322DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14323 show_ip_bgp_neighbors_graceful_restart_cmd,
14324 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14325 SHOW_STR
14326 BGP_STR
14327 IP_STR
14328 IPV6_STR
14329 NEIGHBOR_STR
14330 "Neighbor to display information about\n"
14331 "Neighbor to display information about\n"
14332 "Neighbor on BGP configured interface\n"
14333 GR_SHOW
14334 JSON_STR)
14335{
14336 char *sh_arg = NULL;
14337 enum show_type sh_type;
14338 int idx = 0;
14339 afi_t afi = AFI_MAX;
2986cac2 14340 bool uj = use_json(argc, argv);
14341
36235319 14342 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 14343 afi = AFI_MAX;
14344
14345 idx++;
14346
14347 if (argv_find(argv, argc, "A.B.C.D", &idx)
14348 || argv_find(argv, argc, "X:X::X:X", &idx)
14349 || argv_find(argv, argc, "WORD", &idx)) {
14350 sh_type = show_peer;
14351 sh_arg = argv[idx]->arg;
14352 } else
14353 sh_type = show_all;
14354
14355 if (!argv_find(argv, argc, "graceful-restart", &idx))
14356 return CMD_SUCCESS;
14357
14358
36235319
QY
14359 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14360 afi, uj);
2986cac2 14361}
14362
716b2d8a 14363/* "show [ip] bgp neighbors" commands. */
718e3744 14364DEFUN (show_ip_bgp_neighbors,
14365 show_ip_bgp_neighbors_cmd,
24345e82 14366 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 14367 SHOW_STR
14368 IP_STR
14369 BGP_STR
f2a8972b 14370 BGP_INSTANCE_HELP_STR
8c3deaae
QY
14371 "Address Family\n"
14372 "Address Family\n"
718e3744 14373 "Detailed information on TCP and BGP neighbor connections\n"
14374 "Neighbor to display information about\n"
a80beece 14375 "Neighbor to display information about\n"
91d37724 14376 "Neighbor on BGP configured interface\n"
9973d184 14377 JSON_STR)
718e3744 14378{
d62a17ae 14379 char *vrf = NULL;
14380 char *sh_arg = NULL;
14381 enum show_type sh_type;
d1927ebe 14382 afi_t afi = AFI_MAX;
718e3744 14383
9f049418 14384 bool uj = use_json(argc, argv);
718e3744 14385
d62a17ae 14386 int idx = 0;
718e3744 14387
9a8bdf1c
PG
14388 /* [<vrf> VIEWVRFNAME] */
14389 if (argv_find(argv, argc, "vrf", &idx)) {
14390 vrf = argv[idx + 1]->arg;
14391 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14392 vrf = NULL;
14393 } else if (argv_find(argv, argc, "view", &idx))
14394 /* [<view> VIEWVRFNAME] */
d62a17ae 14395 vrf = argv[idx + 1]->arg;
718e3744 14396
d62a17ae 14397 idx++;
d1927ebe
AS
14398
14399 if (argv_find(argv, argc, "ipv4", &idx)) {
14400 sh_type = show_ipv4_all;
14401 afi = AFI_IP;
14402 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14403 sh_type = show_ipv6_all;
14404 afi = AFI_IP6;
14405 } else {
14406 sh_type = show_all;
14407 }
14408
d62a17ae 14409 if (argv_find(argv, argc, "A.B.C.D", &idx)
14410 || argv_find(argv, argc, "X:X::X:X", &idx)
14411 || argv_find(argv, argc, "WORD", &idx)) {
14412 sh_type = show_peer;
14413 sh_arg = argv[idx]->arg;
d1927ebe
AS
14414 }
14415
14416 if (sh_type == show_peer && afi == AFI_IP) {
14417 sh_type = show_ipv4_peer;
14418 } else if (sh_type == show_peer && afi == AFI_IP6) {
14419 sh_type = show_ipv6_peer;
14420 }
856ca177 14421
d62a17ae 14422 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 14423}
14424
716b2d8a 14425/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 14426 paths' and `show ip mbgp paths'. Those functions results are the
14427 same.*/
f412b39a 14428DEFUN (show_ip_bgp_paths,
718e3744 14429 show_ip_bgp_paths_cmd,
46f296b4 14430 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 14431 SHOW_STR
14432 IP_STR
14433 BGP_STR
46f296b4 14434 BGP_SAFI_HELP_STR
718e3744 14435 "Path information\n")
14436{
d62a17ae 14437 vty_out(vty, "Address Refcnt Path\n");
14438 aspath_print_all_vty(vty);
14439 return CMD_SUCCESS;
718e3744 14440}
14441
718e3744 14442#include "hash.h"
14443
e3b78da8 14444static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14445 struct vty *vty)
718e3744 14446{
d62a17ae 14447 struct community *com;
718e3744 14448
e3b78da8 14449 com = (struct community *)bucket->data;
3f65c5b1 14450 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 14451 community_str(com, false));
718e3744 14452}
14453
14454/* Show BGP's community internal data. */
f412b39a 14455DEFUN (show_ip_bgp_community_info,
718e3744 14456 show_ip_bgp_community_info_cmd,
bec37ba5 14457 "show [ip] bgp community-info",
718e3744 14458 SHOW_STR
14459 IP_STR
14460 BGP_STR
14461 "List all bgp community information\n")
14462{
d62a17ae 14463 vty_out(vty, "Address Refcnt Community\n");
718e3744 14464
d62a17ae 14465 hash_iterate(community_hash(),
e3b78da8 14466 (void (*)(struct hash_bucket *,
d62a17ae 14467 void *))community_show_all_iterator,
14468 vty);
718e3744 14469
d62a17ae 14470 return CMD_SUCCESS;
718e3744 14471}
14472
e3b78da8 14473static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14474 struct vty *vty)
57d187bc 14475{
d62a17ae 14476 struct lcommunity *lcom;
57d187bc 14477
e3b78da8 14478 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 14479 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 14480 lcommunity_str(lcom, false));
57d187bc
JS
14481}
14482
14483/* Show BGP's community internal data. */
14484DEFUN (show_ip_bgp_lcommunity_info,
14485 show_ip_bgp_lcommunity_info_cmd,
14486 "show ip bgp large-community-info",
14487 SHOW_STR
14488 IP_STR
14489 BGP_STR
14490 "List all bgp large-community information\n")
14491{
d62a17ae 14492 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 14493
d62a17ae 14494 hash_iterate(lcommunity_hash(),
e3b78da8 14495 (void (*)(struct hash_bucket *,
d62a17ae 14496 void *))lcommunity_show_all_iterator,
14497 vty);
57d187bc 14498
d62a17ae 14499 return CMD_SUCCESS;
57d187bc 14500}
2986cac2 14501/* Graceful Restart */
14502
14503static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
14504 struct bgp *bgp,
14505 bool use_json,
14506 json_object *json)
2986cac2 14507{
57d187bc
JS
14508
14509
2986cac2 14510 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14511
7318ae88 14512 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 14513
14514 switch (bgp_global_gr_mode) {
14515
14516 case GLOBAL_HELPER:
13909c4f 14517 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 14518 break;
14519
14520 case GLOBAL_GR:
13909c4f 14521 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 14522 break;
14523
14524 case GLOBAL_DISABLE:
13909c4f 14525 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 14526 break;
14527
14528 case GLOBAL_INVALID:
2986cac2 14529 vty_out(vty,
2ba1fe69 14530 "Global BGP GR Mode Invalid\n");
2986cac2 14531 break;
14532 }
14533 vty_out(vty, "\n");
14534}
14535
36235319
QY
14536static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14537 enum show_type type,
14538 const char *ip_str,
14539 afi_t afi, bool use_json)
2986cac2 14540{
14541 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14542 afi = AFI_IP;
14543
14544 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14545
36235319
QY
14546 bgp_show_neighbor_graceful_restart_vty(
14547 vty, type, ip_str, afi, use_json);
2986cac2 14548 afi++;
14549 }
14550 } else if (afi != AFI_MAX) {
36235319
QY
14551 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14552 use_json);
2986cac2 14553 } else {
14554 return CMD_ERR_INCOMPLETE;
14555 }
14556
14557 return CMD_SUCCESS;
14558}
14559/* Graceful Restart */
14560
f412b39a 14561DEFUN (show_ip_bgp_attr_info,
718e3744 14562 show_ip_bgp_attr_info_cmd,
bec37ba5 14563 "show [ip] bgp attribute-info",
718e3744 14564 SHOW_STR
14565 IP_STR
14566 BGP_STR
14567 "List all bgp attribute information\n")
14568{
d62a17ae 14569 attr_show_all(vty);
14570 return CMD_SUCCESS;
718e3744 14571}
6b0655a2 14572
03915806
CS
14573static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14574 afi_t afi, safi_t safi,
14575 bool use_json, json_object *json)
53089bec 14576{
14577 struct bgp *bgp;
14578 struct listnode *node;
14579 char *vname;
14580 char buf1[INET6_ADDRSTRLEN];
14581 char *ecom_str;
14582 vpn_policy_direction_t dir;
14583
03915806 14584 if (json) {
b46dfd20
DS
14585 json_object *json_import_vrfs = NULL;
14586 json_object *json_export_vrfs = NULL;
14587
b46dfd20
DS
14588 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14589
53089bec 14590 if (!bgp) {
75eeda93 14591 vty_json(vty, json);
b46dfd20 14592
53089bec 14593 return CMD_WARNING;
14594 }
b46dfd20 14595
94d4c685
DS
14596 /* Provide context for the block */
14597 json_object_string_add(json, "vrf", name ? name : "default");
14598 json_object_string_add(json, "afiSafi",
5cb5f4d0 14599 get_afi_safi_str(afi, safi, true));
94d4c685 14600
b46dfd20
DS
14601 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14602 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14603 json_object_string_add(json, "importFromVrfs", "none");
14604 json_object_string_add(json, "importRts", "none");
14605 } else {
6ce24e52
DS
14606 json_import_vrfs = json_object_new_array();
14607
b46dfd20
DS
14608 for (ALL_LIST_ELEMENTS_RO(
14609 bgp->vpn_policy[afi].import_vrf,
14610 node, vname))
14611 json_object_array_add(json_import_vrfs,
14612 json_object_new_string(vname));
14613
b20875ea
CS
14614 json_object_object_add(json, "importFromVrfs",
14615 json_import_vrfs);
b46dfd20 14616 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14617 if (bgp->vpn_policy[afi].rtlist[dir]) {
14618 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14619 bgp->vpn_policy[afi].rtlist[dir],
14620 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14621 json_object_string_add(json, "importRts",
14622 ecom_str);
14623 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14624 } else
14625 json_object_string_add(json, "importRts",
14626 "none");
b46dfd20
DS
14627 }
14628
14629 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14630 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14631 json_object_string_add(json, "exportToVrfs", "none");
14632 json_object_string_add(json, "routeDistinguisher",
14633 "none");
14634 json_object_string_add(json, "exportRts", "none");
14635 } else {
6ce24e52
DS
14636 json_export_vrfs = json_object_new_array();
14637
b46dfd20
DS
14638 for (ALL_LIST_ELEMENTS_RO(
14639 bgp->vpn_policy[afi].export_vrf,
14640 node, vname))
14641 json_object_array_add(json_export_vrfs,
14642 json_object_new_string(vname));
14643 json_object_object_add(json, "exportToVrfs",
14644 json_export_vrfs);
14645 json_object_string_add(json, "routeDistinguisher",
14646 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14647 buf1, RD_ADDRSTRLEN));
14648
14649 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14650 if (bgp->vpn_policy[afi].rtlist[dir]) {
14651 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14652 bgp->vpn_policy[afi].rtlist[dir],
14653 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14654 json_object_string_add(json, "exportRts",
14655 ecom_str);
14656 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14657 } else
14658 json_object_string_add(json, "exportRts",
14659 "none");
b46dfd20
DS
14660 }
14661
03915806 14662 if (use_json) {
75eeda93 14663 vty_json(vty, json);
03915806 14664 }
53089bec 14665 } else {
b46dfd20
DS
14666 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14667
53089bec 14668 if (!bgp) {
b46dfd20 14669 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 14670 return CMD_WARNING;
14671 }
53089bec 14672
b46dfd20
DS
14673 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14674 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14675 vty_out(vty,
14676 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 14677 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14678 else {
14679 vty_out(vty,
14680 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 14681 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14682
14683 for (ALL_LIST_ELEMENTS_RO(
14684 bgp->vpn_policy[afi].import_vrf,
14685 node, vname))
14686 vty_out(vty, " %s\n", vname);
14687
14688 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14689 ecom_str = NULL;
14690 if (bgp->vpn_policy[afi].rtlist[dir]) {
14691 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14692 bgp->vpn_policy[afi].rtlist[dir],
14693 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 14694 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 14695
b20875ea
CS
14696 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14697 } else
14698 vty_out(vty, "Import RT(s):\n");
53089bec 14699 }
53089bec 14700
b46dfd20
DS
14701 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14702 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14703 vty_out(vty,
14704 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 14705 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14706 else {
14707 vty_out(vty,
04c9077f 14708 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 14709 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14710
14711 for (ALL_LIST_ELEMENTS_RO(
14712 bgp->vpn_policy[afi].export_vrf,
14713 node, vname))
14714 vty_out(vty, " %s\n", vname);
14715
14716 vty_out(vty, "RD: %s\n",
14717 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14718 buf1, RD_ADDRSTRLEN));
14719
14720 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14721 if (bgp->vpn_policy[afi].rtlist[dir]) {
14722 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14723 bgp->vpn_policy[afi].rtlist[dir],
14724 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14725 vty_out(vty, "Export RT: %s\n", ecom_str);
14726 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14727 } else
14728 vty_out(vty, "Import RT(s):\n");
53089bec 14729 }
53089bec 14730 }
14731
14732 return CMD_SUCCESS;
14733}
14734
03915806
CS
14735static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14736 safi_t safi, bool use_json)
14737{
14738 struct listnode *node, *nnode;
14739 struct bgp *bgp;
14740 char *vrf_name = NULL;
14741 json_object *json = NULL;
14742 json_object *json_vrf = NULL;
14743 json_object *json_vrfs = NULL;
14744
14745 if (use_json) {
14746 json = json_object_new_object();
14747 json_vrfs = json_object_new_object();
14748 }
14749
14750 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14751
14752 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14753 vrf_name = bgp->name;
14754
14755 if (use_json) {
14756 json_vrf = json_object_new_object();
14757 } else {
14758 vty_out(vty, "\nInstance %s:\n",
14759 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14760 ? VRF_DEFAULT_NAME : bgp->name);
14761 }
14762 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14763 if (use_json) {
14764 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14765 json_object_object_add(json_vrfs,
14766 VRF_DEFAULT_NAME, json_vrf);
14767 else
14768 json_object_object_add(json_vrfs, vrf_name,
14769 json_vrf);
14770 }
14771 }
14772
14773 if (use_json) {
14774 json_object_object_add(json, "vrfs", json_vrfs);
75eeda93 14775 vty_json(vty, json);
03915806
CS
14776 }
14777
14778 return CMD_SUCCESS;
14779}
14780
53089bec 14781/* "show [ip] bgp route-leak" command. */
14782DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
14783 show_ip_bgp_route_leak_cmd,
14784 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
14785 SHOW_STR
14786 IP_STR
14787 BGP_STR
14788 BGP_INSTANCE_HELP_STR
14789 BGP_AFI_HELP_STR
14790 BGP_SAFI_HELP_STR
14791 "Route leaking information\n"
14792 JSON_STR)
53089bec 14793{
14794 char *vrf = NULL;
14795 afi_t afi = AFI_MAX;
14796 safi_t safi = SAFI_MAX;
14797
9f049418 14798 bool uj = use_json(argc, argv);
53089bec 14799 int idx = 0;
03915806 14800 json_object *json = NULL;
53089bec 14801
14802 /* show [ip] bgp */
14803 if (argv_find(argv, argc, "ip", &idx)) {
14804 afi = AFI_IP;
14805 safi = SAFI_UNICAST;
14806 }
14807 /* [vrf VIEWVRFNAME] */
14808 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
14809 vty_out(vty,
14810 "%% This command is not applicable to BGP views\n");
53089bec 14811 return CMD_WARNING;
14812 }
14813
9a8bdf1c
PG
14814 if (argv_find(argv, argc, "vrf", &idx)) {
14815 vrf = argv[idx + 1]->arg;
14816 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14817 vrf = NULL;
14818 }
53089bec 14819 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
c48349e3 14820 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
53089bec 14821 argv_find_and_parse_safi(argv, argc, &idx, &safi);
53089bec 14822
14823 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
14824 vty_out(vty,
14825 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 14826 return CMD_WARNING;
14827 }
14828
03915806
CS
14829 if (vrf && strmatch(vrf, "all"))
14830 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
14831
14832 if (uj)
14833 json = json_object_new_object();
14834
14835 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 14836}
14837
d62a17ae 14838static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
14839 safi_t safi)
f186de26 14840{
d62a17ae 14841 struct listnode *node, *nnode;
14842 struct bgp *bgp;
f186de26 14843
d62a17ae 14844 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14845 vty_out(vty, "\nInstance %s:\n",
14846 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14847 ? VRF_DEFAULT_NAME
d62a17ae 14848 : bgp->name);
14849 update_group_show(bgp, afi, safi, vty, 0);
14850 }
f186de26 14851}
14852
d62a17ae 14853static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
14854 int safi, uint64_t subgrp_id)
4fb25c53 14855{
d62a17ae 14856 struct bgp *bgp;
4fb25c53 14857
d62a17ae 14858 if (name) {
14859 if (strmatch(name, "all")) {
14860 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
14861 return CMD_SUCCESS;
14862 } else {
14863 bgp = bgp_lookup_by_name(name);
14864 }
14865 } else {
14866 bgp = bgp_get_default();
14867 }
4fb25c53 14868
d62a17ae 14869 if (bgp)
14870 update_group_show(bgp, afi, safi, vty, subgrp_id);
14871 return CMD_SUCCESS;
4fb25c53
DW
14872}
14873
8fe8a7f6
DS
14874DEFUN (show_ip_bgp_updgrps,
14875 show_ip_bgp_updgrps_cmd,
c1a44e43 14876 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 14877 SHOW_STR
14878 IP_STR
14879 BGP_STR
14880 BGP_INSTANCE_HELP_STR
c9e571b4 14881 BGP_AFI_HELP_STR
9bedbb1e 14882 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
14883 "Detailed info about dynamic update groups\n"
14884 "Specific subgroup to display detailed info for\n")
8386ac43 14885{
d62a17ae 14886 char *vrf = NULL;
14887 afi_t afi = AFI_IP6;
14888 safi_t safi = SAFI_UNICAST;
14889 uint64_t subgrp_id = 0;
14890
14891 int idx = 0;
14892
14893 /* show [ip] bgp */
14894 if (argv_find(argv, argc, "ip", &idx))
14895 afi = AFI_IP;
9a8bdf1c
PG
14896 /* [<vrf> VIEWVRFNAME] */
14897 if (argv_find(argv, argc, "vrf", &idx)) {
14898 vrf = argv[idx + 1]->arg;
14899 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14900 vrf = NULL;
14901 } else if (argv_find(argv, argc, "view", &idx))
14902 /* [<view> VIEWVRFNAME] */
14903 vrf = argv[idx + 1]->arg;
d62a17ae 14904 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14905 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14906 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14907 }
5bf15956 14908
d62a17ae 14909 /* get subgroup id, if provided */
14910 idx = argc - 1;
14911 if (argv[idx]->type == VARIABLE_TKN)
14912 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 14913
d62a17ae 14914 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
14915}
14916
f186de26 14917DEFUN (show_bgp_instance_all_ipv6_updgrps,
14918 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 14919 "show [ip] bgp <view|vrf> all update-groups",
f186de26 14920 SHOW_STR
716b2d8a 14921 IP_STR
f186de26 14922 BGP_STR
14923 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 14924 "Detailed info about dynamic update groups\n")
f186de26 14925{
d62a17ae 14926 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
14927 return CMD_SUCCESS;
f186de26 14928}
14929
43d3f4fc
DS
14930DEFUN (show_bgp_l2vpn_evpn_updgrps,
14931 show_bgp_l2vpn_evpn_updgrps_cmd,
14932 "show [ip] bgp l2vpn evpn update-groups",
14933 SHOW_STR
14934 IP_STR
14935 BGP_STR
14936 "l2vpn address family\n"
14937 "evpn sub-address family\n"
14938 "Detailed info about dynamic update groups\n")
14939{
14940 char *vrf = NULL;
14941 uint64_t subgrp_id = 0;
14942
14943 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
14944 return CMD_SUCCESS;
14945}
14946
5bf15956
DW
14947DEFUN (show_bgp_updgrps_stats,
14948 show_bgp_updgrps_stats_cmd,
716b2d8a 14949 "show [ip] bgp update-groups statistics",
3f9c7369 14950 SHOW_STR
716b2d8a 14951 IP_STR
3f9c7369 14952 BGP_STR
0c7b1b01 14953 "Detailed info about dynamic update groups\n"
3f9c7369
DS
14954 "Statistics\n")
14955{
d62a17ae 14956 struct bgp *bgp;
3f9c7369 14957
d62a17ae 14958 bgp = bgp_get_default();
14959 if (bgp)
14960 update_group_show_stats(bgp, vty);
3f9c7369 14961
d62a17ae 14962 return CMD_SUCCESS;
3f9c7369
DS
14963}
14964
8386ac43 14965DEFUN (show_bgp_instance_updgrps_stats,
14966 show_bgp_instance_updgrps_stats_cmd,
18c57037 14967 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 14968 SHOW_STR
716b2d8a 14969 IP_STR
8386ac43 14970 BGP_STR
14971 BGP_INSTANCE_HELP_STR
0c7b1b01 14972 "Detailed info about dynamic update groups\n"
8386ac43 14973 "Statistics\n")
14974{
d62a17ae 14975 int idx_word = 3;
14976 struct bgp *bgp;
8386ac43 14977
d62a17ae 14978 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
14979 if (bgp)
14980 update_group_show_stats(bgp, vty);
8386ac43 14981
d62a17ae 14982 return CMD_SUCCESS;
8386ac43 14983}
14984
d62a17ae 14985static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
14986 afi_t afi, safi_t safi,
14987 const char *what, uint64_t subgrp_id)
3f9c7369 14988{
d62a17ae 14989 struct bgp *bgp;
8386ac43 14990
d62a17ae 14991 if (name)
14992 bgp = bgp_lookup_by_name(name);
14993 else
14994 bgp = bgp_get_default();
8386ac43 14995
d62a17ae 14996 if (bgp) {
14997 if (!strcmp(what, "advertise-queue"))
14998 update_group_show_adj_queue(bgp, afi, safi, vty,
14999 subgrp_id);
15000 else if (!strcmp(what, "advertised-routes"))
15001 update_group_show_advertised(bgp, afi, safi, vty,
15002 subgrp_id);
15003 else if (!strcmp(what, "packet-queue"))
15004 update_group_show_packet_queue(bgp, afi, safi, vty,
15005 subgrp_id);
15006 }
3f9c7369
DS
15007}
15008
dc64bdec
QY
15009DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15010 show_ip_bgp_instance_updgrps_adj_s_cmd,
15011 "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",
15012 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15013 BGP_SAFI_HELP_STR
15014 "Detailed info about dynamic update groups\n"
15015 "Specific subgroup to display info for\n"
15016 "Advertisement queue\n"
15017 "Announced routes\n"
15018 "Packet queue\n")
3f9c7369 15019{
dc64bdec
QY
15020 uint64_t subgrp_id = 0;
15021 afi_t afiz;
15022 safi_t safiz;
15023 if (sgid)
15024 subgrp_id = strtoull(sgid, NULL, 10);
15025
15026 if (!ip && !afi)
15027 afiz = AFI_IP6;
15028 if (!ip && afi)
15029 afiz = bgp_vty_afi_from_str(afi);
15030 if (ip && !afi)
15031 afiz = AFI_IP;
15032 if (ip && afi) {
15033 afiz = bgp_vty_afi_from_str(afi);
15034 if (afiz != AFI_IP)
15035 vty_out(vty,
15036 "%% Cannot specify both 'ip' and 'ipv6'\n");
15037 return CMD_WARNING;
15038 }
d62a17ae 15039
dc64bdec 15040 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15041
dc64bdec 15042 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15043 return CMD_SUCCESS;
15044}
15045
6f4eacf3
DA
15046static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15047 json_object *json)
d62a17ae 15048{
15049 struct listnode *node, *nnode;
15050 struct prefix *range;
15051 struct peer *conf;
15052 struct peer *peer;
d62a17ae 15053 afi_t afi;
15054 safi_t safi;
15055 const char *peer_status;
d62a17ae 15056 int lr_count;
15057 int dynamic;
6f4eacf3
DA
15058 bool af_cfgd;
15059 json_object *json_peer_group = NULL;
15060 json_object *json_peer_group_afc = NULL;
15061 json_object *json_peer_group_members = NULL;
15062 json_object *json_peer_group_dynamic = NULL;
15063 json_object *json_peer_group_dynamic_af = NULL;
15064 json_object *json_peer_group_ranges = NULL;
d62a17ae 15065
15066 conf = group->conf;
15067
6f4eacf3
DA
15068 if (json) {
15069 json_peer_group = json_object_new_object();
15070 json_peer_group_afc = json_object_new_array();
15071 }
15072
d62a17ae 15073 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3
DA
15074 if (json)
15075 json_object_int_add(json_peer_group, "remoteAs",
15076 conf->as);
15077 else
15078 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15079 group->name, conf->as);
d62a17ae 15080 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3
DA
15081 if (json)
15082 json_object_int_add(json_peer_group, "remoteAs",
15083 group->bgp->as);
15084 else
15085 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15086 group->name, group->bgp->as);
d62a17ae 15087 } else {
6f4eacf3
DA
15088 if (!json)
15089 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 15090 }
f14e6fdb 15091
6f4eacf3
DA
15092 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15093 if (json)
15094 json_object_string_add(json_peer_group, "type",
15095 "internal");
15096 else
15097 vty_out(vty, " Peer-group type is internal\n");
15098 } else {
15099 if (json)
15100 json_object_string_add(json_peer_group, "type",
15101 "external");
15102 else
15103 vty_out(vty, " Peer-group type is external\n");
15104 }
d62a17ae 15105
15106 /* Display AFs configured. */
6f4eacf3
DA
15107 if (!json)
15108 vty_out(vty, " Configured address-families:");
15109
05c7a1cc
QY
15110 FOREACH_AFI_SAFI (afi, safi) {
15111 if (conf->afc[afi][safi]) {
6f4eacf3
DA
15112 af_cfgd = true;
15113 if (json)
15114 json_object_array_add(
15115 json_peer_group_afc,
15116 json_object_new_string(get_afi_safi_str(
15117 afi, safi, false)));
15118 else
15119 vty_out(vty, " %s;",
15120 get_afi_safi_str(afi, safi, false));
d62a17ae 15121 }
05c7a1cc 15122 }
6f4eacf3
DA
15123
15124 if (json) {
15125 json_object_object_add(json_peer_group,
15126 "addressFamiliesConfigured",
15127 json_peer_group_afc);
15128 } else {
15129 if (!af_cfgd)
15130 vty_out(vty, " none\n");
15131 else
15132 vty_out(vty, "\n");
15133 }
d62a17ae 15134
15135 /* Display listen ranges (for dynamic neighbors), if any */
15136 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 15137 lr_count = listcount(group->listen_range[afi]);
15138 if (lr_count) {
6f4eacf3
DA
15139 if (json) {
15140 if (!json_peer_group_dynamic)
15141 json_peer_group_dynamic =
15142 json_object_new_object();
15143
15144 json_peer_group_dynamic_af =
15145 json_object_new_object();
15146 json_peer_group_ranges =
15147 json_object_new_array();
15148 json_object_int_add(json_peer_group_dynamic_af,
15149 "count", lr_count);
15150 } else {
15151 vty_out(vty, " %d %s listen range(s)\n",
15152 lr_count, afi2str(afi));
15153 }
d62a17ae 15154
15155 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
15156 nnode, range)) {
15157 if (json) {
15158 char buf[BUFSIZ];
15159
15160 snprintfrr(buf, sizeof(buf), "%pFX",
15161 range);
15162
15163 json_object_array_add(
15164 json_peer_group_ranges,
15165 json_object_new_string(buf));
15166 } else {
15167 vty_out(vty, " %pFX\n", range);
15168 }
15169 }
15170
15171 if (json) {
15172 json_object_object_add(
15173 json_peer_group_dynamic_af, "ranges",
15174 json_peer_group_ranges);
15175
15176 json_object_object_add(
15177 json_peer_group_dynamic, afi2str(afi),
15178 json_peer_group_dynamic_af);
15179 }
d62a17ae 15180 }
15181 }
f14e6fdb 15182
6f4eacf3
DA
15183 if (json_peer_group_dynamic)
15184 json_object_object_add(json_peer_group, "dynamicRanges",
15185 json_peer_group_dynamic);
15186
d62a17ae 15187 /* Display group members and their status */
15188 if (listcount(group->peer)) {
6f4eacf3
DA
15189 if (json)
15190 json_peer_group_members = json_object_new_object();
15191 else
15192 vty_out(vty, " Peer-group members:\n");
d62a17ae 15193 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15194 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15195 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15196 peer_status = "Idle (Admin)";
15197 else if (CHECK_FLAG(peer->sflags,
15198 PEER_STATUS_PREFIX_OVERFLOW))
15199 peer_status = "Idle (PfxCt)";
15200 else
15201 peer_status = lookup_msg(bgp_status_msg,
15202 peer->status, NULL);
15203
15204 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
15205
15206 if (json) {
15207 json_object *json_peer_group_member =
15208 json_object_new_object();
15209
15210 json_object_string_add(json_peer_group_member,
15211 "status", peer_status);
15212
15213 if (dynamic)
15214 json_object_boolean_true_add(
15215 json_peer_group_member,
15216 "dynamic");
15217
15218 json_object_object_add(json_peer_group_members,
15219 peer->host,
15220 json_peer_group_member);
15221 } else {
15222 vty_out(vty, " %s %s %s \n", peer->host,
15223 dynamic ? "(dynamic)" : "",
15224 peer_status);
15225 }
d62a17ae 15226 }
6f4eacf3
DA
15227 if (json)
15228 json_object_object_add(json_peer_group, "members",
15229 json_peer_group_members);
d62a17ae 15230 }
f14e6fdb 15231
6f4eacf3
DA
15232 if (json)
15233 json_object_object_add(json, group->name, json_peer_group);
15234
d62a17ae 15235 return CMD_SUCCESS;
15236}
15237
ff9959b0 15238static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 15239 const char *group_name, bool uj)
d62a17ae 15240{
ff9959b0 15241 struct bgp *bgp;
d62a17ae 15242 struct listnode *node, *nnode;
15243 struct peer_group *group;
ff9959b0 15244 bool found = false;
6f4eacf3
DA
15245 json_object *json = NULL;
15246
15247 if (uj)
15248 json = json_object_new_object();
ff9959b0
QY
15249
15250 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15251
15252 if (!bgp) {
c48349e3 15253 if (uj)
75eeda93 15254 vty_json(vty, json);
c48349e3 15255 else
6f4eacf3 15256 vty_out(vty, "%% BGP instance not found\n");
6f4eacf3 15257
ff9959b0
QY
15258 return CMD_WARNING;
15259 }
d62a17ae 15260
15261 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15262 if (group_name) {
15263 if (strmatch(group->name, group_name)) {
6f4eacf3 15264 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
15265 found = true;
15266 break;
d62a17ae 15267 }
ff9959b0 15268 } else {
6f4eacf3 15269 bgp_show_one_peer_group(vty, group, json);
d62a17ae 15270 }
f14e6fdb 15271 }
f14e6fdb 15272
6f4eacf3 15273 if (group_name && !found && !uj)
d62a17ae 15274 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15275
c48349e3 15276 if (uj)
75eeda93 15277 vty_json(vty, json);
6f4eacf3 15278
d62a17ae 15279 return CMD_SUCCESS;
f14e6fdb
DS
15280}
15281
6f4eacf3
DA
15282DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15283 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15284 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15285 "Detailed information on BGP peer groups\n"
15286 "Peer group name\n" JSON_STR)
f14e6fdb 15287{
d62a17ae 15288 char *vrf, *pg;
d62a17ae 15289 int idx = 0;
6f4eacf3 15290 bool uj = use_json(argc, argv);
f14e6fdb 15291
a4d82a8a
PZ
15292 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15293 : NULL;
d62a17ae 15294 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15295
6f4eacf3 15296 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 15297}
3f9c7369 15298
d6e3c605 15299
718e3744 15300/* Redistribute VTY commands. */
15301
585f1adc
IR
15302DEFUN (bgp_redistribute_ipv4,
15303 bgp_redistribute_ipv4_cmd,
15304 "redistribute " FRR_IP_REDIST_STR_BGPD,
15305 "Redistribute information from another routing protocol\n"
15306 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 15307{
585f1adc 15308 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15309 int idx_protocol = 1;
585f1adc 15310 int type;
37a87b8f 15311
585f1adc
IR
15312 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15313 if (type < 0) {
15314 vty_out(vty, "%% Invalid route type\n");
15315 return CMD_WARNING_CONFIG_FAILED;
15316 }
7f323236 15317
585f1adc
IR
15318 bgp_redist_add(bgp, AFI_IP, type, 0);
15319 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 15320}
15321
d62a17ae 15322ALIAS_HIDDEN(
15323 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15324 "redistribute " FRR_IP_REDIST_STR_BGPD,
15325 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 15326
585f1adc
IR
15327DEFUN (bgp_redistribute_ipv4_rmap,
15328 bgp_redistribute_ipv4_rmap_cmd,
15329 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15330 "Redistribute information from another routing protocol\n"
15331 FRR_IP_REDIST_HELP_STR_BGPD
15332 "Route map reference\n"
15333 "Pointer to route-map entries\n")
718e3744 15334{
585f1adc 15335 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15336 int idx_protocol = 1;
15337 int idx_word = 3;
585f1adc
IR
15338 int type;
15339 struct bgp_redist *red;
15340 bool changed;
15341 struct route_map *route_map = route_map_lookup_warn_noexist(
15342 vty, argv[idx_word]->arg);
15343
15344 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15345 if (type < 0) {
15346 vty_out(vty, "%% Invalid route type\n");
15347 return CMD_WARNING_CONFIG_FAILED;
15348 }
37a87b8f 15349
585f1adc
IR
15350 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15351 changed =
15352 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15353 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 15354}
15355
d62a17ae 15356ALIAS_HIDDEN(
15357 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15358 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15359 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15360 "Route map reference\n"
15361 "Pointer to route-map entries\n")
596c17ba 15362
585f1adc
IR
15363DEFUN (bgp_redistribute_ipv4_metric,
15364 bgp_redistribute_ipv4_metric_cmd,
15365 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15366 "Redistribute information from another routing protocol\n"
15367 FRR_IP_REDIST_HELP_STR_BGPD
15368 "Metric for redistributed routes\n"
15369 "Default metric\n")
718e3744 15370{
585f1adc 15371 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15372 int idx_protocol = 1;
15373 int idx_number = 3;
585f1adc
IR
15374 int type;
15375 uint32_t metric;
15376 struct bgp_redist *red;
15377 bool changed;
15378
15379 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15380 if (type < 0) {
15381 vty_out(vty, "%% Invalid route type\n");
15382 return CMD_WARNING_CONFIG_FAILED;
15383 }
15384 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15385
585f1adc
IR
15386 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15387 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15388 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15389}
15390
15391ALIAS_HIDDEN(
15392 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15393 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15394 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15395 "Metric for redistributed routes\n"
15396 "Default metric\n")
596c17ba 15397
585f1adc
IR
15398DEFUN (bgp_redistribute_ipv4_rmap_metric,
15399 bgp_redistribute_ipv4_rmap_metric_cmd,
15400 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15401 "Redistribute information from another routing protocol\n"
15402 FRR_IP_REDIST_HELP_STR_BGPD
15403 "Route map reference\n"
15404 "Pointer to route-map entries\n"
15405 "Metric for redistributed routes\n"
15406 "Default metric\n")
718e3744 15407{
585f1adc 15408 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15409 int idx_protocol = 1;
15410 int idx_word = 3;
15411 int idx_number = 5;
585f1adc
IR
15412 int type;
15413 uint32_t metric;
15414 struct bgp_redist *red;
15415 bool changed;
15416 struct route_map *route_map =
15417 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15418
15419 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15420 if (type < 0) {
15421 vty_out(vty, "%% Invalid route type\n");
15422 return CMD_WARNING_CONFIG_FAILED;
15423 }
15424 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15425
585f1adc
IR
15426 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15427 changed =
15428 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15429 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15430 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15431}
15432
15433ALIAS_HIDDEN(
15434 bgp_redistribute_ipv4_rmap_metric,
15435 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15436 "redistribute " FRR_IP_REDIST_STR_BGPD
15437 " route-map WORD metric (0-4294967295)",
15438 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15439 "Route map reference\n"
15440 "Pointer to route-map entries\n"
15441 "Metric for redistributed routes\n"
15442 "Default metric\n")
596c17ba 15443
585f1adc
IR
15444DEFUN (bgp_redistribute_ipv4_metric_rmap,
15445 bgp_redistribute_ipv4_metric_rmap_cmd,
15446 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15447 "Redistribute information from another routing protocol\n"
15448 FRR_IP_REDIST_HELP_STR_BGPD
15449 "Metric for redistributed routes\n"
15450 "Default metric\n"
15451 "Route map reference\n"
15452 "Pointer to route-map entries\n")
718e3744 15453{
585f1adc 15454 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15455 int idx_protocol = 1;
37a87b8f 15456 int idx_number = 3;
585f1adc
IR
15457 int idx_word = 5;
15458 int type;
15459 uint32_t metric;
15460 struct bgp_redist *red;
15461 bool changed;
15462 struct route_map *route_map =
15463 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15464
15465 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15466 if (type < 0) {
15467 vty_out(vty, "%% Invalid route type\n");
15468 return CMD_WARNING_CONFIG_FAILED;
15469 }
15470 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15471
585f1adc
IR
15472 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15473 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15474 changed |=
15475 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15476 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15477}
15478
15479ALIAS_HIDDEN(
15480 bgp_redistribute_ipv4_metric_rmap,
15481 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15482 "redistribute " FRR_IP_REDIST_STR_BGPD
15483 " metric (0-4294967295) route-map WORD",
15484 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15485 "Metric for redistributed routes\n"
15486 "Default metric\n"
15487 "Route map reference\n"
15488 "Pointer to route-map entries\n")
596c17ba 15489
585f1adc
IR
15490DEFUN (bgp_redistribute_ipv4_ospf,
15491 bgp_redistribute_ipv4_ospf_cmd,
15492 "redistribute <ospf|table> (1-65535)",
15493 "Redistribute information from another routing protocol\n"
15494 "Open Shortest Path First (OSPFv2)\n"
15495 "Non-main Kernel Routing Table\n"
15496 "Instance ID/Table ID\n")
7c8ff89e 15497{
585f1adc
IR
15498 VTY_DECLVAR_CONTEXT(bgp, bgp);
15499 int idx_ospf_table = 1;
d62a17ae 15500 int idx_number = 2;
585f1adc
IR
15501 unsigned short instance;
15502 unsigned short protocol;
7c8ff89e 15503
585f1adc 15504 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 15505
585f1adc
IR
15506 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15507 protocol = ZEBRA_ROUTE_OSPF;
15508 else
15509 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 15510
585f1adc
IR
15511 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15512 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
15513}
15514
d62a17ae 15515ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15516 "redistribute <ospf|table> (1-65535)",
15517 "Redistribute information from another routing protocol\n"
15518 "Open Shortest Path First (OSPFv2)\n"
15519 "Non-main Kernel Routing Table\n"
15520 "Instance ID/Table ID\n")
596c17ba 15521
585f1adc
IR
15522DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15523 bgp_redistribute_ipv4_ospf_rmap_cmd,
15524 "redistribute <ospf|table> (1-65535) route-map WORD",
15525 "Redistribute information from another routing protocol\n"
15526 "Open Shortest Path First (OSPFv2)\n"
15527 "Non-main Kernel Routing Table\n"
15528 "Instance ID/Table ID\n"
15529 "Route map reference\n"
15530 "Pointer to route-map entries\n")
7c8ff89e 15531{
585f1adc
IR
15532 VTY_DECLVAR_CONTEXT(bgp, bgp);
15533 int idx_ospf_table = 1;
d62a17ae 15534 int idx_number = 2;
15535 int idx_word = 4;
585f1adc
IR
15536 struct bgp_redist *red;
15537 unsigned short instance;
15538 int protocol;
15539 bool changed;
15540 struct route_map *route_map =
15541 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15542
15543 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15544 protocol = ZEBRA_ROUTE_OSPF;
15545 else
15546 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15547
585f1adc
IR
15548 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15549 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15550 changed =
15551 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15552 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15553}
15554
15555ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15556 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15557 "redistribute <ospf|table> (1-65535) route-map WORD",
15558 "Redistribute information from another routing protocol\n"
15559 "Open Shortest Path First (OSPFv2)\n"
15560 "Non-main Kernel Routing Table\n"
15561 "Instance ID/Table ID\n"
15562 "Route map reference\n"
15563 "Pointer to route-map entries\n")
596c17ba 15564
585f1adc
IR
15565DEFUN (bgp_redistribute_ipv4_ospf_metric,
15566 bgp_redistribute_ipv4_ospf_metric_cmd,
15567 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15568 "Redistribute information from another routing protocol\n"
15569 "Open Shortest Path First (OSPFv2)\n"
15570 "Non-main Kernel Routing Table\n"
15571 "Instance ID/Table ID\n"
15572 "Metric for redistributed routes\n"
15573 "Default metric\n")
7c8ff89e 15574{
585f1adc
IR
15575 VTY_DECLVAR_CONTEXT(bgp, bgp);
15576 int idx_ospf_table = 1;
d62a17ae 15577 int idx_number = 2;
15578 int idx_number_2 = 4;
585f1adc
IR
15579 uint32_t metric;
15580 struct bgp_redist *red;
15581 unsigned short instance;
15582 int protocol;
15583 bool changed;
15584
15585 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15586 protocol = ZEBRA_ROUTE_OSPF;
15587 else
15588 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15589
585f1adc
IR
15590 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15591 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15592
585f1adc
IR
15593 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15594 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15595 metric);
15596 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15597}
15598
15599ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15600 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15601 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15602 "Redistribute information from another routing protocol\n"
15603 "Open Shortest Path First (OSPFv2)\n"
15604 "Non-main Kernel Routing Table\n"
15605 "Instance ID/Table ID\n"
15606 "Metric for redistributed routes\n"
15607 "Default metric\n")
596c17ba 15608
585f1adc
IR
15609DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
15610 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15611 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15612 "Redistribute information from another routing protocol\n"
15613 "Open Shortest Path First (OSPFv2)\n"
15614 "Non-main Kernel Routing Table\n"
15615 "Instance ID/Table ID\n"
15616 "Route map reference\n"
15617 "Pointer to route-map entries\n"
15618 "Metric for redistributed routes\n"
15619 "Default metric\n")
7c8ff89e 15620{
585f1adc
IR
15621 VTY_DECLVAR_CONTEXT(bgp, bgp);
15622 int idx_ospf_table = 1;
d62a17ae 15623 int idx_number = 2;
15624 int idx_word = 4;
15625 int idx_number_2 = 6;
585f1adc
IR
15626 uint32_t metric;
15627 struct bgp_redist *red;
15628 unsigned short instance;
15629 int protocol;
15630 bool changed;
15631 struct route_map *route_map =
15632 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15633
15634 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15635 protocol = ZEBRA_ROUTE_OSPF;
15636 else
15637 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15638
585f1adc
IR
15639 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15640 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15641
585f1adc
IR
15642 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15643 changed =
15644 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15645 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15646 metric);
15647 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15648}
15649
15650ALIAS_HIDDEN(
15651 bgp_redistribute_ipv4_ospf_rmap_metric,
15652 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15653 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15654 "Redistribute information from another routing protocol\n"
15655 "Open Shortest Path First (OSPFv2)\n"
15656 "Non-main Kernel Routing Table\n"
15657 "Instance ID/Table ID\n"
15658 "Route map reference\n"
15659 "Pointer to route-map entries\n"
15660 "Metric for redistributed routes\n"
15661 "Default metric\n")
596c17ba 15662
585f1adc
IR
15663DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
15664 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15665 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15666 "Redistribute information from another routing protocol\n"
15667 "Open Shortest Path First (OSPFv2)\n"
15668 "Non-main Kernel Routing Table\n"
15669 "Instance ID/Table ID\n"
15670 "Metric for redistributed routes\n"
15671 "Default metric\n"
15672 "Route map reference\n"
15673 "Pointer to route-map entries\n")
7c8ff89e 15674{
585f1adc
IR
15675 VTY_DECLVAR_CONTEXT(bgp, bgp);
15676 int idx_ospf_table = 1;
d62a17ae 15677 int idx_number = 2;
15678 int idx_number_2 = 4;
15679 int idx_word = 6;
585f1adc
IR
15680 uint32_t metric;
15681 struct bgp_redist *red;
15682 unsigned short instance;
15683 int protocol;
15684 bool changed;
15685 struct route_map *route_map =
15686 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15687
15688 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15689 protocol = ZEBRA_ROUTE_OSPF;
15690 else
15691 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15692
585f1adc
IR
15693 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15694 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15695
585f1adc
IR
15696 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15697 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15698 metric);
15699 changed |=
15700 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15701 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15702}
15703
15704ALIAS_HIDDEN(
15705 bgp_redistribute_ipv4_ospf_metric_rmap,
15706 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15707 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15708 "Redistribute information from another routing protocol\n"
15709 "Open Shortest Path First (OSPFv2)\n"
15710 "Non-main Kernel Routing Table\n"
15711 "Instance ID/Table ID\n"
15712 "Metric for redistributed routes\n"
15713 "Default metric\n"
15714 "Route map reference\n"
15715 "Pointer to route-map entries\n")
596c17ba 15716
585f1adc
IR
15717DEFUN (no_bgp_redistribute_ipv4_ospf,
15718 no_bgp_redistribute_ipv4_ospf_cmd,
15719 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15720 NO_STR
15721 "Redistribute information from another routing protocol\n"
15722 "Open Shortest Path First (OSPFv2)\n"
15723 "Non-main Kernel Routing Table\n"
15724 "Instance ID/Table ID\n"
15725 "Metric for redistributed routes\n"
15726 "Default metric\n"
15727 "Route map reference\n"
15728 "Pointer to route-map entries\n")
7c8ff89e 15729{
585f1adc
IR
15730 VTY_DECLVAR_CONTEXT(bgp, bgp);
15731 int idx_ospf_table = 2;
d62a17ae 15732 int idx_number = 3;
585f1adc
IR
15733 unsigned short instance;
15734 int protocol;
37a87b8f 15735
585f1adc
IR
15736 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15737 protocol = ZEBRA_ROUTE_OSPF;
15738 else
15739 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15740
585f1adc
IR
15741 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15742 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
d62a17ae 15743}
15744
15745ALIAS_HIDDEN(
15746 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 15747 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15748 NO_STR
15749 "Redistribute information from another routing protocol\n"
15750 "Open Shortest Path First (OSPFv2)\n"
15751 "Non-main Kernel Routing Table\n"
15752 "Instance ID/Table ID\n"
15753 "Metric for redistributed routes\n"
15754 "Default metric\n"
15755 "Route map reference\n"
15756 "Pointer to route-map entries\n")
596c17ba 15757
585f1adc
IR
15758DEFUN (no_bgp_redistribute_ipv4,
15759 no_bgp_redistribute_ipv4_cmd,
15760 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15761 NO_STR
15762 "Redistribute information from another routing protocol\n"
15763 FRR_IP_REDIST_HELP_STR_BGPD
15764 "Metric for redistributed routes\n"
15765 "Default metric\n"
15766 "Route map reference\n"
15767 "Pointer to route-map entries\n")
718e3744 15768{
585f1adc 15769 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15770 int idx_protocol = 2;
585f1adc 15771 int type;
d62a17ae 15772
585f1adc
IR
15773 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15774 if (type < 0) {
15775 vty_out(vty, "%% Invalid route type\n");
15776 return CMD_WARNING_CONFIG_FAILED;
15777 }
15778 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
d62a17ae 15779}
15780
15781ALIAS_HIDDEN(
15782 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15783 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 15784 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15785 NO_STR
15786 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15787 "Metric for redistributed routes\n"
15788 "Default metric\n"
15789 "Route map reference\n"
15790 "Pointer to route-map entries\n")
596c17ba 15791
585f1adc
IR
15792DEFUN (bgp_redistribute_ipv6,
15793 bgp_redistribute_ipv6_cmd,
15794 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15795 "Redistribute information from another routing protocol\n"
15796 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 15797{
585f1adc 15798 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15799 int idx_protocol = 1;
585f1adc 15800 int type;
718e3744 15801
585f1adc
IR
15802 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15803 if (type < 0) {
15804 vty_out(vty, "%% Invalid route type\n");
15805 return CMD_WARNING_CONFIG_FAILED;
15806 }
718e3744 15807
585f1adc
IR
15808 bgp_redist_add(bgp, AFI_IP6, type, 0);
15809 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 15810}
15811
585f1adc
IR
15812DEFUN (bgp_redistribute_ipv6_rmap,
15813 bgp_redistribute_ipv6_rmap_cmd,
15814 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
15815 "Redistribute information from another routing protocol\n"
15816 FRR_IP6_REDIST_HELP_STR_BGPD
15817 "Route map reference\n"
15818 "Pointer to route-map entries\n")
718e3744 15819{
585f1adc 15820 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15821 int idx_protocol = 1;
15822 int idx_word = 3;
585f1adc
IR
15823 int type;
15824 struct bgp_redist *red;
15825 bool changed;
15826 struct route_map *route_map =
15827 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15828
15829 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15830 if (type < 0) {
15831 vty_out(vty, "%% Invalid route type\n");
15832 return CMD_WARNING_CONFIG_FAILED;
15833 }
37a87b8f 15834
585f1adc
IR
15835 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15836 changed =
15837 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15838 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15839}
15840
585f1adc 15841DEFUN (bgp_redistribute_ipv6_metric,
718e3744 15842 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 15843 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 15844 "Redistribute information from another routing protocol\n"
ab0181ee 15845 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 15846 "Metric for redistributed routes\n"
15847 "Default metric\n")
15848{
585f1adc 15849 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15850 int idx_protocol = 1;
15851 int idx_number = 3;
585f1adc
IR
15852 int type;
15853 uint32_t metric;
15854 struct bgp_redist *red;
15855 bool changed;
15856
15857 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15858 if (type < 0) {
15859 vty_out(vty, "%% Invalid route type\n");
15860 return CMD_WARNING_CONFIG_FAILED;
15861 }
15862 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15863
585f1adc
IR
15864 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15865 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
15866 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15867}
15868
585f1adc
IR
15869DEFUN (bgp_redistribute_ipv6_rmap_metric,
15870 bgp_redistribute_ipv6_rmap_metric_cmd,
15871 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15872 "Redistribute information from another routing protocol\n"
15873 FRR_IP6_REDIST_HELP_STR_BGPD
15874 "Route map reference\n"
15875 "Pointer to route-map entries\n"
15876 "Metric for redistributed routes\n"
15877 "Default metric\n")
718e3744 15878{
585f1adc 15879 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15880 int idx_protocol = 1;
15881 int idx_word = 3;
15882 int idx_number = 5;
585f1adc
IR
15883 int type;
15884 uint32_t metric;
15885 struct bgp_redist *red;
15886 bool changed;
15887 struct route_map *route_map =
15888 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15889
15890 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15891 if (type < 0) {
15892 vty_out(vty, "%% Invalid route type\n");
15893 return CMD_WARNING_CONFIG_FAILED;
15894 }
15895 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15896
585f1adc
IR
15897 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15898 changed =
15899 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15900 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
15901 metric);
15902 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15903}
15904
585f1adc
IR
15905DEFUN (bgp_redistribute_ipv6_metric_rmap,
15906 bgp_redistribute_ipv6_metric_rmap_cmd,
15907 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15908 "Redistribute information from another routing protocol\n"
15909 FRR_IP6_REDIST_HELP_STR_BGPD
15910 "Metric for redistributed routes\n"
15911 "Default metric\n"
15912 "Route map reference\n"
15913 "Pointer to route-map entries\n")
718e3744 15914{
585f1adc 15915 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15916 int idx_protocol = 1;
37a87b8f 15917 int idx_number = 3;
585f1adc
IR
15918 int idx_word = 5;
15919 int type;
15920 uint32_t metric;
15921 struct bgp_redist *red;
15922 bool changed;
15923 struct route_map *route_map =
15924 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15925
15926 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15927 if (type < 0) {
15928 vty_out(vty, "%% Invalid route type\n");
15929 return CMD_WARNING_CONFIG_FAILED;
15930 }
15931 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15932
585f1adc
IR
15933 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15934 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
15935 metric);
15936 changed |=
15937 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15938 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15939}
15940
585f1adc
IR
15941DEFUN (no_bgp_redistribute_ipv6,
15942 no_bgp_redistribute_ipv6_cmd,
15943 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15944 NO_STR
15945 "Redistribute information from another routing protocol\n"
15946 FRR_IP6_REDIST_HELP_STR_BGPD
15947 "Metric for redistributed routes\n"
15948 "Default metric\n"
15949 "Route map reference\n"
15950 "Pointer to route-map entries\n")
718e3744 15951{
585f1adc 15952 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15953 int idx_protocol = 2;
585f1adc 15954 int type;
37a87b8f 15955
585f1adc
IR
15956 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15957 if (type < 0) {
15958 vty_out(vty, "%% Invalid route type\n");
15959 return CMD_WARNING_CONFIG_FAILED;
15960 }
718e3744 15961
585f1adc 15962 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
d62a17ae 15963}
15964
4ab46701
AR
15965/* Neighbor update tcp-mss. */
15966static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
15967 const char *tcp_mss_str)
15968{
15969 struct peer *peer;
15970 uint32_t tcp_mss_val = 0;
15971
15972 peer = peer_and_group_lookup_vty(vty, peer_str);
15973 if (!peer)
15974 return CMD_WARNING_CONFIG_FAILED;
15975
15976 if (tcp_mss_str) {
15977 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
15978 peer_tcp_mss_set(peer, tcp_mss_val);
15979 } else {
15980 peer_tcp_mss_unset(peer);
15981 }
15982
15983 return CMD_SUCCESS;
15984}
15985
15986DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
15987 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
15988 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
15989 "TCP max segment size\n"
15990 "TCP MSS value\n")
15991{
15992 int peer_index = 1;
15993 int mss_index = 3;
15994
15995 vty_out(vty,
15996 " Warning: Reset BGP session for tcp-mss value to take effect\n");
15997 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
15998 argv[mss_index]->arg);
15999}
16000
16001DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16002 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16003 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16004 "TCP max segment size\n"
16005 "TCP MSS value\n")
16006{
16007 int peer_index = 2;
16008
16009 vty_out(vty,
16010 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16011 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16012}
16013
dd65f45e
DL
16014static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16015 afi_t afi, safi_t safi)
d62a17ae 16016{
16017 int i;
16018
16019 /* Unicast redistribution only. */
16020 if (safi != SAFI_UNICAST)
2b791107 16021 return;
d62a17ae 16022
16023 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16024 /* Redistribute BGP does not make sense. */
16025 if (i != ZEBRA_ROUTE_BGP) {
16026 struct list *red_list;
16027 struct listnode *node;
16028 struct bgp_redist *red;
16029
16030 red_list = bgp->redist[afi][i];
16031 if (!red_list)
16032 continue;
16033
16034 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16035 /* "redistribute" configuration. */
16036 vty_out(vty, " redistribute %s",
16037 zebra_route_string(i));
16038 if (red->instance)
16039 vty_out(vty, " %d", red->instance);
16040 if (red->redist_metric_flag)
16041 vty_out(vty, " metric %u",
16042 red->redist_metric);
16043 if (red->rmap.name)
16044 vty_out(vty, " route-map %s",
16045 red->rmap.name);
16046 vty_out(vty, "\n");
16047 }
16048 }
16049 }
718e3744 16050}
6b0655a2 16051
dd65f45e
DL
16052/* peer-group helpers for config-write */
16053
16054static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16055{
16056 if (!peer_group_active(peer)) {
16057 if (CHECK_FLAG(peer->flags_invert, flag))
16058 return !CHECK_FLAG(peer->flags, flag);
16059 else
16060 return !!CHECK_FLAG(peer->flags, flag);
16061 }
16062
16063 return !!CHECK_FLAG(peer->flags_override, flag);
16064}
16065
16066static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16067 uint32_t flag)
16068{
16069 if (!peer_group_active(peer)) {
16070 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16071 return !peer_af_flag_check(peer, afi, safi, flag);
16072 else
16073 return !!peer_af_flag_check(peer, afi, safi, flag);
16074 }
16075
16076 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16077}
16078
16079static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16080 uint8_t type, int direct)
16081{
16082 struct bgp_filter *filter;
16083
16084 if (peer_group_active(peer))
16085 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16086 type);
16087
16088 filter = &peer->filter[afi][safi];
16089 switch (type) {
16090 case PEER_FT_DISTRIBUTE_LIST:
16091 return !!(filter->dlist[direct].name);
16092 case PEER_FT_FILTER_LIST:
16093 return !!(filter->aslist[direct].name);
16094 case PEER_FT_PREFIX_LIST:
16095 return !!(filter->plist[direct].name);
16096 case PEER_FT_ROUTE_MAP:
16097 return !!(filter->map[direct].name);
16098 case PEER_FT_UNSUPPRESS_MAP:
16099 return !!(filter->usmap.name);
7f7940e6
MK
16100 case PEER_FT_ADVERTISE_MAP:
16101 return !!(filter->advmap.aname
16102 && ((filter->advmap.condition == direct)
16103 && filter->advmap.cname));
dd65f45e
DL
16104 default:
16105 return false;
16106 }
16107}
16108
16109/* Return true if the addpath type is set for peer and different from
16110 * peer-group.
16111 */
3dc339cd
DA
16112static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16113 safi_t safi)
dd65f45e
DL
16114{
16115 enum bgp_addpath_strat type, g_type;
16116
16117 type = peer->addpath_type[afi][safi];
16118
16119 if (type != BGP_ADDPATH_NONE) {
16120 if (peer_group_active(peer)) {
16121 g_type = peer->group->conf->addpath_type[afi][safi];
16122
16123 if (type != g_type)
3dc339cd 16124 return true;
dd65f45e 16125 else
3dc339cd 16126 return false;
dd65f45e
DL
16127 }
16128
3dc339cd 16129 return true;
dd65f45e
DL
16130 }
16131
3dc339cd 16132 return false;
dd65f45e
DL
16133}
16134
b9c7bc5a 16135/* This is part of the address-family block (unicast only) */
dd65f45e 16136static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16137 afi_t afi)
16138{
b9c7bc5a 16139 int indent = 2;
53970de3 16140 uint32_t tovpn_sid_index = 0;
ddb5b488 16141
8a066a70 16142 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16143 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16144 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16145 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16146 bgp->vpn_policy[afi]
bb4f6190 16147 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16148 else
16149 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16150 bgp->vpn_policy[afi]
16151 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16152 }
12a844a5
DS
16153 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16154 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16155 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16156 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16157 return;
16158
e70e9f8e
PZ
16159 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16160 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16161
16162 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16163
16164 } else {
16165 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16166 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16167 bgp->vpn_policy[afi].tovpn_label);
16168 }
ddb5b488 16169 }
53970de3
RS
16170
16171 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16172 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16173 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16174 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16175 } else if (tovpn_sid_index != 0) {
16176 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16177 tovpn_sid_index);
16178 }
16179
ddb5b488
PZ
16180 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16181 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16182 char buf[RD_ADDRSTRLEN];
b9c7bc5a 16183 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
16184 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16185 sizeof(buf)));
16186 }
16187 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16188 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16189
16190 char buf[PREFIX_STRLEN];
16191 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16192 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16193 sizeof(buf))) {
16194
b9c7bc5a
PZ
16195 vty_out(vty, "%*snexthop vpn export %s\n",
16196 indent, "", buf);
ddb5b488
PZ
16197 }
16198 }
16199 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16200 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16201 && ecommunity_cmp(
16202 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16203 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16204
16205 char *b = ecommunity_ecom2str(
16206 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16207 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16208 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16209 XFREE(MTYPE_ECOMMUNITY_STR, b);
16210 } else {
16211 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16212 char *b = ecommunity_ecom2str(
16213 bgp->vpn_policy[afi]
16214 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16215 ECOMMUNITY_FORMAT_ROUTE_MAP,
16216 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16217 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16218 XFREE(MTYPE_ECOMMUNITY_STR, b);
16219 }
16220 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16221 char *b = ecommunity_ecom2str(
16222 bgp->vpn_policy[afi]
16223 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16224 ECOMMUNITY_FORMAT_ROUTE_MAP,
16225 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16226 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16227 XFREE(MTYPE_ECOMMUNITY_STR, b);
16228 }
16229 }
bb4f6190
DS
16230
16231 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16232 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16233 bgp->vpn_policy[afi]
16234 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16235
301ad80a
PG
16236 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16237 char *b = ecommunity_ecom2str(
16238 bgp->vpn_policy[afi]
16239 .import_redirect_rtlist,
16240 ECOMMUNITY_FORMAT_ROUTE_MAP,
16241 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16242
9a659715
PG
16243 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16244 != ECOMMUNITY_SIZE)
c6423c31 16245 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16246 indent, "", b);
16247 else
16248 vty_out(vty, "%*srt redirect import %s\n",
16249 indent, "", b);
301ad80a
PG
16250 XFREE(MTYPE_ECOMMUNITY_STR, b);
16251 }
ddb5b488
PZ
16252}
16253
dd65f45e
DL
16254static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16255 afi_t afi, safi_t safi)
16256{
16257 struct bgp_filter *filter;
16258 char *addr;
16259
16260 addr = peer->host;
16261 filter = &peer->filter[afi][safi];
16262
16263 /* distribute-list. */
16264 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16265 FILTER_IN))
16266 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16267 filter->dlist[FILTER_IN].name);
16268
16269 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16270 FILTER_OUT))
16271 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16272 filter->dlist[FILTER_OUT].name);
16273
16274 /* prefix-list. */
16275 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16276 FILTER_IN))
16277 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16278 filter->plist[FILTER_IN].name);
16279
16280 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16281 FILTER_OUT))
16282 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16283 filter->plist[FILTER_OUT].name);
16284
16285 /* route-map. */
16286 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16287 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16288 filter->map[RMAP_IN].name);
16289
16290 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16291 RMAP_OUT))
16292 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16293 filter->map[RMAP_OUT].name);
16294
16295 /* unsuppress-map */
16296 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16297 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16298 filter->usmap.name);
16299
7f7940e6
MK
16300 /* advertise-map : always applied in OUT direction*/
16301 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16302 CONDITION_NON_EXIST))
16303 vty_out(vty,
16304 " neighbor %s advertise-map %s non-exist-map %s\n",
16305 addr, filter->advmap.aname, filter->advmap.cname);
16306
16307 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16308 CONDITION_EXIST))
16309 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16310 addr, filter->advmap.aname, filter->advmap.cname);
16311
dd65f45e
DL
16312 /* filter-list. */
16313 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16314 FILTER_IN))
16315 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16316 filter->aslist[FILTER_IN].name);
16317
16318 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16319 FILTER_OUT))
16320 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16321 filter->aslist[FILTER_OUT].name);
16322}
16323
16324/* BGP peer configuration display function. */
16325static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16326 struct peer *peer)
16327{
16328 struct peer *g_peer = NULL;
16329 char buf[SU_ADDRSTRLEN];
16330 char *addr;
16331 int if_pg_printed = false;
16332 int if_ras_printed = false;
16333
16334 /* Skip dynamic neighbors. */
16335 if (peer_dynamic_neighbor(peer))
16336 return;
16337
16338 if (peer->conf_if)
16339 addr = peer->conf_if;
16340 else
16341 addr = peer->host;
16342
16343 /************************************
16344 ****** Global to the neighbor ******
16345 ************************************/
16346 if (peer->conf_if) {
16347 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16348 vty_out(vty, " neighbor %s interface v6only", addr);
16349 else
16350 vty_out(vty, " neighbor %s interface", addr);
16351
16352 if (peer_group_active(peer)) {
16353 vty_out(vty, " peer-group %s", peer->group->name);
16354 if_pg_printed = true;
16355 } else if (peer->as_type == AS_SPECIFIED) {
16356 vty_out(vty, " remote-as %u", peer->as);
16357 if_ras_printed = true;
16358 } else if (peer->as_type == AS_INTERNAL) {
16359 vty_out(vty, " remote-as internal");
16360 if_ras_printed = true;
16361 } else if (peer->as_type == AS_EXTERNAL) {
16362 vty_out(vty, " remote-as external");
16363 if_ras_printed = true;
16364 }
16365
16366 vty_out(vty, "\n");
16367 }
16368
16369 /* remote-as and peer-group */
16370 /* peer is a member of a peer-group */
16371 if (peer_group_active(peer)) {
16372 g_peer = peer->group->conf;
16373
16374 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16375 if (peer->as_type == AS_SPECIFIED) {
16376 vty_out(vty, " neighbor %s remote-as %u\n",
16377 addr, peer->as);
16378 } else if (peer->as_type == AS_INTERNAL) {
16379 vty_out(vty,
16380 " neighbor %s remote-as internal\n",
16381 addr);
16382 } else if (peer->as_type == AS_EXTERNAL) {
16383 vty_out(vty,
16384 " neighbor %s remote-as external\n",
16385 addr);
16386 }
16387 }
16388
16389 /* For swpX peers we displayed the peer-group
16390 * via 'neighbor swpX interface peer-group PGNAME' */
16391 if (!if_pg_printed)
16392 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16393 peer->group->name);
16394 }
16395
16396 /* peer is NOT a member of a peer-group */
16397 else {
16398 /* peer is a peer-group, declare the peer-group */
16399 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16400 vty_out(vty, " neighbor %s peer-group\n", addr);
16401 }
16402
16403 if (!if_ras_printed) {
16404 if (peer->as_type == AS_SPECIFIED) {
16405 vty_out(vty, " neighbor %s remote-as %u\n",
16406 addr, peer->as);
16407 } else if (peer->as_type == AS_INTERNAL) {
16408 vty_out(vty,
16409 " neighbor %s remote-as internal\n",
16410 addr);
16411 } else if (peer->as_type == AS_EXTERNAL) {
16412 vty_out(vty,
16413 " neighbor %s remote-as external\n",
16414 addr);
16415 }
16416 }
16417 }
16418
16419 /* local-as */
16420 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16421 vty_out(vty, " neighbor %s local-as %u", addr,
16422 peer->change_local_as);
16423 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16424 vty_out(vty, " no-prepend");
16425 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16426 vty_out(vty, " replace-as");
16427 vty_out(vty, "\n");
16428 }
16429
16430 /* description */
16431 if (peer->desc) {
16432 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16433 }
16434
16435 /* shutdown */
16436 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16437 if (peer->tx_shutdown_message)
16438 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16439 peer->tx_shutdown_message);
16440 else
16441 vty_out(vty, " neighbor %s shutdown\n", addr);
16442 }
16443
8336c896
DA
16444 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16445 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16446 peer->rtt_expected, peer->rtt_keepalive_conf);
16447
dd65f45e 16448 /* bfd */
21bfce98
RZ
16449 if (peer->bfd_config)
16450 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
16451
16452 /* password */
16453 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16454 vty_out(vty, " neighbor %s password %s\n", addr,
16455 peer->password);
16456
16457 /* neighbor solo */
16458 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16459 if (!peer_group_active(peer)) {
16460 vty_out(vty, " neighbor %s solo\n", addr);
16461 }
16462 }
16463
16464 /* BGP port */
16465 if (peer->port != BGP_PORT_DEFAULT) {
16466 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16467 }
16468
16469 /* Local interface name */
16470 if (peer->ifname) {
16471 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16472 }
16473
4ab46701
AR
16474 /* TCP max segment size */
16475 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16476 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16477
dd65f45e
DL
16478 /* passive */
16479 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16480 vty_out(vty, " neighbor %s passive\n", addr);
16481
16482 /* ebgp-multihop */
16483 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
16484 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16485 && peer->ttl == MAXTTL)) {
dd65f45e
DL
16486 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16487 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16488 peer->ttl);
16489 }
16490 }
16491
16492 /* ttl-security hops */
e2521429 16493 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
16494 if (!peer_group_active(peer)
16495 || g_peer->gtsm_hops != peer->gtsm_hops) {
16496 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16497 addr, peer->gtsm_hops);
16498 }
16499 }
16500
16501 /* disable-connected-check */
16502 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16503 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16504
27aa23a4
DA
16505 /* link-bw-encoding-ieee */
16506 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16507 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16508 addr);
16509
d08c0c80
DA
16510 /* extended-optional-parameters */
16511 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16512 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16513 addr);
16514
dd65f45e
DL
16515 /* enforce-first-as */
16516 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16517 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16518
16519 /* update-source */
16520 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16521 if (peer->update_source)
16522 vty_out(vty, " neighbor %s update-source %s\n", addr,
16523 sockunion2str(peer->update_source, buf,
16524 SU_ADDRSTRLEN));
16525 else if (peer->update_if)
16526 vty_out(vty, " neighbor %s update-source %s\n", addr,
16527 peer->update_if);
16528 }
16529
16530 /* advertisement-interval */
16531 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16532 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16533 peer->routeadv);
16534
16535 /* timers */
16536 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16537 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16538 peer->keepalive, peer->holdtime);
16539
16540 /* timers connect */
16541 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16542 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16543 peer->connect);
5d5393b9
DL
16544 /* need special-case handling for changed default values due to
16545 * config profile / version (because there is no "timers bgp connect"
16546 * command, we need to save this per-peer :/)
16547 */
16548 else if (!peer_group_active(peer) && !peer->connect &&
16549 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16550 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16551 peer->bgp->default_connect_retry);
dd65f45e 16552
d43114f3
DS
16553 /* timers delayopen */
16554 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16555 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16556 peer->delayopen);
16557 /* Save config even though flag is not set if default values have been
16558 * changed
16559 */
16560 else if (!peer_group_active(peer) && !peer->delayopen
16561 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16562 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16563 peer->bgp->default_delayopen);
16564
dd65f45e
DL
16565 /* capability dynamic */
16566 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16567 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16568
16569 /* capability extended-nexthop */
16570 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
843770f6
DA
16571 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE))
16572 vty_out(vty,
16573 " no neighbor %s capability extended-nexthop\n",
16574 addr);
16575 else if (!peer->conf_if)
16576 vty_out(vty,
16577 " neighbor %s capability extended-nexthop\n",
16578 addr);
dd65f45e
DL
16579 }
16580
16581 /* dont-capability-negotiation */
16582 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16583 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16584
16585 /* override-capability */
16586 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16587 vty_out(vty, " neighbor %s override-capability\n", addr);
16588
16589 /* strict-capability-match */
16590 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16591 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16592
16593 /* Sender side AS path loop detection. */
16594 if (peer->as_path_loop_detection)
16595 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16596 addr);
cfd47646 16597
16598 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16599 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 16600
16601 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16602 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 16603 vty_out(vty,
16604 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
16605 } else if (CHECK_FLAG(
16606 peer->peer_gr_new_status_flag,
16607 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 16608 vty_out(vty,
16609 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
16610 } else if (
16611 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16612 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16613 && !(CHECK_FLAG(
16614 peer->peer_gr_new_status_flag,
16615 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16616 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16617 addr);
cfd47646 16618 }
16619 }
dd65f45e
DL
16620}
16621
16622/* BGP peer configuration display function. */
16623static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16624 struct peer *peer, afi_t afi, safi_t safi)
16625{
16626 struct peer *g_peer = NULL;
16627 char *addr;
16628 bool flag_scomm, flag_secomm, flag_slcomm;
16629
16630 /* Skip dynamic neighbors. */
16631 if (peer_dynamic_neighbor(peer))
16632 return;
16633
16634 if (peer->conf_if)
16635 addr = peer->conf_if;
16636 else
16637 addr = peer->host;
16638
16639 /************************************
16640 ****** Per AF to the neighbor ******
16641 ************************************/
16642 if (peer_group_active(peer)) {
16643 g_peer = peer->group->conf;
16644
16645 /* If the peer-group is active but peer is not, print a 'no
16646 * activate' */
16647 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16648 vty_out(vty, " no neighbor %s activate\n", addr);
16649 }
16650
16651 /* If the peer-group is not active but peer is, print an
16652 'activate' */
16653 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16654 vty_out(vty, " neighbor %s activate\n", addr);
16655 }
16656 } else {
16657 if (peer->afc[afi][safi]) {
38d11af5
TA
16658 if (safi == SAFI_ENCAP)
16659 vty_out(vty, " neighbor %s activate\n", addr);
16660 else if (!bgp->default_af[afi][safi])
dd65f45e
DL
16661 vty_out(vty, " neighbor %s activate\n", addr);
16662 } else {
38d11af5
TA
16663 if (bgp->default_af[afi][safi])
16664 vty_out(vty, " no neighbor %s activate\n",
16665 addr);
dd65f45e
DL
16666 }
16667 }
16668
16669 /* addpath TX knobs */
16670 if (peergroup_af_addpath_check(peer, afi, safi)) {
16671 switch (peer->addpath_type[afi][safi]) {
16672 case BGP_ADDPATH_ALL:
16673 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16674 addr);
16675 break;
16676 case BGP_ADDPATH_BEST_PER_AS:
16677 vty_out(vty,
16678 " neighbor %s addpath-tx-bestpath-per-AS\n",
16679 addr);
16680 break;
16681 case BGP_ADDPATH_MAX:
16682 case BGP_ADDPATH_NONE:
16683 break;
16684 }
16685 }
16686
7c0e4312
DA
16687 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
16688 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
16689
dd65f45e
DL
16690 /* ORF capability. */
16691 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16692 || peergroup_af_flag_check(peer, afi, safi,
16693 PEER_FLAG_ORF_PREFIX_RM)) {
16694 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16695
16696 if (peergroup_af_flag_check(peer, afi, safi,
16697 PEER_FLAG_ORF_PREFIX_SM)
16698 && peergroup_af_flag_check(peer, afi, safi,
16699 PEER_FLAG_ORF_PREFIX_RM))
16700 vty_out(vty, " both");
16701 else if (peergroup_af_flag_check(peer, afi, safi,
16702 PEER_FLAG_ORF_PREFIX_SM))
16703 vty_out(vty, " send");
16704 else
16705 vty_out(vty, " receive");
16706 vty_out(vty, "\n");
16707 }
16708
dd65f45e
DL
16709 /* Route reflector client. */
16710 if (peergroup_af_flag_check(peer, afi, safi,
16711 PEER_FLAG_REFLECTOR_CLIENT)) {
16712 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16713 }
16714
16715 /* next-hop-self force */
16716 if (peergroup_af_flag_check(peer, afi, safi,
16717 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16718 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16719 }
16720
16721 /* next-hop-self */
16722 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16723 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16724 }
16725
16726 /* remove-private-AS */
16727 if (peergroup_af_flag_check(peer, afi, safi,
16728 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16729 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16730 addr);
16731 }
16732
16733 else if (peergroup_af_flag_check(peer, afi, safi,
16734 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16735 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16736 addr);
16737 }
16738
16739 else if (peergroup_af_flag_check(peer, afi, safi,
16740 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16741 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16742 }
16743
16744 else if (peergroup_af_flag_check(peer, afi, safi,
16745 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16746 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16747 }
16748
16749 /* as-override */
16750 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16751 vty_out(vty, " neighbor %s as-override\n", addr);
16752 }
16753
16754 /* send-community print. */
16755 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16756 PEER_FLAG_SEND_COMMUNITY);
16757 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16758 PEER_FLAG_SEND_EXT_COMMUNITY);
16759 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16760 PEER_FLAG_SEND_LARGE_COMMUNITY);
16761
16762 if (flag_scomm && flag_secomm && flag_slcomm) {
16763 vty_out(vty, " no neighbor %s send-community all\n", addr);
16764 } else {
16765 if (flag_scomm)
16766 vty_out(vty, " no neighbor %s send-community\n", addr);
16767 if (flag_secomm)
16768 vty_out(vty,
16769 " no neighbor %s send-community extended\n",
16770 addr);
16771
16772 if (flag_slcomm)
16773 vty_out(vty, " no neighbor %s send-community large\n",
16774 addr);
16775 }
16776
16777 /* Default information */
16778 if (peergroup_af_flag_check(peer, afi, safi,
16779 PEER_FLAG_DEFAULT_ORIGINATE)) {
16780 vty_out(vty, " neighbor %s default-originate", addr);
16781
16782 if (peer->default_rmap[afi][safi].name)
16783 vty_out(vty, " route-map %s",
16784 peer->default_rmap[afi][safi].name);
16785
16786 vty_out(vty, "\n");
16787 }
16788
16789 /* Soft reconfiguration inbound. */
16790 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16791 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16792 addr);
16793 }
16794
16795 /* maximum-prefix. */
16796 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 16797 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
16798 peer->pmax[afi][safi]);
16799
16800 if (peer->pmax_threshold[afi][safi]
16801 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16802 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16803 if (peer_af_flag_check(peer, afi, safi,
16804 PEER_FLAG_MAX_PREFIX_WARNING))
16805 vty_out(vty, " warning-only");
16806 if (peer->pmax_restart[afi][safi])
16807 vty_out(vty, " restart %u",
16808 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
16809 if (peer_af_flag_check(peer, afi, safi,
16810 PEER_FLAG_MAX_PREFIX_FORCE))
16811 vty_out(vty, " force");
dd65f45e
DL
16812
16813 vty_out(vty, "\n");
16814 }
16815
fde246e8
DA
16816 /* maximum-prefix-out */
16817 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 16818 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
16819 addr, peer->pmax_out[afi][safi]);
16820
dd65f45e
DL
16821 /* Route server client. */
16822 if (peergroup_af_flag_check(peer, afi, safi,
16823 PEER_FLAG_RSERVER_CLIENT)) {
16824 vty_out(vty, " neighbor %s route-server-client\n", addr);
16825 }
16826
16827 /* Nexthop-local unchanged. */
16828 if (peergroup_af_flag_check(peer, afi, safi,
16829 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16830 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16831 }
16832
16833 /* allowas-in <1-10> */
16834 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16835 if (peer_af_flag_check(peer, afi, safi,
16836 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16837 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16838 } else if (peer->allowas_in[afi][safi] == 3) {
16839 vty_out(vty, " neighbor %s allowas-in\n", addr);
16840 } else {
16841 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16842 peer->allowas_in[afi][safi]);
16843 }
16844 }
16845
16846 /* weight */
16847 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16848 vty_out(vty, " neighbor %s weight %lu\n", addr,
16849 peer->weight[afi][safi]);
16850
16851 /* Filter. */
16852 bgp_config_write_filter(vty, peer, afi, safi);
16853
16854 /* atribute-unchanged. */
16855 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16856 || (safi != SAFI_EVPN
16857 && peer_af_flag_check(peer, afi, safi,
16858 PEER_FLAG_NEXTHOP_UNCHANGED))
16859 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16860
16861 if (!peer_group_active(peer)
16862 || peergroup_af_flag_check(peer, afi, safi,
16863 PEER_FLAG_AS_PATH_UNCHANGED)
16864 || peergroup_af_flag_check(peer, afi, safi,
16865 PEER_FLAG_NEXTHOP_UNCHANGED)
16866 || peergroup_af_flag_check(peer, afi, safi,
16867 PEER_FLAG_MED_UNCHANGED)) {
16868
16869 vty_out(vty,
16870 " neighbor %s attribute-unchanged%s%s%s\n",
16871 addr,
16872 peer_af_flag_check(peer, afi, safi,
16873 PEER_FLAG_AS_PATH_UNCHANGED)
16874 ? " as-path"
16875 : "",
16876 peer_af_flag_check(peer, afi, safi,
16877 PEER_FLAG_NEXTHOP_UNCHANGED)
16878 ? " next-hop"
16879 : "",
16880 peer_af_flag_check(peer, afi, safi,
16881 PEER_FLAG_MED_UNCHANGED)
16882 ? " med"
16883 : "");
16884 }
16885 }
16886}
16887
16888/* Address family based peer configuration display. */
16889static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
16890 safi_t safi)
16891{
16892 struct peer *peer;
16893 struct peer_group *group;
16894 struct listnode *node, *nnode;
16895
16896
16897 vty_frame(vty, " !\n address-family ");
16898 if (afi == AFI_IP) {
16899 if (safi == SAFI_UNICAST)
16900 vty_frame(vty, "ipv4 unicast");
16901 else if (safi == SAFI_LABELED_UNICAST)
16902 vty_frame(vty, "ipv4 labeled-unicast");
16903 else if (safi == SAFI_MULTICAST)
16904 vty_frame(vty, "ipv4 multicast");
16905 else if (safi == SAFI_MPLS_VPN)
16906 vty_frame(vty, "ipv4 vpn");
16907 else if (safi == SAFI_ENCAP)
16908 vty_frame(vty, "ipv4 encap");
16909 else if (safi == SAFI_FLOWSPEC)
16910 vty_frame(vty, "ipv4 flowspec");
16911 } else if (afi == AFI_IP6) {
16912 if (safi == SAFI_UNICAST)
16913 vty_frame(vty, "ipv6 unicast");
16914 else if (safi == SAFI_LABELED_UNICAST)
16915 vty_frame(vty, "ipv6 labeled-unicast");
16916 else if (safi == SAFI_MULTICAST)
16917 vty_frame(vty, "ipv6 multicast");
16918 else if (safi == SAFI_MPLS_VPN)
16919 vty_frame(vty, "ipv6 vpn");
16920 else if (safi == SAFI_ENCAP)
16921 vty_frame(vty, "ipv6 encap");
16922 else if (safi == SAFI_FLOWSPEC)
16923 vty_frame(vty, "ipv6 flowspec");
16924 } else if (afi == AFI_L2VPN) {
16925 if (safi == SAFI_EVPN)
16926 vty_frame(vty, "l2vpn evpn");
16927 }
16928 vty_frame(vty, "\n");
16929
16930 bgp_config_write_distance(vty, bgp, afi, safi);
16931
16932 bgp_config_write_network(vty, bgp, afi, safi);
16933
16934 bgp_config_write_redistribute(vty, bgp, afi, safi);
16935
8a4e7fe6
DA
16936 /* BGP flag dampening. */
16937 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6c75f4b3 16938 bgp_config_write_damp(vty, afi, safi);
8a4e7fe6 16939
dd65f45e
DL
16940 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
16941 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
16942
16943 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
16944 /* Do not display doppelganger peers */
16945 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16946 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
16947 }
16948
16949 bgp_config_write_maxpaths(vty, bgp, afi, safi);
16950 bgp_config_write_table_map(vty, bgp, afi, safi);
16951
16952 if (safi == SAFI_EVPN)
16953 bgp_config_write_evpn_info(vty, bgp, afi, safi);
16954
16955 if (safi == SAFI_FLOWSPEC)
16956 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
16957
16958 if (safi == SAFI_UNICAST) {
16959 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
16960 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16961 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
16962
16963 vty_out(vty, " export vpn\n");
16964 }
16965 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16966 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
16967
16968 vty_out(vty, " import vpn\n");
16969 }
16970 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16971 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
16972 char *name;
16973
16974 for (ALL_LIST_ELEMENTS_RO(
16975 bgp->vpn_policy[afi].import_vrf, node,
16976 name))
16977 vty_out(vty, " import vrf %s\n", name);
16978 }
16979 }
16980
16981 vty_endframe(vty, " exit-address-family\n");
16982}
16983
16984int bgp_config_write(struct vty *vty)
16985{
16986 struct bgp *bgp;
16987 struct peer_group *group;
16988 struct peer *peer;
16989 struct listnode *node, *nnode;
16990 struct listnode *mnode, *mnnode;
b16bcbba
TA
16991 afi_t afi;
16992 safi_t safi;
dd65f45e
DL
16993
16994 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
16995 vty_out(vty, "bgp route-map delay-timer %u\n",
16996 bm->rmap_update_timer);
16997
d70583f7
D
16998 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
16999 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17000 if (bm->v_update_delay != bm->v_establish_wait)
17001 vty_out(vty, " %d", bm->v_establish_wait);
17002 vty_out(vty, "\n");
17003 }
17004
9acb67cb
DS
17005 if (bm->wait_for_fib)
17006 vty_out(vty, "bgp suppress-fib-pending\n");
17007
05bd726c 17008 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17009 vty_out(vty, "bgp graceful-shutdown\n");
17010
c163f297
DS
17011 /* No-RIB (Zebra) option flag configuration */
17012 if (bgp_option_check(BGP_OPT_NO_FIB))
17013 vty_out(vty, "bgp no-rib\n");
17014
870791a3
IR
17015 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17016 vty_out(vty, "bgp send-extra-data zebra\n");
e46723a5 17017
dd65f45e
DL
17018 /* BGP configuration. */
17019 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17020
17021 /* skip all auto created vrf as they dont have user config */
17022 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17023 continue;
17024
17025 /* Router bgp ASN */
17026 vty_out(vty, "router bgp %u", bgp->as);
17027
17028 if (bgp->name)
17029 vty_out(vty, " %s %s",
17030 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17031 ? "view" : "vrf", bgp->name);
17032 vty_out(vty, "\n");
17033
17034 /* BGP fast-external-failover. */
17035 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17036 vty_out(vty, " no bgp fast-external-failover\n");
17037
17038 /* BGP router ID. */
3a6290bd 17039 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17040 vty_out(vty, " bgp router-id %pI4\n",
17041 &bgp->router_id_static);
dd65f45e 17042
c208c586
S
17043 /* Suppress fib pending */
17044 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17045 vty_out(vty, " bgp suppress-fib-pending\n");
17046
dd65f45e 17047 /* BGP log-neighbor-changes. */
892fedb6 17048 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17049 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17050 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17051 CHECK_FLAG(bgp->flags,
17052 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17053 ? ""
17054 : "no ");
17055
17056 /* BGP configuration. */
892fedb6 17057 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17058 vty_out(vty, " bgp always-compare-med\n");
17059
17060 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17061 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17062 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17063 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17064 CHECK_FLAG(bgp->flags,
17065 BGP_FLAG_EBGP_REQUIRES_POLICY)
17066 ? ""
17067 : "no ");
dd65f45e
DL
17068
17069 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17070 if (bgp->reject_as_sets)
dd65f45e
DL
17071 vty_out(vty, " bgp reject-as-sets\n");
17072
2adac256
DA
17073 /* Suppress duplicate updates if the route actually not changed
17074 */
17075 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17076 != SAVE_BGP_SUPPRESS_DUPLICATES)
17077 vty_out(vty, " %sbgp suppress-duplicates\n",
17078 CHECK_FLAG(bgp->flags,
17079 BGP_FLAG_SUPPRESS_DUPLICATES)
17080 ? ""
17081 : "no ");
17082
b16bcbba
TA
17083 /* BGP default <afi>-<safi> */
17084 FOREACH_AFI_SAFI (afi, safi) {
17085 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17086 if (!bgp->default_af[afi][safi])
17087 vty_out(vty, " no bgp default %s\n",
17088 get_bgp_default_af_flag(afi,
17089 safi));
17090 } else if (bgp->default_af[afi][safi])
17091 vty_out(vty, " bgp default %s\n",
17092 get_bgp_default_af_flag(afi, safi));
17093 }
e84c59af 17094
dd65f45e
DL
17095 /* BGP default local-preference. */
17096 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17097 vty_out(vty, " bgp default local-preference %u\n",
17098 bgp->default_local_pref);
17099
17100 /* BGP default show-hostname */
892fedb6 17101 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17102 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17103 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17104 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17105 ? ""
17106 : "no ");
17107
aef999a2
DA
17108 /* BGP default show-nexthop-hostname */
17109 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17110 != SAVE_BGP_SHOW_HOSTNAME)
17111 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17112 CHECK_FLAG(bgp->flags,
17113 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17114 ? ""
17115 : "no ");
17116
dd65f45e
DL
17117 /* BGP default subgroup-pkt-queue-max. */
17118 if (bgp->default_subgroup_pkt_queue_max
17119 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17120 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17121 bgp->default_subgroup_pkt_queue_max);
17122
17123 /* BGP client-to-client reflection. */
892fedb6 17124 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17125 vty_out(vty, " no bgp client-to-client reflection\n");
17126
17127 /* BGP cluster ID. */
17128 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17129 vty_out(vty, " bgp cluster-id %pI4\n",
17130 &bgp->cluster_id);
dd65f45e
DL
17131
17132 /* Disable ebgp connected nexthop check */
892fedb6 17133 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17134 vty_out(vty,
17135 " bgp disable-ebgp-connected-route-check\n");
17136
17137 /* Confederation identifier*/
17138 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17139 vty_out(vty, " bgp confederation identifier %u\n",
17140 bgp->confed_id);
17141
17142 /* Confederation peer */
17143 if (bgp->confed_peers_cnt > 0) {
17144 int i;
17145
17146 vty_out(vty, " bgp confederation peers");
17147
17148 for (i = 0; i < bgp->confed_peers_cnt; i++)
17149 vty_out(vty, " %u", bgp->confed_peers[i]);
17150
17151 vty_out(vty, "\n");
17152 }
17153
17154 /* BGP deterministic-med. */
892fedb6 17155 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 17156 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 17157 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
17158 CHECK_FLAG(bgp->flags,
17159 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
17160 ? ""
17161 : "no ");
17162
17163 /* BGP update-delay. */
17164 bgp_config_write_update_delay(vty, bgp);
17165
17166 if (bgp->v_maxmed_onstartup
17167 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17168 vty_out(vty, " bgp max-med on-startup %u",
17169 bgp->v_maxmed_onstartup);
17170 if (bgp->maxmed_onstartup_value
17171 != BGP_MAXMED_VALUE_DEFAULT)
17172 vty_out(vty, " %u",
17173 bgp->maxmed_onstartup_value);
17174 vty_out(vty, "\n");
17175 }
17176 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17177 vty_out(vty, " bgp max-med administrative");
17178 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17179 vty_out(vty, " %u", bgp->maxmed_admin_value);
17180 vty_out(vty, "\n");
17181 }
17182
17183 /* write quanta */
17184 bgp_config_write_wpkt_quanta(vty, bgp);
17185 /* read quanta */
17186 bgp_config_write_rpkt_quanta(vty, bgp);
17187
17188 /* coalesce time */
17189 bgp_config_write_coalesce_time(vty, bgp);
17190
05bd726c 17191 /* BGP per-instance graceful-shutdown */
17192 /* BGP-wide settings and per-instance settings are mutually
17193 * exclusive.
17194 */
17195 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17196 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17197 vty_out(vty, " bgp graceful-shutdown\n");
17198
8606be87
DA
17199 /* Long-lived Graceful Restart */
17200 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17201 vty_out(vty,
17202 " bgp long-lived-graceful-restart stale-time %u\n",
17203 bgp->llgr_stale_time);
17204
dd65f45e
DL
17205 /* BGP graceful-restart. */
17206 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17207 vty_out(vty,
17208 " bgp graceful-restart stalepath-time %u\n",
17209 bgp->stalepath_time);
cfd47646 17210
dd65f45e
DL
17211 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17212 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17213 bgp->restart_time);
cfd47646 17214
17215 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17216 vty_out(vty,
17217 " bgp graceful-restart select-defer-time %u\n",
17218 bgp->select_defer_time);
17219
17220 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
17221 vty_out(vty, " bgp graceful-restart\n");
17222
cfd47646 17223 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17224 vty_out(vty, " bgp graceful-restart-disable\n");
17225
dd65f45e 17226 /* BGP graceful-restart Preserve State F bit. */
892fedb6 17227 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
17228 vty_out(vty,
17229 " bgp graceful-restart preserve-fw-state\n");
17230
dc95985f 17231 /* Stale timer for RIB */
17232 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17233 vty_out(vty,
17234 " bgp graceful-restart rib-stale-time %u\n",
17235 bgp->rib_stale_time);
17236
dd65f45e 17237 /* BGP bestpath method. */
892fedb6 17238 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 17239 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 17240 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
17241 vty_out(vty, " bgp bestpath as-path confed\n");
17242
892fedb6
DA
17243 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17244 if (CHECK_FLAG(bgp->flags,
17245 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
17246 vty_out(vty,
17247 " bgp bestpath as-path multipath-relax as-set\n");
17248 } else {
17249 vty_out(vty,
17250 " bgp bestpath as-path multipath-relax\n");
17251 }
17252 }
17253
892fedb6 17254 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17255 vty_out(vty,
17256 " bgp route-reflector allow-outbound-policy\n");
17257 }
892fedb6 17258 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17259 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17260 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17261 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17262 vty_out(vty, " bgp bestpath med");
892fedb6 17263 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17264 vty_out(vty, " confed");
892fedb6
DA
17265 if (CHECK_FLAG(bgp->flags,
17266 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17267 vty_out(vty, " missing-as-worst");
17268 vty_out(vty, "\n");
17269 }
17270
ee88563a
JM
17271 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17272 vty_out(vty,
17273 " bgp bestpath peer-type multipath-relax\n");
17274
f7e1c681 17275 /* Link bandwidth handling. */
17276 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17277 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17278 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17279 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17280 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17281 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17282
dd65f45e 17283 /* BGP network import check. */
892fedb6 17284 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17285 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17286 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17287 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17288 ? ""
17289 : "no ");
17290
17291 /* BGP timers configuration. */
5d5393b9 17292 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 17293 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17294 vty_out(vty, " timers bgp %u %u\n",
17295 bgp->default_keepalive, bgp->default_holdtime);
17296
b042667a
TI
17297 /* BGP minimum holdtime configuration. */
17298 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17299 && bgp->default_min_holdtime != 0)
17300 vty_out(vty, " bgp minimum-holdtime %u\n",
17301 bgp->default_min_holdtime);
17302
389e4f92
QY
17303 /* Conditional advertisement timer configuration */
17304 if (bgp->condition_check_period
17305 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17306 vty_out(vty,
17307 " bgp conditional-advertisement timer %u\n",
17308 bgp->condition_check_period);
17309
dd65f45e
DL
17310 /* peer-group */
17311 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17312 bgp_config_write_peer_global(vty, bgp, group->conf);
17313 }
17314
17315 /* Normal neighbor configuration. */
17316 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17317 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17318 bgp_config_write_peer_global(vty, bgp, peer);
17319 }
17320
17321 /* listen range and limit for dynamic BGP neighbors */
17322 bgp_config_write_listen(vty, bgp);
17323
17324 /*
17325 * BGP default autoshutdown neighbors
17326 *
17327 * This must be placed after any peer and peer-group
17328 * configuration, to avoid setting all peers to shutdown after
17329 * a daemon restart, which is undesired behavior. (see #2286)
17330 */
17331 if (bgp->autoshutdown)
17332 vty_out(vty, " bgp default shutdown\n");
17333
9cf59432
DS
17334 /* BGP instance administrative shutdown */
17335 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17336 vty_out(vty, " bgp shutdown\n");
17337
f852eb98
PG
17338 if (bgp->fast_convergence)
17339 vty_out(vty, " bgp fast-convergence\n");
17340
a0281b2e
HS
17341 if (bgp->srv6_enabled) {
17342 vty_frame(vty, " !\n segment-routing srv6\n");
96db4340 17343 if (strlen(bgp->srv6_locator_name))
a0281b2e
HS
17344 vty_out(vty, " locator %s\n",
17345 bgp->srv6_locator_name);
ff7c3ee1 17346 vty_endframe(vty, " exit\n");
a0281b2e
HS
17347 }
17348
17349
dd65f45e
DL
17350 /* IPv4 unicast configuration. */
17351 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17352
17353 /* IPv4 multicast configuration. */
17354 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17355
17356 /* IPv4 labeled-unicast configuration. */
17357 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17358
17359 /* IPv4 VPN configuration. */
17360 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17361
17362 /* ENCAPv4 configuration. */
17363 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17364
17365 /* FLOWSPEC v4 configuration. */
17366 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17367
17368 /* IPv6 unicast configuration. */
17369 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17370
17371 /* IPv6 multicast configuration. */
17372 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17373
17374 /* IPv6 labeled-unicast configuration. */
17375 bgp_config_write_family(vty, bgp, AFI_IP6,
17376 SAFI_LABELED_UNICAST);
17377
17378 /* IPv6 VPN configuration. */
17379 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17380
17381 /* ENCAPv6 configuration. */
17382 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17383
17384 /* FLOWSPEC v6 configuration. */
17385 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17386
17387 /* EVPN configuration. */
17388 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17389
17390 hook_call(bgp_inst_config_write, bgp, vty);
17391
49e5a4a0 17392#ifdef ENABLE_BGP_VNC
dd65f45e
DL
17393 bgp_rfapi_cfg_write(vty, bgp);
17394#endif
17395
07679ad9 17396 vty_out(vty, "exit\n");
dd65f45e
DL
17397 vty_out(vty, "!\n");
17398 }
17399 return 0;
17400}
17401
ddb5b488 17402
718e3744 17403/* BGP node structure. */
d62a17ae 17404static struct cmd_node bgp_node = {
f4b8291f 17405 .name = "bgp",
62b346ee 17406 .node = BGP_NODE,
24389580 17407 .parent_node = CONFIG_NODE,
62b346ee 17408 .prompt = "%s(config-router)# ",
612c2c15 17409 .config_write = bgp_config_write,
718e3744 17410};
17411
d62a17ae 17412static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 17413 .name = "bgp ipv4 unicast",
62b346ee 17414 .node = BGP_IPV4_NODE,
24389580 17415 .parent_node = BGP_NODE,
62b346ee 17416 .prompt = "%s(config-router-af)# ",
dd2c81b8 17417 .no_xpath = true,
718e3744 17418};
17419
d62a17ae 17420static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 17421 .name = "bgp ipv4 multicast",
62b346ee 17422 .node = BGP_IPV4M_NODE,
24389580 17423 .parent_node = BGP_NODE,
62b346ee 17424 .prompt = "%s(config-router-af)# ",
dd2c81b8 17425 .no_xpath = true,
718e3744 17426};
17427
d62a17ae 17428static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 17429 .name = "bgp ipv4 labeled unicast",
62b346ee 17430 .node = BGP_IPV4L_NODE,
24389580 17431 .parent_node = BGP_NODE,
62b346ee 17432 .prompt = "%s(config-router-af)# ",
dd2c81b8 17433 .no_xpath = true,
f51bae9c
DS
17434};
17435
d62a17ae 17436static struct cmd_node bgp_ipv6_unicast_node = {
a17cfb3f 17437 .name = "bgp ipv6 unicast",
62b346ee 17438 .node = BGP_IPV6_NODE,
24389580 17439 .parent_node = BGP_NODE,
62b346ee 17440 .prompt = "%s(config-router-af)# ",
dd2c81b8 17441 .no_xpath = true,
718e3744 17442};
17443
d62a17ae 17444static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 17445 .name = "bgp ipv6 multicast",
62b346ee 17446 .node = BGP_IPV6M_NODE,
24389580 17447 .parent_node = BGP_NODE,
62b346ee 17448 .prompt = "%s(config-router-af)# ",
dd2c81b8 17449 .no_xpath = true,
25ffbdc1 17450};
17451
d62a17ae 17452static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 17453 .name = "bgp ipv6 labeled unicast",
62b346ee 17454 .node = BGP_IPV6L_NODE,
24389580 17455 .parent_node = BGP_NODE,
62b346ee 17456 .prompt = "%s(config-router-af)# ",
dd2c81b8 17457 .no_xpath = true,
f51bae9c
DS
17458};
17459
62b346ee 17460static struct cmd_node bgp_vpnv4_node = {
f4b8291f 17461 .name = "bgp vpnv4",
62b346ee 17462 .node = BGP_VPNV4_NODE,
24389580 17463 .parent_node = BGP_NODE,
62b346ee 17464 .prompt = "%s(config-router-af)# ",
dd2c81b8 17465 .no_xpath = true,
62b346ee 17466};
6b0655a2 17467
62b346ee 17468static struct cmd_node bgp_vpnv6_node = {
f4b8291f 17469 .name = "bgp vpnv6",
62b346ee 17470 .node = BGP_VPNV6_NODE,
24389580 17471 .parent_node = BGP_NODE,
62b346ee 17472 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 17473 .no_xpath = true,
62b346ee 17474};
8ecd3266 17475
62b346ee 17476static struct cmd_node bgp_evpn_node = {
f4b8291f 17477 .name = "bgp evpn",
62b346ee 17478 .node = BGP_EVPN_NODE,
24389580 17479 .parent_node = BGP_NODE,
62b346ee 17480 .prompt = "%s(config-router-evpn)# ",
dd2c81b8 17481 .no_xpath = true,
62b346ee 17482};
4e0b7b6d 17483
62b346ee 17484static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 17485 .name = "bgp evpn vni",
62b346ee 17486 .node = BGP_EVPN_VNI_NODE,
24389580 17487 .parent_node = BGP_EVPN_NODE,
62b346ee 17488 .prompt = "%s(config-router-af-vni)# ",
62b346ee 17489};
90e60aa7 17490
62b346ee 17491static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 17492 .name = "bgp ipv4 flowspec",
62b346ee 17493 .node = BGP_FLOWSPECV4_NODE,
24389580 17494 .parent_node = BGP_NODE,
62b346ee 17495 .prompt = "%s(config-router-af)# ",
dd2c81b8 17496 .no_xpath = true,
62b346ee 17497};
7c40bf39 17498
62b346ee 17499static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 17500 .name = "bgp ipv6 flowspec",
62b346ee 17501 .node = BGP_FLOWSPECV6_NODE,
24389580 17502 .parent_node = BGP_NODE,
62b346ee 17503 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 17504 .no_xpath = true,
62b346ee 17505};
7c40bf39 17506
bfaab44d
HS
17507static struct cmd_node bgp_srv6_node = {
17508 .name = "bgp srv6",
17509 .node = BGP_SRV6_NODE,
17510 .parent_node = BGP_NODE,
17511 .prompt = "%s(config-router-srv6)# ",
17512};
17513
d62a17ae 17514static void community_list_vty(void);
1f8ae70b 17515
8c20061f
DA
17516static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17517{
17518 struct bgp *bgp;
17519 struct peer_group *group;
17520 struct listnode *lnbgp, *lnpeer;
17521
17522 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17523 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17524 vector_set(comps,
17525 XSTRDUP(MTYPE_COMPLETION, group->name));
17526 }
17527}
17528
17529static void bgp_ac_peer(vector comps, struct cmd_token *token)
b8a815e5 17530{
d62a17ae 17531 struct bgp *bgp;
17532 struct peer *peer;
d62a17ae 17533 struct listnode *lnbgp, *lnpeer;
b8a815e5 17534
d62a17ae 17535 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17536 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17537 /* only provide suggestions on the appropriate input
17538 * token type,
17539 * they'll otherwise show up multiple times */
17540 enum cmd_token_type match_type;
17541 char *name = peer->host;
d48ed3e0 17542
d62a17ae 17543 if (peer->conf_if) {
17544 match_type = VARIABLE_TKN;
17545 name = peer->conf_if;
17546 } else if (strchr(peer->host, ':'))
17547 match_type = IPV6_TKN;
17548 else
17549 match_type = IPV4_TKN;
d48ed3e0 17550
d62a17ae 17551 if (token->type != match_type)
17552 continue;
d48ed3e0 17553
d62a17ae 17554 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17555 }
d62a17ae 17556 }
b8a815e5
DL
17557}
17558
8c20061f
DA
17559static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17560{
17561 bgp_ac_peer(comps, token);
84de1483
DA
17562
17563 if (token->type == VARIABLE_TKN)
17564 bgp_ac_peergroup(comps, token);
8c20061f
DA
17565}
17566
b8a815e5 17567static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 17568 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17569 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 17570 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 17571 {.completions = NULL}};
17572
47a306a0
DS
17573static const struct cmd_variable_handler bgp_var_peergroup[] = {
17574 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17575 {.completions = NULL} };
17576
d62a17ae 17577void bgp_vty_init(void)
17578{
17579 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 17580 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 17581
17582 /* Install bgp top node. */
612c2c15
DL
17583 install_node(&bgp_node);
17584 install_node(&bgp_ipv4_unicast_node);
17585 install_node(&bgp_ipv4_multicast_node);
17586 install_node(&bgp_ipv4_labeled_unicast_node);
17587 install_node(&bgp_ipv6_unicast_node);
17588 install_node(&bgp_ipv6_multicast_node);
17589 install_node(&bgp_ipv6_labeled_unicast_node);
17590 install_node(&bgp_vpnv4_node);
17591 install_node(&bgp_vpnv6_node);
17592 install_node(&bgp_evpn_node);
17593 install_node(&bgp_evpn_vni_node);
17594 install_node(&bgp_flowspecv4_node);
17595 install_node(&bgp_flowspecv6_node);
bfaab44d 17596 install_node(&bgp_srv6_node);
d62a17ae 17597
17598 /* Install default VTY commands to new nodes. */
17599 install_default(BGP_NODE);
17600 install_default(BGP_IPV4_NODE);
17601 install_default(BGP_IPV4M_NODE);
17602 install_default(BGP_IPV4L_NODE);
17603 install_default(BGP_IPV6_NODE);
17604 install_default(BGP_IPV6M_NODE);
17605 install_default(BGP_IPV6L_NODE);
17606 install_default(BGP_VPNV4_NODE);
17607 install_default(BGP_VPNV6_NODE);
7c40bf39 17608 install_default(BGP_FLOWSPECV4_NODE);
17609 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 17610 install_default(BGP_EVPN_NODE);
17611 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 17612 install_default(BGP_SRV6_NODE);
d62a17ae 17613
8029b216
AK
17614 /* "bgp local-mac" hidden commands. */
17615 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17616 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17617
9acb67cb
DS
17618 /* "bgp suppress-fib-pending" global */
17619 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17620
d62a17ae 17621 /* bgp route-map delay-timer commands. */
17622 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17623 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17624
f852eb98
PG
17625 /* bgp fast-convergence command */
17626 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
17627 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
17628
d70583f7
D
17629 /* global bgp update-delay command */
17630 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17631 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17632
05bd726c 17633 /* global bgp graceful-shutdown command */
17634 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17635 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17636
d62a17ae 17637 /* Dummy commands (Currently not supported) */
17638 install_element(BGP_NODE, &no_synchronization_cmd);
17639 install_element(BGP_NODE, &no_auto_summary_cmd);
17640
17641 /* "router bgp" commands. */
17642 install_element(CONFIG_NODE, &router_bgp_cmd);
17643
17644 /* "no router bgp" commands. */
17645 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17646
17647 /* "bgp router-id" commands. */
17648 install_element(BGP_NODE, &bgp_router_id_cmd);
17649 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17650
c208c586
S
17651 /* "bgp suppress-fib-pending" command */
17652 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17653
d62a17ae 17654 /* "bgp cluster-id" commands. */
17655 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17656 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17657
c163f297
DS
17658 /* "bgp no-rib" commands. */
17659 install_element(CONFIG_NODE, &bgp_norib_cmd);
17660 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17661
e46723a5
DS
17662 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17663
d62a17ae 17664 /* "bgp confederation" commands. */
17665 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17666 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17667
17668 /* "bgp confederation peers" commands. */
17669 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17670 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17671
17672 /* bgp max-med command */
17673 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17674 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17675 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17676 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17677 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17678
17679 /* bgp disable-ebgp-connected-nh-check */
17680 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17681 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17682
17683 /* bgp update-delay command */
17684 install_element(BGP_NODE, &bgp_update_delay_cmd);
17685 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 17686
17687 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 17688 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 17689
17690 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17691 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17692
17693 /* "maximum-paths" commands. */
17694 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17695 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17696 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17697 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17698 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17699 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17700 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17701 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17702 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17703 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17704 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17705 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17706 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17707 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17708 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17709
39edabac
PG
17710 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17711 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17712 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17713 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17714 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 17715 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17716 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17717 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17718 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17719 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17720
17721 /* "timers bgp" commands. */
17722 install_element(BGP_NODE, &bgp_timers_cmd);
17723 install_element(BGP_NODE, &no_bgp_timers_cmd);
17724
b042667a
TI
17725 /* "minimum-holdtime" commands. */
17726 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
17727 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
17728
d62a17ae 17729 /* route-map delay-timer commands - per instance for backwards compat.
17730 */
17731 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17732 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17733
17734 /* "bgp client-to-client reflection" commands */
17735 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17736 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17737
17738 /* "bgp always-compare-med" commands */
17739 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17740 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17741
9dac9fc8
DA
17742 /* bgp ebgp-requires-policy */
17743 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17744 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17745
2adac256
DA
17746 /* bgp suppress-duplicates */
17747 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17748 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17749
fb29348a
DA
17750 /* bgp reject-as-sets */
17751 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17752 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17753
d62a17ae 17754 /* "bgp deterministic-med" commands */
17755 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17756 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17757
055679e9 17758 /* "bgp graceful-restart" command */
36235319
QY
17759 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17760 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 17761
17762 /* "bgp graceful-restart-disable" command */
36235319
QY
17763 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17764 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 17765
17766 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
17767 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17768 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 17769
17770 /* "neighbor a:b:c:d graceful-restart-disable" command */
17771 install_element(BGP_NODE,
17772 &bgp_neighbor_graceful_restart_disable_set_cmd);
17773 install_element(BGP_NODE,
17774 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17775
17776 /* "neighbor a:b:c:d graceful-restart-helper" command */
17777 install_element(BGP_NODE,
17778 &bgp_neighbor_graceful_restart_helper_set_cmd);
17779 install_element(BGP_NODE,
17780 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17781
d62a17ae 17782 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17783 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17784 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17785 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 17786 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 17787 install_element(BGP_NODE,
17788 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 17789 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17790 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17791
d6e3c15b 17792 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17793 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 17794 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17795 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 17796
7f323236
DW
17797 /* "bgp graceful-shutdown" commands */
17798 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17799 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17800
8606be87
DA
17801 /* "bgp long-lived-graceful-restart" commands */
17802 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
17803 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
17804
d62a17ae 17805 /* "bgp fast-external-failover" commands */
17806 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17807 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17808
d62a17ae 17809 /* "bgp bestpath compare-routerid" commands */
17810 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17811 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17812
17813 /* "bgp bestpath as-path ignore" commands */
17814 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17815 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17816
17817 /* "bgp bestpath as-path confed" commands */
17818 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17819 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17820
17821 /* "bgp bestpath as-path multipath-relax" commands */
17822 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17823 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17824
ee88563a
JM
17825 /* "bgp bestpath peer-type multipath-relax" commands */
17826 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
17827 install_element(BGP_NODE,
17828 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
17829
d62a17ae 17830 /* "bgp log-neighbor-changes" commands */
17831 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17832 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17833
17834 /* "bgp bestpath med" commands */
17835 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17836 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17837
f7e1c681 17838 /* "bgp bestpath bandwidth" commands */
17839 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 17840 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 17841
b16bcbba
TA
17842 /* "no bgp default <afi>-<safi>" commands. */
17843 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
e84c59af 17844
d62a17ae 17845 /* "bgp network import-check" commands. */
17846 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17847 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17848 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17849
17850 /* "bgp default local-preference" commands. */
17851 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17852 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17853
17854 /* bgp default show-hostname */
17855 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17856 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17857
aef999a2
DA
17858 /* bgp default show-nexthop-hostname */
17859 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17860 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17861
d62a17ae 17862 /* "bgp default subgroup-pkt-queue-max" commands. */
17863 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17864 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17865
17866 /* bgp ibgp-allow-policy-mods command */
17867 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17868 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17869
17870 /* "bgp listen limit" commands. */
17871 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17872 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17873
17874 /* "bgp listen range" commands. */
17875 install_element(BGP_NODE, &bgp_listen_range_cmd);
17876 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17877
8175f54a 17878 /* "bgp default shutdown" command */
f26845f9 17879 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
17880
17881 /* "bgp shutdown" commands */
17882 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 17883 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 17884 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 17885 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 17886
d62a17ae 17887 /* "neighbor remote-as" commands. */
17888 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17889 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17890 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17891 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17892 install_element(BGP_NODE,
17893 &neighbor_interface_v6only_config_remote_as_cmd);
17894 install_element(BGP_NODE, &no_neighbor_cmd);
17895 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17896
17897 /* "neighbor peer-group" commands. */
17898 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17899 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17900 install_element(BGP_NODE,
17901 &no_neighbor_interface_peer_group_remote_as_cmd);
17902
17903 /* "neighbor local-as" commands. */
17904 install_element(BGP_NODE, &neighbor_local_as_cmd);
17905 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17906 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17907 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17908
17909 /* "neighbor solo" commands. */
17910 install_element(BGP_NODE, &neighbor_solo_cmd);
17911 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17912
17913 /* "neighbor password" commands. */
17914 install_element(BGP_NODE, &neighbor_password_cmd);
17915 install_element(BGP_NODE, &no_neighbor_password_cmd);
17916
17917 /* "neighbor activate" commands. */
17918 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17919 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17920 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17921 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17922 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17923 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17924 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17925 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
17926 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 17927 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
17928 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 17929 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
17930
17931 /* "no neighbor activate" commands. */
17932 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
17933 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
17934 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
17935 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
17936 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
17937 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
17938 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
17939 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
17940 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 17941 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
17942 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 17943 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
17944
17945 /* "neighbor peer-group" set commands. */
17946 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
17947 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17948 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
17949 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17950 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
17951 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
17952 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17953 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 17954 install_element(BGP_FLOWSPECV4_NODE,
17955 &neighbor_set_peer_group_hidden_cmd);
17956 install_element(BGP_FLOWSPECV6_NODE,
17957 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 17958
17959 /* "no neighbor peer-group unset" commands. */
17960 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
17961 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17962 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17963 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17964 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17965 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17966 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17967 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 17968 install_element(BGP_FLOWSPECV4_NODE,
17969 &no_neighbor_set_peer_group_hidden_cmd);
17970 install_element(BGP_FLOWSPECV6_NODE,
17971 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 17972
17973 /* "neighbor softreconfiguration inbound" commands.*/
17974 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
17975 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
17976 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
17977 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17978 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
17979 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17980 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
17981 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17982 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
17983 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17984 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
17985 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17986 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
17987 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17988 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
17989 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17990 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
17991 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 17992 install_element(BGP_FLOWSPECV4_NODE,
17993 &neighbor_soft_reconfiguration_cmd);
17994 install_element(BGP_FLOWSPECV4_NODE,
17995 &no_neighbor_soft_reconfiguration_cmd);
17996 install_element(BGP_FLOWSPECV6_NODE,
17997 &neighbor_soft_reconfiguration_cmd);
17998 install_element(BGP_FLOWSPECV6_NODE,
17999 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
18000 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18001 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 18002
18003 /* "neighbor attribute-unchanged" commands. */
18004 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18005 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18006 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18007 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18008 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18009 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18010 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18011 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18012 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18013 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18014 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18015 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18016 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18017 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18018 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18019 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18020 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18021 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18022
18023 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18024 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18025
b8ad84d2
PG
18026 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18027 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18028 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18029 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18030
d62a17ae 18031 /* "nexthop-local unchanged" commands */
18032 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18033 install_element(BGP_IPV6_NODE,
18034 &no_neighbor_nexthop_local_unchanged_cmd);
18035
18036 /* "neighbor next-hop-self" commands. */
18037 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18038 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18039 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18040 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18041 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18042 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18043 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18044 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18045 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18046 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18047 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18048 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18049 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18050 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18051 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18052 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18053 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18054 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
18055 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18056 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 18057
18058 /* "neighbor next-hop-self force" commands. */
18059 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18060 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
18061 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18062 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18063 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18064 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18065 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18066 install_element(BGP_IPV4_NODE,
18067 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18068 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18069 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18070 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18071 install_element(BGP_IPV4M_NODE,
18072 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18073 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18074 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18075 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18076 install_element(BGP_IPV4L_NODE,
18077 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18078 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18079 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18080 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18081 install_element(BGP_IPV6_NODE,
18082 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18083 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18084 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18085 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18086 install_element(BGP_IPV6M_NODE,
18087 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18088 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18089 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18090 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18091 install_element(BGP_IPV6L_NODE,
18092 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18093 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18094 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18095 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18096 install_element(BGP_VPNV4_NODE,
18097 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18098 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18099 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18100 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18101 install_element(BGP_VPNV6_NODE,
18102 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
18103 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18104 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 18105
18106 /* "neighbor as-override" commands. */
18107 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18108 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18109 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18110 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18111 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18112 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18113 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18114 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18115 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18116 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18117 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18118 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18119 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18120 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18121 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18122 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18123 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18124 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18125
18126 /* "neighbor remove-private-AS" commands. */
18127 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18128 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18129 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18130 install_element(BGP_NODE,
18131 &no_neighbor_remove_private_as_all_hidden_cmd);
18132 install_element(BGP_NODE,
18133 &neighbor_remove_private_as_replace_as_hidden_cmd);
18134 install_element(BGP_NODE,
18135 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18136 install_element(BGP_NODE,
18137 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18138 install_element(
18139 BGP_NODE,
18140 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18141 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18142 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18143 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18144 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18145 install_element(BGP_IPV4_NODE,
18146 &neighbor_remove_private_as_replace_as_cmd);
18147 install_element(BGP_IPV4_NODE,
18148 &no_neighbor_remove_private_as_replace_as_cmd);
18149 install_element(BGP_IPV4_NODE,
18150 &neighbor_remove_private_as_all_replace_as_cmd);
18151 install_element(BGP_IPV4_NODE,
18152 &no_neighbor_remove_private_as_all_replace_as_cmd);
18153 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18154 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18155 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18156 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18157 install_element(BGP_IPV4M_NODE,
18158 &neighbor_remove_private_as_replace_as_cmd);
18159 install_element(BGP_IPV4M_NODE,
18160 &no_neighbor_remove_private_as_replace_as_cmd);
18161 install_element(BGP_IPV4M_NODE,
18162 &neighbor_remove_private_as_all_replace_as_cmd);
18163 install_element(BGP_IPV4M_NODE,
18164 &no_neighbor_remove_private_as_all_replace_as_cmd);
18165 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18166 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18167 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18168 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18169 install_element(BGP_IPV4L_NODE,
18170 &neighbor_remove_private_as_replace_as_cmd);
18171 install_element(BGP_IPV4L_NODE,
18172 &no_neighbor_remove_private_as_replace_as_cmd);
18173 install_element(BGP_IPV4L_NODE,
18174 &neighbor_remove_private_as_all_replace_as_cmd);
18175 install_element(BGP_IPV4L_NODE,
18176 &no_neighbor_remove_private_as_all_replace_as_cmd);
18177 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18178 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18179 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18180 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18181 install_element(BGP_IPV6_NODE,
18182 &neighbor_remove_private_as_replace_as_cmd);
18183 install_element(BGP_IPV6_NODE,
18184 &no_neighbor_remove_private_as_replace_as_cmd);
18185 install_element(BGP_IPV6_NODE,
18186 &neighbor_remove_private_as_all_replace_as_cmd);
18187 install_element(BGP_IPV6_NODE,
18188 &no_neighbor_remove_private_as_all_replace_as_cmd);
18189 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18190 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18191 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18192 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18193 install_element(BGP_IPV6M_NODE,
18194 &neighbor_remove_private_as_replace_as_cmd);
18195 install_element(BGP_IPV6M_NODE,
18196 &no_neighbor_remove_private_as_replace_as_cmd);
18197 install_element(BGP_IPV6M_NODE,
18198 &neighbor_remove_private_as_all_replace_as_cmd);
18199 install_element(BGP_IPV6M_NODE,
18200 &no_neighbor_remove_private_as_all_replace_as_cmd);
18201 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18202 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18203 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18204 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18205 install_element(BGP_IPV6L_NODE,
18206 &neighbor_remove_private_as_replace_as_cmd);
18207 install_element(BGP_IPV6L_NODE,
18208 &no_neighbor_remove_private_as_replace_as_cmd);
18209 install_element(BGP_IPV6L_NODE,
18210 &neighbor_remove_private_as_all_replace_as_cmd);
18211 install_element(BGP_IPV6L_NODE,
18212 &no_neighbor_remove_private_as_all_replace_as_cmd);
18213 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18214 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18215 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18216 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18217 install_element(BGP_VPNV4_NODE,
18218 &neighbor_remove_private_as_replace_as_cmd);
18219 install_element(BGP_VPNV4_NODE,
18220 &no_neighbor_remove_private_as_replace_as_cmd);
18221 install_element(BGP_VPNV4_NODE,
18222 &neighbor_remove_private_as_all_replace_as_cmd);
18223 install_element(BGP_VPNV4_NODE,
18224 &no_neighbor_remove_private_as_all_replace_as_cmd);
18225 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18226 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18227 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18228 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18229 install_element(BGP_VPNV6_NODE,
18230 &neighbor_remove_private_as_replace_as_cmd);
18231 install_element(BGP_VPNV6_NODE,
18232 &no_neighbor_remove_private_as_replace_as_cmd);
18233 install_element(BGP_VPNV6_NODE,
18234 &neighbor_remove_private_as_all_replace_as_cmd);
18235 install_element(BGP_VPNV6_NODE,
18236 &no_neighbor_remove_private_as_all_replace_as_cmd);
18237
18238 /* "neighbor send-community" commands.*/
18239 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18240 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18241 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18242 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18243 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18244 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18245 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18246 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18247 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18248 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18249 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18250 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18251 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18252 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18253 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18254 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18255 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18256 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18257 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18258 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18259 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18260 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18261 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18262 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18263 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18264 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18265 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18266 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18267 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18268 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18269 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18270 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18271 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18272 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18273 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18274 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18275
18276 /* "neighbor route-reflector" commands.*/
18277 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18278 install_element(BGP_NODE,
18279 &no_neighbor_route_reflector_client_hidden_cmd);
18280 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18281 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18282 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18283 install_element(BGP_IPV4M_NODE,
18284 &no_neighbor_route_reflector_client_cmd);
18285 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18286 install_element(BGP_IPV4L_NODE,
18287 &no_neighbor_route_reflector_client_cmd);
18288 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18289 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18290 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18291 install_element(BGP_IPV6M_NODE,
18292 &no_neighbor_route_reflector_client_cmd);
18293 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18294 install_element(BGP_IPV6L_NODE,
18295 &no_neighbor_route_reflector_client_cmd);
18296 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18297 install_element(BGP_VPNV4_NODE,
18298 &no_neighbor_route_reflector_client_cmd);
18299 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18300 install_element(BGP_VPNV6_NODE,
18301 &no_neighbor_route_reflector_client_cmd);
7c40bf39 18302 install_element(BGP_FLOWSPECV4_NODE,
18303 &neighbor_route_reflector_client_cmd);
18304 install_element(BGP_FLOWSPECV4_NODE,
18305 &no_neighbor_route_reflector_client_cmd);
18306 install_element(BGP_FLOWSPECV6_NODE,
18307 &neighbor_route_reflector_client_cmd);
18308 install_element(BGP_FLOWSPECV6_NODE,
18309 &no_neighbor_route_reflector_client_cmd);
d62a17ae 18310 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18311 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18312
18313 /* "neighbor route-server" commands.*/
18314 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18315 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18316 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18317 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18318 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18319 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18320 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18321 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18322 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18323 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18324 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18325 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18326 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18327 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18328 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18329 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18330 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18331 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
18332 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18333 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 18334 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18335 install_element(BGP_FLOWSPECV4_NODE,
18336 &no_neighbor_route_server_client_cmd);
18337 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18338 install_element(BGP_FLOWSPECV6_NODE,
18339 &no_neighbor_route_server_client_cmd);
d62a17ae 18340
7c0e4312
DA
18341 /* "neighbor disable-addpath-rx" commands. */
18342 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
18343 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18344 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
18345 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18346 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
18347 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18348 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
18349 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18350 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
18351 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18352 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
18353 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18354 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
18355 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18356 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
18357 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18358
d62a17ae 18359 /* "neighbor addpath-tx-all-paths" commands.*/
18360 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18361 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18362 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18363 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18364 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18365 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18366 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18367 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18368 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18369 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18370 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18371 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18372 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18373 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18374 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18375 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18376 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18377 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18378
18379 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18380 install_element(BGP_NODE,
18381 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18382 install_element(BGP_NODE,
18383 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18384 install_element(BGP_IPV4_NODE,
18385 &neighbor_addpath_tx_bestpath_per_as_cmd);
18386 install_element(BGP_IPV4_NODE,
18387 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18388 install_element(BGP_IPV4M_NODE,
18389 &neighbor_addpath_tx_bestpath_per_as_cmd);
18390 install_element(BGP_IPV4M_NODE,
18391 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18392 install_element(BGP_IPV4L_NODE,
18393 &neighbor_addpath_tx_bestpath_per_as_cmd);
18394 install_element(BGP_IPV4L_NODE,
18395 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18396 install_element(BGP_IPV6_NODE,
18397 &neighbor_addpath_tx_bestpath_per_as_cmd);
18398 install_element(BGP_IPV6_NODE,
18399 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18400 install_element(BGP_IPV6M_NODE,
18401 &neighbor_addpath_tx_bestpath_per_as_cmd);
18402 install_element(BGP_IPV6M_NODE,
18403 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18404 install_element(BGP_IPV6L_NODE,
18405 &neighbor_addpath_tx_bestpath_per_as_cmd);
18406 install_element(BGP_IPV6L_NODE,
18407 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18408 install_element(BGP_VPNV4_NODE,
18409 &neighbor_addpath_tx_bestpath_per_as_cmd);
18410 install_element(BGP_VPNV4_NODE,
18411 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18412 install_element(BGP_VPNV6_NODE,
18413 &neighbor_addpath_tx_bestpath_per_as_cmd);
18414 install_element(BGP_VPNV6_NODE,
18415 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18416
2b31007c
RZ
18417 /* "neighbor sender-as-path-loop-detection" commands. */
18418 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18419 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18420
d62a17ae 18421 /* "neighbor passive" commands. */
18422 install_element(BGP_NODE, &neighbor_passive_cmd);
18423 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18424
18425
18426 /* "neighbor shutdown" commands. */
18427 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18428 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18429 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18430 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
18431 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18432 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 18433
18434 /* "neighbor capability extended-nexthop" commands.*/
18435 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18436 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18437
18438 /* "neighbor capability orf prefix-list" commands.*/
18439 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18440 install_element(BGP_NODE,
18441 &no_neighbor_capability_orf_prefix_hidden_cmd);
18442 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18443 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18444 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18445 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18446 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18447 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18448 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18449 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18450 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18451 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18452 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18453 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18454
18455 /* "neighbor capability dynamic" commands.*/
18456 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18457 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18458
18459 /* "neighbor dont-capability-negotiate" commands. */
18460 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18461 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18462
18463 /* "neighbor ebgp-multihop" commands. */
18464 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18465 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18466 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18467
18468 /* "neighbor disable-connected-check" commands. */
18469 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18470 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18471
7ab294ea
DA
18472 /* "neighbor disable-link-bw-encoding-ieee" commands. */
18473 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
18474 install_element(BGP_NODE,
18475 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
27aa23a4 18476
d08c0c80
DA
18477 /* "neighbor extended-optional-parameters" commands. */
18478 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
18479 install_element(BGP_NODE,
18480 &no_neighbor_extended_optional_parameters_cmd);
18481
47cbc09b
PM
18482 /* "neighbor enforce-first-as" commands. */
18483 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18484 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18485
d62a17ae 18486 /* "neighbor description" commands. */
18487 install_element(BGP_NODE, &neighbor_description_cmd);
18488 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 18489 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 18490
18491 /* "neighbor update-source" commands. "*/
18492 install_element(BGP_NODE, &neighbor_update_source_cmd);
18493 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18494
18495 /* "neighbor default-originate" commands. */
18496 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18497 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18498 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18499 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18500 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18501 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18502 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18503 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18504 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18505 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18506 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18507 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18508 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18509 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18510 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18511 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18512 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18513 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18514 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18515 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18516 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18517
18518 /* "neighbor port" commands. */
18519 install_element(BGP_NODE, &neighbor_port_cmd);
18520 install_element(BGP_NODE, &no_neighbor_port_cmd);
18521
18522 /* "neighbor weight" commands. */
18523 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18524 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18525
18526 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18527 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18528 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18529 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18530 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18531 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18532 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18533 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18534 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18535 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18536 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18537 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18538 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18539 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18540 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18541 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18542
18543 /* "neighbor override-capability" commands. */
18544 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18545 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18546
18547 /* "neighbor strict-capability-match" commands. */
18548 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18549 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18550
18551 /* "neighbor timers" commands. */
18552 install_element(BGP_NODE, &neighbor_timers_cmd);
18553 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18554
18555 /* "neighbor timers connect" commands. */
18556 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18557 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18558
d43114f3
DS
18559 /* "neighbor timers delayopen" commands. */
18560 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18561 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18562
d62a17ae 18563 /* "neighbor advertisement-interval" commands. */
18564 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18565 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18566
18567 /* "neighbor interface" commands. */
18568 install_element(BGP_NODE, &neighbor_interface_cmd);
18569 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18570
18571 /* "neighbor distribute" commands. */
18572 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18573 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18574 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18575 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18576 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18577 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18578 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18579 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18580 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18581 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18582 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18583 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18584 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18585 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18586 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18587 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18588 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18589 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18590
18591 /* "neighbor prefix-list" commands. */
18592 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
642ef664 18593 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
d62a17ae 18594 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18595 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18596 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
642ef664 18597 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18598 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
642ef664 18599 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18600 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18601 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18602 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
642ef664 18603 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18604 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
642ef664 18605 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18606 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18607 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18608 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18609 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18610 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18611 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18612 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18613 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18614
18615 /* "neighbor filter-list" commands. */
18616 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18617 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18618 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18619 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18620 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18621 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18622 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18623 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18624 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18625 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18626 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18627 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18628 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18629 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18630 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18631 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18632 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18633 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 18634 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18635 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18636 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18637 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 18638
18639 /* "neighbor route-map" commands. */
d6d7ed37
IR
18640 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18641 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
d62a17ae 18642 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18643 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18644 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
0ea8d871 18645 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18646 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
0ea8d871 18647 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18648 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18649 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18650 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
0ea8d871 18651 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18652 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
0ea8d871 18653 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18654 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18655 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18656 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18657 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18658 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18659 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18660 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18661 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549 18662 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
0ea8d871 18663 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18664
18665 /* "neighbor unsuppress-map" commands. */
18666 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18667 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18668 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18669 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18670 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18671 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18672 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18673 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18674 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18675 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18676 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18677 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18678 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18679 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18680 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18681 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18682 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18683 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18684
7f7940e6 18685 /* "neighbor advertise-map" commands. */
389e4f92 18686 install_element(BGP_NODE, &bgp_condadv_period_cmd);
7f7940e6 18687 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 18688 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18689 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18690 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18691 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18692 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18693 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18694 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18695 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18696
fde246e8
DA
18697 /* neighbor maximum-prefix-out commands. */
18698 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18699 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18700 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18701 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18702 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18703 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18704 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18705 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18706 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18707 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18708 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18709 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18710 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18711 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18712 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18713 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18714 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18715 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18716
d62a17ae 18717 /* "neighbor maximum-prefix" commands. */
18718 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18719 install_element(BGP_NODE,
18720 &neighbor_maximum_prefix_threshold_hidden_cmd);
18721 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18722 install_element(BGP_NODE,
18723 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18724 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18725 install_element(BGP_NODE,
18726 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18727 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18728 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18729 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18730 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18731 install_element(BGP_IPV4_NODE,
18732 &neighbor_maximum_prefix_threshold_warning_cmd);
18733 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18734 install_element(BGP_IPV4_NODE,
18735 &neighbor_maximum_prefix_threshold_restart_cmd);
18736 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18737 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18738 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18739 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18740 install_element(BGP_IPV4M_NODE,
18741 &neighbor_maximum_prefix_threshold_warning_cmd);
18742 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18743 install_element(BGP_IPV4M_NODE,
18744 &neighbor_maximum_prefix_threshold_restart_cmd);
18745 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18746 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18747 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18748 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18749 install_element(BGP_IPV4L_NODE,
18750 &neighbor_maximum_prefix_threshold_warning_cmd);
18751 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18752 install_element(BGP_IPV4L_NODE,
18753 &neighbor_maximum_prefix_threshold_restart_cmd);
18754 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18755 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18756 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18757 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18758 install_element(BGP_IPV6_NODE,
18759 &neighbor_maximum_prefix_threshold_warning_cmd);
18760 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18761 install_element(BGP_IPV6_NODE,
18762 &neighbor_maximum_prefix_threshold_restart_cmd);
18763 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18764 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18765 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18766 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18767 install_element(BGP_IPV6M_NODE,
18768 &neighbor_maximum_prefix_threshold_warning_cmd);
18769 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18770 install_element(BGP_IPV6M_NODE,
18771 &neighbor_maximum_prefix_threshold_restart_cmd);
18772 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18773 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18774 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18775 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18776 install_element(BGP_IPV6L_NODE,
18777 &neighbor_maximum_prefix_threshold_warning_cmd);
18778 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18779 install_element(BGP_IPV6L_NODE,
18780 &neighbor_maximum_prefix_threshold_restart_cmd);
18781 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18782 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18783 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18784 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18785 install_element(BGP_VPNV4_NODE,
18786 &neighbor_maximum_prefix_threshold_warning_cmd);
18787 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18788 install_element(BGP_VPNV4_NODE,
18789 &neighbor_maximum_prefix_threshold_restart_cmd);
18790 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18791 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18792 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18793 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18794 install_element(BGP_VPNV6_NODE,
18795 &neighbor_maximum_prefix_threshold_warning_cmd);
18796 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18797 install_element(BGP_VPNV6_NODE,
18798 &neighbor_maximum_prefix_threshold_restart_cmd);
18799 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18800
18801 /* "neighbor allowas-in" */
18802 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18803 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18804 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18805 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18806 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18807 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18808 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18809 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18810 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18811 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18812 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18813 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18814 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18815 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18816 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18817 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18818 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18819 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18820 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18821 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18822
18823 /* address-family commands. */
18824 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18825 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 18826#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 18827 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18828 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 18829#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 18830
d62a17ae 18831 install_element(BGP_NODE, &address_family_evpn_cmd);
18832
18833 /* "exit-address-family" command. */
18834 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18835 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18836 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18837 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18838 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18839 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18840 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18841 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 18842 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18843 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 18844 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18845
18846 /* "clear ip bgp commands" */
18847 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18848
18849 /* clear ip bgp prefix */
18850 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18851 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18852 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18853
18854 /* "show [ip] bgp summary" commands. */
18855 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 18856 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 18857 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 18858 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 18859 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18860 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 18861 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18862
18863 /* "show [ip] bgp neighbors" commands. */
18864 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18865
36235319 18866 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 18867
d62a17ae 18868 /* "show [ip] bgp peer-group" commands. */
18869 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18870
18871 /* "show [ip] bgp paths" commands. */
18872 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18873
18874 /* "show [ip] bgp community" commands. */
18875 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18876
18877 /* "show ip bgp large-community" commands. */
18878 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18879 /* "show [ip] bgp attribute-info" commands. */
18880 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 18881 /* "show [ip] bgp route-leak" command */
18882 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 18883
18884 /* "redistribute" commands. */
18885 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18886 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18887 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18888 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18889 install_element(BGP_NODE,
18890 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18891 install_element(BGP_NODE,
18892 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18893 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18894 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18895 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18896 install_element(BGP_NODE,
18897 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18898 install_element(BGP_NODE,
18899 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18900 install_element(BGP_NODE,
18901 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18902 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18903 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18904 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18905 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18906 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18907 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18908 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18909 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18910 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18911 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18912 install_element(BGP_IPV4_NODE,
18913 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18914 install_element(BGP_IPV4_NODE,
18915 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18916 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18917 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18918 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18919 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18920 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18921 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18922
b9c7bc5a
PZ
18923 /* import|export vpn [route-map WORD] */
18924 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18925 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 18926
12a844a5
DS
18927 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18928 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18929
d62a17ae 18930 /* ttl_security commands */
18931 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18932 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18933
18934 /* "show [ip] bgp memory" commands. */
18935 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18936
acf71666
MK
18937 /* "show bgp martian next-hop" */
18938 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18939
48ecf8f5
DS
18940 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18941
d62a17ae 18942 /* "show [ip] bgp views" commands. */
18943 install_element(VIEW_NODE, &show_bgp_views_cmd);
18944
18945 /* "show [ip] bgp vrfs" commands. */
18946 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
18947
18948 /* Community-list. */
18949 community_list_vty();
ddb5b488 18950
ed0e57e3
DA
18951 community_alias_vty();
18952
ddb5b488 18953 /* vpn-policy commands */
b9c7bc5a
PZ
18954 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
18955 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
18956 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
18957 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
18958 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
18959 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
18960 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
18961 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
18962 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
18963 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
18964 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
18965 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 18966
301ad80a
PG
18967 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
18968 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
18969
b9c7bc5a
PZ
18970 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
18971 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
18972 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
18973 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
18974 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
18975 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
18976 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
18977 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
18978 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
18979 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
18980
18981 /* tcp-mss command */
18982 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
18983 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
18984
18985 /* srv6 commands */
ea372e81 18986 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
bfaab44d 18987 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
0249b8b6 18988 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
a0281b2e 18989 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
0249b8b6 18990 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
b72c9e14
HS
18991 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
18992 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
718e3744 18993}
6b0655a2 18994
718e3744 18995#include "memory.h"
18996#include "bgp_regex.h"
18997#include "bgp_clist.h"
18998#include "bgp_ecommunity.h"
18999
19000/* VTY functions. */
19001
19002/* Direction value to string conversion. */
d62a17ae 19003static const char *community_direct_str(int direct)
19004{
19005 switch (direct) {
19006 case COMMUNITY_DENY:
19007 return "deny";
19008 case COMMUNITY_PERMIT:
19009 return "permit";
19010 default:
19011 return "unknown";
19012 }
718e3744 19013}
19014
19015/* Display error string. */
d62a17ae 19016static void community_list_perror(struct vty *vty, int ret)
19017{
19018 switch (ret) {
19019 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19020 vty_out(vty, "%% Can't find community-list\n");
19021 break;
19022 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19023 vty_out(vty, "%% Malformed community-list value\n");
19024 break;
19025 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19026 vty_out(vty,
19027 "%% Community name conflict, previously defined as standard community\n");
19028 break;
19029 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19030 vty_out(vty,
19031 "%% Community name conflict, previously defined as expanded community\n");
19032 break;
19033 }
718e3744 19034}
19035
5bf15956
DW
19036/* "community-list" keyword help string. */
19037#define COMMUNITY_LIST_STR "Add a community list entry\n"
19038
7336e101
SP
19039/*community-list standard */
19040DEFUN (community_list_standard,
19041 bgp_community_list_standard_cmd,
a2099c1d 19042 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19043 BGP_STR
718e3744 19044 COMMUNITY_LIST_STR
19045 "Community list number (standard)\n"
5bf15956 19046 "Add an standard community-list entry\n"
718e3744 19047 "Community list name\n"
2f8cc0e5
DA
19048 "Sequence number of an entry\n"
19049 "Sequence number\n"
718e3744 19050 "Specify community to reject\n"
19051 "Specify community to accept\n"
19052 COMMUNITY_VAL_STR)
19053{
d62a17ae 19054 char *cl_name_or_number = NULL;
2f8cc0e5 19055 char *seq = NULL;
d62a17ae 19056 int direct = 0;
19057 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 19058 int idx = 0;
7336e101 19059
a08032fe 19060 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19061 if (idx)
19062 seq = argv[idx]->arg;
19063
19064 idx = 0;
d62a17ae 19065 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19066 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19067 cl_name_or_number = argv[idx]->arg;
19068 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19069 : COMMUNITY_DENY;
19070 argv_find(argv, argc, "AA:NN", &idx);
19071 char *str = argv_concat(argv, argc, idx);
42f914d4 19072
2f8cc0e5
DA
19073 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19074 direct, style);
42f914d4 19075
d62a17ae 19076 XFREE(MTYPE_TMP, str);
42f914d4 19077
d62a17ae 19078 if (ret < 0) {
19079 /* Display error string. */
19080 community_list_perror(vty, ret);
19081 return CMD_WARNING_CONFIG_FAILED;
19082 }
42f914d4 19083
d62a17ae 19084 return CMD_SUCCESS;
718e3744 19085}
19086
7336e101
SP
19087DEFUN (no_community_list_standard_all,
19088 no_bgp_community_list_standard_all_cmd,
a2099c1d 19089 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19090 NO_STR
19091 BGP_STR
19092 COMMUNITY_LIST_STR
19093 "Community list number (standard)\n"
19094 "Add an standard community-list entry\n"
19095 "Community list name\n"
2f8cc0e5
DA
19096 "Sequence number of an entry\n"
19097 "Sequence number\n"
7336e101
SP
19098 "Specify community to reject\n"
19099 "Specify community to accept\n"
19100 COMMUNITY_VAL_STR)
718e3744 19101{
d62a17ae 19102 char *cl_name_or_number = NULL;
174b5cb9 19103 char *str = NULL;
d62a17ae 19104 int direct = 0;
19105 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 19106 char *seq = NULL;
d62a17ae 19107 int idx = 0;
7336e101 19108
a08032fe 19109 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19110 if (idx)
19111 seq = argv[idx]->arg;
19112
19113 idx = 0;
174b5cb9
DA
19114 argv_find(argv, argc, "permit", &idx);
19115 argv_find(argv, argc, "deny", &idx);
19116
19117 if (idx) {
19118 direct = argv_find(argv, argc, "permit", &idx)
19119 ? COMMUNITY_PERMIT
19120 : COMMUNITY_DENY;
19121
19122 idx = 0;
19123 argv_find(argv, argc, "AA:NN", &idx);
19124 str = argv_concat(argv, argc, idx);
19125 }
19126
19127 idx = 0;
d62a17ae 19128 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19129 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19130 cl_name_or_number = argv[idx]->arg;
42f914d4 19131
2f8cc0e5 19132 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19133 direct, style);
42f914d4 19134
d62a17ae 19135 XFREE(MTYPE_TMP, str);
daf9ddbb 19136
d62a17ae 19137 if (ret < 0) {
19138 community_list_perror(vty, ret);
19139 return CMD_WARNING_CONFIG_FAILED;
19140 }
42f914d4 19141
d62a17ae 19142 return CMD_SUCCESS;
718e3744 19143}
7336e101 19144
174b5cb9 19145ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
a2099c1d 19146 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
174b5cb9
DA
19147 NO_STR BGP_STR COMMUNITY_LIST_STR
19148 "Community list number (standard)\n"
19149 "Add an standard community-list entry\n"
19150 "Community list name\n")
19151
7336e101
SP
19152/*community-list expanded */
19153DEFUN (community_list_expanded_all,
19154 bgp_community_list_expanded_all_cmd,
a2099c1d 19155 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19156 BGP_STR
19157 COMMUNITY_LIST_STR
718e3744 19158 "Community list number (expanded)\n"
5bf15956 19159 "Add an expanded community-list entry\n"
718e3744 19160 "Community list name\n"
2f8cc0e5
DA
19161 "Sequence number of an entry\n"
19162 "Sequence number\n"
718e3744 19163 "Specify community to reject\n"
19164 "Specify community to accept\n"
19165 COMMUNITY_VAL_STR)
19166{
d62a17ae 19167 char *cl_name_or_number = NULL;
2f8cc0e5 19168 char *seq = NULL;
d62a17ae 19169 int direct = 0;
19170 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19171 int idx = 0;
7b9a4750 19172
a08032fe 19173 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19174 if (idx)
19175 seq = argv[idx]->arg;
19176
19177 idx = 0;
19178
d62a17ae 19179 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19180 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19181 cl_name_or_number = argv[idx]->arg;
19182 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19183 : COMMUNITY_DENY;
19184 argv_find(argv, argc, "AA:NN", &idx);
19185 char *str = argv_concat(argv, argc, idx);
42f914d4 19186
2f8cc0e5
DA
19187 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19188 direct, style);
42f914d4 19189
d62a17ae 19190 XFREE(MTYPE_TMP, str);
42f914d4 19191
d62a17ae 19192 if (ret < 0) {
19193 /* Display error string. */
19194 community_list_perror(vty, ret);
19195 return CMD_WARNING_CONFIG_FAILED;
19196 }
42f914d4 19197
d62a17ae 19198 return CMD_SUCCESS;
718e3744 19199}
19200
7336e101
SP
19201DEFUN (no_community_list_expanded_all,
19202 no_bgp_community_list_expanded_all_cmd,
a2099c1d 19203 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19204 NO_STR
19205 BGP_STR
19206 COMMUNITY_LIST_STR
19207 "Community list number (expanded)\n"
19208 "Add an expanded community-list entry\n"
19209 "Community list name\n"
2f8cc0e5
DA
19210 "Sequence number of an entry\n"
19211 "Sequence number\n"
7336e101
SP
19212 "Specify community to reject\n"
19213 "Specify community to accept\n"
19214 COMMUNITY_VAL_STR)
718e3744 19215{
d62a17ae 19216 char *cl_name_or_number = NULL;
2f8cc0e5 19217 char *seq = NULL;
174b5cb9 19218 char *str = NULL;
d62a17ae 19219 int direct = 0;
19220 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19221 int idx = 0;
174b5cb9 19222
a08032fe 19223 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19224 if (idx)
19225 seq = argv[idx]->arg;
19226
19227 idx = 0;
174b5cb9
DA
19228 argv_find(argv, argc, "permit", &idx);
19229 argv_find(argv, argc, "deny", &idx);
19230
19231 if (idx) {
19232 direct = argv_find(argv, argc, "permit", &idx)
19233 ? COMMUNITY_PERMIT
19234 : COMMUNITY_DENY;
19235
19236 idx = 0;
19237 argv_find(argv, argc, "AA:NN", &idx);
19238 str = argv_concat(argv, argc, idx);
7336e101 19239 }
174b5cb9
DA
19240
19241 idx = 0;
d62a17ae 19242 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19243 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19244 cl_name_or_number = argv[idx]->arg;
42f914d4 19245
2f8cc0e5 19246 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19247 direct, style);
42f914d4 19248
d62a17ae 19249 XFREE(MTYPE_TMP, str);
daf9ddbb 19250
d62a17ae 19251 if (ret < 0) {
19252 community_list_perror(vty, ret);
19253 return CMD_WARNING_CONFIG_FAILED;
19254 }
42f914d4 19255
d62a17ae 19256 return CMD_SUCCESS;
718e3744 19257}
19258
36d4bb44
EB
19259ALIAS(no_community_list_expanded_all,
19260 no_bgp_community_list_expanded_all_list_cmd,
a2099c1d 19261 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
36d4bb44 19262 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
19263 "Community list number (expanded)\n"
19264 "Add an expanded community-list entry\n"
19265 "Community list name\n")
19266
8d9b8ed9
PM
19267/* Return configuration string of community-list entry. */
19268static const char *community_list_config_str(struct community_entry *entry)
19269{
19270 const char *str;
19271
19272 if (entry->any)
19273 str = "";
19274 else {
19275 if (entry->style == COMMUNITY_LIST_STANDARD)
19276 str = community_str(entry->u.com, false);
19277 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19278 str = lcommunity_str(entry->u.lcom, false);
19279 else
19280 str = entry->config;
19281 }
19282 return str;
19283}
19284
d62a17ae 19285static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 19286{
d62a17ae 19287 struct community_entry *entry;
718e3744 19288
d62a17ae 19289 for (entry = list->head; entry; entry = entry->next) {
19290 if (entry == list->head) {
19291 if (all_digit(list->name))
19292 vty_out(vty, "Community %s list %s\n",
19293 entry->style == COMMUNITY_LIST_STANDARD
19294 ? "standard"
19295 : "(expanded) access",
19296 list->name);
19297 else
19298 vty_out(vty, "Named Community %s list %s\n",
19299 entry->style == COMMUNITY_LIST_STANDARD
19300 ? "standard"
19301 : "expanded",
19302 list->name);
19303 }
19304 if (entry->any)
19305 vty_out(vty, " %s\n",
19306 community_direct_str(entry->direct));
19307 else
19308 vty_out(vty, " %s %s\n",
19309 community_direct_str(entry->direct),
8d9b8ed9 19310 community_list_config_str(entry));
d62a17ae 19311 }
718e3744 19312}
19313
7336e101
SP
19314DEFUN (show_community_list,
19315 show_bgp_community_list_cmd,
19316 "show bgp community-list",
718e3744 19317 SHOW_STR
7336e101 19318 BGP_STR
718e3744 19319 "List community-list\n")
19320{
d62a17ae 19321 struct community_list *list;
19322 struct community_list_master *cm;
718e3744 19323
d62a17ae 19324 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19325 if (!cm)
19326 return CMD_SUCCESS;
718e3744 19327
d62a17ae 19328 for (list = cm->num.head; list; list = list->next)
19329 community_list_show(vty, list);
718e3744 19330
d62a17ae 19331 for (list = cm->str.head; list; list = list->next)
19332 community_list_show(vty, list);
718e3744 19333
d62a17ae 19334 return CMD_SUCCESS;
718e3744 19335}
19336
7336e101
SP
19337DEFUN (show_community_list_arg,
19338 show_bgp_community_list_arg_cmd,
a2099c1d 19339 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
7336e101
SP
19340 SHOW_STR
19341 BGP_STR
718e3744 19342 "List community-list\n"
19343 "Community-list number\n"
960b69b9 19344 "Community-list name\n"
19345 "Detailed information on community-list\n")
718e3744 19346{
d62a17ae 19347 int idx_comm_list = 3;
19348 struct community_list *list;
718e3744 19349
e237b0d2 19350 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19351 COMMUNITY_LIST_MASTER);
19352 if (!list) {
19353 vty_out(vty, "%% Can't find community-list\n");
19354 return CMD_WARNING;
19355 }
718e3744 19356
d62a17ae 19357 community_list_show(vty, list);
718e3744 19358
d62a17ae 19359 return CMD_SUCCESS;
718e3744 19360}
6b0655a2 19361
57d187bc
JS
19362/*
19363 * Large Community code.
19364 */
d62a17ae 19365static int lcommunity_list_set_vty(struct vty *vty, int argc,
19366 struct cmd_token **argv, int style,
19367 int reject_all_digit_name)
19368{
19369 int ret;
19370 int direct;
19371 char *str;
19372 int idx = 0;
19373 char *cl_name;
2f8cc0e5
DA
19374 char *seq = NULL;
19375
a08032fe 19376 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19377 seq = argv[idx]->arg;
d62a17ae 19378
2f8cc0e5 19379 idx = 0;
d62a17ae 19380 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19381 : COMMUNITY_DENY;
19382
19383 /* All digit name check. */
19384 idx = 0;
a2099c1d 19385 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19386 argv_find(argv, argc, "(1-99)", &idx);
19387 argv_find(argv, argc, "(100-500)", &idx);
19388 cl_name = argv[idx]->arg;
19389 if (reject_all_digit_name && all_digit(cl_name)) {
19390 vty_out(vty, "%% Community name cannot have all digits\n");
19391 return CMD_WARNING_CONFIG_FAILED;
19392 }
19393
19394 idx = 0;
19395 argv_find(argv, argc, "AA:BB:CC", &idx);
19396 argv_find(argv, argc, "LINE", &idx);
19397 /* Concat community string argument. */
19398 if (idx)
19399 str = argv_concat(argv, argc, idx);
19400 else
19401 str = NULL;
19402
2f8cc0e5 19403 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 19404
19405 /* Free temporary community list string allocated by
19406 argv_concat(). */
0a22ddfb 19407 XFREE(MTYPE_TMP, str);
d62a17ae 19408
19409 if (ret < 0) {
19410 community_list_perror(vty, ret);
19411 return CMD_WARNING_CONFIG_FAILED;
19412 }
19413 return CMD_SUCCESS;
19414}
19415
19416static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19417 struct cmd_token **argv, int style)
19418{
19419 int ret;
19420 int direct = 0;
19421 char *str = NULL;
19422 int idx = 0;
2f8cc0e5 19423 char *seq = NULL;
d62a17ae 19424
a08032fe 19425 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19426 seq = argv[idx]->arg;
d62a17ae 19427
2f8cc0e5 19428 idx = 0;
d62a17ae 19429 argv_find(argv, argc, "permit", &idx);
19430 argv_find(argv, argc, "deny", &idx);
19431
19432 if (idx) {
19433 /* Check the list direct. */
19434 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19435 direct = COMMUNITY_PERMIT;
19436 else
19437 direct = COMMUNITY_DENY;
19438
19439 idx = 0;
19440 argv_find(argv, argc, "LINE", &idx);
19441 argv_find(argv, argc, "AA:AA:NN", &idx);
19442 /* Concat community string argument. */
19443 str = argv_concat(argv, argc, idx);
19444 }
19445
19446 idx = 0;
19447 argv_find(argv, argc, "(1-99)", &idx);
19448 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19449 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19450
19451 /* Unset community list. */
2f8cc0e5 19452 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 19453 style);
19454
19455 /* Free temporary community list string allocated by
19456 argv_concat(). */
0a22ddfb 19457 XFREE(MTYPE_TMP, str);
d62a17ae 19458
19459 if (ret < 0) {
19460 community_list_perror(vty, ret);
19461 return CMD_WARNING_CONFIG_FAILED;
19462 }
19463
19464 return CMD_SUCCESS;
57d187bc
JS
19465}
19466
19467/* "large-community-list" keyword help string. */
19468#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19469#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19470
7336e101
SP
19471DEFUN (lcommunity_list_standard,
19472 bgp_lcommunity_list_standard_cmd,
a08032fe 19473 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19474 BGP_STR
19475 LCOMMUNITY_LIST_STR
19476 "Large Community list number (standard)\n"
2f8cc0e5
DA
19477 "Sequence number of an entry\n"
19478 "Sequence number\n"
7336e101
SP
19479 "Specify large community to reject\n"
19480 "Specify large community to accept\n"
19481 LCOMMUNITY_VAL_STR)
52951b63 19482{
d62a17ae 19483 return lcommunity_list_set_vty(vty, argc, argv,
19484 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
19485}
19486
7336e101
SP
19487DEFUN (lcommunity_list_expanded,
19488 bgp_lcommunity_list_expanded_cmd,
a08032fe 19489 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19490 BGP_STR
19491 LCOMMUNITY_LIST_STR
19492 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19493 "Sequence number of an entry\n"
19494 "Sequence number\n"
7336e101
SP
19495 "Specify large community to reject\n"
19496 "Specify large community to accept\n"
19497 "An ordered list as a regular-expression\n")
57d187bc 19498{
d62a17ae 19499 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19500 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
19501}
19502
7336e101
SP
19503DEFUN (lcommunity_list_name_standard,
19504 bgp_lcommunity_list_name_standard_cmd,
a2099c1d 19505 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19506 BGP_STR
19507 LCOMMUNITY_LIST_STR
19508 "Specify standard large-community-list\n"
19509 "Large Community list name\n"
2f8cc0e5
DA
19510 "Sequence number of an entry\n"
19511 "Sequence number\n"
7336e101
SP
19512 "Specify large community to reject\n"
19513 "Specify large community to accept\n"
19514 LCOMMUNITY_VAL_STR)
52951b63 19515{
d62a17ae 19516 return lcommunity_list_set_vty(vty, argc, argv,
19517 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
19518}
19519
7336e101
SP
19520DEFUN (lcommunity_list_name_expanded,
19521 bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 19522 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19523 BGP_STR
19524 LCOMMUNITY_LIST_STR
19525 "Specify expanded large-community-list\n"
19526 "Large Community list name\n"
2f8cc0e5
DA
19527 "Sequence number of an entry\n"
19528 "Sequence number\n"
7336e101
SP
19529 "Specify large community to reject\n"
19530 "Specify large community to accept\n"
19531 "An ordered list as a regular-expression\n")
57d187bc 19532{
d62a17ae 19533 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19534 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
19535}
19536
4378f57c
DA
19537DEFUN (no_lcommunity_list_all,
19538 no_bgp_lcommunity_list_all_cmd,
a2099c1d 19539 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
7336e101
SP
19540 NO_STR
19541 BGP_STR
19542 LCOMMUNITY_LIST_STR
19543 "Large Community list number (standard)\n"
19544 "Large Community list number (expanded)\n"
19545 "Large Community list name\n")
57d187bc 19546{
7336e101
SP
19547 return lcommunity_list_unset_vty(vty, argc, argv,
19548 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19549}
19550
4378f57c
DA
19551DEFUN (no_lcommunity_list_name_standard_all,
19552 no_bgp_lcommunity_list_name_standard_all_cmd,
a2099c1d 19553 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
4378f57c
DA
19554 NO_STR
19555 BGP_STR
19556 LCOMMUNITY_LIST_STR
19557 "Specify standard large-community-list\n"
19558 "Large Community list name\n")
19559{
19560 return lcommunity_list_unset_vty(vty, argc, argv,
19561 LARGE_COMMUNITY_LIST_STANDARD);
19562}
19563
7336e101
SP
19564DEFUN (no_lcommunity_list_name_expanded_all,
19565 no_bgp_lcommunity_list_name_expanded_all_cmd,
a2099c1d 19566 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
7336e101
SP
19567 NO_STR
19568 BGP_STR
19569 LCOMMUNITY_LIST_STR
19570 "Specify expanded large-community-list\n"
19571 "Large Community list name\n")
57d187bc 19572{
d62a17ae 19573 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19574 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19575}
19576
7336e101
SP
19577DEFUN (no_lcommunity_list_standard,
19578 no_bgp_lcommunity_list_standard_cmd,
a08032fe 19579 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19580 NO_STR
19581 BGP_STR
19582 LCOMMUNITY_LIST_STR
19583 "Large Community list number (standard)\n"
2f8cc0e5
DA
19584 "Sequence number of an entry\n"
19585 "Sequence number\n"
7336e101
SP
19586 "Specify large community to reject\n"
19587 "Specify large community to accept\n"
19588 LCOMMUNITY_VAL_STR)
57d187bc 19589{
d62a17ae 19590 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19591 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19592}
19593
7336e101
SP
19594DEFUN (no_lcommunity_list_expanded,
19595 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 19596 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19597 NO_STR
19598 BGP_STR
19599 LCOMMUNITY_LIST_STR
19600 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19601 "Sequence number of an entry\n"
19602 "Sequence number\n"
7336e101
SP
19603 "Specify large community to reject\n"
19604 "Specify large community to accept\n"
19605 "An ordered list as a regular-expression\n")
57d187bc 19606{
d62a17ae 19607 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19608 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19609}
19610
7336e101
SP
19611DEFUN (no_lcommunity_list_name_standard,
19612 no_bgp_lcommunity_list_name_standard_cmd,
a2099c1d 19613 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19614 NO_STR
19615 BGP_STR
19616 LCOMMUNITY_LIST_STR
19617 "Specify standard large-community-list\n"
19618 "Large Community list name\n"
2f8cc0e5
DA
19619 "Sequence number of an entry\n"
19620 "Sequence number\n"
7336e101
SP
19621 "Specify large community to reject\n"
19622 "Specify large community to accept\n"
19623 LCOMMUNITY_VAL_STR)
57d187bc 19624{
d62a17ae 19625 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19626 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19627}
19628
7336e101
SP
19629DEFUN (no_lcommunity_list_name_expanded,
19630 no_bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 19631 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19632 NO_STR
19633 BGP_STR
19634 LCOMMUNITY_LIST_STR
19635 "Specify expanded large-community-list\n"
19636 "Large community list name\n"
2f8cc0e5
DA
19637 "Sequence number of an entry\n"
19638 "Sequence number\n"
7336e101
SP
19639 "Specify large community to reject\n"
19640 "Specify large community to accept\n"
19641 "An ordered list as a regular-expression\n")
57d187bc 19642{
d62a17ae 19643 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19644 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19645}
19646
d62a17ae 19647static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19648{
19649 struct community_entry *entry;
19650
19651 for (entry = list->head; entry; entry = entry->next) {
19652 if (entry == list->head) {
19653 if (all_digit(list->name))
19654 vty_out(vty, "Large community %s list %s\n",
169b72c8 19655 entry->style ==
19656 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19657 ? "standard"
19658 : "(expanded) access",
19659 list->name);
19660 else
19661 vty_out(vty,
19662 "Named large community %s list %s\n",
169b72c8 19663 entry->style ==
19664 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19665 ? "standard"
19666 : "expanded",
19667 list->name);
19668 }
19669 if (entry->any)
19670 vty_out(vty, " %s\n",
19671 community_direct_str(entry->direct));
19672 else
19673 vty_out(vty, " %s %s\n",
19674 community_direct_str(entry->direct),
8d9b8ed9 19675 community_list_config_str(entry));
d62a17ae 19676 }
57d187bc
JS
19677}
19678
7336e101
SP
19679DEFUN (show_lcommunity_list,
19680 show_bgp_lcommunity_list_cmd,
19681 "show bgp large-community-list",
57d187bc 19682 SHOW_STR
7336e101 19683 BGP_STR
57d187bc
JS
19684 "List large-community list\n")
19685{
d62a17ae 19686 struct community_list *list;
19687 struct community_list_master *cm;
57d187bc 19688
d62a17ae 19689 cm = community_list_master_lookup(bgp_clist,
19690 LARGE_COMMUNITY_LIST_MASTER);
19691 if (!cm)
19692 return CMD_SUCCESS;
57d187bc 19693
d62a17ae 19694 for (list = cm->num.head; list; list = list->next)
19695 lcommunity_list_show(vty, list);
57d187bc 19696
d62a17ae 19697 for (list = cm->str.head; list; list = list->next)
19698 lcommunity_list_show(vty, list);
57d187bc 19699
d62a17ae 19700 return CMD_SUCCESS;
57d187bc
JS
19701}
19702
7336e101
SP
19703DEFUN (show_lcommunity_list_arg,
19704 show_bgp_lcommunity_list_arg_cmd,
a2099c1d 19705 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
7336e101
SP
19706 SHOW_STR
19707 BGP_STR
57d187bc 19708 "List large-community list\n"
960b69b9 19709 "Large-community-list number\n"
19710 "Large-community-list name\n"
19711 "Detailed information on large-community-list\n")
57d187bc 19712{
d62a17ae 19713 struct community_list *list;
57d187bc 19714
e237b0d2 19715 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 19716 LARGE_COMMUNITY_LIST_MASTER);
19717 if (!list) {
960b69b9 19718 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 19719 return CMD_WARNING;
19720 }
57d187bc 19721
d62a17ae 19722 lcommunity_list_show(vty, list);
57d187bc 19723
d62a17ae 19724 return CMD_SUCCESS;
57d187bc
JS
19725}
19726
718e3744 19727/* "extcommunity-list" keyword help string. */
19728#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19729#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19730
7336e101
SP
19731DEFUN (extcommunity_list_standard,
19732 bgp_extcommunity_list_standard_cmd,
a2099c1d 19733 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19734 BGP_STR
718e3744 19735 EXTCOMMUNITY_LIST_STR
19736 "Extended Community list number (standard)\n"
718e3744 19737 "Specify standard extcommunity-list\n"
5bf15956 19738 "Community list name\n"
2f8cc0e5
DA
19739 "Sequence number of an entry\n"
19740 "Sequence number\n"
718e3744 19741 "Specify community to reject\n"
19742 "Specify community to accept\n"
19743 EXTCOMMUNITY_VAL_STR)
19744{
d62a17ae 19745 int style = EXTCOMMUNITY_LIST_STANDARD;
19746 int direct = 0;
19747 char *cl_number_or_name = NULL;
2f8cc0e5 19748 char *seq = NULL;
42f914d4 19749
d62a17ae 19750 int idx = 0;
7b9a4750 19751
d62a17ae 19752 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19753 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19754 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19755
a08032fe 19756 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19757 seq = argv[idx]->arg;
19758
d62a17ae 19759 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19760 : COMMUNITY_DENY;
19761 argv_find(argv, argc, "AA:NN", &idx);
19762 char *str = argv_concat(argv, argc, idx);
42f914d4 19763
2f8cc0e5 19764 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19765 direct, style);
42f914d4 19766
d62a17ae 19767 XFREE(MTYPE_TMP, str);
42f914d4 19768
d62a17ae 19769 if (ret < 0) {
19770 community_list_perror(vty, ret);
19771 return CMD_WARNING_CONFIG_FAILED;
19772 }
42f914d4 19773
d62a17ae 19774 return CMD_SUCCESS;
718e3744 19775}
19776
7336e101
SP
19777DEFUN (extcommunity_list_name_expanded,
19778 bgp_extcommunity_list_name_expanded_cmd,
a2099c1d 19779 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19780 BGP_STR
19781 EXTCOMMUNITY_LIST_STR
5bf15956 19782 "Extended Community list number (expanded)\n"
718e3744 19783 "Specify expanded extcommunity-list\n"
19784 "Extended Community list name\n"
2f8cc0e5
DA
19785 "Sequence number of an entry\n"
19786 "Sequence number\n"
718e3744 19787 "Specify community to reject\n"
19788 "Specify community to accept\n"
19789 "An ordered list as a regular-expression\n")
19790{
d62a17ae 19791 int style = EXTCOMMUNITY_LIST_EXPANDED;
19792 int direct = 0;
19793 char *cl_number_or_name = NULL;
2f8cc0e5 19794 char *seq = NULL;
d62a17ae 19795 int idx = 0;
7336e101 19796
d62a17ae 19797 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19798 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19799 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19800
a08032fe 19801 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19802 seq = argv[idx]->arg;
19803
d62a17ae 19804 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19805 : COMMUNITY_DENY;
19806 argv_find(argv, argc, "LINE", &idx);
19807 char *str = argv_concat(argv, argc, idx);
42f914d4 19808
2f8cc0e5 19809 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19810 direct, style);
42f914d4 19811
d62a17ae 19812 XFREE(MTYPE_TMP, str);
42f914d4 19813
d62a17ae 19814 if (ret < 0) {
19815 community_list_perror(vty, ret);
19816 return CMD_WARNING_CONFIG_FAILED;
19817 }
42f914d4 19818
d62a17ae 19819 return CMD_SUCCESS;
718e3744 19820}
19821
7336e101
SP
19822DEFUN (no_extcommunity_list_standard_all,
19823 no_bgp_extcommunity_list_standard_all_cmd,
a2099c1d 19824 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19825 NO_STR
19826 BGP_STR
19827 EXTCOMMUNITY_LIST_STR
813d4307 19828 "Extended Community list number (standard)\n"
718e3744 19829 "Specify standard extcommunity-list\n"
5bf15956 19830 "Community list name\n"
2f8cc0e5
DA
19831 "Sequence number of an entry\n"
19832 "Sequence number\n"
718e3744 19833 "Specify community to reject\n"
19834 "Specify community to accept\n"
19835 EXTCOMMUNITY_VAL_STR)
19836{
d62a17ae 19837 int style = EXTCOMMUNITY_LIST_STANDARD;
19838 int direct = 0;
19839 char *cl_number_or_name = NULL;
d4455c89 19840 char *str = NULL;
2f8cc0e5 19841 char *seq = NULL;
d62a17ae 19842 int idx = 0;
d4455c89 19843
a08032fe 19844 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19845 seq = argv[idx]->arg;
19846
19847 idx = 0;
d4455c89
DA
19848 argv_find(argv, argc, "permit", &idx);
19849 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
19850 if (idx) {
19851 direct = argv_find(argv, argc, "permit", &idx)
19852 ? COMMUNITY_PERMIT
19853 : COMMUNITY_DENY;
19854
19855 idx = 0;
19856 argv_find(argv, argc, "AA:NN", &idx);
19857 str = argv_concat(argv, argc, idx);
19858 }
19859
19860 idx = 0;
d62a17ae 19861 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19862 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19863 cl_number_or_name = argv[idx]->arg;
42f914d4 19864
d62a17ae 19865 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19866 seq, direct, style);
42f914d4 19867
d62a17ae 19868 XFREE(MTYPE_TMP, str);
42f914d4 19869
d62a17ae 19870 if (ret < 0) {
19871 community_list_perror(vty, ret);
19872 return CMD_WARNING_CONFIG_FAILED;
19873 }
42f914d4 19874
d62a17ae 19875 return CMD_SUCCESS;
718e3744 19876}
19877
d4455c89
DA
19878ALIAS(no_extcommunity_list_standard_all,
19879 no_bgp_extcommunity_list_standard_all_list_cmd,
a2099c1d 19880 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
36d4bb44 19881 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19882 "Extended Community list number (standard)\n"
19883 "Specify standard extcommunity-list\n"
19884 "Community list name\n")
19885
7336e101
SP
19886DEFUN (no_extcommunity_list_expanded_all,
19887 no_bgp_extcommunity_list_expanded_all_cmd,
a2099c1d 19888 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19889 NO_STR
19890 BGP_STR
19891 EXTCOMMUNITY_LIST_STR
718e3744 19892 "Extended Community list number (expanded)\n"
718e3744 19893 "Specify expanded extcommunity-list\n"
5bf15956 19894 "Extended Community list name\n"
2f8cc0e5
DA
19895 "Sequence number of an entry\n"
19896 "Sequence number\n"
718e3744 19897 "Specify community to reject\n"
19898 "Specify community to accept\n"
19899 "An ordered list as a regular-expression\n")
19900{
d62a17ae 19901 int style = EXTCOMMUNITY_LIST_EXPANDED;
19902 int direct = 0;
19903 char *cl_number_or_name = NULL;
d4455c89 19904 char *str = NULL;
2f8cc0e5 19905 char *seq = NULL;
d62a17ae 19906 int idx = 0;
d4455c89 19907
a08032fe 19908 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19909 seq = argv[idx]->arg;
19910
19911 idx = 0;
d4455c89
DA
19912 argv_find(argv, argc, "permit", &idx);
19913 argv_find(argv, argc, "deny", &idx);
19914
19915 if (idx) {
19916 direct = argv_find(argv, argc, "permit", &idx)
19917 ? COMMUNITY_PERMIT
19918 : COMMUNITY_DENY;
19919
19920 idx = 0;
19921 argv_find(argv, argc, "LINE", &idx);
19922 str = argv_concat(argv, argc, idx);
19923 }
19924
19925 idx = 0;
d62a17ae 19926 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19927 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19928 cl_number_or_name = argv[idx]->arg;
42f914d4 19929
d62a17ae 19930 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19931 seq, direct, style);
42f914d4 19932
d62a17ae 19933 XFREE(MTYPE_TMP, str);
42f914d4 19934
d62a17ae 19935 if (ret < 0) {
19936 community_list_perror(vty, ret);
19937 return CMD_WARNING_CONFIG_FAILED;
19938 }
42f914d4 19939
d62a17ae 19940 return CMD_SUCCESS;
718e3744 19941}
19942
d4455c89
DA
19943ALIAS(no_extcommunity_list_expanded_all,
19944 no_bgp_extcommunity_list_expanded_all_list_cmd,
a2099c1d 19945 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
36d4bb44 19946 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19947 "Extended Community list number (expanded)\n"
19948 "Specify expanded extcommunity-list\n"
19949 "Extended Community list name\n")
19950
d62a17ae 19951static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 19952{
d62a17ae 19953 struct community_entry *entry;
718e3744 19954
d62a17ae 19955 for (entry = list->head; entry; entry = entry->next) {
19956 if (entry == list->head) {
19957 if (all_digit(list->name))
19958 vty_out(vty, "Extended community %s list %s\n",
19959 entry->style == EXTCOMMUNITY_LIST_STANDARD
19960 ? "standard"
19961 : "(expanded) access",
19962 list->name);
19963 else
19964 vty_out(vty,
19965 "Named extended community %s list %s\n",
19966 entry->style == EXTCOMMUNITY_LIST_STANDARD
19967 ? "standard"
19968 : "expanded",
19969 list->name);
19970 }
19971 if (entry->any)
19972 vty_out(vty, " %s\n",
19973 community_direct_str(entry->direct));
19974 else
19975 vty_out(vty, " %s %s\n",
19976 community_direct_str(entry->direct),
8d9b8ed9 19977 community_list_config_str(entry));
d62a17ae 19978 }
718e3744 19979}
19980
7336e101
SP
19981DEFUN (show_extcommunity_list,
19982 show_bgp_extcommunity_list_cmd,
19983 "show bgp extcommunity-list",
718e3744 19984 SHOW_STR
7336e101 19985 BGP_STR
718e3744 19986 "List extended-community list\n")
19987{
d62a17ae 19988 struct community_list *list;
19989 struct community_list_master *cm;
718e3744 19990
d62a17ae 19991 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19992 if (!cm)
19993 return CMD_SUCCESS;
718e3744 19994
d62a17ae 19995 for (list = cm->num.head; list; list = list->next)
19996 extcommunity_list_show(vty, list);
718e3744 19997
d62a17ae 19998 for (list = cm->str.head; list; list = list->next)
19999 extcommunity_list_show(vty, list);
718e3744 20000
d62a17ae 20001 return CMD_SUCCESS;
718e3744 20002}
20003
7336e101
SP
20004DEFUN (show_extcommunity_list_arg,
20005 show_bgp_extcommunity_list_arg_cmd,
a2099c1d 20006 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
7336e101
SP
20007 SHOW_STR
20008 BGP_STR
718e3744 20009 "List extended-community list\n"
20010 "Extcommunity-list number\n"
960b69b9 20011 "Extcommunity-list name\n"
20012 "Detailed information on extcommunity-list\n")
718e3744 20013{
d62a17ae 20014 int idx_comm_list = 3;
20015 struct community_list *list;
718e3744 20016
e237b0d2 20017 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20018 EXTCOMMUNITY_LIST_MASTER);
20019 if (!list) {
20020 vty_out(vty, "%% Can't find extcommunity-list\n");
20021 return CMD_WARNING;
20022 }
718e3744 20023
d62a17ae 20024 extcommunity_list_show(vty, list);
718e3744 20025
d62a17ae 20026 return CMD_SUCCESS;
718e3744 20027}
6b0655a2 20028
718e3744 20029/* Display community-list and extcommunity-list configuration. */
d62a17ae 20030static int community_list_config_write(struct vty *vty)
20031{
20032 struct community_list *list;
20033 struct community_entry *entry;
20034 struct community_list_master *cm;
20035 int write = 0;
20036
20037 /* Community-list. */
20038 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20039
20040 for (list = cm->num.head; list; list = list->next)
20041 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20042 vty_out(vty,
20043 "bgp community-list %s seq %" PRId64 " %s %s\n",
20044 list->name, entry->seq,
d62a17ae 20045 community_direct_str(entry->direct),
20046 community_list_config_str(entry));
20047 write++;
20048 }
20049 for (list = cm->str.head; list; list = list->next)
20050 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20051 vty_out(vty,
20052 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 20053 entry->style == COMMUNITY_LIST_STANDARD
20054 ? "standard"
20055 : "expanded",
2f8cc0e5
DA
20056 list->name, entry->seq,
20057 community_direct_str(entry->direct),
d62a17ae 20058 community_list_config_str(entry));
20059 write++;
20060 }
20061
20062 /* Extcommunity-list. */
20063 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_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 extcommunity-list %s seq %" PRId64 " %s %s\n",
20069 list->name, entry->seq,
20070 community_direct_str(entry->direct),
d62a17ae 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 20076 vty_out(vty,
6cde4b45 20077 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 20078 entry->style == EXTCOMMUNITY_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
20088 /* lcommunity-list. */
20089 cm = community_list_master_lookup(bgp_clist,
20090 LARGE_COMMUNITY_LIST_MASTER);
20091
20092 for (list = cm->num.head; list; list = list->next)
20093 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20094 vty_out(vty,
6cde4b45 20095 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
20096 list->name, entry->seq,
20097 community_direct_str(entry->direct),
d62a17ae 20098 community_list_config_str(entry));
20099 write++;
20100 }
20101 for (list = cm->str.head; list; list = list->next)
20102 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20103 vty_out(vty,
6cde4b45 20104 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 20105
d62a17ae 20106 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20107 ? "standard"
20108 : "expanded",
2f8cc0e5 20109 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 20110 community_list_config_str(entry));
20111 write++;
20112 }
20113
20114 return write;
20115}
20116
612c2c15 20117static int community_list_config_write(struct vty *vty);
d62a17ae 20118static struct cmd_node community_list_node = {
f4b8291f 20119 .name = "community list",
62b346ee
DL
20120 .node = COMMUNITY_LIST_NODE,
20121 .prompt = "",
612c2c15 20122 .config_write = community_list_config_write,
718e3744 20123};
20124
d62a17ae 20125static void community_list_vty(void)
20126{
612c2c15 20127 install_node(&community_list_node);
d62a17ae 20128
20129 /* Community-list. */
7336e101
SP
20130 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20131 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20132 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 20133 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 20134 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 20135 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
20136 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20137 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 20138
20139 /* Extcommunity-list. */
7336e101
SP
20140 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20141 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20142 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
20143 install_element(CONFIG_NODE,
20144 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 20145 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
20146 install_element(CONFIG_NODE,
20147 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
20148 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20149 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 20150
20151 /* Large Community List */
7336e101 20152 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
20153 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20154 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 20155 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
20156 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20157 install_element(CONFIG_NODE,
20158 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
20159 install_element(CONFIG_NODE,
20160 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20161 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20162 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20163 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20164 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20165 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20166 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
225096bc
DA
20167
20168 bgp_community_list_command_completion_setup();
5bf15956 20169}
ed0e57e3
DA
20170
20171static struct cmd_node community_alias_node = {
20172 .name = "community alias",
20173 .node = COMMUNITY_ALIAS_NODE,
20174 .prompt = "",
20175 .config_write = bgp_community_alias_write,
20176};
20177
20178void community_alias_vty(void)
20179{
20180 install_node(&community_alias_node);
20181
20182 /* Community-list. */
20183 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
b4ad2fae
DS
20184
20185 bgp_community_alias_command_completion_setup();
ed0e57e3 20186}